Skip to content

AI-native design editor. Open-source Figma alternative.

7.3 KB
Raw Blame
export interface RuntimeScenario {
  code: string
  name: string
}

export const runtimeScenarios: RuntimeScenario[] = [
  {
    name: 'Kiwi GUID subpath',
    code: "const { guidToString } = await import('@open-pencil/kiwi/fig/guid'); if (guidToString({ sessionID: 1, localID: 2 }) !== '1:2') throw new Error('Kiwi GUID subpath failed')"
  },
  {
    name: 'Kiwi container subpath',
    code: "const { buildFigKiwi, parseFigKiwiChunks } = await import('@open-pencil/kiwi/fig/container'); const chunks = parseFigKiwiChunks(buildFigKiwi(new Uint8Array([1]), new Uint8Array([2]))); if (chunks?.length !== 2) throw new Error('Kiwi container subpath failed')"
  },
  {
    name: 'FIG archive API',
    code: "const { FIG_PACKAGE_STATUS, effectiveFigmaRawNodeFields, parseFigBuffer, writeFigArchive, readFigContainer, writeFigContainer } = await import('@open-pencil/fig'); if (FIG_PACKAGE_STATUS !== 'document-reader' || typeof effectiveFigmaRawNodeFields !== 'function' || typeof parseFigBuffer !== 'function' || typeof writeFigArchive !== 'function') throw new Error('Fig package status smoke failed'); const document = readFigContainer(writeFigContainer({ schemaDeflated: new Uint8Array([1]), dataRaw: new Uint8Array([2]) })); if (document.dataRaw[0] !== 2) throw new Error('Fig container smoke failed')"
  },
  {
    name: 'FIG NodeChange API',
    code: "const { convertLineHeight, sceneNodeToKiwi } = await import('@open-pencil/fig/node-change'); const lineHeight = convertLineHeight({ value: 1.5, units: 'RAW' }); if (lineHeight?.unit !== 'PERCENT' || lineHeight.value !== 150 || typeof sceneNodeToKiwi !== 'function') throw new Error('Fig NodeChange subpath failed')"
  },
  {
    name: 'FIG instance override API',
    code: "const { interpretInstance, materializeInstance } = await import('@open-pencil/fig/instance-overrides'); if (typeof interpretInstance !== 'function' || typeof materializeInstance !== 'function') throw new Error('Fig instance override subpath failed')"
  },
  {
    name: 'SceneGraph package',
    code: "const { SceneGraph } = await import('@open-pencil/scene-graph'); const graph = new SceneGraph(); if (graph.getPages().length !== 1) throw new Error('SceneGraph package smoke failed')"
  },
  {
    name: 'PEN parser',
    code: "const { parsePenFile } = await import('@open-pencil/pen'); const graph = parsePenFile(JSON.stringify({ version: '1', children: [{ id: 'frame', type: 'frame', width: 100, height: 50 }] })); if (graph.getPages()[0].childIds.length !== 1) throw new Error('Pen package smoke failed')"
  },
  {
    name: 'draw.io codec',
    code: 'const { parseDrawIOFile, writeDrawIOFile } = await import(\'@open-pencil/drawio\'); const file = parseDrawIOFile(\'<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0"/><mxCell id="a" vertex="1" parent="1"/></root></mxGraphModel>\'); if (file?.pages[0]?.cells.length !== 1 || !writeDrawIOFile(file).startsWith(\'<mxfile\')) throw new Error(\'draw.io package smoke failed\')'
  },
  {
    name: 'Mermaid parser',
    code: "const { parseFlowchart } = await import('@open-pencil/mermaid'); const chart = parseFlowchart('flowchart LR\\n  A[Start] --> B{Done?}'); if (chart.direction !== 'LR' || chart.nodes[1]?.shape !== 'diam' || chart.edges.length !== 1) throw new Error('Mermaid package smoke failed')"
  },
  {
    name: 'Emit package',
    code: "const { jsx } = await import('@open-pencil/emit'); const code = jsx.printJSX(jsx.element('Card', [jsx.attribute('wide', null)], [], 0)); if (code !== '<Card wide />') throw new Error('Codegen package smoke failed: ' + code)"
  },
  {
    name: 'Design JSX package',
    code: "const { Frame, Text, JSX_REFERENCE } = await import('@open-pencil/design-jsx'); const tree = Frame({ w: 100, children: [Text({ children: 'OpenPencil' })] }); if (tree.type !== 'frame' || tree.children.length !== 1 || !JSX_REFERENCE.includes('Frame')) throw new Error('Design JSX package smoke failed')"
  },
  {
    name: 'Design JSX runtime',
    code: "const { jsx } = await import('@open-pencil/design-jsx/jsx-runtime'); const { Frame, Text } = await import('@open-pencil/design-jsx'); const tree = jsx(Frame, { w: 100, children: jsx(Text, { children: 'OpenPencil' }) }); if (tree.type !== 'frame' || tree.children[0]?.type !== 'text') throw new Error('Design JSX runtime failed')"
  },
  {
    name: 'DOM/CSS conversion',
    code: "const { htmlToSceneGraph } = await import('@open-pencil/dom-css'); const graph = await htmlToSceneGraph('<div class=card>OpenPencil</div>', { cssText: '.card { width: 320px; }' }); if (graph.getPages()[0].width !== 320) throw new Error('DOM/CSS scene graph failed')"
  },
  {
    name: 'DOM/CSS browser API',
    code: "const browser = await import('@open-pencil/dom-css/browser'); for (const key of ['browserHTMLToDesignDocument', 'browserHTMLToSceneGraph', 'browserTailwindJSXToSceneGraph']) if (typeof browser[key] !== 'function') throw new Error('DOM/CSS browser export missing: ' + key)"
  },
  {
    name: 'DOM/CSS JSX runtime',
    code: "const { jsx, jsxToDesignDocument } = await import('@open-pencil/dom-css/jsx-runtime'); const document = await jsxToDesignDocument(jsx('section', { class: 'card', style: { width: '120px' }, children: 'OpenPencil' })); const node = document.children[0]; if (node?.type !== 'element' || node.inlineStyle?.width !== '120px') throw new Error('DOM/CSS JSX runtime failed')"
  },
  {
    name: 'Oxlint plugin',
    code: "const { default: plugin } = await import('@open-pencil/oxlint-plugin'); if (plugin.meta.name !== 'open-pencil' || Object.keys(plugin.rules).length < 28 || !plugin.rules['no-unvalidated-json-parse']?.meta) throw new Error('Oxlint plugin smoke failed')"
  },
  {
    name: 'Oxlint recommended configuration',
    code: "const { default: preset } = await import('@open-pencil/oxlint-plugin/recommended'); if (preset.rules['open-pencil/no-silent-catch'] !== 'error' || !preset.plugins.includes('typescript')) throw new Error('Oxlint recommended configuration smoke failed')"
  },
  {
    name: 'Cloud contract',
    code: "const { CLOUD_AI_TOKEN_AUDIENCE, aiWalletSchema } = await import('@open-pencil/cloud/contract'); const { safeParse } = await import('valibot'); if (CLOUD_AI_TOKEN_AUDIENCE !== 'openpencil-ai' || !safeParse(aiWalletSchema, { balance: 5, buckets: [] }).success) throw new Error('Cloud contract smoke failed')"
  },
  {
    name: 'XPath query',
    code: "const { SceneGraph } = await import('@open-pencil/scene-graph'); const { FigmaAPI } = await import('@open-pencil/core/figma-api'); const { matchByXPath, queryByXPath } = await import('@open-pencil/core/xpath'); const graph = new SceneGraph(); new FigmaAPI(graph).createRectangle(); const found = await queryByXPath(graph, '//RECTANGLE'); if (found.length !== 1 || !(await matchByXPath(graph, '@width > 0', found[0]))) throw new Error('XPath query smoke failed')"
  },
  {
    name: 'PDF export',
    code: "const { SceneGraph } = await import('@open-pencil/scene-graph'); const { FigmaAPI } = await import('@open-pencil/core/figma-api'); const { BUILTIN_IO_FORMATS, IORegistry } = await import('@open-pencil/core/io'); const graph = new SceneGraph(); const rectangle = new FigmaAPI(graph).createRectangle(); const result = await new IORegistry(BUILTIN_IO_FORMATS).exportContent('pdf', { graph, target: { scope: 'node', nodeId: rectangle.id } }); if (!(result.data instanceof Uint8Array) || new TextDecoder().decode(result.data.subarray(0, 5)) !== '%PDF-') throw new Error('PDF export smoke failed')"
  }
]