@lottiefiles/relottie-parse
Version:
Parse Lottie JSON format to LAST
35 lines (33 loc) • 1.23 kB
JavaScript
import { DEFAULT_OPTIONS } from './chunk-N7XJKEIG.js';
import { Slots } from './chunk-KA742OHG.js';
import { traverseJsonExit, traverseJsonEnter } from './chunk-UJT6FNLI.js';
import { Stack } from './chunk-WVIQP6RP.js';
import { parse as parse$1, traverse } from '@humanwhocodes/momoa';
import { is } from 'unist-util-is';
function parse(document, file, settings = {}) {
const jsonAst = parse$1(document);
const options = { ...DEFAULT_OPTIONS, ...settings.parse };
const stack = new Stack();
const info = { hasExpressions: false, slots: new Slots(file, options) };
traverse(jsonAst, {
enter(node, parent) {
traverseJsonEnter(node, parent, stack, file, options, info);
},
exit(node, parent) {
traverseJsonExit(node, parent, stack, file, options, info);
}
});
info.slots?.mutate();
const tree = stack.pop();
if (tree && options.phantomRoot) {
return tree;
} else if (is(tree, "root")) {
tree.hasExpressions = info.hasExpressions || false;
return tree;
} else {
file.fail(`Stack's last item has to be "root" but it's "${tree ? tree.type : "unknown"}"`, tree);
}
}
export { parse };
//# sourceMappingURL=chunk-SETW43GU.js.map
//# sourceMappingURL=chunk-SETW43GU.js.map