@pairdraw/core 0.21.0 → 0.21.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. package/dist/canvas/shaders/compile.d.ts +3 -1
  2. package/dist/canvas/shaders/compile.d.ts.map +1 -1
  3. package/dist/canvas/shaders/compile.js +12 -3
  4. package/dist/canvas/shaders/compile.js.map +1 -1
  5. package/dist/canvas/shaders/draw.d.ts.map +1 -1
  6. package/dist/canvas/shaders/draw.js +10 -3
  7. package/dist/canvas/shaders/draw.js.map +1 -1
  8. package/dist/canvas/shaders/effect.d.ts.map +1 -1
  9. package/dist/canvas/shaders/effect.js +6 -16
  10. package/dist/canvas/shaders/effect.js.map +1 -1
  11. package/dist/editor/bridges/undo.d.ts +1 -1
  12. package/dist/editor/clipboard/export.js +2 -2
  13. package/dist/editor/clipboard/export.js.map +1 -1
  14. package/dist/editor/create.d.ts +1 -1
  15. package/dist/io/formats/drawio/warnings.d.ts +17 -2
  16. package/dist/io/formats/drawio/warnings.d.ts.map +1 -1
  17. package/dist/io/formats/drawio/warnings.js +14 -7
  18. package/dist/io/formats/drawio/warnings.js.map +1 -1
  19. package/dist/io/formats/html/index.d.ts +1 -0
  20. package/dist/io/formats/html/index.d.ts.map +1 -1
  21. package/dist/io/formats/html/index.js +5 -3
  22. package/dist/io/formats/html/index.js.map +1 -1
  23. package/dist/io/formats/pen/index.d.ts.map +1 -1
  24. package/dist/io/formats/pen/index.js +13 -4
  25. package/dist/io/formats/pen/index.js.map +1 -1
  26. package/dist/io/formats.d.ts.map +1 -1
  27. package/dist/io/formats.js +10 -4
  28. package/dist/io/formats.js.map +1 -1
  29. package/dist/io/index.d.ts +2 -2
  30. package/dist/io/types.d.ts +11 -2
  31. package/dist/io/types.d.ts.map +1 -1
  32. package/package.json +9 -9
  33. package/src/canvas/shaders/compile.ts +14 -3
  34. package/src/canvas/shaders/draw.ts +11 -4
  35. package/src/canvas/shaders/effect.ts +6 -18
  36. package/src/editor/clipboard/export.ts +2 -2
  37. package/src/io/formats/drawio/warnings.ts +27 -8
  38. package/src/io/formats/html/index.ts +9 -3
  39. package/src/io/formats/pen/index.ts +14 -6
  40. package/src/io/formats.ts +10 -4
  41. package/src/io/index.ts +1 -0
  42. package/src/io/types.ts +10 -0
