hippofish/packages/client/src/scripts/extract-mfm.ts

23 lines
414 B
TypeScript
Raw Normal View History

2023-05-12 06:46:26 +02:00
import * as mfm from "mfm-js";
2023-05-13 05:11:41 +02:00
const animatedMfm = [
"tada",
"jelly",
"twitch",
"shake",
"spin",
"jump",
"bounce",
"rainbow",
2023-05-23 02:26:27 +02:00
"fade",
2023-05-13 05:11:41 +02:00
];
2023-05-12 06:46:26 +02:00
2023-05-13 05:11:41 +02:00
export function extractMfmWithAnimation(nodes: mfm.MfmNode[]): string[] {
2023-05-12 06:46:26 +02:00
const mfmNodes = mfm.extract(nodes, (node) => {
2023-05-13 05:11:41 +02:00
return node.type === "fn" && animatedMfm.indexOf(node.props.name) > -1;
2023-05-12 06:46:26 +02:00
});
const mfms = mfmNodes.map((x) => x.props.fn);
return mfms;
}