(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.BpmnJS = f()}})(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 0) {
throw new Error('Invalid string. Length must be a multiple of 4')
}
// the number of equal signs (place holders)
// if there are two placeholders, than the two characters before it
// represent one byte
// if there is only one, then the three characters before it represent 2 bytes
// this is just a cheap hack to not do indexOf twice
var len = b64.length
placeHolders = '=' === b64.charAt(len - 2) ? 2 : '=' === b64.charAt(len - 1) ? 1 : 0
// base64 is 4/3 + up to two characters of the original data
arr = new Arr(b64.length * 3 / 4 - placeHolders)
// if there are placeholders, only get up to the last complete 4 chars
l = placeHolders > 0 ? b64.length - 4 : b64.length
var L = 0
function push (v) {
arr[L++] = v
}
for (i = 0, j = 0; i < l; i += 4, j += 3) {
tmp = (decode(b64.charAt(i)) << 18) | (decode(b64.charAt(i + 1)) << 12) | (decode(b64.charAt(i + 2)) << 6) | decode(b64.charAt(i + 3))
push((tmp & 0xFF0000) >> 16)
push((tmp & 0xFF00) >> 8)
push(tmp & 0xFF)
}
if (placeHolders === 2) {
tmp = (decode(b64.charAt(i)) << 2) | (decode(b64.charAt(i + 1)) >> 4)
push(tmp & 0xFF)
} else if (placeHolders === 1) {
tmp = (decode(b64.charAt(i)) << 10) | (decode(b64.charAt(i + 1)) << 4) | (decode(b64.charAt(i + 2)) >> 2)
push((tmp >> 8) & 0xFF)
push(tmp & 0xFF)
}
return arr
}
function uint8ToBase64 (uint8) {
var i,
extraBytes = uint8.length % 3, // if we have 1 byte left, pad 2 bytes
output = "",
temp, length
function encode (num) {
return lookup.charAt(num)
}
function tripletToBase64 (num) {
return encode(num >> 18 & 0x3F) + encode(num >> 12 & 0x3F) + encode(num >> 6 & 0x3F) + encode(num & 0x3F)
}
// go through the array every three bytes, we'll deal with trailing stuff later
for (i = 0, length = uint8.length - extraBytes; i < length; i += 3) {
temp = (uint8[i] << 16) + (uint8[i + 1] << 8) + (uint8[i + 2])
output += tripletToBase64(temp)
}
// pad the end with zeros, but make sure to not forget the extra bytes
switch (extraBytes) {
case 1:
temp = uint8[uint8.length - 1]
output += encode(temp >> 2)
output += encode((temp << 4) & 0x3F)
output += '=='
break
case 2:
temp = (uint8[uint8.length - 2] << 8) + (uint8[uint8.length - 1])
output += encode(temp >> 10)
output += encode((temp >> 4) & 0x3F)
output += encode((temp << 2) & 0x3F)
output += '='
break
}
return output
}
exports.toByteArray = b64ToByteArray
exports.fromByteArray = uint8ToBase64
}(typeof exports === 'undefined' ? (this.base64js = {}) : exports))
},{}],3:[function(require,module,exports){
module.exports = require('./lib');
},{"./lib":27}],4:[function(require,module,exports){
'use strict';
var DEFAULT_PRIORITY = 1000;
/**
* A component that decides upon the visibility / editable
* state of properties in the properties panel.
*
* Implementors must subclass this component and override
* {@link PropertiesActivator#isEntryVisible} and
* {@link PropertiesActivator#isPropertyEditable} to provide
* custom behavior.
*
* @class
* @constructor
*
* @param {EventBus} eventBus
* @param {Number} [priority] at which priority to hook into the activation
*/
function PropertiesActivator(eventBus, priority) {
var self = this;
priority = priority || DEFAULT_PRIORITY;
eventBus.on('propertiesPanel.isEntryVisible', priority, function(e) {
return self.isEntryVisible(e.entry, e.element);
});
eventBus.on('propertiesPanel.isPropertyEditable', priority, function(e) {
return self.isPropertyEditable(e.entry, e.propertyName, e.element);
});
}
PropertiesActivator.$inject = [ 'eventBus' ];
module.exports = PropertiesActivator;
/**
* Should the given entry be visible for the specified element.
*
* @method PropertiesActivator#isEntryVisible
*
* @param {EntryDescriptor} entry
* @param {ModdleElement} element
*
* @returns {Boolean}
*/
PropertiesActivator.prototype.isEntryVisible = function(entry, element) {
return true;
};
/**
* Should the given property be editable for the specified element
*
* @method PropertiesActivator#isPropertyEditable
*
* @param {EntryDescriptor} entry
* @param {String} propertyName
* @param {ModdleElement} element
*
* @returns {Boolean}
*/
PropertiesActivator.prototype.isPropertyEditable = function(entry, propertyName, element) {
return true;
};
},{}],5:[function(require,module,exports){
'use strict';
var domify = require('min-dom/lib/domify'),
domQuery = require('min-dom/lib/query'),
domRemove = require('min-dom/lib/remove'),
domClasses = require('min-dom/lib/classes'),
domClosest = require('min-dom/lib/closest'),
domAttr = require('min-dom/lib/attr'),
domDelegate = require('min-dom/lib/delegate'),
domMatches = require('min-dom/lib/matches');
var forEach = require('lodash/collection/forEach'),
filter = require('lodash/collection/filter'),
get = require('lodash/object/get'),
keys = require('lodash/object/keys'),
isEmpty = require('lodash/lang/isEmpty'),
isArray = require('lodash/lang/isArray'),
xor = require('lodash/array/xor'),
debounce = require('lodash/function/debounce'),
filter = require('lodash/collection/filter');
var updateSelection = require('selection-update');
var scrollTabs = require('scroll-tabs');
var HIDE_CLASS = 'pp-hidden';
var DEBOUNCE_DELAY = 300;
function isToggle(node) {
return node.type === 'checkbox' || node.type === 'radio';
}
function isSelect(node) {
return node.type === 'select-one';
}
function getPropertyPlaceholders(node) {
var selector = 'input[name], textarea[name], [data-value]';
var placeholders = domQuery.all(selector, node);
if ((!placeholders || !placeholders.length) && domMatches(node, selector)) {
placeholders = [ node ];
}
return placeholders;
}
/**
* Return all active form controls.
* This excludes the invisible controls unless all is true
*
* @param {Element} node
* @param {Boolean} [all=false]
*/
function getFormControls(node, all) {
var controls = domQuery.all('input[name], textarea[name], select[name]', node);
if (!controls || !controls.length) {
controls = domMatches(node, 'option') ? [ node ] : controls;
}
if (!all) {
controls = filter(controls, function(node) {
return !domClosest(node, '.' + HIDE_CLASS);
});
}
return controls;
}
function getFormControlValuesInScope(entryNode) {
var values = {};
var controlNodes = getFormControls(entryNode);
forEach(controlNodes, function(controlNode) {
var value = controlNode.value;
var name = domAttr(controlNode, 'name') || domAttr(controlNode, 'data-name');
// take toggle state into account for radio / checkboxes
if (isToggle(controlNode)) {
if (controlNode.checked) {
if (!domAttr(controlNode, 'value')) {
value = true;
} else {
value = controlNode.value;
}
} else {
value = null;
}
}
if (value !== null) {
// return the actual value
// handle serialization in entry provider
// (ie. if empty string should be serialized or not)
values[name] = value;
}
});
return values;
}
/**
* Extract input values from entry node
*
* @param {DOMElement} entryNode
* @returns {Object}
*/
function getFormControlValues(entryNode) {
var values;
var listContainer = domQuery('[data-list-entry-container]', entryNode);
if(!!listContainer) {
values = [];
var listNodes = listContainer.children || [];
forEach(listNodes, function(listNode) {
values.push(getFormControlValuesInScope(listNode));
});
}
else {
values = getFormControlValuesInScope(entryNode);
}
return values;
}
var keys = Object.keys;
/**
* Return true if the given form extracted value equals
* to an old cached version.
*
* @param {Object} value
* @param {Object} oldValue
* @return {Boolean}
*/
function valueEqual(value, oldValue) {
if (value && !oldValue) {
return false;
}
var allKeys = keys(value).concat(keys(oldValue));
return allKeys.every(function(key) {
return value[key] === oldValue[key];
});
}
/**
* Return true if the given form extracted value(s)
* equal an old cached version.
*
* @param {Array|Object} values
* @param {Array|Object} oldValues
* @return {Boolean}
*/
function valuesEqual(values, oldValues) {
if (isArray(values)) {
if (values.length !== oldValues.length) {
return false;
}
return values.every(function(v, idx) {
return valueEqual(v, oldValues[idx]);
});
}
return valueEqual(values, oldValues);
}
/**
* Return a mapping of { id: entry } for all entries in the given groups in the given tabs.
*
* @param {Object} tabs
* @return {Object}
*/
function extractEntries(tabs) {
return indexBy(flattenDeep(map(flattenDeep(map(tabs, 'groups')), 'entries')), 'id');
}
/**
* Return a mapping of { id: group } for all groups in the given tabs.
*
* @param {Object} tabs
* @return {Object}
*/
function extractGroups(tabs) {
return indexBy(flattenDeep(map(tabs, 'groups')), 'id');
}
/**
* Get the expandable textarea.
*
* @param {DOMElement} node
*
* @return {DOMElement} expandable textarea
*/
function getExpandableTextArea(node) {
return domQuery('textarea[data-expandable]', node);
}
/**
* Expands the given textarea according to the line breaks
* in the value.
*
* The minimum rows are determined from the attribute [data-min-rows].
* The maximum rows are determined from the attribute [data-max-rows].
*
* If the number of line breaks is greater than the maximum rows value,
* then the attribute [rows] of the textarea is set to [data-max-rows]. If
* the attribute [data-max-rows] is not present, then the attribute [rows]
* of the textarea is set to the number of line breaks or [data-min-rows].
*
* If the number of line breaks is less than the minimum rows value,
* then the attribute [rows] of the textarea is set to [data-min-rows].
* If the attribute [data-min-rows] is not present, then the attribute [rows]
* of the textarea is set to the numer of line breaks or [data-max-rows].
*
* @param {DOMElement} textarea
*/
function expandTextArea(textarea) {
if (textarea) {
var value = textarea.value || '';
var lines = value.split(/\r?\n/g);
var minRows = domAttr(textarea, 'data-min-rows');
var maxRows = domAttr(textarea, 'data-max-rows');
var rows = lines.length || 1;
if (minRows) {
rows = Math.max(parseInt(minRows, 10), rows);
}
if (maxRows) {
rows = Math.min(parseInt(maxRows, 10), rows);
}
textarea.rows = rows;
}
}
/**
* A properties panel implementation.
*
* To use it provide a `propertiesProvider` component that knows
* about which properties to display.
*
* Properties edit state / visibility can be intercepted
* via a custom {@link PropertiesActivator}.
*
* @class
* @constructor
*
* @param {Object} config
* @param {EventBus} eventBus
* @param {Modeling} modeling
* @param {PropertiesProvider} propertiesProvider
* @param {Canvas} canvas
* @param {CommandStack} commandStack
*/
function PropertiesPanel(config, eventBus, modeling, propertiesProvider, commandStack, canvas) {
this._eventBus = eventBus;
this._modeling = modeling;
this._commandStack = commandStack;
this._canvas = canvas;
this._propertiesProvider = propertiesProvider;
this._init(config);
}
PropertiesPanel.$inject = [
'config.propertiesPanel',
'eventBus',
'modeling',
'propertiesProvider',
'commandStack',
'canvas' ];
module.exports = PropertiesPanel;
PropertiesPanel.prototype._init = function(config) {
var eventBus = this._eventBus;
var self = this;
/**
* Select the root element once it is added to the canvas
*/
eventBus.on('root.added', function(e) {
self.update(e.element);
});
eventBus.on('selection.changed', function(e) {
var newElement = e.newSelection[0];
self.update(newElement);
});
// add / update tab-bar scrolling
eventBus.on([
'propertiesPanel.changed',
'propertiesPanel.resized'
], function(event) {
var tabBarNode = domQuery('.djs-properties-tab-bar', self._container);
if (!tabBarNode) {
return;
}
var scroller = scrollTabs.get(tabBarNode);
if (!scroller) {
// we did not initialize yet, do that
// now and make sure we select the active
// tab on scroll update
scroller = scrollTabs(tabBarNode, {
selectors: {
tabsContainer: '.djs-properties-tabs-links',
tab: '.djs-properties-tabs-links li',
ignore: '.pp-hidden',
active: '.pp-active'
}
});
scroller.on('scroll', function(newActiveNode, oldActiveNode, direction) {
var linkNode = domQuery('[data-tab-target]', newActiveNode);
var tabId = domAttr(linkNode, 'data-tab-target');
self.activateTab(tabId);
});
}
// react on tab changes and or tabContainer resize
// and make sure the active tab is shown completely
scroller.update();
});
eventBus.on('elements.changed', function(e) {
var current = self._current;
var element = current && current.element;
if (element) {
if (e.elements.indexOf(element) !== -1) {
self.update(element);
}
}
});
eventBus.on('diagram.destroy', function() {
self.detach();
});
this._container = domify('
');
this._bindListeners(this._container);
if (config && config.parent) {
this.attachTo(config.parent);
}
};
PropertiesPanel.prototype.attachTo = function(parentNode) {
if (!parentNode) {
throw new Error('parentNode required');
}
// ensure we detach from the
// previous, old parent
this.detach();
// unwrap jQuery if provided
if (parentNode.get) {
parentNode = parentNode.get(0);
}
if (typeof parentNode === 'string') {
parentNode = domQuery(parentNode);
}
var container = this._container;
parentNode.appendChild(container);
this._emit('attach');
};
PropertiesPanel.prototype.detach = function() {
var container = this._container,
parentNode = container.parentNode;
if (!parentNode) {
return;
}
this._emit('detach');
parentNode.removeChild(container);
};
/**
* Select the given tab within the properties panel.
*
* @param {Object|String} tab
*/
PropertiesPanel.prototype.activateTab = function(tab) {
var tabId = typeof tab === 'string' ? tab : tab.id;
var current = this._current;
var panelNode = current.panel;
var allTabNodes = domQuery.all('.djs-properties-tab', panelNode),
allTabLinkNodes = domQuery.all('.djs-properties-tab-link', panelNode);
forEach(allTabNodes, function(tabNode) {
var currentTabId = domAttr(tabNode, 'data-tab');
domClasses(tabNode).toggle('pp-active', tabId === currentTabId);
});
forEach(allTabLinkNodes, function(tabLinkNode) {
var tabLink = domQuery('[data-tab-target]', tabLinkNode),
currentTabId = domAttr(tabLink, 'data-tab-target');
domClasses(tabLinkNode).toggle('pp-active', tabId === currentTabId);
});
};
/**
* Update the DOM representation of the properties panel
*/
PropertiesPanel.prototype.update = function(element) {
var current = this._current;
// no actual selection change
var needsCreate = true;
if (typeof element === 'undefined') {
// use RootElement of BPMN diagram to generate properties panel if no element is selected
element = this._canvas.getRootElement();
}
var newTabs = this._propertiesProvider.getTabs(element);
if (current && current.element === element) {
// see if we can reuse the existing panel
needsCreate = this._entriesChanged(current, newTabs);
//needsCreate = false;
}
if (needsCreate) {
if (current) {
// remove old panel
domRemove(current.panel);
}
this._current = this._create(element, newTabs);
// activate first tab
this.activateTab(this._current.tabs[0]);
}
if (this._current) {
// make sure correct tab contents are visible
this._updateActivation(this._current);
}
this._emit('changed');
};
/**
* Returns true if one of two groups has different entries than the other.
*
* @param {Object} current
* @param {Object} newTabs
* @return {Booelan}
*/
PropertiesPanel.prototype._entriesChanged = function(current, newTabs) {
var oldEntryIds = keys(current.entries),
newEntryIds = keys(extractEntries(newTabs));
return !isEmpty(xor(oldEntryIds, newEntryIds));
};
PropertiesPanel.prototype._emit = function(event) {
this._eventBus.fire('propertiesPanel.' + event, { panel: this, current: this._current });
};
PropertiesPanel.prototype._bindListeners = function(container) {
var self = this;
// handles a change for a given event
var handleChange = function handleChange(event) {
// see if we handle a change inside a [data-entry] element.
// if not, drop out
var node = domClosest(event.delegateTarget, '[data-entry]'),
entryId, entry;
// change from outside a [data-entry] element, simply ignore
if (!node) {
return;
}
entryId = domAttr(node, 'data-entry');
entry = self.getEntry(entryId);
var values = getFormControlValues(node);
if (event.type === 'change') {
// - if the "data-on-change" attribute is present and a value is changed,
// then the associated action is performed.
// - if the associated action returns "true" then an update to the business
// object is done
// - if it does not return "true", then only the DOM content is updated
var onChangeAction = event.delegateTarget.getAttribute('data-on-change');
if (onChangeAction) {
var isEntryDirty = self.executeAction(entry, node, onChangeAction, event);
if (!isEntryDirty) {
return self.update(self._current.element);
}
}
}
self.applyChanges(entry, values, node);
self.updateState(entry, node);
};
domDelegate.bind(container, 'textarea[data-expandable]', 'input', function(event) {
expandTextArea(event.delegateTarget);
});
// debounce update only elements that are target of key events,
// i.e. INPUT and TEXTAREA. SELECTs will trigger an immediate update anyway.
domDelegate.bind(container, 'input, textarea', 'input', debounce(handleChange, DEBOUNCE_DELAY));
domDelegate.bind(container, 'input, textarea, select', 'change', handleChange);
domDelegate.bind(container, '[data-action]', 'click', function onClick(event) {
// triggers on all inputs
var inputNode = event.delegateTarget;
var entryNode = domClosest(inputNode, '[data-entry]');
var actionId = domAttr(inputNode, 'data-action'),
entryId = domAttr(entryNode, 'data-entry');
var entry = self.getEntry(entryId);
var isEntryDirty = self.executeAction(entry, entryNode, actionId, event);
if (!!isEntryDirty) {
var values = getFormControlValues(entryNode);
self.applyChanges(entry, values, entryNode);
}
self.updateState(entry, entryNode);
});
function handleInput(event, element) {
// triggers on all inputs
var inputNode = event.delegateTarget;
var entryNode = domClosest(inputNode, '[data-entry]');
// only work on data entries
if (!entryNode) {
return;
}
var eventHandlerId = domAttr(inputNode, 'data-blur'),
entryId = domAttr(entryNode, 'data-entry');
var entry = self.getEntry(entryId);
var isEntryDirty = self.executeAction(entry, entryNode, eventHandlerId, event);
if (isEntryDirty) {
var values = getFormControlValues(entryNode);
self.applyChanges(entry, values, entryNode);
}
self.updateState(entry, entryNode);
}
domDelegate.bind(container, '[data-blur]', 'blur', handleInput, true);
// make tab links interactive
domDelegate.bind(container, '.djs-properties-tabs-links [data-tab-target]', 'click', function(event) {
event.preventDefault();
var delegateTarget = event.delegateTarget;
var tabId = domAttr(delegateTarget, 'data-tab-target');
// activate tab on link click
self.activateTab(tabId);
});
};
PropertiesPanel.prototype.updateState = function(entry, entryNode) {
this.updateShow(entry, entryNode);
this.updateDisable(entry, entryNode);
this.updateTextArea(entry, entryNode);
};
/**
* Update the size of a textarea in the DOM, if it is set to be expandable.
*/
PropertiesPanel.prototype.updateTextArea = function(entry, node) {
expandTextArea(getExpandableTextArea(node));
};
/**
* Update the visibility of the entry node in the DOM
*/
PropertiesPanel.prototype.updateShow = function(entry, node) {
var current = this._current;
if (!current) {
return;
}
var showNodes = domQuery.all('[data-show]', node) || [];
forEach(showNodes, function(showNode) {
var expr = domAttr(showNode, 'data-show');
var fn = get(entry, expr);
if (fn) {
var scope = domClosest(showNode, '[data-scope]') || node;
var shouldShow = fn(current.element, node, showNode, scope) || false;
var hasClass = domClasses(showNode).has(HIDE_CLASS);
if (shouldShow) {
if (hasClass) {
domClasses(showNode).remove(HIDE_CLASS);
}
} else {
domClasses(showNode).add(HIDE_CLASS);
}
}
});
};
/**
* Evaluates a given function. If it returns true, then the
* node is marked as "disabled".
*/
PropertiesPanel.prototype.updateDisable = function(entry, node) {
var current = this._current;
if (!current) {
return;
}
var nodes = domQuery.all('[data-disable]', node) || [];
forEach(nodes, function(currentNode) {
var expr = domAttr(currentNode, 'data-disable');
var fn = get(entry, expr);
if (fn) {
var scope = domClosest(currentNode, '[data-scope]') || node;
var shouldDisable = fn(current.element, node, currentNode, scope) || false;
domAttr(currentNode, 'disabled', shouldDisable ? '' : null);
}
});
};
PropertiesPanel.prototype.executeAction = function(entry, entryNode, actionId, event) {
var current = this._current;
if (!current) {
return;
}
var fn = get(entry, actionId);
if (!!fn) {
var scopeNode = domClosest(event.target, '[data-scope]') || entryNode;
return fn.apply(entry, [ current.element, entryNode, event, scopeNode ]);
}
};
/**
* Apply changes to the business object by executing a command
*/
PropertiesPanel.prototype.applyChanges = function(entry, values, containerElement) {
var element = this._current.element;
// ensure we only update the model if we got dirty changes
if (valuesEqual(values, entry.oldValues)) {
return;
}
var command = entry.set(element, values, containerElement);
var commandToExecute;
if (isArray(command)) {
if (command.length) {
commandToExecute = {
cmd: 'properties-panel.multi-command-executor',
context: flattenDeep(command)
};
}
} else {
commandToExecute = command;
}
if (commandToExecute) {
this._commandStack.execute(commandToExecute.cmd, commandToExecute.context || {element : element});
} else {
this.update(element);
}
};
/**
* apply validation errors in the DOM and show or remove an error message near the entry node.
*/
PropertiesPanel.prototype.applyValidationErrors = function(validationErrors, entryNode) {
var valid = true;
var controlNodes = getFormControls(entryNode, true);
forEach(controlNodes, function(controlNode) {
var name = domAttr(controlNode, 'name') || domAttr(controlNode, 'data-name');
var error = validationErrors && validationErrors[name];
var errorMessageNode = domQuery('.pp-error-message', controlNode.parentNode);
if (error) {
valid = false;
if (!errorMessageNode) {
errorMessageNode = domify('
');
domClasses(errorMessageNode).add('pp-error-message');
// insert errorMessageNode after controlNode
controlNode.parentNode.insertBefore(errorMessageNode, controlNode.nextSibling);
}
errorMessageNode.innerHTML = error;
domClasses(controlNode).add('invalid');
} else {
domClasses(controlNode).remove('invalid');
if (errorMessageNode) {
controlNode.parentNode.removeChild(errorMessageNode);
}
}
});
return valid;
};
/**
* Check if the entry contains valid input
*/
PropertiesPanel.prototype.validate = function(entry, values, entryNode) {
var self = this;
var current = this._current;
var valid = true;
entryNode = entryNode || domQuery('[data-entry="' + entry.id + '"]', current.panel);
if (values instanceof Array) {
var listContainer = domQuery('[data-list-entry-container]', entryNode),
listEntryNodes = listContainer.children || [];
// create new elements
for(var i = 0; i < values.length; i++) {
var listValue = values[i];
if(entry.validateListItem) {
var validationErrors = entry.validateListItem(current.element, listValue, entryNode, i),
listEntryNode = listEntryNodes[i];
valid = self.applyValidationErrors(validationErrors, listEntryNode) && valid;
}
}
}
else {
if (entry.validate) {
this.validationErrors = entry.validate(current.element, values, entryNode);
valid = self.applyValidationErrors(this.validationErrors, entryNode) && valid;
}
}
return valid;
};
PropertiesPanel.prototype.getEntry = function(id) {
return this._current && this._current.entries[id];
};
var flattenDeep = require('lodash/array/flattenDeep'),
indexBy = require('lodash/collection/indexBy'),
map = require('lodash/collection/map');
PropertiesPanel.prototype._create = function(element, tabs) {
if (!element) {
return null;
}
var containerNode = this._container;
var panelNode = this._createPanel(element, tabs);
containerNode.appendChild(panelNode);
var entries = extractEntries(tabs);
var groups = extractGroups(tabs);
return {
tabs: tabs,
groups: groups,
entries: entries,
element: element,
panel: panelNode
};
};
PropertiesPanel.prototype._bindTemplate = function(element, entry, values, entryNode, idx) {
var eventBus = this._eventBus;
function isPropertyEditable(entry, propertyName) {
return eventBus.fire('propertiesPanel.isPropertyEditable', {
entry: entry,
propertyName: propertyName,
element: element
});
}
var inputNodes = getPropertyPlaceholders(entryNode);
forEach(inputNodes, function(node) {
var name,
newValue,
editable;
// we deal with an input element
if ('value' in node) {
name = domAttr(node, 'name') || domAttr(node, 'data-name');
newValue = values[name];
editable = isPropertyEditable(entry, name);
if (editable && entry.editable) {
editable = entry.editable(element, entryNode, node, name, newValue, idx);
}
domAttr(node, 'readonly', editable ? null : '');
domAttr(node, 'disabled', editable ? null : '');
if (entry.setControlValue) {
entry.setControlValue(element, entryNode, node, name, newValue, idx);
} else if (isToggle(node)) {
setToggleValue(node, newValue);
} else if (isSelect(node)) {
setSelectValue(node, newValue);
} else {
setInputValue(node, newValue);
}
}
// we deal with some non-editable html element
else {
name = domAttr(node, 'data-value');
newValue = values[name];
if (entry.setControlValue) {
entry.setControlValue(element, entryNode, node, name, newValue, idx);
}
else {
setTextValue(node, newValue);
}
}
});
};
// TODO(nikku): WTF freaking name? Change / clarify.
PropertiesPanel.prototype._updateActivation = function(current) {
var self = this;
var eventBus = this._eventBus;
var element = current.element;
function isEntryVisible(entry) {
return eventBus.fire('propertiesPanel.isEntryVisible', {
entry: entry,
element: element
});
}
function isGroupVisible(group, element, groupNode) {
if (typeof group.enabled === 'function') {
return group.enabled(element, groupNode);
} else {
return true;
}
}
function isTabVisible(tab, element) {
if (typeof tab.enabled === 'function') {
return tab.enabled(element);
} else {
return true;
}
}
function toggleVisible(node, visible) {
domClasses(node).toggle(HIDE_CLASS, !visible);
}
function updateLabel(element, selector, text) {
var labelNode = domQuery(selector, element);
if (!labelNode) {
return;
}
labelNode.textContent = text;
}
var panelNode = current.panel;
forEach(current.tabs, function(tab) {
var tabNode = domQuery('[data-tab=' + tab.id + ']', panelNode);
var tabLinkNode = domQuery('[data-tab-target=' + tab.id + ']', panelNode).parentNode;
var tabVisible = false;
forEach(tab.groups, function(group) {
var groupVisible = false;
var groupNode = domQuery('[data-group=' + group.id + ']', tabNode);
forEach(group.entries, function(entry) {
var entryNode = domQuery('[data-entry="' + entry.id + '"]', groupNode);
var entryVisible = isEntryVisible(entry);
groupVisible = groupVisible || entryVisible;
toggleVisible(entryNode, entryVisible);
var values = 'get' in entry ? entry.get(element, entryNode) : {};
if (values instanceof Array) {
var listEntryContainer = domQuery('[data-list-entry-container]', entryNode);
var existingElements = listEntryContainer.children || [];
for (var i = 0; i < values.length; i++) {
var listValue = values[i];
var listItemNode = existingElements[i];
if (!listItemNode) {
listItemNode = domify(entry.createListEntryTemplate(listValue, i, listEntryContainer));
listEntryContainer.appendChild(listItemNode);
}
domAttr(listItemNode, 'data-index', i);
self._bindTemplate(element, entry, listValue, listItemNode, i);
}
var entriesToRemove = existingElements.length - values.length;
for (var j = 0; j < entriesToRemove; j++) {
// remove orphaned element
listEntryContainer.removeChild(listEntryContainer.lastChild);
}
} else {
self._bindTemplate(element, entry, values, entryNode);
}
// update conditionally visible elements
self.updateState(entry, entryNode);
self.validate(entry, values, entryNode);
// remember initial state for later dirty checking
entry.oldValues = getFormControlValues(entryNode);
});
if (typeof group.label === 'function') {
updateLabel(groupNode, '.group-label', group.label(element, groupNode));
}
groupVisible = groupVisible && isGroupVisible(group, element, groupNode);
tabVisible = tabVisible || groupVisible;
toggleVisible(groupNode, groupVisible);
});
tabVisible = tabVisible && isTabVisible(tab, element);
toggleVisible(tabNode, tabVisible);
toggleVisible(tabLinkNode, tabVisible);
});
// inject elements id into header
updateLabel(panelNode, '[data-label-id]', element.id || '');
};
PropertiesPanel.prototype._createPanel = function(element, tabs) {
var self = this;
var panelNode = domify('
'),
headerNode = domify(''),
tabBarNode = domify('
'),
tabLinksNode = domify(''),
tabContainerNode = domify('
');
panelNode.appendChild(headerNode);
forEach(tabs, function(tab, tabIndex) {
if (!tab.id) {
throw new Error('tab must have an id');
}
var tabNode = domify('
'),
tabLinkNode = domify('' +
'' + tab.label + ' ' +
' ');
var groups = tab.groups;
forEach(groups, function(group) {
if (!group.id) {
throw new Error('group must have an id');
}
var groupNode = domify('' +
' ' +
'' + group.label + ' ' +
'
');
// TODO(nre): use event delegation to handle that...
groupNode.querySelector('.group-toggle').addEventListener('click', function (evt) {
domClasses(groupNode).toggle('group-closed');
evt.preventDefault();
evt.stopPropagation();
});
groupNode.addEventListener('click', function (evt) {
if (!evt.defaultPrevented && domClasses(groupNode).has('group-closed')) {
domClasses(groupNode).remove('group-closed');
}
});
forEach(group.entries, function(entry) {
if (!entry.id) {
throw new Error('entry must have an id');
}
var html = entry.html;
if (typeof html === 'string') {
html = domify(html);
}
// unwrap jquery
if (html.get) {
html = html.get(0);
}
var entryNode = domify('
');
forEach(entry.cssClasses || [], function (cssClass) {
domClasses(entryNode).add(cssClass);
});
entryNode.appendChild(html);
groupNode.appendChild(entryNode);
// update conditionally visible elements
self.updateState(entry, entryNode);
});
tabNode.appendChild(groupNode);
});
tabLinksNode.appendChild(tabLinkNode);
tabContainerNode.appendChild(tabNode);
});
tabBarNode.appendChild(tabLinksNode);
panelNode.appendChild(tabBarNode);
panelNode.appendChild(tabContainerNode);
return panelNode;
};
function setInputValue(node, value) {
var selection;
// prevents input fields from having the value 'undefined'
if (value === undefined) {
value = '';
}
// update selection on undo/redo
if (document.activeElement === node) {
selection = updateSelection(getSelection(node), node.value, value);
}
node.value = value;
if (selection) {
setSelection(node, selection);
}
}
function setSelectValue(node, value) {
if (value !== undefined) {
node.value = value;
}
}
function setToggleValue(node, value) {
var nodeValue = node.value;
node.checked = (value === nodeValue) || (!domAttr(node, 'value') && value);
}
function setTextValue(node, value) {
node.textContent = value;
}
function getSelection(node) {
return {
start: node.selectionStart,
end: node.selectionEnd
};
}
function setSelection(node, selection) {
node.selectionStart = selection.start;
node.selectionEnd = selection.end;
}
},{"lodash/array/flattenDeep":125,"lodash/array/xor":127,"lodash/collection/filter":130,"lodash/collection/forEach":132,"lodash/collection/indexBy":135,"lodash/collection/map":136,"lodash/function/debounce":141,"lodash/lang/isArray":239,"lodash/lang/isEmpty":240,"lodash/object/get":250,"lodash/object/keys":251,"min-dom/lib/attr":262,"min-dom/lib/classes":263,"min-dom/lib/closest":265,"min-dom/lib/delegate":266,"min-dom/lib/domify":267,"min-dom/lib/matches":269,"min-dom/lib/query":270,"min-dom/lib/remove":271,"scroll-tabs":298,"selection-update":299}],6:[function(require,module,exports){
'use strict';
var domQuery = require('min-dom/lib/query'),
domClear = require('min-dom/lib/clear'),
is = require('bpmn-js/lib/util/ModelUtil').is,
forEach = require('lodash/collection/forEach'),
domify = require('min-dom/lib/domify'),
Ids = require('ids');
var SPACE_REGEX = /\s/;
// for QName validation as per http://www.w3.org/TR/REC-xml/#NT-NameChar
var QNAME_REGEX = /^([a-z][\w-.]*:)?[a-z_][\w-.]*$/i;
// for ID validation as per BPMN Schema (QName - Namespace)
var ID_REGEX = /^[a-z_][\w-.]*$/i;
function selectedOption(selectBox) {
if (selectBox.selectedIndex >= 0) {
return selectBox.options[selectBox.selectedIndex].value;
}
}
module.exports.selectedOption = selectedOption;
function selectedType(elementSyntax, inputNode) {
var typeSelect = domQuery(elementSyntax, inputNode);
return selectedOption(typeSelect);
}
module.exports.selectedType = selectedType;
/**
* Retrieve the root element the document this
* business object is contained in.
*
* @return {ModdleElement}
*/
function getRoot(businessObject) {
var parent = businessObject;
while (parent.$parent) {
parent = parent.$parent;
}
return parent;
}
module.exports.getRoot = getRoot;
/**
* filters all elements in the list which have a given type.
* removes a new list
*/
function filterElementsByType(objectList, type) {
var list = objectList || [];
var result = [];
forEach(list, function(obj) {
if (is(obj, type)) {
result.push(obj);
}
});
return result;
}
module.exports.filterElementsByType = filterElementsByType;
function findRootElementsByType(businessObject, referencedType) {
var root = getRoot(businessObject);
return filterElementsByType(root.rootElements, referencedType);
}
module.exports.findRootElementsByType = findRootElementsByType;
function removeAllChildren(domElement) {
while(!!domElement.firstChild) {
domElement.removeChild(domElement.firstChild);
}
}
module.exports.removeAllChildren = removeAllChildren;
/**
* adds an empty option to the list
*/
function addEmptyParameter(list) {
return list.push({'label': '', 'value': '', 'name': ''});
}
module.exports.addEmptyParameter = addEmptyParameter;
/**
* returns a list with all root elements for the given parameter 'referencedType'
*/
function refreshOptionsModel(businessObject, referencedType) {
var model = [];
var referableObjects = findRootElementsByType(businessObject, referencedType);
forEach(referableObjects, function(obj) {
model.push({
label: (obj.name || '') + ' (id='+obj.id+')',
value: obj.id,
name: obj.name
});
});
return model;
}
module.exports.refreshOptionsModel = refreshOptionsModel;
/**
* fills the drop down with options
*/
function updateOptionsDropDown(domSelector, businessObject, referencedType, entryNode) {
var options = refreshOptionsModel(businessObject, referencedType);
addEmptyParameter(options);
var selectBox = domQuery(domSelector, entryNode);
domClear(selectBox);
forEach(options, function(option){
var optionEntry = domify('' + option.label + ' ');
selectBox.appendChild(optionEntry);
});
return options;
}
module.exports.updateOptionsDropDown = updateOptionsDropDown;
/**
* checks whether the id value is valid
*
* @param {ModdleElement} bo
* @param {String} idValue
*
* @return {String} error message
*/
function isIdValid(bo, idValue) {
var assigned = bo.$model.ids.assigned(idValue);
var idExists = !!assigned && assigned !== bo;
if (!idValue || idExists) {
return 'Element must have an unique id.';
}
return validateId(idValue);
}
module.exports.isIdValid = isIdValid;
function validateId(idValue) {
if (containsSpace(idValue)) {
return 'Id must not contain spaces.';
}
if (!ID_REGEX.test(idValue)) {
if (QNAME_REGEX.test(idValue)) {
return 'Id must not contain prefix.';
}
return 'Id must be a valid QName.';
}
}
module.exports.validateId = validateId;
function containsSpace(value) {
return SPACE_REGEX.test(value);
}
module.exports.containsSpace = containsSpace;
/**
* generate a semantic id with given prefix
*/
function nextId(prefix) {
var ids = new Ids([32,32,1]);
return ids.nextPrefixed(prefix);
}
module.exports.nextId = nextId;
function triggerClickEvent(element) {
var evt;
var eventType = 'click';
if (!!document.createEvent) {
try {
// Chrome, Safari, Firefox
evt = new MouseEvent((eventType), { view: window, bubbles: true, cancelable: true });
} catch (e) {
// IE 11, PhantomJS (wat!)
evt = document.createEvent('MouseEvent');
evt.initEvent((eventType), true, true);
}
return element.dispatchEvent(evt);
} else {
// Welcome IE
evt = document.createEventObject();
return element.fireEvent('on' + eventType, evt);
}
}
module.exports.triggerClickEvent = triggerClickEvent;
},{"bpmn-js/lib/util/ModelUtil":57,"ids":120,"lodash/collection/forEach":132,"min-dom/lib/clear":264,"min-dom/lib/domify":267,"min-dom/lib/query":270}],7:[function(require,module,exports){
'use strict';
var elementHelper = require('../helper/ElementHelper');
/**
* A handler capable of creating a new element under a provided parent
* and updating / creating a reference to it in one atomic action.
*
* @class
* @constructor
*/
function CreateAndReferenceElementHandler(elementRegistry, bpmnFactory) {
this._elementRegistry = elementRegistry;
this._bpmnFactory = bpmnFactory;
}
CreateAndReferenceElementHandler.$inject = [ 'elementRegistry', 'bpmnFactory' ];
module.exports = CreateAndReferenceElementHandler;
function ensureNotNull(prop, name) {
if(!prop) {
throw new Error(name + ' required');
}
return prop;
}
////// api /////////////////////////////////////////////
/**
* Creates a new element under a provided parent and updates / creates a reference to it in
* one atomic action.
*
* @method CreateAndReferenceElementHandler#execute
*
* @param {Object} context
* @param {djs.model.Base} context.element which is the context for the reference
* @param {moddle.referencingObject} context.referencingObject the object which creates the reference
* @param {String} context.referenceProperty the property of the referencingObject which makes the reference
* @param {moddle.newObject} context.newObject the new object to add
* @param {moddle.newObjectContainer} context.newObjectContainer the container for the new object
*
* @returns {Array} the updated element
*/
CreateAndReferenceElementHandler.prototype.execute = function(context) {
var referencingObject = ensureNotNull(context.referencingObject, 'referencingObject'),
referenceProperty = ensureNotNull(context.referenceProperty, 'referenceProperty'),
newObject = ensureNotNull(context.newObject, 'newObject'),
newObjectContainer = ensureNotNull(context.newObjectContainer, 'newObjectContainer'),
newObjectParent = ensureNotNull(context.newObjectParent, 'newObjectParent'),
changed = [ context.element ]; // this will not change any diagram-js elements
// create new object
var referencedObject = elementHelper
.createElement(newObject.type, newObject.properties, newObjectParent, this._bpmnFactory);
context.referencedObject = referencedObject;
// add to containing list
newObjectContainer.push(referencedObject);
// adjust reference attribute
context.previousReference = referencingObject[referenceProperty];
referencingObject[referenceProperty] = referencedObject;
context.changed = changed;
// indicate changed on objects affected by the update
return changed;
};
/**
* Reverts the update
*
* @method CreateAndReferenceElementHandler#revert
*
* @param {Object} context
*
* @returns {djs.mode.Base} the updated element
*/
CreateAndReferenceElementHandler.prototype.revert = function(context) {
var referencingObject = context.referencingObject,
referenceProperty = context.referenceProperty,
previousReference = context.previousReference,
referencedObject = context.referencedObject,
newObjectContainer = context.newObjectContainer;
// reset reference
referencingObject.set(referenceProperty, previousReference);
// remove new element
newObjectContainer.splice(newObjectContainer.indexOf(referencedObject), 1);
return context.changed;
};
},{"../helper/ElementHelper":24}],8:[function(require,module,exports){
'use strict';
var forEach = require('lodash/collection/forEach');
var elementHelper = require('../helper/ElementHelper');
/**
* A handler that implements a BPMN 2.0 property update
* for business objects which are not represented in the
* diagram.
*
* This is useful in the context of the properties panel in
* order to update child elements of elements visible in
* the diagram.
*
* Example: perform an update of a specific event definition
* of an intermediate event.
*
* @class
* @constructor
*/
function CreateBusinessObjectListHandler(elementRegistry, bpmnFactory) {
this._elementRegistry = elementRegistry;
this._bpmnFactory = bpmnFactory;
}
CreateBusinessObjectListHandler.$inject = [ 'elementRegistry', 'bpmnFactory' ];
module.exports = CreateBusinessObjectListHandler;
function ensureNotNull(prop, name) {
if(!prop) {
throw new Error(name + ' required');
}
return prop;
}
function ensureList(prop, name) {
if(!prop || Object.prototype.toString.call(prop) !== '[object Array]' ) {
throw new Error(name + ' needs to be a list');
}
return prop;
}
////// api /////////////////////////////////////////////
/**
* Creates a new element under a provided parent and updates / creates a reference to it in
* one atomic action.
*
* @method CreateBusinessObjectListHandler#execute
*
* @param {Object} context
* @param {djs.model.Base} context.element which is the context for the reference
* @param {moddle.referencingObject} context.referencingObject the object which creates the reference
* @param {String} context.referenceProperty the property of the referencingObject which makes the reference
* @param {moddle.newObject} context.newObject the new object to add
* @param {moddle.newObjectContainer} context.newObjectContainer the container for the new object
*
* @return {Array} the updated element
*/
CreateBusinessObjectListHandler.prototype.execute = function(context) {
var currentObject = ensureNotNull(context.currentObject, 'currentObject'),
propertyName = ensureNotNull(context.propertyName, 'propertyName'),
newObjects = ensureList(context.newObjects, 'newObjects'),
changed = [ context.element ]; // this will not change any diagram-js elements
var childObjects = [];
var self = this;
// create new array of business objects
forEach(newObjects, function(obj) {
var element = elementHelper.createElement(obj.type, obj.properties, currentObject, self._bpmnFactory);
childObjects.push(element);
});
context.childObject = childObjects;
// adjust array reference in the parent business object
context.previousChilds = currentObject[propertyName];
currentObject[propertyName] = childObjects;
context.changed = changed;
// indicate changed on objects affected by the update
return changed;
};
/**
* Reverts the update
*
* @method CreateBusinessObjectListHandler#revert
*
* @param {Object} context
*
* @return {djs.mode.Base} the updated element
*/
CreateBusinessObjectListHandler.prototype.revert = function(context) {
var currentObject = context.currentObject,
propertyName = context.propertyName,
previousChilds = context.previousChilds;
// remove new element
currentObject.set(propertyName, previousChilds);
return context.changed;
};
},{"../helper/ElementHelper":24,"lodash/collection/forEach":132}],9:[function(require,module,exports){
'use strict';
var forEach = require('lodash/collection/forEach');
/**
* A handler that combines and executes multiple commands.
*
* All updates are bundled on the command stack and executed in one step.
* This also makes it possible to revert the changes in one step.
*
* Example use case: remove the camunda:formKey attribute and in addition
* add all form fields needed for the camunda:formData property.
*
* @class
* @constructor
*/
function MultiCommandHandler(commandStack) {
this._commandStack = commandStack;
}
MultiCommandHandler.$inject = [ 'commandStack' ];
module.exports = MultiCommandHandler;
MultiCommandHandler.prototype.preExecute = function(context) {
var commandStack = this._commandStack;
forEach(context, function(command) {
commandStack.execute(command.cmd, command.context);
});
};
},{"lodash/collection/forEach":132}],10:[function(require,module,exports){
'use strict';
var reduce = require('lodash/object/transform'),
is = require('bpmn-js/lib/util/ModelUtil').is,
keys = require('lodash/object/keys'),
forEach = require('lodash/collection/forEach');
/**
* A handler that implements a BPMN 2.0 property update
* for business objects which are not represented in the
* diagram.
*
* This is useful in the context of the properties panel in
* order to update child elements of elements visible in
* the diagram.
*
* Example: perform an update of a specific event definition
* of an intermediate event.
*
* @class
* @constructor
*/
function UpdateBusinessObjectHandler(elementRegistry) {
this._elementRegistry = elementRegistry;
}
UpdateBusinessObjectHandler.$inject = [ 'elementRegistry' ];
module.exports = UpdateBusinessObjectHandler;
/**
* returns the root element
*/
function getRoot(businessObject) {
var parent = businessObject;
while(parent.$parent) {
parent = parent.$parent;
}
return parent;
}
function getProperties(businessObject, propertyNames) {
return reduce(propertyNames, function(result, key) {
result[key] = businessObject.get(key);
return result;
}, {});
}
function setProperties(businessObject, properties) {
forEach(properties, function(value, key) {
businessObject.set(key, value);
});
}
////// api /////////////////////////////////////////////
/**
* Updates a business object with a list of new properties
*
* @method UpdateBusinessObjectHandler#execute
*
* @param {Object} context
* @param {djs.model.Base} context.element the element which has a child business object updated
* @param {moddle.businessObject} context.businessObject the businessObject to update
* @param {Object} context.properties a list of properties to set on the businessObject
*
* @return {Array} the updated element
*/
UpdateBusinessObjectHandler.prototype.execute = function(context) {
var element = context.element,
businessObject = context.businessObject,
rootElements = getRoot(businessObject).rootElements,
referenceType = context.referenceType,
referenceProperty = context.referenceProperty,
changed = [ element ]; // this will not change any diagram-js elements
if (!element) {
throw new Error('element required');
}
if(!businessObject) {
throw new Error('businessObject required');
}
var properties = context.properties,
oldProperties = context.oldProperties || getProperties(businessObject, keys(properties));
// check if there the update needs an external element for reference
if(typeof referenceType !== 'undefined' && typeof referenceProperty !== 'undefined') {
forEach(rootElements, function(rootElement) {
if(is(rootElement, referenceType)) {
if(rootElement.id === properties[referenceProperty]) {
properties[referenceProperty] = rootElement;
}
}
});
}
// update properties
setProperties(businessObject, properties);
// store old values
context.oldProperties = oldProperties;
context.changed = changed;
// indicate changed on objects affected by the update
return changed;
};
/**
* Reverts the update
*
* @method UpdateBusinessObjectHandler#revert
*
* @param {Object} context
*
* @return {djs.mode.Base} the updated element
*/
UpdateBusinessObjectHandler.prototype.revert = function(context) {
var oldProperties = context.oldProperties,
businessObject = context.businessObject;
// update properties
setProperties(businessObject, oldProperties);
return context.changed;
};
},{"bpmn-js/lib/util/ModelUtil":57,"lodash/collection/forEach":132,"lodash/object/keys":251,"lodash/object/transform":257}],11:[function(require,module,exports){
'use strict';
var forEach = require('lodash/collection/forEach');
/**
* A handler that implements a BPMN 2.0 property update
* for business object lists which are not represented in the
* diagram.
*
* This is useful in the context of the properties panel in
* order to update child elements of elements visible in
* the diagram.
*
* Example: perform an update of a specific event definition
* of an intermediate event.
*
* @class
* @constructor
*/
function UpdateBusinessObjectListHandler(elementRegistry, bpmnFactory) {
this._elementRegistry = elementRegistry;
this._bpmnFactory = bpmnFactory;
}
UpdateBusinessObjectListHandler.$inject = [ 'elementRegistry', 'bpmnFactory' ];
module.exports = UpdateBusinessObjectListHandler;
function ensureNotNull(prop, name) {
if (!prop) {
throw new Error(name + 'required');
}
return prop;
}
////// api /////////////////////////////////////////////
/**
* Updates a element under a provided parent.
*/
UpdateBusinessObjectListHandler.prototype.execute = function(context) {
var currentObject = ensureNotNull(context.currentObject, 'currentObject'),
propertyName = ensureNotNull(context.propertyName, 'propertyName'),
updatedObjectList = context.updatedObjectList,
objectsToRemove = context.objectsToRemove || [],
objectsToAdd = context.objectsToAdd || [],
changed = [ context.element], // this will not change any diagram-js elements
referencePropertyName;
if (context.referencePropertyName) {
referencePropertyName = context.referencePropertyName;
}
var objectList = currentObject[propertyName];
// adjust array reference in the parent business object
context.previousList = currentObject[propertyName];
if (updatedObjectList) {
currentObject[propertyName] = updatedObjectList;
}
else {
var listCopy = [];
// remove all objects which should be removed
forEach(objectList, function(object) {
if (objectsToRemove.indexOf(object) == -1) {
listCopy.push(object);
}
});
// add all objects which should be added
listCopy = listCopy.concat(objectsToAdd);
// set property to new list
if (listCopy.length > 0 || !referencePropertyName) {
// as long as there are elements in the list update the list
currentObject[propertyName] = listCopy;
} else if (referencePropertyName) {
// remove the list when it is empty
var parentObject = currentObject.$parent;
parentObject.set(referencePropertyName, undefined);
}
}
context.changed = changed;
// indicate changed on objects affected by the update
return changed;
};
/**
* Reverts the update
*
* @method CreateBusinessObjectListHandler#revert
*
* @param {Object} context
*
* @return {djs.mode.Base} the updated element
*/
UpdateBusinessObjectListHandler.prototype.revert = function(context) {
var currentObject = context.currentObject,
propertyName = context.propertyName,
previousList = context.previousList,
parentObject = currentObject.$parent;
if (context.referencePropertyName) {
parentObject.set(context.referencePropertyName, currentObject);
}
// remove new element
currentObject.set(propertyName, previousList);
return context.changed;
};
},{"lodash/collection/forEach":132}],12:[function(require,module,exports){
'use strict';
var forEach = require('lodash/collection/forEach');
var HANDLERS = {
'properties-panel.update-businessobject': require('./UpdateBusinessObjectHandler'),
'properties-panel.create-and-reference': require('./CreateAndReferenceHandler'),
'properties-panel.create-businessobject-list': require('./CreateBusinessObjectListHandler'),
'properties-panel.update-businessobject-list': require('./UpdateBusinessObjectListHandler'),
'properties-panel.multi-command-executor': require('./MultiCommandHandler')
};
function CommandInitializer(eventBus, commandStack) {
eventBus.on('diagram.init', function() {
forEach(HANDLERS, function(handler, id) {
commandStack.registerHandler(id, handler);
});
});
}
CommandInitializer.$inject = [ 'eventBus', 'commandStack' ];
module.exports = {
__init__: [ CommandInitializer ]
};
},{"./CreateAndReferenceHandler":7,"./CreateBusinessObjectListHandler":8,"./MultiCommandHandler":9,"./UpdateBusinessObjectHandler":10,"./UpdateBusinessObjectListHandler":11,"lodash/collection/forEach":132}],13:[function(require,module,exports){
'use strict';
var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
cmdHelper = require('../helper/CmdHelper');
var checkbox = function(options, defaultParameters) {
var resource = defaultParameters,
label = options.label || resource.id,
canBeDisabled = !!options.disabled && typeof options.disabled === 'function';
resource.html =
' ' +
'' + label + ' ';
resource.get = function(element) {
var bo = getBusinessObject(element),
res = {};
res[options.modelProperty] = bo.get(options.modelProperty);
return res;
};
resource.set = function(element, values) {
var res = {};
res[options.modelProperty] = !!values[options.modelProperty];
return cmdHelper.updateProperties(element, res);
};
if(typeof options.set === 'function') {
resource.set = options.set;
}
if(typeof options.get === 'function') {
resource.get = options.get;
}
if(canBeDisabled) {
resource.isDisabled = function() {
return !options.disabled.apply(resource, arguments);
};
}
resource.cssClasses = ['pp-checkbox'];
return resource;
};
module.exports = checkbox;
},{"../helper/CmdHelper":23,"bpmn-js/lib/util/ModelUtil":57}],14:[function(require,module,exports){
'use strict';
var assign = require('lodash/object/assign'),
find = require('lodash/collection/find');
var domQuery = require('min-dom/lib/query');
var selectEntryFactory = require('./SelectEntryFactory');
/**
* The combo box is a special implementation of the select entry and adds the option 'custom' to the
* select box. If 'custom' is selected, an additional text input field is shown which allows to define
* a custom value.
*
* @param {Object} options
* @param {string} options.id
* @param {string} options.label
* @param {Array} options.selectOptions list of name/value pairs
* @param {string} options.modelProperty
* @param {function} options.get
* @param {function} options.set
* @param {function} options.disabled
* @param {string} [options.customValue] custom select option value (default: 'custom')
* @param {string} [options.customName] custom select option name visible in the select box (default: 'custom')
*
* @return {Object}
*/
var comboBox = function(options) {
var selectOptions = options.selectOptions,
modelProperty = options.modelProperty,
customValue = options.customValue || 'custom',
customName = options.customName || 'custom ' + modelProperty;
// check if a value is not a built in value
var isCustomValue = function(value) {
if (typeof value[modelProperty] === 'undefined') {
return false;
}
var isCustom = !find(selectOptions, function(option) {
return value[modelProperty] === option.value;
});
return isCustom;
};
var comboOptions = assign({}, options);
// true if the selected value in the select box is customValue
comboOptions.showCustomInput = function(element, node) {
var selectBox = domQuery('[data-entry="'+ options.id +'"] select', node.parentNode);
if (selectBox) {
return selectBox.value === customValue;
}
return false;
};
comboOptions.get = function(element, node) {
var value = options.get(element, node);
var modifiedValues = {};
if (!isCustomValue(value)) {
modifiedValues[modelProperty] = value[modelProperty] || '';
return modifiedValues;
}
modifiedValues[modelProperty] = customValue;
modifiedValues['custom-'+modelProperty] = value[modelProperty];
return modifiedValues;
};
comboOptions.set = function(element, values, node) {
var modifiedValues = {};
// if the custom select option has been selected
// take the value from the text input field
if (values[modelProperty] === customValue) {
modifiedValues[modelProperty] = values['custom-' + modelProperty] || '';
}
else if (options.emptyParameter && values[modelProperty] === '') {
modifiedValues[modelProperty] = undefined;
}
else {
modifiedValues[modelProperty] = values[modelProperty];
}
return options.set(element, modifiedValues, node);
};
comboOptions.selectOptions.push({ name: customName, value: customValue });
var comboBoxEntry = assign({}, selectEntryFactory(comboOptions, comboOptions));
comboBoxEntry.html += '' +
' ' +
'
';
return comboBoxEntry;
};
module.exports = comboBox;
},{"./SelectEntryFactory":18,"lodash/collection/find":131,"lodash/object/assign":249,"min-dom/lib/query":270}],15:[function(require,module,exports){
'use strict';
var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject;
// input entities
var textInputField = require('./TextInputEntryFactory'),
checkboxField = require('./CheckboxEntryFactory'),
selectBoxField = require('./SelectEntryFactory'),
comboBoxField = require('./ComboEntryFactory'),
textAreaField = require('./TextAreaEntryFactory'),
validationAwareTextInputField = require('./ValidationAwareTextInput'),
tableField = require('./TableEntryFactory'),
labelEntry = require('./LabelFactory'),
link = require('./LinkEntryFactory');
var cmdHelper = require('../helper/CmdHelper');
// helpers ////////////////////////////////////////
function ensureNotNull(prop) {
if(!prop) {
throw new Error(prop + ' must be set.');
}
return prop;
}
/**
* sets the default parameters which are needed to create an entry
*
* @param options
* @returns {{id: *, description: (*|string), get: (*|Function), set: (*|Function),
* validate: (*|Function), html: string}}
*/
var setDefaultParameters = function ( options ) {
// default method to fetch the current value of the input field
var defaultGet = function (element) {
var bo = getBusinessObject(element),
res = {},
prop = ensureNotNull(options.modelProperty);
res[prop] = bo.get(prop);
return res;
};
// default method to set a new value to the input field
var defaultSet = function (element, values) {
var res = {},
prop = ensureNotNull(options.modelProperty);
if (values[prop] !== '') {
res[prop] = values[prop];
} else {
res[prop] = undefined;
}
return cmdHelper.updateProperties(element, res);
};
// default validation method
var defaultValidate = function () {
return {};
};
return {
id : options.id,
description : ( options.description || '' ),
get : ( options.get || defaultGet ),
set : ( options.set || defaultSet ),
validate : ( options.validate || defaultValidate ),
html: ''
};
};
function EntryFactory() {
}
/**
* Generates an text input entry object for a property panel.
* options are:
* - id: id of the entry - String
*
* - description: description of the property - String
*
* - label: label for the input field - String
*
* - set: setter method - Function
*
* - get: getter method - Function
*
* - validate: validation mehtod - Function
*
* - modelProperty: name of the model property - String
*
* - buttonAction: Object which contains the following properties: - Object
* ---- name: name of the [data-action] callback - String
* ---- method: callback function for [data-action] - Function
*
* - buttonShow: Object which contains the following properties: - Object
* ---- name: name of the [data-show] callback - String
* ---- method: callback function for [data-show] - Function
*
* @param options
* @returns the propertyPanel entry resource object
*/
EntryFactory.textField = function(options) {
return textInputField(options, setDefaultParameters(options));
};
EntryFactory.validationAwareTextField = function(options) {
return validationAwareTextInputField(options, setDefaultParameters(options));
};
/**
* Generates a checkbox input entry object for a property panel.
* options are:
* - id: id of the entry - String
*
* - description: description of the property - String
*
* - label: label for the input field - String
*
* - set: setter method - Function
*
* - get: getter method - Function
*
* - validate: validation mehtod - Function
*
* - modelProperty: name of the model property - String
*
* @param options
* @returns the propertyPanel entry resource object
*/
EntryFactory.checkbox = function(options) {
return checkboxField(options, setDefaultParameters(options));
};
EntryFactory.textArea = function(options) {
return textAreaField(options, setDefaultParameters(options));
};
EntryFactory.selectBox = function(options) {
return selectBoxField(options, setDefaultParameters(options));
};
EntryFactory.comboBox = function(options) {
return comboBoxField(options);
};
EntryFactory.table = function(options) {
return tableField(options);
};
EntryFactory.label = function(options) {
return labelEntry(options);
};
EntryFactory.link = function(options) {
return link(options);
};
module.exports = EntryFactory;
},{"../helper/CmdHelper":23,"./CheckboxEntryFactory":13,"./ComboEntryFactory":14,"./LabelFactory":16,"./LinkEntryFactory":17,"./SelectEntryFactory":18,"./TableEntryFactory":19,"./TextAreaEntryFactory":20,"./TextInputEntryFactory":21,"./ValidationAwareTextInput":22,"bpmn-js/lib/util/ModelUtil":57}],16:[function(require,module,exports){
'use strict';
/**
* The label factory provides a label entry. For the label text
* it expects either a string provided by the options.labelText
* parameter or it could be generated programmatically using a
* function passed as the options.get parameter.
*
* @param {Object} options
* @param {string} options.id
* @param {string} [options.labelText]
* @param {Function} [options.get]
* @param {Function} [options.showLabel]
* @param {Boolean} [options.divider] adds a divider at the top of the label if true; default: false
*/
var label = function(options) {
return {
id: options.id,
html: '' +
' ',
get: function(element, node) {
if (typeof options.get === 'function') {
return options.get(element, node);
}
return { label: options.labelText };
},
showLabel: function(element, node) {
if (typeof options.showLabel === 'function') {
return options.showLabel(element, node);
}
return true;
}
};
};
module.exports = label;
},{}],17:[function(require,module,exports){
'use strict';
var utils = require('../Utils');
var link = function(options, defaultParameters) {
var id = options.id,
label = options.label || id,
hideLink = options.hideLink,
canBeHidden = typeof hideLink === 'function',
getClickableElement = options.getClickableElement;
var resource = { id: id };
resource.html =
'' + label + ' ';
resource.linkSelected = function(element, node, event, scopeNode) {
if (typeof getClickableElement === 'function') {
var link = getClickableElement.apply(resource, [ element, node, event, scopeNode ]);
link && utils.triggerClickEvent(link);
}
return false;
};
if (canBeHidden) {
resource.hideLink = function() {
return !hideLink.apply(resource, arguments);
};
}
return resource;
};
module.exports = link;
},{"../Utils":6}],18:[function(require,module,exports){
'use strict';
var forEach = require('lodash/collection/forEach');
var isList = function(list) {
return !(!list || Object.prototype.toString.call(list) !== '[object Array]');
};
var addEmptyParameter = function(list) {
return list.concat([ { name: '', value: '' } ]);
};
/**
* @param {Object} options
* @param {string} options.id
* @param {string} [options.label]
* @param {Array} options.selectOptions
* @param {string} options.modelProperty
* @param {boolean} options.emptyParameter
* @param {function} options.disabled
* @param {Object} defaultParameters
*
* @return {Object}
*/
var selectbox = function(options, defaultParameters) {
var resource = defaultParameters,
label = options.label || resource.id,
selectOptions = options.selectOptions,
modelProperty = options.modelProperty,
emptyParameter = options.emptyParameter,
canBeDisabled = !!options.disabled && typeof options.disabled === 'function';
if (isList(selectOptions)) {
if (emptyParameter) {
selectOptions = addEmptyParameter(selectOptions);
}
} else {
selectOptions = [ { name: '', value: '' } ];
}
resource.html =
'' + label + ' ' +
'';
forEach(selectOptions, function(option){
resource.html += '' + (option.name || '') + ' ';
});
resource.html += ' ';
if(canBeDisabled) {
resource.isDisabled = function() {
return !options.disabled.apply(resource, arguments);
};
}
resource.cssClasses = ['dropdown'];
return resource;
};
module.exports = selectbox;
},{"lodash/collection/forEach":132}],19:[function(require,module,exports){
'use strict';
var cmdHelper = require('../helper/CmdHelper');
var domQuery = require('min-dom/lib/query'),
domAttr = require('min-dom/lib/attr'),
domClosest = require('min-dom/lib/closest');
var filter = require('lodash/collection/filter'),
forEach = require('lodash/collection/forEach'),
keys = require('lodash/object/keys');
var domify = require('min-dom/lib/domify');
var TABLE_ROW_DIV_SNIPPET = '';
var DELETE_ROW_BUTTON_SNIPPET = '' +
'X ' +
' ';
function createInputRowTemplate(properties, canRemove) {
var template = TABLE_ROW_DIV_SNIPPET;
template += createInputTemplate(properties, canRemove);
template += canRemove ? DELETE_ROW_BUTTON_SNIPPET : '';
template += '
';
return template;
}
function createInputTemplate(properties, canRemove) {
var columns = properties.length;
var template = '';
forEach(properties, function(prop) {
template += ' ';
});
return template;
}
function createLabelRowTemplate(labels) {
var template = TABLE_ROW_DIV_SNIPPET;
template += createLabelTemplate(labels);
template += '';
return template;
}
function createLabelTemplate(labels) {
var columns = labels.length;
var template = '';
forEach(labels, function(label) {
template += '' + label + ' ';
});
return template;
}
function pick(elements, properties) {
return (elements || []).map(function(elem) {
var newElement = {};
forEach(properties, function(prop) {
newElement[prop] = elem[prop] || '';
});
return newElement;
});
}
function diff(element, node, values, oldValues, editable) {
return filter(values, function(value, idx) {
return !valueEqual(element, node, value, oldValues[idx], editable, idx);
});
}
function valueEqual(element, node, value, oldValue, editable, idx) {
if (value && !oldValue) {
return false;
}
var allKeys = keys(value).concat(keys(oldValue));
return allKeys.every(function(key) {
var n = value[key] || undefined;
var o = oldValue[key] || undefined;
return !editable(element, node, key, idx) || n === o;
});
}
function getEntryNode(node) {
return domClosest(node, '[data-entry]', true);
}
function getContainer(node) {
return domQuery('div[data-list-entry-container]', node);
}
/**
* @param {Object} options
* @param {string} options.id
* @param {Array} options.modelProperties
* @param {Array} options.labels
* @param {Function} options.getElements - this callback function must return a list of business object items
* @param {Function} options.removeElement
* @param {Function} options.addElement
* @param {Function} options.updateElement
* @param {Function} options.editable
* @param {Function} options.setControlValue
* @param {Function} options.show
*
* @return {Object}
*/
module.exports = function(options) {
var id = options.id,
modelProperties = options.modelProperties,
labels = options.labels;
var labelRow = createLabelRowTemplate(labels);
var getElements = options.getElements;
var removeElement = options.removeElement,
canRemove = typeof removeElement === 'function';
var addElement = options.addElement,
canAdd = typeof addElement === 'function',
addLabel = options.addLabel || 'Add Value';
var updateElement = options.updateElement,
canUpdate = typeof updateElement === 'function';
var editable = options.editable || function() { return true; },
setControlValue = options.setControlValue;
var show = options.show,
canBeShown = typeof show === 'function';
var elements = function(element, node) {
return pick(getElements(element, node), modelProperties);
};
var factory = {
id: id,
html: ( canAdd ?
'' +
'' + addLabel + ' ' +
'+ ' +
'
' : '') +
'' +
'
' +
labelRow +
'
' +
'
' +
'
' +
'
',
get: function(element, node) {
var boElements = elements(element, node, this.__invalidValues);
var invalidValues = this.__invalidValues;
delete this.__invalidValues;
forEach(invalidValues, function(value, idx) {
var element = boElements[idx];
forEach(modelProperties, function(prop) {
element[prop] = value[prop];
});
});
return boElements;
},
set: function(element, values, node) {
var action = this.__action || {};
delete this.__action;
if (action.id === 'delete-element') {
return removeElement(element, node, action.idx);
}
else if (action.id === 'add-element') {
return addElement(element, node);
}
else if (canUpdate) {
var commands = [],
valuesToValidate = values;
if (typeof options.validate !== 'function') {
valuesToValidate = diff(element, node, values, elements(element, node), editable);
}
var self = this;
forEach(valuesToValidate, function(value) {
var validationError,
idx = values.indexOf(value);
if (typeof options.validate === 'function') {
validationError = options.validate(element, value, node, idx);
}
if (!validationError) {
var cmd = updateElement(element, value, node, idx);
if(cmd) {
commands.push(cmd);
}
} else {
// cache invalid value in an object by index as key
self.__invalidValues = self.__invalidValues || {};
self.__invalidValues[idx] = value;
// execute a command, which does not do anything
commands.push(cmdHelper.updateProperties(element, {}));
}
});
return commands;
}
},
createListEntryTemplate: function(value, index, selectBox) {
return createInputRowTemplate(modelProperties, canRemove);
},
addElement: function(element, node, event, scopeNode) {
var template = domify(createInputRowTemplate(modelProperties, canRemove));
var container = getContainer(node);
container.appendChild(template);
this.__action = {
id: 'add-element'
};
return true;
},
deleteElement: function(element, node, event, scopeNode) {
var container = getContainer(node);
var rowToDelete = event.delegateTarget.parentNode;
var idx = parseInt(domAttr(rowToDelete, 'data-index'), 10);
container.removeChild(rowToDelete);
this.__action = {
id: 'delete-element',
idx: idx
};
return true;
},
editable: function(element, rowNode, input, prop, value, idx) {
var entryNode = domClosest(rowNode, '[data-entry]');
return editable(element, entryNode, prop, idx);
},
show: function(element, entryNode, node, scopeNode) {
entryNode = getEntryNode(entryNode);
return show(element, entryNode, node, scopeNode);
},
showTable: function(element, entryNode, node, scopeNode) {
entryNode = getEntryNode(entryNode);
var elems = elements(element, entryNode);
return elems && elems.length && (!canBeShown || show(element, entryNode, node, scopeNode));
},
validateListItem: function(element, value, node, idx) {
if (typeof options.validate === 'function') {
return options.validate(element, value, node, idx);
}
}
};
if (setControlValue) {
factory.setControlValue = function(element, rowNode, input, prop, value, idx) {
var entryNode = getEntryNode(rowNode);
setControlValue(element, entryNode, input, prop, value, idx);
};
}
return factory;
};
},{"../helper/CmdHelper":23,"lodash/collection/filter":130,"lodash/collection/forEach":132,"lodash/object/keys":251,"min-dom/lib/attr":262,"min-dom/lib/closest":265,"min-dom/lib/domify":267,"min-dom/lib/query":270}],20:[function(require,module,exports){
'use strict';
var textArea = function(options, defaultParameters) {
var resource = defaultParameters,
label = options.label || resource.id,
canBeShown = !!options.show && typeof options.show === 'function',
expandable = options.expandable,
minRows = options.minRows,
maxRows = options.maxRows;
resource.html =
'' + label + ' ' +
'' +
'' +
'
';
if(canBeShown) {
resource.isShown = function() {
return options.show.apply(resource, arguments);
};
}
resource.cssClasses = ['pp-textarea'];
return resource;
};
module.exports = textArea;
},{}],21:[function(require,module,exports){
'use strict';
var domQuery = require('min-dom/lib/query');
var textField = function(options, defaultParameters) {
// Default action for the button next to the input-field
var defaultButtonAction = function (element, inputNode) {
var input = domQuery('input[name="' + options.modelProperty + '"]', inputNode);
input.value = '';
return true;
};
// default method to determine if the button should be visible
var defaultButtonShow = function (element, inputNode) {
var input = domQuery('input[name="' + options.modelProperty + '"]', inputNode);
return input.value !== '';
};
var resource = defaultParameters,
label = options.label || resource.id,
dataValueLabel = options.dataValueLabel,
buttonLabel = ( options.buttonLabel || 'X' ),
actionName = ( typeof options.buttonAction != 'undefined' ) ? options.buttonAction.name : 'clear',
actionMethod = ( typeof options.buttonAction != 'undefined' ) ? options.buttonAction.method : defaultButtonAction,
showName = ( typeof options.buttonShow != 'undefined' ) ? options.buttonShow.name : 'canClear',
showMethod = ( typeof options.buttonShow != 'undefined' ) ? options.buttonShow.method : defaultButtonShow,
canBeDisabled = !!options.disabled && typeof options.disabled === 'function';
resource.html =
''+ label +' ' +
'' +
' ' +
'' +
'' + buttonLabel + ' ' +
' ' +
'
';
resource[actionName] = actionMethod;
resource[showName] = showMethod;
if(canBeDisabled) {
resource.isDisabled = function() {
return !options.disabled.apply(resource, arguments);
};
}
resource.cssClasses = ['pp-textfield'];
return resource;
};
module.exports = textField;
},{"min-dom/lib/query":270}],22:[function(require,module,exports){
'use strict';
var textField = require('./TextInputEntryFactory');
/**
* This function is a wrapper around TextInputEntryFactory.
* It adds functionality to cache an invalid value entered in the
* text input, instead of setting it on the business object.
*/
var validationAwareTextField = function(options, defaultParameters) {
var modelProperty = options.modelProperty;
defaultParameters.get = function(element, node) {
var value = this.__lastInvalidValue;
delete this.__lastInvalidValue;
var properties = {};
properties[modelProperty] = value !== undefined ? value : options.getProperty(element, node);
return properties;
};
defaultParameters.set = function(element, values, node) {
var validationErrors = validate.apply(this, [ element, values, node ]),
propertyValue = values[modelProperty];
// make sure we do not update the id
if (validationErrors && validationErrors[modelProperty]) {
this.__lastInvalidValue = propertyValue;
return options.setProperty(element, {}, node);
} else {
var properties = {};
properties[modelProperty] = propertyValue;
return options.setProperty(element, properties, node);
}
};
var validate = defaultParameters.validate = function(element, values, node) {
var value = values[modelProperty] || this.__lastInvalidValue;
var property = {};
property[modelProperty] = value;
return options.validate(element, property, node);
};
return textField(options, defaultParameters);
};
module.exports = validationAwareTextField;
},{"./TextInputEntryFactory":21}],23:[function(require,module,exports){
'use strict';
var CmdHelper = {};
module.exports = CmdHelper;
CmdHelper.updateProperties = function(element, properties) {
return {
cmd: 'element.updateProperties',
context: { element: element, properties: properties }
};
};
CmdHelper.updateBusinessObject = function(element, businessObject, newProperties) {
return {
cmd: 'properties-panel.update-businessobject',
context: {
element: element,
businessObject: businessObject,
properties: newProperties
}
};
};
CmdHelper.addElementsTolist = function(element, businessObject, listPropertyName, objectsToAdd) {
return {
cmd: 'properties-panel.update-businessobject-list',
context: {
element: element,
currentObject: businessObject,
propertyName: listPropertyName,
objectsToAdd: objectsToAdd
}
};
};
CmdHelper.removeElementsFromList = function
(element, businessObject, listPropertyName, referencePropertyName, objectsToRemove) {
return {
cmd: 'properties-panel.update-businessobject-list',
context: {
element: element,
currentObject: businessObject,
propertyName: listPropertyName,
referencePropertyName: referencePropertyName,
objectsToRemove: objectsToRemove
}
};
};
CmdHelper.addAndRemoveElementsFromList = function
(element, businessObject, listPropertyName, referencePropertyName, objectsToAdd, objectsToRemove) {
return {
cmd: 'properties-panel.update-businessobject-list',
context: {
element: element,
currentObject: businessObject,
propertyName: listPropertyName,
referencePropertyName: referencePropertyName,
objectsToAdd: objectsToAdd,
objectsToRemove: objectsToRemove
}
};
};
CmdHelper.setList = function(element, businessObject, listPropertyName, updatedObjectList) {
return {
cmd: 'properties-panel.update-businessobject-list',
context: {
element: element,
currentObject: businessObject,
propertyName: listPropertyName,
updatedObjectList: updatedObjectList
}
};
};
},{}],24:[function(require,module,exports){
'use strict';
var ElementHelper = {};
module.exports = ElementHelper;
/**
* Creates a new element and set the parent to it
*
* @method ElementHelper#createElement
*
* @param {String} elementType of the new element
* @param {Object} properties of the new element in key-value pairs
* @param {moddle.object} parent of the new element
* @param {BpmnFactory} factory which creates the new element
*
* @returns {djs.model.Base} element which is created
*/
ElementHelper.createElement = function(elementType, properties, parent, factory) {
var element = factory.create(elementType, properties);
element.$parent = parent;
return element;
};
},{}],25:[function(require,module,exports){
'use strict';
var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
is = require('bpmn-js/lib/util/ModelUtil').is,
forEach = require('lodash/collection/forEach');
var EventDefinitionHelper = {};
module.exports = EventDefinitionHelper;
EventDefinitionHelper.getEventDefinition = function(element, eventType) {
var bo = getBusinessObject(element),
eventDefinition = null;
if(bo.eventDefinitions) {
forEach(bo.eventDefinitions, function(event) {
if(is(event, eventType)) {
eventDefinition = event;
}
});
}
return eventDefinition;
};
EventDefinitionHelper.getTimerEventDefinition = function(element) {
return this.getEventDefinition(element, 'bpmn:TimerEventDefinition');
};
EventDefinitionHelper.getMessageEventDefinition = function(element) {
return this.getEventDefinition(element, 'bpmn:MessageEventDefinition');
};
EventDefinitionHelper.getSignalEventDefinition = function(element) {
return this.getEventDefinition(element, 'bpmn:SignalEventDefinition');
};
EventDefinitionHelper.getErrorEventDefinition = function(element) {
return this.getEventDefinition(element, 'bpmn:ErrorEventDefinition');
};
EventDefinitionHelper.getEscalationEventDefinition = function(element) {
return this.getEventDefinition(element, 'bpmn:EscalationEventDefinition');
};
EventDefinitionHelper.getCompensateEventDefinition = function(element) {
return this.getEventDefinition(element, 'bpmn:CompensateEventDefinition');
};
},{"bpmn-js/lib/util/ModelUtil":57,"lodash/collection/forEach":132}],26:[function(require,module,exports){
'use strict';
var is = require('bpmn-js/lib/util/ModelUtil').is,
getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
cmdHelper = require('./CmdHelper');
var ParticipantHelper = {};
module.exports = ParticipantHelper;
ParticipantHelper.modifyProcessBusinessObject = function(element, property, values) {
if( !is(element, 'bpmn:Participant') ) {
return {};
}
var bo = getBusinessObject(element).get('processRef'),
properties = {};
properties[property] = values[property];
return cmdHelper.updateBusinessObject(element, bo, properties);
};
ParticipantHelper.getProcessBusinessObject = function(element, propertyName) {
if( !is(element, 'bpmn:Participant') ) {
return {};
}
var bo = getBusinessObject(element).get('processRef'),
properties = {};
properties[propertyName] = bo.get(propertyName);
return properties;
};
},{"./CmdHelper":23,"bpmn-js/lib/util/ModelUtil":57}],27:[function(require,module,exports){
module.exports = {
__depends__: [
require('./cmd')
],
__init__: [ 'propertiesPanel' ],
propertiesPanel: [ 'type', require('./PropertiesPanel') ]
};
},{"./PropertiesPanel":5,"./cmd":12}],28:[function(require,module,exports){
'use strict';
var inherits = require('inherits');
var PropertiesActivator = require('../../PropertiesActivator');
var processProps = require('./parts/ProcessProps'),
eventProps = require('./parts/EventProps'),
linkProps = require('./parts/LinkProps'),
documentationProps = require('./parts/DocumentationProps'),
idProps = require('./parts/IdProps'),
nameProps = require('./parts/NameProps');
function createGeneralTabGroups(element, bpmnFactory, elementRegistry) {
var generalGroup = {
id: 'general',
label: 'General',
entries: []
};
idProps(generalGroup, element, elementRegistry);
nameProps(generalGroup, element);
processProps(generalGroup, element);
var detailsGroup = {
id: 'details',
label: 'Details',
entries: []
};
linkProps(detailsGroup, element);
eventProps(detailsGroup, element, bpmnFactory, elementRegistry);
var documentationGroup = {
id: 'documentation',
label: 'Documentation',
entries: []
};
documentationProps(documentationGroup, element, bpmnFactory);
return[
generalGroup,
detailsGroup,
documentationGroup
];
}
function BpmnPropertiesProvider(eventBus, bpmnFactory, elementRegistry) {
PropertiesActivator.call(this, eventBus);
this.getTabs = function(element) {
var generalTab = {
id: 'general',
label: 'General',
groups: createGeneralTabGroups(element, bpmnFactory, elementRegistry)
};
return [
generalTab
];
};
}
BpmnPropertiesProvider.$inject = [ 'eventBus', 'bpmnFactory', 'elementRegistry' ];
inherits(BpmnPropertiesProvider, PropertiesActivator);
module.exports = BpmnPropertiesProvider;
},{"../../PropertiesActivator":4,"./parts/DocumentationProps":30,"./parts/EventProps":31,"./parts/IdProps":32,"./parts/LinkProps":33,"./parts/NameProps":34,"./parts/ProcessProps":35,"inherits":122}],29:[function(require,module,exports){
module.exports = {
__init__: [ 'propertiesProvider' ],
propertiesProvider: [ 'type', require('./BpmnPropertiesProvider') ]
};
},{"./BpmnPropertiesProvider":28}],30:[function(require,module,exports){
'use strict';
var entryFactory = require('../../../factory/EntryFactory'),
getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
cmdHelper = require('../../../helper/CmdHelper');
module.exports = function(group, element, bpmnFactory) {
// Documentation
var entry = entryFactory.textArea({
id: 'documentation',
description: '',
label: 'Documentation',
modelProperty: 'documentation'
});
entry.set = function(element, values) {
var businessObject = getBusinessObject(element),
newObjectList = [];
if (typeof values.documentation !== 'undefined' && values.documentation !== '') {
newObjectList.push(bpmnFactory.create('bpmn:Documentation', {
text: values.documentation
}));
}
return cmdHelper.setList(element, businessObject, 'documentation', newObjectList);
};
entry.get = function(element) {
var businessObject = getBusinessObject(element),
documentations = businessObject.get('documentation'),
text = (documentations.length > 0) ? documentations[0].text : '';
return { documentation: text };
};
group.entries.push(entry);
};
},{"../../../factory/EntryFactory":15,"../../../helper/CmdHelper":23,"bpmn-js/lib/util/ModelUtil":57}],31:[function(require,module,exports){
'use strict';
var is = require('bpmn-js/lib/util/ModelUtil').is,
getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
eventDefinitionHelper = require('../../../helper/EventDefinitionHelper');
var forEach = require('lodash/collection/forEach');
var message = require('./implementation/MessageEventDefinition'),
signal = require('./implementation/SignalEventDefinition'),
error = require('./implementation/ErrorEventDefinition'),
escalation = require('./implementation/EscalationEventDefinition'),
timer = require('./implementation/TimerEventDefinition'),
compensation = require('./implementation/CompensateEventDefinition');
module.exports = function(group, element, bpmnFactory, elementRegistry) {
var events = [
'bpmn:StartEvent',
'bpmn:EndEvent',
'bpmn:IntermediateThrowEvent',
'bpmn:BoundaryEvent',
'bpmn:IntermediateCatchEvent'
];
// Message and Signal Event Definition
forEach(events, function(event) {
if(is(element, event)) {
var messageEventDefinition = eventDefinitionHelper.getMessageEventDefinition(element),
signalEventDefinition = eventDefinitionHelper.getSignalEventDefinition(element);
if(messageEventDefinition) {
message(group, element, bpmnFactory, messageEventDefinition);
}
if(signalEventDefinition) {
signal(group, element, bpmnFactory, signalEventDefinition);
}
}
});
// Special Case: Receive Task
if(is(element, 'bpmn:ReceiveTask')) {
message(group, element, bpmnFactory, getBusinessObject(element));
}
// Error Event Definition
var errorEvents = [
'bpmn:StartEvent',
'bpmn:BoundaryEvent',
'bpmn:EndEvent'
];
forEach(errorEvents, function(event) {
if(is(element, event)) {
var showErrorCodeVariable = is(element, 'bpmn:StartEvent') || is (element, 'bpmn:BoundaryEvent');
var errorEventDefinition = eventDefinitionHelper.getErrorEventDefinition(element);
if(errorEventDefinition) {
error(group, element, bpmnFactory, errorEventDefinition, showErrorCodeVariable);
}
}
});
// Escalation Event Definition
var escalationEvents = [
'bpmn:StartEvent',
'bpmn:BoundaryEvent',
'bpmn:IntermediateThrowEvent',
'bpmn:EndEvent'
];
forEach(escalationEvents, function(event) {
if(is(element, event)) {
var showEscalationCodeVariable = is(element, 'bpmn:StartEvent') || is(element, 'bpmn:BoundaryEvent');
// get business object
var escalationEventDefinition = eventDefinitionHelper.getEscalationEventDefinition(element);
if(escalationEventDefinition) {
escalation(group, element, bpmnFactory, escalationEventDefinition, showEscalationCodeVariable);
}
}
});
// Timer Event Definition
var timerEvents = [
'bpmn:StartEvent',
'bpmn:BoundaryEvent',
'bpmn:IntermediateCatchEvent'
];
forEach(timerEvents, function(event) {
if(is(element, event)) {
// get business object
var timerEventDefinition = eventDefinitionHelper.getTimerEventDefinition(element);
if(timerEventDefinition) {
timer(group, element, bpmnFactory, timerEventDefinition);
}
}
});
// Compensate Event Definition
var compensationEvents = [
'bpmn:EndEvent',
'bpmn:IntermediateThrowEvent'
];
forEach(compensationEvents, function(event) {
if(is(element, event)) {
// get business object
var compensateEventDefinition = eventDefinitionHelper.getCompensateEventDefinition(element);
if(compensateEventDefinition) {
compensation(group, element, bpmnFactory, compensateEventDefinition, elementRegistry);
}
}
});
};
},{"../../../helper/EventDefinitionHelper":25,"./implementation/CompensateEventDefinition":36,"./implementation/ErrorEventDefinition":38,"./implementation/EscalationEventDefinition":39,"./implementation/MessageEventDefinition":41,"./implementation/SignalEventDefinition":43,"./implementation/TimerEventDefinition":44,"bpmn-js/lib/util/ModelUtil":57,"lodash/collection/forEach":132}],32:[function(require,module,exports){
'use strict';
var entryFactory = require('../../../factory/EntryFactory'),
getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
utils = require('../../../Utils'),
cmdHelper = require('../../../helper/CmdHelper');
module.exports = function(group, element) {
// Id
group.entries.push(entryFactory.validationAwareTextField({
id: 'id',
description: '',
label: 'Id',
modelProperty: 'id',
getProperty: function(element) {
return element.id;
},
setProperty: function(element, properties) {
return cmdHelper.updateProperties(element, properties);
},
validate: function(element, values) {
var idValue = values.id;
var bo = getBusinessObject(element);
var idError = utils.isIdValid(bo, idValue);
return idError ? { id: idError } : {};
}
}));
};
},{"../../../Utils":6,"../../../factory/EntryFactory":15,"../../../helper/CmdHelper":23,"bpmn-js/lib/util/ModelUtil":57}],33:[function(require,module,exports){
'use strict';
var is = require('bpmn-js/lib/util/ModelUtil').is,
getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
entryFactory = require('../../../factory/EntryFactory'),
cmdHelper = require('../../../helper/CmdHelper');
var forEach = require('lodash/collection/forEach');
function getLinkEventDefinition(element) {
var bo = getBusinessObject(element);
var linkEventDefinition = null;
if(bo.eventDefinitions) {
forEach(bo.eventDefinitions, function(eventDefinition) {
if(is(eventDefinition, 'bpmn:LinkEventDefinition')) {
linkEventDefinition = eventDefinition;
}
});
}
return linkEventDefinition;
}
module.exports = function(group, element) {
var linkEvents = [ 'bpmn:IntermediateThrowEvent', 'bpmn:IntermediateCatchEvent' ];
forEach(linkEvents, function(event) {
if(is(element, event)) {
var linkEventDefinition = getLinkEventDefinition(element);
if(linkEventDefinition) {
var entry = entryFactory.textField({
id: 'link-event',
description: '',
label: 'Link Name',
modelProperty: 'link-name'
});
entry.get = function () {
return { 'link-name': linkEventDefinition.get('name')};
};
entry.set = function (element, values) {
var newProperties = {
name: values['link-name']
};
return cmdHelper.updateBusinessObject(element, linkEventDefinition, newProperties);
};
group.entries.push(entry);
}
}
});
};
},{"../../../factory/EntryFactory":15,"../../../helper/CmdHelper":23,"bpmn-js/lib/util/ModelUtil":57,"lodash/collection/forEach":132}],34:[function(require,module,exports){
'use strict';
var nameEntryFactory = require('./implementation/Name'),
is = require('bpmn-js/lib/util/ModelUtil').is;
module.exports = function(group, element) {
if (!is(element, 'bpmn:Collaboration')) {
// name
group.entries = group.entries.concat(nameEntryFactory(element));
}
};
},{"./implementation/Name":42,"bpmn-js/lib/util/ModelUtil":57}],35:[function(require,module,exports){
'use strict';
var is = require('bpmn-js/lib/util/ModelUtil').is,
entryFactory = require('../../../factory/EntryFactory'),
participantHelper = require('../../../helper/ParticipantHelper'),
getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
nameEntryFactory = require('./implementation/Name');
module.exports = function(group, element) {
var businessObject = getBusinessObject(element);
if (is(element, 'bpmn:Process') || (is(element, 'bpmn:Participant') && businessObject.get('processRef'))) {
/**
* processId
*/
if(is(element, 'bpmn:Participant')) {
var idEntry = entryFactory.textField({
id: 'process-id',
description: '',
label: 'Process Id',
modelProperty: 'processId'
});
// in participants we have to change the default behavior of set and get
idEntry.get = function (element) {
var properties = participantHelper.getProcessBusinessObject(element, 'id');
return { processId: properties.id };
};
idEntry.set = function (element, values) {
return participantHelper.modifyProcessBusinessObject(element, 'id', { id: values.processId });
};
group.entries.push(idEntry);
/**
* process name
*/
var processNameEntry = nameEntryFactory(element, {
id: 'process-name',
label: 'Process Name'
})[0];
// in participants we have to change the default behavior of set and get
processNameEntry.get = function (element) {
return participantHelper.getProcessBusinessObject(element, 'name');
};
processNameEntry.set = function (element, values) {
return participantHelper.modifyProcessBusinessObject(element, 'name', values);
};
group.entries.push(processNameEntry);
}
/**
* isExecutable
*/
var executableEntry = entryFactory.checkbox({
id: 'process-is-executable',
description: 'Defines if a process is executable by a process engine',
label: 'Executable',
modelProperty: 'isExecutable'
});
// in participants we have to change the default behavior of set and get
if(is(element, 'bpmn:Participant')) {
executableEntry.get = function (element) {
return participantHelper.getProcessBusinessObject(element, 'isExecutable');
};
executableEntry.set = function (element, values) {
return participantHelper.modifyProcessBusinessObject(element, 'isExecutable', values);
};
}
group.entries.push(executableEntry);
}
};
},{"../../../factory/EntryFactory":15,"../../../helper/ParticipantHelper":26,"./implementation/Name":42,"bpmn-js/lib/util/ModelUtil":57}],36:[function(require,module,exports){
'use strict';
var entryFactory = require('../../../../factory/EntryFactory');
var cmdHelper = require('../../../../helper/CmdHelper'),
eventDefinitionHelper = require('../../../../helper/EventDefinitionHelper'),
utils = require('../../../../Utils');
var getBusinessObject = require('bpmn-js/lib/util/ModelUtil').getBusinessObject,
is = require('bpmn-js/lib/util/ModelUtil').is;
var forEach = require('lodash/collection/forEach'),
find = require('lodash/collection/find'),
filter = require('lodash/collection/filter');
function getContainedActivities(element) {
return getFlowElements(element, 'bpmn:Activity');
}
function getContainedBoundaryEvents(element) {
return getFlowElements(element, 'bpmn:BoundaryEvent');
}
function getFlowElements(element, type) {
return utils.filterElementsByType(element.flowElements, type);
}
function isCompensationEventAttachedToActivity(activity, boundaryEvents) {
var activityId = activity.id;
var boundaryEvent = find(boundaryEvents, function(boundaryEvent) {
var compensateEventDefinition = eventDefinitionHelper.getCompensateEventDefinition(boundaryEvent);
var attachedToRef = boundaryEvent.attachedToRef;
return compensateEventDefinition && attachedToRef && attachedToRef.id === activityId;
});
return !!boundaryEvent;
}
// subprocess: only when it is not triggeredByEvent
// activity: only when it attach a compensation boundary event
// callActivity: no limitation
function canActivityBeCompensated(activity, boundaryEvents) {
return (is(activity, 'bpmn:SubProcess') && !activity.triggeredByEvent) ||
is(activity, 'bpmn:CallActivity') ||
isCompensationEventAttachedToActivity(activity, boundaryEvents);
}
function getActivitiesForCompensation(element) {
var boundaryEvents = getContainedBoundaryEvents(element);
return filter(getContainedActivities(element), function(activity) {
return canActivityBeCompensated(activity, boundaryEvents);
});
}
function getActivitiesForActivityRef(element) {
var bo = getBusinessObject(element);
var parent = bo.$parent;
var activitiesForActivityRef = getActivitiesForCompensation(parent);
// if throwing compensation event is in an event sub process:
// get also all activities outside of the event sub process
if (is(parent, 'bpmn:SubProcess') && parent.triggeredByEvent) {
parent = parent.$parent;
if (parent) {
activitiesForActivityRef = activitiesForActivityRef.concat(getActivitiesForCompensation(parent));
}
}
return activitiesForActivityRef;
}
function createActivityRefOptions(element) {
var options = [ { value: '' } ];
var activities = getActivitiesForActivityRef(element);
forEach(activities, function(activity) {
var activityId = activity.id;
var name = (activity.name ? (activity.name + ' ') : '') + '(id=' + activityId + ')';
options.push({ value: activityId, name: name });
});
return options;
}
module.exports = function(group, element, bpmnFactory, compensateEventDefinition, elementRegistry) {
group.entries.push(entryFactory.checkbox({
id: 'wait-for-completion',
description: 'Configure compensation event definition',
label: 'Wait for Completion',
modelProperty: 'waitForCompletion',
get: function(element, node) {
return {
waitForCompletion: compensateEventDefinition.waitForCompletion
};
},
set: function(element, values) {
values.waitForCompletion = values.waitForCompletion || undefined;
return cmdHelper.updateBusinessObject(element, compensateEventDefinition, values);
}
}));
group.entries.push(entryFactory.selectBox({
id: 'activity-ref',
label: 'Activity Ref',
selectOptions: createActivityRefOptions(element),
modelProperty: 'activityRef',
get: function(element, node) {
var activityRef = compensateEventDefinition.activityRef;
activityRef = activityRef && activityRef.id;
return {
activityRef: activityRef || ''
};
},
set: function(element, values) {
var activityRef = values.activityRef || undefined;
activityRef = activityRef && getBusinessObject(elementRegistry.get(activityRef));
return cmdHelper.updateBusinessObject(element, compensateEventDefinition, {
activityRef: activityRef
});
}
}));
};
},{"../../../../Utils":6,"../../../../factory/EntryFactory":15,"../../../../helper/CmdHelper":23,"../../../../helper/EventDefinitionHelper":25,"bpmn-js/lib/util/ModelUtil":57,"lodash/collection/filter":130,"lodash/collection/find":131,"lodash/collection/forEach":132}],37:[function(require,module,exports){
'use strict';
var entryFactory = require('../../../../factory/EntryFactory');
var cmdHelper = require('../../../../helper/CmdHelper');
/**
* Create an entry to modify a property of an element which
* is referenced by a event definition.
*
* @param {djs.model.Base} element
* @param {ModdleElement} definition
* @param {BpmnFactory} bpmnFactory
* @param {Object} options
* @param {string} options.id the id of the entry
* @param {string} options.label the label of the entry
* @param {string} options.referenceProperty the name of referencing property
* @param {string} options.modelProperty the name of property to modify
* @param {string} options.shouldValidate a flag indicate whether to validate or not
*
* @return {Array} return an array containing the entries
*/
module.exports = function(element, definition, bpmnFactory, options) {
var id = options.id || 'element-property';
var label = options.label;
var referenceProperty = options.referenceProperty;
var modelProperty = options.modelProperty || 'name';
var shouldValidate = options.shouldValidate || false;
var entry = entryFactory.textField({
id: id,
label: label,
modelProperty: modelProperty,
get: function(element, node) {
var reference = definition.get(referenceProperty);
var props = {};
props[modelProperty] = reference && reference.get(modelProperty);
return props;
},
set: function(element, values, node) {
var reference = definition.get(referenceProperty);
var props = {};
props[modelProperty] = values[modelProperty] || undefined;
return cmdHelper.updateBusinessObject(element, reference, props);
},
disabled: function(element, node) {
return !definition.get(referenceProperty);
}
});
if (shouldValidate) {
entry.validate = function(element, values, node) {
var reference = definition.get(referenceProperty);
if (reference && !values[modelProperty]) {
var validationErrors = {};
validationErrors[modelProperty] = 'Must provide a value';
return validationErrors;
}
};
}
return [ entry ];
};
},{"../../../../factory/EntryFactory":15,"../../../../helper/CmdHelper":23}],38:[function(require,module,exports){
'use strict';
var entryFactory = require('../../../../factory/EntryFactory'),
cmdHelper = require('../../../../helper/CmdHelper');
var eventDefinitionReference = require('./EventDefinitionReference'),
elementReferenceProperty = require('./ElementReferenceProperty');
module.exports = function(group, element, bpmnFactory, errorEventDefinition, showErrorCodeVariable) {
group.entries = group.entries.concat(eventDefinitionReference(element, errorEventDefinition, bpmnFactory, {
label: 'Error',
description: 'Configure the error element',
elementName: 'error',
elementType: 'bpmn:Error',
referenceProperty: 'errorRef',
newElementIdPrefix: 'Error_'
}));
group.entries = group.entries.concat(elementReferenceProperty(element, errorEventDefinition, bpmnFactory, {
id: 'error-element-name',
label: 'Error Name',
referenceProperty: 'errorRef',
modelProperty: 'name',
shouldValidate: true
}));
group.entries = group.entries.concat(elementReferenceProperty(element, errorEventDefinition, bpmnFactory, {
id: 'error-element-code',
label: 'Error Code',
referenceProperty: 'errorRef',
modelProperty: 'errorCode'
}));
if (showErrorCodeVariable) {
group.entries.push(entryFactory.textField({
id : 'errorCodeVariable',
label : 'Error Code Variable',
modelProperty : 'errorCodeVariable',
get: function(element) {
var codeVariable = errorEventDefinition.get('camunda:errorCodeVariable');
return {
errorCodeVariable: codeVariable
};
},
set: function(element, values) {
return cmdHelper.updateBusinessObject(element, errorEventDefinition, {
'camunda:errorCodeVariable': values.errorCodeVariable || undefined
});
}
}));
}
};
},{"../../../../factory/EntryFactory":15,"../../../../helper/CmdHelper":23,"./ElementReferenceProperty":37,"./EventDefinitionReference":40}],39:[function(require,module,exports){
'use strict';
var entryFactory = require('../../../../factory/EntryFactory'),
cmdHelper = require('../../../../helper/CmdHelper');
var eventDefinitionReference = require('./EventDefinitionReference'),
elementReferenceProperty = require('./ElementReferenceProperty');
module.exports = function(group, element, bpmnFactory, escalationEventDefinition, showEscalationCodeVariable) {
group.entries = group.entries.concat(eventDefinitionReference(element, escalationEventDefinition, bpmnFactory, {
label: 'Escalation',
description: 'Configure the escalation element',
elementName: 'escalation',
elementType: 'bpmn:Escalation',
referenceProperty: 'escalationRef',
newElementIdPrefix: 'Escalation_'
}));
group.entries = group.entries.concat(elementReferenceProperty(element, escalationEventDefinition, bpmnFactory, {
id: 'escalation-element-name',
label: 'Escalation Name',
referenceProperty: 'escalationRef',
modelProperty: 'name',
shouldValidate: true
}));
group.entries = group.entries.concat(elementReferenceProperty(element, escalationEventDefinition, bpmnFactory, {
id: 'escalation-element-code',
label: 'Escalation Code',
referenceProperty: 'escalationRef',
modelProperty: 'escalationCode'
}));
if (showEscalationCodeVariable) {
group.entries.push(entryFactory.textField({
id : 'escalationCodeVariable',
label : 'Escalation Code Variable',
modelProperty : 'escalationCodeVariable',
get: function(element) {
var codeVariable = escalationEventDefinition.get('camunda:escalationCodeVariable');
return {
escalationCodeVariable: codeVariable
};
},
set: function(element, values) {
return cmdHelper.updateBusinessObject(element, escalationEventDefinition, {
'camunda:escalationCodeVariable': values.escalationCodeVariable || undefined
});
}
}));
}
};
},{"../../../../factory/EntryFactory":15,"../../../../helper/CmdHelper":23,"./ElementReferenceProperty":37,"./EventDefinitionReference":40}],40:[function(require,module,exports){
'use strict';
var cmdHelper = require('../../../../helper/CmdHelper');
var domQuery = require('min-dom/lib/query'),
domify = require('min-dom/lib/domify'),
domAttr = require('min-dom/lib/attr');
var forEach = require('lodash/collection/forEach'),
find = require('lodash/collection/find');
var elementHelper = require('../../../../helper/ElementHelper');
var utils = require('../../../../Utils');
var selector = 'select[name=selectedElement]';
/**
* Get select box containing all elements.
*
* @param {DOMElement} node
*
* @return {DOMElement} the select box
*/
function getSelectBox(node) {
return domQuery(selector, node.parentElement);
}
/**
* Find element by given id.
*
* @param {ModdleElement} eventDefinition
*
* @return {ModdleElement} an element
*/
function findElementById(eventDefinition, type, id) {
var elements = utils.findRootElementsByType(eventDefinition, type);
return find(elements, function(element) {
return element.id === id;
});
}
/**
* Create an entry to modify the reference to an element from an
* event definition.
*
* @param {djs.model.Base} element
* @param {ModdleElement} definition
* @param {BpmnFactory} bpmnFactory
* @param {Object} options
* @param {string} options.label the label of the entry
* @param {string} options.description the description of the entry
* @param {string} options.elementName the name of the element
* @param {string} options.elementType the type of the element
* @param {string} options.referenceProperty the name of referencing property
* @param {string} options.newElementIdPrefix the prefix of a new created element
*
* @return {Array} return an array containing the entries
*/
module.exports = function(element, definition, bpmnFactory, options) {
var elementName = options.elementName || '',
elementType = options.elementType,
referenceProperty = options.referenceProperty;
var newElementIdPrefix = options.newElementIdPrefix || 'elem_';
var label = options.label || '',
description = options.description || '';
var entries = [];
entries.push({
id: 'event-definitions-' + elementName,
description: description,
html: '' +
'
' + label + ' ' +
'
' +
'' +
' ' +
'+ ' +
'
' +
'
',
get: function(element, entryNode) {
utils.updateOptionsDropDown(selector, definition, elementType, entryNode);
var reference = definition.get(referenceProperty);
return {
selectedElement: (reference && reference.id) || ''
};
},
set: function(element, values) {
var selection = values.selectedElement;
var props = {};
if (!selection || typeof selection === 'undefined') {
// remove reference to element
props[referenceProperty] = undefined;
return cmdHelper.updateBusinessObject(element, definition, props);
}
var commands = [];
var selectedElement = findElementById(definition, elementType, selection);
if (!selectedElement) {
var root = utils.getRoot(definition);
// create a new element
selectedElement = elementHelper.createElement(elementType, { name: selection }, root, bpmnFactory);
commands.push(cmdHelper.addAndRemoveElementsFromList(element, root, 'rootElements', null, [ selectedElement ]));
}
// update reference to element
props[referenceProperty] = selectedElement;
commands.push(cmdHelper.updateBusinessObject(element, definition, props));
return commands;
},
addElement: function(element, inputNode) {
// note: this generated id will be used as name
// of the element and not as id
var id = utils.nextId(newElementIdPrefix);
var optionTemplate = domify(' (id='+id+')' + ' ');
// add new option
var selectBox = getSelectBox(inputNode);
selectBox.insertBefore(optionTemplate, selectBox.firstChild);
// select new element in the select box
forEach(selectBox, function(option) {
if (option.value === id) {
domAttr(option, 'selected', 'selected');
} else {
domAttr(option, 'selected', null);
}
});
return true;
}
});
return entries;
};
},{"../../../../Utils":6,"../../../../helper/CmdHelper":23,"../../../../helper/ElementHelper":24,"lodash/collection/find":131,"lodash/collection/forEach":132,"min-dom/lib/attr":262,"min-dom/lib/domify":267,"min-dom/lib/query":270}],41:[function(require,module,exports){
'use strict';
var eventDefinitionReference = require('./EventDefinitionReference'),
elementReferenceProperty = require('./ElementReferenceProperty');
module.exports = function(group, element, bpmnFactory, messageEventDefinition) {
group.entries = group.entries.concat(eventDefinitionReference(element, messageEventDefinition, bpmnFactory, {
label: 'Message',
description: 'Configure the message element',
elementName: 'message',
elementType: 'bpmn:Message',
referenceProperty: 'messageRef',
newElementIdPrefix: 'Message_'
}));
group.entries = group.entries.concat(elementReferenceProperty(element, messageEventDefinition, bpmnFactory, {
id: 'message-element-name',
label: 'Message Name',
referenceProperty: 'messageRef',
modelProperty: 'name',
shouldValidate: true
}));
};
},{"./ElementReferenceProperty":37,"./EventDefinitionReference":40}],42:[function(require,module,exports){
'use strict';
var entryFactory = require('../../../../factory/EntryFactory');
/**
* Create an entry to modify the name of an an element.
*
* @param {djs.model.Base} element
* @param {Object} options
* @param {string} options.id the id of the entry
* @param {string} options.label the label of the entry
*
* @return {Array} return an array containing
* the entry to modify the name
*/
module.exports = function(element, options) {
options = options || {};
var id = options.id || 'name',
label = options.label || 'Name';
var nameEntry = entryFactory.textArea({
id: id,
label: label,
modelProperty: 'name',
expandable: true,
minRows: 1,
maxRows: 3
});
return [ nameEntry ];
};
},{"../../../../factory/EntryFactory":15}],43:[function(require,module,exports){
'use strict';
var eventDefinitionReference = require('./EventDefinitionReference'),
elementReferenceProperty = require('./ElementReferenceProperty');
module.exports = function(group, element, bpmnFactory, signalEventDefinition) {
group.entries = group.entries.concat(eventDefinitionReference(element, signalEventDefinition, bpmnFactory, {
label: 'Signal',
description: 'Configure the signal element',
elementName: 'signal',
elementType: 'bpmn:Signal',
referenceProperty: 'signalRef',
newElementIdPrefix: 'Signal_'
}));
group.entries = group.entries.concat(elementReferenceProperty(element, signalEventDefinition, bpmnFactory, {
id: 'signal-element-name',
label: 'Signal Name',
referenceProperty: 'signalRef',
modelProperty: 'name',
shouldValidate: true
}));
};
},{"./ElementReferenceProperty":37,"./EventDefinitionReference":40}],44:[function(require,module,exports){
'use strict';
var elementHelper = require('../../../../helper/ElementHelper'),
cmdHelper = require('../../../../helper/CmdHelper');
var entryFactory = require('../../../../factory/EntryFactory');
/**
* Get the timer definition type for a given timer event definition.
*
* @param {ModdleElement} timer
*
* @return {string|undefined} the timer definition type
*/
function getTimerDefinitionType(timer) {
var timeDate = timer.get('timeDate');
if (typeof timeDate !== 'undefined') {
return 'timeDate';
}
var timeCycle = timer.get('timeCycle');
if (typeof timeCycle !== 'undefined') {
return 'timeCycle';
}
var timeDuration = timer.get('timeDuration');
if (typeof timeDuration !== 'undefined') {
return 'timeDuration';
}
}
/**
* Creates 'bpmn:FormalExpression' element.
*
* @param {ModdleElement} parent
* @param {string} body
* @param {BpmnFactory} bpmnFactory
*
* @return {ModdleElement} a formal expression
*/
function createFormalExpression(parent, body, bpmnFactory) {
body = body || undefined;
return elementHelper.createElement('bpmn:FormalExpression', { body: body }, parent, bpmnFactory);
}
function TimerEventDefinition(group, element, bpmnFactory, timerEventDefinition) {
var selectOptions = [
{ value: 'timeDate', name: 'Date' },
{ value: 'timeDuration', name: 'Duration' },
{ value: 'timeCycle', name: 'Cycle' }
];
group.entries.push(entryFactory.selectBox({
id: 'timer-event-definition-type',
label: 'Timer Definition Type',
selectOptions: selectOptions,
emptyParameter: true,
modelProperty: 'timerDefinitionType',
get: function(element, node) {
return {
timerDefinitionType: getTimerDefinitionType(timerEventDefinition) || ''
};
},
set: function(element, values) {
var props = {
timeDuration: undefined,
timeDate: undefined,
timeCycle: undefined
};
var newType = values.timerDefinitionType;
if (values.timerDefinitionType) {
var oldType = getTimerDefinitionType(timerEventDefinition);
var value;
if (oldType) {
var definition = timerEventDefinition.get(oldType);
value = definition.get('body');
}
props[newType] = createFormalExpression(timerEventDefinition, value, bpmnFactory);
}
return cmdHelper.updateBusinessObject(element, timerEventDefinition, props);
}
}));
group.entries.push(entryFactory.textField({
id: 'timer-event-definition',
label: 'Timer Definition',
modelProperty: 'timerDefinition',
get: function(element, node) {
var type = getTimerDefinitionType(timerEventDefinition);
var definition = type && timerEventDefinition.get(type);
var value = definition && definition.get('body');
return {
timerDefinition: value
};
},
set: function(element, values) {
var type = getTimerDefinitionType(timerEventDefinition);
var definition = type && timerEventDefinition.get(type);
if (definition) {
return cmdHelper.updateBusinessObject(element, definition, {
body: values.timerDefinition || undefined
});
}
},
validate: function(element) {
var type = getTimerDefinitionType(timerEventDefinition);
var definition = type && timerEventDefinition.get(type);
if (definition) {
var value = definition.get('body');
if (!value) {
return {
timerDefinition: 'Must provide a value'
};
}
}
},
disabled: function(element) {
return !getTimerDefinitionType(timerEventDefinition);
}
}));
}
module.exports = TimerEventDefinition;
},{"../../../../factory/EntryFactory":15,"../../../../helper/CmdHelper":23,"../../../../helper/ElementHelper":24}],45:[function(require,module,exports){
/**
* The code in the area
* must not be changed.
*
* @see http://bpmn.io/license for more information.
*/
'use strict';
var assign = require('lodash/object/assign'),
omit = require('lodash/object/omit'),
isString = require('lodash/lang/isString'),
isNumber = require('lodash/lang/isNumber');
var domify = require('min-dom/lib/domify'),
domQuery = require('min-dom/lib/query'),
domRemove = require('min-dom/lib/remove');
var Diagram = require('diagram-js'),
BpmnModdle = require('bpmn-moddle');
var inherits = require('inherits');
var Importer = require('./import/Importer');
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} [options.modules] a list of modules to override the default modules
* @param {Array} [options.additionalModules] a list of modules to use with the default modules
*/
function Viewer(options) {
options = assign({}, DEFAULT_OPTIONS, options);
this.moddle = this._createModdle(options);
this.container = this._createContainer(options);
/* */
addProjectLogo(this.container);
/* */
this._init(this.container, this.moddle, options);
}
inherits(Viewer, Diagram);
module.exports = Viewer;
/**
* Parse and render a BPMN 2.0 diagram.
*
* Once finished the viewer reports back the result to the
* provided callback function with (err, warnings).
*
* ## Life-Cycle Events
*
* During import the viewer will fire life-cycle events:
*
* * import.parse.start (about to read model from xml)
* * import.parse.complete (model read; may have worked or not)
* * import.render.start (graphical import start)
* * import.render.complete (graphical import finished)
* * import.done (everything done)
*
* You can use these events to hook into the life-cycle.
*
* @param {String} xml the BPMN 2.0 xml
* @param {Function} [done] invoked with (err, warnings=[])
*/
Viewer.prototype.importXML = function(xml, done) {
// done is optional
done = done || function() {};
var self = this;
// hook in pre-parse listeners +
// allow xml manipulation
xml = this._emit('import.parse.start', { xml: xml }) || xml;
this.moddle.fromXML(xml, 'bpmn:Definitions', function(err, definitions, context) {
// hook in post parse listeners +
// allow definitions manipulation
definitions = self._emit('import.parse.complete', {
error: err,
definitions: definitions,
context: context
}) || definitions;
if (err) {
err = checkValidationError(err);
self._emit('import.done', { error: err });
return done(err);
}
var parseWarnings = context.warnings;
self.importDefinitions(definitions, function(err, importWarnings) {
var allWarnings = [].concat(parseWarnings, importWarnings || []);
self._emit('import.done', { error: err, warnings: allWarnings });
done(err, allWarnings);
});
});
};
/**
* Export the currently displayed BPMN 2.0 diagram as
* a BPMN 2.0 XML document.
*
* @param {Object} [options] export options
* @param {Boolean} [options.format=false] output formated XML
* @param {Boolean} [options.preamble=true] output preamble
*
* @param {Function} done invoked with (err, xml)
*/
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);
};
/**
* Export the currently displayed BPMN 2.0 diagram as
* an SVG image.
*
* @param {Object} [options]
* @param {Function} done invoked with (err, svgStr)
*/
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 =
'\n' +
'\n' +
'\n' +
'' +
defs + contents +
' ';
done(null, svg);
};
/**
* Get a named diagram service.
*
* @example
*
* var elementRegistry = viewer.get('elementRegistry');
* var startEventShape = elementRegistry.get('StartEvent_1');
*
* @param {String} name
*
* @return {Object} diagram service instance
*
* @method Viewer#get
*/
/**
* Invoke a function in the context of this viewer.
*
* @example
*
* viewer.invoke(function(elementRegistry) {
* var startEventShape = elementRegistry.get('StartEvent_1');
* });
*
* @param {Function} fn to be invoked
*
* @return {Object} the functions return value
*
* @method Viewer#invoke
*/
/**
* Remove all drawn elements from the viewer.
*
* After calling this method the viewer can still
* be reused for opening another diagram.
*
* @method Viewer#clear
*/
Viewer.prototype.importDefinitions = function(definitions, done) {
// use try/catch to not swallow synchronous exceptions
// that may be raised during model parsing
try {
if (this.definitions) {
// clear existing rendered diagram
this.clear();
}
// update definitions
this.definitions = definitions;
// perform graphical import
Importer.importBpmnDiagram(this, definitions, done);
} catch (e) {
// handle synchronous errors
done(e);
}
};
Viewer.prototype.getModules = function() {
return this._modules;
};
/**
* Destroy the viewer instance and remove all its
* remainders from the document tree.
*/
Viewer.prototype.destroy = function() {
// diagram destroy
Diagram.prototype.destroy.call(this);
// dom detach
domRemove(this.container);
};
/**
* Register an event listener
*
* Remove a previously added listener via {@link #off(event, callback)}.
*
* @param {String} event
* @param {Number} [priority]
* @param {Function} callback
* @param {Object} [that]
*/
Viewer.prototype.on = function(event, priority, callback, target) {
return this.get('eventBus').on(event, priority, callback, target);
};
/**
* De-register an event listener
*
* @param {String} event
* @param {Function} callback
*/
Viewer.prototype.off = function(event, callback) {
this.get('eventBus').off(event, callback);
};
Viewer.prototype._init = function(container, moddle, options) {
var baseModules = options.modules || this.getModules(),
additionalModules = options.additionalModules || [],
staticModules = [
{
bpmnjs: [ 'value', this ],
moddle: [ 'value', moddle ]
}
];
var diagramModules = [].concat(staticModules, baseModules, additionalModules);
var diagramOptions = assign(omit(options, 'additionalModules'), {
canvas: assign({}, options.canvas, { container: container }),
modules: diagramModules
});
// invoke diagram constructor
Diagram.call(this, diagramOptions);
};
/**
* Emit an event on the underlying {@link EventBus}
*
* @param {String} type
* @param {Object} event
*
* @return {Object} event processing result (if any)
*/
Viewer.prototype._emit = function(type, event) {
return this.get('eventBus').fire(type, event);
};
Viewer.prototype._createContainer = function(options) {
var parent = options.container,
container;
// support jquery element
// unwrap it if passed
if (parent.get) {
parent = parent.get(0);
}
// support selector
if (isString(parent)) {
parent = domQuery(parent);
}
container = domify('
');
assign(container.style, {
width: ensureUnit(options.width),
height: ensureUnit(options.height),
position: options.position
});
parent.appendChild(container);
return container;
};
Viewer.prototype._createModdle = function(options) {
var moddleOptions = assign({}, this._moddleExtensions, options.moddleExtensions);
return new BpmnModdle(moddleOptions);
};
// modules the viewer is composed of
Viewer.prototype._modules = [
require('./core'),
require('diagram-js/lib/i18n/translate'),
require('diagram-js/lib/features/selection'),
require('diagram-js/lib/features/overlays')
];
// default moddle extensions the viewer is composed of
Viewer.prototype._moddleExtensions = {};
/* */
var PoweredBy = require('./util/PoweredByUtil'),
domEvent = require('min-dom/lib/event');
/**
* Adds the project logo to the diagram container as
* required by the bpmn.io license.
*
* @see http://bpmn.io/license
*
* @param {Element} container
*/
function addProjectLogo(container) {
var logoData = PoweredBy.BPMNIO_LOGO;
var linkMarkup =
'' +
' ' +
' ';
var linkElement = domify(linkMarkup);
container.appendChild(linkElement);
domEvent.bind(linkElement, 'click', function(event) {
PoweredBy.open();
event.preventDefault();
});
}
/* */
},{"./core":46,"./import/Importer":52,"./util/PoweredByUtil":58,"bpmn-moddle":59,"diagram-js":78,"diagram-js/lib/features/overlays":95,"diagram-js/lib/features/selection":99,"diagram-js/lib/i18n/translate":100,"inherits":122,"lodash/lang/isNumber":243,"lodash/lang/isString":246,"lodash/object/assign":249,"lodash/object/omit":254,"min-dom/lib/domify":267,"min-dom/lib/event":268,"min-dom/lib/query":270,"min-dom/lib/remove":271}],46:[function(require,module,exports){
module.exports = {
__depends__: [
require('../draw'),
require('../import')
]
};
},{"../draw":49,"../import":54}],47:[function(require,module,exports){
'use strict';
var inherits = require('inherits'),
isObject = require('lodash/lang/isObject'),
assign = require('lodash/object/assign'),
forEach = require('lodash/collection/forEach'),
every = require('lodash/collection/every'),
includes = require('lodash/collection/includes'),
some = require('lodash/collection/some');
var BaseRenderer = require('diagram-js/lib/draw/BaseRenderer'),
TextUtil = require('diagram-js/lib/util/Text'),
DiUtil = require('../util/DiUtil');
var is = require('../util/ModelUtil').is;
var RenderUtil = require('diagram-js/lib/util/RenderUtil');
var componentsToPath = RenderUtil.componentsToPath,
createLine = RenderUtil.createLine;
var TASK_BORDER_RADIUS = 10;
var INNER_OUTER_DIST = 3;
var LABEL_STYLE = {
fontFamily: 'Arial, sans-serif',
fontSize: '12px'
};
function BpmnRenderer(eventBus, styles, pathMap, priority) {
BaseRenderer.call(this, eventBus, priority);
var textUtil = new TextUtil({
style: LABEL_STYLE,
size: { width: 100 }
});
var markers = {};
var computeStyle = styles.computeStyle;
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('association-start', {
element: svg.path('M 11 5 L 1 10 L 11 15'),
attrs: {
fill: 'none',
stroke: 'black',
strokeWidth: 1.5
},
ref: { x: 1, y: 10 },
scale: 0.5
});
createMarker('association-end', {
element: svg.path('M 1 5 L 11 10 L 1 15'),
attrs: {
fill: 'none',
stroke: 'black',
strokeWidth: 1.5
},
ref: { x: 12, 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 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 drawMarker(type, p, path, attrs) {
return drawPath(p, path, assign({ 'data-marker': type }, 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);
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 = this.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.22,
my: 0.5
}
});
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) {
attrs = assign({ fillOpacity: 0.95 }, attrs);
var rect = renderer('bpmn:Activity')(p, element, attrs);
var expanded = DiUtil.isExpanded(element);
var isEventSubProcess = DiUtil.isEventSubProcess(element);
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:SubProcess')(p, element, {
strokeWidth: 5
});
},
'bpmn:Participant': function(p, element) {
var lane = renderer('bpmn:Lane')(p, element, {
fillOpacity: 0.95,
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:Activity')) {
path.attr({
markerStart: marker('conditional-flow-marker')
});
}
// default marker
if (source.default && (source.$instanceOf('bpmn:Gateway') || source.$instanceOf('bpmn:Activity')) &&
source.default === sequenceFlow) {
path.attr({
markerStart: marker('conditional-default-flow-marker')
});
}
return path;
},
'bpmn:Association': function(p, element, attrs) {
var semantic = getSemantic(element);
attrs = assign({
strokeDasharray: '0.5, 5',
strokeLinecap: 'round',
strokeLinejoin: 'round'
}, attrs || {});
if (semantic.associationDirection === 'One' ||
semantic.associationDirection === 'Both') {
attrs.markerEnd = marker('association-end');
}
if (semantic.associationDirection === 'Both') {
attrs.markerStart = marker('association-start');
}
return drawLine(p, element.waypoints, attrs);
},
'bpmn:DataInputAssociation': function(p, element) {
return renderer('bpmn:Association')(p, element, {
markerEnd: marker('association-end')
});
},
'bpmn:DataOutputAssociation': function(p, element) {
return renderer('bpmn:Association')(p, element, {
markerEnd: marker('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 = {
strokeWidth: 1
};
if (!cancel) {
attrs.strokeDasharray = '6';
attrs.strokeLinecap = 'round';
}
var outer = renderer('bpmn:Event')(p, element, attrs);
/* inner path */ drawCircle(p, element.width, element.height, INNER_OUTER_DIST, assign(attrs, { fill: 'none' }));
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 markerPath = 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
}
});
drawMarker('participant-multiplicity', p, markerPath);
},
'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 markerPath = 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
}
});
drawMarker('sub-process', p, markerPath);
},
'ParallelMarker': function(p, element, position) {
var markerPath = 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
}
});
drawMarker('parallel', p, markerPath);
},
'SequentialMarker': function(p, element, position) {
var markerPath = 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
}
});
drawMarker('sequential', p, markerPath);
},
'CompensationMarker': function(p, element, position) {
var markerMath = 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
}
});
drawMarker('compensation', p, markerMath, { strokeWidth: 1 });
},
'LoopMarker': function(p, element, position) {
var markerPath = 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
}
});
drawMarker('loop', p, markerPath, {
strokeWidth: 1,
fill: 'none',
strokeLinecap: 'round',
strokeMiterlimit: 0.5
});
},
'AdhocMarker': function(p, element, position) {
var markerPath = 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
}
});
drawMarker('adhoc', p, markerPath, {
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.isForCompensation) {
renderer('CompensationMarker')(p, element, position);
}
if (obj.$type === 'bpmn:AdHocSubProcess') {
renderer('AdhocMarker')(p, element, position);
}
var loopCharacteristics = obj.loopCharacteristics,
isSequential = loopCharacteristics && loopCharacteristics.isSequential;
if (loopCharacteristics) {
if (isSequential === undefined) {
renderer('LoopMarker')(p, element, position);
}
if (isSequential === false) {
renderer('ParallelMarker')(p, element, position);
}
if (isSequential === true) {
renderer('SequentialMarker')(p, element, position);
}
}
}
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
});
}
// hook onto canvas init event to initialize
// connection start/end markers on svg
eventBus.on('canvas.init', function(event) {
initMarkers(event.svg);
});
}
inherits(BpmnRenderer, BaseRenderer);
BpmnRenderer.$inject = [ 'eventBus', 'styles', 'pathMap' ];
module.exports = BpmnRenderer;
BpmnRenderer.prototype.canRender = function(element) {
return is(element, 'bpmn:BaseElement');
};
BpmnRenderer.prototype.drawShape = function(visuals, element) {
var type = element.type;
var h = this.handlers[type];
/* jshint -W040 */
return h(visuals, element);
};
BpmnRenderer.prototype.drawConnection = function(visuals, element) {
var type = element.type;
var h = this.handlers[type];
/* jshint -W040 */
return h(visuals, element);
};
BpmnRenderer.prototype.getShapePath = function(element) {
if (is(element, 'bpmn:Event')) {
return getCirclePath(element);
}
if (is(element, 'bpmn:Activity')) {
return getRoundRectPath(element, TASK_BORDER_RADIUS);
}
if (is(element, 'bpmn:Gateway')) {
return getDiamondPath(element);
}
return getRectPath(element);
};
///////// helper functions /////////////////////////////
/**
* 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');
}
function isCollection(element) {
return element.isCollection ||
(element.elementObjectRef && element.elementObjectRef.isCollection);
}
function getDi(element) {
return element.businessObject.di;
}
function getSemantic(element) {
return element.businessObject;
}
/////// cropping path customizations /////////////////////////
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, borderRadius) {
var x = shape.x,
y = shape.y,
width = shape.width,
height = shape.height;
var roundRectPath = [
['M', x + borderRadius, y],
['l', width - borderRadius * 2, 0],
['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, borderRadius],
['l', 0, height - borderRadius * 2],
['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, borderRadius],
['l', borderRadius * 2 - width, 0],
['a', borderRadius, borderRadius, 0, 0, 1, -borderRadius, -borderRadius],
['l', 0, borderRadius * 2 - height],
['a', borderRadius, borderRadius, 0, 0, 1, borderRadius, -borderRadius],
['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);
}
},{"../util/DiUtil":55,"../util/ModelUtil":57,"diagram-js/lib/draw/BaseRenderer":86,"diagram-js/lib/util/RenderUtil":110,"diagram-js/lib/util/Text":111,"inherits":122,"lodash/collection/every":129,"lodash/collection/forEach":132,"lodash/collection/includes":134,"lodash/collection/some":138,"lodash/lang/isObject":244,"lodash/object/assign":249}],48:[function(require,module,exports){
'use strict';
var Snap = require('diagram-js/vendor/snapsvg');
/**
* Map containing SVG paths needed by BpmnRenderer.
*/
function PathMap() {
/**
* Contains a map of path elements
*
* Path definition
* A parameterized path is defined like this:
*
* '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]
* }
*
* It's important to specify a correct height and width 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).
* The 'heightElements ' and 'widthElements ' 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 heightElement '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.
*
* The values for the y axis can be accessed in the path string using {e.y0}, {e.y1}, ....
* The values for the x axis can be accessed in the path string using {e.x0}, {e.x1}, ....
*
* The numbers x0, x1 respectively y0, y1, ... map to the corresponding array index.
*
*/
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.x1},-{e.y2} {e.x2},-{e.y3} 0,{e.y1} -{e.x2},-{e.y3} z',
height: 36,
width: 36,
heightElements: [6.5, 13, 0.4, 6.1],
widthElements: [9, 9.3, 8.7]
},
'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} 7,-5 0,10 z m 7.1,-0.3 6.9,-4.7 0,10 -6.9,-4.7 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.
* Use case
* Use case is to scale the content of elements (event, gateways) based
* on the element bounding box's size.
*
* Why not transform
* 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.
*
* @param {String} pathId The ID of the path.
* @param {Object} param
* Example param object scales the path to 60% size of the container (data.width, data.height).
*
* {
* xScaleFactor: 0.6,
* yScaleFactor:0.6,
* containerWidth: data.width,
* containerHeight: data.height,
* position: {
* mx: 0.46,
* my: 0.2,
* }
* }
*
*
* targetpathwidth = xScaleFactor * containerWidth
* targetpathheight = yScaleFactor * containerHeight
* Position is used to set the starting coordinate of the path. M is computed:
*
* position.x * containerWidth
* position.y * containerHeight
*
* Center of the container position: {
* mx: 0.5,
* my: 0.5,
* }
* Upper left corner of the container
* position: {
* mx: 0.0,
* my: 0.0,
* }
*
*
*
*
*/
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;
},{"diagram-js/vendor/snapsvg":112}],49:[function(require,module,exports){
module.exports = {
__init__: [ 'bpmnRenderer' ],
bpmnRenderer: [ 'type', require('./BpmnRenderer') ],
pathMap: [ 'type', require('./PathMap') ]
};
},{"./BpmnRenderer":47,"./PathMap":48}],50:[function(require,module,exports){
'use strict';
var assign = require('lodash/object/assign'),
map = require('lodash/collection/map');
var LabelUtil = require('../util/LabelUtil');
var is = require('../util/ModelUtil').is;
var hasExternalLabel = LabelUtil.hasExternalLabel,
getExternalLabelBounds = LabelUtil.getExternalLabelBounds,
isExpanded = require('../util/DiUtil').isExpanded,
elementToString = require('./Util').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 };
});
}
function notYetDrawn(translate, semantic, refSemantic, property) {
return new Error(translate('element {element} referenced by {referenced}#{property} not yet drawn', {
element: elementToString(refSemantic),
referenced: elementToString(semantic),
property: property
}));
}
/**
* 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, translate) {
this._eventBus = eventBus;
this._canvas = canvas;
this._elementFactory = elementFactory;
this._elementRegistry = elementRegistry;
this._translate = translate;
}
BpmnImporter.$inject = [ 'eventBus', 'canvas', 'elementFactory', 'elementRegistry', 'translate' ];
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,
translate = this._translate;
// ROOT ELEMENT
// handle the special case that we deal with a
// invisible root element (process or collaboration)
if (is(di, 'bpmndi:BPMNPlane')) {
// add a virtual element (not being drawn)
element = this._elementFactory.createRoot(elementData(semantic));
this._canvas.setRootElement(element);
}
// SHAPE
else if (is(di, '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)
}));
if (is(semantic, 'bpmn:BoundaryEvent')) {
this._attachBoundary(semantic, element);
}
this._canvas.addShape(element, parentElement);
}
// CONNECTION
else if (is(di, '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)
}));
if (is(semantic, 'bpmn:DataInputAssociation') || is(semantic, 'bpmn:DataOutputAssociation')) {
// implicit root element
parentElement = null;
}
this._canvas.addConnection(element, parentElement);
} else {
throw new Error(translate('unknown di {di} for element {semantic}', {
di: elementToString(di),
semantic: elementToString(semantic)
}));
}
// (optional) LABEL
if (hasExternalLabel(semantic)) {
this.addLabel(semantic, element);
}
this._eventBus.fire('bpmnElement.added', { element: element });
return element;
};
/**
* Attach the boundary element to the given host
*
* @param {ModdleElement} boundarySemantic
* @param {djs.model.Base} boundaryElement
*/
BpmnImporter.prototype._attachBoundary = function(boundarySemantic, boundaryElement) {
var translate = this._translate;
var hostSemantic = boundarySemantic.attachedToRef;
if (!hostSemantic) {
throw new Error(translate('missing {semantic}#attachedToRef', {
semantic: elementToString(boundarySemantic)
}));
}
var host = this._elementRegistry.get(hostSemantic.id),
attachers = host && host.attachers;
if (!host) {
throw notYetDrawn(translate, boundarySemantic, hostSemantic, 'attachedToRef');
}
// wire element.host <> host.attachers
boundaryElement.host = host;
if (!attachers) {
host.attachers = attachers = [];
}
if (attachers.indexOf(boundaryElement) === -1) {
attachers.push(boundaryElement);
}
};
/**
* 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 || !semantic.name,
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,
translate = this._translate;
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 notYetDrawn(translate, semantic, refSemantic, side + 'Ref');
} else {
throw new Error(translate('{semantic}#{side} Ref not specified', {
semantic: elementToString(semantic),
side: side
}));
}
};
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);
};
},{"../util/DiUtil":55,"../util/LabelUtil":56,"../util/ModelUtil":57,"./Util":53,"lodash/collection/map":136,"lodash/object/assign":249}],51:[function(require,module,exports){
'use strict';
var filter = require('lodash/collection/filter'),
find = require('lodash/collection/find'),
forEach = require('lodash/collection/forEach');
var Refs = require('object-refs');
var elementToString = require('./Util').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, translate) {
// list of containers already walked
var handledElements = {};
// 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 handled(element) {
handledElements[element.id] = element;
}
function isHandled(element) {
return handledElements[element.id];
}
function visit(element, ctx) {
var gfx = element.gfx;
// avoid multiple rendering of elements
if (gfx) {
throw new Error(
translate('already rendered {element}', { element: elementToString(element) })
);
}
// call handler
return handler.element(element, ctx);
}
function visitRoot(element, diagram) {
return handler.root(element, diagram);
}
function visitIfDi(element, ctx) {
try {
var gfx = element.di && visit(element, ctx);
handled(element);
return gfx;
} catch (e) {
logError(e.message, { element: element, error: e });
console.error(translate('failed to import {element}', { element: 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(
translate('multiple DI elements defined for {element}', {
element: elementToString(bpmnElement)
}),
{ element: bpmnElement }
);
} else {
diRefs.bind(bpmnElement, 'di');
bpmnElement.di = di;
}
} else {
logError(
translate('no bpmnElement referenced in {element}', {
element: 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 //////////////////////
/**
* Handle definitions and return the rendered diagram (if any)
*
* @param {ModdleElement} definitions to walk and import
* @param {ModdleElement} [diagram] specific diagram to import and display
*
* @throws {Error} if no diagram to display could be found
*/
function handleDefinitions(definitions, diagram) {
// make sure we walk the correct bpmnElement
var diagrams = definitions.diagrams;
if (diagram && diagrams.indexOf(diagram) === -1) {
throw new Error(translate('diagram not part of bpmn:Definitions'));
}
if (!diagram && diagrams && diagrams.length) {
diagram = diagrams[0];
}
// no diagram -> nothing to import
if (!diagram) {
throw new Error(translate('no diagram to display'));
}
// load DI from selected diagram only
handleDiagram(diagram);
var plane = diagram.plane;
if (!plane) {
throw new Error(translate(
'no plane for {element}',
{ element: 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) {
throw new Error(translate('no process or collaboration to display'));
} else {
logError(
translate('correcting missing bpmnElement on {plane} to {rootElement}', {
plane: elementToString(plane),
rootElement: 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(
translate('unsupported bpmnElement for {plane}: {rootElement}', {
plane: elementToString(plane),
rootElement: 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
handled(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 !isHandled(e) && is(e, 'bpmn:Process') && e.laneSets;
});
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);
}
if (is(flowNode, 'bpmn:Activity')) {
handleIoSpecification(flowNode.ioSpecification, context);
}
// defer handling of associations
// affected types:
//
// * bpmn:Activity
// * bpmn:ThrowEvent
// * bpmn:CatchEvent
//
deferred.push(function() {
forEach(flowNode.dataInputAssociations, contextual(handleDataAssociation, context));
forEach(flowNode.dataOutputAssociations, contextual(handleDataAssociation, 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);
}
wireFlowNodeRefs(lane);
}
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);
}
handleFlowElements(container.flowElements, 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);
} 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(
translate('unrecognized flowElement {element} in context {context}', {
element: elementToString(e),
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);
});
}
function wireFlowNodeRefs(lane) {
// wire the virtual flowNodeRefs <-> relationship
forEach(lane.flowNodeRef, function(flowNode) {
var lanes = flowNode.get('lanes');
if (lanes) {
lanes.push(lane);
}
});
}
///// API ////////////////////////////////
return {
handleDefinitions: handleDefinitions
};
}
module.exports = BpmnTreeWalker;
},{"./Util":53,"lodash/collection/filter":130,"lodash/collection/find":131,"lodash/collection/forEach":132,"object-refs":284}],52:[function(require,module,exports){
'use strict';
var BpmnTreeWalker = require('./BpmnTreeWalker');
/**
* 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'),
translate = diagram.get('translate');
var error,
warnings = [];
/**
* Walk the diagram semantically, importing (=drawing)
* all elements you encounter.
*
* @param {ModdleElement} definitions
*/
function render(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, translate);
// traverse BPMN 2.0 document model,
// starting at definitions
walker.handleDefinitions(definitions);
}
eventBus.fire('import.render.start', { definitions: definitions });
try {
render(definitions);
} catch (e) {
error = e;
}
eventBus.fire('import.render.complete', {
error: error,
warnings: warnings
});
done(error, warnings);
}
module.exports.importBpmnDiagram = importBpmnDiagram;
},{"./BpmnTreeWalker":51}],53:[function(require,module,exports){
'use strict';
module.exports.elementToString = function(e) {
if (!e) {
return '';
}
return '<' + e.$type + (e.id ? ' id="' + e.id : '') + '" />';
};
},{}],54:[function(require,module,exports){
module.exports = {
__depends__: [
require('diagram-js/lib/i18n/translate')
],
bpmnImporter: [ 'type', require('./BpmnImporter') ]
};
},{"./BpmnImporter":50,"diagram-js/lib/i18n/translate":100}],55:[function(require,module,exports){
'use strict';
var is = require('./ModelUtil').is,
getBusinessObject = require('./ModelUtil').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;
};
module.exports.isInterrupting = function(element) {
return element && getBusinessObject(element).isInterrupting !== false;
};
module.exports.isEventSubProcess = function(element) {
return element && !!getBusinessObject(element).triggeredByEvent;
};
},{"./ModelUtil":57}],56:[function(require,module,exports){
'use strict';
var assign = require('lodash/object/assign');
var is = require('./ModelUtil').is;
var DEFAULT_LABEL_SIZE = module.exports.DEFAULT_LABEL_SIZE = {
width: 90,
height: 20
};
var FLOW_LABEL_INDENT = module.exports.FLOW_LABEL_INDENT = 15;
/**
* 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 is(semantic, 'bpmn:Event') ||
is(semantic, 'bpmn:Gateway') ||
is(semantic, 'bpmn:DataStoreReference') ||
is(semantic, 'bpmn:DataObjectReference') ||
is(semantic, 'bpmn:SequenceFlow') ||
is(semantic, 'bpmn:MessageFlow');
};
/**
* Get the position for sequence flow labels
*
* @param {Array} waypoints
* @return {Point} the label position
*/
function getFlowLabelPosition(waypoints) {
// get the waypoints mid
var mid = waypoints.length / 2 - 1;
var first = waypoints[Math.floor(mid)];
var second = waypoints[Math.ceil(mid + 0.01)];
// get position
var position = getWaypointsMid(waypoints);
// calculate angle
var angle = Math.atan( (second.y - first.y) / (second.x - first.x) );
var x = position.x,
y = position.y;
if ( Math.abs(angle) < Math.PI / 2 ) {
y -= FLOW_LABEL_INDENT;
} else {
x += FLOW_LABEL_INDENT;
}
return { x: x, y: y };
}
module.exports.getFlowLabelPosition = getFlowLabelPosition;
/**
* Get the middle of a number of waypoints
*
* @param {Array} waypoints
* @return {Point} the mid point
*/
function getWaypointsMid(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
};
}
module.exports.getWaypointsMid = getWaypointsMid;
function getExternalLabelMid(element) {
if (element.waypoints) {
return getFlowLabelPosition(element.waypoints);
} else {
return {
x: element.x + element.width / 2,
y: element.y + element.height + DEFAULT_LABEL_SIZE.height / 2
};
}
}
module.exports.getExternalLabelMid = getExternalLabelMid;
/**
* 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);
};
},{"./ModelUtil":57,"lodash/object/assign":249}],57:[function(require,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 && (typeof bo.$instanceOf === 'function') && 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;
},{}],58:[function(require,module,exports){
/**
* This file must not be changed or exchanged.
*
* @see http://bpmn.io/license for more information.
*/
'use strict';
var domify = require('min-dom/lib/domify');
var domDelegate = require('min-dom/lib/delegate');
/* jshint -W101 */
// inlined ../resources/bpmnjs.png
var logoData = module.exports.BPMNIO_LOGO = 'iVBORw0KGgoAAAANSUhEUgAAADQAAAA0CAMAAADypuvZAAAAGXRFWHRTb2Z0d2FyZQBBZG9iZSBJbWFnZVJlYWR5ccllPAAAADBQTFRFiMte9PrwldFwfcZPqtqN0+zEyOe1XLgjvuKncsJAZ70y6fXh3vDT////UrQV////G2zN+AAAABB0Uk5T////////////////////AOAjXRkAAAHDSURBVHjavJZJkoUgDEBJmAX8979tM8u3E6x20VlYJfFFMoL4vBDxATxZcakIOJTWSmxvKWVIkJ8jHvlRv1F2LFrVISCZI+tCtQx+XfewgVTfyY3plPiQEAzI3zWy+kR6NBhFBYeBuscJLOUuA2WVLpCjVIaFzrNQZArxAZKUQm6gsj37L9Cb7dnIBUKxENaaMJQqMpDXvSL+ktxdGRm2IsKgJGGPg7atwUG5CcFUEuSv+CwQqizTrvDTNXdMU2bMiDWZd8d7QIySWVRsb2vBBioxOFt4OinPBapL+neAb5KL5IJ8szOza2/DYoipUCx+CjO0Bpsv0V6mktNZ+k8rlABlWG0FrOpKYVo8DT3dBeLEjUBAj7moDogVii7nSS9QzZnFcOVBp1g2PyBQ3Vr5aIapN91VJy33HTJLC1iX2FY6F8gRdaAeIEfVONgtFCzZTmoLEdOjBDfsIOA6128gw3eu1shAajdZNAORxuQDJN5A5PbEG6gNIu24QJD5iNyRMZIr6bsHbCtCU/OaOaSvgkUyDMdDa1BXGf5HJ1To+/Ym6mCKT02Y+/Sa126ZKyd3jxhzpc1r8zVL6YM1Qy/kR4ABAFJ6iQUnivhAAAAAAElFTkSuQmCC';
/* jshint +W101 */
function css(attrs) {
return attrs.join(';');
}
var LIGHTBOX_STYLES = css([
'z-index: 1001',
'position: fixed',
'top: 0',
'left: 0',
'right: 0',
'bottom: 0'
]);
var BACKDROP_STYLES = css([
'width: 100%',
'height: 100%',
'background: rgba(0,0,0,0.2)'
]);
var NOTICE_STYLES = css([
'position: absolute',
'left: 50%',
'top: 40%',
'margin: 0 -130px',
'width: 260px',
'padding: 10px',
'background: white',
'border: solid 1px #AAA',
'border-radius: 3px',
'font-family: Helvetica, Arial, sans-serif',
'font-size: 14px',
'line-height: 1.2em'
]);
var LIGHTBOX_MARKUP =
'' +
'
' +
'
' +
'
' +
' ' +
' ' +
'Web-based tooling for BPMN, DMN and CMMN diagrams ' +
'powered by
bpmn.io .' +
'
' +
'
';
var lightbox;
function open() {
if (!lightbox) {
lightbox = domify(LIGHTBOX_MARKUP);
domDelegate.bind(lightbox, '.backdrop', 'click', function(event) {
document.body.removeChild(lightbox);
});
}
document.body.appendChild(lightbox);
}
module.exports.open = open;
},{"min-dom/lib/delegate":266,"min-dom/lib/domify":267}],59:[function(require,module,exports){
module.exports = require('./lib/simple');
},{"./lib/simple":61}],60:[function(require,module,exports){
'use strict';
var isString = require('lodash/lang/isString'),
isFunction = require('lodash/lang/isFunction'),
assign = require('lodash/object/assign');
var Moddle = require('moddle'),
XmlReader = require('moddle-xml/lib/reader'),
XmlWriter = require('moddle-xml/lib/writer');
/**
* 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);
}
};
},{"lodash/lang/isFunction":241,"lodash/lang/isString":246,"lodash/object/assign":249,"moddle":275,"moddle-xml/lib/reader":273,"moddle-xml/lib/writer":274}],61:[function(require,module,exports){
'use strict';
var assign = require('lodash/object/assign');
var BpmnModdle = require('./bpmn-moddle');
var packages = {
bpmn: require('../resources/bpmn/json/bpmn.json'),
bpmndi: require('../resources/bpmn/json/bpmndi.json'),
dc: require('../resources/bpmn/json/dc.json'),
di: require('../resources/bpmn/json/di.json')
};
module.exports = function(additionalPackages, options) {
return new BpmnModdle(assign({}, packages, additionalPackages), options);
};
},{"../resources/bpmn/json/bpmn.json":62,"../resources/bpmn/json/bpmndi.json":63,"../resources/bpmn/json/dc.json":64,"../resources/bpmn/json/di.json":65,"./bpmn-moddle":60,"lodash/object/assign":249}],62:[function(require,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",
"isReference": true
},
{
"name": "outMessageRef",
"type": "Message",
"isReference": true
},
{
"name": "errorRef",
"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": "laneSets",
"type": "LaneSet",
"isMany": true,
"replaces": "FlowElementsContainer#laneSets"
},
{
"name": "flowElements",
"type": "FlowElement",
"isMany": true,
"replaces": "FlowElementsContainer#flowElements"
},
{
"name": "artifacts",
"type": "Artifact",
"isMany": true
},
{
"name": "resources",
"type": "ResourceRole",
"isMany": true
},
{
"name": "correlationSubscriptions",
"type": "CorrelationSubscription",
"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": "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": "partitionElementRef",
"type": "BaseElement",
"isAttr": true,
"isReference": true
},
{
"name": "partitionElement",
"type": "BaseElement"
},
{
"name": "flowNodeRef",
"type": "FlowNode",
"isMany": true,
"isReference": true
},
{
"name": "childLaneSet",
"type": "LaneSet",
"xml": {
"serialize": "xsi:type"
}
}
]
},
{
"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",
"xml": {
"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",
"isId": true
},
{
"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": "dataInputs",
"type": "DataInput",
"isMany": true
},
{
"name": "dataInputAssociations",
"type": "DataInputAssociation",
"isMany": true
},
{
"name": "inputSet",
"type": "InputSet"
},
{
"name": "eventDefinitions",
"type": "EventDefinition",
"isMany": true
},
{
"name": "eventDefinitionRef",
"type": "EventDefinition",
"isMany": true,
"isReference": true
}
]
},
{
"name": "CatchEvent",
"isAbstract": true,
"superClass": [
"Event"
],
"properties": [
{
"name": "parallelMultiple",
"isAttr": true,
"type": "Boolean",
"default": false
},
{
"name": "dataOutputs",
"type": "DataOutput",
"isMany": true
},
{
"name": "dataOutputAssociations",
"type": "DataOutputAssociation",
"isMany": true
},
{
"name": "outputSet",
"type": "OutputSet"
},
{
"name": "eventDefinitions",
"type": "EventDefinition",
"isMany": true
},
{
"name": "eventDefinitionRef",
"type": "EventDefinition",
"isMany": true,
"isReference": 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",
"xml": {
"serialize": "xsi:type"
}
},
{
"name": "timeCycle",
"type": "Expression",
"xml": {
"serialize": "xsi:type"
}
},
{
"name": "timeDuration",
"type": "Expression",
"xml": {
"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",
"xml": {
"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": "assignment",
"type": "Assignment",
"isMany": true
},
{
"name": "sourceRef",
"type": "ItemAwareElement",
"isMany": true,
"isReference": true
},
{
"name": "targetRef",
"type": "ItemAwareElement",
"isReference": true
},
{
"name": "transformation",
"type": "FormalExpression",
"xml": {
"serialize": "property"
}
}
]
},
{
"name": "DataInput",
"superClass": [
"ItemAwareElement"
],
"properties": [
{
"name": "name",
"isAttr": true,
"type": "String"
},
{
"name": "isCollection",
"default": false,
"isAttr": true,
"type": "Boolean"
},
{
"name": "inputSetRef",
"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": "outputSetRef",
"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": "dataInputs",
"type": "DataInput",
"isMany": true
},
{
"name": "dataOutputs",
"type": "DataOutput",
"isMany": true
},
{
"name": "inputSets",
"type": "InputSet",
"isMany": true
},
{
"name": "outputSets",
"type": "OutputSet",
"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",
"xml": {
"serialize": "xsi:type"
}
},
{
"name": "to",
"type": "Expression",
"xml": {
"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",
"xml": {
"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",
"xml": {
"serialize": "property"
}
},
{
"name": "supportedInterfaceRef",
"type": "Interface",
"isMany": true,
"isReference": true
},
{
"name": "ioBinding",
"type": "InputOutputBinding",
"isMany": true,
"xml": {
"serialize": "property"
}
}
]
},
{
"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": "interfaceRef",
"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": "participants",
"type": "Participant",
"isMany": true
},
{
"name": "messageFlows",
"type": "MessageFlow",
"isMany": true
},
{
"name": "artifacts",
"type": "Artifact",
"isMany": true
},
{
"name": "conversations",
"type": "ConversationNode",
"isMany": true
},
{
"name": "conversationAssociations",
"type": "ConversationAssociation"
},
{
"name": "participantAssociations",
"type": "ParticipantAssociation",
"isMany": true
},
{
"name": "messageFlowAssociations",
"type": "MessageFlowAssociation",
"isMany": true
},
{
"name": "correlationKeys",
"type": "CorrelationKey",
"isMany": true
},
{
"name": "choreographyRef",
"type": "Choreography",
"isMany": true,
"isReference": 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": "default",
"type": "SequenceFlow",
"isAttr": true,
"isReference": true
},
{
"name": "ioSpecification",
"type": "InputOutputSpecification",
"xml": {
"serialize": "property"
}
},
{
"name": "boundaryEventRefs",
"type": "BoundaryEvent",
"isMany": true,
"isReference": true
},
{
"name": "properties",
"type": "Property",
"isMany": true
},
{
"name": "dataInputAssociations",
"type": "DataInputAssociation",
"isMany": true
},
{
"name": "dataOutputAssociations",
"type": "DataOutputAssociation",
"isMany": true
},
{
"name": "startQuantity",
"default": 1,
"isAttr": true,
"type": "Integer"
},
{
"name": "resources",
"type": "ResourceRole",
"isMany": true
},
{
"name": "completionQuantity",
"default": 1,
"isAttr": true,
"type": "Integer"
},
{
"name": "loopCharacteristics",
"type": "LoopCharacteristics"
}
]
},
{
"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",
"xml": {
"serialize": "xsi:type"
}
},
{
"name": "loopDataInputRef",
"type": "ItemAwareElement",
"isReference": true
},
{
"name": "loopDataOutputRef",
"type": "ItemAwareElement",
"isReference": true
},
{
"name": "inputDataItem",
"type": "DataInput",
"xml": {
"serialize": "property"
}
},
{
"name": "outputDataItem",
"type": "DataOutput",
"xml": {
"serialize": "property"
}
},
{
"name": "complexBehaviorDefinition",
"type": "ComplexBehaviorDefinition",
"isMany": true
},
{
"name": "completionCondition",
"type": "Expression",
"xml": {
"serialize": "xsi:type"
}
},
{
"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",
"xml": {
"serialize": "xsi:type"
}
},
{
"name": "loopMaximum",
"type": "Expression",
"xml": {
"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",
"xml": {
"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",
"xml": {
"serialize": "xsi:type"
}
},
{
"name": "parameterRef",
"type": "ResourceParameter",
"isAttr": true,
"isReference": true
}
]
},
{
"name": "ResourceAssignmentExpression",
"properties": [
{
"name": "expression",
"type": "Expression",
"xml": {
"serialize": "xsi:type"
}
}
],
"superClass": [
"BaseElement"
]
},
{
"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"
}
}
},{}],63:[function(require,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"
}
},{}],64:[function(require,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": []
}
},{}],65:[function(require,module,exports){
module.exports={
"name": "DI",
"uri": "http://www.omg.org/spec/DD/20100524/DI",
"types": [
{
"name": "DiagramElement",
"isAbstract": true,
"properties": [
{
"name": "id",
"type": "String",
"isAttr": true,
"isId": true
},
{
"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",
"xml": {
"serialize": "xsi:type"
}
}
]
},
{
"name": "Diagram",
"isAbstract": true,
"properties": [
{
"name": "id",
"type": "String",
"isAttr": true,
"isId": true
},
{
"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,
"properties": [
{
"name": "id",
"type": "String",
"isAttr": true,
"isId": true
}
]
},
{
"name": "Extension",
"properties": [
{
"name": "values",
"type": "Element",
"isMany": true
}
]
}
],
"associations": [],
"prefix": "di",
"xml": {
"tagAlias": "lowerCase"
}
}
},{}],66:[function(require,module,exports){
},{}],67:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
function EventEmitter() {
this._events = this._events || {};
this._maxListeners = this._maxListeners || undefined;
}
module.exports = EventEmitter;
// Backwards-compat with node 0.10.x
EventEmitter.EventEmitter = EventEmitter;
EventEmitter.prototype._events = undefined;
EventEmitter.prototype._maxListeners = undefined;
// By default EventEmitters will print a warning if more than 10 listeners are
// added to it. This is a useful default which helps finding memory leaks.
EventEmitter.defaultMaxListeners = 10;
// Obviously not all Emitters should be limited to 10. This function allows
// that to be increased. Set to zero for unlimited.
EventEmitter.prototype.setMaxListeners = function(n) {
if (!isNumber(n) || n < 0 || isNaN(n))
throw TypeError('n must be a positive number');
this._maxListeners = n;
return this;
};
EventEmitter.prototype.emit = function(type) {
var er, handler, len, args, i, listeners;
if (!this._events)
this._events = {};
// If there is no 'error' event listener then throw.
if (type === 'error') {
if (!this._events.error ||
(isObject(this._events.error) && !this._events.error.length)) {
er = arguments[1];
if (er instanceof Error) {
throw er; // Unhandled 'error' event
}
throw TypeError('Uncaught, unspecified "error" event.');
}
}
handler = this._events[type];
if (isUndefined(handler))
return false;
if (isFunction(handler)) {
switch (arguments.length) {
// fast cases
case 1:
handler.call(this);
break;
case 2:
handler.call(this, arguments[1]);
break;
case 3:
handler.call(this, arguments[1], arguments[2]);
break;
// slower
default:
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
args[i - 1] = arguments[i];
handler.apply(this, args);
}
} else if (isObject(handler)) {
len = arguments.length;
args = new Array(len - 1);
for (i = 1; i < len; i++)
args[i - 1] = arguments[i];
listeners = handler.slice();
len = listeners.length;
for (i = 0; i < len; i++)
listeners[i].apply(this, args);
}
return true;
};
EventEmitter.prototype.addListener = function(type, listener) {
var m;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events)
this._events = {};
// To avoid recursion in the case that type === "newListener"! Before
// adding it to the listeners, first emit "newListener".
if (this._events.newListener)
this.emit('newListener', type,
isFunction(listener.listener) ?
listener.listener : listener);
if (!this._events[type])
// Optimize the case of one listener. Don't need the extra array object.
this._events[type] = listener;
else if (isObject(this._events[type]))
// If we've already got an array, just append.
this._events[type].push(listener);
else
// Adding the second element, need to change to array.
this._events[type] = [this._events[type], listener];
// Check for listener leak
if (isObject(this._events[type]) && !this._events[type].warned) {
var m;
if (!isUndefined(this._maxListeners)) {
m = this._maxListeners;
} else {
m = EventEmitter.defaultMaxListeners;
}
if (m && m > 0 && this._events[type].length > m) {
this._events[type].warned = true;
console.error('(node) warning: possible EventEmitter memory ' +
'leak detected. %d listeners added. ' +
'Use emitter.setMaxListeners() to increase limit.',
this._events[type].length);
if (typeof console.trace === 'function') {
// not supported in IE 10
console.trace();
}
}
}
return this;
};
EventEmitter.prototype.on = EventEmitter.prototype.addListener;
EventEmitter.prototype.once = function(type, listener) {
if (!isFunction(listener))
throw TypeError('listener must be a function');
var fired = false;
function g() {
this.removeListener(type, g);
if (!fired) {
fired = true;
listener.apply(this, arguments);
}
}
g.listener = listener;
this.on(type, g);
return this;
};
// emits a 'removeListener' event iff the listener was removed
EventEmitter.prototype.removeListener = function(type, listener) {
var list, position, length, i;
if (!isFunction(listener))
throw TypeError('listener must be a function');
if (!this._events || !this._events[type])
return this;
list = this._events[type];
length = list.length;
position = -1;
if (list === listener ||
(isFunction(list.listener) && list.listener === listener)) {
delete this._events[type];
if (this._events.removeListener)
this.emit('removeListener', type, listener);
} else if (isObject(list)) {
for (i = length; i-- > 0;) {
if (list[i] === listener ||
(list[i].listener && list[i].listener === listener)) {
position = i;
break;
}
}
if (position < 0)
return this;
if (list.length === 1) {
list.length = 0;
delete this._events[type];
} else {
list.splice(position, 1);
}
if (this._events.removeListener)
this.emit('removeListener', type, listener);
}
return this;
};
EventEmitter.prototype.removeAllListeners = function(type) {
var key, listeners;
if (!this._events)
return this;
// not listening for removeListener, no need to emit
if (!this._events.removeListener) {
if (arguments.length === 0)
this._events = {};
else if (this._events[type])
delete this._events[type];
return this;
}
// emit removeListener for all listeners on all events
if (arguments.length === 0) {
for (key in this._events) {
if (key === 'removeListener') continue;
this.removeAllListeners(key);
}
this.removeAllListeners('removeListener');
this._events = {};
return this;
}
listeners = this._events[type];
if (isFunction(listeners)) {
this.removeListener(type, listeners);
} else {
// LIFO order
while (listeners.length)
this.removeListener(type, listeners[listeners.length - 1]);
}
delete this._events[type];
return this;
};
EventEmitter.prototype.listeners = function(type) {
var ret;
if (!this._events || !this._events[type])
ret = [];
else if (isFunction(this._events[type]))
ret = [this._events[type]];
else
ret = this._events[type].slice();
return ret;
};
EventEmitter.listenerCount = function(emitter, type) {
var ret;
if (!emitter._events || !emitter._events[type])
ret = 0;
else if (isFunction(emitter._events[type]))
ret = 1;
else
ret = emitter._events[type].length;
return ret;
};
function isFunction(arg) {
return typeof arg === 'function';
}
function isNumber(arg) {
return typeof arg === 'number';
}
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
function isUndefined(arg) {
return arg === void 0;
}
},{}],68:[function(require,module,exports){
(function (global){
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh
* @license MIT
*/
/* eslint-disable no-proto */
'use strict'
var base64 = require('base64-js')
var ieee754 = require('ieee754')
var isArray = require('isarray')
exports.Buffer = Buffer
exports.SlowBuffer = SlowBuffer
exports.INSPECT_MAX_BYTES = 50
Buffer.poolSize = 8192 // not used by this implementation
var rootParent = {}
/**
* If `Buffer.TYPED_ARRAY_SUPPORT`:
* === true Use Uint8Array implementation (fastest)
* === false Use Object implementation (most compatible, even IE6)
*
* Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+,
* Opera 11.6+, iOS 4.2+.
*
* Due to various browser bugs, sometimes the Object implementation will be used even
* when the browser supports typed arrays.
*
* Note:
*
* - Firefox 4-29 lacks support for adding new properties to `Uint8Array` instances,
* See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438.
*
* - Safari 5-7 lacks support for changing the `Object.prototype.constructor` property
* on objects.
*
* - Chrome 9-10 is missing the `TypedArray.prototype.subarray` function.
*
* - IE10 has a broken `TypedArray.prototype.subarray` function which returns arrays of
* incorrect length in some situations.
* We detect these buggy browsers and set `Buffer.TYPED_ARRAY_SUPPORT` to `false` so they
* get the Object implementation, which is slower but behaves correctly.
*/
Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
? global.TYPED_ARRAY_SUPPORT
: typedArraySupport()
function typedArraySupport () {
function Bar () {}
try {
var arr = new Uint8Array(1)
arr.foo = function () { return 42 }
arr.constructor = Bar
return arr.foo() === 42 && // typed array instances can be augmented
arr.constructor === Bar && // constructor can be set
typeof arr.subarray === 'function' && // chrome 9-10 lack `subarray`
arr.subarray(1, 1).byteLength === 0 // ie10 has broken `subarray`
} catch (e) {
return false
}
}
function kMaxLength () {
return Buffer.TYPED_ARRAY_SUPPORT
? 0x7fffffff
: 0x3fffffff
}
/**
* Class: Buffer
* =============
*
* The Buffer constructor returns instances of `Uint8Array` that are augmented
* with function properties for all the node `Buffer` API functions. We use
* `Uint8Array` so that square bracket notation works as expected -- it returns
* a single octet.
*
* By augmenting the instances, we can avoid modifying the `Uint8Array`
* prototype.
*/
function Buffer (arg) {
if (!(this instanceof Buffer)) {
// Avoid going through an ArgumentsAdaptorTrampoline in the common case.
if (arguments.length > 1) return new Buffer(arg, arguments[1])
return new Buffer(arg)
}
if (!Buffer.TYPED_ARRAY_SUPPORT) {
this.length = 0
this.parent = undefined
}
// Common case.
if (typeof arg === 'number') {
return fromNumber(this, arg)
}
// Slightly less common case.
if (typeof arg === 'string') {
return fromString(this, arg, arguments.length > 1 ? arguments[1] : 'utf8')
}
// Unusual.
return fromObject(this, arg)
}
function fromNumber (that, length) {
that = allocate(that, length < 0 ? 0 : checked(length) | 0)
if (!Buffer.TYPED_ARRAY_SUPPORT) {
for (var i = 0; i < length; i++) {
that[i] = 0
}
}
return that
}
function fromString (that, string, encoding) {
if (typeof encoding !== 'string' || encoding === '') encoding = 'utf8'
// Assumption: byteLength() return value is always < kMaxLength.
var length = byteLength(string, encoding) | 0
that = allocate(that, length)
that.write(string, encoding)
return that
}
function fromObject (that, object) {
if (Buffer.isBuffer(object)) return fromBuffer(that, object)
if (isArray(object)) return fromArray(that, object)
if (object == null) {
throw new TypeError('must start with number, buffer, array or string')
}
if (typeof ArrayBuffer !== 'undefined') {
if (object.buffer instanceof ArrayBuffer) {
return fromTypedArray(that, object)
}
if (object instanceof ArrayBuffer) {
return fromArrayBuffer(that, object)
}
}
if (object.length) return fromArrayLike(that, object)
return fromJsonObject(that, object)
}
function fromBuffer (that, buffer) {
var length = checked(buffer.length) | 0
that = allocate(that, length)
buffer.copy(that, 0, 0, length)
return that
}
function fromArray (that, array) {
var length = checked(array.length) | 0
that = allocate(that, length)
for (var i = 0; i < length; i += 1) {
that[i] = array[i] & 255
}
return that
}
// Duplicate of fromArray() to keep fromArray() monomorphic.
function fromTypedArray (that, array) {
var length = checked(array.length) | 0
that = allocate(that, length)
// Truncating the elements is probably not what people expect from typed
// arrays with BYTES_PER_ELEMENT > 1 but it's compatible with the behavior
// of the old Buffer constructor.
for (var i = 0; i < length; i += 1) {
that[i] = array[i] & 255
}
return that
}
function fromArrayBuffer (that, array) {
if (Buffer.TYPED_ARRAY_SUPPORT) {
// Return an augmented `Uint8Array` instance, for best performance
array.byteLength
that = Buffer._augment(new Uint8Array(array))
} else {
// Fallback: Return an object instance of the Buffer class
that = fromTypedArray(that, new Uint8Array(array))
}
return that
}
function fromArrayLike (that, array) {
var length = checked(array.length) | 0
that = allocate(that, length)
for (var i = 0; i < length; i += 1) {
that[i] = array[i] & 255
}
return that
}
// Deserialize { type: 'Buffer', data: [1,2,3,...] } into a Buffer object.
// Returns a zero-length buffer for inputs that don't conform to the spec.
function fromJsonObject (that, object) {
var array
var length = 0
if (object.type === 'Buffer' && isArray(object.data)) {
array = object.data
length = checked(array.length) | 0
}
that = allocate(that, length)
for (var i = 0; i < length; i += 1) {
that[i] = array[i] & 255
}
return that
}
if (Buffer.TYPED_ARRAY_SUPPORT) {
Buffer.prototype.__proto__ = Uint8Array.prototype
Buffer.__proto__ = Uint8Array
} else {
// pre-set for values that may exist in the future
Buffer.prototype.length = undefined
Buffer.prototype.parent = undefined
}
function allocate (that, length) {
if (Buffer.TYPED_ARRAY_SUPPORT) {
// Return an augmented `Uint8Array` instance, for best performance
that = Buffer._augment(new Uint8Array(length))
that.__proto__ = Buffer.prototype
} else {
// Fallback: Return an object instance of the Buffer class
that.length = length
that._isBuffer = true
}
var fromPool = length !== 0 && length <= Buffer.poolSize >>> 1
if (fromPool) that.parent = rootParent
return that
}
function checked (length) {
// Note: cannot use `length < kMaxLength` here because that fails when
// length is NaN (which is otherwise coerced to zero.)
if (length >= kMaxLength()) {
throw new RangeError('Attempt to allocate Buffer larger than maximum ' +
'size: 0x' + kMaxLength().toString(16) + ' bytes')
}
return length | 0
}
function SlowBuffer (subject, encoding) {
if (!(this instanceof SlowBuffer)) return new SlowBuffer(subject, encoding)
var buf = new Buffer(subject, encoding)
delete buf.parent
return buf
}
Buffer.isBuffer = function isBuffer (b) {
return !!(b != null && b._isBuffer)
}
Buffer.compare = function compare (a, b) {
if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) {
throw new TypeError('Arguments must be Buffers')
}
if (a === b) return 0
var x = a.length
var y = b.length
var i = 0
var len = Math.min(x, y)
while (i < len) {
if (a[i] !== b[i]) break
++i
}
if (i !== len) {
x = a[i]
y = b[i]
}
if (x < y) return -1
if (y < x) return 1
return 0
}
Buffer.isEncoding = function isEncoding (encoding) {
switch (String(encoding).toLowerCase()) {
case 'hex':
case 'utf8':
case 'utf-8':
case 'ascii':
case 'binary':
case 'base64':
case 'raw':
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return true
default:
return false
}
}
Buffer.concat = function concat (list, length) {
if (!isArray(list)) throw new TypeError('list argument must be an Array of Buffers.')
if (list.length === 0) {
return new Buffer(0)
}
var i
if (length === undefined) {
length = 0
for (i = 0; i < list.length; i++) {
length += list[i].length
}
}
var buf = new Buffer(length)
var pos = 0
for (i = 0; i < list.length; i++) {
var item = list[i]
item.copy(buf, pos)
pos += item.length
}
return buf
}
function byteLength (string, encoding) {
if (typeof string !== 'string') string = '' + string
var len = string.length
if (len === 0) return 0
// Use a for loop to avoid recursion
var loweredCase = false
for (;;) {
switch (encoding) {
case 'ascii':
case 'binary':
// Deprecated
case 'raw':
case 'raws':
return len
case 'utf8':
case 'utf-8':
return utf8ToBytes(string).length
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return len * 2
case 'hex':
return len >>> 1
case 'base64':
return base64ToBytes(string).length
default:
if (loweredCase) return utf8ToBytes(string).length // assume utf8
encoding = ('' + encoding).toLowerCase()
loweredCase = true
}
}
}
Buffer.byteLength = byteLength
function slowToString (encoding, start, end) {
var loweredCase = false
start = start | 0
end = end === undefined || end === Infinity ? this.length : end | 0
if (!encoding) encoding = 'utf8'
if (start < 0) start = 0
if (end > this.length) end = this.length
if (end <= start) return ''
while (true) {
switch (encoding) {
case 'hex':
return hexSlice(this, start, end)
case 'utf8':
case 'utf-8':
return utf8Slice(this, start, end)
case 'ascii':
return asciiSlice(this, start, end)
case 'binary':
return binarySlice(this, start, end)
case 'base64':
return base64Slice(this, start, end)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return utf16leSlice(this, start, end)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = (encoding + '').toLowerCase()
loweredCase = true
}
}
}
Buffer.prototype.toString = function toString () {
var length = this.length | 0
if (length === 0) return ''
if (arguments.length === 0) return utf8Slice(this, 0, length)
return slowToString.apply(this, arguments)
}
Buffer.prototype.equals = function equals (b) {
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
if (this === b) return true
return Buffer.compare(this, b) === 0
}
Buffer.prototype.inspect = function inspect () {
var str = ''
var max = exports.INSPECT_MAX_BYTES
if (this.length > 0) {
str = this.toString('hex', 0, max).match(/.{2}/g).join(' ')
if (this.length > max) str += ' ... '
}
return ''
}
Buffer.prototype.compare = function compare (b) {
if (!Buffer.isBuffer(b)) throw new TypeError('Argument must be a Buffer')
if (this === b) return 0
return Buffer.compare(this, b)
}
Buffer.prototype.indexOf = function indexOf (val, byteOffset) {
if (byteOffset > 0x7fffffff) byteOffset = 0x7fffffff
else if (byteOffset < -0x80000000) byteOffset = -0x80000000
byteOffset >>= 0
if (this.length === 0) return -1
if (byteOffset >= this.length) return -1
// Negative offsets start from the end of the buffer
if (byteOffset < 0) byteOffset = Math.max(this.length + byteOffset, 0)
if (typeof val === 'string') {
if (val.length === 0) return -1 // special case: looking for empty string always fails
return String.prototype.indexOf.call(this, val, byteOffset)
}
if (Buffer.isBuffer(val)) {
return arrayIndexOf(this, val, byteOffset)
}
if (typeof val === 'number') {
if (Buffer.TYPED_ARRAY_SUPPORT && Uint8Array.prototype.indexOf === 'function') {
return Uint8Array.prototype.indexOf.call(this, val, byteOffset)
}
return arrayIndexOf(this, [ val ], byteOffset)
}
function arrayIndexOf (arr, val, byteOffset) {
var foundIndex = -1
for (var i = 0; byteOffset + i < arr.length; i++) {
if (arr[byteOffset + i] === val[foundIndex === -1 ? 0 : i - foundIndex]) {
if (foundIndex === -1) foundIndex = i
if (i - foundIndex + 1 === val.length) return byteOffset + foundIndex
} else {
foundIndex = -1
}
}
return -1
}
throw new TypeError('val must be string, number or Buffer')
}
// `get` is deprecated
Buffer.prototype.get = function get (offset) {
console.log('.get() is deprecated. Access using array indexes instead.')
return this.readUInt8(offset)
}
// `set` is deprecated
Buffer.prototype.set = function set (v, offset) {
console.log('.set() is deprecated. Access using array indexes instead.')
return this.writeUInt8(v, offset)
}
function hexWrite (buf, string, offset, length) {
offset = Number(offset) || 0
var remaining = buf.length - offset
if (!length) {
length = remaining
} else {
length = Number(length)
if (length > remaining) {
length = remaining
}
}
// must be an even number of digits
var strLen = string.length
if (strLen % 2 !== 0) throw new Error('Invalid hex string')
if (length > strLen / 2) {
length = strLen / 2
}
for (var i = 0; i < length; i++) {
var parsed = parseInt(string.substr(i * 2, 2), 16)
if (isNaN(parsed)) throw new Error('Invalid hex string')
buf[offset + i] = parsed
}
return i
}
function utf8Write (buf, string, offset, length) {
return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length)
}
function asciiWrite (buf, string, offset, length) {
return blitBuffer(asciiToBytes(string), buf, offset, length)
}
function binaryWrite (buf, string, offset, length) {
return asciiWrite(buf, string, offset, length)
}
function base64Write (buf, string, offset, length) {
return blitBuffer(base64ToBytes(string), buf, offset, length)
}
function ucs2Write (buf, string, offset, length) {
return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length)
}
Buffer.prototype.write = function write (string, offset, length, encoding) {
// Buffer#write(string)
if (offset === undefined) {
encoding = 'utf8'
length = this.length
offset = 0
// Buffer#write(string, encoding)
} else if (length === undefined && typeof offset === 'string') {
encoding = offset
length = this.length
offset = 0
// Buffer#write(string, offset[, length][, encoding])
} else if (isFinite(offset)) {
offset = offset | 0
if (isFinite(length)) {
length = length | 0
if (encoding === undefined) encoding = 'utf8'
} else {
encoding = length
length = undefined
}
// legacy write(string, encoding, offset, length) - remove in v0.13
} else {
var swap = encoding
encoding = offset
offset = length | 0
length = swap
}
var remaining = this.length - offset
if (length === undefined || length > remaining) length = remaining
if ((string.length > 0 && (length < 0 || offset < 0)) || offset > this.length) {
throw new RangeError('attempt to write outside buffer bounds')
}
if (!encoding) encoding = 'utf8'
var loweredCase = false
for (;;) {
switch (encoding) {
case 'hex':
return hexWrite(this, string, offset, length)
case 'utf8':
case 'utf-8':
return utf8Write(this, string, offset, length)
case 'ascii':
return asciiWrite(this, string, offset, length)
case 'binary':
return binaryWrite(this, string, offset, length)
case 'base64':
// Warning: maxLength not taken into account in base64Write
return base64Write(this, string, offset, length)
case 'ucs2':
case 'ucs-2':
case 'utf16le':
case 'utf-16le':
return ucs2Write(this, string, offset, length)
default:
if (loweredCase) throw new TypeError('Unknown encoding: ' + encoding)
encoding = ('' + encoding).toLowerCase()
loweredCase = true
}
}
}
Buffer.prototype.toJSON = function toJSON () {
return {
type: 'Buffer',
data: Array.prototype.slice.call(this._arr || this, 0)
}
}
function base64Slice (buf, start, end) {
if (start === 0 && end === buf.length) {
return base64.fromByteArray(buf)
} else {
return base64.fromByteArray(buf.slice(start, end))
}
}
function utf8Slice (buf, start, end) {
end = Math.min(buf.length, end)
var res = []
var i = start
while (i < end) {
var firstByte = buf[i]
var codePoint = null
var bytesPerSequence = (firstByte > 0xEF) ? 4
: (firstByte > 0xDF) ? 3
: (firstByte > 0xBF) ? 2
: 1
if (i + bytesPerSequence <= end) {
var secondByte, thirdByte, fourthByte, tempCodePoint
switch (bytesPerSequence) {
case 1:
if (firstByte < 0x80) {
codePoint = firstByte
}
break
case 2:
secondByte = buf[i + 1]
if ((secondByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0x1F) << 0x6 | (secondByte & 0x3F)
if (tempCodePoint > 0x7F) {
codePoint = tempCodePoint
}
}
break
case 3:
secondByte = buf[i + 1]
thirdByte = buf[i + 2]
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0xC | (secondByte & 0x3F) << 0x6 | (thirdByte & 0x3F)
if (tempCodePoint > 0x7FF && (tempCodePoint < 0xD800 || tempCodePoint > 0xDFFF)) {
codePoint = tempCodePoint
}
}
break
case 4:
secondByte = buf[i + 1]
thirdByte = buf[i + 2]
fourthByte = buf[i + 3]
if ((secondByte & 0xC0) === 0x80 && (thirdByte & 0xC0) === 0x80 && (fourthByte & 0xC0) === 0x80) {
tempCodePoint = (firstByte & 0xF) << 0x12 | (secondByte & 0x3F) << 0xC | (thirdByte & 0x3F) << 0x6 | (fourthByte & 0x3F)
if (tempCodePoint > 0xFFFF && tempCodePoint < 0x110000) {
codePoint = tempCodePoint
}
}
}
}
if (codePoint === null) {
// we did not generate a valid codePoint so insert a
// replacement char (U+FFFD) and advance only 1 byte
codePoint = 0xFFFD
bytesPerSequence = 1
} else if (codePoint > 0xFFFF) {
// encode to utf16 (surrogate pair dance)
codePoint -= 0x10000
res.push(codePoint >>> 10 & 0x3FF | 0xD800)
codePoint = 0xDC00 | codePoint & 0x3FF
}
res.push(codePoint)
i += bytesPerSequence
}
return decodeCodePointsArray(res)
}
// Based on http://stackoverflow.com/a/22747272/680742, the browser with
// the lowest limit is Chrome, with 0x10000 args.
// We go 1 magnitude less, for safety
var MAX_ARGUMENTS_LENGTH = 0x1000
function decodeCodePointsArray (codePoints) {
var len = codePoints.length
if (len <= MAX_ARGUMENTS_LENGTH) {
return String.fromCharCode.apply(String, codePoints) // avoid extra slice()
}
// Decode in chunks to avoid "call stack size exceeded".
var res = ''
var i = 0
while (i < len) {
res += String.fromCharCode.apply(
String,
codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)
)
}
return res
}
function asciiSlice (buf, start, end) {
var ret = ''
end = Math.min(buf.length, end)
for (var i = start; i < end; i++) {
ret += String.fromCharCode(buf[i] & 0x7F)
}
return ret
}
function binarySlice (buf, start, end) {
var ret = ''
end = Math.min(buf.length, end)
for (var i = start; i < end; i++) {
ret += String.fromCharCode(buf[i])
}
return ret
}
function hexSlice (buf, start, end) {
var len = buf.length
if (!start || start < 0) start = 0
if (!end || end < 0 || end > len) end = len
var out = ''
for (var i = start; i < end; i++) {
out += toHex(buf[i])
}
return out
}
function utf16leSlice (buf, start, end) {
var bytes = buf.slice(start, end)
var res = ''
for (var i = 0; i < bytes.length; i += 2) {
res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256)
}
return res
}
Buffer.prototype.slice = function slice (start, end) {
var len = this.length
start = ~~start
end = end === undefined ? len : ~~end
if (start < 0) {
start += len
if (start < 0) start = 0
} else if (start > len) {
start = len
}
if (end < 0) {
end += len
if (end < 0) end = 0
} else if (end > len) {
end = len
}
if (end < start) end = start
var newBuf
if (Buffer.TYPED_ARRAY_SUPPORT) {
newBuf = Buffer._augment(this.subarray(start, end))
} else {
var sliceLen = end - start
newBuf = new Buffer(sliceLen, undefined)
for (var i = 0; i < sliceLen; i++) {
newBuf[i] = this[i + start]
}
}
if (newBuf.length) newBuf.parent = this.parent || this
return newBuf
}
/*
* Need to make sure that buffer isn't trying to write out of bounds.
*/
function checkOffset (offset, ext, length) {
if ((offset % 1) !== 0 || offset < 0) throw new RangeError('offset is not uint')
if (offset + ext > length) throw new RangeError('Trying to access beyond buffer length')
}
Buffer.prototype.readUIntLE = function readUIntLE (offset, byteLength, noAssert) {
offset = offset | 0
byteLength = byteLength | 0
if (!noAssert) checkOffset(offset, byteLength, this.length)
var val = this[offset]
var mul = 1
var i = 0
while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul
}
return val
}
Buffer.prototype.readUIntBE = function readUIntBE (offset, byteLength, noAssert) {
offset = offset | 0
byteLength = byteLength | 0
if (!noAssert) {
checkOffset(offset, byteLength, this.length)
}
var val = this[offset + --byteLength]
var mul = 1
while (byteLength > 0 && (mul *= 0x100)) {
val += this[offset + --byteLength] * mul
}
return val
}
Buffer.prototype.readUInt8 = function readUInt8 (offset, noAssert) {
if (!noAssert) checkOffset(offset, 1, this.length)
return this[offset]
}
Buffer.prototype.readUInt16LE = function readUInt16LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length)
return this[offset] | (this[offset + 1] << 8)
}
Buffer.prototype.readUInt16BE = function readUInt16BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length)
return (this[offset] << 8) | this[offset + 1]
}
Buffer.prototype.readUInt32LE = function readUInt32LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length)
return ((this[offset]) |
(this[offset + 1] << 8) |
(this[offset + 2] << 16)) +
(this[offset + 3] * 0x1000000)
}
Buffer.prototype.readUInt32BE = function readUInt32BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length)
return (this[offset] * 0x1000000) +
((this[offset + 1] << 16) |
(this[offset + 2] << 8) |
this[offset + 3])
}
Buffer.prototype.readIntLE = function readIntLE (offset, byteLength, noAssert) {
offset = offset | 0
byteLength = byteLength | 0
if (!noAssert) checkOffset(offset, byteLength, this.length)
var val = this[offset]
var mul = 1
var i = 0
while (++i < byteLength && (mul *= 0x100)) {
val += this[offset + i] * mul
}
mul *= 0x80
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
return val
}
Buffer.prototype.readIntBE = function readIntBE (offset, byteLength, noAssert) {
offset = offset | 0
byteLength = byteLength | 0
if (!noAssert) checkOffset(offset, byteLength, this.length)
var i = byteLength
var mul = 1
var val = this[offset + --i]
while (i > 0 && (mul *= 0x100)) {
val += this[offset + --i] * mul
}
mul *= 0x80
if (val >= mul) val -= Math.pow(2, 8 * byteLength)
return val
}
Buffer.prototype.readInt8 = function readInt8 (offset, noAssert) {
if (!noAssert) checkOffset(offset, 1, this.length)
if (!(this[offset] & 0x80)) return (this[offset])
return ((0xff - this[offset] + 1) * -1)
}
Buffer.prototype.readInt16LE = function readInt16LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length)
var val = this[offset] | (this[offset + 1] << 8)
return (val & 0x8000) ? val | 0xFFFF0000 : val
}
Buffer.prototype.readInt16BE = function readInt16BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 2, this.length)
var val = this[offset + 1] | (this[offset] << 8)
return (val & 0x8000) ? val | 0xFFFF0000 : val
}
Buffer.prototype.readInt32LE = function readInt32LE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length)
return (this[offset]) |
(this[offset + 1] << 8) |
(this[offset + 2] << 16) |
(this[offset + 3] << 24)
}
Buffer.prototype.readInt32BE = function readInt32BE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length)
return (this[offset] << 24) |
(this[offset + 1] << 16) |
(this[offset + 2] << 8) |
(this[offset + 3])
}
Buffer.prototype.readFloatLE = function readFloatLE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length)
return ieee754.read(this, offset, true, 23, 4)
}
Buffer.prototype.readFloatBE = function readFloatBE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 4, this.length)
return ieee754.read(this, offset, false, 23, 4)
}
Buffer.prototype.readDoubleLE = function readDoubleLE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 8, this.length)
return ieee754.read(this, offset, true, 52, 8)
}
Buffer.prototype.readDoubleBE = function readDoubleBE (offset, noAssert) {
if (!noAssert) checkOffset(offset, 8, this.length)
return ieee754.read(this, offset, false, 52, 8)
}
function checkInt (buf, value, offset, ext, max, min) {
if (!Buffer.isBuffer(buf)) throw new TypeError('buffer must be a Buffer instance')
if (value > max || value < min) throw new RangeError('value is out of bounds')
if (offset + ext > buf.length) throw new RangeError('index out of range')
}
Buffer.prototype.writeUIntLE = function writeUIntLE (value, offset, byteLength, noAssert) {
value = +value
offset = offset | 0
byteLength = byteLength | 0
if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
var mul = 1
var i = 0
this[offset] = value & 0xFF
while (++i < byteLength && (mul *= 0x100)) {
this[offset + i] = (value / mul) & 0xFF
}
return offset + byteLength
}
Buffer.prototype.writeUIntBE = function writeUIntBE (value, offset, byteLength, noAssert) {
value = +value
offset = offset | 0
byteLength = byteLength | 0
if (!noAssert) checkInt(this, value, offset, byteLength, Math.pow(2, 8 * byteLength), 0)
var i = byteLength - 1
var mul = 1
this[offset + i] = value & 0xFF
while (--i >= 0 && (mul *= 0x100)) {
this[offset + i] = (value / mul) & 0xFF
}
return offset + byteLength
}
Buffer.prototype.writeUInt8 = function writeUInt8 (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 1, 0xff, 0)
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
this[offset] = (value & 0xff)
return offset + 1
}
function objectWriteUInt16 (buf, value, offset, littleEndian) {
if (value < 0) value = 0xffff + value + 1
for (var i = 0, j = Math.min(buf.length - offset, 2); i < j; i++) {
buf[offset + i] = (value & (0xff << (8 * (littleEndian ? i : 1 - i)))) >>>
(littleEndian ? i : 1 - i) * 8
}
}
Buffer.prototype.writeUInt16LE = function writeUInt16LE (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff)
this[offset + 1] = (value >>> 8)
} else {
objectWriteUInt16(this, value, offset, true)
}
return offset + 2
}
Buffer.prototype.writeUInt16BE = function writeUInt16BE (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 2, 0xffff, 0)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8)
this[offset + 1] = (value & 0xff)
} else {
objectWriteUInt16(this, value, offset, false)
}
return offset + 2
}
function objectWriteUInt32 (buf, value, offset, littleEndian) {
if (value < 0) value = 0xffffffff + value + 1
for (var i = 0, j = Math.min(buf.length - offset, 4); i < j; i++) {
buf[offset + i] = (value >>> (littleEndian ? i : 3 - i) * 8) & 0xff
}
}
Buffer.prototype.writeUInt32LE = function writeUInt32LE (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset + 3] = (value >>> 24)
this[offset + 2] = (value >>> 16)
this[offset + 1] = (value >>> 8)
this[offset] = (value & 0xff)
} else {
objectWriteUInt32(this, value, offset, true)
}
return offset + 4
}
Buffer.prototype.writeUInt32BE = function writeUInt32BE (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 4, 0xffffffff, 0)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24)
this[offset + 1] = (value >>> 16)
this[offset + 2] = (value >>> 8)
this[offset + 3] = (value & 0xff)
} else {
objectWriteUInt32(this, value, offset, false)
}
return offset + 4
}
Buffer.prototype.writeIntLE = function writeIntLE (value, offset, byteLength, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) {
var limit = Math.pow(2, 8 * byteLength - 1)
checkInt(this, value, offset, byteLength, limit - 1, -limit)
}
var i = 0
var mul = 1
var sub = value < 0 ? 1 : 0
this[offset] = value & 0xFF
while (++i < byteLength && (mul *= 0x100)) {
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
}
return offset + byteLength
}
Buffer.prototype.writeIntBE = function writeIntBE (value, offset, byteLength, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) {
var limit = Math.pow(2, 8 * byteLength - 1)
checkInt(this, value, offset, byteLength, limit - 1, -limit)
}
var i = byteLength - 1
var mul = 1
var sub = value < 0 ? 1 : 0
this[offset + i] = value & 0xFF
while (--i >= 0 && (mul *= 0x100)) {
this[offset + i] = ((value / mul) >> 0) - sub & 0xFF
}
return offset + byteLength
}
Buffer.prototype.writeInt8 = function writeInt8 (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 1, 0x7f, -0x80)
if (!Buffer.TYPED_ARRAY_SUPPORT) value = Math.floor(value)
if (value < 0) value = 0xff + value + 1
this[offset] = (value & 0xff)
return offset + 1
}
Buffer.prototype.writeInt16LE = function writeInt16LE (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff)
this[offset + 1] = (value >>> 8)
} else {
objectWriteUInt16(this, value, offset, true)
}
return offset + 2
}
Buffer.prototype.writeInt16BE = function writeInt16BE (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 2, 0x7fff, -0x8000)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 8)
this[offset + 1] = (value & 0xff)
} else {
objectWriteUInt16(this, value, offset, false)
}
return offset + 2
}
Buffer.prototype.writeInt32LE = function writeInt32LE (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value & 0xff)
this[offset + 1] = (value >>> 8)
this[offset + 2] = (value >>> 16)
this[offset + 3] = (value >>> 24)
} else {
objectWriteUInt32(this, value, offset, true)
}
return offset + 4
}
Buffer.prototype.writeInt32BE = function writeInt32BE (value, offset, noAssert) {
value = +value
offset = offset | 0
if (!noAssert) checkInt(this, value, offset, 4, 0x7fffffff, -0x80000000)
if (value < 0) value = 0xffffffff + value + 1
if (Buffer.TYPED_ARRAY_SUPPORT) {
this[offset] = (value >>> 24)
this[offset + 1] = (value >>> 16)
this[offset + 2] = (value >>> 8)
this[offset + 3] = (value & 0xff)
} else {
objectWriteUInt32(this, value, offset, false)
}
return offset + 4
}
function checkIEEE754 (buf, value, offset, ext, max, min) {
if (value > max || value < min) throw new RangeError('value is out of bounds')
if (offset + ext > buf.length) throw new RangeError('index out of range')
if (offset < 0) throw new RangeError('index out of range')
}
function writeFloat (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
checkIEEE754(buf, value, offset, 4, 3.4028234663852886e+38, -3.4028234663852886e+38)
}
ieee754.write(buf, value, offset, littleEndian, 23, 4)
return offset + 4
}
Buffer.prototype.writeFloatLE = function writeFloatLE (value, offset, noAssert) {
return writeFloat(this, value, offset, true, noAssert)
}
Buffer.prototype.writeFloatBE = function writeFloatBE (value, offset, noAssert) {
return writeFloat(this, value, offset, false, noAssert)
}
function writeDouble (buf, value, offset, littleEndian, noAssert) {
if (!noAssert) {
checkIEEE754(buf, value, offset, 8, 1.7976931348623157E+308, -1.7976931348623157E+308)
}
ieee754.write(buf, value, offset, littleEndian, 52, 8)
return offset + 8
}
Buffer.prototype.writeDoubleLE = function writeDoubleLE (value, offset, noAssert) {
return writeDouble(this, value, offset, true, noAssert)
}
Buffer.prototype.writeDoubleBE = function writeDoubleBE (value, offset, noAssert) {
return writeDouble(this, value, offset, false, noAssert)
}
// copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length)
Buffer.prototype.copy = function copy (target, targetStart, start, end) {
if (!start) start = 0
if (!end && end !== 0) end = this.length
if (targetStart >= target.length) targetStart = target.length
if (!targetStart) targetStart = 0
if (end > 0 && end < start) end = start
// Copy 0 bytes; we're done
if (end === start) return 0
if (target.length === 0 || this.length === 0) return 0
// Fatal error conditions
if (targetStart < 0) {
throw new RangeError('targetStart out of bounds')
}
if (start < 0 || start >= this.length) throw new RangeError('sourceStart out of bounds')
if (end < 0) throw new RangeError('sourceEnd out of bounds')
// Are we oob?
if (end > this.length) end = this.length
if (target.length - targetStart < end - start) {
end = target.length - targetStart + start
}
var len = end - start
var i
if (this === target && start < targetStart && targetStart < end) {
// descending copy from end
for (i = len - 1; i >= 0; i--) {
target[i + targetStart] = this[i + start]
}
} else if (len < 1000 || !Buffer.TYPED_ARRAY_SUPPORT) {
// ascending copy from start
for (i = 0; i < len; i++) {
target[i + targetStart] = this[i + start]
}
} else {
target._set(this.subarray(start, start + len), targetStart)
}
return len
}
// fill(value, start=0, end=buffer.length)
Buffer.prototype.fill = function fill (value, start, end) {
if (!value) value = 0
if (!start) start = 0
if (!end) end = this.length
if (end < start) throw new RangeError('end < start')
// Fill 0 bytes; we're done
if (end === start) return
if (this.length === 0) return
if (start < 0 || start >= this.length) throw new RangeError('start out of bounds')
if (end < 0 || end > this.length) throw new RangeError('end out of bounds')
var i
if (typeof value === 'number') {
for (i = start; i < end; i++) {
this[i] = value
}
} else {
var bytes = utf8ToBytes(value.toString())
var len = bytes.length
for (i = start; i < end; i++) {
this[i] = bytes[i % len]
}
}
return this
}
/**
* Creates a new `ArrayBuffer` with the *copied* memory of the buffer instance.
* Added in Node 0.12. Only available in browsers that support ArrayBuffer.
*/
Buffer.prototype.toArrayBuffer = function toArrayBuffer () {
if (typeof Uint8Array !== 'undefined') {
if (Buffer.TYPED_ARRAY_SUPPORT) {
return (new Buffer(this)).buffer
} else {
var buf = new Uint8Array(this.length)
for (var i = 0, len = buf.length; i < len; i += 1) {
buf[i] = this[i]
}
return buf.buffer
}
} else {
throw new TypeError('Buffer.toArrayBuffer not supported in this browser')
}
}
// HELPER FUNCTIONS
// ================
var BP = Buffer.prototype
/**
* Augment a Uint8Array *instance* (not the Uint8Array class!) with Buffer methods
*/
Buffer._augment = function _augment (arr) {
arr.constructor = Buffer
arr._isBuffer = true
// save reference to original Uint8Array set method before overwriting
arr._set = arr.set
// deprecated
arr.get = BP.get
arr.set = BP.set
arr.write = BP.write
arr.toString = BP.toString
arr.toLocaleString = BP.toString
arr.toJSON = BP.toJSON
arr.equals = BP.equals
arr.compare = BP.compare
arr.indexOf = BP.indexOf
arr.copy = BP.copy
arr.slice = BP.slice
arr.readUIntLE = BP.readUIntLE
arr.readUIntBE = BP.readUIntBE
arr.readUInt8 = BP.readUInt8
arr.readUInt16LE = BP.readUInt16LE
arr.readUInt16BE = BP.readUInt16BE
arr.readUInt32LE = BP.readUInt32LE
arr.readUInt32BE = BP.readUInt32BE
arr.readIntLE = BP.readIntLE
arr.readIntBE = BP.readIntBE
arr.readInt8 = BP.readInt8
arr.readInt16LE = BP.readInt16LE
arr.readInt16BE = BP.readInt16BE
arr.readInt32LE = BP.readInt32LE
arr.readInt32BE = BP.readInt32BE
arr.readFloatLE = BP.readFloatLE
arr.readFloatBE = BP.readFloatBE
arr.readDoubleLE = BP.readDoubleLE
arr.readDoubleBE = BP.readDoubleBE
arr.writeUInt8 = BP.writeUInt8
arr.writeUIntLE = BP.writeUIntLE
arr.writeUIntBE = BP.writeUIntBE
arr.writeUInt16LE = BP.writeUInt16LE
arr.writeUInt16BE = BP.writeUInt16BE
arr.writeUInt32LE = BP.writeUInt32LE
arr.writeUInt32BE = BP.writeUInt32BE
arr.writeIntLE = BP.writeIntLE
arr.writeIntBE = BP.writeIntBE
arr.writeInt8 = BP.writeInt8
arr.writeInt16LE = BP.writeInt16LE
arr.writeInt16BE = BP.writeInt16BE
arr.writeInt32LE = BP.writeInt32LE
arr.writeInt32BE = BP.writeInt32BE
arr.writeFloatLE = BP.writeFloatLE
arr.writeFloatBE = BP.writeFloatBE
arr.writeDoubleLE = BP.writeDoubleLE
arr.writeDoubleBE = BP.writeDoubleBE
arr.fill = BP.fill
arr.inspect = BP.inspect
arr.toArrayBuffer = BP.toArrayBuffer
return arr
}
var INVALID_BASE64_RE = /[^+\/0-9A-Za-z-_]/g
function base64clean (str) {
// Node strips out invalid characters like \n and \t from the string, base64-js does not
str = stringtrim(str).replace(INVALID_BASE64_RE, '')
// Node converts strings with length < 2 to ''
if (str.length < 2) return ''
// Node allows for non-padded base64 strings (missing trailing ===), base64-js does not
while (str.length % 4 !== 0) {
str = str + '='
}
return str
}
function stringtrim (str) {
if (str.trim) return str.trim()
return str.replace(/^\s+|\s+$/g, '')
}
function toHex (n) {
if (n < 16) return '0' + n.toString(16)
return n.toString(16)
}
function utf8ToBytes (string, units) {
units = units || Infinity
var codePoint
var length = string.length
var leadSurrogate = null
var bytes = []
for (var i = 0; i < length; i++) {
codePoint = string.charCodeAt(i)
// is surrogate component
if (codePoint > 0xD7FF && codePoint < 0xE000) {
// last char was a lead
if (!leadSurrogate) {
// no lead yet
if (codePoint > 0xDBFF) {
// unexpected trail
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
continue
} else if (i + 1 === length) {
// unpaired lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
continue
}
// valid lead
leadSurrogate = codePoint
continue
}
// 2 leads in a row
if (codePoint < 0xDC00) {
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
leadSurrogate = codePoint
continue
}
// valid surrogate pair
codePoint = (leadSurrogate - 0xD800 << 10 | codePoint - 0xDC00) + 0x10000
} else if (leadSurrogate) {
// valid bmp char, but last char was a lead
if ((units -= 3) > -1) bytes.push(0xEF, 0xBF, 0xBD)
}
leadSurrogate = null
// encode utf8
if (codePoint < 0x80) {
if ((units -= 1) < 0) break
bytes.push(codePoint)
} else if (codePoint < 0x800) {
if ((units -= 2) < 0) break
bytes.push(
codePoint >> 0x6 | 0xC0,
codePoint & 0x3F | 0x80
)
} else if (codePoint < 0x10000) {
if ((units -= 3) < 0) break
bytes.push(
codePoint >> 0xC | 0xE0,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
)
} else if (codePoint < 0x110000) {
if ((units -= 4) < 0) break
bytes.push(
codePoint >> 0x12 | 0xF0,
codePoint >> 0xC & 0x3F | 0x80,
codePoint >> 0x6 & 0x3F | 0x80,
codePoint & 0x3F | 0x80
)
} else {
throw new Error('Invalid code point')
}
}
return bytes
}
function asciiToBytes (str) {
var byteArray = []
for (var i = 0; i < str.length; i++) {
// Node's code seems to be doing this and not & 0x7F..
byteArray.push(str.charCodeAt(i) & 0xFF)
}
return byteArray
}
function utf16leToBytes (str, units) {
var c, hi, lo
var byteArray = []
for (var i = 0; i < str.length; i++) {
if ((units -= 2) < 0) break
c = str.charCodeAt(i)
hi = c >> 8
lo = c % 256
byteArray.push(lo)
byteArray.push(hi)
}
return byteArray
}
function base64ToBytes (str) {
return base64.toByteArray(base64clean(str))
}
function blitBuffer (src, dst, offset, length) {
for (var i = 0; i < length; i++) {
if ((i + offset >= dst.length) || (i >= src.length)) break
dst[i + offset] = src[i]
}
return i
}
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"base64-js":2,"ieee754":121,"isarray":69}],69:[function(require,module,exports){
var toString = {}.toString;
module.exports = Array.isArray || function (arr) {
return toString.call(arr) == '[object Array]';
};
},{}],70:[function(require,module,exports){
/**
* Module dependencies.
*/
try {
var index = require('indexof');
} catch (err) {
var index = require('component-indexof');
}
/**
* 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);
};
},{"component-indexof":74,"indexof":74}],71:[function(require,module,exports){
var matches = require('matches-selector')
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
}
}
},{"matches-selector":75}],72:[function(require,module,exports){
/**
* Module dependencies.
*/
try {
var closest = require('closest');
} catch(err) {
var closest = require('component-closest');
}
try {
var event = require('event');
} catch(err) {
var event = require('component-event');
}
/**
* 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);
};
},{"closest":71,"component-closest":71,"component-event":73,"event":73}],73:[function(require,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;
};
},{}],74:[function(require,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;
};
},{}],75:[function(require,module,exports){
/**
* Module dependencies.
*/
try {
var query = require('query');
} catch (err) {
var query = require('component-query');
}
/**
* 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;
}
},{"component-query":76,"query":76}],76:[function(require,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;
};
},{}],77:[function(require,module,exports){
(function (Buffer){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// NOTE: These type checking functions intentionally don't use `instanceof`
// because it is fragile and can be easily faked with `Object.create()`.
function isArray(arg) {
if (Array.isArray) {
return Array.isArray(arg);
}
return objectToString(arg) === '[object Array]';
}
exports.isArray = isArray;
function isBoolean(arg) {
return typeof arg === 'boolean';
}
exports.isBoolean = isBoolean;
function isNull(arg) {
return arg === null;
}
exports.isNull = isNull;
function isNullOrUndefined(arg) {
return arg == null;
}
exports.isNullOrUndefined = isNullOrUndefined;
function isNumber(arg) {
return typeof arg === 'number';
}
exports.isNumber = isNumber;
function isString(arg) {
return typeof arg === 'string';
}
exports.isString = isString;
function isSymbol(arg) {
return typeof arg === 'symbol';
}
exports.isSymbol = isSymbol;
function isUndefined(arg) {
return arg === void 0;
}
exports.isUndefined = isUndefined;
function isRegExp(re) {
return objectToString(re) === '[object RegExp]';
}
exports.isRegExp = isRegExp;
function isObject(arg) {
return typeof arg === 'object' && arg !== null;
}
exports.isObject = isObject;
function isDate(d) {
return objectToString(d) === '[object Date]';
}
exports.isDate = isDate;
function isError(e) {
return (objectToString(e) === '[object Error]' || e instanceof Error);
}
exports.isError = isError;
function isFunction(arg) {
return typeof arg === 'function';
}
exports.isFunction = isFunction;
function isPrimitive(arg) {
return arg === null ||
typeof arg === 'boolean' ||
typeof arg === 'number' ||
typeof arg === 'string' ||
typeof arg === 'symbol' || // ES6 symbol
typeof arg === 'undefined';
}
exports.isPrimitive = isPrimitive;
exports.isBuffer = Buffer.isBuffer;
function objectToString(o) {
return Object.prototype.toString.call(o);
}
}).call(this,{"isBuffer":require("../../is-buffer/index.js")})
},{"../../is-buffer/index.js":123}],78:[function(require,module,exports){
module.exports = require('./lib/Diagram');
},{"./lib/Diagram":79}],79:[function(require,module,exports){
'use strict';
var di = require('didi');
/**
* Bootstrap an injector from a list of modules, instantiating a number of default components
*
* @ignore
* @param {Array} 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 = require('./core');
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 to the constructor.
*
* @class djs.Diagram
* @memberOf djs
* @constructor
*
* @example
*
* Creating a plug-in that logs whenever a shape is added to the canvas.
*
* // 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} [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 {Boolean} [strict=true] if false, resolve missing services to null
*/
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');
};
/**
* Clear the diagram, removing all contents.
*/
Diagram.prototype.clear = function() {
this.get('eventBus').fire('diagram.clear');
};
},{"./core":85,"didi":114}],80:[function(require,module,exports){
'use strict';
var isNumber = require('lodash/lang/isNumber'),
assign = require('lodash/object/assign'),
forEach = require('lodash/collection/forEach'),
every = require('lodash/collection/every'),
debounce = require('lodash/function/debounce');
var Collections = require('../util/Collections'),
Elements = require('../util/Elements');
var Snap = require('../../vendor/snapsvg');
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 around the svg element with the respective size
// this way we can always get the correct container size
// (this is impossible for
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';
var REQUIRED_MODEL_ATTRS = {
shape: [ 'x', 'y', 'width', 'height' ],
connection: [ 'waypoints' ]
};
/**
* 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) {
var eventBus = this._eventBus;
// Creates a element that is wrapped into a .
// 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)
//
//
//
// ...
//
//
// html container
var container = this._container = createContainer(config),
svg = this._svg = Snap.createSnapAt('100%', '100%', container),
viewport = this._viewport = createGroup(svg, 'viewport');
this._layers = {};
// debounce canvas.viewbox.changed events
// for smoother diagram interaction
if (config.deferUpdate !== false) {
this._viewboxChanged = debounce(this._viewboxChanged, 300);
}
eventBus.on('diagram.init', function() {
/**
* An event indicating that the canvas is ready to be drawn on.
*
* @memberOf Canvas
*
* @event canvas.init
*
* @type {Object}
* @property {Snap
} svg the created svg element
* @property {Snap} viewport the direct parent of diagram elements and shapes
*/
eventBus.fire('canvas.init', {
svg: svg,
viewport: viewport
});
// fire this in order for certain components to check
// if they need to be adjusted due the canvas size
this.resized();
}, this);
eventBus.on('diagram.destroy', 500, this._destroy, this);
eventBus.on('diagram.clear', 500, this._clear, this);
};
Canvas.prototype._destroy = function(emit) {
this._eventBus.fire('canvas.destroy', {
svg: this._svg,
viewport: this._viewport
});
var parent = this._container.parentNode;
if (parent) {
parent.removeChild(this._container);
}
delete this._svg;
delete this._container;
delete this._layers;
delete this._rootElement;
delete this._viewport;
};
Canvas.prototype._clear = function() {
var self = this;
var allElements = this._elementRegistry.getAll();
// remove all elements
allElements.forEach(function(element) {
var type = Elements.getType(element);
if (type === 'root') {
self.setRootElement(null, true);
} else {
self._removeElement(element, type);
}
});
// force recomputation of view box
delete this._cachedViewbox;
};
/**
* Returns the default layer on which
* all elements are drawn.
*
* @returns {Snap}
*/
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}
*/
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; // ...
*
* @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', children: [] });
}
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) {
if (element) {
this._ensureValid('root', element);
}
var currentRoot = this._rootElement,
elementRegistry = this._elementRegistry,
eventBus = this._eventBus;
if (currentRoot) {
if (!override) {
throw new Error('rootElement already set, need to specify override');
}
// simulate element remove event sequence
eventBus.fire('root.remove', { element: currentRoot });
eventBus.fire('root.removed', { element: currentRoot });
elementRegistry.remove(currentRoot);
}
if (element) {
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._ensureValid = function(type, 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');
}
var requiredAttrs = REQUIRED_MODEL_ATTRS[type];
var valid = every(requiredAttrs, function(attr) {
return typeof element[attr] !== 'undefined';
});
if (!valid) {
throw new Error(
'must supply { ' + requiredAttrs.join(', ') + ' } with ' + type);
}
};
Canvas.prototype._setParent = function(element, parent, parentIndex) {
Collections.add(parent.children, element, parentIndex);
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]
* @param {Number} [parentIndex]
*
* @return {Object|djs.model.Base} the added element
*/
Canvas.prototype._addElement = function(type, element, parent, parentIndex) {
parent = parent || this.getRootElement();
var eventBus = this._eventBus,
graphicsFactory = this._graphicsFactory;
this._ensureValid(type, element);
eventBus.fire(type + '.add', { element: element, parent: parent });
this._setParent(element, parent, parentIndex);
// 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]
* @param {Number} [parentIndex]
*
* @return {djs.model.Shape} the added shape
*/
Canvas.prototype.addShape = function(shape, parent, parentIndex) {
return this._addElement('shape', shape, parent, parentIndex);
};
/**
* Adds a connection to the canvas
*
* @param {Object|djs.model.Connection} connection to add to the diagram
* @param {djs.model.Base} [parent]
* @param {Number} [parentIndex]
*
* @return {djs.model.Connection} the added connection
*/
Canvas.prototype.addConnection = function(connection, parent, parentIndex) {
return this._addElement('connection', connection, parent, parentIndex);
};
/**
* 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');
};
/**
* 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);
};
/**
* Perform a viewbox update via a given change function.
*
* @param {Function} changeFn
*/
Canvas.prototype._changeViewbox = function(changeFn) {
// notify others of the upcoming viewbox change
this._eventBus.fire('canvas.viewbox.changing');
// perform actual change
changeFn.apply(this);
// reset the cached viewbox so that
// a new get operation on viewbox or zoom
// triggers a viewbox re-computation
this._cachedViewbox = null;
// notify others of the change; this step
// may or may not be debounced
this._viewboxChanged();
};
Canvas.prototype._viewboxChanged = function() {
this._eventBus.fire('canvas.viewbox.changed', { viewbox: this.viewbox() });
};
/**
* Gets or sets the view box of the canvas, i.e. the
* area that is currently displayed.
*
* The getter may return a cached viewbox (if it is currently
* changing). To force a recomputation, pass `false` as the first argument.
*
* @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
*
* var viewbox = canvas.viewbox(); // pass `false` to force recomputing the box.
*
* console.log(viewbox);
* // {
* // inner: Dimensions,
* // outer: Dimensions,
* // scale,
* // x, y,
* // width, height
* // }
*
* @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
*
* @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 {
this._changeViewbox(function() {
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);
});
}
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) {
this._changeViewbox(function() {
delta = assign({ dx: 0, dy: 0 }, delta || {});
matrix = this._svg.node.createSVGMatrix().translate(delta.dx, delta.dy).multiply(matrix);
setCTM(node, matrix);
});
}
return { x: matrix.e, y: matrix.f };
};
/**
* Gets or sets the current zoom of the canvas, optionally zooming
* to the specified position.
*
* The getter may return a cached zoom level. Call it with `false` as
* the first argument to force recomputation of the current level.
*
* @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) {
return this.viewbox(newScale).scale;
}
if (newScale === 'fit-viewport') {
return this._fitViewport(center);
}
var outer,
matrix;
this._changeViewbox(function() {
if (typeof center !== 'object') {
outer = this.viewbox().outer;
center = {
x: outer.width / 2,
y: outer.height / 2
};
}
matrix = this._setZoom(newScale, center);
});
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(false).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
};
};
/**
* Fires an event in order other modules can react to the
* canvas resizing
*/
Canvas.prototype.resized = function() {
// force recomputation of view box
delete this._cachedViewbox;
this._eventBus.fire('canvas.resized');
};
},{"../../vendor/snapsvg":112,"../util/Collections":103,"../util/Elements":104,"lodash/collection/every":129,"lodash/collection/forEach":132,"lodash/function/debounce":141,"lodash/lang/isNumber":243,"lodash/object/assign":249}],81:[function(require,module,exports){
'use strict';
var Model = require('../model');
/**
* 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);
};
},{"../model":102}],82:[function(require,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} gfx
* @param {Snap} [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, '');
if (container.secondaryGfx) {
container.secondaryGfx.attr(ELEMENT_ID, '');
}
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}
*/
ElementRegistry.prototype.filter = function(fn) {
var filtered = [];
this.forEach(function(element, gfx) {
if (fn(element, gfx)) {
filtered.push(element);
}
});
return filtered;
};
/**
* Return all rendered model elements.
*
* @return {Array}
*/
ElementRegistry.prototype.getAll = function() {
return this.filter(function(e) { return e; });
};
/**
* 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); //
*
* elementRegistry.getGraphics(rootElement, true); //
*
*
* @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');
}
};
},{}],83:[function(require,module,exports){
'use strict';
var isFunction = require('lodash/lang/isFunction'),
isArray = require('lodash/lang/isArray'),
isNumber = require('lodash/lang/isNumber'),
bind = require('lodash/function/bind'),
assign = require('lodash/object/assign');
var FN_REF = '__fn';
var DEFAULT_PRIORITY = 1000;
var slice = Array.prototype.slice;
/**
* 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!');
* });
*
*
* // listen for event and pass the context (`this`)
* eventBus.on('foobar', function(event) {
* this.foo();
* }, this);
* ```
*
*
* ## 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 on lowest priority to allow
// message passing until the bitter end
this.on('diagram.destroy', 1, this._destroy, this);
}
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} events
* @param {Number} [priority=1000] the priority in which this listener is called, larger is higher
* @param {Function} callback
* @param {Object} [that] Pass context (`this`) to the callback
*/
EventBus.prototype.on = function(events, priority, callback, that) {
events = isArray(events) ? events : [ events ];
if (isFunction(priority)) {
that = callback;
callback = priority;
priority = DEFAULT_PRIORITY;
}
if (!isNumber(priority)) {
throw new Error('priority must be a number');
}
var actualCallback = callback;
if (that) {
actualCallback = bind(callback, that);
// make sure we remember and are able to remove
// bound callbacks via {@link #off} using the original
// callback
actualCallback[FN_REF] = callback[FN_REF] || callback;
}
var self = this,
listener = { priority: priority, callback: actualCallback };
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
* @param {Object} [that] Pass context (`this`) to the callback
*/
EventBus.prototype.once = function(event, priority, callback, that) {
var self = this;
if (isFunction(priority)) {
that = callback;
callback = priority;
priority = DEFAULT_PRIORITY;
}
if (!isNumber(priority)) {
throw new Error('priority must be a number');
}
function wrappedCallback() {
self.off(event, wrappedCallback);
return callback.apply(that, arguments);
}
// make sure we remember and are able to remove
// bound callbacks via {@link #off} using the original
// callback
wrappedCallback[FN_REF] = callback;
this.on(event, priority, 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,
listenerCallback,
idx;
if (callback) {
// move through listeners from back to front
// and remove matching listeners
for (idx = listeners.length - 1; (listener = listeners[idx]); idx--) {
listenerCallback = listener.callback;
if (listenerCallback === callback || listenerCallback[FN_REF] === 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,
listeners,
returnValue,
args;
args = 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)
var originalType = event.type;
// update event type before delegation
if (type !== originalType) {
event.type = type;
}
try {
returnValue = this._invokeListeners(event, args, listeners);
} 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;
};
EventBus.prototype._destroy = function() {
this._listeners = {};
};
EventBus.prototype._invokeListeners = function(event, args, listeners) {
var idx,
listener,
returnValue;
for (idx = 0; (listener = listeners[idx]); idx++) {
// handle stopped propagation
if (event.cancelBubble) {
break;
}
returnValue = this._invokeListener(event, args, listener);
}
return returnValue;
};
EventBus.prototype._invokeListener = function(event, args, listener) {
var returnValue;
try {
// returning false prevents the default action
returnValue = invokeFunction(listener.callback, args);
// stop propagation on return value
if (returnValue !== undefined) {
event.returnValue = returnValue;
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;
}
}
return returnValue;
};
/*
* 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 || {});
};
/**
* Invoke function. Be fast...
*
* @param {Function} fn
* @param {Array} args
*
* @return {Any}
*/
function invokeFunction(fn, args) {
return fn.apply(null, args);
}
},{"lodash/function/bind":140,"lodash/lang/isArray":239,"lodash/lang/isFunction":241,"lodash/lang/isNumber":243,"lodash/object/assign":249}],84:[function(require,module,exports){
'use strict';
var forEach = require('lodash/collection/forEach'),
reduce = require('lodash/collection/reduce');
var GraphicsUtil = require('../util/GraphicsUtil'),
domClear = require('min-dom/lib/clear');
/**
* A factory that creates graphical elements
*
* @param {EventBus} eventBus
* @param {ElementRegistry} elementRegistry
*/
function GraphicsFactory(eventBus, elementRegistry) {
this._eventBus = eventBus;
this._elementRegistry = elementRegistry;
}
GraphicsFactory.$inject = [ 'eventBus' , '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 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:
*
*
*
*
*
*
*
*
*
*
*
*
*
* @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.drawShape = function(visual, element) {
var eventBus = this._eventBus;
return eventBus.fire('render.shape', { gfx: visual, element: element });
};
GraphicsFactory.prototype.getShapePath = function(element) {
var eventBus = this._eventBus;
return eventBus.fire('render.getShapePath', element);
};
GraphicsFactory.prototype.drawConnection = function(visual, element) {
var eventBus = this._eventBus;
return eventBus.fire('render.connection', { gfx: visual, element: element });
};
GraphicsFactory.prototype.getConnectionPath = function(waypoints) {
var eventBus = this._eventBus;
return eventBus.fire('render.getConnectionPath', waypoints);
};
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.drawShape(visual, element);
// update positioning
gfx.translate(element.x, element.y);
} else
if (type === 'connection') {
this.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();
};
},{"../util/GraphicsUtil":106,"lodash/collection/forEach":132,"lodash/collection/reduce":137,"min-dom/lib/clear":264}],85:[function(require,module,exports){
module.exports = {
__depends__: [ require('../draw') ],
__init__: [ 'canvas' ],
canvas: [ 'type', require('./Canvas') ],
elementRegistry: [ 'type', require('./ElementRegistry') ],
elementFactory: [ 'type', require('./ElementFactory') ],
eventBus: [ 'type', require('./EventBus') ],
graphicsFactory: [ 'type', require('./GraphicsFactory') ]
};
},{"../draw":89,"./Canvas":80,"./ElementFactory":81,"./ElementRegistry":82,"./EventBus":83,"./GraphicsFactory":84}],86:[function(require,module,exports){
'use strict';
var DEFAULT_RENDER_PRIORITY = 1000;
/**
* The base implementation of shape and connection renderers.
*
* @param {EventBus} eventBus
* @param {Number} [renderPriority=1000]
*/
function BaseRenderer(eventBus, renderPriority) {
var self = this;
renderPriority = renderPriority || DEFAULT_RENDER_PRIORITY;
eventBus.on([ 'render.shape', 'render.connection' ], renderPriority, function(evt, context) {
var type = evt.type,
element = context.element,
visuals = context.gfx;
if (self.canRender(element)) {
if (type === 'render.shape') {
return self.drawShape(visuals, element);
} else {
return self.drawConnection(visuals, element);
}
}
});
eventBus.on([ 'render.getShapePath', 'render.getConnectionPath'], renderPriority, function(evt, element) {
if (self.canRender(element)) {
if (evt.type === 'render.getShapePath') {
return self.getShapePath(element);
} else {
return self.getConnectionPath(element);
}
}
});
}
/**
* Should check whether *this* renderer can render
* the element/connection.
*
* @param {element} element
*
* @returns {Boolean}
*/
BaseRenderer.prototype.canRender = function() {};
/**
* Provides the shape's snap svg element to be drawn on the `canvas`.
*
* @param {djs.Graphics} visuals
* @param {Shape} shape
*
* @returns {Snap.svg} [returns a Snap.svg paper element ]
*/
BaseRenderer.prototype.drawShape = function() {};
/**
* Provides the shape's snap svg element to be drawn on the `canvas`.
*
* @param {djs.Graphics} visuals
* @param {Connection} connection
*
* @returns {Snap.svg} [returns a Snap.svg paper element ]
*/
BaseRenderer.prototype.drawConnection = function() {};
/**
* Gets the SVG path of a shape that represents it's visual bounds.
*
* @param {Shape} shape
*
* @return {string} svg path
*/
BaseRenderer.prototype.getShapePath = function() {};
/**
* Gets the SVG path of a connection that represents it's visual bounds.
*
* @param {Connection} connection
*
* @return {string} svg path
*/
BaseRenderer.prototype.getConnectionPath = function() {};
module.exports = BaseRenderer;
},{}],87:[function(require,module,exports){
'use strict';
var inherits = require('inherits');
var BaseRenderer = require('./BaseRenderer');
var renderUtil = require('../util/RenderUtil');
var componentsToPath = renderUtil.componentsToPath,
createLine = renderUtil.createLine;
// apply default renderer with lowest possible priority
// so that it only kicks in if noone else could render
var DEFAULT_RENDER_PRIORITY = 1;
/**
* The default renderer used for shapes and connections.
*
* @param {EventBus} eventBus
* @param {Styles} styles
*/
function DefaultRenderer(eventBus, styles) {
//
BaseRenderer.call(this, eventBus, DEFAULT_RENDER_PRIORITY);
this.CONNECTION_STYLE = styles.style([ 'no-fill' ], { strokeWidth: 5, stroke: 'fuchsia' });
this.SHAPE_STYLE = styles.style({ fill: 'white', stroke: 'fuchsia', strokeWidth: 2 });
}
inherits(DefaultRenderer, BaseRenderer);
DefaultRenderer.prototype.canRender = function() {
return true;
};
DefaultRenderer.prototype.drawShape = function drawShape(visuals, element) {
return visuals.rect(0, 0, element.width || 0, element.height || 0).attr(this.SHAPE_STYLE);
};
DefaultRenderer.prototype.drawConnection = function drawConnection(visuals, connection) {
return createLine(connection.waypoints, this.CONNECTION_STYLE).appendTo(visuals);
};
DefaultRenderer.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);
};
DefaultRenderer.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);
};
DefaultRenderer.$inject = [ 'eventBus', 'styles' ];
module.exports = DefaultRenderer;
},{"../util/RenderUtil":110,"./BaseRenderer":86,"inherits":122}],88:[function(require,module,exports){
'use strict';
var isArray = require('lodash/lang/isArray'),
assign = require('lodash/object/assign'),
reduce = require('lodash/collection/reduce');
/**
* A component that manages shape styles
*/
function Styles() {
var defaultTraits = {
'no-fill': {
fill: 'none'
},
'no-border': {
strokeOpacity: 0.0
},
'no-events': {
pointerEvents: 'none'
}
};
var self = this;
/**
* Builds a style definition from a className, a list of traits and an object of additional attributes.
*
* @param {String} className
* @param {Array} 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} 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;
};
this.computeStyle = function(custom, traits, defaultStyles) {
if (!isArray(traits)) {
defaultStyles = traits;
traits = [];
}
return self.style(traits || [], assign({}, defaultStyles, custom || {}));
};
}
module.exports = Styles;
},{"lodash/collection/reduce":137,"lodash/lang/isArray":239,"lodash/object/assign":249}],89:[function(require,module,exports){
module.exports = {
__init__: [ 'defaultRenderer' ],
defaultRenderer: [ 'type', require('./DefaultRenderer') ],
styles: [ 'type', require('./Styles') ]
};
},{"./DefaultRenderer":87,"./Styles":88}],90:[function(require,module,exports){
'use strict';
var forEach = require('lodash/collection/forEach'),
domDelegate = require('min-dom/lib/delegate');
var isPrimaryButton = require('../../util/Mouse').isPrimaryButton;
var Snap = require('../../../vendor/snapsvg');
var renderUtil = require('../../util/RenderUtil');
var createLine = renderUtil.createLine,
updateLine = renderUtil.updateLine;
/**
* 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
});
/**
* Fire an interaction event.
*
* @param {String} type local event name, e.g. element.click.
* @param {DOMEvent} event native event
* @param {djs.model.Base} [element] the diagram element to emit the event on;
* defaults to the event target
*/
function fire(type, event, element) {
// only react on left mouse button interactions
// for interaction events
if (!isPrimaryButton(event)) {
return;
}
var target, gfx, returnValue;
if (!element) {
target = event.delegateTarget || event.target;
if (target) {
gfx = new Snap(target);
element = elementRegistry.get(gfx);
}
} else {
gfx = elementRegistry.getGraphics(element);
}
if (!gfx || !element) {
return;
}
returnValue = eventBus.fire(type, { element: element, gfx: gfx, originalEvent: event });
if (returnValue === false) {
event.stopPropagation();
event.preventDefault();
}
}
// TODO(nikku): document this
var handlers = {};
function mouseHandler(type) {
var fn = handlers[type];
if (!fn) {
fn = handlers[type] = function(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'
};
///// manual event trigger
/**
* Trigger an interaction event (based on a native dom event)
* on the target shape or connection.
*
* @param {String} eventName the name of the triggered DOM event
* @param {MouseEvent} event
* @param {djs.model.Base} targetElement
*/
function triggerMouseEvent(eventName, event, targetElement) {
// i.e. element.mousedown...
var localEventName = bindings[eventName];
if (!localEventName) {
throw new Error('unmapped DOM event name <' + eventName + '>');
}
return fire(localEventName, event, targetElement);
}
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;
if (element.waypoints) {
hit = createLine(element.waypoints);
} else {
hit = Snap.create('rect', { x: 0, y: 0, width: element.width, height: element.height });
}
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.triggerMouseEvent = triggerMouseEvent;
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} 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} 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} 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} 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} 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} gfx
* @property {Event} originalEvent
*/
},{"../../../vendor/snapsvg":112,"../../util/Mouse":108,"../../util/RenderUtil":110,"lodash/collection/forEach":132,"min-dom/lib/delegate":266}],91:[function(require,module,exports){
module.exports = {
__init__: [ 'interactionEvents' ],
interactionEvents: [ 'type', require('./InteractionEvents') ]
};
},{"./InteractionEvents":90}],92:[function(require,module,exports){
'use strict';
var getBBox = require('../../util/Elements').getBBox;
/**
* @class
*
* A plugin that adds an outline to shapes and connections that may be activated and styled
* via CSS classes.
*
* @param {EventBus} eventBus
* @param {Styles} styles
* @param {ElementRegistry} elementRegistry
*/
function Outline(eventBus, styles, elementRegistry) {
this.offset = 6;
var OUTLINE_STYLE = styles.cls('djs-outline', [ 'no-fill' ]);
var self = this;
function createOutline(gfx, bounds) {
return gfx.rect(10, 10, 0, 0).attr(OUTLINE_STYLE);
}
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);
}
self.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);
}
self.updateConnectionOutline(outline, element);
});
}
/**
* Updates the outline of a shape respecting the dimension of the
* element and an outline offset.
*
* @param {SVGElement} outline
* @param {djs.model.Base} element
*/
Outline.prototype.updateShapeOutline = function(outline, element) {
outline.attr({
x: -this.offset,
y: -this.offset,
width: element.width + this.offset * 2,
height: element.height + this.offset * 2
});
};
/**
* Updates the outline of a connection respecting the bounding box of
* the connection and an outline offset.
*
* @param {SVGElement} outline
* @param {djs.model.Base} element
*/
Outline.prototype.updateConnectionOutline = function(outline, connection) {
var bbox = getBBox(connection);
outline.attr({
x: bbox.x - this.offset,
y: bbox.y - this.offset,
width: bbox.width + this.offset * 2,
height: bbox.height + this.offset * 2
});
};
Outline.$inject = ['eventBus', 'styles', 'elementRegistry'];
module.exports = Outline;
},{"../../util/Elements":104}],93:[function(require,module,exports){
'use strict';
module.exports = {
__init__: [ 'outline' ],
outline: [ 'type', require('./Outline') ]
};
},{"./Outline":92}],94:[function(require,module,exports){
'use strict';
var isArray = require('lodash/lang/isArray'),
isString = require('lodash/lang/isString'),
isObject = require('lodash/lang/isObject'),
assign = require('lodash/object/assign'),
forEach = require('lodash/collection/forEach'),
find = require('lodash/collection/find'),
filter = require('lodash/collection/filter');
var domify = require('min-dom/lib/domify'),
domClasses = require('min-dom/lib/classes'),
domAttr = require('min-dom/lib/attr'),
domRemove = require('min-dom/lib/remove');
var getBBox = require('../../util/Elements').getBBox;
// document wide unique overlay ids
var ids = new (require('../../util/IdGenerator'))('ov');
function createRoot(parent) {
var root = domify('
');
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: '0
'
* });
*
* // or add via shape id
*
* overlays.add('some-element-id', {
* position: {
* top: -5,
* left: -5
* }
* html: '0
'
* });
*
* // or add with optional type
*
* overlays.add(someShape, 'badge', {
* position: {
* top: -5,
* left: -5
* }
* html: '0
'
* });
*
*
* // remove an overlay
*
* var id = overlays.add(...);
* overlays.remove(id);
*
* @param {EventBus} eventBus
* @param {Canvas} canvas
* @param {ElementRegistry} elementRegistry
*/
function Overlays(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();
}
Overlays.$inject = [ '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} the overlay(s)
*/
Overlays.prototype.get = function(search) {
if (isString(search)) {
search = { id: search };
}
if (isString(search.element)) {
search.element = this._elementRegistry.get(search.element);
}
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);
domAttr(container.html, 'data-container-id', element.id);
};
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('
');
this._overlayRoot.appendChild(html);
var container = {
html: html,
element: element,
overlays: []
};
this._updateOverlayContainer(container);
this._overlayContainers.push(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;
this._overlayRoot.style['-webkit-transform'] = matrix;
};
Overlays.prototype._getOverlayContainer = function(element, raw) {
var container = find(this._overlayContainers, function(c) {
return c.element === element;
});
if (!container && !raw) {
return 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('');
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);
this._updateOverlayVisibilty(overlay, this._canvas.viewbox());
};
Overlays.prototype._updateOverlayVisibilty = function(overlay, viewbox) {
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._updateOverlaysVisibilty = function(viewbox) {
var self = this;
forEach(this._overlays, function(overlay) {
self._updateOverlayVisibilty(overlay, viewbox);
});
};
Overlays.prototype._init = function() {
var eventBus = this._eventBus;
var self = this;
// scroll/zoom integration
function updateViewbox(viewbox) {
self._updateRoot(viewbox);
self._updateOverlaysVisibilty(viewbox);
self.show();
}
eventBus.on('canvas.viewbox.changing', function(event) {
self.hide();
});
eventBus.on('canvas.viewbox.changed', function(event) {
updateViewbox(event.viewbox);
});
// remove integration
eventBus.on([ 'shape.remove', 'connection.remove' ], function(e) {
var element = e.element;
var overlays = self.get({ element: element });
forEach(overlays, function(o) {
self.remove(o.id);
});
var container = self._getOverlayContainer(element);
if (container) {
domRemove(container.html);
var i = self._overlayContainers.indexOf(container);
if (i !== -1) {
self._overlayContainers.splice(i, 1);
}
}
});
// 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);
}
});
};
},{"../../util/Elements":104,"../../util/IdGenerator":107,"lodash/collection/filter":130,"lodash/collection/find":131,"lodash/collection/forEach":132,"lodash/lang/isArray":239,"lodash/lang/isObject":244,"lodash/lang/isString":246,"lodash/object/assign":249,"min-dom/lib/attr":262,"min-dom/lib/classes":263,"min-dom/lib/domify":267,"min-dom/lib/remove":271}],95:[function(require,module,exports){
module.exports = {
__init__: [ 'overlays' ],
overlays: [ 'type', require('./Overlays') ]
};
},{"./Overlays":94}],96:[function(require,module,exports){
'use strict';
var isArray = require('lodash/lang/isArray'),
forEach = require('lodash/collection/forEach');
/**
* 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);
});
eventBus.on([ 'diagram.clear' ], function(e) {
self.select(null);
});
}
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 });
};
},{"lodash/collection/forEach":132,"lodash/lang/isArray":239}],97:[function(require,module,exports){
'use strict';
var hasPrimaryModifier = require('../../util/Mouse').hasPrimaryModifier;
function SelectionBehavior(eventBus, selection, canvas, elementRegistry) {
eventBus.on('create.end', 500, function(e) {
// select the created shape after a
// successful create operation
if (e.context.canExecute) {
selection.select(e.context.shape);
}
});
eventBus.on('connect.end', 500, function(e) {
// select the connect end target
// after a connect operation
if (e.context.canExecute && e.context.target) {
selection.select(e.context.target);
}
});
eventBus.on('shape.move.end', 500, function(e) {
var previousSelection = e.previousSelection || [];
var shape = elementRegistry.get(e.context.shape.id);
// make sure at least the main moved element is being
// selected after a move operation
if (shape && previousSelection.indexOf(shape) === -1) {
selection.select(shape);
}
});
// 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', 'elementRegistry' ];
module.exports = SelectionBehavior;
},{"../../util/Mouse":108}],98:[function(require,module,exports){
'use strict';
var forEach = require('lodash/collection/forEach');
var MARKER_HOVER = 'hover',
MARKER_SELECTED = 'selected';
/**
* A plugin that adds a visible selection UI to shapes and connections
* by appending the
hover
and
selected
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;
},{"lodash/collection/forEach":132}],99:[function(require,module,exports){
module.exports = {
__init__: [ 'selectionVisuals', 'selectionBehavior' ],
__depends__: [
require('../interaction-events'),
require('../outline')
],
selection: [ 'type', require('./Selection') ],
selectionVisuals: [ 'type', require('./SelectionVisuals') ],
selectionBehavior: [ 'type', require('./SelectionBehavior') ]
};
},{"../interaction-events":91,"../outline":93,"./Selection":96,"./SelectionBehavior":97,"./SelectionVisuals":98}],100:[function(require,module,exports){
module.exports = {
translate: [ 'value', require('./translate') ]
};
},{"./translate":101}],101:[function(require,module,exports){
'use strict';
/**
* A simple translation stub to be used for multi-language support
* in diagrams. Can be easily replaced with a more sophisticated
* solution.
*
* @example
*
* // use it inside any diagram component by injecting `translate`.
*
* function MyService(translate) {
* alert(translate('HELLO {you}', { you: 'You!' }));
* }
*
* @param {String} template to interpolate
* @param {Object} [replacements] a map with substitutes
*
* @return {String} the translated string
*/
module.exports = function translate(template, replacements) {
replacements = replacements || {};
return template.replace(/{([^}]+)}/g, function(_, key) {
return replacements[key] || '{' + key + '}';
});
};
},{}],102:[function(require,module,exports){
'use strict';
var assign = require('lodash/object/assign'),
inherits = require('inherits');
var Refs = require('object-refs');
var parentRefs = new Refs({ name: 'children', enumerable: true, collection: true }, { name: 'parent' }),
labelRefs = new Refs({ name: 'label', enumerable: true }, { name: 'labelTarget' }),
attacherRefs = new Refs({ name: 'attachers', collection: true }, { name: 'host' }),
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
*/
outgoingRefs.bind(this, 'outgoing');
/**
* The list of incoming connections
*
* @name Base#incoming
* @type Array
*/
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
*/
parentRefs.bind(this, 'children');
/**
* @name Shape#host
* @type Shape
*/
attacherRefs.bind(this, 'host');
/**
* @name Shape#attachers
* @type Shape
*/
attacherRefs.bind(this, 'attachers');
}
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;
},{"inherits":122,"lodash/object/assign":249,"object-refs":284}],103:[function(require,module,exports){
'use strict';
/**
* Failsafe remove an element from a collection
*
* @param {Array} [collection]
* @param {Object} [element]
*
* @return {Number} the previous index of the element
*/
module.exports.remove = function(collection, element) {
if (!collection || !element) {
return -1;
}
var idx = collection.indexOf(element);
if (idx !== -1) {
collection.splice(idx, 1);
}
return idx;
};
/**
* Fail save add an element to the given connection, ensuring
* it does not yet exist.
*
* @param {Array} collection
* @param {Object} element
* @param {Number} idx
*/
module.exports.add = function(collection, element, idx) {
if (!collection || !element) {
return;
}
if (typeof idx !== 'number') {
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 save get the index of an element in a collection.
*
* @param {Array} 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);
};
},{}],104:[function(require,module,exports){
'use strict';
var isArray = require('lodash/lang/isArray'),
isNumber = require('lodash/lang/isNumber'),
groupBy = require('lodash/collection/groupBy'),
forEach = require('lodash/collection/forEach');
/**
* Adds an element to a collection and returns true if the
* element was added.
*
* @param {Array} 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;
}
/**
* Iterate over each element in a collection, calling the iterator function `fn`
* with (element, index, recursionDepth).
*
* Recurse into all elements that are returned by `fn`.
*
* @param {Object|Array} elements
* @param {Function} fn iterator function called with (element, index, recursionDepth)
* @param {Number} [depth] maximum recursion depth
*/
function eachElement(elements, fn, depth) {
depth = depth || 0;
if (!isArray(elements)) {
elements = [ elements ];
}
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 {djs.model.Base|Array} 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} 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} elements to query
* @param {Boolean} allowDuplicates to allow duplicates in the result set
*
* @return {Array} the collected elements
*/
function selfAndDirectChildren(elements, allowDuplicates) {
return selfAndChildren(elements, !allowDuplicates, 1);
}
/**
* Return self + ALL children for a number of elements
*
* @param {Array} elements to query
* @param {Boolean} allowDuplicates to allow duplicates in the result set
*
* @return {Array} the collected elements
*/
function selfAndAllChildren(elements, allowDuplicates) {
return selfAndChildren(elements, !allowDuplicates, -1);
}
/**
* Gets the the closure for all selected elements,
* their connections and their attachment's connections
*
* @param {Array} 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} elements List of Elements to search through
* @param {Object} bbox the enclosing bbox.
*
* If bbox.(width|height) is not specified
* the method returns all elements with element.x/y > bbox.x/y
*
* If only bbox.x or bbox.y is specified, method return all elements with
* e.x > bbox.x or e.y > bbox.y.
*
*
*/
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.add = add;
module.exports.eachElement = eachElement;
module.exports.selfAndDirectChildren = selfAndDirectChildren;
module.exports.selfAndAllChildren = selfAndAllChildren;
module.exports.getBBox = getBBox;
module.exports.getEnclosedElements = getEnclosedElements;
module.exports.getClosure = getClosure;
function getElementType(element) {
if ('waypoints' in element) {
return 'connection';
}
if ('x' in element) {
return 'shape';
}
return 'root';
}
module.exports.getType = getElementType;
},{"lodash/collection/forEach":132,"lodash/collection/groupBy":133,"lodash/lang/isArray":239,"lodash/lang/isNumber":243}],105:[function(require,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;
},{}],106:[function(require,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} gfx
*
* @return {Snap}
*/
function getVisual(gfx) {
return gfx.select('.djs-visual');
}
/**
* Returns the children for a given diagram element.
*
* @param {Snap} gfx
* @return {Snap}
*/
function getChildren(gfx) {
return gfx.parent().children()[1];
}
/**
* Returns the visual bbox of an element
*
* @param {Snap} gfx
*
* @return {Bounds}
*/
function getBBox(gfx) {
return getVisual(gfx).select('*').getBBox();
}
module.exports.getVisual = getVisual;
module.exports.getChildren = getChildren;
module.exports.getBBox = getBBox;
},{}],107:[function(require,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);
};
},{}],108:[function(require,module,exports){
'use strict';
var getOriginalEvent = require('./Event').getOriginal;
var isMac = require('./Platform').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.metaKey;
} else {
return originalEvent.ctrlKey;
}
};
module.exports.hasSecondaryModifier = function(event) {
var originalEvent = getOriginalEvent(event) || event;
return isPrimaryButton(event) && originalEvent.shiftKey;
};
},{"./Event":105,"./Platform":109}],109:[function(require,module,exports){
'use strict';
module.exports.isMac = function isMac() {
return (/mac/i).test(navigator.platform);
};
},{}],110:[function(require,module,exports){
'use strict';
var Snap = require('../../vendor/snapsvg');
module.exports.componentsToPath = function(elements) {
return elements.join(',').replace(/,?([A-z]),?/g, '$1');
};
function toSVGPoints(points) {
var result = '';
for (var i = 0, p; (p = points[i]); i++) {
result += p.x + ',' + p.y + ' ';
}
return result;
}
module.exports.toSVGPoints = toSVGPoints;
module.exports.createLine = function(points, attrs) {
return Snap.create('polyline', { points: toSVGPoints(points) }).attr(attrs || {});
};
module.exports.updateLine = function(gfx, points) {
return gfx.attr({ points: toSVGPoints(points) });
};
},{"../../vendor/snapsvg":112}],111:[function(require,module,exports){
'use strict';
var isObject = require('lodash/lang/isObject'),
assign = require('lodash/object/assign'),
pick = require('lodash/object/pick'),
forEach = require('lodash/collection/forEach'),
reduce = require('lodash/collection/reduce'),
merge = require('lodash/object/merge');
var Snap = require('../../vendor/snapsvg');
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 pick(fakeText.getBBox(), [ 'width', 'height' ]);
}
/**
* Layout the next line and return the layouted element.
*
* Alters the lines passed.
*
* @param {Array} lines
* @return {Object} the line descriptor, an object { width, height, text }
*/
function layoutNext(lines, maxWidth, fakeText) {
var originalLine = lines.shift(),
fitLine = originalLine;
var textBBox;
for (;;) {
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;
},{"../../vendor/snapsvg":112,"lodash/collection/forEach":132,"lodash/collection/reduce":137,"lodash/lang/isObject":244,"lodash/object/assign":249,"lodash/object/merge":253,"lodash/object/pick":256}],112:[function(require,module,exports){
'use strict';
var snapsvg = module.exports = require('snapsvg');
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);
};
});
},{"snapsvg":300}],113:[function(require,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;
},{}],114:[function(require,module,exports){
module.exports = {
annotate: require('./annotation').annotate,
Module: require('./module'),
Injector: require('./injector')
};
},{"./annotation":113,"./injector":115,"./module":116}],115:[function(require,module,exports){
var Module = require('./module');
var autoAnnotate = require('./annotation').parse;
var annotate = require('./annotation').annotate;
var isArray = require('./annotation').isArray;
var Injector = function(modules, parent) {
parent = parent || {
get: function(name, strict) {
currentlyResolving.push(name);
if (strict === false) {
return null;
} else {
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);
};
/**
* Return a named service.
*
* @param {String} name
* @param {Boolean} [strict=true] if false, resolve missing services to null
*
* @return {Object}
*/
var get = function(name, strict) {
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, strict);
};
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) {
/*jshint -W083 */
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;
},{"./annotation":113,"./module":116}],116:[function(require,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;
},{}],117:[function(require,module,exports){
/**
* Expose `parse`.
*/
module.exports = parse;
/**
* Tests for browser support.
*/
var innerHTMLBug = false;
var bugTestDiv;
if (typeof document !== 'undefined') {
bugTestDiv = document.createElement('div');
// Setup
bugTestDiv.innerHTML = ' a ';
// Make sure that link elements get serialized correctly by innerHTML
// This requires a wrapper element in IE
innerHTMLBug = !bugTestDiv.getElementsByTagName('link').length;
bugTestDiv = undefined;
}
/**
* Wrap map from jquery.
*/
var map = {
legend: [1, '', ' '],
tr: [2, ''],
col: [2, ''],
// 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', '
'] : [0, '', '']
};
map.td =
map.th = [3, ''];
map.option =
map.optgroup = [1, '', ' '];
map.thead =
map.tbody =
map.colgroup =
map.caption =
map.tfoot = [1, ''];
map.polyline =
map.ellipse =
map.polygon =
map.circle =
map.text =
map.line =
map.path =
map.rect =
map.g = [1, '',' '];
/**
* Parse `html` and return a DOM Node instance, which could be a TextNode,
* HTML DOM Node of some kind ( 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;
}
},{}],118:[function(require,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);
},{}],119:[function(require,module,exports){
var hat = module.exports = function (bits, base) {
if (!base) base = 16;
if (bits === undefined) bits = 128;
if (bits <= 0) return '0';
var digits = Math.log(Math.pow(2, bits)) / Math.log(base);
for (var i = 2; digits === Infinity; i *= 2) {
digits = Math.log(Math.pow(2, bits / i)) / Math.log(base) * i;
}
var rem = digits - Math.floor(digits);
var res = '';
for (var i = 0; i < Math.floor(digits); i++) {
var x = Math.floor(Math.random() * base).toString(base);
res = x + res;
}
if (rem) {
var b = Math.pow(base, rem);
var x = Math.floor(Math.random() * b).toString(base);
res = x + res;
}
var parsed = parseInt(res, base);
if (parsed !== Infinity && parsed >= Math.pow(2, bits)) {
return hat(bits, base)
}
else return res;
};
hat.rack = function (bits, base, expandBy) {
var fn = function (data) {
var iters = 0;
do {
if (iters ++ > 10) {
if (expandBy) bits += expandBy;
else throw new Error('too many ID collisions, use more bits')
}
var id = hat(bits, base);
} while (Object.hasOwnProperty.call(hats, id));
hats[id] = data;
return id;
};
var hats = fn.hats = {};
fn.get = function (id) {
return fn.hats[id];
};
fn.set = function (id, value) {
fn.hats[id] = value;
return fn;
};
fn.bits = bits || 128;
fn.base = base || 16;
return fn;
};
},{}],120:[function(require,module,exports){
'use strict';
var hat = require('hat');
/**
* Create a new id generator / cache instance.
*
* You may optionally provide a seed that is used internally.
*
* @param {Seed} seed
*/
function Ids(seed) {
if (!(this instanceof Ids)) {
return new Ids(seed);
}
seed = seed || [ 128, 36, 1 ];
this._seed = seed.length ? hat.rack(seed[0], seed[1], seed[2]) : seed;
}
module.exports = Ids;
/**
* Generate a next id.
*
* @param {Object} [element] element to bind the id to
*
* @return {String} id
*/
Ids.prototype.next = function(element) {
return this._seed(element || true);
};
/**
* Generate a next id with a given prefix.
*
* @param {Object} [element] element to bind the id to
*
* @return {String} id
*/
Ids.prototype.nextPrefixed = function(prefix, element) {
var id;
do {
id = prefix + this.next(true);
} while (this.assigned(id));
// claim {prefix}{random}
this.claim(id, element);
// return
return id;
};
/**
* Manually claim an existing id.
*
* @param {String} id
* @param {String} [element] element the id is claimed by
*/
Ids.prototype.claim = function(id, element) {
this._seed.set(id, element || true);
};
/**
* Returns true if the given id has already been assigned.
*
* @param {String} id
* @return {Boolean}
*/
Ids.prototype.assigned = function(id) {
return this._seed.get(id) || false;
};
/**
* Unclaim an id.
*
* @param {String} id the id to unclaim
*/
Ids.prototype.unclaim = function(id) {
delete this._seed.hats[id];
};
/**
* Clear all claimed ids.
*/
Ids.prototype.clear = function() {
var hats = this._seed.hats,
id;
for (id in hats) {
this.unclaim(id);
}
};
},{"hat":119}],121:[function(require,module,exports){
exports.read = function (buffer, offset, isLE, mLen, nBytes) {
var e, m
var eLen = nBytes * 8 - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var nBits = -7
var i = isLE ? (nBytes - 1) : 0
var d = isLE ? -1 : 1
var s = buffer[offset + i]
i += d
e = s & ((1 << (-nBits)) - 1)
s >>= (-nBits)
nBits += eLen
for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {}
m = e & ((1 << (-nBits)) - 1)
e >>= (-nBits)
nBits += mLen
for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {}
if (e === 0) {
e = 1 - eBias
} else if (e === eMax) {
return m ? NaN : ((s ? -1 : 1) * Infinity)
} else {
m = m + Math.pow(2, mLen)
e = e - eBias
}
return (s ? -1 : 1) * m * Math.pow(2, e - mLen)
}
exports.write = function (buffer, value, offset, isLE, mLen, nBytes) {
var e, m, c
var eLen = nBytes * 8 - mLen - 1
var eMax = (1 << eLen) - 1
var eBias = eMax >> 1
var rt = (mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0)
var i = isLE ? 0 : (nBytes - 1)
var d = isLE ? 1 : -1
var s = value < 0 || (value === 0 && 1 / value < 0) ? 1 : 0
value = Math.abs(value)
if (isNaN(value) || value === Infinity) {
m = isNaN(value) ? 1 : 0
e = eMax
} else {
e = Math.floor(Math.log(value) / Math.LN2)
if (value * (c = Math.pow(2, -e)) < 1) {
e--
c *= 2
}
if (e + eBias >= 1) {
value += rt / c
} else {
value += rt * Math.pow(2, 1 - eBias)
}
if (value * c >= 2) {
e++
c /= 2
}
if (e + eBias >= eMax) {
m = 0
e = eMax
} else if (e + eBias >= 1) {
m = (value * c - 1) * Math.pow(2, mLen)
e = e + eBias
} else {
m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen)
e = 0
}
}
for (; mLen >= 8; buffer[offset + i] = m & 0xff, i += d, m /= 256, mLen -= 8) {}
e = (e << mLen) | m
eLen += mLen
for (; eLen > 0; buffer[offset + i] = e & 0xff, i += d, e /= 256, eLen -= 8) {}
buffer[offset + i - d] |= s * 128
}
},{}],122:[function(require,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
}
}
},{}],123:[function(require,module,exports){
/**
* Determine if an object is Buffer
*
* Author: Feross Aboukhadijeh
* License: MIT
*
* `npm install is-buffer`
*/
module.exports = function (obj) {
return !!(obj != null &&
(obj._isBuffer || // For Safari 5-7 (missing Object.prototype.constructor)
(obj.constructor &&
typeof obj.constructor.isBuffer === 'function' &&
obj.constructor.isBuffer(obj))
))
}
},{}],124:[function(require,module,exports){
module.exports = Array.isArray || function (arr) {
return Object.prototype.toString.call(arr) == '[object Array]';
};
},{}],125:[function(require,module,exports){
var baseFlatten = require('../internal/baseFlatten');
/**
* Recursively flattens a nested array.
*
* @static
* @memberOf _
* @category Array
* @param {Array} array The array to recursively flatten.
* @returns {Array} Returns the new flattened array.
* @example
*
* _.flattenDeep([1, [2, 3, [4]]]);
* // => [1, 2, 3, 4]
*/
function flattenDeep(array) {
var length = array ? array.length : 0;
return length ? baseFlatten(array, true) : [];
}
module.exports = flattenDeep;
},{"../internal/baseFlatten":167}],126:[function(require,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;
},{}],127:[function(require,module,exports){
var arrayPush = require('../internal/arrayPush'),
baseDifference = require('../internal/baseDifference'),
baseUniq = require('../internal/baseUniq'),
isArrayLike = require('../internal/isArrayLike');
/**
* Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
* of the provided arrays.
*
* @static
* @memberOf _
* @category Array
* @param {...Array} [arrays] The arrays to inspect.
* @returns {Array} Returns the new array of values.
* @example
*
* _.xor([1, 2], [4, 2]);
* // => [1, 4]
*/
function xor() {
var index = -1,
length = arguments.length;
while (++index < length) {
var array = arguments[index];
if (isArrayLike(array)) {
var result = result
? arrayPush(baseDifference(result, array), baseDifference(array, result))
: array;
}
}
return result ? baseUniq(result) : [];
}
module.exports = xor;
},{"../internal/arrayPush":152,"../internal/baseDifference":161,"../internal/baseUniq":189,"../internal/isArrayLike":218}],128:[function(require,module,exports){
var LazyWrapper = require('../internal/LazyWrapper'),
LodashWrapper = require('../internal/LodashWrapper'),
baseLodash = require('../internal/baseLodash'),
isArray = require('../lang/isArray'),
isObjectLike = require('../internal/isObjectLike'),
wrapperClone = require('../internal/wrapperClone');
/** Used for native method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/**
* Creates a `lodash` object which wraps `value` to enable implicit chaining.
* Methods that operate on and return arrays, collections, and functions can
* be chained together. Methods that retrieve a single value or may return a
* primitive value will automatically end the chain returning the unwrapped
* value. Explicit chaining may be enabled using `_.chain`. The execution of
* chained methods is lazy, that is, execution is deferred until `_#value`
* is implicitly or explicitly called.
*
* Lazy evaluation allows several methods to support shortcut fusion. Shortcut
* fusion is an optimization strategy which merge iteratee calls; this can help
* to avoid the creation of intermediate data structures and greatly reduce the
* number of iteratee executions.
*
* Chaining is supported in custom builds as long as the `_#value` method is
* directly or indirectly included in the build.
*
* In addition to lodash methods, wrappers have `Array` and `String` methods.
*
* The wrapper `Array` methods are:
* `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
* `splice`, and `unshift`
*
* The wrapper `String` methods are:
* `replace` and `split`
*
* The wrapper methods that support shortcut fusion are:
* `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
* `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
* `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
* and `where`
*
* The chainable wrapper methods are:
* `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
* `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
* `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
* `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
* `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
* `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
* `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
* `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
* `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
* `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
* `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
* `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
* `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
* `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
* `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
* `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
* `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
*
* The wrapper methods that are **not** chainable by default are:
* `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
* `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
* `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
* `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
* `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
* `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
* `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
* `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
* `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
* `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
* `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
* `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
* `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
* `unescape`, `uniqueId`, `value`, and `words`
*
* The wrapper method `sample` will return a wrapped value when `n` is provided,
* otherwise an unwrapped value is returned.
*
* @name _
* @constructor
* @category Chain
* @param {*} value The value to wrap in a `lodash` instance.
* @returns {Object} Returns the new `lodash` wrapper instance.
* @example
*
* var wrapped = _([1, 2, 3]);
*
* // returns an unwrapped value
* wrapped.reduce(function(total, n) {
* return total + n;
* });
* // => 6
*
* // returns a wrapped value
* var squares = wrapped.map(function(n) {
* return n * n;
* });
*
* _.isArray(squares);
* // => false
*
* _.isArray(squares.value());
* // => true
*/
function lodash(value) {
if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
if (value instanceof LodashWrapper) {
return value;
}
if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
return wrapperClone(value);
}
}
return new LodashWrapper(value);
}
// Ensure wrappers are instances of `baseLodash`.
lodash.prototype = baseLodash.prototype;
module.exports = lodash;
},{"../internal/LazyWrapper":144,"../internal/LodashWrapper":145,"../internal/baseLodash":176,"../internal/isObjectLike":224,"../internal/wrapperClone":237,"../lang/isArray":239}],129:[function(require,module,exports){
var arrayEvery = require('../internal/arrayEvery'),
baseCallback = require('../internal/baseCallback'),
baseEvery = require('../internal/baseEvery'),
isArray = require('../lang/isArray'),
isIterateeCall = require('../internal/isIterateeCall');
/**
* 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 = undefined;
}
if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = baseCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
module.exports = every;
},{"../internal/arrayEvery":149,"../internal/baseCallback":157,"../internal/baseEvery":163,"../internal/isIterateeCall":220,"../lang/isArray":239}],130:[function(require,module,exports){
var arrayFilter = require('../internal/arrayFilter'),
baseCallback = require('../internal/baseCallback'),
baseFilter = require('../internal/baseFilter'),
isArray = require('../lang/isArray');
/**
* 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;
},{"../internal/arrayFilter":150,"../internal/baseCallback":157,"../internal/baseFilter":164,"../lang/isArray":239}],131:[function(require,module,exports){
var baseEach = require('../internal/baseEach'),
createFind = require('../internal/createFind');
/**
* 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;
},{"../internal/baseEach":162,"../internal/createFind":203}],132:[function(require,module,exports){
var arrayEach = require('../internal/arrayEach'),
baseEach = require('../internal/baseEach'),
createForEach = require('../internal/createForEach');
/**
* 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;
},{"../internal/arrayEach":148,"../internal/baseEach":162,"../internal/createForEach":204}],133:[function(require,module,exports){
var createAggregator = require('../internal/createAggregator');
/** 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;
},{"../internal/createAggregator":196}],134:[function(require,module,exports){
var baseIndexOf = require('../internal/baseIndexOf'),
getLength = require('../internal/getLength'),
isArray = require('../lang/isArray'),
isIterateeCall = require('../internal/isIterateeCall'),
isLength = require('../internal/isLength'),
isString = require('../lang/isString'),
values = require('../object/values');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* Checks if `target` is in `collection` using
* [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
* for equality comparisons. If `fromIndex` is negative, it's 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 (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)
: (!!length && baseIndexOf(collection, target, fromIndex) > -1);
}
module.exports = includes;
},{"../internal/baseIndexOf":172,"../internal/getLength":214,"../internal/isIterateeCall":220,"../internal/isLength":223,"../lang/isArray":239,"../lang/isString":246,"../object/values":258}],135:[function(require,module,exports){
var createAggregator = require('../internal/createAggregator');
/**
* 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 the last element responsible for generating the key. The
* iteratee function 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
*
* var keyData = [
* { 'dir': 'left', 'code': 97 },
* { 'dir': 'right', 'code': 100 }
* ];
*
* _.indexBy(keyData, 'dir');
* // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
*
* _.indexBy(keyData, function(object) {
* return String.fromCharCode(object.code);
* });
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*
* _.indexBy(keyData, function(object) {
* return this.fromCharCode(object.code);
* }, String);
* // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
*/
var indexBy = createAggregator(function(result, value, key) {
result[key] = value;
});
module.exports = indexBy;
},{"../internal/createAggregator":196}],136:[function(require,module,exports){
var arrayMap = require('../internal/arrayMap'),
baseCallback = require('../internal/baseCallback'),
baseMap = require('../internal/baseMap'),
isArray = require('../lang/isArray');
/**
* 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 iteratees 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;
},{"../internal/arrayMap":151,"../internal/baseCallback":157,"../internal/baseMap":177,"../lang/isArray":239}],137:[function(require,module,exports){
var arrayReduce = require('../internal/arrayReduce'),
baseEach = require('../internal/baseEach'),
createReduce = require('../internal/createReduce');
/**
* 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 iteratees for methods like
* `_.reduce`, `_.reduceRight`, and `_.transform`.
*
* The guarded methods are:
* `assign`, `defaults`, `defaultsDeep`, `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;
},{"../internal/arrayReduce":153,"../internal/baseEach":162,"../internal/createReduce":207}],138:[function(require,module,exports){
var arraySome = require('../internal/arraySome'),
baseCallback = require('../internal/baseCallback'),
baseSome = require('../internal/baseSome'),
isArray = require('../lang/isArray'),
isIterateeCall = require('../internal/isIterateeCall');
/**
* 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 = undefined;
}
if (typeof predicate != 'function' || thisArg !== undefined) {
predicate = baseCallback(predicate, thisArg, 3);
}
return func(collection, predicate);
}
module.exports = some;
},{"../internal/arraySome":154,"../internal/baseCallback":157,"../internal/baseSome":187,"../internal/isIterateeCall":220,"../lang/isArray":239}],139:[function(require,module,exports){
var getNative = require('../internal/getNative');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeNow = getNative(Date, 'now');
/**
* 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;
},{"../internal/getNative":216}],140:[function(require,module,exports){
var createWrapper = require('../internal/createWrapper'),
replaceHolders = require('../internal/replaceHolders'),
restParam = require('./restParam');
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
PARTIAL_FLAG = 32;
/**
* Creates a function that invokes `func` with the `this` binding of `thisArg`
* and prepends any additional `_.bind` arguments to those provided to the
* bound function.
*
* The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
* may be used as a placeholder for partially applied arguments.
*
* **Note:** Unlike native `Function#bind` this method does not set the "length"
* property of bound functions.
*
* @static
* @memberOf _
* @category Function
* @param {Function} func The function to bind.
* @param {*} thisArg The `this` binding of `func`.
* @param {...*} [partials] The arguments to be partially applied.
* @returns {Function} Returns the new bound function.
* @example
*
* var greet = function(greeting, punctuation) {
* return greeting + ' ' + this.user + punctuation;
* };
*
* var object = { 'user': 'fred' };
*
* var bound = _.bind(greet, object, 'hi');
* bound('!');
* // => 'hi fred!'
*
* // using placeholders
* var bound = _.bind(greet, object, _, '!');
* bound('hi');
* // => 'hi fred!'
*/
var bind = restParam(function(func, thisArg, partials) {
var bitmask = BIND_FLAG;
if (partials.length) {
var holders = replaceHolders(partials, bind.placeholder);
bitmask |= PARTIAL_FLAG;
}
return createWrapper(func, bitmask, thisArg, partials, holders);
});
// Assign default placeholders.
bind.placeholder = {};
module.exports = bind;
},{"../internal/createWrapper":208,"../internal/replaceHolders":232,"./restParam":143}],141:[function(require,module,exports){
var isObject = require('../lang/isObject'),
now = require('../date/now');
/** 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 debounced function that delays invoking `func` until after `wait`
* milliseconds have elapsed since the last time the debounced function was
* invoked. The debounced 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's 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);
}
lastCalled = 0;
maxTimeoutId = timeoutId = trailingCall = undefined;
}
function complete(isCalled, id) {
if (id) {
clearTimeout(id);
}
maxTimeoutId = timeoutId = trailingCall = undefined;
if (isCalled) {
lastCalled = now();
result = func.apply(thisArg, args);
if (!timeoutId && !maxTimeoutId) {
args = thisArg = undefined;
}
}
}
function delayed() {
var remaining = wait - (now() - stamp);
if (remaining <= 0 || remaining > wait) {
complete(trailingCall, maxTimeoutId);
} else {
timeoutId = setTimeout(delayed, remaining);
}
}
function maxDelayed() {
complete(trailing, timeoutId);
}
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 = undefined;
}
return result;
}
debounced.cancel = cancel;
return debounced;
}
module.exports = debounce;
},{"../date/now":139,"../lang/isObject":244}],142:[function(require,module,exports){
var baseDelay = require('../internal/baseDelay'),
restParam = require('./restParam');
/**
* Defers invoking the `func` until the current call stack has cleared. Any
* additional arguments are provided to `func` when it's 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;
},{"../internal/baseDelay":160,"./restParam":143}],143:[function(require,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/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;
},{}],144:[function(require,module,exports){
var baseCreate = require('./baseCreate'),
baseLodash = require('./baseLodash');
/** Used as references for `-Infinity` and `Infinity`. */
var POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
/**
* Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
*
* @private
* @param {*} value The value to wrap.
*/
function LazyWrapper(value) {
this.__wrapped__ = value;
this.__actions__ = [];
this.__dir__ = 1;
this.__filtered__ = false;
this.__iteratees__ = [];
this.__takeCount__ = POSITIVE_INFINITY;
this.__views__ = [];
}
LazyWrapper.prototype = baseCreate(baseLodash.prototype);
LazyWrapper.prototype.constructor = LazyWrapper;
module.exports = LazyWrapper;
},{"./baseCreate":159,"./baseLodash":176}],145:[function(require,module,exports){
var baseCreate = require('./baseCreate'),
baseLodash = require('./baseLodash');
/**
* The base constructor for creating `lodash` wrapper objects.
*
* @private
* @param {*} value The value to wrap.
* @param {boolean} [chainAll] Enable chaining for all wrapper methods.
* @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
*/
function LodashWrapper(value, chainAll, actions) {
this.__wrapped__ = value;
this.__actions__ = actions || [];
this.__chain__ = !!chainAll;
}
LodashWrapper.prototype = baseCreate(baseLodash.prototype);
LodashWrapper.prototype.constructor = LodashWrapper;
module.exports = LodashWrapper;
},{"./baseCreate":159,"./baseLodash":176}],146:[function(require,module,exports){
(function (global){
var cachePush = require('./cachePush'),
getNative = require('./getNative');
/** Native method references. */
var Set = getNative(global, 'Set');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeCreate = getNative(Object, 'create');
/**
*
* 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 : {})
},{"./cachePush":193,"./getNative":216}],147:[function(require,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;
},{}],148:[function(require,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;
},{}],149:[function(require,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;
},{}],150:[function(require,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;
},{}],151:[function(require,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;
},{}],152:[function(require,module,exports){
/**
* Appends the elements of `values` to `array`.
*
* @private
* @param {Array} array The array to modify.
* @param {Array} values The values to append.
* @returns {Array} Returns `array`.
*/
function arrayPush(array, values) {
var index = -1,
length = values.length,
offset = array.length;
while (++index < length) {
array[offset + index] = values[index];
}
return array;
}
module.exports = arrayPush;
},{}],153:[function(require,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;
},{}],154:[function(require,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;
},{}],155:[function(require,module,exports){
var keys = require('../object/keys');
/**
* 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 index = -1,
props = keys(source),
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;
},{"../object/keys":251}],156:[function(require,module,exports){
var baseCopy = require('./baseCopy'),
keys = require('../object/keys');
/**
* 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`.
*/
function baseAssign(object, source) {
return source == null
? object
: baseCopy(source, keys(source), object);
}
module.exports = baseAssign;
},{"../object/keys":251,"./baseCopy":158}],157:[function(require,module,exports){
var baseMatches = require('./baseMatches'),
baseMatchesProperty = require('./baseMatchesProperty'),
bindCallback = require('./bindCallback'),
identity = require('../utility/identity'),
property = require('../utility/property');
/**
* 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;
},{"../utility/identity":259,"../utility/property":261,"./baseMatches":178,"./baseMatchesProperty":179,"./bindCallback":191}],158:[function(require,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;
},{}],159:[function(require,module,exports){
var isObject = require('../lang/isObject');
/**
* The base implementation of `_.create` without support for assigning
* properties to the created object.
*
* @private
* @param {Object} prototype The object to inherit from.
* @returns {Object} Returns the new object.
*/
var baseCreate = (function() {
function object() {}
return function(prototype) {
if (isObject(prototype)) {
object.prototype = prototype;
var result = new object;
object.prototype = undefined;
}
return result || {};
};
}());
module.exports = baseCreate;
},{"../lang/isObject":244}],160:[function(require,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;
},{}],161:[function(require,module,exports){
var baseIndexOf = require('./baseIndexOf'),
cacheIndexOf = require('./cacheIndexOf'),
createCache = require('./createCache');
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;
/**
* 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 >= LARGE_ARRAY_SIZE) ? 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;
},{"./baseIndexOf":172,"./cacheIndexOf":192,"./createCache":201}],162:[function(require,module,exports){
var baseForOwn = require('./baseForOwn'),
createBaseEach = require('./createBaseEach');
/**
* 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;
},{"./baseForOwn":170,"./createBaseEach":198}],163:[function(require,module,exports){
var baseEach = require('./baseEach');
/**
* 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;
},{"./baseEach":162}],164:[function(require,module,exports){
var baseEach = require('./baseEach');
/**
* 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;
},{"./baseEach":162}],165:[function(require,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;
},{}],166:[function(require,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;
},{}],167:[function(require,module,exports){
var arrayPush = require('./arrayPush'),
isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray'),
isArrayLike = require('./isArrayLike'),
isObjectLike = require('./isObjectLike');
/**
* 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.
* @param {Array} [result=[]] The initial result value.
* @returns {Array} Returns the new flattened array.
*/
function baseFlatten(array, isDeep, isStrict, result) {
result || (result = []);
var index = -1,
length = array.length;
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).
baseFlatten(value, isDeep, isStrict, result);
} else {
arrayPush(result, value);
}
} else if (!isStrict) {
result[result.length] = value;
}
}
return result;
}
module.exports = baseFlatten;
},{"../lang/isArguments":238,"../lang/isArray":239,"./arrayPush":152,"./isArrayLike":218,"./isObjectLike":224}],168:[function(require,module,exports){
var createBaseFor = require('./createBaseFor');
/**
* 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;
},{"./createBaseFor":199}],169:[function(require,module,exports){
var baseFor = require('./baseFor'),
keysIn = require('../object/keysIn');
/**
* 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;
},{"../object/keysIn":252,"./baseFor":168}],170:[function(require,module,exports){
var baseFor = require('./baseFor'),
keys = require('../object/keys');
/**
* 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;
},{"../object/keys":251,"./baseFor":168}],171:[function(require,module,exports){
var toObject = require('./toObject');
/**
* 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 = 0,
length = path.length;
while (object != null && index < length) {
object = object[path[index++]];
}
return (index && index == length) ? object : undefined;
}
module.exports = baseGet;
},{"./toObject":235}],172:[function(require,module,exports){
var indexOfNaN = require('./indexOfNaN');
/**
* 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;
},{"./indexOfNaN":217}],173:[function(require,module,exports){
var baseIsEqualDeep = require('./baseIsEqualDeep'),
isObject = require('../lang/isObject'),
isObjectLike = require('./isObjectLike');
/**
* 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) {
if (value === other) {
return true;
}
if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
return value !== value && other !== other;
}
return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
}
module.exports = baseIsEqual;
},{"../lang/isObject":244,"./baseIsEqualDeep":174,"./isObjectLike":224}],174:[function(require,module,exports){
var equalArrays = require('./equalArrays'),
equalByTag = require('./equalByTag'),
equalObjects = require('./equalObjects'),
isArray = require('../lang/isArray'),
isTypedArray = require('../lang/isTypedArray');
/** `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`](http://ecma-international.org/ecma-262/6.0/#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 objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
if (objIsWrapped || othIsWrapped) {
return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? 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;
},{"../lang/isArray":239,"../lang/isTypedArray":247,"./equalArrays":209,"./equalByTag":210,"./equalObjects":211}],175:[function(require,module,exports){
var baseIsEqual = require('./baseIsEqual'),
toObject = require('./toObject');
/**
* The base implementation of `_.isMatch` without support for callback
* shorthands and `this` binding.
*
* @private
* @param {Object} object The object to inspect.
* @param {Array} matchData The propery names, values, and compare flags to match.
* @param {Function} [customizer] The function to customize comparing objects.
* @returns {boolean} Returns `true` if `object` is a match, else `false`.
*/
function baseIsMatch(object, matchData, customizer) {
var index = matchData.length,
length = index,
noCustomizer = !customizer;
if (object == null) {
return !length;
}
object = toObject(object);
while (index--) {
var data = matchData[index];
if ((noCustomizer && data[2])
? data[1] !== object[data[0]]
: !(data[0] in object)
) {
return false;
}
}
while (++index < length) {
data = matchData[index];
var key = data[0],
objValue = object[key],
srcValue = data[1];
if (noCustomizer && data[2]) {
if (objValue === undefined && !(key in object)) {
return false;
}
} else {
var result = customizer ? customizer(objValue, srcValue, key) : undefined;
if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
return false;
}
}
}
return true;
}
module.exports = baseIsMatch;
},{"./baseIsEqual":173,"./toObject":235}],176:[function(require,module,exports){
/**
* The function whose prototype all chaining wrappers inherit from.
*
* @private
*/
function baseLodash() {
// No operation performed.
}
module.exports = baseLodash;
},{}],177:[function(require,module,exports){
var baseEach = require('./baseEach'),
isArrayLike = require('./isArrayLike');
/**
* 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;
},{"./baseEach":162,"./isArrayLike":218}],178:[function(require,module,exports){
var baseIsMatch = require('./baseIsMatch'),
getMatchData = require('./getMatchData'),
toObject = require('./toObject');
/**
* 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 matchData = getMatchData(source);
if (matchData.length == 1 && matchData[0][2]) {
var key = matchData[0][0],
value = matchData[0][1];
return function(object) {
if (object == null) {
return false;
}
return object[key] === value && (value !== undefined || (key in toObject(object)));
};
}
return function(object) {
return baseIsMatch(object, matchData);
};
}
module.exports = baseMatches;
},{"./baseIsMatch":175,"./getMatchData":215,"./toObject":235}],179:[function(require,module,exports){
var baseGet = require('./baseGet'),
baseIsEqual = require('./baseIsEqual'),
baseSlice = require('./baseSlice'),
isArray = require('../lang/isArray'),
isKey = require('./isKey'),
isStrictComparable = require('./isStrictComparable'),
last = require('../array/last'),
toObject = require('./toObject'),
toPath = require('./toPath');
/**
* The base implementation of `_.matchesProperty` which does not clone `srcValue`.
*
* @private
* @param {string} path The path of the property to get.
* @param {*} srcValue The value to compare.
* @returns {Function} Returns the new function.
*/
function baseMatchesProperty(path, srcValue) {
var isArr = isArray(path),
isCommon = isKey(path) && isStrictComparable(srcValue),
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] === srcValue
? (srcValue !== undefined || (key in object))
: baseIsEqual(srcValue, object[key], undefined, true);
};
}
module.exports = baseMatchesProperty;
},{"../array/last":126,"../lang/isArray":239,"./baseGet":171,"./baseIsEqual":173,"./baseSlice":186,"./isKey":221,"./isStrictComparable":225,"./toObject":235,"./toPath":236}],180:[function(require,module,exports){
var arrayEach = require('./arrayEach'),
baseMergeDeep = require('./baseMergeDeep'),
isArray = require('../lang/isArray'),
isArrayLike = require('./isArrayLike'),
isObject = require('../lang/isObject'),
isObjectLike = require('./isObjectLike'),
isTypedArray = require('../lang/isTypedArray'),
keys = require('../object/keys');
/**
* 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 merged values.
* @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)),
props = isSrcArr ? undefined : keys(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 ((result !== undefined || (isSrcArr && !(key in object))) &&
(isCommon || (result === result ? (result !== value) : (value === value)))) {
object[key] = result;
}
}
});
return object;
}
module.exports = baseMerge;
},{"../lang/isArray":239,"../lang/isObject":244,"../lang/isTypedArray":247,"../object/keys":251,"./arrayEach":148,"./baseMergeDeep":181,"./isArrayLike":218,"./isObjectLike":224}],181:[function(require,module,exports){
var arrayCopy = require('./arrayCopy'),
isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray'),
isArrayLike = require('./isArrayLike'),
isPlainObject = require('../lang/isPlainObject'),
isTypedArray = require('../lang/isTypedArray'),
toPlainObject = require('../lang/toPlainObject');
/**
* 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 merged values.
* @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;
},{"../lang/isArguments":238,"../lang/isArray":239,"../lang/isPlainObject":245,"../lang/isTypedArray":247,"../lang/toPlainObject":248,"./arrayCopy":147,"./isArrayLike":218}],182:[function(require,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;
},{}],183:[function(require,module,exports){
var baseGet = require('./baseGet'),
toPath = require('./toPath');
/**
* 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;
},{"./baseGet":171,"./toPath":236}],184:[function(require,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;
},{}],185:[function(require,module,exports){
var identity = require('../utility/identity'),
metaMap = require('./metaMap');
/**
* The base implementation of `setData` without support for hot loop detection.
*
* @private
* @param {Function} func The function to associate metadata with.
* @param {*} data The metadata.
* @returns {Function} Returns `func`.
*/
var baseSetData = !metaMap ? identity : function(func, data) {
metaMap.set(func, data);
return func;
};
module.exports = baseSetData;
},{"../utility/identity":259,"./metaMap":227}],186:[function(require,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;
},{}],187:[function(require,module,exports){
var baseEach = require('./baseEach');
/**
* 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;
},{"./baseEach":162}],188:[function(require,module,exports){
/**
* Converts `value` to a string if it's 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) {
return value == null ? '' : (value + '');
}
module.exports = baseToString;
},{}],189:[function(require,module,exports){
var baseIndexOf = require('./baseIndexOf'),
cacheIndexOf = require('./cacheIndexOf'),
createCache = require('./createCache');
/** Used as the size to enable large array optimizations. */
var LARGE_ARRAY_SIZE = 200;
/**
* The base implementation of `_.uniq` without support for callback shorthands
* and `this` binding.
*
* @private
* @param {Array} array The array to inspect.
* @param {Function} [iteratee] The function invoked per iteration.
* @returns {Array} Returns the new duplicate free array.
*/
function baseUniq(array, iteratee) {
var index = -1,
indexOf = baseIndexOf,
length = array.length,
isCommon = true,
isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
seen = isLarge ? createCache() : null,
result = [];
if (seen) {
indexOf = cacheIndexOf;
isCommon = false;
} else {
isLarge = false;
seen = iteratee ? [] : result;
}
outer:
while (++index < length) {
var value = array[index],
computed = iteratee ? iteratee(value, index, array) : value;
if (isCommon && value === value) {
var seenIndex = seen.length;
while (seenIndex--) {
if (seen[seenIndex] === computed) {
continue outer;
}
}
if (iteratee) {
seen.push(computed);
}
result.push(value);
}
else if (indexOf(seen, computed, 0) < 0) {
if (iteratee || isLarge) {
seen.push(computed);
}
result.push(value);
}
}
return result;
}
module.exports = baseUniq;
},{"./baseIndexOf":172,"./cacheIndexOf":192,"./createCache":201}],190:[function(require,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;
},{}],191:[function(require,module,exports){
var identity = require('../utility/identity');
/**
* 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;
},{"../utility/identity":259}],192:[function(require,module,exports){
var isObject = require('../lang/isObject');
/**
* 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;
},{"../lang/isObject":244}],193:[function(require,module,exports){
var isObject = require('../lang/isObject');
/**
* 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;
},{"../lang/isObject":244}],194:[function(require,module,exports){
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* Creates an array that is the composition of partially applied arguments,
* placeholders, and provided arguments into a single array of arguments.
*
* @private
* @param {Array|Object} args The provided arguments.
* @param {Array} partials The arguments to prepend to those provided.
* @param {Array} holders The `partials` placeholder indexes.
* @returns {Array} Returns the new array of composed arguments.
*/
function composeArgs(args, partials, holders) {
var holdersLength = holders.length,
argsIndex = -1,
argsLength = nativeMax(args.length - holdersLength, 0),
leftIndex = -1,
leftLength = partials.length,
result = Array(leftLength + argsLength);
while (++leftIndex < leftLength) {
result[leftIndex] = partials[leftIndex];
}
while (++argsIndex < holdersLength) {
result[holders[argsIndex]] = args[argsIndex];
}
while (argsLength--) {
result[leftIndex++] = args[argsIndex++];
}
return result;
}
module.exports = composeArgs;
},{}],195:[function(require,module,exports){
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* This function is like `composeArgs` except that the arguments composition
* is tailored for `_.partialRight`.
*
* @private
* @param {Array|Object} args The provided arguments.
* @param {Array} partials The arguments to append to those provided.
* @param {Array} holders The `partials` placeholder indexes.
* @returns {Array} Returns the new array of composed arguments.
*/
function composeArgsRight(args, partials, holders) {
var holdersIndex = -1,
holdersLength = holders.length,
argsIndex = -1,
argsLength = nativeMax(args.length - holdersLength, 0),
rightIndex = -1,
rightLength = partials.length,
result = Array(argsLength + rightLength);
while (++argsIndex < argsLength) {
result[argsIndex] = args[argsIndex];
}
var offset = argsIndex;
while (++rightIndex < rightLength) {
result[offset + rightIndex] = partials[rightIndex];
}
while (++holdersIndex < holdersLength) {
result[offset + holders[holdersIndex]] = args[argsIndex++];
}
return result;
}
module.exports = composeArgsRight;
},{}],196:[function(require,module,exports){
var baseCallback = require('./baseCallback'),
baseEach = require('./baseEach'),
isArray = require('../lang/isArray');
/**
* Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
*
* @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;
},{"../lang/isArray":239,"./baseCallback":157,"./baseEach":162}],197:[function(require,module,exports){
var bindCallback = require('./bindCallback'),
isIterateeCall = require('./isIterateeCall'),
restParam = require('../function/restParam');
/**
* Creates a `_.assign`, `_.defaults`, or `_.merge` function.
*
* @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] : undefined,
guard = length > 2 ? sources[2] : undefined,
thisArg = length > 1 ? sources[length - 1] : undefined;
if (typeof customizer == 'function') {
customizer = bindCallback(customizer, thisArg, 5);
length -= 2;
} else {
customizer = typeof thisArg == 'function' ? thisArg : undefined;
length -= (customizer ? 1 : 0);
}
if (guard && isIterateeCall(sources[0], sources[1], guard)) {
customizer = length < 3 ? undefined : customizer;
length = 1;
}
while (++index < length) {
var source = sources[index];
if (source) {
assigner(object, source, customizer);
}
}
return object;
});
}
module.exports = createAssigner;
},{"../function/restParam":143,"./bindCallback":191,"./isIterateeCall":220}],198:[function(require,module,exports){
var getLength = require('./getLength'),
isLength = require('./isLength'),
toObject = require('./toObject');
/**
* 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;
},{"./getLength":214,"./isLength":223,"./toObject":235}],199:[function(require,module,exports){
var toObject = require('./toObject');
/**
* 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;
},{"./toObject":235}],200:[function(require,module,exports){
(function (global){
var createCtorWrapper = require('./createCtorWrapper');
/**
* Creates a function that wraps `func` and invokes it with the `this`
* binding of `thisArg`.
*
* @private
* @param {Function} func The function to bind.
* @param {*} [thisArg] The `this` binding of `func`.
* @returns {Function} Returns the new bound function.
*/
function createBindWrapper(func, thisArg) {
var Ctor = createCtorWrapper(func);
function wrapper() {
var fn = (this && this !== global && this instanceof wrapper) ? Ctor : func;
return fn.apply(thisArg, arguments);
}
return wrapper;
}
module.exports = createBindWrapper;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./createCtorWrapper":202}],201:[function(require,module,exports){
(function (global){
var SetCache = require('./SetCache'),
getNative = require('./getNative');
/** Native method references. */
var Set = getNative(global, 'Set');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeCreate = getNative(Object, 'create');
/**
* 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`.
*/
function createCache(values) {
return (nativeCreate && Set) ? new SetCache(values) : null;
}
module.exports = createCache;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./SetCache":146,"./getNative":216}],202:[function(require,module,exports){
var baseCreate = require('./baseCreate'),
isObject = require('../lang/isObject');
/**
* Creates a function that produces an instance of `Ctor` regardless of
* whether it was invoked as part of a `new` expression or by `call` or `apply`.
*
* @private
* @param {Function} Ctor The constructor to wrap.
* @returns {Function} Returns the new wrapped function.
*/
function createCtorWrapper(Ctor) {
return function() {
// Use a `switch` statement to work with class constructors.
// See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
// for more details.
var args = arguments;
switch (args.length) {
case 0: return new Ctor;
case 1: return new Ctor(args[0]);
case 2: return new Ctor(args[0], args[1]);
case 3: return new Ctor(args[0], args[1], args[2]);
case 4: return new Ctor(args[0], args[1], args[2], args[3]);
case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
}
var thisBinding = baseCreate(Ctor.prototype),
result = Ctor.apply(thisBinding, args);
// Mimic the constructor's `return` behavior.
// See https://es5.github.io/#x13.2.2 for more details.
return isObject(result) ? result : thisBinding;
};
}
module.exports = createCtorWrapper;
},{"../lang/isObject":244,"./baseCreate":159}],203:[function(require,module,exports){
var baseCallback = require('./baseCallback'),
baseFind = require('./baseFind'),
baseFindIndex = require('./baseFindIndex'),
isArray = require('../lang/isArray');
/**
* 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;
},{"../lang/isArray":239,"./baseCallback":157,"./baseFind":165,"./baseFindIndex":166}],204:[function(require,module,exports){
var bindCallback = require('./bindCallback'),
isArray = require('../lang/isArray');
/**
* 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;
},{"../lang/isArray":239,"./bindCallback":191}],205:[function(require,module,exports){
(function (global){
var arrayCopy = require('./arrayCopy'),
composeArgs = require('./composeArgs'),
composeArgsRight = require('./composeArgsRight'),
createCtorWrapper = require('./createCtorWrapper'),
isLaziable = require('./isLaziable'),
reorder = require('./reorder'),
replaceHolders = require('./replaceHolders'),
setData = require('./setData');
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
BIND_KEY_FLAG = 2,
CURRY_BOUND_FLAG = 4,
CURRY_FLAG = 8,
CURRY_RIGHT_FLAG = 16,
PARTIAL_FLAG = 32,
PARTIAL_RIGHT_FLAG = 64,
ARY_FLAG = 128;
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMax = Math.max;
/**
* Creates a function that wraps `func` and invokes it with optional `this`
* binding of, partial application, and currying.
*
* @private
* @param {Function|string} func The function or method name to reference.
* @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
* @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to prepend to those provided to the new function.
* @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [partialsRight] The arguments to append to those provided to the new function.
* @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
var isAry = bitmask & ARY_FLAG,
isBind = bitmask & BIND_FLAG,
isBindKey = bitmask & BIND_KEY_FLAG,
isCurry = bitmask & CURRY_FLAG,
isCurryBound = bitmask & CURRY_BOUND_FLAG,
isCurryRight = bitmask & CURRY_RIGHT_FLAG,
Ctor = isBindKey ? undefined : createCtorWrapper(func);
function wrapper() {
// Avoid `arguments` object use disqualifying optimizations by
// converting it to an array before providing it to other functions.
var length = arguments.length,
index = length,
args = Array(length);
while (index--) {
args[index] = arguments[index];
}
if (partials) {
args = composeArgs(args, partials, holders);
}
if (partialsRight) {
args = composeArgsRight(args, partialsRight, holdersRight);
}
if (isCurry || isCurryRight) {
var placeholder = wrapper.placeholder,
argsHolders = replaceHolders(args, placeholder);
length -= argsHolders.length;
if (length < arity) {
var newArgPos = argPos ? arrayCopy(argPos) : undefined,
newArity = nativeMax(arity - length, 0),
newsHolders = isCurry ? argsHolders : undefined,
newHoldersRight = isCurry ? undefined : argsHolders,
newPartials = isCurry ? args : undefined,
newPartialsRight = isCurry ? undefined : args;
bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
if (!isCurryBound) {
bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
}
var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
result = createHybridWrapper.apply(undefined, newData);
if (isLaziable(func)) {
setData(result, newData);
}
result.placeholder = placeholder;
return result;
}
}
var thisBinding = isBind ? thisArg : this,
fn = isBindKey ? thisBinding[func] : func;
if (argPos) {
args = reorder(args, argPos);
}
if (isAry && ary < args.length) {
args.length = ary;
}
if (this && this !== global && this instanceof wrapper) {
fn = Ctor || createCtorWrapper(func);
}
return fn.apply(thisBinding, args);
}
return wrapper;
}
module.exports = createHybridWrapper;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./arrayCopy":147,"./composeArgs":194,"./composeArgsRight":195,"./createCtorWrapper":202,"./isLaziable":222,"./reorder":231,"./replaceHolders":232,"./setData":233}],206:[function(require,module,exports){
(function (global){
var createCtorWrapper = require('./createCtorWrapper');
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1;
/**
* Creates a function that wraps `func` and invokes it with the optional `this`
* binding of `thisArg` and the `partials` prepended to those provided to
* the wrapper.
*
* @private
* @param {Function} func The function to partially apply arguments to.
* @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
* @param {*} thisArg The `this` binding of `func`.
* @param {Array} partials The arguments to prepend to those provided to the new function.
* @returns {Function} Returns the new bound function.
*/
function createPartialWrapper(func, bitmask, thisArg, partials) {
var isBind = bitmask & BIND_FLAG,
Ctor = createCtorWrapper(func);
function wrapper() {
// Avoid `arguments` object use disqualifying optimizations by
// converting it to an array before providing it `func`.
var argsIndex = -1,
argsLength = arguments.length,
leftIndex = -1,
leftLength = partials.length,
args = Array(leftLength + argsLength);
while (++leftIndex < leftLength) {
args[leftIndex] = partials[leftIndex];
}
while (argsLength--) {
args[leftIndex++] = arguments[++argsIndex];
}
var fn = (this && this !== global && this instanceof wrapper) ? Ctor : func;
return fn.apply(isBind ? thisArg : this, args);
}
return wrapper;
}
module.exports = createPartialWrapper;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./createCtorWrapper":202}],207:[function(require,module,exports){
var baseCallback = require('./baseCallback'),
baseReduce = require('./baseReduce'),
isArray = require('../lang/isArray');
/**
* 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;
},{"../lang/isArray":239,"./baseCallback":157,"./baseReduce":184}],208:[function(require,module,exports){
var baseSetData = require('./baseSetData'),
createBindWrapper = require('./createBindWrapper'),
createHybridWrapper = require('./createHybridWrapper'),
createPartialWrapper = require('./createPartialWrapper'),
getData = require('./getData'),
mergeData = require('./mergeData'),
setData = require('./setData');
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
BIND_KEY_FLAG = 2,
PARTIAL_FLAG = 32,
PARTIAL_RIGHT_FLAG = 64;
/** 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 either curries or invokes `func` with optional
* `this` binding and partially applied arguments.
*
* @private
* @param {Function|string} func The function or method name to reference.
* @param {number} bitmask The bitmask of flags.
* The bitmask may be composed of the following flags:
* 1 - `_.bind`
* 2 - `_.bindKey`
* 4 - `_.curry` or `_.curryRight` of a bound function
* 8 - `_.curry`
* 16 - `_.curryRight`
* 32 - `_.partial`
* 64 - `_.partialRight`
* 128 - `_.rearg`
* 256 - `_.ary`
* @param {*} [thisArg] The `this` binding of `func`.
* @param {Array} [partials] The arguments to be partially applied.
* @param {Array} [holders] The `partials` placeholder indexes.
* @param {Array} [argPos] The argument positions of the new function.
* @param {number} [ary] The arity cap of `func`.
* @param {number} [arity] The arity of `func`.
* @returns {Function} Returns the new wrapped function.
*/
function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
var isBindKey = bitmask & BIND_KEY_FLAG;
if (!isBindKey && typeof func != 'function') {
throw new TypeError(FUNC_ERROR_TEXT);
}
var length = partials ? partials.length : 0;
if (!length) {
bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
partials = holders = undefined;
}
length -= (holders ? holders.length : 0);
if (bitmask & PARTIAL_RIGHT_FLAG) {
var partialsRight = partials,
holdersRight = holders;
partials = holders = undefined;
}
var data = isBindKey ? undefined : getData(func),
newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
if (data) {
mergeData(newData, data);
bitmask = newData[1];
arity = newData[9];
}
newData[9] = arity == null
? (isBindKey ? 0 : func.length)
: (nativeMax(arity - length, 0) || 0);
if (bitmask == BIND_FLAG) {
var result = createBindWrapper(newData[0], newData[2]);
} else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
result = createPartialWrapper.apply(undefined, newData);
} else {
result = createHybridWrapper.apply(undefined, newData);
}
var setter = data ? baseSetData : setData;
return setter(result, newData);
}
module.exports = createWrapper;
},{"./baseSetData":185,"./createBindWrapper":200,"./createHybridWrapper":205,"./createPartialWrapper":206,"./getData":212,"./mergeData":226,"./setData":233}],209:[function(require,module,exports){
var arraySome = require('./arraySome');
/**
* 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;
if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
return false;
}
// Ignore non-index properties.
while (++index < arrLength) {
var arrValue = array[index],
othValue = other[index],
result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
if (result !== undefined) {
if (result) {
continue;
}
return false;
}
// Recursively compare arrays (susceptible to call stack limits).
if (isLoose) {
if (!arraySome(other, function(othValue) {
return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
})) {
return false;
}
} else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
return false;
}
}
return true;
}
module.exports = equalArrays;
},{"./arraySome":154}],210:[function(require,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} object 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;
},{}],211:[function(require,module,exports){
var keys = require('../object/keys');
/** 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 index = objLength;
while (index--) {
var key = objProps[index];
if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
return false;
}
}
var skipCtor = isLoose;
while (++index < objLength) {
key = objProps[index];
var objValue = object[key],
othValue = other[key],
result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
// Recursively compare objects (susceptible to call stack limits).
if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : 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;
},{"../object/keys":251}],212:[function(require,module,exports){
var metaMap = require('./metaMap'),
noop = require('../utility/noop');
/**
* Gets metadata for `func`.
*
* @private
* @param {Function} func The function to query.
* @returns {*} Returns the metadata for `func`.
*/
var getData = !metaMap ? noop : function(func) {
return metaMap.get(func);
};
module.exports = getData;
},{"../utility/noop":260,"./metaMap":227}],213:[function(require,module,exports){
var realNames = require('./realNames');
/**
* Gets the name of `func`.
*
* @private
* @param {Function} func The function to query.
* @returns {string} Returns the function name.
*/
function getFuncName(func) {
var result = (func.name + ''),
array = realNames[result],
length = array ? array.length : 0;
while (length--) {
var data = array[length],
otherFunc = data.func;
if (otherFunc == null || otherFunc == func) {
return data.name;
}
}
return result;
}
module.exports = getFuncName;
},{"./realNames":230}],214:[function(require,module,exports){
var baseProperty = require('./baseProperty');
/**
* 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;
},{"./baseProperty":182}],215:[function(require,module,exports){
var isStrictComparable = require('./isStrictComparable'),
pairs = require('../object/pairs');
/**
* Gets the propery names, values, and compare flags of `object`.
*
* @private
* @param {Object} object The object to query.
* @returns {Array} Returns the match data of `object`.
*/
function getMatchData(object) {
var result = pairs(object),
length = result.length;
while (length--) {
result[length][2] = isStrictComparable(result[length][1]);
}
return result;
}
module.exports = getMatchData;
},{"../object/pairs":255,"./isStrictComparable":225}],216:[function(require,module,exports){
var isNative = require('../lang/isNative');
/**
* Gets the native function at `key` of `object`.
*
* @private
* @param {Object} object The object to query.
* @param {string} key The key of the method to get.
* @returns {*} Returns the function if it's native, else `undefined`.
*/
function getNative(object, key) {
var value = object == null ? undefined : object[key];
return isNative(value) ? value : undefined;
}
module.exports = getNative;
},{"../lang/isNative":242}],217:[function(require,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;
},{}],218:[function(require,module,exports){
var getLength = require('./getLength'),
isLength = require('./isLength');
/**
* 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;
},{"./getLength":214,"./isLength":223}],219:[function(require,module,exports){
/** Used to detect unsigned integer values. */
var reIsUint = /^\d+$/;
/**
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
* of an array-like value.
*/
var MAX_SAFE_INTEGER = 9007199254740991;
/**
* 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 = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
length = length == null ? MAX_SAFE_INTEGER : length;
return value > -1 && value % 1 == 0 && value < length;
}
module.exports = isIndex;
},{}],220:[function(require,module,exports){
var isArrayLike = require('./isArrayLike'),
isIndex = require('./isIndex'),
isObject = require('../lang/isObject');
/**
* 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;
},{"../lang/isObject":244,"./isArrayLike":218,"./isIndex":219}],221:[function(require,module,exports){
var isArray = require('../lang/isArray'),
toObject = require('./toObject');
/** 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;
},{"../lang/isArray":239,"./toObject":235}],222:[function(require,module,exports){
var LazyWrapper = require('./LazyWrapper'),
getData = require('./getData'),
getFuncName = require('./getFuncName'),
lodash = require('../chain/lodash');
/**
* Checks if `func` has a lazy counterpart.
*
* @private
* @param {Function} func The function to check.
* @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
*/
function isLaziable(func) {
var funcName = getFuncName(func),
other = lodash[funcName];
if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
return false;
}
if (func === other) {
return true;
}
var data = getData(other);
return !!data && func === data[0];
}
module.exports = isLaziable;
},{"../chain/lodash":128,"./LazyWrapper":144,"./getData":212,"./getFuncName":213}],223:[function(require,module,exports){
/**
* Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
* of an array-like value.
*/
var MAX_SAFE_INTEGER = 9007199254740991;
/**
* Checks if `value` is a valid array-like length.
*
* **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#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;
},{}],224:[function(require,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;
},{}],225:[function(require,module,exports){
var isObject = require('../lang/isObject');
/**
* 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;
},{"../lang/isObject":244}],226:[function(require,module,exports){
var arrayCopy = require('./arrayCopy'),
composeArgs = require('./composeArgs'),
composeArgsRight = require('./composeArgsRight'),
replaceHolders = require('./replaceHolders');
/** Used to compose bitmasks for wrapper metadata. */
var BIND_FLAG = 1,
CURRY_BOUND_FLAG = 4,
CURRY_FLAG = 8,
ARY_FLAG = 128,
REARG_FLAG = 256;
/** Used as the internal argument placeholder. */
var PLACEHOLDER = '__lodash_placeholder__';
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMin = Math.min;
/**
* Merges the function metadata of `source` into `data`.
*
* Merging metadata reduces the number of wrappers required to invoke a function.
* This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
* may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
* augment function arguments, making the order in which they are executed important,
* preventing the merging of metadata. However, we make an exception for a safe
* common case where curried functions have `_.ary` and or `_.rearg` applied.
*
* @private
* @param {Array} data The destination metadata.
* @param {Array} source The source metadata.
* @returns {Array} Returns `data`.
*/
function mergeData(data, source) {
var bitmask = data[1],
srcBitmask = source[1],
newBitmask = bitmask | srcBitmask,
isCommon = newBitmask < ARY_FLAG;
var isCombo =
(srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
(srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
(srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
// Exit early if metadata can't be merged.
if (!(isCommon || isCombo)) {
return data;
}
// Use source `thisArg` if available.
if (srcBitmask & BIND_FLAG) {
data[2] = source[2];
// Set when currying a bound function.
newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
}
// Compose partial arguments.
var value = source[3];
if (value) {
var partials = data[3];
data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
}
// Compose partial right arguments.
value = source[5];
if (value) {
partials = data[5];
data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
}
// Use source `argPos` if available.
value = source[7];
if (value) {
data[7] = arrayCopy(value);
}
// Use source `ary` if it's smaller.
if (srcBitmask & ARY_FLAG) {
data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
}
// Use source `arity` if one is not provided.
if (data[9] == null) {
data[9] = source[9];
}
// Use source `func` and merge bitmasks.
data[0] = source[0];
data[1] = newBitmask;
return data;
}
module.exports = mergeData;
},{"./arrayCopy":147,"./composeArgs":194,"./composeArgsRight":195,"./replaceHolders":232}],227:[function(require,module,exports){
(function (global){
var getNative = require('./getNative');
/** Native method references. */
var WeakMap = getNative(global, 'WeakMap');
/** Used to store function metadata. */
var metaMap = WeakMap && new WeakMap;
module.exports = metaMap;
}).call(this,typeof global !== "undefined" ? global : typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : {})
},{"./getNative":216}],228:[function(require,module,exports){
var toObject = require('./toObject');
/**
* 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;
},{"./toObject":235}],229:[function(require,module,exports){
var baseForIn = require('./baseForIn');
/**
* 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;
},{"./baseForIn":169}],230:[function(require,module,exports){
/** Used to lookup unminified function names. */
var realNames = {};
module.exports = realNames;
},{}],231:[function(require,module,exports){
var arrayCopy = require('./arrayCopy'),
isIndex = require('./isIndex');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeMin = Math.min;
/**
* Reorder `array` according to the specified indexes where the element at
* the first index is assigned as the first element, the element at
* the second index is assigned as the second element, and so on.
*
* @private
* @param {Array} array The array to reorder.
* @param {Array} indexes The arranged array indexes.
* @returns {Array} Returns `array`.
*/
function reorder(array, indexes) {
var arrLength = array.length,
length = nativeMin(indexes.length, arrLength),
oldArray = arrayCopy(array);
while (length--) {
var index = indexes[length];
array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
}
return array;
}
module.exports = reorder;
},{"./arrayCopy":147,"./isIndex":219}],232:[function(require,module,exports){
/** Used as the internal argument placeholder. */
var PLACEHOLDER = '__lodash_placeholder__';
/**
* Replaces all `placeholder` elements in `array` with an internal placeholder
* and returns an array of their indexes.
*
* @private
* @param {Array} array The array to modify.
* @param {*} placeholder The placeholder to replace.
* @returns {Array} Returns the new array of placeholder indexes.
*/
function replaceHolders(array, placeholder) {
var index = -1,
length = array.length,
resIndex = -1,
result = [];
while (++index < length) {
if (array[index] === placeholder) {
array[index] = PLACEHOLDER;
result[++resIndex] = index;
}
}
return result;
}
module.exports = replaceHolders;
},{}],233:[function(require,module,exports){
var baseSetData = require('./baseSetData'),
now = require('../date/now');
/** Used to detect when a function becomes hot. */
var HOT_COUNT = 150,
HOT_SPAN = 16;
/**
* Sets metadata for `func`.
*
* **Note:** If this function becomes hot, i.e. is invoked a lot in a short
* period of time, it will trip its breaker and transition to an identity function
* to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
* for more details.
*
* @private
* @param {Function} func The function to associate metadata with.
* @param {*} data The metadata.
* @returns {Function} Returns `func`.
*/
var setData = (function() {
var count = 0,
lastCalled = 0;
return function(key, value) {
var stamp = now(),
remaining = HOT_SPAN - (stamp - lastCalled);
lastCalled = stamp;
if (remaining > 0) {
if (++count >= HOT_COUNT) {
return key;
}
} else {
count = 0;
}
return baseSetData(key, value);
};
}());
module.exports = setData;
},{"../date/now":139,"./baseSetData":185}],234:[function(require,module,exports){
var isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray'),
isIndex = require('./isIndex'),
isLength = require('./isLength'),
keysIn = require('../object/keysIn');
/** 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) || 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;
},{"../lang/isArguments":238,"../lang/isArray":239,"../object/keysIn":252,"./isIndex":219,"./isLength":223}],235:[function(require,module,exports){
var isObject = require('../lang/isObject');
/**
* Converts `value` to an object if it's 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;
},{"../lang/isObject":244}],236:[function(require,module,exports){
var baseToString = require('./baseToString'),
isArray = require('../lang/isArray');
/** 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's 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;
},{"../lang/isArray":239,"./baseToString":188}],237:[function(require,module,exports){
var LazyWrapper = require('./LazyWrapper'),
LodashWrapper = require('./LodashWrapper'),
arrayCopy = require('./arrayCopy');
/**
* Creates a clone of `wrapper`.
*
* @private
* @param {Object} wrapper The wrapper to clone.
* @returns {Object} Returns the cloned wrapper.
*/
function wrapperClone(wrapper) {
return wrapper instanceof LazyWrapper
? wrapper.clone()
: new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
}
module.exports = wrapperClone;
},{"./LazyWrapper":144,"./LodashWrapper":145,"./arrayCopy":147}],238:[function(require,module,exports){
var isArrayLike = require('../internal/isArrayLike'),
isObjectLike = require('../internal/isObjectLike');
/** Used for native method references. */
var objectProto = Object.prototype;
/** Used to check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Native method references. */
var propertyIsEnumerable = objectProto.propertyIsEnumerable;
/**
* 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) &&
hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
}
module.exports = isArguments;
},{"../internal/isArrayLike":218,"../internal/isObjectLike":224}],239:[function(require,module,exports){
var getNative = require('../internal/getNative'),
isLength = require('../internal/isLength'),
isObjectLike = require('../internal/isObjectLike');
/** `Object#toString` result references. */
var arrayTag = '[object Array]';
/** Used for native method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#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 = getNative(Array, 'isArray');
/**
* 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;
},{"../internal/getNative":216,"../internal/isLength":223,"../internal/isObjectLike":224}],240:[function(require,module,exports){
var isArguments = require('./isArguments'),
isArray = require('./isArray'),
isArrayLike = require('../internal/isArrayLike'),
isFunction = require('./isFunction'),
isObjectLike = require('../internal/isObjectLike'),
isString = require('./isString'),
keys = require('../object/keys');
/**
* Checks if `value` is empty. A value is considered empty unless it's an
* `arguments` object, array, string, or jQuery-like collection with a length
* greater than `0` or an object with own enumerable properties.
*
* @static
* @memberOf _
* @category Lang
* @param {Array|Object|string} value The value to inspect.
* @returns {boolean} Returns `true` if `value` is empty, else `false`.
* @example
*
* _.isEmpty(null);
* // => true
*
* _.isEmpty(true);
* // => true
*
* _.isEmpty(1);
* // => true
*
* _.isEmpty([1, 2, 3]);
* // => false
*
* _.isEmpty({ 'a': 1 });
* // => false
*/
function isEmpty(value) {
if (value == null) {
return true;
}
if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
(isObjectLike(value) && isFunction(value.splice)))) {
return !value.length;
}
return !keys(value).length;
}
module.exports = isEmpty;
},{"../internal/isArrayLike":218,"../internal/isObjectLike":224,"../object/keys":251,"./isArguments":238,"./isArray":239,"./isFunction":241,"./isString":246}],241:[function(require,module,exports){
var isObject = require('./isObject');
/** `Object#toString` result references. */
var funcTag = '[object Function]';
/** Used for native method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objToString = objectProto.toString;
/**
* 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
*/
function isFunction(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 which returns 'object' for typed array constructors.
return isObject(value) && objToString.call(value) == funcTag;
}
module.exports = isFunction;
},{"./isObject":244}],242:[function(require,module,exports){
var isFunction = require('./isFunction'),
isObjectLike = require('../internal/isObjectLike');
/** 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 check objects for own properties. */
var hasOwnProperty = objectProto.hasOwnProperty;
/** Used to detect if a method is native. */
var reIsNative = RegExp('^' +
fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
.replace(/hasOwnProperty|(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 (isFunction(value)) {
return reIsNative.test(fnToString.call(value));
}
return isObjectLike(value) && reIsHostCtor.test(value);
}
module.exports = isNative;
},{"../internal/isObjectLike":224,"./isFunction":241}],243:[function(require,module,exports){
var isObjectLike = require('../internal/isObjectLike');
/** `Object#toString` result references. */
var numberTag = '[object Number]';
/** Used for native method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#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;
},{"../internal/isObjectLike":224}],244:[function(require,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 !!value && (type == 'object' || type == 'function');
}
module.exports = isObject;
},{}],245:[function(require,module,exports){
var baseForIn = require('../internal/baseForIn'),
isArguments = require('./isArguments'),
isObjectLike = require('../internal/isObjectLike');
/** `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`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
* of values.
*/
var objToString = objectProto.toString;
/**
* 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
*/
function isPlainObject(value) {
var Ctor;
// Exit early for non `Object` objects.
if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isArguments(value)) ||
(!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 = isPlainObject;
},{"../internal/baseForIn":169,"../internal/isObjectLike":224,"./isArguments":238}],246:[function(require,module,exports){
var isObjectLike = require('../internal/isObjectLike');
/** `Object#toString` result references. */
var stringTag = '[object String]';
/** Used for native method references. */
var objectProto = Object.prototype;
/**
* Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#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;
},{"../internal/isObjectLike":224}],247:[function(require,module,exports){
var isLength = require('../internal/isLength'),
isObjectLike = require('../internal/isObjectLike');
/** `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`](http://ecma-international.org/ecma-262/6.0/#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;
},{"../internal/isLength":223,"../internal/isObjectLike":224}],248:[function(require,module,exports){
var baseCopy = require('../internal/baseCopy'),
keysIn = require('../object/keysIn');
/**
* 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;
},{"../internal/baseCopy":158,"../object/keysIn":252}],249:[function(require,module,exports){
var assignWith = require('../internal/assignWith'),
baseAssign = require('../internal/baseAssign'),
createAssigner = require('../internal/createAssigner');
/**
* 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's 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`](http://ecma-international.org/ecma-262/6.0/#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;
},{"../internal/assignWith":155,"../internal/baseAssign":156,"../internal/createAssigner":197}],250:[function(require,module,exports){
var baseGet = require('../internal/baseGet'),
toPath = require('../internal/toPath');
/**
* Gets the property value at `path` of `object`. If the resolved value is
* `undefined` the `defaultValue` is used in its place.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @param {Array|string} path The path of the property to get.
* @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
* @returns {*} Returns the resolved value.
* @example
*
* var object = { 'a': [{ 'b': { 'c': 3 } }] };
*
* _.get(object, 'a[0].b.c');
* // => 3
*
* _.get(object, ['a', '0', 'b', 'c']);
* // => 3
*
* _.get(object, 'a.b.c', 'default');
* // => 'default'
*/
function get(object, path, defaultValue) {
var result = object == null ? undefined : baseGet(object, toPath(path), (path + ''));
return result === undefined ? defaultValue : result;
}
module.exports = get;
},{"../internal/baseGet":171,"../internal/toPath":236}],251:[function(require,module,exports){
var getNative = require('../internal/getNative'),
isArrayLike = require('../internal/isArrayLike'),
isObject = require('../lang/isObject'),
shimKeys = require('../internal/shimKeys');
/* Native method references for those with the same name as other `lodash` methods. */
var nativeKeys = getNative(Object, 'keys');
/**
* Creates an array of the own enumerable property names of `object`.
*
* **Note:** Non-object values are coerced to objects. See the
* [ES spec](http://ecma-international.org/ecma-262/6.0/#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 ? undefined : 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;
},{"../internal/getNative":216,"../internal/isArrayLike":218,"../internal/shimKeys":234,"../lang/isObject":244}],252:[function(require,module,exports){
var isArguments = require('../lang/isArguments'),
isArray = require('../lang/isArray'),
isIndex = require('../internal/isIndex'),
isLength = require('../internal/isLength'),
isObject = require('../lang/isObject');
/** 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) || 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;
},{"../internal/isIndex":219,"../internal/isLength":223,"../lang/isArguments":238,"../lang/isArray":239,"../lang/isObject":244}],253:[function(require,module,exports){
var baseMerge = require('../internal/baseMerge'),
createAssigner = require('../internal/createAssigner');
/**
* 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's 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;
},{"../internal/baseMerge":180,"../internal/createAssigner":197}],254:[function(require,module,exports){
var arrayMap = require('../internal/arrayMap'),
baseDifference = require('../internal/baseDifference'),
baseFlatten = require('../internal/baseFlatten'),
bindCallback = require('../internal/bindCallback'),
keysIn = require('./keysIn'),
pickByArray = require('../internal/pickByArray'),
pickByCallback = require('../internal/pickByCallback'),
restParam = require('../function/restParam');
/**
* 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;
},{"../function/restParam":143,"../internal/arrayMap":151,"../internal/baseDifference":161,"../internal/baseFlatten":167,"../internal/bindCallback":191,"../internal/pickByArray":228,"../internal/pickByCallback":229,"./keysIn":252}],255:[function(require,module,exports){
var keys = require('./keys'),
toObject = require('../internal/toObject');
/**
* Creates a two dimensional array of the key-value pairs for `object`,
* e.g. `[[key1, value1], [key2, value2]]`.
*
* @static
* @memberOf _
* @category Object
* @param {Object} object The object to query.
* @returns {Array} Returns the new array of key-value pairs.
* @example
*
* _.pairs({ 'barney': 36, 'fred': 40 });
* // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
*/
function pairs(object) {
object = toObject(object);
var index = -1,
props = keys(object),
length = props.length,
result = Array(length);
while (++index < length) {
var key = props[index];
result[index] = [key, object[key]];
}
return result;
}
module.exports = pairs;
},{"../internal/toObject":235,"./keys":251}],256:[function(require,module,exports){
var baseFlatten = require('../internal/baseFlatten'),
bindCallback = require('../internal/bindCallback'),
pickByArray = require('../internal/pickByArray'),
pickByCallback = require('../internal/pickByCallback'),
restParam = require('../function/restParam');
/**
* 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's 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;
},{"../function/restParam":143,"../internal/baseFlatten":167,"../internal/bindCallback":191,"../internal/pickByArray":228,"../internal/pickByCallback":229}],257:[function(require,module,exports){
var arrayEach = require('../internal/arrayEach'),
baseCallback = require('../internal/baseCallback'),
baseCreate = require('../internal/baseCreate'),
baseForOwn = require('../internal/baseForOwn'),
isArray = require('../lang/isArray'),
isFunction = require('../lang/isFunction'),
isObject = require('../lang/isObject'),
isTypedArray = require('../lang/isTypedArray');
/**
* An alternative to `_.reduce`; this method transforms `object` to a new
* `accumulator` object which is the result of running each of its own enumerable
* properties through `iteratee`, with each invocation potentially mutating
* the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
* with four arguments: (accumulator, value, key, object). Iteratee functions
* may exit iteration early by explicitly returning `false`.
*
* @static
* @memberOf _
* @category Object
* @param {Array|Object} object The object to iterate over.
* @param {Function} [iteratee=_.identity] The function invoked per iteration.
* @param {*} [accumulator] The custom accumulator value.
* @param {*} [thisArg] The `this` binding of `iteratee`.
* @returns {*} Returns the accumulated value.
* @example
*
* _.transform([2, 3, 4], function(result, n) {
* result.push(n *= n);
* return n % 2 == 0;
* });
* // => [4, 9]
*
* _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
* result[key] = n * 3;
* });
* // => { 'a': 3, 'b': 6 }
*/
function transform(object, iteratee, accumulator, thisArg) {
var isArr = isArray(object) || isTypedArray(object);
iteratee = baseCallback(iteratee, thisArg, 4);
if (accumulator == null) {
if (isArr || isObject(object)) {
var Ctor = object.constructor;
if (isArr) {
accumulator = isArray(object) ? new Ctor : [];
} else {
accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
}
} else {
accumulator = {};
}
}
(isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
return iteratee(accumulator, value, index, object);
});
return accumulator;
}
module.exports = transform;
},{"../internal/arrayEach":148,"../internal/baseCallback":157,"../internal/baseCreate":159,"../internal/baseForOwn":170,"../lang/isArray":239,"../lang/isFunction":241,"../lang/isObject":244,"../lang/isTypedArray":247}],258:[function(require,module,exports){
var baseValues = require('../internal/baseValues'),
keys = require('./keys');
/**
* 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;
},{"../internal/baseValues":190,"./keys":251}],259:[function(require,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;
},{}],260:[function(require,module,exports){
/**
* A no-operation function that returns `undefined` regardless of the
* arguments it receives.
*
* @static
* @memberOf _
* @category Utility
* @example
*
* var object = { 'user': 'fred' };
*
* _.noop(object) === undefined;
* // => true
*/
function noop() {
// No operation performed.
}
module.exports = noop;
},{}],261:[function(require,module,exports){
var baseProperty = require('../internal/baseProperty'),
basePropertyDeep = require('../internal/basePropertyDeep'),
isKey = require('../internal/isKey');
/**
* Creates a function that 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;
},{"../internal/baseProperty":182,"../internal/basePropertyDeep":183,"../internal/isKey":221}],262:[function(require,module,exports){
/**
* Set attribute `name` to `val`, or get attr `name`.
*
* @param {Element} el
* @param {String} name
* @param {String} [val]
* @api public
*/
module.exports = function(el, name, val) {
// get
if (arguments.length == 2) {
return el.getAttribute(name);
}
// remove
if (val === null) {
return el.removeAttribute(name);
}
// set
el.setAttribute(name, val);
return el;
};
},{}],263:[function(require,module,exports){
module.exports = require('component-classes');
},{"component-classes":70}],264:[function(require,module,exports){
module.exports = function(el) {
var c;
while (el.childNodes.length) {
c = el.childNodes[0];
el.removeChild(c);
}
return el;
};
},{}],265:[function(require,module,exports){
module.exports = require('component-closest');
},{"component-closest":71}],266:[function(require,module,exports){
module.exports = require('component-delegate');
},{"component-delegate":72}],267:[function(require,module,exports){
module.exports = require('domify');
},{"domify":117}],268:[function(require,module,exports){
module.exports = require('component-event');
},{"component-event":73}],269:[function(require,module,exports){
module.exports = require('component-matches-selector');
},{"component-matches-selector":75}],270:[function(require,module,exports){
module.exports = require('component-query');
},{"component-query":76}],271:[function(require,module,exports){
module.exports = function(el) {
el.parentNode && el.parentNode.removeChild(el);
};
},{}],272:[function(require,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'
};
var XSI_TYPE = module.exports.XSI_TYPE = 'xsi:type';
function serializeFormat(element) {
return element.xml && element.xml.serialize;
}
module.exports.serializeAsType = function(element) {
return serializeFormat(element) === XSI_TYPE;
};
module.exports.serializeAsProperty = function(element) {
return serializeFormat(element) === 'property';
};
},{}],273:[function(require,module,exports){
'use strict';
var reduce = require('lodash/collection/reduce'),
forEach = require('lodash/collection/forEach'),
find = require('lodash/collection/find'),
assign = require('lodash/object/assign'),
defer = require('lodash/function/defer');
var Stack = require('tiny-stack'),
SaxParser = require('sax').parser,
Moddle = require('moddle'),
parseNameNs = require('moddle/lib/ns').parseName,
Types = require('moddle/lib/types'),
coerceType = Types.coerceType,
isSimpleType = Types.isSimple,
common = require('./common'),
XSI_TYPE = common.XSI_TYPE,
XSI_URI = common.DEFAULT_NS_MAP.xsi,
serializeAsType = common.serializeAsType,
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);
});
}
function error(message) {
return new Error(message);
}
/**
* Get the moddle descriptor for a given instance or type.
*
* @param {ModdleElement|Function} element
*
* @return {Object} the moddle descriptor
*/
function getModdleDescriptor(element) {
return element.$descriptor;
}
/**
* A parse context.
*
* @class
*
* @param {Object} options
* @param {ElementHandler} options.rootHandler the root handler for parsing a document
* @param {boolean} [options.lax=false] whether or not to ignore invalid elements
*/
function Context(options) {
/**
* @property {ElementHandler} rootHandler
*/
/**
* @property {Boolean} lax
*/
assign(this, options);
this.elementsById = {};
this.references = [];
this.warnings = [];
/**
* Add an unresolved reference.
*
* @param {Object} reference
*/
this.addReference = function(reference) {
this.references.push(reference);
};
/**
* Add a processed element.
*
* @param {ModdleElement} element
*/
this.addElement = function(element) {
if (!element) {
throw error('expected element');
}
var elementsById = this.elementsById;
var descriptor = getModdleDescriptor(element);
var idProperty = descriptor.idProperty,
id;
if (idProperty) {
id = element.get(idProperty.name);
if (id) {
if (elementsById[id]) {
throw error('duplicate ID <' + id + '>');
}
elementsById[id] = element;
}
}
};
/**
* Add an import warning.
*
* @param {Object} warning
* @param {String} warning.message
* @param {Error} [warning.error]
*/
this.addWarning = function(warning) {
this.warnings.push(warning);
};
}
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 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(node) {
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;
if (!element) {
element = this.element = this.createElement(node);
this.context.addElement(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 = getModdleDescriptor(element),
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 = getModdleDescriptor(Type),
context = this.context,
instance = new Type({});
forEach(attributes, function(value, name) {
var prop = descriptor.propertiesByName[name],
values;
if (prop && prop.isReference) {
if (!prop.isMany) {
context.addReference({
element: instance,
property: prop.ns.name,
id: value
});
} else {
// IDREFS: parse references as whitespace-separated list
values = value.split(' ');
forEach(values, function(v) {
context.addReference({
element: instance,
property: prop.ns.name,
id: v
});
});
}
} 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 = getModdleDescriptor(type);
var propertyName = nameNs.name,
property = descriptor.propertiesByName[propertyName],
elementTypeName,
elementType,
typeAnnotation;
// search for properties by name first
if (property) {
if (serializeAsType(property)) {
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: getModdleDescriptor(elementType).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: getModdleDescriptor(elementType).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 error('unrecognized element <' + nameNs.name + '>');
};
ElementHandler.prototype.toString = function() {
return 'ElementDescriptor[' + getModdleDescriptor(this.type).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);
}
/**
* Parse the given XML into a moddle document tree.
*
* @param {String} xml
* @param {ElementHandler|Object} options or rootHandler
* @param {Function} done
*/
XMLReader.prototype.fromXML = function(xml, options, done) {
var rootHandler = options.rootHandler;
if (options instanceof ElementHandler) {
// root handler passed via (xml, { rootHandler: ElementHandler }, ...)
rootHandler = options;
options = {};
} else {
if (typeof options === 'string') {
// rootHandler passed via (xml, 'someString', ...)
rootHandler = this.handler(options);
options = {};
} else if (typeof rootHandler === 'string') {
// rootHandler passed via (xml, { rootHandler: 'someString' }, ...)
rootHandler = this.handler(rootHandler);
}
}
var model = this.model,
lax = this.lax;
var context = new Context(assign({}, options, { rootHandler: rootHandler })),
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 = getModdleDescriptor(element).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);
// we replace an existing place holder (idx != -1) or
// append to the collection instead
if (idx === -1) {
idx = collection.length;
}
if (!reference) {
// remove unresolvable reference
collection.splice(idx, 1);
} else {
// add or update reference in collection
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 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;
},{"./common":272,"lodash/collection/find":131,"lodash/collection/forEach":132,"lodash/collection/reduce":137,"lodash/function/defer":142,"lodash/object/assign":249,"moddle":275,"moddle/lib/ns":280,"moddle/lib/types":283,"sax":297,"tiny-stack":303}],274:[function(require,module,exports){
'use strict';
var map = require('lodash/collection/map'),
forEach = require('lodash/collection/forEach'),
isString = require('lodash/lang/isString'),
filter = require('lodash/collection/filter'),
assign = require('lodash/object/assign');
var Types = require('moddle/lib/types'),
parseNameNs = require('moddle/lib/ns').parseName,
common = require('./common'),
nameToAlias = common.nameToAlias,
serializeAsType = common.serializeAsType,
serializeAsProperty = common.serializeAsProperty;
var XML_PREAMBLE = '\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 getNsAttrs(namespaces) {
function isUsed(ns) {
return namespaces.used[ns.uri];
}
function toAttr(ns) {
var name = 'xmlns' + (ns.prefix ? ':' + ns.prefix : '');
return { name: name, value: ns.uri };
}
var allNs = [].concat(namespaces.wellknown, namespaces.custom);
return map(filter(allNs, isUsed), toAttr);
}
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;
if (p.isVirtual) {
return false;
}
// 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;
}
// do not serialize null properties
if (value === null) {
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('');
}
};
BodySerializer.prototype.build = function(prop, value) {
this.value = value;
if (prop.type === 'String' && value.search(ESCAPE_CHARS) !== -1) {
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;
};
/**
* Get the actual ns attribute name for the given element.
*
* @param {Object} element
* @param {Boolean} [inherited=false]
*
* @return {Object} nsName
*/
ElementSerializer.prototype.nsAttributeName = function(element) {
var ns;
if (isString(element)) {
ns = parseNameNs(element);
} else {
ns = element.ns;
}
// return just local name for inherited attributes
if (element.inherited) {
return { localName: ns.localName };
}
// parse + log effective 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}
*/
ElementSerializer.prototype.parseNsAttributes = function(element) {
var self = this;
var genericAttrs = element.$attrs;
var model = element.$model;
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);
var ns;
// parse xmlns:foo="http://foo.bar"
if (nameNs.prefix === 'xmlns') {
ns = { prefix: nameNs.localName, uri: value };
}
// parse xmlns="http://foo.bar"
if (!nameNs.prefix && nameNs.localName === 'xmlns') {
ns = { uri: value };
}
if (ns) {
if (model.getPackage(value)) {
// register well known namespace
self.logNamespace(ns, true);
} else {
// log custom namespace directly as used
self.logNamespaceUsed(ns);
}
} 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(
'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 = serializeAsType(p),
asProperty = serializeAsProperty(p);
forEach(value, function(v) {
var serializer;
if (asType) {
serializer = new TypeSerializer(self, ns);
} else
if (asProperty) {
serializer = new ElementSerializer(self, ns);
} else {
serializer = new ElementSerializer(self);
}
body.push(serializer.build(v));
});
}
});
};
ElementSerializer.prototype.getNamespaces = function() {
var namespaces = this.namespaces,
parent = this.parent;
if (!namespaces) {
namespaces = this.namespaces = parent ? parent.getNamespaces() : {
prefixMap: {},
uriMap: {},
used: {},
wellknown: [],
custom: []
};
}
return namespaces;
};
ElementSerializer.prototype.logNamespace = function(ns, wellknown) {
var namespaces = this.getNamespaces();
var nsUri = ns.uri;
var existing = namespaces.uriMap[nsUri];
if (!existing) {
namespaces.uriMap[nsUri] = ns;
if (wellknown) {
namespaces.wellknown.push(ns);
} else {
namespaces.custom.push(ns);
}
}
namespaces.prefixMap[ns.prefix] = nsUri;
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 wellknownUri = DEFAULT_NS_MAP[prefix] || model && (model.getPackage(prefix) || {}).uri;
var uri = ns.uri || namespaces.prefixMap[prefix] || wellknownUri;
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 }, wellknownUri);
}
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) {
var value = element.get(p.name);
if (p.isReference) {
if (!p.isMany) {
value = value.id;
}
else {
var values = [];
forEach(value, function(v) {
values.push(v.id);
});
// IDREFS is a whitespace-separated list of references.
value = values.join(' ');
}
}
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;
if (root) {
attrs = getNsAttrs(this.namespaces).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;
},{"./common":272,"lodash/collection/filter":130,"lodash/collection/forEach":132,"lodash/collection/map":136,"lodash/lang/isString":246,"lodash/object/assign":249,"moddle/lib/ns":280,"moddle/lib/types":283}],275:[function(require,module,exports){
module.exports = require('./lib/moddle');
},{"./lib/moddle":279}],276:[function(require,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;
},{}],277:[function(require,module,exports){
'use strict';
var pick = require('lodash/object/pick'),
assign = require('lodash/object/assign'),
forEach = require('lodash/collection/forEach');
var parseNameNs = require('./ns').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',
'idProperty'
]);
};
/**
* Add property at given index.
*
* @param {Object} p
* @param {Number} [idx]
* @param {Boolean} [validate=true]
*/
DescriptorBuilder.prototype.addProperty = function(p, idx, validate) {
if (typeof idx === 'boolean') {
validate = idx;
idx = undefined;
}
this.addNamedProperty(p, validate !== false);
var properties = this.properties;
if (idx !== undefined) {
properties.splice(idx, 0, p);
} else {
properties.push(p);
}
};
DescriptorBuilder.prototype.replaceProperty = function(oldProperty, newProperty, replace) {
var oldNameNs = oldProperty.ns;
var props = this.properties,
propertiesByName = this.propertiesByName,
rename = oldProperty.name !== newProperty.name;
if (oldProperty.isId) {
if (!newProperty.isId) {
throw new Error(
'property <' + newProperty.ns.name + '> must be id property ' +
'to refine <' + oldProperty.ns.name + '>');
}
this.setIdProperty(newProperty, false);
}
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);
}
// validate existence and get location of old property
var idx = props.indexOf(oldProperty);
if (idx === -1) {
throw new Error('property <' + oldNameNs.name + '> not found in property list');
}
// remove old property
props.splice(idx, 1);
// replacing the named property is intentional
//
// * validate only if this is a "rename" operation
// * add at specific index unless we "replace"
//
this.addProperty(newProperty, replace ? undefined : idx, rename);
// make new property available under old name
propertiesByName[oldNameNs.name] = propertiesByName[oldNameNs.localName] = newProperty;
};
DescriptorBuilder.prototype.redefineProperty = function(p, targetPropertyName, replace) {
var nsPrefix = p.ns.prefix;
var parts = targetPropertyName.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, replace);
}
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.setIdProperty = function(p, validate) {
if (validate && this.idProperty) {
throw new Error(
'id property defined multiple times ' +
'(<' + this.idProperty.ns.name + '>, <' + p.ns.name + '>)');
}
this.idProperty = p;
};
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, inherited) {
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,
inherited: inherited
});
Object.defineProperty(p, 'definedBy', {
value: t
});
var replaces = p.replaces,
redefines = p.redefines;
// add replace/redefine support
if (replaces || redefines) {
this.redefineProperty(p, replaces || redefines, replaces);
} else {
if (p.isBody) {
this.setBodyProperty(p);
}
if (p.isId) {
this.setIdProperty(p);
}
this.addProperty(p);
}
}, this);
allTypes.push(t);
};
},{"./ns":280,"lodash/collection/forEach":132,"lodash/object/assign":249,"lodash/object/pick":256}],278:[function(require,module,exports){
'use strict';
var forEach = require('lodash/collection/forEach');
var Base = require('./base');
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;
};
},{"./base":276,"lodash/collection/forEach":132}],279:[function(require,module,exports){
'use strict';
var isString = require('lodash/lang/isString'),
isObject = require('lodash/lang/isObject'),
forEach = require('lodash/collection/forEach'),
find = require('lodash/collection/find');
var Factory = require('./factory'),
Registry = require('./registry'),
Properties = require('./properties');
var parseNameNs = require('./ns').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} packages the packages to contain
*/
function Moddle(packages) {
this.properties = new Properties(this);
this.factory = new Factory(this, this.properties);
this.registry = new Registry(packages, this.properties);
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];
};
},{"./factory":278,"./ns":280,"./properties":281,"./registry":282,"lodash/collection/find":131,"lodash/collection/forEach":132,"lodash/lang/isObject":244,"lodash/lang/isString":246}],280:[function(require,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 or , got ' + name);
}
name = (prefix ? prefix + ':' : '') + localName;
return {
name: name,
prefix: prefix,
localName: localName
};
};
},{}],281:[function(require,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.
* If the value is undefined, the property gets deleted.
*
* @param {Object} target
* @param {String} name
* @param {Object} value
*/
Properties.prototype.set = function(target, name, value) {
var property = this.model.getPropertyDescriptor(target, name);
var propertyName = property && property.name;
if (isUndefined(value)) {
// unset the property, if the specified value is undefined;
// delete from $attrs (for extensions) or the target itself
if (property) {
delete target[propertyName];
} else {
delete target.$attrs[name];
}
} else {
// set the property, defining well defined properties on the fly
// or simply updating them in target.$attrs (for extensions)
if (property) {
if (propertyName in target) {
target[propertyName] = value;
} else {
defineProperty(target, property, value);
}
} else {
target.$attrs[name] = 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) {
defineProperty(target, property, []);
}
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 });
};
function isUndefined(val) {
return typeof val === 'undefined';
}
function defineProperty(target, property, value) {
Object.defineProperty(target, property.name, {
enumerable: !property.isReference,
writable: true,
value: value,
configurable: true
});
}
},{}],282:[function(require,module,exports){
'use strict';
var assign = require('lodash/object/assign'),
forEach = require('lodash/collection/forEach');
var Types = require('./types'),
DescriptorBuilder = require('./descriptor-builder');
var parseNameNs = require('./ns').parseName,
isBuiltInType = Types.isBuiltIn;
function Registry(packages, properties) {
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,
* calling iterator with (type, inherited) for all elements in
* the inheritance chain.
*
* @param {Object} nsName
* @param {Function} iterator
* @param {Boolean} [trait=false]
*/
Registry.prototype.mapTypes = function(nsName, iterator, trait) {
var type = isBuiltInType(nsName.name) ? { name: nsName.name } : this.typeMap[nsName.name];
var self = this;
/**
* Traverse the selected trait.
*
* @param {String} cls
*/
function traverseTrait(cls) {
return traverseSuper(cls, true);
}
/**
* Traverse the selected super type or trait
*
* @param {String} cls
* @param {Boolean} [trait=false]
*/
function traverseSuper(cls, trait) {
var parentNs = parseNameNs(cls, isBuiltInType(cls) ? '' : nsName.prefix);
self.mapTypes(parentNs, iterator, trait);
}
if (!type) {
throw new Error('unknown type <' + nsName.name + '>');
}
forEach(type.superClass, trait ? traverseTrait : traverseSuper);
// call iterator with (type, inherited=!trait)
iterator(type, !trait);
forEach(type.traits, traverseTrait);
};
/**
* 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, inherited) {
builder.addTrait(type, inherited);
});
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 });
};
},{"./descriptor-builder":277,"./ns":280,"./types":283,"lodash/collection/forEach":132,"lodash/object/assign":249}],283:[function(require,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];
};
},{}],284:[function(require,module,exports){
module.exports = require('./lib/refs');
module.exports.Collection = require('./lib/collection');
},{"./lib/collection":285,"./lib/refs":286}],285:[function(require,module,exports){
'use strict';
/**
* An empty collection stub. Use {@link RefsCollection.extend} to extend a
* collection with ref semantics.
*
* @class RefsCollection
*/
/**
* Extends a collection with {@link Refs} aware methods
*
* @memberof RefsCollection
* @static
*
* @param {Array} collection
* @param {Refs} refs instance
* @param {Object} property represented by the collection
* @param {Object} target object the collection is attached to
*
* @return {RefsCollection} 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
*/
Object.defineProperty(collection, 'remove', {
value: 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
*/
Object.defineProperty(collection, 'contains', {
value: 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
*/
Object.defineProperty(collection, 'add', {
value: function(element) {
if (!this.contains(element)) {
this.push(element);
// set inverse
refs.set(element, inverseProperty, target);
}
}
});
// a simple marker, identifying this element
// as being a refs collection
Object.defineProperty(collection, '__refs_collection', {
value: true
});
return collection;
}
function isExtended(collection) {
return collection.__refs_collection === true;
}
module.exports.extend = extend;
module.exports.isExtended = isExtended;
},{}],286:[function(require,module,exports){
'use strict';
var Collection = require('./collection');
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.
*
*
* When bound to an object using {@link Refs#bind} the references
* get activated and ensure that add and remove operations are applied
* reversely, too.
*
*
*
* 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.
*
*
* @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.ensureRefsCollection = function(target, property) {
var collection = target[property.name];
if (!Collection.isExtended(collection)) {
defineCollectionProperty(this, property, target);
}
return collection;
};
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) {
this.ensureRefsCollection(target, property).remove(value);
} else {
target[property.name] = undefined;
}
}
};
Refs.prototype.set = function(target, property, value) {
if (target) {
this.ensureBound(target, property);
if (property.collection) {
this.ensureRefsCollection(target, property).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]
*/
},{"./collection":285}],287:[function(require,module,exports){
module.exports = require("./lib/_stream_duplex.js")
},{"./lib/_stream_duplex.js":288}],288:[function(require,module,exports){
(function (process){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// a duplex stream is just a stream that is both readable and writable.
// Since JS doesn't have multiple prototypal inheritance, this class
// prototypally inherits from Readable, and then parasitically from
// Writable.
module.exports = Duplex;
/**/
var objectKeys = Object.keys || function (obj) {
var keys = [];
for (var key in obj) keys.push(key);
return keys;
}
/* */
/**/
var util = require('core-util-is');
util.inherits = require('inherits');
/* */
var Readable = require('./_stream_readable');
var Writable = require('./_stream_writable');
util.inherits(Duplex, Readable);
forEach(objectKeys(Writable.prototype), function(method) {
if (!Duplex.prototype[method])
Duplex.prototype[method] = Writable.prototype[method];
});
function Duplex(options) {
if (!(this instanceof Duplex))
return new Duplex(options);
Readable.call(this, options);
Writable.call(this, options);
if (options && options.readable === false)
this.readable = false;
if (options && options.writable === false)
this.writable = false;
this.allowHalfOpen = true;
if (options && options.allowHalfOpen === false)
this.allowHalfOpen = false;
this.once('end', onend);
}
// the no-half-open enforcer
function onend() {
// if we allow half-open state, or if the writable side ended,
// then we're ok.
if (this.allowHalfOpen || this._writableState.ended)
return;
// no more data can be written.
// But allow more writes to happen in this tick.
process.nextTick(this.end.bind(this));
}
function forEach (xs, f) {
for (var i = 0, l = xs.length; i < l; i++) {
f(xs[i], i);
}
}
}).call(this,undefined)
},{"./_stream_readable":290,"./_stream_writable":292,"core-util-is":77,"inherits":122}],289:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// a passthrough stream.
// basically just the most minimal sort of Transform stream.
// Every written chunk gets output as-is.
module.exports = PassThrough;
var Transform = require('./_stream_transform');
/**/
var util = require('core-util-is');
util.inherits = require('inherits');
/* */
util.inherits(PassThrough, Transform);
function PassThrough(options) {
if (!(this instanceof PassThrough))
return new PassThrough(options);
Transform.call(this, options);
}
PassThrough.prototype._transform = function(chunk, encoding, cb) {
cb(null, chunk);
};
},{"./_stream_transform":291,"core-util-is":77,"inherits":122}],290:[function(require,module,exports){
(function (process){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
module.exports = Readable;
/**/
var isArray = require('isarray');
/* */
/**/
var Buffer = require('buffer').Buffer;
/* */
Readable.ReadableState = ReadableState;
var EE = require('events').EventEmitter;
/**/
if (!EE.listenerCount) EE.listenerCount = function(emitter, type) {
return emitter.listeners(type).length;
};
/* */
var Stream = require('stream');
/**/
var util = require('core-util-is');
util.inherits = require('inherits');
/* */
var StringDecoder;
/**/
var debug = require('util');
if (debug && debug.debuglog) {
debug = debug.debuglog('stream');
} else {
debug = function () {};
}
/* */
util.inherits(Readable, Stream);
function ReadableState(options, stream) {
var Duplex = require('./_stream_duplex');
options = options || {};
// the point at which it stops calling _read() to fill the buffer
// Note: 0 is a valid value, means "don't call _read preemptively ever"
var hwm = options.highWaterMark;
var defaultHwm = options.objectMode ? 16 : 16 * 1024;
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
// cast to ints.
this.highWaterMark = ~~this.highWaterMark;
this.buffer = [];
this.length = 0;
this.pipes = null;
this.pipesCount = 0;
this.flowing = null;
this.ended = false;
this.endEmitted = false;
this.reading = false;
// a flag to be able to tell if the onwrite cb is called immediately,
// or on a later tick. We set this to true at first, because any
// actions that shouldn't happen until "later" should generally also
// not happen before the first write call.
this.sync = true;
// whenever we return null, then we set a flag to say
// that we're awaiting a 'readable' event emission.
this.needReadable = false;
this.emittedReadable = false;
this.readableListening = false;
// object stream flag. Used to make read(n) ignore n and to
// make all the buffer merging and length checks go away
this.objectMode = !!options.objectMode;
if (stream instanceof Duplex)
this.objectMode = this.objectMode || !!options.readableObjectMode;
// Crypto is kind of old and crusty. Historically, its default string
// encoding is 'binary' so we have to make this configurable.
// Everything else in the universe uses 'utf8', though.
this.defaultEncoding = options.defaultEncoding || 'utf8';
// when piping, we only care about 'readable' events that happen
// after read()ing all the bytes and not getting any pushback.
this.ranOut = false;
// the number of writers that are awaiting a drain event in .pipe()s
this.awaitDrain = 0;
// if true, a maybeReadMore has been scheduled
this.readingMore = false;
this.decoder = null;
this.encoding = null;
if (options.encoding) {
if (!StringDecoder)
StringDecoder = require('string_decoder/').StringDecoder;
this.decoder = new StringDecoder(options.encoding);
this.encoding = options.encoding;
}
}
function Readable(options) {
var Duplex = require('./_stream_duplex');
if (!(this instanceof Readable))
return new Readable(options);
this._readableState = new ReadableState(options, this);
// legacy
this.readable = true;
Stream.call(this);
}
// Manually shove something into the read() buffer.
// This returns true if the highWaterMark has not been hit yet,
// similar to how Writable.write() returns true if you should
// write() some more.
Readable.prototype.push = function(chunk, encoding) {
var state = this._readableState;
if (util.isString(chunk) && !state.objectMode) {
encoding = encoding || state.defaultEncoding;
if (encoding !== state.encoding) {
chunk = new Buffer(chunk, encoding);
encoding = '';
}
}
return readableAddChunk(this, state, chunk, encoding, false);
};
// Unshift should *always* be something directly out of read()
Readable.prototype.unshift = function(chunk) {
var state = this._readableState;
return readableAddChunk(this, state, chunk, '', true);
};
function readableAddChunk(stream, state, chunk, encoding, addToFront) {
var er = chunkInvalid(state, chunk);
if (er) {
stream.emit('error', er);
} else if (util.isNullOrUndefined(chunk)) {
state.reading = false;
if (!state.ended)
onEofChunk(stream, state);
} else if (state.objectMode || chunk && chunk.length > 0) {
if (state.ended && !addToFront) {
var e = new Error('stream.push() after EOF');
stream.emit('error', e);
} else if (state.endEmitted && addToFront) {
var e = new Error('stream.unshift() after end event');
stream.emit('error', e);
} else {
if (state.decoder && !addToFront && !encoding)
chunk = state.decoder.write(chunk);
if (!addToFront)
state.reading = false;
// if we want the data now, just emit it.
if (state.flowing && state.length === 0 && !state.sync) {
stream.emit('data', chunk);
stream.read(0);
} else {
// update the buffer info.
state.length += state.objectMode ? 1 : chunk.length;
if (addToFront)
state.buffer.unshift(chunk);
else
state.buffer.push(chunk);
if (state.needReadable)
emitReadable(stream);
}
maybeReadMore(stream, state);
}
} else if (!addToFront) {
state.reading = false;
}
return needMoreData(state);
}
// if it's past the high water mark, we can push in some more.
// Also, if we have no data yet, we can stand some
// more bytes. This is to work around cases where hwm=0,
// such as the repl. Also, if the push() triggered a
// readable event, and the user called read(largeNumber) such that
// needReadable was set, then we ought to push more, so that another
// 'readable' event will be triggered.
function needMoreData(state) {
return !state.ended &&
(state.needReadable ||
state.length < state.highWaterMark ||
state.length === 0);
}
// backwards compatibility.
Readable.prototype.setEncoding = function(enc) {
if (!StringDecoder)
StringDecoder = require('string_decoder/').StringDecoder;
this._readableState.decoder = new StringDecoder(enc);
this._readableState.encoding = enc;
return this;
};
// Don't raise the hwm > 128MB
var MAX_HWM = 0x800000;
function roundUpToNextPowerOf2(n) {
if (n >= MAX_HWM) {
n = MAX_HWM;
} else {
// Get the next highest power of 2
n--;
for (var p = 1; p < 32; p <<= 1) n |= n >> p;
n++;
}
return n;
}
function howMuchToRead(n, state) {
if (state.length === 0 && state.ended)
return 0;
if (state.objectMode)
return n === 0 ? 0 : 1;
if (isNaN(n) || util.isNull(n)) {
// only flow one buffer at a time
if (state.flowing && state.buffer.length)
return state.buffer[0].length;
else
return state.length;
}
if (n <= 0)
return 0;
// If we're asking for more than the target buffer level,
// then raise the water mark. Bump up to the next highest
// power of 2, to prevent increasing it excessively in tiny
// amounts.
if (n > state.highWaterMark)
state.highWaterMark = roundUpToNextPowerOf2(n);
// don't have that much. return null, unless we've ended.
if (n > state.length) {
if (!state.ended) {
state.needReadable = true;
return 0;
} else
return state.length;
}
return n;
}
// you can override either this method, or the async _read(n) below.
Readable.prototype.read = function(n) {
debug('read', n);
var state = this._readableState;
var nOrig = n;
if (!util.isNumber(n) || n > 0)
state.emittedReadable = false;
// if we're doing read(0) to trigger a readable event, but we
// already have a bunch of data in the buffer, then just trigger
// the 'readable' event and move on.
if (n === 0 &&
state.needReadable &&
(state.length >= state.highWaterMark || state.ended)) {
debug('read: emitReadable', state.length, state.ended);
if (state.length === 0 && state.ended)
endReadable(this);
else
emitReadable(this);
return null;
}
n = howMuchToRead(n, state);
// if we've ended, and we're now clear, then finish it up.
if (n === 0 && state.ended) {
if (state.length === 0)
endReadable(this);
return null;
}
// All the actual chunk generation logic needs to be
// *below* the call to _read. The reason is that in certain
// synthetic stream cases, such as passthrough streams, _read
// may be a completely synchronous operation which may change
// the state of the read buffer, providing enough data when
// before there was *not* enough.
//
// So, the steps are:
// 1. Figure out what the state of things will be after we do
// a read from the buffer.
//
// 2. If that resulting state will trigger a _read, then call _read.
// Note that this may be asynchronous, or synchronous. Yes, it is
// deeply ugly to write APIs this way, but that still doesn't mean
// that the Readable class should behave improperly, as streams are
// designed to be sync/async agnostic.
// Take note if the _read call is sync or async (ie, if the read call
// has returned yet), so that we know whether or not it's safe to emit
// 'readable' etc.
//
// 3. Actually pull the requested chunks out of the buffer and return.
// if we need a readable event, then we need to do some reading.
var doRead = state.needReadable;
debug('need readable', doRead);
// if we currently have less than the highWaterMark, then also read some
if (state.length === 0 || state.length - n < state.highWaterMark) {
doRead = true;
debug('length less than watermark', doRead);
}
// however, if we've ended, then there's no point, and if we're already
// reading, then it's unnecessary.
if (state.ended || state.reading) {
doRead = false;
debug('reading or ended', doRead);
}
if (doRead) {
debug('do read');
state.reading = true;
state.sync = true;
// if the length is currently zero, then we *need* a readable event.
if (state.length === 0)
state.needReadable = true;
// call internal read method
this._read(state.highWaterMark);
state.sync = false;
}
// If _read pushed data synchronously, then `reading` will be false,
// and we need to re-evaluate how much data we can return to the user.
if (doRead && !state.reading)
n = howMuchToRead(nOrig, state);
var ret;
if (n > 0)
ret = fromList(n, state);
else
ret = null;
if (util.isNull(ret)) {
state.needReadable = true;
n = 0;
}
state.length -= n;
// If we have nothing in the buffer, then we want to know
// as soon as we *do* get something into the buffer.
if (state.length === 0 && !state.ended)
state.needReadable = true;
// If we tried to read() past the EOF, then emit end on the next tick.
if (nOrig !== n && state.ended && state.length === 0)
endReadable(this);
if (!util.isNull(ret))
this.emit('data', ret);
return ret;
};
function chunkInvalid(state, chunk) {
var er = null;
if (!util.isBuffer(chunk) &&
!util.isString(chunk) &&
!util.isNullOrUndefined(chunk) &&
!state.objectMode) {
er = new TypeError('Invalid non-string/buffer chunk');
}
return er;
}
function onEofChunk(stream, state) {
if (state.decoder && !state.ended) {
var chunk = state.decoder.end();
if (chunk && chunk.length) {
state.buffer.push(chunk);
state.length += state.objectMode ? 1 : chunk.length;
}
}
state.ended = true;
// emit 'readable' now to make sure it gets picked up.
emitReadable(stream);
}
// Don't emit readable right away in sync mode, because this can trigger
// another read() call => stack overflow. This way, it might trigger
// a nextTick recursion warning, but that's not so bad.
function emitReadable(stream) {
var state = stream._readableState;
state.needReadable = false;
if (!state.emittedReadable) {
debug('emitReadable', state.flowing);
state.emittedReadable = true;
if (state.sync)
process.nextTick(function() {
emitReadable_(stream);
});
else
emitReadable_(stream);
}
}
function emitReadable_(stream) {
debug('emit readable');
stream.emit('readable');
flow(stream);
}
// at this point, the user has presumably seen the 'readable' event,
// and called read() to consume some data. that may have triggered
// in turn another _read(n) call, in which case reading = true if
// it's in progress.
// However, if we're not ended, or reading, and the length < hwm,
// then go ahead and try to read some more preemptively.
function maybeReadMore(stream, state) {
if (!state.readingMore) {
state.readingMore = true;
process.nextTick(function() {
maybeReadMore_(stream, state);
});
}
}
function maybeReadMore_(stream, state) {
var len = state.length;
while (!state.reading && !state.flowing && !state.ended &&
state.length < state.highWaterMark) {
debug('maybeReadMore read 0');
stream.read(0);
if (len === state.length)
// didn't get any data, stop spinning.
break;
else
len = state.length;
}
state.readingMore = false;
}
// abstract method. to be overridden in specific implementation classes.
// call cb(er, data) where data is <= n in length.
// for virtual (non-string, non-buffer) streams, "length" is somewhat
// arbitrary, and perhaps not very meaningful.
Readable.prototype._read = function(n) {
this.emit('error', new Error('not implemented'));
};
Readable.prototype.pipe = function(dest, pipeOpts) {
var src = this;
var state = this._readableState;
switch (state.pipesCount) {
case 0:
state.pipes = dest;
break;
case 1:
state.pipes = [state.pipes, dest];
break;
default:
state.pipes.push(dest);
break;
}
state.pipesCount += 1;
debug('pipe count=%d opts=%j', state.pipesCount, pipeOpts);
var doEnd = (!pipeOpts || pipeOpts.end !== false) &&
dest !== process.stdout &&
dest !== process.stderr;
var endFn = doEnd ? onend : cleanup;
if (state.endEmitted)
process.nextTick(endFn);
else
src.once('end', endFn);
dest.on('unpipe', onunpipe);
function onunpipe(readable) {
debug('onunpipe');
if (readable === src) {
cleanup();
}
}
function onend() {
debug('onend');
dest.end();
}
// when the dest drains, it reduces the awaitDrain counter
// on the source. This would be more elegant with a .once()
// handler in flow(), but adding and removing repeatedly is
// too slow.
var ondrain = pipeOnDrain(src);
dest.on('drain', ondrain);
function cleanup() {
debug('cleanup');
// cleanup event handlers once the pipe is broken
dest.removeListener('close', onclose);
dest.removeListener('finish', onfinish);
dest.removeListener('drain', ondrain);
dest.removeListener('error', onerror);
dest.removeListener('unpipe', onunpipe);
src.removeListener('end', onend);
src.removeListener('end', cleanup);
src.removeListener('data', ondata);
// if the reader is waiting for a drain event from this
// specific writer, then it would cause it to never start
// flowing again.
// So, if this is awaiting a drain, then we just call it now.
// If we don't know, then assume that we are waiting for one.
if (state.awaitDrain &&
(!dest._writableState || dest._writableState.needDrain))
ondrain();
}
src.on('data', ondata);
function ondata(chunk) {
debug('ondata');
var ret = dest.write(chunk);
if (false === ret) {
debug('false write response, pause',
src._readableState.awaitDrain);
src._readableState.awaitDrain++;
src.pause();
}
}
// if the dest has an error, then stop piping into it.
// however, don't suppress the throwing behavior for this.
function onerror(er) {
debug('onerror', er);
unpipe();
dest.removeListener('error', onerror);
if (EE.listenerCount(dest, 'error') === 0)
dest.emit('error', er);
}
// This is a brutally ugly hack to make sure that our error handler
// is attached before any userland ones. NEVER DO THIS.
if (!dest._events || !dest._events.error)
dest.on('error', onerror);
else if (isArray(dest._events.error))
dest._events.error.unshift(onerror);
else
dest._events.error = [onerror, dest._events.error];
// Both close and finish should trigger unpipe, but only once.
function onclose() {
dest.removeListener('finish', onfinish);
unpipe();
}
dest.once('close', onclose);
function onfinish() {
debug('onfinish');
dest.removeListener('close', onclose);
unpipe();
}
dest.once('finish', onfinish);
function unpipe() {
debug('unpipe');
src.unpipe(dest);
}
// tell the dest that it's being piped to
dest.emit('pipe', src);
// start the flow if it hasn't been started already.
if (!state.flowing) {
debug('pipe resume');
src.resume();
}
return dest;
};
function pipeOnDrain(src) {
return function() {
var state = src._readableState;
debug('pipeOnDrain', state.awaitDrain);
if (state.awaitDrain)
state.awaitDrain--;
if (state.awaitDrain === 0 && EE.listenerCount(src, 'data')) {
state.flowing = true;
flow(src);
}
};
}
Readable.prototype.unpipe = function(dest) {
var state = this._readableState;
// if we're not piping anywhere, then do nothing.
if (state.pipesCount === 0)
return this;
// just one destination. most common case.
if (state.pipesCount === 1) {
// passed in one, but it's not the right one.
if (dest && dest !== state.pipes)
return this;
if (!dest)
dest = state.pipes;
// got a match.
state.pipes = null;
state.pipesCount = 0;
state.flowing = false;
if (dest)
dest.emit('unpipe', this);
return this;
}
// slow case. multiple pipe destinations.
if (!dest) {
// remove all.
var dests = state.pipes;
var len = state.pipesCount;
state.pipes = null;
state.pipesCount = 0;
state.flowing = false;
for (var i = 0; i < len; i++)
dests[i].emit('unpipe', this);
return this;
}
// try to find the right one.
var i = indexOf(state.pipes, dest);
if (i === -1)
return this;
state.pipes.splice(i, 1);
state.pipesCount -= 1;
if (state.pipesCount === 1)
state.pipes = state.pipes[0];
dest.emit('unpipe', this);
return this;
};
// set up data events if they are asked for
// Ensure readable listeners eventually get something
Readable.prototype.on = function(ev, fn) {
var res = Stream.prototype.on.call(this, ev, fn);
// If listening to data, and it has not explicitly been paused,
// then call resume to start the flow of data on the next tick.
if (ev === 'data' && false !== this._readableState.flowing) {
this.resume();
}
if (ev === 'readable' && this.readable) {
var state = this._readableState;
if (!state.readableListening) {
state.readableListening = true;
state.emittedReadable = false;
state.needReadable = true;
if (!state.reading) {
var self = this;
process.nextTick(function() {
debug('readable nexttick read 0');
self.read(0);
});
} else if (state.length) {
emitReadable(this, state);
}
}
}
return res;
};
Readable.prototype.addListener = Readable.prototype.on;
// pause() and resume() are remnants of the legacy readable stream API
// If the user uses them, then switch into old mode.
Readable.prototype.resume = function() {
var state = this._readableState;
if (!state.flowing) {
debug('resume');
state.flowing = true;
if (!state.reading) {
debug('resume read 0');
this.read(0);
}
resume(this, state);
}
return this;
};
function resume(stream, state) {
if (!state.resumeScheduled) {
state.resumeScheduled = true;
process.nextTick(function() {
resume_(stream, state);
});
}
}
function resume_(stream, state) {
state.resumeScheduled = false;
stream.emit('resume');
flow(stream);
if (state.flowing && !state.reading)
stream.read(0);
}
Readable.prototype.pause = function() {
debug('call pause flowing=%j', this._readableState.flowing);
if (false !== this._readableState.flowing) {
debug('pause');
this._readableState.flowing = false;
this.emit('pause');
}
return this;
};
function flow(stream) {
var state = stream._readableState;
debug('flow', state.flowing);
if (state.flowing) {
do {
var chunk = stream.read();
} while (null !== chunk && state.flowing);
}
}
// wrap an old-style stream as the async data source.
// This is *not* part of the readable stream interface.
// It is an ugly unfortunate mess of history.
Readable.prototype.wrap = function(stream) {
var state = this._readableState;
var paused = false;
var self = this;
stream.on('end', function() {
debug('wrapped end');
if (state.decoder && !state.ended) {
var chunk = state.decoder.end();
if (chunk && chunk.length)
self.push(chunk);
}
self.push(null);
});
stream.on('data', function(chunk) {
debug('wrapped data');
if (state.decoder)
chunk = state.decoder.write(chunk);
if (!chunk || !state.objectMode && !chunk.length)
return;
var ret = self.push(chunk);
if (!ret) {
paused = true;
stream.pause();
}
});
// proxy all the other methods.
// important when wrapping filters and duplexes.
for (var i in stream) {
if (util.isFunction(stream[i]) && util.isUndefined(this[i])) {
this[i] = function(method) { return function() {
return stream[method].apply(stream, arguments);
}}(i);
}
}
// proxy certain important events.
var events = ['error', 'close', 'destroy', 'pause', 'resume'];
forEach(events, function(ev) {
stream.on(ev, self.emit.bind(self, ev));
});
// when we try to consume some more bytes, simply unpause the
// underlying stream.
self._read = function(n) {
debug('wrapped _read', n);
if (paused) {
paused = false;
stream.resume();
}
};
return self;
};
// exposed for testing purposes only.
Readable._fromList = fromList;
// Pluck off n bytes from an array of buffers.
// Length is the combined lengths of all the buffers in the list.
function fromList(n, state) {
var list = state.buffer;
var length = state.length;
var stringMode = !!state.decoder;
var objectMode = !!state.objectMode;
var ret;
// nothing in the list, definitely empty.
if (list.length === 0)
return null;
if (length === 0)
ret = null;
else if (objectMode)
ret = list.shift();
else if (!n || n >= length) {
// read it all, truncate the array.
if (stringMode)
ret = list.join('');
else
ret = Buffer.concat(list, length);
list.length = 0;
} else {
// read just some of it.
if (n < list[0].length) {
// just take a part of the first list item.
// slice is the same for buffers and strings.
var buf = list[0];
ret = buf.slice(0, n);
list[0] = buf.slice(n);
} else if (n === list[0].length) {
// first list is a perfect match
ret = list.shift();
} else {
// complex case.
// we have enough to cover it, but it spans past the first buffer.
if (stringMode)
ret = '';
else
ret = new Buffer(n);
var c = 0;
for (var i = 0, l = list.length; i < l && c < n; i++) {
var buf = list[0];
var cpy = Math.min(n - c, buf.length);
if (stringMode)
ret += buf.slice(0, cpy);
else
buf.copy(ret, c, 0, cpy);
if (cpy < buf.length)
list[0] = buf.slice(cpy);
else
list.shift();
c += cpy;
}
}
}
return ret;
}
function endReadable(stream) {
var state = stream._readableState;
// If we get here before consuming all the bytes, then that is a
// bug in node. Should never happen.
if (state.length > 0)
throw new Error('endReadable called on non-empty stream');
if (!state.endEmitted) {
state.ended = true;
process.nextTick(function() {
// Check that we didn't get one last unshift.
if (!state.endEmitted && state.length === 0) {
state.endEmitted = true;
stream.readable = false;
stream.emit('end');
}
});
}
}
function forEach (xs, f) {
for (var i = 0, l = xs.length; i < l; i++) {
f(xs[i], i);
}
}
function indexOf (xs, x) {
for (var i = 0, l = xs.length; i < l; i++) {
if (xs[i] === x) return i;
}
return -1;
}
}).call(this,undefined)
},{"./_stream_duplex":288,"buffer":68,"core-util-is":77,"events":67,"inherits":122,"isarray":124,"stream":301,"string_decoder/":302,"util":66}],291:[function(require,module,exports){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// a transform stream is a readable/writable stream where you do
// something with the data. Sometimes it's called a "filter",
// but that's not a great name for it, since that implies a thing where
// some bits pass through, and others are simply ignored. (That would
// be a valid example of a transform, of course.)
//
// While the output is causally related to the input, it's not a
// necessarily symmetric or synchronous transformation. For example,
// a zlib stream might take multiple plain-text writes(), and then
// emit a single compressed chunk some time in the future.
//
// Here's how this works:
//
// The Transform stream has all the aspects of the readable and writable
// stream classes. When you write(chunk), that calls _write(chunk,cb)
// internally, and returns false if there's a lot of pending writes
// buffered up. When you call read(), that calls _read(n) until
// there's enough pending readable data buffered up.
//
// In a transform stream, the written data is placed in a buffer. When
// _read(n) is called, it transforms the queued up data, calling the
// buffered _write cb's as it consumes chunks. If consuming a single
// written chunk would result in multiple output chunks, then the first
// outputted bit calls the readcb, and subsequent chunks just go into
// the read buffer, and will cause it to emit 'readable' if necessary.
//
// This way, back-pressure is actually determined by the reading side,
// since _read has to be called to start processing a new chunk. However,
// a pathological inflate type of transform can cause excessive buffering
// here. For example, imagine a stream where every byte of input is
// interpreted as an integer from 0-255, and then results in that many
// bytes of output. Writing the 4 bytes {ff,ff,ff,ff} would result in
// 1kb of data being output. In this case, you could write a very small
// amount of input, and end up with a very large amount of output. In
// such a pathological inflating mechanism, there'd be no way to tell
// the system to stop doing the transform. A single 4MB write could
// cause the system to run out of memory.
//
// However, even in such a pathological case, only a single written chunk
// would be consumed, and then the rest would wait (un-transformed) until
// the results of the previous transformed chunk were consumed.
module.exports = Transform;
var Duplex = require('./_stream_duplex');
/**/
var util = require('core-util-is');
util.inherits = require('inherits');
/* */
util.inherits(Transform, Duplex);
function TransformState(options, stream) {
this.afterTransform = function(er, data) {
return afterTransform(stream, er, data);
};
this.needTransform = false;
this.transforming = false;
this.writecb = null;
this.writechunk = null;
}
function afterTransform(stream, er, data) {
var ts = stream._transformState;
ts.transforming = false;
var cb = ts.writecb;
if (!cb)
return stream.emit('error', new Error('no writecb in Transform class'));
ts.writechunk = null;
ts.writecb = null;
if (!util.isNullOrUndefined(data))
stream.push(data);
if (cb)
cb(er);
var rs = stream._readableState;
rs.reading = false;
if (rs.needReadable || rs.length < rs.highWaterMark) {
stream._read(rs.highWaterMark);
}
}
function Transform(options) {
if (!(this instanceof Transform))
return new Transform(options);
Duplex.call(this, options);
this._transformState = new TransformState(options, this);
// when the writable side finishes, then flush out anything remaining.
var stream = this;
// start out asking for a readable event once data is transformed.
this._readableState.needReadable = true;
// we have implemented the _read method, and done the other things
// that Readable wants before the first _read call, so unset the
// sync guard flag.
this._readableState.sync = false;
this.once('prefinish', function() {
if (util.isFunction(this._flush))
this._flush(function(er) {
done(stream, er);
});
else
done(stream);
});
}
Transform.prototype.push = function(chunk, encoding) {
this._transformState.needTransform = false;
return Duplex.prototype.push.call(this, chunk, encoding);
};
// This is the part where you do stuff!
// override this function in implementation classes.
// 'chunk' is an input chunk.
//
// Call `push(newChunk)` to pass along transformed output
// to the readable side. You may call 'push' zero or more times.
//
// Call `cb(err)` when you are done with this chunk. If you pass
// an error, then that'll put the hurt on the whole operation. If you
// never call cb(), then you'll never get another chunk.
Transform.prototype._transform = function(chunk, encoding, cb) {
throw new Error('not implemented');
};
Transform.prototype._write = function(chunk, encoding, cb) {
var ts = this._transformState;
ts.writecb = cb;
ts.writechunk = chunk;
ts.writeencoding = encoding;
if (!ts.transforming) {
var rs = this._readableState;
if (ts.needTransform ||
rs.needReadable ||
rs.length < rs.highWaterMark)
this._read(rs.highWaterMark);
}
};
// Doesn't matter what the args are here.
// _transform does all the work.
// That we got here means that the readable side wants more data.
Transform.prototype._read = function(n) {
var ts = this._transformState;
if (!util.isNull(ts.writechunk) && ts.writecb && !ts.transforming) {
ts.transforming = true;
this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform);
} else {
// mark that we need a transform, so that any data that comes in
// will get processed, now that we've asked for it.
ts.needTransform = true;
}
};
function done(stream, er) {
if (er)
return stream.emit('error', er);
// if there's nothing in the write buffer, then that means
// that nothing more will ever be provided
var ws = stream._writableState;
var ts = stream._transformState;
if (ws.length)
throw new Error('calling transform done when ws.length != 0');
if (ts.transforming)
throw new Error('calling transform done when still transforming');
return stream.push(null);
}
},{"./_stream_duplex":288,"core-util-is":77,"inherits":122}],292:[function(require,module,exports){
(function (process){
// Copyright Joyent, Inc. and other Node contributors.
//
// Permission is hereby granted, free of charge, to any person obtaining a
// copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit
// persons to whom the Software is furnished to do so, subject to the
// following conditions:
//
// The above copyright notice and this permission notice shall be included
// in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
// USE OR OTHER DEALINGS IN THE SOFTWARE.
// A bit simpler than readable streams.
// Implement an async ._write(chunk, cb), and it'll handle all
// the drain event emission and buffering.
module.exports = Writable;
/**/
var Buffer = require('buffer').Buffer;
/* */
Writable.WritableState = WritableState;
/**/
var util = require('core-util-is');
util.inherits = require('inherits');
/* */
var Stream = require('stream');
util.inherits(Writable, Stream);
function WriteReq(chunk, encoding, cb) {
this.chunk = chunk;
this.encoding = encoding;
this.callback = cb;
}
function WritableState(options, stream) {
var Duplex = require('./_stream_duplex');
options = options || {};
// the point at which write() starts returning false
// Note: 0 is a valid value, means that we always return false if
// the entire buffer is not flushed immediately on write()
var hwm = options.highWaterMark;
var defaultHwm = options.objectMode ? 16 : 16 * 1024;
this.highWaterMark = (hwm || hwm === 0) ? hwm : defaultHwm;
// object stream flag to indicate whether or not this stream
// contains buffers or objects.
this.objectMode = !!options.objectMode;
if (stream instanceof Duplex)
this.objectMode = this.objectMode || !!options.writableObjectMode;
// cast to ints.
this.highWaterMark = ~~this.highWaterMark;
this.needDrain = false;
// at the start of calling end()
this.ending = false;
// when end() has been called, and returned
this.ended = false;
// when 'finish' is emitted
this.finished = false;
// should we decode strings into buffers before passing to _write?
// this is here so that some node-core streams can optimize string
// handling at a lower level.
var noDecode = options.decodeStrings === false;
this.decodeStrings = !noDecode;
// Crypto is kind of old and crusty. Historically, its default string
// encoding is 'binary' so we have to make this configurable.
// Everything else in the universe uses 'utf8', though.
this.defaultEncoding = options.defaultEncoding || 'utf8';
// not an actual buffer we keep track of, but a measurement
// of how much we're waiting to get pushed to some underlying
// socket or file.
this.length = 0;
// a flag to see when we're in the middle of a write.
this.writing = false;
// when true all writes will be buffered until .uncork() call
this.corked = 0;
// a flag to be able to tell if the onwrite cb is called immediately,
// or on a later tick. We set this to true at first, because any
// actions that shouldn't happen until "later" should generally also
// not happen before the first write call.
this.sync = true;
// a flag to know if we're processing previously buffered items, which
// may call the _write() callback in the same tick, so that we don't
// end up in an overlapped onwrite situation.
this.bufferProcessing = false;
// the callback that's passed to _write(chunk,cb)
this.onwrite = function(er) {
onwrite(stream, er);
};
// the callback that the user supplies to write(chunk,encoding,cb)
this.writecb = null;
// the amount that is being written when _write is called.
this.writelen = 0;
this.buffer = [];
// number of pending user-supplied write callbacks
// this must be 0 before 'finish' can be emitted
this.pendingcb = 0;
// emit prefinish if the only thing we're waiting for is _write cbs
// This is relevant for synchronous Transform streams
this.prefinished = false;
// True if the error was already emitted and should not be thrown again
this.errorEmitted = false;
}
function Writable(options) {
var Duplex = require('./_stream_duplex');
// Writable ctor is applied to Duplexes, though they're not
// instanceof Writable, they're instanceof Readable.
if (!(this instanceof Writable) && !(this instanceof Duplex))
return new Writable(options);
this._writableState = new WritableState(options, this);
// legacy.
this.writable = true;
Stream.call(this);
}
// Otherwise people can pipe Writable streams, which is just wrong.
Writable.prototype.pipe = function() {
this.emit('error', new Error('Cannot pipe. Not readable.'));
};
function writeAfterEnd(stream, state, cb) {
var er = new Error('write after end');
// TODO: defer error events consistently everywhere, not just the cb
stream.emit('error', er);
process.nextTick(function() {
cb(er);
});
}
// If we get something that is not a buffer, string, null, or undefined,
// and we're not in objectMode, then that's an error.
// Otherwise stream chunks are all considered to be of length=1, and the
// watermarks determine how many objects to keep in the buffer, rather than
// how many bytes or characters.
function validChunk(stream, state, chunk, cb) {
var valid = true;
if (!util.isBuffer(chunk) &&
!util.isString(chunk) &&
!util.isNullOrUndefined(chunk) &&
!state.objectMode) {
var er = new TypeError('Invalid non-string/buffer chunk');
stream.emit('error', er);
process.nextTick(function() {
cb(er);
});
valid = false;
}
return valid;
}
Writable.prototype.write = function(chunk, encoding, cb) {
var state = this._writableState;
var ret = false;
if (util.isFunction(encoding)) {
cb = encoding;
encoding = null;
}
if (util.isBuffer(chunk))
encoding = 'buffer';
else if (!encoding)
encoding = state.defaultEncoding;
if (!util.isFunction(cb))
cb = function() {};
if (state.ended)
writeAfterEnd(this, state, cb);
else if (validChunk(this, state, chunk, cb)) {
state.pendingcb++;
ret = writeOrBuffer(this, state, chunk, encoding, cb);
}
return ret;
};
Writable.prototype.cork = function() {
var state = this._writableState;
state.corked++;
};
Writable.prototype.uncork = function() {
var state = this._writableState;
if (state.corked) {
state.corked--;
if (!state.writing &&
!state.corked &&
!state.finished &&
!state.bufferProcessing &&
state.buffer.length)
clearBuffer(this, state);
}
};
function decodeChunk(state, chunk, encoding) {
if (!state.objectMode &&
state.decodeStrings !== false &&
util.isString(chunk)) {
chunk = new Buffer(chunk, encoding);
}
return chunk;
}
// if we're already writing something, then just put this
// in the queue, and wait our turn. Otherwise, call _write
// If we return false, then we need a drain event, so set that flag.
function writeOrBuffer(stream, state, chunk, encoding, cb) {
chunk = decodeChunk(state, chunk, encoding);
if (util.isBuffer(chunk))
encoding = 'buffer';
var len = state.objectMode ? 1 : chunk.length;
state.length += len;
var ret = state.length < state.highWaterMark;
// we must ensure that previous needDrain will not be reset to false.
if (!ret)
state.needDrain = true;
if (state.writing || state.corked)
state.buffer.push(new WriteReq(chunk, encoding, cb));
else
doWrite(stream, state, false, len, chunk, encoding, cb);
return ret;
}
function doWrite(stream, state, writev, len, chunk, encoding, cb) {
state.writelen = len;
state.writecb = cb;
state.writing = true;
state.sync = true;
if (writev)
stream._writev(chunk, state.onwrite);
else
stream._write(chunk, encoding, state.onwrite);
state.sync = false;
}
function onwriteError(stream, state, sync, er, cb) {
if (sync)
process.nextTick(function() {
state.pendingcb--;
cb(er);
});
else {
state.pendingcb--;
cb(er);
}
stream._writableState.errorEmitted = true;
stream.emit('error', er);
}
function onwriteStateUpdate(state) {
state.writing = false;
state.writecb = null;
state.length -= state.writelen;
state.writelen = 0;
}
function onwrite(stream, er) {
var state = stream._writableState;
var sync = state.sync;
var cb = state.writecb;
onwriteStateUpdate(state);
if (er)
onwriteError(stream, state, sync, er, cb);
else {
// Check if we're actually ready to finish, but don't emit yet
var finished = needFinish(stream, state);
if (!finished &&
!state.corked &&
!state.bufferProcessing &&
state.buffer.length) {
clearBuffer(stream, state);
}
if (sync) {
process.nextTick(function() {
afterWrite(stream, state, finished, cb);
});
} else {
afterWrite(stream, state, finished, cb);
}
}
}
function afterWrite(stream, state, finished, cb) {
if (!finished)
onwriteDrain(stream, state);
state.pendingcb--;
cb();
finishMaybe(stream, state);
}
// Must force callback to be called on nextTick, so that we don't
// emit 'drain' before the write() consumer gets the 'false' return
// value, and has a chance to attach a 'drain' listener.
function onwriteDrain(stream, state) {
if (state.length === 0 && state.needDrain) {
state.needDrain = false;
stream.emit('drain');
}
}
// if there's something in the buffer waiting, then process it
function clearBuffer(stream, state) {
state.bufferProcessing = true;
if (stream._writev && state.buffer.length > 1) {
// Fast case, write everything using _writev()
var cbs = [];
for (var c = 0; c < state.buffer.length; c++)
cbs.push(state.buffer[c].callback);
// count the one we are adding, as well.
// TODO(isaacs) clean this up
state.pendingcb++;
doWrite(stream, state, true, state.length, state.buffer, '', function(err) {
for (var i = 0; i < cbs.length; i++) {
state.pendingcb--;
cbs[i](err);
}
});
// Clear buffer
state.buffer = [];
} else {
// Slow case, write chunks one-by-one
for (var c = 0; c < state.buffer.length; c++) {
var entry = state.buffer[c];
var chunk = entry.chunk;
var encoding = entry.encoding;
var cb = entry.callback;
var len = state.objectMode ? 1 : chunk.length;
doWrite(stream, state, false, len, chunk, encoding, cb);
// if we didn't call the onwrite immediately, then
// it means that we need to wait until it does.
// also, that means that the chunk and cb are currently
// being processed, so move the buffer counter past them.
if (state.writing) {
c++;
break;
}
}
if (c < state.buffer.length)
state.buffer = state.buffer.slice(c);
else
state.buffer.length = 0;
}
state.bufferProcessing = false;
}
Writable.prototype._write = function(chunk, encoding, cb) {
cb(new Error('not implemented'));
};
Writable.prototype._writev = null;
Writable.prototype.end = function(chunk, encoding, cb) {
var state = this._writableState;
if (util.isFunction(chunk)) {
cb = chunk;
chunk = null;
encoding = null;
} else if (util.isFunction(encoding)) {
cb = encoding;
encoding = null;
}
if (!util.isNullOrUndefined(chunk))
this.write(chunk, encoding);
// .end() fully uncorks
if (state.corked) {
state.corked = 1;
this.uncork();
}
// ignore unnecessary end() calls.
if (!state.ending && !state.finished)
endWritable(this, state, cb);
};
function needFinish(stream, state) {
return (state.ending &&
state.length === 0 &&
!state.finished &&
!state.writing);
}
function prefinish(stream, state) {
if (!state.prefinished) {
state.prefinished = true;
stream.emit('prefinish');
}
}
function finishMaybe(stream, state) {
var need = needFinish(stream, state);
if (need) {
if (state.pendingcb === 0) {
prefinish(stream, state);
state.finished = true;
stream.emit('finish');
} else
prefinish(stream, state);
}
return need;
}
function endWritable(stream, state, cb) {
state.ending = true;
finishMaybe(stream, state);
if (cb) {
if (state.finished)
process.nextTick(cb);
else
stream.once('finish', cb);
}
state.ended = true;
}
}).call(this,undefined)
},{"./_stream_duplex":288,"buffer":68,"core-util-is":77,"inherits":122,"stream":301}],293:[function(require,module,exports){
module.exports = require("./lib/_stream_passthrough.js")
},{"./lib/_stream_passthrough.js":289}],294:[function(require,module,exports){
(function (process){
exports = module.exports = require('./lib/_stream_readable.js');
exports.Stream = require('stream');
exports.Readable = exports;
exports.Writable = require('./lib/_stream_writable.js');
exports.Duplex = require('./lib/_stream_duplex.js');
exports.Transform = require('./lib/_stream_transform.js');
exports.PassThrough = require('./lib/_stream_passthrough.js');
if (!process.browser && process.env.READABLE_STREAM === 'disable') {
module.exports = require('stream');
}
}).call(this,undefined)
},{"./lib/_stream_duplex.js":288,"./lib/_stream_passthrough.js":289,"./lib/_stream_readable.js":290,"./lib/_stream_transform.js":291,"./lib/_stream_writable.js":292,"stream":301}],295:[function(require,module,exports){
module.exports = require("./lib/_stream_transform.js")
},{"./lib/_stream_transform.js":291}],296:[function(require,module,exports){
module.exports = require("./lib/_stream_writable.js")
},{"./lib/_stream_writable.js":292}],297:[function(require,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 = require("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 = require('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++ //
, SCRIPT : S++ //