070959e133
landing-page-staging / Deploy landing page to staging (push) Has been skipped
landing-page-ci / Validate landing page (push) Failing after 4s
visual-baseline / Capture visual baselines (push) Has been cancelled
bake-plugin-previews / Bake plugin previews (push) Has been cancelled
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} |