+910
-5
| (function (global, factory) { | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('approximate-curve')) : | ||
| typeof define === 'function' && define.amd ? define(['approximate-curve'], factory) : | ||
| (global.OwnEasing = factory(global.ApproximateCurves)); | ||
| }(this, (function (ApproximateCurves) { 'use strict'; | ||
| typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
| typeof define === 'function' && define.amd ? define(factory) : | ||
| (global.OwnEasing = factory()); | ||
| }(this, (function () { 'use strict'; | ||
| ApproximateCurves = ApproximateCurves && ApproximateCurves.hasOwnProperty('default') ? ApproximateCurves['default'] : ApproximateCurves; | ||
| 'use strict'; | ||
| var _slicedToArray = (function () { function sliceIterator (arr, i) { var _arr = []; var _n = true; var _d = false; var _e; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i['return']) _i['return'](); } finally { if (_d) throw _e } } return _arr } return function (arr, i) { if (Array.isArray(arr)) { return arr } else if (Symbol.iterator in Object(arr)) { return sliceIterator(arr, i) } else { throw new TypeError('Invalid attempt to destructure non-iterable instance') } } }()); | ||
| // I extracted this from the a2c function from | ||
| // SVG path – https://github.com/fontello/svgpath | ||
| // | ||
| // All credit goes to: | ||
| // | ||
| // Sergey Batishchev – https://github.com/snb2013 | ||
| // Vitaly Puzrin – https://github.com/puzrin | ||
| // Alex Kocharin – https://github.com/rlidwka | ||
| var TAU = Math.PI * 2; | ||
| var mapToEllipse = function mapToEllipse (_ref, rx, ry, cosphi, sinphi, centerx, centery) { | ||
| var x = _ref.x, | ||
| y = _ref.y; | ||
| x *= rx; | ||
| y *= ry; | ||
| var xp = cosphi * x - sinphi * y; | ||
| var yp = sinphi * x + cosphi * y; | ||
| return { | ||
| x: xp + centerx, | ||
| y: yp + centery | ||
| } | ||
| }; | ||
| var approxUnitArc = function approxUnitArc (ang1, ang2) { | ||
| var a = 4 / 3 * Math.tan(ang2 / 4); | ||
| var x1 = Math.cos(ang1); | ||
| var y1 = Math.sin(ang1); | ||
| var x2 = Math.cos(ang1 + ang2); | ||
| var y2 = Math.sin(ang1 + ang2); | ||
| return [{ | ||
| x: x1 - y1 * a, | ||
| y: y1 + x1 * a | ||
| }, { | ||
| x: x2 + y2 * a, | ||
| y: y2 - x2 * a | ||
| }, { | ||
| x: x2, | ||
| y: y2 | ||
| }] | ||
| }; | ||
| var vectorAngle = function vectorAngle (ux, uy, vx, vy) { | ||
| var sign = ux * vy - uy * vx < 0 ? -1 : 1; | ||
| var umag = Math.sqrt(ux * ux + uy * uy); | ||
| var vmag = Math.sqrt(ux * ux + uy * uy); | ||
| var dot = ux * vx + uy * vy; | ||
| var div = dot / (umag * vmag); | ||
| if (div > 1) { | ||
| div = 1; | ||
| } | ||
| if (div < -1) { | ||
| div = -1; | ||
| } | ||
| return sign * Math.acos(div) | ||
| }; | ||
| var getArcCenter = function getArcCenter (px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp) { | ||
| var rxsq = Math.pow(rx, 2); | ||
| var rysq = Math.pow(ry, 2); | ||
| var pxpsq = Math.pow(pxp, 2); | ||
| var pypsq = Math.pow(pyp, 2); | ||
| var radicant = rxsq * rysq - rxsq * pypsq - rysq * pxpsq; | ||
| if (radicant < 0) { | ||
| radicant = 0; | ||
| } | ||
| radicant /= rxsq * pypsq + rysq * pxpsq; | ||
| radicant = Math.sqrt(radicant) * (largeArcFlag === sweepFlag ? -1 : 1); | ||
| var centerxp = radicant * rx / ry * pyp; | ||
| var centeryp = radicant * -ry / rx * pxp; | ||
| var centerx = cosphi * centerxp - sinphi * centeryp + (px + cx) / 2; | ||
| var centery = sinphi * centerxp + cosphi * centeryp + (py + cy) / 2; | ||
| var vx1 = (pxp - centerxp) / rx; | ||
| var vy1 = (pyp - centeryp) / ry; | ||
| var vx2 = (-pxp - centerxp) / rx; | ||
| var vy2 = (-pyp - centeryp) / ry; | ||
| var ang1 = vectorAngle(1, 0, vx1, vy1); | ||
| var ang2 = vectorAngle(vx1, vy1, vx2, vy2); | ||
| if (sweepFlag === 0 && ang2 > 0) { | ||
| ang2 -= TAU; | ||
| } | ||
| if (sweepFlag === 1 && ang2 < 0) { | ||
| ang2 += TAU; | ||
| } | ||
| return [centerx, centery, ang1, ang2] | ||
| }; | ||
| var arcToBezier = function arcToBezier (_ref2) { | ||
| var px = _ref2.px, | ||
| py = _ref2.py, | ||
| cx = _ref2.cx, | ||
| cy = _ref2.cy, | ||
| rx = _ref2.rx, | ||
| ry = _ref2.ry, | ||
| _ref2$xAxisRotation = _ref2.xAxisRotation, | ||
| xAxisRotation = _ref2$xAxisRotation === undefined ? 0 : _ref2$xAxisRotation, | ||
| _ref2$largeArcFlag = _ref2.largeArcFlag, | ||
| largeArcFlag = _ref2$largeArcFlag === undefined ? 0 : _ref2$largeArcFlag, | ||
| _ref2$sweepFlag = _ref2.sweepFlag, | ||
| sweepFlag = _ref2$sweepFlag === undefined ? 0 : _ref2$sweepFlag; | ||
| var curves = []; | ||
| if (rx === 0 || ry === 0) { | ||
| return [] | ||
| } | ||
| var sinphi = Math.sin(xAxisRotation * TAU / 360); | ||
| var cosphi = Math.cos(xAxisRotation * TAU / 360); | ||
| var pxp = cosphi * (px - cx) / 2 + sinphi * (py - cy) / 2; | ||
| var pyp = -sinphi * (px - cx) / 2 + cosphi * (py - cy) / 2; | ||
| if (pxp === 0 && pyp === 0) { | ||
| return [] | ||
| } | ||
| rx = Math.abs(rx); | ||
| ry = Math.abs(ry); | ||
| var lambda = Math.pow(pxp, 2) / Math.pow(rx, 2) + Math.pow(pyp, 2) / Math.pow(ry, 2); | ||
| if (lambda > 1) { | ||
| rx *= Math.sqrt(lambda); | ||
| ry *= Math.sqrt(lambda); | ||
| } | ||
| var _getArcCenter = getArcCenter(px, py, cx, cy, rx, ry, largeArcFlag, sweepFlag, sinphi, cosphi, pxp, pyp), | ||
| _getArcCenter2 = _slicedToArray(_getArcCenter, 4), | ||
| centerx = _getArcCenter2[0], | ||
| centery = _getArcCenter2[1], | ||
| ang1 = _getArcCenter2[2], | ||
| ang2 = _getArcCenter2[3]; | ||
| var segments = Math.max(Math.ceil(Math.abs(ang2) / (TAU / 4)), 1); | ||
| ang2 /= segments; | ||
| for (var i = 0; i < segments; i++) { | ||
| curves.push(approxUnitArc(ang1, ang2)); | ||
| ang1 += ang2; | ||
| } | ||
| return curves.map(function (curve) { | ||
| var _mapToEllipse = mapToEllipse(curve[0], rx, ry, cosphi, sinphi, centerx, centery), | ||
| x1 = _mapToEllipse.x, | ||
| y1 = _mapToEllipse.y; | ||
| var _mapToEllipse2 = mapToEllipse(curve[1], rx, ry, cosphi, sinphi, centerx, centery), | ||
| x2 = _mapToEllipse2.x, | ||
| y2 = _mapToEllipse2.y; | ||
| var _mapToEllipse3 = mapToEllipse(curve[2], rx, ry, cosphi, sinphi, centerx, centery), | ||
| x = _mapToEllipse3.x, | ||
| y = _mapToEllipse3.y; | ||
| return { x1: x1, y1: y1, x2: x2, y2: y2, x: x, y: y } | ||
| }) | ||
| }; | ||
| var toPoints = function toPoints (props) { | ||
| switch (props.type) { | ||
| case 'circle': | ||
| return getPointsFromCircle(props) | ||
| case 'ellipse': | ||
| return getPointsFromEllipse(props) | ||
| case 'line': | ||
| return getPointsFromLine(props) | ||
| case 'path': | ||
| return getPointsFromPath(props) | ||
| case 'polygon': | ||
| return getPointsFromPolygon(props) | ||
| case 'polyline': | ||
| return getPointsFromPolyline(props) | ||
| case 'rect': | ||
| return getPointsFromRect(props) | ||
| case 'g': | ||
| return getPointsFromG(props) | ||
| default: | ||
| throw new Error('Not a valid shape type') | ||
| } | ||
| }; | ||
| var getPointsFromCircle = function getPointsFromCircle (_ref2) { | ||
| var cx = _ref2.cx, | ||
| cy = _ref2.cy, | ||
| r = _ref2.r; | ||
| return [{ x: cx, y: cy - r, moveTo: true }, { x: cx, y: cy + r, curve: { type: 'arc', rx: r, ry: r, sweepFlag: 1 } }, { x: cx, y: cy - r, curve: { type: 'arc', rx: r, ry: r, sweepFlag: 1 } }] | ||
| }; | ||
| var getPointsFromEllipse = function getPointsFromEllipse (_ref3) { | ||
| var cx = _ref3.cx, | ||
| cy = _ref3.cy, | ||
| rx = _ref3.rx, | ||
| ry = _ref3.ry; | ||
| return [{ x: cx, y: cy - ry, moveTo: true }, { x: cx, y: cy + ry, curve: { type: 'arc', rx: rx, ry: ry, sweepFlag: 1 } }, { x: cx, y: cy - ry, curve: { type: 'arc', rx: rx, ry: ry, sweepFlag: 1 } }] | ||
| }; | ||
| var getPointsFromLine = function getPointsFromLine (_ref4) { | ||
| var x1 = _ref4.x1, | ||
| x2 = _ref4.x2, | ||
| y1 = _ref4.y1, | ||
| y2 = _ref4.y2; | ||
| return [{ x: x1, y: y1, moveTo: true }, { x: x2, y: y2 }] | ||
| }; | ||
| var validCommands = /[MmLlHhVvCcSsQqTtAaZz]/g; | ||
| var commandLengths = { | ||
| A: 7, | ||
| C: 6, | ||
| H: 1, | ||
| L: 2, | ||
| M: 2, | ||
| Q: 4, | ||
| S: 4, | ||
| T: 2, | ||
| V: 1, | ||
| Z: 0 | ||
| }; | ||
| var relativeCommands = ['a', 'c', 'h', 'l', 'm', 'q', 's', 't', 'v']; | ||
| var isRelative = function isRelative (command) { | ||
| return relativeCommands.indexOf(command) !== -1 | ||
| }; | ||
| var optionalArcKeys = ['xAxisRotation', 'largeArcFlag', 'sweepFlag']; | ||
| var getCommands = function getCommands (d) { | ||
| return d.match(validCommands) | ||
| }; | ||
| var getParams = function getParams (d) { | ||
| return d.split(validCommands).map(function (v) { | ||
| return v.replace(/[0-9]+-/g, function (m) { | ||
| return m.slice(0, -1) + ' -' | ||
| }) | ||
| }).map(function (v) { | ||
| return v.replace(/\.[0-9]+/g, function (m) { | ||
| return m + ' ' | ||
| }) | ||
| }).map(function (v) { | ||
| return v.trim() | ||
| }).filter(function (v) { | ||
| return v.length > 0 | ||
| }).map(function (v) { | ||
| return v.split(/[ ,]+/).map(parseFloat).filter(function (n) { | ||
| return !isNaN(n) | ||
| }) | ||
| }) | ||
| }; | ||
| var getPointsFromPath = function getPointsFromPath (_ref5) { | ||
| var d = _ref5.d; | ||
| var commands = getCommands(d); | ||
| var params = getParams(d); | ||
| var points = []; | ||
| var moveTo = void 0; | ||
| for (var i = 0, l = commands.length; i < l; i++) { | ||
| var command = commands[i]; | ||
| var upperCaseCommand = command.toUpperCase(); | ||
| var commandLength = commandLengths[upperCaseCommand]; | ||
| var relative = isRelative(command); | ||
| var prevPoint = i === 0 ? null : points[points.length - 1]; | ||
| if (commandLength > 0) { | ||
| var commandParams = params.shift(); | ||
| var iterations = commandParams.length / commandLength; | ||
| for (var j = 0; j < iterations; j++) { | ||
| switch (upperCaseCommand) { | ||
| case 'M': | ||
| var x = (relative && prevPoint ? prevPoint.x : 0) + commandParams.shift(); | ||
| var y = (relative && prevPoint ? prevPoint.y : 0) + commandParams.shift(); | ||
| moveTo = { x: x, y: y }; | ||
| points.push({ x: x, y: y, moveTo: true }); | ||
| break | ||
| case 'L': | ||
| points.push({ | ||
| x: (relative ? prevPoint.x : 0) + commandParams.shift(), | ||
| y: (relative ? prevPoint.y : 0) + commandParams.shift() | ||
| }); | ||
| break | ||
| case 'H': | ||
| points.push({ | ||
| x: (relative ? prevPoint.x : 0) + commandParams.shift(), | ||
| y: prevPoint.y | ||
| }); | ||
| break | ||
| case 'V': | ||
| points.push({ | ||
| x: prevPoint.x, | ||
| y: (relative ? prevPoint.y : 0) + commandParams.shift() | ||
| }); | ||
| break | ||
| case 'A': | ||
| points.push({ | ||
| curve: { | ||
| type: 'arc', | ||
| rx: commandParams.shift(), | ||
| ry: commandParams.shift(), | ||
| xAxisRotation: commandParams.shift(), | ||
| largeArcFlag: commandParams.shift(), | ||
| sweepFlag: commandParams.shift() | ||
| }, | ||
| x: (relative ? prevPoint.x : 0) + commandParams.shift(), | ||
| y: (relative ? prevPoint.y : 0) + commandParams.shift() | ||
| }); | ||
| var _iteratorNormalCompletion = true; | ||
| var _didIteratorError = false; | ||
| var _iteratorError; | ||
| try { | ||
| for (var _iterator = optionalArcKeys[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
| var k = _step.value; | ||
| if (points[points.length - 1]['curve'][k] === 0) { | ||
| delete points[points.length - 1]['curve'][k]; | ||
| } | ||
| } | ||
| } catch (err) { | ||
| _didIteratorError = true; | ||
| _iteratorError = err; | ||
| } finally { | ||
| try { | ||
| if (!_iteratorNormalCompletion && _iterator.return) { | ||
| _iterator.return(); | ||
| } | ||
| } finally { | ||
| if (_didIteratorError) { | ||
| throw _iteratorError | ||
| } | ||
| } | ||
| } | ||
| break | ||
| case 'C': | ||
| points.push({ | ||
| curve: { | ||
| type: 'cubic', | ||
| x1: (relative ? prevPoint.x : 0) + commandParams.shift(), | ||
| y1: (relative ? prevPoint.y : 0) + commandParams.shift(), | ||
| x2: (relative ? prevPoint.x : 0) + commandParams.shift(), | ||
| y2: (relative ? prevPoint.y : 0) + commandParams.shift() | ||
| }, | ||
| x: (relative ? prevPoint.x : 0) + commandParams.shift(), | ||
| y: (relative ? prevPoint.y : 0) + commandParams.shift() | ||
| }); | ||
| break | ||
| case 'S': | ||
| var sx2 = (relative ? prevPoint.x : 0) + commandParams.shift(); | ||
| var sy2 = (relative ? prevPoint.y : 0) + commandParams.shift(); | ||
| var sx = (relative ? prevPoint.x : 0) + commandParams.shift(); | ||
| var sy = (relative ? prevPoint.y : 0) + commandParams.shift(); | ||
| var diff = {}; | ||
| var sx1 = void 0; | ||
| var sy1 = void 0; | ||
| if (prevPoint.curve && prevPoint.curve.type === 'cubic') { | ||
| diff.x = Math.abs(prevPoint.x - prevPoint.curve.x2); | ||
| diff.y = Math.abs(prevPoint.y - prevPoint.curve.y2); | ||
| sx1 = prevPoint.x < prevPoint.curve.x2 ? prevPoint.x - diff.x : prevPoint.x + diff.x; | ||
| sy1 = prevPoint.y < prevPoint.curve.y2 ? prevPoint.y - diff.y : prevPoint.y + diff.y; | ||
| } else { | ||
| diff.x = Math.abs(sx - sx2); | ||
| diff.y = Math.abs(sy - sy2); | ||
| sx1 = prevPoint.x; | ||
| sy1 = prevPoint.y; | ||
| } | ||
| points.push({ curve: { type: 'cubic', x1: sx1, y1: sy1, x2: sx2, y2: sy2 }, x: sx, y: sy }); | ||
| break | ||
| case 'Q': | ||
| points.push({ | ||
| curve: { | ||
| type: 'quadratic', | ||
| x1: (relative ? prevPoint.x : 0) + commandParams.shift(), | ||
| y1: (relative ? prevPoint.y : 0) + commandParams.shift() | ||
| }, | ||
| x: (relative ? prevPoint.x : 0) + commandParams.shift(), | ||
| y: (relative ? prevPoint.y : 0) + commandParams.shift() | ||
| }); | ||
| break | ||
| case 'T': | ||
| var tx = (relative ? prevPoint.x : 0) + commandParams.shift(); | ||
| var ty = (relative ? prevPoint.y : 0) + commandParams.shift(); | ||
| var tx1 = void 0; | ||
| var ty1 = void 0; | ||
| if (prevPoint.curve && prevPoint.curve.type === 'quadratic') { | ||
| var _diff = { | ||
| x: Math.abs(prevPoint.x - prevPoint.curve.x1), | ||
| y: Math.abs(prevPoint.y - prevPoint.curve.y1) | ||
| }; | ||
| tx1 = prevPoint.x < prevPoint.curve.x1 ? prevPoint.x - _diff.x : prevPoint.x + _diff.x; | ||
| ty1 = prevPoint.y < prevPoint.curve.y1 ? prevPoint.y - _diff.y : prevPoint.y + _diff.y; | ||
| } else { | ||
| tx1 = prevPoint.x; | ||
| ty1 = prevPoint.y; | ||
| } | ||
| points.push({ curve: { type: 'quadratic', x1: tx1, y1: ty1 }, x: tx, y: ty }); | ||
| break | ||
| } | ||
| } | ||
| } else { | ||
| if (prevPoint.x !== moveTo.x || prevPoint.y !== moveTo.y) { | ||
| points.push({ x: moveTo.x, y: moveTo.y }); | ||
| } | ||
| } | ||
| } | ||
| return points | ||
| }; | ||
| var getPointsFromPolygon = function getPointsFromPolygon (_ref6) { | ||
| var points = _ref6.points; | ||
| return getPointsFromPoints({ closed: true, points: points }) | ||
| }; | ||
| var getPointsFromPolyline = function getPointsFromPolyline (_ref7) { | ||
| var points = _ref7.points; | ||
| return getPointsFromPoints({ closed: false, points: points }) | ||
| }; | ||
| var getPointsFromPoints = function getPointsFromPoints (_ref8) { | ||
| var closed = _ref8.closed, | ||
| points = _ref8.points; | ||
| var numbers = points.split(/[\s,]+/).map(function (n) { | ||
| return parseFloat(n) | ||
| }); | ||
| var p = numbers.reduce(function (arr, point, i) { | ||
| if (i % 2 === 0) { | ||
| arr.push({ x: point }); | ||
| } else { | ||
| arr[(i - 1) / 2].y = point; | ||
| } | ||
| return arr | ||
| }, []); | ||
| if (closed) { | ||
| var firstPoint = p[0]; | ||
| p.push({x:firstPoint.x,y:firstPoint.y}); | ||
| } | ||
| p[0].moveTo = true; | ||
| return p | ||
| }; | ||
| var getPointsFromRect = function getPointsFromRect (_ref9) { | ||
| var height = _ref9.height, | ||
| rx = _ref9.rx, | ||
| ry = _ref9.ry, | ||
| width = _ref9.width, | ||
| x = _ref9.x, | ||
| y = _ref9.y; | ||
| if (rx || ry) { | ||
| return getPointsFromRectWithCornerRadius({ | ||
| height: height, | ||
| rx: rx || ry, | ||
| ry: ry || rx, | ||
| width: width, | ||
| x: x, | ||
| y: y | ||
| }) | ||
| } | ||
| return getPointsFromBasicRect({ height: height, width: width, x: x, y: y }) | ||
| }; | ||
| var getPointsFromBasicRect = function getPointsFromBasicRect (_ref10) { | ||
| var height = _ref10.height, | ||
| width = _ref10.width, | ||
| x = _ref10.x, | ||
| y = _ref10.y; | ||
| return [{ x: x, y: y, moveTo: true }, { x: x + width, y: y }, { x: x + width, y: y + height }, { x: x, y: y + height }, { x: x, y: y }] | ||
| }; | ||
| var getPointsFromRectWithCornerRadius = function getPointsFromRectWithCornerRadius (_ref11) { | ||
| var height = _ref11.height, | ||
| rx = _ref11.rx, | ||
| ry = _ref11.ry, | ||
| width = _ref11.width, | ||
| x = _ref11.x, | ||
| y = _ref11.y; | ||
| var curve = { type: 'arc', rx: rx, ry: ry, sweepFlag: 1 }; | ||
| return [{ x: x + rx, y: y, moveTo: true }, { x: x + width - rx, y: y }, { x: x + width, y: y + ry, curve: curve }, { x: x + width, y: y + height - ry }, { x: x + width - rx, y: y + height, curve: curve }, { x: x + rx, y: y + height }, { x: x, y: y + height - ry, curve: curve }, { x: x, y: y + ry }, { x: x + rx, y: y, curve: curve }] | ||
| }; | ||
| var getPointsFromG = function getPointsFromG (_ref12) { | ||
| var shapes = _ref12.shapes; | ||
| return shapes.map(function (s) { | ||
| return toPoints(s) | ||
| }) | ||
| }; | ||
| // AntiGrain approximate bezier curve algorithm | ||
| // ported by @mattdesl | ||
| // thank you | ||
| // you're amazing | ||
| var vec2 = function (x, y) { | ||
| return { | ||
| x: x, | ||
| y: y | ||
| } | ||
| }; | ||
| var recursionLimit = 20; | ||
| var fltEpsilon = 1.19209290e-7; | ||
| var pathDistEpsilon = 1.0; | ||
| var curveAngleToleranceEpsilon = 0.01; | ||
| var mAngleTolerance = 0; | ||
| var mCuspLimit = 0; | ||
| /// /// Based on: | ||
| /// /// https://github.com/pelson/antigrain/blob/master/agg-2.4/src/agg_curves.cpp | ||
| function CubicBezierApprox(x1, y1, x2, y2, x3, y3, x4, y4, points, distanceTolerance) { | ||
| if (!points) { | ||
| points = []; | ||
| } | ||
| points.push(vec2(x1, y1)); | ||
| cubicApproxRecursive(x1, y1, x2, y2, x3, y3, x4, y4, points, distanceTolerance || pathDistEpsilon, 0); | ||
| points.push(vec2(x4, y4)); | ||
| return points | ||
| } | ||
| function QuadraticBezierApprox(x1, y1, x2, y2, x3, y3, points, distanceTolerance) { | ||
| if (!points) { | ||
| points = []; | ||
| } | ||
| points.push(vec2(x1, y1)); | ||
| quadraticApproxRecursive(x1, y1, x2, y2, x3, y3, points, distanceTolerance || pathDistEpsilon, 0); | ||
| points.push(vec2(x4, y4)); | ||
| return points | ||
| } | ||
| function cubicApproxRecursive(x1, y1, x2, y2, x3, y3, x4, y4, points, distanceTolerance, level) { | ||
| if (level > recursionLimit) { | ||
| return | ||
| } | ||
| var pi = Math.PI; | ||
| // Calculate all the mid-points of the line segments | ||
| // ---------------------- | ||
| var x12 = (x1 + x2) / 2; | ||
| var y12 = (y1 + y2) / 2; | ||
| var x23 = (x2 + x3) / 2; | ||
| var y23 = (y2 + y3) / 2; | ||
| var x34 = (x3 + x4) / 2; | ||
| var y34 = (y3 + y4) / 2; | ||
| var x123 = (x12 + x23) / 2; | ||
| var y123 = (y12 + y23) / 2; | ||
| var x234 = (x23 + x34) / 2; | ||
| var y234 = (y23 + y34) / 2; | ||
| var x1234 = (x123 + x234) / 2; | ||
| var y1234 = (y123 + y234) / 2; | ||
| if (level > 0) { // Enforce subdivision first time | ||
| // Try to approximate the full cubic curve by a single straight line | ||
| // ------------------ | ||
| var dx = x4 - x1; | ||
| var dy = y4 - y1; | ||
| var d2 = Math.abs((x2 - x4) * dy - (y2 - y4) * dx); | ||
| var d3 = Math.abs((x3 - x4) * dy - (y3 - y4) * dx); | ||
| var da1, | ||
| da2; | ||
| if (d2 > fltEpsilon && d3 > fltEpsilon) { | ||
| // Regular care | ||
| // ----------------- | ||
| if ((d2 + d3) * (d2 + d3) <= distanceTolerance * (dx * dx + dy * dy)) { | ||
| // If the curvature doesn't exceed the distanceTolerance value | ||
| // we tend to finish subdivisions. | ||
| // ---------------------- | ||
| if (mAngleTolerance < curveAngleToleranceEpsilon) { | ||
| points.push(vec2(x1234, y1234)); | ||
| return | ||
| } | ||
| // Angle & Cusp Condition | ||
| // ---------------------- | ||
| var a23 = Math.atan2(y3 - y2, x3 - x2); | ||
| da1 = Math.abs(a23 - Math.atan2(y2 - y1, x2 - x1)); | ||
| da2 = Math.abs(Math.atan2(y4 - y3, x4 - x3) - a23); | ||
| if (da1 >= pi) { | ||
| da1 = 2 * pi - da1; | ||
| } | ||
| if (da2 >= pi) { | ||
| da2 = 2 * pi - da2; | ||
| } | ||
| if (da1 + da2 < mAngleTolerance) { | ||
| // Finally we can stop the recursion | ||
| // ---------------------- | ||
| points.push(vec2(x1234, y1234)); | ||
| return | ||
| } | ||
| if (mCuspLimit !== 0.0) { | ||
| if (da1 > mCuspLimit) { | ||
| points.push(vec2(x2, y2)); | ||
| return | ||
| } | ||
| if (da2 > mCuspLimit) { | ||
| points.push(vec2(x3, y3)); | ||
| return | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| if (d2 > fltEpsilon) { | ||
| // p1,p3,p4 are collinear, p2 is considerable | ||
| // ---------------------- | ||
| if (d2 * d2 <= distanceTolerance * (dx * dx + dy * dy)) { | ||
| if (mAngleTolerance < curveAngleToleranceEpsilon) { | ||
| points.push(vec2(x1234, y1234)); | ||
| return | ||
| } | ||
| // Angle Condition | ||
| // ---------------------- | ||
| da1 = Math.abs(Math.atan2(y3 - y2, x3 - x2) - Math.atan2(y2 - y1, x2 - x1)); | ||
| if (da1 >= pi) { | ||
| da1 = 2 * pi - da1; | ||
| } | ||
| if (da1 < mAngleTolerance) { | ||
| points.push(vec2(x2, y2)); | ||
| points.push(vec2(x3, y3)); | ||
| return | ||
| } | ||
| if (mCuspLimit !== 0.0) { | ||
| if (da1 > mCuspLimit) { | ||
| points.push(vec2(x2, y2)); | ||
| return | ||
| } | ||
| } | ||
| } | ||
| } else if (d3 > fltEpsilon) { | ||
| // p1,p2,p4 are collinear, p3 is considerable | ||
| // ---------------------- | ||
| if (d3 * d3 <= distanceTolerance * (dx * dx + dy * dy)) { | ||
| if (mAngleTolerance < curveAngleToleranceEpsilon) { | ||
| points.push(vec2(x1234, y1234)); | ||
| return | ||
| } | ||
| // Angle Condition | ||
| // ---------------------- | ||
| da1 = Math.abs(Math.atan2(y4 - y3, x4 - x3) - Math.atan2(y3 - y2, x3 - x2)); | ||
| if (da1 >= pi) { | ||
| da1 = 2 * pi - da1; | ||
| } | ||
| if (da1 < mAngleTolerance) { | ||
| points.push(vec2(x2, y2)); | ||
| points.push(vec2(x3, y3)); | ||
| return | ||
| } | ||
| if (mCuspLimit !== 0.0) { | ||
| if (da1 > mCuspLimit) { | ||
| points.push(vec2(x3, y3)); | ||
| return | ||
| } | ||
| } | ||
| } | ||
| } else { | ||
| // Collinear case | ||
| // ----------------- | ||
| dx = x1234 - (x1 + x4) / 2; | ||
| dy = y1234 - (y1 + y4) / 2; | ||
| if (dx * dx + dy * dy <= distanceTolerance) { | ||
| points.push(vec2(x1234, y1234)); | ||
| return | ||
| } | ||
| } | ||
| } | ||
| } | ||
| // Continue subdivision | ||
| // ---------------------- | ||
| cubicApproxRecursive(x1, y1, x12, y12, x123, y123, x1234, y1234, points, distanceTolerance, level + 1); | ||
| cubicApproxRecursive(x1234, y1234, x234, y234, x34, y34, x4, y4, points, distanceTolerance, level + 1); | ||
| } | ||
| function quadraticApproxRecursive(x1, y1, x2, y2, x3, y3, points, distanceTolerance, level) { | ||
| if (level > RECURSION_LIMIT) { | ||
| return | ||
| } | ||
| var pi = Math.PI; | ||
| // Calculate all the mid-points of the line segments | ||
| // ---------------------- | ||
| var x12 = (x1 + x2) / 2; | ||
| var y12 = (y1 + y2) / 2; | ||
| var x23 = (x2 + x3) / 2; | ||
| var y23 = (y2 + y3) / 2; | ||
| var x123 = (x12 + x23) / 2; | ||
| var y123 = (y12 + y23) / 2; | ||
| var dx = x3 - x1; | ||
| var dy = y3 - y1; | ||
| var d = Math.abs((x2 - x3) * dy - (y2 - y3) * dx); | ||
| if (d > FLT_EPSILON) { | ||
| // Regular care | ||
| // ----------------- | ||
| if (d * d <= distanceTolerance * (dx * dx + dy * dy)) { | ||
| // If the curvature doesn't exceed the distance_tolerance value | ||
| // we tend to finish subdivisions. | ||
| // ---------------------- | ||
| if (m_angle_tolerance < curve_angle_tolerance_epsilon) { | ||
| points.push(vec2(x123, y123)); | ||
| return | ||
| } | ||
| // Angle & Cusp Condition | ||
| // ---------------------- | ||
| var da = Math.abs(Math.atan2(y3 - y2, x3 - x2) - Math.atan2(y2 - y1, x2 - x1)); | ||
| if (da >= pi) { | ||
| da = 2 * pi - da; | ||
| } | ||
| if (da < m_angle_tolerance) { | ||
| // Finally we can stop the recursion | ||
| // ---------------------- | ||
| points.push(vec2(x123, y123)); | ||
| return | ||
| } | ||
| } | ||
| } else { | ||
| // Collinear case | ||
| // ----------------- | ||
| dx = x123 - (x1 + x3) / 2; | ||
| dy = y123 - (y1 + y3) / 2; | ||
| if (dx * dx + dy * dy <= distanceTolerance) { | ||
| points.push(vec2(x123, y123)); | ||
| return | ||
| } | ||
| } | ||
| // Continue subdivision | ||
| // ---------------------- | ||
| quadraticApproxRecursive(x1, y1, x12, y12, x123, y123, points, distanceTolerance, level + 1); | ||
| quadraticApproxRecursive(x123, y123, x23, y23, x3, y3, points, distanceTolerance, level + 1); | ||
| } | ||
| // Mod by @dalisoft | ||
| function ApproximateCurves(points) { | ||
| if (typeof points === 'string') { | ||
| points = toPoints({ | ||
| type: "path", | ||
| d: points | ||
| }); | ||
| } else if (typeof points === 'object' && points.type) { | ||
| points = toPoints(points); | ||
| } | ||
| var i = 0, | ||
| p, | ||
| p0, | ||
| type, | ||
| x1, | ||
| y1, | ||
| x2, | ||
| y2, | ||
| _straightLines; | ||
| while (i < points.length) { | ||
| p = points[i]; | ||
| if (p.curve) { | ||
| p0 = points[i - 1]; | ||
| type = p.curve.type; | ||
| x1 = p.curve.x1; | ||
| y1 = p.curve.y1; | ||
| x2 = p.curve.x2; | ||
| y2 = p.curve.y2; | ||
| if (type === 'arc') { | ||
| var curves = arcToBezier({ | ||
| px: p0.x, | ||
| py: p0.y, | ||
| cx: p.x, | ||
| cy: p.y, | ||
| rx: p.curve.rx, | ||
| ry: p.curve.ry, | ||
| xAxisRotation: p.curve.xAxisRotation, | ||
| largeArcFlag: p.curve.largeArcFlag, | ||
| sweepFlag: p.curve.sweepFlag | ||
| }); | ||
| points.splice(i, 1); | ||
| for (var i2 = 0, len = curves.length; i2 < len; i2++) { | ||
| var _ref = curves[i], | ||
| x1 = _ref.x1, | ||
| y1 = _ref.y1, | ||
| x2 = _ref.x2, | ||
| y2 = _ref.y2, | ||
| x = _ref.x, | ||
| y = _ref.y; | ||
| points.splice(i + i2, 0, { | ||
| x: x, | ||
| y: y, | ||
| curve: { | ||
| type: 'cubic', | ||
| x1: x1, | ||
| y1: y1, | ||
| x2: x2, | ||
| y2: y2 | ||
| } | ||
| }); | ||
| } | ||
| i--; | ||
| } else if (type === 'cubic') { | ||
| points.splice(i, 1); | ||
| _straightLines = CubicBezierApprox(p0.x, p0.y, x1, y1, x2, y2, p.x, p.y); | ||
| for (var i2 = 0, len = _straightLines.length; i2 < len; i2++) { | ||
| points.splice(i + i2, 0, _straightLines[i2]); | ||
| } | ||
| } else if (type === 'quadratic') { | ||
| points.splice(i, 1); | ||
| _straightLines = QuadraticBezierApprox(p0.x, p0.y, x1, y1, p.x, p.y); | ||
| for (var i2 = 0, len = _straightLines.length; i2 < len; i2++) { | ||
| points.splice(i + i2, 0, _straightLines[i2]); | ||
| } | ||
| } | ||
| } else { | ||
| i++; | ||
| } | ||
| } | ||
| return points | ||
| } | ||
| var getY = function (points, samples, width, height) { | ||
@@ -10,0 +915,0 @@ samples = samples !== undefined ? samples : 300000; |
@@ -1,1 +0,1 @@ | ||
| !function(e,r){"object"==typeof exports&&"undefined"!=typeof module?module.exports=r(require("approximate-curve")):"function"==typeof define&&define.amd?define(["approximate-curve"],r):e.OwnEasing=r(e.ApproximateCurves)}(this,function(e){"use strict";function r(e,r,n,u){return t(e,r?100*r:300,n,u)}e=e&&e.hasOwnProperty("default")?e.default:e;var t=function(r,t,n,u){t=void 0!==t?t:3e5,n=void 0!==n?n:100,u=void 0!==u?u:100;var o=[],i=[],a=(r=e(r)).length-1,f=1/t,p=0,h=r[0];o.push(h.x/n),i.push(1-h.y/u);for(var s=0;s<t;s++){var v=(p+=f)*a,d=Math.floor(v),l=v-d,c=d+1>a?a:d+1,x=r[d],y=r[c];o.push((x.x+(y.x-x.x)*l)/n),i.push(1-(x.y+(y.y-x.y)*l)/u)}var g=r[r.length-1],m=g.x/n,w=1-g.y/u;o.push(m),i.push(w);var A=1===w;return function(e){for(var r=0,t=o.length;r<t;r++)if(e===o[r]||o[r]<e&&o[r+1]>e)return i[r];return 1===e?A?e:w:A?e:i[e*i.length-1|0]}};return r.Value=function(r,t,n,u){var o=e(r);return function(e,r){var t=e.length-1,n=r*t,u=Math.floor(n),i=u+1>t?t:u+1,a=getPointAtElapsed(o,r).y/100-.5;return e[u]+(e[i]-e[u])*a}},r}); | ||
| !function(r,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):r.OwnEasing=t()}(this,function(){"use strict";function r(r,t,a,n,i,u,s,c,y,o){return y||(y=[]),y.push(E(r,t)),e(r,t,a,n,i,u,s,c,y,o||N,0),y.push(E(s,c)),y}function t(r,t,e,n,i,u,s,c){return s||(s=[]),s.push(E(r,t)),a(r,t,e,n,i,u,s,c||N,0),s.push(E(x4,y4)),s}function e(r,t,a,n,i,u,s,c,y,o,h){if(!(h>L)){var x=Math.PI,f=(r+a)/2,v=(t+n)/2,p=(a+i)/2,l=(n+u)/2,M=(i+s)/2,d=(u+c)/2,g=(f+p)/2,b=(v+l)/2,w=(p+M)/2,m=(l+d)/2,F=(g+w)/2,A=(b+m)/2;if(h>0){var T,q,_=s-r,k=c-t,I=Math.abs((a-s)*k-(n-c)*_),S=Math.abs((i-s)*k-(u-c)*_);if(I>C&&S>C){if((I+S)*(I+S)<=o*(_*_+k*k)){if(P<O)return void y.push(E(F,A));var R=Math.atan2(u-n,i-a);if(T=Math.abs(R-Math.atan2(n-t,a-r)),q=Math.abs(Math.atan2(c-u,s-i)-R),T>=x&&(T=2*x-T),q>=x&&(q=2*x-q),T+q<P)return void y.push(E(F,A));if(0!==V){if(T>V)return void y.push(E(a,n));if(q>V)return void y.push(E(i,u))}}}else if(I>C){if(I*I<=o*(_*_+k*k)){if(P<O)return void y.push(E(F,A));if((T=Math.abs(Math.atan2(u-n,i-a)-Math.atan2(n-t,a-r)))>=x&&(T=2*x-T),T<P)return y.push(E(a,n)),void y.push(E(i,u));if(0!==V&&T>V)return void y.push(E(a,n))}}else if(S>C){if(S*S<=o*(_*_+k*k)){if(P<O)return void y.push(E(F,A));if((T=Math.abs(Math.atan2(c-u,s-i)-Math.atan2(u-n,i-a)))>=x&&(T=2*x-T),T<P)return y.push(E(a,n)),void y.push(E(i,u));if(0!==V&&T>V)return void y.push(E(i,u))}}else if(_=F-(r+s)/2,k=A-(t+c)/2,_*_+k*k<=o)return void y.push(E(F,A))}e(r,t,f,v,g,b,F,A,y,o,h+1),e(F,A,w,m,M,d,s,c,y,o,h+1)}}function a(r,t,e,n,i,u,s,c,y){if(!(y>RECURSION_LIMIT)){var o=Math.PI,h=(r+e)/2,x=(t+n)/2,f=(e+i)/2,v=(n+u)/2,p=(h+f)/2,l=(x+v)/2,M=i-r,d=u-t,g=Math.abs((e-i)*d-(n-u)*M);if(g>FLT_EPSILON){if(g*g<=c*(M*M+d*d)){if(m_angle_tolerance<curve_angle_tolerance_epsilon)return void s.push(E(p,l));var b=Math.abs(Math.atan2(u-n,i-e)-Math.atan2(n-t,e-r));if(b>=o&&(b=2*o-b),b<m_angle_tolerance)return void s.push(E(p,l))}}else if(M=p-(r+i)/2,d=l-(t+u)/2,M*M+d*d<=c)return void s.push(E(p,l));a(r,t,h,x,p,l,s,c,y+1),a(p,l,f,v,i,u,s,c,y+1)}}function n(e){"string"==typeof e?e=f({type:"path",d:e}):"object"==typeof e&&e.type&&(e=f(e));for(var a,n,i,u,s=0;s<e.length;)if((a=e[s]).curve){if(n=e[s-1],i=a.curve.type,v=a.curve.x1,p=a.curve.y1,l=a.curve.x2,M=a.curve.y2,"arc"===i){var c=x({px:n.x,py:n.y,cx:a.x,cy:a.y,rx:a.curve.rx,ry:a.curve.ry,xAxisRotation:a.curve.xAxisRotation,largeArcFlag:a.curve.largeArcFlag,sweepFlag:a.curve.sweepFlag});e.splice(s,1);for(var y=0,o=c.length;y<o;y++){var h=c[s],v=h.x1,p=h.y1,l=h.x2,M=h.y2,d=h.x,g=h.y;e.splice(s+y,0,{x:d,y:g,curve:{type:"cubic",x1:v,y1:p,x2:l,y2:M}})}s--}else if("cubic"===i){e.splice(s,1);for(var y=0,o=(u=r(n.x,n.y,v,p,l,M,a.x,a.y)).length;y<o;y++)e.splice(s+y,0,u[y])}else if("quadratic"===i){e.splice(s,1);for(var y=0,o=(u=t(n.x,n.y,v,p,a.x,a.y)).length;y<o;y++)e.splice(s+y,0,u[y])}}else s++;return e}function i(r,t,e,a){return j(r,t?100*t:300,e,a)}var u=function(){function r(r,t){var e,a=[],n=!0,i=!1;try{for(var u,s=r[Symbol.iterator]();!(n=(u=s.next()).done)&&(a.push(u.value),!t||a.length!==t);n=!0);}catch(r){i=!0,e=r}finally{try{!n&&s.return&&s.return()}finally{if(i)throw e}}return a}return function(t,e){if(Array.isArray(t))return t;if(Symbol.iterator in Object(t))return r(t,e);throw new TypeError("Invalid attempt to destructure non-iterable instance")}}(),s=2*Math.PI,c=function(r,t,e,a,n,i,u){var s=r.x,c=r.y;return{x:a*(s*=t)-n*(c*=e)+i,y:n*s+a*c+u}},y=function(r,t){var e=4/3*Math.tan(t/4),a=Math.cos(r),n=Math.sin(r),i=Math.cos(r+t),u=Math.sin(r+t);return[{x:a-n*e,y:n+a*e},{x:i+u*e,y:u-i*e},{x:i,y:u}]},o=function(r,t,e,a){var n=r*a-t*e<0?-1:1,i=(r*e+t*a)/(Math.sqrt(r*r+t*t)*Math.sqrt(r*r+t*t));return i>1&&(i=1),i<-1&&(i=-1),n*Math.acos(i)},h=function(r,t,e,a,n,i,u,c,y,h,x,f){var v=Math.pow(n,2),p=Math.pow(i,2),l=Math.pow(x,2),M=Math.pow(f,2),d=v*p-v*M-p*l;d<0&&(d=0),d/=v*M+p*l;var g=(d=Math.sqrt(d)*(u===c?-1:1))*n/i*f,b=d*-i/n*x,w=h*g-y*b+(r+e)/2,m=y*g+h*b+(t+a)/2,F=(x-g)/n,A=(f-b)/i,T=(-x-g)/n,q=(-f-b)/i,_=o(1,0,F,A),k=o(F,A,T,q);return 0===c&&k>0&&(k-=s),1===c&&k<0&&(k+=s),[w,m,_,k]},x=function(r){var t=r.px,e=r.py,a=r.cx,n=r.cy,i=r.rx,o=r.ry,x=r.xAxisRotation,f=void 0===x?0:x,v=r.largeArcFlag,p=void 0===v?0:v,l=r.sweepFlag,M=void 0===l?0:l,d=[];if(0===i||0===o)return[];var g=Math.sin(f*s/360),b=Math.cos(f*s/360),w=b*(t-a)/2+g*(e-n)/2,m=-g*(t-a)/2+b*(e-n)/2;if(0===w&&0===m)return[];i=Math.abs(i),o=Math.abs(o);var F=Math.pow(w,2)/Math.pow(i,2)+Math.pow(m,2)/Math.pow(o,2);F>1&&(i*=Math.sqrt(F),o*=Math.sqrt(F));var A=h(t,e,a,n,i,o,p,M,g,b,w,m),T=u(A,4),q=T[0],_=T[1],k=T[2],I=T[3],S=Math.max(Math.ceil(Math.abs(I)/(s/4)),1);I/=S;for(var R=0;R<S;R++)d.push(y(k,I)),k+=I;return d.map(function(r){var t=c(r[0],i,o,b,g,q,_),e=t.x,a=t.y,n=c(r[1],i,o,b,g,q,_),u=n.x,s=n.y,y=c(r[2],i,o,b,g,q,_);return{x1:e,y1:a,x2:u,y2:s,x:y.x,y:y.y}})},f=function(r){switch(r.type){case"circle":return v(r);case"ellipse":return p(r);case"line":return l(r);case"path":return A(r);case"polygon":return T(r);case"polyline":return q(r);case"rect":return k(r);case"g":return R(r);default:throw new Error("Not a valid shape type")}},v=function(r){var t=r.cx,e=r.cy,a=r.r;return[{x:t,y:e-a,moveTo:!0},{x:t,y:e+a,curve:{type:"arc",rx:a,ry:a,sweepFlag:1}},{x:t,y:e-a,curve:{type:"arc",rx:a,ry:a,sweepFlag:1}}]},p=function(r){var t=r.cx,e=r.cy,a=r.rx,n=r.ry;return[{x:t,y:e-n,moveTo:!0},{x:t,y:e+n,curve:{type:"arc",rx:a,ry:n,sweepFlag:1}},{x:t,y:e-n,curve:{type:"arc",rx:a,ry:n,sweepFlag:1}}]},l=function(r){var t=r.x1,e=r.x2;return[{x:t,y:r.y1,moveTo:!0},{x:e,y:r.y2}]},M=/[MmLlHhVvCcSsQqTtAaZz]/g,d={A:7,C:6,H:1,L:2,M:2,Q:4,S:4,T:2,V:1,Z:0},g=["a","c","h","l","m","q","s","t","v"],b=function(r){return-1!==g.indexOf(r)},w=["xAxisRotation","largeArcFlag","sweepFlag"],m=function(r){return r.match(M)},F=function(r){return r.split(M).map(function(r){return r.replace(/[0-9]+-/g,function(r){return r.slice(0,-1)+" -"})}).map(function(r){return r.replace(/\.[0-9]+/g,function(r){return r+" "})}).map(function(r){return r.trim()}).filter(function(r){return r.length>0}).map(function(r){return r.split(/[ ,]+/).map(parseFloat).filter(function(r){return!isNaN(r)})})},A=function(r){for(var t=r.d,e=m(t),a=F(t),n=[],i=void 0,u=0,s=e.length;u<s;u++){var c=e[u],y=c.toUpperCase(),o=d[y],h=b(c),x=0===u?null:n[n.length-1];if(o>0)for(var f=a.shift(),v=f.length/o,p=0;p<v;p++)switch(y){case"M":var l=(h&&x?x.x:0)+f.shift(),M=(h&&x?x.y:0)+f.shift();i={x:l,y:M},n.push({x:l,y:M,moveTo:!0});break;case"L":n.push({x:(h?x.x:0)+f.shift(),y:(h?x.y:0)+f.shift()});break;case"H":n.push({x:(h?x.x:0)+f.shift(),y:x.y});break;case"V":n.push({x:x.x,y:(h?x.y:0)+f.shift()});break;case"A":n.push({curve:{type:"arc",rx:f.shift(),ry:f.shift(),xAxisRotation:f.shift(),largeArcFlag:f.shift(),sweepFlag:f.shift()},x:(h?x.x:0)+f.shift(),y:(h?x.y:0)+f.shift()});var g,A=!0,T=!1;try{for(var q,_=w[Symbol.iterator]();!(A=(q=_.next()).done);A=!0){var k=q.value;0===n[n.length-1].curve[k]&&delete n[n.length-1].curve[k]}}catch(r){T=!0,g=r}finally{try{!A&&_.return&&_.return()}finally{if(T)throw g}}break;case"C":n.push({curve:{type:"cubic",x1:(h?x.x:0)+f.shift(),y1:(h?x.y:0)+f.shift(),x2:(h?x.x:0)+f.shift(),y2:(h?x.y:0)+f.shift()},x:(h?x.x:0)+f.shift(),y:(h?x.y:0)+f.shift()});break;case"S":var I=(h?x.x:0)+f.shift(),S=(h?x.y:0)+f.shift(),R=(h?x.x:0)+f.shift(),E=(h?x.y:0)+f.shift(),L={},C=void 0,N=void 0;x.curve&&"cubic"===x.curve.type?(L.x=Math.abs(x.x-x.curve.x2),L.y=Math.abs(x.y-x.curve.y2),C=x.x<x.curve.x2?x.x-L.x:x.x+L.x,N=x.y<x.curve.y2?x.y-L.y:x.y+L.y):(L.x=Math.abs(R-I),L.y=Math.abs(E-S),C=x.x,N=x.y),n.push({curve:{type:"cubic",x1:C,y1:N,x2:I,y2:S},x:R,y:E});break;case"Q":n.push({curve:{type:"quadratic",x1:(h?x.x:0)+f.shift(),y1:(h?x.y:0)+f.shift()},x:(h?x.x:0)+f.shift(),y:(h?x.y:0)+f.shift()});break;case"T":var O=(h?x.x:0)+f.shift(),P=(h?x.y:0)+f.shift(),V=void 0,j=void 0;if(x.curve&&"quadratic"===x.curve.type){var H={x:Math.abs(x.x-x.curve.x1),y:Math.abs(x.y-x.curve.y1)};V=x.x<x.curve.x1?x.x-H.x:x.x+H.x,j=x.y<x.curve.y1?x.y-H.y:x.y+H.y}else V=x.x,j=x.y;n.push({curve:{type:"quadratic",x1:V,y1:j},x:O,y:P})}else x.x===i.x&&x.y===i.y||n.push({x:i.x,y:i.y})}return n},T=function(r){var t=r.points;return _({closed:!0,points:t})},q=function(r){var t=r.points;return _({closed:!1,points:t})},_=function(r){var t=r.closed,e=r.points.split(/[\s,]+/).map(function(r){return parseFloat(r)}).reduce(function(r,t,e){return e%2==0?r.push({x:t}):r[(e-1)/2].y=t,r},[]);if(t){var a=e[0];e.push({x:a.x,y:a.y})}return e[0].moveTo=!0,e},k=function(r){var t=r.height,e=r.rx,a=r.ry,n=r.width,i=r.x,u=r.y;return e||a?S({height:t,rx:e||a,ry:a||e,width:n,x:i,y:u}):I({height:t,width:n,x:i,y:u})},I=function(r){var t=r.height,e=r.width,a=r.x,n=r.y;return[{x:a,y:n,moveTo:!0},{x:a+e,y:n},{x:a+e,y:n+t},{x:a,y:n+t},{x:a,y:n}]},S=function(r){var t=r.height,e=r.rx,a=r.ry,n=r.width,i=r.x,u=r.y,s={type:"arc",rx:e,ry:a,sweepFlag:1};return[{x:i+e,y:u,moveTo:!0},{x:i+n-e,y:u},{x:i+n,y:u+a,curve:s},{x:i+n,y:u+t-a},{x:i+n-e,y:u+t,curve:s},{x:i+e,y:u+t},{x:i,y:u+t-a,curve:s},{x:i,y:u+a},{x:i+e,y:u,curve:s}]},R=function(r){return r.shapes.map(function(r){return f(r)})},E=function(r,t){return{x:r,y:t}},L=20,C=1.1920929e-7,N=1,O=.01,P=0,V=0,j=function(r,t,e,a){t=void 0!==t?t:3e5,e=void 0!==e?e:100,a=void 0!==a?a:100;var i=[],u=[],s=(r=n(r)).length-1,c=1/t,y=0,o=r[0];i.push(o.x/e),u.push(1-o.y/a);for(var h=0;h<t;h++){var x=(y+=c)*s,f=Math.floor(x),v=x-f,p=f+1>s?s:f+1,l=r[f],M=r[p];i.push((l.x+(M.x-l.x)*v)/e),u.push(1-(l.y+(M.y-l.y)*v)/a)}var d=r[r.length-1],g=d.x/e,b=1-d.y/a;i.push(g),u.push(b);var w=1===b;return function(r){for(var t=0,e=i.length;t<e;t++)if(r===i[t]||i[t]<r&&i[t+1]>r)return u[t];return 1===r?w?r:b:w?r:u[r*u.length-1|0]}};return i.Value=function(r,t,e,a){var i=n(r);return function(r,t){var e=r.length-1,a=t*e,n=Math.floor(a),u=n+1>e?e:n+1,s=getPointAtElapsed(i,t).y/100-.5;return r[n]+(r[u]-r[n])*s}},i}); |
+2
-3
| { | ||
| "name": "owneasing", | ||
| "version": "0.0.1", | ||
| "version": "0.0.2", | ||
| "description": "Custom Easing based on SVG Path Data", | ||
@@ -25,4 +25,3 @@ "main": "owneasing.umd.js", | ||
| "devDependencies": { | ||
| "snazzy": "^7.0.0", | ||
| "standard": "^10.0.3", | ||
| "rollup-plugin-node-resolve": "^3.0.0", | ||
| "uglify-js": "^3.1.2" | ||
@@ -29,0 +28,0 @@ }, |
+5
-3
@@ -1,2 +0,2 @@ | ||
| # es6tween-plugin-attr | ||
| # OwnEasing | ||
@@ -7,5 +7,7 @@ # Usage | ||
| import { Tween } from 'es6-tween'; | ||
| import 'es6tween-plugin-attr'; | ||
| import OwnEasing from 'owneasing'; | ||
| let tween = new Tween({node:document.querySelector('#myCircleSVG'), attr: {r:50}}).to({attr:{r:150}}, 2000).start(); | ||
| let myEase = OwnEasing('M... C...') | ||
| let tween = new Tween(from).to(to, 2000).easing(myEase).start(); | ||
| ``` |
+6
-0
@@ -0,1 +1,3 @@ | ||
| import nodeResolve from 'rollup-plugin-node-resolve' | ||
| export default { | ||
@@ -7,3 +9,7 @@ input: 'owneasing.js', | ||
| }, | ||
| plugins: [nodeResolve({jsnext:true})], | ||
| globals: { | ||
| 'approximate-curve': 'ApproximateCurves' | ||
| }, | ||
| name: 'OwnEasing' | ||
| } |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
49176
223.7%2
-33.33%886
597.64%12
20%1
Infinity%