2021-12-08 22:43:31 +01:00
|
|
|
import KEC from '../objects/kute';
|
|
|
|
import numbers from '../interpolation/numbers';
|
2021-03-30 11:23:29 +02:00
|
|
|
|
|
|
|
// Component Functions
|
2021-12-08 22:43:31 +01:00
|
|
|
/**
|
|
|
|
* Sets the property update function.
|
|
|
|
* @param {string} tweenProp the property name
|
|
|
|
*/
|
2021-03-30 11:23:29 +02:00
|
|
|
export function onStartDraw(tweenProp) {
|
2021-12-08 22:43:31 +01:00
|
|
|
if (tweenProp in this.valuesEnd && !KEC[tweenProp]) {
|
|
|
|
KEC[tweenProp] = (elem, a, b, v) => {
|
|
|
|
/* eslint-disable no-bitwise -- impossible to satisfy */
|
2021-03-30 11:23:29 +02:00
|
|
|
const pathLength = (a.l * 100 >> 0) / 100;
|
|
|
|
const start = (numbers(a.s, b.s, v) * 100 >> 0) / 100;
|
|
|
|
const end = (numbers(a.e, b.e, v) * 100 >> 0) / 100;
|
|
|
|
const offset = 0 - start;
|
|
|
|
const dashOne = end + offset;
|
2021-12-08 22:43:31 +01:00
|
|
|
// eslint-disable-next-line no-param-reassign -- impossible to satisfy
|
2021-03-30 11:23:29 +02:00
|
|
|
elem.style.strokeDashoffset = `${offset}px`;
|
2021-12-08 22:43:31 +01:00
|
|
|
// eslint-disable-next-line no-param-reassign -- impossible to satisfy
|
2021-03-30 11:23:29 +02:00
|
|
|
elem.style.strokeDasharray = `${((dashOne < 1 ? 0 : dashOne) * 100 >> 0) / 100}px, ${pathLength}px`;
|
2021-12-08 22:43:31 +01:00
|
|
|
/* eslint-disable no-bitwise -- impossible to satisfy */
|
2021-03-30 11:23:29 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Component Base
|
2021-12-08 22:43:31 +01:00
|
|
|
const SvgDrawBase = {
|
2021-03-30 11:23:29 +02:00
|
|
|
component: 'baseSVGDraw',
|
|
|
|
property: 'draw',
|
|
|
|
Interpolate: { numbers },
|
|
|
|
functions: { onStart: onStartDraw },
|
|
|
|
};
|
|
|
|
|
2021-12-08 22:43:31 +01:00
|
|
|
export default SvgDrawBase;
|