anime-rails 3.2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +13 -0
- data/.rubocop.yml +13 -0
- data/CHANGELOG.md +5 -0
- data/CODE_OF_CONDUCT.md +84 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +21 -0
- data/README.md +30 -0
- data/Rakefile +16 -0
- data/anime-rails.gemspec +29 -0
- data/lib/anime-rails.rb +10 -0
- data/lib/anime-rails/engine.rb +6 -0
- data/lib/anime-rails/source_file.rb +13 -0
- data/lib/anime-rails/version.rb +7 -0
- data/vendor/assets/javascripts/anime.es.js +1310 -0
- data/vendor/assets/javascripts/anime.js +1289 -0
- data/vendor/assets/javascripts/anime.min.js +8 -0
- metadata +120 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 07ac8c6c565068f1cfed1f5bfeda138bc47d884e5d8f8eaac7ce659999824d1b
|
4
|
+
data.tar.gz: 7e05bc12054fc2a1f9796e91309faea0b5aa2f5f5e094a12851e50c8ced40885
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c46c7f2748297ad7c62ea1a8188f129632c8f26170508fe073da069a854b149100e3a5624a92b9d923650122ac7e68f806a2262520d2c37ee40b5dae8946c51c
|
7
|
+
data.tar.gz: 4cff819d2082b14ae38337e042a339a3278a04bccebe3ff5e8693989da9e25db953e29078f4f260e9d0f5927572a7710b1a004dde38487c2cbb4a4fc71d59092
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
data/CHANGELOG.md
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
|
6
|
+
|
7
|
+
We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
|
8
|
+
|
9
|
+
## Our Standards
|
10
|
+
|
11
|
+
Examples of behavior that contributes to a positive environment for our community include:
|
12
|
+
|
13
|
+
* Demonstrating empathy and kindness toward other people
|
14
|
+
* Being respectful of differing opinions, viewpoints, and experiences
|
15
|
+
* Giving and gracefully accepting constructive feedback
|
16
|
+
* Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
|
17
|
+
* Focusing on what is best not just for us as individuals, but for the overall community
|
18
|
+
|
19
|
+
Examples of unacceptable behavior include:
|
20
|
+
|
21
|
+
* The use of sexualized language or imagery, and sexual attention or
|
22
|
+
advances of any kind
|
23
|
+
* Trolling, insulting or derogatory comments, and personal or political attacks
|
24
|
+
* Public or private harassment
|
25
|
+
* Publishing others' private information, such as a physical or email
|
26
|
+
address, without their explicit permission
|
27
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
28
|
+
professional setting
|
29
|
+
|
30
|
+
## Enforcement Responsibilities
|
31
|
+
|
32
|
+
Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
|
33
|
+
|
34
|
+
Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
|
35
|
+
|
36
|
+
## Scope
|
37
|
+
|
38
|
+
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
|
39
|
+
|
40
|
+
## Enforcement
|
41
|
+
|
42
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at vasul2537125@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
|
43
|
+
|
44
|
+
All community leaders are obligated to respect the privacy and security of the reporter of any incident.
|
45
|
+
|
46
|
+
## Enforcement Guidelines
|
47
|
+
|
48
|
+
Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
|
49
|
+
|
50
|
+
### 1. Correction
|
51
|
+
|
52
|
+
**Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
|
53
|
+
|
54
|
+
**Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
|
55
|
+
|
56
|
+
### 2. Warning
|
57
|
+
|
58
|
+
**Community Impact**: A violation through a single incident or series of actions.
|
59
|
+
|
60
|
+
**Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
|
61
|
+
|
62
|
+
### 3. Temporary Ban
|
63
|
+
|
64
|
+
**Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
|
65
|
+
|
66
|
+
**Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
|
67
|
+
|
68
|
+
### 4. Permanent Ban
|
69
|
+
|
70
|
+
**Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
|
71
|
+
|
72
|
+
**Consequence**: A permanent ban from any sort of public interaction within the community.
|
73
|
+
|
74
|
+
## Attribution
|
75
|
+
|
76
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
|
77
|
+
available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
|
78
|
+
|
79
|
+
Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
|
80
|
+
|
81
|
+
[homepage]: https://www.contributor-covenant.org
|
82
|
+
|
83
|
+
For answers to common questions about this code of conduct, see the FAQ at
|
84
|
+
https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2021 Vasyl Mytskaniuk
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# Anime for rails asset pipeline
|
2
|
+
|
3
|
+
[Anime](https://github.com/juliangarnier/anime) is a lightweight JavaScript animation library with a simple, yet powerful API. It works with CSS properties, SVG, DOM attributes and JavaScript Objects.
|
4
|
+
|
5
|
+
The `anime-rails` gem integrates the `Anime` javascript library with Rails asset pipeline
|
6
|
+
|
7
|
+
|
8
|
+
<h4 align="center">JavaScript animation engine | <a href="https://animejs.com" target="_blank">animejs.com</a></h4>
|
9
|
+
|
10
|
+
<p align="center">
|
11
|
+
<a href="https://www.npmjs.com/package/animejs" rel="nofollow"><img src="https://camo.githubusercontent.com/011820ee25bf1d3ddaf635d869903b98eccaeae7/68747470733a2f2f696d672e736869656c64732e696f2f6e706d2f762f616e696d656a732e7376673f7374796c653d666c61742d737175617265" alt="npm version" data-canonical-src="https://img.shields.io/npm/v/animejs.svg?style=flat-square" style="max-width:100%;"></a>
|
12
|
+
</p>
|
13
|
+
|
14
|
+
<p align="center">
|
15
|
+
<a href="#getting-started">Getting started</a> | <a href="#documentation">Documentation</a> | <a href="#demos-and-examples">Demos and examples</a> | <a href="#browser-support">Browser support</a>
|
16
|
+
</p>
|
17
|
+
|
18
|
+
## Usage
|
19
|
+
|
20
|
+
### Install anime-rails gem
|
21
|
+
|
22
|
+
Add `anime-rails` to your Gemfile and run `bundle install`:
|
23
|
+
|
24
|
+
gem "anime-rails"
|
25
|
+
|
26
|
+
### Include anime-rails javascript assets
|
27
|
+
|
28
|
+
Add the following to your `app/assets/javascripts/application.js`:
|
29
|
+
|
30
|
+
//= require anime
|
data/Rakefile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rubocop/rake_task"
|
5
|
+
|
6
|
+
RuboCop::RakeTask.new
|
7
|
+
|
8
|
+
task default: :rubocop
|
9
|
+
|
10
|
+
require File.expand_path('../lib/anime-rails/source_file', __FILE__)
|
11
|
+
|
12
|
+
desc "Update with juliangarnier's anime Library"
|
13
|
+
task "update-anime" do
|
14
|
+
files = SourceFile.new
|
15
|
+
files.fetch
|
16
|
+
end
|
data/anime-rails.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require File.expand_path("../lib/anime-rails/version", __FILE__)
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "anime-rails"
|
7
|
+
spec.version = Anime::Rails::VERSION
|
8
|
+
spec.authors = ["Vasyl Mytskaniuk"]
|
9
|
+
spec.email = ["vasul2537125@gmail.com"]
|
10
|
+
|
11
|
+
spec.summary = %q{Integrate anime javascript library with Rails asset pipeline}
|
12
|
+
spec.description = %q{Anime.js is a lightweight JavaScript animation library with a simple, yet powerful API. It works with CSS properties, SVG, DOM attributes and JavaScript Objects. }
|
13
|
+
spec.homepage = "https://github.com/vmyts539/anime-rails"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = ">= 2.4.0"
|
16
|
+
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
18
|
+
spec.metadata["source_code_uri"] = "https://github.com/vmyts539/anime-rails"
|
19
|
+
spec.metadata["changelog_uri"] = "https://github.com/vmyts539/anime-rails/releases"
|
20
|
+
|
21
|
+
spec.files = `git ls-files`.split("\n")
|
22
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_development_dependency "thor", "~> 1"
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.0"
|
27
|
+
spec.add_development_dependency "rails", ">= 3.0"
|
28
|
+
spec.add_development_dependency "httpclient", "~> 2.2"
|
29
|
+
end
|
data/lib/anime-rails.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require "thor"
|
2
|
+
|
3
|
+
class SourceFile < Thor
|
4
|
+
include Thor::Actions
|
5
|
+
|
6
|
+
desc "fetch source files", "fetch source files from GitHub"
|
7
|
+
def fetch
|
8
|
+
self.destination_root = "vendor/assets"
|
9
|
+
remote = "https://github.com/juliangarnier/anime"
|
10
|
+
get "#{remote}/raw/#{tag}/lib/anime.min.js", "javascripts/anime.min.js"
|
11
|
+
get "#{remote}/raw/#{tag}/lib/anime.es.js", "javascripts/anime.es.js"
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,1310 @@
|
|
1
|
+
/*
|
2
|
+
* anime.js v3.2.1
|
3
|
+
* (c) 2020 Julian Garnier
|
4
|
+
* Released under the MIT license
|
5
|
+
* animejs.com
|
6
|
+
*/
|
7
|
+
|
8
|
+
// Defaults
|
9
|
+
|
10
|
+
var defaultInstanceSettings = {
|
11
|
+
update: null,
|
12
|
+
begin: null,
|
13
|
+
loopBegin: null,
|
14
|
+
changeBegin: null,
|
15
|
+
change: null,
|
16
|
+
changeComplete: null,
|
17
|
+
loopComplete: null,
|
18
|
+
complete: null,
|
19
|
+
loop: 1,
|
20
|
+
direction: 'normal',
|
21
|
+
autoplay: true,
|
22
|
+
timelineOffset: 0
|
23
|
+
};
|
24
|
+
|
25
|
+
var defaultTweenSettings = {
|
26
|
+
duration: 1000,
|
27
|
+
delay: 0,
|
28
|
+
endDelay: 0,
|
29
|
+
easing: 'easeOutElastic(1, .5)',
|
30
|
+
round: 0
|
31
|
+
};
|
32
|
+
|
33
|
+
var validTransforms = ['translateX', 'translateY', 'translateZ', 'rotate', 'rotateX', 'rotateY', 'rotateZ', 'scale', 'scaleX', 'scaleY', 'scaleZ', 'skew', 'skewX', 'skewY', 'perspective', 'matrix', 'matrix3d'];
|
34
|
+
|
35
|
+
// Caching
|
36
|
+
|
37
|
+
var cache = {
|
38
|
+
CSS: {},
|
39
|
+
springs: {}
|
40
|
+
};
|
41
|
+
|
42
|
+
// Utils
|
43
|
+
|
44
|
+
function minMax(val, min, max) {
|
45
|
+
return Math.min(Math.max(val, min), max);
|
46
|
+
}
|
47
|
+
|
48
|
+
function stringContains(str, text) {
|
49
|
+
return str.indexOf(text) > -1;
|
50
|
+
}
|
51
|
+
|
52
|
+
function applyArguments(func, args) {
|
53
|
+
return func.apply(null, args);
|
54
|
+
}
|
55
|
+
|
56
|
+
var is = {
|
57
|
+
arr: function (a) { return Array.isArray(a); },
|
58
|
+
obj: function (a) { return stringContains(Object.prototype.toString.call(a), 'Object'); },
|
59
|
+
pth: function (a) { return is.obj(a) && a.hasOwnProperty('totalLength'); },
|
60
|
+
svg: function (a) { return a instanceof SVGElement; },
|
61
|
+
inp: function (a) { return a instanceof HTMLInputElement; },
|
62
|
+
dom: function (a) { return a.nodeType || is.svg(a); },
|
63
|
+
str: function (a) { return typeof a === 'string'; },
|
64
|
+
fnc: function (a) { return typeof a === 'function'; },
|
65
|
+
und: function (a) { return typeof a === 'undefined'; },
|
66
|
+
nil: function (a) { return is.und(a) || a === null; },
|
67
|
+
hex: function (a) { return /(^#[0-9A-F]{6}$)|(^#[0-9A-F]{3}$)/i.test(a); },
|
68
|
+
rgb: function (a) { return /^rgb/.test(a); },
|
69
|
+
hsl: function (a) { return /^hsl/.test(a); },
|
70
|
+
col: function (a) { return (is.hex(a) || is.rgb(a) || is.hsl(a)); },
|
71
|
+
key: function (a) { return !defaultInstanceSettings.hasOwnProperty(a) && !defaultTweenSettings.hasOwnProperty(a) && a !== 'targets' && a !== 'keyframes'; },
|
72
|
+
};
|
73
|
+
|
74
|
+
// Easings
|
75
|
+
|
76
|
+
function parseEasingParameters(string) {
|
77
|
+
var match = /\(([^)]+)\)/.exec(string);
|
78
|
+
return match ? match[1].split(',').map(function (p) { return parseFloat(p); }) : [];
|
79
|
+
}
|
80
|
+
|
81
|
+
// Spring solver inspired by Webkit Copyright © 2016 Apple Inc. All rights reserved. https://webkit.org/demos/spring/spring.js
|
82
|
+
|
83
|
+
function spring(string, duration) {
|
84
|
+
|
85
|
+
var params = parseEasingParameters(string);
|
86
|
+
var mass = minMax(is.und(params[0]) ? 1 : params[0], .1, 100);
|
87
|
+
var stiffness = minMax(is.und(params[1]) ? 100 : params[1], .1, 100);
|
88
|
+
var damping = minMax(is.und(params[2]) ? 10 : params[2], .1, 100);
|
89
|
+
var velocity = minMax(is.und(params[3]) ? 0 : params[3], .1, 100);
|
90
|
+
var w0 = Math.sqrt(stiffness / mass);
|
91
|
+
var zeta = damping / (2 * Math.sqrt(stiffness * mass));
|
92
|
+
var wd = zeta < 1 ? w0 * Math.sqrt(1 - zeta * zeta) : 0;
|
93
|
+
var a = 1;
|
94
|
+
var b = zeta < 1 ? (zeta * w0 + -velocity) / wd : -velocity + w0;
|
95
|
+
|
96
|
+
function solver(t) {
|
97
|
+
var progress = duration ? (duration * t) / 1000 : t;
|
98
|
+
if (zeta < 1) {
|
99
|
+
progress = Math.exp(-progress * zeta * w0) * (a * Math.cos(wd * progress) + b * Math.sin(wd * progress));
|
100
|
+
} else {
|
101
|
+
progress = (a + b * progress) * Math.exp(-progress * w0);
|
102
|
+
}
|
103
|
+
if (t === 0 || t === 1) { return t; }
|
104
|
+
return 1 - progress;
|
105
|
+
}
|
106
|
+
|
107
|
+
function getDuration() {
|
108
|
+
var cached = cache.springs[string];
|
109
|
+
if (cached) { return cached; }
|
110
|
+
var frame = 1/6;
|
111
|
+
var elapsed = 0;
|
112
|
+
var rest = 0;
|
113
|
+
while(true) {
|
114
|
+
elapsed += frame;
|
115
|
+
if (solver(elapsed) === 1) {
|
116
|
+
rest++;
|
117
|
+
if (rest >= 16) { break; }
|
118
|
+
} else {
|
119
|
+
rest = 0;
|
120
|
+
}
|
121
|
+
}
|
122
|
+
var duration = elapsed * frame * 1000;
|
123
|
+
cache.springs[string] = duration;
|
124
|
+
return duration;
|
125
|
+
}
|
126
|
+
|
127
|
+
return duration ? solver : getDuration;
|
128
|
+
|
129
|
+
}
|
130
|
+
|
131
|
+
// Basic steps easing implementation https://developer.mozilla.org/fr/docs/Web/CSS/transition-timing-function
|
132
|
+
|
133
|
+
function steps(steps) {
|
134
|
+
if ( steps === void 0 ) steps = 10;
|
135
|
+
|
136
|
+
return function (t) { return Math.ceil((minMax(t, 0.000001, 1)) * steps) * (1 / steps); };
|
137
|
+
}
|
138
|
+
|
139
|
+
// BezierEasing https://github.com/gre/bezier-easing
|
140
|
+
|
141
|
+
var bezier = (function () {
|
142
|
+
|
143
|
+
var kSplineTableSize = 11;
|
144
|
+
var kSampleStepSize = 1.0 / (kSplineTableSize - 1.0);
|
145
|
+
|
146
|
+
function A(aA1, aA2) { return 1.0 - 3.0 * aA2 + 3.0 * aA1 }
|
147
|
+
function B(aA1, aA2) { return 3.0 * aA2 - 6.0 * aA1 }
|
148
|
+
function C(aA1) { return 3.0 * aA1 }
|
149
|
+
|
150
|
+
function calcBezier(aT, aA1, aA2) { return ((A(aA1, aA2) * aT + B(aA1, aA2)) * aT + C(aA1)) * aT }
|
151
|
+
function getSlope(aT, aA1, aA2) { return 3.0 * A(aA1, aA2) * aT * aT + 2.0 * B(aA1, aA2) * aT + C(aA1) }
|
152
|
+
|
153
|
+
function binarySubdivide(aX, aA, aB, mX1, mX2) {
|
154
|
+
var currentX, currentT, i = 0;
|
155
|
+
do {
|
156
|
+
currentT = aA + (aB - aA) / 2.0;
|
157
|
+
currentX = calcBezier(currentT, mX1, mX2) - aX;
|
158
|
+
if (currentX > 0.0) { aB = currentT; } else { aA = currentT; }
|
159
|
+
} while (Math.abs(currentX) > 0.0000001 && ++i < 10);
|
160
|
+
return currentT;
|
161
|
+
}
|
162
|
+
|
163
|
+
function newtonRaphsonIterate(aX, aGuessT, mX1, mX2) {
|
164
|
+
for (var i = 0; i < 4; ++i) {
|
165
|
+
var currentSlope = getSlope(aGuessT, mX1, mX2);
|
166
|
+
if (currentSlope === 0.0) { return aGuessT; }
|
167
|
+
var currentX = calcBezier(aGuessT, mX1, mX2) - aX;
|
168
|
+
aGuessT -= currentX / currentSlope;
|
169
|
+
}
|
170
|
+
return aGuessT;
|
171
|
+
}
|
172
|
+
|
173
|
+
function bezier(mX1, mY1, mX2, mY2) {
|
174
|
+
|
175
|
+
if (!(0 <= mX1 && mX1 <= 1 && 0 <= mX2 && mX2 <= 1)) { return; }
|
176
|
+
var sampleValues = new Float32Array(kSplineTableSize);
|
177
|
+
|
178
|
+
if (mX1 !== mY1 || mX2 !== mY2) {
|
179
|
+
for (var i = 0; i < kSplineTableSize; ++i) {
|
180
|
+
sampleValues[i] = calcBezier(i * kSampleStepSize, mX1, mX2);
|
181
|
+
}
|
182
|
+
}
|
183
|
+
|
184
|
+
function getTForX(aX) {
|
185
|
+
|
186
|
+
var intervalStart = 0;
|
187
|
+
var currentSample = 1;
|
188
|
+
var lastSample = kSplineTableSize - 1;
|
189
|
+
|
190
|
+
for (; currentSample !== lastSample && sampleValues[currentSample] <= aX; ++currentSample) {
|
191
|
+
intervalStart += kSampleStepSize;
|
192
|
+
}
|
193
|
+
|
194
|
+
--currentSample;
|
195
|
+
|
196
|
+
var dist = (aX - sampleValues[currentSample]) / (sampleValues[currentSample + 1] - sampleValues[currentSample]);
|
197
|
+
var guessForT = intervalStart + dist * kSampleStepSize;
|
198
|
+
var initialSlope = getSlope(guessForT, mX1, mX2);
|
199
|
+
|
200
|
+
if (initialSlope >= 0.001) {
|
201
|
+
return newtonRaphsonIterate(aX, guessForT, mX1, mX2);
|
202
|
+
} else if (initialSlope === 0.0) {
|
203
|
+
return guessForT;
|
204
|
+
} else {
|
205
|
+
return binarySubdivide(aX, intervalStart, intervalStart + kSampleStepSize, mX1, mX2);
|
206
|
+
}
|
207
|
+
|
208
|
+
}
|
209
|
+
|
210
|
+
return function (x) {
|
211
|
+
if (mX1 === mY1 && mX2 === mY2) { return x; }
|
212
|
+
if (x === 0 || x === 1) { return x; }
|
213
|
+
return calcBezier(getTForX(x), mY1, mY2);
|
214
|
+
}
|
215
|
+
|
216
|
+
}
|
217
|
+
|
218
|
+
return bezier;
|
219
|
+
|
220
|
+
})();
|
221
|
+
|
222
|
+
var penner = (function () {
|
223
|
+
|
224
|
+
// Based on jQuery UI's implemenation of easing equations from Robert Penner (http://www.robertpenner.com/easing)
|
225
|
+
|
226
|
+
var eases = { linear: function () { return function (t) { return t; }; } };
|
227
|
+
|
228
|
+
var functionEasings = {
|
229
|
+
Sine: function () { return function (t) { return 1 - Math.cos(t * Math.PI / 2); }; },
|
230
|
+
Circ: function () { return function (t) { return 1 - Math.sqrt(1 - t * t); }; },
|
231
|
+
Back: function () { return function (t) { return t * t * (3 * t - 2); }; },
|
232
|
+
Bounce: function () { return function (t) {
|
233
|
+
var pow2, b = 4;
|
234
|
+
while (t < (( pow2 = Math.pow(2, --b)) - 1) / 11) {}
|
235
|
+
return 1 / Math.pow(4, 3 - b) - 7.5625 * Math.pow(( pow2 * 3 - 2 ) / 22 - t, 2)
|
236
|
+
}; },
|
237
|
+
Elastic: function (amplitude, period) {
|
238
|
+
if ( amplitude === void 0 ) amplitude = 1;
|
239
|
+
if ( period === void 0 ) period = .5;
|
240
|
+
|
241
|
+
var a = minMax(amplitude, 1, 10);
|
242
|
+
var p = minMax(period, .1, 2);
|
243
|
+
return function (t) {
|
244
|
+
return (t === 0 || t === 1) ? t :
|
245
|
+
-a * Math.pow(2, 10 * (t - 1)) * Math.sin((((t - 1) - (p / (Math.PI * 2) * Math.asin(1 / a))) * (Math.PI * 2)) / p);
|
246
|
+
}
|
247
|
+
}
|
248
|
+
};
|
249
|
+
|
250
|
+
var baseEasings = ['Quad', 'Cubic', 'Quart', 'Quint', 'Expo'];
|
251
|
+
|
252
|
+
baseEasings.forEach(function (name, i) {
|
253
|
+
functionEasings[name] = function () { return function (t) { return Math.pow(t, i + 2); }; };
|
254
|
+
});
|
255
|
+
|
256
|
+
Object.keys(functionEasings).forEach(function (name) {
|
257
|
+
var easeIn = functionEasings[name];
|
258
|
+
eases['easeIn' + name] = easeIn;
|
259
|
+
eases['easeOut' + name] = function (a, b) { return function (t) { return 1 - easeIn(a, b)(1 - t); }; };
|
260
|
+
eases['easeInOut' + name] = function (a, b) { return function (t) { return t < 0.5 ? easeIn(a, b)(t * 2) / 2 :
|
261
|
+
1 - easeIn(a, b)(t * -2 + 2) / 2; }; };
|
262
|
+
eases['easeOutIn' + name] = function (a, b) { return function (t) { return t < 0.5 ? (1 - easeIn(a, b)(1 - t * 2)) / 2 :
|
263
|
+
(easeIn(a, b)(t * 2 - 1) + 1) / 2; }; };
|
264
|
+
});
|
265
|
+
|
266
|
+
return eases;
|
267
|
+
|
268
|
+
})();
|
269
|
+
|
270
|
+
function parseEasings(easing, duration) {
|
271
|
+
if (is.fnc(easing)) { return easing; }
|
272
|
+
var name = easing.split('(')[0];
|
273
|
+
var ease = penner[name];
|
274
|
+
var args = parseEasingParameters(easing);
|
275
|
+
switch (name) {
|
276
|
+
case 'spring' : return spring(easing, duration);
|
277
|
+
case 'cubicBezier' : return applyArguments(bezier, args);
|
278
|
+
case 'steps' : return applyArguments(steps, args);
|
279
|
+
default : return applyArguments(ease, args);
|
280
|
+
}
|
281
|
+
}
|
282
|
+
|
283
|
+
// Strings
|
284
|
+
|
285
|
+
function selectString(str) {
|
286
|
+
try {
|
287
|
+
var nodes = document.querySelectorAll(str);
|
288
|
+
return nodes;
|
289
|
+
} catch(e) {
|
290
|
+
return;
|
291
|
+
}
|
292
|
+
}
|
293
|
+
|
294
|
+
// Arrays
|
295
|
+
|
296
|
+
function filterArray(arr, callback) {
|
297
|
+
var len = arr.length;
|
298
|
+
var thisArg = arguments.length >= 2 ? arguments[1] : void 0;
|
299
|
+
var result = [];
|
300
|
+
for (var i = 0; i < len; i++) {
|
301
|
+
if (i in arr) {
|
302
|
+
var val = arr[i];
|
303
|
+
if (callback.call(thisArg, val, i, arr)) {
|
304
|
+
result.push(val);
|
305
|
+
}
|
306
|
+
}
|
307
|
+
}
|
308
|
+
return result;
|
309
|
+
}
|
310
|
+
|
311
|
+
function flattenArray(arr) {
|
312
|
+
return arr.reduce(function (a, b) { return a.concat(is.arr(b) ? flattenArray(b) : b); }, []);
|
313
|
+
}
|
314
|
+
|
315
|
+
function toArray(o) {
|
316
|
+
if (is.arr(o)) { return o; }
|
317
|
+
if (is.str(o)) { o = selectString(o) || o; }
|
318
|
+
if (o instanceof NodeList || o instanceof HTMLCollection) { return [].slice.call(o); }
|
319
|
+
return [o];
|
320
|
+
}
|
321
|
+
|
322
|
+
function arrayContains(arr, val) {
|
323
|
+
return arr.some(function (a) { return a === val; });
|
324
|
+
}
|
325
|
+
|
326
|
+
// Objects
|
327
|
+
|
328
|
+
function cloneObject(o) {
|
329
|
+
var clone = {};
|
330
|
+
for (var p in o) { clone[p] = o[p]; }
|
331
|
+
return clone;
|
332
|
+
}
|
333
|
+
|
334
|
+
function replaceObjectProps(o1, o2) {
|
335
|
+
var o = cloneObject(o1);
|
336
|
+
for (var p in o1) { o[p] = o2.hasOwnProperty(p) ? o2[p] : o1[p]; }
|
337
|
+
return o;
|
338
|
+
}
|
339
|
+
|
340
|
+
function mergeObjects(o1, o2) {
|
341
|
+
var o = cloneObject(o1);
|
342
|
+
for (var p in o2) { o[p] = is.und(o1[p]) ? o2[p] : o1[p]; }
|
343
|
+
return o;
|
344
|
+
}
|
345
|
+
|
346
|
+
// Colors
|
347
|
+
|
348
|
+
function rgbToRgba(rgbValue) {
|
349
|
+
var rgb = /rgb\((\d+,\s*[\d]+,\s*[\d]+)\)/g.exec(rgbValue);
|
350
|
+
return rgb ? ("rgba(" + (rgb[1]) + ",1)") : rgbValue;
|
351
|
+
}
|
352
|
+
|
353
|
+
function hexToRgba(hexValue) {
|
354
|
+
var rgx = /^#?([a-f\d])([a-f\d])([a-f\d])$/i;
|
355
|
+
var hex = hexValue.replace(rgx, function (m, r, g, b) { return r + r + g + g + b + b; } );
|
356
|
+
var rgb = /^#?([a-f\d]{2})([a-f\d]{2})([a-f\d]{2})$/i.exec(hex);
|
357
|
+
var r = parseInt(rgb[1], 16);
|
358
|
+
var g = parseInt(rgb[2], 16);
|
359
|
+
var b = parseInt(rgb[3], 16);
|
360
|
+
return ("rgba(" + r + "," + g + "," + b + ",1)");
|
361
|
+
}
|
362
|
+
|
363
|
+
function hslToRgba(hslValue) {
|
364
|
+
var hsl = /hsl\((\d+),\s*([\d.]+)%,\s*([\d.]+)%\)/g.exec(hslValue) || /hsla\((\d+),\s*([\d.]+)%,\s*([\d.]+)%,\s*([\d.]+)\)/g.exec(hslValue);
|
365
|
+
var h = parseInt(hsl[1], 10) / 360;
|
366
|
+
var s = parseInt(hsl[2], 10) / 100;
|
367
|
+
var l = parseInt(hsl[3], 10) / 100;
|
368
|
+
var a = hsl[4] || 1;
|
369
|
+
function hue2rgb(p, q, t) {
|
370
|
+
if (t < 0) { t += 1; }
|
371
|
+
if (t > 1) { t -= 1; }
|
372
|
+
if (t < 1/6) { return p + (q - p) * 6 * t; }
|
373
|
+
if (t < 1/2) { return q; }
|
374
|
+
if (t < 2/3) { return p + (q - p) * (2/3 - t) * 6; }
|
375
|
+
return p;
|
376
|
+
}
|
377
|
+
var r, g, b;
|
378
|
+
if (s == 0) {
|
379
|
+
r = g = b = l;
|
380
|
+
} else {
|
381
|
+
var q = l < 0.5 ? l * (1 + s) : l + s - l * s;
|
382
|
+
var p = 2 * l - q;
|
383
|
+
r = hue2rgb(p, q, h + 1/3);
|
384
|
+
g = hue2rgb(p, q, h);
|
385
|
+
b = hue2rgb(p, q, h - 1/3);
|
386
|
+
}
|
387
|
+
return ("rgba(" + (r * 255) + "," + (g * 255) + "," + (b * 255) + "," + a + ")");
|
388
|
+
}
|
389
|
+
|
390
|
+
function colorToRgb(val) {
|
391
|
+
if (is.rgb(val)) { return rgbToRgba(val); }
|
392
|
+
if (is.hex(val)) { return hexToRgba(val); }
|
393
|
+
if (is.hsl(val)) { return hslToRgba(val); }
|
394
|
+
}
|
395
|
+
|
396
|
+
// Units
|
397
|
+
|
398
|
+
function getUnit(val) {
|
399
|
+
var split = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?(%|px|pt|em|rem|in|cm|mm|ex|ch|pc|vw|vh|vmin|vmax|deg|rad|turn)?$/.exec(val);
|
400
|
+
if (split) { return split[1]; }
|
401
|
+
}
|
402
|
+
|
403
|
+
function getTransformUnit(propName) {
|
404
|
+
if (stringContains(propName, 'translate') || propName === 'perspective') { return 'px'; }
|
405
|
+
if (stringContains(propName, 'rotate') || stringContains(propName, 'skew')) { return 'deg'; }
|
406
|
+
}
|
407
|
+
|
408
|
+
// Values
|
409
|
+
|
410
|
+
function getFunctionValue(val, animatable) {
|
411
|
+
if (!is.fnc(val)) { return val; }
|
412
|
+
return val(animatable.target, animatable.id, animatable.total);
|
413
|
+
}
|
414
|
+
|
415
|
+
function getAttribute(el, prop) {
|
416
|
+
return el.getAttribute(prop);
|
417
|
+
}
|
418
|
+
|
419
|
+
function convertPxToUnit(el, value, unit) {
|
420
|
+
var valueUnit = getUnit(value);
|
421
|
+
if (arrayContains([unit, 'deg', 'rad', 'turn'], valueUnit)) { return value; }
|
422
|
+
var cached = cache.CSS[value + unit];
|
423
|
+
if (!is.und(cached)) { return cached; }
|
424
|
+
var baseline = 100;
|
425
|
+
var tempEl = document.createElement(el.tagName);
|
426
|
+
var parentEl = (el.parentNode && (el.parentNode !== document)) ? el.parentNode : document.body;
|
427
|
+
parentEl.appendChild(tempEl);
|
428
|
+
tempEl.style.position = 'absolute';
|
429
|
+
tempEl.style.width = baseline + unit;
|
430
|
+
var factor = baseline / tempEl.offsetWidth;
|
431
|
+
parentEl.removeChild(tempEl);
|
432
|
+
var convertedUnit = factor * parseFloat(value);
|
433
|
+
cache.CSS[value + unit] = convertedUnit;
|
434
|
+
return convertedUnit;
|
435
|
+
}
|
436
|
+
|
437
|
+
function getCSSValue(el, prop, unit) {
|
438
|
+
if (prop in el.style) {
|
439
|
+
var uppercasePropName = prop.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
|
440
|
+
var value = el.style[prop] || getComputedStyle(el).getPropertyValue(uppercasePropName) || '0';
|
441
|
+
return unit ? convertPxToUnit(el, value, unit) : value;
|
442
|
+
}
|
443
|
+
}
|
444
|
+
|
445
|
+
function getAnimationType(el, prop) {
|
446
|
+
if (is.dom(el) && !is.inp(el) && (!is.nil(getAttribute(el, prop)) || (is.svg(el) && el[prop]))) { return 'attribute'; }
|
447
|
+
if (is.dom(el) && arrayContains(validTransforms, prop)) { return 'transform'; }
|
448
|
+
if (is.dom(el) && (prop !== 'transform' && getCSSValue(el, prop))) { return 'css'; }
|
449
|
+
if (el[prop] != null) { return 'object'; }
|
450
|
+
}
|
451
|
+
|
452
|
+
function getElementTransforms(el) {
|
453
|
+
if (!is.dom(el)) { return; }
|
454
|
+
var str = el.style.transform || '';
|
455
|
+
var reg = /(\w+)\(([^)]*)\)/g;
|
456
|
+
var transforms = new Map();
|
457
|
+
var m; while (m = reg.exec(str)) { transforms.set(m[1], m[2]); }
|
458
|
+
return transforms;
|
459
|
+
}
|
460
|
+
|
461
|
+
function getTransformValue(el, propName, animatable, unit) {
|
462
|
+
var defaultVal = stringContains(propName, 'scale') ? 1 : 0 + getTransformUnit(propName);
|
463
|
+
var value = getElementTransforms(el).get(propName) || defaultVal;
|
464
|
+
if (animatable) {
|
465
|
+
animatable.transforms.list.set(propName, value);
|
466
|
+
animatable.transforms['last'] = propName;
|
467
|
+
}
|
468
|
+
return unit ? convertPxToUnit(el, value, unit) : value;
|
469
|
+
}
|
470
|
+
|
471
|
+
function getOriginalTargetValue(target, propName, unit, animatable) {
|
472
|
+
switch (getAnimationType(target, propName)) {
|
473
|
+
case 'transform': return getTransformValue(target, propName, animatable, unit);
|
474
|
+
case 'css': return getCSSValue(target, propName, unit);
|
475
|
+
case 'attribute': return getAttribute(target, propName);
|
476
|
+
default: return target[propName] || 0;
|
477
|
+
}
|
478
|
+
}
|
479
|
+
|
480
|
+
function getRelativeValue(to, from) {
|
481
|
+
var operator = /^(\*=|\+=|-=)/.exec(to);
|
482
|
+
if (!operator) { return to; }
|
483
|
+
var u = getUnit(to) || 0;
|
484
|
+
var x = parseFloat(from);
|
485
|
+
var y = parseFloat(to.replace(operator[0], ''));
|
486
|
+
switch (operator[0][0]) {
|
487
|
+
case '+': return x + y + u;
|
488
|
+
case '-': return x - y + u;
|
489
|
+
case '*': return x * y + u;
|
490
|
+
}
|
491
|
+
}
|
492
|
+
|
493
|
+
function validateValue(val, unit) {
|
494
|
+
if (is.col(val)) { return colorToRgb(val); }
|
495
|
+
if (/\s/g.test(val)) { return val; }
|
496
|
+
var originalUnit = getUnit(val);
|
497
|
+
var unitLess = originalUnit ? val.substr(0, val.length - originalUnit.length) : val;
|
498
|
+
if (unit) { return unitLess + unit; }
|
499
|
+
return unitLess;
|
500
|
+
}
|
501
|
+
|
502
|
+
// getTotalLength() equivalent for circle, rect, polyline, polygon and line shapes
|
503
|
+
// adapted from https://gist.github.com/SebLambla/3e0550c496c236709744
|
504
|
+
|
505
|
+
function getDistance(p1, p2) {
|
506
|
+
return Math.sqrt(Math.pow(p2.x - p1.x, 2) + Math.pow(p2.y - p1.y, 2));
|
507
|
+
}
|
508
|
+
|
509
|
+
function getCircleLength(el) {
|
510
|
+
return Math.PI * 2 * getAttribute(el, 'r');
|
511
|
+
}
|
512
|
+
|
513
|
+
function getRectLength(el) {
|
514
|
+
return (getAttribute(el, 'width') * 2) + (getAttribute(el, 'height') * 2);
|
515
|
+
}
|
516
|
+
|
517
|
+
function getLineLength(el) {
|
518
|
+
return getDistance(
|
519
|
+
{x: getAttribute(el, 'x1'), y: getAttribute(el, 'y1')},
|
520
|
+
{x: getAttribute(el, 'x2'), y: getAttribute(el, 'y2')}
|
521
|
+
);
|
522
|
+
}
|
523
|
+
|
524
|
+
function getPolylineLength(el) {
|
525
|
+
var points = el.points;
|
526
|
+
var totalLength = 0;
|
527
|
+
var previousPos;
|
528
|
+
for (var i = 0 ; i < points.numberOfItems; i++) {
|
529
|
+
var currentPos = points.getItem(i);
|
530
|
+
if (i > 0) { totalLength += getDistance(previousPos, currentPos); }
|
531
|
+
previousPos = currentPos;
|
532
|
+
}
|
533
|
+
return totalLength;
|
534
|
+
}
|
535
|
+
|
536
|
+
function getPolygonLength(el) {
|
537
|
+
var points = el.points;
|
538
|
+
return getPolylineLength(el) + getDistance(points.getItem(points.numberOfItems - 1), points.getItem(0));
|
539
|
+
}
|
540
|
+
|
541
|
+
// Path animation
|
542
|
+
|
543
|
+
function getTotalLength(el) {
|
544
|
+
if (el.getTotalLength) { return el.getTotalLength(); }
|
545
|
+
switch(el.tagName.toLowerCase()) {
|
546
|
+
case 'circle': return getCircleLength(el);
|
547
|
+
case 'rect': return getRectLength(el);
|
548
|
+
case 'line': return getLineLength(el);
|
549
|
+
case 'polyline': return getPolylineLength(el);
|
550
|
+
case 'polygon': return getPolygonLength(el);
|
551
|
+
}
|
552
|
+
}
|
553
|
+
|
554
|
+
function setDashoffset(el) {
|
555
|
+
var pathLength = getTotalLength(el);
|
556
|
+
el.setAttribute('stroke-dasharray', pathLength);
|
557
|
+
return pathLength;
|
558
|
+
}
|
559
|
+
|
560
|
+
// Motion path
|
561
|
+
|
562
|
+
function getParentSvgEl(el) {
|
563
|
+
var parentEl = el.parentNode;
|
564
|
+
while (is.svg(parentEl)) {
|
565
|
+
if (!is.svg(parentEl.parentNode)) { break; }
|
566
|
+
parentEl = parentEl.parentNode;
|
567
|
+
}
|
568
|
+
return parentEl;
|
569
|
+
}
|
570
|
+
|
571
|
+
function getParentSvg(pathEl, svgData) {
|
572
|
+
var svg = svgData || {};
|
573
|
+
var parentSvgEl = svg.el || getParentSvgEl(pathEl);
|
574
|
+
var rect = parentSvgEl.getBoundingClientRect();
|
575
|
+
var viewBoxAttr = getAttribute(parentSvgEl, 'viewBox');
|
576
|
+
var width = rect.width;
|
577
|
+
var height = rect.height;
|
578
|
+
var viewBox = svg.viewBox || (viewBoxAttr ? viewBoxAttr.split(' ') : [0, 0, width, height]);
|
579
|
+
return {
|
580
|
+
el: parentSvgEl,
|
581
|
+
viewBox: viewBox,
|
582
|
+
x: viewBox[0] / 1,
|
583
|
+
y: viewBox[1] / 1,
|
584
|
+
w: width,
|
585
|
+
h: height,
|
586
|
+
vW: viewBox[2],
|
587
|
+
vH: viewBox[3]
|
588
|
+
}
|
589
|
+
}
|
590
|
+
|
591
|
+
function getPath(path, percent) {
|
592
|
+
var pathEl = is.str(path) ? selectString(path)[0] : path;
|
593
|
+
var p = percent || 100;
|
594
|
+
return function(property) {
|
595
|
+
return {
|
596
|
+
property: property,
|
597
|
+
el: pathEl,
|
598
|
+
svg: getParentSvg(pathEl),
|
599
|
+
totalLength: getTotalLength(pathEl) * (p / 100)
|
600
|
+
}
|
601
|
+
}
|
602
|
+
}
|
603
|
+
|
604
|
+
function getPathProgress(path, progress, isPathTargetInsideSVG) {
|
605
|
+
function point(offset) {
|
606
|
+
if ( offset === void 0 ) offset = 0;
|
607
|
+
|
608
|
+
var l = progress + offset >= 1 ? progress + offset : 0;
|
609
|
+
return path.el.getPointAtLength(l);
|
610
|
+
}
|
611
|
+
var svg = getParentSvg(path.el, path.svg);
|
612
|
+
var p = point();
|
613
|
+
var p0 = point(-1);
|
614
|
+
var p1 = point(+1);
|
615
|
+
var scaleX = isPathTargetInsideSVG ? 1 : svg.w / svg.vW;
|
616
|
+
var scaleY = isPathTargetInsideSVG ? 1 : svg.h / svg.vH;
|
617
|
+
switch (path.property) {
|
618
|
+
case 'x': return (p.x - svg.x) * scaleX;
|
619
|
+
case 'y': return (p.y - svg.y) * scaleY;
|
620
|
+
case 'angle': return Math.atan2(p1.y - p0.y, p1.x - p0.x) * 180 / Math.PI;
|
621
|
+
}
|
622
|
+
}
|
623
|
+
|
624
|
+
// Decompose value
|
625
|
+
|
626
|
+
function decomposeValue(val, unit) {
|
627
|
+
// const rgx = /-?\d*\.?\d+/g; // handles basic numbers
|
628
|
+
// const rgx = /[+-]?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation
|
629
|
+
var rgx = /[+-]?\d*\.?\d+(?:\.\d+)?(?:[eE][+-]?\d+)?/g; // handles exponents notation
|
630
|
+
var value = validateValue((is.pth(val) ? val.totalLength : val), unit) + '';
|
631
|
+
return {
|
632
|
+
original: value,
|
633
|
+
numbers: value.match(rgx) ? value.match(rgx).map(Number) : [0],
|
634
|
+
strings: (is.str(val) || unit) ? value.split(rgx) : []
|
635
|
+
}
|
636
|
+
}
|
637
|
+
|
638
|
+
// Animatables
|
639
|
+
|
640
|
+
function parseTargets(targets) {
|
641
|
+
var targetsArray = targets ? (flattenArray(is.arr(targets) ? targets.map(toArray) : toArray(targets))) : [];
|
642
|
+
return filterArray(targetsArray, function (item, pos, self) { return self.indexOf(item) === pos; });
|
643
|
+
}
|
644
|
+
|
645
|
+
function getAnimatables(targets) {
|
646
|
+
var parsed = parseTargets(targets);
|
647
|
+
return parsed.map(function (t, i) {
|
648
|
+
return {target: t, id: i, total: parsed.length, transforms: { list: getElementTransforms(t) } };
|
649
|
+
});
|
650
|
+
}
|
651
|
+
|
652
|
+
// Properties
|
653
|
+
|
654
|
+
function normalizePropertyTweens(prop, tweenSettings) {
|
655
|
+
var settings = cloneObject(tweenSettings);
|
656
|
+
// Override duration if easing is a spring
|
657
|
+
if (/^spring/.test(settings.easing)) { settings.duration = spring(settings.easing); }
|
658
|
+
if (is.arr(prop)) {
|
659
|
+
var l = prop.length;
|
660
|
+
var isFromTo = (l === 2 && !is.obj(prop[0]));
|
661
|
+
if (!isFromTo) {
|
662
|
+
// Duration divided by the number of tweens
|
663
|
+
if (!is.fnc(tweenSettings.duration)) { settings.duration = tweenSettings.duration / l; }
|
664
|
+
} else {
|
665
|
+
// Transform [from, to] values shorthand to a valid tween value
|
666
|
+
prop = {value: prop};
|
667
|
+
}
|
668
|
+
}
|
669
|
+
var propArray = is.arr(prop) ? prop : [prop];
|
670
|
+
return propArray.map(function (v, i) {
|
671
|
+
var obj = (is.obj(v) && !is.pth(v)) ? v : {value: v};
|
672
|
+
// Default delay value should only be applied to the first tween
|
673
|
+
if (is.und(obj.delay)) { obj.delay = !i ? tweenSettings.delay : 0; }
|
674
|
+
// Default endDelay value should only be applied to the last tween
|
675
|
+
if (is.und(obj.endDelay)) { obj.endDelay = i === propArray.length - 1 ? tweenSettings.endDelay : 0; }
|
676
|
+
return obj;
|
677
|
+
}).map(function (k) { return mergeObjects(k, settings); });
|
678
|
+
}
|
679
|
+
|
680
|
+
|
681
|
+
function flattenKeyframes(keyframes) {
|
682
|
+
var propertyNames = filterArray(flattenArray(keyframes.map(function (key) { return Object.keys(key); })), function (p) { return is.key(p); })
|
683
|
+
.reduce(function (a,b) { if (a.indexOf(b) < 0) { a.push(b); } return a; }, []);
|
684
|
+
var properties = {};
|
685
|
+
var loop = function ( i ) {
|
686
|
+
var propName = propertyNames[i];
|
687
|
+
properties[propName] = keyframes.map(function (key) {
|
688
|
+
var newKey = {};
|
689
|
+
for (var p in key) {
|
690
|
+
if (is.key(p)) {
|
691
|
+
if (p == propName) { newKey.value = key[p]; }
|
692
|
+
} else {
|
693
|
+
newKey[p] = key[p];
|
694
|
+
}
|
695
|
+
}
|
696
|
+
return newKey;
|
697
|
+
});
|
698
|
+
};
|
699
|
+
|
700
|
+
for (var i = 0; i < propertyNames.length; i++) loop( i );
|
701
|
+
return properties;
|
702
|
+
}
|
703
|
+
|
704
|
+
function getProperties(tweenSettings, params) {
|
705
|
+
var properties = [];
|
706
|
+
var keyframes = params.keyframes;
|
707
|
+
if (keyframes) { params = mergeObjects(flattenKeyframes(keyframes), params); }
|
708
|
+
for (var p in params) {
|
709
|
+
if (is.key(p)) {
|
710
|
+
properties.push({
|
711
|
+
name: p,
|
712
|
+
tweens: normalizePropertyTweens(params[p], tweenSettings)
|
713
|
+
});
|
714
|
+
}
|
715
|
+
}
|
716
|
+
return properties;
|
717
|
+
}
|
718
|
+
|
719
|
+
// Tweens
|
720
|
+
|
721
|
+
function normalizeTweenValues(tween, animatable) {
|
722
|
+
var t = {};
|
723
|
+
for (var p in tween) {
|
724
|
+
var value = getFunctionValue(tween[p], animatable);
|
725
|
+
if (is.arr(value)) {
|
726
|
+
value = value.map(function (v) { return getFunctionValue(v, animatable); });
|
727
|
+
if (value.length === 1) { value = value[0]; }
|
728
|
+
}
|
729
|
+
t[p] = value;
|
730
|
+
}
|
731
|
+
t.duration = parseFloat(t.duration);
|
732
|
+
t.delay = parseFloat(t.delay);
|
733
|
+
return t;
|
734
|
+
}
|
735
|
+
|
736
|
+
function normalizeTweens(prop, animatable) {
|
737
|
+
var previousTween;
|
738
|
+
return prop.tweens.map(function (t) {
|
739
|
+
var tween = normalizeTweenValues(t, animatable);
|
740
|
+
var tweenValue = tween.value;
|
741
|
+
var to = is.arr(tweenValue) ? tweenValue[1] : tweenValue;
|
742
|
+
var toUnit = getUnit(to);
|
743
|
+
var originalValue = getOriginalTargetValue(animatable.target, prop.name, toUnit, animatable);
|
744
|
+
var previousValue = previousTween ? previousTween.to.original : originalValue;
|
745
|
+
var from = is.arr(tweenValue) ? tweenValue[0] : previousValue;
|
746
|
+
var fromUnit = getUnit(from) || getUnit(originalValue);
|
747
|
+
var unit = toUnit || fromUnit;
|
748
|
+
if (is.und(to)) { to = previousValue; }
|
749
|
+
tween.from = decomposeValue(from, unit);
|
750
|
+
tween.to = decomposeValue(getRelativeValue(to, from), unit);
|
751
|
+
tween.start = previousTween ? previousTween.end : 0;
|
752
|
+
tween.end = tween.start + tween.delay + tween.duration + tween.endDelay;
|
753
|
+
tween.easing = parseEasings(tween.easing, tween.duration);
|
754
|
+
tween.isPath = is.pth(tweenValue);
|
755
|
+
tween.isPathTargetInsideSVG = tween.isPath && is.svg(animatable.target);
|
756
|
+
tween.isColor = is.col(tween.from.original);
|
757
|
+
if (tween.isColor) { tween.round = 1; }
|
758
|
+
previousTween = tween;
|
759
|
+
return tween;
|
760
|
+
});
|
761
|
+
}
|
762
|
+
|
763
|
+
// Tween progress
|
764
|
+
|
765
|
+
var setProgressValue = {
|
766
|
+
css: function (t, p, v) { return t.style[p] = v; },
|
767
|
+
attribute: function (t, p, v) { return t.setAttribute(p, v); },
|
768
|
+
object: function (t, p, v) { return t[p] = v; },
|
769
|
+
transform: function (t, p, v, transforms, manual) {
|
770
|
+
transforms.list.set(p, v);
|
771
|
+
if (p === transforms.last || manual) {
|
772
|
+
var str = '';
|
773
|
+
transforms.list.forEach(function (value, prop) { str += prop + "(" + value + ") "; });
|
774
|
+
t.style.transform = str;
|
775
|
+
}
|
776
|
+
}
|
777
|
+
};
|
778
|
+
|
779
|
+
// Set Value helper
|
780
|
+
|
781
|
+
function setTargetsValue(targets, properties) {
|
782
|
+
var animatables = getAnimatables(targets);
|
783
|
+
animatables.forEach(function (animatable) {
|
784
|
+
for (var property in properties) {
|
785
|
+
var value = getFunctionValue(properties[property], animatable);
|
786
|
+
var target = animatable.target;
|
787
|
+
var valueUnit = getUnit(value);
|
788
|
+
var originalValue = getOriginalTargetValue(target, property, valueUnit, animatable);
|
789
|
+
var unit = valueUnit || getUnit(originalValue);
|
790
|
+
var to = getRelativeValue(validateValue(value, unit), originalValue);
|
791
|
+
var animType = getAnimationType(target, property);
|
792
|
+
setProgressValue[animType](target, property, to, animatable.transforms, true);
|
793
|
+
}
|
794
|
+
});
|
795
|
+
}
|
796
|
+
|
797
|
+
// Animations
|
798
|
+
|
799
|
+
function createAnimation(animatable, prop) {
|
800
|
+
var animType = getAnimationType(animatable.target, prop.name);
|
801
|
+
if (animType) {
|
802
|
+
var tweens = normalizeTweens(prop, animatable);
|
803
|
+
var lastTween = tweens[tweens.length - 1];
|
804
|
+
return {
|
805
|
+
type: animType,
|
806
|
+
property: prop.name,
|
807
|
+
animatable: animatable,
|
808
|
+
tweens: tweens,
|
809
|
+
duration: lastTween.end,
|
810
|
+
delay: tweens[0].delay,
|
811
|
+
endDelay: lastTween.endDelay
|
812
|
+
}
|
813
|
+
}
|
814
|
+
}
|
815
|
+
|
816
|
+
function getAnimations(animatables, properties) {
|
817
|
+
return filterArray(flattenArray(animatables.map(function (animatable) {
|
818
|
+
return properties.map(function (prop) {
|
819
|
+
return createAnimation(animatable, prop);
|
820
|
+
});
|
821
|
+
})), function (a) { return !is.und(a); });
|
822
|
+
}
|
823
|
+
|
824
|
+
// Create Instance
|
825
|
+
|
826
|
+
function getInstanceTimings(animations, tweenSettings) {
|
827
|
+
var animLength = animations.length;
|
828
|
+
var getTlOffset = function (anim) { return anim.timelineOffset ? anim.timelineOffset : 0; };
|
829
|
+
var timings = {};
|
830
|
+
timings.duration = animLength ? Math.max.apply(Math, animations.map(function (anim) { return getTlOffset(anim) + anim.duration; })) : tweenSettings.duration;
|
831
|
+
timings.delay = animLength ? Math.min.apply(Math, animations.map(function (anim) { return getTlOffset(anim) + anim.delay; })) : tweenSettings.delay;
|
832
|
+
timings.endDelay = animLength ? timings.duration - Math.max.apply(Math, animations.map(function (anim) { return getTlOffset(anim) + anim.duration - anim.endDelay; })) : tweenSettings.endDelay;
|
833
|
+
return timings;
|
834
|
+
}
|
835
|
+
|
836
|
+
var instanceID = 0;
|
837
|
+
|
838
|
+
function createNewInstance(params) {
|
839
|
+
var instanceSettings = replaceObjectProps(defaultInstanceSettings, params);
|
840
|
+
var tweenSettings = replaceObjectProps(defaultTweenSettings, params);
|
841
|
+
var properties = getProperties(tweenSettings, params);
|
842
|
+
var animatables = getAnimatables(params.targets);
|
843
|
+
var animations = getAnimations(animatables, properties);
|
844
|
+
var timings = getInstanceTimings(animations, tweenSettings);
|
845
|
+
var id = instanceID;
|
846
|
+
instanceID++;
|
847
|
+
return mergeObjects(instanceSettings, {
|
848
|
+
id: id,
|
849
|
+
children: [],
|
850
|
+
animatables: animatables,
|
851
|
+
animations: animations,
|
852
|
+
duration: timings.duration,
|
853
|
+
delay: timings.delay,
|
854
|
+
endDelay: timings.endDelay
|
855
|
+
});
|
856
|
+
}
|
857
|
+
|
858
|
+
// Core
|
859
|
+
|
860
|
+
var activeInstances = [];
|
861
|
+
|
862
|
+
var engine = (function () {
|
863
|
+
var raf;
|
864
|
+
|
865
|
+
function play() {
|
866
|
+
if (!raf && (!isDocumentHidden() || !anime.suspendWhenDocumentHidden) && activeInstances.length > 0) {
|
867
|
+
raf = requestAnimationFrame(step);
|
868
|
+
}
|
869
|
+
}
|
870
|
+
function step(t) {
|
871
|
+
// memo on algorithm issue:
|
872
|
+
// dangerous iteration over mutable `activeInstances`
|
873
|
+
// (that collection may be updated from within callbacks of `tick`-ed animation instances)
|
874
|
+
var activeInstancesLength = activeInstances.length;
|
875
|
+
var i = 0;
|
876
|
+
while (i < activeInstancesLength) {
|
877
|
+
var activeInstance = activeInstances[i];
|
878
|
+
if (!activeInstance.paused) {
|
879
|
+
activeInstance.tick(t);
|
880
|
+
i++;
|
881
|
+
} else {
|
882
|
+
activeInstances.splice(i, 1);
|
883
|
+
activeInstancesLength--;
|
884
|
+
}
|
885
|
+
}
|
886
|
+
raf = i > 0 ? requestAnimationFrame(step) : undefined;
|
887
|
+
}
|
888
|
+
|
889
|
+
function handleVisibilityChange() {
|
890
|
+
if (!anime.suspendWhenDocumentHidden) { return; }
|
891
|
+
|
892
|
+
if (isDocumentHidden()) {
|
893
|
+
// suspend ticks
|
894
|
+
raf = cancelAnimationFrame(raf);
|
895
|
+
} else { // is back to active tab
|
896
|
+
// first adjust animations to consider the time that ticks were suspended
|
897
|
+
activeInstances.forEach(
|
898
|
+
function (instance) { return instance ._onDocumentVisibility(); }
|
899
|
+
);
|
900
|
+
engine();
|
901
|
+
}
|
902
|
+
}
|
903
|
+
if (typeof document !== 'undefined') {
|
904
|
+
document.addEventListener('visibilitychange', handleVisibilityChange);
|
905
|
+
}
|
906
|
+
|
907
|
+
return play;
|
908
|
+
})();
|
909
|
+
|
910
|
+
function isDocumentHidden() {
|
911
|
+
return !!document && document.hidden;
|
912
|
+
}
|
913
|
+
|
914
|
+
// Public Instance
|
915
|
+
|
916
|
+
function anime(params) {
|
917
|
+
if ( params === void 0 ) params = {};
|
918
|
+
|
919
|
+
|
920
|
+
var startTime = 0, lastTime = 0, now = 0;
|
921
|
+
var children, childrenLength = 0;
|
922
|
+
var resolve = null;
|
923
|
+
|
924
|
+
function makePromise(instance) {
|
925
|
+
var promise = window.Promise && new Promise(function (_resolve) { return resolve = _resolve; });
|
926
|
+
instance.finished = promise;
|
927
|
+
return promise;
|
928
|
+
}
|
929
|
+
|
930
|
+
var instance = createNewInstance(params);
|
931
|
+
var promise = makePromise(instance);
|
932
|
+
|
933
|
+
function toggleInstanceDirection() {
|
934
|
+
var direction = instance.direction;
|
935
|
+
if (direction !== 'alternate') {
|
936
|
+
instance.direction = direction !== 'normal' ? 'normal' : 'reverse';
|
937
|
+
}
|
938
|
+
instance.reversed = !instance.reversed;
|
939
|
+
children.forEach(function (child) { return child.reversed = instance.reversed; });
|
940
|
+
}
|
941
|
+
|
942
|
+
function adjustTime(time) {
|
943
|
+
return instance.reversed ? instance.duration - time : time;
|
944
|
+
}
|
945
|
+
|
946
|
+
function resetTime() {
|
947
|
+
startTime = 0;
|
948
|
+
lastTime = adjustTime(instance.currentTime) * (1 / anime.speed);
|
949
|
+
}
|
950
|
+
|
951
|
+
function seekChild(time, child) {
|
952
|
+
if (child) { child.seek(time - child.timelineOffset); }
|
953
|
+
}
|
954
|
+
|
955
|
+
function syncInstanceChildren(time) {
|
956
|
+
if (!instance.reversePlayback) {
|
957
|
+
for (var i = 0; i < childrenLength; i++) { seekChild(time, children[i]); }
|
958
|
+
} else {
|
959
|
+
for (var i$1 = childrenLength; i$1--;) { seekChild(time, children[i$1]); }
|
960
|
+
}
|
961
|
+
}
|
962
|
+
|
963
|
+
function setAnimationsProgress(insTime) {
|
964
|
+
var i = 0;
|
965
|
+
var animations = instance.animations;
|
966
|
+
var animationsLength = animations.length;
|
967
|
+
while (i < animationsLength) {
|
968
|
+
var anim = animations[i];
|
969
|
+
var animatable = anim.animatable;
|
970
|
+
var tweens = anim.tweens;
|
971
|
+
var tweenLength = tweens.length - 1;
|
972
|
+
var tween = tweens[tweenLength];
|
973
|
+
// Only check for keyframes if there is more than one tween
|
974
|
+
if (tweenLength) { tween = filterArray(tweens, function (t) { return (insTime < t.end); })[0] || tween; }
|
975
|
+
var elapsed = minMax(insTime - tween.start - tween.delay, 0, tween.duration) / tween.duration;
|
976
|
+
var eased = isNaN(elapsed) ? 1 : tween.easing(elapsed);
|
977
|
+
var strings = tween.to.strings;
|
978
|
+
var round = tween.round;
|
979
|
+
var numbers = [];
|
980
|
+
var toNumbersLength = tween.to.numbers.length;
|
981
|
+
var progress = (void 0);
|
982
|
+
for (var n = 0; n < toNumbersLength; n++) {
|
983
|
+
var value = (void 0);
|
984
|
+
var toNumber = tween.to.numbers[n];
|
985
|
+
var fromNumber = tween.from.numbers[n] || 0;
|
986
|
+
if (!tween.isPath) {
|
987
|
+
value = fromNumber + (eased * (toNumber - fromNumber));
|
988
|
+
} else {
|
989
|
+
value = getPathProgress(tween.value, eased * toNumber, tween.isPathTargetInsideSVG);
|
990
|
+
}
|
991
|
+
if (round) {
|
992
|
+
if (!(tween.isColor && n > 2)) {
|
993
|
+
value = Math.round(value * round) / round;
|
994
|
+
}
|
995
|
+
}
|
996
|
+
numbers.push(value);
|
997
|
+
}
|
998
|
+
// Manual Array.reduce for better performances
|
999
|
+
var stringsLength = strings.length;
|
1000
|
+
if (!stringsLength) {
|
1001
|
+
progress = numbers[0];
|
1002
|
+
} else {
|
1003
|
+
progress = strings[0];
|
1004
|
+
for (var s = 0; s < stringsLength; s++) {
|
1005
|
+
var a = strings[s];
|
1006
|
+
var b = strings[s + 1];
|
1007
|
+
var n$1 = numbers[s];
|
1008
|
+
if (!isNaN(n$1)) {
|
1009
|
+
if (!b) {
|
1010
|
+
progress += n$1 + ' ';
|
1011
|
+
} else {
|
1012
|
+
progress += n$1 + b;
|
1013
|
+
}
|
1014
|
+
}
|
1015
|
+
}
|
1016
|
+
}
|
1017
|
+
setProgressValue[anim.type](animatable.target, anim.property, progress, animatable.transforms);
|
1018
|
+
anim.currentValue = progress;
|
1019
|
+
i++;
|
1020
|
+
}
|
1021
|
+
}
|
1022
|
+
|
1023
|
+
function setCallback(cb) {
|
1024
|
+
if (instance[cb] && !instance.passThrough) { instance[cb](instance); }
|
1025
|
+
}
|
1026
|
+
|
1027
|
+
function countIteration() {
|
1028
|
+
if (instance.remaining && instance.remaining !== true) {
|
1029
|
+
instance.remaining--;
|
1030
|
+
}
|
1031
|
+
}
|
1032
|
+
|
1033
|
+
function setInstanceProgress(engineTime) {
|
1034
|
+
var insDuration = instance.duration;
|
1035
|
+
var insDelay = instance.delay;
|
1036
|
+
var insEndDelay = insDuration - instance.endDelay;
|
1037
|
+
var insTime = adjustTime(engineTime);
|
1038
|
+
instance.progress = minMax((insTime / insDuration) * 100, 0, 100);
|
1039
|
+
instance.reversePlayback = insTime < instance.currentTime;
|
1040
|
+
if (children) { syncInstanceChildren(insTime); }
|
1041
|
+
if (!instance.began && instance.currentTime > 0) {
|
1042
|
+
instance.began = true;
|
1043
|
+
setCallback('begin');
|
1044
|
+
}
|
1045
|
+
if (!instance.loopBegan && instance.currentTime > 0) {
|
1046
|
+
instance.loopBegan = true;
|
1047
|
+
setCallback('loopBegin');
|
1048
|
+
}
|
1049
|
+
if (insTime <= insDelay && instance.currentTime !== 0) {
|
1050
|
+
setAnimationsProgress(0);
|
1051
|
+
}
|
1052
|
+
if ((insTime >= insEndDelay && instance.currentTime !== insDuration) || !insDuration) {
|
1053
|
+
setAnimationsProgress(insDuration);
|
1054
|
+
}
|
1055
|
+
if (insTime > insDelay && insTime < insEndDelay) {
|
1056
|
+
if (!instance.changeBegan) {
|
1057
|
+
instance.changeBegan = true;
|
1058
|
+
instance.changeCompleted = false;
|
1059
|
+
setCallback('changeBegin');
|
1060
|
+
}
|
1061
|
+
setCallback('change');
|
1062
|
+
setAnimationsProgress(insTime);
|
1063
|
+
} else {
|
1064
|
+
if (instance.changeBegan) {
|
1065
|
+
instance.changeCompleted = true;
|
1066
|
+
instance.changeBegan = false;
|
1067
|
+
setCallback('changeComplete');
|
1068
|
+
}
|
1069
|
+
}
|
1070
|
+
instance.currentTime = minMax(insTime, 0, insDuration);
|
1071
|
+
if (instance.began) { setCallback('update'); }
|
1072
|
+
if (engineTime >= insDuration) {
|
1073
|
+
lastTime = 0;
|
1074
|
+
countIteration();
|
1075
|
+
if (!instance.remaining) {
|
1076
|
+
instance.paused = true;
|
1077
|
+
if (!instance.completed) {
|
1078
|
+
instance.completed = true;
|
1079
|
+
setCallback('loopComplete');
|
1080
|
+
setCallback('complete');
|
1081
|
+
if (!instance.passThrough && 'Promise' in window) {
|
1082
|
+
resolve();
|
1083
|
+
promise = makePromise(instance);
|
1084
|
+
}
|
1085
|
+
}
|
1086
|
+
} else {
|
1087
|
+
startTime = now;
|
1088
|
+
setCallback('loopComplete');
|
1089
|
+
instance.loopBegan = false;
|
1090
|
+
if (instance.direction === 'alternate') {
|
1091
|
+
toggleInstanceDirection();
|
1092
|
+
}
|
1093
|
+
}
|
1094
|
+
}
|
1095
|
+
}
|
1096
|
+
|
1097
|
+
instance.reset = function() {
|
1098
|
+
var direction = instance.direction;
|
1099
|
+
instance.passThrough = false;
|
1100
|
+
instance.currentTime = 0;
|
1101
|
+
instance.progress = 0;
|
1102
|
+
instance.paused = true;
|
1103
|
+
instance.began = false;
|
1104
|
+
instance.loopBegan = false;
|
1105
|
+
instance.changeBegan = false;
|
1106
|
+
instance.completed = false;
|
1107
|
+
instance.changeCompleted = false;
|
1108
|
+
instance.reversePlayback = false;
|
1109
|
+
instance.reversed = direction === 'reverse';
|
1110
|
+
instance.remaining = instance.loop;
|
1111
|
+
children = instance.children;
|
1112
|
+
childrenLength = children.length;
|
1113
|
+
for (var i = childrenLength; i--;) { instance.children[i].reset(); }
|
1114
|
+
if (instance.reversed && instance.loop !== true || (direction === 'alternate' && instance.loop === 1)) { instance.remaining++; }
|
1115
|
+
setAnimationsProgress(instance.reversed ? instance.duration : 0);
|
1116
|
+
};
|
1117
|
+
|
1118
|
+
// internal method (for engine) to adjust animation timings before restoring engine ticks (rAF)
|
1119
|
+
instance._onDocumentVisibility = resetTime;
|
1120
|
+
|
1121
|
+
// Set Value helper
|
1122
|
+
|
1123
|
+
instance.set = function(targets, properties) {
|
1124
|
+
setTargetsValue(targets, properties);
|
1125
|
+
return instance;
|
1126
|
+
};
|
1127
|
+
|
1128
|
+
instance.tick = function(t) {
|
1129
|
+
now = t;
|
1130
|
+
if (!startTime) { startTime = now; }
|
1131
|
+
setInstanceProgress((now + (lastTime - startTime)) * anime.speed);
|
1132
|
+
};
|
1133
|
+
|
1134
|
+
instance.seek = function(time) {
|
1135
|
+
setInstanceProgress(adjustTime(time));
|
1136
|
+
};
|
1137
|
+
|
1138
|
+
instance.pause = function() {
|
1139
|
+
instance.paused = true;
|
1140
|
+
resetTime();
|
1141
|
+
};
|
1142
|
+
|
1143
|
+
instance.play = function() {
|
1144
|
+
if (!instance.paused) { return; }
|
1145
|
+
if (instance.completed) { instance.reset(); }
|
1146
|
+
instance.paused = false;
|
1147
|
+
activeInstances.push(instance);
|
1148
|
+
resetTime();
|
1149
|
+
engine();
|
1150
|
+
};
|
1151
|
+
|
1152
|
+
instance.reverse = function() {
|
1153
|
+
toggleInstanceDirection();
|
1154
|
+
instance.completed = instance.reversed ? false : true;
|
1155
|
+
resetTime();
|
1156
|
+
};
|
1157
|
+
|
1158
|
+
instance.restart = function() {
|
1159
|
+
instance.reset();
|
1160
|
+
instance.play();
|
1161
|
+
};
|
1162
|
+
|
1163
|
+
instance.remove = function(targets) {
|
1164
|
+
var targetsArray = parseTargets(targets);
|
1165
|
+
removeTargetsFromInstance(targetsArray, instance);
|
1166
|
+
};
|
1167
|
+
|
1168
|
+
instance.reset();
|
1169
|
+
|
1170
|
+
if (instance.autoplay) { instance.play(); }
|
1171
|
+
|
1172
|
+
return instance;
|
1173
|
+
|
1174
|
+
}
|
1175
|
+
|
1176
|
+
// Remove targets from animation
|
1177
|
+
|
1178
|
+
function removeTargetsFromAnimations(targetsArray, animations) {
|
1179
|
+
for (var a = animations.length; a--;) {
|
1180
|
+
if (arrayContains(targetsArray, animations[a].animatable.target)) {
|
1181
|
+
animations.splice(a, 1);
|
1182
|
+
}
|
1183
|
+
}
|
1184
|
+
}
|
1185
|
+
|
1186
|
+
function removeTargetsFromInstance(targetsArray, instance) {
|
1187
|
+
var animations = instance.animations;
|
1188
|
+
var children = instance.children;
|
1189
|
+
removeTargetsFromAnimations(targetsArray, animations);
|
1190
|
+
for (var c = children.length; c--;) {
|
1191
|
+
var child = children[c];
|
1192
|
+
var childAnimations = child.animations;
|
1193
|
+
removeTargetsFromAnimations(targetsArray, childAnimations);
|
1194
|
+
if (!childAnimations.length && !child.children.length) { children.splice(c, 1); }
|
1195
|
+
}
|
1196
|
+
if (!animations.length && !children.length) { instance.pause(); }
|
1197
|
+
}
|
1198
|
+
|
1199
|
+
function removeTargetsFromActiveInstances(targets) {
|
1200
|
+
var targetsArray = parseTargets(targets);
|
1201
|
+
for (var i = activeInstances.length; i--;) {
|
1202
|
+
var instance = activeInstances[i];
|
1203
|
+
removeTargetsFromInstance(targetsArray, instance);
|
1204
|
+
}
|
1205
|
+
}
|
1206
|
+
|
1207
|
+
// Stagger helpers
|
1208
|
+
|
1209
|
+
function stagger(val, params) {
|
1210
|
+
if ( params === void 0 ) params = {};
|
1211
|
+
|
1212
|
+
var direction = params.direction || 'normal';
|
1213
|
+
var easing = params.easing ? parseEasings(params.easing) : null;
|
1214
|
+
var grid = params.grid;
|
1215
|
+
var axis = params.axis;
|
1216
|
+
var fromIndex = params.from || 0;
|
1217
|
+
var fromFirst = fromIndex === 'first';
|
1218
|
+
var fromCenter = fromIndex === 'center';
|
1219
|
+
var fromLast = fromIndex === 'last';
|
1220
|
+
var isRange = is.arr(val);
|
1221
|
+
var val1 = isRange ? parseFloat(val[0]) : parseFloat(val);
|
1222
|
+
var val2 = isRange ? parseFloat(val[1]) : 0;
|
1223
|
+
var unit = getUnit(isRange ? val[1] : val) || 0;
|
1224
|
+
var start = params.start || 0 + (isRange ? val1 : 0);
|
1225
|
+
var values = [];
|
1226
|
+
var maxValue = 0;
|
1227
|
+
return function (el, i, t) {
|
1228
|
+
if (fromFirst) { fromIndex = 0; }
|
1229
|
+
if (fromCenter) { fromIndex = (t - 1) / 2; }
|
1230
|
+
if (fromLast) { fromIndex = t - 1; }
|
1231
|
+
if (!values.length) {
|
1232
|
+
for (var index = 0; index < t; index++) {
|
1233
|
+
if (!grid) {
|
1234
|
+
values.push(Math.abs(fromIndex - index));
|
1235
|
+
} else {
|
1236
|
+
var fromX = !fromCenter ? fromIndex%grid[0] : (grid[0]-1)/2;
|
1237
|
+
var fromY = !fromCenter ? Math.floor(fromIndex/grid[0]) : (grid[1]-1)/2;
|
1238
|
+
var toX = index%grid[0];
|
1239
|
+
var toY = Math.floor(index/grid[0]);
|
1240
|
+
var distanceX = fromX - toX;
|
1241
|
+
var distanceY = fromY - toY;
|
1242
|
+
var value = Math.sqrt(distanceX * distanceX + distanceY * distanceY);
|
1243
|
+
if (axis === 'x') { value = -distanceX; }
|
1244
|
+
if (axis === 'y') { value = -distanceY; }
|
1245
|
+
values.push(value);
|
1246
|
+
}
|
1247
|
+
maxValue = Math.max.apply(Math, values);
|
1248
|
+
}
|
1249
|
+
if (easing) { values = values.map(function (val) { return easing(val / maxValue) * maxValue; }); }
|
1250
|
+
if (direction === 'reverse') { values = values.map(function (val) { return axis ? (val < 0) ? val * -1 : -val : Math.abs(maxValue - val); }); }
|
1251
|
+
}
|
1252
|
+
var spacing = isRange ? (val2 - val1) / maxValue : val1;
|
1253
|
+
return start + (spacing * (Math.round(values[i] * 100) / 100)) + unit;
|
1254
|
+
}
|
1255
|
+
}
|
1256
|
+
|
1257
|
+
// Timeline
|
1258
|
+
|
1259
|
+
function timeline(params) {
|
1260
|
+
if ( params === void 0 ) params = {};
|
1261
|
+
|
1262
|
+
var tl = anime(params);
|
1263
|
+
tl.duration = 0;
|
1264
|
+
tl.add = function(instanceParams, timelineOffset) {
|
1265
|
+
var tlIndex = activeInstances.indexOf(tl);
|
1266
|
+
var children = tl.children;
|
1267
|
+
if (tlIndex > -1) { activeInstances.splice(tlIndex, 1); }
|
1268
|
+
function passThrough(ins) { ins.passThrough = true; }
|
1269
|
+
for (var i = 0; i < children.length; i++) { passThrough(children[i]); }
|
1270
|
+
var insParams = mergeObjects(instanceParams, replaceObjectProps(defaultTweenSettings, params));
|
1271
|
+
insParams.targets = insParams.targets || params.targets;
|
1272
|
+
var tlDuration = tl.duration;
|
1273
|
+
insParams.autoplay = false;
|
1274
|
+
insParams.direction = tl.direction;
|
1275
|
+
insParams.timelineOffset = is.und(timelineOffset) ? tlDuration : getRelativeValue(timelineOffset, tlDuration);
|
1276
|
+
passThrough(tl);
|
1277
|
+
tl.seek(insParams.timelineOffset);
|
1278
|
+
var ins = anime(insParams);
|
1279
|
+
passThrough(ins);
|
1280
|
+
children.push(ins);
|
1281
|
+
var timings = getInstanceTimings(children, params);
|
1282
|
+
tl.delay = timings.delay;
|
1283
|
+
tl.endDelay = timings.endDelay;
|
1284
|
+
tl.duration = timings.duration;
|
1285
|
+
tl.seek(0);
|
1286
|
+
tl.reset();
|
1287
|
+
if (tl.autoplay) { tl.play(); }
|
1288
|
+
return tl;
|
1289
|
+
};
|
1290
|
+
return tl;
|
1291
|
+
}
|
1292
|
+
|
1293
|
+
anime.version = '3.2.1';
|
1294
|
+
anime.speed = 1;
|
1295
|
+
// TODO:#review: naming, documentation
|
1296
|
+
anime.suspendWhenDocumentHidden = true;
|
1297
|
+
anime.running = activeInstances;
|
1298
|
+
anime.remove = removeTargetsFromActiveInstances;
|
1299
|
+
anime.get = getOriginalTargetValue;
|
1300
|
+
anime.set = setTargetsValue;
|
1301
|
+
anime.convertPx = convertPxToUnit;
|
1302
|
+
anime.path = getPath;
|
1303
|
+
anime.setDashoffset = setDashoffset;
|
1304
|
+
anime.stagger = stagger;
|
1305
|
+
anime.timeline = timeline;
|
1306
|
+
anime.easing = parseEasings;
|
1307
|
+
anime.penner = penner;
|
1308
|
+
anime.random = function (min, max) { return Math.floor(Math.random() * (max - min + 1)) + min; };
|
1309
|
+
|
1310
|
+
export default anime;
|