feat: add --node flag to scope conversion to a single node#3
Open
tommymorgan wants to merge 1 commit into
Open
feat: add --node flag to scope conversion to a single node#3tommymorgan wants to merge 1 commit into
tommymorgan wants to merge 1 commit into
Conversation
Large .fig files convert to the entire document, hundreds of MB of JSON,
even when only one frame is needed. --node <ID> scopes conversion to a
single node and its subtree, matched by its guid {sessionID, localID}.
The id accepts both forms Figma provides: 6886:48774 (REST) and
6886-48774 (the node-id in a figma.com URL). Matching runs right after
build_tree and before the transform passes, so only the targeted subtree
is processed. In ZIP mode it converts the archived file containing the
node and skips the rest, erroring only if no file has it. Rejected
together with --raw.
convert_node(bytes, base_dir, target) carries the optional target;
convert() stays as a no-target wrapper, so existing callers are
unchanged. A miss is reported as FigError::NodeNotFound(NodeId).
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
Large Figma files convert to hundreds of MB of optimized JSON, the entire
document, even when only one frame is needed. This adds a
--nodeflag thatscopes conversion to a single node, given by its
sessionID:localID(the idFigma puts in file URLs; dash or colon form accepted). On a real 23MB
.figfile thisturns a 313MB JSON export into ~1.5MB for one frame.
What
--node <ID>on the CLI. Works for plain.figand ZIP archives; for anarchive it converts only the inner file containing the node, skips the rest,
and errors clearly if no file matches. Rejected together with
--raw.convert_node(bytes, base_dir, target);convert()becomes a no-targetwrapper, so existing callers are unchanged.
guidright afterbuild_tree, before thetransformation passes run, so only the targeted subtree is processed.
NodeIdis au64sessionID/localIDpair that parses from either form viaFromStr; a miss is reported asFigError::NodeNotFound(NodeId).Usage
fig2json --help(the--nodeoption is the addition):Example, pulling a single frame out of a locally-saved
.fig(here a ZIP thatextracts to
out/):Tests
schema::node_filterunit tests (id parsing: colon/dash/whitespace andrejected forms; subtree finding incl. sibling exclusion, first-match, and
guarding against matching non-guid id keys), written test-first.
tests/cli.rs) for--nodeand--rawvalidation.cargo clippyclean.