npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@imgly/figma-importer

v0.2.1

Published

Import Figma files into CE.SDK scenes

Readme

@imgly/figma-importer

Import a Figma local .fig file or a live Figma file through the REST API into a CE.SDK scene.

Installation and runtime

The importer runs in the browser with @cesdk/engine (or the editor's cesdk.engine) and in Node.js with @cesdk/node:

npm install @cesdk/engine @imgly/figma-importer   # browser
npm install @cesdk/node @imgly/figma-importer     # Node.js

A 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 decoder compiles generated JavaScript. To import a .fig, a page with a Content Security Policy must therefore allow 'wasm-unsafe-eval' and 'unsafe-eval' in script-src, and Safari must be 16.4 or newer, for WebAssembly SIMD. The other browsers that CE.SDK supports have SIMD. A REST import needs neither, but connect-src must allow https://api.figma.com and the host of the image URLs that Figma's API returns. A file with text also loads a font catalog: the default one, or your own ly.img.gfonts and ly.img.gfonts-fallbacks sources when you register them first. connect-src must allow the origin of the catalog that the import uses.

Import a local file

In Figma, choose File → Save local copy to obtain a .fig file. In the browser, read the file the user picks and import it into the editor's engine:

import { importFig } from '@imgly/figma-importer';

const file = input.files[0];
const result = await importFig(cesdk.engine, new Uint8Array(await file.arrayBuffer()));
await cesdk.engine.scene.zoomToBlock(result.scene);

In Node.js, read the file from disk and save the scene as an archive:

import CreativeEngine from '@cesdk/node';
import { importFig } from '@imgly/figma-importer';
import { readFile, writeFile } from 'node:fs/promises';

const engine = await CreativeEngine.init({
  license: process.env.CESDK_LICENSE
});
try {
  const result = await importFig(engine, await readFile('design.fig'));
  console.info('Loaded canvas:', result.canvas, 'Available:', result.canvases);
  for (const message of result.logger.getMessages()) {
    console.warn(`${message.type}: ${message.code} — ${message.message}`);
  }
  const archive = await engine.scene.saveToArchive();
  await writeFile('design.imgly', new Uint8Array(await archive.arrayBuffer()));
} finally {
  engine.dispose();
}

A Figma canvas becomes one CE.SDK scene. An engine holds one scene at a time. For a file with several canvases, ImportResult.canvases lists all names and ImportResult.canvas identifies the loaded one. The first is selected by default; pass { canvas: 'Canvas name' } or { canvas: 1 } (zero-based index) to load another. Each new import replaces the engine's current scene, so save each scene before continuing.

Resource limits

The local-file parser accepts up to 64 MiB of compressed input and 4,096 ZIP members with at most 256 MiB of extracted data. The decompressed schema is limited to 1 MiB, the message to 128 MiB, metadata JSON to 1 MiB, and the binary to 64 chunks. Zstandard messages must contain one frame with at most 4,096 blocks and a history window no larger than 128 MiB. Decompression stops when an output limit is exceeded, including when a ZIP header understates the output size.

Kiwi message decoding checks budgets before allocating arrays, copying byte arrays or creating records. A message may use at most 10 million array slots, 1 million records, 128 levels of nesting, 10 million read and allocation work units, and 128 MiB of copied byte arrays. Schema compilation accepts up to 4,096 definitions and 32,768 fields. Identifiers are limited to 1,024 UTF-16 code units each, referenced names to 1 Mi code units in total, and generated source to 8 Mi code units.

Local .fig decoding rejects files that exceed 100,000 generated nodes, 128 levels of nesting, a conservative 64 MiB string budget, or 10 million decoding work units. Work counts visited record fields, string lengths, override processing and geometry bytes. Repeated component instances and geometry references consume the budget on every use, before their output is created. Exceeding a limit throws Figma import limit exceeded with the limit's name. These limits protect local-file decoding; they do not bound all later engine allocations or REST responses.

Import through the REST API

import { importFigmaFile } from '@imgly/figma-importer';

const result = await importFigmaFile(engine, {
  fileKey: 'YOUR_FIGMA_FILE_KEY',
  token: process.env.FIGMA_TOKEN,
  canvas: 0
});

In Node.js, the token defaults to FIGMA_TOKEN when omitted. Use the file key from a Figma file URL and a token with access to that file. Figma's API accepts requests from browsers, but a token in a page is visible to the people who use it. In the browser, pass only a token that the user supplies, such as their own personal access token, and keep your own tokens on the server. nodeIds selects subtrees, retaining their ancestor chains. The options also accept a custom fetch, baseUrl, concurrency, and retry settings. Rate-limit responses are retried according to Retry-After; permissions and Figma's API quotas still apply.

The REST API is a read path for design content. Export uses .fig files; there is no REST endpoint to upload that file or write the scene's design nodes. REST and local .fig input can expose different information, so preservation is limited to what the chosen source supplies.

Mapping and preservation

Both inputs use the same mapper. Top-level frames become pages, as below. Other containers become groups, shapes become graphics, and text retains supported per-range styling. Image fills, gradients, strokes, supported effects, blend modes, and corner radii are mapped to CE.SDK properties.

Each top-level frame of the selected canvas becomes a CE.SDK page with the frame's size, fill, name and clipping. Components and instances at the top level count as frames, and so do the frames inside a top-level section or component set, also through nested sections. Hidden sections and containers with non-default blend modes stay as groups. When a container is split into pages, the importer reports omitted visible fills, strokes and effects with PAGE_CONTAINER_STYLE_DROPPED and keeps the original styles in Figma metadata when enabled. The pages are in reading order: rows from top to bottom, each row from left to right. A frame is in the same row as the top-most remaining frame when its top edge is not below that frame's vertical center.

Nodes beside the frames, such as notes or arrows, go on one extra page at the end, named after the canvas, with a CANVAS_CONTENT_OUTSIDE_FRAMES warning. Masked or translucent frames and component sets stay on the ordinary layer import path. A canvas without an eligible top-level frame becomes one page sized to its content. A frame page preserves the inside stroke, a supported drop shadow, the blend mode and image fill opacity. The importer reports PAGE_FRAME_STYLE_DROPPED for styles it cannot map, such as outside strokes, corner radius and rotation. A translucent image fill can tint an inside stroke in CE.SDK. The importer reports this combination with PAGE_FRAME_STROKE_APPROXIMATED.

The companion exporter restores the imported frames at their original canvas positions and in their original stacking order. Loose content returns to its location on the canvas. If its page is clipped or empty, the exporter keeps a frame to preserve the page bounds.

To get the whole canvas as one content-sized page, with each frame as a group, turn the option off:

await importFig(engine, bytes, { framesAsPages: false });

With the option off, the importer still unwraps a .fig canvas containing one frame named after the canvas or a single row of frames with no other top-level content. A grid of frames, such as the exporter writes for frames that were imported at their canvas positions, imports as one page.

Children are placed absolutely. Figma auto-layout, constraints, masks, and component relationships do not become live CE.SDK behavior. Fonts must be resolvable in CE.SDK; inspect conversion notes for substitutions and other approximations.

Text can reflow even when font family names match. Figma and the available font versions can have different metrics.

Local component instances retain supported text and style overrides, including overrides inside nested instances. With framesAsPages enabled, eligible top-level instances become pages. Imported instances are editable independently of their source components. Unresolved local overrides are retained in metadata and reported through INSTANCE_OVERRIDE_UNSUPPORTED.

Frames below the top level become groups. CE.SDK groups cannot clip children to the original frame bounds, so overflowing children remain visible. The importer reports FRAME_CLIPPING_UNSUPPORTED for clipped frame or component containers with children. The original clipsContent value is retained in metadata when preservation is enabled.

By default, Figma-specific information is kept as JSON-valued block metadata under x-figma/<topic>. The companion @imgly/figma-exporter reads this metadata when exporting. Engine state wins for mapped properties, preserving edits; metadata supplies unmapped properties. This is best-effort preservation, not a guarantee of an identical Figma file or render.

For a scene that will not return to Figma, opt out explicitly:

await importFig(engine, bytes, { preserveFigmaData: false });

The mapped block tree is unchanged, but unmapped information is no longer available to the exporter. Review logger.getMessages() after every conversion for typed warnings and errors.

Development and samples

Run commands from the monorepo root. Nx builds the workspace engine and shared utilities before the converter:

pnpm install
pnpm exec nx run @imgly/figma-importer:test:fetch-fixtures
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-importer:build
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-importer:typecheck
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-importer:test
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-importer:coverage
scripts/dev/heavy-job.sh -- pnpm exec nx run @imgly/figma-importer:test:mutation

The offline corpus in src/test/fixtures contains Figma REST snapshots, image fills, and Figma reference renders. It is stored with Git LFS; missing fixture data fails the suite. Local .fig samples live in the exporter's src/test/fixtures/fig, with provenance and limits described in that directory's README.

Live tests call Figma 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-importer:test:live

The exporter cross suite checks the complete import/export/import loop and compares the original structure. That local loop must be complemented by opening exported files in Figma: two converters can agree on the same mistake.

For an interactive example, see the Figma roundtrip showcase. It imports and exports .fig files in the browser, and imports through REST on a local Node server that keeps the token. It also covers canvas selection, editing and archive loading.

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.