mirror of
https://github.com/nexu-io/open-design.git
synced 2026-10-27 09:51:12 +01:00
274 lines
9.5 KiB
JavaScript
274 lines
9.5 KiB
JavaScript
// OD Figma Import — plugin main thread.
|
|||
|
|
//
|
||
|
|
// Rebuilds an OD Figma capture IR (produced by the OD Clipper / OD Library; see
|
||
|
|
// IR.md) into editable Figma layers. The UI (ui.html) hands us a parsed IR
|
||
|
|
// object; we preload its fonts, then walk the node-tree creating FRAME / TEXT /
|
||
|
|
// RECTANGLE nodes at their captured geometry with fills, strokes, corner radii
|
||
|
|
// and shadows.
|
||
|
|
//
|
||
|
|
// Standalone, dependency-free, no build step — loaded via
|
||
|
|
// "Plugins → Development → Import plugin from manifest…".
|
||
|
|
|
||
|
|
figma.showUI(__html__, { width: 340, height: 420, title: 'OD Figma Import' });
|
||
|
|
|
||
|
|
figma.ui.onmessage = async (msg) => {
|
||
|
|
if (!msg) return;
|
||
|
|
if (msg.type === 'cancel') {
|
||
|
|
figma.closePlugin();
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
if (msg.type === 'import') {
|
||
|
|
try {
|
||
|
|
const ir = msg.ir;
|
||
|
|
if (!ir || !ir.root) throw new Error('Not an OD Figma capture (missing root).');
|
||
|
|
const container = await importIr(ir);
|
||
|
|
figma.ui.postMessage({ type: 'done', name: container.name });
|
||
|
|
figma.notify(`Imported “${container.name}”`);
|
||
|
|
} catch (err) {
|
||
|
|
figma.ui.postMessage({ type: 'error', message: String((err && err.message) || err) });
|
||
|
|
}
|
||
|
|
}
|
||
|
|
};
|
||
|
|
|
||
|
|
// --- font preloading -------------------------------------------------------
|
||
|
|
|
||
|
|
let LOADED_FONTS = new Set();
|
||
|
|
const fontKey = (family, style) => `${family} |