(
node: SceneNode,
config: CodegenConfig,
pluginCode?: string,
opts?: { returnDevComponent?: boolean; variableDisplay?: VariableDisplayMode }
)
| 52 | PLUGIN_SANDBOX_WORKER.codegen, |
| 53 | { |
| 54 | ...job, |
| 55 | pluginCode |
| 56 | } |
| 57 | ) |
| 58 | return validateCodegenResponse(response) |
| 59 | } |
| 60 | |
| 61 | async function codegenBatch( |
| 62 | jobs: CodegenJobPayload[], |
| 63 | pluginCode?: string |
| 64 | ): Promise<ResponsePayload[]> { |
| 65 | const response = await requestPluginSandbox<CodegenBatchRequestPayload, unknown>( |
| 66 | PLUGIN_SANDBOX_WORKER.codegen, |
| 67 | { jobs, pluginCode } |
| 68 | ) |
| 69 | const results = validateCodegenBatchResponse(response) |
| 70 | if (results.length !== jobs.length) { |
| 71 | throw new PluginSandboxError( |
| 72 | 'protocol-error', |
| 73 | `Plugin returned ${results.length} batch results for ${jobs.length} jobs.` |
| 74 | ) |
| 75 | } |
| 76 | return results |
| 77 | } |
| 78 | |
| 79 | export type CodegenConfig = { |
| 80 | cssUnit: 'px' | 'rem' |
| 81 | rootFontSize: number |
| 82 | scale: number |
| 83 | } |
| 84 | |
| 85 | export function workerUnitOptions( |
| 86 | config: CodegenConfig |
| 87 | ): Pick<SerializeOptions, 'useRem' | 'rootFontSize' | 'scale'> { |
| 88 | return { |
| 89 | useRem: config.cssUnit === 'rem', |
no test coverage detected