@imgly/figma-exporter
v0.2.1
Published
Export CE.SDK scenes as Figma .fig files
Downloads
6,899
Readme
@imgly/figma-exporter
Export a CE.SDK scene as a Figma .fig file, including scenes created in
CE.SDK and scenes imported from Figma.
Installation and runtime
The exporter runs in the browser with @cesdk/engine (or the editor's
cesdk.engine) and in Node.js with @cesdk/node. The engine is a peer
dependency supplied by the integrating application:
npm install @cesdk/engine @imgly/figma-exporter # browser
npm install @cesdk/node @imgly/figma-exporter # Node.jsA valid CE.SDK license is required. Node.js must be 22.15 or newer (Node.js 23
requires 23.8+). The .fig codec is libzstd compiled to WebAssembly, and the
Kiwi schema encoder compiles generated JavaScript. A page with a Content
Security Policy must therefore allow 'wasm-unsafe-eval' and 'unsafe-eval'
in script-src. The codec needs WebAssembly SIMD, so Safari must be 16.4 or
newer; the other browsers that CE.SDK supports have it.
Export a scene
In the browser, export the editor's current scene and download the file:
import { exportFig } from '@imgly/figma-exporter';
const { fig, logger } = await exportFig(cesdk.engine, { fileName: 'My design' });
const url = URL.createObjectURL(new Blob([fig]));
const link = document.createElement('a');
link.href = url;
link.download = 'design.fig';
link.click();
setTimeout(() => URL.revokeObjectURL(url), 1000);In Node.js, load an archive and write the file to disk:
import CreativeEngine from '@cesdk/node';
import { exportFig } from '@imgly/figma-exporter';
import { writeFile } from 'node:fs/promises';
const engine = await CreativeEngine.init({
license: process.env.CESDK_LICENSE
});
try {
await engine.scene.loadFromArchiveURL(
'https://example.com/design.imgly',
false,
true
);
const { fig, logger } = await exportFig(engine, { fileName: 'My design' });
await writeFile('design.fig', fig);
for (const message of logger.getMessages()) {
console.warn(`${message.type}: ${message.code} — ${message.message}`);
}
} finally {
engine.dispose();
}In an editor, the export reads the scene while it runs, so block editing until
it ends, for example with cesdk.utils.showLoadingDialog(). A property edited
during the export, such as a color or a text, can have its old or its new
value in the file. When the export ends, it fails with an error if layers were
added, deleted or rearranged, another scene was loaded, or the design unit or
the resolution of a scene in millimetres or inches changed. A change that is
undone before the export ends is not detected.
exportFig(engine, { fileName, thumbnail }) sets the file name shown in
Figma and optionally supplies a thumbnail. One CE.SDK scene becomes
one Figma canvas. Each scene page becomes a frame carrying its dimensions,
fills, name, and clipping behavior, with one exception for content imported
from outside the frames. Its layers return directly to the canvas at their
original positions and stacking slots. An empty, clipped or restyled
page keeps a frame. The frame takes the frontmost surviving source slot
when its layers came from several slots.
Imported frames return to their positions in the source stacking order. New pages and duplicates go in a row below the imported content. On re-import, frames follow spatial reading order and the page made from loose canvas layers comes last, even if you appended a new page after it in CE.SDK.
Import the downloaded file through Figma's file browser, then open it in the editor to check the result. Figma computes text layout when a file is opened, so an API render requested before that can omit text.
Mapping and preservation
Supported text, graphics, image fills, gradients, strokes, and effects
become editable Figma nodes. Supported graphics that need an image
fallback are rendered and reported through a BLOCK_RASTERIZED conversion
note. Unsupported block types are skipped and reported through
UNSUPPORTED_BLOCK_TYPE. Inspect logger.getMessages() after export;
approximations can affect appearance or editability.
The companion @imgly/figma-importer stores
Figma-specific information as x-figma/<topic> metadata. This exporter
uses it to restore unmapped properties. Engine state wins for mapped
properties, so edits in CE.SDK are retained; metadata supplies unmapped
ones. Preservation is best effort, limited to the source information and
supported mappings. It does not guarantee an identical Figma document or
render. Scenes authored in CE.SDK do not need Figma metadata to export.
Text can reflow even when font family names match. Figma and the available
font versions can have different metrics.
Changing an imported text block's sizing mode in CE.SDK overrides its preserved Figma autosizing mode. Unchanged sizing modes can still use the original Figma mode when the file is opened there.
Timed scenes export a still at each page's current playhead. Nested group and track offsets determine which clips are included.
Why export a file?
Figma's REST API reads design content but provides no endpoint to upload
a .fig file or write design nodes. The exporter writes the file format
using a vendored copy of
openfig-core. Importing
the output into Figma is a separate application step. A local roundtrip
cannot replace that verification.
Development and verification
Run these commands from the monorepo root. Nx prepares the workspace engine, importer, and shared utilities:
pnpm install
pnpm exec nx run @imgly/figma-exporter:test:fetch-fixtures
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-exporter:build
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-exporter:typecheck
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-exporter:test
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-exporter:coverage
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-exporter:test:mutationThe offline suite includes:
- G0: structural invariants for exported documents.
- G5: Figma → CE.SDK →
.fig→ CE.SDK, comparing the two CE.SDK renders. - G7: exported structure against the original Figma tree, reporting node survival and matching bounds separately.
- Idempotence: repeated conversions must stop changing structure.
- Conformance: output checks against files accepted by Figma.
These gates measure different failures; a good G5 result alone does not prove fidelity to Figma. Current results belong to the test run that produced them rather than a fixed README table.
G6 is the verdict in Figma itself. Generate a .fig through
exportFig(), import it in Figma, open it to complete text layout, and
compare Figma's render with the original CE.SDK render. The builder probe
in src/test/support/probe.ts checks the format layer separately; its
acceptance does not prove that every scene mapper produces correct output.
The offline test run generates exports and CE.SDK reference PNGs under
src/test/results/g6-export/. After importing and opening the exact
exported-cursor.fig in Figma, run from this package directory:
pnpm g6:verify src/test/results/g6-export/exported-cursor.fig YOUR_FIGMA_FILE_KEYThe verifier compares the expected frames and their renders, using the
reference PNGs beside the supplied export. G6_DIR overrides that
directory. A missing frame, reference, or Figma render fails the command.
Live tests require a token and run separately:
# FIGMA_TOKEN must be set in the environment or package .env.local.
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-exporter:test:liveThe local .fig corpus and its provenance are documented in
src/test/fixtures/fig/README.md. Those
files were generated by this exporter and saved again by Figma. They are
useful format fixtures, while designs authored independently in Figma are
needed for broader content coverage. Fetching the corpus also retrieves
the importer's REST snapshots and reference renders through Git LFS.
Interactive showcase
The Figma roundtrip showcase
lets you import .fig or through REST, edit in the browser, open a CE.SDK
archive, and download .fig or .imgly. .fig files convert in the
browser. REST imports run on its local Node server, so the API token stays
out of the browser.
License
See LICENSE.md. A valid CE.SDK license is required;
get one at img.ly.
The terms and attribution of the bundled code, such as the .fig parser
openfig-core and, in the CommonJS build, libzstd, are in
THIRD_PARTY_NOTICES.md.
