UNPKG

svelte-motion

Version:

Svelte animation library based on the React library framer-motion.

43 lines (40 loc) 1.5 kB
/** based on framer-motion@4.0.3, Copyright (c) 2018 Framer B.V. */ import {fixed} from '../../../utils/fix-process-env'; import { px } from 'style-value-types'; // Convert a progress 0-1 to a pixels value based on the provided length var progressToPixels = function (progress, length) { return px.transform(progress * length); }; var dashKeys = { offset: "stroke-dashoffset", array: "stroke-dasharray", }; var camelKeys = { offset: "strokeDashoffset", array: "strokeDasharray", }; /** * Build SVG path properties. Uses the path's measured length to convert * our custom pathLength, pathSpacing and pathOffset into stroke-dashoffset * and stroke-dasharray attributes. * * This function is mutative to reduce per-frame GC. */ function buildSVGPath(attrs, totalLength, length, spacing, offset, useDashCase) { if (spacing === void 0) { spacing = 1; } if (offset === void 0) { offset = 0; } if (useDashCase === void 0) { useDashCase = true; } // We use dash case when setting attributes directly to the DOM node and camel case // when defining props on a React component. var keys = useDashCase ? dashKeys : camelKeys; // Build the dash offset attrs[keys.offset] = progressToPixels(-offset, totalLength); // Build the dash array var pathLength = progressToPixels(length, totalLength); var pathSpacing = progressToPixels(spacing, totalLength); attrs[keys.array] = pathLength + " " + pathSpacing; } export { buildSVGPath };