@@ -1 +1 @@
1
- {"version":3,"file":"formats.js","names":[],"sources":["../../src/io/formats.ts"],"sourcesContent":["import { filename } from 'pathe/utils'\n\nimport { sceneNodeToJSX, selectionToJSX } from '@pairdraw/design-jsx'\nimport { isDrawIOExportFileName } from '@pairdraw/drawio'\nimport type { DocumentKind, SceneGraph } from '@pairdraw/scene-graph'\n\nimport { layoutAuthoredNodes } from '#core/layout'\n\nimport type { DrawIOExportTarget } from './formats/drawio/export'\nimport { exportFigFile, parseFigFile } from './formats/fig'\nimport type { PDFPageSpec } from './formats/pdf/plan'\nimport { penFormat } from './formats/pen'\nimport type { PPTXExportOptions } from './formats/pptx'\nimport { headlessRenderNodes, renderNodesToImage, type RasterExportFormat } from './formats/raster'\nimport { extractExportGraph, findPageId } from './subgraph'\nimport type {\n ExportRequest,\n ExportResult,\n FigWriteOptions,\n HTMLExportOptions,\n IOContext,\n IOFormatAdapter,\n IOFormatExportOptions,\n IOFormatSupport,\n PDFFormatExportOptions,\n RasterExportOptions,\n SVGExportOptions\n} from './types'\n\n/** Formats that export a document, page, selection, or single node alike. */\nconst EXPORT_EVERY_TARGET: IOFormatSupport = {\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n}\n\n/** Formats with a size of their own, so no export scale or quality. */\nconst FIXED_SIZE_EXPORT: IOFormatExportOptions = { scale: false, quality: false }\n\nfunction lowerExt(name: string): string {\n const match = /\\.([^.]+)$/.exec(name.toLowerCase())\n return match?.[1] ?? ''\n}\n\nfunction ensureSingleNode(target: ExportRequest['target']): string | null {\n if (target.scope === 'node') return target.nodeId\n if (target.scope === 'selection' && target.nodeIds.length === 1) return target.nodeIds[0]\n return null\n}\n\nfunction resolveExportNodes(request: ExportRequest): { pageId: string; nodeIds: string[] } | null {\n switch (request.target.scope) {\n case 'document': {\n const page = request.graph.getPages()[0]\n return { pageId: page.id, nodeIds: page.childIds }\n }\n case 'page': {\n const page = request.graph.getNode(request.target.pageId)\n if (!page) return null\n return { pageId: page.id, nodeIds: page.childIds }\n }\n case 'selection': {\n const first = request.target.nodeIds[0]\n if (!first) return null\n const pageId = findPageId(request.graph, first)\n if (!pageId) return null\n if (!request.target.nodeIds.every((nodeId) => findPageId(request.graph, nodeId) === pageId)) {\n throw new Error('Export selection must stay on a single page')\n }\n return { pageId, nodeIds: request.target.nodeIds }\n }\n case 'node':\n return resolveExportNodes({\n ...request,\n target: { scope: 'selection', nodeIds: [request.target.nodeId] }\n })\n default:\n return null\n }\n}\n\nasync function renderRaster(\n request: ExportRequest,\n options: RasterExportOptions,\n context?: IOContext\n): Promise<Uint8Array | null> {\n const target = resolveExportNodes(request)\n if (!target) return null\n const scale = options.scale ?? 1\n\n if (context?.canvasKit && context.renderer) {\n return renderNodesToImage(\n context.canvasKit,\n context.renderer,\n request.graph,\n target.pageId,\n target.nodeIds,\n {\n scale,\n format: options.format,\n quality: options.quality,\n trimTransparent: request.target.scope === 'page' || request.target.scope === 'document'\n }\n )\n }\n\n return headlessRenderNodes(request.graph, target.pageId, target.nodeIds, {\n scale,\n format: options.format,\n quality: options.quality,\n trimTransparent: request.target.scope === 'page' || request.target.scope === 'document'\n })\n}\n\nfunction rasterFormat<F extends RasterExportFormat>(format: F): IOFormatAdapter<Lowercase<F>> {\n const extension = format.toLowerCase() as Lowercase<F>\n let mimeType = 'image/png'\n if (format === 'JPG') mimeType = 'image/jpeg'\n else if (format === 'WEBP') mimeType = 'image/webp'\n\n return {\n id: extension,\n label: format,\n role: 'derived-export',\n category: 'raster',\n extensions: [extension],\n mimeTypes: [mimeType],\n support: {\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: {\n scale: true,\n quality: format !== 'PNG',\n colorSpace: false\n },\n async exportContent(request, options?: RasterExportOptions, context?: IOContext) {\n const data = await renderRaster(\n request,\n {\n format,\n scale: options?.scale,\n quality: options?.quality\n },\n context\n )\n if (!data) throw new Error('Nothing to export')\n return {\n format: extension,\n mimeType,\n extension,\n data\n }\n }\n }\n}\n\n/** The file a document saves as: Figma's `.fig` for a design, FigJam's `.jam` for a board. */\nexport const DOCUMENT_EXTENSIONS: Readonly<Record<DocumentKind, 'fig' | 'jam'>> = {\n design: 'fig',\n board: 'jam'\n}\n\nexport const figFormat: IOFormatAdapter<'fig'> = {\n id: 'fig',\n label: 'Pairdraw Document',\n role: 'native-document',\n category: 'document',\n extensions: ['fig', 'jam'],\n mimeTypes: ['application/octet-stream'],\n support: {\n readDocument: true,\n writeDocument: true,\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: FIXED_SIZE_EXPORT,\n matchesFile(fileName) {\n const ext = lowerExt(fileName)\n return ext === 'fig' || ext === 'jam'\n },\n async readDocument(input) {\n const data = input.data.slice().buffer\n const graph = await parseFigFile(data, { populate: 'first-page' })\n return { graph, sourceFormat: 'fig' }\n },\n async writeDocument(graph, options?: FigWriteOptions, context?: IOContext) {\n return writeFig(graph, options, context, options?.thumbnailPageId)\n },\n async exportContent(request, options?: FigWriteOptions, context?: IOContext) {\n // A whole document is written as it is, so one opened from an archive keeps that archive.\n if (request.target.scope === 'document')\n return writeFig(request.graph, options, context, options?.thumbnailPageId, request.fileName)\n const extracted = extractExportGraph(request.graph, request.target)\n return writeFig(\n extracted.graph,\n options,\n context,\n options?.thumbnailPageId ?? extracted.pageId ?? undefined,\n request.fileName\n )\n }\n}\n\n/** A `.fig` named as asked, or else after the file it is written to, or else Untitled. */\nasync function writeFig(\n graph: SceneGraph,\n options: FigWriteOptions | undefined,\n context: IOContext | undefined,\n pageId: string | undefined,\n fileName?: string\n): Promise<ExportResult> {\n const data = await exportFigFile(graph, {\n ck: context?.canvasKit,\n renderer: context?.renderer,\n pageId,\n renderHeadlessThumbnail: options?.renderThumbnail ?? false,\n documentName: options?.documentName ?? (fileName && filename(fileName))\n })\n const extension = DOCUMENT_EXTENSIONS[graph.documentKind]\n return { format: 'fig', mimeType: 'application/octet-stream', extension, data }\n}\n\nexport const drawioFormat: IOFormatAdapter<'drawio'> = {\n id: 'drawio',\n label: 'draw.io Diagram',\n role: 'interchange-document',\n category: 'document',\n extensions: ['drawio', 'dio'],\n mimeTypes: ['application/vnd.jgraph.mxfile'],\n support: {\n readDocument: true,\n writeDocument: true,\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: FIXED_SIZE_EXPORT,\n laysOutOnRead: true,\n // A draw.io PNG or SVG export opens as its diagram when its name says it is one.\n matchesFile(fileName, mimeType) {\n const ext = lowerExt(fileName)\n return (\n ext === 'drawio' ||\n ext === 'dio' ||\n isDrawIOExportFileName(fileName) ||\n mimeType === 'application/vnd.jgraph.mxfile'\n )\n },\n async readDocument(input) {\n const { readDrawIOBytes } = await import('@pairdraw/drawio')\n const { drawioToSceneGraph } = await import('./formats/drawio')\n const file = readDrawIOBytes(input.data)\n if (!file) throw new Error('This file holds no draw.io diagram')\n if (file.unreadable.length > 0) {\n throw new Error(`Could not read the draw.io pages ${file.unreadable.join(', ')}`)\n }\n const graph = drawioToSceneGraph(file)\n // draw.io stores label text, not the sizes it lays out to.\n layoutAuthoredNodes(\n graph,\n graph.getPages().map((page) => page.id)\n )\n return { graph, sourceFormat: 'drawio' }\n },\n async writeDocument(graph) {\n const pageIds = graph.getPages().map((page) => page.id)\n return writeDrawIO(graph, { pageIds })\n },\n // A page or a selection goes as a one-page diagram; the document, every page.\n async exportContent(request) {\n if (request.target.scope === 'document') {\n const pageIds = request.graph.getPages().map((page) => page.id)\n return writeDrawIO(request.graph, { pageIds })\n }\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n return writeDrawIO(request.graph, target)\n }\n}\n\nexport const mermaidFormat: IOFormatAdapter<'mermaid'> = {\n id: 'mermaid',\n label: 'Mermaid Diagram',\n role: 'interchange-document',\n category: 'document',\n extensions: ['mmd', 'mermaid'],\n mimeTypes: ['text/vnd.mermaid'],\n support: {\n readDocument: true\n },\n laysOutOnRead: true,\n matchesFile(fileName, mimeType) {\n const ext = lowerExt(fileName)\n return ext === 'mmd' || ext === 'mermaid' || mimeType === 'text/vnd.mermaid'\n },\n async readDocument(input) {\n const { detectMermaidDiagram } = await import('@pairdraw/mermaid')\n const text = new TextDecoder().decode(input.data)\n if (!detectMermaidDiagram(text)) throw new Error('This file holds no Mermaid flowchart')\n // Mermaid stores a diagram's structure, which reading lays out with its text measured.\n const { mermaidToSceneGraph } = await import('./formats/mermaid')\n return { graph: await mermaidToSceneGraph(text), sourceFormat: 'mermaid' }\n }\n}\n\n/** Pages or layers as a draw.io file, loading the writer only when one is saved. */\nasync function writeDrawIO(graph: SceneGraph, target: DrawIOExportTarget): Promise<ExportResult> {\n const { writeDrawIOFile } = await import('@pairdraw/drawio')\n const { sceneGraphToDrawIO } = await import('./formats/drawio')\n const { drawioDroppedWarnings } = await import('./formats/drawio/warnings')\n return {\n format: 'drawio',\n mimeType: 'application/vnd.jgraph.mxfile',\n extension: 'drawio',\n data: writeDrawIOFile(sceneGraphToDrawIO(graph, target)),\n encoding: 'utf8',\n warnings: drawioDroppedWarnings(graph)\n }\n}\n\nexport const pngFormat = rasterFormat('PNG')\nexport const jpgFormat = rasterFormat('JPG')\nexport const webpFormat = rasterFormat('WEBP')\n\nexport const svgFormat: IOFormatAdapter<'svg'> = {\n id: 'svg',\n label: 'SVG',\n role: 'derived-export',\n category: 'vector',\n extensions: ['svg'],\n mimeTypes: ['image/svg+xml'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: { ...FIXED_SIZE_EXPORT, colorSpace: true },\n async exportContent(request, options?: SVGExportOptions, context?: IOContext) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToLaidOutSVG } = await import('./formats/svg/text/layout')\n const { booleanPathResolver, needsBooleanPaths } = await import('./formats/boolean-path')\n // A boolean made in Pairdraw stores no result path; the export computes it from the operands.\n const booleanPath = needsBooleanPaths(request.graph)\n ? await booleanPathResolver(context?.canvasKit, context?.renderer)\n : undefined\n const data = await renderNodesToLaidOutSVG(\n request.graph,\n target.pageId,\n target.nodeIds,\n {\n ...options,\n // An export writes the profile the document is stored in, so a Display P3 color keeps its\n // gamut; a caller may still ask for sRGB. PDF and thumbnails render SVG themselves and\n // stay sRGB, as their formats expect.\n colorSpace: options?.colorSpace ?? request.graph.documentColorSpace,\n booleanPath\n },\n context?.canvasKit,\n context?.renderer\n )\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'svg',\n mimeType: 'image/svg+xml',\n extension: 'svg',\n data,\n encoding: 'utf8'\n }\n }\n}\n\n/**\n * The PDF pages an export makes. A selection gets a page per layer in the order it lists them,\n * each sized to its layer, as slides and Figma's frame export do, unless `single` asks for one\n * page; a page or a document is one page of its layers unless `frames` asks for a page each.\n */\nasync function pdfPageSpecs(\n request: ExportRequest,\n options: PDFFormatExportOptions | undefined\n): Promise<PDFPageSpec[]> {\n const frames = options?.pages ? options.pages === 'frames' : request.target.scope === 'selection'\n if (frames) {\n const { target } = request\n let ids: string[] | undefined\n if (target.scope === 'selection') ids = target.nodeIds\n else if (target.scope === 'node') ids = [target.nodeId]\n const first = ids?.[0]\n let currentPageId: string | null | undefined\n if (first) currentPageId = findPageId(request.graph, first)\n else if (target.scope === 'page') currentPageId = target.pageId\n else if (target.scope === 'document') currentPageId = request.graph.getPages()[0]?.id\n if (!currentPageId) throw new Error('Nothing to export')\n // Without IDs, the plan takes the page's visible layers, in layer order.\n const { planPDFPages } = await import('./formats/pdf/plan')\n return planPDFPages(request.graph, { mode: 'frames', ids, currentPageId })\n }\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n return [target]\n}\n\nexport const pdfFormat: IOFormatAdapter<'pdf'> = {\n id: 'pdf',\n label: 'PDF',\n role: 'derived-export',\n category: 'vector',\n extensions: ['pdf'],\n mimeTypes: ['application/pdf'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: PDFFormatExportOptions, context?: IOContext) {\n const specs = await pdfPageSpecs(request, options)\n // Embedded, as Figma embeds every face its PDFs draw.\n const { exportPDFDocument } = await import('./formats/pdf/document')\n const data = (\n await exportPDFDocument(\n request.graph,\n specs,\n { embedFonts: true },\n context?.canvasKit,\n context?.renderer\n )\n )?.data\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'pdf',\n mimeType: 'application/pdf',\n extension: 'pdf',\n data\n }\n }\n}\n\n/**\n * Every top-level frame becomes a slide, so a PPTX document export spans all\n * pages — the shared resolver only reaches the first one.\n */\nfunction resolvePPTXExportNodes(\n request: ExportRequest\n): { pageId: string; nodeIds: string[] } | null {\n if (request.target.scope !== 'document') return resolveExportNodes(request)\n const pages = request.graph.getPages()\n if (!pages.length) return null\n return { pageId: pages[0].id, nodeIds: pages.flatMap((page) => page.childIds) }\n}\n\nexport const pptxFormat: IOFormatAdapter<'pptx'> = {\n id: 'pptx',\n label: 'PowerPoint',\n role: 'derived-export',\n category: 'print',\n extensions: ['pptx'],\n mimeTypes: ['application/vnd.openxmlformats-officedocument.presentationml.presentation'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: PPTXExportOptions, context?: IOContext) {\n const target = resolvePPTXExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToPPTX } = await import('./formats/pptx')\n const data = await renderNodesToPPTX(request.graph, target.pageId, target.nodeIds, {\n ...options,\n context: options?.context ?? context\n })\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'pptx',\n mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n extension: 'pptx',\n data\n }\n }\n}\n\nexport const jsxFormat: IOFormatAdapter<'jsx'> = {\n id: 'jsx',\n label: 'JSX',\n role: 'derived-export',\n category: 'code',\n extensions: ['jsx'],\n mimeTypes: ['text/plain', 'text/jsx'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, _options?: unknown, context?: IOContext): Promise<ExportResult> {\n const nodeId = ensureSingleNode(request.target)\n // A page or a document exports its top-level layers, as Tailwind JSX does.\n const target = nodeId ? null : resolveExportNodes(request)\n const { booleanPathResolver, needsBooleanPaths } = await import('./formats/boolean-path')\n const authored = needsBooleanPaths(request.graph)\n ? [...request.graph.getAllNodes()].filter(\n (node) => node.type === 'BOOLEAN_OPERATION' && node.fillGeometry.length === 0\n )\n : []\n const restore: (() => void)[] = []\n if (authored.length > 0) {\n const { parseSVGPath } = await import('@pairdraw/scene-graph/parse-path')\n const booleanPath = await booleanPathResolver(context?.canvasKit, context?.renderer)\n for (const node of authored) {\n const d = booleanPath(request.graph, node)\n if (!d) continue\n const network = parseSVGPath(d, 'EVENODD', { includeOpenRegions: true })\n const carrier = node as typeof node & { vectorNetwork?: typeof network }\n const previous = carrier.vectorNetwork\n carrier.vectorNetwork = network\n restore.push(() => {\n carrier.vectorNetwork = previous\n })\n }\n }\n let data = ''\n try {\n if (nodeId) data = sceneNodeToJSX(nodeId, request.graph)\n else if (target) data = selectionToJSX(target.nodeIds, request.graph)\n } finally {\n for (const undo of restore) undo()\n }\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'jsx',\n mimeType: 'text/plain',\n extension: 'jsx',\n data,\n encoding: 'utf8'\n }\n }\n}\n\nexport const htmlFormat: IOFormatAdapter<'html'> = {\n id: 'html',\n label: 'HTML',\n role: 'derived-export',\n category: 'code',\n extensions: ['html'],\n mimeTypes: ['text/html'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: HTMLExportOptions, context?: IOContext) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToHTML } = await import('./formats/html')\n const { html, assets } = await renderNodesToHTML(\n request.graph,\n target.nodeIds,\n options,\n request.fileName,\n context\n )\n return {\n format: 'html',\n mimeType: 'text/html',\n extension: 'html',\n data: html,\n encoding: 'utf8',\n assets\n }\n }\n}\n\nexport const tailwindJSXFormat: IOFormatAdapter<'tailwind-jsx'> = {\n id: 'tailwind-jsx',\n label: 'Tailwind JSX',\n role: 'derived-export',\n category: 'code',\n extensions: ['jsx'],\n mimeTypes: ['text/plain', 'text/jsx'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, _options?: unknown, context?: IOContext) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { sceneNodesToTailwindJSX } = await import('@pairdraw/dom-css/export')\n const { vectorElement } = await import('#core/io/formats/html/vectors')\n const { booleanPathResolver, needsBooleanPaths } = await import('./formats/boolean-path')\n const booleanPath = needsBooleanPaths(request.graph)\n ? await booleanPathResolver(context?.canvasKit, context?.renderer)\n : undefined\n const data = sceneNodesToTailwindJSX(request.graph, target.nodeIds, {\n vectorElement: (graph, node) => vectorElement(graph, node, booleanPath)\n })\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'tailwind-jsx',\n mimeType: 'text/plain',\n extension: 'jsx',\n data,\n encoding: 'utf8'\n }\n }\n}\n\nexport { penFormat }\n\nexport const BUILTIN_IO_FORMATS = [\n figFormat,\n penFormat,\n drawioFormat,\n mermaidFormat,\n pngFormat,\n jpgFormat,\n webpFormat,\n svgFormat,\n pdfFormat,\n pptxFormat,\n jsxFormat,\n tailwindJSXFormat,\n htmlFormat\n] as const satisfies readonly IOFormatAdapter[]\n\nexport type BuiltinIOFormatId = (typeof BUILTIN_IO_FORMATS)[number]['id']\n"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,sBAAuC;CAC3C,gBAAgB;CAChB,YAAY;CACZ,iBAAiB;CACjB,YAAY;AACd;;AAGA,MAAM,oBAA2C;CAAE,OAAO;CAAO,SAAS;AAAM;AA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zC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,mBAAmB;EAChD,MAAM,EAAE,sBAAsB,MAAM,OAAO;EAC3C,MAAM,EAAE,MAAM,WAAW,MAAM,kBAC7B,QAAQ,OACR,OAAO,SACP,SACA,QAAQ,UACR,OACF;EACA,OAAO;GACL,QAAQ;GACR,UAAU;GACV,WAAW;GACX,MAAM;GACN,UAAU;GACV;EACF;CACF;AACF;AAEA,MAAa,oBAAqD;CAChE,IAAI;CACJ,OAAO;CACP,MAAM;CACN,UAAU;CACV,YAAY,CAAC,KAAK;CAClB,WAAW,CAAC,cAAc,UAAU;CACpC,SAAS;CACT,eAAe;CACf,MAAM,cAAc,SAAS,UAAoB,SAAqB;EACpE,MAAM,SAAS,mBAAmB,OAAO;EACzC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,mBAAmB;EAChD,MAAM,EAAE,4BAA4B,MAAM,OAAO;EACjD,MAAM,EAAE,kBAAkB,MAAM,OAAO;EACvC,MAAM,EAAE,qBAAqB,sBAAsB,MAAM,OAAO;EAChE,MAAM,cAAc,kBAAkB,QAAQ,KAAK,IAC/C,MAAM,oBAAoB,SAAS,WAAW,SAAS,QAAQ,IAC/D,KAAA;EACJ,MAAM,OAAO,wBAAwB,QAAQ,OAAO,OAAO,SAAS,EAClE,gBAAgB,OAAO,SAAS,cAAc,OAAO,MAAM,WAAW,EACxE,CAAC;EACD,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,mBAAmB;EAC9C,OAAO;GACL,QAAQ;GACR,UAAU;GACV,WAAW;GACX;GACA,UAAU;EACZ;CACF;AACF;AAIA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
1
+ {"version":3,"file":"formats.js","names":[],"sources":["../../src/io/formats.ts"],"sourcesContent":["import { filename } from 'pathe/utils'\n\nimport { sceneNodeToJSX, selectionToJSX } from '@pairdraw/design-jsx'\nimport { isDrawIOExportFileName } from '@pairdraw/drawio'\nimport type { DocumentKind, SceneGraph } from '@pairdraw/scene-graph'\n\nimport { layoutAuthoredNodes } from '#core/layout'\n\nimport type { DrawIOExportTarget } from './formats/drawio/export'\nimport { exportFigFile, parseFigFile } from './formats/fig'\nimport type { PDFPageSpec } from './formats/pdf/plan'\nimport { penFormat } from './formats/pen'\nimport type { PPTXExportOptions } from './formats/pptx'\nimport { headlessRenderNodes, renderNodesToImage, type RasterExportFormat } from './formats/raster'\nimport { extractExportGraph, findPageId } from './subgraph'\nimport type {\n ExportRequest,\n ExportResult,\n FigWriteOptions,\n HTMLExportOptions,\n IOContext,\n IOFormatAdapter,\n IOFormatExportOptions,\n IOFormatSupport,\n PDFFormatExportOptions,\n RasterExportOptions,\n SVGExportOptions\n} from './types'\n\n/** Formats that export a document, page, selection, or single node alike. */\nconst EXPORT_EVERY_TARGET: IOFormatSupport = {\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n}\n\n/** Formats with a size of their own, so no export scale or quality. */\nconst FIXED_SIZE_EXPORT: IOFormatExportOptions = { scale: false, quality: false }\n\nfunction lowerExt(name: string): string {\n const match = /\\.([^.]+)$/.exec(name.toLowerCase())\n return match?.[1] ?? ''\n}\n\nfunction ensureSingleNode(target: ExportRequest['target']): string | null {\n if (target.scope === 'node') return target.nodeId\n if (target.scope === 'selection' && target.nodeIds.length === 1) return target.nodeIds[0]\n return null\n}\n\nfunction resolveExportNodes(request: ExportRequest): { pageId: string; nodeIds: string[] } | null {\n switch (request.target.scope) {\n case 'document': {\n const page = request.graph.getPages()[0]\n return { pageId: page.id, nodeIds: page.childIds }\n }\n case 'page': {\n const page = request.graph.getNode(request.target.pageId)\n if (!page) return null\n return { pageId: page.id, nodeIds: page.childIds }\n }\n case 'selection': {\n const first = request.target.nodeIds[0]\n if (!first) return null\n const pageId = findPageId(request.graph, first)\n if (!pageId) return null\n if (!request.target.nodeIds.every((nodeId) => findPageId(request.graph, nodeId) === pageId)) {\n throw new Error('Export selection must stay on a single page')\n }\n return { pageId, nodeIds: request.target.nodeIds }\n }\n case 'node':\n return resolveExportNodes({\n ...request,\n target: { scope: 'selection', nodeIds: [request.target.nodeId] }\n })\n default:\n return null\n }\n}\n\nasync function renderRaster(\n request: ExportRequest,\n options: RasterExportOptions,\n context?: IOContext\n): Promise<Uint8Array | null> {\n const target = resolveExportNodes(request)\n if (!target) return null\n const scale = options.scale ?? 1\n\n if (context?.canvasKit && context.renderer) {\n return renderNodesToImage(\n context.canvasKit,\n context.renderer,\n request.graph,\n target.pageId,\n target.nodeIds,\n {\n scale,\n format: options.format,\n quality: options.quality,\n trimTransparent: request.target.scope === 'page' || request.target.scope === 'document'\n }\n )\n }\n\n return headlessRenderNodes(request.graph, target.pageId, target.nodeIds, {\n scale,\n format: options.format,\n quality: options.quality,\n trimTransparent: request.target.scope === 'page' || request.target.scope === 'document'\n })\n}\n\nfunction rasterFormat<F extends RasterExportFormat>(format: F): IOFormatAdapter<Lowercase<F>> {\n const extension = format.toLowerCase() as Lowercase<F>\n let mimeType = 'image/png'\n if (format === 'JPG') mimeType = 'image/jpeg'\n else if (format === 'WEBP') mimeType = 'image/webp'\n\n return {\n id: extension,\n label: format,\n role: 'derived-export',\n category: 'raster',\n extensions: [extension],\n mimeTypes: [mimeType],\n support: {\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: {\n scale: true,\n quality: format !== 'PNG',\n colorSpace: false\n },\n async exportContent(request, options?: RasterExportOptions, context?: IOContext) {\n const data = await renderRaster(\n request,\n {\n format,\n scale: options?.scale,\n quality: options?.quality\n },\n context\n )\n if (!data) throw new Error('Nothing to export')\n return {\n format: extension,\n mimeType,\n extension,\n data\n }\n }\n }\n}\n\n/** The file a document saves as: Figma's `.fig` for a design, FigJam's `.jam` for a board. */\nexport const DOCUMENT_EXTENSIONS: Readonly<Record<DocumentKind, 'fig' | 'jam'>> = {\n design: 'fig',\n board: 'jam'\n}\n\nexport const figFormat: IOFormatAdapter<'fig'> = {\n id: 'fig',\n label: 'Pairdraw Document',\n role: 'native-document',\n category: 'document',\n extensions: ['fig', 'jam'],\n mimeTypes: ['application/octet-stream'],\n support: {\n readDocument: true,\n writeDocument: true,\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: FIXED_SIZE_EXPORT,\n matchesFile(fileName) {\n const ext = lowerExt(fileName)\n return ext === 'fig' || ext === 'jam'\n },\n async readDocument(input) {\n const data = input.data.slice().buffer\n const graph = await parseFigFile(data, { populate: 'first-page' })\n return { graph, sourceFormat: 'fig' }\n },\n async writeDocument(graph, options?: FigWriteOptions, context?: IOContext) {\n return writeFig(graph, options, context, options?.thumbnailPageId)\n },\n async exportContent(request, options?: FigWriteOptions, context?: IOContext) {\n // A whole document is written as it is, so one opened from an archive keeps that archive.\n if (request.target.scope === 'document')\n return writeFig(request.graph, options, context, options?.thumbnailPageId, request.fileName)\n const extracted = extractExportGraph(request.graph, request.target)\n return writeFig(\n extracted.graph,\n options,\n context,\n options?.thumbnailPageId ?? extracted.pageId ?? undefined,\n request.fileName\n )\n }\n}\n\n/** A `.fig` named as asked, or else after the file it is written to, or else Untitled. */\nasync function writeFig(\n graph: SceneGraph,\n options: FigWriteOptions | undefined,\n context: IOContext | undefined,\n pageId: string | undefined,\n fileName?: string\n): Promise<ExportResult> {\n const data = await exportFigFile(graph, {\n ck: context?.canvasKit,\n renderer: context?.renderer,\n pageId,\n renderHeadlessThumbnail: options?.renderThumbnail ?? false,\n documentName: options?.documentName ?? (fileName && filename(fileName))\n })\n const extension = DOCUMENT_EXTENSIONS[graph.documentKind]\n return { format: 'fig', mimeType: 'application/octet-stream', extension, data }\n}\n\nexport const drawioFormat: IOFormatAdapter<'drawio'> = {\n id: 'drawio',\n label: 'draw.io Diagram',\n role: 'interchange-document',\n category: 'document',\n extensions: ['drawio', 'dio'],\n mimeTypes: ['application/vnd.jgraph.mxfile'],\n support: {\n readDocument: true,\n writeDocument: true,\n exportDocument: true,\n exportPage: true,\n exportSelection: true,\n exportNode: true\n },\n exportOptions: FIXED_SIZE_EXPORT,\n laysOutOnRead: true,\n // A draw.io PNG or SVG export opens as its diagram when its name says it is one.\n matchesFile(fileName, mimeType) {\n const ext = lowerExt(fileName)\n return (\n ext === 'drawio' ||\n ext === 'dio' ||\n isDrawIOExportFileName(fileName) ||\n mimeType === 'application/vnd.jgraph.mxfile'\n )\n },\n async readDocument(input) {\n const { readDrawIOBytes } = await import('@pairdraw/drawio')\n const { drawioToSceneGraph } = await import('./formats/drawio')\n const file = readDrawIOBytes(input.data)\n if (!file) throw new Error('This file holds no draw.io diagram')\n if (file.unreadable.length > 0) {\n throw new Error(`Could not read the draw.io pages ${file.unreadable.join(', ')}`)\n }\n const graph = drawioToSceneGraph(file)\n // draw.io stores label text, not the sizes it lays out to.\n layoutAuthoredNodes(\n graph,\n graph.getPages().map((page) => page.id)\n )\n return { graph, sourceFormat: 'drawio' }\n },\n async writeDocument(graph) {\n const pageIds = graph.getPages().map((page) => page.id)\n return writeDrawIO(graph, { pageIds })\n },\n // A page or a selection goes as a one-page diagram; the document, every page.\n async exportContent(request) {\n if (request.target.scope === 'document') {\n const pageIds = request.graph.getPages().map((page) => page.id)\n return writeDrawIO(request.graph, { pageIds })\n }\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n return writeDrawIO(request.graph, target)\n }\n}\n\nexport const mermaidFormat: IOFormatAdapter<'mermaid'> = {\n id: 'mermaid',\n label: 'Mermaid Diagram',\n role: 'interchange-document',\n category: 'document',\n extensions: ['mmd', 'mermaid'],\n mimeTypes: ['text/vnd.mermaid'],\n support: {\n readDocument: true\n },\n laysOutOnRead: true,\n matchesFile(fileName, mimeType) {\n const ext = lowerExt(fileName)\n return ext === 'mmd' || ext === 'mermaid' || mimeType === 'text/vnd.mermaid'\n },\n async readDocument(input) {\n const { detectMermaidDiagram } = await import('@pairdraw/mermaid')\n const text = new TextDecoder().decode(input.data)\n if (!detectMermaidDiagram(text)) throw new Error('This file holds no Mermaid flowchart')\n // Mermaid stores a diagram's structure, which reading lays out with its text measured.\n const { mermaidToSceneGraph } = await import('./formats/mermaid')\n return { graph: await mermaidToSceneGraph(text), sourceFormat: 'mermaid' }\n }\n}\n\n/** Pages or layers as a draw.io file, loading the writer only when one is saved. */\nasync function writeDrawIO(graph: SceneGraph, target: DrawIOExportTarget): Promise<ExportResult> {\n const { writeDrawIOFile } = await import('@pairdraw/drawio')\n const { sceneGraphToDrawIO } = await import('./formats/drawio')\n const { drawioWriteWarnings, drawioWriteWarningText } = await import('./formats/drawio/warnings')\n const warningDetails = drawioWriteWarnings(graph)\n const written: ExportResult = {\n format: 'drawio',\n mimeType: 'application/vnd.jgraph.mxfile',\n extension: 'drawio',\n data: writeDrawIOFile(sceneGraphToDrawIO(graph, target)),\n encoding: 'utf8'\n }\n if (warningDetails.length === 0) return written\n return {\n ...written,\n warnings: warningDetails.map(drawioWriteWarningText),\n warningDetails\n }\n}\n\nexport const pngFormat = rasterFormat('PNG')\nexport const jpgFormat = rasterFormat('JPG')\nexport const webpFormat = rasterFormat('WEBP')\n\nexport const svgFormat: IOFormatAdapter<'svg'> = {\n id: 'svg',\n label: 'SVG',\n role: 'derived-export',\n category: 'vector',\n extensions: ['svg'],\n mimeTypes: ['image/svg+xml'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: { ...FIXED_SIZE_EXPORT, colorSpace: true },\n async exportContent(request, options?: SVGExportOptions, context?: IOContext) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToLaidOutSVG } = await import('./formats/svg/text/layout')\n const { booleanPathResolver, needsBooleanPaths } = await import('./formats/boolean-path')\n // A boolean made in Pairdraw stores no result path; the export computes it from the operands.\n const booleanPath = needsBooleanPaths(request.graph)\n ? await booleanPathResolver(context?.canvasKit, context?.renderer)\n : undefined\n const data = await renderNodesToLaidOutSVG(\n request.graph,\n target.pageId,\n target.nodeIds,\n {\n ...options,\n // An export writes the profile the document is stored in, so a Display P3 color keeps its\n // gamut; a caller may still ask for sRGB. PDF and thumbnails render SVG themselves and\n // stay sRGB, as their formats expect.\n colorSpace: options?.colorSpace ?? request.graph.documentColorSpace,\n booleanPath\n },\n context?.canvasKit,\n context?.renderer\n )\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'svg',\n mimeType: 'image/svg+xml',\n extension: 'svg',\n data,\n encoding: 'utf8'\n }\n }\n}\n\n/**\n * The PDF pages an export makes. A selection gets a page per layer in the order it lists them,\n * each sized to its layer, as slides and Figma's frame export do, unless `single` asks for one\n * page; a page or a document is one page of its layers unless `frames` asks for a page each.\n */\nasync function pdfPageSpecs(\n request: ExportRequest,\n options: PDFFormatExportOptions | undefined\n): Promise<PDFPageSpec[]> {\n const frames = options?.pages ? options.pages === 'frames' : request.target.scope === 'selection'\n if (frames) {\n const { target } = request\n let ids: string[] | undefined\n if (target.scope === 'selection') ids = target.nodeIds\n else if (target.scope === 'node') ids = [target.nodeId]\n const first = ids?.[0]\n let currentPageId: string | null | undefined\n if (first) currentPageId = findPageId(request.graph, first)\n else if (target.scope === 'page') currentPageId = target.pageId\n else if (target.scope === 'document') currentPageId = request.graph.getPages()[0]?.id\n if (!currentPageId) throw new Error('Nothing to export')\n // Without IDs, the plan takes the page's visible layers, in layer order.\n const { planPDFPages } = await import('./formats/pdf/plan')\n return planPDFPages(request.graph, { mode: 'frames', ids, currentPageId })\n }\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n return [target]\n}\n\nexport const pdfFormat: IOFormatAdapter<'pdf'> = {\n id: 'pdf',\n label: 'PDF',\n role: 'derived-export',\n category: 'vector',\n extensions: ['pdf'],\n mimeTypes: ['application/pdf'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: PDFFormatExportOptions, context?: IOContext) {\n const specs = await pdfPageSpecs(request, options)\n // Embedded, as Figma embeds every face its PDFs draw.\n const { exportPDFDocument } = await import('./formats/pdf/document')\n const data = (\n await exportPDFDocument(\n request.graph,\n specs,\n { embedFonts: true },\n context?.canvasKit,\n context?.renderer\n )\n )?.data\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'pdf',\n mimeType: 'application/pdf',\n extension: 'pdf',\n data\n }\n }\n}\n\n/**\n * Every top-level frame becomes a slide, so a PPTX document export spans all\n * pages — the shared resolver only reaches the first one.\n */\nfunction resolvePPTXExportNodes(\n request: ExportRequest\n): { pageId: string; nodeIds: string[] } | null {\n if (request.target.scope !== 'document') return resolveExportNodes(request)\n const pages = request.graph.getPages()\n if (!pages.length) return null\n return { pageId: pages[0].id, nodeIds: pages.flatMap((page) => page.childIds) }\n}\n\nexport const pptxFormat: IOFormatAdapter<'pptx'> = {\n id: 'pptx',\n label: 'PowerPoint',\n role: 'derived-export',\n category: 'print',\n extensions: ['pptx'],\n mimeTypes: ['application/vnd.openxmlformats-officedocument.presentationml.presentation'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: PPTXExportOptions, context?: IOContext) {\n const target = resolvePPTXExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToPPTX } = await import('./formats/pptx')\n const data = await renderNodesToPPTX(request.graph, target.pageId, target.nodeIds, {\n ...options,\n context: options?.context ?? context\n })\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'pptx',\n mimeType: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',\n extension: 'pptx',\n data\n }\n }\n}\n\nexport const jsxFormat: IOFormatAdapter<'jsx'> = {\n id: 'jsx',\n label: 'JSX',\n role: 'derived-export',\n category: 'code',\n extensions: ['jsx'],\n mimeTypes: ['text/plain', 'text/jsx'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, _options?: unknown, context?: IOContext): Promise<ExportResult> {\n const nodeId = ensureSingleNode(request.target)\n // A page or a document exports its top-level layers, as Tailwind JSX does.\n const target = nodeId ? null : resolveExportNodes(request)\n const { booleanPathResolver, needsBooleanPaths } = await import('./formats/boolean-path')\n const authored = needsBooleanPaths(request.graph)\n ? [...request.graph.getAllNodes()].filter(\n (node) => node.type === 'BOOLEAN_OPERATION' && node.fillGeometry.length === 0\n )\n : []\n const restore: (() => void)[] = []\n if (authored.length > 0) {\n const { parseSVGPath } = await import('@pairdraw/scene-graph/parse-path')\n const booleanPath = await booleanPathResolver(context?.canvasKit, context?.renderer)\n for (const node of authored) {\n const d = booleanPath(request.graph, node)\n if (!d) continue\n const network = parseSVGPath(d, 'EVENODD', { includeOpenRegions: true })\n const carrier = node as typeof node & { vectorNetwork?: typeof network }\n const previous = carrier.vectorNetwork\n carrier.vectorNetwork = network\n restore.push(() => {\n carrier.vectorNetwork = previous\n })\n }\n }\n let data = ''\n try {\n if (nodeId) data = sceneNodeToJSX(nodeId, request.graph)\n else if (target) data = selectionToJSX(target.nodeIds, request.graph)\n } finally {\n for (const undo of restore) undo()\n }\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'jsx',\n mimeType: 'text/plain',\n extension: 'jsx',\n data,\n encoding: 'utf8'\n }\n }\n}\n\nexport const htmlFormat: IOFormatAdapter<'html'> = {\n id: 'html',\n label: 'HTML',\n role: 'derived-export',\n category: 'code',\n extensions: ['html'],\n mimeTypes: ['text/html'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, options?: HTMLExportOptions, context?: IOContext) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { renderNodesToHTML } = await import('./formats/html')\n const { html, assets } = await renderNodesToHTML(\n request.graph,\n target.nodeIds,\n options,\n request.fileName,\n context\n )\n return {\n format: 'html',\n mimeType: 'text/html',\n extension: 'html',\n data: html,\n encoding: 'utf8',\n assets\n }\n }\n}\n\nexport const tailwindJSXFormat: IOFormatAdapter<'tailwind-jsx'> = {\n id: 'tailwind-jsx',\n label: 'Tailwind JSX',\n role: 'derived-export',\n category: 'code',\n extensions: ['jsx'],\n mimeTypes: ['text/plain', 'text/jsx'],\n support: EXPORT_EVERY_TARGET,\n exportOptions: FIXED_SIZE_EXPORT,\n async exportContent(request, _options?: unknown, context?: IOContext) {\n const target = resolveExportNodes(request)\n if (!target) throw new Error('Nothing to export')\n const { sceneNodesToTailwindJSX } = await import('@pairdraw/dom-css/export')\n const { vectorElement } = await import('#core/io/formats/html/vectors')\n const { booleanPathResolver, needsBooleanPaths } = await import('./formats/boolean-path')\n const booleanPath = needsBooleanPaths(request.graph)\n ? await booleanPathResolver(context?.canvasKit, context?.renderer)\n : undefined\n const data = sceneNodesToTailwindJSX(request.graph, target.nodeIds, {\n vectorElement: (graph, node) => vectorElement(graph, node, booleanPath)\n })\n if (!data) throw new Error('Nothing to export')\n return {\n format: 'tailwind-jsx',\n mimeType: 'text/plain',\n extension: 'jsx',\n data,\n encoding: 'utf8'\n }\n }\n}\n\nexport { penFormat }\n\nexport const BUILTIN_IO_FORMATS = [\n figFormat,\n penFormat,\n drawioFormat,\n mermaidFormat,\n pngFormat,\n jpgFormat,\n webpFormat,\n svgFormat,\n pdfFormat,\n pptxFormat,\n jsxFormat,\n tailwindJSXFormat,\n htmlFormat\n] as const satisfies readonly IOFormatAdapter[]\n\nexport type BuiltinIOFormatId = (typeof BUILTIN_IO_FORMATS)[number]['id']\n"],"mappings":";;;;;;;;;;;;AA8BA,MAAM,sBAAuC;CAC3C,gBAAgB;CAChB,YAAY;CACZ,iBAAiB;CACjB,YAAY;AACd;;AAGA,MAAM,oBAA2C;CAAE,OAAO;CAAO,SAAS;AAAM;AAEhF,SAAS,SAAS,MAAsB;CAEtC,OADc,aAAa,KAAK,KAAK,YAAY,CACtC,CAAC,GAAG,MAAM;AACvB;AAEA,SAAS,iBAAiB,QAAgD;CACxE,IAAI,OAAO,UAAU,QAAQ,OAAO,OAAO;CAC3C,IAAI,OAAO,UAAU,eAAe,OAAO,QAAQ,WAAW,GAAG,OAAO,OAAO,QAAQ;CACvF,OAAO;AACT;AAEA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,QAAQ,OACR,OAAO,SACP,SACA,QAAQ,UACR,OACF;EACA,OAAO;GACL,QAAQ;GACR,UAAU;GACV,WAAW;GACX,MAAM;GACN,UAAU;GACV;EACF;CACF;AACF;AAEA,MAAa,oBAAqD;CAChE,IAAI;CACJ,OAAO;CACP,MAAM;CACN,UAAU;CACV,YAAY,CAAC,KAAK;CAClB,WAAW,CAAC,cAAc,UAAU;CACpC,SAAS;CACT,eAAe;CACf,MAAM,cAAc,SAAS,UAAoB,SAAqB;EACpE,MAAM,SAAS,mBAAmB,OAAO;EACzC,IAAI,CAAC,QAAQ,MAAM,IAAI,MAAM,mBAAmB;EAChD,MAAM,EAAE,4BAA4B,MAAM,OAAO;EACjD,MAAM,EAAE,kBAAkB,MAAM,OAAO;EACvC,MAAM,EAAE,qBAAqB,sBAAsB,MAAM,OAAO;EAChE,MAAM,cAAc,kBAAkB,QAAQ,KAAK,IAC/C,MAAM,oBAAoB,SAAS,WAAW,SAAS,QAAQ,IAC/D,KAAA;EACJ,MAAM,OAAO,wBAAwB,QAAQ,OAAO,OAAO,SAAS,EAClE,gBAAgB,OAAO,SAAS,cAAc,OAAO,MAAM,WAAW,EACxE,CAAC;EACD,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,mBAAmB;EAC9C,OAAO;GACL,QAAQ;GACR,UAAU;GACV,WAAW;GACX;GACA,UAAU;EACZ;CACF;AACF;AAIA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
@@ -1,4 +1,4 @@
1
- import { ExportAsset, ExportRequest, ExportResult, ExportTarget, FigWriteOptions, HTMLExportOptions, IOBinaryData, IOContext, IOData, IOFormatAdapter, IOFormatCategory, IOFormatExportOptions, IOFormatRole, IOFormatSupport, IOTextData, IOTextEncoding, PDFFormatExportOptions, RasterExportOptions, ReadDocumentInput, ReadDocumentResult, ReadDocumentWarning, SVGExportOptions } from "./types.js";
1
+ import { ExportAsset, ExportRequest, ExportResult, ExportTarget, FigWriteOptions, HTMLExportOptions, IOBinaryData, IOContext, IOData, IOFormatAdapter, IOFormatCategory, IOFormatExportOptions, IOFormatRole, IOFormatSupport, IOTextData, IOTextEncoding, PDFFormatExportOptions, RasterExportOptions, ReadDocumentInput, ReadDocumentResult, ReadDocumentWarning, SVGExportOptions, WriteDocumentWarning } from "./types.js";
2
2
  import { penFormat } from "./formats/pen/index.js";
3
3
  import { BUILTIN_IO_FORMATS, BuiltinIOFormatId, DOCUMENT_EXTENSIONS, figFormat, htmlFormat, jpgFormat, jsxFormat, pngFormat, svgFormat, tailwindJSXFormat, webpFormat } from "./formats.js";
4
4
  import { vectorElement } from "./formats/html/vectors.js";
@@ -7,4 +7,4 @@ import { renderNodesToPPTX } from "./formats/pptx/export.js";
7
7
  import "./formats/pptx/index.js";
8
8
  import { IORegistry } from "./registry.js";
9
9
  import { extractExportGraph, findPageId } from "./subgraph.js";
10
- export { BUILTIN_IO_FORMATS, type BuiltinIOFormatId, DOCUMENT_EXTENSIONS, type ExportAsset, type ExportRequest, type ExportResult, type ExportTarget, type FigWriteOptions, type HTMLExportOptions, type IOBinaryData, type IOContext, type IOData, type IOFormatAdapter, type IOFormatCategory, type IOFormatExportOptions, type IOFormatRole, type IOFormatSupport, IORegistry, type IOTextData, type IOTextEncoding, type PDFFormatExportOptions, type PPTXExportOptions, type PPTXExportStats, type PPTXRasterize, type RasterExportOptions, type ReadDocumentInput, type ReadDocumentResult, type ReadDocumentWarning, type SVGExportOptions, extractExportGraph, figFormat, findPageId, htmlFormat, jpgFormat, jsxFormat, penFormat, pngFormat, renderNodesToPPTX, svgFormat, tailwindJSXFormat, vectorElement, webpFormat };
10
+ export { BUILTIN_IO_FORMATS, type BuiltinIOFormatId, DOCUMENT_EXTENSIONS, type ExportAsset, type ExportRequest, type ExportResult, type ExportTarget, type FigWriteOptions, type HTMLExportOptions, type IOBinaryData, type IOContext, type IOData, type IOFormatAdapter, type IOFormatCategory, type IOFormatExportOptions, type IOFormatRole, type IOFormatSupport, IORegistry, type IOTextData, type IOTextEncoding, type PDFFormatExportOptions, type PPTXExportOptions, type PPTXExportStats, type PPTXRasterize, type RasterExportOptions, type ReadDocumentInput, type ReadDocumentResult, type ReadDocumentWarning, type SVGExportOptions, type WriteDocumentWarning, extractExportGraph, figFormat, findPageId, htmlFormat, jpgFormat, jsxFormat, penFormat, pngFormat, renderNodesToPPTX, svgFormat, tailwindJSXFormat, vectorElement, webpFormat };
@@ -4,10 +4,12 @@ import { SkiaRenderer } from "../canvas/renderer.js";
4
4
  import "../icons/index.js";
5
5
  import { RasterExportFormat } from "./formats/raster/render.js";
6
6
  import "./formats/raster/index.js";
7
+ import { DrawioWriteWarning } from "./formats/drawio/warnings.js";
7
8
  import { CanvasKit } from "canvaskit-wasm";
8
9
  import { RenderColorSpace } from "@pairdraw/scene-graph/color";
9
10
  import { SceneGraph } from "@pairdraw/scene-graph";
10
11
  import { TailwindStylesheetLoader } from "@pairdraw/dom-css/export";
12
+ import { PenWriteWarning } from "@pairdraw/pen";
11
13
  //#region src/io/types.d.ts
12
14
  type IOFormatRole = 'native-document' | 'interchange-document' | 'derived-export';
13
15
  type IOFormatCategory = 'document' | 'raster' | 'vector' | 'code' | 'print';
@@ -128,7 +130,14 @@ interface ExportResult {
128
130
  assets?: ExportAsset[];
129
131
  /** What the format could not hold, such as the variables draw.io has no model for. */
130
132
  warnings?: string[];
131
- }
133
+ /** The same facts as kinds, for a host that shows them in its own language. */
134
+ warningDetails?: WriteDocumentWarning[];
135
+ }
136
+ /**
137
+ * What a writer could not put in its file, as facts: the pen and draw.io writers name their own
138
+ * kinds, and a host translates them instead of printing the English `warnings` sentences.
139
+ */
140
+ type WriteDocumentWarning = PenWriteWarning | DrawioWriteWarning;
132
141
  interface HTMLExportOptions {
133
142
  html?: 'fragment' | 'standalone';
134
143
  style?: 'inline' | 'tailwind';
@@ -183,5 +192,5 @@ interface IOFormatAdapter<Id extends string = string> {
183
192
  exportContent?(request: ExportRequest, options?: unknown, context?: IOContext): Promise<ExportResult>;
184
193
  }
185
194
  //#endregion
186
- export { ExportAsset, ExportRequest, ExportResult, ExportTarget, ExportTargetDocument, ExportTargetNode, ExportTargetPage, ExportTargetSelection, FigWriteOptions, HTMLExportOptions, IOBinaryData, IOContext, IOData, IOFormatAdapter, IOFormatCategory, IOFormatExportOptions, IOFormatRole, IOFormatSupport, IOTextData, IOTextEncoding, PDFFormatExportOptions, RasterExportOptions, ReadDocumentInput, ReadDocumentResult, ReadDocumentWarning, SVGExportOptions };
195
+ export { ExportAsset, ExportRequest, ExportResult, ExportTarget, ExportTargetDocument, ExportTargetNode, ExportTargetPage, ExportTargetSelection, FigWriteOptions, HTMLExportOptions, IOBinaryData, IOContext, IOData, IOFormatAdapter, IOFormatCategory, IOFormatExportOptions, IOFormatRole, IOFormatSupport, IOTextData, IOTextEncoding, PDFFormatExportOptions, RasterExportOptions, ReadDocumentInput, ReadDocumentResult, ReadDocumentWarning, SVGExportOptions, WriteDocumentWarning };
187
196
  //# sourceMappingURL=types.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/io/types.ts"],"mappings":";;;;;;;;;;;KAWY;KAEA;KAEA;KAEA,eAAe;KACf;KACA,SAAS,eAAe;UAEnB;;;;;;EAMf;EACA;EACA,MAAM;;;;;EAKN,WAAW,eAAe,QAAQ;;;;;;;;EAQlC,YAAY,eAAe,QAAQ;;;KAIzB;EAEN;;;;;EAKA;;EAEA;;;EAIA;;EAEA;;;EAIA;;EAEA;;;EAIA;;EAEA;;UAGW;EACf,OAAO;EACP;;EAEA,WAAW;;UAGI;EACf;;UAGe;EACf;EACA;;UAGe;EACf;EACA;;UAGe;EACf;EACA;;KAGU,eACR,uBACA,mBACA,wBACA;UAEa;EACf,OAAO;EACP,QAAQ;EACR;;UAGe;EACf,YAAY;EACZ,WAAW;;EAEX,QAAQ;;UAGO;EACf;EACA;;EAEA;;UAGe;EACf;EACA;EACA,aAAa;EACb,QAAQ;;UAGO;EACf;EACA,aAAa;;;UAIE;EACf;EACA,SAAS;;UAGM;EACf;EACA;EACA;EACA,MAAM;EACN,WAAW;;EAEX,SAAS;;EAET;;UAGe;EACf;EACA;EACA;;EAEA;;EAEA;;EAEA;;EAEA,yBAAyB;;;UAIV;;;;;EAKf;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;;UAGe,gBAAgB;EAC/B,IAAI;EACJ;EACA,MAAM;EACN,UAAU;EACV;EACA;EACA,SAAS;EACT,gBAAgB;;;;;EAKhB;EAEA,aAAa,kBAAkB;EAE/B,cAAc,OAAO,mBAAmB,UAAU,YAAY,QAAQ;EACtE,eAAe,OAAO,YAAY,mBAAmB,UAAU,YAAY,QAAQ;EACnF,eACE,SAAS,eACT,mBACA,UAAU,YACT,QAAQ"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../../src/io/types.ts"],"mappings":";;;;;;;;;;;;;KAaY;KAEA;KAEA;KAEA,eAAe;KACf;KACA,SAAS,eAAe;UAEnB;;;;;;EAMf;EACA;EACA,MAAM;;;;;EAKN,WAAW,eAAe,QAAQ;;;;;;;;EAQlC,YAAY,eAAe,QAAQ;;;KAIzB;EAEN;;;;;EAKA;;EAEA;;;EAIA;;EAEA;;;EAIA;;EAEA;;;EAIA;;EAEA;;UAGW;EACf,OAAO;EACP;;EAEA,WAAW;;UAGI;EACf;;UAGe;EACf;EACA;;UAGe;EACf;EACA;;UAGe;EACf;EACA;;KAGU,eACR,uBACA,mBACA,wBACA;UAEa;EACf,OAAO;EACP,QAAQ;EACR;;UAGe;EACf,YAAY;EACZ,WAAW;;EAEX,QAAQ;;UAGO;EACf;EACA;;EAEA;;UAGe;EACf;EACA;EACA,aAAa;EACb,QAAQ;;UAGO;EACf;EACA,aAAa;;;UAIE;EACf;EACA,SAAS;;UAGM;EACf;EACA;EACA;EACA,MAAM;EACN,WAAW;;EAEX,SAAS;;EAET;;EAEA,iBAAiB;;;;;;KAOP,uBAAuB,kBAAkB;UAEpC;EACf;EACA;EACA;;EAEA;;EAEA;;EAEA;;EAEA,yBAAyB;;;UAIV;;;;;EAKf;;UAGe;EACf;EACA;EACA;EACA;EACA;EACA;;UAGe;EACf;EACA;EACA;;UAGe,gBAAgB;EAC/B,IAAI;EACJ;EACA,MAAM;EACN,UAAU;EACV;EACA;EACA,SAAS;EACT,gBAAgB;;;;;EAKhB;EAEA,aAAa,kBAAkB;EAE/B,cAAc,OAAO,mBAAmB,UAAU,YAAY,QAAQ;EACtE,eAAe,OAAO,YAAY,mBAAmB,UAAU,YAAY,QAAQ;EACnF,eACE,SAAS,eACT,mBACA,UAAU,YACT,QAAQ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pairdraw/core",
3
- "version": "0.21.0",
3
+ "version": "0.21.1",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
@@ -11,14 +11,14 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "dependencies": {
13
13
  "@iconify/utils": "^3.1.4",
14
- "@pairdraw/design-jsx": "^0.21.0",
15
- "@pairdraw/dom-css": "^0.21.0",
16
- "@pairdraw/drawio": "^0.21.0",
17
- "@pairdraw/fig": "^0.21.0",
18
- "@pairdraw/kiwi": "^0.21.0",
19
- "@pairdraw/mermaid": "^0.21.0",
20
- "@pairdraw/pen": "^0.21.0",
21
- "@pairdraw/scene-graph": "^0.21.0",
14
+ "@pairdraw/design-jsx": "^0.21.1",
15
+ "@pairdraw/dom-css": "^0.21.1",
16
+ "@pairdraw/drawio": "^0.21.1",
17
+ "@pairdraw/fig": "^0.21.1",
18
+ "@pairdraw/kiwi": "^0.21.1",
19
+ "@pairdraw/mermaid": "^0.21.1",
20
+ "@pairdraw/pen": "^0.21.1",
21
+ "@pairdraw/scene-graph": "^0.21.1",
22
22
  "@tauri-apps/api": "^2.12.1",
23
23
  "@valibot/to-json-schema": "^1.8.0",
24
24
  "@xmldom/xmldom": "^0.9.12",
@@ -14,6 +14,8 @@ import {
14
14
  type ShaderUniformValue
15
15
  } from '@pairdraw/scene-graph/shaders'
16
16
 
17
+ import { ResourceCache } from '#core/cache/resource'
18
+
17
19
  import { FRAME_HEIGHT_UNIFORM, OBJECT_SIZE_UNIFORM, translateShader } from './translate'
18
20
 
19
21
  /** A shader source with its compiled effect, or why it could not compile. */
@@ -24,8 +26,14 @@ export interface CompiledShader {
24
26
  error: string | null
25
27
  }
26
28
 
27
- /** One cache per CanvasKit instance, so a reload gets fresh effects. */
28
- const caches = new WeakMap<CanvasKit, Map<string, CompiledShader>>()
29
+ /** Sources compiled per CanvasKit instance; the shader library and edits share this budget. */
30
+ export const SHADER_CACHE_ENTRIES = 64
31
+
32
+ /**
33
+ * One owning cache per CanvasKit instance, so a reload gets fresh effects. Effects are native
34
+ * handles: the cache is their only owner, and disposing a slot is what frees one.
35
+ */
36
+ const caches = new WeakMap<CanvasKit, ResourceCache<string, CompiledShader>>()
29
37
 
30
38
  /** The frame values the renderer supplies instead of the document. */
31
39
  export interface ShaderFrame {
@@ -109,7 +117,10 @@ export function shaderSamplers(compiled: CompiledShader): string[] {
109
117
  export function compileShader(ck: CanvasKit, source: string): CompiledShader {
110
118
  let cache = caches.get(ck)
111
119
  if (!cache) {
112
- cache = new Map()
120
+ cache = new ResourceCache<string, CompiledShader>({
121
+ maxEntries: SHADER_CACHE_ENTRIES,
122
+ dispose: (compiled) => compiled.effect?.delete()
123
+ })
113
124
  caches.set(ck, cache)
114
125
  }
115
126
  const cached = cache.get(source)
@@ -23,8 +23,12 @@ import { sdfShader } from './sdf'
23
23
  /** When the page started drawing shaders, which is what `@time` counts from. */
24
24
  const startedAt = Date.now()
25
25
 
26
- /** The effect each paint last compiled with, by frame image, so a broken edit keeps drawing. */
27
- const lastGood = new Map<string, CompiledShader>()
26
+ /**
27
+ * The source each paint last compiled from, by frame image, so a broken edit keeps drawing. A source
28
+ * is stored rather than the compiled object: the compile cache owns the handle, and a remembered
29
+ * object could be disposed by an eviction between the edit and the draw.
30
+ */
31
+ const lastGood = new Map<string, string>()
28
32
 
29
33
  /** How many paints keep a last good effect, so a long session does not hold every one forever. */
30
34
  const KEEP_LAST_GOOD = 32
@@ -42,7 +46,7 @@ function effectFor(r: SkiaRenderer, shader: ShaderSourcePaint): CompiledShader |
42
46
  const compiled = compileShader(r.ck, shader.source)
43
47
  if (compiled.effect) {
44
48
  lastGood.delete(shader.image)
45
- lastGood.set(shader.image, compiled)
49
+ lastGood.set(shader.image, shader.source)
46
50
  while (lastGood.size > KEEP_LAST_GOOD) {
47
51
  const oldest = lastGood.keys().next().value
48
52
  if (oldest === undefined) break
@@ -50,7 +54,10 @@ function effectFor(r: SkiaRenderer, shader: ShaderSourcePaint): CompiledShader |
50
54
  }
51
55
  return compiled
52
56
  }
53
- return lastGood.get(shader.image) ?? null
57
+ const goodSource = lastGood.get(shader.image)
58
+ if (goodSource === undefined) return null
59
+ const good = compileShader(r.ck, goodSource)
60
+ return good.effect ? good : null
54
61
  }
55
62
 
56
63
  /**
@@ -23,26 +23,14 @@ const MAX_SIDE = 4096
23
23
  /** When the page started drawing shaders, which is what `@time` counts from. */
24
24
  const startedAt = Date.now()
25
25
 
26
- /** The effect each layer last compiled with, so a broken edit keeps drawing instead of blanking. */
27
- const lastGood = new Map<string, CompiledShader>()
28
-
29
- /** How many layers keep a last good effect, so a long session does not hold every one forever. */
30
- const KEEP_LAST_GOOD = 32
31
-
32
- /** The effect to draw `effect` with: its own compile, or the one it last compiled with. */
26
+ /**
27
+ * The effect to draw `effect` with. A failed compile has nothing to fall back to here: the last
28
+ * good compile of a source is that same source's entry, which `compileShader` memoizes, so its
29
+ * effect is already returned by a successful compile. The compile cache owns the handle.
30
+ */
33
31
  function effectFor(r: SkiaRenderer, effect: ShaderEffect): CompiledShader | null {
34
32
  const compiled = compileShader(r.ck, effect.source)
35
- if (compiled.effect) {
36
- lastGood.delete(effect.source)
37
- lastGood.set(effect.source, compiled)
38
- while (lastGood.size > KEEP_LAST_GOOD) {
39
- const oldest = lastGood.keys().next().value
40
- if (oldest === undefined) break
41
- lastGood.delete(oldest)
42
- }
43
- return compiled
44
- }
45
- return lastGood.get(effect.source) ?? null
33
+ return compiled.effect ? compiled : null
46
34
  }
47
35
 
48
36
  /** The device pixels one layer coordinate spans, so the snapshot draws at the canvas's own rate. */
@@ -41,14 +41,14 @@ export function createClipboardExportActions(ctx: EditorContext) {
41
41
  async function copySelectionAsHTML(ids: string[]): Promise<string | null> {
42
42
  if (ids.length === 0) return null
43
43
  const { renderNodesToHTML } = await import('#core/io/formats/html')
44
- const { html } = await renderNodesToHTML(
44
+ const { html, draws } = await renderNodesToHTML(
45
45
  ctx.graph,
46
46
  ids,
47
47
  { html: 'fragment', style: 'inline', assets: 'inline' },
48
48
  undefined,
49
49
  { canvasKit: ctx.getCk() ?? undefined, renderer: ctx.getRenderer() ?? undefined }
50
50
  )
51
- return html || null
51
+ return draws ? html || null : null
52
52
  }
53
53
 
54
54
  return { copySelectionAsText, copySelectionAsSVG, copySelectionAsJSX, copySelectionAsHTML }
@@ -5,23 +5,42 @@ function counted(count: number, one: string, many: string): string {
5
5
  return `${count} ${count === 1 ? one : many}`
6
6
  }
7
7
 
8
+ /**
9
+ * What a draw.io file could not hold, as facts rather than a sentence: the app shows these in the
10
+ * reader's language, while the CLI and MCP print `drawioWriteWarningText` of each.
11
+ */
12
+ export interface DrawioWriteWarning {
13
+ kind: 'unbound-variables'
14
+ /** Variables the graph holds, none of which draw.io can carry. */
15
+ variables: number
16
+ /** The collections those variables belong to, by name. */
17
+ collections: string[]
18
+ /** Layers painted through a binding, which open without it. */
19
+ layers: number
20
+ }
21
+
8
22
  /**
9
23
  * What a draw.io file cannot hold. draw.io has no variable model and no style that reads one, so
10
24
  * a document that paints with variables arrives in draw.io as plain colours and comes back
11
25
  * unbound. The writer names that loss instead of writing a file that looks complete.
12
26
  */
13
- export function drawioDroppedWarnings(graph: SceneGraph): string[] {
27
+ export function drawioWriteWarnings(graph: SceneGraph): DrawioWriteWarning[] {
14
28
  const variables = graph.getLiveVariables().length
15
29
  if (variables === 0) return []
16
- const names = graph.getLiveCollections().map((collection) => collection.name)
17
- const dropped = `draw.io has no variables: ${counted(variables, 'variable', 'variables')} in ${counted(names.length, 'collection', 'collections')} (${names.join(', ')}) not written`
18
- const bound = [...graph.nodes.values()].filter(
30
+ const collections = graph.getLiveCollections().map((collection) => collection.name)
31
+ const layers = [...graph.nodes.values()].filter(
19
32
  (node) => Object.keys(node.boundVariables).length > 0
20
33
  ).length
21
- if (bound === 0) return [dropped]
34
+ return [{ kind: 'unbound-variables', variables, collections, layers }]
35
+ }
36
+
37
+ /** The English sentence a write warning has always been reported as. */
38
+ export function drawioWriteWarningText(warning: DrawioWriteWarning): string {
39
+ const dropped = `draw.io has no variables: ${counted(warning.variables, 'variable', 'variables')} in ${counted(warning.collections.length, 'collection', 'collections')} (${warning.collections.join(', ')}) not written`
40
+ if (warning.layers === 0) return dropped
22
41
  const users =
23
- bound === 1
42
+ warning.layers === 1
24
43
  ? '1 layer that uses one lost the binding'
25
- : `${counted(bound, 'layer', 'layers')} that use them lost the binding`
26
- return [`${dropped}, and ${users}`]
44
+ : `${counted(warning.layers, 'layer', 'layers')} that use them lost the binding`
45
+ return `${dropped}, and ${users}`
27
46
  }
@@ -1,6 +1,7 @@
1
1
  import { filename } from 'pathe/utils'
2
2
 
3
3
  import {
4
+ designNodeDraws,
4
5
  exportHTMLBundle,
5
6
  sceneNodesToDesignDocument,
6
7
  type DesignDocument
@@ -44,8 +45,9 @@ export async function renderNodesToHTML(
44
45
  options: HTMLExportOptions = {},
45
46
  fileName?: string,
46
47
  context?: IOContext
47
- ): Promise<{ html: string; assets: ExportAsset[] }> {
48
- const bundle = await exportHTMLBundle(await designDocument(graph, nodeIds, options, context), {
48
+ ): Promise<{ html: string; assets: ExportAsset[]; draws: boolean }> {
49
+ const projected = await designDocument(graph, nodeIds, options, context)
50
+ const bundle = await exportHTMLBundle(projected, {
49
51
  html: options.html,
50
52
  style: options.style,
51
53
  assets: options.assets,
@@ -59,5 +61,9 @@ export async function renderNodesToHTML(
59
61
  })
60
62
  const page = bundle.files.find((file) => file.path === bundle.entrypoint)
61
63
  if (typeof page?.content !== 'string') throw new Error('HTML export produced no page')
62
- return { html: page.content, assets: bundle.files.filter((file) => file !== page) }
64
+ return {
65
+ html: page.content,
66
+ assets: bundle.files.filter((file) => file !== page),
67
+ draws: projected.children.some(designNodeDraws)
68
+ }
63
69
  }
@@ -9,11 +9,17 @@ import {
9
9
  withUsedImports,
10
10
  writePenDocument,
11
11
  type PenIconRequest,
12
- type PenIconSource
12
+ type PenIconSource,
13
+ type PenWriteWarning
13
14
  } from '@pairdraw/pen'
14
15
 
15
16
  import { defaultIcons, drawIcon, type IconData, type IconProvider } from '#core/icons'
16
- import type { IOFormatAdapter, ReadDocumentInput, ReadDocumentWarning } from '#core/io/types'
17
+ import type {
18
+ ExportResult,
19
+ IOFormatAdapter,
20
+ ReadDocumentInput,
21
+ ReadDocumentWarning
22
+ } from '#core/io/types'
17
23
  import { layoutAuthoredNodes } from '#core/layout'
18
24
 
19
25
  import { loadPenFonts } from './fonts'
@@ -209,14 +215,16 @@ export const penFormat: IOFormatAdapter<'pen'> = {
209
215
  },
210
216
  async writeDocument(graph) {
211
217
  const warnings: string[] = []
212
- const data = writePenDocument(graph, { warnings })
213
- return {
218
+ const warningDetails: PenWriteWarning[] = []
219
+ const data = writePenDocument(graph, { warnings, warningDetails })
220
+ const written: ExportResult = {
214
221
  format: 'pen',
215
222
  mimeType: 'application/json',
216
223
  extension: 'pen',
217
224
  data,
218
- encoding: 'utf8',
219
- ...(warnings.length > 0 ? { warnings } : {})
225
+ encoding: 'utf8'
220
226
  }
227
+ if (warningDetails.length === 0) return written
228
+ return { ...written, warnings, warningDetails }
221
229
  }
222
230
  }
package/src/io/formats.ts CHANGED
@@ -314,14 +314,20 @@ export const mermaidFormat: IOFormatAdapter<'mermaid'> = {
314
314
  async function writeDrawIO(graph: SceneGraph, target: DrawIOExportTarget): Promise<ExportResult> {
315
315
  const { writeDrawIOFile } = await import('@pairdraw/drawio')
316
316
  const { sceneGraphToDrawIO } = await import('./formats/drawio')
317
- const { drawioDroppedWarnings } = await import('./formats/drawio/warnings')
318
- return {
317
+ const { drawioWriteWarnings, drawioWriteWarningText } = await import('./formats/drawio/warnings')
318
+ const warningDetails = drawioWriteWarnings(graph)
319
+ const written: ExportResult = {
319
320
  format: 'drawio',
320
321
  mimeType: 'application/vnd.jgraph.mxfile',
321
322
  extension: 'drawio',
322
323
  data: writeDrawIOFile(sceneGraphToDrawIO(graph, target)),
323
- encoding: 'utf8',
324
- warnings: drawioDroppedWarnings(graph)
324
+ encoding: 'utf8'
325
+ }
326
+ if (warningDetails.length === 0) return written
327
+ return {
328
+ ...written,
329
+ warnings: warningDetails.map(drawioWriteWarningText),
330
+ warningDetails
325
331
  }
326
332
  }
327
333
 
package/src/io/index.ts CHANGED
@@ -35,6 +35,7 @@ export type {
35
35
  ExportRequest,
36
36
  ExportAsset,
37
37
  ExportResult,
38
+ WriteDocumentWarning,
38
39
  HTMLExportOptions,
39
40
  PDFFormatExportOptions,
40
41
  IOContext,
package/src/io/types.ts CHANGED
@@ -1,12 +1,14 @@
1
1
  import type { CanvasKit } from 'canvaskit-wasm'
2
2
 
3
3
  import type { TailwindStylesheetLoader } from '@pairdraw/dom-css/export'
4
+ import type { PenWriteWarning } from '@pairdraw/pen'
4
5
  import type { SceneGraph } from '@pairdraw/scene-graph'
5
6
  import type { RenderColorSpace } from '@pairdraw/scene-graph/color'
6
7
 
7
8
  import type { SkiaRenderer } from '#core/canvas'
8
9
  import type { IconProvider } from '#core/icons'
9
10
 
11
+ import type { DrawioWriteWarning } from './formats/drawio/warnings'
10
12
  import type { RasterExportFormat } from './formats/raster'
11
13
 
12
14
  export type IOFormatRole = 'native-document' | 'interchange-document' | 'derived-export'
@@ -154,8 +156,16 @@ export interface ExportResult {
154
156
  assets?: ExportAsset[]
155
157
  /** What the format could not hold, such as the variables draw.io has no model for. */
156
158
  warnings?: string[]
159
+ /** The same facts as kinds, for a host that shows them in its own language. */
160
+ warningDetails?: WriteDocumentWarning[]
157
161
  }
158
162
 
163
+ /**
164
+ * What a writer could not put in its file, as facts: the pen and draw.io writers name their own
165
+ * kinds, and a host translates them instead of printing the English `warnings` sentences.
166
+ */
167
+ export type WriteDocumentWarning = PenWriteWarning | DrawioWriteWarning
168
+
159
169
  export interface HTMLExportOptions {
160
170
  html?: 'fragment' | 'standalone'
161
171
  style?: 'inline' | 'tailwind'