diff options
author | talasila <talasila@research.att.com> | 2017-02-08 10:13:29 -0500 |
---|---|---|
committer | talasila <talasila@research.att.com> | 2017-02-08 10:15:00 -0500 |
commit | f8a8d5192b1e5013d9e2f699be54b072ef39d5f0 (patch) | |
tree | b7a65bb0a7d70a9dc24c064113868e5f3b8e6a09 /dcae_dmaapbc_webapp/src/main/webapp/app/fusion/ase/scripts/bower_components/bpmn-js/dist/bpmn-navigated-viewer.js | |
parent | 72a80fbff7120630576ccd5aa67c20818c2943c7 (diff) |
Initial OpenECOMP UI/DMaapBC commit
Change-Id: Ia492e1b88311b9bed4c31f593b28deaaad73b7e4
Signed-off-by: talasila <talasila@research.att.com>
Diffstat (limited to 'dcae_dmaapbc_webapp/src/main/webapp/app/fusion/ase/scripts/bower_components/bpmn-js/dist/bpmn-navigated-viewer.js')
-rw-r--r-- | dcae_dmaapbc_webapp/src/main/webapp/app/fusion/ase/scripts/bower_components/bpmn-js/dist/bpmn-navigated-viewer.js | 27371 |
1 files changed, 27371 insertions, 0 deletions
diff --git a/dcae_dmaapbc_webapp/src/main/webapp/app/fusion/ase/scripts/bower_components/bpmn-js/dist/bpmn-navigated-viewer.js b/dcae_dmaapbc_webapp/src/main/webapp/app/fusion/ase/scripts/bower_components/bpmn-js/dist/bpmn-navigated-viewer.js new file mode 100644 index 0000000..ea0861c --- /dev/null +++ b/dcae_dmaapbc_webapp/src/main/webapp/app/fusion/ase/scripts/bower_components/bpmn-js/dist/bpmn-navigated-viewer.js @@ -0,0 +1,27371 @@ +/*! + * bpmn-js - bpmn-navigated-viewer v0.10.3 + + * Copyright 2014, 2015 camunda Services GmbH and other contributors + * + * Released under the bpmn.io license + * http://bpmn.io/license + * + * Source Code: https://github.com/bpmn-io/bpmn-js + * + * Date: 2015-05-18 + */ +!function(e){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var f;"undefined"!=typeof window?f=window:"undefined"!=typeof global?f=global:"undefined"!=typeof self&&(f=self),f.BpmnJS=e()}}(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(_dereq_,module,exports){ +'use strict'; + +var inherits = _dereq_(79); + +var Viewer = _dereq_(2); + + +/** + * A viewer that includes mouse navigation facilities + * + * @param {Object} options + */ +function NavigatedViewer(options) { + Viewer.call(this, options); +} + +inherits(NavigatedViewer, Viewer); + +module.exports = NavigatedViewer; + +NavigatedViewer.prototype._navigationModules = [ + _dereq_(61), + _dereq_(59) +]; + +NavigatedViewer.prototype._modules = [].concat( + NavigatedViewer.prototype._modules, + NavigatedViewer.prototype._navigationModules); +},{"2":2,"59":59,"61":61,"79":79}],2:[function(_dereq_,module,exports){ +'use strict'; + +var assign = _dereq_(175), + omit = _dereq_(179), + isString = _dereq_(172), + isNumber = _dereq_(169); + +var domify = _dereq_(190), + domQuery = _dereq_(192), + domRemove = _dereq_(193); + +var Diagram = _dereq_(36), + BpmnModdle = _dereq_(15); + +var Importer = _dereq_(9); + + +function initListeners(diagram, listeners) { + var events = diagram.get('eventBus'); + + listeners.forEach(function(l) { + events.on(l.event, l.handler); + }); +} + +function checkValidationError(err) { + + // check if we can help the user by indicating wrong BPMN 2.0 xml + // (in case he or the exporting tool did not get that right) + + var pattern = /unparsable content <([^>]+)> detected([\s\S]*)$/; + var match = pattern.exec(err.message); + + if (match) { + err.message = + 'unparsable content <' + match[1] + '> detected; ' + + 'this may indicate an invalid BPMN 2.0 diagram file' + match[2]; + } + + return err; +} + +var DEFAULT_OPTIONS = { + width: '100%', + height: '100%', + position: 'relative', + container: 'body' +}; + + +/** + * Ensure the passed argument is a proper unit (defaulting to px) + */ +function ensureUnit(val) { + return val + (isNumber(val) ? 'px' : ''); +} + +/** + * A viewer for BPMN 2.0 diagrams. + * + * Have a look at {@link NavigatedViewer} or {@link Modeler} for bundles that include + * additional features. + * + * + * ## Extending the Viewer + * + * In order to extend the viewer pass extension modules to bootstrap via the + * `additionalModules` option. An extension module is an object that exposes + * named services. + * + * The following example depicts the integration of a simple + * logging component that integrates with interaction events: + * + * + * ```javascript + * + * // logging component + * function InteractionLogger(eventBus) { + * eventBus.on('element.hover', function(event) { + * console.log() + * }) + * } + * + * InteractionLogger.$inject = [ 'eventBus' ]; // minification save + * + * // extension module + * var extensionModule = { + * __init__: [ 'interactionLogger' ], + * interactionLogger: [ 'type', InteractionLogger ] + * }; + * + * // extend the viewer + * var bpmnViewer = new Viewer({ additionalModules: [ extensionModule ] }); + * bpmnViewer.importXML(...); + * ``` + * + * @param {Object} [options] configuration options to pass to the viewer + * @param {DOMElement} [options.container] the container to render the viewer in, defaults to body. + * @param {String|Number} [options.width] the width of the viewer + * @param {String|Number} [options.height] the height of the viewer + * @param {Object} [options.moddleExtensions] extension packages to provide + * @param {Array<didi.Module>} [options.modules] a list of modules to override the default modules + * @param {Array<didi.Module>} [options.additionalModules] a list of modules to use with the default modules + */ +function Viewer(options) { + + this.options = options = assign({}, DEFAULT_OPTIONS, options || {}); + + var parent = options.container; + + // support jquery element + // unwrap it if passed + if (parent.get) { + parent = parent.get(0); + } + + // support selector + if (isString(parent)) { + parent = domQuery(parent); + } + + var container = this.container = domify('<div class="bjs-container"></div>'); + parent.appendChild(container); + + assign(container.style, { + width: ensureUnit(options.width), + height: ensureUnit(options.height), + position: options.position + }); + + /** + * The code in the <project-logo></project-logo> area + * must not be changed, see http://bpmn.io/license for more information + * + * <project-logo> + */ + + /* jshint -W101 */ + + // inlined ../resources/bpmnjs.png + var logoData = 'iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAMAAADypuvZAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADBQTFRFiMte9PrwldFwfcZPqtqN0+zEyOe1XLgjvuKncsJAZ70y6fXh3vDT////UrQV////G2zN+AAAABB0Uk5T////////////////////AOAjXRkAAAHDSURBVHjavJZJkoUgDEBJmAX8979tM8u3E6x20VlYJfFFMoL4vBDxATxZcakIOJTWSmxvKWVIkJ8jHvlRv1F2LFrVISCZI+tCtQx+XfewgVTfyY3plPiQEAzI3zWy+kR6NBhFBYeBuscJLOUuA2WVLpCjVIaFzrNQZArxAZKUQm6gsj37L9Cb7dnIBUKxENaaMJQqMpDXvSL+ktxdGRm2IsKgJGGPg7atwUG5CcFUEuSv+CwQqizTrvDTNXdMU2bMiDWZd8d7QIySWVRsb2vBBioxOFt4OinPBapL+neAb5KL5IJ8szOza2/DYoipUCx+CjO0Bpsv0V6mktNZ+k8rlABlWG0FrOpKYVo8DT3dBeLEjUBAj7moDogVii7nSS9QzZnFcOVBp1g2PyBQ3Vr5aIapN91VJy33HTJLC1iX2FY6F8gRdaAeIEfVONgtFCzZTmoLEdOjBDfsIOA6128gw3eu1shAajdZNAORxuQDJN5A5PbEG6gNIu24QJD5iNyRMZIr6bsHbCtCU/OaOaSvgkUyDMdDa1BXGf5HJ1To+/Ym6mCKT02Y+/Sa126ZKyd3jxhzpc1r8zVL6YM1Qy/kR4ABAFJ6iQUnivhAAAAAAElFTkSuQmCC'; + + /* jshint +W101 */ + + var linkMarkup = + '<a href="http://bpmn.io" ' + + 'target="_blank" ' + + 'class="bjs-powered-by" ' + + 'title="Powered by bpmn.io" ' + + 'style="position: absolute; bottom: 15px; right: 15px; z-index: 100">' + + '<img src="data:image/png;base64,' + logoData + '">' + + '</a>'; + + container.appendChild(domify(linkMarkup)); + + /* </project-logo> */ +} + +Viewer.prototype.importXML = function(xml, done) { + + var self = this; + + this.moddle = this.createModdle(); + + this.moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) { + + if (err) { + err = checkValidationError(err); + return done(err); + } + + var parseWarnings = context.warnings; + + self.importDefinitions(definitions, function(err, importWarnings) { + if (err) { + return done(err); + } + + done(null, parseWarnings.concat(importWarnings || [])); + }); + }); +}; + +Viewer.prototype.saveXML = function(options, done) { + + if (!done) { + done = options; + options = {}; + } + + var definitions = this.definitions; + + if (!definitions) { + return done(new Error('no definitions loaded')); + } + + this.moddle.toXML(definitions, options, done); +}; + +Viewer.prototype.createModdle = function() { + return new BpmnModdle(this.options.moddleExtensions); +}; + +Viewer.prototype.saveSVG = function(options, done) { + + if (!done) { + done = options; + options = {}; + } + + var canvas = this.get('canvas'); + + var contentNode = canvas.getDefaultLayer(), + defsNode = canvas._svg.select('defs'); + + var contents = contentNode.innerSVG(), + defs = (defsNode && defsNode.outerSVG()) || ''; + + var bbox = contentNode.getBBox(); + + var svg = + '<?xml version="1.0" encoding="utf-8"?>\n' + + '<!-- created with bpmn-js / http://bpmn.io -->\n' + + '<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">\n' + + '<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" ' + + 'width="' + bbox.width + '" height="' + bbox.height + '" ' + + 'viewBox="' + bbox.x + ' ' + bbox.y + ' ' + bbox.width + ' ' + bbox.height + '" version="1.1">' + + defs + contents + + '</svg>'; + + done(null, svg); +}; + +Viewer.prototype.get = function(name) { + + if (!this.diagram) { + throw new Error('no diagram loaded'); + } + + return this.diagram.get(name); +}; + +Viewer.prototype.invoke = function(fn) { + + if (!this.diagram) { + throw new Error('no diagram loaded'); + } + + return this.diagram.invoke(fn); +}; + +Viewer.prototype.importDefinitions = function(definitions, done) { + + // use try/catch to not swallow synchronous exceptions + // that may be raised during model parsing + try { + if (this.diagram) { + this.clear(); + } + + this.definitions = definitions; + + var diagram = this.diagram = this._createDiagram(this.options); + + this._init(diagram); + + Importer.importBpmnDiagram(diagram, definitions, done); + } catch (e) { + done(e); + } +}; + +Viewer.prototype._init = function(diagram) { + initListeners(diagram, this.__listeners || []); +}; + +Viewer.prototype._createDiagram = function(options) { + + var modules = [].concat(options.modules || this.getModules(), options.additionalModules || []); + + // add self as an available service + modules.unshift({ + bpmnjs: [ 'value', this ], + moddle: [ 'value', this.moddle ] + }); + + options = omit(options, 'additionalModules'); + + options = assign(options, { + canvas: { container: this.container }, + modules: modules + }); + + return new Diagram(options); +}; + + +Viewer.prototype.getModules = function() { + return this._modules; +}; + +/** + * Remove all drawn elements from the viewer. + * + * After calling this method the viewer can still + * be reused for opening another diagram. + */ +Viewer.prototype.clear = function() { + var diagram = this.diagram; + + if (diagram) { + diagram.destroy(); + } +}; + +/** + * Destroy the viewer instance and remove all its remainders + * from the document tree. + */ +Viewer.prototype.destroy = function() { + // clear underlying diagram + this.clear(); + + // remove container + domRemove(this.container); +}; + +/** + * Register an event listener on the viewer + * + * @param {String} event + * @param {Function} handler + */ +Viewer.prototype.on = function(event, handler) { + var diagram = this.diagram, + listeners = this.__listeners = this.__listeners || []; + + listeners.push({ event: event, handler: handler }); + + if (diagram) { + diagram.get('eventBus').on(event, handler); + } +}; + +// modules the viewer is composed of +Viewer.prototype._modules = [ + _dereq_(3), + _dereq_(56), + _dereq_(52) +]; + +module.exports = Viewer; + +},{"15":15,"169":169,"172":172,"175":175,"179":179,"190":190,"192":192,"193":193,"3":3,"36":36,"52":52,"56":56,"9":9}],3:[function(_dereq_,module,exports){ +module.exports = { + __depends__: [ + _dereq_(6), + _dereq_(11) + ] +}; +},{"11":11,"6":6}],4:[function(_dereq_,module,exports){ +'use strict'; + +var inherits = _dereq_(79), + isArray = _dereq_(166), + isObject = _dereq_(170), + assign = _dereq_(175), + forEach = _dereq_(84), + every = _dereq_(81), + includes = _dereq_(86), + some = _dereq_(89); + +var DefaultRenderer = _dereq_(44), + TextUtil = _dereq_(71), + DiUtil = _dereq_(12); + +var createLine = DefaultRenderer.createLine; + + +function BpmnRenderer(events, styles, pathMap) { + + DefaultRenderer.call(this, styles); + + var TASK_BORDER_RADIUS = 10; + var INNER_OUTER_DIST = 3; + + var LABEL_STYLE = { + fontFamily: 'Arial, sans-serif', + fontSize: '12px' + }; + + var textUtil = new TextUtil({ + style: LABEL_STYLE, + size: { width: 100 } + }); + + var markers = {}; + + function addMarker(id, element) { + markers[id] = element; + } + + function marker(id) { + return markers[id]; + } + + function initMarkers(svg) { + + function createMarker(id, options) { + var attrs = assign({ + fill: 'black', + strokeWidth: 1, + strokeLinecap: 'round', + strokeDasharray: 'none' + }, options.attrs); + + var ref = options.ref || { x: 0, y: 0 }; + + var scale = options.scale || 1; + + // fix for safari / chrome / firefox bug not correctly + // resetting stroke dash array + if (attrs.strokeDasharray === 'none') { + attrs.strokeDasharray = [10000, 1]; + } + + var marker = options.element + .attr(attrs) + .marker(0, 0, 20, 20, ref.x, ref.y) + .attr({ + markerWidth: 20 * scale, + markerHeight: 20 * scale + }); + + return addMarker(id, marker); + } + + + createMarker('sequenceflow-end', { + element: svg.path('M 1 5 L 11 10 L 1 15 Z'), + ref: { x: 11, y: 10 }, + scale: 0.5 + }); + + createMarker('messageflow-start', { + element: svg.circle(6, 6, 3.5), + attrs: { + fill: 'white', + stroke: 'black' + }, + ref: { x: 6, y: 6 } + }); + + createMarker('messageflow-end', { + element: svg.path('m 1 5 l 0 -3 l 7 3 l -7 3 z'), + attrs: { + fill: 'white', + stroke: 'black', + strokeLinecap: 'butt' + }, + ref: { x: 8.5, y: 5 } + }); + + createMarker('data-association-end', { + element: svg.path('M 1 5 L 11 10 L 1 15'), + attrs: { + fill: 'white', + stroke: 'black' + }, + ref: { x: 11, y: 10 }, + scale: 0.5 + }); + + createMarker('conditional-flow-marker', { + element: svg.path('M 0 10 L 8 6 L 16 10 L 8 14 Z'), + attrs: { + fill: 'white', + stroke: 'black' + }, + ref: { x: -1, y: 10 }, + scale: 0.5 + }); + + createMarker('conditional-default-flow-marker', { + element: svg.path('M 1 4 L 5 16'), + attrs: { + stroke: 'black' + }, + ref: { x: -5, y: 10 }, + scale: 0.5 + }); + } + + function computeStyle(custom, traits, defaultStyles) { + if (!isArray(traits)) { + defaultStyles = traits; + traits = []; + } + + return styles.style(traits || [], assign(defaultStyles, custom || {})); + } + + function drawCircle(p, width, height, offset, attrs) { + + if (isObject(offset)) { + attrs = offset; + offset = 0; + } + + offset = offset || 0; + + attrs = computeStyle(attrs, { + stroke: 'black', + strokeWidth: 2, + fill: 'white' + }); + + var cx = width / 2, + cy = height / 2; + + return p.circle(cx, cy, Math.round((width + height) / 4 - offset)).attr(attrs); + } + + function drawRect(p, width, height, r, offset, attrs) { + + if (isObject(offset)) { + attrs = offset; + offset = 0; + } + + offset = offset || 0; + + attrs = computeStyle(attrs, { + stroke: 'black', + strokeWidth: 2, + fill: 'white' + }); + + return p.rect(offset, offset, width - offset * 2, height - offset * 2, r).attr(attrs); + } + + function drawDiamond(p, width, height, attrs) { + + var x_2 = width / 2; + var y_2 = height / 2; + + var points = [x_2, 0, width, y_2, x_2, height, 0, y_2 ]; + + attrs = computeStyle(attrs, { + stroke: 'black', + strokeWidth: 2, + fill: 'white' + }); + + return p.polygon(points).attr(attrs); + } + + function drawLine(p, waypoints, attrs) { + attrs = computeStyle(attrs, [ 'no-fill' ], { + stroke: 'black', + strokeWidth: 2, + fill: 'none' + }); + + return createLine(waypoints, attrs).appendTo(p); + } + + function drawPath(p, d, attrs) { + + attrs = computeStyle(attrs, [ 'no-fill' ], { + strokeWidth: 2, + stroke: 'black' + }); + + return p.path(d).attr(attrs); + } + + function as(type) { + return function(p, element) { + return handlers[type](p, element); + }; + } + + function renderer(type) { + return handlers[type]; + } + + function renderEventContent(element, p) { + + var event = getSemantic(element); + var isThrowing = isThrowEvent(event); + + if (isTypedEvent(event, 'bpmn:MessageEventDefinition')) { + return renderer('bpmn:MessageEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:TimerEventDefinition')) { + return renderer('bpmn:TimerEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:ConditionalEventDefinition')) { + return renderer('bpmn:ConditionalEventDefinition')(p, element); + } + + if (isTypedEvent(event, 'bpmn:SignalEventDefinition')) { + return renderer('bpmn:SignalEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:CancelEventDefinition') && + isTypedEvent(event, 'bpmn:TerminateEventDefinition', { parallelMultiple: false })) { + return renderer('bpmn:MultipleEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:CancelEventDefinition') && + isTypedEvent(event, 'bpmn:TerminateEventDefinition', { parallelMultiple: true })) { + return renderer('bpmn:ParallelMultipleEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:EscalationEventDefinition')) { + return renderer('bpmn:EscalationEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:LinkEventDefinition')) { + return renderer('bpmn:LinkEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:ErrorEventDefinition')) { + return renderer('bpmn:ErrorEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:CancelEventDefinition')) { + return renderer('bpmn:CancelEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:CompensateEventDefinition')) { + return renderer('bpmn:CompensateEventDefinition')(p, element, isThrowing); + } + + if (isTypedEvent(event, 'bpmn:TerminateEventDefinition')) { + return renderer('bpmn:TerminateEventDefinition')(p, element, isThrowing); + } + + return null; + } + + function renderLabel(p, label, options) { + return textUtil.createText(p, label || '', options).addClass('djs-label'); + } + + function renderEmbeddedLabel(p, element, align) { + var semantic = getSemantic(element); + return renderLabel(p, semantic.name, { box: element, align: align, padding: 5 }); + } + + function renderExternalLabel(p, element, align) { + var semantic = getSemantic(element); + + if (!semantic.name) { + element.hidden = true; + } + + return renderLabel(p, semantic.name, { box: element, align: align, style: { fontSize: '11px' } }); + } + + function renderLaneLabel(p, text, element) { + var textBox = renderLabel(p, text, { + box: { height: 30, width: element.height }, + align: 'center-middle' + }); + + var top = -1 * element.height; + textBox.transform( + 'rotate(270) ' + + 'translate(' + top + ',' + 0 + ')' + ); + } + + function createPathFromConnection(connection) { + var waypoints = connection.waypoints; + + var pathData = 'm ' + waypoints[0].x + ',' + waypoints[0].y; + for (var i = 1; i < waypoints.length; i++) { + pathData += 'L' + waypoints[i].x + ',' + waypoints[i].y + ' '; + } + return pathData; + } + + var handlers = { + 'bpmn:Event': function(p, element, attrs) { + return drawCircle(p, element.width, element.height, attrs); + }, + 'bpmn:StartEvent': function(p, element) { + var attrs = {}; + var semantic = getSemantic(element); + + if (!semantic.isInterrupting) { + attrs = { + strokeDasharray: '6', + strokeLinecap: 'round' + }; + } + + var circle = renderer('bpmn:Event')(p, element, attrs); + + renderEventContent(element, p); + + return circle; + }, + 'bpmn:MessageEventDefinition': function(p, element, isThrowing) { + var pathData = pathMap.getScaledPath('EVENT_MESSAGE', { + xScaleFactor: 0.9, + yScaleFactor: 0.9, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.235, + my: 0.315 + } + }); + + var fill = isThrowing ? 'black' : 'white'; + var stroke = isThrowing ? 'white' : 'black'; + + var messagePath = drawPath(p, pathData, { + strokeWidth: 1, + fill: fill, + stroke: stroke + }); + + return messagePath; + }, + 'bpmn:TimerEventDefinition': function(p, element) { + + var circle = drawCircle(p, element.width, element.height, 0.2 * element.height, { + strokeWidth: 2 + }); + + var pathData = pathMap.getScaledPath('EVENT_TIMER_WH', { + xScaleFactor: 0.75, + yScaleFactor: 0.75, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.5, + my: 0.5 + } + }); + + drawPath(p, pathData, { + strokeWidth: 2, + strokeLinecap: 'square' + }); + + for(var i = 0;i < 12;i++) { + + var linePathData = pathMap.getScaledPath('EVENT_TIMER_LINE', { + xScaleFactor: 0.75, + yScaleFactor: 0.75, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.5, + my: 0.5 + } + }); + + var width = element.width / 2; + var height = element.height / 2; + + drawPath(p, linePathData, { + strokeWidth: 1, + strokeLinecap: 'square', + transform: 'rotate(' + (i * 30) + ',' + height + ',' + width + ')' + }); + } + + return circle; + }, + 'bpmn:EscalationEventDefinition': function(p, event, isThrowing) { + var pathData = pathMap.getScaledPath('EVENT_ESCALATION', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: event.width, + containerHeight: event.height, + position: { + mx: 0.5, + my: 0.555 + } + }); + + var fill = isThrowing ? 'black' : 'none'; + + return drawPath(p, pathData, { + strokeWidth: 1, + fill: fill + }); + }, + 'bpmn:ConditionalEventDefinition': function(p, event) { + var pathData = pathMap.getScaledPath('EVENT_CONDITIONAL', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: event.width, + containerHeight: event.height, + position: { + mx: 0.5, + my: 0.222 + } + }); + + return drawPath(p, pathData, { + strokeWidth: 1 + }); + }, + 'bpmn:LinkEventDefinition': function(p, event, isThrowing) { + var pathData = pathMap.getScaledPath('EVENT_LINK', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: event.width, + containerHeight: event.height, + position: { + mx: 0.57, + my: 0.263 + } + }); + + var fill = isThrowing ? 'black' : 'none'; + + return drawPath(p, pathData, { + strokeWidth: 1, + fill: fill + }); + }, + 'bpmn:ErrorEventDefinition': function(p, event, isThrowing) { + var pathData = pathMap.getScaledPath('EVENT_ERROR', { + xScaleFactor: 1.1, + yScaleFactor: 1.1, + containerWidth: event.width, + containerHeight: event.height, + position: { + mx: 0.2, + my: 0.722 + } + }); + + var fill = isThrowing ? 'black' : 'none'; + + return drawPath(p, pathData, { + strokeWidth: 1, + fill: fill + }); + }, + 'bpmn:CancelEventDefinition': function(p, event, isThrowing) { + var pathData = pathMap.getScaledPath('EVENT_CANCEL_45', { + xScaleFactor: 1.0, + yScaleFactor: 1.0, + containerWidth: event.width, + containerHeight: event.height, + position: { + mx: 0.638, + my: -0.055 + } + }); + + var fill = isThrowing ? 'black' : 'none'; + + return drawPath(p, pathData, { + strokeWidth: 1, + fill: fill + }).transform('rotate(45)'); + }, + 'bpmn:CompensateEventDefinition': function(p, event, isThrowing) { + var pathData = pathMap.getScaledPath('EVENT_COMPENSATION', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: event.width, + containerHeight: event.height, + position: { + mx: 0.201, + my: 0.472 + } + }); + + var fill = isThrowing ? 'black' : 'none'; + + return drawPath(p, pathData, { + strokeWidth: 1, + fill: fill + }); + }, + 'bpmn:SignalEventDefinition': function(p, event, isThrowing) { + var pathData = pathMap.getScaledPath('EVENT_SIGNAL', { + xScaleFactor: 0.9, + yScaleFactor: 0.9, + containerWidth: event.width, + containerHeight: event.height, + position: { + mx: 0.5, + my: 0.2 + } + }); + + var fill = isThrowing ? 'black' : 'none'; + + return drawPath(p, pathData, { + strokeWidth: 1, + fill: fill + }); + }, + 'bpmn:MultipleEventDefinition': function(p, event, isThrowing) { + var pathData = pathMap.getScaledPath('EVENT_MULTIPLE', { + xScaleFactor: 1.1, + yScaleFactor: 1.1, + containerWidth: event.width, + containerHeight: event.height, + position: { + mx: 0.222, + my: 0.36 + } + }); + + var fill = isThrowing ? 'black' : 'none'; + + return drawPath(p, pathData, { + strokeWidth: 1, + fill: fill + }); + }, + 'bpmn:ParallelMultipleEventDefinition': function(p, event) { + var pathData = pathMap.getScaledPath('EVENT_PARALLEL_MULTIPLE', { + xScaleFactor: 1.2, + yScaleFactor: 1.2, + containerWidth: event.width, + containerHeight: event.height, + position: { + mx: 0.458, + my: 0.194 + } + }); + + return drawPath(p, pathData, { + strokeWidth: 1 + }); + }, + 'bpmn:EndEvent': function(p, element) { + var circle = renderer('bpmn:Event')(p, element, { + strokeWidth: 4 + }); + + renderEventContent(element, p, true); + + return circle; + }, + 'bpmn:TerminateEventDefinition': function(p, element) { + var circle = drawCircle(p, element.width, element.height, 8, { + strokeWidth: 4, + fill: 'black' + }); + + return circle; + }, + 'bpmn:IntermediateEvent': function(p, element) { + var outer = renderer('bpmn:Event')(p, element, { strokeWidth: 1 }); + /* inner */ drawCircle(p, element.width, element.height, INNER_OUTER_DIST, { strokeWidth: 1, fill: 'none' }); + + renderEventContent(element, p); + + return outer; + }, + 'bpmn:IntermediateCatchEvent': as('bpmn:IntermediateEvent'), + 'bpmn:IntermediateThrowEvent': as('bpmn:IntermediateEvent'), + + 'bpmn:Activity': function(p, element, attrs) { + return drawRect(p, element.width, element.height, TASK_BORDER_RADIUS, attrs); + }, + + 'bpmn:Task': function(p, element, attrs) { + var rect = renderer('bpmn:Activity')(p, element, attrs); + renderEmbeddedLabel(p, element, 'center-middle'); + attachTaskMarkers(p, element); + return rect; + }, + 'bpmn:ServiceTask': function(p, element) { + var task = renderer('bpmn:Task')(p, element); + + var pathDataBG = pathMap.getScaledPath('TASK_TYPE_SERVICE', { + abspos: { + x: 12, + y: 18 + } + }); + + /* service bg */ drawPath(p, pathDataBG, { + strokeWidth: 1, + fill: 'none' + }); + + var fillPathData = pathMap.getScaledPath('TASK_TYPE_SERVICE_FILL', { + abspos: { + x: 17.2, + y: 18 + } + }); + + /* service fill */ drawPath(p, fillPathData, { + strokeWidth: 0, + stroke: 'none', + fill: 'white' + }); + + var pathData = pathMap.getScaledPath('TASK_TYPE_SERVICE', { + abspos: { + x: 17, + y: 22 + } + }); + + /* service */ drawPath(p, pathData, { + strokeWidth: 1, + fill: 'white' + }); + + return task; + }, + 'bpmn:UserTask': function(p, element) { + var task = renderer('bpmn:Task')(p, element); + + var x = 15; + var y = 12; + + var pathData = pathMap.getScaledPath('TASK_TYPE_USER_1', { + abspos: { + x: x, + y: y + } + }); + + /* user path */ drawPath(p, pathData, { + strokeWidth: 0.5, + fill: 'none' + }); + + var pathData2 = pathMap.getScaledPath('TASK_TYPE_USER_2', { + abspos: { + x: x, + y: y + } + }); + + /* user2 path */ drawPath(p, pathData2, { + strokeWidth: 0.5, + fill: 'none' + }); + + var pathData3 = pathMap.getScaledPath('TASK_TYPE_USER_3', { + abspos: { + x: x, + y: y + } + }); + + /* user3 path */ drawPath(p, pathData3, { + strokeWidth: 0.5, + fill: 'black' + }); + + return task; + }, + 'bpmn:ManualTask': function(p, element) { + var task = renderer('bpmn:Task')(p, element); + + var pathData = pathMap.getScaledPath('TASK_TYPE_MANUAL', { + abspos: { + x: 17, + y: 15 + } + }); + + /* manual path */ drawPath(p, pathData, { + strokeWidth: 0.25, + fill: 'white', + stroke: 'black' + }); + + return task; + }, + 'bpmn:SendTask': function(p, element) { + var task = renderer('bpmn:Task')(p, element); + + var pathData = pathMap.getScaledPath('TASK_TYPE_SEND', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: 21, + containerHeight: 14, + position: { + mx: 0.285, + my: 0.357 + } + }); + + /* send path */ drawPath(p, pathData, { + strokeWidth: 1, + fill: 'black', + stroke: 'white' + }); + + return task; + }, + 'bpmn:ReceiveTask' : function(p, element) { + var semantic = getSemantic(element); + + var task = renderer('bpmn:Task')(p, element); + var pathData; + + if (semantic.instantiate) { + drawCircle(p, 28, 28, 20 * 0.22, { strokeWidth: 1 }); + + pathData = pathMap.getScaledPath('TASK_TYPE_INSTANTIATING_SEND', { + abspos: { + x: 7.77, + y: 9.52 + } + }); + } else { + + pathData = pathMap.getScaledPath('TASK_TYPE_SEND', { + xScaleFactor: 0.9, + yScaleFactor: 0.9, + containerWidth: 21, + containerHeight: 14, + position: { + mx: 0.3, + my: 0.4 + } + }); + } + + /* receive path */ drawPath(p, pathData, { + strokeWidth: 1 + }); + + return task; + }, + 'bpmn:ScriptTask': function(p, element) { + var task = renderer('bpmn:Task')(p, element); + + var pathData = pathMap.getScaledPath('TASK_TYPE_SCRIPT', { + abspos: { + x: 15, + y: 20 + } + }); + + /* script path */ drawPath(p, pathData, { + strokeWidth: 1 + }); + + return task; + }, + 'bpmn:BusinessRuleTask': function(p, element) { + var task = renderer('bpmn:Task')(p, element); + + var headerPathData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_HEADER', { + abspos: { + x: 8, + y: 8 + } + }); + + var businessHeaderPath = drawPath(p, headerPathData); + businessHeaderPath.attr({ + strokeWidth: 1, + fill: 'AAA' + }); + + var headerData = pathMap.getScaledPath('TASK_TYPE_BUSINESS_RULE_MAIN', { + abspos: { + x: 8, + y: 8 + } + }); + + var businessPath = drawPath(p, headerData); + businessPath.attr({ + strokeWidth: 1 + }); + + return task; + }, + 'bpmn:SubProcess': function(p, element, attrs) { + var rect = renderer('bpmn:Activity')(p, element, attrs); + + var semantic = getSemantic(element); + + var expanded = DiUtil.isExpanded(semantic); + + var isEventSubProcess = !!semantic.triggeredByEvent; + if (isEventSubProcess) { + rect.attr({ + strokeDasharray: '1,2' + }); + } + + renderEmbeddedLabel(p, element, expanded ? 'center-top' : 'center-middle'); + + if (expanded) { + attachTaskMarkers(p, element); + } else { + attachTaskMarkers(p, element, ['SubProcessMarker']); + } + + return rect; + }, + 'bpmn:AdHocSubProcess': function(p, element) { + return renderer('bpmn:SubProcess')(p, element); + }, + 'bpmn:Transaction': function(p, element) { + var outer = renderer('bpmn:SubProcess')(p, element); + + var innerAttrs = styles.style([ 'no-fill', 'no-events' ]); + + /* inner path */ drawRect(p, element.width, element.height, TASK_BORDER_RADIUS - 2, INNER_OUTER_DIST, innerAttrs); + + return outer; + }, + 'bpmn:CallActivity': function(p, element) { + return renderer('bpmn:Task')(p, element, { + strokeWidth: 5 + }); + }, + 'bpmn:Participant': function(p, element) { + + var lane = renderer('bpmn:Lane')(p, element, { + fill: 'White' + }); + + var expandedPool = DiUtil.isExpanded(element); + + if (expandedPool) { + drawLine(p, [ + { x: 30, y: 0 }, + { x: 30, y: element.height } + ]); + var text = getSemantic(element).name; + renderLaneLabel(p, text, element); + } else { + // Collapsed pool draw text inline + var text2 = getSemantic(element).name; + renderLabel(p, text2, { box: element, align: 'center-middle' }); + } + + var participantMultiplicity = !!(getSemantic(element).participantMultiplicity); + + if(participantMultiplicity) { + renderer('ParticipantMultiplicityMarker')(p, element); + } + + return lane; + }, + 'bpmn:Lane': function(p, element, attrs) { + var rect = drawRect(p, element.width, element.height, 0, attrs || { + fill: 'none' + }); + + var semantic = getSemantic(element); + + if (semantic.$type === 'bpmn:Lane') { + var text = semantic.name; + renderLaneLabel(p, text, element); + } + + return rect; + }, + 'bpmn:InclusiveGateway': function(p, element) { + var diamond = drawDiamond(p, element.width, element.height); + + /* circle path */ + drawCircle(p, element.width, element.height, element.height * 0.24, { + strokeWidth: 2.5, + fill: 'none' + }); + + return diamond; + }, + 'bpmn:ExclusiveGateway': function(p, element) { + var diamond = drawDiamond(p, element.width, element.height); + + var pathData = pathMap.getScaledPath('GATEWAY_EXCLUSIVE', { + xScaleFactor: 0.4, + yScaleFactor: 0.4, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.32, + my: 0.3 + } + }); + + if (!!(getDi(element).isMarkerVisible)) { + drawPath(p, pathData, { + strokeWidth: 1, + fill: 'black' + }); + } + + return diamond; + }, + 'bpmn:ComplexGateway': function(p, element) { + var diamond = drawDiamond(p, element.width, element.height); + + var pathData = pathMap.getScaledPath('GATEWAY_COMPLEX', { + xScaleFactor: 0.5, + yScaleFactor:0.5, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.46, + my: 0.26 + } + }); + + /* complex path */ drawPath(p, pathData, { + strokeWidth: 1, + fill: 'black' + }); + + return diamond; + }, + 'bpmn:ParallelGateway': function(p, element) { + var diamond = drawDiamond(p, element.width, element.height); + + var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', { + xScaleFactor: 0.6, + yScaleFactor:0.6, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.46, + my: 0.2 + } + }); + + /* parallel path */ drawPath(p, pathData, { + strokeWidth: 1, + fill: 'black' + }); + + return diamond; + }, + 'bpmn:EventBasedGateway': function(p, element) { + + var semantic = getSemantic(element); + + var diamond = drawDiamond(p, element.width, element.height); + + /* outer circle path */ drawCircle(p, element.width, element.height, element.height * 0.20, { + strokeWidth: 1, + fill: 'none' + }); + + var type = semantic.eventGatewayType; + var instantiate = !!semantic.instantiate; + + function drawEvent() { + + var pathData = pathMap.getScaledPath('GATEWAY_EVENT_BASED', { + xScaleFactor: 0.18, + yScaleFactor: 0.18, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.36, + my: 0.44 + } + }); + + /* event path */ drawPath(p, pathData, { + strokeWidth: 2, + fill: 'none' + }); + } + + if (type === 'Parallel') { + + var pathData = pathMap.getScaledPath('GATEWAY_PARALLEL', { + xScaleFactor: 0.4, + yScaleFactor:0.4, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.474, + my: 0.296 + } + }); + + var parallelPath = drawPath(p, pathData); + parallelPath.attr({ + strokeWidth: 1, + fill: 'none' + }); + } else if (type === 'Exclusive') { + + if (!instantiate) { + var innerCircle = drawCircle(p, element.width, element.height, element.height * 0.26); + innerCircle.attr({ + strokeWidth: 1, + fill: 'none' + }); + } + + drawEvent(); + } + + + return diamond; + }, + 'bpmn:Gateway': function(p, element) { + return drawDiamond(p, element.width, element.height); + }, + 'bpmn:SequenceFlow': function(p, element) { + var pathData = createPathFromConnection(element); + var path = drawPath(p, pathData, { + strokeLinejoin: 'round', + markerEnd: marker('sequenceflow-end') + }); + + var sequenceFlow = getSemantic(element); + var source = element.source.businessObject; + + // conditional flow marker + if (sequenceFlow.conditionExpression && source.$instanceOf('bpmn:Task')) { + path.attr({ + markerStart: marker('conditional-flow-marker') + }); + } + + // default marker + if (source.default && source.$instanceOf('bpmn:Gateway') && source.default === sequenceFlow) { + path.attr({ + markerStart: marker('conditional-default-flow-marker') + }); + } + + return path; + }, + 'bpmn:Association': function(p, element, attrs) { + + attrs = assign({ + strokeDasharray: '1,6', + strokeLinecap: 'round', + strokeLinejoin: 'round' + }, attrs || {}); + + // TODO(nre): style according to directed state + return drawLine(p, element.waypoints, attrs); + }, + 'bpmn:DataInputAssociation': function(p, element) { + return renderer('bpmn:Association')(p, element, { + markerEnd: marker('data-association-end') + }); + }, + 'bpmn:DataOutputAssociation': function(p, element) { + return renderer('bpmn:Association')(p, element, { + markerEnd: marker('data-association-end') + }); + }, + 'bpmn:MessageFlow': function(p, element) { + + var semantic = getSemantic(element), + di = getDi(element); + + var pathData = createPathFromConnection(element); + var path = drawPath(p, pathData, { + markerEnd: marker('messageflow-end'), + markerStart: marker('messageflow-start'), + strokeDasharray: '10, 12', + strokeLinecap: 'round', + strokeLinejoin: 'round', + strokeWidth: '1.5px' + }); + + if (semantic.messageRef) { + var midPoint = path.getPointAtLength(path.getTotalLength() / 2); + + var markerPathData = pathMap.getScaledPath('MESSAGE_FLOW_MARKER', { + abspos: { + x: midPoint.x, + y: midPoint.y + } + }); + + var messageAttrs = { strokeWidth: 1 }; + + if (di.messageVisibleKind === 'initiating') { + messageAttrs.fill = 'white'; + messageAttrs.stroke = 'black'; + } else { + messageAttrs.fill = '#888'; + messageAttrs.stroke = 'white'; + } + + drawPath(p, markerPathData, messageAttrs); + } + + return path; + }, + 'bpmn:DataObject': function(p, element) { + var pathData = pathMap.getScaledPath('DATA_OBJECT_PATH', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.474, + my: 0.296 + } + }); + + var elementObject = drawPath(p, pathData, { fill: 'white' }); + + var semantic = getSemantic(element); + + if (isCollection(semantic)) { + renderDataItemCollection(p, element); + } + + return elementObject; + }, + 'bpmn:DataObjectReference': as('bpmn:DataObject'), + 'bpmn:DataInput': function(p, element) { + + var arrowPathData = pathMap.getRawPath('DATA_ARROW'); + + // page + var elementObject = renderer('bpmn:DataObject')(p, element); + + /* input arrow path */ drawPath(p, arrowPathData, { strokeWidth: 1 }); + + return elementObject; + }, + 'bpmn:DataOutput': function(p, element) { + var arrowPathData = pathMap.getRawPath('DATA_ARROW'); + + // page + var elementObject = renderer('bpmn:DataObject')(p, element); + + /* output arrow path */ drawPath(p, arrowPathData, { + strokeWidth: 1, + fill: 'black' + }); + + return elementObject; + }, + 'bpmn:DataStoreReference': function(p, element) { + var DATA_STORE_PATH = pathMap.getScaledPath('DATA_STORE', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0, + my: 0.133 + } + }); + + var elementStore = drawPath(p, DATA_STORE_PATH, { + strokeWidth: 2, + fill: 'white' + }); + + return elementStore; + }, + 'bpmn:BoundaryEvent': function(p, element) { + + var semantic = getSemantic(element), + cancel = semantic.cancelActivity; + + var attrs = { + strokeLinecap: 'round', + strokeWidth: 1 + }; + + if (!cancel) { + attrs.strokeDasharray = '6'; + } + + var outer = renderer('bpmn:Event')(p, element, attrs); + /* inner path */ drawCircle(p, element.width, element.height, INNER_OUTER_DIST, attrs); + + renderEventContent(element, p); + + return outer; + }, + 'bpmn:Group': function(p, element) { + return drawRect(p, element.width, element.height, TASK_BORDER_RADIUS, { + strokeWidth: 1, + strokeDasharray: '8,3,1,3', + fill: 'none', + pointerEvents: 'none' + }); + }, + 'label': function(p, element) { + return renderExternalLabel(p, element, ''); + }, + 'bpmn:TextAnnotation': function(p, element) { + var style = { + 'fill': 'none', + 'stroke': 'none' + }; + var textElement = drawRect(p, element.width, element.height, 0, 0, style); + var textPathData = pathMap.getScaledPath('TEXT_ANNOTATION', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.0, + my: 0.0 + } + }); + drawPath(p, textPathData); + + var text = getSemantic(element).text || ''; + renderLabel(p, text, { box: element, align: 'left-middle', padding: 5 }); + + return textElement; + }, + 'ParticipantMultiplicityMarker': function(p, element) { + var subProcessPath = pathMap.getScaledPath('MARKER_PARALLEL', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: ((element.width / 2) / element.width), + my: (element.height - 15) / element.height + } + }); + + drawPath(p, subProcessPath); + }, + 'SubProcessMarker': function(p, element) { + var markerRect = drawRect(p, 14, 14, 0, { + strokeWidth: 1 + }); + + // Process marker is placed in the middle of the box + // therefore fixed values can be used here + markerRect.transform('translate(' + (element.width / 2 - 7.5) + ',' + (element.height - 20) + ')'); + + var subProcessPath = pathMap.getScaledPath('MARKER_SUB_PROCESS', { + xScaleFactor: 1.5, + yScaleFactor: 1.5, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: (element.width / 2 - 7.5) / element.width, + my: (element.height - 20) / element.height + } + }); + + drawPath(p, subProcessPath); + }, + 'ParallelMarker': function(p, element, position) { + var subProcessPath = pathMap.getScaledPath('MARKER_PARALLEL', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: ((element.width / 2 + position.parallel) / element.width), + my: (element.height - 20) / element.height + } + }); + drawPath(p, subProcessPath); + }, + 'SequentialMarker': function(p, element, position) { + var sequentialPath = pathMap.getScaledPath('MARKER_SEQUENTIAL', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: ((element.width / 2 + position.seq) / element.width), + my: (element.height - 19) / element.height + } + }); + drawPath(p, sequentialPath); + }, + 'CompensationMarker': function(p, element, position) { + var compensationPath = pathMap.getScaledPath('MARKER_COMPENSATION', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: ((element.width / 2 + position.compensation) / element.width), + my: (element.height - 13) / element.height + } + }); + drawPath(p, compensationPath, { strokeWidth: 1 }); + }, + 'LoopMarker': function(p, element, position) { + var loopPath = pathMap.getScaledPath('MARKER_LOOP', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: ((element.width / 2 + position.loop) / element.width), + my: (element.height - 7) / element.height + } + }); + + drawPath(p, loopPath, { + strokeWidth: 1, + fill: 'none', + strokeLinecap: 'round', + strokeMiterlimit: 0.5 + }); + }, + 'AdhocMarker': function(p, element, position) { + var loopPath = pathMap.getScaledPath('MARKER_ADHOC', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: ((element.width / 2 + position.adhoc) / element.width), + my: (element.height - 15) / element.height + } + }); + + drawPath(p, loopPath, { + strokeWidth: 1, + fill: 'black' + }); + } + }; + + function attachTaskMarkers(p, element, taskMarkers) { + var obj = getSemantic(element); + + var subprocess = includes(taskMarkers, 'SubProcessMarker'); + var position; + + if (subprocess) { + position = { + seq: -21, + parallel: -22, + compensation: -42, + loop: -18, + adhoc: 10 + }; + } else { + position = { + seq: -3, + parallel: -6, + compensation: -27, + loop: 0, + adhoc: 10 + }; + } + + forEach(taskMarkers, function(marker) { + renderer(marker)(p, element, position); + }); + + if (obj.$type === 'bpmn:AdHocSubProcess') { + renderer('AdhocMarker')(p, element, position); + } + if (obj.loopCharacteristics && obj.loopCharacteristics.isSequential === undefined) { + renderer('LoopMarker')(p, element, position); + return; + } + if (obj.loopCharacteristics && + obj.loopCharacteristics.isSequential !== undefined && + !obj.loopCharacteristics.isSequential) { + renderer('ParallelMarker')(p, element, position); + } + if (obj.loopCharacteristics && !!obj.loopCharacteristics.isSequential) { + renderer('SequentialMarker')(p, element, position); + } + if (!!obj.isForCompensation) { + renderer('CompensationMarker')(p, element, position); + } + } + + function drawShape(parent, element) { + var type = element.type; + var h = handlers[type]; + + /* jshint -W040 */ + if (!h) { + return DefaultRenderer.prototype.drawShape.apply(this, [ parent, element ]); + } else { + return h(parent, element); + } + } + + function drawConnection(parent, element) { + var type = element.type; + var h = handlers[type]; + + /* jshint -W040 */ + if (!h) { + return DefaultRenderer.prototype.drawConnection.apply(this, [ parent, element ]); + } else { + return h(parent, element); + } + } + + function renderDataItemCollection(p, element) { + + var yPosition = (element.height - 16) / element.height; + + var pathData = pathMap.getScaledPath('DATA_OBJECT_COLLECTION_PATH', { + xScaleFactor: 1, + yScaleFactor: 1, + containerWidth: element.width, + containerHeight: element.height, + position: { + mx: 0.451, + my: yPosition + } + }); + + /* collection path */ drawPath(p, pathData, { + strokeWidth: 2 + }); + } + + function isCollection(element, filter) { + return element.isCollection || + (element.elementObjectRef && element.elementObjectRef.isCollection); + } + + function getDi(element) { + return element.businessObject.di; + } + + function getSemantic(element) { + return element.businessObject; + } + + /** + * Checks if eventDefinition of the given element matches with semantic type. + * + * @return {boolean} true if element is of the given semantic type + */ + function isTypedEvent(event, eventDefinitionType, filter) { + + function matches(definition, filter) { + return every(filter, function(val, key) { + + // we want a == conversion here, to be able to catch + // undefined == false and friends + /* jshint -W116 */ + return definition[key] == val; + }); + } + + return some(event.eventDefinitions, function(definition) { + return definition.$type === eventDefinitionType && matches(event, filter); + }); + } + + function isThrowEvent(event) { + return (event.$type === 'bpmn:IntermediateThrowEvent') || (event.$type === 'bpmn:EndEvent'); + } + + + /////// cropping path customizations ///////////////////////// + + function componentsToPath(elements) { + return elements.join(',').replace(/,?([A-z]),?/g, '$1'); + } + + function getCirclePath(shape) { + + var cx = shape.x + shape.width / 2, + cy = shape.y + shape.height / 2, + radius = shape.width / 2; + + var circlePath = [ + ['M', cx, cy], + ['m', 0, -radius], + ['a', radius, radius, 0, 1, 1, 0, 2 * radius], + ['a', radius, radius, 0, 1, 1, 0, -2 * radius], + ['z'] + ]; + + return componentsToPath(circlePath); + } + + function getRoundRectPath(shape) { + + var radius = TASK_BORDER_RADIUS, + x = shape.x, + y = shape.y, + width = shape.width, + height = shape.height; + + var roundRectPath = [ + ['M', x + radius, y], + ['l', width - radius * 2, 0], + ['a', radius, radius, 0, 0, 1, radius, radius], + ['l', 0, height - radius * 2], + ['a', radius, radius, 0, 0, 1, -radius, radius], + ['l', radius * 2 - width, 0], + ['a', radius, radius, 0, 0, 1, -radius, -radius], + ['l', 0, radius * 2 - height], + ['a', radius, radius, 0, 0, 1, radius, -radius], + ['z'] + ]; + + return componentsToPath(roundRectPath); + } + + function getDiamondPath(shape) { + + var width = shape.width, + height = shape.height, + x = shape.x, + y = shape.y, + halfWidth = width / 2, + halfHeight = height / 2; + + var diamondPath = [ + ['M', x + halfWidth, y], + ['l', halfWidth, halfHeight], + ['l', -halfWidth, halfHeight], + ['l', -halfWidth, -halfHeight], + ['z'] + ]; + + return componentsToPath(diamondPath); + } + + function getRectPath(shape) { + var x = shape.x, + y = shape.y, + width = shape.width, + height = shape.height; + + var rectPath = [ + ['M', x, y], + ['l', width, 0], + ['l', 0, height], + ['l', -width, 0], + ['z'] + ]; + + return componentsToPath(rectPath); + } + + function getShapePath(element) { + var obj = getSemantic(element); + + if (obj.$instanceOf('bpmn:Event')) { + return getCirclePath(element); + } + + if (obj.$instanceOf('bpmn:Activity')) { + return getRoundRectPath(element); + } + + if (obj.$instanceOf('bpmn:Gateway')) { + return getDiamondPath(element); + } + + return getRectPath(element); + } + + + // hook onto canvas init event to initialize + // connection start/end markers on svg + events.on('canvas.init', function(event) { + initMarkers(event.svg); + }); + + this.drawShape = drawShape; + this.drawConnection = drawConnection; + + this.getShapePath = getShapePath; +} + +inherits(BpmnRenderer, DefaultRenderer); + + +BpmnRenderer.$inject = [ 'eventBus', 'styles', 'pathMap' ]; + +module.exports = BpmnRenderer; + +},{"12":12,"166":166,"170":170,"175":175,"44":44,"71":71,"79":79,"81":81,"84":84,"86":86,"89":89}],5:[function(_dereq_,module,exports){ +'use strict'; + +var Snap = _dereq_(74); + +/** + * Map containing SVG paths needed by BpmnRenderer. + */ + +function PathMap() { + + /** + * Contains a map of path elements + * + * <h1>Path definition</h1> + * A parameterized path is defined like this: + * <pre> + * 'GATEWAY_PARALLEL': { + * d: 'm {mx},{my} {e.x0},0 0,{e.x1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' + + '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z', + * height: 17.5, + * width: 17.5, + * heightElements: [2.5, 7.5], + * widthElements: [2.5, 7.5] + * } + * </pre> + * <p>It's important to specify a correct <b>height and width</b> for the path as the scaling + * is based on the ratio between the specified height and width in this object and the + * height and width that is set as scale target (Note x,y coordinates will be scaled with + * individual ratios).</p> + * <p>The '<b>heightElements</b>' and '<b>widthElements</b>' array must contain the values that will be scaled. + * The scaling is based on the computed ratios. + * Coordinates on the y axis should be in the <b>heightElement</b>'s array, they will be scaled using + * the computed ratio coefficient. + * In the parameterized path the scaled values can be accessed through the 'e' object in {} brackets. + * <ul> + * <li>The values for the y axis can be accessed in the path string using {e.y0}, {e.y1}, ....</li> + * <li>The values for the x axis can be accessed in the path string using {e.x0}, {e.x1}, ....</li> + * </ul> + * The numbers x0, x1 respectively y0, y1, ... map to the corresponding array index. + * </p> + */ + this.pathMap = { + 'EVENT_MESSAGE': { + d: 'm {mx},{my} l 0,{e.y1} l {e.x1},0 l 0,-{e.y1} z l {e.x0},{e.y0} l {e.x0},-{e.y0}', + height: 36, + width: 36, + heightElements: [6, 14], + widthElements: [10.5, 21] + }, + 'EVENT_SIGNAL': { + d: 'M {mx},{my} l {e.x0},{e.y0} l -{e.x1},0 Z', + height: 36, + width: 36, + heightElements: [18], + widthElements: [10, 20] + }, + 'EVENT_ESCALATION': { + d: 'm {mx},{my} c -{e.x1},{e.y0} -{e.x3},{e.y1} -{e.x5},{e.y4} {e.x1},-{e.y3} {e.x3},-{e.y5} {e.x5},-{e.y6} ' + + '{e.x0},{e.y3} {e.x2},{e.y5} {e.x4},{e.y6} -{e.x0},-{e.y0} -{e.x2},-{e.y1} -{e.x4},-{e.y4} z', + height: 36, + width: 36, + heightElements: [2.382, 4.764, 4.926, 6.589333, 7.146, 13.178667, 19.768], + widthElements: [2.463, 2.808, 4.926, 5.616, 7.389, 8.424] + }, + 'EVENT_CONDITIONAL': { + d: 'M {e.x0},{e.y0} l {e.x1},0 l 0,{e.y2} l -{e.x1},0 Z ' + + 'M {e.x2},{e.y3} l {e.x0},0 ' + + 'M {e.x2},{e.y4} l {e.x0},0 ' + + 'M {e.x2},{e.y5} l {e.x0},0 ' + + 'M {e.x2},{e.y6} l {e.x0},0 ' + + 'M {e.x2},{e.y7} l {e.x0},0 ' + + 'M {e.x2},{e.y8} l {e.x0},0 ', + height: 36, + width: 36, + heightElements: [8.5, 14.5, 18, 11.5, 14.5, 17.5, 20.5, 23.5, 26.5], + widthElements: [10.5, 14.5, 12.5] + }, + 'EVENT_LINK': { + d: 'm {mx},{my} 0,{e.y0} -{e.x1},0 0,{e.y1} {e.x1},0 0,{e.y0} {e.x0},-{e.y2} -{e.x0},-{e.y2} z', + height: 36, + width: 36, + heightElements: [4.4375, 6.75, 7.8125], + widthElements: [9.84375, 13.5] + }, + 'EVENT_ERROR': { + d: 'm {mx},{my} {e.x0},-{e.y0} {e.x1},-{e.y1} {e.x2},{e.y2} {e.x3},-{e.y3} -{e.x4},{e.y4} -{e.x5},-{e.y5} z', + height: 36, + width: 36, + heightElements: [0.023, 8.737, 8.151, 16.564, 10.591, 8.714], + widthElements: [0.085, 6.672, 6.97, 4.273, 5.337, 6.636] + }, + 'EVENT_CANCEL_45': { + d: 'm {mx},{my} -{e.x1},0 0,{e.x0} {e.x1},0 0,{e.y1} {e.x0},0 ' + + '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z', + height: 36, + width: 36, + heightElements: [4.75, 8.5], + widthElements: [4.75, 8.5] + }, + 'EVENT_COMPENSATION': { + d: 'm {mx},{my} {e.x0},-{e.y0} 0,{e.y1} z m {e.x0},0 {e.x0},-{e.y0} 0,{e.y1} z', + height: 36, + width: 36, + heightElements: [5, 10], + widthElements: [10] + }, + 'EVENT_TIMER_WH': { + d: 'M {mx},{my} l {e.x0},-{e.y0} m -{e.x0},{e.y0} l {e.x1},{e.y1} ', + height: 36, + width: 36, + heightElements: [10, 2], + widthElements: [3, 7] + }, + 'EVENT_TIMER_LINE': { + d: 'M {mx},{my} ' + + 'm {e.x0},{e.y0} l -{e.x1},{e.y1} ', + height: 36, + width: 36, + heightElements: [10, 3], + widthElements: [0, 0] + }, + 'EVENT_MULTIPLE': { + d:'m {mx},{my} {e.x1},-{e.y0} {e.x1},{e.y0} -{e.x0},{e.y1} -{e.x2},0 z', + height: 36, + width: 36, + heightElements: [6.28099, 12.56199], + widthElements: [3.1405, 9.42149, 12.56198] + }, + 'EVENT_PARALLEL_MULTIPLE': { + d:'m {mx},{my} {e.x0},0 0,{e.y1} {e.x1},0 0,{e.y0} -{e.x1},0 0,{e.y1} ' + + '-{e.x0},0 0,-{e.y1} -{e.x1},0 0,-{e.y0} {e.x1},0 z', + height: 36, + width: 36, + heightElements: [2.56228, 7.68683], + widthElements: [2.56228, 7.68683] + }, + 'GATEWAY_EXCLUSIVE': { + d:'m {mx},{my} {e.x0},{e.y0} {e.x1},{e.y0} {e.x2},0 {e.x4},{e.y2} ' + + '{e.x4},{e.y1} {e.x2},0 {e.x1},{e.y3} {e.x0},{e.y3} ' + + '{e.x3},0 {e.x5},{e.y1} {e.x5},{e.y2} {e.x3},0 z', + height: 17.5, + width: 17.5, + heightElements: [8.5, 6.5312, -6.5312, -8.5], + widthElements: [6.5, -6.5, 3, -3, 5, -5] + }, + 'GATEWAY_PARALLEL': { + d:'m {mx},{my} 0,{e.y1} -{e.x1},0 0,{e.y0} {e.x1},0 0,{e.y1} {e.x0},0 ' + + '0,-{e.y1} {e.x1},0 0,-{e.y0} -{e.x1},0 0,-{e.y1} -{e.x0},0 z', + height: 30, + width: 30, + heightElements: [5, 12.5], + widthElements: [5, 12.5] + }, + 'GATEWAY_EVENT_BASED': { + d:'m {mx},{my} {e.x0},{e.y0} {e.x0},{e.y1} {e.x1},{e.y2} {e.x2},0 z', + height: 11, + width: 11, + heightElements: [-6, 6, 12, -12], + widthElements: [9, -3, -12] + }, + 'GATEWAY_COMPLEX': { + d:'m {mx},{my} 0,{e.y0} -{e.x0},-{e.y1} -{e.x1},{e.y2} {e.x0},{e.y1} -{e.x2},0 0,{e.y3} ' + + '{e.x2},0 -{e.x0},{e.y1} l {e.x1},{e.y2} {e.x0},-{e.y1} 0,{e.y0} {e.x3},0 0,-{e.y0} {e.x0},{e.y1} ' + + '{e.x1},-{e.y2} -{e.x0},-{e.y1} {e.x2},0 0,-{e.y3} -{e.x2},0 {e.x0},-{e.y1} -{e.x1},-{e.y2} ' + + '-{e.x0},{e.y1} 0,-{e.y0} -{e.x3},0 z', + height: 17.125, + width: 17.125, + heightElements: [4.875, 3.4375, 2.125, 3], + widthElements: [3.4375, 2.125, 4.875, 3] + }, + 'DATA_OBJECT_PATH': { + d:'m 0,0 {e.x1},0 {e.x0},{e.y0} 0,{e.y1} -{e.x2},0 0,-{e.y2} {e.x1},0 0,{e.y0} {e.x0},0', + height: 61, + width: 51, + heightElements: [10, 50, 60], + widthElements: [10, 40, 50, 60] + }, + 'DATA_OBJECT_COLLECTION_PATH': { + d:'m {mx}, {my} ' + + 'm 0 15 l 0 -15 ' + + 'm 4 15 l 0 -15 ' + + 'm 4 15 l 0 -15 ', + height: 61, + width: 51, + heightElements: [12], + widthElements: [1, 6, 12, 15] + }, + 'DATA_ARROW': { + d:'m 5,9 9,0 0,-3 5,5 -5,5 0,-3 -9,0 z', + height: 61, + width: 51, + heightElements: [], + widthElements: [] + }, + 'DATA_STORE': { + d:'m {mx},{my} ' + + 'l 0,{e.y2} ' + + 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' + + 'l 0,-{e.y2} ' + + 'c -{e.x0},-{e.y1} -{e.x1},-{e.y1} -{e.x2},0' + + 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0 ' + + 'm -{e.x2},{e.y0}' + + 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0' + + 'm -{e.x2},{e.y0}' + + 'c {e.x0},{e.y1} {e.x1},{e.y1} {e.x2},0', + height: 61, + width: 61, + heightElements: [7, 10, 45], + widthElements: [2, 58, 60] + }, + 'TEXT_ANNOTATION': { + d: 'm {mx}, {my} m 10,0 l -10,0 l 0,{e.y0} l 10,0', + height: 30, + width: 10, + heightElements: [30], + widthElements: [10] + }, + 'MARKER_SUB_PROCESS': { + d: 'm{mx},{my} m 7,2 l 0,10 m -5,-5 l 10,0', + height: 10, + width: 10, + heightElements: [], + widthElements: [] + }, + 'MARKER_PARALLEL': { + d: 'm{mx},{my} m 3,2 l 0,10 m 3,-10 l 0,10 m 3,-10 l 0,10', + height: 10, + width: 10, + heightElements: [], + widthElements: [] + }, + 'MARKER_SEQUENTIAL': { + d: 'm{mx},{my} m 0,3 l 10,0 m -10,3 l 10,0 m -10,3 l 10,0', + height: 10, + width: 10, + heightElements: [], + widthElements: [] + }, + 'MARKER_COMPENSATION': { + d: 'm {mx},{my} 8,-5 0,10 z m 9,0 8,-5 0,10 z', + height: 10, + width: 21, + heightElements: [], + widthElements: [] + }, + 'MARKER_LOOP': { + d: 'm {mx},{my} c 3.526979,0 6.386161,-2.829858 6.386161,-6.320661 0,-3.490806 -2.859182,-6.320661 ' + + '-6.386161,-6.320661 -3.526978,0 -6.38616,2.829855 -6.38616,6.320661 0,1.745402 ' + + '0.714797,3.325567 1.870463,4.469381 0.577834,0.571908 1.265885,1.034728 2.029916,1.35457 ' + + 'l -0.718163,-3.909793 m 0.718163,3.909793 -3.885211,0.802902', + height: 13.9, + width: 13.7, + heightElements: [], + widthElements: [] + }, + 'MARKER_ADHOC': { + d: 'm {mx},{my} m 0.84461,2.64411 c 1.05533,-1.23780996 2.64337,-2.07882 4.29653,-1.97997996 2.05163,0.0805 ' + + '3.85579,1.15803 5.76082,1.79107 1.06385,0.34139996 2.24454,0.1438 3.18759,-0.43767 0.61743,-0.33642 ' + + '1.2775,-0.64078 1.7542,-1.17511 0,0.56023 0,1.12046 0,1.6807 -0.98706,0.96237996 -2.29792,1.62393996 ' + + '-3.6918,1.66181996 -1.24459,0.0927 -2.46671,-0.2491 -3.59505,-0.74812 -1.35789,-0.55965 ' + + '-2.75133,-1.33436996 -4.27027,-1.18121996 -1.37741,0.14601 -2.41842,1.13685996 -3.44288,1.96782996 z', + height: 4, + width: 15, + heightElements: [], + widthElements: [] + }, + 'TASK_TYPE_SEND': { + d: 'm {mx},{my} l 0,{e.y1} l {e.x1},0 l 0,-{e.y1} z l {e.x0},{e.y0} l {e.x0},-{e.y0}', + height: 14, + width: 21, + heightElements: [6, 14], + widthElements: [10.5, 21] + }, + 'TASK_TYPE_SCRIPT': { + d: 'm {mx},{my} c 9.966553,-6.27276 -8.000926,-7.91932 2.968968,-14.938 l -8.802728,0 ' + + 'c -10.969894,7.01868 6.997585,8.66524 -2.968967,14.938 z ' + + 'm -7,-12 l 5,0 ' + + 'm -4.5,3 l 4.5,0 ' + + 'm -3,3 l 5,0' + + 'm -4,3 l 5,0', + height: 15, + width: 12.6, + heightElements: [6, 14], + widthElements: [10.5, 21] + }, + 'TASK_TYPE_USER_1': { + d: 'm {mx},{my} c 0.909,-0.845 1.594,-2.049 1.594,-3.385 0,-2.554 -1.805,-4.62199999 ' + + '-4.357,-4.62199999 -2.55199998,0 -4.28799998,2.06799999 -4.28799998,4.62199999 0,1.348 ' + + '0.974,2.562 1.89599998,3.405 -0.52899998,0.187 -5.669,2.097 -5.794,4.7560005 v 6.718 ' + + 'h 17 v -6.718 c 0,-2.2980005 -5.5279996,-4.5950005 -6.0509996,-4.7760005 z' + + 'm -8,6 l 0,5.5 m 11,0 l 0,-5' + }, + 'TASK_TYPE_USER_2': { + d: 'm {mx},{my} m 2.162,1.009 c 0,2.4470005 -2.158,4.4310005 -4.821,4.4310005 ' + + '-2.66499998,0 -4.822,-1.981 -4.822,-4.4310005 ' + }, + 'TASK_TYPE_USER_3': { + d: 'm {mx},{my} m -6.9,-3.80 c 0,0 2.25099998,-2.358 4.27399998,-1.177 2.024,1.181 4.221,1.537 ' + + '4.124,0.965 -0.098,-0.57 -0.117,-3.79099999 -4.191,-4.13599999 -3.57499998,0.001 ' + + '-4.20799998,3.36699999 -4.20699998,4.34799999 z' + }, + 'TASK_TYPE_MANUAL': { + d: 'm {mx},{my} c 0.234,-0.01 5.604,0.008 8.029,0.004 0.808,0 1.271,-0.172 1.417,-0.752 0.227,-0.898 ' + + '-0.334,-1.314 -1.338,-1.316 -2.467,-0.01 -7.886,-0.004 -8.108,-0.004 -0.014,-0.079 0.016,-0.533 0,-0.61 ' + + '0.195,-0.042 8.507,0.006 9.616,0.002 0.877,-0.007 1.35,-0.438 1.353,-1.208 0.003,-0.768 -0.479,-1.09 ' + + '-1.35,-1.091 -2.968,-0.002 -9.619,-0.013 -9.619,-0.013 v -0.591 c 0,0 5.052,-0.016 7.225,-0.016 ' + + '0.888,-0.002 1.354,-0.416 1.351,-1.193 -0.006,-0.761 -0.492,-1.196 -1.361,-1.196 -3.473,-0.005 ' + + '-10.86,-0.003 -11.0829995,-0.003 -0.022,-0.047 -0.045,-0.094 -0.069,-0.139 0.3939995,-0.319 ' + + '2.0409995,-1.626 2.4149995,-2.017 0.469,-0.4870005 0.519,-1.1650005 0.162,-1.6040005 -0.414,-0.511 ' + + '-0.973,-0.5 -1.48,-0.236 -1.4609995,0.764 -6.5999995,3.6430005 -7.7329995,4.2710005 -0.9,0.499 ' + + '-1.516,1.253 -1.882,2.19 -0.37000002,0.95 -0.17,2.01 -0.166,2.979 0.004,0.718 -0.27300002,1.345 ' + + '-0.055,2.063 0.629,2.087 2.425,3.312 4.859,3.318 4.6179995,0.014 9.2379995,-0.139 13.8569995,-0.158 ' + + '0.755,-0.004 1.171,-0.301 1.182,-1.033 0.012,-0.754 -0.423,-0.969 -1.183,-0.973 -1.778,-0.01 ' + + '-5.824,-0.004 -6.04,-0.004 10e-4,-0.084 0.003,-0.586 10e-4,-0.67 z' + }, + 'TASK_TYPE_INSTANTIATING_SEND': { + d: 'm {mx},{my} l 0,8.4 l 12.6,0 l 0,-8.4 z l 6.3,3.6 l 6.3,-3.6' + }, + 'TASK_TYPE_SERVICE': { + d: 'm {mx},{my} v -1.71335 c 0.352326,-0.0705 0.703932,-0.17838 1.047628,-0.32133 ' + + '0.344416,-0.14465 0.665822,-0.32133 0.966377,-0.52145 l 1.19431,1.18005 1.567487,-1.57688 ' + + '-1.195028,-1.18014 c 0.403376,-0.61394 0.683079,-1.29908 0.825447,-2.01824 l 1.622133,-0.01 ' + + 'v -2.2196 l -1.636514,0.01 c -0.07333,-0.35153 -0.178319,-0.70024 -0.323564,-1.04372 ' + + '-0.145244,-0.34406 -0.321407,-0.6644 -0.522735,-0.96217 l 1.131035,-1.13631 -1.583305,-1.56293 ' + + '-1.129598,1.13589 c -0.614052,-0.40108 -1.302883,-0.68093 -2.022633,-0.82247 l 0.0093,-1.61852 ' + + 'h -2.241173 l 0.0042,1.63124 c -0.353763,0.0736 -0.705369,0.17977 -1.049785,0.32371 -0.344415,0.14437 ' + + '-0.665102,0.32092 -0.9635006,0.52046 l -1.1698628,-1.15823 -1.5667691,1.5792 1.1684265,1.15669 ' + + 'c -0.4026573,0.61283 -0.68308,1.29797 -0.8247287,2.01713 l -1.6588041,0.003 v 2.22174 ' + + 'l 1.6724648,-0.006 c 0.073327,0.35077 0.1797598,0.70243 0.3242851,1.04472 0.1452428,0.34448 ' + + '0.3214064,0.6644 0.5227339,0.96066 l -1.1993431,1.19723 1.5840256,1.56011 1.1964668,-1.19348 ' + + 'c 0.6140517,0.40346 1.3028827,0.68232 2.0233517,0.82331 l 7.19e-4,1.69892 h 2.226848 z ' + + 'm 0.221462,-3.9957 c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' + + '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' + + '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z' + }, + 'TASK_TYPE_SERVICE_FILL': { + d: 'm {mx},{my} c -1.788948,0.7502 -3.8576,-0.0928 -4.6097055,-1.87438 -0.7521065,-1.78321 ' + + '0.090598,-3.84627 1.8802645,-4.59604 1.78823,-0.74936 3.856881,0.0929 4.608987,1.87437 ' + + '0.752106,1.78165 -0.0906,3.84612 -1.879546,4.59605 z' + }, + 'TASK_TYPE_BUSINESS_RULE_HEADER': { + d: 'm {mx},{my} 0,4 20,0 0,-4 z' + }, + 'TASK_TYPE_BUSINESS_RULE_MAIN': { + d: 'm {mx},{my} 0,12 20,0 0,-12 z' + + 'm 0,8 l 20,0 ' + + 'm -13,-4 l 0,8' + }, + 'MESSAGE_FLOW_MARKER': { + d: 'm {mx},{my} m -10.5 ,-7 l 0,14 l 21,0 l 0,-14 z l 10.5,6 l 10.5,-6' + } + }; + + this.getRawPath = function getRawPath(pathId) { + return this.pathMap[pathId].d; + }; + + /** + * Scales the path to the given height and width. + * <h1>Use case</h1> + * <p>Use case is to scale the content of elements (event, gateways) based + * on the element bounding box's size. + * </p> + * <h1>Why not transform</h1> + * <p>Scaling a path with transform() will also scale the stroke and IE does not support + * the option 'non-scaling-stroke' to prevent this. + * Also there are use cases where only some parts of a path should be + * scaled.</p> + * + * @param {String} pathId The ID of the path. + * @param {Object} param <p> + * Example param object scales the path to 60% size of the container (data.width, data.height). + * <pre> + * { + * xScaleFactor: 0.6, + * yScaleFactor:0.6, + * containerWidth: data.width, + * containerHeight: data.height, + * position: { + * mx: 0.46, + * my: 0.2, + * } + * } + * </pre> + * <ul> + * <li>targetpathwidth = xScaleFactor * containerWidth</li> + * <li>targetpathheight = yScaleFactor * containerHeight</li> + * <li>Position is used to set the starting coordinate of the path. M is computed: + * <ul> + * <li>position.x * containerWidth</li> + * <li>position.y * containerHeight</li> + * </ul> + * Center of the container <pre> position: { + * mx: 0.5, + * my: 0.5, + * }</pre> + * Upper left corner of the container + * <pre> position: { + * mx: 0.0, + * my: 0.0, + * }</pre> + * </li> + * </ul> + * </p> + * + */ + this.getScaledPath = function getScaledPath(pathId, param) { + var rawPath = this.pathMap[pathId]; + + // positioning + // compute the start point of the path + var mx, my; + + if(!!param.abspos) { + mx = param.abspos.x; + my = param.abspos.y; + } else { + mx = param.containerWidth * param.position.mx; + my = param.containerHeight * param.position.my; + } + + var coordinates = {}; //map for the scaled coordinates + if(param.position) { + + // path + var heightRatio = (param.containerHeight / rawPath.height) * param.yScaleFactor; + var widthRatio = (param.containerWidth / rawPath.width) * param.xScaleFactor; + + + //Apply height ratio + for (var heightIndex = 0; heightIndex < rawPath.heightElements.length; heightIndex++) { + coordinates['y' + heightIndex] = rawPath.heightElements[heightIndex] * heightRatio; + } + + //Apply width ratio + for (var widthIndex = 0; widthIndex < rawPath.widthElements.length; widthIndex++) { + coordinates['x' + widthIndex] = rawPath.widthElements[widthIndex] * widthRatio; + } + } + + //Apply value to raw path + var path = Snap.format( + rawPath.d, { + mx: mx, + my: my, + e: coordinates + } + ); + return path; + }; +} + +module.exports = PathMap; + +},{"74":74}],6:[function(_dereq_,module,exports){ +module.exports = { + renderer: [ 'type', _dereq_(4) ], + pathMap: [ 'type', _dereq_(5) ] +}; +},{"4":4,"5":5}],7:[function(_dereq_,module,exports){ +'use strict'; + +var assign = _dereq_(175), + map = _dereq_(87); + +var LabelUtil = _dereq_(13); + +var hasExternalLabel = LabelUtil.hasExternalLabel, + getExternalLabelBounds = LabelUtil.getExternalLabelBounds, + isExpanded = _dereq_(12).isExpanded, + elementToString = _dereq_(10).elementToString; + + +function elementData(semantic, attrs) { + return assign({ + id: semantic.id, + type: semantic.$type, + businessObject: semantic + }, attrs); +} + +function collectWaypoints(waypoints) { + return map(waypoints, function(p) { + return { x: p.x, y: p.y }; + }); +} + + +/** + * An importer that adds bpmn elements to the canvas + * + * @param {EventBus} eventBus + * @param {Canvas} canvas + * @param {ElementFactory} elementFactory + * @param {ElementRegistry} elementRegistry + */ +function BpmnImporter(eventBus, canvas, elementFactory, elementRegistry) { + this._eventBus = eventBus; + this._canvas = canvas; + + this._elementFactory = elementFactory; + this._elementRegistry = elementRegistry; +} + +BpmnImporter.$inject = [ 'eventBus', 'canvas', 'elementFactory', 'elementRegistry' ]; + +module.exports = BpmnImporter; + + +/** + * Add bpmn element (semantic) to the canvas onto the + * specified parent shape. + */ +BpmnImporter.prototype.add = function(semantic, parentElement) { + + var di = semantic.di, + element; + + // ROOT ELEMENT + // handle the special case that we deal with a + // invisible root element (process or collaboration) + if (di.$instanceOf('bpmndi:BPMNPlane')) { + + // add a virtual element (not being drawn) + element = this._elementFactory.createRoot(elementData(semantic)); + + this._canvas.setRootElement(element); + } + + // SHAPE + else if (di.$instanceOf('bpmndi:BPMNShape')) { + + var collapsed = !isExpanded(semantic); + var hidden = parentElement && (parentElement.hidden || parentElement.collapsed); + + var bounds = semantic.di.bounds; + + element = this._elementFactory.createShape(elementData(semantic, { + collapsed: collapsed, + hidden: hidden, + x: Math.round(bounds.x), + y: Math.round(bounds.y), + width: Math.round(bounds.width), + height: Math.round(bounds.height) + })); + + this._canvas.addShape(element, parentElement); + } + + // CONNECTION + else if (di.$instanceOf('bpmndi:BPMNEdge')) { + + var source = this._getSource(semantic), + target = this._getTarget(semantic); + + element = this._elementFactory.createConnection(elementData(semantic, { + source: source, + target: target, + waypoints: collectWaypoints(semantic.di.waypoint) + })); + + this._canvas.addConnection(element, parentElement); + } else { + throw new Error('unknown di ' + elementToString(di) + ' for element ' + elementToString(semantic)); + } + + // (optional) LABEL + if (hasExternalLabel(semantic)) { + this.addLabel(semantic, element); + } + + + this._eventBus.fire('bpmnElement.added', { element: element }); + + return element; +}; + + +/** + * add label for an element + */ +BpmnImporter.prototype.addLabel = function(semantic, element) { + var bounds = getExternalLabelBounds(semantic, element); + + var label = this._elementFactory.createLabel(elementData(semantic, { + id: semantic.id + '_label', + labelTarget: element, + type: 'label', + hidden: element.hidden, + x: Math.round(bounds.x), + y: Math.round(bounds.y), + width: Math.round(bounds.width), + height: Math.round(bounds.height) + })); + + return this._canvas.addShape(label, element.parent); +}; + +/** + * Return the drawn connection end based on the given side. + * + * @throws {Error} if the end is not yet drawn + */ +BpmnImporter.prototype._getEnd = function(semantic, side) { + + var element, + refSemantic, + type = semantic.$type; + + refSemantic = semantic[side + 'Ref']; + + // handle mysterious isMany DataAssociation#sourceRef + if (side === 'source' && type === 'bpmn:DataInputAssociation') { + refSemantic = refSemantic && refSemantic[0]; + } + + // fix source / target for DataInputAssociation / DataOutputAssociation + if (side === 'source' && type === 'bpmn:DataOutputAssociation' || + side === 'target' && type === 'bpmn:DataInputAssociation') { + + refSemantic = semantic.$parent; + } + + element = refSemantic && this._getElement(refSemantic); + + if (element) { + return element; + } + + if (refSemantic) { + throw new Error( + 'element ' + elementToString(refSemantic) + ' referenced by ' + + elementToString(semantic) + '#' + side + 'Ref not yet drawn'); + } else { + throw new Error(elementToString(semantic) + '#' + side + 'Ref not specified'); + } +}; + +BpmnImporter.prototype._getSource = function(semantic) { + return this._getEnd(semantic, 'source'); +}; + +BpmnImporter.prototype._getTarget = function(semantic) { + return this._getEnd(semantic, 'target'); +}; + + +BpmnImporter.prototype._getElement = function(semantic) { + return this._elementRegistry.get(semantic.id); +}; + +},{"10":10,"12":12,"13":13,"175":175,"87":87}],8:[function(_dereq_,module,exports){ +'use strict'; + +var filter = _dereq_(82), + find = _dereq_(83), + forEach = _dereq_(84); + +var Refs = _dereq_(202); + +var elementToString = _dereq_(10).elementToString; + +var diRefs = new Refs({ name: 'bpmnElement', enumerable: true }, { name: 'di' }); + +/** + * Returns true if an element has the given meta-model type + * + * @param {ModdleElement} element + * @param {String} type + * + * @return {Boolean} + */ +function is(element, type) { + return element.$instanceOf(type); +} + + +/** + * Find a suitable display candidate for definitions where the DI does not + * correctly specify one. + */ +function findDisplayCandidate(definitions) { + return find(definitions.rootElements, function(e) { + return is(e, 'bpmn:Process') || is(e, 'bpmn:Collaboration'); + }); +} + + +function BpmnTreeWalker(handler) { + + // list of containers already walked + var handledProcesses = []; + + // list of elements to handle deferred to ensure + // prerequisites are drawn + var deferred = []; + + ///// Helpers ///////////////////////////////// + + function contextual(fn, ctx) { + return function(e) { + fn(e, ctx); + }; + } + + function visit(element, ctx) { + + var gfx = element.gfx; + + // avoid multiple rendering of elements + if (gfx) { + throw new Error('already rendered ' + elementToString(element)); + } + + // call handler + return handler.element(element, ctx); + } + + function visitRoot(element, diagram) { + return handler.root(element, diagram); + } + + function visitIfDi(element, ctx) { + try { + return element.di && visit(element, ctx); + } catch (e) { + logError(e.message, { element: element, error: e }); + + console.error('failed to import ' + elementToString(element)); + console.error(e); + } + } + + function logError(message, context) { + handler.error(message, context); + } + + ////// DI handling //////////////////////////// + + function registerDi(di) { + var bpmnElement = di.bpmnElement; + + if (bpmnElement) { + if (bpmnElement.di) { + logError('multiple DI elements defined for ' + elementToString(bpmnElement), { element: bpmnElement }); + } else { + diRefs.bind(bpmnElement, 'di'); + bpmnElement.di = di; + } + } else { + logError('no bpmnElement referenced in ' + elementToString(di), { element: di }); + } + } + + function handleDiagram(diagram) { + handlePlane(diagram.plane); + } + + function handlePlane(plane) { + registerDi(plane); + + forEach(plane.planeElement, handlePlaneElement); + } + + function handlePlaneElement(planeElement) { + registerDi(planeElement); + } + + + ////// Semantic handling ////////////////////// + + function handleDefinitions(definitions, diagram) { + // make sure we walk the correct bpmnElement + + var diagrams = definitions.diagrams; + + if (diagram && diagrams.indexOf(diagram) === -1) { + throw new Error('diagram not part of bpmn:Definitions'); + } + + if (!diagram && diagrams && diagrams.length) { + diagram = diagrams[0]; + } + + // no diagram -> nothing to import + if (!diagram) { + return; + } + + // load DI from selected diagram only + handleDiagram(diagram); + + + var plane = diagram.plane; + + if (!plane) { + throw new Error('no plane for ' + elementToString(diagram)); + } + + + var rootElement = plane.bpmnElement; + + // ensure we default to a suitable display candidate (process or collaboration), + // even if non is specified in DI + if (!rootElement) { + rootElement = findDisplayCandidate(definitions); + + if (!rootElement) { + return logError('no process or collaboration present to display'); + } else { + + logError('correcting missing bpmnElement on ' + elementToString(plane) + ' to ' + elementToString(rootElement)); + + // correct DI on the fly + plane.bpmnElement = rootElement; + registerDi(plane); + } + } + + + var ctx = visitRoot(rootElement, plane); + + if (is(rootElement, 'bpmn:Process')) { + handleProcess(rootElement, ctx); + } else if (is(rootElement, 'bpmn:Collaboration')) { + handleCollaboration(rootElement, ctx); + + // force drawing of everything not yet drawn that is part of the target DI + handleUnhandledProcesses(definitions.rootElements, ctx); + } else { + throw new Error('unsupported bpmnElement for ' + elementToString(plane) + ' : ' + elementToString(rootElement)); + } + + // handle all deferred elements + handleDeferred(deferred); + } + + function handleDeferred(deferred) { + forEach(deferred, function(d) { d(); }); + } + + function handleProcess(process, context) { + handleFlowElementsContainer(process, context); + handleIoSpecification(process.ioSpecification, context); + + handleArtifacts(process.artifacts, context); + + // log process handled + handledProcesses.push(process); + } + + function handleUnhandledProcesses(rootElements) { + + // walk through all processes that have not yet been drawn and draw them + // if they contain lanes with DI information. + // we do this to pass the free-floating lane test cases in the MIWG test suite + var processes = filter(rootElements, function(e) { + return is(e, 'bpmn:Process') && e.laneSets && handledProcesses.indexOf(e) === -1; + }); + + processes.forEach(contextual(handleProcess)); + } + + function handleMessageFlow(messageFlow, context) { + visitIfDi(messageFlow, context); + } + + function handleMessageFlows(messageFlows, context) { + forEach(messageFlows, contextual(handleMessageFlow, context)); + } + + function handleDataAssociation(association, context) { + visitIfDi(association, context); + } + + function handleDataInput(dataInput, context) { + visitIfDi(dataInput, context); + } + + function handleDataOutput(dataOutput, context) { + visitIfDi(dataOutput, context); + } + + function handleArtifact(artifact, context) { + + // bpmn:TextAnnotation + // bpmn:Group + // bpmn:Association + + visitIfDi(artifact, context); + } + + function handleArtifacts(artifacts, context) { + + forEach(artifacts, function(e) { + if (is(e, 'bpmn:Association')) { + deferred.push(function() { + handleArtifact(e, context); + }); + } else { + handleArtifact(e, context); + } + }); + } + + function handleIoSpecification(ioSpecification, context) { + + if (!ioSpecification) { + return; + } + + forEach(ioSpecification.dataInputs, contextual(handleDataInput, context)); + forEach(ioSpecification.dataOutputs, contextual(handleDataOutput, context)); + } + + function handleSubProcess(subProcess, context) { + handleFlowElementsContainer(subProcess, context); + handleArtifacts(subProcess.artifacts, context); + } + + function handleFlowNode(flowNode, context) { + var childCtx = visitIfDi(flowNode, context); + + if (is(flowNode, 'bpmn:SubProcess')) { + handleSubProcess(flowNode, childCtx || context); + } + } + + function handleSequenceFlow(sequenceFlow, context) { + visitIfDi(sequenceFlow, context); + } + + function handleDataElement(dataObject, context) { + visitIfDi(dataObject, context); + } + + function handleBoundaryEvent(dataObject, context) { + visitIfDi(dataObject, context); + } + + function handleLane(lane, context) { + var newContext = visitIfDi(lane, context); + + if (lane.childLaneSet) { + handleLaneSet(lane.childLaneSet, newContext || context); + } else { + var filterList = filter(lane.flowNodeRef, function(e) { + return e.$type !== 'bpmn:BoundaryEvent'; + }); + handleFlowElements(filterList, newContext || context); + } + } + + function handleLaneSet(laneSet, context) { + forEach(laneSet.lanes, contextual(handleLane, context)); + } + + function handleLaneSets(laneSets, context) { + forEach(laneSets, contextual(handleLaneSet, context)); + } + + function handleFlowElementsContainer(container, context) { + + if (container.laneSets) { + handleLaneSets(container.laneSets, context); + handleNonFlowNodes(container.flowElements); + } else { + handleFlowElements(container.flowElements, context); + } + } + + function handleNonFlowNodes(flowElements, context) { + forEach(flowElements, function(e) { + if (is(e, 'bpmn:SequenceFlow')) { + deferred.push(function() { + handleSequenceFlow(e, context); + }); + } else if (is(e, 'bpmn:BoundaryEvent')) { + deferred.unshift(function() { + handleBoundaryEvent(e, context); + }); + } else if (is(e, 'bpmn:DataObject')) { + // SKIP (assume correct referencing via DataObjectReference) + } else if (is(e, 'bpmn:DataStoreReference')) { + handleDataElement(e, context); + } else if (is(e, 'bpmn:DataObjectReference')) { + handleDataElement(e, context); + } + }); + } + + function handleFlowElements(flowElements, context) { + forEach(flowElements, function(e) { + if (is(e, 'bpmn:SequenceFlow')) { + deferred.push(function() { + handleSequenceFlow(e, context); + }); + } else if (is(e, 'bpmn:BoundaryEvent')) { + deferred.unshift(function() { + handleBoundaryEvent(e, context); + }); + } else if (is(e, 'bpmn:FlowNode')) { + handleFlowNode(e, context); + + if (is(e, 'bpmn:Activity')) { + + handleIoSpecification(e.ioSpecification, context); + + // defer handling of associations + deferred.push(function() { + forEach(e.dataInputAssociations, contextual(handleDataAssociation, context)); + forEach(e.dataOutputAssociations, contextual(handleDataAssociation, context)); + }); + } + } else if (is(e, 'bpmn:DataObject')) { + // SKIP (assume correct referencing via DataObjectReference) + } else if (is(e, 'bpmn:DataStoreReference')) { + handleDataElement(e, context); + } else if (is(e, 'bpmn:DataObjectReference')) { + handleDataElement(e, context); + } else { + logError( + 'unrecognized flowElement ' + elementToString(e) + ' in context ' + + (context ? elementToString(context.businessObject) : null), + { element: e, context: context }); + } + }); + } + + function handleParticipant(participant, context) { + var newCtx = visitIfDi(participant, context); + + var process = participant.processRef; + if (process) { + handleProcess(process, newCtx || context); + } + } + + function handleCollaboration(collaboration) { + + forEach(collaboration.participants, contextual(handleParticipant)); + + handleArtifacts(collaboration.artifacts); + + // handle message flows latest in the process + deferred.push(function() { + handleMessageFlows(collaboration.messageFlows); + }); + } + + + ///// API //////////////////////////////// + + return { + handleDefinitions: handleDefinitions + }; +} + +module.exports = BpmnTreeWalker; +},{"10":10,"202":202,"82":82,"83":83,"84":84}],9:[function(_dereq_,module,exports){ +'use strict'; + +var BpmnTreeWalker = _dereq_(8); + + +/** + * Import the definitions into a diagram. + * + * Errors and warnings are reported through the specified callback. + * + * @param {Diagram} diagram + * @param {ModdleElement} definitions + * @param {Function} done the callback, invoked with (err, [ warning ]) once the import is done + */ +function importBpmnDiagram(diagram, definitions, done) { + + var importer = diagram.get('bpmnImporter'), + eventBus = diagram.get('eventBus'); + + var error, + warnings = []; + + function parse(definitions) { + + var visitor = { + + root: function(element) { + return importer.add(element); + }, + + element: function(element, parentShape) { + return importer.add(element, parentShape); + }, + + error: function(message, context) { + warnings.push({ message: message, context: context }); + } + }; + + var walker = new BpmnTreeWalker(visitor); + + // import + walker.handleDefinitions(definitions); + } + + eventBus.fire('import.start'); + + try { + parse(definitions); + } catch (e) { + error = e; + } + + eventBus.fire(error ? 'import.error' : 'import.success', { error: error, warnings: warnings }); + done(error, warnings); +} + +module.exports.importBpmnDiagram = importBpmnDiagram; +},{"8":8}],10:[function(_dereq_,module,exports){ +'use strict'; + +module.exports.elementToString = function(e) { + if (!e) { + return '<null>'; + } + + return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />'; +}; +},{}],11:[function(_dereq_,module,exports){ +module.exports = { + bpmnImporter: [ 'type', _dereq_(7) ] +}; +},{"7":7}],12:[function(_dereq_,module,exports){ +'use strict'; + +var is = _dereq_(14).is, + getBusinessObject = _dereq_(14).getBusinessObject; + +module.exports.isExpanded = function(element) { + + if (is(element, 'bpmn:CallActivity')) { + return false; + } + + if (is(element, 'bpmn:SubProcess')) { + return getBusinessObject(element).di.isExpanded; + } + + if (is(element, 'bpmn:Participant')) { + return !!getBusinessObject(element).processRef; + } + + return true; +}; + +},{"14":14}],13:[function(_dereq_,module,exports){ +'use strict'; + +var assign = _dereq_(175); + + +var DEFAULT_LABEL_SIZE = module.exports.DEFAULT_LABEL_SIZE = { + width: 90, + height: 20 +}; + + +/** + * Returns true if the given semantic has an external label + * + * @param {BpmnElement} semantic + * @return {Boolean} true if has label + */ +module.exports.hasExternalLabel = function(semantic) { + + return semantic.$instanceOf('bpmn:Event') || + semantic.$instanceOf('bpmn:Gateway') || + semantic.$instanceOf('bpmn:DataStoreReference') || + semantic.$instanceOf('bpmn:DataObjectReference') || + semantic.$instanceOf('bpmn:SequenceFlow') || + semantic.$instanceOf('bpmn:MessageFlow'); +}; + + +/** + * Get the middle of a number of waypoints + * + * @param {Array<Point>} waypoints + * @return {Point} the mid point + */ +var getWaypointsMid = module.exports.getWaypointsMid = function(waypoints) { + + var mid = waypoints.length / 2 - 1; + + var first = waypoints[Math.floor(mid)]; + var second = waypoints[Math.ceil(mid + 0.01)]; + + return { + x: first.x + (second.x - first.x) / 2, + y: first.y + (second.y - first.y) / 2 + }; +}; + + +var getExternalLabelMid = module.exports.getExternalLabelMid = function(element) { + + if (element.waypoints) { + return getWaypointsMid(element.waypoints); + } else { + return { + x: element.x + element.width / 2, + y: element.y + element.height + DEFAULT_LABEL_SIZE.height / 2 + }; + } +}; + +/** + * Returns the bounds of an elements label, parsed from the elements DI or + * generated from its bounds. + * + * @param {BpmnElement} semantic + * @param {djs.model.Base} element + */ +module.exports.getExternalLabelBounds = function(semantic, element) { + + var mid, + size, + bounds, + di = semantic.di, + label = di.label; + + if (label && label.bounds) { + bounds = label.bounds; + + size = { + width: Math.max(DEFAULT_LABEL_SIZE.width, bounds.width), + height: bounds.height + }; + + mid = { + x: bounds.x + bounds.width / 2, + y: bounds.y + bounds.height / 2 + }; + } else { + + mid = getExternalLabelMid(element); + + size = DEFAULT_LABEL_SIZE; + } + + return assign({ + x: mid.x - size.width / 2, + y: mid.y - size.height / 2 + }, size); +}; +},{"175":175}],14:[function(_dereq_,module,exports){ +'use strict'; + +/** + * Is an element of the given BPMN type? + * + * @param {djs.model.Base|ModdleElement} element + * @param {String} type + * + * @return {Boolean} + */ +function is(element, type) { + var bo = getBusinessObject(element); + + return bo && bo.$instanceOf(type); +} + +module.exports.is = is; + + +/** + * Return the business object for a given element. + * + * @param {djs.model.Base|ModdleElement} element + * + * @return {ModdleElement} + */ +function getBusinessObject(element) { + return (element && element.businessObject) || element; +} + +module.exports.getBusinessObject = getBusinessObject; + +},{}],15:[function(_dereq_,module,exports){ +module.exports = _dereq_(17); +},{"17":17}],16:[function(_dereq_,module,exports){ +'use strict'; + +var isString = _dereq_(172), + isFunction = _dereq_(167), + assign = _dereq_(175); + +var Moddle = _dereq_(23), + XmlReader = _dereq_(19), + XmlWriter = _dereq_(20); + +/** + * A sub class of {@link Moddle} with support for import and export of BPMN 2.0 xml files. + * + * @class BpmnModdle + * @extends Moddle + * + * @param {Object|Array} packages to use for instantiating the model + * @param {Object} [options] additional options to pass over + */ +function BpmnModdle(packages, options) { + Moddle.call(this, packages, options); +} + +BpmnModdle.prototype = Object.create(Moddle.prototype); + +module.exports = BpmnModdle; + + +/** + * Instantiates a BPMN model tree from a given xml string. + * + * @param {String} xmlStr + * @param {String} [typeName='bpmn:Definitions'] name of the root element + * @param {Object} [options] options to pass to the underlying reader + * @param {Function} done callback that is invoked with (err, result, parseContext) + * once the import completes + */ +BpmnModdle.prototype.fromXML = function(xmlStr, typeName, options, done) { + + if (!isString(typeName)) { + done = options; + options = typeName; + typeName = 'bpmn:Definitions'; + } + + if (isFunction(options)) { + done = options; + options = {}; + } + + var reader = new XmlReader(assign({ model: this, lax: true }, options)); + var rootHandler = reader.handler(typeName); + + reader.fromXML(xmlStr, rootHandler, done); +}; + + +/** + * Serializes a BPMN 2.0 object tree to XML. + * + * @param {String} element the root element, typically an instance of `bpmn:Definitions` + * @param {Object} [options] to pass to the underlying writer + * @param {Function} done callback invoked with (err, xmlStr) once the import completes + */ +BpmnModdle.prototype.toXML = function(element, options, done) { + + if (isFunction(options)) { + done = options; + options = {}; + } + + var writer = new XmlWriter(options); + try { + var result = writer.toXML(element); + done(null, result); + } catch (e) { + done(e); + } +}; + +},{"167":167,"172":172,"175":175,"19":19,"20":20,"23":23}],17:[function(_dereq_,module,exports){ +'use strict'; + +var assign = _dereq_(175); + +var BpmnModdle = _dereq_(16); + +var packages = { + bpmn: _dereq_(32), + bpmndi: _dereq_(33), + dc: _dereq_(34), + di: _dereq_(35) +}; + +module.exports = function(additionalPackages, options) { + return new BpmnModdle(assign({}, packages, additionalPackages), options); +}; +},{"16":16,"175":175,"32":32,"33":33,"34":34,"35":35}],18:[function(_dereq_,module,exports){ +'use strict'; + +function capitalize(string) { + return string.charAt(0).toUpperCase() + string.slice(1); +} + +function lower(string) { + return string.charAt(0).toLowerCase() + string.slice(1); +} + +function hasLowerCaseAlias(pkg) { + return pkg.xml && pkg.xml.tagAlias === 'lowerCase'; +} + + +module.exports.aliasToName = function(alias, pkg) { + if (hasLowerCaseAlias(pkg)) { + return capitalize(alias); + } else { + return alias; + } +}; + +module.exports.nameToAlias = function(name, pkg) { + if (hasLowerCaseAlias(pkg)) { + return lower(name); + } else { + return name; + } +}; + +module.exports.DEFAULT_NS_MAP = { + 'xsi': 'http://www.w3.org/2001/XMLSchema-instance' +}; + +module.exports.XSI_TYPE = 'xsi:type'; +},{}],19:[function(_dereq_,module,exports){ +'use strict'; + +var reduce = _dereq_(88), + forEach = _dereq_(84), + find = _dereq_(83), + assign = _dereq_(175), + defer = _dereq_(92); + +var Stack = _dereq_(22), + SaxParser = _dereq_(21).parser, + Moddle = _dereq_(23), + parseNameNs = _dereq_(28).parseName, + Types = _dereq_(31), + coerceType = Types.coerceType, + isSimpleType = Types.isSimple, + common = _dereq_(18), + XSI_TYPE = common.XSI_TYPE, + XSI_URI = common.DEFAULT_NS_MAP.xsi, + aliasToName = common.aliasToName; + +function parseNodeAttributes(node) { + var nodeAttrs = node.attributes; + + return reduce(nodeAttrs, function(result, v, k) { + var name, ns; + + if (!v.local) { + name = v.prefix; + } else { + ns = parseNameNs(v.name, v.prefix); + name = ns.name; + } + + result[name] = v.value; + return result; + }, {}); +} + +function normalizeType(node, attr, model) { + var nameNs = parseNameNs(attr.value); + + var uri = node.ns[nameNs.prefix || ''], + localName = nameNs.localName, + pkg = uri && model.getPackage(uri), + typePrefix; + + if (pkg) { + typePrefix = pkg.xml && pkg.xml.typePrefix; + + if (typePrefix && localName.indexOf(typePrefix) === 0) { + localName = localName.slice(typePrefix.length); + } + + attr.value = pkg.prefix + ':' + localName; + } +} + +/** + * Normalizes namespaces for a node given an optional default namespace and a + * number of mappings from uris to default prefixes. + * + * @param {XmlNode} node + * @param {Model} model the model containing all registered namespaces + * @param {Uri} defaultNsUri + */ +function normalizeNamespaces(node, model, defaultNsUri) { + var uri, prefix; + + uri = node.uri || defaultNsUri; + + if (uri) { + var pkg = model.getPackage(uri); + + if (pkg) { + prefix = pkg.prefix; + } else { + prefix = node.prefix; + } + + node.prefix = prefix; + node.uri = uri; + } + + forEach(node.attributes, function(attr) { + + // normalize xsi:type attributes because the + // assigned type may or may not be namespace prefixed + if (attr.uri === XSI_URI && attr.local === 'type') { + normalizeType(node, attr, model); + } + + normalizeNamespaces(attr, model, null); + }); +} + + +/** + * A parse context. + * + * @class + * + * @param {Object} options + * @param {ElementHandler} options.parseRoot the root handler for parsing a document + * @param {boolean} [options.lax=false] whether or not to ignore invalid elements + */ +function Context(options) { + + /** + * @property {ElementHandler} parseRoot + */ + + /** + * @property {Boolean} lax + */ + + assign(this, options); + + var elementsById = this.elementsById = {}; + var references = this.references = []; + var warnings = this.warnings = []; + + this.addReference = function(reference) { + references.push(reference); + }; + + this.addElement = function(id, element) { + + if (!id || !element) { + throw new Error('[xml-reader] id or ctx must not be null'); + } + + elementsById[id] = element; + }; + + this.addWarning = function (w) { + warnings.push(w); + }; +} + +function BaseHandler() {} + +BaseHandler.prototype.handleEnd = function() {}; +BaseHandler.prototype.handleText = function() {}; +BaseHandler.prototype.handleNode = function() {}; + + +/** + * A simple pass through handler that does nothing except for + * ignoring all input it receives. + * + * This is used to ignore unknown elements and + * attributes. + */ +function NoopHandler() { } + +NoopHandler.prototype = new BaseHandler(); + +NoopHandler.prototype.handleNode = function() { + return this; +}; + +function BodyHandler() {} + +BodyHandler.prototype = new BaseHandler(); + +BodyHandler.prototype.handleText = function(text) { + this.body = (this.body || '') + text; +}; + +function ReferenceHandler(property, context) { + this.property = property; + this.context = context; +} + +ReferenceHandler.prototype = new BodyHandler(); + +ReferenceHandler.prototype.handleNode = function(node) { + + if (this.element) { + throw new Error('expected no sub nodes'); + } else { + this.element = this.createReference(node); + } + + return this; +}; + +ReferenceHandler.prototype.handleEnd = function() { + this.element.id = this.body; +}; + +ReferenceHandler.prototype.createReference = function() { + return { + property: this.property.ns.name, + id: '' + }; +}; + +function ValueHandler(propertyDesc, element) { + this.element = element; + this.propertyDesc = propertyDesc; +} + +ValueHandler.prototype = new BodyHandler(); + +ValueHandler.prototype.handleEnd = function() { + + var value = this.body, + element = this.element, + propertyDesc = this.propertyDesc; + + value = coerceType(propertyDesc.type, value); + + if (propertyDesc.isMany) { + element.get(propertyDesc.name).push(value); + } else { + element.set(propertyDesc.name, value); + } +}; + + +function BaseElementHandler() {} + +BaseElementHandler.prototype = Object.create(BodyHandler.prototype); + +BaseElementHandler.prototype.handleNode = function(node) { + var parser = this, + element = this.element, + id; + + if (!element) { + element = this.element = this.createElement(node); + id = element.id; + + if (id) { + this.context.addElement(id, element); + } + } else { + parser = this.handleChild(node); + } + + return parser; +}; + +/** + * @class XMLReader.ElementHandler + * + */ +function ElementHandler(model, type, context) { + this.model = model; + this.type = model.getType(type); + this.context = context; +} + +ElementHandler.prototype = new BaseElementHandler(); + +ElementHandler.prototype.addReference = function(reference) { + this.context.addReference(reference); +}; + +ElementHandler.prototype.handleEnd = function() { + + var value = this.body, + element = this.element, + descriptor = element.$descriptor, + bodyProperty = descriptor.bodyProperty; + + if (bodyProperty && value !== undefined) { + value = coerceType(bodyProperty.type, value); + element.set(bodyProperty.name, value); + } +}; + +/** + * Create an instance of the model from the given node. + * + * @param {Element} node the xml node + */ +ElementHandler.prototype.createElement = function(node) { + var attributes = parseNodeAttributes(node), + Type = this.type, + descriptor = Type.$descriptor, + context = this.context, + instance = new Type({}); + + forEach(attributes, function(value, name) { + + var prop = descriptor.propertiesByName[name]; + + if (prop && prop.isReference) { + context.addReference({ + element: instance, + property: prop.ns.name, + id: value + }); + } else { + if (prop) { + value = coerceType(prop.type, value); + } + + instance.set(name, value); + } + }); + + return instance; +}; + +ElementHandler.prototype.getPropertyForNode = function(node) { + + var nameNs = parseNameNs(node.local, node.prefix); + + var type = this.type, + model = this.model, + descriptor = type.$descriptor; + + var propertyName = nameNs.name, + property = descriptor.propertiesByName[propertyName], + elementTypeName, + elementType, + typeAnnotation; + + // search for properties by name first + + if (property) { + + if (property.serialize === XSI_TYPE) { + typeAnnotation = node.attributes[XSI_TYPE]; + + // xsi type is optional, if it does not exists the + // default type is assumed + if (typeAnnotation) { + + elementTypeName = typeAnnotation.value; + + // TODO: extract real name from attribute + elementType = model.getType(elementTypeName); + + return assign({}, property, { effectiveType: elementType.$descriptor.name }); + } + } + + // search for properties by name first + return property; + } + + + var pkg = model.getPackage(nameNs.prefix); + + if (pkg) { + elementTypeName = nameNs.prefix + ':' + aliasToName(nameNs.localName, descriptor.$pkg); + elementType = model.getType(elementTypeName); + + // search for collection members later + property = find(descriptor.properties, function(p) { + return !p.isVirtual && !p.isReference && !p.isAttribute && elementType.hasType(p.type); + }); + + if (property) { + return assign({}, property, { effectiveType: elementType.$descriptor.name }); + } + } else { + // parse unknown element (maybe extension) + property = find(descriptor.properties, function(p) { + return !p.isReference && !p.isAttribute && p.type === 'Element'; + }); + + if (property) { + return property; + } + } + + throw new Error('unrecognized element <' + nameNs.name + '>'); +}; + +ElementHandler.prototype.toString = function() { + return 'ElementDescriptor[' + this.type.$descriptor.name + ']'; +}; + +ElementHandler.prototype.valueHandler = function(propertyDesc, element) { + return new ValueHandler(propertyDesc, element); +}; + +ElementHandler.prototype.referenceHandler = function(propertyDesc) { + return new ReferenceHandler(propertyDesc, this.context); +}; + +ElementHandler.prototype.handler = function(type) { + if (type === 'Element') { + return new GenericElementHandler(this.model, type, this.context); + } else { + return new ElementHandler(this.model, type, this.context); + } +}; + +/** + * Handle the child element parsing + * + * @param {Element} node the xml node + */ +ElementHandler.prototype.handleChild = function(node) { + var propertyDesc, type, element, childHandler; + + propertyDesc = this.getPropertyForNode(node); + element = this.element; + + type = propertyDesc.effectiveType || propertyDesc.type; + + if (isSimpleType(type)) { + return this.valueHandler(propertyDesc, element); + } + + if (propertyDesc.isReference) { + childHandler = this.referenceHandler(propertyDesc).handleNode(node); + } else { + childHandler = this.handler(type).handleNode(node); + } + + var newElement = childHandler.element; + + // child handles may decide to skip elements + // by not returning anything + if (newElement !== undefined) { + + if (propertyDesc.isMany) { + element.get(propertyDesc.name).push(newElement); + } else { + element.set(propertyDesc.name, newElement); + } + + if (propertyDesc.isReference) { + assign(newElement, { + element: element + }); + + this.context.addReference(newElement); + } else { + // establish child -> parent relationship + newElement.$parent = element; + } + } + + return childHandler; +}; + + +function GenericElementHandler(model, type, context) { + this.model = model; + this.context = context; +} + +GenericElementHandler.prototype = Object.create(BaseElementHandler.prototype); + +GenericElementHandler.prototype.createElement = function(node) { + + var name = node.name, + prefix = node.prefix, + uri = node.ns[prefix], + attributes = node.attributes; + + return this.model.createAny(name, uri, attributes); +}; + +GenericElementHandler.prototype.handleChild = function(node) { + + var handler = new GenericElementHandler(this.model, 'Element', this.context).handleNode(node), + element = this.element; + + var newElement = handler.element, + children; + + if (newElement !== undefined) { + children = element.$children = element.$children || []; + children.push(newElement); + + // establish child -> parent relationship + newElement.$parent = element; + } + + return handler; +}; + +GenericElementHandler.prototype.handleText = function(text) { + this.body = this.body || '' + text; +}; + +GenericElementHandler.prototype.handleEnd = function() { + if (this.body) { + this.element.$body = this.body; + } +}; + +/** + * A reader for a meta-model + * + * @param {Object} options + * @param {Model} options.model used to read xml files + * @param {Boolean} options.lax whether to make parse errors warnings + */ +function XMLReader(options) { + + if (options instanceof Moddle) { + options = { + model: options + }; + } + + assign(this, { lax: false }, options); +} + + +XMLReader.prototype.fromXML = function(xml, rootHandler, done) { + + var model = this.model, + lax = this.lax, + context = new Context({ + parseRoot: rootHandler + }); + + var parser = new SaxParser(true, { xmlns: true, trim: true }), + stack = new Stack(); + + rootHandler.context = context; + + // push root handler + stack.push(rootHandler); + + + function resolveReferences() { + + var elementsById = context.elementsById; + var references = context.references; + + var i, r; + + for (i = 0; !!(r = references[i]); i++) { + var element = r.element; + var reference = elementsById[r.id]; + var property = element.$descriptor.propertiesByName[r.property]; + + if (!reference) { + context.addWarning({ + message: 'unresolved reference <' + r.id + '>', + element: r.element, + property: r.property, + value: r.id + }); + } + + if (property.isMany) { + var collection = element.get(property.name), + idx = collection.indexOf(r); + + if (!reference) { + // remove unresolvable reference + collection.splice(idx, 1); + } else { + // update reference + collection[idx] = reference; + } + } else { + element.set(property.name, reference); + } + } + } + + function handleClose(tagName) { + stack.pop().handleEnd(); + } + + function handleOpen(node) { + var handler = stack.peek(); + + normalizeNamespaces(node, model); + + try { + stack.push(handler.handleNode(node)); + } catch (e) { + + var line = this.line, + column = this.column; + + var message = + 'unparsable content <' + node.name + '> detected\n\t' + + 'line: ' + line + '\n\t' + + 'column: ' + column + '\n\t' + + 'nested error: ' + e.message; + + if (lax) { + context.addWarning({ + message: message, + error: e + }); + + console.warn('could not parse node'); + console.warn(e); + + stack.push(new NoopHandler()); + } else { + console.error('could not parse document'); + console.error(e); + + throw new Error(message); + } + } + } + + function handleText(text) { + stack.peek().handleText(text); + } + + parser.onopentag = handleOpen; + parser.oncdata = parser.ontext = handleText; + parser.onclosetag = handleClose; + parser.onend = resolveReferences; + + // deferred parse XML to make loading really ascnchronous + // this ensures the execution environment (node or browser) + // is kept responsive and that certain optimization strategies + // can kick in + defer(function() { + var error; + + try { + parser.write(xml).close(); + } catch (e) { + error = e; + } + + done(error, error ? undefined : rootHandler.element, context); + }); +}; + +XMLReader.prototype.handler = function(name) { + return new ElementHandler(this.model, name); +}; + +module.exports = XMLReader; +module.exports.ElementHandler = ElementHandler; +},{"175":175,"18":18,"21":21,"22":22,"23":23,"28":28,"31":31,"83":83,"84":84,"88":88,"92":92}],20:[function(_dereq_,module,exports){ +'use strict'; + +var map = _dereq_(87), + forEach = _dereq_(84), + isString = _dereq_(172), + filter = _dereq_(82), + assign = _dereq_(175); + +var Types = _dereq_(31), + parseNameNs = _dereq_(28).parseName, + common = _dereq_(18), + nameToAlias = common.nameToAlias; + +var XML_PREAMBLE = '<?xml version="1.0" encoding="UTF-8"?>\n', + ESCAPE_CHARS = /(<|>|'|"|&|\n\r|\n)/g, + DEFAULT_NS_MAP = common.DEFAULT_NS_MAP, + XSI_TYPE = common.XSI_TYPE; + + +function nsName(ns) { + if (isString(ns)) { + return ns; + } else { + return (ns.prefix ? ns.prefix + ':' : '') + ns.localName; + } +} + +function getElementNs(ns, descriptor) { + if (descriptor.isGeneric) { + return descriptor.name; + } else { + return assign({ localName: nameToAlias(descriptor.ns.localName, descriptor.$pkg) }, ns); + } +} + +function getPropertyNs(ns, descriptor) { + return assign({ localName: descriptor.ns.localName }, ns); +} + +function getSerializableProperties(element) { + var descriptor = element.$descriptor; + + return filter(descriptor.properties, function(p) { + var name = p.name; + + // do not serialize defaults + if (!element.hasOwnProperty(name)) { + return false; + } + + var value = element[name]; + + // do not serialize default equals + if (value === p.default) { + return false; + } + + return p.isMany ? value.length : true; + }); +} + +var ESCAPE_MAP = { + '\n': '10', + '\n\r': '10', + '"': '34', + '\'': '39', + '<': '60', + '>': '62', + '&': '38' +}; + +/** + * Escape a string attribute to not contain any bad values (line breaks, '"', ...) + * + * @param {String} str the string to escape + * @return {String} the escaped string + */ +function escapeAttr(str) { + + // ensure we are handling strings here + str = isString(str) ? str : '' + str; + + return str.replace(ESCAPE_CHARS, function(str) { + return '&#' + ESCAPE_MAP[str] + ';'; + }); +} + +function filterAttributes(props) { + return filter(props, function(p) { return p.isAttr; }); +} + +function filterContained(props) { + return filter(props, function(p) { return !p.isAttr; }); +} + + +function ReferenceSerializer(parent, ns) { + this.ns = ns; +} + +ReferenceSerializer.prototype.build = function(element) { + this.element = element; + return this; +}; + +ReferenceSerializer.prototype.serializeTo = function(writer) { + writer + .appendIndent() + .append('<' + nsName(this.ns) + '>' + this.element.id + '</' + nsName(this.ns) + '>') + .appendNewLine(); +}; + +function BodySerializer() {} + +BodySerializer.prototype.serializeValue = BodySerializer.prototype.serializeTo = function(writer) { + var escape = this.escape; + + if (escape) { + writer.append('<![CDATA['); + } + + writer.append(this.value); + + if (escape) { + writer.append(']]>'); + } +}; + +BodySerializer.prototype.build = function(prop, value) { + this.value = value; + + if (prop.type === 'String' && ESCAPE_CHARS.test(value)) { + this.escape = true; + } + + return this; +}; + +function ValueSerializer(ns) { + this.ns = ns; +} + +ValueSerializer.prototype = new BodySerializer(); + +ValueSerializer.prototype.serializeTo = function(writer) { + + writer + .appendIndent() + .append('<' + nsName(this.ns) + '>'); + + this.serializeValue(writer); + + writer + .append( '</' + nsName(this.ns) + '>') + .appendNewLine(); +}; + +function ElementSerializer(parent, ns) { + this.body = []; + this.attrs = []; + + this.parent = parent; + this.ns = ns; +} + +ElementSerializer.prototype.build = function(element) { + this.element = element; + + var otherAttrs = this.parseNsAttributes(element); + + if (!this.ns) { + this.ns = this.nsTagName(element.$descriptor); + } + + if (element.$descriptor.isGeneric) { + this.parseGeneric(element); + } else { + var properties = getSerializableProperties(element); + + this.parseAttributes(filterAttributes(properties)); + this.parseContainments(filterContained(properties)); + + this.parseGenericAttributes(element, otherAttrs); + } + + return this; +}; + +ElementSerializer.prototype.nsTagName = function(descriptor) { + var effectiveNs = this.logNamespaceUsed(descriptor.ns); + return getElementNs(effectiveNs, descriptor); +}; + +ElementSerializer.prototype.nsPropertyTagName = function(descriptor) { + var effectiveNs = this.logNamespaceUsed(descriptor.ns); + return getPropertyNs(effectiveNs, descriptor); +}; + +ElementSerializer.prototype.isLocalNs = function(ns) { + return ns.uri === this.ns.uri; +}; + +ElementSerializer.prototype.nsAttributeName = function(element) { + + var ns; + + if (isString(element)) { + ns = parseNameNs(element); + } else + if (element.ns) { + ns = element.ns; + } + + var effectiveNs = this.logNamespaceUsed(ns); + + // strip prefix if same namespace like parent + if (this.isLocalNs(effectiveNs)) { + return { localName: ns.localName }; + } else { + return assign({ localName: ns.localName }, effectiveNs); + } +}; + +ElementSerializer.prototype.parseGeneric = function(element) { + + var self = this, + body = this.body, + attrs = this.attrs; + + forEach(element, function(val, key) { + + if (key === '$body') { + body.push(new BodySerializer().build({ type: 'String' }, val)); + } else + if (key === '$children') { + forEach(val, function(child) { + body.push(new ElementSerializer(self).build(child)); + }); + } else + if (key.indexOf('$') !== 0) { + attrs.push({ name: key, value: escapeAttr(val) }); + } + }); +}; + +/** + * Parse namespaces and return a list of left over generic attributes + * + * @param {Object} element + * @return {Array<Object>} + */ +ElementSerializer.prototype.parseNsAttributes = function(element) { + var self = this; + + var genericAttrs = element.$attrs; + + var attributes = []; + + // parse namespace attributes first + // and log them. push non namespace attributes to a list + // and process them later + forEach(genericAttrs, function(value, name) { + var nameNs = parseNameNs(name); + + if (nameNs.prefix === 'xmlns') { + self.logNamespace({ prefix: nameNs.localName, uri: value }); + } else + if (!nameNs.prefix && nameNs.localName === 'xmlns') { + self.logNamespace({ uri: value }); + } else { + attributes.push({ name: name, value: value }); + } + }); + + return attributes; +}; + +ElementSerializer.prototype.parseGenericAttributes = function(element, attributes) { + + var self = this; + + forEach(attributes, function(attr) { + + // do not serialize xsi:type attribute + // it is set manually based on the actual implementation type + if (attr.name === XSI_TYPE) { + return; + } + + try { + self.addAttribute(self.nsAttributeName(attr.name), attr.value); + } catch (e) { + console.warn('[writer] missing namespace information for ', attr.name, '=', attr.value, 'on', element, e); + } + }); +}; + +ElementSerializer.prototype.parseContainments = function(properties) { + + var self = this, + body = this.body, + element = this.element; + + forEach(properties, function(p) { + var value = element.get(p.name), + isReference = p.isReference, + isMany = p.isMany; + + var ns = self.nsPropertyTagName(p); + + if (!isMany) { + value = [ value ]; + } + + if (p.isBody) { + body.push(new BodySerializer().build(p, value[0])); + } else + if (Types.isSimple(p.type)) { + forEach(value, function(v) { + body.push(new ValueSerializer(ns).build(p, v)); + }); + } else + if (isReference) { + forEach(value, function(v) { + body.push(new ReferenceSerializer(self, ns).build(v)); + }); + } else { + // allow serialization via type + // rather than element name + var asType = p.serialize === XSI_TYPE; + + forEach(value, function(v) { + var serializer; + + if (asType) { + serializer = new TypeSerializer(self, ns); + } else { + serializer = new ElementSerializer(self); + } + + body.push(serializer.build(v)); + }); + } + }); +}; + +ElementSerializer.prototype.getNamespaces = function() { + if (!this.parent) { + if (!this.namespaces) { + this.namespaces = { + prefixMap: {}, + uriMap: {}, + used: {} + }; + } + } else { + this.namespaces = this.parent.getNamespaces(); + } + + return this.namespaces; +}; + +ElementSerializer.prototype.logNamespace = function(ns) { + var namespaces = this.getNamespaces(); + + var existing = namespaces.uriMap[ns.uri]; + + if (!existing) { + namespaces.uriMap[ns.uri] = ns; + } + + namespaces.prefixMap[ns.prefix] = ns.uri; + + return ns; +}; + +ElementSerializer.prototype.logNamespaceUsed = function(ns) { + var element = this.element, + model = element.$model, + namespaces = this.getNamespaces(); + + // ns may be + // + // * prefix only + // * prefix:uri + + var prefix = ns.prefix; + var uri = ns.uri || DEFAULT_NS_MAP[prefix] || + namespaces.prefixMap[prefix] || (model ? (model.getPackage(prefix) || {}).uri : null); + + if (!uri) { + throw new Error('no namespace uri given for prefix <' + ns.prefix + '>'); + } + + ns = namespaces.uriMap[uri]; + + if (!ns) { + ns = this.logNamespace({ prefix: prefix, uri: uri }); + } + + if (!namespaces.used[ns.uri]) { + namespaces.used[ns.uri] = ns; + } + + return ns; +}; + +ElementSerializer.prototype.parseAttributes = function(properties) { + var self = this, + element = this.element; + + forEach(properties, function(p) { + self.logNamespaceUsed(p.ns); + + var value = element.get(p.name); + + if (p.isReference) { + value = value.id; + } + + self.addAttribute(self.nsAttributeName(p), value); + }); +}; + +ElementSerializer.prototype.addAttribute = function(name, value) { + var attrs = this.attrs; + + if (isString(value)) { + value = escapeAttr(value); + } + + attrs.push({ name: name, value: value }); +}; + +ElementSerializer.prototype.serializeAttributes = function(writer) { + var attrs = this.attrs, + root = !this.parent, + namespaces = this.namespaces; + + function collectNsAttrs() { + return map(namespaces.used, function(ns) { + var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : ''); + return { name: name, value: ns.uri }; + }); + } + + if (root) { + attrs = collectNsAttrs().concat(attrs); + } + + forEach(attrs, function(a) { + writer + .append(' ') + .append(nsName(a.name)).append('="').append(a.value).append('"'); + }); +}; + +ElementSerializer.prototype.serializeTo = function(writer) { + var hasBody = this.body.length, + indent = !(this.body.length === 1 && this.body[0] instanceof BodySerializer); + + writer + .appendIndent() + .append('<' + nsName(this.ns)); + + this.serializeAttributes(writer); + + writer.append(hasBody ? '>' : ' />'); + + if (hasBody) { + + if (indent) { + writer + .appendNewLine() + .indent(); + } + + forEach(this.body, function(b) { + b.serializeTo(writer); + }); + + if (indent) { + writer + .unindent() + .appendIndent(); + } + + writer.append('</' + nsName(this.ns) + '>'); + } + + writer.appendNewLine(); +}; + +/** + * A serializer for types that handles serialization of data types + */ +function TypeSerializer(parent, ns) { + ElementSerializer.call(this, parent, ns); +} + +TypeSerializer.prototype = new ElementSerializer(); + +TypeSerializer.prototype.build = function(element) { + var descriptor = element.$descriptor; + + this.element = element; + + this.typeNs = this.nsTagName(descriptor); + + // add xsi:type attribute to represent the elements + // actual type + + var typeNs = this.typeNs, + pkg = element.$model.getPackage(typeNs.uri), + typePrefix = (pkg.xml && pkg.xml.typePrefix) || ''; + + this.addAttribute(this.nsAttributeName(XSI_TYPE), + (typeNs.prefix ? typeNs.prefix + ':' : '') + + typePrefix + descriptor.ns.localName); + + // do the usual stuff + return ElementSerializer.prototype.build.call(this, element); +}; + +TypeSerializer.prototype.isLocalNs = function(ns) { + return ns.uri === this.typeNs.uri; +}; + +function SavingWriter() { + this.value = ''; + + this.write = function(str) { + this.value += str; + }; +} + +function FormatingWriter(out, format) { + + var indent = ['']; + + this.append = function(str) { + out.write(str); + + return this; + }; + + this.appendNewLine = function() { + if (format) { + out.write('\n'); + } + + return this; + }; + + this.appendIndent = function() { + if (format) { + out.write(indent.join(' ')); + } + + return this; + }; + + this.indent = function() { + indent.push(''); + return this; + }; + + this.unindent = function() { + indent.pop(); + return this; + }; +} + +/** + * A writer for meta-model backed document trees + * + * @param {Object} options output options to pass into the writer + */ +function XMLWriter(options) { + + options = assign({ format: false, preamble: true }, options || {}); + + function toXML(tree, writer) { + var internalWriter = writer || new SavingWriter(); + var formatingWriter = new FormatingWriter(internalWriter, options.format); + + if (options.preamble) { + formatingWriter.append(XML_PREAMBLE); + } + + new ElementSerializer().build(tree).serializeTo(formatingWriter); + + if (!writer) { + return internalWriter.value; + } + } + + return { + toXML: toXML + }; +} + +module.exports = XMLWriter; +},{"172":172,"175":175,"18":18,"28":28,"31":31,"82":82,"84":84,"87":87}],21:[function(_dereq_,module,exports){ +(function (Buffer){ +// wrapper for non-node envs +;(function (sax) { + +sax.parser = function (strict, opt) { return new SAXParser(strict, opt) } +sax.SAXParser = SAXParser +sax.SAXStream = SAXStream +sax.createStream = createStream + +// When we pass the MAX_BUFFER_LENGTH position, start checking for buffer overruns. +// When we check, schedule the next check for MAX_BUFFER_LENGTH - (max(buffer lengths)), +// since that's the earliest that a buffer overrun could occur. This way, checks are +// as rare as required, but as often as necessary to ensure never crossing this bound. +// Furthermore, buffers are only tested at most once per write(), so passing a very +// large string into write() might have undesirable effects, but this is manageable by +// the caller, so it is assumed to be safe. Thus, a call to write() may, in the extreme +// edge case, result in creating at most one complete copy of the string passed in. +// Set to Infinity to have unlimited buffers. +sax.MAX_BUFFER_LENGTH = 64 * 1024 + +var buffers = [ + "comment", "sgmlDecl", "textNode", "tagName", "doctype", + "procInstName", "procInstBody", "entity", "attribName", + "attribValue", "cdata", "script" +] + +sax.EVENTS = // for discoverability. + [ "text" + , "processinginstruction" + , "sgmldeclaration" + , "doctype" + , "comment" + , "attribute" + , "opentag" + , "closetag" + , "opencdata" + , "cdata" + , "closecdata" + , "error" + , "end" + , "ready" + , "script" + , "opennamespace" + , "closenamespace" + ] + +function SAXParser (strict, opt) { + if (!(this instanceof SAXParser)) return new SAXParser(strict, opt) + + var parser = this + clearBuffers(parser) + parser.q = parser.c = "" + parser.bufferCheckPosition = sax.MAX_BUFFER_LENGTH + parser.opt = opt || {} + parser.opt.lowercase = parser.opt.lowercase || parser.opt.lowercasetags + parser.looseCase = parser.opt.lowercase ? "toLowerCase" : "toUpperCase" + parser.tags = [] + parser.closed = parser.closedRoot = parser.sawRoot = false + parser.tag = parser.error = null + parser.strict = !!strict + parser.noscript = !!(strict || parser.opt.noscript) + parser.state = S.BEGIN + parser.ENTITIES = Object.create(sax.ENTITIES) + parser.attribList = [] + + // namespaces form a prototype chain. + // it always points at the current tag, + // which protos to its parent tag. + if (parser.opt.xmlns) parser.ns = Object.create(rootNS) + + // mostly just for error reporting + parser.trackPosition = parser.opt.position !== false + if (parser.trackPosition) { + parser.position = parser.line = parser.column = 0 + } + emit(parser, "onready") +} + +if (!Object.create) Object.create = function (o) { + function f () { this.__proto__ = o } + f.prototype = o + return new f +} + +if (!Object.getPrototypeOf) Object.getPrototypeOf = function (o) { + return o.__proto__ +} + +if (!Object.keys) Object.keys = function (o) { + var a = [] + for (var i in o) if (o.hasOwnProperty(i)) a.push(i) + return a +} + +function checkBufferLength (parser) { + var maxAllowed = Math.max(sax.MAX_BUFFER_LENGTH, 10) + , maxActual = 0 + for (var i = 0, l = buffers.length; i < l; i ++) { + var len = parser[buffers[i]].length + if (len > maxAllowed) { + // Text/cdata nodes can get big, and since they're buffered, + // we can get here under normal conditions. + // Avoid issues by emitting the text node now, + // so at least it won't get any bigger. + switch (buffers[i]) { + case "textNode": + closeText(parser) + break + + case "cdata": + emitNode(parser, "oncdata", parser.cdata) + parser.cdata = "" + break + + case "script": + emitNode(parser, "onscript", parser.script) + parser.script = "" + break + + default: + error(parser, "Max buffer length exceeded: "+buffers[i]) + } + } + maxActual = Math.max(maxActual, len) + } + // schedule the next check for the earliest possible buffer overrun. + parser.bufferCheckPosition = (sax.MAX_BUFFER_LENGTH - maxActual) + + parser.position +} + +function clearBuffers (parser) { + for (var i = 0, l = buffers.length; i < l; i ++) { + parser[buffers[i]] = "" + } +} + +function flushBuffers (parser) { + closeText(parser) + if (parser.cdata !== "") { + emitNode(parser, "oncdata", parser.cdata) + parser.cdata = "" + } + if (parser.script !== "") { + emitNode(parser, "onscript", parser.script) + parser.script = "" + } +} + +SAXParser.prototype = + { end: function () { end(this) } + , write: write + , resume: function () { this.error = null; return this } + , close: function () { return this.write(null) } + , flush: function () { flushBuffers(this) } + } + +try { + var Stream = _dereq_("stream").Stream +} catch (ex) { + var Stream = function () {} +} + + +var streamWraps = sax.EVENTS.filter(function (ev) { + return ev !== "error" && ev !== "end" +}) + +function createStream (strict, opt) { + return new SAXStream(strict, opt) +} + +function SAXStream (strict, opt) { + if (!(this instanceof SAXStream)) return new SAXStream(strict, opt) + + Stream.apply(this) + + this._parser = new SAXParser(strict, opt) + this.writable = true + this.readable = true + + + var me = this + + this._parser.onend = function () { + me.emit("end") + } + + this._parser.onerror = function (er) { + me.emit("error", er) + + // if didn't throw, then means error was handled. + // go ahead and clear error, so we can write again. + me._parser.error = null + } + + this._decoder = null; + + streamWraps.forEach(function (ev) { + Object.defineProperty(me, "on" + ev, { + get: function () { return me._parser["on" + ev] }, + set: function (h) { + if (!h) { + me.removeAllListeners(ev) + return me._parser["on"+ev] = h + } + me.on(ev, h) + }, + enumerable: true, + configurable: false + }) + }) +} + +SAXStream.prototype = Object.create(Stream.prototype, + { constructor: { value: SAXStream } }) + +SAXStream.prototype.write = function (data) { + if (typeof Buffer === 'function' && + typeof Buffer.isBuffer === 'function' && + Buffer.isBuffer(data)) { + if (!this._decoder) { + var SD = _dereq_('string_decoder').StringDecoder + this._decoder = new SD('utf8') + } + data = this._decoder.write(data); + } + + this._parser.write(data.toString()) + this.emit("data", data) + return true +} + +SAXStream.prototype.end = function (chunk) { + if (chunk && chunk.length) this.write(chunk) + this._parser.end() + return true +} + +SAXStream.prototype.on = function (ev, handler) { + var me = this + if (!me._parser["on"+ev] && streamWraps.indexOf(ev) !== -1) { + me._parser["on"+ev] = function () { + var args = arguments.length === 1 ? [arguments[0]] + : Array.apply(null, arguments) + args.splice(0, 0, ev) + me.emit.apply(me, args) + } + } + + return Stream.prototype.on.call(me, ev, handler) +} + + + +// character classes and tokens +var whitespace = "\r\n\t " + // this really needs to be replaced with character classes. + // XML allows all manner of ridiculous numbers and digits. + , number = "0124356789" + , letter = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + // (Letter | "_" | ":") + , quote = "'\"" + , entity = number+letter+"#" + , attribEnd = whitespace + ">" + , CDATA = "[CDATA[" + , DOCTYPE = "DOCTYPE" + , XML_NAMESPACE = "http://www.w3.org/XML/1998/namespace" + , XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/" + , rootNS = { xml: XML_NAMESPACE, xmlns: XMLNS_NAMESPACE } + +// turn all the string character sets into character class objects. +whitespace = charClass(whitespace) +number = charClass(number) +letter = charClass(letter) + +// http://www.w3.org/TR/REC-xml/#NT-NameStartChar +// This implementation works on strings, a single character at a time +// as such, it cannot ever support astral-plane characters (10000-EFFFF) +// without a significant breaking change to either this parser, or the +// JavaScript language. Implementation of an emoji-capable xml parser +// is left as an exercise for the reader. +var nameStart = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD]/ + +var nameBody = /[:_A-Za-z\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u02FF\u0370-\u037D\u037F-\u1FFF\u200C-\u200D\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u00B7\u0300-\u036F\u203F-\u2040\.\d-]/ + +quote = charClass(quote) +entity = charClass(entity) +attribEnd = charClass(attribEnd) + +function charClass (str) { + return str.split("").reduce(function (s, c) { + s[c] = true + return s + }, {}) +} + +function isRegExp (c) { + return Object.prototype.toString.call(c) === '[object RegExp]' +} + +function is (charclass, c) { + return isRegExp(charclass) ? !!c.match(charclass) : charclass[c] +} + +function not (charclass, c) { + return !is(charclass, c) +} + +var S = 0 +sax.STATE = +{ BEGIN : S++ +, TEXT : S++ // general stuff +, TEXT_ENTITY : S++ // & and such. +, OPEN_WAKA : S++ // < +, SGML_DECL : S++ // <!BLARG +, SGML_DECL_QUOTED : S++ // <!BLARG foo "bar +, DOCTYPE : S++ // <!DOCTYPE +, DOCTYPE_QUOTED : S++ // <!DOCTYPE "//blah +, DOCTYPE_DTD : S++ // <!DOCTYPE "//blah" [ ... +, DOCTYPE_DTD_QUOTED : S++ // <!DOCTYPE "//blah" [ "foo +, COMMENT_STARTING : S++ // <!- +, COMMENT : S++ // <!-- +, COMMENT_ENDING : S++ // <!-- blah - +, COMMENT_ENDED : S++ // <!-- blah -- +, CDATA : S++ // <![CDATA[ something +, CDATA_ENDING : S++ // ] +, CDATA_ENDING_2 : S++ // ]] +, PROC_INST : S++ // <?hi +, PROC_INST_BODY : S++ // <?hi there +, PROC_INST_ENDING : S++ // <?hi "there" ? +, OPEN_TAG : S++ // <strong +, OPEN_TAG_SLASH : S++ // <strong / +, ATTRIB : S++ // <a +, ATTRIB_NAME : S++ // <a foo +, ATTRIB_NAME_SAW_WHITE : S++ // <a foo _ +, ATTRIB_VALUE : S++ // <a foo= +, ATTRIB_VALUE_QUOTED : S++ // <a foo="bar +, ATTRIB_VALUE_CLOSED : S++ // <a foo="bar" +, ATTRIB_VALUE_UNQUOTED : S++ // <a foo=bar +, ATTRIB_VALUE_ENTITY_Q : S++ // <foo bar=""" +, ATTRIB_VALUE_ENTITY_U : S++ // <foo bar=" +, CLOSE_TAG : S++ // </a +, CLOSE_TAG_SAW_WHITE : S++ // </a > +, SCRIPT : S++ // <script> ... +, SCRIPT_ENDING : S++ // <script> ... < +} + +sax.ENTITIES = +{ "amp" : "&" +, "gt" : ">" +, "lt" : "<" +, "quot" : "\"" +, "apos" : "'" +, "AElig" : 198 +, "Aacute" : 193 +, "Acirc" : 194 +, "Agrave" : 192 +, "Aring" : 197 +, "Atilde" : 195 +, "Auml" : 196 +, "Ccedil" : 199 +, "ETH" : 208 +, "Eacute" : 201 +, "Ecirc" : 202 +, "Egrave" : 200 +, "Euml" : 203 +, "Iacute" : 205 +, "Icirc" : 206 +, "Igrave" : 204 +, "Iuml" : 207 +, "Ntilde" : 209 +, "Oacute" : 211 +, "Ocirc" : 212 +, "Ograve" : 210 +, "Oslash" : 216 +, "Otilde" : 213 +, "Ouml" : 214 +, "THORN" : 222 +, "Uacute" : 218 +, "Ucirc" : 219 +, "Ugrave" : 217 +, "Uuml" : 220 +, "Yacute" : 221 +, "aacute" : 225 +, "acirc" : 226 +, "aelig" : 230 +, "agrave" : 224 +, "aring" : 229 +, "atilde" : 227 +, "auml" : 228 +, "ccedil" : 231 +, "eacute" : 233 +, "ecirc" : 234 +, "egrave" : 232 +, "eth" : 240 +, "euml" : 235 +, "iacute" : 237 +, "icirc" : 238 +, "igrave" : 236 +, "iuml" : 239 +, "ntilde" : 241 +, "oacute" : 243 +, "ocirc" : 244 +, "ograve" : 242 +, "oslash" : 248 +, "otilde" : 245 +, "ouml" : 246 +, "szlig" : 223 +, "thorn" : 254 +, "uacute" : 250 +, "ucirc" : 251 +, "ugrave" : 249 +, "uuml" : 252 +, "yacute" : 253 +, "yuml" : 255 +, "copy" : 169 +, "reg" : 174 +, "nbsp" : 160 +, "iexcl" : 161 +, "cent" : 162 +, "pound" : 163 +, "curren" : 164 +, "yen" : 165 +, "brvbar" : 166 +, "sect" : 167 +, "uml" : 168 +, "ordf" : 170 +, "laquo" : 171 +, "not" : 172 +, "shy" : 173 +, "macr" : 175 +, "deg" : 176 +, "plusmn" : 177 +, "sup1" : 185 +, "sup2" : 178 +, "sup3" : 179 +, "acute" : 180 +, "micro" : 181 +, "para" : 182 +, "middot" : 183 +, "cedil" : 184 +, "ordm" : 186 +, "raquo" : 187 +, "frac14" : 188 +, "frac12" : 189 +, "frac34" : 190 +, "iquest" : 191 +, "times" : 215 +, "divide" : 247 +, "OElig" : 338 +, "oelig" : 339 +, "Scaron" : 352 +, "scaron" : 353 +, "Yuml" : 376 +, "fnof" : 402 +, "circ" : 710 +, "tilde" : 732 +, "Alpha" : 913 +, "Beta" : 914 +, "Gamma" : 915 +, "Delta" : 916 +, "Epsilon" : 917 +, "Zeta" : 918 +, "Eta" : 919 +, "Theta" : 920 +, "Iota" : 921 +, "Kappa" : 922 +, "Lambda" : 923 +, "Mu" : 924 +, "Nu" : 925 +, "Xi" : 926 +, "Omicron" : 927 +, "Pi" : 928 +, "Rho" : 929 +, "Sigma" : 931 +, "Tau" : 932 +, "Upsilon" : 933 +, "Phi" : 934 +, "Chi" : 935 +, "Psi" : 936 +, "Omega" : 937 +, "alpha" : 945 +, "beta" : 946 +, "gamma" : 947 +, "delta" : 948 +, "epsilon" : 949 +, "zeta" : 950 +, "eta" : 951 +, "theta" : 952 +, "iota" : 953 +, "kappa" : 954 +, "lambda" : 955 +, "mu" : 956 +, "nu" : 957 +, "xi" : 958 +, "omicron" : 959 +, "pi" : 960 +, "rho" : 961 +, "sigmaf" : 962 +, "sigma" : 963 +, "tau" : 964 +, "upsilon" : 965 +, "phi" : 966 +, "chi" : 967 +, "psi" : 968 +, "omega" : 969 +, "thetasym" : 977 +, "upsih" : 978 +, "piv" : 982 +, "ensp" : 8194 +, "emsp" : 8195 +, "thinsp" : 8201 +, "zwnj" : 8204 +, "zwj" : 8205 +, "lrm" : 8206 +, "rlm" : 8207 +, "ndash" : 8211 +, "mdash" : 8212 +, "lsquo" : 8216 +, "rsquo" : 8217 +, "sbquo" : 8218 +, "ldquo" : 8220 +, "rdquo" : 8221 +, "bdquo" : 8222 +, "dagger" : 8224 +, "Dagger" : 8225 +, "bull" : 8226 +, "hellip" : 8230 +, "permil" : 8240 +, "prime" : 8242 +, "Prime" : 8243 +, "lsaquo" : 8249 +, "rsaquo" : 8250 +, "oline" : 8254 +, "frasl" : 8260 +, "euro" : 8364 +, "image" : 8465 +, "weierp" : 8472 +, "real" : 8476 +, "trade" : 8482 +, "alefsym" : 8501 +, "larr" : 8592 +, "uarr" : 8593 +, "rarr" : 8594 +, "darr" : 8595 +, "harr" : 8596 +, "crarr" : 8629 +, "lArr" : 8656 +, "uArr" : 8657 +, "rArr" : 8658 +, "dArr" : 8659 +, "hArr" : 8660 +, "forall" : 8704 +, "part" : 8706 +, "exist" : 8707 +, "empty" : 8709 +, "nabla" : 8711 +, "isin" : 8712 +, "notin" : 8713 +, "ni" : 8715 +, "prod" : 8719 +, "sum" : 8721 +, "minus" : 8722 +, "lowast" : 8727 +, "radic" : 8730 +, "prop" : 8733 +, "infin" : 8734 +, "ang" : 8736 +, "and" : 8743 +, "or" : 8744 +, "cap" : 8745 +, "cup" : 8746 +, "int" : 8747 +, "there4" : 8756 +, "sim" : 8764 +, "cong" : 8773 +, "asymp" : 8776 +, "ne" : 8800 +, "equiv" : 8801 +, "le" : 8804 +, "ge" : 8805 +, "sub" : 8834 +, "sup" : 8835 +, "nsub" : 8836 +, "sube" : 8838 +, "supe" : 8839 +, "oplus" : 8853 +, "otimes" : 8855 +, "perp" : 8869 +, "sdot" : 8901 +, "lceil" : 8968 +, "rceil" : 8969 +, "lfloor" : 8970 +, "rfloor" : 8971 +, "lang" : 9001 +, "rang" : 9002 +, "loz" : 9674 +, "spades" : 9824 +, "clubs" : 9827 +, "hearts" : 9829 +, "diams" : 9830 +} + +Object.keys(sax.ENTITIES).forEach(function (key) { + var e = sax.ENTITIES[key] + var s = typeof e === 'number' ? String.fromCharCode(e) : e + sax.ENTITIES[key] = s +}) + +for (var S in sax.STATE) sax.STATE[sax.STATE[S]] = S + +// shorthand +S = sax.STATE + +function emit (parser, event, data) { + parser[event] && parser[event](data) +} + +function emitNode (parser, nodeType, data) { + if (parser.textNode) closeText(parser) + emit(parser, nodeType, data) +} + +function closeText (parser) { + parser.textNode = textopts(parser.opt, parser.textNode) + if (parser.textNode) emit(parser, "ontext", parser.textNode) + parser.textNode = "" +} + +function textopts (opt, text) { + if (opt.trim) text = text.trim() + if (opt.normalize) text = text.replace(/\s+/g, " ") + return text +} + +function error (parser, er) { + closeText(parser) + if (parser.trackPosition) { + er += "\nLine: "+parser.line+ + "\nColumn: "+parser.column+ + "\nChar: "+parser.c + } + er = new Error(er) + parser.error = er + emit(parser, "onerror", er) + return parser +} + +function end (parser) { + if (!parser.closedRoot) strictFail(parser, "Unclosed root tag") + if ((parser.state !== S.BEGIN) && (parser.state !== S.TEXT)) error(parser, "Unexpected end") + closeText(parser) + parser.c = "" + parser.closed = true + emit(parser, "onend") + SAXParser.call(parser, parser.strict, parser.opt) + return parser +} + +function strictFail (parser, message) { + if (typeof parser !== 'object' || !(parser instanceof SAXParser)) + throw new Error('bad call to strictFail'); + if (parser.strict) error(parser, message) +} + +function newTag (parser) { + if (!parser.strict) parser.tagName = parser.tagName[parser.looseCase]() + var parent = parser.tags[parser.tags.length - 1] || parser + , tag = parser.tag = { name : parser.tagName, attributes : {} } + + // will be overridden if tag contails an xmlns="foo" or xmlns:foo="bar" + if (parser.opt.xmlns) tag.ns = parent.ns + parser.attribList.length = 0 +} + +function qname (name, attribute) { + var i = name.indexOf(":") + , qualName = i < 0 ? [ "", name ] : name.split(":") + , prefix = qualName[0] + , local = qualName[1] + + // <x "xmlns"="http://foo"> + if (attribute && name === "xmlns") { + prefix = "xmlns" + local = "" + } + + return { prefix: prefix, local: local } +} + +function attrib (parser) { + if (!parser.strict) parser.attribName = parser.attribName[parser.looseCase]() + + if (parser.attribList.indexOf(parser.attribName) !== -1 || + parser.tag.attributes.hasOwnProperty(parser.attribName)) { + return parser.attribName = parser.attribValue = "" + } + + if (parser.opt.xmlns) { + var qn = qname(parser.attribName, true) + , prefix = qn.prefix + , local = qn.local + + if (prefix === "xmlns") { + // namespace binding attribute; push the binding into scope + if (local === "xml" && parser.attribValue !== XML_NAMESPACE) { + strictFail( parser + , "xml: prefix must be bound to " + XML_NAMESPACE + "\n" + + "Actual: " + parser.attribValue ) + } else if (local === "xmlns" && parser.attribValue !== XMLNS_NAMESPACE) { + strictFail( parser + , "xmlns: prefix must be bound to " + XMLNS_NAMESPACE + "\n" + + "Actual: " + parser.attribValue ) + } else { + var tag = parser.tag + , parent = parser.tags[parser.tags.length - 1] || parser + if (tag.ns === parent.ns) { + tag.ns = Object.create(parent.ns) + } + tag.ns[local] = parser.attribValue + } + } + + // defer onattribute events until all attributes have been seen + // so any new bindings can take effect; preserve attribute order + // so deferred events can be emitted in document order + parser.attribList.push([parser.attribName, parser.attribValue]) + } else { + // in non-xmlns mode, we can emit the event right away + parser.tag.attributes[parser.attribName] = parser.attribValue + emitNode( parser + , "onattribute" + , { name: parser.attribName + , value: parser.attribValue } ) + } + + parser.attribName = parser.attribValue = "" +} + +function openTag (parser, selfClosing) { + if (parser.opt.xmlns) { + // emit namespace binding events + var tag = parser.tag + + // add namespace info to tag + var qn = qname(parser.tagName) + tag.prefix = qn.prefix + tag.local = qn.local + tag.uri = tag.ns[qn.prefix] || "" + + if (tag.prefix && !tag.uri) { + strictFail(parser, "Unbound namespace prefix: " + + JSON.stringify(parser.tagName)) + tag.uri = qn.prefix + } + + var parent = parser.tags[parser.tags.length - 1] || parser + if (tag.ns && parent.ns !== tag.ns) { + Object.keys(tag.ns).forEach(function (p) { + emitNode( parser + , "onopennamespace" + , { prefix: p , uri: tag.ns[p] } ) + }) + } + + // handle deferred onattribute events + // Note: do not apply default ns to attributes: + // http://www.w3.org/TR/REC-xml-names/#defaulting + for (var i = 0, l = parser.attribList.length; i < l; i ++) { + var nv = parser.attribList[i] + var name = nv[0] + , value = nv[1] + , qualName = qname(name, true) + , prefix = qualName.prefix + , local = qualName.local + , uri = prefix == "" ? "" : (tag.ns[prefix] || "") + , a = { name: name + , value: value + , prefix: prefix + , local: local + , uri: uri + } + + // if there's any attributes with an undefined namespace, + // then fail on them now. + if (prefix && prefix != "xmlns" && !uri) { + strictFail(parser, "Unbound namespace prefix: " + + JSON.stringify(prefix)) + a.uri = prefix + } + parser.tag.attributes[name] = a + emitNode(parser, "onattribute", a) + } + parser.attribList.length = 0 + } + + parser.tag.isSelfClosing = !!selfClosing + + // process the tag + parser.sawRoot = true + parser.tags.push(parser.tag) + emitNode(parser, "onopentag", parser.tag) + if (!selfClosing) { + // special case for <script> in non-strict mode. + if (!parser.noscript && parser.tagName.toLowerCase() === "script") { + parser.state = S.SCRIPT + } else { + parser.state = S.TEXT + } + parser.tag = null + parser.tagName = "" + } + parser.attribName = parser.attribValue = "" + parser.attribList.length = 0 +} + +function closeTag (parser) { + if (!parser.tagName) { + strictFail(parser, "Weird empty close tag.") + parser.textNode += "</>" + parser.state = S.TEXT + return + } + + if (parser.script) { + if (parser.tagName !== "script") { + parser.script += "</" + parser.tagName + ">" + parser.tagName = "" + parser.state = S.SCRIPT + return + } + emitNode(parser, "onscript", parser.script) + parser.script = "" + } + + // first make sure that the closing tag actually exists. + // <a><b></c></b></a> will close everything, otherwise. + var t = parser.tags.length + var tagName = parser.tagName + if (!parser.strict) tagName = tagName[parser.looseCase]() + var closeTo = tagName + while (t --) { + var close = parser.tags[t] + if (close.name !== closeTo) { + // fail the first time in strict mode + strictFail(parser, "Unexpected close tag") + } else break + } + + // didn't find it. we already failed for strict, so just abort. + if (t < 0) { + strictFail(parser, "Unmatched closing tag: "+parser.tagName) + parser.textNode += "</" + parser.tagName + ">" + parser.state = S.TEXT + return + } + parser.tagName = tagName + var s = parser.tags.length + while (s --> t) { + var tag = parser.tag = parser.tags.pop() + parser.tagName = parser.tag.name + emitNode(parser, "onclosetag", parser.tagName) + + var x = {} + for (var i in tag.ns) x[i] = tag.ns[i] + + var parent = parser.tags[parser.tags.length - 1] || parser + if (parser.opt.xmlns && tag.ns !== parent.ns) { + // remove namespace bindings introduced by tag + Object.keys(tag.ns).forEach(function (p) { + var n = tag.ns[p] + emitNode(parser, "onclosenamespace", { prefix: p, uri: n }) + }) + } + } + if (t === 0) parser.closedRoot = true + parser.tagName = parser.attribValue = parser.attribName = "" + parser.attribList.length = 0 + parser.state = S.TEXT +} + +function parseEntity (parser) { + var entity = parser.entity + , entityLC = entity.toLowerCase() + , num + , numStr = "" + if (parser.ENTITIES[entity]) + return parser.ENTITIES[entity] + if (parser.ENTITIES[entityLC]) + return parser.ENTITIES[entityLC] + entity = entityLC + if (entity.charAt(0) === "#") { + if (entity.charAt(1) === "x") { + entity = entity.slice(2) + num = parseInt(entity, 16) + numStr = num.toString(16) + } else { + entity = entity.slice(1) + num = parseInt(entity, 10) + numStr = num.toString(10) + } + } + entity = entity.replace(/^0+/, "") + if (numStr.toLowerCase() !== entity) { + strictFail(parser, "Invalid character entity") + return "&"+parser.entity + ";" + } + + return String.fromCodePoint(num) +} + +function write (chunk) { + var parser = this + if (this.error) throw this.error + if (parser.closed) return error(parser, + "Cannot write after close. Assign an onready handler.") + if (chunk === null) return end(parser) + var i = 0, c = "" + while (parser.c = c = chunk.charAt(i++)) { + if (parser.trackPosition) { + parser.position ++ + if (c === "\n") { + parser.line ++ + parser.column = 0 + } else parser.column ++ + } + switch (parser.state) { + + case S.BEGIN: + if (c === "<") { + parser.state = S.OPEN_WAKA + parser.startTagPosition = parser.position + } else if (not(whitespace,c)) { + // have to process this as a text node. + // weird, but happens. + strictFail(parser, "Non-whitespace before first tag.") + parser.textNode = c + parser.state = S.TEXT + } + continue + + case S.TEXT: + if (parser.sawRoot && !parser.closedRoot) { + var starti = i-1 + while (c && c!=="<" && c!=="&") { + c = chunk.charAt(i++) + if (c && parser.trackPosition) { + parser.position ++ + if (c === "\n") { + parser.line ++ + parser.column = 0 + } else parser.column ++ + } + } + parser.textNode += chunk.substring(starti, i-1) + } + if (c === "<") { + parser.state = S.OPEN_WAKA + parser.startTagPosition = parser.position + } else { + if (not(whitespace, c) && (!parser.sawRoot || parser.closedRoot)) + strictFail(parser, "Text data outside of root node.") + if (c === "&") parser.state = S.TEXT_ENTITY + else parser.textNode += c + } + continue + + case S.SCRIPT: + // only non-strict + if (c === "<") { + parser.state = S.SCRIPT_ENDING + } else parser.script += c + continue + + case S.SCRIPT_ENDING: + if (c === "/") { + parser.state = S.CLOSE_TAG + } else { + parser.script += "<" + c + parser.state = S.SCRIPT + } + continue + + case S.OPEN_WAKA: + // either a /, ?, !, or text is coming next. + if (c === "!") { + parser.state = S.SGML_DECL + parser.sgmlDecl = "" + } else if (is(whitespace, c)) { + // wait for it... + } else if (is(nameStart,c)) { + parser.state = S.OPEN_TAG + parser.tagName = c + } else if (c === "/") { + parser.state = S.CLOSE_TAG + parser.tagName = "" + } else if (c === "?") { + parser.state = S.PROC_INST + parser.procInstName = parser.procInstBody = "" + } else { + strictFail(parser, "Unencoded <") + // if there was some whitespace, then add that in. + if (parser.startTagPosition + 1 < parser.position) { + var pad = parser.position - parser.startTagPosition + c = new Array(pad).join(" ") + c + } + parser.textNode += "<" + c + parser.state = S.TEXT + } + continue + + case S.SGML_DECL: + if ((parser.sgmlDecl+c).toUpperCase() === CDATA) { + emitNode(parser, "onopencdata") + parser.state = S.CDATA + parser.sgmlDecl = "" + parser.cdata = "" + } else if (parser.sgmlDecl+c === "--") { + parser.state = S.COMMENT + parser.comment = "" + parser.sgmlDecl = "" + } else if ((parser.sgmlDecl+c).toUpperCase() === DOCTYPE) { + parser.state = S.DOCTYPE + if (parser.doctype || parser.sawRoot) strictFail(parser, + "Inappropriately located doctype declaration") + parser.doctype = "" + parser.sgmlDecl = "" + } else if (c === ">") { + emitNode(parser, "onsgmldeclaration", parser.sgmlDecl) + parser.sgmlDecl = "" + parser.state = S.TEXT + } else if (is(quote, c)) { + parser.state = S.SGML_DECL_QUOTED + parser.sgmlDecl += c + } else parser.sgmlDecl += c + continue + + case S.SGML_DECL_QUOTED: + if (c === parser.q) { + parser.state = S.SGML_DECL + parser.q = "" + } + parser.sgmlDecl += c + continue + + case S.DOCTYPE: + if (c === ">") { + parser.state = S.TEXT + emitNode(parser, "ondoctype", parser.doctype) + parser.doctype = true // just remember that we saw it. + } else { + parser.doctype += c + if (c === "[") parser.state = S.DOCTYPE_DTD + else if (is(quote, c)) { + parser.state = S.DOCTYPE_QUOTED + parser.q = c + } + } + continue + + case S.DOCTYPE_QUOTED: + parser.doctype += c + if (c === parser.q) { + parser.q = "" + parser.state = S.DOCTYPE + } + continue + + case S.DOCTYPE_DTD: + parser.doctype += c + if (c === "]") parser.state = S.DOCTYPE + else if (is(quote,c)) { + parser.state = S.DOCTYPE_DTD_QUOTED + parser.q = c + } + continue + + case S.DOCTYPE_DTD_QUOTED: + parser.doctype += c + if (c === parser.q) { + parser.state = S.DOCTYPE_DTD + parser.q = "" + } + continue + + case S.COMMENT: + if (c === "-") parser.state = S.COMMENT_ENDING + else parser.comment += c + continue + + case S.COMMENT_ENDING: + if (c === "-") { + parser.state = S.COMMENT_ENDED + parser.comment = textopts(parser.opt, parser.comment) + if (parser.comment) emitNode(parser, "oncomment", parser.comment) + parser.comment = "" + } else { + parser.comment += "-" + c + parser.state = S.COMMENT + } + continue + + case S.COMMENT_ENDED: + if (c !== ">") { + strictFail(parser, "Malformed comment") + // allow <!-- blah -- bloo --> in non-strict mode, + // which is a comment of " blah -- bloo " + parser.comment += "--" + c + parser.state = S.COMMENT + } else parser.state = S.TEXT + continue + + case S.CDATA: + if (c === "]") parser.state = S.CDATA_ENDING + else parser.cdata += c + continue + + case S.CDATA_ENDING: + if (c === "]") parser.state = S.CDATA_ENDING_2 + else { + parser.cdata += "]" + c + parser.state = S.CDATA + } + continue + + case S.CDATA_ENDING_2: + if (c === ">") { + if (parser.cdata) emitNode(parser, "oncdata", parser.cdata) + emitNode(parser, "onclosecdata") + parser.cdata = "" + parser.state = S.TEXT + } else if (c === "]") { + parser.cdata += "]" + } else { + parser.cdata += "]]" + c + parser.state = S.CDATA + } + continue + + case S.PROC_INST: + if (c === "?") parser.state = S.PROC_INST_ENDING + else if (is(whitespace, c)) parser.state = S.PROC_INST_BODY + else parser.procInstName += c + continue + + case S.PROC_INST_BODY: + if (!parser.procInstBody && is(whitespace, c)) continue + else if (c === "?") parser.state = S.PROC_INST_ENDING + else parser.procInstBody += c + continue + + case S.PROC_INST_ENDING: + if (c === ">") { + emitNode(parser, "onprocessinginstruction", { + name : parser.procInstName, + body : parser.procInstBody + }) + parser.procInstName = parser.procInstBody = "" + parser.state = S.TEXT + } else { + parser.procInstBody += "?" + c + parser.state = S.PROC_INST_BODY + } + continue + + case S.OPEN_TAG: + if (is(nameBody, c)) parser.tagName += c + else { + newTag(parser) + if (c === ">") openTag(parser) + else if (c === "/") parser.state = S.OPEN_TAG_SLASH + else { + if (not(whitespace, c)) strictFail( + parser, "Invalid character in tag name") + parser.state = S.ATTRIB + } + } + continue + + case S.OPEN_TAG_SLASH: + if (c === ">") { + openTag(parser, true) + closeTag(parser) + } else { + strictFail(parser, "Forward-slash in opening tag not followed by >") + parser.state = S.ATTRIB + } + continue + + case S.ATTRIB: + // haven't read the attribute name yet. + if (is(whitespace, c)) continue + else if (c === ">") openTag(parser) + else if (c === "/") parser.state = S.OPEN_TAG_SLASH + else if (is(nameStart, c)) { + parser.attribName = c + parser.attribValue = "" + parser.state = S.ATTRIB_NAME + } else strictFail(parser, "Invalid attribute name") + continue + + case S.ATTRIB_NAME: + if (c === "=") parser.state = S.ATTRIB_VALUE + else if (c === ">") { + strictFail(parser, "Attribute without value") + parser.attribValue = parser.attribName + attrib(parser) + openTag(parser) + } + else if (is(whitespace, c)) parser.state = S.ATTRIB_NAME_SAW_WHITE + else if (is(nameBody, c)) parser.attribName += c + else strictFail(parser, "Invalid attribute name") + continue + + case S.ATTRIB_NAME_SAW_WHITE: + if (c === "=") parser.state = S.ATTRIB_VALUE + else if (is(whitespace, c)) continue + else { + strictFail(parser, "Attribute without value") + parser.tag.attributes[parser.attribName] = "" + parser.attribValue = "" + emitNode(parser, "onattribute", + { name : parser.attribName, value : "" }) + parser.attribName = "" + if (c === ">") openTag(parser) + else if (is(nameStart, c)) { + parser.attribName = c + parser.state = S.ATTRIB_NAME + } else { + strictFail(parser, "Invalid attribute name") + parser.state = S.ATTRIB + } + } + continue + + case S.ATTRIB_VALUE: + if (is(whitespace, c)) continue + else if (is(quote, c)) { + parser.q = c + parser.state = S.ATTRIB_VALUE_QUOTED + } else { + strictFail(parser, "Unquoted attribute value") + parser.state = S.ATTRIB_VALUE_UNQUOTED + parser.attribValue = c + } + continue + + case S.ATTRIB_VALUE_QUOTED: + if (c !== parser.q) { + if (c === "&") parser.state = S.ATTRIB_VALUE_ENTITY_Q + else parser.attribValue += c + continue + } + attrib(parser) + parser.q = "" + parser.state = S.ATTRIB_VALUE_CLOSED + continue + + case S.ATTRIB_VALUE_CLOSED: + if (is(whitespace, c)) { + parser.state = S.ATTRIB + } else if (c === ">") openTag(parser) + else if (c === "/") parser.state = S.OPEN_TAG_SLASH + else if (is(nameStart, c)) { + strictFail(parser, "No whitespace between attributes") + parser.attribName = c + parser.attribValue = "" + parser.state = S.ATTRIB_NAME + } else strictFail(parser, "Invalid attribute name") + continue + + case S.ATTRIB_VALUE_UNQUOTED: + if (not(attribEnd,c)) { + if (c === "&") parser.state = S.ATTRIB_VALUE_ENTITY_U + else parser.attribValue += c + continue + } + attrib(parser) + if (c === ">") openTag(parser) + else parser.state = S.ATTRIB + continue + + case S.CLOSE_TAG: + if (!parser.tagName) { + if (is(whitespace, c)) continue + else if (not(nameStart, c)) { + if (parser.script) { + parser.script += "</" + c + parser.state = S.SCRIPT + } else { + strictFail(parser, "Invalid tagname in closing tag.") + } + } else parser.tagName = c + } + else if (c === ">") closeTag(parser) + else if (is(nameBody, c)) parser.tagName += c + else if (parser.script) { + parser.script += "</" + parser.tagName + parser.tagName = "" + parser.state = S.SCRIPT + } else { + if (not(whitespace, c)) strictFail(parser, + "Invalid tagname in closing tag") + parser.state = S.CLOSE_TAG_SAW_WHITE + } + continue + + case S.CLOSE_TAG_SAW_WHITE: + if (is(whitespace, c)) continue + if (c === ">") closeTag(parser) + else strictFail(parser, "Invalid characters in closing tag") + continue + + case S.TEXT_ENTITY: + case S.ATTRIB_VALUE_ENTITY_Q: + case S.ATTRIB_VALUE_ENTITY_U: + switch(parser.state) { + case S.TEXT_ENTITY: + var returnState = S.TEXT, buffer = "textNode" + break + + case S.ATTRIB_VALUE_ENTITY_Q: + var returnState = S.ATTRIB_VALUE_QUOTED, buffer = "attribValue" + break + + case S.ATTRIB_VALUE_ENTITY_U: + var returnState = S.ATTRIB_VALUE_UNQUOTED, buffer = "attribValue" + break + } + if (c === ";") { + parser[buffer] += parseEntity(parser) + parser.entity = "" + parser.state = returnState + } + else if (is(entity, c)) parser.entity += c + else { + strictFail(parser, "Invalid character entity") + parser[buffer] += "&" + parser.entity + c + parser.entity = "" + parser.state = returnState + } + continue + + default: + throw new Error(parser, "Unknown state: " + parser.state) + } + } // while + // cdata blocks can get very big under normal conditions. emit and move on. + // if (parser.state === S.CDATA && parser.cdata) { + // emitNode(parser, "oncdata", parser.cdata) + // parser.cdata = "" + // } + if (parser.position >= parser.bufferCheckPosition) checkBufferLength(parser) + return parser +} + +/*! http://mths.be/fromcodepoint v0.1.0 by @mathias */ +if (!String.fromCodePoint) { + (function() { + var stringFromCharCode = String.fromCharCode; + var floor = Math.floor; + var fromCodePoint = function() { + var MAX_SIZE = 0x4000; + var codeUnits = []; + var highSurrogate; + var lowSurrogate; + var index = -1; + var length = arguments.length; + if (!length) { + return ''; + } + var result = ''; + while (++index < length) { + var codePoint = Number(arguments[index]); + if ( + !isFinite(codePoint) || // `NaN`, `+Infinity`, or `-Infinity` + codePoint < 0 || // not a valid Unicode code point + codePoint > 0x10FFFF || // not a valid Unicode code point + floor(codePoint) != codePoint // not an integer + ) { + throw RangeError('Invalid code point: ' + codePoint); + } + if (codePoint <= 0xFFFF) { // BMP code point + codeUnits.push(codePoint); + } else { // Astral code point; split in surrogate halves + // http://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae + codePoint -= 0x10000; + highSurrogate = (codePoint >> 10) + 0xD800; + lowSurrogate = (codePoint % 0x400) + 0xDC00; + codeUnits.push(highSurrogate, lowSurrogate); + } + if (index + 1 == length || codeUnits.length > MAX_SIZE) { + result += stringFromCharCode.apply(null, codeUnits); + codeUnits.length = 0; + } + } + return result; + }; + if (Object.defineProperty) { + Object.defineProperty(String, 'fromCodePoint', { + 'value': fromCodePoint, + 'configurable': true, + 'writable': true + }); + } else { + String.fromCodePoint = fromCodePoint; + } + }()); +} + +})(typeof exports === "undefined" ? sax = {} : exports); + +}).call(this,undefined) + +},{"undefined":undefined}],22:[function(_dereq_,module,exports){ +/** + * Tiny stack for browser or server + * + * @author Jason Mulligan <jason.mulligan@avoidwork.com> + * @copyright 2014 Jason Mulligan + * @license BSD-3 <https://raw.github.com/avoidwork/tiny-stack/master/LICENSE> + * @link http://avoidwork.github.io/tiny-stack + * @module tiny-stack + * @version 0.1.0 + */ + +( function ( global ) { + +"use strict"; + +/** + * TinyStack + * + * @constructor + */ +function TinyStack () { + this.data = [null]; + this.top = 0; +} + +/** + * Clears the stack + * + * @method clear + * @memberOf TinyStack + * @return {Object} {@link TinyStack} + */ +TinyStack.prototype.clear = function clear () { + this.data = [null]; + this.top = 0; + + return this; +}; + +/** + * Gets the size of the stack + * + * @method length + * @memberOf TinyStack + * @return {Number} Size of stack + */ +TinyStack.prototype.length = function length () { + return this.top; +}; + +/** + * Gets the item at the top of the stack + * + * @method peek + * @memberOf TinyStack + * @return {Mixed} Item at the top of the stack + */ +TinyStack.prototype.peek = function peek () { + return this.data[this.top]; +}; + +/** + * Gets & removes the item at the top of the stack + * + * @method pop + * @memberOf TinyStack + * @return {Mixed} Item at the top of the stack + */ +TinyStack.prototype.pop = function pop () { + if ( this.top > 0 ) { + this.top--; + + return this.data.pop(); + } + else { + return undefined; + } +}; + +/** + * Pushes an item onto the stack + * + * @method push + * @memberOf TinyStack + * @return {Object} {@link TinyStack} + */ +TinyStack.prototype.push = function push ( arg ) { + this.data[++this.top] = arg; + + return this; +}; + +/** + * TinyStack factory + * + * @method factory + * @return {Object} {@link TinyStack} + */ +function factory () { + return new TinyStack(); +} + +// Node, AMD & window supported +if ( typeof exports != "undefined" ) { + module.exports = factory; +} +else if ( typeof define == "function" ) { + define( function () { + return factory; + } ); +} +else { + global.stack = factory; +} +} )( this ); + +},{}],23:[function(_dereq_,module,exports){ +module.exports = _dereq_(27); +},{"27":27}],24:[function(_dereq_,module,exports){ +'use strict'; + +function Base() { } + +Base.prototype.get = function(name) { + return this.$model.properties.get(this, name); +}; + +Base.prototype.set = function(name, value) { + this.$model.properties.set(this, name, value); +}; + + +module.exports = Base; +},{}],25:[function(_dereq_,module,exports){ +'use strict'; + +var pick = _dereq_(180), + assign = _dereq_(175), + forEach = _dereq_(84); + +var parseNameNs = _dereq_(28).parseName; + + +function DescriptorBuilder(nameNs) { + this.ns = nameNs; + this.name = nameNs.name; + this.allTypes = []; + this.properties = []; + this.propertiesByName = {}; +} + +module.exports = DescriptorBuilder; + + +DescriptorBuilder.prototype.build = function() { + return pick(this, [ 'ns', 'name', 'allTypes', 'properties', 'propertiesByName', 'bodyProperty' ]); +}; + +DescriptorBuilder.prototype.addProperty = function(p, idx) { + this.addNamedProperty(p, true); + + var properties = this.properties; + + if (idx !== undefined) { + properties.splice(idx, 0, p); + } else { + properties.push(p); + } +}; + + +DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty) { + var oldNameNs = oldProperty.ns; + + var props = this.properties, + propertiesByName = this.propertiesByName, + rename = oldProperty.name !== newProperty.name; + + if (oldProperty.isBody) { + + if (!newProperty.isBody) { + throw new Error( + 'property <' + newProperty.ns.name + '> must be body property ' + + 'to refine <' + oldProperty.ns.name + '>'); + } + + // TODO: Check compatibility + this.setBodyProperty(newProperty, false); + } + + // replacing the named property is intentional + // thus, validate only if this is a "rename" operation + this.addNamedProperty(newProperty, rename); + + // replace old property at index with new one + var idx = props.indexOf(oldProperty); + if (idx === -1) { + throw new Error('property <' + oldNameNs.name + '> not found in property list'); + } + + props[idx] = newProperty; + + // replace propertiesByName entry with new property + propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty; +}; + + +DescriptorBuilder.prototype.redefineProperty = function(p) { + + var nsPrefix = p.ns.prefix; + var parts = p.redefines.split('#'); + + var name = parseNameNs(parts[0], nsPrefix); + var attrName = parseNameNs(parts[1], name.prefix).name; + + var redefinedProperty = this.propertiesByName[attrName]; + if (!redefinedProperty) { + throw new Error('refined property <' + attrName + '> not found'); + } else { + this.replaceProperty(redefinedProperty, p); + } + + delete p.redefines; +}; + +DescriptorBuilder.prototype.addNamedProperty = function(p, validate) { + var ns = p.ns, + propsByName = this.propertiesByName; + + if (validate) { + this.assertNotDefined(p, ns.name); + this.assertNotDefined(p, ns.localName); + } + + propsByName[ns.name] = propsByName[ns.localName] = p; +}; + +DescriptorBuilder.prototype.removeNamedProperty = function(p) { + var ns = p.ns, + propsByName = this.propertiesByName; + + delete propsByName[ns.name]; + delete propsByName[ns.localName]; +}; + +DescriptorBuilder.prototype.setBodyProperty = function(p, validate) { + + if (validate && this.bodyProperty) { + throw new Error( + 'body property defined multiple times ' + + '(<' + this.bodyProperty.ns.name + '>, <' + p.ns.name + '>)'); + } + + this.bodyProperty = p; +}; + +DescriptorBuilder.prototype.addIdProperty = function(name) { + var nameNs = parseNameNs(name, this.ns.prefix); + + var p = { + name: nameNs.localName, + type: 'String', + isAttr: true, + ns: nameNs + }; + + // ensure that id is always the first attribute (if present) + this.addProperty(p, 0); +}; + +DescriptorBuilder.prototype.assertNotDefined = function(p, name) { + var propertyName = p.name, + definedProperty = this.propertiesByName[propertyName]; + + if (definedProperty) { + throw new Error( + 'property <' + propertyName + '> already defined; ' + + 'override of <' + definedProperty.definedBy.ns.name + '#' + definedProperty.ns.name + '> by ' + + '<' + p.definedBy.ns.name + '#' + p.ns.name + '> not allowed without redefines'); + } +}; + +DescriptorBuilder.prototype.hasProperty = function(name) { + return this.propertiesByName[name]; +}; + +DescriptorBuilder.prototype.addTrait = function(t) { + + var allTypes = this.allTypes; + + if (allTypes.indexOf(t) !== -1) { + return; + } + + forEach(t.properties, function(p) { + + // clone property to allow extensions + p = assign({}, p, { + name: p.ns.localName + }); + + Object.defineProperty(p, 'definedBy', { + value: t + }); + + // add redefine support + if (p.redefines) { + this.redefineProperty(p); + } else { + if (p.isBody) { + this.setBodyProperty(p); + } + this.addProperty(p); + } + }, this); + + allTypes.push(t); +}; + +},{"175":175,"180":180,"28":28,"84":84}],26:[function(_dereq_,module,exports){ +'use strict'; + +var forEach = _dereq_(84); + +var Base = _dereq_(24); + + +function Factory(model, properties) { + this.model = model; + this.properties = properties; +} + +module.exports = Factory; + + +Factory.prototype.createType = function(descriptor) { + + var model = this.model; + + var props = this.properties, + prototype = Object.create(Base.prototype); + + // initialize default values + forEach(descriptor.properties, function(p) { + if (!p.isMany && p.default !== undefined) { + prototype[p.name] = p.default; + } + }); + + props.defineModel(prototype, model); + props.defineDescriptor(prototype, descriptor); + + var name = descriptor.ns.name; + + /** + * The new type constructor + */ + function ModdleElement(attrs) { + props.define(this, '$type', { value: name, enumerable: true }); + props.define(this, '$attrs', { value: {} }); + props.define(this, '$parent', { writable: true }); + + forEach(attrs, function(val, key) { + this.set(key, val); + }, this); + } + + ModdleElement.prototype = prototype; + + ModdleElement.hasType = prototype.$instanceOf = this.model.hasType; + + // static links + props.defineModel(ModdleElement, model); + props.defineDescriptor(ModdleElement, descriptor); + + return ModdleElement; +}; +},{"24":24,"84":84}],27:[function(_dereq_,module,exports){ +'use strict'; + +var isString = _dereq_(172), + isObject = _dereq_(170), + forEach = _dereq_(84), + find = _dereq_(83); + + +var Factory = _dereq_(26), + Registry = _dereq_(30), + Properties = _dereq_(29); + +var parseNameNs = _dereq_(28).parseName; + + +//// Moddle implementation ///////////////////////////////////////////////// + +/** + * @class Moddle + * + * A model that can be used to create elements of a specific type. + * + * @example + * + * var Moddle = require('moddle'); + * + * var pkg = { + * name: 'mypackage', + * prefix: 'my', + * types: [ + * { name: 'Root' } + * ] + * }; + * + * var moddle = new Moddle([pkg]); + * + * @param {Array<Package>} packages the packages to contain + * @param {Object} options additional options to pass to the model + */ +function Moddle(packages, options) { + + options = options || {}; + + this.properties = new Properties(this); + + this.factory = new Factory(this, this.properties); + this.registry = new Registry(packages, this.properties, options); + + this.typeCache = {}; +} + +module.exports = Moddle; + + +/** + * Create an instance of the specified type. + * + * @method Moddle#create + * + * @example + * + * var foo = moddle.create('my:Foo'); + * var bar = moddle.create('my:Bar', { id: 'BAR_1' }); + * + * @param {String|Object} descriptor the type descriptor or name know to the model + * @param {Object} attrs a number of attributes to initialize the model instance with + * @return {Object} model instance + */ +Moddle.prototype.create = function(descriptor, attrs) { + var Type = this.getType(descriptor); + + if (!Type) { + throw new Error('unknown type <' + descriptor + '>'); + } + + return new Type(attrs); +}; + + +/** + * Returns the type representing a given descriptor + * + * @method Moddle#getType + * + * @example + * + * var Foo = moddle.getType('my:Foo'); + * var foo = new Foo({ 'id' : 'FOO_1' }); + * + * @param {String|Object} descriptor the type descriptor or name know to the model + * @return {Object} the type representing the descriptor + */ +Moddle.prototype.getType = function(descriptor) { + + var cache = this.typeCache; + + var name = isString(descriptor) ? descriptor : descriptor.ns.name; + + var type = cache[name]; + + if (!type) { + descriptor = this.registry.getEffectiveDescriptor(name); + type = cache[name] = this.factory.createType(descriptor); + } + + return type; +}; + + +/** + * Creates an any-element type to be used within model instances. + * + * This can be used to create custom elements that lie outside the meta-model. + * The created element contains all the meta-data required to serialize it + * as part of meta-model elements. + * + * @method Moddle#createAny + * + * @example + * + * var foo = moddle.createAny('vendor:Foo', 'http://vendor', { + * value: 'bar' + * }); + * + * var container = moddle.create('my:Container', 'http://my', { + * any: [ foo ] + * }); + * + * // go ahead and serialize the stuff + * + * + * @param {String} name the name of the element + * @param {String} nsUri the namespace uri of the element + * @param {Object} [properties] a map of properties to initialize the instance with + * @return {Object} the any type instance + */ +Moddle.prototype.createAny = function(name, nsUri, properties) { + + var nameNs = parseNameNs(name); + + var element = { + $type: name + }; + + var descriptor = { + name: name, + isGeneric: true, + ns: { + prefix: nameNs.prefix, + localName: nameNs.localName, + uri: nsUri + } + }; + + this.properties.defineDescriptor(element, descriptor); + this.properties.defineModel(element, this); + this.properties.define(element, '$parent', { enumerable: false, writable: true }); + + forEach(properties, function(a, key) { + if (isObject(a) && a.value !== undefined) { + element[a.name] = a.value; + } else { + element[key] = a; + } + }); + + return element; +}; + +/** + * Returns a registered package by uri or prefix + * + * @return {Object} the package + */ +Moddle.prototype.getPackage = function(uriOrPrefix) { + return this.registry.getPackage(uriOrPrefix); +}; + +/** + * Returns a snapshot of all known packages + * + * @return {Object} the package + */ +Moddle.prototype.getPackages = function() { + return this.registry.getPackages(); +}; + +/** + * Returns the descriptor for an element + */ +Moddle.prototype.getElementDescriptor = function(element) { + return element.$descriptor; +}; + +/** + * Returns true if the given descriptor or instance + * represents the given type. + * + * May be applied to this, if element is omitted. + */ +Moddle.prototype.hasType = function(element, type) { + if (type === undefined) { + type = element; + element = this; + } + + var descriptor = element.$model.getElementDescriptor(element); + + return !!find(descriptor.allTypes, function(t) { + return t.name === type; + }); +}; + + +/** + * Returns the descriptor of an elements named property + */ +Moddle.prototype.getPropertyDescriptor = function(element, property) { + return this.getElementDescriptor(element).propertiesByName[property]; +}; + +},{"170":170,"172":172,"26":26,"28":28,"29":29,"30":30,"83":83,"84":84}],28:[function(_dereq_,module,exports){ +'use strict'; + +/** + * Parses a namespaced attribute name of the form (ns:)localName to an object, + * given a default prefix to assume in case no explicit namespace is given. + * + * @param {String} name + * @param {String} [defaultPrefix] the default prefix to take, if none is present. + * + * @return {Object} the parsed name + */ +module.exports.parseName = function(name, defaultPrefix) { + var parts = name.split(/:/), + localName, prefix; + + // no prefix (i.e. only local name) + if (parts.length === 1) { + localName = name; + prefix = defaultPrefix; + } else + // prefix + local name + if (parts.length === 2) { + localName = parts[1]; + prefix = parts[0]; + } else { + throw new Error('expected <prefix:localName> or <localName>, got ' + name); + } + + name = (prefix ? prefix + ':' : '') + localName; + + return { + name: name, + prefix: prefix, + localName: localName + }; +}; +},{}],29:[function(_dereq_,module,exports){ +'use strict'; + + +/** + * A utility that gets and sets properties of model elements. + * + * @param {Model} model + */ +function Properties(model) { + this.model = model; +} + +module.exports = Properties; + + +/** + * Sets a named property on the target element + * + * @param {Object} target + * @param {String} name + * @param {Object} value + */ +Properties.prototype.set = function(target, name, value) { + + var property = this.model.getPropertyDescriptor(target, name); + + if (!property) { + target.$attrs[name] = value; + } else { + Object.defineProperty(target, property.name, { + enumerable: !property.isReference, + writable: true, + value: value + }); + } +}; + +/** + * Returns the named property of the given element + * + * @param {Object} target + * @param {String} name + * + * @return {Object} + */ +Properties.prototype.get = function(target, name) { + + var property = this.model.getPropertyDescriptor(target, name); + + if (!property) { + return target.$attrs[name]; + } + + var propertyName = property.name; + + // check if access to collection property and lazily initialize it + if (!target[propertyName] && property.isMany) { + Object.defineProperty(target, propertyName, { + enumerable: !property.isReference, + writable: true, + value: [] + }); + } + + return target[propertyName]; +}; + + +/** + * Define a property on the target element + * + * @param {Object} target + * @param {String} name + * @param {Object} options + */ +Properties.prototype.define = function(target, name, options) { + Object.defineProperty(target, name, options); +}; + + +/** + * Define the descriptor for an element + */ +Properties.prototype.defineDescriptor = function(target, descriptor) { + this.define(target, '$descriptor', { value: descriptor }); +}; + +/** + * Define the model for an element + */ +Properties.prototype.defineModel = function(target, model) { + this.define(target, '$model', { value: model }); +}; +},{}],30:[function(_dereq_,module,exports){ +'use strict'; + +var assign = _dereq_(175), + forEach = _dereq_(84); + +var Types = _dereq_(31), + DescriptorBuilder = _dereq_(25); + +var parseNameNs = _dereq_(28).parseName, + isBuiltInType = Types.isBuiltIn; + + +function Registry(packages, properties, options) { + this.options = assign({ generateId: 'id' }, options || {}); + + this.packageMap = {}; + this.typeMap = {}; + + this.packages = []; + + this.properties = properties; + + forEach(packages, this.registerPackage, this); +} + +module.exports = Registry; + + +Registry.prototype.getPackage = function(uriOrPrefix) { + return this.packageMap[uriOrPrefix]; +}; + +Registry.prototype.getPackages = function() { + return this.packages; +}; + + +Registry.prototype.registerPackage = function(pkg) { + + // copy package + pkg = assign({}, pkg); + + // register types + forEach(pkg.types, function(descriptor) { + this.registerType(descriptor, pkg); + }, this); + + this.packageMap[pkg.uri] = this.packageMap[pkg.prefix] = pkg; + this.packages.push(pkg); +}; + + +/** + * Register a type from a specific package with us + */ +Registry.prototype.registerType = function(type, pkg) { + + type = assign({}, type, { + superClass: (type.superClass || []).slice(), + extends: (type.extends || []).slice(), + properties: (type.properties || []).slice() + }); + + var ns = parseNameNs(type.name, pkg.prefix), + name = ns.name, + propertiesByName = {}; + + // parse properties + forEach(type.properties, function(p) { + + // namespace property names + var propertyNs = parseNameNs(p.name, ns.prefix), + propertyName = propertyNs.name; + + // namespace property types + if (!isBuiltInType(p.type)) { + p.type = parseNameNs(p.type, propertyNs.prefix).name; + } + + assign(p, { + ns: propertyNs, + name: propertyName + }); + + propertiesByName[propertyName] = p; + }); + + // update ns + name + assign(type, { + ns: ns, + name: name, + propertiesByName: propertiesByName + }); + + forEach(type.extends, function(extendsName) { + var extended = this.typeMap[extendsName]; + + extended.traits = extended.traits || []; + extended.traits.push(name); + }, this); + + // link to package + this.definePackage(type, pkg); + + // register + this.typeMap[name] = type; +}; + + +/** + * Traverse the type hierarchy from bottom to top. + */ +Registry.prototype.mapTypes = function(nsName, iterator) { + + var type = isBuiltInType(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name]; + + var self = this; + + /** + * Traverse the selected super type or trait + * + * @param {String} cls + */ + function traverseSuper(cls) { + var parentNs = parseNameNs(cls, isBuiltInType(cls) ? '' : nsName.prefix); + self.mapTypes(parentNs, iterator); + } + + if (!type) { + throw new Error('unknown type <' + nsName.name + '>'); + } + + forEach(type.superClass, traverseSuper); + + iterator(type); + + forEach(type.traits, traverseSuper); +}; + + +/** + * Returns the effective descriptor for a type. + * + * @param {String} type the namespaced name (ns:localName) of the type + * + * @return {Descriptor} the resulting effective descriptor + */ +Registry.prototype.getEffectiveDescriptor = function(name) { + + var nsName = parseNameNs(name); + + var builder = new DescriptorBuilder(nsName); + + this.mapTypes(nsName, function(type) { + builder.addTrait(type); + }); + + // check we have an id assigned + var id = this.options.generateId; + if (id && !builder.hasProperty(id)) { + builder.addIdProperty(id); + } + + var descriptor = builder.build(); + + // define package link + this.definePackage(descriptor, descriptor.allTypes[descriptor.allTypes.length - 1].$pkg); + + return descriptor; +}; + + +Registry.prototype.definePackage = function(target, pkg) { + this.properties.define(target, '$pkg', { value: pkg }); +}; +},{"175":175,"25":25,"28":28,"31":31,"84":84}],31:[function(_dereq_,module,exports){ +'use strict'; + +/** + * Built-in moddle types + */ +var BUILTINS = { + String: true, + Boolean: true, + Integer: true, + Real: true, + Element: true +}; + +/** + * Converters for built in types from string representations + */ +var TYPE_CONVERTERS = { + String: function(s) { return s; }, + Boolean: function(s) { return s === 'true'; }, + Integer: function(s) { return parseInt(s, 10); }, + Real: function(s) { return parseFloat(s, 10); } +}; + +/** + * Convert a type to its real representation + */ +module.exports.coerceType = function(type, value) { + + var converter = TYPE_CONVERTERS[type]; + + if (converter) { + return converter(value); + } else { + return value; + } +}; + +/** + * Return whether the given type is built-in + */ +module.exports.isBuiltIn = function(type) { + return !!BUILTINS[type]; +}; + +/** + * Return whether the given type is simple + */ +module.exports.isSimple = function(type) { + return !!TYPE_CONVERTERS[type]; +}; +},{}],32:[function(_dereq_,module,exports){ +module.exports={ + "name": "BPMN20", + "uri": "http://www.omg.org/spec/BPMN/20100524/MODEL", + "associations": [], + "types": [ + { + "name": "Interface", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "operations", + "type": "Operation", + "isMany": true + }, + { + "name": "implementationRef", + "type": "String", + "isAttr": true + } + ] + }, + { + "name": "Operation", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "inMessageRef", + "type": "Message", + "isAttr": true, + "isReference": true + }, + { + "name": "outMessageRef", + "type": "Message", + "isAttr": true, + "isReference": true + }, + { + "name": "errorRefs", + "type": "Error", + "isMany": true, + "isReference": true + }, + { + "name": "implementationRef", + "type": "String", + "isAttr": true + } + ] + }, + { + "name": "EndPoint", + "superClass": [ + "RootElement" + ] + }, + { + "name": "Auditing", + "superClass": [ + "BaseElement" + ] + }, + { + "name": "GlobalTask", + "superClass": [ + "CallableElement" + ], + "properties": [ + { + "name": "resources", + "type": "ResourceRole", + "isMany": true + } + ] + }, + { + "name": "Monitoring", + "superClass": [ + "BaseElement" + ] + }, + { + "name": "Performer", + "superClass": [ + "ResourceRole" + ] + }, + { + "name": "Process", + "superClass": [ + "FlowElementsContainer", + "CallableElement" + ], + "properties": [ + { + "name": "processType", + "type": "ProcessType", + "isAttr": true + }, + { + "name": "isClosed", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "auditing", + "type": "Auditing" + }, + { + "name": "monitoring", + "type": "Monitoring" + }, + { + "name": "properties", + "type": "Property", + "isMany": true + }, + { + "name": "supports", + "type": "Process", + "isMany": true, + "isReference": true + }, + { + "name": "definitionalCollaborationRef", + "type": "Collaboration", + "isAttr": true, + "isReference": true + }, + { + "name": "isExecutable", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "resources", + "type": "ResourceRole", + "isMany": true + }, + { + "name": "artifacts", + "type": "Artifact", + "isMany": true + }, + { + "name": "correlationSubscriptions", + "type": "CorrelationSubscription", + "isMany": true + } + ] + }, + { + "name": "LaneSet", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "lanes", + "type": "Lane", + "isMany": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "Lane", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "childLaneSet", + "type": "LaneSet", + "serialize": "xsi:type" + }, + { + "name": "partitionElementRef", + "type": "BaseElement", + "isAttr": true, + "isReference": true + }, + { + "name": "flowNodeRef", + "type": "FlowNode", + "isMany": true, + "isReference": true + }, + { + "name": "partitionElement", + "type": "BaseElement" + } + ] + }, + { + "name": "GlobalManualTask", + "superClass": [ + "GlobalTask" + ] + }, + { + "name": "ManualTask", + "superClass": [ + "Task" + ] + }, + { + "name": "UserTask", + "superClass": [ + "Task" + ], + "properties": [ + { + "name": "renderings", + "type": "Rendering", + "isMany": true + }, + { + "name": "implementation", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "Rendering", + "superClass": [ + "BaseElement" + ] + }, + { + "name": "HumanPerformer", + "superClass": [ + "Performer" + ] + }, + { + "name": "PotentialOwner", + "superClass": [ + "HumanPerformer" + ] + }, + { + "name": "GlobalUserTask", + "superClass": [ + "GlobalTask" + ], + "properties": [ + { + "name": "implementation", + "isAttr": true, + "type": "String" + }, + { + "name": "renderings", + "type": "Rendering", + "isMany": true + } + ] + }, + { + "name": "Gateway", + "isAbstract": true, + "superClass": [ + "FlowNode" + ], + "properties": [ + { + "name": "gatewayDirection", + "type": "GatewayDirection", + "default": "Unspecified", + "isAttr": true + } + ] + }, + { + "name": "EventBasedGateway", + "superClass": [ + "Gateway" + ], + "properties": [ + { + "name": "instantiate", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "eventGatewayType", + "type": "EventBasedGatewayType", + "isAttr": true, + "default": "Exclusive" + } + ] + }, + { + "name": "ComplexGateway", + "superClass": [ + "Gateway" + ], + "properties": [ + { + "name": "activationCondition", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "default", + "type": "SequenceFlow", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ExclusiveGateway", + "superClass": [ + "Gateway" + ], + "properties": [ + { + "name": "default", + "type": "SequenceFlow", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "InclusiveGateway", + "superClass": [ + "Gateway" + ], + "properties": [ + { + "name": "default", + "type": "SequenceFlow", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ParallelGateway", + "superClass": [ + "Gateway" + ] + }, + { + "name": "RootElement", + "isAbstract": true, + "superClass": [ + "BaseElement" + ] + }, + { + "name": "Relationship", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "type", + "isAttr": true, + "type": "String" + }, + { + "name": "direction", + "type": "RelationshipDirection", + "isAttr": true + }, + { + "name": "source", + "isMany": true, + "isReference": true, + "type": "Element" + }, + { + "name": "target", + "isMany": true, + "isReference": true, + "type": "Element" + } + ] + }, + { + "name": "BaseElement", + "isAbstract": true, + "properties": [ + { + "name": "id", + "isAttr": true, + "type": "String" + }, + { + "name": "documentation", + "type": "Documentation", + "isMany": true + }, + { + "name": "extensionDefinitions", + "type": "ExtensionDefinition", + "isMany": true, + "isReference": true + }, + { + "name": "extensionElements", + "type": "ExtensionElements" + } + ] + }, + { + "name": "Extension", + "properties": [ + { + "name": "mustUnderstand", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "definition", + "type": "ExtensionDefinition" + } + ] + }, + { + "name": "ExtensionDefinition", + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "extensionAttributeDefinitions", + "type": "ExtensionAttributeDefinition", + "isMany": true + } + ] + }, + { + "name": "ExtensionAttributeDefinition", + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "type", + "isAttr": true, + "type": "String" + }, + { + "name": "isReference", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "extensionDefinition", + "type": "ExtensionDefinition", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ExtensionElements", + "properties": [ + { + "name": "valueRef", + "isAttr": true, + "isReference": true, + "type": "Element" + }, + { + "name": "values", + "type": "Element", + "isMany": true + }, + { + "name": "extensionAttributeDefinition", + "type": "ExtensionAttributeDefinition", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "Documentation", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "text", + "type": "String", + "isBody": true + }, + { + "name": "textFormat", + "default": "text/plain", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "Event", + "isAbstract": true, + "superClass": [ + "FlowNode", + "InteractionNode" + ], + "properties": [ + { + "name": "properties", + "type": "Property", + "isMany": true + } + ] + }, + { + "name": "IntermediateCatchEvent", + "superClass": [ + "CatchEvent" + ] + }, + { + "name": "IntermediateThrowEvent", + "superClass": [ + "ThrowEvent" + ] + }, + { + "name": "EndEvent", + "superClass": [ + "ThrowEvent" + ] + }, + { + "name": "StartEvent", + "superClass": [ + "CatchEvent" + ], + "properties": [ + { + "name": "isInterrupting", + "default": true, + "isAttr": true, + "type": "Boolean" + } + ] + }, + { + "name": "ThrowEvent", + "isAbstract": true, + "superClass": [ + "Event" + ], + "properties": [ + { + "name": "inputSet", + "type": "InputSet" + }, + { + "name": "eventDefinitionRefs", + "type": "EventDefinition", + "isMany": true, + "isReference": true + }, + { + "name": "dataInputAssociation", + "type": "DataInputAssociation", + "isMany": true + }, + { + "name": "dataInputs", + "type": "DataInput", + "isMany": true + }, + { + "name": "eventDefinitions", + "type": "EventDefinition", + "isMany": true + } + ] + }, + { + "name": "CatchEvent", + "isAbstract": true, + "superClass": [ + "Event" + ], + "properties": [ + { + "name": "parallelMultiple", + "isAttr": true, + "type": "Boolean", + "default": false + }, + { + "name": "outputSet", + "type": "OutputSet" + }, + { + "name": "eventDefinitionRefs", + "type": "EventDefinition", + "isMany": true, + "isReference": true + }, + { + "name": "dataOutputAssociation", + "type": "DataOutputAssociation", + "isMany": true + }, + { + "name": "dataOutputs", + "type": "DataOutput", + "isMany": true + }, + { + "name": "eventDefinitions", + "type": "EventDefinition", + "isMany": true + } + ] + }, + { + "name": "BoundaryEvent", + "superClass": [ + "CatchEvent" + ], + "properties": [ + { + "name": "cancelActivity", + "default": true, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "attachedToRef", + "type": "Activity", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "EventDefinition", + "isAbstract": true, + "superClass": [ + "RootElement" + ] + }, + { + "name": "CancelEventDefinition", + "superClass": [ + "EventDefinition" + ] + }, + { + "name": "ErrorEventDefinition", + "superClass": [ + "EventDefinition" + ], + "properties": [ + { + "name": "errorRef", + "type": "Error", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "TerminateEventDefinition", + "superClass": [ + "EventDefinition" + ] + }, + { + "name": "EscalationEventDefinition", + "superClass": [ + "EventDefinition" + ], + "properties": [ + { + "name": "escalationRef", + "type": "Escalation", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "Escalation", + "properties": [ + { + "name": "structureRef", + "type": "ItemDefinition", + "isAttr": true, + "isReference": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "escalationCode", + "isAttr": true, + "type": "String" + } + ], + "superClass": [ + "RootElement" + ] + }, + { + "name": "CompensateEventDefinition", + "superClass": [ + "EventDefinition" + ], + "properties": [ + { + "name": "waitForCompletion", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "activityRef", + "type": "Activity", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "TimerEventDefinition", + "superClass": [ + "EventDefinition" + ], + "properties": [ + { + "name": "timeDate", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "timeCycle", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "timeDuration", + "type": "Expression", + "serialize": "xsi:type" + } + ] + }, + { + "name": "LinkEventDefinition", + "superClass": [ + "EventDefinition" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "target", + "type": "LinkEventDefinition", + "isAttr": true, + "isReference": true + }, + { + "name": "source", + "type": "LinkEventDefinition", + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "MessageEventDefinition", + "superClass": [ + "EventDefinition" + ], + "properties": [ + { + "name": "messageRef", + "type": "Message", + "isAttr": true, + "isReference": true + }, + { + "name": "operationRef", + "type": "Operation", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ConditionalEventDefinition", + "superClass": [ + "EventDefinition" + ], + "properties": [ + { + "name": "condition", + "type": "Expression", + "serialize": "xsi:type" + } + ] + }, + { + "name": "SignalEventDefinition", + "superClass": [ + "EventDefinition" + ], + "properties": [ + { + "name": "signalRef", + "type": "Signal", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "Signal", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "structureRef", + "type": "ItemDefinition", + "isAttr": true, + "isReference": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "ImplicitThrowEvent", + "superClass": [ + "ThrowEvent" + ] + }, + { + "name": "DataState", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "ItemAwareElement", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "itemSubjectRef", + "type": "ItemDefinition", + "isAttr": true, + "isReference": true + }, + { + "name": "dataState", + "type": "DataState" + } + ] + }, + { + "name": "DataAssociation", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "transformation", + "type": "FormalExpression" + }, + { + "name": "assignment", + "type": "Assignment", + "isMany": true + }, + { + "name": "sourceRef", + "type": "ItemAwareElement", + "isMany": true, + "isReference": true + }, + { + "name": "targetRef", + "type": "ItemAwareElement", + "isReference": true + } + ] + }, + { + "name": "DataInput", + "superClass": [ + "ItemAwareElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "isCollection", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "inputSetRefs", + "type": "InputSet", + "isVirtual": true, + "isMany": true, + "isReference": true + }, + { + "name": "inputSetWithOptional", + "type": "InputSet", + "isVirtual": true, + "isMany": true, + "isReference": true + }, + { + "name": "inputSetWithWhileExecuting", + "type": "InputSet", + "isVirtual": true, + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "DataOutput", + "superClass": [ + "ItemAwareElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "isCollection", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "outputSetRefs", + "type": "OutputSet", + "isVirtual": true, + "isMany": true, + "isReference": true + }, + { + "name": "outputSetWithOptional", + "type": "OutputSet", + "isVirtual": true, + "isMany": true, + "isReference": true + }, + { + "name": "outputSetWithWhileExecuting", + "type": "OutputSet", + "isVirtual": true, + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "InputSet", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "dataInputRefs", + "type": "DataInput", + "isMany": true, + "isReference": true + }, + { + "name": "optionalInputRefs", + "type": "DataInput", + "isMany": true, + "isReference": true + }, + { + "name": "whileExecutingInputRefs", + "type": "DataInput", + "isMany": true, + "isReference": true + }, + { + "name": "outputSetRefs", + "type": "OutputSet", + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "OutputSet", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "dataOutputRefs", + "type": "DataOutput", + "isMany": true, + "isReference": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "inputSetRefs", + "type": "InputSet", + "isMany": true, + "isReference": true + }, + { + "name": "optionalOutputRefs", + "type": "DataOutput", + "isMany": true, + "isReference": true + }, + { + "name": "whileExecutingOutputRefs", + "type": "DataOutput", + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "Property", + "superClass": [ + "ItemAwareElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "DataInputAssociation", + "superClass": [ + "DataAssociation" + ] + }, + { + "name": "DataOutputAssociation", + "superClass": [ + "DataAssociation" + ] + }, + { + "name": "InputOutputSpecification", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "inputSets", + "type": "InputSet", + "isMany": true + }, + { + "name": "outputSets", + "type": "OutputSet", + "isMany": true + }, + { + "name": "dataInputs", + "type": "DataInput", + "isMany": true + }, + { + "name": "dataOutputs", + "type": "DataOutput", + "isMany": true + } + ] + }, + { + "name": "DataObject", + "superClass": [ + "FlowElement", + "ItemAwareElement" + ], + "properties": [ + { + "name": "isCollection", + "default": false, + "isAttr": true, + "type": "Boolean" + } + ] + }, + { + "name": "InputOutputBinding", + "properties": [ + { + "name": "inputDataRef", + "type": "InputSet", + "isAttr": true, + "isReference": true + }, + { + "name": "outputDataRef", + "type": "OutputSet", + "isAttr": true, + "isReference": true + }, + { + "name": "operationRef", + "type": "Operation", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "Assignment", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "from", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "to", + "type": "Expression", + "serialize": "xsi:type" + } + ] + }, + { + "name": "DataStore", + "superClass": [ + "RootElement", + "ItemAwareElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "capacity", + "isAttr": true, + "type": "Integer" + }, + { + "name": "isUnlimited", + "default": true, + "isAttr": true, + "type": "Boolean" + } + ] + }, + { + "name": "DataStoreReference", + "superClass": [ + "ItemAwareElement", + "FlowElement" + ], + "properties": [ + { + "name": "dataStoreRef", + "type": "DataStore", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "DataObjectReference", + "superClass": [ + "ItemAwareElement", + "FlowElement" + ], + "properties": [ + { + "name": "dataObjectRef", + "type": "DataObject", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ConversationLink", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "sourceRef", + "type": "InteractionNode", + "isAttr": true, + "isReference": true + }, + { + "name": "targetRef", + "type": "InteractionNode", + "isAttr": true, + "isReference": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "ConversationAssociation", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "innerConversationNodeRef", + "type": "ConversationNode", + "isAttr": true, + "isReference": true + }, + { + "name": "outerConversationNodeRef", + "type": "ConversationNode", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "CallConversation", + "superClass": [ + "ConversationNode" + ], + "properties": [ + { + "name": "calledCollaborationRef", + "type": "Collaboration", + "isAttr": true, + "isReference": true + }, + { + "name": "participantAssociations", + "type": "ParticipantAssociation", + "isMany": true + } + ] + }, + { + "name": "Conversation", + "superClass": [ + "ConversationNode" + ] + }, + { + "name": "SubConversation", + "superClass": [ + "ConversationNode" + ], + "properties": [ + { + "name": "conversationNodes", + "type": "ConversationNode", + "isMany": true + } + ] + }, + { + "name": "ConversationNode", + "isAbstract": true, + "superClass": [ + "InteractionNode", + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "participantRefs", + "type": "Participant", + "isMany": true, + "isReference": true + }, + { + "name": "messageFlowRefs", + "type": "MessageFlow", + "isMany": true, + "isReference": true + }, + { + "name": "correlationKeys", + "type": "CorrelationKey", + "isMany": true + } + ] + }, + { + "name": "GlobalConversation", + "superClass": [ + "Collaboration" + ] + }, + { + "name": "PartnerEntity", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "participantRef", + "type": "Participant", + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "PartnerRole", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "participantRef", + "type": "Participant", + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "CorrelationProperty", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "correlationPropertyRetrievalExpression", + "type": "CorrelationPropertyRetrievalExpression", + "isMany": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "type", + "type": "ItemDefinition", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "Error", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "structureRef", + "type": "ItemDefinition", + "isAttr": true, + "isReference": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "errorCode", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "CorrelationKey", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "correlationPropertyRef", + "type": "CorrelationProperty", + "isMany": true, + "isReference": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "Expression", + "superClass": [ + "BaseElement" + ], + "isAbstract": true + }, + { + "name": "FormalExpression", + "superClass": [ + "Expression" + ], + "properties": [ + { + "name": "language", + "isAttr": true, + "type": "String" + }, + { + "name": "body", + "type": "String", + "isBody": true + }, + { + "name": "evaluatesToTypeRef", + "type": "ItemDefinition", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "Message", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "itemRef", + "type": "ItemDefinition", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ItemDefinition", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "itemKind", + "type": "ItemKind", + "isAttr": true + }, + { + "name": "structureRef", + "type": "String", + "isAttr": true + }, + { + "name": "isCollection", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "import", + "type": "Import", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "FlowElement", + "isAbstract": true, + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "auditing", + "type": "Auditing" + }, + { + "name": "monitoring", + "type": "Monitoring" + }, + { + "name": "categoryValueRef", + "type": "CategoryValue", + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "SequenceFlow", + "superClass": [ + "FlowElement" + ], + "properties": [ + { + "name": "isImmediate", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "conditionExpression", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "sourceRef", + "type": "FlowNode", + "isAttr": true, + "isReference": true + }, + { + "name": "targetRef", + "type": "FlowNode", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "FlowElementsContainer", + "isAbstract": true, + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "laneSets", + "type": "LaneSet", + "isMany": true + }, + { + "name": "flowElements", + "type": "FlowElement", + "isMany": true + } + ] + }, + { + "name": "CallableElement", + "isAbstract": true, + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "ioSpecification", + "type": "InputOutputSpecification" + }, + { + "name": "supportedInterfaceRefs", + "type": "Interface", + "isMany": true, + "isReference": true + }, + { + "name": "ioBinding", + "type": "InputOutputBinding", + "isMany": true + } + ] + }, + { + "name": "FlowNode", + "isAbstract": true, + "superClass": [ + "FlowElement" + ], + "properties": [ + { + "name": "incoming", + "type": "SequenceFlow", + "isMany": true, + "isReference": true + }, + { + "name": "outgoing", + "type": "SequenceFlow", + "isMany": true, + "isReference": true + }, + { + "name": "lanes", + "type": "Lane", + "isVirtual": true, + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "CorrelationPropertyRetrievalExpression", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "messagePath", + "type": "FormalExpression" + }, + { + "name": "messageRef", + "type": "Message", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "CorrelationPropertyBinding", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "dataPath", + "type": "FormalExpression" + }, + { + "name": "correlationPropertyRef", + "type": "CorrelationProperty", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "Resource", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "resourceParameters", + "type": "ResourceParameter", + "isMany": true + } + ] + }, + { + "name": "ResourceParameter", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "isRequired", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "type", + "type": "ItemDefinition", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "CorrelationSubscription", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "correlationKeyRef", + "type": "CorrelationKey", + "isAttr": true, + "isReference": true + }, + { + "name": "correlationPropertyBinding", + "type": "CorrelationPropertyBinding", + "isMany": true + } + ] + }, + { + "name": "MessageFlow", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "sourceRef", + "type": "InteractionNode", + "isAttr": true, + "isReference": true + }, + { + "name": "targetRef", + "type": "InteractionNode", + "isAttr": true, + "isReference": true + }, + { + "name": "messageRef", + "type": "Message", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "MessageFlowAssociation", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "innerMessageFlowRef", + "type": "MessageFlow", + "isAttr": true, + "isReference": true + }, + { + "name": "outerMessageFlowRef", + "type": "MessageFlow", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "InteractionNode", + "isAbstract": true, + "properties": [ + { + "name": "incomingConversationLinks", + "type": "ConversationLink", + "isVirtual": true, + "isMany": true, + "isReference": true + }, + { + "name": "outgoingConversationLinks", + "type": "ConversationLink", + "isVirtual": true, + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "Participant", + "superClass": [ + "InteractionNode", + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "interfaceRefs", + "type": "Interface", + "isMany": true, + "isReference": true + }, + { + "name": "participantMultiplicity", + "type": "ParticipantMultiplicity" + }, + { + "name": "endPointRefs", + "type": "EndPoint", + "isMany": true, + "isReference": true + }, + { + "name": "processRef", + "type": "Process", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ParticipantAssociation", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "innerParticipantRef", + "type": "Participant", + "isAttr": true, + "isReference": true + }, + { + "name": "outerParticipantRef", + "type": "Participant", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ParticipantMultiplicity", + "properties": [ + { + "name": "minimum", + "default": 0, + "isAttr": true, + "type": "Integer" + }, + { + "name": "maximum", + "default": 1, + "isAttr": true, + "type": "Integer" + } + ] + }, + { + "name": "Collaboration", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "isClosed", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "choreographyRef", + "type": "Choreography", + "isMany": true, + "isReference": true + }, + { + "name": "artifacts", + "type": "Artifact", + "isMany": true + }, + { + "name": "participantAssociations", + "type": "ParticipantAssociation", + "isMany": true + }, + { + "name": "messageFlowAssociations", + "type": "MessageFlowAssociation", + "isMany": true + }, + { + "name": "conversationAssociations", + "type": "ConversationAssociation" + }, + { + "name": "participants", + "type": "Participant", + "isMany": true + }, + { + "name": "messageFlows", + "type": "MessageFlow", + "isMany": true + }, + { + "name": "correlationKeys", + "type": "CorrelationKey", + "isMany": true + }, + { + "name": "conversations", + "type": "ConversationNode", + "isMany": true + }, + { + "name": "conversationLinks", + "type": "ConversationLink", + "isMany": true + } + ] + }, + { + "name": "ChoreographyActivity", + "isAbstract": true, + "superClass": [ + "FlowNode" + ], + "properties": [ + { + "name": "participantRefs", + "type": "Participant", + "isMany": true, + "isReference": true + }, + { + "name": "initiatingParticipantRef", + "type": "Participant", + "isAttr": true, + "isReference": true + }, + { + "name": "correlationKeys", + "type": "CorrelationKey", + "isMany": true + }, + { + "name": "loopType", + "type": "ChoreographyLoopType", + "default": "None", + "isAttr": true + } + ] + }, + { + "name": "CallChoreography", + "superClass": [ + "ChoreographyActivity" + ], + "properties": [ + { + "name": "calledChoreographyRef", + "type": "Choreography", + "isAttr": true, + "isReference": true + }, + { + "name": "participantAssociations", + "type": "ParticipantAssociation", + "isMany": true + } + ] + }, + { + "name": "SubChoreography", + "superClass": [ + "ChoreographyActivity", + "FlowElementsContainer" + ], + "properties": [ + { + "name": "artifacts", + "type": "Artifact", + "isMany": true + } + ] + }, + { + "name": "ChoreographyTask", + "superClass": [ + "ChoreographyActivity" + ], + "properties": [ + { + "name": "messageFlowRef", + "type": "MessageFlow", + "isMany": true, + "isReference": true + } + ] + }, + { + "name": "Choreography", + "superClass": [ + "FlowElementsContainer", + "Collaboration" + ] + }, + { + "name": "GlobalChoreographyTask", + "superClass": [ + "Choreography" + ], + "properties": [ + { + "name": "initiatingParticipantRef", + "type": "Participant", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "TextAnnotation", + "superClass": [ + "Artifact" + ], + "properties": [ + { + "name": "text", + "type": "String" + }, + { + "name": "textFormat", + "default": "text/plain", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "Group", + "superClass": [ + "Artifact" + ], + "properties": [ + { + "name": "categoryValueRef", + "type": "CategoryValue", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "Association", + "superClass": [ + "Artifact" + ], + "properties": [ + { + "name": "associationDirection", + "type": "AssociationDirection", + "isAttr": true + }, + { + "name": "sourceRef", + "type": "BaseElement", + "isAttr": true, + "isReference": true + }, + { + "name": "targetRef", + "type": "BaseElement", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "Category", + "superClass": [ + "RootElement" + ], + "properties": [ + { + "name": "categoryValue", + "type": "CategoryValue", + "isMany": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "Artifact", + "isAbstract": true, + "superClass": [ + "BaseElement" + ] + }, + { + "name": "CategoryValue", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "categorizedFlowElements", + "type": "FlowElement", + "isVirtual": true, + "isMany": true, + "isReference": true + }, + { + "name": "value", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "Activity", + "isAbstract": true, + "superClass": [ + "FlowNode" + ], + "properties": [ + { + "name": "isForCompensation", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "loopCharacteristics", + "type": "LoopCharacteristics" + }, + { + "name": "resources", + "type": "ResourceRole", + "isMany": true + }, + { + "name": "default", + "type": "SequenceFlow", + "isAttr": true, + "isReference": true + }, + { + "name": "properties", + "type": "Property", + "isMany": true + }, + { + "name": "ioSpecification", + "type": "InputOutputSpecification" + }, + { + "name": "boundaryEventRefs", + "type": "BoundaryEvent", + "isMany": true, + "isReference": true + }, + { + "name": "dataInputAssociations", + "type": "DataInputAssociation", + "isMany": true + }, + { + "name": "dataOutputAssociations", + "type": "DataOutputAssociation", + "isMany": true + }, + { + "name": "startQuantity", + "default": 1, + "isAttr": true, + "type": "Integer" + }, + { + "name": "completionQuantity", + "default": 1, + "isAttr": true, + "type": "Integer" + } + ] + }, + { + "name": "ServiceTask", + "superClass": [ + "Task" + ], + "properties": [ + { + "name": "implementation", + "isAttr": true, + "type": "String" + }, + { + "name": "operationRef", + "type": "Operation", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "SubProcess", + "superClass": [ + "Activity", + "FlowElementsContainer", + "InteractionNode" + ], + "properties": [ + { + "name": "triggeredByEvent", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "artifacts", + "type": "Artifact", + "isMany": true + } + ] + }, + { + "name": "LoopCharacteristics", + "isAbstract": true, + "superClass": [ + "BaseElement" + ] + }, + { + "name": "MultiInstanceLoopCharacteristics", + "superClass": [ + "LoopCharacteristics" + ], + "properties": [ + { + "name": "isSequential", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "behavior", + "type": "MultiInstanceBehavior", + "default": "All", + "isAttr": true + }, + { + "name": "loopCardinality", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "loopDataInputRef", + "type": "ItemAwareElement", + "isAttr": true, + "isReference": true + }, + { + "name": "loopDataOutputRef", + "type": "ItemAwareElement", + "isAttr": true, + "isReference": true + }, + { + "name": "inputDataItem", + "type": "DataInput" + }, + { + "name": "outputDataItem", + "type": "DataOutput" + }, + { + "name": "completionCondition", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "complexBehaviorDefinition", + "type": "ComplexBehaviorDefinition", + "isMany": true + }, + { + "name": "oneBehaviorEventRef", + "type": "EventDefinition", + "isAttr": true, + "isReference": true + }, + { + "name": "noneBehaviorEventRef", + "type": "EventDefinition", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "StandardLoopCharacteristics", + "superClass": [ + "LoopCharacteristics" + ], + "properties": [ + { + "name": "testBefore", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "loopCondition", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "loopMaximum", + "type": "Expression", + "serialize": "xsi:type" + } + ] + }, + { + "name": "CallActivity", + "superClass": [ + "Activity" + ], + "properties": [ + { + "name": "calledElement", + "type": "String", + "isAttr": true + } + ] + }, + { + "name": "Task", + "superClass": [ + "Activity", + "InteractionNode" + ] + }, + { + "name": "SendTask", + "superClass": [ + "Task" + ], + "properties": [ + { + "name": "implementation", + "isAttr": true, + "type": "String" + }, + { + "name": "operationRef", + "type": "Operation", + "isAttr": true, + "isReference": true + }, + { + "name": "messageRef", + "type": "Message", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ReceiveTask", + "superClass": [ + "Task" + ], + "properties": [ + { + "name": "implementation", + "isAttr": true, + "type": "String" + }, + { + "name": "instantiate", + "default": false, + "isAttr": true, + "type": "Boolean" + }, + { + "name": "operationRef", + "type": "Operation", + "isAttr": true, + "isReference": true + }, + { + "name": "messageRef", + "type": "Message", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ScriptTask", + "superClass": [ + "Task" + ], + "properties": [ + { + "name": "scriptFormat", + "isAttr": true, + "type": "String" + }, + { + "name": "script", + "type": "String" + } + ] + }, + { + "name": "BusinessRuleTask", + "superClass": [ + "Task" + ], + "properties": [ + { + "name": "implementation", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "AdHocSubProcess", + "superClass": [ + "SubProcess" + ], + "properties": [ + { + "name": "completionCondition", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "ordering", + "type": "AdHocOrdering", + "isAttr": true + }, + { + "name": "cancelRemainingInstances", + "default": true, + "isAttr": true, + "type": "Boolean" + } + ] + }, + { + "name": "Transaction", + "superClass": [ + "SubProcess" + ], + "properties": [ + { + "name": "protocol", + "isAttr": true, + "type": "String" + }, + { + "name": "method", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "GlobalScriptTask", + "superClass": [ + "GlobalTask" + ], + "properties": [ + { + "name": "scriptLanguage", + "isAttr": true, + "type": "String" + }, + { + "name": "script", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "GlobalBusinessRuleTask", + "superClass": [ + "GlobalTask" + ], + "properties": [ + { + "name": "implementation", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "ComplexBehaviorDefinition", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "condition", + "type": "FormalExpression" + }, + { + "name": "event", + "type": "ImplicitThrowEvent" + } + ] + }, + { + "name": "ResourceRole", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "resourceRef", + "type": "Resource", + "isReference": true + }, + { + "name": "resourceParameterBindings", + "type": "ResourceParameterBinding", + "isMany": true + }, + { + "name": "resourceAssignmentExpression", + "type": "ResourceAssignmentExpression" + }, + { + "name": "name", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "ResourceParameterBinding", + "properties": [ + { + "name": "expression", + "type": "Expression", + "serialize": "xsi:type" + }, + { + "name": "parameterRef", + "type": "ResourceParameter", + "isAttr": true, + "isReference": true + } + ] + }, + { + "name": "ResourceAssignmentExpression", + "properties": [ + { + "name": "expression", + "type": "Expression", + "serialize": "xsi:type" + } + ] + }, + { + "name": "Import", + "properties": [ + { + "name": "importType", + "isAttr": true, + "type": "String" + }, + { + "name": "location", + "isAttr": true, + "type": "String" + }, + { + "name": "namespace", + "isAttr": true, + "type": "String" + } + ] + }, + { + "name": "Definitions", + "superClass": [ + "BaseElement" + ], + "properties": [ + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "targetNamespace", + "isAttr": true, + "type": "String" + }, + { + "name": "expressionLanguage", + "default": "http://www.w3.org/1999/XPath", + "isAttr": true, + "type": "String" + }, + { + "name": "typeLanguage", + "default": "http://www.w3.org/2001/XMLSchema", + "isAttr": true, + "type": "String" + }, + { + "name": "imports", + "type": "Import", + "isMany": true + }, + { + "name": "extensions", + "type": "Extension", + "isMany": true + }, + { + "name": "rootElements", + "type": "RootElement", + "isMany": true + }, + { + "name": "diagrams", + "isMany": true, + "type": "bpmndi:BPMNDiagram" + }, + { + "name": "exporter", + "isAttr": true, + "type": "String" + }, + { + "name": "relationships", + "type": "Relationship", + "isMany": true + }, + { + "name": "exporterVersion", + "isAttr": true, + "type": "String" + } + ] + } + ], + "emumerations": [ + { + "name": "ProcessType", + "literalValues": [ + { + "name": "None" + }, + { + "name": "Public" + }, + { + "name": "Private" + } + ] + }, + { + "name": "GatewayDirection", + "literalValues": [ + { + "name": "Unspecified" + }, + { + "name": "Converging" + }, + { + "name": "Diverging" + }, + { + "name": "Mixed" + } + ] + }, + { + "name": "EventBasedGatewayType", + "literalValues": [ + { + "name": "Parallel" + }, + { + "name": "Exclusive" + } + ] + }, + { + "name": "RelationshipDirection", + "literalValues": [ + { + "name": "None" + }, + { + "name": "Forward" + }, + { + "name": "Backward" + }, + { + "name": "Both" + } + ] + }, + { + "name": "ItemKind", + "literalValues": [ + { + "name": "Physical" + }, + { + "name": "Information" + } + ] + }, + { + "name": "ChoreographyLoopType", + "literalValues": [ + { + "name": "None" + }, + { + "name": "Standard" + }, + { + "name": "MultiInstanceSequential" + }, + { + "name": "MultiInstanceParallel" + } + ] + }, + { + "name": "AssociationDirection", + "literalValues": [ + { + "name": "None" + }, + { + "name": "One" + }, + { + "name": "Both" + } + ] + }, + { + "name": "MultiInstanceBehavior", + "literalValues": [ + { + "name": "None" + }, + { + "name": "One" + }, + { + "name": "All" + }, + { + "name": "Complex" + } + ] + }, + { + "name": "AdHocOrdering", + "literalValues": [ + { + "name": "Parallel" + }, + { + "name": "Sequential" + } + ] + } + ], + "prefix": "bpmn", + "xml": { + "tagAlias": "lowerCase", + "typePrefix": "t" + } +} +},{}],33:[function(_dereq_,module,exports){ +module.exports={ + "name": "BPMNDI", + "uri": "http://www.omg.org/spec/BPMN/20100524/DI", + "types": [ + { + "name": "BPMNDiagram", + "properties": [ + { + "name": "plane", + "type": "BPMNPlane", + "redefines": "di:Diagram#rootElement" + }, + { + "name": "labelStyle", + "type": "BPMNLabelStyle", + "isMany": true + } + ], + "superClass": [ + "di:Diagram" + ] + }, + { + "name": "BPMNPlane", + "properties": [ + { + "name": "bpmnElement", + "isAttr": true, + "isReference": true, + "type": "bpmn:BaseElement", + "redefines": "di:DiagramElement#modelElement" + } + ], + "superClass": [ + "di:Plane" + ] + }, + { + "name": "BPMNShape", + "properties": [ + { + "name": "bpmnElement", + "isAttr": true, + "isReference": true, + "type": "bpmn:BaseElement", + "redefines": "di:DiagramElement#modelElement" + }, + { + "name": "isHorizontal", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "isExpanded", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "isMarkerVisible", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "label", + "type": "BPMNLabel" + }, + { + "name": "isMessageVisible", + "isAttr": true, + "type": "Boolean" + }, + { + "name": "participantBandKind", + "type": "ParticipantBandKind", + "isAttr": true + }, + { + "name": "choreographyActivityShape", + "type": "BPMNShape", + "isAttr": true, + "isReference": true + } + ], + "superClass": [ + "di:LabeledShape" + ] + }, + { + "name": "BPMNEdge", + "properties": [ + { + "name": "label", + "type": "BPMNLabel" + }, + { + "name": "bpmnElement", + "isAttr": true, + "isReference": true, + "type": "bpmn:BaseElement", + "redefines": "di:DiagramElement#modelElement" + }, + { + "name": "sourceElement", + "isAttr": true, + "isReference": true, + "type": "di:DiagramElement", + "redefines": "di:Edge#source" + }, + { + "name": "targetElement", + "isAttr": true, + "isReference": true, + "type": "di:DiagramElement", + "redefines": "di:Edge#target" + }, + { + "name": "messageVisibleKind", + "type": "MessageVisibleKind", + "isAttr": true, + "default": "initiating" + } + ], + "superClass": [ + "di:LabeledEdge" + ] + }, + { + "name": "BPMNLabel", + "properties": [ + { + "name": "labelStyle", + "type": "BPMNLabelStyle", + "isAttr": true, + "isReference": true, + "redefines": "di:DiagramElement#style" + } + ], + "superClass": [ + "di:Label" + ] + }, + { + "name": "BPMNLabelStyle", + "properties": [ + { + "name": "font", + "type": "dc:Font" + } + ], + "superClass": [ + "di:Style" + ] + } + ], + "emumerations": [ + { + "name": "ParticipantBandKind", + "literalValues": [ + { + "name": "top_initiating" + }, + { + "name": "middle_initiating" + }, + { + "name": "bottom_initiating" + }, + { + "name": "top_non_initiating" + }, + { + "name": "middle_non_initiating" + }, + { + "name": "bottom_non_initiating" + } + ] + }, + { + "name": "MessageVisibleKind", + "literalValues": [ + { + "name": "initiating" + }, + { + "name": "non_initiating" + } + ] + } + ], + "associations": [], + "prefix": "bpmndi" +} +},{}],34:[function(_dereq_,module,exports){ +module.exports={ + "name": "DC", + "uri": "http://www.omg.org/spec/DD/20100524/DC", + "types": [ + { + "name": "Boolean" + }, + { + "name": "Integer" + }, + { + "name": "Real" + }, + { + "name": "String" + }, + { + "name": "Font", + "properties": [ + { + "name": "name", + "type": "String", + "isAttr": true + }, + { + "name": "size", + "type": "Real", + "isAttr": true + }, + { + "name": "isBold", + "type": "Boolean", + "isAttr": true + }, + { + "name": "isItalic", + "type": "Boolean", + "isAttr": true + }, + { + "name": "isUnderline", + "type": "Boolean", + "isAttr": true + }, + { + "name": "isStrikeThrough", + "type": "Boolean", + "isAttr": true + } + ] + }, + { + "name": "Point", + "properties": [ + { + "name": "x", + "type": "Real", + "default": "0", + "isAttr": true + }, + { + "name": "y", + "type": "Real", + "default": "0", + "isAttr": true + } + ] + }, + { + "name": "Bounds", + "properties": [ + { + "name": "x", + "type": "Real", + "default": "0", + "isAttr": true + }, + { + "name": "y", + "type": "Real", + "default": "0", + "isAttr": true + }, + { + "name": "width", + "type": "Real", + "isAttr": true + }, + { + "name": "height", + "type": "Real", + "isAttr": true + } + ] + } + ], + "prefix": "dc", + "associations": [] +} +},{}],35:[function(_dereq_,module,exports){ +module.exports={ + "name": "DI", + "uri": "http://www.omg.org/spec/DD/20100524/DI", + "types": [ + { + "name": "DiagramElement", + "isAbstract": true, + "properties": [ + { + "name": "extension", + "type": "Extension" + }, + { + "name": "owningDiagram", + "type": "Diagram", + "isReadOnly": true, + "isVirtual": true, + "isReference": true + }, + { + "name": "owningElement", + "type": "DiagramElement", + "isReadOnly": true, + "isVirtual": true, + "isReference": true + }, + { + "name": "modelElement", + "isReadOnly": true, + "isVirtual": true, + "isReference": true, + "type": "Element" + }, + { + "name": "style", + "type": "Style", + "isReadOnly": true, + "isVirtual": true, + "isReference": true + }, + { + "name": "ownedElement", + "type": "DiagramElement", + "isReadOnly": true, + "isVirtual": true, + "isMany": true + } + ] + }, + { + "name": "Node", + "isAbstract": true, + "superClass": [ + "DiagramElement" + ] + }, + { + "name": "Edge", + "isAbstract": true, + "superClass": [ + "DiagramElement" + ], + "properties": [ + { + "name": "source", + "type": "DiagramElement", + "isReadOnly": true, + "isVirtual": true, + "isReference": true + }, + { + "name": "target", + "type": "DiagramElement", + "isReadOnly": true, + "isVirtual": true, + "isReference": true + }, + { + "name": "waypoint", + "isUnique": false, + "isMany": true, + "type": "dc:Point", + "serialize": "xsi:type" + } + ] + }, + { + "name": "Diagram", + "isAbstract": true, + "properties": [ + { + "name": "rootElement", + "type": "DiagramElement", + "isReadOnly": true, + "isVirtual": true + }, + { + "name": "name", + "isAttr": true, + "type": "String" + }, + { + "name": "documentation", + "isAttr": true, + "type": "String" + }, + { + "name": "resolution", + "isAttr": true, + "type": "Real" + }, + { + "name": "ownedStyle", + "type": "Style", + "isReadOnly": true, + "isVirtual": true, + "isMany": true + } + ] + }, + { + "name": "Shape", + "isAbstract": true, + "superClass": [ + "Node" + ], + "properties": [ + { + "name": "bounds", + "type": "dc:Bounds" + } + ] + }, + { + "name": "Plane", + "isAbstract": true, + "superClass": [ + "Node" + ], + "properties": [ + { + "name": "planeElement", + "type": "DiagramElement", + "subsettedProperty": "DiagramElement-ownedElement", + "isMany": true + } + ] + }, + { + "name": "LabeledEdge", + "isAbstract": true, + "superClass": [ + "Edge" + ], + "properties": [ + { + "name": "ownedLabel", + "type": "Label", + "isReadOnly": true, + "subsettedProperty": "DiagramElement-ownedElement", + "isVirtual": true, + "isMany": true + } + ] + }, + { + "name": "LabeledShape", + "isAbstract": true, + "superClass": [ + "Shape" + ], + "properties": [ + { + "name": "ownedLabel", + "type": "Label", + "isReadOnly": true, + "subsettedProperty": "DiagramElement-ownedElement", + "isVirtual": true, + "isMany": true + } + ] + }, + { + "name": "Label", + "isAbstract": true, + "superClass": [ + "Node" + ], + "properties": [ + { + "name": "bounds", + "type": "dc:Bounds" + } + ] + }, + { + "name": "Style", + "isAbstract": true + }, + { + "name": "Extension", + "properties": [ + { + "name": "values", + "type": "Element", + "isMany": true + } + ] + } + ], + "associations": [], + "prefix": "di", + "xml": { + "tagAlias": "lowerCase" + } +} +},{}],36:[function(_dereq_,module,exports){ +module.exports = _dereq_(37); +},{"37":37}],37:[function(_dereq_,module,exports){ +'use strict'; + +var di = _dereq_(76); + + +/** + * Bootstrap an injector from a list of modules, instantiating a number of default components + * + * @ignore + * @param {Array<didi.Module>} bootstrapModules + * + * @return {didi.Injector} a injector to use to access the components + */ +function bootstrap(bootstrapModules) { + + var modules = [], + components = []; + + function hasModule(m) { + return modules.indexOf(m) >= 0; + } + + function addModule(m) { + modules.push(m); + } + + function visit(m) { + if (hasModule(m)) { + return; + } + + (m.__depends__ || []).forEach(visit); + + if (hasModule(m)) { + return; + } + + addModule(m); + + (m.__init__ || []).forEach(function(c) { + components.push(c); + }); + } + + bootstrapModules.forEach(visit); + + var injector = new di.Injector(modules); + + components.forEach(function(c) { + + try { + // eagerly resolve component (fn or string) + injector[typeof c === 'string' ? 'get' : 'invoke'](c); + } catch (e) { + console.error('Failed to instantiate component'); + console.error(e.stack); + + throw e; + } + }); + + return injector; +} + +/** + * Creates an injector from passed options. + * + * @ignore + * @param {Object} options + * @return {didi.Injector} + */ +function createInjector(options) { + + options = options || {}; + + var configModule = { + 'config': ['value', options] + }; + + var coreModule = _dereq_(43); + + var modules = [ configModule, coreModule ].concat(options.modules || []); + + return bootstrap(modules); +} + + +/** + * The main diagram-js entry point that bootstraps the diagram with the given + * configuration. + * + * To register extensions with the diagram, pass them as Array<didi.Module> to the constructor. + * + * @class djs.Diagram + * @memberOf djs + * @constructor + * + * @example + * + * <caption>Creating a plug-in that logs whenever a shape is added to the canvas.</caption> + * + * // plug-in implemenentation + * function MyLoggingPlugin(eventBus) { + * eventBus.on('shape.added', function(event) { + * console.log('shape ', event.shape, ' was added to the diagram'); + * }); + * } + * + * // export as module + * module.exports = { + * __init__: [ 'myLoggingPlugin' ], + * myLoggingPlugin: [ 'type', MyLoggingPlugin ] + * }; + * + * + * // instantiate the diagram with the new plug-in + * + * var diagram = new Diagram({ modules: [ require('path-to-my-logging-plugin') ] }); + * + * diagram.invoke([ 'canvas', function(canvas) { + * // add shape to drawing canvas + * canvas.addShape({ x: 10, y: 10 }); + * }); + * + * // 'shape ... was added to the diagram' logged to console + * + * @param {Object} options + * @param {Array<didi.Module>} [options.modules] external modules to instantiate with the diagram + * @param {didi.Injector} [injector] an (optional) injector to bootstrap the diagram with + */ +function Diagram(options, injector) { + + // create injector unless explicitly specified + this.injector = injector = injector || createInjector(options); + + // API + + /** + * Resolves a diagram service + * + * @method Diagram#get + * + * @param {String} name the name of the diagram service to be retrieved + * @param {Object} [locals] a number of locals to use to resolve certain dependencies + */ + this.get = injector.get; + + /** + * Executes a function into which diagram services are injected + * + * @method Diagram#invoke + * + * @param {Function|Object[]} fn the function to resolve + * @param {Object} locals a number of locals to use to resolve certain dependencies + */ + this.invoke = injector.invoke; + + // init + + // indicate via event + + + /** + * An event indicating that all plug-ins are loaded. + * + * Use this event to fire other events to interested plug-ins + * + * @memberOf Diagram + * + * @event diagram.init + * + * @example + * + * eventBus.on('diagram.init', function() { + * eventBus.fire('my-custom-event', { foo: 'BAR' }); + * }); + * + * @type {Object} + */ + this.get('eventBus').fire('diagram.init'); +} + +module.exports = Diagram; + + +/** + * Destroys the diagram + * + * @method Diagram#destroy + */ +Diagram.prototype.destroy = function() { + this.get('eventBus').fire('diagram.destroy'); +}; +},{"43":43,"76":76}],38:[function(_dereq_,module,exports){ +'use strict'; + +var isNumber = _dereq_(169), + assign = _dereq_(175), + forEach = _dereq_(84); + +var Collections = _dereq_(63); + +var Snap = _dereq_(74); + +function round(number, resolution) { + return Math.round(number * resolution) / resolution; +} + +function ensurePx(number) { + return isNumber(number) ? number + 'px' : number; +} + +/** + * Creates a HTML container element for a SVG element with + * the given configuration + * + * @param {Object} options + * @return {HTMLElement} the container element + */ +function createContainer(options) { + + options = assign({}, { width: '100%', height: '100%' }, options); + + var container = options.container || document.body; + + // create a <div> around the svg element with the respective size + // this way we can always get the correct container size + // (this is impossible for <svg> elements at the moment) + var parent = document.createElement('div'); + parent.setAttribute('class', 'djs-container'); + + assign(parent.style, { + position: 'relative', + overflow: 'hidden', + width: ensurePx(options.width), + height: ensurePx(options.height) + }); + + container.appendChild(parent); + + return parent; +} + +function createGroup(parent, cls) { + return parent.group().attr({ 'class' : cls }); +} + +var BASE_LAYER = 'base'; + + +/** + * The main drawing canvas. + * + * @class + * @constructor + * + * @emits Canvas#canvas.init + * + * @param {Object} config + * @param {EventBus} eventBus + * @param {GraphicsFactory} graphicsFactory + * @param {ElementRegistry} elementRegistry + */ +function Canvas(config, eventBus, graphicsFactory, elementRegistry) { + this._eventBus = eventBus; + this._elementRegistry = elementRegistry; + this._graphicsFactory = graphicsFactory; + + this._init(config || {}); +} + +Canvas.$inject = [ 'config.canvas', 'eventBus', 'graphicsFactory', 'elementRegistry' ]; + +module.exports = Canvas; + + +Canvas.prototype._init = function(config) { + + // Creates a <svg> element that is wrapped into a <div>. + // This way we are always able to correctly figure out the size of the svg element + // by querying the parent node. + // + // (It is not possible to get the size of a svg element cross browser @ 2014-04-01) + // + // <div class="djs-container" style="width: {desired-width}, height: {desired-height}"> + // <svg width="100%" height="100%"> + // ... + // </svg> + // </div> + + // html container + var eventBus = this._eventBus, + + container = createContainer(config), + svg = Snap.createSnapAt('100%', '100%', container), + viewport = createGroup(svg, 'viewport'), + + self = this; + + this._container = container; + this._svg = svg; + this._viewport = viewport; + this._layers = {}; + + eventBus.on('diagram.init', function(event) { + + /** + * An event indicating that the canvas is ready to be drawn on. + * + * @memberOf Canvas + * + * @event canvas.init + * + * @type {Object} + * @property {Snap<SVGSVGElement>} svg the created svg element + * @property {Snap<SVGGroup>} viewport the direct parent of diagram elements and shapes + */ + eventBus.fire('canvas.init', { svg: svg, viewport: viewport }); + }); + + eventBus.on('diagram.destroy', function() { + + var parent = self._container.parentNode; + + if (parent) { + parent.removeChild(container); + } + + eventBus.fire('canvas.destroy', { svg: self._svg, viewport: self._viewport }); + + self._svg.remove(); + + self._svg = self._container = self._layers = self._viewport = null; + }); + +}; + +/** + * Returns the default layer on which + * all elements are drawn. + * + * @returns {Snap<SVGGroup>} + */ +Canvas.prototype.getDefaultLayer = function() { + return this.getLayer(BASE_LAYER); +}; + +/** + * Returns a layer that is used to draw elements + * or annotations on it. + * + * @param {String} name + * + * @returns {Snap<SVGGroup>} + */ +Canvas.prototype.getLayer = function(name) { + + if (!name) { + throw new Error('must specify a name'); + } + + var layer = this._layers[name]; + if (!layer) { + layer = this._layers[name] = createGroup(this._viewport, 'layer-' + name); + } + + return layer; +}; + + +/** + * Returns the html element that encloses the + * drawing canvas. + * + * @return {DOMNode} + */ +Canvas.prototype.getContainer = function() { + return this._container; +}; + + +/////////////// markers /////////////////////////////////// + +Canvas.prototype._updateMarker = function(element, marker, add) { + var container; + + if (!element.id) { + element = this._elementRegistry.get(element); + } + + // we need to access all + container = this._elementRegistry._elements[element.id]; + + if (!container) { + return; + } + + forEach([ container.gfx, container.secondaryGfx ], function(gfx) { + if (gfx) { + // invoke either addClass or removeClass based on mode + gfx[add ? 'addClass' : 'removeClass'](marker); + } + }); + + /** + * An event indicating that a marker has been updated for an element + * + * @event element.marker.update + * @type {Object} + * @property {djs.model.Element} element the shape + * @property {Object} gfx the graphical representation of the shape + * @property {String} marker + * @property {Boolean} add true if the marker was added, false if it got removed + */ + this._eventBus.fire('element.marker.update', { element: element, gfx: container.gfx, marker: marker, add: !!add }); +}; + + +/** + * Adds a marker to an element (basically a css class). + * + * Fires the element.marker.update event, making it possible to + * integrate extension into the marker life-cycle, too. + * + * @example + * canvas.addMarker('foo', 'some-marker'); + * + * var fooGfx = canvas.getGraphics('foo'); + * + * fooGfx; // <g class="... some-marker"> ... </g> + * + * @param {String|djs.model.Base} element + * @param {String} marker + */ +Canvas.prototype.addMarker = function(element, marker) { + this._updateMarker(element, marker, true); +}; + + +/** + * Remove a marker from an element. + * + * Fires the element.marker.update event, making it possible to + * integrate extension into the marker life-cycle, too. + * + * @param {String|djs.model.Base} element + * @param {String} marker + */ +Canvas.prototype.removeMarker = function(element, marker) { + this._updateMarker(element, marker, false); +}; + +/** + * Check the existence of a marker on element. + * + * @param {String|djs.model.Base} element + * @param {String} marker + */ +Canvas.prototype.hasMarker = function(element, marker) { + if (!element.id) { + element = this._elementRegistry.get(element); + } + + var gfx = this.getGraphics(element); + + return gfx && gfx.hasClass(marker); +}; + +/** + * Toggles a marker on an element. + * + * Fires the element.marker.update event, making it possible to + * integrate extension into the marker life-cycle, too. + * + * @param {String|djs.model.Base} element + * @param {String} marker + */ +Canvas.prototype.toggleMarker = function(element, marker) { + if(this.hasMarker(element, marker)) { + this.removeMarker(element, marker); + } else { + this.addMarker(element, marker); + } +}; + +Canvas.prototype.getRootElement = function() { + if (!this._rootElement) { + this.setRootElement({ id: '__implicitroot' }); + } + + return this._rootElement; +}; + + + +//////////////// root element handling /////////////////////////// + +/** + * Sets a given element as the new root element for the canvas + * and returns the new root element. + * + * @param {Object|djs.model.Root} element + * @param {Boolean} [override] whether to override the current root element, if any + * + * @return {Object|djs.model.Root} new root element + */ +Canvas.prototype.setRootElement = function(element, override) { + + this._ensureValidId(element); + + var oldRoot = this._rootElement, + elementRegistry = this._elementRegistry, + eventBus = this._eventBus; + + if (oldRoot) { + if (!override) { + throw new Error('rootElement already set, need to specify override'); + } + + // simulate element remove event sequence + eventBus.fire('root.remove', { element: oldRoot }); + eventBus.fire('root.removed', { element: oldRoot }); + + elementRegistry.remove(oldRoot); + } + + var gfx = this.getDefaultLayer(); + + // resemble element add event sequence + eventBus.fire('root.add', { element: element }); + + elementRegistry.add(element, gfx, this._svg); + + eventBus.fire('root.added', { element: element, gfx: gfx }); + + this._rootElement = element; + + return element; +}; + + + +///////////// add functionality /////////////////////////////// + +Canvas.prototype._ensureValidId = function(element) { + if (!element.id) { + throw new Error('element must have an id'); + } + + if (this._elementRegistry.get(element.id)) { + throw new Error('element with id ' + element.id + ' already exists'); + } +}; + +Canvas.prototype._setParent = function(element, parent) { + Collections.add(parent.children, element); + element.parent = parent; +}; + +/** + * Adds an element to the canvas. + * + * This wires the parent <-> child relationship between the element and + * a explicitly specified parent or an implicit root element. + * + * During add it emits the events + * + * * <{type}.add> (element, parent) + * * <{type}.added> (element, gfx) + * + * Extensions may hook into these events to perform their magic. + * + * @param {String} type + * @param {Object|djs.model.Base} element + * @param {Object|djs.model.Base} [parent] + * + * @return {Object|djs.model.Base} the added element + */ +Canvas.prototype._addElement = function(type, element, parent) { + + parent = parent || this.getRootElement(); + + var eventBus = this._eventBus, + graphicsFactory = this._graphicsFactory; + + this._ensureValidId(element); + + eventBus.fire(type + '.add', { element: element, parent: parent }); + + this._setParent(element, parent); + + // create graphics + var gfx = graphicsFactory.create(type, element); + + this._elementRegistry.add(element, gfx); + + // update its visual + graphicsFactory.update(type, element, gfx); + + eventBus.fire(type + '.added', { element: element, gfx: gfx }); + + return element; +}; + +/** + * Adds a shape to the canvas + * + * @param {Object|djs.model.Shape} shape to add to the diagram + * @param {djs.model.Base} [parent] + * + * @return {djs.model.Shape} the added shape + */ +Canvas.prototype.addShape = function(shape, parent) { + return this._addElement('shape', shape, parent); +}; + +/** + * Adds a connection to the canvas + * + * @param {Object|djs.model.Connection} connection to add to the diagram + * @param {djs.model.Base} [parent] + * + * @return {djs.model.Connection} the added connection + */ +Canvas.prototype.addConnection = function(connection, parent) { + return this._addElement('connection', connection, parent); +}; + + +/** + * Internal remove element + */ +Canvas.prototype._removeElement = function(element, type) { + + var elementRegistry = this._elementRegistry, + graphicsFactory = this._graphicsFactory, + eventBus = this._eventBus; + + element = elementRegistry.get(element.id || element); + + if (!element) { + // element was removed already + return; + } + + eventBus.fire(type + '.remove', { element: element }); + + graphicsFactory.remove(element); + + // unset parent <-> child relationship + Collections.remove(element.parent && element.parent.children, element); + element.parent = null; + + eventBus.fire(type + '.removed', { element: element }); + + elementRegistry.remove(element); + + return element; +}; + + +/** + * Removes a shape from the canvas + * + * @param {String|djs.model.Shape} shape or shape id to be removed + * + * @return {djs.model.Shape} the removed shape + */ +Canvas.prototype.removeShape = function(shape) { + + /** + * An event indicating that a shape is about to be removed from the canvas. + * + * @memberOf Canvas + * + * @event shape.remove + * @type {Object} + * @property {djs.model.Shape} element the shape descriptor + * @property {Object} gfx the graphical representation of the shape + */ + + /** + * An event indicating that a shape has been removed from the canvas. + * + * @memberOf Canvas + * + * @event shape.removed + * @type {Object} + * @property {djs.model.Shape} element the shape descriptor + * @property {Object} gfx the graphical representation of the shape + */ + return this._removeElement(shape, 'shape'); +}; + + +/** + * Removes a connection from the canvas + * + * @param {String|djs.model.Connection} connection or connection id to be removed + * + * @return {djs.model.Connection} the removed connection + */ +Canvas.prototype.removeConnection = function(connection) { + + /** + * An event indicating that a connection is about to be removed from the canvas. + * + * @memberOf Canvas + * + * @event connection.remove + * @type {Object} + * @property {djs.model.Connection} element the connection descriptor + * @property {Object} gfx the graphical representation of the connection + */ + + /** + * An event indicating that a connection has been removed from the canvas. + * + * @memberOf Canvas + * + * @event connection.removed + * @type {Object} + * @property {djs.model.Connection} element the connection descriptor + * @property {Object} gfx the graphical representation of the connection + */ + return this._removeElement(connection, 'connection'); +}; + + +/** + * Sends a shape to the front. + * + * This method takes parent / child relationships between shapes into account + * and makes sure that children are properly handled, too. + * + * @param {djs.model.Shape} shape descriptor of the shape to be sent to front + * @param {boolean} [bubble=true] whether to send parent shapes to front, too + */ +Canvas.prototype.sendToFront = function(shape, bubble) { + + if (bubble !== false) { + bubble = true; + } + + if (bubble && shape.parent) { + this.sendToFront(shape.parent); + } + + forEach(shape.children, function(child) { + this.sendToFront(child, false); + }, this); + + var gfx = this.getGraphics(shape), + gfxParent = gfx.parent(); + + gfx.remove().appendTo(gfxParent); +}; + + +/** + * Return the graphical object underlaying a certain diagram element + * + * @param {String|djs.model.Base} element descriptor of the element + * @param {Boolean} [secondary=false] whether to return the secondary connected element + * + * @return {SVGElement} + */ +Canvas.prototype.getGraphics = function(element, secondary) { + return this._elementRegistry.getGraphics(element, secondary); +}; + + +Canvas.prototype._fireViewboxChange = function() { + this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox(false) }); +}; + + +/** + * Gets or sets the view box of the canvas, i.e. the area that is currently displayed + * + * @param {Object} [box] the new view box to set + * @param {Number} box.x the top left X coordinate of the canvas visible in view box + * @param {Number} box.y the top left Y coordinate of the canvas visible in view box + * @param {Number} box.width the visible width + * @param {Number} box.height + * + * @example + * + * canvas.viewbox({ x: 100, y: 100, width: 500, height: 500 }) + * + * // sets the visible area of the diagram to (100|100) -> (600|100) + * // and and scales it according to the diagram width + * + * @return {Object} the current view box + */ +Canvas.prototype.viewbox = function(box) { + + if (box === undefined && this._cachedViewbox) { + return this._cachedViewbox; + } + + var viewport = this._viewport, + innerBox, + outerBox = this.getSize(), + matrix, + scale, + x, y; + + if (!box) { + // compute the inner box based on the + // diagrams default layer. This allows us to exclude + // external components, such as overlays + innerBox = this.getDefaultLayer().getBBox(true); + + matrix = viewport.transform().localMatrix; + scale = round(matrix.a, 1000); + + x = round(-matrix.e || 0, 1000); + y = round(-matrix.f || 0, 1000); + + box = this._cachedViewbox = { + x: x ? x / scale : 0, + y: y ? y / scale : 0, + width: outerBox.width / scale, + height: outerBox.height / scale, + scale: scale, + inner: { + width: innerBox.width, + height: innerBox.height, + x: innerBox.x, + y: innerBox.y + }, + outer: outerBox + }; + + return box; + } else { + scale = Math.min(outerBox.width / box.width, outerBox.height / box.height); + + matrix = new Snap.Matrix().scale(scale).translate(-box.x, -box.y); + viewport.transform(matrix); + + this._fireViewboxChange(); + } + + return box; +}; + + +/** + * Gets or sets the scroll of the canvas. + * + * @param {Object} [delta] the new scroll to apply. + * + * @param {Number} [delta.dx] + * @param {Number} [delta.dy] + */ +Canvas.prototype.scroll = function(delta) { + + var node = this._viewport.node; + var matrix = node.getCTM(); + + if (delta) { + delta = assign({ dx: 0, dy: 0 }, delta || {}); + + matrix = this._svg.node.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix); + + setCTM(node, matrix); + + this._fireViewboxChange(); + } + + return { x: matrix.e, y: matrix.f }; +}; + + +/** + * Gets or sets the current zoom of the canvas, optionally zooming to the specified position. + * + * @param {String|Number} [newScale] the new zoom level, either a number, i.e. 0.9, + * or `fit-viewport` to adjust the size to fit the current viewport + * @param {String|Point} [center] the reference point { x: .., y: ..} to zoom to, 'auto' to zoom into mid or null + * + * @return {Number} the current scale + */ +Canvas.prototype.zoom = function(newScale, center) { + + if (newScale === 'fit-viewport') { + return this._fitViewport(center); + } + + var vbox = this.viewbox(); + + if (newScale === undefined) { + return vbox.scale; + } + + var outer = vbox.outer; + + if (center === 'auto') { + center = { + x: outer.width / 2, + y: outer.height / 2 + }; + } + + var matrix = this._setZoom(newScale, center); + + this._fireViewboxChange(); + + return round(matrix.a, 1000); +}; + +function setCTM(node, m) { + var mstr = 'matrix(' + m.a + ',' + m.b + ',' + m.c + ',' + m.d + ',' + m.e + ',' + m.f + ')'; + node.setAttribute('transform', mstr); +} + +Canvas.prototype._fitViewport = function(center) { + + var vbox = this.viewbox(), + outer = vbox.outer, + inner = vbox.inner, + newScale, + newViewbox; + + // display the complete diagram without zooming in. + // instead of relying on internal zoom, we perform a + // hard reset on the canvas viewbox to realize this + // + // if diagram does not need to be zoomed in, we focus it around + // the diagram origin instead + + if (inner.x >= 0 && + inner.y >= 0 && + inner.x + inner.width <= outer.width && + inner.y + inner.height <= outer.height && + !center) { + + newViewbox = { + x: 0, + y: 0, + width: Math.max(inner.width + inner.x, outer.width), + height: Math.max(inner.height + inner.y, outer.height) + }; + } else { + + newScale = Math.min(1, outer.width / inner.width, outer.height / inner.height); + newViewbox = { + x: inner.x + (center ? inner.width / 2 - outer.width / newScale / 2 : 0), + y: inner.y + (center ? inner.height / 2 - outer.height / newScale / 2 : 0), + width: outer.width / newScale, + height: outer.height / newScale + }; + } + + this.viewbox(newViewbox); + + return this.viewbox().scale; +}; + + +Canvas.prototype._setZoom = function(scale, center) { + + var svg = this._svg.node, + viewport = this._viewport.node; + + var matrix = svg.createSVGMatrix(); + var point = svg.createSVGPoint(); + + var centerPoint, + originalPoint, + currentMatrix, + scaleMatrix, + newMatrix; + + currentMatrix = viewport.getCTM(); + + + var currentScale = currentMatrix.a; + + if (center) { + centerPoint = assign(point, center); + + // revert applied viewport transformations + originalPoint = centerPoint.matrixTransform(currentMatrix.inverse()); + + // create scale matrix + scaleMatrix = matrix + .translate(originalPoint.x, originalPoint.y) + .scale(1 / currentScale * scale) + .translate(-originalPoint.x, -originalPoint.y); + + newMatrix = currentMatrix.multiply(scaleMatrix); + } else { + newMatrix = matrix.scale(scale); + } + + setCTM(this._viewport.node, newMatrix); + + return newMatrix; +}; + + +/** + * Returns the size of the canvas + * + * @return {Dimensions} + */ +Canvas.prototype.getSize = function () { + return { + width: this._container.clientWidth, + height: this._container.clientHeight + }; +}; + + +/** + * Return the absolute bounding box for the given element + * + * The absolute bounding box may be used to display overlays in the + * callers (browser) coordinate system rather than the zoomed in/out + * canvas coordinates. + * + * @param {ElementDescriptor} element + * @return {Bounds} the absolute bounding box + */ +Canvas.prototype.getAbsoluteBBox = function(element) { + var vbox = this.viewbox(); + var bbox; + + // connection + // use svg bbox + if (element.waypoints) { + var gfx = this.getGraphics(element); + + var transformBBox = gfx.getBBox(true); + bbox = gfx.getBBox(); + + bbox.x -= transformBBox.x; + bbox.y -= transformBBox.y; + + bbox.width += 2 * transformBBox.x; + bbox.height += 2 * transformBBox.y; + } + // shapes + // use data + else { + bbox = element; + } + + var x = bbox.x * vbox.scale - vbox.x * vbox.scale; + var y = bbox.y * vbox.scale - vbox.y * vbox.scale; + + var width = bbox.width * vbox.scale; + var height = bbox.height * vbox.scale; + + return { + x: x, + y: y, + width: width, + height: height + }; +}; + +},{"169":169,"175":175,"63":63,"74":74,"84":84}],39:[function(_dereq_,module,exports){ +'use strict'; + +var Model = _dereq_(57); + + +/** + * A factory for diagram-js shapes + */ +function ElementFactory() { + this._uid = 12; +} + +module.exports = ElementFactory; + + +ElementFactory.prototype.createRoot = function(attrs) { + return this.create('root', attrs); +}; + +ElementFactory.prototype.createLabel = function(attrs) { + return this.create('label', attrs); +}; + +ElementFactory.prototype.createShape = function(attrs) { + return this.create('shape', attrs); +}; + +ElementFactory.prototype.createConnection = function(attrs) { + return this.create('connection', attrs); +}; + +/** + * Create a model element with the given type and + * a number of pre-set attributes. + * + * @param {String} type + * @param {Object} attrs + * @return {djs.model.Base} the newly created model instance + */ +ElementFactory.prototype.create = function(type, attrs) { + + attrs = attrs || {}; + + if (!attrs.id) { + attrs.id = type + '_' + (this._uid++); + } + + return Model.create(type, attrs); +}; +},{"57":57}],40:[function(_dereq_,module,exports){ +'use strict'; + +var ELEMENT_ID = 'data-element-id'; + + +/** + * @class + * + * A registry that keeps track of all shapes in the diagram. + */ +function ElementRegistry() { + this._elements = {}; +} + +module.exports = ElementRegistry; + +/** + * Register a pair of (element, gfx, (secondaryGfx)). + * + * @param {djs.model.Base} element + * @param {Snap<SVGElement>} gfx + * @param {Snap<SVGElement>} [secondaryGfx] optional other element to register, too + */ +ElementRegistry.prototype.add = function(element, gfx, secondaryGfx) { + + var id = element.id; + + this._validateId(id); + + // associate dom node with element + gfx.attr(ELEMENT_ID, id); + + if (secondaryGfx) { + secondaryGfx.attr(ELEMENT_ID, id); + } + + this._elements[id] = { element: element, gfx: gfx, secondaryGfx: secondaryGfx }; +}; + +/** + * Removes an element from the registry. + * + * @param {djs.model.Base} element + */ +ElementRegistry.prototype.remove = function(element) { + var elements = this._elements, + id = element.id || element, + container = id && elements[id]; + + if (container) { + + // unset element id on gfx + container.gfx.attr(ELEMENT_ID, null); + + if (container.secondaryGfx) { + container.secondaryGfx.attr(ELEMENT_ID, null); + } + + delete elements[id]; + } +}; + +/** + * Update the id of an element + * + * @param {djs.model.Base} element + * @param {String} newId + */ +ElementRegistry.prototype.updateId = function(element, newId) { + + this._validateId(newId); + + if (typeof element === 'string') { + element = this.get(element); + } + + var gfx = this.getGraphics(element), + secondaryGfx = this.getGraphics(element, true); + + this.remove(element); + + element.id = newId; + + this.add(element, gfx, secondaryGfx); +}; + +/** + * Return the model element for a given id or graphics. + * + * @example + * + * elementRegistry.get('SomeElementId_1'); + * elementRegistry.get(gfx); + * + * + * @param {String|SVGElement} filter for selecting the element + * + * @return {djs.model.Base} + */ +ElementRegistry.prototype.get = function(filter) { + var id; + + if (typeof filter === 'string') { + id = filter; + } else { + id = filter && filter.attr(ELEMENT_ID); + } + + var container = this._elements[id]; + return container && container.element; +}; + +/** + * Return all elements that match a given filter function. + * + * @param {Function} fn + * + * @return {Array<djs.model.Base>} + */ +ElementRegistry.prototype.filter = function(fn) { + + var filtered = []; + + this.forEach(function(element, gfx) { + if(fn(element, gfx)) { + filtered.push(element); + } + }); + + return filtered; +}; + +/** + * Iterate over all diagram elements. + * + * @param {Function} fn + */ +ElementRegistry.prototype.forEach = function(fn) { + + var map = this._elements; + + Object.keys(map).forEach(function(id) { + var container = map[id], + element = container.element, + gfx = container.gfx; + + return fn(element, gfx); + }); +}; + +/** + * Return the graphical representation of an element or its id. + * + * @example + * elementRegistry.getGraphics('SomeElementId_1'); + * elementRegistry.getGraphics(rootElement); // <g ...> + * + * elementRegistry.getGraphics(rootElement, true); // <svg ...> + * + * + * @param {String|djs.model.Base} filter + * @param {Boolean} [secondary=false] whether to return the secondary connected element + * + * @return {SVGElement} + */ +ElementRegistry.prototype.getGraphics = function(filter, secondary) { + var id = filter.id || filter; + + var container = this._elements[id]; + return container && (secondary ? container.secondaryGfx : container.gfx); +}; + +/** + * Validate the suitability of the given id and signals a problem + * with an exception. + * + * @param {String} id + * + * @throws {Error} if id is empty or already assigned + */ +ElementRegistry.prototype._validateId = function(id) { + if (!id) { + throw new Error('element must have an id'); + } + + if (this._elements[id]) { + throw new Error('element with id ' + id + ' already added'); + } +}; +},{}],41:[function(_dereq_,module,exports){ +'use strict'; + +var isFunction = _dereq_(167), + isArray = _dereq_(166), + isNumber = _dereq_(169), + assign = _dereq_(175); + +var DEFAULT_PRIORITY = 1000; + + +/** + * A general purpose event bus. + * + * This component is used to communicate across a diagram instance. + * Other parts of a diagram can use it to listen to and broadcast events. + * + * + * ## Registering for Events + * + * The event bus provides the {@link EventBus#on} and {@link EventBus#once} + * methods to register for events. {@link EventBus#off} can be used to + * remove event registrations. Listeners receive an instance of {@link Event} + * as the first argument. It allows them to hook into the event execution. + * + * ```javascript + * + * // listen for event + * eventBus.on('foo', function(event) { + * + * // access event type + * event.type; // 'foo' + * + * // stop propagation to other listeners + * event.stopPropagation(); + * + * // prevent event default + * event.preventDefault(); + * }); + * + * // listen for event with custom payload + * eventBus.on('bar', function(event, payload) { + * console.log(payload); + * }); + * + * // listen for event returning value + * eventBus.on('foobar', function(event) { + * + * // stop event propagation + prevent default + * return false; + * + * // stop event propagation + return custom result + * return { + * complex: 'listening result' + * }; + * }); + * + * + * // listen with custom priority (default=1000, higher is better) + * eventBus.on('priorityfoo', 1500, function(event) { + * console.log('invoked first!'); + * }); + * ``` + * + * + * ## Emitting Events + * + * Events can be emitted via the event bus using {@link EventBus#fire}. + * + * ```javascript + * + * // false indicates that the default action + * // was prevented by listeners + * if (eventBus.fire('foo') === false) { + * console.log('default has been prevented!'); + * }; + * + * + * // custom args + return value listener + * eventBus.on('sum', function(event, a, b) { + * return a + b; + * }); + * + * // you can pass custom arguments + retrieve result values. + * var sum = eventBus.fire('sum', 1, 2); + * console.log(sum); // 3 + * ``` + */ +function EventBus() { + this._listeners = {}; + + // cleanup on destroy + + var self = this; + + // destroy on lowest priority to allow + // message passing until the bitter end + this.on('diagram.destroy', 1, function() { + self._listeners = null; + }); +} + +module.exports = EventBus; + + +/** + * Register an event listener for events with the given name. + * + * The callback will be invoked with `event, ...additionalArguments` + * that have been passed to {@link EventBus#fire}. + * + * Returning false from a listener will prevent the events default action + * (if any is specified). To stop an event from being processed further in + * other listeners execute {@link Event#stopPropagation}. + * + * Returning anything but `undefined` from a listener will stop the listener propagation. + * + * @param {String|Array<String>} events + * @param {Number} [priority=1000] the priority in which this listener is called, larger is higher + * @param {Function} callback + */ +EventBus.prototype.on = function(events, priority, callback) { + + events = isArray(events) ? events : [ events ]; + + if (isFunction(priority)) { + callback = priority; + priority = DEFAULT_PRIORITY; + } + + if (!isNumber(priority)) { + throw new Error('priority must be a number'); + } + + var self = this, + listener = { priority: priority, callback: callback }; + + events.forEach(function(e) { + self._addListener(e, listener); + }); +}; + + +/** + * Register an event listener that is executed only once. + * + * @param {String} event the event name to register for + * @param {Function} callback the callback to execute + */ +EventBus.prototype.once = function(event, callback) { + + var self = this; + + function wrappedCallback() { + callback.apply(self, arguments); + self.off(event, wrappedCallback); + } + + this.on(event, wrappedCallback); +}; + + +/** + * Removes event listeners by event and callback. + * + * If no callback is given, all listeners for a given event name are being removed. + * + * @param {String} event + * @param {Function} [callback] + */ +EventBus.prototype.off = function(event, callback) { + var listeners = this._getListeners(event), + listener, idx; + + if (callback) { + + // move through listeners from back to front + // and remove matching listeners + for (idx = listeners.length - 1; !!(listener = listeners[idx]); idx--) { + if (listener.callback === callback) { + listeners.splice(idx, 1); + } + } + } else { + // clear listeners + listeners.length = 0; + } +}; + + +/** + * Fires a named event. + * + * @example + * + * // fire event by name + * events.fire('foo'); + * + * // fire event object with nested type + * var event = { type: 'foo' }; + * events.fire(event); + * + * // fire event with explicit type + * var event = { x: 10, y: 20 }; + * events.fire('element.moved', event); + * + * // pass additional arguments to the event + * events.on('foo', function(event, bar) { + * alert(bar); + * }); + * + * events.fire({ type: 'foo' }, 'I am bar!'); + * + * @param {String} [name] the optional event name + * @param {Object} [event] the event object + * @param {...Object} additional arguments to be passed to the callback functions + * + * @return {Boolean} the events return value, if specified or false if the + * default action was prevented by listeners + */ +EventBus.prototype.fire = function(type, data) { + + var event, + originalType, + listeners, idx, listener, + returnValue, + args; + + args = Array.prototype.slice.call(arguments); + + if (typeof type === 'object') { + event = type; + type = event.type; + } + + if (!type) { + throw new Error('no event type specified'); + } + + listeners = this._listeners[type]; + + if (!listeners) { + return; + } + + // we make sure we fire instances of our home made + // events here. We wrap them only once, though + if (data instanceof Event) { + // we are fine, we alread have an event + event = data; + } else { + event = new Event(); + event.init(data); + } + + // ensure we pass the event as the first parameter + args[0] = event; + + // original event type (in case we delegate) + originalType = event.type; + + try { + + // update event type before delegation + if (type !== originalType) { + event.type = type; + } + + for (idx = 0; !!(listener = listeners[idx]); idx++) { + + // handle stopped propagation + if (event.cancelBubble) { + break; + } + + try { + // returning false prevents the default action + returnValue = event.returnValue = listener.callback.apply(null, args); + + // stop propagation on return value + if (returnValue !== undefined) { + event.stopPropagation(); + } + + // prevent default on return false + if (returnValue === false) { + event.preventDefault(); + } + } catch (e) { + if (!this.handleError(e)) { + console.error('unhandled error in event listener'); + console.error(e.stack); + + throw e; + } + } + } + } finally { + // reset event type after delegation + if (type !== originalType) { + event.type = originalType; + } + } + + // set the return value to false if the event default + // got prevented and no other return value exists + if (returnValue === undefined && event.defaultPrevented) { + returnValue = false; + } + + return returnValue; +}; + + +EventBus.prototype.handleError = function(error) { + return this.fire('error', { error: error }) === false; +}; + + +/* + * Add new listener with a certain priority to the list + * of listeners (for the given event). + * + * The semantics of listener registration / listener execution are + * first register, first serve: New listeners will always be inserted + * after existing listeners with the same priority. + * + * Example: Inserting two listeners with priority 1000 and 1300 + * + * * before: [ 1500, 1500, 1000, 1000 ] + * * after: [ 1500, 1500, (new=1300), 1000, 1000, (new=1000) ] + * + * @param {String} event + * @param {Object} listener { priority, callback } + */ +EventBus.prototype._addListener = function(event, newListener) { + + var listeners = this._getListeners(event), + existingListener, + idx; + + // ensure we order listeners by priority from + // 0 (high) to n > 0 (low) + for (idx = 0; !!(existingListener = listeners[idx]); idx++) { + if (existingListener.priority < newListener.priority) { + + // prepend newListener at before existingListener + listeners.splice(idx, 0, newListener); + return; + } + } + + listeners.push(newListener); +}; + + +EventBus.prototype._getListeners = function(name) { + var listeners = this._listeners[name]; + + if (!listeners) { + this._listeners[name] = listeners = []; + } + + return listeners; +}; + + +/** + * A event that is emitted via the event bus. + */ +function Event() { } + +module.exports.Event = Event; + +Event.prototype.stopPropagation = function() { + this.cancelBubble = true; +}; + +Event.prototype.preventDefault = function() { + this.defaultPrevented = true; +}; + +Event.prototype.init = function(data) { + assign(this, data || {}); +}; + +},{"166":166,"167":167,"169":169,"175":175}],42:[function(_dereq_,module,exports){ +'use strict'; + +var forEach = _dereq_(84), + reduce = _dereq_(88); + +var GraphicsUtil = _dereq_(67), + domClear = _dereq_(188); + +/** + * A factory that creates graphical elements + * + * @param {Renderer} renderer + */ +function GraphicsFactory(renderer, elementRegistry) { + this._renderer = renderer; + this._elementRegistry = elementRegistry; +} + +GraphicsFactory.$inject = [ 'renderer', 'elementRegistry' ]; + +module.exports = GraphicsFactory; + + +GraphicsFactory.prototype._getChildren = function(element) { + + var gfx = this._elementRegistry.getGraphics(element); + + var childrenGfx; + + // root element + if (!element.parent) { + childrenGfx = gfx; + } else { + childrenGfx = GraphicsUtil.getChildren(gfx); + if (!childrenGfx) { + childrenGfx = gfx.parent().group().attr('class', 'djs-children'); + } + } + + return childrenGfx; +}; + +/** + * Clears the graphical representation of the element and returns the + * cleared visual (the <g class="djs-visual" /> element). + */ +GraphicsFactory.prototype._clear = function(gfx) { + var visual = GraphicsUtil.getVisual(gfx); + + domClear(visual.node); + + return visual; +}; + +/** + * Creates a gfx container for shapes and connections + * + * The layout is as follows: + * + * <g class="djs-group"> + * + * <!-- the gfx --> + * <g class="djs-element djs-(shape|connection)"> + * <g class="djs-visual"> + * <!-- the renderer draws in here --> + * </g> + * + * <!-- extensions (overlays, click box, ...) goes here + * </g> + * + * <!-- the gfx child nodes --> + * <g class="djs-children"></g> + * </g> + * + * @param {Object} parent + * @param {String} type the type of the element, i.e. shape | connection + */ +GraphicsFactory.prototype._createContainer = function(type, parentGfx) { + var outerGfx = parentGfx.group().attr('class', 'djs-group'), + gfx = outerGfx.group().attr('class', 'djs-element djs-' + type); + + // create visual + gfx.group().attr('class', 'djs-visual'); + + return gfx; +}; + +GraphicsFactory.prototype.create = function(type, element) { + var childrenGfx = this._getChildren(element.parent); + return this._createContainer(type, childrenGfx); +}; + + +GraphicsFactory.prototype.updateContainments = function(elements) { + + var self = this, + elementRegistry = this._elementRegistry, + parents; + + + parents = reduce(elements, function(map, e) { + + if (e.parent) { + map[e.parent.id] = e.parent; + } + + return map; + }, {}); + + // update all parents of changed and reorganized their children + // in the correct order (as indicated in our model) + forEach(parents, function(parent) { + + var childGfx = self._getChildren(parent), + children = parent.children; + + if (!children) { + return; + } + + forEach(children.slice().reverse(), function(c) { + var gfx = elementRegistry.getGraphics(c); + gfx.parent().prependTo(childGfx); + }); + }); + +}; + +GraphicsFactory.prototype.update = function(type, element, gfx) { + + // Do not update root element + if (!element.parent) { + return; + } + + var visual = this._clear(gfx); + + // redraw + if (type === 'shape') { + this._renderer.drawShape(visual, element); + + // update positioning + gfx.translate(element.x, element.y); + } else + if (type === 'connection') { + this._renderer.drawConnection(visual, element); + } else { + throw new Error('unknown type: ' + type); + } + + gfx.attr('display', element.hidden ? 'none' : 'block'); +}; + + +GraphicsFactory.prototype.remove = function(element) { + var gfx = this._elementRegistry.getGraphics(element); + + // remove + gfx.parent().remove(); +}; + +},{"188":188,"67":67,"84":84,"88":88}],43:[function(_dereq_,module,exports){ +module.exports = { + __depends__: [ _dereq_(46) ], + __init__: [ 'canvas' ], + canvas: [ 'type', _dereq_(38) ], + elementRegistry: [ 'type', _dereq_(40) ], + elementFactory: [ 'type', _dereq_(39) ], + eventBus: [ 'type', _dereq_(41) ], + graphicsFactory: [ 'type', _dereq_(42) ] +}; +},{"38":38,"39":39,"40":40,"41":41,"42":42,"46":46}],44:[function(_dereq_,module,exports){ +'use strict'; + +var Snap = _dereq_(74); + + +/** + * The default renderer used for shapes and connections. + * + * @param {Styles} styles + */ +function Renderer(styles) { + this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' }); + this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 }); +} + +module.exports = Renderer; + +Renderer.$inject = ['styles']; + + +Renderer.prototype.drawShape = function drawShape(gfxGroup, data) { + return gfxGroup.rect(0, 0, data.width || 0, data.height || 0).attr(this.SHAPE_STYLE); +}; + +Renderer.prototype.drawConnection = function drawConnection(gfxGroup, data) { + return createLine(data.waypoints, this.CONNECTION_STYLE).appendTo(gfxGroup); +}; + +function componentsToPath(components) { + return components.join(',').replace(/,?([A-z]),?/g, '$1'); +} + +/** + * Gets the default SVG path of a shape that represents it's visual bounds. + * + * @param {djs.model.Shape} shape + * @return {string} svg path + */ +Renderer.prototype.getShapePath = function getShapePath(shape) { + + var x = shape.x, + y = shape.y, + width = shape.width, + height = shape.height; + + var shapePath = [ + ['M', x, y], + ['l', width, 0], + ['l', 0, height], + ['l', -width, 0], + ['z'] + ]; + + return componentsToPath(shapePath); +}; + +/** + * Gets the default SVG path of a connection that represents it's visual bounds. + * + * @param {djs.model.Connection} connection + * @return {string} svg path + */ +Renderer.prototype.getConnectionPath = function getConnectionPath(connection) { + var waypoints = connection.waypoints; + + var idx, point, connectionPath = []; + + for (idx = 0; !!(point = waypoints[idx]); idx++) { + + // take invisible docking into account + // when creating the path + point = point.original || point; + + connectionPath.push([ idx === 0 ? 'M' : 'L', point.x, point.y ]); + } + + return componentsToPath(connectionPath); +}; + + +function toSVGPoints(points) { + var result = ''; + + for (var i = 0, p; !!(p = points[i]); i++) { + result += p.x + ',' + p.y + ' '; + } + + return result; +} + +function createLine(points, attrs) { + return Snap.create('polyline', { points: toSVGPoints(points) }).attr(attrs || {}); +} + +function updateLine(gfx, points) { + return gfx.attr({ points: toSVGPoints(points) }); +} + +module.exports.createLine = createLine; +module.exports.updateLine = updateLine; +},{"74":74}],45:[function(_dereq_,module,exports){ +'use strict'; + +var isArray = _dereq_(166), + assign = _dereq_(175), + reduce = _dereq_(88); + + +/** + * A component that manages shape styles + */ +function Styles() { + + var defaultTraits = { + + 'no-fill': { + fill: 'none' + }, + 'no-border': { + strokeOpacity: 0.0 + }, + 'no-events': { + pointerEvents: 'none' + } + }; + + /** + * Builds a style definition from a className, a list of traits and an object of additional attributes. + * + * @param {String} className + * @param {Array<String>} traits + * @param {Object} additionalAttrs + * + * @return {Object} the style defintion + */ + this.cls = function(className, traits, additionalAttrs) { + var attrs = this.style(traits, additionalAttrs); + + return assign(attrs, { 'class': className }); + }; + + /** + * Builds a style definition from a list of traits and an object of additional attributes. + * + * @param {Array<String>} traits + * @param {Object} additionalAttrs + * + * @return {Object} the style defintion + */ + this.style = function(traits, additionalAttrs) { + + if (!isArray(traits) && !additionalAttrs) { + additionalAttrs = traits; + traits = []; + } + + var attrs = reduce(traits, function(attrs, t) { + return assign(attrs, defaultTraits[t] || {}); + }, {}); + + return additionalAttrs ? assign(attrs, additionalAttrs) : attrs; + }; +} + +module.exports = Styles; +},{"166":166,"175":175,"88":88}],46:[function(_dereq_,module,exports){ +module.exports = { + renderer: [ 'type', _dereq_(44) ], + styles: [ 'type', _dereq_(45) ] +}; +},{"44":44,"45":45}],47:[function(_dereq_,module,exports){ +'use strict'; + +var forEach = _dereq_(84), + domDelegate = _dereq_(189), + Renderer = _dereq_(44), + createLine = Renderer.createLine, + updateLine = Renderer.updateLine; + + +var isPrimaryButton = _dereq_(69).isPrimaryButton; + +var Snap = _dereq_(74); + +/** + * A plugin that provides interaction events for diagram elements. + * + * It emits the following events: + * + * * element.hover + * * element.out + * * element.click + * * element.dblclick + * * element.mousedown + * + * Each event is a tuple { element, gfx, originalEvent }. + * + * Canceling the event via Event#preventDefault() prevents the original DOM operation. + * + * @param {EventBus} eventBus + */ +function InteractionEvents(eventBus, elementRegistry, styles) { + + var HIT_STYLE = styles.cls('djs-hit', [ 'no-fill', 'no-border' ], { + stroke: 'white', + strokeWidth: 15 + }); + + function fire(type, event) { + var target = event.delegateTarget || event.target, + gfx = target && new Snap(target), + element = elementRegistry.get(gfx), + returnValue; + + if (!gfx || !element) { + return; + } + + returnValue = eventBus.fire(type, { element: element, gfx: gfx, originalEvent: event }); + + if (returnValue === false) { + event.stopPropagation(); + event.preventDefault(); + } + } + + var handlers = {}; + + function mouseHandler(type) { + + var fn = handlers[type]; + + if (!fn) { + fn = handlers[type] = function(event) { + // only indicate left mouse button interactions + if (isPrimaryButton(event)) { + fire(type, event); + } + }; + } + + return fn; + } + + var bindings = { + mouseover: 'element.hover', + mouseout: 'element.out', + click: 'element.click', + dblclick: 'element.dblclick', + mousedown: 'element.mousedown', + mouseup: 'element.mouseup' + }; + + var elementSelector = 'svg, .djs-element'; + + ///// event registration + + function registerEvent(node, event, localEvent) { + var handler = mouseHandler(localEvent); + handler.$delegate = domDelegate.bind(node, elementSelector, event, handler); + } + + function unregisterEvent(node, event, localEvent) { + domDelegate.unbind(node, event, mouseHandler(localEvent).$delegate); + } + + function registerEvents(svg) { + forEach(bindings, function(val, key) { + registerEvent(svg.node, key, val); + }); + } + + function unregisterEvents(svg) { + forEach(bindings, function(val, key) { + unregisterEvent(svg.node, key, val); + }); + } + + eventBus.on('canvas.destroy', function(event) { + unregisterEvents(event.svg); + }); + + eventBus.on('canvas.init', function(event) { + registerEvents(event.svg); + }); + + + eventBus.on([ 'shape.added', 'connection.added' ], function(event) { + var element = event.element, + gfx = event.gfx, + hit, + type; + + if (element.waypoints) { + hit = createLine(element.waypoints); + type = 'connection'; + } else { + hit = Snap.create('rect', { x: 0, y: 0, width: element.width, height: element.height }); + type = 'shape'; + } + + hit.attr(HIT_STYLE).appendTo(gfx.node); + }); + + // update djs-hit on change + + eventBus.on('shape.changed', function(event) { + + var element = event.element, + gfx = event.gfx, + hit = gfx.select('.djs-hit'); + + hit.attr({ + width: element.width, + height: element.height + }); + }); + + eventBus.on('connection.changed', function(event) { + + var element = event.element, + gfx = event.gfx, + hit = gfx.select('.djs-hit'); + + updateLine(hit, element.waypoints); + }); + + + // API + + this.fire = fire; + + this.mouseHandler = mouseHandler; + + this.registerEvent = registerEvent; + this.unregisterEvent = unregisterEvent; +} + + +InteractionEvents.$inject = [ 'eventBus', 'elementRegistry', 'styles' ]; + +module.exports = InteractionEvents; + + +/** + * An event indicating that the mouse hovered over an element + * + * @event element.hover + * + * @type {Object} + * @property {djs.model.Base} element + * @property {Snap<Element>} gfx + * @property {Event} originalEvent + */ + +/** + * An event indicating that the mouse has left an element + * + * @event element.out + * + * @type {Object} + * @property {djs.model.Base} element + * @property {Snap<Element>} gfx + * @property {Event} originalEvent + */ + +/** + * An event indicating that the mouse has clicked an element + * + * @event element.click + * + * @type {Object} + * @property {djs.model.Base} element + * @property {Snap<Element>} gfx + * @property {Event} originalEvent + */ + +/** + * An event indicating that the mouse has double clicked an element + * + * @event element.dblclick + * + * @type {Object} + * @property {djs.model.Base} element + * @property {Snap<Element>} gfx + * @property {Event} originalEvent + */ + +/** + * An event indicating that the mouse has gone down on an element. + * + * @event element.mousedown + * + * @type {Object} + * @property {djs.model.Base} element + * @property {Snap<Element>} gfx + * @property {Event} originalEvent + */ + +/** + * An event indicating that the mouse has gone up on an element. + * + * @event element.mouseup + * + * @type {Object} + * @property {djs.model.Base} element + * @property {Snap<Element>} gfx + * @property {Event} originalEvent + */ +},{"189":189,"44":44,"69":69,"74":74,"84":84}],48:[function(_dereq_,module,exports){ +module.exports = { + __init__: [ 'interactionEvents' ], + interactionEvents: [ 'type', _dereq_(47) ] +}; +},{"47":47}],49:[function(_dereq_,module,exports){ +'use strict'; + +var Snap = _dereq_(74); +var getBBox = _dereq_(65).getBBox; + + +/** + * @class + * + * A plugin that adds an outline to shapes and connections that may be activated and styled + * via CSS classes. + * + * @param {EventBus} events the event bus + */ +function Outline(eventBus, styles, elementRegistry) { + + var OUTLINE_OFFSET = 6; + + var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]); + + function createOutline(gfx, bounds) { + return Snap.create('rect', OUTLINE_STYLE).prependTo(gfx); + } + + function updateShapeOutline(outline, bounds) { + + outline.attr({ + x: -OUTLINE_OFFSET, + y: -OUTLINE_OFFSET, + width: bounds.width + OUTLINE_OFFSET * 2, + height: bounds.height + OUTLINE_OFFSET * 2 + }); + } + + function updateConnectionOutline(outline, connection) { + + var bbox = getBBox(connection); + + outline.attr({ + x: bbox.x - OUTLINE_OFFSET, + y: bbox.y - OUTLINE_OFFSET, + width: bbox.width + OUTLINE_OFFSET * 2, + height: bbox.height + OUTLINE_OFFSET * 2 + }); + } + + eventBus.on([ 'shape.added', 'shape.changed' ], function(event) { + var element = event.element, + gfx = event.gfx; + + var outline = gfx.select('.djs-outline'); + + if (!outline) { + outline = createOutline(gfx, element); + } + + updateShapeOutline(outline, element); + }); + + eventBus.on([ 'connection.added', 'connection.changed' ], function(event) { + var element = event.element, + gfx = event.gfx; + + var outline = gfx.select('.djs-outline'); + + if (!outline) { + outline = createOutline(gfx, element); + } + + updateConnectionOutline(outline, element); + }); + + +} + + +Outline.$inject = ['eventBus', 'styles', 'elementRegistry']; + +module.exports = Outline; + +},{"65":65,"74":74}],50:[function(_dereq_,module,exports){ +'use strict'; + +module.exports = { + __init__: [ 'outline' ], + outline: [ 'type', _dereq_(49) ] +}; +},{"49":49}],51:[function(_dereq_,module,exports){ +'use strict'; + +var isArray = _dereq_(166), + isString = _dereq_(172), + isObject = _dereq_(170), + assign = _dereq_(175), + forEach = _dereq_(84), + filter = _dereq_(82), + debounce = _dereq_(91); + +var domify = _dereq_(190), + domClasses = _dereq_(187), + domRemove = _dereq_(193); + +var getBBox = _dereq_(65).getBBox; + +// document wide unique overlay ids +var ids = new (_dereq_(68))('ov'); + + +function createRoot(parent) { + var root = domify('<div class="djs-overlay-container" style="position: absolute; width: 0; height: 0;" />'); + parent.insertBefore(root, parent.firstChild); + + return root; +} + + +function setPosition(el, x, y) { + assign(el.style, { left: x + 'px', top: y + 'px' }); +} + +function setVisible(el, visible) { + el.style.display = visible === false ? 'none' : ''; +} + +/** + * A service that allows users to attach overlays to diagram elements. + * + * The overlay service will take care of overlay positioning during updates. + * + * @example + * + * // add a pink badge on the top left of the shape + * overlays.add(someShape, { + * position: { + * top: -5, + * left: -5 + * }, + * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>' + * }); + * + * // or add via shape id + * + * overlays.add('some-element-id', { + * position: { + * top: -5, + * left: -5 + * } + * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>' + * }); + * + * // or add with optional type + * + * overlays.add(someShape, 'badge', { + * position: { + * top: -5, + * left: -5 + * } + * html: '<div style="width: 10px; background: fuchsia; color: white;">0</div>' + * }); + * + * + * // remove an overlay + * + * var id = overlays.add(...); + * overlays.remove(id); + * + * @param {EventBus} eventBus + * @param {Canvas} canvas + * @param {ElementRegistry} elementRegistry + */ +function Overlays(config, eventBus, canvas, elementRegistry) { + + this._eventBus = eventBus; + this._canvas = canvas; + this._elementRegistry = elementRegistry; + + this._ids = ids; + + this._overlayDefaults = { + show: { + minZoom: 0.7, + maxZoom: 5.0 + } + }; + + /** + * Mapping overlayId -> overlay + */ + this._overlays = {}; + + /** + * Mapping elementId -> overlay container + */ + this._overlayContainers = {}; + + // root html element for all overlays + this._overlayRoot = createRoot(canvas.getContainer()); + + this._init(config); +} + + +Overlays.$inject = [ 'config.overlays', 'eventBus', 'canvas', 'elementRegistry' ]; + +module.exports = Overlays; + + +/** + * Returns the overlay with the specified id or a list of overlays + * for an element with a given type. + * + * @example + * + * // return the single overlay with the given id + * overlays.get('some-id'); + * + * // return all overlays for the shape + * overlays.get({ element: someShape }); + * + * // return all overlays on shape with type 'badge' + * overlays.get({ element: someShape, type: 'badge' }); + * + * // shape can also be specified as id + * overlays.get({ element: 'element-id', type: 'badge' }); + * + * + * @param {Object} search + * @param {String} [search.id] + * @param {String|djs.model.Base} [search.element] + * @param {String} [search.type] + * + * @return {Object|Array<Object>} the overlay(s) + */ +Overlays.prototype.get = function(search) { + + if (isString(search)) { + search = { id: search }; + } + + if (search.element) { + var container = this._getOverlayContainer(search.element, true); + + // return a list of overlays when searching by element (+type) + if (container) { + return search.type ? filter(container.overlays, { type: search.type }) : container.overlays.slice(); + } else { + return []; + } + } else + if (search.type) { + return filter(this._overlays, { type: search.type }); + } else { + // return single element when searching by id + return search.id ? this._overlays[search.id] : null; + } +}; + +/** + * Adds a HTML overlay to an element. + * + * @param {String|djs.model.Base} element attach overlay to this shape + * @param {String} [type] optional type to assign to the overlay + * @param {Object} overlay the overlay configuration + * + * @param {String|DOMElement} overlay.html html element to use as an overlay + * @param {Object} [overlay.show] show configuration + * @param {Number} [overlay.show.minZoom] minimal zoom level to show the overlay + * @param {Number} [overlay.show.maxZoom] maximum zoom level to show the overlay + * @param {Object} overlay.position where to attach the overlay + * @param {Number} [overlay.position.left] relative to element bbox left attachment + * @param {Number} [overlay.position.top] relative to element bbox top attachment + * @param {Number} [overlay.position.bottom] relative to element bbox bottom attachment + * @param {Number} [overlay.position.right] relative to element bbox right attachment + * + * @return {String} id that may be used to reference the overlay for update or removal + */ +Overlays.prototype.add = function(element, type, overlay) { + + if (isObject(type)) { + overlay = type; + type = null; + } + + if (!element.id) { + element = this._elementRegistry.get(element); + } + + if (!overlay.position) { + throw new Error('must specifiy overlay position'); + } + + if (!overlay.html) { + throw new Error('must specifiy overlay html'); + } + + if (!element) { + throw new Error('invalid element specified'); + } + + var id = this._ids.next(); + + overlay = assign({}, this._overlayDefaults, overlay, { + id: id, + type: type, + element: element, + html: overlay.html + }); + + this._addOverlay(overlay); + + return id; +}; + + +/** + * Remove an overlay with the given id or all overlays matching the given filter. + * + * @see Overlays#get for filter options. + * + * @param {String} [id] + * @param {Object} [filter] + */ +Overlays.prototype.remove = function(filter) { + + var overlays = this.get(filter) || []; + + if (!isArray(overlays)) { + overlays = [ overlays ]; + } + + var self = this; + + forEach(overlays, function(overlay) { + + var container = self._getOverlayContainer(overlay.element, true); + + if (overlay) { + domRemove(overlay.html); + domRemove(overlay.htmlContainer); + + delete overlay.htmlContainer; + delete overlay.element; + + delete self._overlays[overlay.id]; + } + + if (container) { + var idx = container.overlays.indexOf(overlay); + if (idx !== -1) { + container.overlays.splice(idx, 1); + } + } + }); + +}; + + +Overlays.prototype.show = function() { + setVisible(this._overlayRoot); +}; + + +Overlays.prototype.hide = function() { + setVisible(this._overlayRoot, false); +}; + + +Overlays.prototype._updateOverlayContainer = function(container) { + var element = container.element, + html = container.html; + + // update container left,top according to the elements x,y coordinates + // this ensures we can attach child elements relative to this container + + var x = element.x, + y = element.y; + + if (element.waypoints) { + var bbox = getBBox(element); + x = bbox.x; + y = bbox.y; + } + + setPosition(html, x, y); +}; + + +Overlays.prototype._updateOverlay = function(overlay) { + + var position = overlay.position, + htmlContainer = overlay.htmlContainer, + element = overlay.element; + + // update overlay html relative to shape because + // it is already positioned on the element + + // update relative + var left = position.left, + top = position.top; + + if (position.right !== undefined) { + + var width; + + if (element.waypoints) { + width = getBBox(element).width; + } else { + width = element.width; + } + + left = position.right * -1 + width; + } + + if (position.bottom !== undefined) { + + var height; + + if (element.waypoints) { + height = getBBox(element).height; + } else { + height = element.height; + } + + top = position.bottom * -1 + height; + } + + setPosition(htmlContainer, left || 0, top || 0); +}; + + +Overlays.prototype._createOverlayContainer = function(element) { + var html = domify('<div class="djs-overlays djs-overlays-' + element.id + '" style="position: absolute" />'); + + this._overlayRoot.appendChild(html); + + var container = { + html: html, + element: element, + overlays: [] + }; + + this._updateOverlayContainer(container); + + return container; +}; + + +Overlays.prototype._updateRoot = function(viewbox) { + var a = viewbox.scale || 1; + var d = viewbox.scale || 1; + + var matrix = 'matrix(' + a + ',0,0,' + d + ',' + (-1 * viewbox.x * a) + ',' + (-1 * viewbox.y * d) + ')'; + + this._overlayRoot.style.transform = matrix; + this._overlayRoot.style['-ms-transform'] = matrix; +}; + + +Overlays.prototype._getOverlayContainer = function(element, raw) { + var id = (element && element.id) || element; + + var container = this._overlayContainers[id]; + if (!container && !raw) { + container = this._overlayContainers[id] = this._createOverlayContainer(element); + } + + return container; +}; + + +Overlays.prototype._addOverlay = function(overlay) { + + var id = overlay.id, + element = overlay.element, + html = overlay.html, + htmlContainer, + overlayContainer; + + // unwrap jquery (for those who need it) + if (html.get) { + html = html.get(0); + } + + // create proper html elements from + // overlay HTML strings + if (isString(html)) { + html = domify(html); + } + + overlayContainer = this._getOverlayContainer(element); + + htmlContainer = domify('<div class="djs-overlay" data-overlay-id="' + id + '" style="position: absolute">'); + + htmlContainer.appendChild(html); + + if (overlay.type) { + domClasses(htmlContainer).add('djs-overlay-' + overlay.type); + } + + overlay.htmlContainer = htmlContainer; + + overlayContainer.overlays.push(overlay); + overlayContainer.html.appendChild(htmlContainer); + + this._overlays[id] = overlay; + + this._updateOverlay(overlay); +}; + +Overlays.prototype._updateOverlayVisibilty = function(viewbox) { + + forEach(this._overlays, function(overlay) { + var show = overlay.show, + htmlContainer = overlay.htmlContainer, + visible = true; + + if (show) { + if (show.minZoom > viewbox.scale || + show.maxZoom < viewbox.scale) { + visible = false; + } + + setVisible(htmlContainer, visible); + } + }); +}; + +Overlays.prototype._init = function(config) { + + var eventBus = this._eventBus; + + var self = this; + + + // scroll/zoom integration + + var updateViewbox = function(viewbox) { + self._updateRoot(viewbox); + self._updateOverlayVisibilty(viewbox); + + self.show(); + }; + + if (!config || config.deferUpdate !== false) { + updateViewbox = debounce(updateViewbox, 300); + } + + eventBus.on('canvas.viewbox.changed', function(event) { + self.hide(); + updateViewbox(event.viewbox); + }); + + + // remove integration + + eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) { + var overlays = self.get({ element: e.element }); + + forEach(overlays, function(o) { + self.remove(o.id); + }); + }); + + + // move integration + + eventBus.on([ + 'element.changed' + ], function(e) { + var element = e.element; + + var container = self._getOverlayContainer(element, true); + + if (container) { + forEach(container.overlays, function(overlay) { + self._updateOverlay(overlay); + }); + + self._updateOverlayContainer(container); + } + }); + + + // marker integration, simply add them on the overlays as classes, too. + + eventBus.on('element.marker.update', function(e) { + var container = self._getOverlayContainer(e.element, true); + if (container) { + domClasses(container.html)[e.add ? 'add' : 'remove'](e.marker); + } + }); +}; + +},{"166":166,"170":170,"172":172,"175":175,"187":187,"190":190,"193":193,"65":65,"68":68,"82":82,"84":84,"91":91}],52:[function(_dereq_,module,exports){ +module.exports = { + __init__: [ 'overlays' ], + overlays: [ 'type', _dereq_(51) ] +}; +},{"51":51}],53:[function(_dereq_,module,exports){ +'use strict'; + +var isArray = _dereq_(166), + forEach = _dereq_(84); + + +/** + * A service that offers the current selection in a diagram. + * Offers the api to control the selection, too. + * + * @class + * + * @param {EventBus} eventBus the event bus + */ +function Selection(eventBus) { + + this._eventBus = eventBus; + + this._selectedElements = []; + + var self = this; + + eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) { + var element = e.element; + self.deselect(element); + }); +} + +Selection.$inject = [ 'eventBus' ]; + +module.exports = Selection; + + +Selection.prototype.deselect = function(element) { + var selectedElements = this._selectedElements; + + var idx = selectedElements.indexOf(element); + + if (idx !== -1) { + var oldSelection = selectedElements.slice(); + + selectedElements.splice(idx, 1); + + this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements }); + } +}; + + +Selection.prototype.get = function() { + return this._selectedElements; +}; + +Selection.prototype.isSelected = function(element) { + return this._selectedElements.indexOf(element) !== -1; +}; + + +/** + * This method selects one or more elements on the diagram. + * + * By passing an additional add parameter you can decide whether or not the element(s) + * should be added to the already existing selection or not. + * + * @method Selection#select + * + * @param {Object|Object[]} elements element or array of elements to be selected + * @param {boolean} [add] whether the element(s) should be appended to the current selection, defaults to false + */ +Selection.prototype.select = function(elements, add) { + var selectedElements = this._selectedElements, + oldSelection = selectedElements.slice(); + + if (!isArray(elements)) { + elements = elements ? [ elements ] : []; + } + + // selection may be cleared by passing an empty array or null + // to the method + if (add) { + forEach(elements, function(element) { + if (selectedElements.indexOf(element) !== -1) { + // already selected + return; + } else { + selectedElements.push(element); + } + }); + } else { + this._selectedElements = selectedElements = elements.slice(); + } + this._eventBus.fire('selection.changed', { oldSelection: oldSelection, newSelection: selectedElements }); +}; + +},{"166":166,"84":84}],54:[function(_dereq_,module,exports){ +'use strict'; + +var hasPrimaryModifier = _dereq_(69).hasPrimaryModifier; + + +function SelectionBehavior(eventBus, selection, canvas) { + + eventBus.on('create.end', 500, function(e) { + if (e.context.canExecute) { + selection.select(e.shape); + } + }); + + eventBus.on('connect.end', 500, function(e) { + if (e.context.canExecute && e.context.target) { + selection.select(e.context.target); + } + }); + + eventBus.on('shape.move.end', 500, function(e) { + selection.select(e.context.shapes); + }); + + + // Shift + click selection + eventBus.on('element.click', function(event) { + + var element = event.element; + + // do not select the root element + // or connections + if (element === canvas.getRootElement()) { + element = null; + } + + var isSelected = selection.isSelected(element), + isMultiSelect = selection.get().length > 1; + + // mouse-event: SELECTION_KEY + var add = hasPrimaryModifier(event); + + // select OR deselect element in multi selection + if (isSelected && isMultiSelect) { + if (add) { + return selection.deselect(element); + } else { + return selection.select(element); + } + } else + if (!isSelected) { + selection.select(element, add); + } else { + selection.deselect(element); + } + }); +} + +SelectionBehavior.$inject = [ 'eventBus', 'selection', 'canvas' ]; + +module.exports = SelectionBehavior; + +},{"69":69}],55:[function(_dereq_,module,exports){ +'use strict'; + +var forEach = _dereq_(84); + +var MARKER_HOVER = 'hover', + MARKER_SELECTED = 'selected'; + + +/** + * A plugin that adds a visible selection UI to shapes and connections + * by appending the <code>hover</code> and <code>selected</code> classes to them. + * + * @class + * + * Makes elements selectable, too. + * + * @param {EventBus} events + * @param {SelectionService} selection + * @param {Canvas} canvas + */ +function SelectionVisuals(events, canvas, selection, graphicsFactory, styles) { + + this._multiSelectionBox = null; + + function addMarker(e, cls) { + canvas.addMarker(e, cls); + } + + function removeMarker(e, cls) { + canvas.removeMarker(e, cls); + } + + events.on('element.hover', function(event) { + addMarker(event.element, MARKER_HOVER); + }); + + events.on('element.out', function(event) { + removeMarker(event.element, MARKER_HOVER); + }); + + events.on('selection.changed', function(event) { + + function deselect(s) { + removeMarker(s, MARKER_SELECTED); + } + + function select(s) { + addMarker(s, MARKER_SELECTED); + } + + var oldSelection = event.oldSelection, + newSelection = event.newSelection; + + forEach(oldSelection, function(e) { + if (newSelection.indexOf(e) === -1) { + deselect(e); + } + }); + + forEach(newSelection, function(e) { + if (oldSelection.indexOf(e) === -1) { + select(e); + } + }); + }); +} + +SelectionVisuals.$inject = [ + 'eventBus', + 'canvas', + 'selection', + 'graphicsFactory', + 'styles' +]; + +module.exports = SelectionVisuals; + +},{"84":84}],56:[function(_dereq_,module,exports){ +module.exports = { + __init__: [ 'selectionVisuals', 'selectionBehavior' ], + __depends__: [ + _dereq_(48), + _dereq_(50) + ], + selection: [ 'type', _dereq_(53) ], + selectionVisuals: [ 'type', _dereq_(55) ], + selectionBehavior: [ 'type', _dereq_(54) ] +}; + +},{"48":48,"50":50,"53":53,"54":54,"55":55}],57:[function(_dereq_,module,exports){ +'use strict'; + +var assign = _dereq_(175), + inherits = _dereq_(79); + +var Refs = _dereq_(202); + +var parentRefs = new Refs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }), + labelRefs = new Refs({ name: 'label', enumerable: true }, { name: 'labelTarget' }), + outgoingRefs = new Refs({ name: 'outgoing', collection: true }, { name: 'source' }), + incomingRefs = new Refs({ name: 'incoming', collection: true }, { name: 'target' }); + +/** + * @namespace djs.model + */ + +/** + * @memberOf djs.model + */ + +/** + * The basic graphical representation + * + * @class + * + * @abstract + */ +function Base() { + + /** + * The object that backs up the shape + * + * @name Base#businessObject + * @type Object + */ + Object.defineProperty(this, 'businessObject', { + writable: true + }); + + /** + * The parent shape + * + * @name Base#parent + * @type Shape + */ + parentRefs.bind(this, 'parent'); + + /** + * @name Base#label + * @type Label + */ + labelRefs.bind(this, 'label'); + + /** + * The list of outgoing connections + * + * @name Base#outgoing + * @type Array<Connection> + */ + outgoingRefs.bind(this, 'outgoing'); + + /** + * The list of outgoing connections + * + * @name Base#incoming + * @type Array<Connection> + */ + incomingRefs.bind(this, 'incoming'); +} + + +/** + * A graphical object + * + * @class + * @constructor + * + * @extends Base + */ +function Shape() { + Base.call(this); + + /** + * The list of children + * + * @name Shape#children + * @type Array<Base> + */ + parentRefs.bind(this, 'children'); +} + +inherits(Shape, Base); + + +/** + * A root graphical object + * + * @class + * @constructor + * + * @extends Shape + */ +function Root() { + Shape.call(this); +} + +inherits(Root, Shape); + + +/** + * A label for an element + * + * @class + * @constructor + * + * @extends Shape + */ +function Label() { + Shape.call(this); + + /** + * The labeled element + * + * @name Label#labelTarget + * @type Base + */ + labelRefs.bind(this, 'labelTarget'); +} + +inherits(Label, Shape); + + +/** + * A connection between two elements + * + * @class + * @constructor + * + * @extends Base + */ +function Connection() { + Base.call(this); + + /** + * The element this connection originates from + * + * @name Connection#source + * @type Base + */ + outgoingRefs.bind(this, 'source'); + + /** + * The element this connection points to + * + * @name Connection#target + * @type Base + */ + incomingRefs.bind(this, 'target'); +} + +inherits(Connection, Base); + + +var types = { + connection: Connection, + shape: Shape, + label: Label, + root: Root +}; + +/** + * Creates a new model element of the specified type + * + * @method create + * + * @example + * + * var shape1 = Model.create('shape', { x: 10, y: 10, width: 100, height: 100 }); + * var shape2 = Model.create('shape', { x: 210, y: 210, width: 100, height: 100 }); + * + * var connection = Model.create('connection', { waypoints: [ { x: 110, y: 55 }, {x: 210, y: 55 } ] }); + * + * @param {String} type lower-cased model name + * @param {Object} attrs attributes to initialize the new model instance with + * + * @return {Base} the new model instance + */ +module.exports.create = function(type, attrs) { + var Type = types[type]; + if (!Type) { + throw new Error('unknown type: <' + type + '>'); + } + return assign(new Type(), attrs); +}; + + +module.exports.Base = Base; +module.exports.Root = Root; +module.exports.Shape = Shape; +module.exports.Connection = Connection; +module.exports.Label = Label; +},{"175":175,"202":202,"79":79}],58:[function(_dereq_,module,exports){ +'use strict'; + +var Cursor = _dereq_(64), + ClickTrap = _dereq_(62), + domEvent = _dereq_(191), + Event = _dereq_(66); + +function substract(p1, p2) { + return { + x: p1.x - p2.x, + y: p1.y - p2.y + }; +} + +function length(point) { + return Math.sqrt(Math.pow(point.x, 2) + Math.pow(point.y, 2)); +} + + +var THRESHOLD = 15; + + +function MoveCanvas(eventBus, canvas) { + + var container = canvas._container, + context; + + + function handleMove(event) { + + var start = context.start, + position = Event.toPoint(event), + delta = substract(position, start); + + if (!context.dragging && length(delta) > THRESHOLD) { + context.dragging = true; + + // prevent mouse click in this + // interaction sequence + ClickTrap.install(); + + Cursor.set('move'); + } + + if (context.dragging) { + + var lastPosition = context.last || context.start; + + delta = substract(position, lastPosition); + + canvas.scroll({ + dx: delta.x, + dy: delta.y + }); + + context.last = position; + } + + // prevent select + event.preventDefault(); + } + + + function handleEnd(event) { + domEvent.unbind(document, 'mousemove', handleMove); + domEvent.unbind(document, 'mouseup', handleEnd); + + context = null; + + Cursor.unset(); + + // prevent select + Event.stopEvent(event); + } + + function handleStart(event) { + + // reject non-left left mouse button or modifier key + if (event.button || event.ctrlKey || event.shiftKey || event.altKey) { + return; + } + + context = { + start: Event.toPoint(event) + }; + + domEvent.bind(document, 'mousemove', handleMove); + domEvent.bind(document, 'mouseup', handleEnd); + + // prevent select + Event.stopEvent(event); + } + + domEvent.bind(container, 'mousedown', handleStart); +} + + +MoveCanvas.$inject = [ 'eventBus', 'canvas' ]; + +module.exports = MoveCanvas; + +},{"191":191,"62":62,"64":64,"66":66}],59:[function(_dereq_,module,exports){ +module.exports = { + __init__: [ 'moveCanvas' ], + moveCanvas: [ 'type', _dereq_(58) ] +}; +},{"58":58}],60:[function(_dereq_,module,exports){ +'use strict'; + +var domEvent = _dereq_(191); + +var hasPrimaryModifier = _dereq_(69).hasPrimaryModifier, + hasSecondaryModifier = _dereq_(69).hasSecondaryModifier; + +var isMac = _dereq_(70).isMac; + + +function ZoomScroll(events, canvas) { + + var RANGE = { min: 0.2, max: 4 }; + + function cap(scale) { + return Math.max(RANGE.min, Math.min(RANGE.max, scale)); + } + + function reset() { + canvas.zoom('fit-viewport'); + } + + function zoom(direction, position) { + + var currentZoom = canvas.zoom(); + var factor = Math.pow(1 + Math.abs(direction) , direction > 0 ? 1 : -1); + + canvas.zoom(cap(currentZoom * factor), position); + } + + function scroll(delta) { + canvas.scroll(delta); + } + + function init(element) { + + domEvent.bind(element, 'wheel', function(event) { + + event.preventDefault(); + + // mouse-event: SELECTION_KEY + // mouse-event: AND_KEY + var isVerticalScroll = hasPrimaryModifier(event), + isHorizontalScroll = hasSecondaryModifier(event); + + var factor; + + if (isVerticalScroll || isHorizontalScroll) { + + if (isMac) { + factor = event.deltaMode === 0 ? 1.25 : 50; + } else { + factor = event.deltaMode === 0 ? 1/40 : 1/2; + } + + var delta = {}; + + if (isHorizontalScroll) { + delta.dx = (factor * (event.deltaX || event.deltaY)); + } else { + delta.dy = (factor * event.deltaY); + } + + scroll(delta); + } else { + factor = (event.deltaMode === 0 ? 1/40 : 1/2); + + var elementRect = element.getBoundingClientRect(); + + var offset = { + x: event.clientX - elementRect.left, + y: event.clientY - elementRect.top + }; + + // zoom in relative to diagram {x,y} coordinates + zoom(event.deltaY * factor / (-5), offset); + } + }); + } + + events.on('canvas.init', function(e) { + init(canvas._container); + }); + + // API + this.zoom = zoom; + this.reset = reset; +} + + +ZoomScroll.$inject = [ 'eventBus', 'canvas' ]; + +module.exports = ZoomScroll; + + +},{"191":191,"69":69,"70":70}],61:[function(_dereq_,module,exports){ +module.exports = { + __init__: [ 'zoomScroll' ], + zoomScroll: [ 'type', _dereq_(60) ] +}; +},{"60":60}],62:[function(_dereq_,module,exports){ +'use strict'; + +var domEvent = _dereq_(191), + stopEvent = _dereq_(66).stopEvent; + +function trap(event) { + stopEvent(event); + + toggle(false); +} + +function toggle(active) { + domEvent[active ? 'bind' : 'unbind'](document.body, 'click', trap, true); +} + +/** + * Installs a click trap that prevents a ghost click following a dragging operation. + * + * @return {Function} a function to immediately remove the installed trap. + */ +function install() { + + toggle(true); + + return function() { + toggle(false); + }; +} + +module.exports.install = install; +},{"191":191,"66":66}],63:[function(_dereq_,module,exports){ +'use strict'; + +/** + * Failsafe remove an element from a collection + * + * @param {Array<Object>} [collection] + * @param {Object} [element] + * + * @return {Object} the element that got removed or undefined + */ +module.exports.remove = function(collection, element) { + + if (!collection || !element) { + return; + } + + var idx = collection.indexOf(element); + if (idx === -1) { + return; + } + + collection.splice(idx, 1); + + return element; +}; + +/** + * Fail save add an element to the given connection, ensuring + * it does not yet exist. + * + * @param {Array<Object>} collection + * @param {Object} element + * @param {Number} idx + */ +module.exports.add = function(collection, element, idx) { + + if (!collection || !element) { + return; + } + + if (isNaN(idx)) { + idx = -1; + } + + var currentIdx = collection.indexOf(element); + + if (currentIdx !== -1) { + + if (currentIdx === idx) { + // nothing to do, position has not changed + return; + } else { + + if (idx !== -1) { + // remove from current position + collection.splice(currentIdx, 1); + } else { + // already exists in collection + return; + } + } + } + + if (idx !== -1) { + // insert at specified position + collection.splice(idx, 0, element); + } else { + // push to end + collection.push(element); + } +}; + + +/** + * Fail get the index of an element in a collection. + * + * @param {Array<Object>} collection + * @param {Object} element + * + * @return {Number} the index or -1 if collection or element do + * not exist or the element is not contained. + */ +module.exports.indexOf = function(collection, element) { + + if (!collection || !element) { + return -1; + } + + return collection.indexOf(element); +}; + +},{}],64:[function(_dereq_,module,exports){ +'use strict'; + +var domClasses = _dereq_(187); + +var CURSOR_CLS_PATTERN = /^djs-cursor-.*$/; + + +module.exports.set = function(mode) { + var classes = domClasses(document.body); + + classes.removeMatching(CURSOR_CLS_PATTERN); + + if (mode) { + classes.add('djs-cursor-' + mode); + } +}; + +module.exports.unset = function() { + this.set(null); +}; +},{"187":187}],65:[function(_dereq_,module,exports){ +'use strict'; + +var isArray = _dereq_(166), + isNumber = _dereq_(169), + groupBy = _dereq_(85), + forEach = _dereq_(84); + +/** + * Adds an element to a collection and returns true if the + * element was added. + * + * @param {Array<Object>} elements + * @param {Object} e + * @param {Boolean} unique + */ +function add(elements, e, unique) { + var canAdd = !unique || elements.indexOf(e) === -1; + + if (canAdd) { + elements.push(e); + } + + return canAdd; +} + +function eachElement(elements, fn, depth) { + + depth = depth || 0; + + forEach(elements, function(s, i) { + var filter = fn(s, i, depth); + + if (isArray(filter) && filter.length) { + eachElement(filter, fn, depth + 1); + } + }); +} + +/** + * Collects self + child elements up to a given depth from a list of elements. + * + * @param {Array<djs.model.Base>} elements the elements to select the children from + * @param {Boolean} unique whether to return a unique result set (no duplicates) + * @param {Number} maxDepth the depth to search through or -1 for infinite + * + * @return {Array<djs.model.Base>} found elements + */ +function selfAndChildren(elements, unique, maxDepth) { + var result = [], + processedChildren = []; + + eachElement(elements, function(element, i, depth) { + add(result, element, unique); + + var children = element.children; + + // max traversal depth not reached yet + if (maxDepth === -1 || depth < maxDepth) { + + // children exist && children not yet processed + if (children && add(processedChildren, children, unique)) { + return children; + } + } + }); + + return result; +} + +/** + * Return self + direct children for a number of elements + * + * @param {Array<djs.model.Base>} elements to query + * @param {Boolean} allowDuplicates to allow duplicates in the result set + * + * @return {Array<djs.model.Base>} the collected elements + */ +function selfAndDirectChildren(elements, allowDuplicates) { + return selfAndChildren(elements, !allowDuplicates, 1); +} + +/** + * Return self + ALL children for a number of elements + * + * @param {Array<djs.model.Base>} elements to query + * @param {Boolean} allowDuplicates to allow duplicates in the result set + * + * @return {Array<djs.model.Base>} the collected elements + */ +function selfAndAllChildren(elements, allowDuplicates) { + return selfAndChildren(elements, !allowDuplicates, -1); +} + +/** + * Gets the the closure fo all selected elements, + * their connections and + * + * @param {Array<djs.model.Base>} elements + * @return {Object} enclosure + */ +function getClosure(elements) { + + // original elements passed to this function + var topLevel = groupBy(elements, function(e) { return e.id; }); + + var allShapes = {}, + allConnections = {}, + enclosedElements = {}, + enclosedConnections = {}; + + function handleConnection(c) { + if (topLevel[c.source.id] && topLevel[c.target.id]) { + topLevel[c.id] = c; + } + + // not enclosed as a child, but maybe logically + // (connecting two moved elements?) + if (allShapes[c.source.id] && allShapes[c.target.id]) { + enclosedConnections[c.id] = enclosedElements[c.id] = c; + } + + allConnections[c.id] = c; + } + + function handleElement(element) { + + enclosedElements[element.id] = element; + + if (element.waypoints) { + // remember connection + enclosedConnections[element.id] = allConnections[element.id] = element; + } else { + // remember shape + allShapes[element.id] = element; + + // remember all connections + forEach(element.incoming, handleConnection); + + forEach(element.outgoing, handleConnection); + + // recurse into children + return element.children; + } + } + + eachElement(elements, handleElement); + + return { + allShapes: allShapes, + allConnections: allConnections, + topLevel: topLevel, + enclosedConnections: enclosedConnections, + enclosedElements: enclosedElements + }; +} + +/** + * Returns the surrounding bbox for all elements in the array or the element primitive. + */ +function getBBox(elements, stopRecursion) { + + stopRecursion = !!stopRecursion; + if (!isArray(elements)) { + elements = [elements]; + } + + var minX, + minY, + maxX, + maxY; + + forEach(elements, function(element) { + + // If element is a connection the bbox must be computed first + var bbox = element; + if (element.waypoints && !stopRecursion) { + bbox = getBBox(element.waypoints, true); + } + + var x = bbox.x, + y = bbox.y, + height = bbox.height || 0, + width = bbox.width || 0; + + if (x < minX || minX === undefined) { + minX = x; + } + if (y < minY || minY === undefined) { + minY = y; + } + + if ((x + width) > maxX || maxX === undefined) { + maxX = x + width; + } + if ((y + height) > maxY || maxY === undefined) { + maxY = y + height; + } + }); + + return { + x: minX, + y: minY, + height: maxY - minY, + width: maxX - minX + }; +} + + +/** + * Returns all elements that are enclosed from the bounding box. + * + * @param {Array<Object>} elements List of Elements to search through + * @param {Object} bbox the enclosing bbox. + * <ul> + * <li>If bbox.(width|height) is not specified + * the method returns all elements with element.x/y > bbox.x/y + * </li> + * <li>If only bbox.x or bbox.y is specified, method return all elements with + * e.x > bbox.x or e.y > bbox.y.</li> + * </ul> + * + */ +function getEnclosedElements(elements, bbox) { + + var filteredElements = {}; + + forEach(elements, function(element) { + + var e = element; + + if (e.waypoints) { + e = getBBox(e); + } + + if (!isNumber(bbox.y) && (e.x > bbox.x)) { + filteredElements[element.id] = element; + } + if (!isNumber(bbox.x) && (e.y > bbox.y)) { + filteredElements[element.id] = element; + } + if (e.x > bbox.x && e.y > bbox.y) { + if (isNumber(bbox.width) && isNumber(bbox.height) && + e.width + e.x < bbox.width + bbox.x && + e.height + e.y < bbox.height + bbox.y) { + + filteredElements[element.id] = element; + } else if (!isNumber(bbox.width) || !isNumber(bbox.height)) { + filteredElements[element.id] = element; + } + } + }); + + return filteredElements; +} + + + +module.exports.eachElement = eachElement; +module.exports.selfAndDirectChildren = selfAndDirectChildren; +module.exports.selfAndAllChildren = selfAndAllChildren; +module.exports.getBBox = getBBox; +module.exports.getEnclosedElements = getEnclosedElements; + +module.exports.getClosure = getClosure; + +},{"166":166,"169":169,"84":84,"85":85}],66:[function(_dereq_,module,exports){ +'use strict'; + +function __preventDefault(event) { + return event && event.preventDefault(); +} + +function __stopPropagation(event, immediate) { + if (!event) { + return; + } + + if (event.stopPropagation) { + event.stopPropagation(); + } + + if (immediate && event.stopImmediatePropagation) { + event.stopImmediatePropagation(); + } +} + + +function getOriginal(event) { + return event.originalEvent || event.srcEvent; +} + +module.exports.getOriginal = getOriginal; + + +function stopEvent(event, immediate) { + stopPropagation(event, immediate); + preventDefault(event); +} + +module.exports.stopEvent = stopEvent; + + +function preventDefault(event) { + __preventDefault(event); + __preventDefault(getOriginal(event)); +} + +module.exports.preventDefault = preventDefault; + + +function stopPropagation(event, immediate) { + __stopPropagation(event, immediate); + __stopPropagation(getOriginal(event), immediate); +} + +module.exports.stopPropagation = stopPropagation; + + +function toPoint(event) { + + if (event.pointers && event.pointers.length) { + event = event.pointers[0]; + } + + if (event.touches && event.touches.length) { + event = event.touches[0]; + } + + return event ? { + x: event.clientX, + y: event.clientY + } : null; +} + +module.exports.toPoint = toPoint; + +},{}],67:[function(_dereq_,module,exports){ +'use strict'; + +/** + * SVGs for elements are generated by the {@link GraphicsFactory}. + * + * This utility gives quick access to the important semantic + * parts of an element. + */ + +/** + * Returns the visual part of a diagram element + * + * @param {Snap<SVGElement>} gfx + * + * @return {Snap<SVGElement>} + */ +function getVisual(gfx) { + return gfx.select('.djs-visual'); +} + +/** + * Returns the children for a given diagram element. + * + * @param {Snap<SVGElement>} gfx + * @return {Snap<SVGElement>} + */ +function getChildren(gfx) { + return gfx.parent().children()[1]; +} + +/** + * Returns the visual bbox of an element + * + * @param {Snap<SVGElement>} gfx + * + * @return {Bounds} + */ +function getBBox(gfx) { + return getVisual(gfx).select('*').getBBox(); +} + + +module.exports.getVisual = getVisual; +module.exports.getChildren = getChildren; +module.exports.getBBox = getBBox; +},{}],68:[function(_dereq_,module,exports){ +'use strict'; + +/** + * Util that provides unique IDs. + * + * @class djs.util.IdGenerator + * @constructor + * @memberOf djs.util + * + * The ids can be customized via a given prefix and contain a random value to avoid collisions. + * + * @param {String} prefix a prefix to prepend to generated ids (for better readability) + */ +function IdGenerator(prefix) { + + this._counter = 0; + this._prefix = (prefix ? prefix + '-' : '') + Math.floor(Math.random() * 1000000000) + '-'; +} + +module.exports = IdGenerator; + +/** + * Returns a next unique ID. + * + * @method djs.util.IdGenerator#next + * + * @returns {String} the id + */ +IdGenerator.prototype.next = function() { + return this._prefix + (++this._counter); +}; + +},{}],69:[function(_dereq_,module,exports){ +'use strict'; + +var getOriginalEvent = _dereq_(66).getOriginal; + +var isMac = _dereq_(70).isMac; + + +function isPrimaryButton(event) { + // button === 0 -> left áka primary mouse button + return !(getOriginalEvent(event) || event).button; +} + +module.exports.isPrimaryButton = isPrimaryButton; + +module.exports.isMac = isMac; + +module.exports.hasPrimaryModifier = function(event) { + var originalEvent = getOriginalEvent(event) || event; + + if (!isPrimaryButton(event)) { + return false; + } + + // Use alt as primary modifier key for mac OS + if (isMac()) { + return originalEvent.altKey; + } else { + return originalEvent.ctrlKey; + } +}; + + +module.exports.hasSecondaryModifier = function(event) { + var originalEvent = getOriginalEvent(event) || event; + + return isPrimaryButton(event) && originalEvent.shiftKey; +}; + +},{"66":66,"70":70}],70:[function(_dereq_,module,exports){ +'use strict'; + +module.exports.isMac = function isMac() { + return (/mac/i).test(navigator.platform); +}; +},{}],71:[function(_dereq_,module,exports){ +'use strict'; + +var isObject = _dereq_(170), + assign = _dereq_(175), + forEach = _dereq_(84), + reduce = _dereq_(88), + merge = _dereq_(178); + +var Snap = _dereq_(74); + +var DEFAULT_BOX_PADDING = 0; + +var DEFAULT_LABEL_SIZE = { + width: 150, + height: 50 +}; + + +function parseAlign(align) { + + var parts = align.split('-'); + + return { + horizontal: parts[0] || 'center', + vertical: parts[1] || 'top' + }; +} + +function parsePadding(padding) { + + if (isObject(padding)) { + return assign({ top: 0, left: 0, right: 0, bottom: 0 }, padding); + } else { + return { + top: padding, + left: padding, + right: padding, + bottom: padding + }; + } +} + +function getTextBBox(text, fakeText) { + fakeText.textContent = text; + return fakeText.getBBox(); +} + + +/** + * Layout the next line and return the layouted element. + * + * Alters the lines passed. + * + * @param {Array<String>} lines + * @return {Object} the line descriptor, an object { width, height, text } + */ +function layoutNext(lines, maxWidth, fakeText) { + + var originalLine = lines.shift(), + fitLine = originalLine; + + var textBBox; + + while (true) { + textBBox = getTextBBox(fitLine, fakeText); + + textBBox.width = fitLine ? textBBox.width : 0; + + // try to fit + if (fitLine === ' ' || fitLine === '' || textBBox.width < Math.round(maxWidth) || fitLine.length < 4) { + return fit(lines, fitLine, originalLine, textBBox); + } + + + fitLine = shortenLine(fitLine, textBBox.width, maxWidth); + } +} + +function fit(lines, fitLine, originalLine, textBBox) { + if (fitLine.length < originalLine.length) { + var nextLine = lines[0] || '', + remainder = originalLine.slice(fitLine.length).trim(); + + if (/-\s*$/.test(remainder)) { + nextLine = remainder.replace(/-\s*$/, '') + nextLine.replace(/^\s+/, ''); + } else { + nextLine = remainder + ' ' + nextLine; + } + + lines[0] = nextLine; + } + return { width: textBBox.width, height: textBBox.height, text: fitLine }; +} + + +/** + * Shortens a line based on spacing and hyphens. + * Returns the shortened result on success. + * + * @param {String} line + * @param {Number} maxLength the maximum characters of the string + * @return {String} the shortened string + */ +function semanticShorten(line, maxLength) { + var parts = line.split(/(\s|-)/g), + part, + shortenedParts = [], + length = 0; + + // try to shorten via spaces + hyphens + if (parts.length > 1) { + while ((part = parts.shift())) { + if (part.length + length < maxLength) { + shortenedParts.push(part); + length += part.length; + } else { + // remove previous part, too if hyphen does not fit anymore + if (part === '-') { + shortenedParts.pop(); + } + + break; + } + } + } + + return shortenedParts.join(''); +} + + +function shortenLine(line, width, maxWidth) { + var length = Math.max(line.length * (maxWidth / width), 1); + + // try to shorten semantically (i.e. based on spaces and hyphens) + var shortenedLine = semanticShorten(line, length); + + if (!shortenedLine) { + + // force shorten by cutting the long word + shortenedLine = line.slice(0, Math.max(Math.round(length - 1), 1)); + } + + return shortenedLine; +} + + +/** + * Creates a new label utility + * + * @param {Object} config + * @param {Dimensions} config.size + * @param {Number} config.padding + * @param {Object} config.style + * @param {String} config.align + */ +function Text(config) { + + this._config = assign({}, { + size: DEFAULT_LABEL_SIZE, + padding: DEFAULT_BOX_PADDING, + style: {}, + align: 'center-top' + }, config || {}); +} + + +/** + * Create a label in the parent node. + * + * @method Text#createText + * + * @param {SVGElement} parent the parent to draw the label on + * @param {String} text the text to render on the label + * @param {Object} options + * @param {String} options.align how to align in the bounding box. + * Any of { 'center-middle', 'center-top' }, defaults to 'center-top'. + * @param {String} options.style style to be applied to the text + * + * @return {SVGText} the text element created + */ +Text.prototype.createText = function(parent, text, options) { + + var box = merge({}, this._config.size, options.box || {}), + style = merge({}, this._config.style, options.style || {}), + align = parseAlign(options.align || this._config.align), + padding = parsePadding(options.padding !== undefined ? options.padding : this._config.padding); + + var lines = text.split(/\r?\n/g), + layouted = []; + + var maxWidth = box.width - padding.left - padding.right; + + // FF regression: ensure text is shown during rendering + // by attaching it directly to the body + var fakeText = parent.paper.text(0, 0, '').attr(style).node; + + while (lines.length) { + layouted.push(layoutNext(lines, maxWidth, fakeText)); + } + + var totalHeight = reduce(layouted, function(sum, line, idx) { + return sum + line.height; + }, 0); + + // the y position of the next line + var y, x; + + switch (align.vertical) { + case 'middle': + y = (box.height - totalHeight) / 2 - layouted[0].height / 4; + break; + + default: + y = padding.top; + } + + var textElement = parent.text().attr(style); + + forEach(layouted, function(line) { + y += line.height; + + switch (align.horizontal) { + case 'left': + x = padding.left; + break; + + case 'right': + x = (maxWidth - padding.right - line.width); + break; + + default: + // aka center + x = Math.max(((maxWidth - line.width) / 2 + padding.left), 0); + } + + + var tspan = Snap.create('tspan', { x: x, y: y }).node; + tspan.textContent = line.text; + + textElement.append(tspan); + }); + + // remove fake text + fakeText.parentNode.removeChild(fakeText); + + return textElement; +}; + + +module.exports = Text; +},{"170":170,"175":175,"178":178,"74":74,"84":84,"88":88}],72:[function(_dereq_,module,exports){ +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// ┌────────────────────────────────────────────────────────────┐ \\ +// │ Eve 0.4.2 - JavaScript Events Library │ \\ +// ├────────────────────────────────────────────────────────────┤ \\ +// │ Author Dmitry Baranovskiy (http://dmitry.baranovskiy.com/) │ \\ +// └────────────────────────────────────────────────────────────┘ \\ + +(function (glob) { + var version = "0.4.2", + has = "hasOwnProperty", + separator = /[\.\/]/, + comaseparator = /\s*,\s*/, + wildcard = "*", + fun = function () {}, + numsort = function (a, b) { + return a - b; + }, + current_event, + stop, + events = {n: {}}, + firstDefined = function () { + for (var i = 0, ii = this.length; i < ii; i++) { + if (typeof this[i] != "undefined") { + return this[i]; + } + } + }, + lastDefined = function () { + var i = this.length; + while (--i) { + if (typeof this[i] != "undefined") { + return this[i]; + } + } + }, + /*\ + * eve + [ method ] + + * Fires event with given `name`, given scope and other parameters. + + > Arguments + + - name (string) name of the *event*, dot (`.`) or slash (`/`) separated + - scope (object) context for the event handlers + - varargs (...) the rest of arguments will be sent to event handlers + + = (object) array of returned values from the listeners. Array has two methods `.firstDefined()` and `.lastDefined()` to get first or last not `undefined` value. + \*/ + eve = function (name, scope) { + name = String(name); + var e = events, + oldstop = stop, + args = Array.prototype.slice.call(arguments, 2), + listeners = eve.listeners(name), + z = 0, + f = false, + l, + indexed = [], + queue = {}, + out = [], + ce = current_event, + errors = []; + out.firstDefined = firstDefined; + out.lastDefined = lastDefined; + current_event = name; + stop = 0; + for (var i = 0, ii = listeners.length; i < ii; i++) if ("zIndex" in listeners[i]) { + indexed.push(listeners[i].zIndex); + if (listeners[i].zIndex < 0) { + queue[listeners[i].zIndex] = listeners[i]; + } + } + indexed.sort(numsort); + while (indexed[z] < 0) { + l = queue[indexed[z++]]; + out.push(l.apply(scope, args)); + if (stop) { + stop = oldstop; + return out; + } + } + for (i = 0; i < ii; i++) { + l = listeners[i]; + if ("zIndex" in l) { + if (l.zIndex == indexed[z]) { + out.push(l.apply(scope, args)); + if (stop) { + break; + } + do { + z++; + l = queue[indexed[z]]; + l && out.push(l.apply(scope, args)); + if (stop) { + break; + } + } while (l) + } else { + queue[l.zIndex] = l; + } + } else { + out.push(l.apply(scope, args)); + if (stop) { + break; + } + } + } + stop = oldstop; + current_event = ce; + return out; + }; + // Undocumented. Debug only. + eve._events = events; + /*\ + * eve.listeners + [ method ] + + * Internal method which gives you array of all event handlers that will be triggered by the given `name`. + + > Arguments + + - name (string) name of the event, dot (`.`) or slash (`/`) separated + + = (array) array of event handlers + \*/ + eve.listeners = function (name) { + var names = name.split(separator), + e = events, + item, + items, + k, + i, + ii, + j, + jj, + nes, + es = [e], + out = []; + for (i = 0, ii = names.length; i < ii; i++) { + nes = []; + for (j = 0, jj = es.length; j < jj; j++) { + e = es[j].n; + items = [e[names[i]], e[wildcard]]; + k = 2; + while (k--) { + item = items[k]; + if (item) { + nes.push(item); + out = out.concat(item.f || []); + } + } + } + es = nes; + } + return out; + }; + + /*\ + * eve.on + [ method ] + ** + * Binds given event handler with a given name. You can use wildcards “`*`” for the names: + | eve.on("*.under.*", f); + | eve("mouse.under.floor"); // triggers f + * Use @eve to trigger the listener. + ** + > Arguments + ** + - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards + - f (function) event handler function + ** + = (function) returned function accepts a single numeric parameter that represents z-index of the handler. It is an optional feature and only used when you need to ensure that some subset of handlers will be invoked in a given order, despite of the order of assignment. + > Example: + | eve.on("mouse", eatIt)(2); + | eve.on("mouse", scream); + | eve.on("mouse", catchIt)(1); + * This will ensure that `catchIt` function will be called before `eatIt`. + * + * If you want to put your handler before non-indexed handlers, specify a negative value. + * Note: I assume most of the time you don’t need to worry about z-index, but it’s nice to have this feature “just in case”. + \*/ + eve.on = function (name, f) { + name = String(name); + if (typeof f != "function") { + return function () {}; + } + var names = name.split(comaseparator); + for (var i = 0, ii = names.length; i < ii; i++) { + (function (name) { + var names = name.split(separator), + e = events, + exist; + for (var i = 0, ii = names.length; i < ii; i++) { + e = e.n; + e = e.hasOwnProperty(names[i]) && e[names[i]] || (e[names[i]] = {n: {}}); + } + e.f = e.f || []; + for (i = 0, ii = e.f.length; i < ii; i++) if (e.f[i] == f) { + exist = true; + break; + } + !exist && e.f.push(f); + }(names[i])); + } + return function (zIndex) { + if (+zIndex == +zIndex) { + f.zIndex = +zIndex; + } + }; + }; + /*\ + * eve.f + [ method ] + ** + * Returns function that will fire given event with optional arguments. + * Arguments that will be passed to the result function will be also + * concated to the list of final arguments. + | el.onclick = eve.f("click", 1, 2); + | eve.on("click", function (a, b, c) { + | console.log(a, b, c); // 1, 2, [event object] + | }); + > Arguments + - event (string) event name + - varargs (…) and any other arguments + = (function) possible event handler function + \*/ + eve.f = function (event) { + var attrs = [].slice.call(arguments, 1); + return function () { + eve.apply(null, [event, null].concat(attrs).concat([].slice.call(arguments, 0))); + }; + }; + /*\ + * eve.stop + [ method ] + ** + * Is used inside an event handler to stop the event, preventing any subsequent listeners from firing. + \*/ + eve.stop = function () { + stop = 1; + }; + /*\ + * eve.nt + [ method ] + ** + * Could be used inside event handler to figure out actual name of the event. + ** + > Arguments + ** + - subname (string) #optional subname of the event + ** + = (string) name of the event, if `subname` is not specified + * or + = (boolean) `true`, if current event’s name contains `subname` + \*/ + eve.nt = function (subname) { + if (subname) { + return new RegExp("(?:\\.|\\/|^)" + subname + "(?:\\.|\\/|$)").test(current_event); + } + return current_event; + }; + /*\ + * eve.nts + [ method ] + ** + * Could be used inside event handler to figure out actual name of the event. + ** + ** + = (array) names of the event + \*/ + eve.nts = function () { + return current_event.split(separator); + }; + /*\ + * eve.off + [ method ] + ** + * Removes given function from the list of event listeners assigned to given name. + * If no arguments specified all the events will be cleared. + ** + > Arguments + ** + - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards + - f (function) event handler function + \*/ + /*\ + * eve.unbind + [ method ] + ** + * See @eve.off + \*/ + eve.off = eve.unbind = function (name, f) { + if (!name) { + eve._events = events = {n: {}}; + return; + } + var names = name.split(comaseparator); + if (names.length > 1) { + for (var i = 0, ii = names.length; i < ii; i++) { + eve.off(names[i], f); + } + return; + } + names = name.split(separator); + var e, + key, + splice, + i, ii, j, jj, + cur = [events]; + for (i = 0, ii = names.length; i < ii; i++) { + for (j = 0; j < cur.length; j += splice.length - 2) { + splice = [j, 1]; + e = cur[j].n; + if (names[i] != wildcard) { + if (e[names[i]]) { + splice.push(e[names[i]]); + } + } else { + for (key in e) if (e[has](key)) { + splice.push(e[key]); + } + } + cur.splice.apply(cur, splice); + } + } + for (i = 0, ii = cur.length; i < ii; i++) { + e = cur[i]; + while (e.n) { + if (f) { + if (e.f) { + for (j = 0, jj = e.f.length; j < jj; j++) if (e.f[j] == f) { + e.f.splice(j, 1); + break; + } + !e.f.length && delete e.f; + } + for (key in e.n) if (e.n[has](key) && e.n[key].f) { + var funcs = e.n[key].f; + for (j = 0, jj = funcs.length; j < jj; j++) if (funcs[j] == f) { + funcs.splice(j, 1); + break; + } + !funcs.length && delete e.n[key].f; + } + } else { + delete e.f; + for (key in e.n) if (e.n[has](key) && e.n[key].f) { + delete e.n[key].f; + } + } + e = e.n; + } + } + }; + /*\ + * eve.once + [ method ] + ** + * Binds given event handler with a given name to only run once then unbind itself. + | eve.once("login", f); + | eve("login"); // triggers f + | eve("login"); // no listeners + * Use @eve to trigger the listener. + ** + > Arguments + ** + - name (string) name of the event, dot (`.`) or slash (`/`) separated, with optional wildcards + - f (function) event handler function + ** + = (function) same return function as @eve.on + \*/ + eve.once = function (name, f) { + var f2 = function () { + eve.unbind(name, f2); + return f.apply(this, arguments); + }; + return eve.on(name, f2); + }; + /*\ + * eve.version + [ property (string) ] + ** + * Current version of the library. + \*/ + eve.version = version; + eve.toString = function () { + return "You are running Eve " + version; + }; + (typeof module != "undefined" && module.exports) ? (module.exports = eve) : (typeof define === "function" && define.amd ? (define("eve", [], function() { return eve; })) : (glob.eve = eve)); +})(this); + +},{}],73:[function(_dereq_,module,exports){ +// Snap.svg 0.3.0 +// +// Copyright (c) 2013 – 2014 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +// build: 2014-09-08 + +(function (glob, factory) { + // AMD support + if (typeof define === "function" && define.amd) { + // Define as an anonymous module + define(["eve"], function( eve ) { + return factory(glob, eve); + }); + } else if (typeof exports !== 'undefined') { + // Next for Node.js or CommonJS + var eve = _dereq_(72); + module.exports = factory(glob, eve); + } else { + // Browser globals (glob is window) + // Snap adds itself to window + factory(glob, glob.eve); + } +}(window || this, function (window, eve) { + +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +var mina = (function (eve) { + var animations = {}, + requestAnimFrame = window.requestAnimationFrame || + window.webkitRequestAnimationFrame || + window.mozRequestAnimationFrame || + window.oRequestAnimationFrame || + window.msRequestAnimationFrame || + function (callback) { + setTimeout(callback, 16); + }, + isArray = Array.isArray || function (a) { + return a instanceof Array || + Object.prototype.toString.call(a) == "[object Array]"; + }, + idgen = 0, + idprefix = "M" + (+new Date).toString(36), + ID = function () { + return idprefix + (idgen++).toString(36); + }, + diff = function (a, b, A, B) { + if (isArray(a)) { + res = []; + for (var i = 0, ii = a.length; i < ii; i++) { + res[i] = diff(a[i], b, A[i], B); + } + return res; + } + var dif = (A - a) / (B - b); + return function (bb) { + return a + dif * (bb - b); + }; + }, + timer = Date.now || function () { + return +new Date; + }, + sta = function (val) { + var a = this; + if (val == null) { + return a.s; + } + var ds = a.s - val; + a.b += a.dur * ds; + a.B += a.dur * ds; + a.s = val; + }, + speed = function (val) { + var a = this; + if (val == null) { + return a.spd; + } + a.spd = val; + }, + duration = function (val) { + var a = this; + if (val == null) { + return a.dur; + } + a.s = a.s * val / a.dur; + a.dur = val; + }, + stopit = function () { + var a = this; + delete animations[a.id]; + a.update(); + eve("mina.stop." + a.id, a); + }, + pause = function () { + var a = this; + if (a.pdif) { + return; + } + delete animations[a.id]; + a.update(); + a.pdif = a.get() - a.b; + }, + resume = function () { + var a = this; + if (!a.pdif) { + return; + } + a.b = a.get() - a.pdif; + delete a.pdif; + animations[a.id] = a; + }, + update = function () { + var a = this, + res; + if (isArray(a.start)) { + res = []; + for (var j = 0, jj = a.start.length; j < jj; j++) { + res[j] = +a.start[j] + + (a.end[j] - a.start[j]) * a.easing(a.s); + } + } else { + res = +a.start + (a.end - a.start) * a.easing(a.s); + } + a.set(res); + }, + frame = function () { + var len = 0; + for (var i in animations) if (animations.hasOwnProperty(i)) { + var a = animations[i], + b = a.get(), + res; + len++; + a.s = (b - a.b) / (a.dur / a.spd); + if (a.s >= 1) { + delete animations[i]; + a.s = 1; + len--; + (function (a) { + setTimeout(function () { + eve("mina.finish." + a.id, a); + }); + }(a)); + } + a.update(); + } + len && requestAnimFrame(frame); + }, + /*\ + * mina + [ method ] + ** + * Generic animation of numbers + ** + - a (number) start _slave_ number + - A (number) end _slave_ number + - b (number) start _master_ number (start time in general case) + - B (number) end _master_ number (end time in gereal case) + - get (function) getter of _master_ number (see @mina.time) + - set (function) setter of _slave_ number + - easing (function) #optional easing function, default is @mina.linear + = (object) animation descriptor + o { + o id (string) animation id, + o start (number) start _slave_ number, + o end (number) end _slave_ number, + o b (number) start _master_ number, + o s (number) animation status (0..1), + o dur (number) animation duration, + o spd (number) animation speed, + o get (function) getter of _master_ number (see @mina.time), + o set (function) setter of _slave_ number, + o easing (function) easing function, default is @mina.linear, + o status (function) status getter/setter, + o speed (function) speed getter/setter, + o duration (function) duration getter/setter, + o stop (function) animation stopper + o pause (function) pauses the animation + o resume (function) resumes the animation + o update (function) calles setter with the right value of the animation + o } + \*/ + mina = function (a, A, b, B, get, set, easing) { + var anim = { + id: ID(), + start: a, + end: A, + b: b, + s: 0, + dur: B - b, + spd: 1, + get: get, + set: set, + easing: easing || mina.linear, + status: sta, + speed: speed, + duration: duration, + stop: stopit, + pause: pause, + resume: resume, + update: update + }; + animations[anim.id] = anim; + var len = 0, i; + for (i in animations) if (animations.hasOwnProperty(i)) { + len++; + if (len == 2) { + break; + } + } + len == 1 && requestAnimFrame(frame); + return anim; + }; + /*\ + * mina.time + [ method ] + ** + * Returns the current time. Equivalent to: + | function () { + | return (new Date).getTime(); + | } + \*/ + mina.time = timer; + /*\ + * mina.getById + [ method ] + ** + * Returns an animation by its id + - id (string) animation's id + = (object) See @mina + \*/ + mina.getById = function (id) { + return animations[id] || null; + }; + + /*\ + * mina.linear + [ method ] + ** + * Default linear easing + - n (number) input 0..1 + = (number) output 0..1 + \*/ + mina.linear = function (n) { + return n; + }; + /*\ + * mina.easeout + [ method ] + ** + * Easeout easing + - n (number) input 0..1 + = (number) output 0..1 + \*/ + mina.easeout = function (n) { + return Math.pow(n, 1.7); + }; + /*\ + * mina.easein + [ method ] + ** + * Easein easing + - n (number) input 0..1 + = (number) output 0..1 + \*/ + mina.easein = function (n) { + return Math.pow(n, .48); + }; + /*\ + * mina.easeinout + [ method ] + ** + * Easeinout easing + - n (number) input 0..1 + = (number) output 0..1 + \*/ + mina.easeinout = function (n) { + if (n == 1) { + return 1; + } + if (n == 0) { + return 0; + } + var q = .48 - n / 1.04, + Q = Math.sqrt(.1734 + q * q), + x = Q - q, + X = Math.pow(Math.abs(x), 1 / 3) * (x < 0 ? -1 : 1), + y = -Q - q, + Y = Math.pow(Math.abs(y), 1 / 3) * (y < 0 ? -1 : 1), + t = X + Y + .5; + return (1 - t) * 3 * t * t + t * t * t; + }; + /*\ + * mina.backin + [ method ] + ** + * Backin easing + - n (number) input 0..1 + = (number) output 0..1 + \*/ + mina.backin = function (n) { + if (n == 1) { + return 1; + } + var s = 1.70158; + return n * n * ((s + 1) * n - s); + }; + /*\ + * mina.backout + [ method ] + ** + * Backout easing + - n (number) input 0..1 + = (number) output 0..1 + \*/ + mina.backout = function (n) { + if (n == 0) { + return 0; + } + n = n - 1; + var s = 1.70158; + return n * n * ((s + 1) * n + s) + 1; + }; + /*\ + * mina.elastic + [ method ] + ** + * Elastic easing + - n (number) input 0..1 + = (number) output 0..1 + \*/ + mina.elastic = function (n) { + if (n == !!n) { + return n; + } + return Math.pow(2, -10 * n) * Math.sin((n - .075) * + (2 * Math.PI) / .3) + 1; + }; + /*\ + * mina.bounce + [ method ] + ** + * Bounce easing + - n (number) input 0..1 + = (number) output 0..1 + \*/ + mina.bounce = function (n) { + var s = 7.5625, + p = 2.75, + l; + if (n < (1 / p)) { + l = s * n * n; + } else { + if (n < (2 / p)) { + n -= (1.5 / p); + l = s * n * n + .75; + } else { + if (n < (2.5 / p)) { + n -= (2.25 / p); + l = s * n * n + .9375; + } else { + n -= (2.625 / p); + l = s * n * n + .984375; + } + } + } + return l; + }; + window.mina = mina; + return mina; +})(typeof eve == "undefined" ? function () {} : eve); +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +var Snap = (function(root) { +Snap.version = "0.3.0"; +/*\ + * Snap + [ method ] + ** + * Creates a drawing surface or wraps existing SVG element. + ** + - width (number|string) width of surface + - height (number|string) height of surface + * or + - DOM (SVGElement) element to be wrapped into Snap structure + * or + - array (array) array of elements (will return set of elements) + * or + - query (string) CSS query selector + = (object) @Element +\*/ +function Snap(w, h) { + if (w) { + if (w.tagName) { + return wrap(w); + } + if (is(w, "array") && Snap.set) { + return Snap.set.apply(Snap, w); + } + if (w instanceof Element) { + return w; + } + if (h == null) { + w = glob.doc.querySelector(w); + return wrap(w); + } + } + w = w == null ? "100%" : w; + h = h == null ? "100%" : h; + return new Paper(w, h); +} +Snap.toString = function () { + return "Snap v" + this.version; +}; +Snap._ = {}; +var glob = { + win: root.window, + doc: root.window.document +}; +Snap._.glob = glob; +var has = "hasOwnProperty", + Str = String, + toFloat = parseFloat, + toInt = parseInt, + math = Math, + mmax = math.max, + mmin = math.min, + abs = math.abs, + pow = math.pow, + PI = math.PI, + round = math.round, + E = "", + S = " ", + objectToString = Object.prototype.toString, + ISURL = /^url\(['"]?([^\)]+?)['"]?\)$/i, + colourRegExp = /^\s*((#[a-f\d]{6})|(#[a-f\d]{3})|rgba?\(\s*([\d\.]+%?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+%?(?:\s*,\s*[\d\.]+%?)?)\s*\)|hsba?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?%?)\s*\)|hsla?\(\s*([\d\.]+(?:deg|\xb0|%)?\s*,\s*[\d\.]+%?\s*,\s*[\d\.]+(?:%?\s*,\s*[\d\.]+)?%?)\s*\))\s*$/i, + bezierrg = /^(?:cubic-)?bezier\(([^,]+),([^,]+),([^,]+),([^\)]+)\)/, + reURLValue = /^url\(#?([^)]+)\)$/, + separator = Snap._.separator = /[,\s]+/, + whitespace = /[\s]/g, + commaSpaces = /[\s]*,[\s]*/, + hsrg = {hs: 1, rg: 1}, + pathCommand = /([a-z])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\s]*,?[\s]*)+)/ig, + tCommand = /([rstm])[\s,]*((-?\d*\.?\d*(?:e[\-+]?\d+)?[\s]*,?[\s]*)+)/ig, + pathValues = /(-?\d*\.?\d*(?:e[\-+]?\\d+)?)[\s]*,?[\s]*/ig, + idgen = 0, + idprefix = "S" + (+new Date).toString(36), + ID = function (el) { + return (el && el.type ? el.type : E) + idprefix + (idgen++).toString(36); + }, + xlink = "http://www.w3.org/1999/xlink", + xmlns = "http://www.w3.org/2000/svg", + hub = {}, + URL = Snap.url = function (url) { + return "url('#" + url + "')"; + }; + +function $(el, attr) { + if (attr) { + if (el == "#text") { + el = glob.doc.createTextNode(attr.text || ""); + } + if (typeof el == "string") { + el = $(el); + } + if (typeof attr == "string") { + if (attr.substring(0, 6) == "xlink:") { + return el.getAttributeNS(xlink, attr.substring(6)); + } + if (attr.substring(0, 4) == "xml:") { + return el.getAttributeNS(xmlns, attr.substring(4)); + } + return el.getAttribute(attr); + } + for (var key in attr) if (attr[has](key)) { + var val = Str(attr[key]); + if (val) { + if (key.substring(0, 6) == "xlink:") { + el.setAttributeNS(xlink, key.substring(6), val); + } else if (key.substring(0, 4) == "xml:") { + el.setAttributeNS(xmlns, key.substring(4), val); + } else { + el.setAttribute(key, val); + } + } else { + el.removeAttribute(key); + } + } + } else { + el = glob.doc.createElementNS(xmlns, el); + } + return el; +} +Snap._.$ = $; +Snap._.id = ID; +function getAttrs(el) { + var attrs = el.attributes, + name, + out = {}; + for (var i = 0; i < attrs.length; i++) { + if (attrs[i].namespaceURI == xlink) { + name = "xlink:"; + } else { + name = ""; + } + name += attrs[i].name; + out[name] = attrs[i].textContent; + } + return out; +} +function is(o, type) { + type = Str.prototype.toLowerCase.call(type); + if (type == "finite") { + return isFinite(o); + } + if (type == "array" && + (o instanceof Array || Array.isArray && Array.isArray(o))) { + return true; + } + return (type == "null" && o === null) || + (type == typeof o && o !== null) || + (type == "object" && o === Object(o)) || + objectToString.call(o).slice(8, -1).toLowerCase() == type; +} +/*\ + * Snap.format + [ method ] + ** + * Replaces construction of type `{<name>}` to the corresponding argument + ** + - token (string) string to format + - json (object) object which properties are used as a replacement + = (string) formatted string + > Usage + | // this draws a rectangular shape equivalent to "M10,20h40v50h-40z" + | paper.path(Snap.format("M{x},{y}h{dim.width}v{dim.height}h{dim['negative width']}z", { + | x: 10, + | y: 20, + | dim: { + | width: 40, + | height: 50, + | "negative width": -40 + | } + | })); +\*/ +Snap.format = (function () { + var tokenRegex = /\{([^\}]+)\}/g, + objNotationRegex = /(?:(?:^|\.)(.+?)(?=\[|\.|$|\()|\[('|")(.+?)\2\])(\(\))?/g, // matches .xxxxx or ["xxxxx"] to run over object properties + replacer = function (all, key, obj) { + var res = obj; + key.replace(objNotationRegex, function (all, name, quote, quotedName, isFunc) { + name = name || quotedName; + if (res) { + if (name in res) { + res = res[name]; + } + typeof res == "function" && isFunc && (res = res()); + } + }); + res = (res == null || res == obj ? all : res) + ""; + return res; + }; + return function (str, obj) { + return Str(str).replace(tokenRegex, function (all, key) { + return replacer(all, key, obj); + }); + }; +})(); +function clone(obj) { + if (typeof obj == "function" || Object(obj) !== obj) { + return obj; + } + var res = new obj.constructor; + for (var key in obj) if (obj[has](key)) { + res[key] = clone(obj[key]); + } + return res; +} +Snap._.clone = clone; +function repush(array, item) { + for (var i = 0, ii = array.length; i < ii; i++) if (array[i] === item) { + return array.push(array.splice(i, 1)[0]); + } +} +function cacher(f, scope, postprocessor) { + function newf() { + var arg = Array.prototype.slice.call(arguments, 0), + args = arg.join("\u2400"), + cache = newf.cache = newf.cache || {}, + count = newf.count = newf.count || []; + if (cache[has](args)) { + repush(count, args); + return postprocessor ? postprocessor(cache[args]) : cache[args]; + } + count.length >= 1e3 && delete cache[count.shift()]; + count.push(args); + cache[args] = f.apply(scope, arg); + return postprocessor ? postprocessor(cache[args]) : cache[args]; + } + return newf; +} +Snap._.cacher = cacher; +function angle(x1, y1, x2, y2, x3, y3) { + if (x3 == null) { + var x = x1 - x2, + y = y1 - y2; + if (!x && !y) { + return 0; + } + return (180 + math.atan2(-y, -x) * 180 / PI + 360) % 360; + } else { + return angle(x1, y1, x3, y3) - angle(x2, y2, x3, y3); + } +} +function rad(deg) { + return deg % 360 * PI / 180; +} +function deg(rad) { + return rad * 180 / PI % 360; +} +function x_y() { + return this.x + S + this.y; +} +function x_y_w_h() { + return this.x + S + this.y + S + this.width + " \xd7 " + this.height; +} + +/*\ + * Snap.rad + [ method ] + ** + * Transform angle to radians + - deg (number) angle in degrees + = (number) angle in radians +\*/ +Snap.rad = rad; +/*\ + * Snap.deg + [ method ] + ** + * Transform angle to degrees + - rad (number) angle in radians + = (number) angle in degrees +\*/ +Snap.deg = deg; +/*\ + * Snap.angle + [ method ] + ** + * Returns an angle between two or three points + > Parameters + - x1 (number) x coord of first point + - y1 (number) y coord of first point + - x2 (number) x coord of second point + - y2 (number) y coord of second point + - x3 (number) #optional x coord of third point + - y3 (number) #optional y coord of third point + = (number) angle in degrees +\*/ +Snap.angle = angle; +/*\ + * Snap.is + [ method ] + ** + * Handy replacement for the `typeof` operator + - o (…) any object or primitive + - type (string) name of the type, e.g., `string`, `function`, `number`, etc. + = (boolean) `true` if given value is of given type +\*/ +Snap.is = is; +/*\ + * Snap.snapTo + [ method ] + ** + * Snaps given value to given grid + - values (array|number) given array of values or step of the grid + - value (number) value to adjust + - tolerance (number) #optional maximum distance to the target value that would trigger the snap. Default is `10`. + = (number) adjusted value +\*/ +Snap.snapTo = function (values, value, tolerance) { + tolerance = is(tolerance, "finite") ? tolerance : 10; + if (is(values, "array")) { + var i = values.length; + while (i--) if (abs(values[i] - value) <= tolerance) { + return values[i]; + } + } else { + values = +values; + var rem = value % values; + if (rem < tolerance) { + return value - rem; + } + if (rem > values - tolerance) { + return value - rem + values; + } + } + return value; +}; +// Colour +/*\ + * Snap.getRGB + [ method ] + ** + * Parses color string as RGB object + - color (string) color string in one of the following formats: + # <ul> + # <li>Color name (<code>red</code>, <code>green</code>, <code>cornflowerblue</code>, etc)</li> + # <li>#••• — shortened HTML color: (<code>#000</code>, <code>#fc0</code>, etc.)</li> + # <li>#•••••• — full length HTML color: (<code>#000000</code>, <code>#bd2300</code>)</li> + # <li>rgb(•••, •••, •••) — red, green and blue channels values: (<code>rgb(200, 100, 0)</code>)</li> + # <li>rgba(•••, •••, •••, •••) — also with opacity</li> + # <li>rgb(•••%, •••%, •••%) — same as above, but in %: (<code>rgb(100%, 175%, 0%)</code>)</li> + # <li>rgba(•••%, •••%, •••%, •••%) — also with opacity</li> + # <li>hsb(•••, •••, •••) — hue, saturation and brightness values: (<code>hsb(0.5, 0.25, 1)</code>)</li> + # <li>hsba(•••, •••, •••, •••) — also with opacity</li> + # <li>hsb(•••%, •••%, •••%) — same as above, but in %</li> + # <li>hsba(•••%, •••%, •••%, •••%) — also with opacity</li> + # <li>hsl(•••, •••, •••) — hue, saturation and luminosity values: (<code>hsb(0.5, 0.25, 0.5)</code>)</li> + # <li>hsla(•••, •••, •••, •••) — also with opacity</li> + # <li>hsl(•••%, •••%, •••%) — same as above, but in %</li> + # <li>hsla(•••%, •••%, •••%, •••%) — also with opacity</li> + # </ul> + * Note that `%` can be used any time: `rgb(20%, 255, 50%)`. + = (object) RGB object in the following format: + o { + o r (number) red, + o g (number) green, + o b (number) blue, + o hex (string) color in HTML/CSS format: #••••••, + o error (boolean) true if string can't be parsed + o } +\*/ +Snap.getRGB = cacher(function (colour) { + if (!colour || !!((colour = Str(colour)).indexOf("-") + 1)) { + return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: rgbtoString}; + } + if (colour == "none") { + return {r: -1, g: -1, b: -1, hex: "none", toString: rgbtoString}; + } + !(hsrg[has](colour.toLowerCase().substring(0, 2)) || colour.charAt() == "#") && (colour = toHex(colour)); + if (!colour) { + return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: rgbtoString}; + } + var res, + red, + green, + blue, + opacity, + t, + values, + rgb = colour.match(colourRegExp); + if (rgb) { + if (rgb[2]) { + blue = toInt(rgb[2].substring(5), 16); + green = toInt(rgb[2].substring(3, 5), 16); + red = toInt(rgb[2].substring(1, 3), 16); + } + if (rgb[3]) { + blue = toInt((t = rgb[3].charAt(3)) + t, 16); + green = toInt((t = rgb[3].charAt(2)) + t, 16); + red = toInt((t = rgb[3].charAt(1)) + t, 16); + } + if (rgb[4]) { + values = rgb[4].split(commaSpaces); + red = toFloat(values[0]); + values[0].slice(-1) == "%" && (red *= 2.55); + green = toFloat(values[1]); + values[1].slice(-1) == "%" && (green *= 2.55); + blue = toFloat(values[2]); + values[2].slice(-1) == "%" && (blue *= 2.55); + rgb[1].toLowerCase().slice(0, 4) == "rgba" && (opacity = toFloat(values[3])); + values[3] && values[3].slice(-1) == "%" && (opacity /= 100); + } + if (rgb[5]) { + values = rgb[5].split(commaSpaces); + red = toFloat(values[0]); + values[0].slice(-1) == "%" && (red /= 100); + green = toFloat(values[1]); + values[1].slice(-1) == "%" && (green /= 100); + blue = toFloat(values[2]); + values[2].slice(-1) == "%" && (blue /= 100); + (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360); + rgb[1].toLowerCase().slice(0, 4) == "hsba" && (opacity = toFloat(values[3])); + values[3] && values[3].slice(-1) == "%" && (opacity /= 100); + return Snap.hsb2rgb(red, green, blue, opacity); + } + if (rgb[6]) { + values = rgb[6].split(commaSpaces); + red = toFloat(values[0]); + values[0].slice(-1) == "%" && (red /= 100); + green = toFloat(values[1]); + values[1].slice(-1) == "%" && (green /= 100); + blue = toFloat(values[2]); + values[2].slice(-1) == "%" && (blue /= 100); + (values[0].slice(-3) == "deg" || values[0].slice(-1) == "\xb0") && (red /= 360); + rgb[1].toLowerCase().slice(0, 4) == "hsla" && (opacity = toFloat(values[3])); + values[3] && values[3].slice(-1) == "%" && (opacity /= 100); + return Snap.hsl2rgb(red, green, blue, opacity); + } + red = mmin(math.round(red), 255); + green = mmin(math.round(green), 255); + blue = mmin(math.round(blue), 255); + opacity = mmin(mmax(opacity, 0), 1); + rgb = {r: red, g: green, b: blue, toString: rgbtoString}; + rgb.hex = "#" + (16777216 | blue | (green << 8) | (red << 16)).toString(16).slice(1); + rgb.opacity = is(opacity, "finite") ? opacity : 1; + return rgb; + } + return {r: -1, g: -1, b: -1, hex: "none", error: 1, toString: rgbtoString}; +}, Snap); +// SIERRA It seems odd that the following 3 conversion methods are not expressed as .this2that(), like the others. +/*\ + * Snap.hsb + [ method ] + ** + * Converts HSB values to a hex representation of the color + - h (number) hue + - s (number) saturation + - b (number) value or brightness + = (string) hex representation of the color +\*/ +Snap.hsb = cacher(function (h, s, b) { + return Snap.hsb2rgb(h, s, b).hex; +}); +/*\ + * Snap.hsl + [ method ] + ** + * Converts HSL values to a hex representation of the color + - h (number) hue + - s (number) saturation + - l (number) luminosity + = (string) hex representation of the color +\*/ +Snap.hsl = cacher(function (h, s, l) { + return Snap.hsl2rgb(h, s, l).hex; +}); +/*\ + * Snap.rgb + [ method ] + ** + * Converts RGB values to a hex representation of the color + - r (number) red + - g (number) green + - b (number) blue + = (string) hex representation of the color +\*/ +Snap.rgb = cacher(function (r, g, b, o) { + if (is(o, "finite")) { + var round = math.round; + return "rgba(" + [round(r), round(g), round(b), +o.toFixed(2)] + ")"; + } + return "#" + (16777216 | b | (g << 8) | (r << 16)).toString(16).slice(1); +}); +var toHex = function (color) { + var i = glob.doc.getElementsByTagName("head")[0] || glob.doc.getElementsByTagName("svg")[0], + red = "rgb(255, 0, 0)"; + toHex = cacher(function (color) { + if (color.toLowerCase() == "red") { + return red; + } + i.style.color = red; + i.style.color = color; + var out = glob.doc.defaultView.getComputedStyle(i, E).getPropertyValue("color"); + return out == red ? null : out; + }); + return toHex(color); +}, +hsbtoString = function () { + return "hsb(" + [this.h, this.s, this.b] + ")"; +}, +hsltoString = function () { + return "hsl(" + [this.h, this.s, this.l] + ")"; +}, +rgbtoString = function () { + return this.opacity == 1 || this.opacity == null ? + this.hex : + "rgba(" + [this.r, this.g, this.b, this.opacity] + ")"; +}, +prepareRGB = function (r, g, b) { + if (g == null && is(r, "object") && "r" in r && "g" in r && "b" in r) { + b = r.b; + g = r.g; + r = r.r; + } + if (g == null && is(r, string)) { + var clr = Snap.getRGB(r); + r = clr.r; + g = clr.g; + b = clr.b; + } + if (r > 1 || g > 1 || b > 1) { + r /= 255; + g /= 255; + b /= 255; + } + + return [r, g, b]; +}, +packageRGB = function (r, g, b, o) { + r = math.round(r * 255); + g = math.round(g * 255); + b = math.round(b * 255); + var rgb = { + r: r, + g: g, + b: b, + opacity: is(o, "finite") ? o : 1, + hex: Snap.rgb(r, g, b), + toString: rgbtoString + }; + is(o, "finite") && (rgb.opacity = o); + return rgb; +}; +// SIERRA Clarify if Snap does not support consolidated HSLA/RGBA colors. E.g., can you specify a semi-transparent value for Snap.filter.shadow()? +/*\ + * Snap.color + [ method ] + ** + * Parses the color string and returns an object featuring the color's component values + - clr (string) color string in one of the supported formats (see @Snap.getRGB) + = (object) Combined RGB/HSB object in the following format: + o { + o r (number) red, + o g (number) green, + o b (number) blue, + o hex (string) color in HTML/CSS format: #••••••, + o error (boolean) `true` if string can't be parsed, + o h (number) hue, + o s (number) saturation, + o v (number) value (brightness), + o l (number) lightness + o } +\*/ +Snap.color = function (clr) { + var rgb; + if (is(clr, "object") && "h" in clr && "s" in clr && "b" in clr) { + rgb = Snap.hsb2rgb(clr); + clr.r = rgb.r; + clr.g = rgb.g; + clr.b = rgb.b; + clr.opacity = 1; + clr.hex = rgb.hex; + } else if (is(clr, "object") && "h" in clr && "s" in clr && "l" in clr) { + rgb = Snap.hsl2rgb(clr); + clr.r = rgb.r; + clr.g = rgb.g; + clr.b = rgb.b; + clr.opacity = 1; + clr.hex = rgb.hex; + } else { + if (is(clr, "string")) { + clr = Snap.getRGB(clr); + } + if (is(clr, "object") && "r" in clr && "g" in clr && "b" in clr && !("error" in clr)) { + rgb = Snap.rgb2hsl(clr); + clr.h = rgb.h; + clr.s = rgb.s; + clr.l = rgb.l; + rgb = Snap.rgb2hsb(clr); + clr.v = rgb.b; + } else { + clr = {hex: "none"}; + clr.r = clr.g = clr.b = clr.h = clr.s = clr.v = clr.l = -1; + clr.error = 1; + } + } + clr.toString = rgbtoString; + return clr; +}; +/*\ + * Snap.hsb2rgb + [ method ] + ** + * Converts HSB values to an RGB object + - h (number) hue + - s (number) saturation + - v (number) value or brightness + = (object) RGB object in the following format: + o { + o r (number) red, + o g (number) green, + o b (number) blue, + o hex (string) color in HTML/CSS format: #•••••• + o } +\*/ +Snap.hsb2rgb = function (h, s, v, o) { + if (is(h, "object") && "h" in h && "s" in h && "b" in h) { + v = h.b; + s = h.s; + h = h.h; + o = h.o; + } + h *= 360; + var R, G, B, X, C; + h = (h % 360) / 60; + C = v * s; + X = C * (1 - abs(h % 2 - 1)); + R = G = B = v - C; + + h = ~~h; + R += [C, X, 0, 0, X, C][h]; + G += [X, C, C, X, 0, 0][h]; + B += [0, 0, X, C, C, X][h]; + return packageRGB(R, G, B, o); +}; +/*\ + * Snap.hsl2rgb + [ method ] + ** + * Converts HSL values to an RGB object + - h (number) hue + - s (number) saturation + - l (number) luminosity + = (object) RGB object in the following format: + o { + o r (number) red, + o g (number) green, + o b (number) blue, + o hex (string) color in HTML/CSS format: #•••••• + o } +\*/ +Snap.hsl2rgb = function (h, s, l, o) { + if (is(h, "object") && "h" in h && "s" in h && "l" in h) { + l = h.l; + s = h.s; + h = h.h; + } + if (h > 1 || s > 1 || l > 1) { + h /= 360; + s /= 100; + l /= 100; + } + h *= 360; + var R, G, B, X, C; + h = (h % 360) / 60; + C = 2 * s * (l < .5 ? l : 1 - l); + X = C * (1 - abs(h % 2 - 1)); + R = G = B = l - C / 2; + + h = ~~h; + R += [C, X, 0, 0, X, C][h]; + G += [X, C, C, X, 0, 0][h]; + B += [0, 0, X, C, C, X][h]; + return packageRGB(R, G, B, o); +}; +/*\ + * Snap.rgb2hsb + [ method ] + ** + * Converts RGB values to an HSB object + - r (number) red + - g (number) green + - b (number) blue + = (object) HSB object in the following format: + o { + o h (number) hue, + o s (number) saturation, + o b (number) brightness + o } +\*/ +Snap.rgb2hsb = function (r, g, b) { + b = prepareRGB(r, g, b); + r = b[0]; + g = b[1]; + b = b[2]; + + var H, S, V, C; + V = mmax(r, g, b); + C = V - mmin(r, g, b); + H = (C == 0 ? null : + V == r ? (g - b) / C : + V == g ? (b - r) / C + 2 : + (r - g) / C + 4 + ); + H = ((H + 360) % 6) * 60 / 360; + S = C == 0 ? 0 : C / V; + return {h: H, s: S, b: V, toString: hsbtoString}; +}; +/*\ + * Snap.rgb2hsl + [ method ] + ** + * Converts RGB values to an HSL object + - r (number) red + - g (number) green + - b (number) blue + = (object) HSL object in the following format: + o { + o h (number) hue, + o s (number) saturation, + o l (number) luminosity + o } +\*/ +Snap.rgb2hsl = function (r, g, b) { + b = prepareRGB(r, g, b); + r = b[0]; + g = b[1]; + b = b[2]; + + var H, S, L, M, m, C; + M = mmax(r, g, b); + m = mmin(r, g, b); + C = M - m; + H = (C == 0 ? null : + M == r ? (g - b) / C : + M == g ? (b - r) / C + 2 : + (r - g) / C + 4); + H = ((H + 360) % 6) * 60 / 360; + L = (M + m) / 2; + S = (C == 0 ? 0 : + L < .5 ? C / (2 * L) : + C / (2 - 2 * L)); + return {h: H, s: S, l: L, toString: hsltoString}; +}; + +// Transformations +// SIERRA Snap.parsePathString(): By _array of arrays,_ I assume you mean a format like this for two separate segments? [ ["M10,10","L90,90"], ["M90,10","L10,90"] ] Otherwise how is each command structured? +/*\ + * Snap.parsePathString + [ method ] + ** + * Utility method + ** + * Parses given path string into an array of arrays of path segments + - pathString (string|array) path string or array of segments (in the last case it is returned straight away) + = (array) array of segments +\*/ +Snap.parsePathString = function (pathString) { + if (!pathString) { + return null; + } + var pth = Snap.path(pathString); + if (pth.arr) { + return Snap.path.clone(pth.arr); + } + + var paramCounts = {a: 7, c: 6, o: 2, h: 1, l: 2, m: 2, r: 4, q: 4, s: 4, t: 2, v: 1, u: 3, z: 0}, + data = []; + if (is(pathString, "array") && is(pathString[0], "array")) { // rough assumption + data = Snap.path.clone(pathString); + } + if (!data.length) { + Str(pathString).replace(pathCommand, function (a, b, c) { + var params = [], + name = b.toLowerCase(); + c.replace(pathValues, function (a, b) { + b && params.push(+b); + }); + if (name == "m" && params.length > 2) { + data.push([b].concat(params.splice(0, 2))); + name = "l"; + b = b == "m" ? "l" : "L"; + } + if (name == "o" && params.length == 1) { + data.push([b, params[0]]); + } + if (name == "r") { + data.push([b].concat(params)); + } else while (params.length >= paramCounts[name]) { + data.push([b].concat(params.splice(0, paramCounts[name]))); + if (!paramCounts[name]) { + break; + } + } + }); + } + data.toString = Snap.path.toString; + pth.arr = Snap.path.clone(data); + return data; +}; +/*\ + * Snap.parseTransformString + [ method ] + ** + * Utility method + ** + * Parses given transform string into an array of transformations + - TString (string|array) transform string or array of transformations (in the last case it is returned straight away) + = (array) array of transformations +\*/ +var parseTransformString = Snap.parseTransformString = function (TString) { + if (!TString) { + return null; + } + var paramCounts = {r: 3, s: 4, t: 2, m: 6}, + data = []; + if (is(TString, "array") && is(TString[0], "array")) { // rough assumption + data = Snap.path.clone(TString); + } + if (!data.length) { + Str(TString).replace(tCommand, function (a, b, c) { + var params = [], + name = b.toLowerCase(); + c.replace(pathValues, function (a, b) { + b && params.push(+b); + }); + data.push([b].concat(params)); + }); + } + data.toString = Snap.path.toString; + return data; +}; +function svgTransform2string(tstr) { + var res = []; + tstr = tstr.replace(/(?:^|\s)(\w+)\(([^)]+)\)/g, function (all, name, params) { + params = params.split(/\s*,\s*|\s+/); + if (name == "rotate" && params.length == 1) { + params.push(0, 0); + } + if (name == "scale") { + if (params.length > 2) { + params = params.slice(0, 2); + } else if (params.length == 2) { + params.push(0, 0); + } + if (params.length == 1) { + params.push(params[0], 0, 0); + } + } + if (name == "skewX") { + res.push(["m", 1, 0, math.tan(rad(params[0])), 1, 0, 0]); + } else if (name == "skewY") { + res.push(["m", 1, math.tan(rad(params[0])), 0, 1, 0, 0]); + } else { + res.push([name.charAt(0)].concat(params)); + } + return all; + }); + return res; +} +Snap._.svgTransform2string = svgTransform2string; +Snap._.rgTransform = /^[a-z][\s]*-?\.?\d/i; +function transform2matrix(tstr, bbox) { + var tdata = parseTransformString(tstr), + m = new Snap.Matrix; + if (tdata) { + for (var i = 0, ii = tdata.length; i < ii; i++) { + var t = tdata[i], + tlen = t.length, + command = Str(t[0]).toLowerCase(), + absolute = t[0] != command, + inver = absolute ? m.invert() : 0, + x1, + y1, + x2, + y2, + bb; + if (command == "t" && tlen == 2){ + m.translate(t[1], 0); + } else if (command == "t" && tlen == 3) { + if (absolute) { + x1 = inver.x(0, 0); + y1 = inver.y(0, 0); + x2 = inver.x(t[1], t[2]); + y2 = inver.y(t[1], t[2]); + m.translate(x2 - x1, y2 - y1); + } else { + m.translate(t[1], t[2]); + } + } else if (command == "r") { + if (tlen == 2) { + bb = bb || bbox; + m.rotate(t[1], bb.x + bb.width / 2, bb.y + bb.height / 2); + } else if (tlen == 4) { + if (absolute) { + x2 = inver.x(t[2], t[3]); + y2 = inver.y(t[2], t[3]); + m.rotate(t[1], x2, y2); + } else { + m.rotate(t[1], t[2], t[3]); + } + } + } else if (command == "s") { + if (tlen == 2 || tlen == 3) { + bb = bb || bbox; + m.scale(t[1], t[tlen - 1], bb.x + bb.width / 2, bb.y + bb.height / 2); + } else if (tlen == 4) { + if (absolute) { + x2 = inver.x(t[2], t[3]); + y2 = inver.y(t[2], t[3]); + m.scale(t[1], t[1], x2, y2); + } else { + m.scale(t[1], t[1], t[2], t[3]); + } + } else if (tlen == 5) { + if (absolute) { + x2 = inver.x(t[3], t[4]); + y2 = inver.y(t[3], t[4]); + m.scale(t[1], t[2], x2, y2); + } else { + m.scale(t[1], t[2], t[3], t[4]); + } + } + } else if (command == "m" && tlen == 7) { + m.add(t[1], t[2], t[3], t[4], t[5], t[6]); + } + } + } + return m; +} +Snap._.transform2matrix = transform2matrix; +Snap._unit2px = unit2px; +var contains = glob.doc.contains || glob.doc.compareDocumentPosition ? + function (a, b) { + var adown = a.nodeType == 9 ? a.documentElement : a, + bup = b && b.parentNode; + return a == bup || !!(bup && bup.nodeType == 1 && ( + adown.contains ? + adown.contains(bup) : + a.compareDocumentPosition && a.compareDocumentPosition(bup) & 16 + )); + } : + function (a, b) { + if (b) { + while (b) { + b = b.parentNode; + if (b == a) { + return true; + } + } + } + return false; + }; +function getSomeDefs(el) { + var p = (el.node.ownerSVGElement && wrap(el.node.ownerSVGElement)) || + (el.node.parentNode && wrap(el.node.parentNode)) || + Snap.select("svg") || + Snap(0, 0), + pdefs = p.select("defs"), + defs = pdefs == null ? false : pdefs.node; + if (!defs) { + defs = make("defs", p.node).node; + } + return defs; +} +function getSomeSVG(el) { + return el.node.ownerSVGElement && wrap(el.node.ownerSVGElement) || Snap.select("svg"); +} +Snap._.getSomeDefs = getSomeDefs; +Snap._.getSomeSVG = getSomeSVG; +function unit2px(el, name, value) { + var svg = getSomeSVG(el).node, + out = {}, + mgr = svg.querySelector(".svg---mgr"); + if (!mgr) { + mgr = $("rect"); + $(mgr, {x: -9e9, y: -9e9, width: 10, height: 10, "class": "svg---mgr", fill: "none"}); + svg.appendChild(mgr); + } + function getW(val) { + if (val == null) { + return E; + } + if (val == +val) { + return val; + } + $(mgr, {width: val}); + try { + return mgr.getBBox().width; + } catch (e) { + return 0; + } + } + function getH(val) { + if (val == null) { + return E; + } + if (val == +val) { + return val; + } + $(mgr, {height: val}); + try { + return mgr.getBBox().height; + } catch (e) { + return 0; + } + } + function set(nam, f) { + if (name == null) { + out[nam] = f(el.attr(nam) || 0); + } else if (nam == name) { + out = f(value == null ? el.attr(nam) || 0 : value); + } + } + switch (el.type) { + case "rect": + set("rx", getW); + set("ry", getH); + case "image": + set("width", getW); + set("height", getH); + case "text": + set("x", getW); + set("y", getH); + break; + case "circle": + set("cx", getW); + set("cy", getH); + set("r", getW); + break; + case "ellipse": + set("cx", getW); + set("cy", getH); + set("rx", getW); + set("ry", getH); + break; + case "line": + set("x1", getW); + set("x2", getW); + set("y1", getH); + set("y2", getH); + break; + case "marker": + set("refX", getW); + set("markerWidth", getW); + set("refY", getH); + set("markerHeight", getH); + break; + case "radialGradient": + set("fx", getW); + set("fy", getH); + break; + case "tspan": + set("dx", getW); + set("dy", getH); + break; + default: + set(name, getW); + } + svg.removeChild(mgr); + return out; +} +/*\ + * Snap.select + [ method ] + ** + * Wraps a DOM element specified by CSS selector as @Element + - query (string) CSS selector of the element + = (Element) the current element +\*/ +Snap.select = function (query) { + query = Str(query).replace(/([^\\]):/g, "$1\\:"); + return wrap(glob.doc.querySelector(query)); +}; +/*\ + * Snap.selectAll + [ method ] + ** + * Wraps DOM elements specified by CSS selector as set or array of @Element + - query (string) CSS selector of the element + = (Element) the current element +\*/ +Snap.selectAll = function (query) { + var nodelist = glob.doc.querySelectorAll(query), + set = (Snap.set || Array)(); + for (var i = 0; i < nodelist.length; i++) { + set.push(wrap(nodelist[i])); + } + return set; +}; + +function add2group(list) { + if (!is(list, "array")) { + list = Array.prototype.slice.call(arguments, 0); + } + var i = 0, + j = 0, + node = this.node; + while (this[i]) delete this[i++]; + for (i = 0; i < list.length; i++) { + if (list[i].type == "set") { + list[i].forEach(function (el) { + node.appendChild(el.node); + }); + } else { + node.appendChild(list[i].node); + } + } + var children = node.childNodes; + for (i = 0; i < children.length; i++) { + this[j++] = wrap(children[i]); + } + return this; +} +// Hub garbage collector every 10s +setInterval(function () { + for (var key in hub) if (hub[has](key)) { + var el = hub[key], + node = el.node; + if (el.type != "svg" && !node.ownerSVGElement || el.type == "svg" && (!node.parentNode || "ownerSVGElement" in node.parentNode && !node.ownerSVGElement)) { + delete hub[key]; + } + } +}, 1e4); +function Element(el) { + if (el.snap in hub) { + return hub[el.snap]; + } + var svg; + try { + svg = el.ownerSVGElement; + } catch(e) {} + /*\ + * Element.node + [ property (object) ] + ** + * Gives you a reference to the DOM object, so you can assign event handlers or just mess around. + > Usage + | // draw a circle at coordinate 10,10 with radius of 10 + | var c = paper.circle(10, 10, 10); + | c.node.onclick = function () { + | c.attr("fill", "red"); + | }; + \*/ + this.node = el; + if (svg) { + this.paper = new Paper(svg); + } + /*\ + * Element.type + [ property (string) ] + ** + * SVG tag name of the given element. + \*/ + this.type = el.tagName; + var id = this.id = ID(this); + this.anims = {}; + this._ = { + transform: [] + }; + el.snap = id; + hub[id] = this; + if (this.type == "g") { + this.add = add2group; + } + if (this.type in {g: 1, mask: 1, pattern: 1, symbol: 1}) { + for (var method in Paper.prototype) if (Paper.prototype[has](method)) { + this[method] = Paper.prototype[method]; + } + } +} + /*\ + * Element.attr + [ method ] + ** + * Gets or sets given attributes of the element. + ** + - params (object) contains key-value pairs of attributes you want to set + * or + - param (string) name of the attribute + = (Element) the current element + * or + = (string) value of attribute + > Usage + | el.attr({ + | fill: "#fc0", + | stroke: "#000", + | strokeWidth: 2, // CamelCase... + | "fill-opacity": 0.5, // or dash-separated names + | width: "*=2" // prefixed values + | }); + | console.log(el.attr("fill")); // #fc0 + * Prefixed values in format `"+=10"` supported. All four operations + * (`+`, `-`, `*` and `/`) could be used. Optionally you can use units for `+` + * and `-`: `"+=2em"`. + \*/ + Element.prototype.attr = function (params, value) { + var el = this, + node = el.node; + if (!params) { + return el; + } + if (is(params, "string")) { + if (arguments.length > 1) { + var json = {}; + json[params] = value; + params = json; + } else { + return eve("snap.util.getattr." + params, el).firstDefined(); + } + } + for (var att in params) { + if (params[has](att)) { + eve("snap.util.attr." + att, el, params[att]); + } + } + return el; + }; +/*\ + * Snap.parse + [ method ] + ** + * Parses SVG fragment and converts it into a @Fragment + ** + - svg (string) SVG string + = (Fragment) the @Fragment +\*/ +Snap.parse = function (svg) { + var f = glob.doc.createDocumentFragment(), + full = true, + div = glob.doc.createElement("div"); + svg = Str(svg); + if (!svg.match(/^\s*<\s*svg(?:\s|>)/)) { + svg = "<svg>" + svg + "</svg>"; + full = false; + } + div.innerHTML = svg; + svg = div.getElementsByTagName("svg")[0]; + if (svg) { + if (full) { + f = svg; + } else { + while (svg.firstChild) { + f.appendChild(svg.firstChild); + } + div.innerHTML = E; + } + } + return new Fragment(f); +}; +function Fragment(frag) { + this.node = frag; +} +// SIERRA Snap.fragment() could especially use a code example +/*\ + * Snap.fragment + [ method ] + ** + * Creates a DOM fragment from a given list of elements or strings + ** + - varargs (…) SVG string + = (Fragment) the @Fragment +\*/ +Snap.fragment = function () { + var args = Array.prototype.slice.call(arguments, 0), + f = glob.doc.createDocumentFragment(); + for (var i = 0, ii = args.length; i < ii; i++) { + var item = args[i]; + if (item.node && item.node.nodeType) { + f.appendChild(item.node); + } + if (item.nodeType) { + f.appendChild(item); + } + if (typeof item == "string") { + f.appendChild(Snap.parse(item).node); + } + } + return new Fragment(f); +}; + +function make(name, parent) { + var res = $(name); + parent.appendChild(res); + var el = wrap(res); + return el; +} +function Paper(w, h) { + var res, + desc, + defs, + proto = Paper.prototype; + if (w && w.tagName == "svg") { + if (w.snap in hub) { + return hub[w.snap]; + } + var doc = w.ownerDocument; + res = new Element(w); + desc = w.getElementsByTagName("desc")[0]; + defs = w.getElementsByTagName("defs")[0]; + if (!desc) { + desc = $("desc"); + desc.appendChild(doc.createTextNode("Created with Snap")); + res.node.appendChild(desc); + } + if (!defs) { + defs = $("defs"); + res.node.appendChild(defs); + } + res.defs = defs; + for (var key in proto) if (proto[has](key)) { + res[key] = proto[key]; + } + res.paper = res.root = res; + } else { + res = make("svg", glob.doc.body); + $(res.node, { + height: h, + version: 1.1, + width: w, + xmlns: xmlns + }); + } + return res; +} +function wrap(dom) { + if (!dom) { + return dom; + } + if (dom instanceof Element || dom instanceof Fragment) { + return dom; + } + if (dom.tagName && dom.tagName.toLowerCase() == "svg") { + return new Paper(dom); + } + if (dom.tagName && dom.tagName.toLowerCase() == "object" && dom.type == "image/svg+xml") { + return new Paper(dom.contentDocument.getElementsByTagName("svg")[0]); + } + return new Element(dom); +} + +Snap._.make = make; +Snap._.wrap = wrap; +/*\ + * Paper.el + [ method ] + ** + * Creates an element on paper with a given name and no attributes + ** + - name (string) tag name + - attr (object) attributes + = (Element) the current element + > Usage + | var c = paper.circle(10, 10, 10); // is the same as... + | var c = paper.el("circle").attr({ + | cx: 10, + | cy: 10, + | r: 10 + | }); + | // and the same as + | var c = paper.el("circle", { + | cx: 10, + | cy: 10, + | r: 10 + | }); +\*/ +Paper.prototype.el = function (name, attr) { + var el = make(name, this.node); + attr && el.attr(attr); + return el; +}; +// default +eve.on("snap.util.getattr", function () { + var att = eve.nt(); + att = att.substring(att.lastIndexOf(".") + 1); + var css = att.replace(/[A-Z]/g, function (letter) { + return "-" + letter.toLowerCase(); + }); + if (cssAttr[has](css)) { + return this.node.ownerDocument.defaultView.getComputedStyle(this.node, null).getPropertyValue(css); + } else { + return $(this.node, att); + } +}); +var cssAttr = { + "alignment-baseline": 0, + "baseline-shift": 0, + "clip": 0, + "clip-path": 0, + "clip-rule": 0, + "color": 0, + "color-interpolation": 0, + "color-interpolation-filters": 0, + "color-profile": 0, + "color-rendering": 0, + "cursor": 0, + "direction": 0, + "display": 0, + "dominant-baseline": 0, + "enable-background": 0, + "fill": 0, + "fill-opacity": 0, + "fill-rule": 0, + "filter": 0, + "flood-color": 0, + "flood-opacity": 0, + "font": 0, + "font-family": 0, + "font-size": 0, + "font-size-adjust": 0, + "font-stretch": 0, + "font-style": 0, + "font-variant": 0, + "font-weight": 0, + "glyph-orientation-horizontal": 0, + "glyph-orientation-vertical": 0, + "image-rendering": 0, + "kerning": 0, + "letter-spacing": 0, + "lighting-color": 0, + "marker": 0, + "marker-end": 0, + "marker-mid": 0, + "marker-start": 0, + "mask": 0, + "opacity": 0, + "overflow": 0, + "pointer-events": 0, + "shape-rendering": 0, + "stop-color": 0, + "stop-opacity": 0, + "stroke": 0, + "stroke-dasharray": 0, + "stroke-dashoffset": 0, + "stroke-linecap": 0, + "stroke-linejoin": 0, + "stroke-miterlimit": 0, + "stroke-opacity": 0, + "stroke-width": 0, + "text-anchor": 0, + "text-decoration": 0, + "text-rendering": 0, + "unicode-bidi": 0, + "visibility": 0, + "word-spacing": 0, + "writing-mode": 0 +}; + +eve.on("snap.util.attr", function (value) { + var att = eve.nt(), + attr = {}; + att = att.substring(att.lastIndexOf(".") + 1); + attr[att] = value; + var style = att.replace(/-(\w)/gi, function (all, letter) { + return letter.toUpperCase(); + }), + css = att.replace(/[A-Z]/g, function (letter) { + return "-" + letter.toLowerCase(); + }); + if (cssAttr[has](css)) { + this.node.style[style] = value == null ? E : value; + } else { + $(this.node, attr); + } +}); +(function (proto) {}(Paper.prototype)); + +// simple ajax +/*\ + * Snap.ajax + [ method ] + ** + * Simple implementation of Ajax + ** + - url (string) URL + - postData (object|string) data for post request + - callback (function) callback + - scope (object) #optional scope of callback + * or + - url (string) URL + - callback (function) callback + - scope (object) #optional scope of callback + = (XMLHttpRequest) the XMLHttpRequest object, just in case +\*/ +Snap.ajax = function (url, postData, callback, scope){ + var req = new XMLHttpRequest, + id = ID(); + if (req) { + if (is(postData, "function")) { + scope = callback; + callback = postData; + postData = null; + } else if (is(postData, "object")) { + var pd = []; + for (var key in postData) if (postData.hasOwnProperty(key)) { + pd.push(encodeURIComponent(key) + "=" + encodeURIComponent(postData[key])); + } + postData = pd.join("&"); + } + req.open((postData ? "POST" : "GET"), url, true); + if (postData) { + req.setRequestHeader("X-Requested-With", "XMLHttpRequest"); + req.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); + } + if (callback) { + eve.once("snap.ajax." + id + ".0", callback); + eve.once("snap.ajax." + id + ".200", callback); + eve.once("snap.ajax." + id + ".304", callback); + } + req.onreadystatechange = function() { + if (req.readyState != 4) return; + eve("snap.ajax." + id + "." + req.status, scope, req); + }; + if (req.readyState == 4) { + return req; + } + req.send(postData); + return req; + } +}; +/*\ + * Snap.load + [ method ] + ** + * Loads external SVG file as a @Fragment (see @Snap.ajax for more advanced AJAX) + ** + - url (string) URL + - callback (function) callback + - scope (object) #optional scope of callback +\*/ +Snap.load = function (url, callback, scope) { + Snap.ajax(url, function (req) { + var f = Snap.parse(req.responseText); + scope ? callback.call(scope, f) : callback(f); + }); +}; +var getOffset = function (elem) { + var box = elem.getBoundingClientRect(), + doc = elem.ownerDocument, + body = doc.body, + docElem = doc.documentElement, + clientTop = docElem.clientTop || body.clientTop || 0, clientLeft = docElem.clientLeft || body.clientLeft || 0, + top = box.top + (g.win.pageYOffset || docElem.scrollTop || body.scrollTop ) - clientTop, + left = box.left + (g.win.pageXOffset || docElem.scrollLeft || body.scrollLeft) - clientLeft; + return { + y: top, + x: left + }; +}; +/*\ + * Snap.getElementByPoint + [ method ] + ** + * Returns you topmost element under given point. + ** + = (object) Snap element object + - x (number) x coordinate from the top left corner of the window + - y (number) y coordinate from the top left corner of the window + > Usage + | Snap.getElementByPoint(mouseX, mouseY).attr({stroke: "#f00"}); +\*/ +Snap.getElementByPoint = function (x, y) { + var paper = this, + svg = paper.canvas, + target = glob.doc.elementFromPoint(x, y); + if (glob.win.opera && target.tagName == "svg") { + var so = getOffset(target), + sr = target.createSVGRect(); + sr.x = x - so.x; + sr.y = y - so.y; + sr.width = sr.height = 1; + var hits = target.getIntersectionList(sr, null); + if (hits.length) { + target = hits[hits.length - 1]; + } + } + if (!target) { + return null; + } + return wrap(target); +}; +/*\ + * Snap.plugin + [ method ] + ** + * Let you write plugins. You pass in a function with four arguments, like this: + | Snap.plugin(function (Snap, Element, Paper, global, Fragment) { + | Snap.newmethod = function () {}; + | Element.prototype.newmethod = function () {}; + | Paper.prototype.newmethod = function () {}; + | }); + * Inside the function you have access to all main objects (and their + * prototypes). This allow you to extend anything you want. + ** + - f (function) your plugin body +\*/ +Snap.plugin = function (f) { + f(Snap, Element, Paper, glob, Fragment); +}; +glob.win.Snap = Snap; +return Snap; +}(window || this)); +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +Snap.plugin(function (Snap, Element, Paper, glob, Fragment) { + var elproto = Element.prototype, + is = Snap.is, + Str = String, + unit2px = Snap._unit2px, + $ = Snap._.$, + make = Snap._.make, + getSomeDefs = Snap._.getSomeDefs, + has = "hasOwnProperty", + wrap = Snap._.wrap; + /*\ + * Element.getBBox + [ method ] + ** + * Returns the bounding box descriptor for the given element + ** + = (object) bounding box descriptor: + o { + o cx: (number) x of the center, + o cy: (number) x of the center, + o h: (number) height, + o height: (number) height, + o path: (string) path command for the box, + o r0: (number) radius of a circle that fully encloses the box, + o r1: (number) radius of the smallest circle that can be enclosed, + o r2: (number) radius of the largest circle that can be enclosed, + o vb: (string) box as a viewbox command, + o w: (number) width, + o width: (number) width, + o x2: (number) x of the right side, + o x: (number) x of the left side, + o y2: (number) y of the bottom edge, + o y: (number) y of the top edge + o } + \*/ + elproto.getBBox = function (isWithoutTransform) { + if (!Snap.Matrix || !Snap.path) { + return this.node.getBBox(); + } + var el = this, + m = new Snap.Matrix; + if (el.removed) { + return Snap._.box(); + } + while (el.type == "use") { + if (!isWithoutTransform) { + m = m.add(el.transform().localMatrix.translate(el.attr("x") || 0, el.attr("y") || 0)); + } + if (el.original) { + el = el.original; + } else { + var href = el.attr("xlink:href"); + el = el.original = el.node.ownerDocument.getElementById(href.substring(href.indexOf("#") + 1)); + } + } + var _ = el._, + pathfinder = Snap.path.get[el.type] || Snap.path.get.deflt; + try { + if (isWithoutTransform) { + _.bboxwt = pathfinder ? Snap.path.getBBox(el.realPath = pathfinder(el)) : Snap._.box(el.node.getBBox()); + return Snap._.box(_.bboxwt); + } else { + el.realPath = pathfinder(el); + el.matrix = el.transform().localMatrix; + _.bbox = Snap.path.getBBox(Snap.path.map(el.realPath, m.add(el.matrix))); + return Snap._.box(_.bbox); + } + } catch (e) { + // Firefox doesn’t give you bbox of hidden element + return Snap._.box(); + } + }; + var propString = function () { + return this.string; + }; + function extractTransform(el, tstr) { + if (tstr == null) { + var doReturn = true; + if (el.type == "linearGradient" || el.type == "radialGradient") { + tstr = el.node.getAttribute("gradientTransform"); + } else if (el.type == "pattern") { + tstr = el.node.getAttribute("patternTransform"); + } else { + tstr = el.node.getAttribute("transform"); + } + if (!tstr) { + return new Snap.Matrix; + } + tstr = Snap._.svgTransform2string(tstr); + } else { + if (!Snap._.rgTransform.test(tstr)) { + tstr = Snap._.svgTransform2string(tstr); + } else { + tstr = Str(tstr).replace(/\.{3}|\u2026/g, el._.transform || E); + } + if (is(tstr, "array")) { + tstr = Snap.path ? Snap.path.toString.call(tstr) : Str(tstr); + } + el._.transform = tstr; + } + var m = Snap._.transform2matrix(tstr, el.getBBox(1)); + if (doReturn) { + return m; + } else { + el.matrix = m; + } + } + /*\ + * Element.transform + [ method ] + ** + * Gets or sets transformation of the element + ** + - tstr (string) transform string in Snap or SVG format + = (Element) the current element + * or + = (object) transformation descriptor: + o { + o string (string) transform string, + o globalMatrix (Matrix) matrix of all transformations applied to element or its parents, + o localMatrix (Matrix) matrix of transformations applied only to the element, + o diffMatrix (Matrix) matrix of difference between global and local transformations, + o global (string) global transformation as string, + o local (string) local transformation as string, + o toString (function) returns `string` property + o } + \*/ + elproto.transform = function (tstr) { + var _ = this._; + if (tstr == null) { + var papa = this, + global = new Snap.Matrix(this.node.getCTM()), + local = extractTransform(this), + ms = [local], + m = new Snap.Matrix, + i, + localString = local.toTransformString(), + string = Str(local) == Str(this.matrix) ? + Str(_.transform) : localString; + while (papa.type != "svg" && (papa = papa.parent())) { + ms.push(extractTransform(papa)); + } + i = ms.length; + while (i--) { + m.add(ms[i]); + } + return { + string: string, + globalMatrix: global, + totalMatrix: m, + localMatrix: local, + diffMatrix: global.clone().add(local.invert()), + global: global.toTransformString(), + total: m.toTransformString(), + local: localString, + toString: propString + }; + } + if (tstr instanceof Snap.Matrix) { + this.matrix = tstr; + this._.transform = tstr.toTransformString(); + } else { + extractTransform(this, tstr); + } + + if (this.node) { + if (this.type == "linearGradient" || this.type == "radialGradient") { + $(this.node, {gradientTransform: this.matrix}); + } else if (this.type == "pattern") { + $(this.node, {patternTransform: this.matrix}); + } else { + $(this.node, {transform: this.matrix}); + } + } + + return this; + }; + /*\ + * Element.parent + [ method ] + ** + * Returns the element's parent + ** + = (Element) the parent element + \*/ + elproto.parent = function () { + return wrap(this.node.parentNode); + }; + /*\ + * Element.append + [ method ] + ** + * Appends the given element to current one + ** + - el (Element|Set) element to append + = (Element) the parent element + \*/ + /*\ + * Element.add + [ method ] + ** + * See @Element.append + \*/ + elproto.append = elproto.add = function (el) { + if (el) { + if (el.type == "set") { + var it = this; + el.forEach(function (el) { + it.add(el); + }); + return this; + } + el = wrap(el); + this.node.appendChild(el.node); + el.paper = this.paper; + } + return this; + }; + /*\ + * Element.appendTo + [ method ] + ** + * Appends the current element to the given one + ** + - el (Element) parent element to append to + = (Element) the child element + \*/ + elproto.appendTo = function (el) { + if (el) { + el = wrap(el); + el.append(this); + } + return this; + }; + /*\ + * Element.prepend + [ method ] + ** + * Prepends the given element to the current one + ** + - el (Element) element to prepend + = (Element) the parent element + \*/ + elproto.prepend = function (el) { + if (el) { + if (el.type == "set") { + var it = this, + first; + el.forEach(function (el) { + if (first) { + first.after(el); + } else { + it.prepend(el); + } + first = el; + }); + return this; + } + el = wrap(el); + var parent = el.parent(); + this.node.insertBefore(el.node, this.node.firstChild); + this.add && this.add(); + el.paper = this.paper; + this.parent() && this.parent().add(); + parent && parent.add(); + } + return this; + }; + /*\ + * Element.prependTo + [ method ] + ** + * Prepends the current element to the given one + ** + - el (Element) parent element to prepend to + = (Element) the child element + \*/ + elproto.prependTo = function (el) { + el = wrap(el); + el.prepend(this); + return this; + }; + /*\ + * Element.before + [ method ] + ** + * Inserts given element before the current one + ** + - el (Element) element to insert + = (Element) the parent element + \*/ + elproto.before = function (el) { + if (el.type == "set") { + var it = this; + el.forEach(function (el) { + var parent = el.parent(); + it.node.parentNode.insertBefore(el.node, it.node); + parent && parent.add(); + }); + this.parent().add(); + return this; + } + el = wrap(el); + var parent = el.parent(); + this.node.parentNode.insertBefore(el.node, this.node); + this.parent() && this.parent().add(); + parent && parent.add(); + el.paper = this.paper; + return this; + }; + /*\ + * Element.after + [ method ] + ** + * Inserts given element after the current one + ** + - el (Element) element to insert + = (Element) the parent element + \*/ + elproto.after = function (el) { + el = wrap(el); + var parent = el.parent(); + if (this.node.nextSibling) { + this.node.parentNode.insertBefore(el.node, this.node.nextSibling); + } else { + this.node.parentNode.appendChild(el.node); + } + this.parent() && this.parent().add(); + parent && parent.add(); + el.paper = this.paper; + return this; + }; + /*\ + * Element.insertBefore + [ method ] + ** + * Inserts the element after the given one + ** + - el (Element) element next to whom insert to + = (Element) the parent element + \*/ + elproto.insertBefore = function (el) { + el = wrap(el); + var parent = this.parent(); + el.node.parentNode.insertBefore(this.node, el.node); + this.paper = el.paper; + parent && parent.add(); + el.parent() && el.parent().add(); + return this; + }; + /*\ + * Element.insertAfter + [ method ] + ** + * Inserts the element after the given one + ** + - el (Element) element next to whom insert to + = (Element) the parent element + \*/ + elproto.insertAfter = function (el) { + el = wrap(el); + var parent = this.parent(); + el.node.parentNode.insertBefore(this.node, el.node.nextSibling); + this.paper = el.paper; + parent && parent.add(); + el.parent() && el.parent().add(); + return this; + }; + /*\ + * Element.remove + [ method ] + ** + * Removes element from the DOM + = (Element) the detached element + \*/ + elproto.remove = function () { + var parent = this.parent(); + this.node.parentNode && this.node.parentNode.removeChild(this.node); + delete this.paper; + this.removed = true; + parent && parent.add(); + return this; + }; + /*\ + * Element.select + [ method ] + ** + * Gathers the nested @Element matching the given set of CSS selectors + ** + - query (string) CSS selector + = (Element) result of query selection + \*/ + elproto.select = function (query) { + query = Str(query).replace(/([^\\]):/g, "$1\\:"); + return wrap(this.node.querySelector(query)); + }; + /*\ + * Element.selectAll + [ method ] + ** + * Gathers nested @Element objects matching the given set of CSS selectors + ** + - query (string) CSS selector + = (Set|array) result of query selection + \*/ + elproto.selectAll = function (query) { + var nodelist = this.node.querySelectorAll(query), + set = (Snap.set || Array)(); + for (var i = 0; i < nodelist.length; i++) { + set.push(wrap(nodelist[i])); + } + return set; + }; + /*\ + * Element.asPX + [ method ] + ** + * Returns given attribute of the element as a `px` value (not %, em, etc.) + ** + - attr (string) attribute name + - value (string) #optional attribute value + = (Element) result of query selection + \*/ + elproto.asPX = function (attr, value) { + if (value == null) { + value = this.attr(attr); + } + return +unit2px(this, attr, value); + }; + // SIERRA Element.use(): I suggest adding a note about how to access the original element the returned <use> instantiates. It's a part of SVG with which ordinary web developers may be least familiar. + /*\ + * Element.use + [ method ] + ** + * Creates a `<use>` element linked to the current element + ** + = (Element) the `<use>` element + \*/ + elproto.use = function () { + var use, + id = this.node.id; + if (!id) { + id = this.id; + $(this.node, { + id: id + }); + } + if (this.type == "linearGradient" || this.type == "radialGradient" || + this.type == "pattern") { + use = make(this.type, this.node.parentNode); + } else { + use = make("use", this.node.parentNode); + } + $(use.node, { + "xlink:href": "#" + id + }); + use.original = this; + return use; + }; + function fixids(el) { + var els = el.selectAll("*"), + it, + url = /^\s*url\(("|'|)(.*)\1\)\s*$/, + ids = [], + uses = {}; + function urltest(it, name) { + var val = $(it.node, name); + val = val && val.match(url); + val = val && val[2]; + if (val && val.charAt() == "#") { + val = val.substring(1); + } else { + return; + } + if (val) { + uses[val] = (uses[val] || []).concat(function (id) { + var attr = {}; + attr[name] = URL(id); + $(it.node, attr); + }); + } + } + function linktest(it) { + var val = $(it.node, "xlink:href"); + if (val && val.charAt() == "#") { + val = val.substring(1); + } else { + return; + } + if (val) { + uses[val] = (uses[val] || []).concat(function (id) { + it.attr("xlink:href", "#" + id); + }); + } + } + for (var i = 0, ii = els.length; i < ii; i++) { + it = els[i]; + urltest(it, "fill"); + urltest(it, "stroke"); + urltest(it, "filter"); + urltest(it, "mask"); + urltest(it, "clip-path"); + linktest(it); + var oldid = $(it.node, "id"); + if (oldid) { + $(it.node, {id: it.id}); + ids.push({ + old: oldid, + id: it.id + }); + } + } + for (i = 0, ii = ids.length; i < ii; i++) { + var fs = uses[ids[i].old]; + if (fs) { + for (var j = 0, jj = fs.length; j < jj; j++) { + fs[j](ids[i].id); + } + } + } + } + /*\ + * Element.clone + [ method ] + ** + * Creates a clone of the element and inserts it after the element + ** + = (Element) the clone + \*/ + elproto.clone = function () { + var clone = wrap(this.node.cloneNode(true)); + if ($(clone.node, "id")) { + $(clone.node, {id: clone.id}); + } + fixids(clone); + clone.insertAfter(this); + return clone; + }; + /*\ + * Element.toDefs + [ method ] + ** + * Moves element to the shared `<defs>` area + ** + = (Element) the element + \*/ + elproto.toDefs = function () { + var defs = getSomeDefs(this); + defs.appendChild(this.node); + return this; + }; + /*\ + * Element.toPattern + [ method ] + ** + * Creates a `<pattern>` element from the current element + ** + * To create a pattern you have to specify the pattern rect: + - x (string|number) + - y (string|number) + - width (string|number) + - height (string|number) + = (Element) the `<pattern>` element + * You can use pattern later on as an argument for `fill` attribute: + | var p = paper.path("M10-5-10,15M15,0,0,15M0-5-20,15").attr({ + | fill: "none", + | stroke: "#bada55", + | strokeWidth: 5 + | }).pattern(0, 0, 10, 10), + | c = paper.circle(200, 200, 100); + | c.attr({ + | fill: p + | }); + \*/ + elproto.pattern = elproto.toPattern = function (x, y, width, height) { + var p = make("pattern", getSomeDefs(this)); + if (x == null) { + x = this.getBBox(); + } + if (is(x, "object") && "x" in x) { + y = x.y; + width = x.width; + height = x.height; + x = x.x; + } + $(p.node, { + x: x, + y: y, + width: width, + height: height, + patternUnits: "userSpaceOnUse", + id: p.id, + viewBox: [x, y, width, height].join(" ") + }); + p.node.appendChild(this.node); + return p; + }; +// SIERRA Element.marker(): clarify what a reference point is. E.g., helps you offset the object from its edge such as when centering it over a path. +// SIERRA Element.marker(): I suggest the method should accept default reference point values. Perhaps centered with (refX = width/2) and (refY = height/2)? Also, couldn't it assume the element's current _width_ and _height_? And please specify what _x_ and _y_ mean: offsets? If so, from where? Couldn't they also be assigned default values? + /*\ + * Element.marker + [ method ] + ** + * Creates a `<marker>` element from the current element + ** + * To create a marker you have to specify the bounding rect and reference point: + - x (number) + - y (number) + - width (number) + - height (number) + - refX (number) + - refY (number) + = (Element) the `<marker>` element + * You can specify the marker later as an argument for `marker-start`, `marker-end`, `marker-mid`, and `marker` attributes. The `marker` attribute places the marker at every point along the path, and `marker-mid` places them at every point except the start and end. + \*/ + // TODO add usage for markers + elproto.marker = function (x, y, width, height, refX, refY) { + var p = make("marker", getSomeDefs(this)); + if (x == null) { + x = this.getBBox(); + } + if (is(x, "object") && "x" in x) { + y = x.y; + width = x.width; + height = x.height; + refX = x.refX || x.cx; + refY = x.refY || x.cy; + x = x.x; + } + $(p.node, { + viewBox: [x, y, width, height].join(" "), + markerWidth: width, + markerHeight: height, + orient: "auto", + refX: refX || 0, + refY: refY || 0, + id: p.id + }); + p.node.appendChild(this.node); + return p; + }; + // animation + function slice(from, to, f) { + return function (arr) { + var res = arr.slice(from, to); + if (res.length == 1) { + res = res[0]; + } + return f ? f(res) : res; + }; + } + var Animation = function (attr, ms, easing, callback) { + if (typeof easing == "function" && !easing.length) { + callback = easing; + easing = mina.linear; + } + this.attr = attr; + this.dur = ms; + easing && (this.easing = easing); + callback && (this.callback = callback); + }; + Snap._.Animation = Animation; + /*\ + * Snap.animation + [ method ] + ** + * Creates an animation object + ** + - attr (object) attributes of final destination + - duration (number) duration of the animation, in milliseconds + - easing (function) #optional one of easing functions of @mina or custom one + - callback (function) #optional callback function that fires when animation ends + = (object) animation object + \*/ + Snap.animation = function (attr, ms, easing, callback) { + return new Animation(attr, ms, easing, callback); + }; + /*\ + * Element.inAnim + [ method ] + ** + * Returns a set of animations that may be able to manipulate the current element + ** + = (object) in format: + o { + o anim (object) animation object, + o mina (object) @mina object, + o curStatus (number) 0..1 — status of the animation: 0 — just started, 1 — just finished, + o status (function) gets or sets the status of the animation, + o stop (function) stops the animation + o } + \*/ + elproto.inAnim = function () { + var el = this, + res = []; + for (var id in el.anims) if (el.anims[has](id)) { + (function (a) { + res.push({ + anim: new Animation(a._attrs, a.dur, a.easing, a._callback), + mina: a, + curStatus: a.status(), + status: function (val) { + return a.status(val); + }, + stop: function () { + a.stop(); + } + }); + }(el.anims[id])); + } + return res; + }; + /*\ + * Snap.animate + [ method ] + ** + * Runs generic animation of one number into another with a caring function + ** + - from (number|array) number or array of numbers + - to (number|array) number or array of numbers + - setter (function) caring function that accepts one number argument + - duration (number) duration, in milliseconds + - easing (function) #optional easing function from @mina or custom + - callback (function) #optional callback function to execute when animation ends + = (object) animation object in @mina format + o { + o id (string) animation id, consider it read-only, + o duration (function) gets or sets the duration of the animation, + o easing (function) easing, + o speed (function) gets or sets the speed of the animation, + o status (function) gets or sets the status of the animation, + o stop (function) stops the animation + o } + | var rect = Snap().rect(0, 0, 10, 10); + | Snap.animate(0, 10, function (val) { + | rect.attr({ + | x: val + | }); + | }, 1000); + | // in given context is equivalent to + | rect.animate({x: 10}, 1000); + \*/ + Snap.animate = function (from, to, setter, ms, easing, callback) { + if (typeof easing == "function" && !easing.length) { + callback = easing; + easing = mina.linear; + } + var now = mina.time(), + anim = mina(from, to, now, now + ms, mina.time, setter, easing); + callback && eve.once("mina.finish." + anim.id, callback); + return anim; + }; + /*\ + * Element.stop + [ method ] + ** + * Stops all the animations for the current element + ** + = (Element) the current element + \*/ + elproto.stop = function () { + var anims = this.inAnim(); + for (var i = 0, ii = anims.length; i < ii; i++) { + anims[i].stop(); + } + return this; + }; + /*\ + * Element.animate + [ method ] + ** + * Animates the given attributes of the element + ** + - attrs (object) key-value pairs of destination attributes + - duration (number) duration of the animation in milliseconds + - easing (function) #optional easing function from @mina or custom + - callback (function) #optional callback function that executes when the animation ends + = (Element) the current element + \*/ + elproto.animate = function (attrs, ms, easing, callback) { + if (typeof easing == "function" && !easing.length) { + callback = easing; + easing = mina.linear; + } + if (attrs instanceof Animation) { + callback = attrs.callback; + easing = attrs.easing; + ms = easing.dur; + attrs = attrs.attr; + } + var fkeys = [], tkeys = [], keys = {}, from, to, f, eq, + el = this; + for (var key in attrs) if (attrs[has](key)) { + if (el.equal) { + eq = el.equal(key, Str(attrs[key])); + from = eq.from; + to = eq.to; + f = eq.f; + } else { + from = +el.attr(key); + to = +attrs[key]; + } + var len = is(from, "array") ? from.length : 1; + keys[key] = slice(fkeys.length, fkeys.length + len, f); + fkeys = fkeys.concat(from); + tkeys = tkeys.concat(to); + } + var now = mina.time(), + anim = mina(fkeys, tkeys, now, now + ms, mina.time, function (val) { + var attr = {}; + for (var key in keys) if (keys[has](key)) { + attr[key] = keys[key](val); + } + el.attr(attr); + }, easing); + el.anims[anim.id] = anim; + anim._attrs = attrs; + anim._callback = callback; + eve("snap.animcreated." + el.id, anim); + eve.once("mina.finish." + anim.id, function () { + delete el.anims[anim.id]; + callback && callback.call(el); + }); + eve.once("mina.stop." + anim.id, function () { + delete el.anims[anim.id]; + }); + return el; + }; + var eldata = {}; + /*\ + * Element.data + [ method ] + ** + * Adds or retrieves given value associated with given key. (Don’t confuse + * with `data-` attributes) + * + * See also @Element.removeData + - key (string) key to store data + - value (any) #optional value to store + = (object) @Element + * or, if value is not specified: + = (any) value + > Usage + | for (var i = 0, i < 5, i++) { + | paper.circle(10 + 15 * i, 10, 10) + | .attr({fill: "#000"}) + | .data("i", i) + | .click(function () { + | alert(this.data("i")); + | }); + | } + \*/ + elproto.data = function (key, value) { + var data = eldata[this.id] = eldata[this.id] || {}; + if (arguments.length == 0){ + eve("snap.data.get." + this.id, this, data, null); + return data; + } + if (arguments.length == 1) { + if (Snap.is(key, "object")) { + for (var i in key) if (key[has](i)) { + this.data(i, key[i]); + } + return this; + } + eve("snap.data.get." + this.id, this, data[key], key); + return data[key]; + } + data[key] = value; + eve("snap.data.set." + this.id, this, value, key); + return this; + }; + /*\ + * Element.removeData + [ method ] + ** + * Removes value associated with an element by given key. + * If key is not provided, removes all the data of the element. + - key (string) #optional key + = (object) @Element + \*/ + elproto.removeData = function (key) { + if (key == null) { + eldata[this.id] = {}; + } else { + eldata[this.id] && delete eldata[this.id][key]; + } + return this; + }; + /*\ + * Element.outerSVG + [ method ] + ** + * Returns SVG code for the element, equivalent to HTML's `outerHTML`. + * + * See also @Element.innerSVG + = (string) SVG code for the element + \*/ + /*\ + * Element.toString + [ method ] + ** + * See @Element.outerSVG + \*/ + elproto.outerSVG = elproto.toString = toString(1); + /*\ + * Element.innerSVG + [ method ] + ** + * Returns SVG code for the element's contents, equivalent to HTML's `innerHTML` + = (string) SVG code for the element + \*/ + elproto.innerSVG = toString(); + function toString(type) { + return function () { + var res = type ? "<" + this.type : "", + attr = this.node.attributes, + chld = this.node.childNodes; + if (type) { + for (var i = 0, ii = attr.length; i < ii; i++) { + res += " " + attr[i].name + '="' + + attr[i].value.replace(/"/g, '\\"') + '"'; + } + } + if (chld.length) { + type && (res += ">"); + for (i = 0, ii = chld.length; i < ii; i++) { + if (chld[i].nodeType == 3) { + res += chld[i].nodeValue; + } else if (chld[i].nodeType == 1) { + res += wrap(chld[i]).toString(); + } + } + type && (res += "</" + this.type + ">"); + } else { + type && (res += "/>"); + } + return res; + }; + } + elproto.toDataURL = function () { + if (window && window.btoa) { + var bb = this.getBBox(), + svg = Snap.format('<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" width="{width}" height="{height}" viewBox="{x} {y} {width} {height}">{contents}</svg>', { + x: +bb.x.toFixed(3), + y: +bb.y.toFixed(3), + width: +bb.width.toFixed(3), + height: +bb.height.toFixed(3), + contents: this.outerSVG() + }); + return "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(svg))); + } + }; + /*\ + * Fragment.select + [ method ] + ** + * See @Element.select + \*/ + Fragment.prototype.select = elproto.select; + /*\ + * Fragment.selectAll + [ method ] + ** + * See @Element.selectAll + \*/ + Fragment.prototype.selectAll = elproto.selectAll; +}); + +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +Snap.plugin(function (Snap, Element, Paper, glob, Fragment) { + var objectToString = Object.prototype.toString, + Str = String, + math = Math, + E = ""; + function Matrix(a, b, c, d, e, f) { + if (b == null && objectToString.call(a) == "[object SVGMatrix]") { + this.a = a.a; + this.b = a.b; + this.c = a.c; + this.d = a.d; + this.e = a.e; + this.f = a.f; + return; + } + if (a != null) { + this.a = +a; + this.b = +b; + this.c = +c; + this.d = +d; + this.e = +e; + this.f = +f; + } else { + this.a = 1; + this.b = 0; + this.c = 0; + this.d = 1; + this.e = 0; + this.f = 0; + } + } + (function (matrixproto) { + /*\ + * Matrix.add + [ method ] + ** + * Adds the given matrix to existing one + - a (number) + - b (number) + - c (number) + - d (number) + - e (number) + - f (number) + * or + - matrix (object) @Matrix + \*/ + matrixproto.add = function (a, b, c, d, e, f) { + var out = [[], [], []], + m = [[this.a, this.c, this.e], [this.b, this.d, this.f], [0, 0, 1]], + matrix = [[a, c, e], [b, d, f], [0, 0, 1]], + x, y, z, res; + + if (a && a instanceof Matrix) { + matrix = [[a.a, a.c, a.e], [a.b, a.d, a.f], [0, 0, 1]]; + } + + for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) { + res = 0; + for (z = 0; z < 3; z++) { + res += m[x][z] * matrix[z][y]; + } + out[x][y] = res; + } + } + this.a = out[0][0]; + this.b = out[1][0]; + this.c = out[0][1]; + this.d = out[1][1]; + this.e = out[0][2]; + this.f = out[1][2]; + return this; + }; + /*\ + * Matrix.invert + [ method ] + ** + * Returns an inverted version of the matrix + = (object) @Matrix + \*/ + matrixproto.invert = function () { + var me = this, + x = me.a * me.d - me.b * me.c; + return new Matrix(me.d / x, -me.b / x, -me.c / x, me.a / x, (me.c * me.f - me.d * me.e) / x, (me.b * me.e - me.a * me.f) / x); + }; + /*\ + * Matrix.clone + [ method ] + ** + * Returns a copy of the matrix + = (object) @Matrix + \*/ + matrixproto.clone = function () { + return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f); + }; + /*\ + * Matrix.translate + [ method ] + ** + * Translate the matrix + - x (number) horizontal offset distance + - y (number) vertical offset distance + \*/ + matrixproto.translate = function (x, y) { + return this.add(1, 0, 0, 1, x, y); + }; + /*\ + * Matrix.scale + [ method ] + ** + * Scales the matrix + - x (number) amount to be scaled, with `1` resulting in no change + - y (number) #optional amount to scale along the vertical axis. (Otherwise `x` applies to both axes.) + - cx (number) #optional horizontal origin point from which to scale + - cy (number) #optional vertical origin point from which to scale + * Default cx, cy is the middle point of the element. + \*/ + matrixproto.scale = function (x, y, cx, cy) { + y == null && (y = x); + (cx || cy) && this.add(1, 0, 0, 1, cx, cy); + this.add(x, 0, 0, y, 0, 0); + (cx || cy) && this.add(1, 0, 0, 1, -cx, -cy); + return this; + }; + /*\ + * Matrix.rotate + [ method ] + ** + * Rotates the matrix + - a (number) angle of rotation, in degrees + - x (number) horizontal origin point from which to rotate + - y (number) vertical origin point from which to rotate + \*/ + matrixproto.rotate = function (a, x, y) { + a = Snap.rad(a); + x = x || 0; + y = y || 0; + var cos = +math.cos(a).toFixed(9), + sin = +math.sin(a).toFixed(9); + this.add(cos, sin, -sin, cos, x, y); + return this.add(1, 0, 0, 1, -x, -y); + }; + /*\ + * Matrix.x + [ method ] + ** + * Returns x coordinate for given point after transformation described by the matrix. See also @Matrix.y + - x (number) + - y (number) + = (number) x + \*/ + matrixproto.x = function (x, y) { + return x * this.a + y * this.c + this.e; + }; + /*\ + * Matrix.y + [ method ] + ** + * Returns y coordinate for given point after transformation described by the matrix. See also @Matrix.x + - x (number) + - y (number) + = (number) y + \*/ + matrixproto.y = function (x, y) { + return x * this.b + y * this.d + this.f; + }; + matrixproto.get = function (i) { + return +this[Str.fromCharCode(97 + i)].toFixed(4); + }; + matrixproto.toString = function () { + return "matrix(" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)].join() + ")"; + }; + matrixproto.offset = function () { + return [this.e.toFixed(4), this.f.toFixed(4)]; + }; + function norm(a) { + return a[0] * a[0] + a[1] * a[1]; + } + function normalize(a) { + var mag = math.sqrt(norm(a)); + a[0] && (a[0] /= mag); + a[1] && (a[1] /= mag); + } + /*\ + * Matrix.determinant + [ method ] + ** + * Finds determinant of the given matrix. + = (number) determinant + \*/ + matrixproto.determinant = function () { + return this.a * this.d - this.b * this.c; + }; + /*\ + * Matrix.split + [ method ] + ** + * Splits matrix into primitive transformations + = (object) in format: + o dx (number) translation by x + o dy (number) translation by y + o scalex (number) scale by x + o scaley (number) scale by y + o shear (number) shear + o rotate (number) rotation in deg + o isSimple (boolean) could it be represented via simple transformations + \*/ + matrixproto.split = function () { + var out = {}; + // translation + out.dx = this.e; + out.dy = this.f; + + // scale and shear + var row = [[this.a, this.c], [this.b, this.d]]; + out.scalex = math.sqrt(norm(row[0])); + normalize(row[0]); + + out.shear = row[0][0] * row[1][0] + row[0][1] * row[1][1]; + row[1] = [row[1][0] - row[0][0] * out.shear, row[1][1] - row[0][1] * out.shear]; + + out.scaley = math.sqrt(norm(row[1])); + normalize(row[1]); + out.shear /= out.scaley; + + if (this.determinant() < 0) { + out.scalex = -out.scalex; + } + + // rotation + var sin = -row[0][1], + cos = row[1][1]; + if (cos < 0) { + out.rotate = Snap.deg(math.acos(cos)); + if (sin < 0) { + out.rotate = 360 - out.rotate; + } + } else { + out.rotate = Snap.deg(math.asin(sin)); + } + + out.isSimple = !+out.shear.toFixed(9) && (out.scalex.toFixed(9) == out.scaley.toFixed(9) || !out.rotate); + out.isSuperSimple = !+out.shear.toFixed(9) && out.scalex.toFixed(9) == out.scaley.toFixed(9) && !out.rotate; + out.noRotation = !+out.shear.toFixed(9) && !out.rotate; + return out; + }; + /*\ + * Matrix.toTransformString + [ method ] + ** + * Returns transform string that represents given matrix + = (string) transform string + \*/ + matrixproto.toTransformString = function (shorter) { + var s = shorter || this.split(); + if (!+s.shear.toFixed(9)) { + s.scalex = +s.scalex.toFixed(4); + s.scaley = +s.scaley.toFixed(4); + s.rotate = +s.rotate.toFixed(4); + return (s.dx || s.dy ? "t" + [+s.dx.toFixed(4), +s.dy.toFixed(4)] : E) + + (s.scalex != 1 || s.scaley != 1 ? "s" + [s.scalex, s.scaley, 0, 0] : E) + + (s.rotate ? "r" + [+s.rotate.toFixed(4), 0, 0] : E); + } else { + return "m" + [this.get(0), this.get(1), this.get(2), this.get(3), this.get(4), this.get(5)]; + } + }; + })(Matrix.prototype); + /*\ + * Snap.Matrix + [ method ] + ** + * Matrix constructor, extend on your own risk. + * To create matrices use @Snap.matrix. + \*/ + Snap.Matrix = Matrix; + /*\ + * Snap.matrix + [ method ] + ** + * Utility method + ** + * Returns a matrix based on the given parameters + - a (number) + - b (number) + - c (number) + - d (number) + - e (number) + - f (number) + * or + - svgMatrix (SVGMatrix) + = (object) @Matrix + \*/ + Snap.matrix = function (a, b, c, d, e, f) { + return new Matrix(a, b, c, d, e, f); + }; +}); +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +Snap.plugin(function (Snap, Element, Paper, glob, Fragment) { + var has = "hasOwnProperty", + make = Snap._.make, + wrap = Snap._.wrap, + is = Snap.is, + getSomeDefs = Snap._.getSomeDefs, + reURLValue = /^url\(#?([^)]+)\)$/, + $ = Snap._.$, + URL = Snap.url, + Str = String, + separator = Snap._.separator, + E = ""; + // Attributes event handlers + eve.on("snap.util.attr.mask", function (value) { + if (value instanceof Element || value instanceof Fragment) { + eve.stop(); + if (value instanceof Fragment && value.node.childNodes.length == 1) { + value = value.node.firstChild; + getSomeDefs(this).appendChild(value); + value = wrap(value); + } + if (value.type == "mask") { + var mask = value; + } else { + mask = make("mask", getSomeDefs(this)); + mask.node.appendChild(value.node); + } + !mask.node.id && $(mask.node, { + id: mask.id + }); + $(this.node, { + mask: URL(mask.id) + }); + } + }); + (function (clipIt) { + eve.on("snap.util.attr.clip", clipIt); + eve.on("snap.util.attr.clip-path", clipIt); + eve.on("snap.util.attr.clipPath", clipIt); + }(function (value) { + if (value instanceof Element || value instanceof Fragment) { + eve.stop(); + if (value.type == "clipPath") { + var clip = value; + } else { + clip = make("clipPath", getSomeDefs(this)); + clip.node.appendChild(value.node); + !clip.node.id && $(clip.node, { + id: clip.id + }); + } + $(this.node, { + "clip-path": URL(clip.node.id || clip.id) + }); + } + })); + function fillStroke(name) { + return function (value) { + eve.stop(); + if (value instanceof Fragment && value.node.childNodes.length == 1 && + (value.node.firstChild.tagName == "radialGradient" || + value.node.firstChild.tagName == "linearGradient" || + value.node.firstChild.tagName == "pattern")) { + value = value.node.firstChild; + getSomeDefs(this).appendChild(value); + value = wrap(value); + } + if (value instanceof Element) { + if (value.type == "radialGradient" || value.type == "linearGradient" + || value.type == "pattern") { + if (!value.node.id) { + $(value.node, { + id: value.id + }); + } + var fill = URL(value.node.id); + } else { + fill = value.attr(name); + } + } else { + fill = Snap.color(value); + if (fill.error) { + var grad = Snap(getSomeDefs(this).ownerSVGElement).gradient(value); + if (grad) { + if (!grad.node.id) { + $(grad.node, { + id: grad.id + }); + } + fill = URL(grad.node.id); + } else { + fill = value; + } + } else { + fill = Str(fill); + } + } + var attrs = {}; + attrs[name] = fill; + $(this.node, attrs); + this.node.style[name] = E; + }; + } + eve.on("snap.util.attr.fill", fillStroke("fill")); + eve.on("snap.util.attr.stroke", fillStroke("stroke")); + var gradrg = /^([lr])(?:\(([^)]*)\))?(.*)$/i; + eve.on("snap.util.grad.parse", function parseGrad(string) { + string = Str(string); + var tokens = string.match(gradrg); + if (!tokens) { + return null; + } + var type = tokens[1], + params = tokens[2], + stops = tokens[3]; + params = params.split(/\s*,\s*/).map(function (el) { + return +el == el ? +el : el; + }); + if (params.length == 1 && params[0] == 0) { + params = []; + } + stops = stops.split("-"); + stops = stops.map(function (el) { + el = el.split(":"); + var out = { + color: el[0] + }; + if (el[1]) { + out.offset = parseFloat(el[1]); + } + return out; + }); + return { + type: type, + params: params, + stops: stops + }; + }); + + eve.on("snap.util.attr.d", function (value) { + eve.stop(); + if (is(value, "array") && is(value[0], "array")) { + value = Snap.path.toString.call(value); + } + value = Str(value); + if (value.match(/[ruo]/i)) { + value = Snap.path.toAbsolute(value); + } + $(this.node, {d: value}); + })(-1); + eve.on("snap.util.attr.#text", function (value) { + eve.stop(); + value = Str(value); + var txt = glob.doc.createTextNode(value); + while (this.node.firstChild) { + this.node.removeChild(this.node.firstChild); + } + this.node.appendChild(txt); + })(-1); + eve.on("snap.util.attr.path", function (value) { + eve.stop(); + this.attr({d: value}); + })(-1); + eve.on("snap.util.attr.class", function (value) { + eve.stop(); + this.node.className.baseVal = value; + })(-1); + eve.on("snap.util.attr.viewBox", function (value) { + var vb; + if (is(value, "object") && "x" in value) { + vb = [value.x, value.y, value.width, value.height].join(" "); + } else if (is(value, "array")) { + vb = value.join(" "); + } else { + vb = value; + } + $(this.node, { + viewBox: vb + }); + eve.stop(); + })(-1); + eve.on("snap.util.attr.transform", function (value) { + this.transform(value); + eve.stop(); + })(-1); + eve.on("snap.util.attr.r", function (value) { + if (this.type == "rect") { + eve.stop(); + $(this.node, { + rx: value, + ry: value + }); + } + })(-1); + eve.on("snap.util.attr.textpath", function (value) { + eve.stop(); + if (this.type == "text") { + var id, tp, node; + if (!value && this.textPath) { + tp = this.textPath; + while (tp.node.firstChild) { + this.node.appendChild(tp.node.firstChild); + } + tp.remove(); + delete this.textPath; + return; + } + if (is(value, "string")) { + var defs = getSomeDefs(this), + path = wrap(defs.parentNode).path(value); + defs.appendChild(path.node); + id = path.id; + path.attr({id: id}); + } else { + value = wrap(value); + if (value instanceof Element) { + id = value.attr("id"); + if (!id) { + id = value.id; + value.attr({id: id}); + } + } + } + if (id) { + tp = this.textPath; + node = this.node; + if (tp) { + tp.attr({"xlink:href": "#" + id}); + } else { + tp = $("textPath", { + "xlink:href": "#" + id + }); + while (node.firstChild) { + tp.appendChild(node.firstChild); + } + node.appendChild(tp); + this.textPath = wrap(tp); + } + } + } + })(-1); + eve.on("snap.util.attr.text", function (value) { + if (this.type == "text") { + var i = 0, + node = this.node, + tuner = function (chunk) { + var out = $("tspan"); + if (is(chunk, "array")) { + for (var i = 0; i < chunk.length; i++) { + out.appendChild(tuner(chunk[i])); + } + } else { + out.appendChild(glob.doc.createTextNode(chunk)); + } + out.normalize && out.normalize(); + return out; + }; + while (node.firstChild) { + node.removeChild(node.firstChild); + } + var tuned = tuner(value); + while (tuned.firstChild) { + node.appendChild(tuned.firstChild); + } + } + eve.stop(); + })(-1); + function setFontSize(value) { + eve.stop(); + if (value == +value) { + value += "px"; + } + this.node.style.fontSize = value; + } + eve.on("snap.util.attr.fontSize", setFontSize)(-1); + eve.on("snap.util.attr.font-size", setFontSize)(-1); + + + eve.on("snap.util.getattr.transform", function () { + eve.stop(); + return this.transform(); + })(-1); + eve.on("snap.util.getattr.textpath", function () { + eve.stop(); + return this.textPath; + })(-1); + // Markers + (function () { + function getter(end) { + return function () { + eve.stop(); + var style = glob.doc.defaultView.getComputedStyle(this.node, null).getPropertyValue("marker-" + end); + if (style == "none") { + return style; + } else { + return Snap(glob.doc.getElementById(style.match(reURLValue)[1])); + } + }; + } + function setter(end) { + return function (value) { + eve.stop(); + var name = "marker" + end.charAt(0).toUpperCase() + end.substring(1); + if (value == "" || !value) { + this.node.style[name] = "none"; + return; + } + if (value.type == "marker") { + var id = value.node.id; + if (!id) { + $(value.node, {id: value.id}); + } + this.node.style[name] = URL(id); + return; + } + }; + } + eve.on("snap.util.getattr.marker-end", getter("end"))(-1); + eve.on("snap.util.getattr.markerEnd", getter("end"))(-1); + eve.on("snap.util.getattr.marker-start", getter("start"))(-1); + eve.on("snap.util.getattr.markerStart", getter("start"))(-1); + eve.on("snap.util.getattr.marker-mid", getter("mid"))(-1); + eve.on("snap.util.getattr.markerMid", getter("mid"))(-1); + eve.on("snap.util.attr.marker-end", setter("end"))(-1); + eve.on("snap.util.attr.markerEnd", setter("end"))(-1); + eve.on("snap.util.attr.marker-start", setter("start"))(-1); + eve.on("snap.util.attr.markerStart", setter("start"))(-1); + eve.on("snap.util.attr.marker-mid", setter("mid"))(-1); + eve.on("snap.util.attr.markerMid", setter("mid"))(-1); + }()); + eve.on("snap.util.getattr.r", function () { + if (this.type == "rect" && $(this.node, "rx") == $(this.node, "ry")) { + eve.stop(); + return $(this.node, "rx"); + } + })(-1); + function textExtract(node) { + var out = []; + var children = node.childNodes; + for (var i = 0, ii = children.length; i < ii; i++) { + var chi = children[i]; + if (chi.nodeType == 3) { + out.push(chi.nodeValue); + } + if (chi.tagName == "tspan") { + if (chi.childNodes.length == 1 && chi.firstChild.nodeType == 3) { + out.push(chi.firstChild.nodeValue); + } else { + out.push(textExtract(chi)); + } + } + } + return out; + } + eve.on("snap.util.getattr.text", function () { + if (this.type == "text" || this.type == "tspan") { + eve.stop(); + var out = textExtract(this.node); + return out.length == 1 ? out[0] : out; + } + })(-1); + eve.on("snap.util.getattr.#text", function () { + return this.node.textContent; + })(-1); + eve.on("snap.util.getattr.viewBox", function () { + eve.stop(); + var vb = $(this.node, "viewBox"); + if (vb) { + vb = vb.split(separator); + return Snap._.box(+vb[0], +vb[1], +vb[2], +vb[3]); + } else { + return; + } + })(-1); + eve.on("snap.util.getattr.points", function () { + var p = $(this.node, "points"); + eve.stop(); + if (p) { + return p.split(separator); + } else { + return; + } + })(-1); + eve.on("snap.util.getattr.path", function () { + var p = $(this.node, "d"); + eve.stop(); + return p; + })(-1); + eve.on("snap.util.getattr.class", function () { + return this.node.className.baseVal; + })(-1); + function getFontSize() { + eve.stop(); + return this.node.style.fontSize; + } + eve.on("snap.util.getattr.fontSize", getFontSize)(-1); + eve.on("snap.util.getattr.font-size", getFontSize)(-1); +}); + +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +Snap.plugin(function (Snap, Element, Paper, glob, Fragment) { + var proto = Paper.prototype, + is = Snap.is; + /*\ + * Paper.rect + [ method ] + * + * Draws a rectangle + ** + - x (number) x coordinate of the top left corner + - y (number) y coordinate of the top left corner + - width (number) width + - height (number) height + - rx (number) #optional horizontal radius for rounded corners, default is 0 + - ry (number) #optional vertical radius for rounded corners, default is rx or 0 + = (object) the `rect` element + ** + > Usage + | // regular rectangle + | var c = paper.rect(10, 10, 50, 50); + | // rectangle with rounded corners + | var c = paper.rect(40, 40, 50, 50, 10); + \*/ + proto.rect = function (x, y, w, h, rx, ry) { + var attr; + if (ry == null) { + ry = rx; + } + if (is(x, "object") && x == "[object Object]") { + attr = x; + } else if (x != null) { + attr = { + x: x, + y: y, + width: w, + height: h + }; + if (rx != null) { + attr.rx = rx; + attr.ry = ry; + } + } + return this.el("rect", attr); + }; + /*\ + * Paper.circle + [ method ] + ** + * Draws a circle + ** + - x (number) x coordinate of the centre + - y (number) y coordinate of the centre + - r (number) radius + = (object) the `circle` element + ** + > Usage + | var c = paper.circle(50, 50, 40); + \*/ + proto.circle = function (cx, cy, r) { + var attr; + if (is(cx, "object") && cx == "[object Object]") { + attr = cx; + } else if (cx != null) { + attr = { + cx: cx, + cy: cy, + r: r + }; + } + return this.el("circle", attr); + }; + + var preload = (function () { + function onerror() { + this.parentNode.removeChild(this); + } + return function (src, f) { + var img = glob.doc.createElement("img"), + body = glob.doc.body; + img.style.cssText = "position:absolute;left:-9999em;top:-9999em"; + img.onload = function () { + f.call(img); + img.onload = img.onerror = null; + body.removeChild(img); + }; + img.onerror = onerror; + body.appendChild(img); + img.src = src; + }; + }()); + + /*\ + * Paper.image + [ method ] + ** + * Places an image on the surface + ** + - src (string) URI of the source image + - x (number) x offset position + - y (number) y offset position + - width (number) width of the image + - height (number) height of the image + = (object) the `image` element + * or + = (object) Snap element object with type `image` + ** + > Usage + | var c = paper.image("apple.png", 10, 10, 80, 80); + \*/ + proto.image = function (src, x, y, width, height) { + var el = this.el("image"); + if (is(src, "object") && "src" in src) { + el.attr(src); + } else if (src != null) { + var set = { + "xlink:href": src, + preserveAspectRatio: "none" + }; + if (x != null && y != null) { + set.x = x; + set.y = y; + } + if (width != null && height != null) { + set.width = width; + set.height = height; + } else { + preload(src, function () { + Snap._.$(el.node, { + width: this.offsetWidth, + height: this.offsetHeight + }); + }); + } + Snap._.$(el.node, set); + } + return el; + }; + /*\ + * Paper.ellipse + [ method ] + ** + * Draws an ellipse + ** + - x (number) x coordinate of the centre + - y (number) y coordinate of the centre + - rx (number) horizontal radius + - ry (number) vertical radius + = (object) the `ellipse` element + ** + > Usage + | var c = paper.ellipse(50, 50, 40, 20); + \*/ + proto.ellipse = function (cx, cy, rx, ry) { + var attr; + if (is(cx, "object") && cx == "[object Object]") { + attr = cx; + } else if (cx != null) { + attr ={ + cx: cx, + cy: cy, + rx: rx, + ry: ry + }; + } + return this.el("ellipse", attr); + }; + // SIERRA Paper.path(): Unclear from the link what a Catmull-Rom curveto is, and why it would make life any easier. + /*\ + * Paper.path + [ method ] + ** + * Creates a `<path>` element using the given string as the path's definition + - pathString (string) #optional path string in SVG format + * Path string consists of one-letter commands, followed by comma seprarated arguments in numerical form. Example: + | "M10,20L30,40" + * This example features two commands: `M`, with arguments `(10, 20)` and `L` with arguments `(30, 40)`. Uppercase letter commands express coordinates in absolute terms, while lowercase commands express them in relative terms from the most recently declared coordinates. + * + # <p>Here is short list of commands available, for more details see <a href="http://www.w3.org/TR/SVG/paths.html#PathData" title="Details of a path's data attribute's format are described in the SVG specification.">SVG path string format</a> or <a href="https://developer.mozilla.org/en/SVG/Tutorial/Paths">article about path strings at MDN</a>.</p> + # <table><thead><tr><th>Command</th><th>Name</th><th>Parameters</th></tr></thead><tbody> + # <tr><td>M</td><td>moveto</td><td>(x y)+</td></tr> + # <tr><td>Z</td><td>closepath</td><td>(none)</td></tr> + # <tr><td>L</td><td>lineto</td><td>(x y)+</td></tr> + # <tr><td>H</td><td>horizontal lineto</td><td>x+</td></tr> + # <tr><td>V</td><td>vertical lineto</td><td>y+</td></tr> + # <tr><td>C</td><td>curveto</td><td>(x1 y1 x2 y2 x y)+</td></tr> + # <tr><td>S</td><td>smooth curveto</td><td>(x2 y2 x y)+</td></tr> + # <tr><td>Q</td><td>quadratic Bézier curveto</td><td>(x1 y1 x y)+</td></tr> + # <tr><td>T</td><td>smooth quadratic Bézier curveto</td><td>(x y)+</td></tr> + # <tr><td>A</td><td>elliptical arc</td><td>(rx ry x-axis-rotation large-arc-flag sweep-flag x y)+</td></tr> + # <tr><td>R</td><td><a href="http://en.wikipedia.org/wiki/Catmull–Rom_spline#Catmull.E2.80.93Rom_spline">Catmull-Rom curveto</a>*</td><td>x1 y1 (x y)+</td></tr></tbody></table> + * * _Catmull-Rom curveto_ is a not standard SVG command and added to make life easier. + * Note: there is a special case when a path consists of only three commands: `M10,10R…z`. In this case the path connects back to its starting point. + > Usage + | var c = paper.path("M10 10L90 90"); + | // draw a diagonal line: + | // move to 10,10, line to 90,90 + \*/ + proto.path = function (d) { + var attr; + if (is(d, "object") && !is(d, "array")) { + attr = d; + } else if (d) { + attr = {d: d}; + } + return this.el("path", attr); + }; + /*\ + * Paper.g + [ method ] + ** + * Creates a group element + ** + - varargs (…) #optional elements to nest within the group + = (object) the `g` element + ** + > Usage + | var c1 = paper.circle(), + | c2 = paper.rect(), + | g = paper.g(c2, c1); // note that the order of elements is different + * or + | var c1 = paper.circle(), + | c2 = paper.rect(), + | g = paper.g(); + | g.add(c2, c1); + \*/ + /*\ + * Paper.group + [ method ] + ** + * See @Paper.g + \*/ + proto.group = proto.g = function (first) { + var attr, + el = this.el("g"); + if (arguments.length == 1 && first && !first.type) { + el.attr(first); + } else if (arguments.length) { + el.add(Array.prototype.slice.call(arguments, 0)); + } + return el; + }; + /*\ + * Paper.svg + [ method ] + ** + * Creates a nested SVG element. + - x (number) @optional X of the element + - y (number) @optional Y of the element + - width (number) @optional width of the element + - height (number) @optional height of the element + - vbx (number) @optional viewbox X + - vby (number) @optional viewbox Y + - vbw (number) @optional viewbox width + - vbh (number) @optional viewbox height + ** + = (object) the `svg` element + ** + \*/ + proto.svg = function (x, y, width, height, vbx, vby, vbw, vbh) { + var attrs = {}; + if (is(x, "object") && y == null) { + attrs = x; + } else { + if (x != null) { + attrs.x = x; + } + if (y != null) { + attrs.y = y; + } + if (width != null) { + attrs.width = width; + } + if (height != null) { + attrs.height = height; + } + if (vbx != null && vby != null && vbw != null && vbh != null) { + attrs.viewBox = [vbx, vby, vbw, vbh]; + } + } + return this.el("svg", attrs); + }; + /*\ + * Paper.mask + [ method ] + ** + * Equivalent in behaviour to @Paper.g, except it’s a mask. + ** + = (object) the `mask` element + ** + \*/ + proto.mask = function (first) { + var attr, + el = this.el("mask"); + if (arguments.length == 1 && first && !first.type) { + el.attr(first); + } else if (arguments.length) { + el.add(Array.prototype.slice.call(arguments, 0)); + } + return el; + }; + /*\ + * Paper.ptrn + [ method ] + ** + * Equivalent in behaviour to @Paper.g, except it’s a pattern. + - x (number) @optional X of the element + - y (number) @optional Y of the element + - width (number) @optional width of the element + - height (number) @optional height of the element + - vbx (number) @optional viewbox X + - vby (number) @optional viewbox Y + - vbw (number) @optional viewbox width + - vbh (number) @optional viewbox height + ** + = (object) the `pattern` element + ** + \*/ + proto.ptrn = function (x, y, width, height, vx, vy, vw, vh) { + if (is(x, "object")) { + var attr = x; + } else { + attr = {patternUnits: "userSpaceOnUse"}; + if (x) { + attr.x = x; + } + if (y) { + attr.y = y; + } + if (width != null) { + attr.width = width; + } + if (height != null) { + attr.height = height; + } + if (vx != null && vy != null && vw != null && vh != null) { + attr.viewBox = [vx, vy, vw, vh]; + } + } + return this.el("pattern", attr); + }; + /*\ + * Paper.use + [ method ] + ** + * Creates a <use> element. + - id (string) @optional id of element to link + * or + - id (Element) @optional element to link + ** + = (object) the `use` element + ** + \*/ + proto.use = function (id) { + if (id != null) { + if (id instanceof Element) { + if (!id.attr("id")) { + id.attr({id: Snap._.id(id)}); + } + id = id.attr("id"); + } + if (String(id).charAt() == "#") { + id = id.substring(1); + } + return this.el("use", {"xlink:href": "#" + id}); + } else { + return Element.prototype.use.call(this); + } + }; + /*\ + * Paper.symbol + [ method ] + ** + * Creates a <symbol> element. + - vbx (number) @optional viewbox X + - vby (number) @optional viewbox Y + - vbw (number) @optional viewbox width + - vbh (number) @optional viewbox height + = (object) the `symbol` element + ** + \*/ + proto.symbol = function (vx, vy, vw, vh) { + var attr = {}; + if (vx != null && vy != null && vw != null && vh != null) { + attr.viewBox = [vx, vy, vw, vh]; + } + + return this.el("symbol", attr); + }; + /*\ + * Paper.text + [ method ] + ** + * Draws a text string + ** + - x (number) x coordinate position + - y (number) y coordinate position + - text (string|array) The text string to draw or array of strings to nest within separate `<tspan>` elements + = (object) the `text` element + ** + > Usage + | var t1 = paper.text(50, 50, "Snap"); + | var t2 = paper.text(50, 50, ["S","n","a","p"]); + | // Text path usage + | t1.attr({textpath: "M10,10L100,100"}); + | // or + | var pth = paper.path("M10,10L100,100"); + | t1.attr({textpath: pth}); + \*/ + proto.text = function (x, y, text) { + var attr = {}; + if (is(x, "object")) { + attr = x; + } else if (x != null) { + attr = { + x: x, + y: y, + text: text || "" + }; + } + return this.el("text", attr); + }; + /*\ + * Paper.line + [ method ] + ** + * Draws a line + ** + - x1 (number) x coordinate position of the start + - y1 (number) y coordinate position of the start + - x2 (number) x coordinate position of the end + - y2 (number) y coordinate position of the end + = (object) the `line` element + ** + > Usage + | var t1 = paper.line(50, 50, 100, 100); + \*/ + proto.line = function (x1, y1, x2, y2) { + var attr = {}; + if (is(x1, "object")) { + attr = x1; + } else if (x1 != null) { + attr = { + x1: x1, + x2: x2, + y1: y1, + y2: y2 + }; + } + return this.el("line", attr); + }; + /*\ + * Paper.polyline + [ method ] + ** + * Draws a polyline + ** + - points (array) array of points + * or + - varargs (…) points + = (object) the `polyline` element + ** + > Usage + | var p1 = paper.polyline([10, 10, 100, 100]); + | var p2 = paper.polyline(10, 10, 100, 100); + \*/ + proto.polyline = function (points) { + if (arguments.length > 1) { + points = Array.prototype.slice.call(arguments, 0); + } + var attr = {}; + if (is(points, "object") && !is(points, "array")) { + attr = points; + } else if (points != null) { + attr = {points: points}; + } + return this.el("polyline", attr); + }; + /*\ + * Paper.polygon + [ method ] + ** + * Draws a polygon. See @Paper.polyline + \*/ + proto.polygon = function (points) { + if (arguments.length > 1) { + points = Array.prototype.slice.call(arguments, 0); + } + var attr = {}; + if (is(points, "object") && !is(points, "array")) { + attr = points; + } else if (points != null) { + attr = {points: points}; + } + return this.el("polygon", attr); + }; + // gradients + (function () { + var $ = Snap._.$; + // gradients' helpers + function Gstops() { + return this.selectAll("stop"); + } + function GaddStop(color, offset) { + var stop = $("stop"), + attr = { + offset: +offset + "%" + }; + color = Snap.color(color); + attr["stop-color"] = color.hex; + if (color.opacity < 1) { + attr["stop-opacity"] = color.opacity; + } + $(stop, attr); + this.node.appendChild(stop); + return this; + } + function GgetBBox() { + if (this.type == "linearGradient") { + var x1 = $(this.node, "x1") || 0, + x2 = $(this.node, "x2") || 1, + y1 = $(this.node, "y1") || 0, + y2 = $(this.node, "y2") || 0; + return Snap._.box(x1, y1, math.abs(x2 - x1), math.abs(y2 - y1)); + } else { + var cx = this.node.cx || .5, + cy = this.node.cy || .5, + r = this.node.r || 0; + return Snap._.box(cx - r, cy - r, r * 2, r * 2); + } + } + function gradient(defs, str) { + var grad = eve("snap.util.grad.parse", null, str).firstDefined(), + el; + if (!grad) { + return null; + } + grad.params.unshift(defs); + if (grad.type.toLowerCase() == "l") { + el = gradientLinear.apply(0, grad.params); + } else { + el = gradientRadial.apply(0, grad.params); + } + if (grad.type != grad.type.toLowerCase()) { + $(el.node, { + gradientUnits: "userSpaceOnUse" + }); + } + var stops = grad.stops, + len = stops.length, + start = 0, + j = 0; + function seed(i, end) { + var step = (end - start) / (i - j); + for (var k = j; k < i; k++) { + stops[k].offset = +(+start + step * (k - j)).toFixed(2); + } + j = i; + start = end; + } + len--; + for (var i = 0; i < len; i++) if ("offset" in stops[i]) { + seed(i, stops[i].offset); + } + stops[len].offset = stops[len].offset || 100; + seed(len, stops[len].offset); + for (i = 0; i <= len; i++) { + var stop = stops[i]; + el.addStop(stop.color, stop.offset); + } + return el; + } + function gradientLinear(defs, x1, y1, x2, y2) { + var el = Snap._.make("linearGradient", defs); + el.stops = Gstops; + el.addStop = GaddStop; + el.getBBox = GgetBBox; + if (x1 != null) { + $(el.node, { + x1: x1, + y1: y1, + x2: x2, + y2: y2 + }); + } + return el; + } + function gradientRadial(defs, cx, cy, r, fx, fy) { + var el = Snap._.make("radialGradient", defs); + el.stops = Gstops; + el.addStop = GaddStop; + el.getBBox = GgetBBox; + if (cx != null) { + $(el.node, { + cx: cx, + cy: cy, + r: r + }); + } + if (fx != null && fy != null) { + $(el.node, { + fx: fx, + fy: fy + }); + } + return el; + } + /*\ + * Paper.gradient + [ method ] + ** + * Creates a gradient element + ** + - gradient (string) gradient descriptor + > Gradient Descriptor + * The gradient descriptor is an expression formatted as + * follows: `<type>(<coords>)<colors>`. The `<type>` can be + * either linear or radial. The uppercase `L` or `R` letters + * indicate absolute coordinates offset from the SVG surface. + * Lowercase `l` or `r` letters indicate coordinates + * calculated relative to the element to which the gradient is + * applied. Coordinates specify a linear gradient vector as + * `x1`, `y1`, `x2`, `y2`, or a radial gradient as `cx`, `cy`, + * `r` and optional `fx`, `fy` specifying a focal point away + * from the center of the circle. Specify `<colors>` as a list + * of dash-separated CSS color values. Each color may be + * followed by a custom offset value, separated with a colon + * character. + > Examples + * Linear gradient, relative from top-left corner to bottom-right + * corner, from black through red to white: + | var g = paper.gradient("l(0, 0, 1, 1)#000-#f00-#fff"); + * Linear gradient, absolute from (0, 0) to (100, 100), from black + * through red at 25% to white: + | var g = paper.gradient("L(0, 0, 100, 100)#000-#f00:25-#fff"); + * Radial gradient, relative from the center of the element with radius + * half the width, from black to white: + | var g = paper.gradient("r(0.5, 0.5, 0.5)#000-#fff"); + * To apply the gradient: + | paper.circle(50, 50, 40).attr({ + | fill: g + | }); + = (object) the `gradient` element + \*/ + proto.gradient = function (str) { + return gradient(this.defs, str); + }; + proto.gradientLinear = function (x1, y1, x2, y2) { + return gradientLinear(this.defs, x1, y1, x2, y2); + }; + proto.gradientRadial = function (cx, cy, r, fx, fy) { + return gradientRadial(this.defs, cx, cy, r, fx, fy); + }; + /*\ + * Paper.toString + [ method ] + ** + * Returns SVG code for the @Paper + = (string) SVG code for the @Paper + \*/ + proto.toString = function () { + var doc = this.node.ownerDocument, + f = doc.createDocumentFragment(), + d = doc.createElement("div"), + svg = this.node.cloneNode(true), + res; + f.appendChild(d); + d.appendChild(svg); + Snap._.$(svg, {xmlns: "http://www.w3.org/2000/svg"}); + res = d.innerHTML; + f.removeChild(f.firstChild); + return res; + }; + /*\ + * Paper.toDataURL + [ method ] + ** + * Returns SVG code for the @Paper as Data URI string. + = (string) Data URI string + \*/ + proto.toDataURL = function () { + if (window && window.btoa) { + return "data:image/svg+xml;base64," + btoa(unescape(encodeURIComponent(this))); + } + }; + /*\ + * Paper.clear + [ method ] + ** + * Removes all child nodes of the paper, except <defs>. + \*/ + proto.clear = function () { + var node = this.node.firstChild, + next; + while (node) { + next = node.nextSibling; + if (node.tagName != "defs") { + node.parentNode.removeChild(node); + } else { + proto.clear.call({node: node}); + } + node = next; + } + }; + }()); +}); + +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +Snap.plugin(function (Snap, Element, Paper, glob) { + var elproto = Element.prototype, + is = Snap.is, + clone = Snap._.clone, + has = "hasOwnProperty", + p2s = /,?([a-z]),?/gi, + toFloat = parseFloat, + math = Math, + PI = math.PI, + mmin = math.min, + mmax = math.max, + pow = math.pow, + abs = math.abs; + function paths(ps) { + var p = paths.ps = paths.ps || {}; + if (p[ps]) { + p[ps].sleep = 100; + } else { + p[ps] = { + sleep: 100 + }; + } + setTimeout(function () { + for (var key in p) if (p[has](key) && key != ps) { + p[key].sleep--; + !p[key].sleep && delete p[key]; + } + }); + return p[ps]; + } + function box(x, y, width, height) { + if (x == null) { + x = y = width = height = 0; + } + if (y == null) { + y = x.y; + width = x.width; + height = x.height; + x = x.x; + } + return { + x: x, + y: y, + width: width, + w: width, + height: height, + h: height, + x2: x + width, + y2: y + height, + cx: x + width / 2, + cy: y + height / 2, + r1: math.min(width, height) / 2, + r2: math.max(width, height) / 2, + r0: math.sqrt(width * width + height * height) / 2, + path: rectPath(x, y, width, height), + vb: [x, y, width, height].join(" ") + }; + } + function toString() { + return this.join(",").replace(p2s, "$1"); + } + function pathClone(pathArray) { + var res = clone(pathArray); + res.toString = toString; + return res; + } + function getPointAtSegmentLength(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length) { + if (length == null) { + return bezlen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y); + } else { + return findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, + getTotLen(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, length)); + } + } + function getLengthFactory(istotal, subpath) { + function O(val) { + return +(+val).toFixed(3); + } + return Snap._.cacher(function (path, length, onlystart) { + if (path instanceof Element) { + path = path.attr("d"); + } + path = path2curve(path); + var x, y, p, l, sp = "", subpaths = {}, point, + len = 0; + for (var i = 0, ii = path.length; i < ii; i++) { + p = path[i]; + if (p[0] == "M") { + x = +p[1]; + y = +p[2]; + } else { + l = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6]); + if (len + l > length) { + if (subpath && !subpaths.start) { + point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len); + sp += [ + "C" + O(point.start.x), + O(point.start.y), + O(point.m.x), + O(point.m.y), + O(point.x), + O(point.y) + ]; + if (onlystart) {return sp;} + subpaths.start = sp; + sp = [ + "M" + O(point.x), + O(point.y) + "C" + O(point.n.x), + O(point.n.y), + O(point.end.x), + O(point.end.y), + O(p[5]), + O(p[6]) + ].join(); + len += l; + x = +p[5]; + y = +p[6]; + continue; + } + if (!istotal && !subpath) { + point = getPointAtSegmentLength(x, y, p[1], p[2], p[3], p[4], p[5], p[6], length - len); + return point; + } + } + len += l; + x = +p[5]; + y = +p[6]; + } + sp += p.shift() + p; + } + subpaths.end = sp; + point = istotal ? len : subpath ? subpaths : findDotsAtSegment(x, y, p[0], p[1], p[2], p[3], p[4], p[5], 1); + return point; + }, null, Snap._.clone); + } + var getTotalLength = getLengthFactory(1), + getPointAtLength = getLengthFactory(), + getSubpathsAtLength = getLengthFactory(0, 1); + function findDotsAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) { + var t1 = 1 - t, + t13 = pow(t1, 3), + t12 = pow(t1, 2), + t2 = t * t, + t3 = t2 * t, + x = t13 * p1x + t12 * 3 * t * c1x + t1 * 3 * t * t * c2x + t3 * p2x, + y = t13 * p1y + t12 * 3 * t * c1y + t1 * 3 * t * t * c2y + t3 * p2y, + mx = p1x + 2 * t * (c1x - p1x) + t2 * (c2x - 2 * c1x + p1x), + my = p1y + 2 * t * (c1y - p1y) + t2 * (c2y - 2 * c1y + p1y), + nx = c1x + 2 * t * (c2x - c1x) + t2 * (p2x - 2 * c2x + c1x), + ny = c1y + 2 * t * (c2y - c1y) + t2 * (p2y - 2 * c2y + c1y), + ax = t1 * p1x + t * c1x, + ay = t1 * p1y + t * c1y, + cx = t1 * c2x + t * p2x, + cy = t1 * c2y + t * p2y, + alpha = (90 - math.atan2(mx - nx, my - ny) * 180 / PI); + // (mx > nx || my < ny) && (alpha += 180); + return { + x: x, + y: y, + m: {x: mx, y: my}, + n: {x: nx, y: ny}, + start: {x: ax, y: ay}, + end: {x: cx, y: cy}, + alpha: alpha + }; + } + function bezierBBox(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y) { + if (!Snap.is(p1x, "array")) { + p1x = [p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y]; + } + var bbox = curveDim.apply(null, p1x); + return box( + bbox.min.x, + bbox.min.y, + bbox.max.x - bbox.min.x, + bbox.max.y - bbox.min.y + ); + } + function isPointInsideBBox(bbox, x, y) { + return x >= bbox.x && + x <= bbox.x + bbox.width && + y >= bbox.y && + y <= bbox.y + bbox.height; + } + function isBBoxIntersect(bbox1, bbox2) { + bbox1 = box(bbox1); + bbox2 = box(bbox2); + return isPointInsideBBox(bbox2, bbox1.x, bbox1.y) + || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y) + || isPointInsideBBox(bbox2, bbox1.x, bbox1.y2) + || isPointInsideBBox(bbox2, bbox1.x2, bbox1.y2) + || isPointInsideBBox(bbox1, bbox2.x, bbox2.y) + || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y) + || isPointInsideBBox(bbox1, bbox2.x, bbox2.y2) + || isPointInsideBBox(bbox1, bbox2.x2, bbox2.y2) + || (bbox1.x < bbox2.x2 && bbox1.x > bbox2.x + || bbox2.x < bbox1.x2 && bbox2.x > bbox1.x) + && (bbox1.y < bbox2.y2 && bbox1.y > bbox2.y + || bbox2.y < bbox1.y2 && bbox2.y > bbox1.y); + } + function base3(t, p1, p2, p3, p4) { + var t1 = -3 * p1 + 9 * p2 - 9 * p3 + 3 * p4, + t2 = t * t1 + 6 * p1 - 12 * p2 + 6 * p3; + return t * t2 - 3 * p1 + 3 * p2; + } + function bezlen(x1, y1, x2, y2, x3, y3, x4, y4, z) { + if (z == null) { + z = 1; + } + z = z > 1 ? 1 : z < 0 ? 0 : z; + var z2 = z / 2, + n = 12, + Tvalues = [-.1252,.1252,-.3678,.3678,-.5873,.5873,-.7699,.7699,-.9041,.9041,-.9816,.9816], + Cvalues = [0.2491,0.2491,0.2335,0.2335,0.2032,0.2032,0.1601,0.1601,0.1069,0.1069,0.0472,0.0472], + sum = 0; + for (var i = 0; i < n; i++) { + var ct = z2 * Tvalues[i] + z2, + xbase = base3(ct, x1, x2, x3, x4), + ybase = base3(ct, y1, y2, y3, y4), + comb = xbase * xbase + ybase * ybase; + sum += Cvalues[i] * math.sqrt(comb); + } + return z2 * sum; + } + function getTotLen(x1, y1, x2, y2, x3, y3, x4, y4, ll) { + if (ll < 0 || bezlen(x1, y1, x2, y2, x3, y3, x4, y4) < ll) { + return; + } + var t = 1, + step = t / 2, + t2 = t - step, + l, + e = .01; + l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2); + while (abs(l - ll) > e) { + step /= 2; + t2 += (l < ll ? 1 : -1) * step; + l = bezlen(x1, y1, x2, y2, x3, y3, x4, y4, t2); + } + return t2; + } + function intersect(x1, y1, x2, y2, x3, y3, x4, y4) { + if ( + mmax(x1, x2) < mmin(x3, x4) || + mmin(x1, x2) > mmax(x3, x4) || + mmax(y1, y2) < mmin(y3, y4) || + mmin(y1, y2) > mmax(y3, y4) + ) { + return; + } + var nx = (x1 * y2 - y1 * x2) * (x3 - x4) - (x1 - x2) * (x3 * y4 - y3 * x4), + ny = (x1 * y2 - y1 * x2) * (y3 - y4) - (y1 - y2) * (x3 * y4 - y3 * x4), + denominator = (x1 - x2) * (y3 - y4) - (y1 - y2) * (x3 - x4); + + if (!denominator) { + return; + } + var px = nx / denominator, + py = ny / denominator, + px2 = +px.toFixed(2), + py2 = +py.toFixed(2); + if ( + px2 < +mmin(x1, x2).toFixed(2) || + px2 > +mmax(x1, x2).toFixed(2) || + px2 < +mmin(x3, x4).toFixed(2) || + px2 > +mmax(x3, x4).toFixed(2) || + py2 < +mmin(y1, y2).toFixed(2) || + py2 > +mmax(y1, y2).toFixed(2) || + py2 < +mmin(y3, y4).toFixed(2) || + py2 > +mmax(y3, y4).toFixed(2) + ) { + return; + } + return {x: px, y: py}; + } + function inter(bez1, bez2) { + return interHelper(bez1, bez2); + } + function interCount(bez1, bez2) { + return interHelper(bez1, bez2, 1); + } + function interHelper(bez1, bez2, justCount) { + var bbox1 = bezierBBox(bez1), + bbox2 = bezierBBox(bez2); + if (!isBBoxIntersect(bbox1, bbox2)) { + return justCount ? 0 : []; + } + var l1 = bezlen.apply(0, bez1), + l2 = bezlen.apply(0, bez2), + n1 = ~~(l1 / 8), + n2 = ~~(l2 / 8), + dots1 = [], + dots2 = [], + xy = {}, + res = justCount ? 0 : []; + for (var i = 0; i < n1 + 1; i++) { + var p = findDotsAtSegment.apply(0, bez1.concat(i / n1)); + dots1.push({x: p.x, y: p.y, t: i / n1}); + } + for (i = 0; i < n2 + 1; i++) { + p = findDotsAtSegment.apply(0, bez2.concat(i / n2)); + dots2.push({x: p.x, y: p.y, t: i / n2}); + } + for (i = 0; i < n1; i++) { + for (var j = 0; j < n2; j++) { + var di = dots1[i], + di1 = dots1[i + 1], + dj = dots2[j], + dj1 = dots2[j + 1], + ci = abs(di1.x - di.x) < .001 ? "y" : "x", + cj = abs(dj1.x - dj.x) < .001 ? "y" : "x", + is = intersect(di.x, di.y, di1.x, di1.y, dj.x, dj.y, dj1.x, dj1.y); + if (is) { + if (xy[is.x.toFixed(4)] == is.y.toFixed(4)) { + continue; + } + xy[is.x.toFixed(4)] = is.y.toFixed(4); + var t1 = di.t + abs((is[ci] - di[ci]) / (di1[ci] - di[ci])) * (di1.t - di.t), + t2 = dj.t + abs((is[cj] - dj[cj]) / (dj1[cj] - dj[cj])) * (dj1.t - dj.t); + if (t1 >= 0 && t1 <= 1 && t2 >= 0 && t2 <= 1) { + if (justCount) { + res++; + } else { + res.push({ + x: is.x, + y: is.y, + t1: t1, + t2: t2 + }); + } + } + } + } + } + return res; + } + function pathIntersection(path1, path2) { + return interPathHelper(path1, path2); + } + function pathIntersectionNumber(path1, path2) { + return interPathHelper(path1, path2, 1); + } + function interPathHelper(path1, path2, justCount) { + path1 = path2curve(path1); + path2 = path2curve(path2); + var x1, y1, x2, y2, x1m, y1m, x2m, y2m, bez1, bez2, + res = justCount ? 0 : []; + for (var i = 0, ii = path1.length; i < ii; i++) { + var pi = path1[i]; + if (pi[0] == "M") { + x1 = x1m = pi[1]; + y1 = y1m = pi[2]; + } else { + if (pi[0] == "C") { + bez1 = [x1, y1].concat(pi.slice(1)); + x1 = bez1[6]; + y1 = bez1[7]; + } else { + bez1 = [x1, y1, x1, y1, x1m, y1m, x1m, y1m]; + x1 = x1m; + y1 = y1m; + } + for (var j = 0, jj = path2.length; j < jj; j++) { + var pj = path2[j]; + if (pj[0] == "M") { + x2 = x2m = pj[1]; + y2 = y2m = pj[2]; + } else { + if (pj[0] == "C") { + bez2 = [x2, y2].concat(pj.slice(1)); + x2 = bez2[6]; + y2 = bez2[7]; + } else { + bez2 = [x2, y2, x2, y2, x2m, y2m, x2m, y2m]; + x2 = x2m; + y2 = y2m; + } + var intr = interHelper(bez1, bez2, justCount); + if (justCount) { + res += intr; + } else { + for (var k = 0, kk = intr.length; k < kk; k++) { + intr[k].segment1 = i; + intr[k].segment2 = j; + intr[k].bez1 = bez1; + intr[k].bez2 = bez2; + } + res = res.concat(intr); + } + } + } + } + } + return res; + } + function isPointInsidePath(path, x, y) { + var bbox = pathBBox(path); + return isPointInsideBBox(bbox, x, y) && + interPathHelper(path, [["M", x, y], ["H", bbox.x2 + 10]], 1) % 2 == 1; + } + function pathBBox(path) { + var pth = paths(path); + if (pth.bbox) { + return clone(pth.bbox); + } + if (!path) { + return box(); + } + path = path2curve(path); + var x = 0, + y = 0, + X = [], + Y = [], + p; + for (var i = 0, ii = path.length; i < ii; i++) { + p = path[i]; + if (p[0] == "M") { + x = p[1]; + y = p[2]; + X.push(x); + Y.push(y); + } else { + var dim = curveDim(x, y, p[1], p[2], p[3], p[4], p[5], p[6]); + X = X.concat(dim.min.x, dim.max.x); + Y = Y.concat(dim.min.y, dim.max.y); + x = p[5]; + y = p[6]; + } + } + var xmin = mmin.apply(0, X), + ymin = mmin.apply(0, Y), + xmax = mmax.apply(0, X), + ymax = mmax.apply(0, Y), + bb = box(xmin, ymin, xmax - xmin, ymax - ymin); + pth.bbox = clone(bb); + return bb; + } + function rectPath(x, y, w, h, r) { + if (r) { + return [ + ["M", +x + (+r), y], + ["l", w - r * 2, 0], + ["a", r, r, 0, 0, 1, r, r], + ["l", 0, h - r * 2], + ["a", r, r, 0, 0, 1, -r, r], + ["l", r * 2 - w, 0], + ["a", r, r, 0, 0, 1, -r, -r], + ["l", 0, r * 2 - h], + ["a", r, r, 0, 0, 1, r, -r], + ["z"] + ]; + } + var res = [["M", x, y], ["l", w, 0], ["l", 0, h], ["l", -w, 0], ["z"]]; + res.toString = toString; + return res; + } + function ellipsePath(x, y, rx, ry, a) { + if (a == null && ry == null) { + ry = rx; + } + x = +x; + y = +y; + rx = +rx; + ry = +ry; + if (a != null) { + var rad = Math.PI / 180, + x1 = x + rx * Math.cos(-ry * rad), + x2 = x + rx * Math.cos(-a * rad), + y1 = y + rx * Math.sin(-ry * rad), + y2 = y + rx * Math.sin(-a * rad), + res = [["M", x1, y1], ["A", rx, rx, 0, +(a - ry > 180), 0, x2, y2]]; + } else { + res = [ + ["M", x, y], + ["m", 0, -ry], + ["a", rx, ry, 0, 1, 1, 0, 2 * ry], + ["a", rx, ry, 0, 1, 1, 0, -2 * ry], + ["z"] + ]; + } + res.toString = toString; + return res; + } + var unit2px = Snap._unit2px, + getPath = { + path: function (el) { + return el.attr("path"); + }, + circle: function (el) { + var attr = unit2px(el); + return ellipsePath(attr.cx, attr.cy, attr.r); + }, + ellipse: function (el) { + var attr = unit2px(el); + return ellipsePath(attr.cx || 0, attr.cy || 0, attr.rx, attr.ry); + }, + rect: function (el) { + var attr = unit2px(el); + return rectPath(attr.x || 0, attr.y || 0, attr.width, attr.height, attr.rx, attr.ry); + }, + image: function (el) { + var attr = unit2px(el); + return rectPath(attr.x || 0, attr.y || 0, attr.width, attr.height); + }, + line: function (el) { + return "M" + [el.attr("x1") || 0, el.attr("y1") || 0, el.attr("x2"), el.attr("y2")]; + }, + polyline: function (el) { + return "M" + el.attr("points"); + }, + polygon: function (el) { + return "M" + el.attr("points") + "z"; + }, + deflt: function (el) { + var bbox = el.node.getBBox(); + return rectPath(bbox.x, bbox.y, bbox.width, bbox.height); + } + }; + function pathToRelative(pathArray) { + var pth = paths(pathArray), + lowerCase = String.prototype.toLowerCase; + if (pth.rel) { + return pathClone(pth.rel); + } + if (!Snap.is(pathArray, "array") || !Snap.is(pathArray && pathArray[0], "array")) { + pathArray = Snap.parsePathString(pathArray); + } + var res = [], + x = 0, + y = 0, + mx = 0, + my = 0, + start = 0; + if (pathArray[0][0] == "M") { + x = pathArray[0][1]; + y = pathArray[0][2]; + mx = x; + my = y; + start++; + res.push(["M", x, y]); + } + for (var i = start, ii = pathArray.length; i < ii; i++) { + var r = res[i] = [], + pa = pathArray[i]; + if (pa[0] != lowerCase.call(pa[0])) { + r[0] = lowerCase.call(pa[0]); + switch (r[0]) { + case "a": + r[1] = pa[1]; + r[2] = pa[2]; + r[3] = pa[3]; + r[4] = pa[4]; + r[5] = pa[5]; + r[6] = +(pa[6] - x).toFixed(3); + r[7] = +(pa[7] - y).toFixed(3); + break; + case "v": + r[1] = +(pa[1] - y).toFixed(3); + break; + case "m": + mx = pa[1]; + my = pa[2]; + default: + for (var j = 1, jj = pa.length; j < jj; j++) { + r[j] = +(pa[j] - ((j % 2) ? x : y)).toFixed(3); + } + } + } else { + r = res[i] = []; + if (pa[0] == "m") { + mx = pa[1] + x; + my = pa[2] + y; + } + for (var k = 0, kk = pa.length; k < kk; k++) { + res[i][k] = pa[k]; + } + } + var len = res[i].length; + switch (res[i][0]) { + case "z": + x = mx; + y = my; + break; + case "h": + x += +res[i][len - 1]; + break; + case "v": + y += +res[i][len - 1]; + break; + default: + x += +res[i][len - 2]; + y += +res[i][len - 1]; + } + } + res.toString = toString; + pth.rel = pathClone(res); + return res; + } + function pathToAbsolute(pathArray) { + var pth = paths(pathArray); + if (pth.abs) { + return pathClone(pth.abs); + } + if (!is(pathArray, "array") || !is(pathArray && pathArray[0], "array")) { // rough assumption + pathArray = Snap.parsePathString(pathArray); + } + if (!pathArray || !pathArray.length) { + return [["M", 0, 0]]; + } + var res = [], + x = 0, + y = 0, + mx = 0, + my = 0, + start = 0, + pa0; + if (pathArray[0][0] == "M") { + x = +pathArray[0][1]; + y = +pathArray[0][2]; + mx = x; + my = y; + start++; + res[0] = ["M", x, y]; + } + var crz = pathArray.length == 3 && + pathArray[0][0] == "M" && + pathArray[1][0].toUpperCase() == "R" && + pathArray[2][0].toUpperCase() == "Z"; + for (var r, pa, i = start, ii = pathArray.length; i < ii; i++) { + res.push(r = []); + pa = pathArray[i]; + pa0 = pa[0]; + if (pa0 != pa0.toUpperCase()) { + r[0] = pa0.toUpperCase(); + switch (r[0]) { + case "A": + r[1] = pa[1]; + r[2] = pa[2]; + r[3] = pa[3]; + r[4] = pa[4]; + r[5] = pa[5]; + r[6] = +pa[6] + x; + r[7] = +pa[7] + y; + break; + case "V": + r[1] = +pa[1] + y; + break; + case "H": + r[1] = +pa[1] + x; + break; + case "R": + var dots = [x, y].concat(pa.slice(1)); + for (var j = 2, jj = dots.length; j < jj; j++) { + dots[j] = +dots[j] + x; + dots[++j] = +dots[j] + y; + } + res.pop(); + res = res.concat(catmullRom2bezier(dots, crz)); + break; + case "O": + res.pop(); + dots = ellipsePath(x, y, pa[1], pa[2]); + dots.push(dots[0]); + res = res.concat(dots); + break; + case "U": + res.pop(); + res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3])); + r = ["U"].concat(res[res.length - 1].slice(-2)); + break; + case "M": + mx = +pa[1] + x; + my = +pa[2] + y; + default: + for (j = 1, jj = pa.length; j < jj; j++) { + r[j] = +pa[j] + ((j % 2) ? x : y); + } + } + } else if (pa0 == "R") { + dots = [x, y].concat(pa.slice(1)); + res.pop(); + res = res.concat(catmullRom2bezier(dots, crz)); + r = ["R"].concat(pa.slice(-2)); + } else if (pa0 == "O") { + res.pop(); + dots = ellipsePath(x, y, pa[1], pa[2]); + dots.push(dots[0]); + res = res.concat(dots); + } else if (pa0 == "U") { + res.pop(); + res = res.concat(ellipsePath(x, y, pa[1], pa[2], pa[3])); + r = ["U"].concat(res[res.length - 1].slice(-2)); + } else { + for (var k = 0, kk = pa.length; k < kk; k++) { + r[k] = pa[k]; + } + } + pa0 = pa0.toUpperCase(); + if (pa0 != "O") { + switch (r[0]) { + case "Z": + x = +mx; + y = +my; + break; + case "H": + x = r[1]; + break; + case "V": + y = r[1]; + break; + case "M": + mx = r[r.length - 2]; + my = r[r.length - 1]; + default: + x = r[r.length - 2]; + y = r[r.length - 1]; + } + } + } + res.toString = toString; + pth.abs = pathClone(res); + return res; + } + function l2c(x1, y1, x2, y2) { + return [x1, y1, x2, y2, x2, y2]; + } + function q2c(x1, y1, ax, ay, x2, y2) { + var _13 = 1 / 3, + _23 = 2 / 3; + return [ + _13 * x1 + _23 * ax, + _13 * y1 + _23 * ay, + _13 * x2 + _23 * ax, + _13 * y2 + _23 * ay, + x2, + y2 + ]; + } + function a2c(x1, y1, rx, ry, angle, large_arc_flag, sweep_flag, x2, y2, recursive) { + // for more information of where this math came from visit: + // http://www.w3.org/TR/SVG11/implnote.html#ArcImplementationNotes + var _120 = PI * 120 / 180, + rad = PI / 180 * (+angle || 0), + res = [], + xy, + rotate = Snap._.cacher(function (x, y, rad) { + var X = x * math.cos(rad) - y * math.sin(rad), + Y = x * math.sin(rad) + y * math.cos(rad); + return {x: X, y: Y}; + }); + if (!recursive) { + xy = rotate(x1, y1, -rad); + x1 = xy.x; + y1 = xy.y; + xy = rotate(x2, y2, -rad); + x2 = xy.x; + y2 = xy.y; + var cos = math.cos(PI / 180 * angle), + sin = math.sin(PI / 180 * angle), + x = (x1 - x2) / 2, + y = (y1 - y2) / 2; + var h = (x * x) / (rx * rx) + (y * y) / (ry * ry); + if (h > 1) { + h = math.sqrt(h); + rx = h * rx; + ry = h * ry; + } + var rx2 = rx * rx, + ry2 = ry * ry, + k = (large_arc_flag == sweep_flag ? -1 : 1) * + math.sqrt(abs((rx2 * ry2 - rx2 * y * y - ry2 * x * x) / (rx2 * y * y + ry2 * x * x))), + cx = k * rx * y / ry + (x1 + x2) / 2, + cy = k * -ry * x / rx + (y1 + y2) / 2, + f1 = math.asin(((y1 - cy) / ry).toFixed(9)), + f2 = math.asin(((y2 - cy) / ry).toFixed(9)); + + f1 = x1 < cx ? PI - f1 : f1; + f2 = x2 < cx ? PI - f2 : f2; + f1 < 0 && (f1 = PI * 2 + f1); + f2 < 0 && (f2 = PI * 2 + f2); + if (sweep_flag && f1 > f2) { + f1 = f1 - PI * 2; + } + if (!sweep_flag && f2 > f1) { + f2 = f2 - PI * 2; + } + } else { + f1 = recursive[0]; + f2 = recursive[1]; + cx = recursive[2]; + cy = recursive[3]; + } + var df = f2 - f1; + if (abs(df) > _120) { + var f2old = f2, + x2old = x2, + y2old = y2; + f2 = f1 + _120 * (sweep_flag && f2 > f1 ? 1 : -1); + x2 = cx + rx * math.cos(f2); + y2 = cy + ry * math.sin(f2); + res = a2c(x2, y2, rx, ry, angle, 0, sweep_flag, x2old, y2old, [f2, f2old, cx, cy]); + } + df = f2 - f1; + var c1 = math.cos(f1), + s1 = math.sin(f1), + c2 = math.cos(f2), + s2 = math.sin(f2), + t = math.tan(df / 4), + hx = 4 / 3 * rx * t, + hy = 4 / 3 * ry * t, + m1 = [x1, y1], + m2 = [x1 + hx * s1, y1 - hy * c1], + m3 = [x2 + hx * s2, y2 - hy * c2], + m4 = [x2, y2]; + m2[0] = 2 * m1[0] - m2[0]; + m2[1] = 2 * m1[1] - m2[1]; + if (recursive) { + return [m2, m3, m4].concat(res); + } else { + res = [m2, m3, m4].concat(res).join().split(","); + var newres = []; + for (var i = 0, ii = res.length; i < ii; i++) { + newres[i] = i % 2 ? rotate(res[i - 1], res[i], rad).y : rotate(res[i], res[i + 1], rad).x; + } + return newres; + } + } + function findDotAtSegment(p1x, p1y, c1x, c1y, c2x, c2y, p2x, p2y, t) { + var t1 = 1 - t; + return { + x: pow(t1, 3) * p1x + pow(t1, 2) * 3 * t * c1x + t1 * 3 * t * t * c2x + pow(t, 3) * p2x, + y: pow(t1, 3) * p1y + pow(t1, 2) * 3 * t * c1y + t1 * 3 * t * t * c2y + pow(t, 3) * p2y + }; + } + + // Returns bounding box of cubic bezier curve. + // Source: http://blog.hackers-cafe.net/2009/06/how-to-calculate-bezier-curves-bounding.html + // Original version: NISHIO Hirokazu + // Modifications: https://github.com/timo22345 + function curveDim(x0, y0, x1, y1, x2, y2, x3, y3) { + var tvalues = [], + bounds = [[], []], + a, b, c, t, t1, t2, b2ac, sqrtb2ac; + for (var i = 0; i < 2; ++i) { + if (i == 0) { + b = 6 * x0 - 12 * x1 + 6 * x2; + a = -3 * x0 + 9 * x1 - 9 * x2 + 3 * x3; + c = 3 * x1 - 3 * x0; + } else { + b = 6 * y0 - 12 * y1 + 6 * y2; + a = -3 * y0 + 9 * y1 - 9 * y2 + 3 * y3; + c = 3 * y1 - 3 * y0; + } + if (abs(a) < 1e-12) { + if (abs(b) < 1e-12) { + continue; + } + t = -c / b; + if (0 < t && t < 1) { + tvalues.push(t); + } + continue; + } + b2ac = b * b - 4 * c * a; + sqrtb2ac = math.sqrt(b2ac); + if (b2ac < 0) { + continue; + } + t1 = (-b + sqrtb2ac) / (2 * a); + if (0 < t1 && t1 < 1) { + tvalues.push(t1); + } + t2 = (-b - sqrtb2ac) / (2 * a); + if (0 < t2 && t2 < 1) { + tvalues.push(t2); + } + } + + var x, y, j = tvalues.length, + jlen = j, + mt; + while (j--) { + t = tvalues[j]; + mt = 1 - t; + bounds[0][j] = (mt * mt * mt * x0) + (3 * mt * mt * t * x1) + (3 * mt * t * t * x2) + (t * t * t * x3); + bounds[1][j] = (mt * mt * mt * y0) + (3 * mt * mt * t * y1) + (3 * mt * t * t * y2) + (t * t * t * y3); + } + + bounds[0][jlen] = x0; + bounds[1][jlen] = y0; + bounds[0][jlen + 1] = x3; + bounds[1][jlen + 1] = y3; + bounds[0].length = bounds[1].length = jlen + 2; + + + return { + min: {x: mmin.apply(0, bounds[0]), y: mmin.apply(0, bounds[1])}, + max: {x: mmax.apply(0, bounds[0]), y: mmax.apply(0, bounds[1])} + }; + } + + function path2curve(path, path2) { + var pth = !path2 && paths(path); + if (!path2 && pth.curve) { + return pathClone(pth.curve); + } + var p = pathToAbsolute(path), + p2 = path2 && pathToAbsolute(path2), + attrs = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null}, + attrs2 = {x: 0, y: 0, bx: 0, by: 0, X: 0, Y: 0, qx: null, qy: null}, + processPath = function (path, d, pcom) { + var nx, ny; + if (!path) { + return ["C", d.x, d.y, d.x, d.y, d.x, d.y]; + } + !(path[0] in {T: 1, Q: 1}) && (d.qx = d.qy = null); + switch (path[0]) { + case "M": + d.X = path[1]; + d.Y = path[2]; + break; + case "A": + path = ["C"].concat(a2c.apply(0, [d.x, d.y].concat(path.slice(1)))); + break; + case "S": + if (pcom == "C" || pcom == "S") { // In "S" case we have to take into account, if the previous command is C/S. + nx = d.x * 2 - d.bx; // And reflect the previous + ny = d.y * 2 - d.by; // command's control point relative to the current point. + } + else { // or some else or nothing + nx = d.x; + ny = d.y; + } + path = ["C", nx, ny].concat(path.slice(1)); + break; + case "T": + if (pcom == "Q" || pcom == "T") { // In "T" case we have to take into account, if the previous command is Q/T. + d.qx = d.x * 2 - d.qx; // And make a reflection similar + d.qy = d.y * 2 - d.qy; // to case "S". + } + else { // or something else or nothing + d.qx = d.x; + d.qy = d.y; + } + path = ["C"].concat(q2c(d.x, d.y, d.qx, d.qy, path[1], path[2])); + break; + case "Q": + d.qx = path[1]; + d.qy = path[2]; + path = ["C"].concat(q2c(d.x, d.y, path[1], path[2], path[3], path[4])); + break; + case "L": + path = ["C"].concat(l2c(d.x, d.y, path[1], path[2])); + break; + case "H": + path = ["C"].concat(l2c(d.x, d.y, path[1], d.y)); + break; + case "V": + path = ["C"].concat(l2c(d.x, d.y, d.x, path[1])); + break; + case "Z": + path = ["C"].concat(l2c(d.x, d.y, d.X, d.Y)); + break; + } + return path; + }, + fixArc = function (pp, i) { + if (pp[i].length > 7) { + pp[i].shift(); + var pi = pp[i]; + while (pi.length) { + pcoms1[i] = "A"; // if created multiple C:s, their original seg is saved + p2 && (pcoms2[i] = "A"); // the same as above + pp.splice(i++, 0, ["C"].concat(pi.splice(0, 6))); + } + pp.splice(i, 1); + ii = mmax(p.length, p2 && p2.length || 0); + } + }, + fixM = function (path1, path2, a1, a2, i) { + if (path1 && path2 && path1[i][0] == "M" && path2[i][0] != "M") { + path2.splice(i, 0, ["M", a2.x, a2.y]); + a1.bx = 0; + a1.by = 0; + a1.x = path1[i][1]; + a1.y = path1[i][2]; + ii = mmax(p.length, p2 && p2.length || 0); + } + }, + pcoms1 = [], // path commands of original path p + pcoms2 = [], // path commands of original path p2 + pfirst = "", // temporary holder for original path command + pcom = ""; // holder for previous path command of original path + for (var i = 0, ii = mmax(p.length, p2 && p2.length || 0); i < ii; i++) { + p[i] && (pfirst = p[i][0]); // save current path command + + if (pfirst != "C") // C is not saved yet, because it may be result of conversion + { + pcoms1[i] = pfirst; // Save current path command + i && ( pcom = pcoms1[i - 1]); // Get previous path command pcom + } + p[i] = processPath(p[i], attrs, pcom); // Previous path command is inputted to processPath + + if (pcoms1[i] != "A" && pfirst == "C") pcoms1[i] = "C"; // A is the only command + // which may produce multiple C:s + // so we have to make sure that C is also C in original path + + fixArc(p, i); // fixArc adds also the right amount of A:s to pcoms1 + + if (p2) { // the same procedures is done to p2 + p2[i] && (pfirst = p2[i][0]); + if (pfirst != "C") { + pcoms2[i] = pfirst; + i && (pcom = pcoms2[i - 1]); + } + p2[i] = processPath(p2[i], attrs2, pcom); + + if (pcoms2[i] != "A" && pfirst == "C") { + pcoms2[i] = "C"; + } + + fixArc(p2, i); + } + fixM(p, p2, attrs, attrs2, i); + fixM(p2, p, attrs2, attrs, i); + var seg = p[i], + seg2 = p2 && p2[i], + seglen = seg.length, + seg2len = p2 && seg2.length; + attrs.x = seg[seglen - 2]; + attrs.y = seg[seglen - 1]; + attrs.bx = toFloat(seg[seglen - 4]) || attrs.x; + attrs.by = toFloat(seg[seglen - 3]) || attrs.y; + attrs2.bx = p2 && (toFloat(seg2[seg2len - 4]) || attrs2.x); + attrs2.by = p2 && (toFloat(seg2[seg2len - 3]) || attrs2.y); + attrs2.x = p2 && seg2[seg2len - 2]; + attrs2.y = p2 && seg2[seg2len - 1]; + } + if (!p2) { + pth.curve = pathClone(p); + } + return p2 ? [p, p2] : p; + } + function mapPath(path, matrix) { + if (!matrix) { + return path; + } + var x, y, i, j, ii, jj, pathi; + path = path2curve(path); + for (i = 0, ii = path.length; i < ii; i++) { + pathi = path[i]; + for (j = 1, jj = pathi.length; j < jj; j += 2) { + x = matrix.x(pathi[j], pathi[j + 1]); + y = matrix.y(pathi[j], pathi[j + 1]); + pathi[j] = x; + pathi[j + 1] = y; + } + } + return path; + } + + // http://schepers.cc/getting-to-the-point + function catmullRom2bezier(crp, z) { + var d = []; + for (var i = 0, iLen = crp.length; iLen - 2 * !z > i; i += 2) { + var p = [ + {x: +crp[i - 2], y: +crp[i - 1]}, + {x: +crp[i], y: +crp[i + 1]}, + {x: +crp[i + 2], y: +crp[i + 3]}, + {x: +crp[i + 4], y: +crp[i + 5]} + ]; + if (z) { + if (!i) { + p[0] = {x: +crp[iLen - 2], y: +crp[iLen - 1]}; + } else if (iLen - 4 == i) { + p[3] = {x: +crp[0], y: +crp[1]}; + } else if (iLen - 2 == i) { + p[2] = {x: +crp[0], y: +crp[1]}; + p[3] = {x: +crp[2], y: +crp[3]}; + } + } else { + if (iLen - 4 == i) { + p[3] = p[2]; + } else if (!i) { + p[0] = {x: +crp[i], y: +crp[i + 1]}; + } + } + d.push(["C", + (-p[0].x + 6 * p[1].x + p[2].x) / 6, + (-p[0].y + 6 * p[1].y + p[2].y) / 6, + (p[1].x + 6 * p[2].x - p[3].x) / 6, + (p[1].y + 6*p[2].y - p[3].y) / 6, + p[2].x, + p[2].y + ]); + } + + return d; + } + + // export + Snap.path = paths; + + /*\ + * Snap.path.getTotalLength + [ method ] + ** + * Returns the length of the given path in pixels + ** + - path (string) SVG path string + ** + = (number) length + \*/ + Snap.path.getTotalLength = getTotalLength; + /*\ + * Snap.path.getPointAtLength + [ method ] + ** + * Returns the coordinates of the point located at the given length along the given path + ** + - path (string) SVG path string + - length (number) length, in pixels, from the start of the path, excluding non-rendering jumps + ** + = (object) representation of the point: + o { + o x: (number) x coordinate, + o y: (number) y coordinate, + o alpha: (number) angle of derivative + o } + \*/ + Snap.path.getPointAtLength = getPointAtLength; + /*\ + * Snap.path.getSubpath + [ method ] + ** + * Returns the subpath of a given path between given start and end lengths + ** + - path (string) SVG path string + - from (number) length, in pixels, from the start of the path to the start of the segment + - to (number) length, in pixels, from the start of the path to the end of the segment + ** + = (string) path string definition for the segment + \*/ + Snap.path.getSubpath = function (path, from, to) { + if (this.getTotalLength(path) - to < 1e-6) { + return getSubpathsAtLength(path, from).end; + } + var a = getSubpathsAtLength(path, to, 1); + return from ? getSubpathsAtLength(a, from).end : a; + }; + /*\ + * Element.getTotalLength + [ method ] + ** + * Returns the length of the path in pixels (only works for `path` elements) + = (number) length + \*/ + elproto.getTotalLength = function () { + if (this.node.getTotalLength) { + return this.node.getTotalLength(); + } + }; + // SIERRA Element.getPointAtLength()/Element.getTotalLength(): If a <path> is broken into different segments, is the jump distance to the new coordinates set by the _M_ or _m_ commands calculated as part of the path's total length? + /*\ + * Element.getPointAtLength + [ method ] + ** + * Returns coordinates of the point located at the given length on the given path (only works for `path` elements) + ** + - length (number) length, in pixels, from the start of the path, excluding non-rendering jumps + ** + = (object) representation of the point: + o { + o x: (number) x coordinate, + o y: (number) y coordinate, + o alpha: (number) angle of derivative + o } + \*/ + elproto.getPointAtLength = function (length) { + return getPointAtLength(this.attr("d"), length); + }; + // SIERRA Element.getSubpath(): Similar to the problem for Element.getPointAtLength(). Unclear how this would work for a segmented path. Overall, the concept of _subpath_ and what I'm calling a _segment_ (series of non-_M_ or _Z_ commands) is unclear. + /*\ + * Element.getSubpath + [ method ] + ** + * Returns subpath of a given element from given start and end lengths (only works for `path` elements) + ** + - from (number) length, in pixels, from the start of the path to the start of the segment + - to (number) length, in pixels, from the start of the path to the end of the segment + ** + = (string) path string definition for the segment + \*/ + elproto.getSubpath = function (from, to) { + return Snap.path.getSubpath(this.attr("d"), from, to); + }; + Snap._.box = box; + /*\ + * Snap.path.findDotsAtSegment + [ method ] + ** + * Utility method + ** + * Finds dot coordinates on the given cubic beziér curve at the given t + - p1x (number) x of the first point of the curve + - p1y (number) y of the first point of the curve + - c1x (number) x of the first anchor of the curve + - c1y (number) y of the first anchor of the curve + - c2x (number) x of the second anchor of the curve + - c2y (number) y of the second anchor of the curve + - p2x (number) x of the second point of the curve + - p2y (number) y of the second point of the curve + - t (number) position on the curve (0..1) + = (object) point information in format: + o { + o x: (number) x coordinate of the point, + o y: (number) y coordinate of the point, + o m: { + o x: (number) x coordinate of the left anchor, + o y: (number) y coordinate of the left anchor + o }, + o n: { + o x: (number) x coordinate of the right anchor, + o y: (number) y coordinate of the right anchor + o }, + o start: { + o x: (number) x coordinate of the start of the curve, + o y: (number) y coordinate of the start of the curve + o }, + o end: { + o x: (number) x coordinate of the end of the curve, + o y: (number) y coordinate of the end of the curve + o }, + o alpha: (number) angle of the curve derivative at the point + o } + \*/ + Snap.path.findDotsAtSegment = findDotsAtSegment; + /*\ + * Snap.path.bezierBBox + [ method ] + ** + * Utility method + ** + * Returns the bounding box of a given cubic beziér curve + - p1x (number) x of the first point of the curve + - p1y (number) y of the first point of the curve + - c1x (number) x of the first anchor of the curve + - c1y (number) y of the first anchor of the curve + - c2x (number) x of the second anchor of the curve + - c2y (number) y of the second anchor of the curve + - p2x (number) x of the second point of the curve + - p2y (number) y of the second point of the curve + * or + - bez (array) array of six points for beziér curve + = (object) bounding box + o { + o x: (number) x coordinate of the left top point of the box, + o y: (number) y coordinate of the left top point of the box, + o x2: (number) x coordinate of the right bottom point of the box, + o y2: (number) y coordinate of the right bottom point of the box, + o width: (number) width of the box, + o height: (number) height of the box + o } + \*/ + Snap.path.bezierBBox = bezierBBox; + /*\ + * Snap.path.isPointInsideBBox + [ method ] + ** + * Utility method + ** + * Returns `true` if given point is inside bounding box + - bbox (string) bounding box + - x (string) x coordinate of the point + - y (string) y coordinate of the point + = (boolean) `true` if point is inside + \*/ + Snap.path.isPointInsideBBox = isPointInsideBBox; + /*\ + * Snap.path.isBBoxIntersect + [ method ] + ** + * Utility method + ** + * Returns `true` if two bounding boxes intersect + - bbox1 (string) first bounding box + - bbox2 (string) second bounding box + = (boolean) `true` if bounding boxes intersect + \*/ + Snap.path.isBBoxIntersect = isBBoxIntersect; + /*\ + * Snap.path.intersection + [ method ] + ** + * Utility method + ** + * Finds intersections of two paths + - path1 (string) path string + - path2 (string) path string + = (array) dots of intersection + o [ + o { + o x: (number) x coordinate of the point, + o y: (number) y coordinate of the point, + o t1: (number) t value for segment of path1, + o t2: (number) t value for segment of path2, + o segment1: (number) order number for segment of path1, + o segment2: (number) order number for segment of path2, + o bez1: (array) eight coordinates representing beziér curve for the segment of path1, + o bez2: (array) eight coordinates representing beziér curve for the segment of path2 + o } + o ] + \*/ + Snap.path.intersection = pathIntersection; + Snap.path.intersectionNumber = pathIntersectionNumber; + /*\ + * Snap.path.isPointInside + [ method ] + ** + * Utility method + ** + * Returns `true` if given point is inside a given closed path. + * + * Note: fill mode doesn’t affect the result of this method. + - path (string) path string + - x (number) x of the point + - y (number) y of the point + = (boolean) `true` if point is inside the path + \*/ + Snap.path.isPointInside = isPointInsidePath; + /*\ + * Snap.path.getBBox + [ method ] + ** + * Utility method + ** + * Returns the bounding box of a given path + - path (string) path string + = (object) bounding box + o { + o x: (number) x coordinate of the left top point of the box, + o y: (number) y coordinate of the left top point of the box, + o x2: (number) x coordinate of the right bottom point of the box, + o y2: (number) y coordinate of the right bottom point of the box, + o width: (number) width of the box, + o height: (number) height of the box + o } + \*/ + Snap.path.getBBox = pathBBox; + Snap.path.get = getPath; + /*\ + * Snap.path.toRelative + [ method ] + ** + * Utility method + ** + * Converts path coordinates into relative values + - path (string) path string + = (array) path string + \*/ + Snap.path.toRelative = pathToRelative; + /*\ + * Snap.path.toAbsolute + [ method ] + ** + * Utility method + ** + * Converts path coordinates into absolute values + - path (string) path string + = (array) path string + \*/ + Snap.path.toAbsolute = pathToAbsolute; + /*\ + * Snap.path.toCubic + [ method ] + ** + * Utility method + ** + * Converts path to a new path where all segments are cubic beziér curves + - pathString (string|array) path string or array of segments + = (array) array of segments + \*/ + Snap.path.toCubic = path2curve; + /*\ + * Snap.path.map + [ method ] + ** + * Transform the path string with the given matrix + - path (string) path string + - matrix (object) see @Matrix + = (string) transformed path string + \*/ + Snap.path.map = mapPath; + Snap.path.toString = toString; + Snap.path.clone = pathClone; +}); +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +Snap.plugin(function (Snap, Element, Paper, glob) { + var elproto = Element.prototype, + has = "hasOwnProperty", + supportsTouch = "createTouch" in glob.doc, + events = [ + "click", "dblclick", "mousedown", "mousemove", "mouseout", + "mouseover", "mouseup", "touchstart", "touchmove", "touchend", + "touchcancel" + ], + touchMap = { + mousedown: "touchstart", + mousemove: "touchmove", + mouseup: "touchend" + }, + getScroll = function (xy, el) { + var name = xy == "y" ? "scrollTop" : "scrollLeft", + doc = el && el.node ? el.node.ownerDocument : glob.doc; + return doc[name in doc.documentElement ? "documentElement" : "body"][name]; + }, + preventDefault = function () { + this.returnValue = false; + }, + preventTouch = function () { + return this.originalEvent.preventDefault(); + }, + stopPropagation = function () { + this.cancelBubble = true; + }, + stopTouch = function () { + return this.originalEvent.stopPropagation(); + }, + addEvent = (function () { + if (glob.doc.addEventListener) { + return function (obj, type, fn, element) { + var realName = supportsTouch && touchMap[type] ? touchMap[type] : type, + f = function (e) { + var scrollY = getScroll("y", element), + scrollX = getScroll("x", element); + if (supportsTouch && touchMap[has](type)) { + for (var i = 0, ii = e.targetTouches && e.targetTouches.length; i < ii; i++) { + if (e.targetTouches[i].target == obj || obj.contains(e.targetTouches[i].target)) { + var olde = e; + e = e.targetTouches[i]; + e.originalEvent = olde; + e.preventDefault = preventTouch; + e.stopPropagation = stopTouch; + break; + } + } + } + var x = e.clientX + scrollX, + y = e.clientY + scrollY; + return fn.call(element, e, x, y); + }; + + if (type !== realName) { + obj.addEventListener(type, f, false); + } + + obj.addEventListener(realName, f, false); + + return function () { + if (type !== realName) { + obj.removeEventListener(type, f, false); + } + + obj.removeEventListener(realName, f, false); + return true; + }; + }; + } else if (glob.doc.attachEvent) { + return function (obj, type, fn, element) { + var f = function (e) { + e = e || element.node.ownerDocument.window.event; + var scrollY = getScroll("y", element), + scrollX = getScroll("x", element), + x = e.clientX + scrollX, + y = e.clientY + scrollY; + e.preventDefault = e.preventDefault || preventDefault; + e.stopPropagation = e.stopPropagation || stopPropagation; + return fn.call(element, e, x, y); + }; + obj.attachEvent("on" + type, f); + var detacher = function () { + obj.detachEvent("on" + type, f); + return true; + }; + return detacher; + }; + } + })(), + drag = [], + dragMove = function (e) { + var x = e.clientX, + y = e.clientY, + scrollY = getScroll("y"), + scrollX = getScroll("x"), + dragi, + j = drag.length; + while (j--) { + dragi = drag[j]; + if (supportsTouch) { + var i = e.touches && e.touches.length, + touch; + while (i--) { + touch = e.touches[i]; + if (touch.identifier == dragi.el._drag.id || dragi.el.node.contains(touch.target)) { + x = touch.clientX; + y = touch.clientY; + (e.originalEvent ? e.originalEvent : e).preventDefault(); + break; + } + } + } else { + e.preventDefault(); + } + var node = dragi.el.node, + o, + next = node.nextSibling, + parent = node.parentNode, + display = node.style.display; + // glob.win.opera && parent.removeChild(node); + // node.style.display = "none"; + // o = dragi.el.paper.getElementByPoint(x, y); + // node.style.display = display; + // glob.win.opera && (next ? parent.insertBefore(node, next) : parent.appendChild(node)); + // o && eve("snap.drag.over." + dragi.el.id, dragi.el, o); + x += scrollX; + y += scrollY; + eve("snap.drag.move." + dragi.el.id, dragi.move_scope || dragi.el, x - dragi.el._drag.x, y - dragi.el._drag.y, x, y, e); + } + }, + dragUp = function (e) { + Snap.unmousemove(dragMove).unmouseup(dragUp); + var i = drag.length, + dragi; + while (i--) { + dragi = drag[i]; + dragi.el._drag = {}; + eve("snap.drag.end." + dragi.el.id, dragi.end_scope || dragi.start_scope || dragi.move_scope || dragi.el, e); + } + drag = []; + }; + /*\ + * Element.click + [ method ] + ** + * Adds a click event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.unclick + [ method ] + ** + * Removes a click event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.dblclick + [ method ] + ** + * Adds a double click event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.undblclick + [ method ] + ** + * Removes a double click event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.mousedown + [ method ] + ** + * Adds a mousedown event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.unmousedown + [ method ] + ** + * Removes a mousedown event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.mousemove + [ method ] + ** + * Adds a mousemove event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.unmousemove + [ method ] + ** + * Removes a mousemove event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.mouseout + [ method ] + ** + * Adds a mouseout event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.unmouseout + [ method ] + ** + * Removes a mouseout event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.mouseover + [ method ] + ** + * Adds a mouseover event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.unmouseover + [ method ] + ** + * Removes a mouseover event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.mouseup + [ method ] + ** + * Adds a mouseup event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.unmouseup + [ method ] + ** + * Removes a mouseup event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.touchstart + [ method ] + ** + * Adds a touchstart event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.untouchstart + [ method ] + ** + * Removes a touchstart event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.touchmove + [ method ] + ** + * Adds a touchmove event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.untouchmove + [ method ] + ** + * Removes a touchmove event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.touchend + [ method ] + ** + * Adds a touchend event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.untouchend + [ method ] + ** + * Removes a touchend event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + + /*\ + * Element.touchcancel + [ method ] + ** + * Adds a touchcancel event handler to the element + - handler (function) handler for the event + = (object) @Element + \*/ + /*\ + * Element.untouchcancel + [ method ] + ** + * Removes a touchcancel event handler from the element + - handler (function) handler for the event + = (object) @Element + \*/ + for (var i = events.length; i--;) { + (function (eventName) { + Snap[eventName] = elproto[eventName] = function (fn, scope) { + if (Snap.is(fn, "function")) { + this.events = this.events || []; + this.events.push({ + name: eventName, + f: fn, + unbind: addEvent(this.node || document, eventName, fn, scope || this) + }); + } + return this; + }; + Snap["un" + eventName] = + elproto["un" + eventName] = function (fn) { + var events = this.events || [], + l = events.length; + while (l--) if (events[l].name == eventName && + (events[l].f == fn || !fn)) { + events[l].unbind(); + events.splice(l, 1); + !events.length && delete this.events; + return this; + } + return this; + }; + })(events[i]); + } + /*\ + * Element.hover + [ method ] + ** + * Adds hover event handlers to the element + - f_in (function) handler for hover in + - f_out (function) handler for hover out + - icontext (object) #optional context for hover in handler + - ocontext (object) #optional context for hover out handler + = (object) @Element + \*/ + elproto.hover = function (f_in, f_out, scope_in, scope_out) { + return this.mouseover(f_in, scope_in).mouseout(f_out, scope_out || scope_in); + }; + /*\ + * Element.unhover + [ method ] + ** + * Removes hover event handlers from the element + - f_in (function) handler for hover in + - f_out (function) handler for hover out + = (object) @Element + \*/ + elproto.unhover = function (f_in, f_out) { + return this.unmouseover(f_in).unmouseout(f_out); + }; + var draggable = []; + // SIERRA unclear what _context_ refers to for starting, ending, moving the drag gesture. + // SIERRA Element.drag(): _x position of the mouse_: Where are the x/y values offset from? + // SIERRA Element.drag(): much of this member's doc appears to be duplicated for some reason. + // SIERRA Unclear about this sentence: _Additionally following drag events will be triggered: drag.start.<id> on start, drag.end.<id> on end and drag.move.<id> on every move._ Is there a global _drag_ object to which you can assign handlers keyed by an element's ID? + /*\ + * Element.drag + [ method ] + ** + * Adds event handlers for an element's drag gesture + ** + - onmove (function) handler for moving + - onstart (function) handler for drag start + - onend (function) handler for drag end + - mcontext (object) #optional context for moving handler + - scontext (object) #optional context for drag start handler + - econtext (object) #optional context for drag end handler + * Additionaly following `drag` events are triggered: `drag.start.<id>` on start, + * `drag.end.<id>` on end and `drag.move.<id>` on every move. When element is dragged over another element + * `drag.over.<id>` fires as well. + * + * Start event and start handler are called in specified context or in context of the element with following parameters: + o x (number) x position of the mouse + o y (number) y position of the mouse + o event (object) DOM event object + * Move event and move handler are called in specified context or in context of the element with following parameters: + o dx (number) shift by x from the start point + o dy (number) shift by y from the start point + o x (number) x position of the mouse + o y (number) y position of the mouse + o event (object) DOM event object + * End event and end handler are called in specified context or in context of the element with following parameters: + o event (object) DOM event object + = (object) @Element + \*/ + elproto.drag = function (onmove, onstart, onend, move_scope, start_scope, end_scope) { + if (!arguments.length) { + var origTransform; + return this.drag(function (dx, dy) { + this.attr({ + transform: origTransform + (origTransform ? "T" : "t") + [dx, dy] + }); + }, function () { + origTransform = this.transform().local; + }); + } + function start(e, x, y) { + (e.originalEvent || e).preventDefault(); + this._drag.x = x; + this._drag.y = y; + this._drag.id = e.identifier; + !drag.length && Snap.mousemove(dragMove).mouseup(dragUp); + drag.push({el: this, move_scope: move_scope, start_scope: start_scope, end_scope: end_scope}); + onstart && eve.on("snap.drag.start." + this.id, onstart); + onmove && eve.on("snap.drag.move." + this.id, onmove); + onend && eve.on("snap.drag.end." + this.id, onend); + eve("snap.drag.start." + this.id, start_scope || move_scope || this, x, y, e); + } + this._drag = {}; + draggable.push({el: this, start: start}); + this.mousedown(start); + return this; + }; + /* + * Element.onDragOver + [ method ] + ** + * Shortcut to assign event handler for `drag.over.<id>` event, where `id` is the element's `id` (see @Element.id) + - f (function) handler for event, first argument would be the element you are dragging over + \*/ + // elproto.onDragOver = function (f) { + // f ? eve.on("snap.drag.over." + this.id, f) : eve.unbind("snap.drag.over." + this.id); + // }; + /*\ + * Element.undrag + [ method ] + ** + * Removes all drag event handlers from the given element + \*/ + elproto.undrag = function () { + var i = draggable.length; + while (i--) if (draggable[i].el == this) { + this.unmousedown(draggable[i].start); + draggable.splice(i, 1); + eve.unbind("snap.drag.*." + this.id); + } + !draggable.length && Snap.unmousemove(dragMove).unmouseup(dragUp); + return this; + }; +}); +// Copyright (c) 2013 Adobe Systems Incorporated. All rights reserved. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +Snap.plugin(function (Snap, Element, Paper, glob) { + var elproto = Element.prototype, + pproto = Paper.prototype, + rgurl = /^\s*url\((.+)\)/, + Str = String, + $ = Snap._.$; + Snap.filter = {}; + /*\ + * Paper.filter + [ method ] + ** + * Creates a `<filter>` element + ** + - filstr (string) SVG fragment of filter provided as a string + = (object) @Element + * Note: It is recommended to use filters embedded into the page inside an empty SVG element. + > Usage + | var f = paper.filter('<feGaussianBlur stdDeviation="2"/>'), + | c = paper.circle(10, 10, 10).attr({ + | filter: f + | }); + \*/ + pproto.filter = function (filstr) { + var paper = this; + if (paper.type != "svg") { + paper = paper.paper; + } + var f = Snap.parse(Str(filstr)), + id = Snap._.id(), + width = paper.node.offsetWidth, + height = paper.node.offsetHeight, + filter = $("filter"); + $(filter, { + id: id, + filterUnits: "userSpaceOnUse" + }); + filter.appendChild(f.node); + paper.defs.appendChild(filter); + return new Element(filter); + }; + + eve.on("snap.util.getattr.filter", function () { + eve.stop(); + var p = $(this.node, "filter"); + if (p) { + var match = Str(p).match(rgurl); + return match && Snap.select(match[1]); + } + }); + eve.on("snap.util.attr.filter", function (value) { + if (value instanceof Element && value.type == "filter") { + eve.stop(); + var id = value.node.id; + if (!id) { + $(value.node, {id: value.id}); + id = value.id; + } + $(this.node, { + filter: Snap.url(id) + }); + } + if (!value || value == "none") { + eve.stop(); + this.node.removeAttribute("filter"); + } + }); + /*\ + * Snap.filter.blur + [ method ] + ** + * Returns an SVG markup string for the blur filter + ** + - x (number) amount of horizontal blur, in pixels + - y (number) #optional amount of vertical blur, in pixels + = (string) filter representation + > Usage + | var f = paper.filter(Snap.filter.blur(5, 10)), + | c = paper.circle(10, 10, 10).attr({ + | filter: f + | }); + \*/ + Snap.filter.blur = function (x, y) { + if (x == null) { + x = 2; + } + var def = y == null ? x : [x, y]; + return Snap.format('\<feGaussianBlur stdDeviation="{def}"/>', { + def: def + }); + }; + Snap.filter.blur.toString = function () { + return this(); + }; + /*\ + * Snap.filter.shadow + [ method ] + ** + * Returns an SVG markup string for the shadow filter + ** + - dx (number) #optional horizontal shift of the shadow, in pixels + - dy (number) #optional vertical shift of the shadow, in pixels + - blur (number) #optional amount of blur + - color (string) #optional color of the shadow + - opacity (number) #optional `0..1` opacity of the shadow + * or + - dx (number) #optional horizontal shift of the shadow, in pixels + - dy (number) #optional vertical shift of the shadow, in pixels + - color (string) #optional color of the shadow + - opacity (number) #optional `0..1` opacity of the shadow + * which makes blur default to `4`. Or + - dx (number) #optional horizontal shift of the shadow, in pixels + - dy (number) #optional vertical shift of the shadow, in pixels + - opacity (number) #optional `0..1` opacity of the shadow + = (string) filter representation + > Usage + | var f = paper.filter(Snap.filter.shadow(0, 2, 3)), + | c = paper.circle(10, 10, 10).attr({ + | filter: f + | }); + \*/ + Snap.filter.shadow = function (dx, dy, blur, color, opacity) { + if (typeof blur == "string") { + color = blur; + opacity = color; + blur = 4; + } + if (typeof color != "string") { + opacity = color; + color = "#000"; + } + color = color || "#000"; + if (blur == null) { + blur = 4; + } + if (opacity == null) { + opacity = 1; + } + if (dx == null) { + dx = 0; + dy = 2; + } + if (dy == null) { + dy = dx; + } + color = Snap.color(color); + return Snap.format('<feGaussianBlur in="SourceAlpha" stdDeviation="{blur}"/><feOffset dx="{dx}" dy="{dy}" result="offsetblur"/><feFlood flood-color="{color}"/><feComposite in2="offsetblur" operator="in"/><feComponentTransfer><feFuncA type="linear" slope="{opacity}"/></feComponentTransfer><feMerge><feMergeNode/><feMergeNode in="SourceGraphic"/></feMerge>', { + color: color, + dx: dx, + dy: dy, + blur: blur, + opacity: opacity + }); + }; + Snap.filter.shadow.toString = function () { + return this(); + }; + /*\ + * Snap.filter.grayscale + [ method ] + ** + * Returns an SVG markup string for the grayscale filter + ** + - amount (number) amount of filter (`0..1`) + = (string) filter representation + \*/ + Snap.filter.grayscale = function (amount) { + if (amount == null) { + amount = 1; + } + return Snap.format('<feColorMatrix type="matrix" values="{a} {b} {c} 0 0 {d} {e} {f} 0 0 {g} {b} {h} 0 0 0 0 0 1 0"/>', { + a: 0.2126 + 0.7874 * (1 - amount), + b: 0.7152 - 0.7152 * (1 - amount), + c: 0.0722 - 0.0722 * (1 - amount), + d: 0.2126 - 0.2126 * (1 - amount), + e: 0.7152 + 0.2848 * (1 - amount), + f: 0.0722 - 0.0722 * (1 - amount), + g: 0.2126 - 0.2126 * (1 - amount), + h: 0.0722 + 0.9278 * (1 - amount) + }); + }; + Snap.filter.grayscale.toString = function () { + return this(); + }; + /*\ + * Snap.filter.sepia + [ method ] + ** + * Returns an SVG markup string for the sepia filter + ** + - amount (number) amount of filter (`0..1`) + = (string) filter representation + \*/ + Snap.filter.sepia = function (amount) { + if (amount == null) { + amount = 1; + } + return Snap.format('<feColorMatrix type="matrix" values="{a} {b} {c} 0 0 {d} {e} {f} 0 0 {g} {h} {i} 0 0 0 0 0 1 0"/>', { + a: 0.393 + 0.607 * (1 - amount), + b: 0.769 - 0.769 * (1 - amount), + c: 0.189 - 0.189 * (1 - amount), + d: 0.349 - 0.349 * (1 - amount), + e: 0.686 + 0.314 * (1 - amount), + f: 0.168 - 0.168 * (1 - amount), + g: 0.272 - 0.272 * (1 - amount), + h: 0.534 - 0.534 * (1 - amount), + i: 0.131 + 0.869 * (1 - amount) + }); + }; + Snap.filter.sepia.toString = function () { + return this(); + }; + /*\ + * Snap.filter.saturate + [ method ] + ** + * Returns an SVG markup string for the saturate filter + ** + - amount (number) amount of filter (`0..1`) + = (string) filter representation + \*/ + Snap.filter.saturate = function (amount) { + if (amount == null) { + amount = 1; + } + return Snap.format('<feColorMatrix type="saturate" values="{amount}"/>', { + amount: 1 - amount + }); + }; + Snap.filter.saturate.toString = function () { + return this(); + }; + /*\ + * Snap.filter.hueRotate + [ method ] + ** + * Returns an SVG markup string for the hue-rotate filter + ** + - angle (number) angle of rotation + = (string) filter representation + \*/ + Snap.filter.hueRotate = function (angle) { + angle = angle || 0; + return Snap.format('<feColorMatrix type="hueRotate" values="{angle}"/>', { + angle: angle + }); + }; + Snap.filter.hueRotate.toString = function () { + return this(); + }; + /*\ + * Snap.filter.invert + [ method ] + ** + * Returns an SVG markup string for the invert filter + ** + - amount (number) amount of filter (`0..1`) + = (string) filter representation + \*/ + Snap.filter.invert = function (amount) { + if (amount == null) { + amount = 1; + } + return Snap.format('<feComponentTransfer><feFuncR type="table" tableValues="{amount} {amount2}"/><feFuncG type="table" tableValues="{amount} {amount2}"/><feFuncB type="table" tableValues="{amount} {amount2}"/></feComponentTransfer>', { + amount: amount, + amount2: 1 - amount + }); + }; + Snap.filter.invert.toString = function () { + return this(); + }; + /*\ + * Snap.filter.brightness + [ method ] + ** + * Returns an SVG markup string for the brightness filter + ** + - amount (number) amount of filter (`0..1`) + = (string) filter representation + \*/ + Snap.filter.brightness = function (amount) { + if (amount == null) { + amount = 1; + } + return Snap.format('<feComponentTransfer><feFuncR type="linear" slope="{amount}"/><feFuncG type="linear" slope="{amount}"/><feFuncB type="linear" slope="{amount}"/></feComponentTransfer>', { + amount: amount + }); + }; + Snap.filter.brightness.toString = function () { + return this(); + }; + /*\ + * Snap.filter.contrast + [ method ] + ** + * Returns an SVG markup string for the contrast filter + ** + - amount (number) amount of filter (`0..1`) + = (string) filter representation + \*/ + Snap.filter.contrast = function (amount) { + if (amount == null) { + amount = 1; + } + return Snap.format('<feComponentTransfer><feFuncR type="linear" slope="{amount}" intercept="{amount2}"/><feFuncG type="linear" slope="{amount}" intercept="{amount2}"/><feFuncB type="linear" slope="{amount}" intercept="{amount2}"/></feComponentTransfer>', { + amount: amount, + amount2: .5 - amount / 2 + }); + }; + Snap.filter.contrast.toString = function () { + return this(); + }; +}); + +return Snap; +})); +},{"72":72}],74:[function(_dereq_,module,exports){ +'use strict'; + +var snapsvg = module.exports = _dereq_(73); + +snapsvg.plugin(function(Snap, Element) { + + /*\ + * Element.children + [ method ] + ** + * Returns array of all the children of the element. + = (array) array of Elements + \*/ + Element.prototype.children = function () { + var out = [], + ch = this.node.childNodes; + for (var i = 0, ii = ch.length; i < ii; i++) { + out[i] = new Snap(ch[i]); + } + return out; + }; +}); + + +/** + * @class ClassPlugin + * + * Extends snapsvg with methods to add and remove classes + */ +snapsvg.plugin(function (Snap, Element, Paper, global) { + + function split(str) { + return str.split(/\s+/); + } + + function join(array) { + return array.join(' '); + } + + function getClasses(e) { + return split(e.attr('class') || ''); + } + + function setClasses(e, classes) { + e.attr('class', join(classes)); + } + + /** + * @method snapsvg.Element#addClass + * + * @example + * + * e.attr('class', 'selector'); + * + * e.addClass('foo bar'); // adds classes foo and bar + * e.attr('class'); // -> 'selector foo bar' + * + * e.addClass('fooBar'); + * e.attr('class'); // -> 'selector foo bar fooBar' + * + * @param {String} cls classes to be added to the element + * + * @return {snapsvg.Element} the element (this) + */ + Element.prototype.addClass = function(cls) { + var current = getClasses(this), + add = split(cls), + i, e; + + for (i = 0, e; !!(e = add[i]); i++) { + if (current.indexOf(e) === -1) { + current.push(e); + } + } + + setClasses(this, current); + + return this; + }; + + /** + * @method snapsvg.Element#hasClass + * + * @param {String} cls the class to query for + * @return {Boolean} returns true if the element has the given class + */ + Element.prototype.hasClass = function(cls) { + if (!cls) { + throw new Error('[snapsvg] syntax: hasClass(clsStr)'); + } + + return getClasses(this).indexOf(cls) !== -1; + }; + + /** + * @method snapsvg.Element#removeClass + * + * @example + * + * e.attr('class', 'foo bar'); + * + * e.removeClass('foo'); + * e.attr('class'); // -> 'bar' + * + * e.removeClass('foo bar'); // removes classes foo and bar + * e.attr('class'); // -> '' + * + * @param {String} cls classes to be removed from element + * + * @return {snapsvg.Element} the element (this) + */ + Element.prototype.removeClass = function(cls) { + var current = getClasses(this), + remove = split(cls), + i, e, idx; + + for (i = 0, e; !!(e = remove[i]); i++) { + idx = current.indexOf(e); + + if (idx !== -1) { + // remove element from array + current.splice(idx, 1); + } + } + + setClasses(this, current); + + return this; + }; + +}); + +/** + * @class TranslatePlugin + * + * Extends snapsvg with methods to translate elements + */ +snapsvg.plugin(function (Snap, Element, Paper, global) { + + /* + * @method snapsvg.Element#translate + * + * @example + * + * e.translate(10, 20); + * + * // sets transform matrix to translate(10, 20) + * + * @param {Number} x translation + * @param {Number} y translation + * + * @return {snapsvg.Element} the element (this) + */ + Element.prototype.translate = function(x, y) { + var matrix = new Snap.Matrix(); + matrix.translate(x, y); + return this.transform(matrix); + }; +}); + + +/** + * @class CreatePlugin + * + * Create an svg element without attaching it to the dom + */ +snapsvg.plugin(function(Snap) { + + Snap.create = function(name, attrs) { + return Snap._.wrap(Snap._.$(name, attrs)); + }; +}); + + +/** + * @class CreatSnapAtPlugin + * + * Extends snap.svg with a method to create a SVG element + * at a specific position in the DOM. + */ +snapsvg.plugin(function(Snap, Element, Paper, global) { + + /* + * @method snapsvg.createSnapAt + * + * @example + * + * snapsvg.createSnapAt(parentNode, 200, 200); + * + * @param {Number} width of svg + * @param {Number} height of svg + * @param {Object} parentNode svg Element will be child of this + * + * @return {snapsvg.Element} the newly created wrapped SVG element instance + */ + Snap.createSnapAt = function(width, height, parentNode) { + + var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); + svg.setAttribute('width', width); + svg.setAttribute('height', height); + if (!parentNode) { + parentNode = document.body; + } + parentNode.appendChild(svg); + + return new Snap(svg); + }; +}); +},{"73":73}],75:[function(_dereq_,module,exports){ + +var isArray = function(obj) { + return Object.prototype.toString.call(obj) === '[object Array]'; +}; + +var annotate = function() { + var args = Array.prototype.slice.call(arguments); + + if (args.length === 1 && isArray(args[0])) { + args = args[0]; + } + + var fn = args.pop(); + + fn.$inject = args; + + return fn; +}; + + +// Current limitations: +// - can't put into "function arg" comments +// function /* (no parenthesis like this) */ (){} +// function abc( /* xx (no parenthesis like this) */ a, b) {} +// +// Just put the comment before function or inside: +// /* (((this is fine))) */ function(a, b) {} +// function abc(a) { /* (((this is fine))) */} + +var FN_ARGS = /^function\s*[^\(]*\(\s*([^\)]*)\)/m; +var FN_ARG = /\/\*([^\*]*)\*\//m; + +var parse = function(fn) { + if (typeof fn !== 'function') { + throw new Error('Cannot annotate "' + fn + '". Expected a function!'); + } + + var match = fn.toString().match(FN_ARGS); + return match[1] && match[1].split(',').map(function(arg) { + match = arg.match(FN_ARG); + return match ? match[1].trim() : arg.trim(); + }) || []; +}; + + +exports.annotate = annotate; +exports.parse = parse; +exports.isArray = isArray; + +},{}],76:[function(_dereq_,module,exports){ +module.exports = { + annotate: _dereq_(75).annotate, + Module: _dereq_(78), + Injector: _dereq_(77) +}; + +},{"75":75,"77":77,"78":78}],77:[function(_dereq_,module,exports){ +var Module = _dereq_(78); +var autoAnnotate = _dereq_(75).parse; +var annotate = _dereq_(75).annotate; +var isArray = _dereq_(75).isArray; + + +var Injector = function(modules, parent) { + parent = parent || { + get: function(name) { + currentlyResolving.push(name); + throw error('No provider for "' + name + '"!'); + } + }; + + var currentlyResolving = []; + var providers = this._providers = Object.create(parent._providers || null); + var instances = this._instances = Object.create(null); + + var self = instances.injector = this; + + var error = function(msg) { + var stack = currentlyResolving.join(' -> '); + currentlyResolving.length = 0; + return new Error(stack ? msg + ' (Resolving: ' + stack + ')' : msg); + }; + + var get = function(name) { + if (!providers[name] && name.indexOf('.') !== -1) { + var parts = name.split('.'); + var pivot = get(parts.shift()); + + while(parts.length) { + pivot = pivot[parts.shift()]; + } + + return pivot; + } + + if (Object.hasOwnProperty.call(instances, name)) { + return instances[name]; + } + + if (Object.hasOwnProperty.call(providers, name)) { + if (currentlyResolving.indexOf(name) !== -1) { + currentlyResolving.push(name); + throw error('Cannot resolve circular dependency!'); + } + + currentlyResolving.push(name); + instances[name] = providers[name][0](providers[name][1]); + currentlyResolving.pop(); + + return instances[name]; + } + + return parent.get(name); + }; + + var instantiate = function(Type) { + var instance = Object.create(Type.prototype); + var returned = invoke(Type, instance); + + return typeof returned === 'object' ? returned : instance; + }; + + var invoke = function(fn, context) { + if (typeof fn !== 'function') { + if (isArray(fn)) { + fn = annotate(fn.slice()); + } else { + throw new Error('Cannot invoke "' + fn + '". Expected a function!'); + } + } + + var inject = fn.$inject && fn.$inject || autoAnnotate(fn); + var dependencies = inject.map(function(dep) { + return get(dep); + }); + + // TODO(vojta): optimize without apply + return fn.apply(context, dependencies); + }; + + + var createPrivateInjectorFactory = function(privateChildInjector) { + return annotate(function(key) { + return privateChildInjector.get(key); + }); + }; + + var createChild = function(modules, forceNewInstances) { + if (forceNewInstances && forceNewInstances.length) { + var fromParentModule = Object.create(null); + var matchedScopes = Object.create(null); + + var privateInjectorsCache = []; + var privateChildInjectors = []; + var privateChildFactories = []; + + var provider; + var cacheIdx; + var privateChildInjector; + var privateChildInjectorFactory; + for (var name in providers) { + provider = providers[name]; + + if (forceNewInstances.indexOf(name) !== -1) { + if (provider[2] === 'private') { + cacheIdx = privateInjectorsCache.indexOf(provider[3]); + if (cacheIdx === -1) { + privateChildInjector = provider[3].createChild([], forceNewInstances); + privateChildInjectorFactory = createPrivateInjectorFactory(privateChildInjector); + privateInjectorsCache.push(provider[3]); + privateChildInjectors.push(privateChildInjector); + privateChildFactories.push(privateChildInjectorFactory); + fromParentModule[name] = [privateChildInjectorFactory, name, 'private', privateChildInjector]; + } else { + fromParentModule[name] = [privateChildFactories[cacheIdx], name, 'private', privateChildInjectors[cacheIdx]]; + } + } else { + fromParentModule[name] = [provider[2], provider[1]]; + } + matchedScopes[name] = true; + } + + if ((provider[2] === 'factory' || provider[2] === 'type') && provider[1].$scope) { + forceNewInstances.forEach(function(scope) { + if (provider[1].$scope.indexOf(scope) !== -1) { + fromParentModule[name] = [provider[2], provider[1]]; + matchedScopes[scope] = true; + } + }); + } + } + + forceNewInstances.forEach(function(scope) { + if (!matchedScopes[scope]) { + throw new Error('No provider for "' + scope + '". Cannot use provider from the parent!'); + } + }); + + modules.unshift(fromParentModule); + } + + return new Injector(modules, self); + }; + + var factoryMap = { + factory: invoke, + type: instantiate, + value: function(value) { + return value; + } + }; + + modules.forEach(function(module) { + + function arrayUnwrap(type, value) { + if (type !== 'value' && isArray(value)) { + value = annotate(value.slice()); + } + + return value; + } + + // TODO(vojta): handle wrong inputs (modules) + if (module instanceof Module) { + module.forEach(function(provider) { + var name = provider[0]; + var type = provider[1]; + var value = provider[2]; + + providers[name] = [factoryMap[type], arrayUnwrap(type, value), type]; + }); + } else if (typeof module === 'object') { + if (module.__exports__) { + var clonedModule = Object.keys(module).reduce(function(m, key) { + if (key.substring(0, 2) !== '__') { + m[key] = module[key]; + } + return m; + }, Object.create(null)); + + var privateInjector = new Injector((module.__modules__ || []).concat([clonedModule]), self); + var getFromPrivateInjector = annotate(function(key) { + return privateInjector.get(key); + }); + module.__exports__.forEach(function(key) { + providers[key] = [getFromPrivateInjector, key, 'private', privateInjector]; + }); + } else { + Object.keys(module).forEach(function(name) { + if (module[name][2] === 'private') { + providers[name] = module[name]; + return; + } + + var type = module[name][0]; + var value = module[name][1]; + + providers[name] = [factoryMap[type], arrayUnwrap(type, value), type]; + }); + } + } + }); + + // public API + this.get = get; + this.invoke = invoke; + this.instantiate = instantiate; + this.createChild = createChild; +}; + +module.exports = Injector; + +},{"75":75,"78":78}],78:[function(_dereq_,module,exports){ +var Module = function() { + var providers = []; + + this.factory = function(name, factory) { + providers.push([name, 'factory', factory]); + return this; + }; + + this.value = function(name, value) { + providers.push([name, 'value', value]); + return this; + }; + + this.type = function(name, type) { + providers.push([name, 'type', type]); + return this; + }; + + this.forEach = function(iterator) { + providers.forEach(iterator); + }; +}; + +module.exports = Module; + +},{}],79:[function(_dereq_,module,exports){ +if (typeof Object.create === 'function') { + // implementation from standard node.js 'util' module + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + }; +} else { + // old school shim for old browsers + module.exports = function inherits(ctor, superCtor) { + ctor.super_ = superCtor + var TempCtor = function () {} + TempCtor.prototype = superCtor.prototype + ctor.prototype = new TempCtor() + ctor.prototype.constructor = ctor + } +} + +},{}],80:[function(_dereq_,module,exports){ +/** + * Gets the last element of `array`. + * + * @static + * @memberOf _ + * @category Array + * @param {Array} array The array to query. + * @returns {*} Returns the last element of `array`. + * @example + * + * _.last([1, 2, 3]); + * // => 3 + */ +function last(array) { + var length = array ? array.length : 0; + return length ? array[length - 1] : undefined; +} + +module.exports = last; + +},{}],81:[function(_dereq_,module,exports){ +var arrayEvery = _dereq_(97), + baseCallback = _dereq_(104), + baseEvery = _dereq_(109), + isArray = _dereq_(166), + isIterateeCall = _dereq_(154); + +/** + * Checks if `predicate` returns truthy for **all** elements of `collection`. + * The predicate is bound to `thisArg` and invoked with three arguments: + * (value, index|key, collection). + * + * If a property name is provided for `predicate` the created `_.property` + * style callback returns the property value of the given element. + * + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style + * callback returns `true` for elements that have the properties of the given + * object, else `false`. + * + * @static + * @memberOf _ + * @alias all + * @category Collection + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function|Object|string} [predicate=_.identity] The function invoked + * per iteration. + * @param {*} [thisArg] The `this` binding of `predicate`. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. + * @example + * + * _.every([true, 1, null, 'yes'], Boolean); + * // => false + * + * var users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false } + * ]; + * + * // using the `_.matches` callback shorthand + * _.every(users, { 'user': 'barney', 'active': false }); + * // => false + * + * // using the `_.matchesProperty` callback shorthand + * _.every(users, 'active', false); + * // => true + * + * // using the `_.property` callback shorthand + * _.every(users, 'active'); + * // => false + */ +function every(collection, predicate, thisArg) { + var func = isArray(collection) ? arrayEvery : baseEvery; + if (thisArg && isIterateeCall(collection, predicate, thisArg)) { + predicate = null; + } + if (typeof predicate != 'function' || thisArg !== undefined) { + predicate = baseCallback(predicate, thisArg, 3); + } + return func(collection, predicate); +} + +module.exports = every; + +},{"104":104,"109":109,"154":154,"166":166,"97":97}],82:[function(_dereq_,module,exports){ +var arrayFilter = _dereq_(98), + baseCallback = _dereq_(104), + baseFilter = _dereq_(110), + isArray = _dereq_(166); + +/** + * Iterates over elements of `collection`, returning an array of all elements + * `predicate` returns truthy for. The predicate is bound to `thisArg` and + * invoked with three arguments: (value, index|key, collection). + * + * If a property name is provided for `predicate` the created `_.property` + * style callback returns the property value of the given element. + * + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style + * callback returns `true` for elements that have the properties of the given + * object, else `false`. + * + * @static + * @memberOf _ + * @alias select + * @category Collection + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function|Object|string} [predicate=_.identity] The function invoked + * per iteration. + * @param {*} [thisArg] The `this` binding of `predicate`. + * @returns {Array} Returns the new filtered array. + * @example + * + * _.filter([4, 5, 6], function(n) { + * return n % 2 == 0; + * }); + * // => [4, 6] + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } + * ]; + * + * // using the `_.matches` callback shorthand + * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user'); + * // => ['barney'] + * + * // using the `_.matchesProperty` callback shorthand + * _.pluck(_.filter(users, 'active', false), 'user'); + * // => ['fred'] + * + * // using the `_.property` callback shorthand + * _.pluck(_.filter(users, 'active'), 'user'); + * // => ['barney'] + */ +function filter(collection, predicate, thisArg) { + var func = isArray(collection) ? arrayFilter : baseFilter; + predicate = baseCallback(predicate, thisArg, 3); + return func(collection, predicate); +} + +module.exports = filter; + +},{"104":104,"110":110,"166":166,"98":98}],83:[function(_dereq_,module,exports){ +var baseEach = _dereq_(108), + createFind = _dereq_(143); + +/** + * Iterates over elements of `collection`, returning the first element + * `predicate` returns truthy for. The predicate is bound to `thisArg` and + * invoked with three arguments: (value, index|key, collection). + * + * If a property name is provided for `predicate` the created `_.property` + * style callback returns the property value of the given element. + * + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style + * callback returns `true` for elements that have the properties of the given + * object, else `false`. + * + * @static + * @memberOf _ + * @alias detect + * @category Collection + * @param {Array|Object|string} collection The collection to search. + * @param {Function|Object|string} [predicate=_.identity] The function invoked + * per iteration. + * @param {*} [thisArg] The `this` binding of `predicate`. + * @returns {*} Returns the matched element, else `undefined`. + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false }, + * { 'user': 'pebbles', 'age': 1, 'active': true } + * ]; + * + * _.result(_.find(users, function(chr) { + * return chr.age < 40; + * }), 'user'); + * // => 'barney' + * + * // using the `_.matches` callback shorthand + * _.result(_.find(users, { 'age': 1, 'active': true }), 'user'); + * // => 'pebbles' + * + * // using the `_.matchesProperty` callback shorthand + * _.result(_.find(users, 'active', false), 'user'); + * // => 'fred' + * + * // using the `_.property` callback shorthand + * _.result(_.find(users, 'active'), 'user'); + * // => 'barney' + */ +var find = createFind(baseEach); + +module.exports = find; + +},{"108":108,"143":143}],84:[function(_dereq_,module,exports){ +var arrayEach = _dereq_(96), + baseEach = _dereq_(108), + createForEach = _dereq_(144); + +/** + * Iterates over elements of `collection` invoking `iteratee` for each element. + * The `iteratee` is bound to `thisArg` and invoked with three arguments: + * (value, index|key, collection). Iteratee functions may exit iteration early + * by explicitly returning `false`. + * + * **Note:** As with other "Collections" methods, objects with a "length" property + * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn` + * may be used for object iteration. + * + * @static + * @memberOf _ + * @alias each + * @category Collection + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {Array|Object|string} Returns `collection`. + * @example + * + * _([1, 2]).forEach(function(n) { + * console.log(n); + * }).value(); + * // => logs each value from left to right and returns the array + * + * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) { + * console.log(n, key); + * }); + * // => logs each value-key pair and returns the object (iteration order is not guaranteed) + */ +var forEach = createForEach(arrayEach, baseEach); + +module.exports = forEach; + +},{"108":108,"144":144,"96":96}],85:[function(_dereq_,module,exports){ +var createAggregator = _dereq_(138); + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Creates an object composed of keys generated from the results of running + * each element of `collection` through `iteratee`. The corresponding value + * of each key is an array of the elements responsible for generating the key. + * The `iteratee` is bound to `thisArg` and invoked with three arguments: + * (value, index|key, collection). + * + * If a property name is provided for `iteratee` the created `_.property` + * style callback returns the property value of the given element. + * + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `iteratee` the created `_.matches` style + * callback returns `true` for elements that have the properties of the given + * object, else `false`. + * + * @static + * @memberOf _ + * @category Collection + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function|Object|string} [iteratee=_.identity] The function invoked + * per iteration. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.groupBy([4.2, 6.1, 6.4], function(n) { + * return Math.floor(n); + * }); + * // => { '4': [4.2], '6': [6.1, 6.4] } + * + * _.groupBy([4.2, 6.1, 6.4], function(n) { + * return this.floor(n); + * }, Math); + * // => { '4': [4.2], '6': [6.1, 6.4] } + * + * // using the `_.property` callback shorthand + * _.groupBy(['one', 'two', 'three'], 'length'); + * // => { '3': ['one', 'two'], '5': ['three'] } + */ +var groupBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + result[key].push(value); + } else { + result[key] = [value]; + } +}); + +module.exports = groupBy; + +},{"138":138}],86:[function(_dereq_,module,exports){ +var baseIndexOf = _dereq_(118), + getLength = _dereq_(149), + isArray = _dereq_(166), + isIterateeCall = _dereq_(154), + isLength = _dereq_(156), + isString = _dereq_(172), + values = _dereq_(181); + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeMax = Math.max; + +/** + * Checks if `value` is in `collection` using + * [`SameValueZero`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it is used as the offset + * from the end of `collection`. + * + * @static + * @memberOf _ + * @alias contains, include + * @category Collection + * @param {Array|Object|string} collection The collection to search. + * @param {*} target The value to search for. + * @param {number} [fromIndex=0] The index to search from. + * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`. + * @returns {boolean} Returns `true` if a matching element is found, else `false`. + * @example + * + * _.includes([1, 2, 3], 1); + * // => true + * + * _.includes([1, 2, 3], 1, 2); + * // => false + * + * _.includes({ 'user': 'fred', 'age': 40 }, 'fred'); + * // => true + * + * _.includes('pebbles', 'eb'); + * // => true + */ +function includes(collection, target, fromIndex, guard) { + var length = collection ? getLength(collection) : 0; + if (!isLength(length)) { + collection = values(collection); + length = collection.length; + } + if (!length) { + return false; + } + if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) { + fromIndex = 0; + } else { + fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0); + } + return (typeof collection == 'string' || !isArray(collection) && isString(collection)) + ? (fromIndex < length && collection.indexOf(target, fromIndex) > -1) + : (baseIndexOf(collection, target, fromIndex) > -1); +} + +module.exports = includes; + +},{"118":118,"149":149,"154":154,"156":156,"166":166,"172":172,"181":181}],87:[function(_dereq_,module,exports){ +var arrayMap = _dereq_(99), + baseCallback = _dereq_(104), + baseMap = _dereq_(123), + isArray = _dereq_(166); + +/** + * Creates an array of values by running each element in `collection` through + * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three + * arguments: (value, index|key, collection). + * + * If a property name is provided for `iteratee` the created `_.property` + * style callback returns the property value of the given element. + * + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `iteratee` the created `_.matches` style + * callback returns `true` for elements that have the properties of the given + * object, else `false`. + * + * Many lodash methods are guarded to work as interatees for methods like + * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. + * + * The guarded methods are: + * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`, + * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`, + * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`, + * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`, + * `sum`, `uniq`, and `words` + * + * @static + * @memberOf _ + * @alias collect + * @category Collection + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function|Object|string} [iteratee=_.identity] The function invoked + * per iteration. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {Array} Returns the new mapped array. + * @example + * + * function timesThree(n) { + * return n * 3; + * } + * + * _.map([1, 2], timesThree); + * // => [3, 6] + * + * _.map({ 'a': 1, 'b': 2 }, timesThree); + * // => [3, 6] (iteration order is not guaranteed) + * + * var users = [ + * { 'user': 'barney' }, + * { 'user': 'fred' } + * ]; + * + * // using the `_.property` callback shorthand + * _.map(users, 'user'); + * // => ['barney', 'fred'] + */ +function map(collection, iteratee, thisArg) { + var func = isArray(collection) ? arrayMap : baseMap; + iteratee = baseCallback(iteratee, thisArg, 3); + return func(collection, iteratee); +} + +module.exports = map; + +},{"104":104,"123":123,"166":166,"99":99}],88:[function(_dereq_,module,exports){ +var arrayReduce = _dereq_(100), + baseEach = _dereq_(108), + createReduce = _dereq_(145); + +/** + * Reduces `collection` to a value which is the accumulated result of running + * each element in `collection` through `iteratee`, where each successive + * invocation is supplied the return value of the previous. If `accumulator` + * is not provided the first element of `collection` is used as the initial + * value. The `iteratee` is bound to `thisArg` and invoked with four arguments: + * (accumulator, value, index|key, collection). + * + * Many lodash methods are guarded to work as interatees for methods like + * `_.reduce`, `_.reduceRight`, and `_.transform`. + * + * The guarded methods are: + * `assign`, `defaults`, `includes`, `merge`, `sortByAll`, and `sortByOrder` + * + * @static + * @memberOf _ + * @alias foldl, inject + * @category Collection + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {*} [thisArg] The `this` binding of `iteratee`. + * @returns {*} Returns the accumulated value. + * @example + * + * _.reduce([1, 2], function(total, n) { + * return total + n; + * }); + * // => 3 + * + * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) { + * result[key] = n * 3; + * return result; + * }, {}); + * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed) + */ +var reduce = createReduce(arrayReduce, baseEach); + +module.exports = reduce; + +},{"100":100,"108":108,"145":145}],89:[function(_dereq_,module,exports){ +var arraySome = _dereq_(101), + baseCallback = _dereq_(104), + baseSome = _dereq_(132), + isArray = _dereq_(166), + isIterateeCall = _dereq_(154); + +/** + * Checks if `predicate` returns truthy for **any** element of `collection`. + * The function returns as soon as it finds a passing value and does not iterate + * over the entire collection. The predicate is bound to `thisArg` and invoked + * with three arguments: (value, index|key, collection). + * + * If a property name is provided for `predicate` the created `_.property` + * style callback returns the property value of the given element. + * + * If a value is also provided for `thisArg` the created `_.matchesProperty` + * style callback returns `true` for elements that have a matching property + * value, else `false`. + * + * If an object is provided for `predicate` the created `_.matches` style + * callback returns `true` for elements that have the properties of the given + * object, else `false`. + * + * @static + * @memberOf _ + * @alias any + * @category Collection + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function|Object|string} [predicate=_.identity] The function invoked + * per iteration. + * @param {*} [thisArg] The `this` binding of `predicate`. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + * @example + * + * _.some([null, 0, 'yes', false], Boolean); + * // => true + * + * var users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false } + * ]; + * + * // using the `_.matches` callback shorthand + * _.some(users, { 'user': 'barney', 'active': false }); + * // => false + * + * // using the `_.matchesProperty` callback shorthand + * _.some(users, 'active', false); + * // => true + * + * // using the `_.property` callback shorthand + * _.some(users, 'active'); + * // => true + */ +function some(collection, predicate, thisArg) { + var func = isArray(collection) ? arraySome : baseSome; + if (thisArg && isIterateeCall(collection, predicate, thisArg)) { + predicate = null; + } + if (typeof predicate != 'function' || thisArg !== undefined) { + predicate = baseCallback(predicate, thisArg, 3); + } + return func(collection, predicate); +} + +module.exports = some; + +},{"101":101,"104":104,"132":132,"154":154,"166":166}],90:[function(_dereq_,module,exports){ +var isNative = _dereq_(168); + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeNow = isNative(nativeNow = Date.now) && nativeNow; + +/** + * Gets the number of milliseconds that have elapsed since the Unix epoch + * (1 January 1970 00:00:00 UTC). + * + * @static + * @memberOf _ + * @category Date + * @example + * + * _.defer(function(stamp) { + * console.log(_.now() - stamp); + * }, _.now()); + * // => logs the number of milliseconds it took for the deferred function to be invoked + */ +var now = nativeNow || function() { + return new Date().getTime(); +}; + +module.exports = now; + +},{"168":168}],91:[function(_dereq_,module,exports){ +var isObject = _dereq_(170), + now = _dereq_(90); + +/** Used as the `TypeError` message for "Functions" methods. */ +var FUNC_ERROR_TEXT = 'Expected a function'; + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeMax = Math.max; + +/** + * Creates a function that delays invoking `func` until after `wait` milliseconds + * have elapsed since the last time it was invoked. The created function comes + * with a `cancel` method to cancel delayed invocations. Provide an options + * object to indicate that `func` should be invoked on the leading and/or + * trailing edge of the `wait` timeout. Subsequent calls to the debounced + * function return the result of the last `func` invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked + * on the trailing edge of the timeout only if the the debounced function is + * invoked more than once during the `wait` timeout. + * + * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation) + * for details over the differences between `_.debounce` and `_.throttle`. + * + * @static + * @memberOf _ + * @category Function + * @param {Function} func The function to debounce. + * @param {number} [wait=0] The number of milliseconds to delay. + * @param {Object} [options] The options object. + * @param {boolean} [options.leading=false] Specify invoking on the leading + * edge of the timeout. + * @param {number} [options.maxWait] The maximum time `func` is allowed to be + * delayed before it is invoked. + * @param {boolean} [options.trailing=true] Specify invoking on the trailing + * edge of the timeout. + * @returns {Function} Returns the new debounced function. + * @example + * + * // avoid costly calculations while the window size is in flux + * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); + * + * // invoke `sendMail` when the click event is fired, debouncing subsequent calls + * jQuery('#postbox').on('click', _.debounce(sendMail, 300, { + * 'leading': true, + * 'trailing': false + * })); + * + * // ensure `batchLog` is invoked once after 1 second of debounced calls + * var source = new EventSource('/stream'); + * jQuery(source).on('message', _.debounce(batchLog, 250, { + * 'maxWait': 1000 + * })); + * + * // cancel a debounced call + * var todoChanges = _.debounce(batchLog, 1000); + * Object.observe(models.todo, todoChanges); + * + * Object.observe(models, function(changes) { + * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) { + * todoChanges.cancel(); + * } + * }, ['delete']); + * + * // ...at some point `models.todo` is changed + * models.todo.completed = true; + * + * // ...before 1 second has passed `models.todo` is deleted + * // which cancels the debounced `todoChanges` call + * delete models.todo; + */ +function debounce(func, wait, options) { + var args, + maxTimeoutId, + result, + stamp, + thisArg, + timeoutId, + trailingCall, + lastCalled = 0, + maxWait = false, + trailing = true; + + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + wait = wait < 0 ? 0 : (+wait || 0); + if (options === true) { + var leading = true; + trailing = false; + } else if (isObject(options)) { + leading = options.leading; + maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait); + trailing = 'trailing' in options ? options.trailing : trailing; + } + + function cancel() { + if (timeoutId) { + clearTimeout(timeoutId); + } + if (maxTimeoutId) { + clearTimeout(maxTimeoutId); + } + maxTimeoutId = timeoutId = trailingCall = undefined; + } + + function delayed() { + var remaining = wait - (now() - stamp); + if (remaining <= 0 || remaining > wait) { + if (maxTimeoutId) { + clearTimeout(maxTimeoutId); + } + var isCalled = trailingCall; + maxTimeoutId = timeoutId = trailingCall = undefined; + if (isCalled) { + lastCalled = now(); + result = func.apply(thisArg, args); + if (!timeoutId && !maxTimeoutId) { + args = thisArg = null; + } + } + } else { + timeoutId = setTimeout(delayed, remaining); + } + } + + function maxDelayed() { + if (timeoutId) { + clearTimeout(timeoutId); + } + maxTimeoutId = timeoutId = trailingCall = undefined; + if (trailing || (maxWait !== wait)) { + lastCalled = now(); + result = func.apply(thisArg, args); + if (!timeoutId && !maxTimeoutId) { + args = thisArg = null; + } + } + } + + function debounced() { + args = arguments; + stamp = now(); + thisArg = this; + trailingCall = trailing && (timeoutId || !leading); + + if (maxWait === false) { + var leadingCall = leading && !timeoutId; + } else { + if (!maxTimeoutId && !leading) { + lastCalled = stamp; + } + var remaining = maxWait - (stamp - lastCalled), + isCalled = remaining <= 0 || remaining > maxWait; + + if (isCalled) { + if (maxTimeoutId) { + maxTimeoutId = clearTimeout(maxTimeoutId); + } + lastCalled = stamp; + result = func.apply(thisArg, args); + } + else if (!maxTimeoutId) { + maxTimeoutId = setTimeout(maxDelayed, remaining); + } + } + if (isCalled && timeoutId) { + timeoutId = clearTimeout(timeoutId); + } + else if (!timeoutId && wait !== maxWait) { + timeoutId = setTimeout(delayed, wait); + } + if (leadingCall) { + isCalled = true; + result = func.apply(thisArg, args); + } + if (isCalled && !timeoutId && !maxTimeoutId) { + args = thisArg = null; + } + return result; + } + debounced.cancel = cancel; + return debounced; +} + +module.exports = debounce; + +},{"170":170,"90":90}],92:[function(_dereq_,module,exports){ +var baseDelay = _dereq_(106), + restParam = _dereq_(93); + +/** + * Defers invoking the `func` until the current call stack has cleared. Any + * additional arguments are provided to `func` when it is invoked. + * + * @static + * @memberOf _ + * @category Function + * @param {Function} func The function to defer. + * @param {...*} [args] The arguments to invoke the function with. + * @returns {number} Returns the timer id. + * @example + * + * _.defer(function(text) { + * console.log(text); + * }, 'deferred'); + * // logs 'deferred' after one or more milliseconds + */ +var defer = restParam(function(func, args) { + return baseDelay(func, 1, args); +}); + +module.exports = defer; + +},{"106":106,"93":93}],93:[function(_dereq_,module,exports){ +/** Used as the `TypeError` message for "Functions" methods. */ +var FUNC_ERROR_TEXT = 'Expected a function'; + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeMax = Math.max; + +/** + * Creates a function that invokes `func` with the `this` binding of the + * created function and arguments from `start` and beyond provided as an array. + * + * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/rest_parameters). + * + * @static + * @memberOf _ + * @category Function + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @returns {Function} Returns the new function. + * @example + * + * var say = _.restParam(function(what, names) { + * return what + ' ' + _.initial(names).join(', ') + + * (_.size(names) > 1 ? ', & ' : '') + _.last(names); + * }); + * + * say('hello', 'fred', 'barney', 'pebbles'); + * // => 'hello fred, barney, & pebbles' + */ +function restParam(func, start) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0); + return function() { + var args = arguments, + index = -1, + length = nativeMax(args.length - start, 0), + rest = Array(length); + + while (++index < length) { + rest[index] = args[start + index]; + } + switch (start) { + case 0: return func.call(this, rest); + case 1: return func.call(this, args[0], rest); + case 2: return func.call(this, args[0], args[1], rest); + } + var otherArgs = Array(start + 1); + index = -1; + while (++index < start) { + otherArgs[index] = args[index]; + } + otherArgs[start] = rest; + return func.apply(this, otherArgs); + }; +} + +module.exports = restParam; + +},{}],94:[function(_dereq_,module,exports){ +(function (global){ +var cachePush = _dereq_(137), + isNative = _dereq_(168); + +/** Native method references. */ +var Set = isNative(Set = global.Set) && Set; + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate; + +/** + * + * Creates a cache object to store unique values. + * + * @private + * @param {Array} [values] The values to cache. + */ +function SetCache(values) { + var length = values ? values.length : 0; + + this.data = { 'hash': nativeCreate(null), 'set': new Set }; + while (length--) { + this.push(values[length]); + } +} + +// Add functions to the `Set` cache. +SetCache.prototype.push = cachePush; + +module.exports = SetCache; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{"137":137,"168":168}],95:[function(_dereq_,module,exports){ +/** + * Copies the values of `source` to `array`. + * + * @private + * @param {Array} source The array to copy values from. + * @param {Array} [array=[]] The array to copy values to. + * @returns {Array} Returns `array`. + */ +function arrayCopy(source, array) { + var index = -1, + length = source.length; + + array || (array = Array(length)); + while (++index < length) { + array[index] = source[index]; + } + return array; +} + +module.exports = arrayCopy; + +},{}],96:[function(_dereq_,module,exports){ +/** + * A specialized version of `_.forEach` for arrays without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ +function arrayEach(array, iteratee) { + var index = -1, + length = array.length; + + while (++index < length) { + if (iteratee(array[index], index, array) === false) { + break; + } + } + return array; +} + +module.exports = arrayEach; + +},{}],97:[function(_dereq_,module,exports){ +/** + * A specialized version of `_.every` for arrays without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. + */ +function arrayEvery(array, predicate) { + var index = -1, + length = array.length; + + while (++index < length) { + if (!predicate(array[index], index, array)) { + return false; + } + } + return true; +} + +module.exports = arrayEvery; + +},{}],98:[function(_dereq_,module,exports){ +/** + * A specialized version of `_.filter` for arrays without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + */ +function arrayFilter(array, predicate) { + var index = -1, + length = array.length, + resIndex = -1, + result = []; + + while (++index < length) { + var value = array[index]; + if (predicate(value, index, array)) { + result[++resIndex] = value; + } + } + return result; +} + +module.exports = arrayFilter; + +},{}],99:[function(_dereq_,module,exports){ +/** + * A specialized version of `_.map` for arrays without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ +function arrayMap(array, iteratee) { + var index = -1, + length = array.length, + result = Array(length); + + while (++index < length) { + result[index] = iteratee(array[index], index, array); + } + return result; +} + +module.exports = arrayMap; + +},{}],100:[function(_dereq_,module,exports){ +/** + * A specialized version of `_.reduce` for arrays without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initFromArray] Specify using the first element of `array` + * as the initial value. + * @returns {*} Returns the accumulated value. + */ +function arrayReduce(array, iteratee, accumulator, initFromArray) { + var index = -1, + length = array.length; + + if (initFromArray && length) { + accumulator = array[++index]; + } + while (++index < length) { + accumulator = iteratee(accumulator, array[index], index, array); + } + return accumulator; +} + +module.exports = arrayReduce; + +},{}],101:[function(_dereq_,module,exports){ +/** + * A specialized version of `_.some` for arrays without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + */ +function arraySome(array, predicate) { + var index = -1, + length = array.length; + + while (++index < length) { + if (predicate(array[index], index, array)) { + return true; + } + } + return false; +} + +module.exports = arraySome; + +},{}],102:[function(_dereq_,module,exports){ +var getSymbols = _dereq_(150), + keys = _dereq_(176); + +/** Used for native method references. */ +var arrayProto = Array.prototype; + +/** Native method references. */ +var push = arrayProto.push; + +/** + * A specialized version of `_.assign` for customizing assigned values without + * support for argument juggling, multiple sources, and `this` binding `customizer` + * functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {Function} customizer The function to customize assigned values. + * @returns {Object} Returns `object`. + */ +function assignWith(object, source, customizer) { + var props = keys(source); + push.apply(props, getSymbols(source)); + + var index = -1, + length = props.length; + + while (++index < length) { + var key = props[index], + value = object[key], + result = customizer(value, source[key], key, object, source); + + if ((result === result ? (result !== value) : (value === value)) || + (value === undefined && !(key in object))) { + object[key] = result; + } + } + return object; +} + +module.exports = assignWith; + +},{"150":150,"176":176}],103:[function(_dereq_,module,exports){ +var baseCopy = _dereq_(105), + getSymbols = _dereq_(150), + isNative = _dereq_(168), + keys = _dereq_(176); + +/** Native method references. */ +var preventExtensions = isNative(preventExtensions = Object.preventExtensions) && preventExtensions; + +/** Used as `baseAssign`. */ +var nativeAssign = (function() { + // Avoid `Object.assign` in Firefox 34-37 which have an early implementation + // with a now defunct try/catch behavior. See https://bugzilla.mozilla.org/show_bug.cgi?id=1103344 + // for more details. + // + // Use `Object.preventExtensions` on a plain object instead of simply using + // `Object('x')` because Chrome and IE fail to throw an error when attempting + // to assign values to readonly indexes of strings. + var func = preventExtensions && isNative(func = Object.assign) && func; + try { + if (func) { + var object = preventExtensions({ '1': 0 }); + object[0] = 1; + } + } catch(e) { + // Only attempt in strict mode. + try { func(object, 'xo'); } catch(e) {} + return !object[1] && func; + } + return false; +}()); + +/** + * The base implementation of `_.assign` without support for argument juggling, + * multiple sources, and `customizer` functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @returns {Object} Returns `object`. + */ +var baseAssign = nativeAssign || function(object, source) { + return source == null + ? object + : baseCopy(source, getSymbols(source), baseCopy(source, keys(source), object)); +}; + +module.exports = baseAssign; + +},{"105":105,"150":150,"168":168,"176":176}],104:[function(_dereq_,module,exports){ +var baseMatches = _dereq_(124), + baseMatchesProperty = _dereq_(125), + bindCallback = _dereq_(135), + identity = _dereq_(185), + property = _dereq_(186); + +/** + * The base implementation of `_.callback` which supports specifying the + * number of arguments to provide to `func`. + * + * @private + * @param {*} [func=_.identity] The value to convert to a callback. + * @param {*} [thisArg] The `this` binding of `func`. + * @param {number} [argCount] The number of arguments to provide to `func`. + * @returns {Function} Returns the callback. + */ +function baseCallback(func, thisArg, argCount) { + var type = typeof func; + if (type == 'function') { + return thisArg === undefined + ? func + : bindCallback(func, thisArg, argCount); + } + if (func == null) { + return identity; + } + if (type == 'object') { + return baseMatches(func); + } + return thisArg === undefined + ? property(func) + : baseMatchesProperty(func, thisArg); +} + +module.exports = baseCallback; + +},{"124":124,"125":125,"135":135,"185":185,"186":186}],105:[function(_dereq_,module,exports){ +/** + * Copies properties of `source` to `object`. + * + * @private + * @param {Object} source The object to copy properties from. + * @param {Array} props The property names to copy. + * @param {Object} [object={}] The object to copy properties to. + * @returns {Object} Returns `object`. + */ +function baseCopy(source, props, object) { + object || (object = {}); + + var index = -1, + length = props.length; + + while (++index < length) { + var key = props[index]; + object[key] = source[key]; + } + return object; +} + +module.exports = baseCopy; + +},{}],106:[function(_dereq_,module,exports){ +/** Used as the `TypeError` message for "Functions" methods. */ +var FUNC_ERROR_TEXT = 'Expected a function'; + +/** + * The base implementation of `_.delay` and `_.defer` which accepts an index + * of where to slice the arguments to provide to `func`. + * + * @private + * @param {Function} func The function to delay. + * @param {number} wait The number of milliseconds to delay invocation. + * @param {Object} args The arguments provide to `func`. + * @returns {number} Returns the timer id. + */ +function baseDelay(func, wait, args) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + return setTimeout(function() { func.apply(undefined, args); }, wait); +} + +module.exports = baseDelay; + +},{}],107:[function(_dereq_,module,exports){ +var baseIndexOf = _dereq_(118), + cacheIndexOf = _dereq_(136), + createCache = _dereq_(142); + +/** + * The base implementation of `_.difference` which accepts a single array + * of values to exclude. + * + * @private + * @param {Array} array The array to inspect. + * @param {Array} values The values to exclude. + * @returns {Array} Returns the new array of filtered values. + */ +function baseDifference(array, values) { + var length = array ? array.length : 0, + result = []; + + if (!length) { + return result; + } + var index = -1, + indexOf = baseIndexOf, + isCommon = true, + cache = (isCommon && values.length >= 200) ? createCache(values) : null, + valuesLength = values.length; + + if (cache) { + indexOf = cacheIndexOf; + isCommon = false; + values = cache; + } + outer: + while (++index < length) { + var value = array[index]; + + if (isCommon && value === value) { + var valuesIndex = valuesLength; + while (valuesIndex--) { + if (values[valuesIndex] === value) { + continue outer; + } + } + result.push(value); + } + else if (indexOf(values, value, 0) < 0) { + result.push(value); + } + } + return result; +} + +module.exports = baseDifference; + +},{"118":118,"136":136,"142":142}],108:[function(_dereq_,module,exports){ +var baseForOwn = _dereq_(116), + createBaseEach = _dereq_(140); + +/** + * The base implementation of `_.forEach` without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object|string} Returns `collection`. + */ +var baseEach = createBaseEach(baseForOwn); + +module.exports = baseEach; + +},{"116":116,"140":140}],109:[function(_dereq_,module,exports){ +var baseEach = _dereq_(108); + +/** + * The base implementation of `_.every` without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false` + */ +function baseEvery(collection, predicate) { + var result = true; + baseEach(collection, function(value, index, collection) { + result = !!predicate(value, index, collection); + return result; + }); + return result; +} + +module.exports = baseEvery; + +},{"108":108}],110:[function(_dereq_,module,exports){ +var baseEach = _dereq_(108); + +/** + * The base implementation of `_.filter` without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + */ +function baseFilter(collection, predicate) { + var result = []; + baseEach(collection, function(value, index, collection) { + if (predicate(value, index, collection)) { + result.push(value); + } + }); + return result; +} + +module.exports = baseFilter; + +},{"108":108}],111:[function(_dereq_,module,exports){ +/** + * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`, + * without support for callback shorthands and `this` binding, which iterates + * over `collection` using the provided `eachFunc`. + * + * @private + * @param {Array|Object|string} collection The collection to search. + * @param {Function} predicate The function invoked per iteration. + * @param {Function} eachFunc The function to iterate over `collection`. + * @param {boolean} [retKey] Specify returning the key of the found element + * instead of the element itself. + * @returns {*} Returns the found element or its key, else `undefined`. + */ +function baseFind(collection, predicate, eachFunc, retKey) { + var result; + eachFunc(collection, function(value, key, collection) { + if (predicate(value, key, collection)) { + result = retKey ? key : value; + return false; + } + }); + return result; +} + +module.exports = baseFind; + +},{}],112:[function(_dereq_,module,exports){ +/** + * The base implementation of `_.findIndex` and `_.findLastIndex` without + * support for callback shorthands and `this` binding. + * + * @private + * @param {Array} array The array to search. + * @param {Function} predicate The function invoked per iteration. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function baseFindIndex(array, predicate, fromRight) { + var length = array.length, + index = fromRight ? length : -1; + + while ((fromRight ? index-- : ++index < length)) { + if (predicate(array[index], index, array)) { + return index; + } + } + return -1; +} + +module.exports = baseFindIndex; + +},{}],113:[function(_dereq_,module,exports){ +var isArguments = _dereq_(165), + isArray = _dereq_(166), + isArrayLike = _dereq_(152), + isObjectLike = _dereq_(157); + +/** + * The base implementation of `_.flatten` with added support for restricting + * flattening and specifying the start index. + * + * @private + * @param {Array} array The array to flatten. + * @param {boolean} [isDeep] Specify a deep flatten. + * @param {boolean} [isStrict] Restrict flattening to arrays-like objects. + * @returns {Array} Returns the new flattened array. + */ +function baseFlatten(array, isDeep, isStrict) { + var index = -1, + length = array.length, + resIndex = -1, + result = []; + + while (++index < length) { + var value = array[index]; + if (isObjectLike(value) && isArrayLike(value) && + (isStrict || isArray(value) || isArguments(value))) { + if (isDeep) { + // Recursively flatten arrays (susceptible to call stack limits). + value = baseFlatten(value, isDeep, isStrict); + } + var valIndex = -1, + valLength = value.length; + + while (++valIndex < valLength) { + result[++resIndex] = value[valIndex]; + } + } else if (!isStrict) { + result[++resIndex] = value; + } + } + return result; +} + +module.exports = baseFlatten; + +},{"152":152,"157":157,"165":165,"166":166}],114:[function(_dereq_,module,exports){ +var createBaseFor = _dereq_(141); + +/** + * The base implementation of `baseForIn` and `baseForOwn` which iterates + * over `object` properties returned by `keysFunc` invoking `iteratee` for + * each property. Iteratee functions may exit iteration early by explicitly + * returning `false`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ +var baseFor = createBaseFor(); + +module.exports = baseFor; + +},{"141":141}],115:[function(_dereq_,module,exports){ +var baseFor = _dereq_(114), + keysIn = _dereq_(177); + +/** + * The base implementation of `_.forIn` without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ +function baseForIn(object, iteratee) { + return baseFor(object, iteratee, keysIn); +} + +module.exports = baseForIn; + +},{"114":114,"177":177}],116:[function(_dereq_,module,exports){ +var baseFor = _dereq_(114), + keys = _dereq_(176); + +/** + * The base implementation of `_.forOwn` without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ +function baseForOwn(object, iteratee) { + return baseFor(object, iteratee, keys); +} + +module.exports = baseForOwn; + +},{"114":114,"176":176}],117:[function(_dereq_,module,exports){ +var toObject = _dereq_(163); + +/** + * The base implementation of `get` without support for string paths + * and default values. + * + * @private + * @param {Object} object The object to query. + * @param {Array} path The path of the property to get. + * @param {string} [pathKey] The key representation of path. + * @returns {*} Returns the resolved value. + */ +function baseGet(object, path, pathKey) { + if (object == null) { + return; + } + if (pathKey !== undefined && pathKey in toObject(object)) { + path = [pathKey]; + } + var index = -1, + length = path.length; + + while (object != null && ++index < length) { + object = object[path[index]]; + } + return (index && index == length) ? object : undefined; +} + +module.exports = baseGet; + +},{"163":163}],118:[function(_dereq_,module,exports){ +var indexOfNaN = _dereq_(151); + +/** + * The base implementation of `_.indexOf` without support for binary searches. + * + * @private + * @param {Array} array The array to search. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ +function baseIndexOf(array, value, fromIndex) { + if (value !== value) { + return indexOfNaN(array, fromIndex); + } + var index = fromIndex - 1, + length = array.length; + + while (++index < length) { + if (array[index] === value) { + return index; + } + } + return -1; +} + +module.exports = baseIndexOf; + +},{"151":151}],119:[function(_dereq_,module,exports){ +var baseIsEqualDeep = _dereq_(120); + +/** + * The base implementation of `_.isEqual` without support for `this` binding + * `customizer` functions. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @param {Function} [customizer] The function to customize comparing values. + * @param {boolean} [isLoose] Specify performing partial comparisons. + * @param {Array} [stackA] Tracks traversed `value` objects. + * @param {Array} [stackB] Tracks traversed `other` objects. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + */ +function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) { + // Exit early for identical values. + if (value === other) { + return true; + } + var valType = typeof value, + othType = typeof other; + + // Exit early for unlike primitive values. + if ((valType != 'function' && valType != 'object' && othType != 'function' && othType != 'object') || + value == null || other == null) { + // Return `false` unless both values are `NaN`. + return value !== value && other !== other; + } + return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB); +} + +module.exports = baseIsEqual; + +},{"120":120}],120:[function(_dereq_,module,exports){ +var equalArrays = _dereq_(146), + equalByTag = _dereq_(147), + equalObjects = _dereq_(148), + isArray = _dereq_(166), + isTypedArray = _dereq_(173); + +/** `Object#toString` result references. */ +var argsTag = '[object Arguments]', + arrayTag = '[object Array]', + objectTag = '[object Object]'; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** + * A specialized version of `baseIsEqual` for arrays and objects which performs + * deep comparisons and tracks traversed objects enabling objects with circular + * references to be compared. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Function} [customizer] The function to customize comparing objects. + * @param {boolean} [isLoose] Specify performing partial comparisons. + * @param {Array} [stackA=[]] Tracks traversed `value` objects. + * @param {Array} [stackB=[]] Tracks traversed `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ +function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) { + var objIsArr = isArray(object), + othIsArr = isArray(other), + objTag = arrayTag, + othTag = arrayTag; + + if (!objIsArr) { + objTag = objToString.call(object); + if (objTag == argsTag) { + objTag = objectTag; + } else if (objTag != objectTag) { + objIsArr = isTypedArray(object); + } + } + if (!othIsArr) { + othTag = objToString.call(other); + if (othTag == argsTag) { + othTag = objectTag; + } else if (othTag != objectTag) { + othIsArr = isTypedArray(other); + } + } + var objIsObj = objTag == objectTag, + othIsObj = othTag == objectTag, + isSameTag = objTag == othTag; + + if (isSameTag && !(objIsArr || objIsObj)) { + return equalByTag(object, other, objTag); + } + if (!isLoose) { + var valWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), + othWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); + + if (valWrapped || othWrapped) { + return equalFunc(valWrapped ? object.value() : object, othWrapped ? other.value() : other, customizer, isLoose, stackA, stackB); + } + } + if (!isSameTag) { + return false; + } + // Assume cyclic values are equal. + // For more information on detecting circular references see https://es5.github.io/#JO. + stackA || (stackA = []); + stackB || (stackB = []); + + var length = stackA.length; + while (length--) { + if (stackA[length] == object) { + return stackB[length] == other; + } + } + // Add `object` and `other` to the stack of traversed objects. + stackA.push(object); + stackB.push(other); + + var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB); + + stackA.pop(); + stackB.pop(); + + return result; +} + +module.exports = baseIsEqualDeep; + +},{"146":146,"147":147,"148":148,"166":166,"173":173}],121:[function(_dereq_,module,exports){ +/** + * The base implementation of `_.isFunction` without support for environments + * with incorrect `typeof` results. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + */ +function baseIsFunction(value) { + // Avoid a Chakra JIT bug in compatibility modes of IE 11. + // See https://github.com/jashkenas/underscore/issues/1621 for more details. + return typeof value == 'function' || false; +} + +module.exports = baseIsFunction; + +},{}],122:[function(_dereq_,module,exports){ +var baseIsEqual = _dereq_(119); + +/** + * The base implementation of `_.isMatch` without support for callback + * shorthands and `this` binding. + * + * @private + * @param {Object} object The object to inspect. + * @param {Array} props The source property names to match. + * @param {Array} values The source values to match. + * @param {Array} strictCompareFlags Strict comparison flags for source values. + * @param {Function} [customizer] The function to customize comparing objects. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + */ +function baseIsMatch(object, props, values, strictCompareFlags, customizer) { + var index = -1, + length = props.length, + noCustomizer = !customizer; + + while (++index < length) { + if ((noCustomizer && strictCompareFlags[index]) + ? values[index] !== object[props[index]] + : !(props[index] in object) + ) { + return false; + } + } + index = -1; + while (++index < length) { + var key = props[index], + objValue = object[key], + srcValue = values[index]; + + if (noCustomizer && strictCompareFlags[index]) { + var result = objValue !== undefined || (key in object); + } else { + result = customizer ? customizer(objValue, srcValue, key) : undefined; + if (result === undefined) { + result = baseIsEqual(srcValue, objValue, customizer, true); + } + } + if (!result) { + return false; + } + } + return true; +} + +module.exports = baseIsMatch; + +},{"119":119}],123:[function(_dereq_,module,exports){ +var baseEach = _dereq_(108), + isArrayLike = _dereq_(152); + +/** + * The base implementation of `_.map` without support for callback shorthands + * and `this` binding. + * + * @private + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ +function baseMap(collection, iteratee) { + var index = -1, + result = isArrayLike(collection) ? Array(collection.length) : []; + + baseEach(collection, function(value, key, collection) { + result[++index] = iteratee(value, key, collection); + }); + return result; +} + +module.exports = baseMap; + +},{"108":108,"152":152}],124:[function(_dereq_,module,exports){ +var baseIsMatch = _dereq_(122), + constant = _dereq_(184), + isStrictComparable = _dereq_(158), + keys = _dereq_(176), + toObject = _dereq_(163); + +/** + * The base implementation of `_.matches` which does not clone `source`. + * + * @private + * @param {Object} source The object of property values to match. + * @returns {Function} Returns the new function. + */ +function baseMatches(source) { + var props = keys(source), + length = props.length; + + if (!length) { + return constant(true); + } + if (length == 1) { + var key = props[0], + value = source[key]; + + if (isStrictComparable(value)) { + return function(object) { + if (object == null) { + return false; + } + return object[key] === value && (value !== undefined || (key in toObject(object))); + }; + } + } + var values = Array(length), + strictCompareFlags = Array(length); + + while (length--) { + value = source[props[length]]; + values[length] = value; + strictCompareFlags[length] = isStrictComparable(value); + } + return function(object) { + return object != null && baseIsMatch(toObject(object), props, values, strictCompareFlags); + }; +} + +module.exports = baseMatches; + +},{"122":122,"158":158,"163":163,"176":176,"184":184}],125:[function(_dereq_,module,exports){ +var baseGet = _dereq_(117), + baseIsEqual = _dereq_(119), + baseSlice = _dereq_(131), + isArray = _dereq_(166), + isKey = _dereq_(155), + isStrictComparable = _dereq_(158), + last = _dereq_(80), + toObject = _dereq_(163), + toPath = _dereq_(164); + +/** + * The base implementation of `_.matchesProperty` which does not which does + * not clone `value`. + * + * @private + * @param {string} path The path of the property to get. + * @param {*} value The value to compare. + * @returns {Function} Returns the new function. + */ +function baseMatchesProperty(path, value) { + var isArr = isArray(path), + isCommon = isKey(path) && isStrictComparable(value), + pathKey = (path + ''); + + path = toPath(path); + return function(object) { + if (object == null) { + return false; + } + var key = pathKey; + object = toObject(object); + if ((isArr || !isCommon) && !(key in object)) { + object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1)); + if (object == null) { + return false; + } + key = last(path); + object = toObject(object); + } + return object[key] === value + ? (value !== undefined || (key in object)) + : baseIsEqual(value, object[key], null, true); + }; +} + +module.exports = baseMatchesProperty; + +},{"117":117,"119":119,"131":131,"155":155,"158":158,"163":163,"164":164,"166":166,"80":80}],126:[function(_dereq_,module,exports){ +var arrayEach = _dereq_(96), + baseMergeDeep = _dereq_(127), + getSymbols = _dereq_(150), + isArray = _dereq_(166), + isArrayLike = _dereq_(152), + isObject = _dereq_(170), + isObjectLike = _dereq_(157), + isTypedArray = _dereq_(173), + keys = _dereq_(176); + +/** Used for native method references. */ +var arrayProto = Array.prototype; + +/** Native method references. */ +var push = arrayProto.push; + +/** + * The base implementation of `_.merge` without support for argument juggling, + * multiple sources, and `this` binding `customizer` functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {Function} [customizer] The function to customize merging properties. + * @param {Array} [stackA=[]] Tracks traversed source objects. + * @param {Array} [stackB=[]] Associates values with source counterparts. + * @returns {Object} Returns `object`. + */ +function baseMerge(object, source, customizer, stackA, stackB) { + if (!isObject(object)) { + return object; + } + var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)); + if (!isSrcArr) { + var props = keys(source); + push.apply(props, getSymbols(source)); + } + arrayEach(props || source, function(srcValue, key) { + if (props) { + key = srcValue; + srcValue = source[key]; + } + if (isObjectLike(srcValue)) { + stackA || (stackA = []); + stackB || (stackB = []); + baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB); + } + else { + var value = object[key], + result = customizer ? customizer(value, srcValue, key, object, source) : undefined, + isCommon = result === undefined; + + if (isCommon) { + result = srcValue; + } + if ((isSrcArr || result !== undefined) && + (isCommon || (result === result ? (result !== value) : (value === value)))) { + object[key] = result; + } + } + }); + return object; +} + +module.exports = baseMerge; + +},{"127":127,"150":150,"152":152,"157":157,"166":166,"170":170,"173":173,"176":176,"96":96}],127:[function(_dereq_,module,exports){ +var arrayCopy = _dereq_(95), + isArguments = _dereq_(165), + isArray = _dereq_(166), + isArrayLike = _dereq_(152), + isPlainObject = _dereq_(171), + isTypedArray = _dereq_(173), + toPlainObject = _dereq_(174); + +/** + * A specialized version of `baseMerge` for arrays and objects which performs + * deep merges and tracks traversed objects enabling objects with circular + * references to be merged. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {string} key The key of the value to merge. + * @param {Function} mergeFunc The function to merge values. + * @param {Function} [customizer] The function to customize merging properties. + * @param {Array} [stackA=[]] Tracks traversed source objects. + * @param {Array} [stackB=[]] Associates values with source counterparts. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ +function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) { + var length = stackA.length, + srcValue = source[key]; + + while (length--) { + if (stackA[length] == srcValue) { + object[key] = stackB[length]; + return; + } + } + var value = object[key], + result = customizer ? customizer(value, srcValue, key, object, source) : undefined, + isCommon = result === undefined; + + if (isCommon) { + result = srcValue; + if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) { + result = isArray(value) + ? value + : (isArrayLike(value) ? arrayCopy(value) : []); + } + else if (isPlainObject(srcValue) || isArguments(srcValue)) { + result = isArguments(value) + ? toPlainObject(value) + : (isPlainObject(value) ? value : {}); + } + else { + isCommon = false; + } + } + // Add the source value to the stack of traversed objects and associate + // it with its merged value. + stackA.push(srcValue); + stackB.push(result); + + if (isCommon) { + // Recursively merge objects and arrays (susceptible to call stack limits). + object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB); + } else if (result === result ? (result !== value) : (value === value)) { + object[key] = result; + } +} + +module.exports = baseMergeDeep; + +},{"152":152,"165":165,"166":166,"171":171,"173":173,"174":174,"95":95}],128:[function(_dereq_,module,exports){ +/** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new function. + */ +function baseProperty(key) { + return function(object) { + return object == null ? undefined : object[key]; + }; +} + +module.exports = baseProperty; + +},{}],129:[function(_dereq_,module,exports){ +var baseGet = _dereq_(117), + toPath = _dereq_(164); + +/** + * A specialized version of `baseProperty` which supports deep paths. + * + * @private + * @param {Array|string} path The path of the property to get. + * @returns {Function} Returns the new function. + */ +function basePropertyDeep(path) { + var pathKey = (path + ''); + path = toPath(path); + return function(object) { + return baseGet(object, path, pathKey); + }; +} + +module.exports = basePropertyDeep; + +},{"117":117,"164":164}],130:[function(_dereq_,module,exports){ +/** + * The base implementation of `_.reduce` and `_.reduceRight` without support + * for callback shorthands and `this` binding, which iterates over `collection` + * using the provided `eachFunc`. + * + * @private + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} accumulator The initial value. + * @param {boolean} initFromCollection Specify using the first or last element + * of `collection` as the initial value. + * @param {Function} eachFunc The function to iterate over `collection`. + * @returns {*} Returns the accumulated value. + */ +function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) { + eachFunc(collection, function(value, index, collection) { + accumulator = initFromCollection + ? (initFromCollection = false, value) + : iteratee(accumulator, value, index, collection); + }); + return accumulator; +} + +module.exports = baseReduce; + +},{}],131:[function(_dereq_,module,exports){ +/** + * The base implementation of `_.slice` without an iteratee call guard. + * + * @private + * @param {Array} array The array to slice. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the slice of `array`. + */ +function baseSlice(array, start, end) { + var index = -1, + length = array.length; + + start = start == null ? 0 : (+start || 0); + if (start < 0) { + start = -start > length ? 0 : (length + start); + } + end = (end === undefined || end > length) ? length : (+end || 0); + if (end < 0) { + end += length; + } + length = start > end ? 0 : ((end - start) >>> 0); + start >>>= 0; + + var result = Array(length); + while (++index < length) { + result[index] = array[index + start]; + } + return result; +} + +module.exports = baseSlice; + +},{}],132:[function(_dereq_,module,exports){ +var baseEach = _dereq_(108); + +/** + * The base implementation of `_.some` without support for callback shorthands + * and `this` binding. + * + * @private + * @param {Array|Object|string} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + */ +function baseSome(collection, predicate) { + var result; + + baseEach(collection, function(value, index, collection) { + result = predicate(value, index, collection); + return !result; + }); + return !!result; +} + +module.exports = baseSome; + +},{"108":108}],133:[function(_dereq_,module,exports){ +/** + * Converts `value` to a string if it is not one. An empty string is returned + * for `null` or `undefined` values. + * + * @private + * @param {*} value The value to process. + * @returns {string} Returns the string. + */ +function baseToString(value) { + if (typeof value == 'string') { + return value; + } + return value == null ? '' : (value + ''); +} + +module.exports = baseToString; + +},{}],134:[function(_dereq_,module,exports){ +/** + * The base implementation of `_.values` and `_.valuesIn` which creates an + * array of `object` property values corresponding to the property names + * of `props`. + * + * @private + * @param {Object} object The object to query. + * @param {Array} props The property names to get values for. + * @returns {Object} Returns the array of property values. + */ +function baseValues(object, props) { + var index = -1, + length = props.length, + result = Array(length); + + while (++index < length) { + result[index] = object[props[index]]; + } + return result; +} + +module.exports = baseValues; + +},{}],135:[function(_dereq_,module,exports){ +var identity = _dereq_(185); + +/** + * A specialized version of `baseCallback` which only supports `this` binding + * and specifying the number of arguments to provide to `func`. + * + * @private + * @param {Function} func The function to bind. + * @param {*} thisArg The `this` binding of `func`. + * @param {number} [argCount] The number of arguments to provide to `func`. + * @returns {Function} Returns the callback. + */ +function bindCallback(func, thisArg, argCount) { + if (typeof func != 'function') { + return identity; + } + if (thisArg === undefined) { + return func; + } + switch (argCount) { + case 1: return function(value) { + return func.call(thisArg, value); + }; + case 3: return function(value, index, collection) { + return func.call(thisArg, value, index, collection); + }; + case 4: return function(accumulator, value, index, collection) { + return func.call(thisArg, accumulator, value, index, collection); + }; + case 5: return function(value, other, key, object, source) { + return func.call(thisArg, value, other, key, object, source); + }; + } + return function() { + return func.apply(thisArg, arguments); + }; +} + +module.exports = bindCallback; + +},{"185":185}],136:[function(_dereq_,module,exports){ +var isObject = _dereq_(170); + +/** + * Checks if `value` is in `cache` mimicking the return signature of + * `_.indexOf` by returning `0` if the value is found, else `-1`. + * + * @private + * @param {Object} cache The cache to search. + * @param {*} value The value to search for. + * @returns {number} Returns `0` if `value` is found, else `-1`. + */ +function cacheIndexOf(cache, value) { + var data = cache.data, + result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value]; + + return result ? 0 : -1; +} + +module.exports = cacheIndexOf; + +},{"170":170}],137:[function(_dereq_,module,exports){ +var isObject = _dereq_(170); + +/** + * Adds `value` to the cache. + * + * @private + * @name push + * @memberOf SetCache + * @param {*} value The value to cache. + */ +function cachePush(value) { + var data = this.data; + if (typeof value == 'string' || isObject(value)) { + data.set.add(value); + } else { + data.hash[value] = true; + } +} + +module.exports = cachePush; + +},{"170":170}],138:[function(_dereq_,module,exports){ +var baseCallback = _dereq_(104), + baseEach = _dereq_(108), + isArray = _dereq_(166); + +/** + * Creates a function that aggregates a collection, creating an accumulator + * object composed from the results of running each element in the collection + * through an iteratee. + * + * **Note:** This function is used to create `_.countBy`, `_.groupBy`, `_.indexBy`, + * and `_.partition`. + * + * @private + * @param {Function} setter The function to set keys and values of the accumulator object. + * @param {Function} [initializer] The function to initialize the accumulator object. + * @returns {Function} Returns the new aggregator function. + */ +function createAggregator(setter, initializer) { + return function(collection, iteratee, thisArg) { + var result = initializer ? initializer() : {}; + iteratee = baseCallback(iteratee, thisArg, 3); + + if (isArray(collection)) { + var index = -1, + length = collection.length; + + while (++index < length) { + var value = collection[index]; + setter(result, value, iteratee(value, index, collection), collection); + } + } else { + baseEach(collection, function(value, key, collection) { + setter(result, value, iteratee(value, key, collection), collection); + }); + } + return result; + }; +} + +module.exports = createAggregator; + +},{"104":104,"108":108,"166":166}],139:[function(_dereq_,module,exports){ +var bindCallback = _dereq_(135), + isIterateeCall = _dereq_(154), + restParam = _dereq_(93); + +/** + * Creates a function that assigns properties of source object(s) to a given + * destination object. + * + * **Note:** This function is used to create `_.assign`, `_.defaults`, and `_.merge`. + * + * @private + * @param {Function} assigner The function to assign values. + * @returns {Function} Returns the new assigner function. + */ +function createAssigner(assigner) { + return restParam(function(object, sources) { + var index = -1, + length = object == null ? 0 : sources.length, + customizer = length > 2 && sources[length - 2], + guard = length > 2 && sources[2], + thisArg = length > 1 && sources[length - 1]; + + if (typeof customizer == 'function') { + customizer = bindCallback(customizer, thisArg, 5); + length -= 2; + } else { + customizer = typeof thisArg == 'function' ? thisArg : null; + length -= (customizer ? 1 : 0); + } + if (guard && isIterateeCall(sources[0], sources[1], guard)) { + customizer = length < 3 ? null : customizer; + length = 1; + } + while (++index < length) { + var source = sources[index]; + if (source) { + assigner(object, source, customizer); + } + } + return object; + }); +} + +module.exports = createAssigner; + +},{"135":135,"154":154,"93":93}],140:[function(_dereq_,module,exports){ +var getLength = _dereq_(149), + isLength = _dereq_(156), + toObject = _dereq_(163); + +/** + * Creates a `baseEach` or `baseEachRight` function. + * + * @private + * @param {Function} eachFunc The function to iterate over a collection. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ +function createBaseEach(eachFunc, fromRight) { + return function(collection, iteratee) { + var length = collection ? getLength(collection) : 0; + if (!isLength(length)) { + return eachFunc(collection, iteratee); + } + var index = fromRight ? length : -1, + iterable = toObject(collection); + + while ((fromRight ? index-- : ++index < length)) { + if (iteratee(iterable[index], index, iterable) === false) { + break; + } + } + return collection; + }; +} + +module.exports = createBaseEach; + +},{"149":149,"156":156,"163":163}],141:[function(_dereq_,module,exports){ +var toObject = _dereq_(163); + +/** + * Creates a base function for `_.forIn` or `_.forInRight`. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ +function createBaseFor(fromRight) { + return function(object, iteratee, keysFunc) { + var iterable = toObject(object), + props = keysFunc(object), + length = props.length, + index = fromRight ? length : -1; + + while ((fromRight ? index-- : ++index < length)) { + var key = props[index]; + if (iteratee(iterable[key], key, iterable) === false) { + break; + } + } + return object; + }; +} + +module.exports = createBaseFor; + +},{"163":163}],142:[function(_dereq_,module,exports){ +(function (global){ +var SetCache = _dereq_(94), + constant = _dereq_(184), + isNative = _dereq_(168); + +/** Native method references. */ +var Set = isNative(Set = global.Set) && Set; + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeCreate = isNative(nativeCreate = Object.create) && nativeCreate; + +/** + * Creates a `Set` cache object to optimize linear searches of large arrays. + * + * @private + * @param {Array} [values] The values to cache. + * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`. + */ +var createCache = !(nativeCreate && Set) ? constant(null) : function(values) { + return new SetCache(values); +}; + +module.exports = createCache; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{"168":168,"184":184,"94":94}],143:[function(_dereq_,module,exports){ +var baseCallback = _dereq_(104), + baseFind = _dereq_(111), + baseFindIndex = _dereq_(112), + isArray = _dereq_(166); + +/** + * Creates a `_.find` or `_.findLast` function. + * + * @private + * @param {Function} eachFunc The function to iterate over a collection. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new find function. + */ +function createFind(eachFunc, fromRight) { + return function(collection, predicate, thisArg) { + predicate = baseCallback(predicate, thisArg, 3); + if (isArray(collection)) { + var index = baseFindIndex(collection, predicate, fromRight); + return index > -1 ? collection[index] : undefined; + } + return baseFind(collection, predicate, eachFunc); + }; +} + +module.exports = createFind; + +},{"104":104,"111":111,"112":112,"166":166}],144:[function(_dereq_,module,exports){ +var bindCallback = _dereq_(135), + isArray = _dereq_(166); + +/** + * Creates a function for `_.forEach` or `_.forEachRight`. + * + * @private + * @param {Function} arrayFunc The function to iterate over an array. + * @param {Function} eachFunc The function to iterate over a collection. + * @returns {Function} Returns the new each function. + */ +function createForEach(arrayFunc, eachFunc) { + return function(collection, iteratee, thisArg) { + return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection)) + ? arrayFunc(collection, iteratee) + : eachFunc(collection, bindCallback(iteratee, thisArg, 3)); + }; +} + +module.exports = createForEach; + +},{"135":135,"166":166}],145:[function(_dereq_,module,exports){ +var baseCallback = _dereq_(104), + baseReduce = _dereq_(130), + isArray = _dereq_(166); + +/** + * Creates a function for `_.reduce` or `_.reduceRight`. + * + * @private + * @param {Function} arrayFunc The function to iterate over an array. + * @param {Function} eachFunc The function to iterate over a collection. + * @returns {Function} Returns the new each function. + */ +function createReduce(arrayFunc, eachFunc) { + return function(collection, iteratee, accumulator, thisArg) { + var initFromArray = arguments.length < 3; + return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection)) + ? arrayFunc(collection, iteratee, accumulator, initFromArray) + : baseReduce(collection, baseCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc); + }; +} + +module.exports = createReduce; + +},{"104":104,"130":130,"166":166}],146:[function(_dereq_,module,exports){ +/** + * A specialized version of `baseIsEqualDeep` for arrays with support for + * partial deep comparisons. + * + * @private + * @param {Array} array The array to compare. + * @param {Array} other The other array to compare. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Function} [customizer] The function to customize comparing arrays. + * @param {boolean} [isLoose] Specify performing partial comparisons. + * @param {Array} [stackA] Tracks traversed `value` objects. + * @param {Array} [stackB] Tracks traversed `other` objects. + * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. + */ +function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) { + var index = -1, + arrLength = array.length, + othLength = other.length, + result = true; + + if (arrLength != othLength && !(isLoose && othLength > arrLength)) { + return false; + } + // Deep compare the contents, ignoring non-numeric properties. + while (result && ++index < arrLength) { + var arrValue = array[index], + othValue = other[index]; + + result = undefined; + if (customizer) { + result = isLoose + ? customizer(othValue, arrValue, index) + : customizer(arrValue, othValue, index); + } + if (result === undefined) { + // Recursively compare arrays (susceptible to call stack limits). + if (isLoose) { + var othIndex = othLength; + while (othIndex--) { + othValue = other[othIndex]; + result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB); + if (result) { + break; + } + } + } else { + result = (arrValue && arrValue === othValue) || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB); + } + } + } + return !!result; +} + +module.exports = equalArrays; + +},{}],147:[function(_dereq_,module,exports){ +/** `Object#toString` result references. */ +var boolTag = '[object Boolean]', + dateTag = '[object Date]', + errorTag = '[object Error]', + numberTag = '[object Number]', + regexpTag = '[object RegExp]', + stringTag = '[object String]'; + +/** + * A specialized version of `baseIsEqualDeep` for comparing objects of + * the same `toStringTag`. + * + * **Note:** This function only supports comparing values with tags of + * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. + * + * @private + * @param {Object} value The object to compare. + * @param {Object} other The other object to compare. + * @param {string} tag The `toStringTag` of the objects to compare. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ +function equalByTag(object, other, tag) { + switch (tag) { + case boolTag: + case dateTag: + // Coerce dates and booleans to numbers, dates to milliseconds and booleans + // to `1` or `0` treating invalid dates coerced to `NaN` as not equal. + return +object == +other; + + case errorTag: + return object.name == other.name && object.message == other.message; + + case numberTag: + // Treat `NaN` vs. `NaN` as equal. + return (object != +object) + ? other != +other + : object == +other; + + case regexpTag: + case stringTag: + // Coerce regexes to strings and treat strings primitives and string + // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details. + return object == (other + ''); + } + return false; +} + +module.exports = equalByTag; + +},{}],148:[function(_dereq_,module,exports){ +var keys = _dereq_(176); + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * A specialized version of `baseIsEqualDeep` for objects with support for + * partial deep comparisons. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Function} [customizer] The function to customize comparing values. + * @param {boolean} [isLoose] Specify performing partial comparisons. + * @param {Array} [stackA] Tracks traversed `value` objects. + * @param {Array} [stackB] Tracks traversed `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ +function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) { + var objProps = keys(object), + objLength = objProps.length, + othProps = keys(other), + othLength = othProps.length; + + if (objLength != othLength && !isLoose) { + return false; + } + var skipCtor = isLoose, + index = -1; + + while (++index < objLength) { + var key = objProps[index], + result = isLoose ? key in other : hasOwnProperty.call(other, key); + + if (result) { + var objValue = object[key], + othValue = other[key]; + + result = undefined; + if (customizer) { + result = isLoose + ? customizer(othValue, objValue, key) + : customizer(objValue, othValue, key); + } + if (result === undefined) { + // Recursively compare objects (susceptible to call stack limits). + result = (objValue && objValue === othValue) || equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB); + } + } + if (!result) { + return false; + } + skipCtor || (skipCtor = key == 'constructor'); + } + if (!skipCtor) { + var objCtor = object.constructor, + othCtor = other.constructor; + + // Non `Object` object instances with different constructors are not equal. + if (objCtor != othCtor && + ('constructor' in object && 'constructor' in other) && + !(typeof objCtor == 'function' && objCtor instanceof objCtor && + typeof othCtor == 'function' && othCtor instanceof othCtor)) { + return false; + } + } + return true; +} + +module.exports = equalObjects; + +},{"176":176}],149:[function(_dereq_,module,exports){ +var baseProperty = _dereq_(128); + +/** + * Gets the "length" property value of `object`. + * + * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792) + * that affects Safari on at least iOS 8.1-8.3 ARM64. + * + * @private + * @param {Object} object The object to query. + * @returns {*} Returns the "length" value. + */ +var getLength = baseProperty('length'); + +module.exports = getLength; + +},{"128":128}],150:[function(_dereq_,module,exports){ +var constant = _dereq_(184), + isNative = _dereq_(168), + toObject = _dereq_(163); + +/** Native method references. */ +var getOwnPropertySymbols = isNative(getOwnPropertySymbols = Object.getOwnPropertySymbols) && getOwnPropertySymbols; + +/** + * Creates an array of the own symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of symbols. + */ +var getSymbols = !getOwnPropertySymbols ? constant([]) : function(object) { + return getOwnPropertySymbols(toObject(object)); +}; + +module.exports = getSymbols; + +},{"163":163,"168":168,"184":184}],151:[function(_dereq_,module,exports){ +/** + * Gets the index at which the first occurrence of `NaN` is found in `array`. + * + * @private + * @param {Array} array The array to search. + * @param {number} fromIndex The index to search from. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {number} Returns the index of the matched `NaN`, else `-1`. + */ +function indexOfNaN(array, fromIndex, fromRight) { + var length = array.length, + index = fromIndex + (fromRight ? 0 : -1); + + while ((fromRight ? index-- : ++index < length)) { + var other = array[index]; + if (other !== other) { + return index; + } + } + return -1; +} + +module.exports = indexOfNaN; + +},{}],152:[function(_dereq_,module,exports){ +var getLength = _dereq_(149), + isLength = _dereq_(156); + +/** + * Checks if `value` is array-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + */ +function isArrayLike(value) { + return value != null && isLength(getLength(value)); +} + +module.exports = isArrayLike; + +},{"149":149,"156":156}],153:[function(_dereq_,module,exports){ +/** + * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) + * of an array-like value. + */ +var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; + +/** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ +function isIndex(value, length) { + value = +value; + length = length == null ? MAX_SAFE_INTEGER : length; + return value > -1 && value % 1 == 0 && value < length; +} + +module.exports = isIndex; + +},{}],154:[function(_dereq_,module,exports){ +var isArrayLike = _dereq_(152), + isIndex = _dereq_(153), + isObject = _dereq_(170); + +/** + * Checks if the provided arguments are from an iteratee call. + * + * @private + * @param {*} value The potential iteratee value argument. + * @param {*} index The potential iteratee index or key argument. + * @param {*} object The potential iteratee object argument. + * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`. + */ +function isIterateeCall(value, index, object) { + if (!isObject(object)) { + return false; + } + var type = typeof index; + if (type == 'number' + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object)) { + var other = object[index]; + return value === value ? (value === other) : (other !== other); + } + return false; +} + +module.exports = isIterateeCall; + +},{"152":152,"153":153,"170":170}],155:[function(_dereq_,module,exports){ +var isArray = _dereq_(166), + toObject = _dereq_(163); + +/** Used to match property names within property paths. */ +var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/, + reIsPlainProp = /^\w*$/; + +/** + * Checks if `value` is a property name and not a property path. + * + * @private + * @param {*} value The value to check. + * @param {Object} [object] The object to query keys on. + * @returns {boolean} Returns `true` if `value` is a property name, else `false`. + */ +function isKey(value, object) { + var type = typeof value; + if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') { + return true; + } + if (isArray(value)) { + return false; + } + var result = !reIsDeepProp.test(value); + return result || (object != null && value in toObject(object)); +} + +module.exports = isKey; + +},{"163":163,"166":166}],156:[function(_dereq_,module,exports){ +/** + * Used as the [maximum length](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-number.max_safe_integer) + * of an array-like value. + */ +var MAX_SAFE_INTEGER = Math.pow(2, 53) - 1; + +/** + * Checks if `value` is a valid array-like length. + * + * **Note:** This function is based on [`ToLength`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-tolength). + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + */ +function isLength(value) { + return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; +} + +module.exports = isLength; + +},{}],157:[function(_dereq_,module,exports){ +/** + * Checks if `value` is object-like. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + */ +function isObjectLike(value) { + return !!value && typeof value == 'object'; +} + +module.exports = isObjectLike; + +},{}],158:[function(_dereq_,module,exports){ +var isObject = _dereq_(170); + +/** + * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` if suitable for strict + * equality comparisons, else `false`. + */ +function isStrictComparable(value) { + return value === value && !isObject(value); +} + +module.exports = isStrictComparable; + +},{"170":170}],159:[function(_dereq_,module,exports){ +var toObject = _dereq_(163); + +/** + * A specialized version of `_.pick` which picks `object` properties specified + * by `props`. + * + * @private + * @param {Object} object The source object. + * @param {string[]} props The property names to pick. + * @returns {Object} Returns the new object. + */ +function pickByArray(object, props) { + object = toObject(object); + + var index = -1, + length = props.length, + result = {}; + + while (++index < length) { + var key = props[index]; + if (key in object) { + result[key] = object[key]; + } + } + return result; +} + +module.exports = pickByArray; + +},{"163":163}],160:[function(_dereq_,module,exports){ +var baseForIn = _dereq_(115); + +/** + * A specialized version of `_.pick` which picks `object` properties `predicate` + * returns truthy for. + * + * @private + * @param {Object} object The source object. + * @param {Function} predicate The function invoked per iteration. + * @returns {Object} Returns the new object. + */ +function pickByCallback(object, predicate) { + var result = {}; + baseForIn(object, function(value, key, object) { + if (predicate(value, key, object)) { + result[key] = value; + } + }); + return result; +} + +module.exports = pickByCallback; + +},{"115":115}],161:[function(_dereq_,module,exports){ +var baseForIn = _dereq_(115), + isObjectLike = _dereq_(157); + +/** `Object#toString` result references. */ +var objectTag = '[object Object]'; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** + * A fallback implementation of `_.isPlainObject` which checks if `value` + * is an object created by the `Object` constructor or has a `[[Prototype]]` + * of `null`. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. + */ +function shimIsPlainObject(value) { + var Ctor; + + // Exit early for non `Object` objects. + if (!(isObjectLike(value) && objToString.call(value) == objectTag) || + (!hasOwnProperty.call(value, 'constructor') && + (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) { + return false; + } + // IE < 9 iterates inherited properties before own properties. If the first + // iterated property is an object's own property then there are no inherited + // enumerable properties. + var result; + // In most environments an object's own properties are iterated before + // its inherited properties. If the last iterated property is an object's + // own property then there are no inherited enumerable properties. + baseForIn(value, function(subValue, key) { + result = key; + }); + return result === undefined || hasOwnProperty.call(value, result); +} + +module.exports = shimIsPlainObject; + +},{"115":115,"157":157}],162:[function(_dereq_,module,exports){ +var isArguments = _dereq_(165), + isArray = _dereq_(166), + isIndex = _dereq_(153), + isLength = _dereq_(156), + keysIn = _dereq_(177), + support = _dereq_(183); + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * A fallback implementation of `Object.keys` which creates an array of the + * own enumerable property names of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ +function shimKeys(object) { + var props = keysIn(object), + propsLength = props.length, + length = propsLength && object.length; + + var allowIndexes = length && isLength(length) && + (isArray(object) || (support.nonEnumArgs && isArguments(object))); + + var index = -1, + result = []; + + while (++index < propsLength) { + var key = props[index]; + if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) { + result.push(key); + } + } + return result; +} + +module.exports = shimKeys; + +},{"153":153,"156":156,"165":165,"166":166,"177":177,"183":183}],163:[function(_dereq_,module,exports){ +var isObject = _dereq_(170); + +/** + * Converts `value` to an object if it is not one. + * + * @private + * @param {*} value The value to process. + * @returns {Object} Returns the object. + */ +function toObject(value) { + return isObject(value) ? value : Object(value); +} + +module.exports = toObject; + +},{"170":170}],164:[function(_dereq_,module,exports){ +var baseToString = _dereq_(133), + isArray = _dereq_(166); + +/** Used to match property names within property paths. */ +var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g; + +/** Used to match backslashes in property paths. */ +var reEscapeChar = /\\(\\)?/g; + +/** + * Converts `value` to property path array if it is not one. + * + * @private + * @param {*} value The value to process. + * @returns {Array} Returns the property path array. + */ +function toPath(value) { + if (isArray(value)) { + return value; + } + var result = []; + baseToString(value).replace(rePropName, function(match, number, quote, string) { + result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match)); + }); + return result; +} + +module.exports = toPath; + +},{"133":133,"166":166}],165:[function(_dereq_,module,exports){ +var isArrayLike = _dereq_(152), + isObjectLike = _dereq_(157); + +/** `Object#toString` result references. */ +var argsTag = '[object Arguments]'; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** + * Checks if `value` is classified as an `arguments` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isArguments(function() { return arguments; }()); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ +function isArguments(value) { + return isObjectLike(value) && isArrayLike(value) && objToString.call(value) == argsTag; +} + +module.exports = isArguments; + +},{"152":152,"157":157}],166:[function(_dereq_,module,exports){ +var isLength = _dereq_(156), + isNative = _dereq_(168), + isObjectLike = _dereq_(157); + +/** `Object#toString` result references. */ +var arrayTag = '[object Array]'; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeIsArray = isNative(nativeIsArray = Array.isArray) && nativeIsArray; + +/** + * Checks if `value` is classified as an `Array` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isArray([1, 2, 3]); + * // => true + * + * _.isArray(function() { return arguments; }()); + * // => false + */ +var isArray = nativeIsArray || function(value) { + return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag; +}; + +module.exports = isArray; + +},{"156":156,"157":157,"168":168}],167:[function(_dereq_,module,exports){ +(function (global){ +var baseIsFunction = _dereq_(121), + isNative = _dereq_(168); + +/** `Object#toString` result references. */ +var funcTag = '[object Function]'; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** Native method references. */ +var Uint8Array = isNative(Uint8Array = global.Uint8Array) && Uint8Array; + +/** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ +var isFunction = !(baseIsFunction(/x/) || (Uint8Array && !baseIsFunction(Uint8Array))) ? baseIsFunction : function(value) { + // The use of `Object#toString` avoids issues with the `typeof` operator + // in older versions of Chrome and Safari which return 'function' for regexes + // and Safari 8 equivalents which return 'object' for typed array constructors. + return objToString.call(value) == funcTag; +}; + +module.exports = isFunction; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{"121":121,"168":168}],168:[function(_dereq_,module,exports){ +var escapeRegExp = _dereq_(182), + isObjectLike = _dereq_(157); + +/** `Object#toString` result references. */ +var funcTag = '[object Function]'; + +/** Used to detect host constructors (Safari > 5). */ +var reIsHostCtor = /^\[object .+?Constructor\]$/; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to resolve the decompiled source of functions. */ +var fnToString = Function.prototype.toString; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** Used to detect if a method is native. */ +var reIsNative = RegExp('^' + + escapeRegExp(objToString) + .replace(/toString|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' +); + +/** + * Checks if `value` is a native function. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, else `false`. + * @example + * + * _.isNative(Array.prototype.push); + * // => true + * + * _.isNative(_); + * // => false + */ +function isNative(value) { + if (value == null) { + return false; + } + if (objToString.call(value) == funcTag) { + return reIsNative.test(fnToString.call(value)); + } + return isObjectLike(value) && reIsHostCtor.test(value); +} + +module.exports = isNative; + +},{"157":157,"182":182}],169:[function(_dereq_,module,exports){ +var isObjectLike = _dereq_(157); + +/** `Object#toString` result references. */ +var numberTag = '[object Number]'; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** + * Checks if `value` is classified as a `Number` primitive or object. + * + * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified + * as numbers, use the `_.isFinite` method. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isNumber(8.4); + * // => true + * + * _.isNumber(NaN); + * // => true + * + * _.isNumber('8.4'); + * // => false + */ +function isNumber(value) { + return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag); +} + +module.exports = isNumber; + +},{"157":157}],170:[function(_dereq_,module,exports){ +/** + * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`. + * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(1); + * // => false + */ +function isObject(value) { + // Avoid a V8 JIT bug in Chrome 19-20. + // See https://code.google.com/p/v8/issues/detail?id=2291 for more details. + var type = typeof value; + return type == 'function' || (!!value && type == 'object'); +} + +module.exports = isObject; + +},{}],171:[function(_dereq_,module,exports){ +var isNative = _dereq_(168), + shimIsPlainObject = _dereq_(161); + +/** `Object#toString` result references. */ +var objectTag = '[object Object]'; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** Native method references. */ +var getPrototypeOf = isNative(getPrototypeOf = Object.getPrototypeOf) && getPrototypeOf; + +/** + * Checks if `value` is a plain object, that is, an object created by the + * `Object` constructor or one with a `[[Prototype]]` of `null`. + * + * **Note:** This method assumes objects created by the `Object` constructor + * have no inherited enumerable properties. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. + * @example + * + * function Foo() { + * this.a = 1; + * } + * + * _.isPlainObject(new Foo); + * // => false + * + * _.isPlainObject([1, 2, 3]); + * // => false + * + * _.isPlainObject({ 'x': 0, 'y': 0 }); + * // => true + * + * _.isPlainObject(Object.create(null)); + * // => true + */ +var isPlainObject = !getPrototypeOf ? shimIsPlainObject : function(value) { + if (!(value && objToString.call(value) == objectTag)) { + return false; + } + var valueOf = value.valueOf, + objProto = isNative(valueOf) && (objProto = getPrototypeOf(valueOf)) && getPrototypeOf(objProto); + + return objProto + ? (value == objProto || getPrototypeOf(value) == objProto) + : shimIsPlainObject(value); +}; + +module.exports = isPlainObject; + +},{"161":161,"168":168}],172:[function(_dereq_,module,exports){ +var isObjectLike = _dereq_(157); + +/** `Object#toString` result references. */ +var stringTag = '[object String]'; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** + * Checks if `value` is classified as a `String` primitive or object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isString('abc'); + * // => true + * + * _.isString(1); + * // => false + */ +function isString(value) { + return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag); +} + +module.exports = isString; + +},{"157":157}],173:[function(_dereq_,module,exports){ +var isLength = _dereq_(156), + isObjectLike = _dereq_(157); + +/** `Object#toString` result references. */ +var argsTag = '[object Arguments]', + arrayTag = '[object Array]', + boolTag = '[object Boolean]', + dateTag = '[object Date]', + errorTag = '[object Error]', + funcTag = '[object Function]', + mapTag = '[object Map]', + numberTag = '[object Number]', + objectTag = '[object Object]', + regexpTag = '[object RegExp]', + setTag = '[object Set]', + stringTag = '[object String]', + weakMapTag = '[object WeakMap]'; + +var arrayBufferTag = '[object ArrayBuffer]', + float32Tag = '[object Float32Array]', + float64Tag = '[object Float64Array]', + int8Tag = '[object Int8Array]', + int16Tag = '[object Int16Array]', + int32Tag = '[object Int32Array]', + uint8Tag = '[object Uint8Array]', + uint8ClampedTag = '[object Uint8ClampedArray]', + uint16Tag = '[object Uint16Array]', + uint32Tag = '[object Uint32Array]'; + +/** Used to identify `toStringTag` values of typed arrays. */ +var typedArrayTags = {}; +typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = +typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = +typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = +typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = +typedArrayTags[uint32Tag] = true; +typedArrayTags[argsTag] = typedArrayTags[arrayTag] = +typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = +typedArrayTags[dateTag] = typedArrayTags[errorTag] = +typedArrayTags[funcTag] = typedArrayTags[mapTag] = +typedArrayTags[numberTag] = typedArrayTags[objectTag] = +typedArrayTags[regexpTag] = typedArrayTags[setTag] = +typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false; + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** + * Used to resolve the [`toStringTag`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.prototype.tostring) + * of values. + */ +var objToString = objectProto.toString; + +/** + * Checks if `value` is classified as a typed array. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`. + * @example + * + * _.isTypedArray(new Uint8Array); + * // => true + * + * _.isTypedArray([]); + * // => false + */ +function isTypedArray(value) { + return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)]; +} + +module.exports = isTypedArray; + +},{"156":156,"157":157}],174:[function(_dereq_,module,exports){ +var baseCopy = _dereq_(105), + keysIn = _dereq_(177); + +/** + * Converts `value` to a plain object flattening inherited enumerable + * properties of `value` to own properties of the plain object. + * + * @static + * @memberOf _ + * @category Lang + * @param {*} value The value to convert. + * @returns {Object} Returns the converted plain object. + * @example + * + * function Foo() { + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.assign({ 'a': 1 }, new Foo); + * // => { 'a': 1, 'b': 2 } + * + * _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); + * // => { 'a': 1, 'b': 2, 'c': 3 } + */ +function toPlainObject(value) { + return baseCopy(value, keysIn(value)); +} + +module.exports = toPlainObject; + +},{"105":105,"177":177}],175:[function(_dereq_,module,exports){ +var assignWith = _dereq_(102), + baseAssign = _dereq_(103), + createAssigner = _dereq_(139); + +/** + * Assigns own enumerable properties of source object(s) to the destination + * object. Subsequent sources overwrite property assignments of previous sources. + * If `customizer` is provided it is invoked to produce the assigned values. + * The `customizer` is bound to `thisArg` and invoked with five arguments: + * (objectValue, sourceValue, key, object, source). + * + * **Note:** This method mutates `object` and is based on + * [`Object.assign`](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.assign). + * + * @static + * @memberOf _ + * @alias extend + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @param {Function} [customizer] The function to customize assigned values. + * @param {*} [thisArg] The `this` binding of `customizer`. + * @returns {Object} Returns `object`. + * @example + * + * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' }); + * // => { 'user': 'fred', 'age': 40 } + * + * // using a customizer callback + * var defaults = _.partialRight(_.assign, function(value, other) { + * return _.isUndefined(value) ? other : value; + * }); + * + * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' }); + * // => { 'user': 'barney', 'age': 36 } + */ +var assign = createAssigner(function(object, source, customizer) { + return customizer + ? assignWith(object, source, customizer) + : baseAssign(object, source); +}); + +module.exports = assign; + +},{"102":102,"103":103,"139":139}],176:[function(_dereq_,module,exports){ +var isArrayLike = _dereq_(152), + isNative = _dereq_(168), + isObject = _dereq_(170), + shimKeys = _dereq_(162); + +/* Native method references for those with the same name as other `lodash` methods. */ +var nativeKeys = isNative(nativeKeys = Object.keys) && nativeKeys; + +/** + * Creates an array of the own enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. See the + * [ES spec](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-object.keys) + * for more details. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keys(new Foo); + * // => ['a', 'b'] (iteration order is not guaranteed) + * + * _.keys('hi'); + * // => ['0', '1'] + */ +var keys = !nativeKeys ? shimKeys : function(object) { + var Ctor = object != null && object.constructor; + if ((typeof Ctor == 'function' && Ctor.prototype === object) || + (typeof object != 'function' && isArrayLike(object))) { + return shimKeys(object); + } + return isObject(object) ? nativeKeys(object) : []; +}; + +module.exports = keys; + +},{"152":152,"162":162,"168":168,"170":170}],177:[function(_dereq_,module,exports){ +var isArguments = _dereq_(165), + isArray = _dereq_(166), + isIndex = _dereq_(153), + isLength = _dereq_(156), + isObject = _dereq_(170), + support = _dereq_(183); + +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to check objects for own properties. */ +var hasOwnProperty = objectProto.hasOwnProperty; + +/** + * Creates an array of the own and inherited enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keysIn(new Foo); + * // => ['a', 'b', 'c'] (iteration order is not guaranteed) + */ +function keysIn(object) { + if (object == null) { + return []; + } + if (!isObject(object)) { + object = Object(object); + } + var length = object.length; + length = (length && isLength(length) && + (isArray(object) || (support.nonEnumArgs && isArguments(object))) && length) || 0; + + var Ctor = object.constructor, + index = -1, + isProto = typeof Ctor == 'function' && Ctor.prototype === object, + result = Array(length), + skipIndexes = length > 0; + + while (++index < length) { + result[index] = (index + ''); + } + for (var key in object) { + if (!(skipIndexes && isIndex(key, length)) && + !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { + result.push(key); + } + } + return result; +} + +module.exports = keysIn; + +},{"153":153,"156":156,"165":165,"166":166,"170":170,"183":183}],178:[function(_dereq_,module,exports){ +var baseMerge = _dereq_(126), + createAssigner = _dereq_(139); + +/** + * Recursively merges own enumerable properties of the source object(s), that + * don't resolve to `undefined` into the destination object. Subsequent sources + * overwrite property assignments of previous sources. If `customizer` is + * provided it is invoked to produce the merged values of the destination and + * source properties. If `customizer` returns `undefined` merging is handled + * by the method instead. The `customizer` is bound to `thisArg` and invoked + * with five arguments: (objectValue, sourceValue, key, object, source). + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @param {Function} [customizer] The function to customize assigned values. + * @param {*} [thisArg] The `this` binding of `customizer`. + * @returns {Object} Returns `object`. + * @example + * + * var users = { + * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }] + * }; + * + * var ages = { + * 'data': [{ 'age': 36 }, { 'age': 40 }] + * }; + * + * _.merge(users, ages); + * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] } + * + * // using a customizer callback + * var object = { + * 'fruits': ['apple'], + * 'vegetables': ['beet'] + * }; + * + * var other = { + * 'fruits': ['banana'], + * 'vegetables': ['carrot'] + * }; + * + * _.merge(object, other, function(a, b) { + * if (_.isArray(a)) { + * return a.concat(b); + * } + * }); + * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] } + */ +var merge = createAssigner(baseMerge); + +module.exports = merge; + +},{"126":126,"139":139}],179:[function(_dereq_,module,exports){ +var arrayMap = _dereq_(99), + baseDifference = _dereq_(107), + baseFlatten = _dereq_(113), + bindCallback = _dereq_(135), + keysIn = _dereq_(177), + pickByArray = _dereq_(159), + pickByCallback = _dereq_(160), + restParam = _dereq_(93); + +/** + * The opposite of `_.pick`; this method creates an object composed of the + * own and inherited enumerable properties of `object` that are not omitted. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {Function|...(string|string[])} [predicate] The function invoked per + * iteration or property names to omit, specified as individual property + * names or arrays of property names. + * @param {*} [thisArg] The `this` binding of `predicate`. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'user': 'fred', 'age': 40 }; + * + * _.omit(object, 'age'); + * // => { 'user': 'fred' } + * + * _.omit(object, _.isNumber); + * // => { 'user': 'fred' } + */ +var omit = restParam(function(object, props) { + if (object == null) { + return {}; + } + if (typeof props[0] != 'function') { + var props = arrayMap(baseFlatten(props), String); + return pickByArray(object, baseDifference(keysIn(object), props)); + } + var predicate = bindCallback(props[0], props[1], 3); + return pickByCallback(object, function(value, key, object) { + return !predicate(value, key, object); + }); +}); + +module.exports = omit; + +},{"107":107,"113":113,"135":135,"159":159,"160":160,"177":177,"93":93,"99":99}],180:[function(_dereq_,module,exports){ +var baseFlatten = _dereq_(113), + bindCallback = _dereq_(135), + pickByArray = _dereq_(159), + pickByCallback = _dereq_(160), + restParam = _dereq_(93); + +/** + * Creates an object composed of the picked `object` properties. Property + * names may be specified as individual arguments or as arrays of property + * names. If `predicate` is provided it is invoked for each property of `object` + * picking the properties `predicate` returns truthy for. The predicate is + * bound to `thisArg` and invoked with three arguments: (value, key, object). + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {Function|...(string|string[])} [predicate] The function invoked per + * iteration or property names to pick, specified as individual property + * names or arrays of property names. + * @param {*} [thisArg] The `this` binding of `predicate`. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'user': 'fred', 'age': 40 }; + * + * _.pick(object, 'user'); + * // => { 'user': 'fred' } + * + * _.pick(object, _.isString); + * // => { 'user': 'fred' } + */ +var pick = restParam(function(object, props) { + if (object == null) { + return {}; + } + return typeof props[0] == 'function' + ? pickByCallback(object, bindCallback(props[0], props[1], 3)) + : pickByArray(object, baseFlatten(props)); +}); + +module.exports = pick; + +},{"113":113,"135":135,"159":159,"160":160,"93":93}],181:[function(_dereq_,module,exports){ +var baseValues = _dereq_(134), + keys = _dereq_(176); + +/** + * Creates an array of the own enumerable property values of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @static + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property values. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.values(new Foo); + * // => [1, 2] (iteration order is not guaranteed) + * + * _.values('hi'); + * // => ['h', 'i'] + */ +function values(object) { + return baseValues(object, keys(object)); +} + +module.exports = values; + +},{"134":134,"176":176}],182:[function(_dereq_,module,exports){ +var baseToString = _dereq_(133); + +/** + * Used to match `RegExp` [special characters](http://www.regular-expressions.info/characters.html#special). + * In addition to special characters the forward slash is escaped to allow for + * easier `eval` use and `Function` compilation. + */ +var reRegExpChars = /[.*+?^${}()|[\]\/\\]/g, + reHasRegExpChars = RegExp(reRegExpChars.source); + +/** + * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?", + * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`. + * + * @static + * @memberOf _ + * @category String + * @param {string} [string=''] The string to escape. + * @returns {string} Returns the escaped string. + * @example + * + * _.escapeRegExp('[lodash](https://lodash.com/)'); + * // => '\[lodash\]\(https:\/\/lodash\.com\/\)' + */ +function escapeRegExp(string) { + string = baseToString(string); + return (string && reHasRegExpChars.test(string)) + ? string.replace(reRegExpChars, '\\$&') + : string; +} + +module.exports = escapeRegExp; + +},{"133":133}],183:[function(_dereq_,module,exports){ +(function (global){ +/** Used for native method references. */ +var objectProto = Object.prototype; + +/** Used to detect DOM support. */ +var document = (document = global.window) && document.document; + +/** Native method references. */ +var propertyIsEnumerable = objectProto.propertyIsEnumerable; + +/** + * An object environment feature flags. + * + * @static + * @memberOf _ + * @type Object + */ +var support = {}; + +(function(x) { + var Ctor = function() { this.x = x; }, + args = arguments, + object = { '0': x, 'length': x }, + props = []; + + Ctor.prototype = { 'valueOf': x, 'y': x }; + for (var key in new Ctor) { props.push(key); } + + /** + * Detect if functions can be decompiled by `Function#toString` + * (all but Firefox OS certified apps, older Opera mobile browsers, and + * the PlayStation 3; forced `false` for Windows 8 apps). + * + * @memberOf _.support + * @type boolean + */ + support.funcDecomp = /\bthis\b/.test(function() { return this; }); + + /** + * Detect if `Function#name` is supported (all but IE). + * + * @memberOf _.support + * @type boolean + */ + support.funcNames = typeof Function.name == 'string'; + + /** + * Detect if the DOM is supported. + * + * @memberOf _.support + * @type boolean + */ + try { + support.dom = document.createDocumentFragment().nodeType === 11; + } catch(e) { + support.dom = false; + } + + /** + * Detect if `arguments` object indexes are non-enumerable. + * + * In Firefox < 4, IE < 9, PhantomJS, and Safari < 5.1 `arguments` object + * indexes are non-enumerable. Chrome < 25 and Node.js < 0.11.0 treat + * `arguments` object indexes as non-enumerable and fail `hasOwnProperty` + * checks for indexes that exceed the number of function parameters and + * whose associated argument values are `0`. + * + * @memberOf _.support + * @type boolean + */ + try { + support.nonEnumArgs = !propertyIsEnumerable.call(args, 1); + } catch(e) { + support.nonEnumArgs = true; + } +}(1, 0)); + +module.exports = support; + +}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {}) + +},{}],184:[function(_dereq_,module,exports){ +/** + * Creates a function that returns `value`. + * + * @static + * @memberOf _ + * @category Utility + * @param {*} value The value to return from the new function. + * @returns {Function} Returns the new function. + * @example + * + * var object = { 'user': 'fred' }; + * var getter = _.constant(object); + * + * getter() === object; + * // => true + */ +function constant(value) { + return function() { + return value; + }; +} + +module.exports = constant; + +},{}],185:[function(_dereq_,module,exports){ +/** + * This method returns the first argument provided to it. + * + * @static + * @memberOf _ + * @category Utility + * @param {*} value Any value. + * @returns {*} Returns `value`. + * @example + * + * var object = { 'user': 'fred' }; + * + * _.identity(object) === object; + * // => true + */ +function identity(value) { + return value; +} + +module.exports = identity; + +},{}],186:[function(_dereq_,module,exports){ +var baseProperty = _dereq_(128), + basePropertyDeep = _dereq_(129), + isKey = _dereq_(155); + +/** + * Creates a function which returns the property value at `path` on a + * given object. + * + * @static + * @memberOf _ + * @category Utility + * @param {Array|string} path The path of the property to get. + * @returns {Function} Returns the new function. + * @example + * + * var objects = [ + * { 'a': { 'b': { 'c': 2 } } }, + * { 'a': { 'b': { 'c': 1 } } } + * ]; + * + * _.map(objects, _.property('a.b.c')); + * // => [2, 1] + * + * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c'); + * // => [1, 2] + */ +function property(path) { + return isKey(path) ? baseProperty(path) : basePropertyDeep(path); +} + +module.exports = property; + +},{"128":128,"129":129,"155":155}],187:[function(_dereq_,module,exports){ +module.exports = _dereq_(194); +},{"194":194}],188:[function(_dereq_,module,exports){ +module.exports = function(el) { + + var c; + + while (el.childNodes.length) { + c = el.childNodes[0]; + el.removeChild(c); + } + + return el; +}; +},{}],189:[function(_dereq_,module,exports){ +module.exports = _dereq_(197); +},{"197":197}],190:[function(_dereq_,module,exports){ +module.exports = _dereq_(201); +},{"201":201}],191:[function(_dereq_,module,exports){ +module.exports = _dereq_(198); +},{"198":198}],192:[function(_dereq_,module,exports){ +module.exports = _dereq_(200); +},{"200":200}],193:[function(_dereq_,module,exports){ +module.exports = function(el) { + el.parentNode && el.parentNode.removeChild(el); +}; +},{}],194:[function(_dereq_,module,exports){ +/** + * Module dependencies. + */ + +var index = _dereq_(195); + +/** + * Whitespace regexp. + */ + +var re = /\s+/; + +/** + * toString reference. + */ + +var toString = Object.prototype.toString; + +/** + * Wrap `el` in a `ClassList`. + * + * @param {Element} el + * @return {ClassList} + * @api public + */ + +module.exports = function(el){ + return new ClassList(el); +}; + +/** + * Initialize a new ClassList for `el`. + * + * @param {Element} el + * @api private + */ + +function ClassList(el) { + if (!el || !el.nodeType) { + throw new Error('A DOM element reference is required'); + } + this.el = el; + this.list = el.classList; +} + +/** + * Add class `name` if not already present. + * + * @param {String} name + * @return {ClassList} + * @api public + */ + +ClassList.prototype.add = function(name){ + // classList + if (this.list) { + this.list.add(name); + return this; + } + + // fallback + var arr = this.array(); + var i = index(arr, name); + if (!~i) arr.push(name); + this.el.className = arr.join(' '); + return this; +}; + +/** + * Remove class `name` when present, or + * pass a regular expression to remove + * any which match. + * + * @param {String|RegExp} name + * @return {ClassList} + * @api public + */ + +ClassList.prototype.remove = function(name){ + if ('[object RegExp]' == toString.call(name)) { + return this.removeMatching(name); + } + + // classList + if (this.list) { + this.list.remove(name); + return this; + } + + // fallback + var arr = this.array(); + var i = index(arr, name); + if (~i) arr.splice(i, 1); + this.el.className = arr.join(' '); + return this; +}; + +/** + * Remove all classes matching `re`. + * + * @param {RegExp} re + * @return {ClassList} + * @api private + */ + +ClassList.prototype.removeMatching = function(re){ + var arr = this.array(); + for (var i = 0; i < arr.length; i++) { + if (re.test(arr[i])) { + this.remove(arr[i]); + } + } + return this; +}; + +/** + * Toggle class `name`, can force state via `force`. + * + * For browsers that support classList, but do not support `force` yet, + * the mistake will be detected and corrected. + * + * @param {String} name + * @param {Boolean} force + * @return {ClassList} + * @api public + */ + +ClassList.prototype.toggle = function(name, force){ + // classList + if (this.list) { + if ("undefined" !== typeof force) { + if (force !== this.list.toggle(name, force)) { + this.list.toggle(name); // toggle again to correct + } + } else { + this.list.toggle(name); + } + return this; + } + + // fallback + if ("undefined" !== typeof force) { + if (!force) { + this.remove(name); + } else { + this.add(name); + } + } else { + if (this.has(name)) { + this.remove(name); + } else { + this.add(name); + } + } + + return this; +}; + +/** + * Return an array of classes. + * + * @return {Array} + * @api public + */ + +ClassList.prototype.array = function(){ + var className = this.el.getAttribute('class') || ''; + var str = className.replace(/^\s+|\s+$/g, ''); + var arr = str.split(re); + if ('' === arr[0]) arr.shift(); + return arr; +}; + +/** + * Check if class `name` is present. + * + * @param {String} name + * @return {ClassList} + * @api public + */ + +ClassList.prototype.has = +ClassList.prototype.contains = function(name){ + return this.list + ? this.list.contains(name) + : !! ~index(this.array(), name); +}; + +},{"195":195}],195:[function(_dereq_,module,exports){ +module.exports = function(arr, obj){ + if (arr.indexOf) return arr.indexOf(obj); + for (var i = 0; i < arr.length; ++i) { + if (arr[i] === obj) return i; + } + return -1; +}; +},{}],196:[function(_dereq_,module,exports){ +var matches = _dereq_(199) + +module.exports = function (element, selector, checkYoSelf, root) { + element = checkYoSelf ? {parentNode: element} : element + + root = root || document + + // Make sure `element !== document` and `element != null` + // otherwise we get an illegal invocation + while ((element = element.parentNode) && element !== document) { + if (matches(element, selector)) + return element + // After `matches` on the edge case that + // the selector matches the root + // (when the root is not the document) + if (element === root) + return + } +} + +},{"199":199}],197:[function(_dereq_,module,exports){ +/** + * Module dependencies. + */ + +var closest = _dereq_(196) + , event = _dereq_(198); + +/** + * Delegate event `type` to `selector` + * and invoke `fn(e)`. A callback function + * is returned which may be passed to `.unbind()`. + * + * @param {Element} el + * @param {String} selector + * @param {String} type + * @param {Function} fn + * @param {Boolean} capture + * @return {Function} + * @api public + */ + +exports.bind = function(el, selector, type, fn, capture){ + return event.bind(el, type, function(e){ + var target = e.target || e.srcElement; + e.delegateTarget = closest(target, selector, true, el); + if (e.delegateTarget) fn.call(el, e); + }, capture); +}; + +/** + * Unbind event `type`'s callback `fn`. + * + * @param {Element} el + * @param {String} type + * @param {Function} fn + * @param {Boolean} capture + * @api public + */ + +exports.unbind = function(el, type, fn, capture){ + event.unbind(el, type, fn, capture); +}; + +},{"196":196,"198":198}],198:[function(_dereq_,module,exports){ +var bind = window.addEventListener ? 'addEventListener' : 'attachEvent', + unbind = window.removeEventListener ? 'removeEventListener' : 'detachEvent', + prefix = bind !== 'addEventListener' ? 'on' : ''; + +/** + * Bind `el` event `type` to `fn`. + * + * @param {Element} el + * @param {String} type + * @param {Function} fn + * @param {Boolean} capture + * @return {Function} + * @api public + */ + +exports.bind = function(el, type, fn, capture){ + el[bind](prefix + type, fn, capture || false); + return fn; +}; + +/** + * Unbind `el` event `type`'s callback `fn`. + * + * @param {Element} el + * @param {String} type + * @param {Function} fn + * @param {Boolean} capture + * @return {Function} + * @api public + */ + +exports.unbind = function(el, type, fn, capture){ + el[unbind](prefix + type, fn, capture || false); + return fn; +}; +},{}],199:[function(_dereq_,module,exports){ +/** + * Module dependencies. + */ + +var query = _dereq_(200); + +/** + * Element prototype. + */ + +var proto = Element.prototype; + +/** + * Vendor function. + */ + +var vendor = proto.matches + || proto.webkitMatchesSelector + || proto.mozMatchesSelector + || proto.msMatchesSelector + || proto.oMatchesSelector; + +/** + * Expose `match()`. + */ + +module.exports = match; + +/** + * Match `el` to `selector`. + * + * @param {Element} el + * @param {String} selector + * @return {Boolean} + * @api public + */ + +function match(el, selector) { + if (!el || el.nodeType !== 1) return false; + if (vendor) return vendor.call(el, selector); + var nodes = query.all(selector, el.parentNode); + for (var i = 0; i < nodes.length; ++i) { + if (nodes[i] == el) return true; + } + return false; +} + +},{"200":200}],200:[function(_dereq_,module,exports){ +function one(selector, el) { + return el.querySelector(selector); +} + +exports = module.exports = function(selector, el){ + el = el || document; + return one(selector, el); +}; + +exports.all = function(selector, el){ + el = el || document; + return el.querySelectorAll(selector); +}; + +exports.engine = function(obj){ + if (!obj.one) throw new Error('.one callback required'); + if (!obj.all) throw new Error('.all callback required'); + one = obj.one; + exports.all = obj.all; + return exports; +}; + +},{}],201:[function(_dereq_,module,exports){ + +/** + * Expose `parse`. + */ + +module.exports = parse; + +/** + * Tests for browser support. + */ + +var div = document.createElement('div'); +// Setup +div.innerHTML = ' <link/><table></table><a href="/a">a</a><input type="checkbox"/>'; +// Make sure that link elements get serialized correctly by innerHTML +// This requires a wrapper element in IE +var innerHTMLBug = !div.getElementsByTagName('link').length; +div = undefined; + +/** + * Wrap map from jquery. + */ + +var map = { + legend: [1, '<fieldset>', '</fieldset>'], + tr: [2, '<table><tbody>', '</tbody></table>'], + col: [2, '<table><tbody></tbody><colgroup>', '</colgroup></table>'], + // for script/link/style tags to work in IE6-8, you have to wrap + // in a div with a non-whitespace character in front, ha! + _default: innerHTMLBug ? [1, 'X<div>', '</div>'] : [0, '', ''] +}; + +map.td = +map.th = [3, '<table><tbody><tr>', '</tr></tbody></table>']; + +map.option = +map.optgroup = [1, '<select multiple="multiple">', '</select>']; + +map.thead = +map.tbody = +map.colgroup = +map.caption = +map.tfoot = [1, '<table>', '</table>']; + +map.polyline = +map.ellipse = +map.polygon = +map.circle = +map.text = +map.line = +map.path = +map.rect = +map.g = [1, '<svg xmlns="http://www.w3.org/2000/svg" version="1.1">','</svg>']; + +/** + * Parse `html` and return a DOM Node instance, which could be a TextNode, + * HTML DOM Node of some kind (<div> for example), or a DocumentFragment + * instance, depending on the contents of the `html` string. + * + * @param {String} html - HTML string to "domify" + * @param {Document} doc - The `document` instance to create the Node for + * @return {DOMNode} the TextNode, DOM Node, or DocumentFragment instance + * @api private + */ + +function parse(html, doc) { + if ('string' != typeof html) throw new TypeError('String expected'); + + // default to the global `document` object + if (!doc) doc = document; + + // tag name + var m = /<([\w:]+)/.exec(html); + if (!m) return doc.createTextNode(html); + + html = html.replace(/^\s+|\s+$/g, ''); // Remove leading/trailing whitespace + + var tag = m[1]; + + // body support + if (tag == 'body') { + var el = doc.createElement('html'); + el.innerHTML = html; + return el.removeChild(el.lastChild); + } + + // wrap map + var wrap = map[tag] || map._default; + var depth = wrap[0]; + var prefix = wrap[1]; + var suffix = wrap[2]; + var el = doc.createElement('div'); + el.innerHTML = prefix + html + suffix; + while (depth--) el = el.lastChild; + + // one element + if (el.firstChild == el.lastChild) { + return el.removeChild(el.firstChild); + } + + // several elements + var fragment = doc.createDocumentFragment(); + while (el.firstChild) { + fragment.appendChild(el.removeChild(el.firstChild)); + } + + return fragment; +} + +},{}],202:[function(_dereq_,module,exports){ +module.exports = _dereq_(204); + +module.exports.Collection = _dereq_(203); +},{"203":203,"204":204}],203:[function(_dereq_,module,exports){ +'use strict'; + +/** + * An empty collection stub. Use {@link RefsCollection.extend} to extend a + * collection with ref semantics. + * + * @classdesc A change and inverse-reference aware collection with set semantics. + * + * @class RefsCollection + */ +function RefsCollection() { } + +/** + * Extends a collection with {@link Refs} aware methods + * + * @memberof RefsCollection + * @static + * + * @param {Array<Object>} collection + * @param {Refs} refs instance + * @param {Object} property represented by the collection + * @param {Object} target object the collection is attached to + * + * @return {RefsCollection<Object>} the extended array + */ +function extend(collection, refs, property, target) { + + var inverseProperty = property.inverse; + + /** + * Removes the given element from the array and returns it. + * + * @method RefsCollection#remove + * + * @param {Object} element the element to remove + */ + collection.remove = function(element) { + var idx = this.indexOf(element); + if (idx !== -1) { + this.splice(idx, 1); + + // unset inverse + refs.unset(element, inverseProperty, target); + } + + return element; + }; + + /** + * Returns true if the collection contains the given element + * + * @method RefsCollection#contains + * + * @param {Object} element the element to check for + */ + collection.contains = function(element) { + return this.indexOf(element) !== -1; + }; + + /** + * Adds an element to the array, unless it exists already (set semantics). + * + * @method RefsCollection#add + * + * @param {Object} element the element to add + */ + collection.add = function(element) { + + if (!this.contains(element)) { + this.push(element); + + // set inverse + refs.set(element, inverseProperty, target); + } + }; + + return collection; +} + + +module.exports.extend = extend; +},{}],204:[function(_dereq_,module,exports){ +'use strict'; + +var Collection = _dereq_(203); + +function hasOwnProperty(e, property) { + return Object.prototype.hasOwnProperty.call(e, property.name || property); +} + + +function defineCollectionProperty(ref, property, target) { + Object.defineProperty(target, property.name, { + enumerable: property.enumerable, + value: Collection.extend(target[property.name] || [], ref, property, target) + }); +} + + +function defineProperty(ref, property, target) { + + var inverseProperty = property.inverse; + + var _value = target[property.name]; + + Object.defineProperty(target, property.name, { + enumerable: property.enumerable, + + get: function() { + return _value; + }, + + set: function(value) { + + // return if we already performed all changes + if (value === _value) { + return; + } + + var old = _value; + + // temporary set null + _value = null; + + if (old) { + ref.unset(old, inverseProperty, target); + } + + // set new value + _value = value; + + // set inverse value + ref.set(_value, inverseProperty, target); + } + }); + +} + +/** + * Creates a new references object defining two inversly related + * attribute descriptors a and b. + * + * <p> + * When bound to an object using {@link Refs#bind} the references + * get activated and ensure that add and remove operations are applied + * reversely, too. + * </p> + * + * <p> + * For attributes represented as collections {@link Refs} provides the + * {@link RefsCollection#add}, {@link RefsCollection#remove} and {@link RefsCollection#contains} extensions + * that must be used to properly hook into the inverse change mechanism. + * </p> + * + * @class Refs + * + * @classdesc A bi-directional reference between two attributes. + * + * @param {Refs.AttributeDescriptor} a property descriptor + * @param {Refs.AttributeDescriptor} b property descriptor + * + * @example + * + * var refs = Refs({ name: 'wheels', collection: true, enumerable: true }, { name: 'car' }); + * + * var car = { name: 'toyota' }; + * var wheels = [{ pos: 'front-left' }, { pos: 'front-right' }]; + * + * refs.bind(car, 'wheels'); + * + * car.wheels // [] + * car.wheels.add(wheels[0]); + * car.wheels.add(wheels[1]); + * + * car.wheels // [{ pos: 'front-left' }, { pos: 'front-right' }] + * + * wheels[0].car // { name: 'toyota' }; + * car.wheels.remove(wheels[0]); + * + * wheels[0].car // undefined + */ +function Refs(a, b) { + + if (!(this instanceof Refs)) { + return new Refs(a, b); + } + + // link + a.inverse = b; + b.inverse = a; + + this.props = {}; + this.props[a.name] = a; + this.props[b.name] = b; +} + +/** + * Binds one side of a bi-directional reference to a + * target object. + * + * @memberOf Refs + * + * @param {Object} target + * @param {String} property + */ +Refs.prototype.bind = function(target, property) { + if (typeof property === 'string') { + if (!this.props[property]) { + throw new Error('no property <' + property + '> in ref'); + } + property = this.props[property]; + } + + if (property.collection) { + defineCollectionProperty(this, property, target); + } else { + defineProperty(this, property, target); + } +}; + +Refs.prototype.ensureBound = function(target, property) { + if (!hasOwnProperty(target, property)) { + this.bind(target, property); + } +}; + +Refs.prototype.unset = function(target, property, value) { + + if (target) { + this.ensureBound(target, property); + + if (property.collection) { + target[property.name].remove(value); + } else { + target[property.name] = undefined; + } + } +}; + +Refs.prototype.set = function(target, property, value) { + + if (target) { + this.ensureBound(target, property); + + if (property.collection) { + target[property.name].add(value); + } else { + target[property.name] = value; + } + } +}; + +module.exports = Refs; + + +/** + * An attribute descriptor to be used specify an attribute in a {@link Refs} instance + * + * @typedef {Object} Refs.AttributeDescriptor + * @property {String} name + * @property {boolean} [collection=false] + * @property {boolean} [enumerable=false] + */ +},{"203":203}]},{},[1])(1) +}); +//# sourceMappingURL=bpmn-navigated-viewer.js.map
\ No newline at end of file |