mirror of
https://github.com/lucide-icons/lucide.git
synced 2025-12-16 15:07:41 +01:00
* feat(SvgPreview): add features from lucide studio * Update docs/.vitepress/lib/SvgPreview/index.tsx --------- Co-authored-by: Eric Fennis <eric.fennis@gmail.com>
20 lines
562 B
TypeScript
20 lines
562 B
TypeScript
import memoize from 'lodash/memoize';
|
|
import SVGPathCommander from 'svg-path-commander';
|
|
import { Path } from './types';
|
|
|
|
function pathToPoints({ d, prev, next }: Path, interval = 1) {
|
|
const commander = new SVGPathCommander(d);
|
|
const points = [];
|
|
try {
|
|
const totalLength = commander.getTotalLength();
|
|
points.push(prev);
|
|
for (let i = interval; i < totalLength - interval; i += interval) {
|
|
points.push(commander.getPointAtLength(i));
|
|
}
|
|
points.push(next);
|
|
} catch (err) {}
|
|
return points;
|
|
}
|
|
|
|
export default memoize(pathToPoints);
|