UNPKG

svelte-motion

Version:

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

47 lines (44 loc) 2.2 kB
/** based on framer-motion@4.0.3, Copyright (c) 2018 Framer B.V. */ import { __rest } from 'tslib'; import { buildHTMLStyles } from '../../html/utils/build-styles.js'; import { calcSVGTransformOrigin } from './transform-origin.js'; import { buildSVGPath } from './path.js'; /** * Build SVG visual attrbutes, like cx and style.transform */ function buildSVGAttrs(state, _a, projection, layoutState, options, transformTemplate, buildProjectionTransform, buildProjectionTransformOrigin) { var attrX = _a.attrX, attrY = _a.attrY, originX = _a.originX, originY = _a.originY, pathLength = _a.pathLength, _b = _a.pathSpacing, pathSpacing = _b === void 0 ? 1 : _b, _c = _a.pathOffset, pathOffset = _c === void 0 ? 0 : _c, // This is object creation, which we try to avoid per-frame. latest = __rest(_a, ["attrX", "attrY", "originX", "originY", "pathLength", "pathSpacing", "pathOffset"]); buildHTMLStyles(state, latest, projection, layoutState, options, transformTemplate, buildProjectionTransform, buildProjectionTransformOrigin); state.attrs = state.style; state.style = {}; var attrs = state.attrs, style = state.style, dimensions = state.dimensions, totalPathLength = state.totalPathLength; /** * However, we apply transforms as CSS transforms. So if we detect a transform we take it from attrs * and copy it into style. */ if (attrs.transform) { if (dimensions) style.transform = attrs.transform; delete attrs.transform; } // Parse transformOrigin if (dimensions && (originX !== undefined || originY !== undefined || style.transform)) { style.transformOrigin = calcSVGTransformOrigin(dimensions, originX !== undefined ? originX : 0.5, originY !== undefined ? originY : 0.5); } // Treat x/y not as shortcuts but as actual attributes if (attrX !== undefined) attrs.x = attrX; if (attrY !== undefined) attrs.y = attrY; // Build SVG path if one has been measured if (totalPathLength !== undefined && pathLength !== undefined) { buildSVGPath(attrs, totalPathLength, pathLength, pathSpacing, pathOffset, false); } } export { buildSVGAttrs };