@progress/kendo-ui
Version:
This package is part of the [Kendo UI for jQuery](http://www.telerik.com/kendo-ui) suite.
1,778 lines (1,414 loc) • 312 kB
JavaScript
module.exports =
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId])
/******/ return installedModules[moduleId].exports;
/******/ // Create a new module (and put it into the cache)
/******/ var module = installedModules[moduleId] = {
/******/ exports: {},
/******/ id: moduleId,
/******/ loaded: false
/******/ };
/******/ // Execute the module function
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
/******/ // Flag the module as loaded
/******/ module.loaded = true;
/******/ // Return the exports of the module
/******/ return module.exports;
/******/ }
/******/ // expose the modules object (__webpack_modules__)
/******/ __webpack_require__.m = modules;
/******/ // expose the module cache
/******/ __webpack_require__.c = installedModules;
/******/ // __webpack_public_path__
/******/ __webpack_require__.p = "";
/******/ // Load entry module and return exports
/******/ return __webpack_require__(0);
/******/ })
/************************************************************************/
/******/ ({
/***/ 0:
/***/ (function(module, exports, __webpack_require__) {
__webpack_require__(946);
module.exports = __webpack_require__(946);
/***/ }),
/***/ 3:
/***/ (function(module, exports) {
module.exports = function() { throw new Error("define cannot be used indirect"); };
/***/ }),
/***/ 946:
/***/ (function(module, exports, __webpack_require__) {
var __WEBPACK_AMD_DEFINE_FACTORY__, __WEBPACK_AMD_DEFINE_ARRAY__, __WEBPACK_AMD_DEFINE_RESULT__;/***********************************************************************
* WARNING: this file is auto-generated. If you change it directly,
* your modifications will eventually be lost. The source code is in
* `kendo-drawing` repository, you should make your changes there and
* run `src-modules/sync.sh` in this repository.
*/
(function(f, define){
!(__WEBPACK_AMD_DEFINE_ARRAY__ = [ __webpack_require__(947), __webpack_require__(948), __webpack_require__(949) ], __WEBPACK_AMD_DEFINE_FACTORY__ = (f), __WEBPACK_AMD_DEFINE_RESULT__ = (typeof __WEBPACK_AMD_DEFINE_FACTORY__ === 'function' ? (__WEBPACK_AMD_DEFINE_FACTORY__.apply(exports, __WEBPACK_AMD_DEFINE_ARRAY__)) : __WEBPACK_AMD_DEFINE_FACTORY__), __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
})(function(){
(function ($) {
/* jshint eqnull:true */
/* jshint -W058 */
/* jshint -W069 */
/* jshint latedef: nofunc */
window.kendo = window.kendo || {};
var kendoDrawing = kendo.drawing;
var kendoDrawingUtil = kendoDrawing.util;
var Class = kendo.Class;
var kendoUtil = kendo.util;
var support = kendo.support;
var supportBrowser = support.browser;
var createPromise = kendoDrawingUtil.createPromise;
var promiseAll = kendoDrawingUtil.promiseAll;
var ObserversMixin = {
extend: function(proto) {
var this$1 = this;
for (var method in this) {
if (method !== "extend") {
proto[method] = this$1[method];
}
}
},
observers: function() {
this._observers = this._observers || [];
return this._observers;
},
addObserver: function(element) {
if (!this._observers) {
this._observers = [ element ];
} else {
this._observers.push(element);
}
return this;
},
removeObserver: function(element) {
var observers = this.observers();
var index = observers.indexOf(element);
if (index !== -1) {
observers.splice(index, 1);
}
return this;
},
trigger: function(methodName, event) {
var observers = this._observers;
if (observers && !this._suspended) {
for (var idx = 0; idx < observers.length; idx++) {
var observer = observers[idx];
if (observer[methodName]) {
observer[methodName](event);
}
}
}
return this;
},
optionsChange: function(e) {
if (e === void 0) { e = {}; }
e.element = this;
this.trigger("optionsChange", e);
},
geometryChange: function() {
this.trigger("geometryChange", {
element: this
});
},
suspend: function() {
this._suspended = (this._suspended || 0) + 1;
return this;
},
resume: function() {
this._suspended = Math.max((this._suspended || 0) - 1, 0);
return this;
},
_observerField: function(field, value) {
if (this[field]) {
this[field].removeObserver(this);
}
this[field] = value;
value.addObserver(this);
}
};
function append(first, second) {
first.push.apply(first, second);
return first;
}
/* eslint-disable key-spacing,no-multi-spaces,no-param-reassign */
var literals = {
1 : "i", 10 : "x", 100 : "c",
2 : "ii", 20 : "xx", 200 : "cc",
3 : "iii", 30 : "xxx", 300 : "ccc",
4 : "iv", 40 : "xl", 400 : "cd",
5 : "v", 50 : "l", 500 : "d",
6 : "vi", 60 : "lx", 600 : "dc",
7 : "vii", 70 : "lxx", 700 : "dcc",
8 : "viii", 80 : "lxxx", 800 : "dccc",
9 : "ix", 90 : "xc", 900 : "cm",
1000 : "m"
};
function arabicToRoman(n) {
var values = [ 1000,
900 , 800, 700, 600, 500, 400, 300, 200, 100,
90 , 80 , 70 , 60 , 50 , 40 , 30 , 20 , 10 ,
9 , 8 , 7 , 6 , 5 , 4 , 3 , 2 , 1 ];
var roman = "";
while (n > 0) {
if (n < values[0]) {
values.shift();
} else {
roman += literals[values[0]];
n -= values[0];
}
}
return roman;
}
var UNDEFINED = "undefined";
function defined(value) {
return typeof value !== UNDEFINED;
}
var defId = 1;
function definitionId() {
return "kdef" + defId++;
}
var DEG_TO_RAD = Math.PI / 180;
var MAX_NUM = Number.MAX_VALUE;
var MIN_NUM = -Number.MAX_VALUE;
function deg(radians) {
return radians / DEG_TO_RAD;
}
var fromCharCode = String.fromCharCode;
// Encodes a string as UTF-8
function encodeUTF8(input) {
var output = "";
for (var i = 0; i < input.length; i++) {
var c = input.charCodeAt(i);
if (c < 0x80) {
// One byte
output += fromCharCode(c);
} else if (c < 0x800) {
// Two bytes
output += fromCharCode(0xC0 | (c >>> 6));
output += fromCharCode(0x80 | (c & 0x3f));
} else if (c < 0x10000) {
// Three bytes
output += fromCharCode(0xE0 | (c >>> 12));
output += fromCharCode(0x80 | (c >>> 6 & 0x3f));
output += fromCharCode(0x80 | (c & 0x3f));
}
}
return output;
}
// Encodes a string as UTF-16 big-endian
var KEY_STR = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
function encodeBase64(input) {
var output = "";
var i = 0;
var utfInput = encodeUTF8(input);
while (i < utfInput.length) {
var chr1 = utfInput.charCodeAt(i++);
var chr2 = utfInput.charCodeAt(i++);
var chr3 = utfInput.charCodeAt(i++);
var enc1 = chr1 >> 2;
var enc2 = ((chr1 & 3) << 4) | (chr2 >> 4);
var enc3 = ((chr2 & 15) << 2) | (chr3 >> 6);
var enc4 = chr3 & 63;
if (isNaN(chr2)) {
enc3 = enc4 = 64;
} else if (isNaN(chr3)) {
enc4 = 64;
}
output = output +
KEY_STR.charAt(enc1) + KEY_STR.charAt(enc2) +
KEY_STR.charAt(enc3) + KEY_STR.charAt(enc4);
}
return output;
}
function eventCoordinates(e) {
if (defined((e.x || {}).location)) {
return {
x: e.x.location,
y: e.y.location
};
}
return {
x: e.pageX || e.clientX || 0,
y: e.pageY || e.clientY || 0
};
}
function eventElement(e) {
if (e === void 0) { e = {}; }
return e.touch ? e.touch.initialTouch : e.target;
}
function isTransparent(color) {
return color === "" || color === null || color === "none" || color === "transparent" || !defined(color);
}
function last(array) {
if (array) {
return array[array.length - 1];
}
}
function limitValue(value, min, max) {
return Math.max(Math.min(value, max), min);
}
/* eslint-disable no-multi-spaces, key-spacing, indent, camelcase, space-before-blocks, eqeqeq, brace-style */
/* eslint-disable space-infix-ops, space-before-function-paren, array-bracket-spacing, object-curly-spacing */
/* eslint-disable no-nested-ternary, max-params, default-case, no-else-return, no-empty */
/* eslint-disable no-param-reassign, no-var, block-scoped-var */
// mergeSort is stable.
function mergeSort(a, cmp) {
if (a.length < 2) {
return a.slice();
}
function merge(a, b) {
var r = [], ai = 0, bi = 0, i = 0;
while (ai < a.length && bi < b.length) {
if (cmp(a[ai], b[bi]) <= 0) {
r[i++] = a[ai++];
} else {
r[i++] = b[bi++];
}
}
if (ai < a.length) {
r.push.apply(r, a.slice(ai));
}
if (bi < b.length) {
r.push.apply(r, b.slice(bi));
}
return r;
}
return (function sort(a) {
if (a.length <= 1) {
return a;
}
var m = Math.floor(a.length / 2);
var left = a.slice(0, m);
var right = a.slice(m);
left = sort(left);
right = sort(right);
return merge(left, right);
})(a);
}
function rad(degrees) {
return degrees * DEG_TO_RAD;
}
function pow(p) {
if (p) {
return Math.pow(10, p);
}
return 1;
}
function round(value, precision) {
var power = pow(precision);
return Math.round(value * power) / power;
}
function valueOrDefault(value, defaultValue) {
return defined(value) ? value : defaultValue;
}
function bindEvents(element, events) {
for (var eventName in events) {
var eventNames = eventName.trim().split(" ");
for (var idx = 0; idx < eventNames.length; idx++) {
element.addEventListener(eventNames[idx], events[eventName], false);
}
}
}
function elementOffset(element) {
var box = element.getBoundingClientRect();
var documentElement = document.documentElement;
return {
top: box.top + (window.pageYOffset || documentElement.scrollTop) - (documentElement.clientTop || 0),
left: box.left + (window.pageXOffset || documentElement.scrollLeft) - (documentElement.clientLeft || 0)
};
}
function elementStyles(element, styles) {
var result = {};
var style = window.getComputedStyle(element) || {};
var stylesArray = Array.isArray(styles) ? styles : [ styles ];
for (var idx = 0; idx < stylesArray.length; idx++) {
var field = stylesArray[idx];
result[field] = style[field];
}
return result;
}
function getPixels(value) {
if (isNaN(value)) {
return value;
}
return value + "px";
}
function elementSize(element, size) {
if (size) {
var width = size.width;
var height = size.height;
if (defined(width)) {
element.style.width = getPixels(width);
}
if (defined(height)) {
element.style.height = getPixels(height);
}
} else {
var size$1 = elementStyles(element, [ 'width', 'height' ]);
return {
width: parseInt(size$1.width, 10),
height: parseInt(size$1.height, 10)
};
}
}
function unbindEvents(element, events) {
if (events === void 0) { events = {}; }
for (var name in events) {
var eventNames = name.trim().split(" ");
for (var idx = 0; idx < eventNames.length; idx++) {
element.removeEventListener(eventNames[idx], events[name], false);
}
}
}
function elementPadding(element) {
var ref = elementStyles(element, [ "paddingLeft", "paddingTop" ]);
var paddingLeft = ref.paddingLeft;
var paddingTop = ref.paddingTop;
return {
top: parseFloat(paddingTop),
left: parseFloat(paddingLeft)
};
}
function setAccessor(field) {
return function(value) {
if (this[field] !== value) {
this[field] = value;
this.geometryChange();
}
return this;
};
}
function getAccessor(field) {
return function() {
return this[field];
};
}
function defineAccessors(fn, fields) {
for (var i = 0; i < fields.length; i++) {
var name = fields[i];
var capitalized = name.charAt(0).toUpperCase() +
name.substring(1, name.length);
fn["set" + capitalized] = setAccessor(name);
fn["get" + capitalized] = getAccessor(name);
}
}
var Matrix = Class.extend({
init: function(a, b, c, d, e, f) {
if (a === void 0) { a = 0; }
if (b === void 0) { b = 0; }
if (c === void 0) { c = 0; }
if (d === void 0) { d = 0; }
if (e === void 0) { e = 0; }
if (f === void 0) { f = 0; }
this.a = a;
this.b = b;
this.c = c;
this.d = d;
this.e = e;
this.f = f;
},
multiplyCopy: function(matrix) {
return new Matrix(
this.a * matrix.a + this.c * matrix.b,
this.b * matrix.a + this.d * matrix.b,
this.a * matrix.c + this.c * matrix.d,
this.b * matrix.c + this.d * matrix.d,
this.a * matrix.e + this.c * matrix.f + this.e,
this.b * matrix.e + this.d * matrix.f + this.f
);
},
invert: function() {
var ref = this;
var a = ref.a;
var b = ref.b;
var d = ref.c;
var e = ref.d;
var g = ref.e;
var h = ref.f;
var det = a * e - b * d;
if (det === 0) {
return null;
}
return new Matrix(e / det, -b / det, -d / det, a / det,
(d * h - e * g) / det, (b * g - a * h) / det);
},
clone: function() {
return new Matrix(this.a, this.b, this.c, this.d, this.e, this.f);
},
equals: function(other) {
if (!other) {
return false;
}
return this.a === other.a && this.b === other.b &&
this.c === other.c && this.d === other.d &&
this.e === other.e && this.f === other.f;
},
round: function(precision) {
this.a = round(this.a, precision);
this.b = round(this.b, precision);
this.c = round(this.c, precision);
this.d = round(this.d, precision);
this.e = round(this.e, precision);
this.f = round(this.f, precision);
return this;
},
toArray: function(precision) {
var result = [ this.a, this.b, this.c, this.d, this.e, this.f ];
if (defined(precision)) {
for (var i = 0; i < result.length; i++) {
result[i] = round(result[i], precision);
}
}
return result;
},
toString: function(precision, separator) {
if (separator === void 0) { separator = ","; }
return this.toArray(precision).join(separator);
}
});
Matrix.translate = function(x, y) {
return new Matrix(1, 0, 0, 1, x, y);
};
Matrix.unit = function() {
return new Matrix(1, 0, 0, 1, 0, 0);
};
Matrix.rotate = function(angle, x, y) {
var matrix = new Matrix();
matrix.a = Math.cos(rad(angle));
matrix.b = Math.sin(rad(angle));
matrix.c = -matrix.b;
matrix.d = matrix.a;
matrix.e = (x - x * matrix.a + y * matrix.b) || 0;
matrix.f = (y - y * matrix.a - x * matrix.b) || 0;
return matrix;
};
Matrix.scale = function(scaleX, scaleY) {
return new Matrix(scaleX, 0, 0, scaleY, 0, 0);
};
Matrix.IDENTITY = Matrix.unit();
function toMatrix(transformation) {
if (transformation && typeof transformation.matrix === "function") {
return transformation.matrix();
}
return transformation;
}
var Point = Class.extend({
init: function(x, y) {
this.x = x || 0;
this.y = y || 0;
},
equals: function(other) {
return other && other.x === this.x && other.y === this.y;
},
clone: function() {
return new Point(this.x, this.y);
},
rotate: function(angle, origin) {
var originPoint = Point.create(origin) || Point.ZERO;
return this.transform(Matrix.rotate(angle, originPoint.x, originPoint.y));
},
translate: function(x, y) {
this.x += x;
this.y += y;
this.geometryChange();
return this;
},
translateWith: function(point) {
return this.translate(point.x, point.y);
},
move: function(x, y) {
this.x = this.y = 0;
return this.translate(x, y);
},
scale: function(scaleX, scaleY) {
if (scaleY === void 0) { scaleY = scaleX; }
this.x *= scaleX;
this.y *= scaleY;
this.geometryChange();
return this;
},
scaleCopy: function(scaleX, scaleY) {
return this.clone().scale(scaleX, scaleY);
},
transform: function(transformation) {
var matrix = toMatrix(transformation);
var ref = this;
var x = ref.x;
var y = ref.y;
this.x = matrix.a * x + matrix.c * y + matrix.e;
this.y = matrix.b * x + matrix.d * y + matrix.f;
this.geometryChange();
return this;
},
transformCopy: function(transformation) {
var point = this.clone();
if (transformation) {
point.transform(transformation);
}
return point;
},
distanceTo: function(point) {
var dx = this.x - point.x;
var dy = this.y - point.y;
return Math.sqrt(dx * dx + dy * dy);
},
round: function(digits) {
this.x = round(this.x, digits);
this.y = round(this.y, digits);
this.geometryChange();
return this;
},
toArray: function(digits) {
var doRound = defined(digits);
var x = doRound ? round(this.x, digits) : this.x;
var y = doRound ? round(this.y, digits) : this.y;
return [ x, y ];
},
toString: function(digits, separator) {
if (separator === void 0) { separator = " "; }
var ref = this;
var x = ref.x;
var y = ref.y;
if (defined(digits)) {
x = round(x, digits);
y = round(y, digits);
}
return x + separator + y;
}
});
Point.create = function(arg0, arg1) {
if (defined(arg0)) {
if (arg0 instanceof Point) {
return arg0;
} else if (arguments.length === 1 && arg0.length === 2) {
return new Point(arg0[0], arg0[1]);
}
return new Point(arg0, arg1);
}
};
Point.min = function() {
var arguments$1 = arguments;
var minX = MAX_NUM;
var minY = MAX_NUM;
for (var i = 0; i < arguments.length; i++) {
var point = arguments$1[i];
minX = Math.min(point.x, minX);
minY = Math.min(point.y, minY);
}
return new Point(minX, minY);
};
Point.max = function() {
var arguments$1 = arguments;
var maxX = MIN_NUM;
var maxY = MIN_NUM;
for (var i = 0; i < arguments.length; i++) {
var point = arguments$1[i];
maxX = Math.max(point.x, maxX);
maxY = Math.max(point.y, maxY);
}
return new Point(maxX, maxY);
};
Point.minPoint = function() {
return new Point(MIN_NUM, MIN_NUM);
};
Point.maxPoint = function() {
return new Point(MAX_NUM, MAX_NUM);
};
if (Object.defineProperties) {
Object.defineProperties(Point, {
ZERO: {
get: function() {
return new Point(0, 0);
}
}
});
}
defineAccessors(Point.prototype, [ "x", "y" ]);
ObserversMixin.extend(Point.prototype);
var Size = Class.extend({
init: function(width, height) {
this.width = width || 0;
this.height = height || 0;
},
equals: function(other) {
return other && other.width === this.width && other.height === this.height;
},
clone: function() {
return new Size(this.width, this.height);
},
toArray: function(digits) {
var doRound = defined(digits);
var width = doRound ? round(this.width, digits) : this.width;
var height = doRound ? round(this.height, digits) : this.height;
return [ width, height ];
}
});
Size.create = function(arg0, arg1) {
if (defined(arg0)) {
if (arg0 instanceof Size) {
return arg0;
} else if (arguments.length === 1 && arg0.length === 2) {
return new Size(arg0[0], arg0[1]);
}
return new Size(arg0, arg1);
}
};
if (Object.defineProperties) {
Object.defineProperties(Size, {
ZERO: {
get: function() {
return new Size(0, 0);
}
}
});
}
defineAccessors(Size.prototype, [ "width", "height" ]);
ObserversMixin.extend(Size.prototype);
var Rect = Class.extend({
init: function(origin, size) {
if (origin === void 0) { origin = new Point(); }
if (size === void 0) { size = new Size(); }
this.setOrigin(origin);
this.setSize(size);
},
clone: function() {
return new Rect(
this.origin.clone(),
this.size.clone()
);
},
equals: function(other) {
return other &&
other.origin.equals(this.origin) &&
other.size.equals(this.size);
},
setOrigin: function(value) {
this._observerField("origin", Point.create(value));
this.geometryChange();
return this;
},
getOrigin: function() {
return this.origin;
},
setSize: function(value) {
this._observerField("size", Size.create(value));
this.geometryChange();
return this;
},
getSize: function() {
return this.size;
},
width: function() {
return this.size.width;
},
height: function() {
return this.size.height;
},
topLeft: function() {
return this.origin.clone();
},
bottomRight: function() {
return this.origin.clone().translate(this.width(), this.height());
},
topRight: function() {
return this.origin.clone().translate(this.width(), 0);
},
bottomLeft: function() {
return this.origin.clone().translate(0, this.height());
},
center: function() {
return this.origin.clone().translate(this.width() / 2, this.height() / 2);
},
bbox: function(matrix) {
var tl = this.topLeft().transformCopy(matrix);
var tr = this.topRight().transformCopy(matrix);
var br = this.bottomRight().transformCopy(matrix);
var bl = this.bottomLeft().transformCopy(matrix);
return Rect.fromPoints(tl, tr, br, bl);
},
transformCopy: function(m) {
return Rect.fromPoints(
this.topLeft().transform(m),
this.bottomRight().transform(m)
);
},
expand: function(x, y) {
if (y === void 0) { y = x; }
this.size.width += 2 * x;
this.size.height += 2 * y;
this.origin.translate(-x, -y);
return this;
},
expandCopy: function(x, y) {
return this.clone().expand(x, y);
},
containsPoint: function(point) {
var origin = this.origin;
var bottomRight = this.bottomRight();
return !(point.x < origin.x || point.y < origin.y || bottomRight.x < point.x || bottomRight.y < point.y);
},
_isOnPath: function(point, width) {
var rectOuter = this.expandCopy(width, width);
var rectInner = this.expandCopy(-width, -width);
return rectOuter.containsPoint(point) && !rectInner.containsPoint(point);
}
});
Rect.fromPoints = function() {
var topLeft = Point.min.apply(null, arguments);
var bottomRight = Point.max.apply(null, arguments);
var size = new Size(
bottomRight.x - topLeft.x,
bottomRight.y - topLeft.y
);
return new Rect(topLeft, size);
};
Rect.union = function(a, b) {
return Rect.fromPoints(
Point.min(a.topLeft(), b.topLeft()),
Point.max(a.bottomRight(), b.bottomRight())
);
};
Rect.intersect = function(a, b) {
var rect1 = {
left: a.topLeft().x,
top: a.topLeft().y,
right: a.bottomRight().x,
bottom: a.bottomRight().y
};
var rect2 = {
left: b.topLeft().x,
top: b.topLeft().y,
right: b.bottomRight().x,
bottom: b.bottomRight().y
};
if (rect1.left <= rect2.right &&
rect2.left <= rect1.right &&
rect1.top <= rect2.bottom &&
rect2.top <= rect1.bottom) {
return Rect.fromPoints(
new Point(Math.max(rect1.left, rect2.left), Math.max(rect1.top, rect2.top)),
new Point(Math.min(rect1.right, rect2.right), Math.min(rect1.bottom, rect2.bottom))
);
}
};
ObserversMixin.extend(Rect.prototype);
function ellipseExtremeAngles(center, rx, ry, matrix) {
var extremeX = 0;
var extremeY = 0;
if (matrix) {
extremeX = Math.atan2(matrix.c * ry, matrix.a * rx);
if (matrix.b !== 0) {
extremeY = Math.atan2(matrix.d * ry, matrix.b * rx);
}
}
return {
x: extremeX,
y: extremeY
};
}
var PI_DIV_2 = Math.PI / 2;
var Circle = Class.extend({
init: function(center, radius) {
if (center === void 0) { center = new Point(); }
if (radius === void 0) { radius = 0; }
this.setCenter(center);
this.setRadius(radius);
},
setCenter: function(value) {
this._observerField("center", Point.create(value));
this.geometryChange();
return this;
},
getCenter: function() {
return this.center;
},
equals: function(other) {
return other &&
other.center.equals(this.center) &&
other.radius === this.radius;
},
clone: function() {
return new Circle(this.center.clone(), this.radius);
},
pointAt: function(angle) {
return this._pointAt(rad(angle));
},
bbox: function(matrix) {
var this$1 = this;
var extremeAngles = ellipseExtremeAngles(this.center, this.radius, this.radius, matrix);
var minPoint = Point.maxPoint();
var maxPoint = Point.minPoint();
for (var i = 0; i < 4; i++) {
var currentPointX = this$1._pointAt(extremeAngles.x + i * PI_DIV_2).transformCopy(matrix);
var currentPointY = this$1._pointAt(extremeAngles.y + i * PI_DIV_2).transformCopy(matrix);
var currentPoint = new Point(currentPointX.x, currentPointY.y);
minPoint = Point.min(minPoint, currentPoint);
maxPoint = Point.max(maxPoint, currentPoint);
}
return Rect.fromPoints(minPoint, maxPoint);
},
_pointAt: function(angle) {
var ref = this;
var center = ref.center;
var radius = ref.radius;
return new Point(
center.x + radius * Math.cos(angle),
center.y + radius * Math.sin(angle)
);
},
containsPoint: function(point) {
var ref = this;
var center = ref.center;
var radius = ref.radius;
var inCircle = Math.pow(point.x - center.x, 2) +
Math.pow(point.y - center.y, 2) <= Math.pow(radius, 2);
return inCircle;
},
_isOnPath: function(point, width) {
var ref = this;
var center = ref.center;
var radius = ref.radius;
var pointDistance = center.distanceTo(point);
return radius - width <= pointDistance && pointDistance <= radius + width;
}
});
defineAccessors(Circle.prototype, [ "radius" ]);
ObserversMixin.extend(Circle.prototype);
var PRECISION = 10;
function close(a, b, tolerance) {
if (tolerance === void 0) { tolerance = PRECISION; }
return round(Math.abs(a - b), tolerance) === 0;
}
function closeOrLess(a, b, tolerance) {
return a < b || close(a, b, tolerance);
}
function lineIntersection(p0, p1, p2, p3) {
var s1x = p1.x - p0.x;
var s2x = p3.x - p2.x;
var s1y = p1.y - p0.y;
var s2y = p3.y - p2.y;
var nx = p0.x - p2.x;
var ny = p0.y - p2.y;
var d = s1x * s2y - s2x * s1y;
var s = (s1x * ny - s1y * nx) / d;
var t = (s2x * ny - s2y * nx) / d;
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
return new Point(p0.x + t * s1x, p0.y + t * s1y);
}
}
var Transformation = Class.extend({
init: function(matrix) {
if (matrix === void 0) { matrix = Matrix.unit(); }
this._matrix = matrix;
},
clone: function() {
return new Transformation(
this._matrix.clone()
);
},
equals: function(other) {
return other &&
other._matrix.equals(this._matrix);
},
translate: function(x, y) {
this._matrix = this._matrix.multiplyCopy(Matrix.translate(x, y));
this._optionsChange();
return this;
},
scale: function(scaleX, scaleY, origin) {
if (scaleY === void 0) { scaleY = scaleX; }
if (origin === void 0) { origin = null; }
var originPoint = origin;
if (originPoint) {
originPoint = Point.create(originPoint);
this._matrix = this._matrix.multiplyCopy(Matrix.translate(originPoint.x, originPoint.y));
}
this._matrix = this._matrix.multiplyCopy(Matrix.scale(scaleX, scaleY));
if (originPoint) {
this._matrix = this._matrix.multiplyCopy(Matrix.translate(-originPoint.x, -originPoint.y));
}
this._optionsChange();
return this;
},
rotate: function(angle, origin) {
var originPoint = Point.create(origin) || Point.ZERO;
this._matrix = this._matrix.multiplyCopy(Matrix.rotate(angle, originPoint.x, originPoint.y));
this._optionsChange();
return this;
},
multiply: function(transformation) {
var matrix = toMatrix(transformation);
this._matrix = this._matrix.multiplyCopy(matrix);
this._optionsChange();
return this;
},
matrix: function(value) {
if (value) {
this._matrix = value;
this._optionsChange();
return this;
}
return this._matrix;
},
_optionsChange: function() {
this.optionsChange({
field: "transform",
value: this
});
}
});
ObserversMixin.extend(Transformation.prototype);
function transform(matrix) {
if (matrix === null) {
return null;
}
if (matrix instanceof Transformation) {
return matrix;
}
return new Transformation(matrix);
}
var MAX_INTERVAL = 45;
var pow$1 = Math.pow;
var Arc = Class.extend({
init: function(center, options) {
if (center === void 0) { center = new Point(); }
if (options === void 0) { options = {}; }
this.setCenter(center);
this.radiusX = options.radiusX;
this.radiusY = options.radiusY || options.radiusX;
this.startAngle = options.startAngle;
this.endAngle = options.endAngle;
this.anticlockwise = options.anticlockwise || false;
this.xRotation = options.xRotation;
},
clone: function() {
return new Arc(this.center, {
radiusX: this.radiusX,
radiusY: this.radiusY,
startAngle: this.startAngle,
endAngle: this.endAngle,
anticlockwise: this.anticlockwise
});
},
setCenter: function(value) {
this._observerField("center", Point.create(value));
this.geometryChange();
return this;
},
getCenter: function() {
return this.center;
},
pointAt: function(angle) {
var center = this.center;
var radian = rad(angle);
return new Point(
center.x + this.radiusX * Math.cos(radian),
center.y + this.radiusY * Math.sin(radian)
);
},
curvePoints: function() {
var this$1 = this;
var startAngle = this.startAngle;
var dir = this.anticlockwise ? -1 : 1;
var curvePoints = [ this.pointAt(startAngle) ];
var interval = this._arcInterval();
var intervalAngle = interval.endAngle - interval.startAngle;
var subIntervalsCount = Math.ceil(intervalAngle / MAX_INTERVAL);
var subIntervalAngle = intervalAngle / subIntervalsCount;
var currentAngle = startAngle;
var transformation;
if (this.xRotation) {
transformation = transform().rotate(this.xRotation, this.center);
}
for (var i = 1; i <= subIntervalsCount; i++) {
var nextAngle = currentAngle + dir * subIntervalAngle;
var points = this$1._intervalCurvePoints(currentAngle, nextAngle, transformation);
curvePoints.push(points.cp1, points.cp2, points.p2);
currentAngle = nextAngle;
}
return curvePoints;
},
bbox: function(matrix) {
var this$1 = this;
var interval = this._arcInterval();
var startAngle = interval.startAngle;
var endAngle = interval.endAngle;
var extremeAngles = ellipseExtremeAngles(this.center, this.radiusX, this.radiusY, matrix);
var extremeX = deg(extremeAngles.x);
var extremeY = deg(extremeAngles.y);
var endPoint = this.pointAt(endAngle).transformCopy(matrix);
var currentAngleX = bboxStartAngle(extremeX, startAngle);
var currentAngleY = bboxStartAngle(extremeY, startAngle);
var currentPoint = this.pointAt(startAngle).transformCopy(matrix);
var minPoint = Point.min(currentPoint, endPoint);
var maxPoint = Point.max(currentPoint, endPoint);
while (currentAngleX < endAngle || currentAngleY < endAngle) {
var currentPointX = (void 0);
if (currentAngleX < endAngle) {
currentPointX = this$1.pointAt(currentAngleX).transformCopy(matrix);
currentAngleX += 90;
}
var currentPointY = (void 0);
if (currentAngleY < endAngle) {
currentPointY = this$1.pointAt(currentAngleY).transformCopy(matrix);
currentAngleY += 90;
}
currentPoint = new Point(currentPointX.x, currentPointY.y);
minPoint = Point.min(minPoint, currentPoint);
maxPoint = Point.max(maxPoint, currentPoint);
}
return Rect.fromPoints(minPoint, maxPoint);
},
_arcInterval: function() {
var ref = this;
var startAngle = ref.startAngle;
var endAngle = ref.endAngle;
var anticlockwise = ref.anticlockwise;
if (anticlockwise) {
var oldStart = startAngle;
startAngle = endAngle;
endAngle = oldStart;
}
if (startAngle > endAngle || (anticlockwise && startAngle === endAngle)) {
endAngle += 360;
}
return {
startAngle: startAngle,
endAngle: endAngle
};
},
_intervalCurvePoints: function(startAngle, endAngle, transformation) {
var p1 = this.pointAt(startAngle);
var p2 = this.pointAt(endAngle);
var p1Derivative = this._derivativeAt(startAngle);
var p2Derivative = this._derivativeAt(endAngle);
var t = (rad(endAngle) - rad(startAngle)) / 3;
var cp1 = new Point(p1.x + t * p1Derivative.x, p1.y + t * p1Derivative.y);
var cp2 = new Point(p2.x - t * p2Derivative.x, p2.y - t * p2Derivative.y);
if (transformation) {
p1.transform(transformation);
p2.transform(transformation);
cp1.transform(transformation);
cp2.transform(transformation);
}
return {
p1: p1,
cp1: cp1,
cp2: cp2,
p2: p2
};
},
_derivativeAt: function(angle) {
var radian = rad(angle);
return new Point(-this.radiusX * Math.sin(radian), this.radiusY * Math.cos(radian));
},
containsPoint: function(point) {
var interval = this._arcInterval();
var intervalAngle = interval.endAngle - interval.startAngle;
var ref = this;
var center = ref.center;
var radiusX = ref.radiusX;
var radiusY = ref.radiusY;
var distance = center.distanceTo(point);
var angleRad = Math.atan2(point.y - center.y, point.x - center.x);
var pointRadius = (radiusX * radiusY) /
Math.sqrt(pow$1(radiusX, 2) * pow$1(Math.sin(angleRad), 2) + pow$1(radiusY, 2) * pow$1(Math.cos(angleRad), 2));
var startPoint = this.pointAt(this.startAngle).round(PRECISION);
var endPoint = this.pointAt(this.endAngle).round(PRECISION);
var intersection = lineIntersection(center, point.round(PRECISION), startPoint, endPoint);
var containsPoint;
if (intervalAngle < 180) {
containsPoint = intersection && closeOrLess(center.distanceTo(intersection), distance) && closeOrLess(distance, pointRadius);
} else {
var angle = calculateAngle(center.x, center.y, radiusX, radiusY, point.x, point.y);
if (angle !== 360) {
angle = (360 + angle) % 360;
}
var inAngleRange = interval.startAngle <= angle && angle <= interval.endAngle;
containsPoint = (inAngleRange && closeOrLess(distance, pointRadius)) || (!inAngleRange && (!intersection || intersection.equals(point)));
}
return containsPoint;
},
_isOnPath: function(point, width) {
var interval = this._arcInterval();
var center = this.center;
var angle = calculateAngle(center.x, center.y, this.radiusX, this.radiusY, point.x, point.y);
if (angle !== 360) {
angle = (360 + angle) % 360;
}
var inAngleRange = interval.startAngle <= angle && angle <= interval.endAngle;
return inAngleRange && this.pointAt(angle).distanceTo(point) <= width;
}
});
Arc.fromPoints = function(start, end, rx, ry, largeArc, swipe, rotation) {// eslint-disable-line max-params
var arcParameters = normalizeArcParameters({
x1: start.x,
y1: start.y,
x2: end.x,
y2: end.y,
rx: rx,
ry: ry,
largeArc: largeArc,
swipe: swipe,
rotation: rotation
});
return new Arc(arcParameters.center, {
startAngle: arcParameters.startAngle,
endAngle: arcParameters.endAngle,
radiusX: arcParameters.radiusX,
radiusY: arcParameters.radiusY,
xRotation: arcParameters.xRotation,
anticlockwise: swipe === 0
});
};
defineAccessors(Arc.prototype, [ "radiusX", "radiusY", "startAngle", "endAngle", "anticlockwise" ]);
ObserversMixin.extend(Arc.prototype);
function calculateAngle(cx, cy, rx, ry, x, y) {
var cos = round((x - cx) / rx, 3);
var sin = round((y - cy) / ry, 3);
return round(deg(Math.atan2(sin, cos)));
}
function normalizeArcParameters(parameters) {
var x1 = parameters.x1;
var y1 = parameters.y1;
var x2 = parameters.x2;
var y2 = parameters.y2;
var rx = parameters.rx;
var ry = parameters.ry;
var largeArc = parameters.largeArc;
var swipe = parameters.swipe;
var rotation = parameters.rotation; if (rotation === void 0) { rotation = 0; }
var radians = rad(rotation);
var cosine = Math.cos(radians);
var sine = Math.sin(radians);
var xT = cosine * (x1 - x2) / 2 + sine * (y1 - y2) / 2;
var yT = -sine * (x1 - x2) / 2 + cosine * (y1 - y2) / 2;
var sign = largeArc !== swipe ? 1 : -1;
var xt2 = Math.pow(xT, 2);
var yt2 = Math.pow(yT, 2);
var rx2 = Math.pow(rx, 2);
var ry2 = Math.pow(ry, 2);
var delta = xt2 / rx2 + yt2 / ry2;
if (delta > 1) {
delta = Math.sqrt(xt2 / rx2 + yt2 / ry2);
rx = delta * rx;
rx2 = Math.pow(rx, 2);
ry = delta * ry;
ry2 = Math.pow(ry, 2);
}
var constT = sign * Math.sqrt((rx2 * ry2 - rx2 * yt2 - ry2 * xt2) / (rx2 * yt2 + ry2 * xt2));
// due to rounding errors the value could become NaN even after radii correction
if (isNaN(constT)) {
constT = 0;
}
var cxT = constT * (rx * yT) / ry;
var cyT = - constT * (ry * xT) / rx;
var cx = cosine * cxT - sine * cyT + (x1 + x2) / 2;
var cy = sine * cxT + cosine * cyT + (y1 + y2) / 2;
var uX = (xT - cxT) / rx;
var uY = (yT - cyT) / ry;
var vX = -(xT + cxT) / rx;
var vY = -(yT + cyT) / ry;
var startAngle = (uY >= 0 ? 1 : -1) * deg(Math.acos(uX / Math.sqrt(uX * uX + uY * uY)));
var angleCosine = round((uX * vX + uY * vY) / (Math.sqrt(uX * uX + uY * uY) * Math.sqrt(vX * vX + vY * vY)), 10);
var angle = (uX * vY - uY * vX >= 0 ? 1 : -1) * deg(Math.acos(angleCosine));
if (!swipe && angle > 0) {
angle -= 360;
}
if (swipe && angle < 0) {
angle += 360;
}
var endAngle = startAngle + angle;
var signEndAngle = endAngle >= 0 ? 1 : -1;
endAngle = (Math.abs(endAngle) % 360) * signEndAngle;
return {
center: new Point(cx, cy),
startAngle: startAngle,
endAngle: endAngle,
radiusX: rx,
radiusY: ry,
xRotation: rotation
};
}
function bboxStartAngle(angle, start) {
var startAngle = angle;
while (startAngle < start) {
startAngle += 90;
}
return startAngle;
}
function pointAccessor(name) {
var fieldName = "_" + name;
return function(value) {
if (defined(value)) {
this._observerField(fieldName, Point.create(value));
this.geometryChange();
return this;
}
return this[fieldName];
};
}
function definePointAccessors(fn, names) {
for (var i = 0; i < names.length; i++) {
fn[names[i]] = pointAccessor(names[i]);
}
}
function isOutOfEndPoint(endPoint, controlPoint, point) {
var angle = deg(Math.atan2(controlPoint.y - endPoint.y, controlPoint.x - endPoint.x));
var rotatedPoint = point.transformCopy(transform().rotate(-angle, endPoint));
return rotatedPoint.x < endPoint.x;
}
function calculateCurveAt(t, field, points) {
var t1 = 1 - t;
return Math.pow(t1, 3) * points[0][field] +
3 * Math.pow(t1, 2) * t * points[1][field] +
3 * Math.pow(t, 2) * t1 * points[2][field] +
Math.pow(t, 3) * points[3][field];
}
function toCubicPolynomial(points, field) {
return [ -points[0][field] + 3 * points[1][field] - 3 * points[2][field] + points[3][field],
3 * (points[0][field] - 2 * points[1][field] + points[2][field]),
3 * (-points[0][field] + points[1][field]),
points[0][field]
];
}
var ComplexNumber = Class.extend({
init: function(real, img) {
if (real === void 0) { real = 0; }
if (img === void 0) { img = 0; }
this.real = real;
this.img = img;
},
add: function(cNumber) {
return new ComplexNumber(round(this.real + cNumber.real, PRECISION), round(this.img + cNumber.img, PRECISION));
},
addConstant: function(value) {
return new ComplexNumber(this.real + value, this.img);
},
negate: function() {
return new ComplexNumber(-this.real, -this.img);
},
multiply: function(cNumber) {
return new ComplexNumber(this.real * cNumber.real - this.img * cNumber.img,
this.real * cNumber.img + this.img * cNumber.real);
},
multiplyConstant: function(value) {
return new ComplexNumber(this.real * value, this.img * value);
},
nthRoot: function(n) {
var rad$$1 = Math.atan2(this.img, this.real);
var r = Math.sqrt(Math.pow(this.img, 2) + Math.pow(this.real, 2));
var nthR = Math.pow(r, 1 / n);
return new ComplexNumber(nthR * Math.cos(rad$$1 / n), nthR * Math.sin(rad$$1 / n)); //Moivre's formula
},
equals: function(cNumber) {
return this.real === cNumber.real && this.img === cNumber.img;
},
isReal: function() {
return this.img === 0;
}
});
function numberSign(x) {
return x < 0 ? -1 : 1;
}
function solveQuadraticEquation(a, b, c) {
var squareRoot = Math.sqrt(Math.pow(b, 2) - 4 * a * c);
return [
(-b + squareRoot) / (2 * a),
(-b - squareRoot) / (2 * a)
];
}
//Cardano's formula
function solveCubicEquation(a, b, c, d) {
if (a === 0) {
return solveQuadraticEquation(b, c, d);
}
var p = (3 * a * c - Math.pow(b, 2)) / (3 * Math.pow(a, 2));
var q = (2 * Math.pow(b, 3) - 9 * a * b * c + 27 * Math.pow(a, 2) * d) / (27 * Math.pow(a, 3));
var Q = Math.pow(p / 3, 3) + Math.pow(q / 2, 2);
var i = new ComplexNumber(0,1);
var b3a = -b / (3 * a);
var x1, x2, y1, y2, y3, z1, z2;
if (Q < 0) {
x1 = new ComplexNumber(-q / 2, Math.sqrt(-Q)).nthRoot(3);
x2 = new ComplexNumber(-q / 2, - Math.sqrt(-Q)).nthRoot(3);
} else {
x1 = -q / 2 + Math.sqrt(Q);
x1 = new ComplexNumber(numberSign(x1) * Math.pow(Math.abs(x1), 1 / 3));
x2 = -q / 2 - Math.sqrt(Q);
x2 = new ComplexNumber(numberSign(x2) * Math.pow(Math.abs(x2), 1 / 3));
}
y1 = x1.add(x2);
z1 = x1.add(x2).multiplyConstant(-1 / 2);
z2 = x1.add(x2.negate()).multiplyConstant(Math.sqrt(3) / 2);
y2 = z1.add(i.multiply(z2));
y3 = z1.add(i.negate().multiply(z2));
var result = [];
if (y1.isReal()) {
result.push(round(y1.real + b3a, PRECISION));
}
if (y2.isReal()) {
result.push(round(y2.real + b3a, PRECISION));
}
if (y3.isReal()) {
result.push(round(y3.real + b3a, PRECISION));
}
return result;
}
function hasRootsInRange(points, point, field, rootField, range) {
var polynomial = toCubicPolynomial(points, rootField);
var roots = solveCubicEquation(polynomial[0], polynomial[1], polynomial[2], polynomial[3] - point[rootField]);
var intersection;
for (var idx = 0; idx < roots.length; idx++) {
if (0 <= roots[idx] && roots[idx] <= 1) {
intersection = calculateCurveAt(roots[idx], field, points);
if (Math.abs(intersection - point[field]) <= range) {
return true;
}
}
}
}
function curveIntersectionsCount(points, point, bbox) {
var polynomial = toCubicPolynomial(points, "x");
var roots = solveCubicEquation(polynomial[0], polynomial[1], polynomial[2], polynomial[3] - point.x);
var rayIntersection, intersectsRay;
var count = 0;
for (var i = 0; i < roots.length; i++) {
rayIntersection = calculateCurveAt(roots[i], "y", points);
intersectsRay = close(rayIntersection, point.y) || rayIntersection > point.y;
if (intersectsRay && (((roots[i] === 0 || roots[i] === 1) && bbox.bottomRight().x > point.x) || (0 < roots[i] && roots[i] < 1))) {
count++;
}
}
return count;
}
function lineIntersectionsCount(a, b, point) {
var intersects;
if (a.x !== b.x) {
var minX = Math.min(a.x, b.x);
var maxX = Math.max(a.x, b.x);
var minY = Math.min(a.y, b.y);
var maxY = Math.max(a.y, b.y);
var inRange = minX <= point.x && point.x < maxX;
if (minY === maxY) {
intersects = point.y <= minY && inRange;
} else {
intersects = inRange && (((maxY - minY) * ((a.x - b.x) * (a.y - b.y) > 0 ? point.x - minX : maxX - point.x)) / (maxX - minX) + minY - point.y) >= 0;
}
}
return intersects ? 1 : 0;
}
var Segment = Class.extend({
init: function(anchor, controlIn, controlOut) {
this.anchor(anchor || new Point());
this.controlIn(controlIn);
this.controlOut(controlOut);
},
bboxTo: function(toSegment, matrix) {
var segmentAnchor = this.ancho