UNPKG

m3-svelte

Version:

M3 Svelte implements the Material 3 design system in Svelte. See the [website](https://ktibow.github.io/m3-svelte/) for demos and usage instructions.

33 lines (32 loc) 990 B
const frequencyT = (Math.PI * 2) / 1000; const frequencyX = (Math.PI * 2) / 40; const round2 = (x) => Math.round(x * 100) / 100; const round1 = (x) => Math.round(x * 10) / 10; export const linear = (t, b, from, to, time, cutoffTo) => { time = time * frequencyT; time %= Math.PI * 2; if (from >= to) return ""; let path = ""; for (let xIterator = from; xIterator <= to; xIterator += 0.5) { const x = cutoffTo ? Math.min(cutoffTo, xIterator) : xIterator; const sinV = (Math.sin(x * frequencyX + time) + 1) * 0.5; const y = sinV * (t - b) + b; if (x == from) { path = `M ${round1(x)} ${round2(y)}`; } else { path += ` ${round1(x)} ${round2(y)}`; } } return path; }; export const trackOpacity = (right, x) => { let opacity = right - x; if (opacity < 0) opacity = 0; if (opacity > 1) opacity = 1; opacity = round2(opacity); return opacity; };