animate-svg
Advanced tools
Comparing version 1.0.2 to 1.1.0
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var once = function (el, eventType) { return new Promise(function (resolve) { | ||
const once = (el, eventType) => new Promise(resolve => { | ||
el.addEventListener(eventType, function handler(e) { | ||
@@ -8,29 +8,26 @@ el.removeEventListener(eventType, handler); | ||
}); | ||
}); }; | ||
var transitionEndPromise = function (path) { return once(path, 'transitionend'); }; | ||
}); | ||
const transitionEndPromise = (path) => once(path, 'transitionend'); | ||
function getLineLength(path) { | ||
var x1 = +(path.getAttribute('x1') || 0); | ||
var x2 = +(path.getAttribute('x2') || 0); | ||
var y1 = +(path.getAttribute('y1') || 0); | ||
var y2 = +(path.getAttribute('y2') || 0); | ||
var x = x2 - x1; | ||
var y = y2 - y1; | ||
const x1 = +(path.getAttribute('x1') || 0); | ||
const x2 = +(path.getAttribute('x2') || 0); | ||
const y1 = +(path.getAttribute('y1') || 0); | ||
const y2 = +(path.getAttribute('y2') || 0); | ||
const x = x2 - x1; | ||
const y = y2 - y1; | ||
return Math.sqrt(x * x + y * y); | ||
} | ||
var getLength = function (path) { | ||
return typeof path.getTotalLength === 'function' ? path.getTotalLength() : getLineLength(path); | ||
}; | ||
exports.default = function (path, speed, reverse) { | ||
if (reverse === void 0) { reverse = false; } | ||
var length = getLength(path); | ||
var initialOffset = reverse ? -length : length; | ||
var duration = length / speed; | ||
var promise = transitionEndPromise(path); | ||
var style = path.style; | ||
const getLength = (path) => typeof path.getTotalLength === 'function' ? path.getTotalLength() : getLineLength(path); | ||
exports.default = (path, speed, reverse = false) => { | ||
const length = getLength(path); | ||
const initialOffset = reverse ? -length : length; | ||
const duration = length / speed; | ||
const promise = transitionEndPromise(path); | ||
const { style } = path; | ||
style.transition = ''; | ||
style.opacity = ''; | ||
style.strokeDasharray = length + " " + length; | ||
style.strokeDasharray = `${length} ${length}`; | ||
style.strokeDashoffset = initialOffset.toString(); | ||
path.getBoundingClientRect(); | ||
style.transition = "stroke-dashoffset " + duration + "ms linear"; | ||
style.transition = `stroke-dashoffset ${duration}ms linear`; | ||
style.strokeDashoffset = '0'; | ||
@@ -37,0 +34,0 @@ return promise; |
{ | ||
"name": "animate-svg", | ||
"version": "1.0.2", | ||
"version": "1.1.0", | ||
"description": "Animate SVG paths & lines", | ||
@@ -30,4 +30,4 @@ "main": "index.js", | ||
"devDependencies": { | ||
"typescript": "^2.4.2" | ||
"typescript": "^2.5.3" | ||
} | ||
} | ||
} |
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"target": "es2015", | ||
"module": "commonjs", | ||
@@ -5,0 +5,0 @@ "sourceMap": true, |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8166
102