1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
|
3 | typeof define === 'function' && define.amd ? define(['exports'], factory) :
|
4 | (global = global || self, factory(global.window = global.window || {}));
|
5 | }(this, (function (exports) { 'use strict';
|
6 |
|
7 | var _svgPathExp = /[achlmqstvz]|(-?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/ig,
|
8 | _numbersExp = /(?:(-)?\d*\.?\d*(?:e[\-+]?\d+)?)[0-9]/ig,
|
9 | _scientific = /[\+\-]?\d*\.?\d+e[\+\-]?\d+/ig,
|
10 | _selectorExp = /(^[#\.][a-z]|[a-y][a-z])/i,
|
11 | _DEG2RAD = Math.PI / 180,
|
12 | _RAD2DEG = 180 / Math.PI,
|
13 | _sin = Math.sin,
|
14 | _cos = Math.cos,
|
15 | _abs = Math.abs,
|
16 | _sqrt = Math.sqrt,
|
17 | _atan2 = Math.atan2,
|
18 | _largeNum = 1e8,
|
19 | _isString = function _isString(value) {
|
20 | return typeof value === "string";
|
21 | },
|
22 | _isNumber = function _isNumber(value) {
|
23 | return typeof value === "number";
|
24 | },
|
25 | _isUndefined = function _isUndefined(value) {
|
26 | return typeof value === "undefined";
|
27 | },
|
28 | _temp = {},
|
29 | _temp2 = {},
|
30 | _roundingNum = 1e5,
|
31 | _wrapProgress = function _wrapProgress(progress) {
|
32 | return Math.round((progress + _largeNum) % 1 * _roundingNum) / _roundingNum || (progress < 0 ? 0 : 1);
|
33 | },
|
34 | _round = function _round(value) {
|
35 | return Math.round(value * _roundingNum) / _roundingNum || 0;
|
36 | },
|
37 | _roundPrecise = function _roundPrecise(value) {
|
38 | return Math.round(value * 1e10) / 1e10 || 0;
|
39 | },
|
40 | _splitSegment = function _splitSegment(rawPath, segIndex, i, t) {
|
41 | var segment = rawPath[segIndex],
|
42 | shift = t === 1 ? 6 : subdivideSegment(segment, i, t);
|
43 |
|
44 | if (shift && shift + i + 2 < segment.length) {
|
45 | rawPath.splice(segIndex, 0, segment.slice(0, i + shift + 2));
|
46 | segment.splice(0, i + shift);
|
47 | return 1;
|
48 | }
|
49 | },
|
50 | _getSampleIndex = function _getSampleIndex(samples, length, progress) {
|
51 | var l = samples.length,
|
52 | i = ~~(progress * l);
|
53 |
|
54 | if (samples[i] > length) {
|
55 | while (--i && samples[i] > length) {}
|
56 |
|
57 | i < 0 && (i = 0);
|
58 | } else {
|
59 | while (samples[++i] < length && i < l) {}
|
60 | }
|
61 |
|
62 | return i < l ? i : l - 1;
|
63 | },
|
64 | _reverseRawPath = function _reverseRawPath(rawPath, skipOuter) {
|
65 | var i = rawPath.length;
|
66 | skipOuter || rawPath.reverse();
|
67 |
|
68 | while (i--) {
|
69 | rawPath[i].reversed || reverseSegment(rawPath[i]);
|
70 | }
|
71 | },
|
72 | _copyMetaData = function _copyMetaData(source, copy) {
|
73 | copy.totalLength = source.totalLength;
|
74 |
|
75 | if (source.samples) {
|
76 | copy.samples = source.samples.slice(0);
|
77 | copy.lookup = source.lookup.slice(0);
|
78 | copy.minLength = source.minLength;
|
79 | copy.resolution = source.resolution;
|
80 | } else if (source.totalPoints) {
|
81 | copy.totalPoints = source.totalPoints;
|
82 | }
|
83 |
|
84 | return copy;
|
85 | },
|
86 | _appendOrMerge = function _appendOrMerge(rawPath, segment) {
|
87 | var index = rawPath.length,
|
88 | prevSeg = rawPath[index - 1] || [],
|
89 | l = prevSeg.length;
|
90 |
|
91 | if (index && segment[0] === prevSeg[l - 2] && segment[1] === prevSeg[l - 1]) {
|
92 | segment = prevSeg.concat(segment.slice(2));
|
93 | index--;
|
94 | }
|
95 |
|
96 | rawPath[index] = segment;
|
97 | };
|
98 |
|
99 | function getRawPath(value) {
|
100 | value = _isString(value) && _selectorExp.test(value) ? document.querySelector(value) || value : value;
|
101 | var e = value.getAttribute ? value : 0,
|
102 | rawPath;
|
103 |
|
104 | if (e && (value = value.getAttribute("d"))) {
|
105 | if (!e._gsPath) {
|
106 | e._gsPath = {};
|
107 | }
|
108 |
|
109 | rawPath = e._gsPath[value];
|
110 | return rawPath && !rawPath._dirty ? rawPath : e._gsPath[value] = stringToRawPath(value);
|
111 | }
|
112 |
|
113 | return !value ? console.warn("Expecting a <path> element or an SVG path data string") : _isString(value) ? stringToRawPath(value) : _isNumber(value[0]) ? [value] : value;
|
114 | }
|
115 | function copyRawPath(rawPath) {
|
116 | var a = [],
|
117 | i = 0;
|
118 |
|
119 | for (; i < rawPath.length; i++) {
|
120 | a[i] = _copyMetaData(rawPath[i], rawPath[i].slice(0));
|
121 | }
|
122 |
|
123 | return _copyMetaData(rawPath, a);
|
124 | }
|
125 | function reverseSegment(segment) {
|
126 | var i = 0,
|
127 | y;
|
128 | segment.reverse();
|
129 |
|
130 | for (; i < segment.length; i += 2) {
|
131 | y = segment[i];
|
132 | segment[i] = segment[i + 1];
|
133 | segment[i + 1] = y;
|
134 | }
|
135 |
|
136 | segment.reversed = !segment.reversed;
|
137 | }
|
138 |
|
139 | var _createPath = function _createPath(e, ignore) {
|
140 | var path = document.createElementNS("http://www.w3.org/2000/svg", "path"),
|
141 | attr = [].slice.call(e.attributes),
|
142 | i = attr.length,
|
143 | name;
|
144 | ignore = "," + ignore + ",";
|
145 |
|
146 | while (--i > -1) {
|
147 | name = attr[i].nodeName.toLowerCase();
|
148 |
|
149 | if (ignore.indexOf("," + name + ",") < 0) {
|
150 | path.setAttributeNS(null, name, attr[i].nodeValue);
|
151 | }
|
152 | }
|
153 |
|
154 | return path;
|
155 | },
|
156 | _typeAttrs = {
|
157 | rect: "rx,ry,x,y,width,height",
|
158 | circle: "r,cx,cy",
|
159 | ellipse: "rx,ry,cx,cy",
|
160 | line: "x1,x2,y1,y2"
|
161 | },
|
162 | _attrToObj = function _attrToObj(e, attrs) {
|
163 | var props = attrs ? attrs.split(",") : [],
|
164 | obj = {},
|
165 | i = props.length;
|
166 |
|
167 | while (--i > -1) {
|
168 | obj[props[i]] = +e.getAttribute(props[i]) || 0;
|
169 | }
|
170 |
|
171 | return obj;
|
172 | };
|
173 |
|
174 | function convertToPath(element, swap) {
|
175 | var type = element.tagName.toLowerCase(),
|
176 | circ = 0.552284749831,
|
177 | data,
|
178 | x,
|
179 | y,
|
180 | r,
|
181 | ry,
|
182 | path,
|
183 | rcirc,
|
184 | rycirc,
|
185 | points,
|
186 | w,
|
187 | h,
|
188 | x2,
|
189 | x3,
|
190 | x4,
|
191 | x5,
|
192 | x6,
|
193 | y2,
|
194 | y3,
|
195 | y4,
|
196 | y5,
|
197 | y6,
|
198 | attr;
|
199 |
|
200 | if (type === "path" || !element.getBBox) {
|
201 | return element;
|
202 | }
|
203 |
|
204 | path = _createPath(element, "x,y,width,height,cx,cy,rx,ry,r,x1,x2,y1,y2,points");
|
205 | attr = _attrToObj(element, _typeAttrs[type]);
|
206 |
|
207 | if (type === "rect") {
|
208 | r = attr.rx;
|
209 | ry = attr.ry || r;
|
210 | x = attr.x;
|
211 | y = attr.y;
|
212 | w = attr.width - r * 2;
|
213 | h = attr.height - ry * 2;
|
214 |
|
215 | if (r || ry) {
|
216 | x2 = x + r * (1 - circ);
|
217 | x3 = x + r;
|
218 | x4 = x3 + w;
|
219 | x5 = x4 + r * circ;
|
220 | x6 = x4 + r;
|
221 | y2 = y + ry * (1 - circ);
|
222 | y3 = y + ry;
|
223 | y4 = y3 + h;
|
224 | y5 = y4 + ry * circ;
|
225 | y6 = y4 + ry;
|
226 | data = "M" + x6 + "," + y3 + " V" + y4 + " C" + [x6, y5, x5, y6, x4, y6, x4 - (x4 - x3) / 3, y6, x3 + (x4 - x3) / 3, y6, x3, y6, x2, y6, x, y5, x, y4, x, y4 - (y4 - y3) / 3, x, y3 + (y4 - y3) / 3, x, y3, x, y2, x2, y, x3, y, x3 + (x4 - x3) / 3, y, x4 - (x4 - x3) / 3, y, x4, y, x5, y, x6, y2, x6, y3].join(",") + "z";
|
227 | } else {
|
228 | data = "M" + (x + w) + "," + y + " v" + h + " h" + -w + " v" + -h + " h" + w + "z";
|
229 | }
|
230 | } else if (type === "circle" || type === "ellipse") {
|
231 | if (type === "circle") {
|
232 | r = ry = attr.r;
|
233 | rycirc = r * circ;
|
234 | } else {
|
235 | r = attr.rx;
|
236 | ry = attr.ry;
|
237 | rycirc = ry * circ;
|
238 | }
|
239 |
|
240 | x = attr.cx;
|
241 | y = attr.cy;
|
242 | rcirc = r * circ;
|
243 | data = "M" + (x + r) + "," + y + " C" + [x + r, y + rycirc, x + rcirc, y + ry, x, y + ry, x - rcirc, y + ry, x - r, y + rycirc, x - r, y, x - r, y - rycirc, x - rcirc, y - ry, x, y - ry, x + rcirc, y - ry, x + r, y - rycirc, x + r, y].join(",") + "z";
|
244 | } else if (type === "line") {
|
245 | data = "M" + attr.x1 + "," + attr.y1 + " L" + attr.x2 + "," + attr.y2;
|
246 | } else if (type === "polyline" || type === "polygon") {
|
247 | points = (element.getAttribute("points") + "").match(_numbersExp) || [];
|
248 | x = points.shift();
|
249 | y = points.shift();
|
250 | data = "M" + x + "," + y + " L" + points.join(",");
|
251 |
|
252 | if (type === "polygon") {
|
253 | data += "," + x + "," + y + "z";
|
254 | }
|
255 | }
|
256 |
|
257 | path.setAttribute("d", rawPathToString(path._gsRawPath = stringToRawPath(data)));
|
258 |
|
259 | if (swap && element.parentNode) {
|
260 | element.parentNode.insertBefore(path, element);
|
261 | element.parentNode.removeChild(element);
|
262 | }
|
263 |
|
264 | return path;
|
265 | }
|
266 |
|
267 | function getRotationAtBezierT(segment, i, t) {
|
268 | var a = segment[i],
|
269 | b = segment[i + 2],
|
270 | c = segment[i + 4],
|
271 | x;
|
272 | a += (b - a) * t;
|
273 | b += (c - b) * t;
|
274 | a += (b - a) * t;
|
275 | x = b + (c + (segment[i + 6] - c) * t - b) * t - a;
|
276 | a = segment[i + 1];
|
277 | b = segment[i + 3];
|
278 | c = segment[i + 5];
|
279 | a += (b - a) * t;
|
280 | b += (c - b) * t;
|
281 | a += (b - a) * t;
|
282 | return _round(_atan2(b + (c + (segment[i + 7] - c) * t - b) * t - a, x) * _RAD2DEG);
|
283 | }
|
284 |
|
285 | function sliceRawPath(rawPath, start, end) {
|
286 | end = _isUndefined(end) ? 1 : _roundPrecise(end) || 0;
|
287 | start = _roundPrecise(start) || 0;
|
288 | var loops = Math.max(0, ~~(_abs(end - start) - 1e-8)),
|
289 | path = copyRawPath(rawPath);
|
290 |
|
291 | if (start > end) {
|
292 | start = 1 - start;
|
293 | end = 1 - end;
|
294 |
|
295 | _reverseRawPath(path);
|
296 |
|
297 | path.totalLength = 0;
|
298 | }
|
299 |
|
300 | if (start < 0 || end < 0) {
|
301 | var offset = Math.abs(~~Math.min(start, end)) + 1;
|
302 | start += offset;
|
303 | end += offset;
|
304 | }
|
305 |
|
306 | path.totalLength || cacheRawPathMeasurements(path);
|
307 | var wrap = end > 1,
|
308 | s = getProgressData(path, start, _temp, true),
|
309 | e = getProgressData(path, end, _temp2),
|
310 | eSeg = e.segment,
|
311 | sSeg = s.segment,
|
312 | eSegIndex = e.segIndex,
|
313 | sSegIndex = s.segIndex,
|
314 | ei = e.i,
|
315 | si = s.i,
|
316 | sameSegment = sSegIndex === eSegIndex,
|
317 | sameBezier = ei === si && sameSegment,
|
318 | wrapsBehind,
|
319 | sShift,
|
320 | eShift,
|
321 | i,
|
322 | copy,
|
323 | totalSegments,
|
324 | l,
|
325 | j;
|
326 |
|
327 | if (wrap || loops) {
|
328 | wrapsBehind = eSegIndex < sSegIndex || sameSegment && ei < si || sameBezier && e.t < s.t;
|
329 |
|
330 | if (_splitSegment(path, sSegIndex, si, s.t)) {
|
331 | sSegIndex++;
|
332 |
|
333 | if (!wrapsBehind) {
|
334 | eSegIndex++;
|
335 |
|
336 | if (sameBezier) {
|
337 | e.t = (e.t - s.t) / (1 - s.t);
|
338 | ei = 0;
|
339 | } else if (sameSegment) {
|
340 | ei -= si;
|
341 | }
|
342 | }
|
343 | }
|
344 |
|
345 | if (Math.abs(1 - (end - start)) < 1e-5) {
|
346 | eSegIndex = sSegIndex - 1;
|
347 | } else if (!e.t && eSegIndex) {
|
348 | eSegIndex--;
|
349 | } else if (_splitSegment(path, eSegIndex, ei, e.t) && wrapsBehind) {
|
350 | sSegIndex++;
|
351 | }
|
352 |
|
353 | if (s.t === 1) {
|
354 | sSegIndex = (sSegIndex + 1) % path.length;
|
355 | }
|
356 |
|
357 | copy = [];
|
358 | totalSegments = path.length;
|
359 | l = 1 + totalSegments * loops;
|
360 | j = sSegIndex;
|
361 | l += (totalSegments - sSegIndex + eSegIndex) % totalSegments;
|
362 |
|
363 | for (i = 0; i < l; i++) {
|
364 | _appendOrMerge(copy, path[j++ % totalSegments]);
|
365 | }
|
366 |
|
367 | path = copy;
|
368 | } else {
|
369 | eShift = e.t === 1 ? 6 : subdivideSegment(eSeg, ei, e.t);
|
370 |
|
371 | if (start !== end) {
|
372 | sShift = subdivideSegment(sSeg, si, sameBezier ? s.t / e.t : s.t);
|
373 | sameSegment && (eShift += sShift);
|
374 | eSeg.splice(ei + eShift + 2);
|
375 | (sShift || si) && sSeg.splice(0, si + sShift);
|
376 | i = path.length;
|
377 |
|
378 | while (i--) {
|
379 | (i < sSegIndex || i > eSegIndex) && path.splice(i, 1);
|
380 | }
|
381 | } else {
|
382 | eSeg.angle = getRotationAtBezierT(eSeg, ei + eShift, 0);
|
383 | ei += eShift;
|
384 | s = eSeg[ei];
|
385 | e = eSeg[ei + 1];
|
386 | eSeg.length = eSeg.totalLength = 0;
|
387 | eSeg.totalPoints = path.totalPoints = 8;
|
388 | eSeg.push(s, e, s, e, s, e, s, e);
|
389 | }
|
390 | }
|
391 |
|
392 | path.totalLength = 0;
|
393 | return path;
|
394 | }
|
395 |
|
396 | function measureSegment(segment, startIndex, bezierQty) {
|
397 | startIndex = startIndex || 0;
|
398 |
|
399 | if (!segment.samples) {
|
400 | segment.samples = [];
|
401 | segment.lookup = [];
|
402 | }
|
403 |
|
404 | var resolution = ~~segment.resolution || 12,
|
405 | inc = 1 / resolution,
|
406 | endIndex = bezierQty ? startIndex + bezierQty * 6 + 1 : segment.length,
|
407 | x1 = segment[startIndex],
|
408 | y1 = segment[startIndex + 1],
|
409 | samplesIndex = startIndex ? startIndex / 6 * resolution : 0,
|
410 | samples = segment.samples,
|
411 | lookup = segment.lookup,
|
412 | min = (startIndex ? segment.minLength : _largeNum) || _largeNum,
|
413 | prevLength = samples[samplesIndex + bezierQty * resolution - 1],
|
414 | length = startIndex ? samples[samplesIndex - 1] : 0,
|
415 | i,
|
416 | j,
|
417 | x4,
|
418 | x3,
|
419 | x2,
|
420 | xd,
|
421 | xd1,
|
422 | y4,
|
423 | y3,
|
424 | y2,
|
425 | yd,
|
426 | yd1,
|
427 | inv,
|
428 | t,
|
429 | lengthIndex,
|
430 | l,
|
431 | segLength;
|
432 | samples.length = lookup.length = 0;
|
433 |
|
434 | for (j = startIndex + 2; j < endIndex; j += 6) {
|
435 | x4 = segment[j + 4] - x1;
|
436 | x3 = segment[j + 2] - x1;
|
437 | x2 = segment[j] - x1;
|
438 | y4 = segment[j + 5] - y1;
|
439 | y3 = segment[j + 3] - y1;
|
440 | y2 = segment[j + 1] - y1;
|
441 | xd = xd1 = yd = yd1 = 0;
|
442 |
|
443 | if (_abs(x4) < .01 && _abs(y4) < .01 && _abs(x2) + _abs(y2) < .01) {
|
444 | if (segment.length > 8) {
|
445 | segment.splice(j, 6);
|
446 | j -= 6;
|
447 | endIndex -= 6;
|
448 | }
|
449 | } else {
|
450 | for (i = 1; i <= resolution; i++) {
|
451 | t = inc * i;
|
452 | inv = 1 - t;
|
453 | xd = xd1 - (xd1 = (t * t * x4 + 3 * inv * (t * x3 + inv * x2)) * t);
|
454 | yd = yd1 - (yd1 = (t * t * y4 + 3 * inv * (t * y3 + inv * y2)) * t);
|
455 | l = _sqrt(yd * yd + xd * xd);
|
456 |
|
457 | if (l < min) {
|
458 | min = l;
|
459 | }
|
460 |
|
461 | length += l;
|
462 | samples[samplesIndex++] = length;
|
463 | }
|
464 | }
|
465 |
|
466 | x1 += x4;
|
467 | y1 += y4;
|
468 | }
|
469 |
|
470 | if (prevLength) {
|
471 | prevLength -= length;
|
472 |
|
473 | for (; samplesIndex < samples.length; samplesIndex++) {
|
474 | samples[samplesIndex] += prevLength;
|
475 | }
|
476 | }
|
477 |
|
478 | if (samples.length && min) {
|
479 | segment.totalLength = segLength = samples[samples.length - 1] || 0;
|
480 | segment.minLength = min;
|
481 |
|
482 | if (segLength / min < 9999) {
|
483 | l = lengthIndex = 0;
|
484 |
|
485 | for (i = 0; i < segLength; i += min) {
|
486 | lookup[l++] = samples[lengthIndex] < i ? ++lengthIndex : lengthIndex;
|
487 | }
|
488 | }
|
489 | } else {
|
490 | segment.totalLength = samples[0] = 0;
|
491 | }
|
492 |
|
493 | return startIndex ? length - samples[startIndex / 2 - 1] : length;
|
494 | }
|
495 |
|
496 | function cacheRawPathMeasurements(rawPath, resolution) {
|
497 | var pathLength, points, i;
|
498 |
|
499 | for (i = pathLength = points = 0; i < rawPath.length; i++) {
|
500 | rawPath[i].resolution = ~~resolution || 12;
|
501 | points += rawPath[i].length;
|
502 | pathLength += measureSegment(rawPath[i]);
|
503 | }
|
504 |
|
505 | rawPath.totalPoints = points;
|
506 | rawPath.totalLength = pathLength;
|
507 | return rawPath;
|
508 | }
|
509 | function subdivideSegment(segment, i, t) {
|
510 | if (t <= 0 || t >= 1) {
|
511 | return 0;
|
512 | }
|
513 |
|
514 | var ax = segment[i],
|
515 | ay = segment[i + 1],
|
516 | cp1x = segment[i + 2],
|
517 | cp1y = segment[i + 3],
|
518 | cp2x = segment[i + 4],
|
519 | cp2y = segment[i + 5],
|
520 | bx = segment[i + 6],
|
521 | by = segment[i + 7],
|
522 | x1a = ax + (cp1x - ax) * t,
|
523 | x2 = cp1x + (cp2x - cp1x) * t,
|
524 | y1a = ay + (cp1y - ay) * t,
|
525 | y2 = cp1y + (cp2y - cp1y) * t,
|
526 | x1 = x1a + (x2 - x1a) * t,
|
527 | y1 = y1a + (y2 - y1a) * t,
|
528 | x2a = cp2x + (bx - cp2x) * t,
|
529 | y2a = cp2y + (by - cp2y) * t;
|
530 | x2 += (x2a - x2) * t;
|
531 | y2 += (y2a - y2) * t;
|
532 | segment.splice(i + 2, 4, _round(x1a), _round(y1a), _round(x1), _round(y1), _round(x1 + (x2 - x1) * t), _round(y1 + (y2 - y1) * t), _round(x2), _round(y2), _round(x2a), _round(y2a));
|
533 | segment.samples && segment.samples.splice(i / 6 * segment.resolution | 0, 0, 0, 0, 0, 0, 0, 0);
|
534 | return 6;
|
535 | }
|
536 |
|
537 | function getProgressData(rawPath, progress, decoratee, pushToNextIfAtEnd) {
|
538 | decoratee = decoratee || {};
|
539 | rawPath.totalLength || cacheRawPathMeasurements(rawPath);
|
540 |
|
541 | if (progress < 0 || progress > 1) {
|
542 | progress = _wrapProgress(progress);
|
543 | }
|
544 |
|
545 | var segIndex = 0,
|
546 | segment = rawPath[0],
|
547 | samples,
|
548 | resolution,
|
549 | length,
|
550 | min,
|
551 | max,
|
552 | i,
|
553 | t;
|
554 |
|
555 | if (!progress) {
|
556 | t = i = segIndex = 0;
|
557 | segment = rawPath[0];
|
558 | } else if (progress === 1) {
|
559 | t = 1;
|
560 | segIndex = rawPath.length - 1;
|
561 | segment = rawPath[segIndex];
|
562 | i = segment.length - 8;
|
563 | } else {
|
564 | if (rawPath.length > 1) {
|
565 | length = rawPath.totalLength * progress;
|
566 | max = i = 0;
|
567 |
|
568 | while ((max += rawPath[i++].totalLength) < length) {
|
569 | segIndex = i;
|
570 | }
|
571 |
|
572 | segment = rawPath[segIndex];
|
573 | min = max - segment.totalLength;
|
574 | progress = (length - min) / (max - min) || 0;
|
575 | }
|
576 |
|
577 | samples = segment.samples;
|
578 | resolution = segment.resolution;
|
579 | length = segment.totalLength * progress;
|
580 | i = segment.lookup.length ? segment.lookup[~~(length / segment.minLength)] || 0 : _getSampleIndex(samples, length, progress);
|
581 | min = i ? samples[i - 1] : 0;
|
582 | max = samples[i];
|
583 |
|
584 | if (max < length) {
|
585 | min = max;
|
586 | max = samples[++i];
|
587 | }
|
588 |
|
589 | t = 1 / resolution * ((length - min) / (max - min) + i % resolution);
|
590 | i = ~~(i / resolution) * 6;
|
591 |
|
592 | if (pushToNextIfAtEnd && t === 1) {
|
593 | if (i + 6 < segment.length) {
|
594 | i += 6;
|
595 | t = 0;
|
596 | } else if (segIndex + 1 < rawPath.length) {
|
597 | i = t = 0;
|
598 | segment = rawPath[++segIndex];
|
599 | }
|
600 | }
|
601 | }
|
602 |
|
603 | decoratee.t = t;
|
604 | decoratee.i = i;
|
605 | decoratee.path = rawPath;
|
606 | decoratee.segment = segment;
|
607 | decoratee.segIndex = segIndex;
|
608 | return decoratee;
|
609 | }
|
610 |
|
611 | function getPositionOnPath(rawPath, progress, includeAngle, point) {
|
612 | var segment = rawPath[0],
|
613 | result = point || {},
|
614 | samples,
|
615 | resolution,
|
616 | length,
|
617 | min,
|
618 | max,
|
619 | i,
|
620 | t,
|
621 | a,
|
622 | inv;
|
623 |
|
624 | if (progress < 0 || progress > 1) {
|
625 | progress = _wrapProgress(progress);
|
626 | }
|
627 |
|
628 | if (rawPath.length > 1) {
|
629 | length = rawPath.totalLength * progress;
|
630 | max = i = 0;
|
631 |
|
632 | while ((max += rawPath[i++].totalLength) < length) {
|
633 | segment = rawPath[i];
|
634 | }
|
635 |
|
636 | min = max - segment.totalLength;
|
637 | progress = (length - min) / (max - min) || 0;
|
638 | }
|
639 |
|
640 | samples = segment.samples;
|
641 | resolution = segment.resolution;
|
642 | length = segment.totalLength * progress;
|
643 | i = segment.lookup.length ? segment.lookup[progress < 1 ? ~~(length / segment.minLength) : segment.lookup.length - 1] || 0 : _getSampleIndex(samples, length, progress);
|
644 | min = i ? samples[i - 1] : 0;
|
645 | max = samples[i];
|
646 |
|
647 | if (max < length) {
|
648 | min = max;
|
649 | max = samples[++i];
|
650 | }
|
651 |
|
652 | t = 1 / resolution * ((length - min) / (max - min) + i % resolution) || 0;
|
653 | inv = 1 - t;
|
654 | i = ~~(i / resolution) * 6;
|
655 | a = segment[i];
|
656 | result.x = _round((t * t * (segment[i + 6] - a) + 3 * inv * (t * (segment[i + 4] - a) + inv * (segment[i + 2] - a))) * t + a);
|
657 | result.y = _round((t * t * (segment[i + 7] - (a = segment[i + 1])) + 3 * inv * (t * (segment[i + 5] - a) + inv * (segment[i + 3] - a))) * t + a);
|
658 |
|
659 | if (includeAngle) {
|
660 | result.angle = segment.totalLength ? getRotationAtBezierT(segment, i, t >= 1 ? 1 - 1e-9 : t ? t : 1e-9) : segment.angle || 0;
|
661 | }
|
662 |
|
663 | return result;
|
664 | }
|
665 | function transformRawPath(rawPath, a, b, c, d, tx, ty) {
|
666 | var j = rawPath.length,
|
667 | segment,
|
668 | l,
|
669 | i,
|
670 | x,
|
671 | y;
|
672 |
|
673 | while (--j > -1) {
|
674 | segment = rawPath[j];
|
675 | l = segment.length;
|
676 |
|
677 | for (i = 0; i < l; i += 2) {
|
678 | x = segment[i];
|
679 | y = segment[i + 1];
|
680 | segment[i] = x * a + y * c + tx;
|
681 | segment[i + 1] = x * b + y * d + ty;
|
682 | }
|
683 | }
|
684 |
|
685 | rawPath._dirty = 1;
|
686 | return rawPath;
|
687 | }
|
688 |
|
689 | function arcToSegment(lastX, lastY, rx, ry, angle, largeArcFlag, sweepFlag, x, y) {
|
690 | if (lastX === x && lastY === y) {
|
691 | return;
|
692 | }
|
693 |
|
694 | rx = _abs(rx);
|
695 | ry = _abs(ry);
|
696 |
|
697 | var angleRad = angle % 360 * _DEG2RAD,
|
698 | cosAngle = _cos(angleRad),
|
699 | sinAngle = _sin(angleRad),
|
700 | PI = Math.PI,
|
701 | TWOPI = PI * 2,
|
702 | dx2 = (lastX - x) / 2,
|
703 | dy2 = (lastY - y) / 2,
|
704 | x1 = cosAngle * dx2 + sinAngle * dy2,
|
705 | y1 = -sinAngle * dx2 + cosAngle * dy2,
|
706 | x1_sq = x1 * x1,
|
707 | y1_sq = y1 * y1,
|
708 | radiiCheck = x1_sq / (rx * rx) + y1_sq / (ry * ry);
|
709 |
|
710 | if (radiiCheck > 1) {
|
711 | rx = _sqrt(radiiCheck) * rx;
|
712 | ry = _sqrt(radiiCheck) * ry;
|
713 | }
|
714 |
|
715 | var rx_sq = rx * rx,
|
716 | ry_sq = ry * ry,
|
717 | sq = (rx_sq * ry_sq - rx_sq * y1_sq - ry_sq * x1_sq) / (rx_sq * y1_sq + ry_sq * x1_sq);
|
718 |
|
719 | if (sq < 0) {
|
720 | sq = 0;
|
721 | }
|
722 |
|
723 | var coef = (largeArcFlag === sweepFlag ? -1 : 1) * _sqrt(sq),
|
724 | cx1 = coef * (rx * y1 / ry),
|
725 | cy1 = coef * -(ry * x1 / rx),
|
726 | sx2 = (lastX + x) / 2,
|
727 | sy2 = (lastY + y) / 2,
|
728 | cx = sx2 + (cosAngle * cx1 - sinAngle * cy1),
|
729 | cy = sy2 + (sinAngle * cx1 + cosAngle * cy1),
|
730 | ux = (x1 - cx1) / rx,
|
731 | uy = (y1 - cy1) / ry,
|
732 | vx = (-x1 - cx1) / rx,
|
733 | vy = (-y1 - cy1) / ry,
|
734 | temp = ux * ux + uy * uy,
|
735 | angleStart = (uy < 0 ? -1 : 1) * Math.acos(ux / _sqrt(temp)),
|
736 | angleExtent = (ux * vy - uy * vx < 0 ? -1 : 1) * Math.acos((ux * vx + uy * vy) / _sqrt(temp * (vx * vx + vy * vy)));
|
737 |
|
738 | isNaN(angleExtent) && (angleExtent = PI);
|
739 |
|
740 | if (!sweepFlag && angleExtent > 0) {
|
741 | angleExtent -= TWOPI;
|
742 | } else if (sweepFlag && angleExtent < 0) {
|
743 | angleExtent += TWOPI;
|
744 | }
|
745 |
|
746 | angleStart %= TWOPI;
|
747 | angleExtent %= TWOPI;
|
748 |
|
749 | var segments = Math.ceil(_abs(angleExtent) / (TWOPI / 4)),
|
750 | rawPath = [],
|
751 | angleIncrement = angleExtent / segments,
|
752 | controlLength = 4 / 3 * _sin(angleIncrement / 2) / (1 + _cos(angleIncrement / 2)),
|
753 | ma = cosAngle * rx,
|
754 | mb = sinAngle * rx,
|
755 | mc = sinAngle * -ry,
|
756 | md = cosAngle * ry,
|
757 | i;
|
758 |
|
759 | for (i = 0; i < segments; i++) {
|
760 | angle = angleStart + i * angleIncrement;
|
761 | x1 = _cos(angle);
|
762 | y1 = _sin(angle);
|
763 | ux = _cos(angle += angleIncrement);
|
764 | uy = _sin(angle);
|
765 | rawPath.push(x1 - controlLength * y1, y1 + controlLength * x1, ux + controlLength * uy, uy - controlLength * ux, ux, uy);
|
766 | }
|
767 |
|
768 | for (i = 0; i < rawPath.length; i += 2) {
|
769 | x1 = rawPath[i];
|
770 | y1 = rawPath[i + 1];
|
771 | rawPath[i] = x1 * ma + y1 * mc + cx;
|
772 | rawPath[i + 1] = x1 * mb + y1 * md + cy;
|
773 | }
|
774 |
|
775 | rawPath[i - 2] = x;
|
776 | rawPath[i - 1] = y;
|
777 | return rawPath;
|
778 | }
|
779 |
|
780 | function stringToRawPath(d) {
|
781 | var a = (d + "").replace(_scientific, function (m) {
|
782 | var n = +m;
|
783 | return n < 0.0001 && n > -0.0001 ? 0 : n;
|
784 | }).match(_svgPathExp) || [],
|
785 | path = [],
|
786 | relativeX = 0,
|
787 | relativeY = 0,
|
788 | twoThirds = 2 / 3,
|
789 | elements = a.length,
|
790 | points = 0,
|
791 | errorMessage = "ERROR: malformed path: " + d,
|
792 | i,
|
793 | j,
|
794 | x,
|
795 | y,
|
796 | command,
|
797 | isRelative,
|
798 | segment,
|
799 | startX,
|
800 | startY,
|
801 | difX,
|
802 | difY,
|
803 | beziers,
|
804 | prevCommand,
|
805 | flag1,
|
806 | flag2,
|
807 | line = function line(sx, sy, ex, ey) {
|
808 | difX = (ex - sx) / 3;
|
809 | difY = (ey - sy) / 3;
|
810 | segment.push(sx + difX, sy + difY, ex - difX, ey - difY, ex, ey);
|
811 | };
|
812 |
|
813 | if (!d || !isNaN(a[0]) || isNaN(a[1])) {
|
814 | console.log(errorMessage);
|
815 | return path;
|
816 | }
|
817 |
|
818 | for (i = 0; i < elements; i++) {
|
819 | prevCommand = command;
|
820 |
|
821 | if (isNaN(a[i])) {
|
822 | command = a[i].toUpperCase();
|
823 | isRelative = command !== a[i];
|
824 | } else {
|
825 | i--;
|
826 | }
|
827 |
|
828 | x = +a[i + 1];
|
829 | y = +a[i + 2];
|
830 |
|
831 | if (isRelative) {
|
832 | x += relativeX;
|
833 | y += relativeY;
|
834 | }
|
835 |
|
836 | if (!i) {
|
837 | startX = x;
|
838 | startY = y;
|
839 | }
|
840 |
|
841 | if (command === "M") {
|
842 | if (segment) {
|
843 | if (segment.length < 8) {
|
844 | path.length -= 1;
|
845 | } else {
|
846 | points += segment.length;
|
847 | }
|
848 | }
|
849 |
|
850 | relativeX = startX = x;
|
851 | relativeY = startY = y;
|
852 | segment = [x, y];
|
853 | path.push(segment);
|
854 | i += 2;
|
855 | command = "L";
|
856 | } else if (command === "C") {
|
857 | if (!segment) {
|
858 | segment = [0, 0];
|
859 | }
|
860 |
|
861 | if (!isRelative) {
|
862 | relativeX = relativeY = 0;
|
863 | }
|
864 |
|
865 | segment.push(x, y, relativeX + a[i + 3] * 1, relativeY + a[i + 4] * 1, relativeX += a[i + 5] * 1, relativeY += a[i + 6] * 1);
|
866 | i += 6;
|
867 | } else if (command === "S") {
|
868 | difX = relativeX;
|
869 | difY = relativeY;
|
870 |
|
871 | if (prevCommand === "C" || prevCommand === "S") {
|
872 | difX += relativeX - segment[segment.length - 4];
|
873 | difY += relativeY - segment[segment.length - 3];
|
874 | }
|
875 |
|
876 | if (!isRelative) {
|
877 | relativeX = relativeY = 0;
|
878 | }
|
879 |
|
880 | segment.push(difX, difY, x, y, relativeX += a[i + 3] * 1, relativeY += a[i + 4] * 1);
|
881 | i += 4;
|
882 | } else if (command === "Q") {
|
883 | difX = relativeX + (x - relativeX) * twoThirds;
|
884 | difY = relativeY + (y - relativeY) * twoThirds;
|
885 |
|
886 | if (!isRelative) {
|
887 | relativeX = relativeY = 0;
|
888 | }
|
889 |
|
890 | relativeX += a[i + 3] * 1;
|
891 | relativeY += a[i + 4] * 1;
|
892 | segment.push(difX, difY, relativeX + (x - relativeX) * twoThirds, relativeY + (y - relativeY) * twoThirds, relativeX, relativeY);
|
893 | i += 4;
|
894 | } else if (command === "T") {
|
895 | difX = relativeX - segment[segment.length - 4];
|
896 | difY = relativeY - segment[segment.length - 3];
|
897 | segment.push(relativeX + difX, relativeY + difY, x + (relativeX + difX * 1.5 - x) * twoThirds, y + (relativeY + difY * 1.5 - y) * twoThirds, relativeX = x, relativeY = y);
|
898 | i += 2;
|
899 | } else if (command === "H") {
|
900 | line(relativeX, relativeY, relativeX = x, relativeY);
|
901 | i += 1;
|
902 | } else if (command === "V") {
|
903 | line(relativeX, relativeY, relativeX, relativeY = x + (isRelative ? relativeY - relativeX : 0));
|
904 | i += 1;
|
905 | } else if (command === "L" || command === "Z") {
|
906 | if (command === "Z") {
|
907 | x = startX;
|
908 | y = startY;
|
909 | segment.closed = true;
|
910 | }
|
911 |
|
912 | if (command === "L" || _abs(relativeX - x) > 0.5 || _abs(relativeY - y) > 0.5) {
|
913 | line(relativeX, relativeY, x, y);
|
914 |
|
915 | if (command === "L") {
|
916 | i += 2;
|
917 | }
|
918 | }
|
919 |
|
920 | relativeX = x;
|
921 | relativeY = y;
|
922 | } else if (command === "A") {
|
923 | flag1 = a[i + 4];
|
924 | flag2 = a[i + 5];
|
925 | difX = a[i + 6];
|
926 | difY = a[i + 7];
|
927 | j = 7;
|
928 |
|
929 | if (flag1.length > 1) {
|
930 | if (flag1.length < 3) {
|
931 | difY = difX;
|
932 | difX = flag2;
|
933 | j--;
|
934 | } else {
|
935 | difY = flag2;
|
936 | difX = flag1.substr(2);
|
937 | j -= 2;
|
938 | }
|
939 |
|
940 | flag2 = flag1.charAt(1);
|
941 | flag1 = flag1.charAt(0);
|
942 | }
|
943 |
|
944 | beziers = arcToSegment(relativeX, relativeY, +a[i + 1], +a[i + 2], +a[i + 3], +flag1, +flag2, (isRelative ? relativeX : 0) + difX * 1, (isRelative ? relativeY : 0) + difY * 1);
|
945 | i += j;
|
946 |
|
947 | if (beziers) {
|
948 | for (j = 0; j < beziers.length; j++) {
|
949 | segment.push(beziers[j]);
|
950 | }
|
951 | }
|
952 |
|
953 | relativeX = segment[segment.length - 2];
|
954 | relativeY = segment[segment.length - 1];
|
955 | } else {
|
956 | console.log(errorMessage);
|
957 | }
|
958 | }
|
959 |
|
960 | i = segment.length;
|
961 |
|
962 | if (i < 6) {
|
963 | path.pop();
|
964 | i = 0;
|
965 | } else if (segment[0] === segment[i - 2] && segment[1] === segment[i - 1]) {
|
966 | segment.closed = true;
|
967 | }
|
968 |
|
969 | path.totalPoints = points + i;
|
970 | return path;
|
971 | }
|
972 | function flatPointsToSegment(points, curviness) {
|
973 | if (curviness === void 0) {
|
974 | curviness = 1;
|
975 | }
|
976 |
|
977 | var x = points[0],
|
978 | y = 0,
|
979 | segment = [x, y],
|
980 | i = 2;
|
981 |
|
982 | for (; i < points.length; i += 2) {
|
983 | segment.push(x, y, points[i], y = (points[i] - x) * curviness / 2, x = points[i], -y);
|
984 | }
|
985 |
|
986 | return segment;
|
987 | }
|
988 | function pointsToSegment(points, curviness) {
|
989 | _abs(points[0] - points[2]) < 1e-4 && _abs(points[1] - points[3]) < 1e-4 && (points = points.slice(2));
|
990 | var l = points.length - 2,
|
991 | x = +points[0],
|
992 | y = +points[1],
|
993 | nextX = +points[2],
|
994 | nextY = +points[3],
|
995 | segment = [x, y, x, y],
|
996 | dx2 = nextX - x,
|
997 | dy2 = nextY - y,
|
998 | closed = Math.abs(points[l] - x) < 0.001 && Math.abs(points[l + 1] - y) < 0.001,
|
999 | prevX,
|
1000 | prevY,
|
1001 | i,
|
1002 | dx1,
|
1003 | dy1,
|
1004 | r1,
|
1005 | r2,
|
1006 | r3,
|
1007 | tl,
|
1008 | mx1,
|
1009 | mx2,
|
1010 | mxm,
|
1011 | my1,
|
1012 | my2,
|
1013 | mym;
|
1014 |
|
1015 | if (closed) {
|
1016 | points.push(nextX, nextY);
|
1017 | nextX = x;
|
1018 | nextY = y;
|
1019 | x = points[l - 2];
|
1020 | y = points[l - 1];
|
1021 | points.unshift(x, y);
|
1022 | l += 4;
|
1023 | }
|
1024 |
|
1025 | curviness = curviness || curviness === 0 ? +curviness : 1;
|
1026 |
|
1027 | for (i = 2; i < l; i += 2) {
|
1028 | prevX = x;
|
1029 | prevY = y;
|
1030 | x = nextX;
|
1031 | y = nextY;
|
1032 | nextX = +points[i + 2];
|
1033 | nextY = +points[i + 3];
|
1034 |
|
1035 | if (x === nextX && y === nextY) {
|
1036 | continue;
|
1037 | }
|
1038 |
|
1039 | dx1 = dx2;
|
1040 | dy1 = dy2;
|
1041 | dx2 = nextX - x;
|
1042 | dy2 = nextY - y;
|
1043 | r1 = _sqrt(dx1 * dx1 + dy1 * dy1);
|
1044 | r2 = _sqrt(dx2 * dx2 + dy2 * dy2);
|
1045 | r3 = _sqrt(Math.pow(dx2 / r2 + dx1 / r1, 2) + Math.pow(dy2 / r2 + dy1 / r1, 2));
|
1046 | tl = (r1 + r2) * curviness * 0.25 / r3;
|
1047 | mx1 = x - (x - prevX) * (r1 ? tl / r1 : 0);
|
1048 | mx2 = x + (nextX - x) * (r2 ? tl / r2 : 0);
|
1049 | mxm = x - (mx1 + ((mx2 - mx1) * (r1 * 3 / (r1 + r2) + 0.5) / 4 || 0));
|
1050 | my1 = y - (y - prevY) * (r1 ? tl / r1 : 0);
|
1051 | my2 = y + (nextY - y) * (r2 ? tl / r2 : 0);
|
1052 | mym = y - (my1 + ((my2 - my1) * (r1 * 3 / (r1 + r2) + 0.5) / 4 || 0));
|
1053 |
|
1054 | if (x !== prevX || y !== prevY) {
|
1055 | segment.push(_round(mx1 + mxm), _round(my1 + mym), _round(x), _round(y), _round(mx2 + mxm), _round(my2 + mym));
|
1056 | }
|
1057 | }
|
1058 |
|
1059 | x !== nextX || y !== nextY || segment.length < 4 ? segment.push(_round(nextX), _round(nextY), _round(nextX), _round(nextY)) : segment.length -= 2;
|
1060 |
|
1061 | if (segment.length === 2) {
|
1062 | segment.push(x, y, x, y, x, y);
|
1063 | } else if (closed) {
|
1064 | segment.splice(0, 6);
|
1065 | segment.length = segment.length - 6;
|
1066 | }
|
1067 |
|
1068 | return segment;
|
1069 | }
|
1070 | function rawPathToString(rawPath) {
|
1071 | if (_isNumber(rawPath[0])) {
|
1072 | rawPath = [rawPath];
|
1073 | }
|
1074 |
|
1075 | var result = "",
|
1076 | l = rawPath.length,
|
1077 | sl,
|
1078 | s,
|
1079 | i,
|
1080 | segment;
|
1081 |
|
1082 | for (s = 0; s < l; s++) {
|
1083 | segment = rawPath[s];
|
1084 | result += "M" + _round(segment[0]) + "," + _round(segment[1]) + " C";
|
1085 | sl = segment.length;
|
1086 |
|
1087 | for (i = 2; i < sl; i++) {
|
1088 | result += _round(segment[i++]) + "," + _round(segment[i++]) + " " + _round(segment[i++]) + "," + _round(segment[i++]) + " " + _round(segment[i++]) + "," + _round(segment[i]) + " ";
|
1089 | }
|
1090 |
|
1091 | if (segment.closed) {
|
1092 | result += "z";
|
1093 | }
|
1094 | }
|
1095 |
|
1096 | return result;
|
1097 | }
|
1098 |
|
1099 | var _doc,
|
1100 | _win,
|
1101 | _docElement,
|
1102 | _body,
|
1103 | _divContainer,
|
1104 | _svgContainer,
|
1105 | _identityMatrix,
|
1106 | _gEl,
|
1107 | _transformProp = "transform",
|
1108 | _transformOriginProp = _transformProp + "Origin",
|
1109 | _hasOffsetBug,
|
1110 | _setDoc = function _setDoc(element) {
|
1111 | var doc = element.ownerDocument || element;
|
1112 |
|
1113 | if (!(_transformProp in element.style) && "msTransform" in element.style) {
|
1114 | _transformProp = "msTransform";
|
1115 | _transformOriginProp = _transformProp + "Origin";
|
1116 | }
|
1117 |
|
1118 | while (doc.parentNode && (doc = doc.parentNode)) {}
|
1119 |
|
1120 | _win = window;
|
1121 | _identityMatrix = new Matrix2D();
|
1122 |
|
1123 | if (doc) {
|
1124 | _doc = doc;
|
1125 | _docElement = doc.documentElement;
|
1126 | _body = doc.body;
|
1127 | _gEl = _doc.createElementNS("http://www.w3.org/2000/svg", "g");
|
1128 | _gEl.style.transform = "none";
|
1129 | var d1 = doc.createElement("div"),
|
1130 | d2 = doc.createElement("div");
|
1131 |
|
1132 | _body.appendChild(d1);
|
1133 |
|
1134 | d1.appendChild(d2);
|
1135 | d1.style.position = "static";
|
1136 | d1.style[_transformProp] = "translate3d(0,0,1px)";
|
1137 | _hasOffsetBug = d2.offsetParent !== d1;
|
1138 |
|
1139 | _body.removeChild(d1);
|
1140 | }
|
1141 |
|
1142 | return doc;
|
1143 | },
|
1144 | _forceNonZeroScale = function _forceNonZeroScale(e) {
|
1145 | var a, cache;
|
1146 |
|
1147 | while (e && e !== _body) {
|
1148 | cache = e._gsap;
|
1149 | cache && cache.uncache && cache.get(e, "x");
|
1150 |
|
1151 | if (cache && !cache.scaleX && !cache.scaleY && cache.renderTransform) {
|
1152 | cache.scaleX = cache.scaleY = 1e-4;
|
1153 | cache.renderTransform(1, cache);
|
1154 | a ? a.push(cache) : a = [cache];
|
1155 | }
|
1156 |
|
1157 | e = e.parentNode;
|
1158 | }
|
1159 |
|
1160 | return a;
|
1161 | },
|
1162 | _svgTemps = [],
|
1163 | _divTemps = [],
|
1164 | _getDocScrollTop = function _getDocScrollTop() {
|
1165 | return _win.pageYOffset || _doc.scrollTop || _docElement.scrollTop || _body.scrollTop || 0;
|
1166 | },
|
1167 | _getDocScrollLeft = function _getDocScrollLeft() {
|
1168 | return _win.pageXOffset || _doc.scrollLeft || _docElement.scrollLeft || _body.scrollLeft || 0;
|
1169 | },
|
1170 | _svgOwner = function _svgOwner(element) {
|
1171 | return element.ownerSVGElement || ((element.tagName + "").toLowerCase() === "svg" ? element : null);
|
1172 | },
|
1173 | _isFixed = function _isFixed(element) {
|
1174 | if (_win.getComputedStyle(element).position === "fixed") {
|
1175 | return true;
|
1176 | }
|
1177 |
|
1178 | element = element.parentNode;
|
1179 |
|
1180 | if (element && element.nodeType === 1) {
|
1181 | return _isFixed(element);
|
1182 | }
|
1183 | },
|
1184 | _createSibling = function _createSibling(element, i) {
|
1185 | if (element.parentNode && (_doc || _setDoc(element))) {
|
1186 | var svg = _svgOwner(element),
|
1187 | ns = svg ? svg.getAttribute("xmlns") || "http://www.w3.org/2000/svg" : "http://www.w3.org/1999/xhtml",
|
1188 | type = svg ? i ? "rect" : "g" : "div",
|
1189 | x = i !== 2 ? 0 : 100,
|
1190 | y = i === 3 ? 100 : 0,
|
1191 | css = "position:absolute;display:block;pointer-events:none;margin:0;padding:0;",
|
1192 | e = _doc.createElementNS ? _doc.createElementNS(ns.replace(/^https/, "http"), type) : _doc.createElement(type);
|
1193 |
|
1194 | if (i) {
|
1195 | if (!svg) {
|
1196 | if (!_divContainer) {
|
1197 | _divContainer = _createSibling(element);
|
1198 | _divContainer.style.cssText = css;
|
1199 | }
|
1200 |
|
1201 | e.style.cssText = css + "width:0.1px;height:0.1px;top:" + y + "px;left:" + x + "px";
|
1202 |
|
1203 | _divContainer.appendChild(e);
|
1204 | } else {
|
1205 | _svgContainer || (_svgContainer = _createSibling(element));
|
1206 | e.setAttribute("width", 0.01);
|
1207 | e.setAttribute("height", 0.01);
|
1208 | e.setAttribute("transform", "translate(" + x + "," + y + ")");
|
1209 |
|
1210 | _svgContainer.appendChild(e);
|
1211 | }
|
1212 | }
|
1213 |
|
1214 | return e;
|
1215 | }
|
1216 |
|
1217 | throw "Need document and parent.";
|
1218 | },
|
1219 | _consolidate = function _consolidate(m) {
|
1220 | var c = new Matrix2D(),
|
1221 | i = 0;
|
1222 |
|
1223 | for (; i < m.numberOfItems; i++) {
|
1224 | c.multiply(m.getItem(i).matrix);
|
1225 | }
|
1226 |
|
1227 | return c;
|
1228 | },
|
1229 | _getCTM = function _getCTM(svg) {
|
1230 | var m = svg.getCTM(),
|
1231 | transform;
|
1232 |
|
1233 | if (!m) {
|
1234 | transform = svg.style[_transformProp];
|
1235 | svg.style[_transformProp] = "none";
|
1236 | svg.appendChild(_gEl);
|
1237 | m = _gEl.getCTM();
|
1238 | svg.removeChild(_gEl);
|
1239 | transform ? svg.style[_transformProp] = transform : svg.style.removeProperty(_transformProp.replace(/([A-Z])/g, "-$1").toLowerCase());
|
1240 | }
|
1241 |
|
1242 | return m || _identityMatrix.clone();
|
1243 | },
|
1244 | _placeSiblings = function _placeSiblings(element, adjustGOffset) {
|
1245 | var svg = _svgOwner(element),
|
1246 | isRootSVG = element === svg,
|
1247 | siblings = svg ? _svgTemps : _divTemps,
|
1248 | parent = element.parentNode,
|
1249 | container,
|
1250 | m,
|
1251 | b,
|
1252 | x,
|
1253 | y,
|
1254 | cs;
|
1255 |
|
1256 | if (element === _win) {
|
1257 | return element;
|
1258 | }
|
1259 |
|
1260 | siblings.length || siblings.push(_createSibling(element, 1), _createSibling(element, 2), _createSibling(element, 3));
|
1261 | container = svg ? _svgContainer : _divContainer;
|
1262 |
|
1263 | if (svg) {
|
1264 | if (isRootSVG) {
|
1265 | b = _getCTM(element);
|
1266 | x = -b.e / b.a;
|
1267 | y = -b.f / b.d;
|
1268 | m = _identityMatrix;
|
1269 | } else if (element.getBBox) {
|
1270 | b = element.getBBox();
|
1271 | m = element.transform ? element.transform.baseVal : {};
|
1272 | m = !m.numberOfItems ? _identityMatrix : m.numberOfItems > 1 ? _consolidate(m) : m.getItem(0).matrix;
|
1273 | x = m.a * b.x + m.c * b.y;
|
1274 | y = m.b * b.x + m.d * b.y;
|
1275 | } else {
|
1276 | m = new Matrix2D();
|
1277 | x = y = 0;
|
1278 | }
|
1279 |
|
1280 | if (adjustGOffset && element.tagName.toLowerCase() === "g") {
|
1281 | x = y = 0;
|
1282 | }
|
1283 |
|
1284 | (isRootSVG ? svg : parent).appendChild(container);
|
1285 | container.setAttribute("transform", "matrix(" + m.a + "," + m.b + "," + m.c + "," + m.d + "," + (m.e + x) + "," + (m.f + y) + ")");
|
1286 | } else {
|
1287 | x = y = 0;
|
1288 |
|
1289 | if (_hasOffsetBug) {
|
1290 | m = element.offsetParent;
|
1291 | b = element;
|
1292 |
|
1293 | while (b && (b = b.parentNode) && b !== m && b.parentNode) {
|
1294 | if ((_win.getComputedStyle(b)[_transformProp] + "").length > 4) {
|
1295 | x = b.offsetLeft;
|
1296 | y = b.offsetTop;
|
1297 | b = 0;
|
1298 | }
|
1299 | }
|
1300 | }
|
1301 |
|
1302 | cs = _win.getComputedStyle(element);
|
1303 |
|
1304 | if (cs.position !== "absolute" && cs.position !== "fixed") {
|
1305 | m = element.offsetParent;
|
1306 |
|
1307 | while (parent && parent !== m) {
|
1308 | x += parent.scrollLeft || 0;
|
1309 | y += parent.scrollTop || 0;
|
1310 | parent = parent.parentNode;
|
1311 | }
|
1312 | }
|
1313 |
|
1314 | b = container.style;
|
1315 | b.top = element.offsetTop - y + "px";
|
1316 | b.left = element.offsetLeft - x + "px";
|
1317 | b[_transformProp] = cs[_transformProp];
|
1318 | b[_transformOriginProp] = cs[_transformOriginProp];
|
1319 | b.position = cs.position === "fixed" ? "fixed" : "absolute";
|
1320 | element.parentNode.appendChild(container);
|
1321 | }
|
1322 |
|
1323 | return container;
|
1324 | },
|
1325 | _setMatrix = function _setMatrix(m, a, b, c, d, e, f) {
|
1326 | m.a = a;
|
1327 | m.b = b;
|
1328 | m.c = c;
|
1329 | m.d = d;
|
1330 | m.e = e;
|
1331 | m.f = f;
|
1332 | return m;
|
1333 | };
|
1334 |
|
1335 | var Matrix2D = function () {
|
1336 | function Matrix2D(a, b, c, d, e, f) {
|
1337 | if (a === void 0) {
|
1338 | a = 1;
|
1339 | }
|
1340 |
|
1341 | if (b === void 0) {
|
1342 | b = 0;
|
1343 | }
|
1344 |
|
1345 | if (c === void 0) {
|
1346 | c = 0;
|
1347 | }
|
1348 |
|
1349 | if (d === void 0) {
|
1350 | d = 1;
|
1351 | }
|
1352 |
|
1353 | if (e === void 0) {
|
1354 | e = 0;
|
1355 | }
|
1356 |
|
1357 | if (f === void 0) {
|
1358 | f = 0;
|
1359 | }
|
1360 |
|
1361 | _setMatrix(this, a, b, c, d, e, f);
|
1362 | }
|
1363 |
|
1364 | var _proto = Matrix2D.prototype;
|
1365 |
|
1366 | _proto.inverse = function inverse() {
|
1367 | var a = this.a,
|
1368 | b = this.b,
|
1369 | c = this.c,
|
1370 | d = this.d,
|
1371 | e = this.e,
|
1372 | f = this.f,
|
1373 | determinant = a * d - b * c || 1e-10;
|
1374 | return _setMatrix(this, d / determinant, -b / determinant, -c / determinant, a / determinant, (c * f - d * e) / determinant, -(a * f - b * e) / determinant);
|
1375 | };
|
1376 |
|
1377 | _proto.multiply = function multiply(matrix) {
|
1378 | var a = this.a,
|
1379 | b = this.b,
|
1380 | c = this.c,
|
1381 | d = this.d,
|
1382 | e = this.e,
|
1383 | f = this.f,
|
1384 | a2 = matrix.a,
|
1385 | b2 = matrix.c,
|
1386 | c2 = matrix.b,
|
1387 | d2 = matrix.d,
|
1388 | e2 = matrix.e,
|
1389 | f2 = matrix.f;
|
1390 | return _setMatrix(this, a2 * a + c2 * c, a2 * b + c2 * d, b2 * a + d2 * c, b2 * b + d2 * d, e + e2 * a + f2 * c, f + e2 * b + f2 * d);
|
1391 | };
|
1392 |
|
1393 | _proto.clone = function clone() {
|
1394 | return new Matrix2D(this.a, this.b, this.c, this.d, this.e, this.f);
|
1395 | };
|
1396 |
|
1397 | _proto.equals = function equals(matrix) {
|
1398 | var a = this.a,
|
1399 | b = this.b,
|
1400 | c = this.c,
|
1401 | d = this.d,
|
1402 | e = this.e,
|
1403 | f = this.f;
|
1404 | return a === matrix.a && b === matrix.b && c === matrix.c && d === matrix.d && e === matrix.e && f === matrix.f;
|
1405 | };
|
1406 |
|
1407 | _proto.apply = function apply(point, decoratee) {
|
1408 | if (decoratee === void 0) {
|
1409 | decoratee = {};
|
1410 | }
|
1411 |
|
1412 | var x = point.x,
|
1413 | y = point.y,
|
1414 | a = this.a,
|
1415 | b = this.b,
|
1416 | c = this.c,
|
1417 | d = this.d,
|
1418 | e = this.e,
|
1419 | f = this.f;
|
1420 | decoratee.x = x * a + y * c + e || 0;
|
1421 | decoratee.y = x * b + y * d + f || 0;
|
1422 | return decoratee;
|
1423 | };
|
1424 |
|
1425 | return Matrix2D;
|
1426 | }();
|
1427 | function getGlobalMatrix(element, inverse, adjustGOffset, includeScrollInFixed) {
|
1428 | if (!element || !element.parentNode || (_doc || _setDoc(element)).documentElement === element) {
|
1429 | return new Matrix2D();
|
1430 | }
|
1431 |
|
1432 | var zeroScales = _forceNonZeroScale(element),
|
1433 | svg = _svgOwner(element),
|
1434 | temps = svg ? _svgTemps : _divTemps,
|
1435 | container = _placeSiblings(element, adjustGOffset),
|
1436 | b1 = temps[0].getBoundingClientRect(),
|
1437 | b2 = temps[1].getBoundingClientRect(),
|
1438 | b3 = temps[2].getBoundingClientRect(),
|
1439 | parent = container.parentNode,
|
1440 | isFixed = !includeScrollInFixed && _isFixed(element),
|
1441 | m = new Matrix2D((b2.left - b1.left) / 100, (b2.top - b1.top) / 100, (b3.left - b1.left) / 100, (b3.top - b1.top) / 100, b1.left + (isFixed ? 0 : _getDocScrollLeft()), b1.top + (isFixed ? 0 : _getDocScrollTop()));
|
1442 |
|
1443 | parent.removeChild(container);
|
1444 |
|
1445 | if (zeroScales) {
|
1446 | b1 = zeroScales.length;
|
1447 |
|
1448 | while (b1--) {
|
1449 | b2 = zeroScales[b1];
|
1450 | b2.scaleX = b2.scaleY = 0;
|
1451 | b2.renderTransform(1, b2);
|
1452 | }
|
1453 | }
|
1454 |
|
1455 | return inverse ? m.inverse() : m;
|
1456 | }
|
1457 |
|
1458 | |
1459 |
|
1460 |
|
1461 |
|
1462 |
|
1463 |
|
1464 |
|
1465 |
|
1466 |
|
1467 |
|
1468 | var _xProps = "x,translateX,left,marginLeft,xPercent".split(","),
|
1469 | _yProps = "y,translateY,top,marginTop,yPercent".split(","),
|
1470 | _DEG2RAD$1 = Math.PI / 180,
|
1471 | gsap,
|
1472 | PropTween,
|
1473 | _getUnit,
|
1474 | _toArray,
|
1475 | _getGSAP = function _getGSAP() {
|
1476 | return gsap || typeof window !== "undefined" && (gsap = window.gsap) && gsap.registerPlugin && gsap;
|
1477 | },
|
1478 | _populateSegmentFromArray = function _populateSegmentFromArray(segment, values, property, mode) {
|
1479 | var l = values.length,
|
1480 | si = mode === 2 ? 0 : mode,
|
1481 | i = 0,
|
1482 | v;
|
1483 |
|
1484 | for (; i < l; i++) {
|
1485 | segment[si] = v = parseFloat(values[i][property]);
|
1486 | mode === 2 && (segment[si + 1] = 0);
|
1487 | si += 2;
|
1488 | }
|
1489 |
|
1490 | return segment;
|
1491 | },
|
1492 | _getPropNum = function _getPropNum(target, prop, unit) {
|
1493 | return parseFloat(target._gsap.get(target, prop, unit || "px")) || 0;
|
1494 | },
|
1495 | _relativize = function _relativize(segment) {
|
1496 | var x = segment[0],
|
1497 | y = segment[1],
|
1498 | i;
|
1499 |
|
1500 | for (i = 2; i < segment.length; i += 2) {
|
1501 | x = segment[i] += x;
|
1502 | y = segment[i + 1] += y;
|
1503 | }
|
1504 | },
|
1505 | _segmentToRawPath = function _segmentToRawPath(plugin, segment, target, x, y, slicer, vars, unitX, unitY) {
|
1506 | if (vars.type === "cubic") {
|
1507 | segment = [segment];
|
1508 | } else {
|
1509 | vars.fromCurrent !== false && segment.unshift(_getPropNum(target, x, unitX), y ? _getPropNum(target, y, unitY) : 0);
|
1510 | vars.relative && _relativize(segment);
|
1511 | var pointFunc = y ? pointsToSegment : flatPointsToSegment;
|
1512 | segment = [pointFunc(segment, vars.curviness)];
|
1513 | }
|
1514 |
|
1515 | segment = slicer(_align(segment, target, vars));
|
1516 |
|
1517 | _addDimensionalPropTween(plugin, target, x, segment, "x", unitX);
|
1518 |
|
1519 | y && _addDimensionalPropTween(plugin, target, y, segment, "y", unitY);
|
1520 | return cacheRawPathMeasurements(segment, vars.resolution || (vars.curviness === 0 ? 20 : 12));
|
1521 | },
|
1522 | _emptyFunc = function _emptyFunc(v) {
|
1523 | return v;
|
1524 | },
|
1525 | _numExp = /[-+\.]*\d+\.?(?:e-|e\+)?\d*/g,
|
1526 | _originToPoint = function _originToPoint(element, origin, parentMatrix) {
|
1527 | var m = getGlobalMatrix(element),
|
1528 | x = 0,
|
1529 | y = 0,
|
1530 | svg;
|
1531 |
|
1532 | if ((element.tagName + "").toLowerCase() === "svg") {
|
1533 | svg = element.viewBox.baseVal;
|
1534 | svg.width || (svg = {
|
1535 | width: +element.getAttribute("width"),
|
1536 | height: +element.getAttribute("height")
|
1537 | });
|
1538 | } else {
|
1539 | svg = origin && element.getBBox && element.getBBox();
|
1540 | }
|
1541 |
|
1542 | if (origin && origin !== "auto") {
|
1543 | x = origin.push ? origin[0] * (svg ? svg.width : element.offsetWidth || 0) : origin.x;
|
1544 | y = origin.push ? origin[1] * (svg ? svg.height : element.offsetHeight || 0) : origin.y;
|
1545 | }
|
1546 |
|
1547 | return parentMatrix.apply(x || y ? m.apply({
|
1548 | x: x,
|
1549 | y: y
|
1550 | }) : {
|
1551 | x: m.e,
|
1552 | y: m.f
|
1553 | });
|
1554 | },
|
1555 | _getAlignMatrix = function _getAlignMatrix(fromElement, toElement, fromOrigin, toOrigin) {
|
1556 | var parentMatrix = getGlobalMatrix(fromElement.parentNode, true, true),
|
1557 | m = parentMatrix.clone().multiply(getGlobalMatrix(toElement)),
|
1558 | fromPoint = _originToPoint(fromElement, fromOrigin, parentMatrix),
|
1559 | _originToPoint2 = _originToPoint(toElement, toOrigin, parentMatrix),
|
1560 | x = _originToPoint2.x,
|
1561 | y = _originToPoint2.y,
|
1562 | p;
|
1563 |
|
1564 | m.e = m.f = 0;
|
1565 |
|
1566 | if (toOrigin === "auto" && toElement.getTotalLength && toElement.tagName.toLowerCase() === "path") {
|
1567 | p = toElement.getAttribute("d").match(_numExp) || [];
|
1568 | p = m.apply({
|
1569 | x: +p[0],
|
1570 | y: +p[1]
|
1571 | });
|
1572 | x += p.x;
|
1573 | y += p.y;
|
1574 | }
|
1575 |
|
1576 | if (p || toElement.getBBox && fromElement.getBBox && toElement.ownerSVGElement === fromElement.ownerSVGElement) {
|
1577 | p = m.apply(toElement.getBBox());
|
1578 | x -= p.x;
|
1579 | y -= p.y;
|
1580 | }
|
1581 |
|
1582 | m.e = x - fromPoint.x;
|
1583 | m.f = y - fromPoint.y;
|
1584 | return m;
|
1585 | },
|
1586 | _align = function _align(rawPath, target, _ref) {
|
1587 | var align = _ref.align,
|
1588 | matrix = _ref.matrix,
|
1589 | offsetX = _ref.offsetX,
|
1590 | offsetY = _ref.offsetY,
|
1591 | alignOrigin = _ref.alignOrigin;
|
1592 |
|
1593 | var x = rawPath[0][0],
|
1594 | y = rawPath[0][1],
|
1595 | curX = _getPropNum(target, "x"),
|
1596 | curY = _getPropNum(target, "y"),
|
1597 | alignTarget,
|
1598 | m,
|
1599 | p;
|
1600 |
|
1601 | if (!rawPath || !rawPath.length) {
|
1602 | return getRawPath("M0,0L0,0");
|
1603 | }
|
1604 |
|
1605 | if (align) {
|
1606 | if (align === "self" || (alignTarget = _toArray(align)[0] || target) === target) {
|
1607 | transformRawPath(rawPath, 1, 0, 0, 1, curX - x, curY - y);
|
1608 | } else {
|
1609 | if (alignOrigin && alignOrigin[2] !== false) {
|
1610 | gsap.set(target, {
|
1611 | transformOrigin: alignOrigin[0] * 100 + "% " + alignOrigin[1] * 100 + "%"
|
1612 | });
|
1613 | } else {
|
1614 | alignOrigin = [_getPropNum(target, "xPercent") / -100, _getPropNum(target, "yPercent") / -100];
|
1615 | }
|
1616 |
|
1617 | m = _getAlignMatrix(target, alignTarget, alignOrigin, "auto");
|
1618 | p = m.apply({
|
1619 | x: x,
|
1620 | y: y
|
1621 | });
|
1622 | transformRawPath(rawPath, m.a, m.b, m.c, m.d, curX + m.e - (p.x - m.e), curY + m.f - (p.y - m.f));
|
1623 | }
|
1624 | }
|
1625 |
|
1626 | if (matrix) {
|
1627 | transformRawPath(rawPath, matrix.a, matrix.b, matrix.c, matrix.d, matrix.e, matrix.f);
|
1628 | } else if (offsetX || offsetY) {
|
1629 | transformRawPath(rawPath, 1, 0, 0, 1, offsetX || 0, offsetY || 0);
|
1630 | }
|
1631 |
|
1632 | return rawPath;
|
1633 | },
|
1634 | _addDimensionalPropTween = function _addDimensionalPropTween(plugin, target, property, rawPath, pathProperty, forceUnit) {
|
1635 | var cache = target._gsap,
|
1636 | harness = cache.harness,
|
1637 | alias = harness && harness.aliases && harness.aliases[property],
|
1638 | prop = alias && alias.indexOf(",") < 0 ? alias : property,
|
1639 | pt = plugin._pt = new PropTween(plugin._pt, target, prop, 0, 0, _emptyFunc, 0, cache.set(target, prop, plugin));
|
1640 | pt.u = _getUnit(cache.get(target, prop, forceUnit)) || 0;
|
1641 | pt.path = rawPath;
|
1642 | pt.pp = pathProperty;
|
1643 |
|
1644 | plugin._props.push(prop);
|
1645 | },
|
1646 | _sliceModifier = function _sliceModifier(start, end) {
|
1647 | return function (rawPath) {
|
1648 | return start || end !== 1 ? sliceRawPath(rawPath, start, end) : rawPath;
|
1649 | };
|
1650 | };
|
1651 |
|
1652 | var MotionPathPlugin = {
|
1653 | version: "3.10.3",
|
1654 | name: "motionPath",
|
1655 | register: function register(core, Plugin, propTween) {
|
1656 | gsap = core;
|
1657 | _getUnit = gsap.utils.getUnit;
|
1658 | _toArray = gsap.utils.toArray;
|
1659 | PropTween = propTween;
|
1660 | },
|
1661 | init: function init(target, vars) {
|
1662 | if (!gsap) {
|
1663 | console.warn("Please gsap.registerPlugin(MotionPathPlugin)");
|
1664 | return false;
|
1665 | }
|
1666 |
|
1667 | if (!(typeof vars === "object" && !vars.style) || !vars.path) {
|
1668 | vars = {
|
1669 | path: vars
|
1670 | };
|
1671 | }
|
1672 |
|
1673 | var rawPaths = [],
|
1674 | _vars = vars,
|
1675 | path = _vars.path,
|
1676 | autoRotate = _vars.autoRotate,
|
1677 | unitX = _vars.unitX,
|
1678 | unitY = _vars.unitY,
|
1679 | x = _vars.x,
|
1680 | y = _vars.y,
|
1681 | firstObj = path[0],
|
1682 | slicer = _sliceModifier(vars.start, "end" in vars ? vars.end : 1),
|
1683 | rawPath,
|
1684 | p;
|
1685 |
|
1686 | this.rawPaths = rawPaths;
|
1687 | this.target = target;
|
1688 |
|
1689 | if (this.rotate = autoRotate || autoRotate === 0) {
|
1690 | this.rOffset = parseFloat(autoRotate) || 0;
|
1691 | this.radians = !!vars.useRadians;
|
1692 | this.rProp = vars.rotation || "rotation";
|
1693 | this.rSet = target._gsap.set(target, this.rProp, this);
|
1694 | this.ru = _getUnit(target._gsap.get(target, this.rProp)) || 0;
|
1695 | }
|
1696 |
|
1697 | if (Array.isArray(path) && !("closed" in path) && typeof firstObj !== "number") {
|
1698 | for (p in firstObj) {
|
1699 | if (!x && ~_xProps.indexOf(p)) {
|
1700 | x = p;
|
1701 | } else if (!y && ~_yProps.indexOf(p)) {
|
1702 | y = p;
|
1703 | }
|
1704 | }
|
1705 |
|
1706 | if (x && y) {
|
1707 | rawPaths.push(_segmentToRawPath(this, _populateSegmentFromArray(_populateSegmentFromArray([], path, x, 0), path, y, 1), target, x, y, slicer, vars, unitX || _getUnit(path[0][x]), unitY || _getUnit(path[0][y])));
|
1708 | } else {
|
1709 | x = y = 0;
|
1710 | }
|
1711 |
|
1712 | for (p in firstObj) {
|
1713 | p !== x && p !== y && rawPaths.push(_segmentToRawPath(this, _populateSegmentFromArray([], path, p, 2), target, p, 0, slicer, vars, _getUnit(path[0][p])));
|
1714 | }
|
1715 | } else {
|
1716 | rawPath = slicer(_align(getRawPath(vars.path), target, vars));
|
1717 | cacheRawPathMeasurements(rawPath, vars.resolution);
|
1718 | rawPaths.push(rawPath);
|
1719 |
|
1720 | _addDimensionalPropTween(this, target, vars.x || "x", rawPath, "x", vars.unitX || "px");
|
1721 |
|
1722 | _addDimensionalPropTween(this, target, vars.y || "y", rawPath, "y", vars.unitY || "px");
|
1723 | }
|
1724 | },
|
1725 | render: function render(ratio, data) {
|
1726 | var rawPaths = data.rawPaths,
|
1727 | i = rawPaths.length,
|
1728 | pt = data._pt;
|
1729 |
|
1730 | if (ratio > 1) {
|
1731 | ratio = 1;
|
1732 | } else if (ratio < 0) {
|
1733 | ratio = 0;
|
1734 | }
|
1735 |
|
1736 | while (i--) {
|
1737 | getPositionOnPath(rawPaths[i], ratio, !i && data.rotate, rawPaths[i]);
|
1738 | }
|
1739 |
|
1740 | while (pt) {
|
1741 | pt.set(pt.t, pt.p, pt.path[pt.pp] + pt.u, pt.d, ratio);
|
1742 | pt = pt._next;
|
1743 | }
|
1744 |
|
1745 | data.rotate && data.rSet(data.target, data.rProp, rawPaths[0].angle * (data.radians ? _DEG2RAD$1 : 1) + data.rOffset + data.ru, data, ratio);
|
1746 | },
|
1747 | getLength: function getLength(path) {
|
1748 | return cacheRawPathMeasurements(getRawPath(path)).totalLength;
|
1749 | },
|
1750 | sliceRawPath: sliceRawPath,
|
1751 | getRawPath: getRawPath,
|
1752 | pointsToSegment: pointsToSegment,
|
1753 | stringToRawPath: stringToRawPath,
|
1754 | rawPathToString: rawPathToString,
|
1755 | transformRawPath: transformRawPath,
|
1756 | getGlobalMatrix: getGlobalMatrix,
|
1757 | getPositionOnPath: getPositionOnPath,
|
1758 | cacheRawPathMeasurements: cacheRawPathMeasurements,
|
1759 | convertToPath: function convertToPath$1(targets, swap) {
|
1760 | return _toArray(targets).map(function (target) {
|
1761 | return convertToPath(target, swap !== false);
|
1762 | });
|
1763 | },
|
1764 | convertCoordinates: function convertCoordinates(fromElement, toElement, point) {
|
1765 | var m = getGlobalMatrix(toElement, true, true).multiply(getGlobalMatrix(fromElement));
|
1766 | return point ? m.apply(point) : m;
|
1767 | },
|
1768 | getAlignMatrix: _getAlignMatrix,
|
1769 | getRelativePosition: function getRelativePosition(fromElement, toElement, fromOrigin, toOrigin) {
|
1770 | var m = _getAlignMatrix(fromElement, toElement, fromOrigin, toOrigin);
|
1771 |
|
1772 | return {
|
1773 | x: m.e,
|
1774 | y: m.f
|
1775 | };
|
1776 | },
|
1777 | arrayToRawPath: function arrayToRawPath(value, vars) {
|
1778 | vars = vars || {};
|
1779 |
|
1780 | var segment = _populateSegmentFromArray(_populateSegmentFromArray([], value, vars.x || "x", 0), value, vars.y || "y", 1);
|
1781 |
|
1782 | vars.relative && _relativize(segment);
|
1783 | return [vars.type === "cubic" ? segment : pointsToSegment(segment, vars.curviness)];
|
1784 | }
|
1785 | };
|
1786 | _getGSAP() && gsap.registerPlugin(MotionPathPlugin);
|
1787 |
|
1788 | exports.MotionPathPlugin = MotionPathPlugin;
|
1789 | exports.default = MotionPathPlugin;
|
1790 |
|
1791 | Object.defineProperty(exports, '__esModule', { value: true });
|
1792 |
|
1793 | })));
|