motion-dom
Version:
1 lines • 2.08 kB
Source Map (JSON)
{"version":3,"file":"layout-velocity.mjs","sources":["../../../../src/projection/animation/layout-velocity.ts"],"sourcesContent":["import { clamp, Point, secondsToMilliseconds } from \"motion-utils\"\nimport { getSpringOptions } from \"../../animation/generators/spring\"\nimport type { ValueAnimationOptions } from \"../../animation/types\"\n\n/**\n * A curved path ties x and y to one progress value, so it takes the part of\n * the velocity along the straight line from start to end.\n */\nexport const pointToProgressVelocity = (\n tx: number,\n ty: number,\n { x, y }: Point\n) => {\n const lengthSquared = tx * tx + ty * ty\n return lengthSquared < 1 ? 0 : (-1000 * (x * tx + y * ty)) / lengthSquared\n}\n\n/**\n * With `mass: \"auto\"`, mass comes from the element's size: a 300px square\n * has mass 1, bigger elements are heavier and slower (mass 0.25 to 2), and\n * damping scales with mass so the spring keeps its bounce. The result is a\n * physics spring.\n */\nexport const resolveAutoMass = (\n t: any,\n size = 300\n): ValueAnimationOptions<number> => {\n const mass = clamp(0.25, 2, size / 300)\n const { stiffness, damping } = getSpringOptions({\n ...t,\n duration: t.duration && secondsToMilliseconds(t.duration),\n })\n return { ...t, stiffness, damping: damping * Math.sqrt(mass), mass }\n}\n"],"names":[],"mappings":";;;AAIA;;;AAGG;AACI,MAAM,uBAAuB,GAAG,CACnC,EAAU,EACV,EAAU,EACV,EAAE,CAAC,EAAE,CAAC,EAAS,KACf;IACA,MAAM,aAAa,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;IACvC,OAAO,aAAa,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,IAAK,IAAI,CAAC,GAAG,EAAE,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,aAAa;AAC9E;AAEA;;;;;AAKG;AACI,MAAM,eAAe,GAAG,CAC3B,CAAM,EACN,IAAI,GAAG,GAAG,KACqB;AAC/B,IAAA,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,EAAE,CAAC,EAAE,IAAI,GAAG,GAAG,CAAC;AACvC,IAAA,MAAM,EAAE,SAAS,EAAE,OAAO,EAAE,GAAG,gBAAgB,CAAC;AAC5C,QAAA,GAAG,CAAC;QACJ,QAAQ,EAAE,CAAC,CAAC,QAAQ,IAAI,qBAAqB,CAAC,CAAC,CAAC,QAAQ,CAAC;AAC5D,KAAA,CAAC;AACF,IAAA,OAAO,EAAE,GAAG,CAAC,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE;AACxE;;;;"}