@pairdraw/core 0.19.0 → 0.19.2
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.
- package/dist/canvas/overlays/index.d.ts +2 -2
- package/dist/canvas/overlays/index.js +2 -2
- package/dist/canvas/overlays/selection.d.ts +1 -2
- package/dist/canvas/overlays/selection.d.ts.map +1 -1
- package/dist/canvas/overlays/selection.js +2 -9
- package/dist/canvas/overlays/selection.js.map +1 -1
- package/dist/canvas/renderer/fonts.d.ts.map +1 -1
- package/dist/canvas/renderer/fonts.js +2 -0
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer/methods.d.ts +0 -1
- package/dist/canvas/renderer/methods.d.ts.map +1 -1
- package/dist/canvas/renderer/methods.js +1 -4
- package/dist/canvas/renderer/methods.js.map +1 -1
- package/dist/canvas/renderer/overlay-pass.d.ts.map +1 -1
- package/dist/canvas/renderer/overlay-pass.js +0 -1
- package/dist/canvas/renderer/overlay-pass.js.map +1 -1
- package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
- package/dist/canvas/renderer/pipeline.js +0 -1
- package/dist/canvas/renderer/pipeline.js.map +1 -1
- package/dist/canvas/renderer/types.d.ts +0 -1
- package/dist/canvas/renderer/types.d.ts.map +1 -1
- package/dist/canvas/renderer.d.ts +0 -1
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/design-jsx/index.d.ts +2 -2
- package/dist/design-jsx/index.js +2 -2
- package/dist/design-jsx/renderer.d.ts +3 -2
- package/dist/design-jsx/renderer.d.ts.map +1 -1
- package/dist/design-jsx/renderer.js +2 -2
- package/dist/design-jsx/renderer.js.map +1 -1
- package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
- package/dist/editor/clipboard/snapshot.js +12 -4
- package/dist/editor/clipboard/snapshot.js.map +1 -1
- package/dist/editor/clipboard.d.ts.map +1 -1
- package/dist/editor/clipboard.js +2 -7
- package/dist/editor/clipboard.js.map +1 -1
- package/dist/editor/color-space.d.ts.map +1 -1
- package/dist/editor/color-space.js +33 -38
- package/dist/editor/color-space.js.map +1 -1
- package/dist/editor/create.d.ts +9 -5
- package/dist/editor/create.d.ts.map +1 -1
- package/dist/editor/create.js +10 -1
- package/dist/editor/create.js.map +1 -1
- package/dist/editor/history/edit.d.ts.map +1 -1
- package/dist/editor/history/edit.js +2 -1
- package/dist/editor/history/edit.js.map +1 -1
- package/dist/editor/nudge.js +1 -1
- package/dist/editor/nudge.js.map +1 -1
- package/dist/editor/read-only/actions.js +2 -0
- package/dist/editor/read-only/actions.js.map +1 -1
- package/dist/editor/selection/container.d.ts +2 -0
- package/dist/editor/selection/container.d.ts.map +1 -1
- package/dist/editor/selection/container.js +17 -1
- package/dist/editor/selection/container.js.map +1 -1
- package/dist/editor/selection/navigation.js +7 -4
- package/dist/editor/selection/navigation.js.map +1 -1
- package/dist/editor/selection/read.d.ts +2 -2
- package/dist/editor/selection.d.ts +4 -2
- package/dist/editor/selection.d.ts.map +1 -1
- package/dist/editor/shapes/with-text.d.ts.map +1 -1
- package/dist/editor/shapes/with-text.js +2 -5
- package/dist/editor/shapes/with-text.js.map +1 -1
- package/dist/editor/structure/auto-layout-wrap.js +1 -1
- package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
- package/dist/editor/structure/boolean.d.ts +2 -3
- package/dist/editor/structure/boolean.d.ts.map +1 -1
- package/dist/editor/structure/boolean.js.map +1 -1
- package/dist/editor/structure/group/bounds.d.ts.map +1 -1
- package/dist/editor/structure/group/bounds.js +1 -3
- package/dist/editor/structure/group/bounds.js.map +1 -1
- package/dist/editor/structure/outline-stroke.js +3 -3
- package/dist/editor/structure/outline-stroke.js.map +1 -1
- package/dist/editor/structure/reorder.d.ts.map +1 -1
- package/dist/editor/structure/reorder.js +7 -14
- package/dist/editor/structure/reorder.js.map +1 -1
- package/dist/editor/structure/state.js +1 -1
- package/dist/editor/structure/state.js.map +1 -1
- package/dist/editor/structure.d.ts +1 -2
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/structure.js +3 -3
- package/dist/editor/structure.js.map +1 -1
- package/dist/editor/types.d.ts +4 -1
- package/dist/editor/types.d.ts.map +1 -1
- package/dist/editor/variables.d.ts.map +1 -1
- package/dist/editor/variables.js +57 -1
- package/dist/editor/variables.js.map +1 -1
- package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
- package/dist/figma-api/accessors/text/index.js +4 -1
- package/dist/figma-api/accessors/text/index.js.map +1 -1
- package/dist/figma-api/fonts/loaded.d.ts +3 -1
- package/dist/figma-api/fonts/loaded.d.ts.map +1 -1
- package/dist/figma-api/fonts/loaded.js +8 -1
- package/dist/figma-api/fonts/loaded.js.map +1 -1
- package/dist/figma-api/index.d.ts +13 -0
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +13 -0
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/serialization.d.ts.map +1 -1
- package/dist/figma-api/serialization.js +2 -1
- package/dist/figma-api/serialization.js.map +1 -1
- package/dist/figma-api/shape-details.d.ts +26 -0
- package/dist/figma-api/shape-details.d.ts.map +1 -0
- package/dist/figma-api/shape-details.js +28 -0
- package/dist/figma-api/shape-details.js.map +1 -0
- package/dist/figma-api/shape-with-text.js +2 -5
- package/dist/figma-api/shape-with-text.js.map +1 -1
- package/dist/figma-api/surface.d.ts +1 -1
- package/dist/figma-api/surface.d.ts.map +1 -1
- package/dist/figma-api/surface.js +1 -0
- package/dist/figma-api/surface.js.map +1 -1
- package/dist/icons/svg.js +1 -1
- package/dist/icons/svg.js.map +1 -1
- package/dist/io/formats/design-tokens/apply.d.ts +1 -1
- package/dist/io/formats/drawio/index.d.ts.map +1 -1
- package/dist/io/formats/drawio/index.js +1 -1
- package/dist/io/formats/drawio/index.js.map +1 -1
- package/dist/io/formats/html/layers.d.ts +7 -4
- package/dist/io/formats/html/layers.d.ts.map +1 -1
- package/dist/io/formats/html/layers.js +4 -1
- package/dist/io/formats/html/layers.js.map +1 -1
- package/dist/io/formats/pdf/dom.d.ts +6 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +9 -22
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/export.js +1 -1
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/svg/defs.d.ts.map +1 -1
- package/dist/io/formats/svg/defs.js +3 -1
- package/dist/io/formats/svg/defs.js.map +1 -1
- package/dist/io/formats/svg/export.d.ts.map +1 -1
- package/dist/io/formats/svg/export.js +52 -16
- package/dist/io/formats/svg/export.js.map +1 -1
- package/dist/layout/apply.d.ts.map +1 -1
- package/dist/layout/apply.js +50 -12
- package/dist/layout/apply.js.map +1 -1
- package/dist/layout/derived.d.ts +7 -1
- package/dist/layout/derived.d.ts.map +1 -1
- package/dist/layout/derived.js +11 -1
- package/dist/layout/derived.js.map +1 -1
- package/dist/layout/grid.d.ts +7 -2
- package/dist/layout/grid.d.ts.map +1 -1
- package/dist/layout/grid.js +27 -9
- package/dist/layout/grid.js.map +1 -1
- package/dist/layout/mutations.d.ts +1 -0
- package/dist/layout/mutations.d.ts.map +1 -1
- package/dist/layout/mutations.js +10 -0
- package/dist/layout/mutations.js.map +1 -1
- package/dist/layout/strokes.d.ts +9 -1
- package/dist/layout/strokes.d.ts.map +1 -1
- package/dist/layout/strokes.js +12 -1
- package/dist/layout/strokes.js.map +1 -1
- package/dist/layout/yoga-helpers.d.ts +3 -1
- package/dist/layout/yoga-helpers.d.ts.map +1 -1
- package/dist/layout/yoga-helpers.js +16 -2
- package/dist/layout/yoga-helpers.js.map +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js +71 -38
- package/dist/layout.js.map +1 -1
- package/dist/lint/linter.d.ts +1 -0
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +13 -1
- package/dist/lint/linter.js.map +1 -1
- package/dist/lint/rules/effect-style-required.js +1 -0
- package/dist/lint/rules/effect-style-required.js.map +1 -1
- package/dist/lint/rules/text-style-required.js +1 -0
- package/dist/lint/rules/text-style-required.js.map +1 -1
- package/dist/lint/types.d.ts +7 -0
- package/dist/lint/types.d.ts.map +1 -1
- package/dist/rpc/commands.d.ts +2 -2
- package/dist/rpc/index.d.ts +2 -2
- package/dist/rpc/read-commands.d.ts +18 -8
- package/dist/rpc/read-commands.d.ts.map +1 -1
- package/dist/rpc/read-commands.js +18 -9
- package/dist/rpc/read-commands.js.map +1 -1
- package/dist/text/font/faces.d.ts +12 -1
- package/dist/text/font/faces.d.ts.map +1 -1
- package/dist/text/font/faces.js +15 -1
- package/dist/text/font/faces.js.map +1 -1
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +6 -11
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +2 -2
- package/dist/tools/modify/layout.d.ts.map +1 -1
- package/dist/tools/modify/layout.js +1 -0
- package/dist/tools/modify/layout.js.map +1 -1
- package/dist/tools/read/nodes.d.ts.map +1 -1
- package/dist/tools/read/nodes.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +14 -0
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/vector/path.d.ts.map +1 -1
- package/dist/tools/vector/path.js +39 -7
- package/dist/tools/vector/path.js.map +1 -1
- package/dist/xpath.d.ts +3 -0
- package/dist/xpath.d.ts.map +1 -1
- package/dist/xpath.js +3 -1
- package/dist/xpath.js.map +1 -1
- package/package.json +9 -9
- package/src/canvas/overlays/index.ts +0 -1
- package/src/canvas/overlays/selection.ts +1 -12
- package/src/canvas/renderer/fonts.ts +2 -0
- package/src/canvas/renderer/methods.ts +0 -9
- package/src/canvas/renderer/overlay-pass.ts +0 -1
- package/src/canvas/renderer/pipeline.ts +0 -1
- package/src/canvas/renderer/types.ts +0 -1
- package/src/canvas/renderer.ts +0 -1
- package/src/design-jsx/index.ts +1 -1
- package/src/design-jsx/renderer.ts +1 -1
- package/src/editor/clipboard/snapshot.ts +21 -4
- package/src/editor/clipboard.ts +4 -14
- package/src/editor/color-space.ts +47 -38
- package/src/editor/create.ts +14 -2
- package/src/editor/history/edit.ts +5 -1
- package/src/editor/nudge.ts +1 -1
- package/src/editor/read-only/actions.ts +2 -0
- package/src/editor/selection/container.ts +24 -1
- package/src/editor/selection/navigation.ts +8 -6
- package/src/editor/shapes/with-text.ts +2 -5
- package/src/editor/structure/auto-layout-wrap.ts +1 -1
- package/src/editor/structure/boolean.ts +1 -3
- package/src/editor/structure/group/bounds.ts +1 -5
- package/src/editor/structure/outline-stroke.ts +3 -3
- package/src/editor/structure/reorder.ts +8 -14
- package/src/editor/structure/state.ts +1 -1
- package/src/editor/structure.ts +5 -8
- package/src/editor/types.ts +4 -1
- package/src/editor/variables.ts +74 -2
- package/src/figma-api/accessors/text/index.ts +10 -1
- package/src/figma-api/fonts/loaded.ts +9 -0
- package/src/figma-api/index.ts +25 -0
- package/src/figma-api/serialization.ts +2 -1
- package/src/figma-api/shape-details.ts +50 -0
- package/src/figma-api/shape-with-text.ts +2 -5
- package/src/figma-api/surface.ts +1 -0
- package/src/global.d.ts +5 -0
- package/src/icons/svg.ts +3 -1
- package/src/io/formats/drawio/index.ts +3 -1
- package/src/io/formats/html/layers.ts +11 -2
- package/src/io/formats/pdf/dom.ts +10 -18
- package/src/io/formats/pdf/export.ts +1 -1
- package/src/io/formats/svg/defs.ts +10 -1
- package/src/io/formats/svg/export.ts +94 -19
- package/src/layout/apply.ts +87 -21
- package/src/layout/derived.ts +14 -0
- package/src/layout/grid.ts +33 -9
- package/src/layout/mutations.ts +13 -1
- package/src/layout/strokes.ts +12 -0
- package/src/layout/yoga-helpers.ts +18 -1
- package/src/layout.ts +94 -49
- package/src/lint/linter.ts +17 -2
- package/src/lint/rules/effect-style-required.ts +2 -0
- package/src/lint/rules/text-style-required.ts +2 -0
- package/src/lint/types.ts +8 -0
- package/src/rpc/index.ts +1 -0
- package/src/rpc/read-commands.ts +40 -23
- package/src/text/font/faces.ts +22 -0
- package/src/text/font/manager.ts +9 -11
- package/src/tools/modify/layout.ts +5 -0
- package/src/tools/read/nodes.ts +0 -1
- package/src/tools/structure/batch.ts +22 -0
- package/src/tools/vector/path.ts +30 -6
- package/src/xpath.ts +6 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/pdf/export.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { computeContentBounds } from '#core/io/formats/raster'\nimport { renderNodesToSVG, type SVGExportOptions, type SVGTextLayout } from '#core/io/formats/svg'\n\nimport { loadSVG2PDF, withPDFDOM, type SVGPageParser } from './dom'\nimport {\n cutFontInstances,\n embeddedFontAlias,\n planFontEmbedding,\n registerEmbeddedFonts,\n type PDFFallbackFontFile,\n type PDFFontFace,\n type PDFFontReport\n} from './fonts'\nimport type { PDFPageSpec } from './plan'\n\nexport interface PDFExportOptions {\n title?: string\n /** The faces the text uses, to embed their files; without them text uses standard PDF fonts. */\n fonts?: readonly PDFFontFace[]\n /** Line breaks of text nodes as the editor laid them out, so paragraphs stay wrapped. */\n textLayout?: SVGTextLayout\n /** The files of fallback faces the text layout draws characters in, to embed them too. */\n fallbackFile?: PDFFallbackFontFile\n}\n\nexport interface PDFExportResult {\n data: Uint8Array\n /** The pages written, in order. Pages with nothing visible are skipped. */\n pages: Array<{ label?: string; width: number; height: number }>\n /** Embedded and fallback faces, when `fonts` was given. */\n fonts?: PDFFontReport\n}\n\ninterface PreparedPage {\n spec: PDFPageSpec\n svgElement: Element\n width: number\n height: number\n}\n\ntype PageSVGOptions = Pick<SVGExportOptions, 'textLayout' | 'fontAlias'>\n\nfunction preparePage(\n graph: SceneGraph,\n spec: PDFPageSpec,\n svgOptions: PageSVGOptions,\n parse: SVGPageParser\n): PreparedPage | null {\n const svg = renderNodesToSVG(graph, spec.pageId, spec.nodeIds, {\n xmlDeclaration: false,\n ...svgOptions\n })\n if (!svg) return null\n\n const bounds = computeContentBounds(graph, spec.nodeIds)\n if (!bounds) return null\n\n const width = bounds.maxX - bounds.minX\n const height = bounds.maxY - bounds.minY\n if (width <= 0 || height <= 0) return null\n\n const svgElement = parse(svg)\n return svgElement ? { spec, svgElement, width, height } : null\n}\n\nconst orientationOf = (page: PreparedPage) => (page.width > page.height ? 'landscape' : 'portrait')\n\n/**\n * A PDF with one page per spec, each sized to its content. Null when no page has anything visible.\n */\nexport function renderPagesToPDFDetailed(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFExportOptions = {}\n): Promise<PDFExportResult | null> {\n return withPDFDOM((parse) => renderPages(graph, specs, options, parse))\n}\n\nasync function renderPages(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFExportOptions,\n parse: SVGPageParser\n): Promise<PDFExportResult | null> {\n const embedding = options.fonts ? planFontEmbedding(options.fonts, options.fallbackFile) : null\n const svgOptions: PageSVGOptions = {\n textLayout: options.textLayout,\n fontAlias: embedding ? embeddedFontAlias(embedding) : undefined\n }\n const preparePages = () =>\n specs\n .map((spec) => preparePage(graph, spec, svgOptions, parse))\n .filter((page): page is PreparedPage => page !== null)\n let prepared = preparePages()\n if (prepared.length === 0) return null\n const first = prepared[0]\n\n const { jsPDF } = await import('jspdf')\n const svg2pdf = await loadSVG2PDF(
|
|
1
|
+
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/pdf/export.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\n\nimport { computeContentBounds } from '#core/io/formats/raster'\nimport { renderNodesToSVG, type SVGExportOptions, type SVGTextLayout } from '#core/io/formats/svg'\n\nimport { loadSVG2PDF, withPDFDOM, type SVGPageParser } from './dom'\nimport {\n cutFontInstances,\n embeddedFontAlias,\n planFontEmbedding,\n registerEmbeddedFonts,\n type PDFFallbackFontFile,\n type PDFFontFace,\n type PDFFontReport\n} from './fonts'\nimport type { PDFPageSpec } from './plan'\n\nexport interface PDFExportOptions {\n title?: string\n /** The faces the text uses, to embed their files; without them text uses standard PDF fonts. */\n fonts?: readonly PDFFontFace[]\n /** Line breaks of text nodes as the editor laid them out, so paragraphs stay wrapped. */\n textLayout?: SVGTextLayout\n /** The files of fallback faces the text layout draws characters in, to embed them too. */\n fallbackFile?: PDFFallbackFontFile\n}\n\nexport interface PDFExportResult {\n data: Uint8Array\n /** The pages written, in order. Pages with nothing visible are skipped. */\n pages: Array<{ label?: string; width: number; height: number }>\n /** Embedded and fallback faces, when `fonts` was given. */\n fonts?: PDFFontReport\n}\n\ninterface PreparedPage {\n spec: PDFPageSpec\n svgElement: Element\n width: number\n height: number\n}\n\ntype PageSVGOptions = Pick<SVGExportOptions, 'textLayout' | 'fontAlias'>\n\nfunction preparePage(\n graph: SceneGraph,\n spec: PDFPageSpec,\n svgOptions: PageSVGOptions,\n parse: SVGPageParser\n): PreparedPage | null {\n const svg = renderNodesToSVG(graph, spec.pageId, spec.nodeIds, {\n xmlDeclaration: false,\n ...svgOptions\n })\n if (!svg) return null\n\n const bounds = computeContentBounds(graph, spec.nodeIds)\n if (!bounds) return null\n\n const width = bounds.maxX - bounds.minX\n const height = bounds.maxY - bounds.minY\n if (width <= 0 || height <= 0) return null\n\n const svgElement = parse(svg)\n return svgElement ? { spec, svgElement, width, height } : null\n}\n\nconst orientationOf = (page: PreparedPage) => (page.width > page.height ? 'landscape' : 'portrait')\n\n/**\n * A PDF with one page per spec, each sized to its content. Null when no page has anything visible.\n */\nexport function renderPagesToPDFDetailed(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFExportOptions = {}\n): Promise<PDFExportResult | null> {\n return withPDFDOM((parse) => renderPages(graph, specs, options, parse))\n}\n\nasync function renderPages(\n graph: SceneGraph,\n specs: readonly PDFPageSpec[],\n options: PDFExportOptions,\n parse: SVGPageParser\n): Promise<PDFExportResult | null> {\n const embedding = options.fonts ? planFontEmbedding(options.fonts, options.fallbackFile) : null\n const svgOptions: PageSVGOptions = {\n textLayout: options.textLayout,\n fontAlias: embedding ? embeddedFontAlias(embedding) : undefined\n }\n const preparePages = () =>\n specs\n .map((spec) => preparePage(graph, spec, svgOptions, parse))\n .filter((page): page is PreparedPage => page !== null)\n let prepared = preparePages()\n if (prepared.length === 0) return null\n const first = prepared[0]\n\n const { jsPDF } = await import('jspdf')\n const svg2pdf = await loadSVG2PDF()\n\n const doc = new jsPDF({\n orientation: orientationOf(first),\n unit: 'pt',\n format: [first.width, first.height],\n compress: true\n })\n\n if (options.title) {\n doc.setProperties({ title: options.title })\n }\n\n // The pages name the variable instances they draw, which are cut now. jsPDF reads a font file\n // when it is registered, so a face it refuses is only known then. Either way, the pages are\n // written again without the names of faces that are not embedded.\n if (embedding) {\n const cut = await cutFontInstances(embedding)\n if (!registerEmbeddedFonts(doc, embedding) || !cut) prepared = preparePages()\n }\n\n for (const [index, page] of prepared.entries()) {\n if (index > 0) doc.addPage([page.width, page.height], orientationOf(page))\n await svg2pdf(page.svgElement, doc, { x: 0, y: 0, width: page.width, height: page.height })\n }\n\n return {\n data: new Uint8Array(doc.output('arraybuffer')),\n pages: prepared.map((page) => ({\n label: page.spec.label,\n width: page.width,\n height: page.height\n })),\n ...(embedding ? { fonts: embedding.report } : {})\n }\n}\n"],"mappings":";;;;;AA4CA,SAAS,YACP,OACA,MACA,YACA,OACqB;CACrB,MAAM,MAAM,iBAAiB,OAAO,KAAK,QAAQ,KAAK,SAAS;EAC7D,gBAAgB;EAChB,GAAG;CACL,CAAC;CACD,IAAI,CAAC,KAAK,OAAO;CAEjB,MAAM,SAAS,qBAAqB,OAAO,KAAK,OAAO;CACvD,IAAI,CAAC,QAAQ,OAAO;CAEpB,MAAM,QAAQ,OAAO,OAAO,OAAO;CACnC,MAAM,SAAS,OAAO,OAAO,OAAO;CACpC,IAAI,SAAS,KAAK,UAAU,GAAG,OAAO;CAEtC,MAAM,aAAa,MAAM,GAAG;CAC5B,OAAO,aAAa;EAAE;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AO,KAAK;GAAO,QAAQ,KAAK;EAAO,CAAC;CAC5F;CAEA,OAAO;EACL,MAAM,IAAI,WAAW,IAAI,OAAO,aAAa,CAAC;EAC9C,OAAO,SAAS,KAAK,UAAU;GAC7B,OAAO,KAAK,KAAK;GACjB,OAAO,KAAK;GACZ,QAAQ,KAAK;EACf,EAAE;EACF,GAAI,YAAY,EAAE,OAAO,UAAU,OAAO,IAAI,CAAC;CACjD;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.d.ts","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"mappings":";;;;;;;;;;;UAkCiB,uBAAuB;;EAEtC;EACA;EACA,qBAAqB;EACrB;;;KAIU,gBAAgB,MAAM;UAEjB;EACf,MAAM;EACN;EACA,OAAO;EACP,YAAY;;EAEZ;;EAEA,QAAQ,MAAM;;EAEd,aAAa;EACb,YAAY;;iBAGE,UAAU,KAAK,kBAAkB;iBAIjC,YACd,OAAO,OACP,kBACA,aAAY;;;;;;iBAeE,iBACd,OAAO,OACP,iBACA,YAAY;;;;;;iBAaE,iBACd,MAAM,MACN,YAAY,kBACZ;
|
|
1
|
+
{"version":3,"file":"defs.d.ts","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"mappings":";;;;;;;;;;;UAkCiB,uBAAuB;;EAEtC;EACA;EACA,qBAAqB;EACrB;;;KAIU,gBAAgB,MAAM;UAEjB;EACf,MAAM;EACN;EACA,OAAO;EACP,YAAY;;EAEZ;;EAEA,QAAQ,MAAM;;EAEd,aAAa;EACb,YAAY;;iBAGE,UAAU,KAAK,kBAAkB;iBAIjC,YACd,OAAO,OACP,kBACA,aAAY;;;;;;iBAeE,iBACd,OAAO,OACP,iBACA,YAAY;;;;;;iBAaE,iBACd,MAAM,MACN,YAAY,kBACZ;iBAyHc,gBACd,SAAS,UACT,KAAK;EACF;EAAY,MAAM;;iBA6DP,YAAY,MAAM,MAAM,MAAM,WAAW,KAAK;cAqCjD,gBAAgB;cAMhB,iBAAiB;cAMjB,gBAAgB"}
|
|
@@ -114,7 +114,8 @@ function createImagePattern(fill, node, ctx) {
|
|
|
114
114
|
id,
|
|
115
115
|
patternUnits: "objectBoundingBox",
|
|
116
116
|
width: 1,
|
|
117
|
-
height: 1
|
|
117
|
+
height: 1,
|
|
118
|
+
patternTransform: fill.imageRotation ? `rotate(${round(fill.imageRotation)} 0.5 0.5)` : void 0
|
|
118
119
|
}, svg("image", {
|
|
119
120
|
href: `data:${mime};base64,${base64}`,
|
|
120
121
|
width: node.width,
|
|
@@ -179,6 +180,7 @@ function resolveFill(fill, node, ctx) {
|
|
|
179
180
|
if (!fill.visible) return null;
|
|
180
181
|
if (fill.type === "SOLID") return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace);
|
|
181
182
|
if (fill.type === "MESH") return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace);
|
|
183
|
+
if (fill.type === "PATTERN" || fill.type === "NOISE" || fill.type === "CUSTOM") return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace);
|
|
182
184
|
if (fill.type.startsWith("GRADIENT")) {
|
|
183
185
|
const grad = createGradientDef(fill, node, ctx);
|
|
184
186
|
if (grad) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defs.js","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"sourcesContent":["import { fromUint8Array } from 'js-base64'\n\nimport type {\n Effect,\n Fill,\n FontVariation,\n SceneGraph,\n SceneNode,\n ShadowEffect\n} from '@pairdraw/scene-graph'\nimport {\n colorToHex,\n colorToDisplayCSS,\n getDefaultRenderColorSpace,\n type RenderColorSpace\n} from '@pairdraw/scene-graph/color'\nimport {\n gradientPoint,\n invertGradientTransform,\n isIdentityGradientTransform\n} from '@pairdraw/scene-graph/gradient'\nimport { imageMimeType } from '@pairdraw/scene-graph/images'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { FontFaceRef } from '#core/text/font/faces'\n\nimport { svg, type SVGNode } from './node'\nimport { round } from './paths'\nimport type { SVGTextLayout } from './text/lines'\n\n/**\n * A face text is drawn in, with what sets its axes: the font size the optical size follows unless\n * `opticalSizeFromFontSize` is off, and the axes the text sets.\n */\nexport interface SVGFontRequest extends FontFaceRef {\n /** Which of the style's files draws the text, 0 for its own then its shards; 0 when left out. */\n file?: number\n fontSize: number\n variations: readonly FontVariation[]\n opticalSizeFromFontSize: boolean\n}\n\n/** The family to name a font face by instead of its own, or null to keep the face. */\nexport type SVGFontAlias = (font: SVGFontRequest) => string | null\n\nexport interface SVGExportContext {\n defs: SVGNode[]\n defIdCounter: number\n graph: SceneGraph\n colorSpace: RenderColorSpace\n /** Starts every def id, so SVGs inlined on one page cannot reference each other's defs. */\n idPrefix?: string\n /** Paints drawn in `currentColor`, such as an icon's tinted paths, so CSS `color` sets them. */\n tint?: (node: SceneNode) => readonly ('fill' | 'stroke')[]\n /** Measured line breaks. Without them, only explicit newlines start a new baseline. */\n textLayout?: SVGTextLayout\n fontAlias?: SVGFontAlias\n}\n\nexport function nextDefId(ctx: SVGExportContext, prefix: string): string {\n return `${ctx.idPrefix ?? ''}${prefix}${ctx.defIdCounter++}`\n}\n\nexport function formatColor(\n color: Color,\n opacity = 1,\n colorSpace: RenderColorSpace = getDefaultRenderColorSpace()\n): string {\n const alphaColor = { ...color, a: color.a * opacity }\n if (colorSpace === 'display-p3') {\n return colorToDisplayCSS(alphaColor, { colorSpace })\n }\n // Hex has no alpha. Stops and shadows already emit theirs; solid fills use `solidFillOpacity`.\n return colorToHex(alphaColor)\n}\n\n/**\n * A solid paint's SVG color. The canvas paints `opacity` and drops color alpha: `setAlphaf`\n * replaces it, and `.pen` stores a hex alpha in both fields. Display P3 carries that painted\n * alpha in the color. sRGB hex cannot, so `solidFillOpacity` emits it beside the color.\n */\nexport function formatSolidColor(\n color: Color,\n opacity: number,\n colorSpace: RenderColorSpace\n): string {\n if (colorSpace === 'display-p3') {\n return formatColor({ ...color, a: 1 }, round(opacity), colorSpace)\n }\n return formatColor(color, 1, colorSpace)\n}\n\n/**\n * `fill-opacity` for a solid paint. Omitted at full opacity so an opaque export stays unchanged.\n * Display P3 already carries the same alpha in the color `formatSolidColor` returns, unless\n * `separate` is set because that color was replaced and can no longer carry it.\n */\nexport function solidFillOpacity(\n fill: Fill,\n colorSpace: RenderColorSpace,\n separate = false\n): number | undefined {\n if (fill.type !== 'SOLID' || (colorSpace === 'display-p3' && !separate)) return undefined\n const alpha = round(fill.opacity)\n return alpha < 1 ? alpha : undefined\n}\n\nfunction createGradientDef(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n const stops = fill.gradientStops\n const t = fill.gradientTransform\n if (!stops || !t) return null\n\n const stopNodes = stops.map((s) =>\n svg('stop', {\n offset: `${round(s.position * 100)}%`,\n 'stop-color': formatColor(s.color, 1, ctx.colorSpace),\n 'stop-opacity': s.color.a < 1 ? round(s.color.a) : undefined\n })\n )\n\n const id = nextDefId(ctx, 'grad')\n\n // Gradient space in bounding-box units, mapped onto the layer as the canvas draws it.\n const toLayer = invertGradientTransform(t)\n const transform = isIdentityGradientTransform(toLayer)\n ? undefined\n : `matrix(${[toLayer.m00, toLayer.m10, toLayer.m01, toLayer.m11, toLayer.m02, toLayer.m12].map((v) => round(v, 6)).join(' ')})`\n\n if (fill.type === 'GRADIENT_LINEAR') {\n return {\n id,\n node: svg(\n 'linearGradient',\n {\n id,\n x1: 0,\n y1: 0.5,\n x2: 1,\n y2: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // SVG has no diamond gradient, so a diamond exports as the radial one it is closest to.\n if (fill.type === 'GRADIENT_RADIAL' || fill.type === 'GRADIENT_DIAMOND') {\n return {\n id,\n node: svg(\n 'radialGradient',\n {\n id,\n cx: 0.5,\n cy: 0.5,\n r: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // Nor an angular one: it exports as a radial gradient around its centre.\n if (fill.type === 'GRADIENT_ANGULAR') {\n const center = gradientPoint(t, { x: 0.5, y: 0.5 })\n const cx = round(center.x * node.width)\n const cy = round(center.y * node.height)\n const r = Math.max(node.width, node.height)\n return {\n id,\n node: svg('radialGradient', { id, cx, cy, r, gradientUnits: 'userSpaceOnUse' }, ...stopNodes)\n }\n }\n\n return null\n}\n\nfunction createImagePattern(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n if (!fill.imageHash) return null\n const data = ctx.graph.images.get(fill.imageHash)\n if (!data) return null\n\n const id = nextDefId(ctx, 'img')\n const base64 = fromUint8Array(data)\n const mime = imageMimeType(data)\n\n return {\n id,\n node: svg(\n 'pattern',\n {\n id,\n patternUnits: 'objectBoundingBox',\n width: 1,\n height: 1\n },\n svg('image', {\n href: `data:${mime};base64,${base64}`,\n width: node.width,\n height: node.height,\n preserveAspectRatio: fill.imageScaleMode === 'FIT' ? 'xMidYMid meet' : 'xMidYMid slice'\n })\n )\n }\n}\n\nexport function createFilterDef(\n effects: Effect[],\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n // SVG has no shader effect; a shader is a raster the format cannot carry.\n const visible = effects.filter((e): e is ShadowEffect => e.visible && e.type !== 'SHADER')\n if (visible.length === 0) return null\n\n const id = nextDefId(ctx, 'fx')\n const primitives: SVGNode[] = []\n\n for (const effect of visible) {\n if (effect.type === 'DROP_SHADOW') {\n const stdDev = round(effect.radius / 2)\n primitives.push(\n svg('feDropShadow', {\n dx: round(effect.offset.x),\n dy: round(effect.offset.y),\n stdDeviation: stdDev,\n 'flood-color': formatColor(effect.color, 1, ctx.colorSpace),\n 'flood-opacity': round(effect.color.a)\n })\n )\n } else if (effect.type === 'INNER_SHADOW') {\n const sid = `${id}_is`\n const stdDev = round(effect.radius / 2)\n primitives.push(\n svg('feGaussianBlur', { in: 'SourceAlpha', stdDeviation: stdDev, result: `${sid}_blur` }),\n svg('feOffset', {\n dx: round(effect.offset.x),\n dy: round(effect.offset.y),\n result: `${sid}_off`\n }),\n svg('feComposite', {\n in: 'SourceAlpha',\n in2: `${sid}_off`,\n operator: 'out',\n result: `${sid}_inv`\n }),\n svg('feFlood', {\n 'flood-color': formatColor(effect.color, 1, ctx.colorSpace),\n 'flood-opacity': round(effect.color.a)\n }),\n svg('feComposite', { in2: `${sid}_inv`, operator: 'in', result: `${sid}_shadow` }),\n svg('feComposite', {\n in: `${sid}_shadow`,\n in2: 'SourceGraphic',\n operator: 'over'\n })\n )\n } else {\n const stdDev = round(effect.radius / 2)\n primitives.push(svg('feGaussianBlur', { stdDeviation: stdDev }))\n }\n }\n\n if (primitives.length === 0) return null\n\n return {\n id,\n node: svg('filter', { id }, ...primitives)\n }\n}\n\nexport function resolveFill(fill: Fill, node: SceneNode, ctx: SVGExportContext): string | null {\n if (!fill.visible) return null\n\n if (fill.type === 'SOLID') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n // SVG has no mesh element: a mesh exports its own color, as `.fig` records carry it.\n if (fill.type === 'MESH') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n if (fill.type.startsWith('GRADIENT')) {\n const grad = createGradientDef(fill, node, ctx)\n if (grad) {\n ctx.defs.push(grad.node)\n return `url(#${grad.id})`\n }\n }\n\n if (fill.type === 'IMAGE') {\n const pattern = createImagePattern(fill, node, ctx)\n if (pattern) {\n ctx.defs.push(pattern.node)\n return `url(#${pattern.id})`\n }\n }\n\n return null\n}\n\nexport const SVG_STROKE_CAP: Record<string, string> = {\n NONE: 'butt',\n ROUND: 'round',\n SQUARE: 'square'\n}\n\nexport const SVG_STROKE_JOIN: Record<string, string> = {\n MITER: 'miter',\n ROUND: 'round',\n BEVEL: 'bevel'\n}\n\nexport const SVG_BLEND_MODE: Record<string, string> = {\n NORMAL: 'normal',\n DARKEN: 'darken',\n MULTIPLY: 'multiply',\n COLOR_BURN: 'color-burn',\n LIGHTEN: 'lighten',\n LINEAR_BURN: 'plus-darker',\n SCREEN: 'screen',\n LINEAR_DODGE: 'plus-lighter',\n COLOR_DODGE: 'color-dodge',\n OVERLAY: 'overlay',\n SOFT_LIGHT: 'soft-light',\n HARD_LIGHT: 'hard-light',\n DIFFERENCE: 'difference',\n EXCLUSION: 'exclusion',\n HUE: 'hue',\n SATURATION: 'saturation',\n COLOR: 'color',\n LUMINOSITY: 'luminosity'\n}\n"],"mappings":";;;;;;;AA2DA,SAAgB,UAAU,KAAuB,QAAwB;CACvE,OAAO,GAAG,IAAI,YAAY,KAAK,SAAS,IAAI;AAC9C;AAEA,SAAgB,YACd,OACA,UAAU,GACV,aAA+B,2BAA2B,GAClD;CACR,MAAM,aAAa;EAAE,GAAG;EAAO,GAAG,MAAM,IAAI;CAAQ;CACpD,IAAI,eAAe,cACjB,OAAO,kBAAkB,YAAY,EAAE,WAAW,CAAC;CAGrD,OAAO,WAAW,UAAU;AAC9B;;;;;;AAOA,SAAgB,iBACd,OACA,SACA,YACQ;CACR,IAAI,eAAe,cACjB,OAAO,YAAY;EAAE,GAAG;EAAO,GAAG;CAAE,GAAG,MAAM,OAAO,GAAG,UAAU;CAEnE,OAAO,YAAY,OAAO,GAAG,UAAU;AACzC;;;;;;AAOA,SAAgB,iBACd,MACA,YACA,WAAW,OACS;CACpB,IAAI,KAAK,SAAS,WAAY,eAAe,gBAAgB,CAAC,UAAW,OAAO,KAAA;CAChF,MAAM,QAAQ,MAAM,KAAK,OAAO;CAChC,OAAO,QAAQ,IAAI,QAAQ,KAAA;AAC7B;AAEA,SAAS,kBACP,MACA,MACA,KACsC;CACtC,MAAM,QAAQ,KAAK;CACnB,MAAM,IAAI,KAAK;CACf,IAAI,CAAC,SAAS,CAAC,GAAG,OAAO;CAEzB,MAAM,YAAY,MAAM,KAAK,MAC3B,IAAI,QAAQ;EACV,QAAQ,GAAG,MAAM,EAAE,WAAW,GAAG,EAAE;EACnC,cAAc,YAAY,EAAE,OAAO,GAAG,IAAI,UAAU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A,MAAa,iBAAyC;CACpD,MAAM;CACN,OAAO;CACP,QAAQ;AACV;AAEA,MAAa,kBAA0C;CACrD,OAAO;CACP,OAAO;CACP,OAAO;AACT;AAEA,MAAa,iBAAyC;CACpD,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,SAAS;CACT,aAAa;CACb,QAAQ;CACR,cAAc;CACd,aAAa;CACb,SAAS;CACT,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,WAAW;CACX,KAAK;CACL,YAAY;CACZ,OAAO;CACP,YAAY;AACd"}
|
|
1
|
+
{"version":3,"file":"defs.js","names":[],"sources":["../../../../src/io/formats/svg/defs.ts"],"sourcesContent":["import { fromUint8Array } from 'js-base64'\n\nimport type {\n Effect,\n Fill,\n FontVariation,\n SceneGraph,\n SceneNode,\n ShadowEffect\n} from '@pairdraw/scene-graph'\nimport {\n colorToHex,\n colorToDisplayCSS,\n getDefaultRenderColorSpace,\n type RenderColorSpace\n} from '@pairdraw/scene-graph/color'\nimport {\n gradientPoint,\n invertGradientTransform,\n isIdentityGradientTransform\n} from '@pairdraw/scene-graph/gradient'\nimport { imageMimeType } from '@pairdraw/scene-graph/images'\nimport type { Color } from '@pairdraw/scene-graph/primitives'\n\nimport type { FontFaceRef } from '#core/text/font/faces'\n\nimport { svg, type SVGNode } from './node'\nimport { round } from './paths'\nimport type { SVGTextLayout } from './text/lines'\n\n/**\n * A face text is drawn in, with what sets its axes: the font size the optical size follows unless\n * `opticalSizeFromFontSize` is off, and the axes the text sets.\n */\nexport interface SVGFontRequest extends FontFaceRef {\n /** Which of the style's files draws the text, 0 for its own then its shards; 0 when left out. */\n file?: number\n fontSize: number\n variations: readonly FontVariation[]\n opticalSizeFromFontSize: boolean\n}\n\n/** The family to name a font face by instead of its own, or null to keep the face. */\nexport type SVGFontAlias = (font: SVGFontRequest) => string | null\n\nexport interface SVGExportContext {\n defs: SVGNode[]\n defIdCounter: number\n graph: SceneGraph\n colorSpace: RenderColorSpace\n /** Starts every def id, so SVGs inlined on one page cannot reference each other's defs. */\n idPrefix?: string\n /** Paints drawn in `currentColor`, such as an icon's tinted paths, so CSS `color` sets them. */\n tint?: (node: SceneNode) => readonly ('fill' | 'stroke')[]\n /** Measured line breaks. Without them, only explicit newlines start a new baseline. */\n textLayout?: SVGTextLayout\n fontAlias?: SVGFontAlias\n}\n\nexport function nextDefId(ctx: SVGExportContext, prefix: string): string {\n return `${ctx.idPrefix ?? ''}${prefix}${ctx.defIdCounter++}`\n}\n\nexport function formatColor(\n color: Color,\n opacity = 1,\n colorSpace: RenderColorSpace = getDefaultRenderColorSpace()\n): string {\n const alphaColor = { ...color, a: color.a * opacity }\n if (colorSpace === 'display-p3') {\n return colorToDisplayCSS(alphaColor, { colorSpace })\n }\n // Hex has no alpha. Stops and shadows already emit theirs; solid fills use `solidFillOpacity`.\n return colorToHex(alphaColor)\n}\n\n/**\n * A solid paint's SVG color. The canvas paints `opacity` and drops color alpha: `setAlphaf`\n * replaces it, and `.pen` stores a hex alpha in both fields. Display P3 carries that painted\n * alpha in the color. sRGB hex cannot, so `solidFillOpacity` emits it beside the color.\n */\nexport function formatSolidColor(\n color: Color,\n opacity: number,\n colorSpace: RenderColorSpace\n): string {\n if (colorSpace === 'display-p3') {\n return formatColor({ ...color, a: 1 }, round(opacity), colorSpace)\n }\n return formatColor(color, 1, colorSpace)\n}\n\n/**\n * `fill-opacity` for a solid paint. Omitted at full opacity so an opaque export stays unchanged.\n * Display P3 already carries the same alpha in the color `formatSolidColor` returns, unless\n * `separate` is set because that color was replaced and can no longer carry it.\n */\nexport function solidFillOpacity(\n fill: Fill,\n colorSpace: RenderColorSpace,\n separate = false\n): number | undefined {\n if (fill.type !== 'SOLID' || (colorSpace === 'display-p3' && !separate)) return undefined\n const alpha = round(fill.opacity)\n return alpha < 1 ? alpha : undefined\n}\n\nfunction createGradientDef(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n const stops = fill.gradientStops\n const t = fill.gradientTransform\n if (!stops || !t) return null\n\n const stopNodes = stops.map((s) =>\n svg('stop', {\n offset: `${round(s.position * 100)}%`,\n 'stop-color': formatColor(s.color, 1, ctx.colorSpace),\n 'stop-opacity': s.color.a < 1 ? round(s.color.a) : undefined\n })\n )\n\n const id = nextDefId(ctx, 'grad')\n\n // Gradient space in bounding-box units, mapped onto the layer as the canvas draws it.\n const toLayer = invertGradientTransform(t)\n const transform = isIdentityGradientTransform(toLayer)\n ? undefined\n : `matrix(${[toLayer.m00, toLayer.m10, toLayer.m01, toLayer.m11, toLayer.m02, toLayer.m12].map((v) => round(v, 6)).join(' ')})`\n\n if (fill.type === 'GRADIENT_LINEAR') {\n return {\n id,\n node: svg(\n 'linearGradient',\n {\n id,\n x1: 0,\n y1: 0.5,\n x2: 1,\n y2: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // SVG has no diamond gradient, so a diamond exports as the radial one it is closest to.\n if (fill.type === 'GRADIENT_RADIAL' || fill.type === 'GRADIENT_DIAMOND') {\n return {\n id,\n node: svg(\n 'radialGradient',\n {\n id,\n cx: 0.5,\n cy: 0.5,\n r: 0.5,\n gradientUnits: 'objectBoundingBox',\n gradientTransform: transform\n },\n ...stopNodes\n )\n }\n }\n\n // Nor an angular one: it exports as a radial gradient around its centre.\n if (fill.type === 'GRADIENT_ANGULAR') {\n const center = gradientPoint(t, { x: 0.5, y: 0.5 })\n const cx = round(center.x * node.width)\n const cy = round(center.y * node.height)\n const r = Math.max(node.width, node.height)\n return {\n id,\n node: svg('radialGradient', { id, cx, cy, r, gradientUnits: 'userSpaceOnUse' }, ...stopNodes)\n }\n }\n\n return null\n}\n\nfunction createImagePattern(\n fill: Fill,\n node: SceneNode,\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n if (!fill.imageHash) return null\n const data = ctx.graph.images.get(fill.imageHash)\n if (!data) return null\n\n const id = nextDefId(ctx, 'img')\n const base64 = fromUint8Array(data)\n const mime = imageMimeType(data)\n\n return {\n id,\n node: svg(\n 'pattern',\n {\n id,\n patternUnits: 'objectBoundingBox',\n width: 1,\n height: 1,\n patternTransform: fill.imageRotation\n ? `rotate(${round(fill.imageRotation)} 0.5 0.5)`\n : undefined\n },\n svg('image', {\n href: `data:${mime};base64,${base64}`,\n width: node.width,\n height: node.height,\n preserveAspectRatio: fill.imageScaleMode === 'FIT' ? 'xMidYMid meet' : 'xMidYMid slice'\n })\n )\n }\n}\n\nexport function createFilterDef(\n effects: Effect[],\n ctx: SVGExportContext\n): { id: string; node: SVGNode } | null {\n // SVG has no shader effect; a shader is a raster the format cannot carry.\n const visible = effects.filter((e): e is ShadowEffect => e.visible && e.type !== 'SHADER')\n if (visible.length === 0) return null\n\n const id = nextDefId(ctx, 'fx')\n const primitives: SVGNode[] = []\n\n for (const effect of visible) {\n if (effect.type === 'DROP_SHADOW') {\n const stdDev = round(effect.radius / 2)\n primitives.push(\n svg('feDropShadow', {\n dx: round(effect.offset.x),\n dy: round(effect.offset.y),\n stdDeviation: stdDev,\n 'flood-color': formatColor(effect.color, 1, ctx.colorSpace),\n 'flood-opacity': round(effect.color.a)\n })\n )\n } else if (effect.type === 'INNER_SHADOW') {\n const sid = `${id}_is`\n const stdDev = round(effect.radius / 2)\n primitives.push(\n svg('feGaussianBlur', { in: 'SourceAlpha', stdDeviation: stdDev, result: `${sid}_blur` }),\n svg('feOffset', {\n dx: round(effect.offset.x),\n dy: round(effect.offset.y),\n result: `${sid}_off`\n }),\n svg('feComposite', {\n in: 'SourceAlpha',\n in2: `${sid}_off`,\n operator: 'out',\n result: `${sid}_inv`\n }),\n svg('feFlood', {\n 'flood-color': formatColor(effect.color, 1, ctx.colorSpace),\n 'flood-opacity': round(effect.color.a)\n }),\n svg('feComposite', { in2: `${sid}_inv`, operator: 'in', result: `${sid}_shadow` }),\n svg('feComposite', {\n in: `${sid}_shadow`,\n in2: 'SourceGraphic',\n operator: 'over'\n })\n )\n } else {\n const stdDev = round(effect.radius / 2)\n primitives.push(svg('feGaussianBlur', { stdDeviation: stdDev }))\n }\n }\n\n if (primitives.length === 0) return null\n\n return {\n id,\n node: svg('filter', { id }, ...primitives)\n }\n}\n\nexport function resolveFill(fill: Fill, node: SceneNode, ctx: SVGExportContext): string | null {\n if (!fill.visible) return null\n\n if (fill.type === 'SOLID') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n // SVG has no mesh element: a mesh exports its own color, as `.fig` records carry it.\n if (fill.type === 'MESH') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n // The canvas draws a pattern, noise or custom paint as its own colour when the format has no\n // element for it, so the export must not drop the layer.\n if (fill.type === 'PATTERN' || fill.type === 'NOISE' || fill.type === 'CUSTOM') {\n return formatSolidColor(fill.color, fill.opacity, ctx.colorSpace)\n }\n\n if (fill.type.startsWith('GRADIENT')) {\n const grad = createGradientDef(fill, node, ctx)\n if (grad) {\n ctx.defs.push(grad.node)\n return `url(#${grad.id})`\n }\n }\n\n if (fill.type === 'IMAGE') {\n const pattern = createImagePattern(fill, node, ctx)\n if (pattern) {\n ctx.defs.push(pattern.node)\n return `url(#${pattern.id})`\n }\n }\n\n return null\n}\n\nexport const SVG_STROKE_CAP: Record<string, string> = {\n NONE: 'butt',\n ROUND: 'round',\n SQUARE: 'square'\n}\n\nexport const SVG_STROKE_JOIN: Record<string, string> = {\n MITER: 'miter',\n ROUND: 'round',\n BEVEL: 'bevel'\n}\n\nexport const SVG_BLEND_MODE: Record<string, string> = {\n NORMAL: 'normal',\n DARKEN: 'darken',\n MULTIPLY: 'multiply',\n COLOR_BURN: 'color-burn',\n LIGHTEN: 'lighten',\n LINEAR_BURN: 'plus-darker',\n SCREEN: 'screen',\n LINEAR_DODGE: 'plus-lighter',\n COLOR_DODGE: 'color-dodge',\n OVERLAY: 'overlay',\n SOFT_LIGHT: 'soft-light',\n HARD_LIGHT: 'hard-light',\n DIFFERENCE: 'difference',\n EXCL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AAEA,MAAa,iBAAyC;CACpD,MAAM;CACN,OAAO;CACP,QAAQ;AACV;AAEA,MAAa,kBAA0C;CACrD,OAAO;CACP,OAAO;CACP,OAAO;AACT;AAEA,MAAa,iBAAyC;CACpD,QAAQ;CACR,QAAQ;CACR,UAAU;CACV,YAAY;CACZ,SAAS;CACT,aAAa;CACb,QAAQ;CACR,cAAc;CACd,aAAa;CACb,SAAS;CACT,YAAY;CACZ,YAAY;CACZ,YAAY;CACZ,WAAW;CACX,KAAK;CACL,YAAY;CACZ,OAAO;CACP,YAAY;AACd"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","names":[],"sources":["../../../../src/io/formats/svg/export.ts"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"export.d.ts","names":[],"sources":["../../../../src/io/formats/svg/export.ts"],"mappings":";;;;;;;UAyiBiB;;EAEf;;EAEA;;;;;EAKA,aAAa;;;;;EAKb,YAAY;;iBAGE,iBACd,OAAO,YACP,iBACA,mBACA,UAAS;;;;;;iBAiEK,qBACd,OAAO,YACP,MAAM,aAEJ,UACA,YACA,QACC,KAAK;EAA8B;EAAkB,aAAa;IACpE"}
|
|
@@ -22,6 +22,32 @@ function networkElements(node, network, common) {
|
|
|
22
22
|
if (looseSegments(network).length === 0) return regions;
|
|
23
23
|
return [...regions, ...openPathElements(node, network, common, looseSegments)];
|
|
24
24
|
}
|
|
25
|
+
/** Paints one path's fill stack; a blended fill draws its stroke as a separate path. */
|
|
26
|
+
function vectorFillElements(attrs, visibleFills, strokeAttrs, common, node, ctx) {
|
|
27
|
+
const elements = [];
|
|
28
|
+
for (const [index, fill] of visibleFills.entries()) {
|
|
29
|
+
const fillAttr = resolveFill(fill, node, ctx);
|
|
30
|
+
if (!fillAttr) continue;
|
|
31
|
+
const style = paintBlendStyle(fill);
|
|
32
|
+
const last = index === visibleFills.length - 1;
|
|
33
|
+
const splitStroke = style !== void 0 && last && common.stroke !== "none";
|
|
34
|
+
const stroke = last && !splitStroke ? common.stroke : "none";
|
|
35
|
+
elements.push(svg("path", {
|
|
36
|
+
...attrs,
|
|
37
|
+
fill: fillAttr,
|
|
38
|
+
"fill-opacity": solidFillOpacity(fill, ctx.colorSpace),
|
|
39
|
+
style,
|
|
40
|
+
stroke
|
|
41
|
+
}));
|
|
42
|
+
if (splitStroke) elements.push(svg("path", {
|
|
43
|
+
d: attrs.d,
|
|
44
|
+
"fill-rule": attrs["fill-rule"],
|
|
45
|
+
fill: "none",
|
|
46
|
+
...strokeAttrs
|
|
47
|
+
}));
|
|
48
|
+
}
|
|
49
|
+
return elements;
|
|
50
|
+
}
|
|
25
51
|
function vectorShapeElements(node, common, strokeAttrs, ctx, fallbackFills) {
|
|
26
52
|
const elements = [];
|
|
27
53
|
if (node.fillGeometry.length > 0) for (const geo of node.fillGeometry) {
|
|
@@ -45,16 +71,7 @@ function vectorShapeElements(node, common, strokeAttrs, ctx, fallbackFills) {
|
|
|
45
71
|
}));
|
|
46
72
|
continue;
|
|
47
73
|
}
|
|
48
|
-
|
|
49
|
-
const fillAttr = resolveFill(fill, node, ctx);
|
|
50
|
-
if (!fillAttr) continue;
|
|
51
|
-
elements.push(svg("path", {
|
|
52
|
-
...attrs,
|
|
53
|
-
fill: fillAttr,
|
|
54
|
-
"fill-opacity": solidFillOpacity(fill, ctx.colorSpace),
|
|
55
|
-
stroke: index === visibleFills.length - 1 ? common.stroke : "none"
|
|
56
|
-
}));
|
|
57
|
-
}
|
|
74
|
+
elements.push(...vectorFillElements(attrs, visibleFills, strokeAttrs, common, node, ctx));
|
|
58
75
|
}
|
|
59
76
|
else if (node.vectorNetwork) elements.push(...networkElements(node, node.vectorNetwork, common));
|
|
60
77
|
if (node.strokeGeometry.length > 0 && strokeAttrs.stroke && strokeAttrs.stroke !== "none") for (const geo of node.strokeGeometry) {
|
|
@@ -197,12 +214,12 @@ function buildGroupAttrs(node, ctx) {
|
|
|
197
214
|
clipId
|
|
198
215
|
};
|
|
199
216
|
}
|
|
200
|
-
function buildSVGStrokeAttrs(visibleStrokes,
|
|
217
|
+
function buildSVGStrokeAttrs(visibleStrokes, node, ctx) {
|
|
201
218
|
if (visibleStrokes.length === 0) return {};
|
|
202
219
|
const stroke = visibleStrokes[0];
|
|
203
|
-
const cap = stroke.cap ??
|
|
220
|
+
const cap = stroke.cap ?? node.strokeCap;
|
|
204
221
|
const attrs = {
|
|
205
|
-
stroke: formatSolidColor(stroke.color, 1, colorSpace),
|
|
222
|
+
stroke: stroke.type === "SOLID" ? formatSolidColor(stroke.color, 1, ctx.colorSpace) : resolveFill(stroke, node, ctx) ?? formatSolidColor(stroke.color, 1, ctx.colorSpace),
|
|
206
223
|
"stroke-width": round(stroke.weight)
|
|
207
224
|
};
|
|
208
225
|
if (stroke.opacity < 1) attrs["stroke-opacity"] = round(stroke.opacity);
|
|
@@ -211,6 +228,25 @@ function buildSVGStrokeAttrs(visibleStrokes, colorSpace, nodeCap) {
|
|
|
211
228
|
if (stroke.dashPattern && stroke.dashPattern.length > 0) attrs["stroke-dasharray"] = stroke.dashPattern.map((n) => round(n)).join(" ");
|
|
212
229
|
return attrs;
|
|
213
230
|
}
|
|
231
|
+
/** The blend CSS a paint adds, when the canvas would not composite it source-over. */
|
|
232
|
+
function paintBlendStyle(fill) {
|
|
233
|
+
const blend = fill?.blendMode ? SVG_BLEND_MODE[fill.blendMode] : void 0;
|
|
234
|
+
return blend && blend !== "normal" ? `mix-blend-mode: ${blend}` : void 0;
|
|
235
|
+
}
|
|
236
|
+
/** Adds a paint's blend mode to the elements that draw it. */
|
|
237
|
+
function withPaintBlend(elements, fill) {
|
|
238
|
+
const style = paintBlendStyle(fill);
|
|
239
|
+
if (style) for (const element of elements) element.attrs.style = style;
|
|
240
|
+
return elements;
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* Draws the fill and the stroke as separate elements when the fill blends, so the stroke keeps the
|
|
244
|
+
* source-over canvas gives it instead of inheriting the fill's blend mode.
|
|
245
|
+
*/
|
|
246
|
+
function shapeWithPaint(node, fillAttr, fillOpacity, strokeAttrs, fill, ctx) {
|
|
247
|
+
if (!(paintBlendStyle(fill) !== void 0) || !strokeAttrs.stroke) return withPaintBlend(nodeShapeElements(node, fillAttr, fillOpacity, strokeAttrs, ctx), fill);
|
|
248
|
+
return [...withPaintBlend(nodeShapeElements(node, fillAttr, fillOpacity, {}, ctx), fill), ...nodeShapeElements(node, null, void 0, strokeAttrs, ctx)];
|
|
249
|
+
}
|
|
214
250
|
function hasPathLevelFills(node) {
|
|
215
251
|
return node.type === "VECTOR" && node.fillGeometry.some((geometry) => geometry.fills?.length);
|
|
216
252
|
}
|
|
@@ -233,11 +269,11 @@ function fillAndStrokeElements(node, visibleFills, fillAttr, fillOpacity, stroke
|
|
|
233
269
|
const elements = [];
|
|
234
270
|
for (const fill of visibleFills) {
|
|
235
271
|
const ref = resolveFill(fill, node, ctx);
|
|
236
|
-
if (ref) elements.push(...
|
|
272
|
+
if (ref) elements.push(...shapeWithPaint(node, ref, solidFillOpacity(fill, ctx.colorSpace), fill === visibleFills[visibleFills.length - 1] ? strokeAttrs : {}, fill, ctx));
|
|
237
273
|
}
|
|
238
274
|
return elements;
|
|
239
275
|
}
|
|
240
|
-
if ((fillAttr || visibleStrokeCount > 0) && !isGroupLike(node)) return
|
|
276
|
+
if ((fillAttr || visibleStrokeCount > 0) && !isGroupLike(node)) return shapeWithPaint(node, fillAttr, fillOpacity, strokeAttrs, visibleFills.length === 1 ? visibleFills[0] : void 0, ctx);
|
|
241
277
|
return [];
|
|
242
278
|
}
|
|
243
279
|
/** The paint CSS `color` sets, for a tinted icon path. */
|
|
@@ -268,7 +304,7 @@ function renderNode(node, ctx) {
|
|
|
268
304
|
const tintedFill = fill.color !== null && tint.includes("fill");
|
|
269
305
|
const fillAttr = tintedFill ? CURRENT_COLOR : fill.color;
|
|
270
306
|
const fillOpacity = ownFill ? solidFillOpacity(ownFill, ctx.colorSpace, tintedFill) : fill.opacity;
|
|
271
|
-
const ownStrokes = buildSVGStrokeAttrs(visibleStrokes,
|
|
307
|
+
const ownStrokes = buildSVGStrokeAttrs(visibleStrokes, node, ctx);
|
|
272
308
|
const children = buildShapeChildren(node, visibleFills, fillAttr, fillOpacity, ownStrokes.stroke && tint.includes("stroke") ? {
|
|
273
309
|
...ownStrokes,
|
|
274
310
|
stroke: CURRENT_COLOR
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/svg/export.ts"],"sourcesContent":["import type { RenderColorSpace } from '@pairdraw/scene-graph/color'\n\nimport { normalizeDashPattern } from '#core/canvas/strokes'\nimport { lineStrokePath } from '#core/canvas/strokes/line'\nimport { fittedDashPattern } from '#core/canvas/strokes/sides'\nimport { computeContentBounds } from '#core/io/formats/raster'\n\nimport {\n nextDefId,\n formatSolidColor,\n createFilterDef,\n resolveFill,\n solidFillOpacity,\n SVG_STROKE_CAP,\n SVG_STROKE_JOIN,\n SVG_BLEND_MODE\n} from './defs'\nimport {\n round,\n geometryBlobToSVGPath,\n makePolygonPoints,\n roundedPolygonPath,\n hasRadius,\n hasSmoothCorners,\n boxOutlinePath,\n arcPath,\n shapeWithTextOutlinePath\n} from './paths'\n\nexport { geometryBlobToSVGPath, nodeOutlinePath, type OutlineNode } from './paths'\n\nimport type { SceneGraph, SceneNode, Fill, Stroke, VectorNetwork } from '@pairdraw/scene-graph'\nimport { looseSegments, regionSVGPaths } from '@pairdraw/scene-graph/vector-network'\n\nimport { arrowHeadElements, openPathElements, vectorArrowHeads } from './arrows'\nimport type { SVGExportContext, SVGFontAlias } from './defs'\nimport { svg, renderSVGNode } from './node'\nimport type { SVGNode } from './node'\nimport { alignedStroke, alignedStrokeElement, shapeWithTextDetailElements } from './strokes'\nimport { renderTextNode } from './text/export'\nimport type { SVGTextLayout } from './text/lines'\n\n// --- Node rendering ---\n\n/**\n * A vector network's paths: its regions as they are traced, and its open segments as the canvas\n * strokes them, rounded and pulled back under their heads.\n */\nfunction networkElements(\n node: SceneNode,\n network: VectorNetwork,\n common: Record<string, string | number | undefined>\n): SVGNode[] {\n const regions = regionSVGPaths(network).map((d) => svg('path', { d, ...common }))\n if (looseSegments(network).length === 0) return regions\n return [...regions, ...openPathElements(node, network, common, looseSegments)]\n}\n\nfunction vectorShapeElements(\n node: SceneNode,\n common: Record<string, string | number | undefined>,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext,\n fallbackFills?: Fill[]\n): SVGNode[] {\n const elements: SVGNode[] = []\n if (node.fillGeometry.length > 0) {\n for (const geo of node.fillGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (!d) continue\n const attrs = {\n d,\n 'fill-rule': geo.windingRule === 'EVENODD' ? 'evenodd' : undefined,\n ...common\n }\n const pathFills = geo.fills?.length ? geo.fills : fallbackFills\n if (!pathFills) {\n elements.push(svg('path', attrs))\n continue\n }\n const visibleFills = pathFills.filter((fill) => fill.visible)\n if (visibleFills.length === 0) {\n elements.push(svg('path', { ...attrs, fill: 'none' }))\n continue\n }\n for (const [index, fill] of visibleFills.entries()) {\n const fillAttr = resolveFill(fill, node, ctx)\n if (!fillAttr) continue\n elements.push(\n svg('path', {\n ...attrs,\n fill: fillAttr,\n 'fill-opacity': solidFillOpacity(fill, ctx.colorSpace),\n stroke: index === visibleFills.length - 1 ? common.stroke : 'none'\n })\n )\n }\n }\n } else if (node.vectorNetwork) {\n elements.push(...networkElements(node, node.vectorNetwork, common))\n }\n if (node.strokeGeometry.length > 0 && strokeAttrs.stroke && strokeAttrs.stroke !== 'none') {\n for (const geo of node.strokeGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (d) {\n elements.push(\n svg('path', {\n d,\n fill: strokeAttrs.stroke,\n 'fill-opacity': strokeAttrs['stroke-opacity'],\n stroke: 'none'\n })\n )\n }\n }\n }\n if (node.vectorNetwork) elements.push(...vectorArrowHeads(node, node.vectorNetwork, strokeAttrs))\n return elements.length > 0\n ? elements\n : [svg('rect', { width: round(node.width), height: round(node.height), ...common })]\n}\n\n/** A line's dashes stretched along it as the canvas lays them, half a dash at each end. */\nfunction lineDashAttrs(stroke: Stroke | undefined, length: number) {\n const fitted = fittedDashPattern(length, normalizeDashPattern(stroke?.dashPattern))\n if (!fitted) return {}\n return {\n 'stroke-dasharray': fitted.intervals.map((size) => round(size)).join(' '),\n 'stroke-dashoffset': round(fitted.offset)\n }\n}\n\nfunction nodeShapeElements(\n node: SceneNode,\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext\n): SVGNode[] {\n const common: Record<string, string | number | undefined> = {\n fill: fillAttr ?? 'none',\n 'fill-opacity': fillOpacity,\n ...strokeAttrs\n }\n\n switch (node.type) {\n case 'ELLIPSE': {\n if (node.arcData) {\n return [svg('path', { d: arcPath(node), ...common })]\n }\n return [\n svg('ellipse', {\n cx: round(node.width / 2),\n cy: round(node.height / 2),\n rx: round(node.width / 2),\n ry: round(node.height / 2),\n ...common\n })\n ]\n }\n\n case 'LINE': {\n // Where the canvas strokes it: to one side of the line, with its caps inside its length.\n const stroke = node.strokes.find((item) => item.visible)\n const {\n network,\n from: start,\n to: end\n } = lineStrokePath(node, stroke?.weight ?? 0, stroke?.cap ?? node.strokeCap)\n return [\n svg('line', {\n x1: round(start.x),\n y1: round(start.y),\n x2: round(end.x),\n y2: round(end.y),\n fill: 'none',\n ...strokeAttrs,\n ...lineDashAttrs(stroke, Math.hypot(end.x - start.x, end.y - start.y))\n }),\n ...arrowHeadElements(node, network, stroke, strokeAttrs)\n ]\n }\n\n case 'STAR':\n case 'POLYGON':\n return node.cornerRadius > 0\n ? [svg('path', { d: roundedPolygonPath(node), ...common })]\n : [svg('polygon', { points: makePolygonPoints(node), ...common })]\n\n case 'VECTOR':\n return vectorShapeElements(node, common, strokeAttrs, ctx)\n\n case 'SHAPE_WITH_TEXT':\n return shapeWithTextElements(node, common, strokeAttrs, ctx)\n\n default:\n return [boxOutlineElement(node, common)]\n }\n}\n\n/**\n * A box layer's outline as one element: a rect, a rect with `rx`/`ry` for one radius, or the\n * shared box path for independent or smoothed corners, so fills and clips follow the same edge.\n */\nfunction boxOutlineElement(\n node: SceneNode,\n attrs: Record<string, string | number | undefined>\n): SVGNode {\n const width = round(node.width)\n const height = round(node.height)\n if (!hasRadius(node)) return svg('rect', { width, height, ...attrs })\n if (node.independentCorners || hasSmoothCorners(node)) {\n return svg('path', { d: boxOutlinePath(node), ...attrs })\n }\n // SVG clamps rx and ry to their own sides; the canvas keeps a too-large radius circular.\n const radius = round(Math.min(node.cornerRadius, node.width / 2, node.height / 2))\n return svg('rect', { width, height, rx: radius, ry: radius, ...attrs })\n}\n\n/**\n * A FigJam shape's outline, and its inner lines, such as a database's front rim, stroked as the\n * canvas strokes them: at the stroke's own weight, ending where the outline does.\n */\nfunction shapeWithTextElements(\n node: SceneNode,\n common: Record<string, string | number | undefined>,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext\n): SVGNode[] {\n return [\n svg('path', { d: shapeWithTextOutlinePath(node), ...common }),\n ...shapeWithTextDetailElements(node, strokeAttrs, ctx)\n ]\n}\n\n// --- Main recursive renderer ---\n\nfunction buildTransformAttr(node: SceneNode): string | undefined {\n const transforms: string[] = []\n if (node.x !== 0 || node.y !== 0) transforms.push(`translate(${round(node.x)}, ${round(node.y)})`)\n if (node.rotation !== 0) {\n transforms.push(\n `rotate(${round(node.rotation)}, ${round(node.width / 2)}, ${round(node.height / 2)})`\n )\n }\n if (node.flipX || node.flipY) {\n const tx = node.flipX ? node.width : 0\n const ty = node.flipY ? node.height : 0\n const sx = node.flipX ? -1 : 1\n const sy = node.flipY ? -1 : 1\n transforms.push(`translate(${round(tx)}, ${round(ty)}) scale(${sx}, ${sy})`)\n }\n return transforms.length > 0 ? transforms.join(' ') : undefined\n}\n\nfunction buildGroupAttrs(\n node: SceneNode,\n ctx: SVGExportContext\n): { attrs: Record<string, string | number | undefined>; clipId?: string } {\n const attrs: Record<string, string | number | undefined> = {}\n\n const transform = buildTransformAttr(node)\n if (transform) attrs.transform = transform\n\n if (node.opacity < 1) attrs.opacity = round(node.opacity)\n\n const blend = SVG_BLEND_MODE[node.blendMode]\n if (blend && blend !== 'normal' && node.blendMode !== 'PASS_THROUGH') {\n attrs.style = `mix-blend-mode: ${blend}`\n }\n\n const filterDef = createFilterDef(node.effects, ctx)\n if (filterDef) {\n ctx.defs.push(filterDef.node)\n attrs.filter = `url(#${filterDef.id})`\n }\n\n let clipId: string | undefined\n if (node.clipsContent && node.childIds.length > 0) {\n clipId = nextDefId(ctx, 'clip')\n ctx.defs.push(svg('clipPath', { id: clipId }, boxOutlineElement(node, {})))\n }\n\n return { attrs, clipId }\n}\n\nfunction buildSVGStrokeAttrs(\n visibleStrokes: Stroke[],\n colorSpace: 'srgb' | 'display-p3',\n nodeCap: SceneNode['strokeCap']\n): Record<string, string | number | undefined> {\n if (visibleStrokes.length === 0) return {}\n const stroke = visibleStrokes[0]\n const cap = stroke.cap ?? nodeCap\n const attrs: Record<string, string | number | undefined> = {\n // Opacity 1 keeps the color opaque. Display P3 must not also keep color alpha here, or a\n // viewer multiplies it by stroke-opacity; the canvas paints stroke.opacity alone.\n stroke: formatSolidColor(stroke.color, 1, colorSpace),\n 'stroke-width': round(stroke.weight)\n }\n if (stroke.opacity < 1) attrs['stroke-opacity'] = round(stroke.opacity)\n if (cap !== 'NONE') attrs['stroke-linecap'] = SVG_STROKE_CAP[cap] ?? 'butt'\n if (stroke.join && stroke.join !== 'MITER') {\n attrs['stroke-linejoin'] = SVG_STROKE_JOIN[stroke.join] ?? 'miter'\n }\n if (stroke.dashPattern && stroke.dashPattern.length > 0) {\n attrs['stroke-dasharray'] = stroke.dashPattern.map((n) => round(n)).join(' ')\n }\n return attrs\n}\n\nfunction hasPathLevelFills(node: SceneNode): boolean {\n return node.type === 'VECTOR' && node.fillGeometry.some((geometry) => geometry.fills?.length)\n}\n\nfunction buildShapeChildren(\n node: SceneNode,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n visibleStrokes: Stroke[],\n ctx: SVGExportContext\n): SVGNode[] {\n const aligned = hasPathLevelFills(node) ? null : alignedStroke(node, visibleStrokes[0])\n if (!aligned) {\n return fillAndStrokeElements(\n node,\n visibleFills,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleStrokes.length,\n ctx\n )\n }\n // The fill goes as it is, and the stroke over it inside or outside the outline.\n return [\n ...fillAndStrokeElements(node, visibleFills, fillAttr, fillOpacity, {}, 0, ctx),\n ...alignedStrokeElement(node, aligned, strokeAttrs, ctx),\n ...(node.type === 'SHAPE_WITH_TEXT' ? shapeWithTextDetailElements(node, strokeAttrs, ctx) : [])\n ]\n}\n\nfunction fillAndStrokeElements(\n node: SceneNode,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n visibleStrokeCount: number,\n ctx: SVGExportContext\n): SVGNode[] {\n if (hasPathLevelFills(node)) {\n return vectorShapeElements(\n node,\n { fill: fillAttr ?? 'none', 'fill-opacity': fillOpacity, ...strokeAttrs },\n strokeAttrs,\n ctx,\n visibleFills\n )\n }\n\n if (visibleFills.length > 1) {\n const elements: SVGNode[] = []\n for (const fill of visibleFills) {\n const ref = resolveFill(fill, node, ctx)\n if (ref) {\n elements.push(\n ...nodeShapeElements(\n node,\n ref,\n solidFillOpacity(fill, ctx.colorSpace),\n fill === visibleFills[visibleFills.length - 1] ? strokeAttrs : {},\n ctx\n )\n )\n }\n }\n return elements\n }\n\n const hasFillOrStroke = fillAttr || visibleStrokeCount > 0\n if (hasFillOrStroke && !isGroupLike(node)) {\n return nodeShapeElements(node, fillAttr, fillOpacity, strokeAttrs, ctx)\n }\n\n return []\n}\n\n/** The paint CSS `color` sets, for a tinted icon path. */\nconst CURRENT_COLOR = 'currentColor'\n\n/** A paint's SVG color and, for an sRGB solid, the `fill-opacity` beside it. */\nfunction exportedFill(\n fill: Fill | undefined,\n node: SceneNode,\n ctx: SVGExportContext\n): { color: string | null; opacity: number | undefined } {\n if (!fill) return { color: null, opacity: undefined }\n return {\n color: resolveFill(fill, node, ctx),\n opacity: solidFillOpacity(fill, ctx.colorSpace)\n }\n}\n\nfunction renderNode(node: SceneNode, ctx: SVGExportContext): SVGNode | null {\n if (!node.visible) return null\n\n const { attrs: groupAttrs, clipId } = buildGroupAttrs(node, ctx)\n\n if (node.type === 'TEXT') {\n const fill = exportedFill(\n node.fills.find((f) => f.visible),\n node,\n ctx\n )\n return svg('g', groupAttrs, renderTextNode(node, fill.color, ctx, fill.opacity))\n }\n\n const visibleFills = node.fills.filter((f) => f.visible)\n const visibleStrokes = node.strokes.filter((s) => s.visible)\n const tint = ctx.tint?.(node) ?? []\n const ownFill = visibleFills.length > 0 && !hasPathLevelFills(node) ? visibleFills[0] : undefined\n const fill = exportedFill(ownFill, node, ctx)\n const tintedFill = fill.color !== null && tint.includes('fill')\n const fillAttr = tintedFill ? CURRENT_COLOR : fill.color\n // `currentColor` has no alpha. Display P3 normally bakes solid opacity into the color, which a\n // tint throws away, so a tinted solid keeps `fill-opacity` in every color space.\n const fillOpacity = ownFill ? solidFillOpacity(ownFill, ctx.colorSpace, tintedFill) : fill.opacity\n const ownStrokes = buildSVGStrokeAttrs(visibleStrokes, ctx.colorSpace, node.strokeCap)\n const strokeAttrs =\n ownStrokes.stroke && tint.includes('stroke')\n ? { ...ownStrokes, stroke: CURRENT_COLOR }\n : ownStrokes\n\n const children: (SVGNode | null)[] = buildShapeChildren(\n node,\n visibleFills,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleStrokes,\n ctx\n )\n\n const childNodes = ctx.graph.getChildren(node.id)\n const childContent: SVGNode[] = []\n for (const child of childNodes) {\n const rendered = renderNode(child, ctx)\n if (rendered) childContent.push(rendered)\n }\n\n if (clipId && childContent.length > 0) {\n children.push(svg('g', { 'clip-path': `url(#${clipId})` }, ...childContent))\n } else {\n children.push(...childContent)\n }\n\n const validChildren = children.filter((c): c is SVGNode => c !== null)\n\n if (validChildren.length === 0 && Object.keys(groupAttrs).length === 0) {\n return null\n }\n\n if (validChildren.length === 1 && Object.keys(groupAttrs).length === 0) {\n return validChildren[0]\n }\n\n return svg('g', groupAttrs, ...validChildren)\n}\n\nfunction isGroupLike(node: SceneNode): boolean {\n return node.type === 'GROUP'\n}\n\n// --- Public API ---\n\nexport interface SVGExportOptions {\n /** Include XML declaration (default: true) */\n xmlDeclaration?: boolean\n /** Target export color space (default: srgb) */\n colorSpace?: 'srgb' | 'display-p3'\n /**\n * Line breaks of text nodes as the editor laid them out, wraps included. Without them, only\n * explicit newlines start a new baseline, which renderers that do not wrap SVG text keep.\n */\n textLayout?: SVGTextLayout\n /**\n * A family to name a font face by instead of its own, such as the one a PDF embeds the face's\n * file under. Text in an aliased face is written in that family at normal weight and style.\n */\n fontAlias?: SVGFontAlias\n}\n\nexport function renderNodesToSVG(\n graph: SceneGraph,\n _pageId: string,\n nodeIds: string[],\n options: SVGExportOptions = {}\n): string | null {\n const bounds = computeContentBounds(graph, nodeIds)\n if (!bounds) return null\n\n const { minX, minY, maxX, maxY } = bounds\n const width = round(maxX - minX)\n const height = round(maxY - minY)\n\n const ctx: SVGExportContext = {\n defs: [],\n defIdCounter: 0,\n graph,\n colorSpace: options.colorSpace ?? 'srgb',\n textLayout: options.textLayout,\n fontAlias: options.fontAlias\n }\n\n const contentNodes: SVGNode[] = []\n\n for (const id of nodeIds) {\n const node = graph.getNode(id)\n if (!node?.visible) continue\n\n const abs = graph.getAbsolutePosition(id)\n const offsetX = abs.x - minX\n const offsetY = abs.y - minY\n\n const needsOffset = offsetX !== node.x || offsetY !== node.y\n const clone = needsOffset ? { ...node, x: round(offsetX), y: round(offsetY) } : node\n\n const rendered = renderNode(clone, ctx)\n if (rendered) contentNodes.push(rendered)\n }\n\n if (contentNodes.length === 0) return null\n\n const rootChildren: (SVGNode | string)[] = []\n if (ctx.defs.length > 0) {\n rootChildren.push(svg('defs', {}, ...ctx.defs))\n }\n rootChildren.push(...contentNodes)\n\n const root = svg(\n 'svg',\n {\n xmlns: 'http://www.w3.org/2000/svg',\n 'xmlns:xlink': 'http://www.w3.org/1999/xlink',\n width,\n height,\n viewBox: `0 0 ${width} ${height}`\n },\n ...(rootChildren as SVGNode[])\n )\n\n const svgStr = renderSVGNode(root)\n const xmlDecl = options.xmlDeclaration !== false ? '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n' : ''\n return xmlDecl + svgStr\n}\n\n/**\n * One layer as an `<svg>` element sized to its box, for inlining in HTML where the box already\n * places, rotates, and fades it: the drawing starts at the layer's origin without its rotation\n * or opacity, and keeps its flips.\n */\nexport function renderNodeSVGElement(\n graph: SceneGraph,\n node: SceneNode,\n {\n idPrefix,\n colorSpace = 'srgb',\n tint\n }: Pick<SVGExportContext, 'tint'> & { idPrefix: string; colorSpace?: RenderColorSpace }\n): SVGNode | null {\n const ctx: SVGExportContext = { defs: [], defIdCounter: 0, graph, colorSpace, idPrefix, tint }\n const drawn = renderNode({ ...node, x: 0, y: 0, rotation: 0, opacity: 1 }, ctx)\n if (!drawn) return null\n // A straight line has no height or width, but its stroke still needs a viewport to draw in.\n const width = Math.max(1, round(node.width))\n const height = Math.max(1, round(node.height))\n return svg(\n 'svg',\n { width, height, viewBox: `0 0 ${width} ${height}` },\n ctx.defs.length > 0 ? svg('defs', {}, ...ctx.defs) : null,\n drawn\n )\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAgDA,SAAS,gBACP,MACA,SACA,QACW;CACX,MAAM,UAAU,eAAe,OAAO,CAAC,CAAC,KAAK,MAAM,IAAI,QAAQ;EAAE;EAAG,GAAG;CAAO,CAAC,CAAC;CAChF,IAAI,cAAc,OAAO,CAAC,CAAC,WAAW,GAAG,OAAO;CAChD,OAAO,CAAC,GAAG,SAAS,GAAG,iBAAiB,MAAM,SAAS,QAAQ,aAAa,CAAC;AAC/E;AAEA,SAAS,o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AAM,CAAC;EAAG,cAAc;EAAG;EAAO;EAAY;EAAU;CAAK;CAC7F,MAAM,QAAQ,WAAW;EAAE,GAAG;EAAM,GAAG;EAAG,GAAG;EAAG,UAAU;EAAG,SAAS;CAAE,GAAG,GAAG;CAC9E,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,QAAQ,KAAK,IAAI,GAAG,MAAM,KAAK,KAAK,CAAC;CAC3C,MAAM,SAAS,KAAK,IAAI,GAAG,MAAM,KAAK,MAAM,CAAC;CAC7C,OAAO,IACL,OACA;EAAE;EAAO;EAAQ,SAAS,OAAO,MAAM,GAAG;CAAS,GACnD,IAAI,KAAK,SAAS,IAAI,IAAI,QAAQ,CAAC,GAAG,GAAG,IAAI,IAAI,IAAI,MACrD,KACF;AACF"}
|
|
1
|
+
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/svg/export.ts"],"sourcesContent":["import type { RenderColorSpace } from '@pairdraw/scene-graph/color'\n\nimport { normalizeDashPattern } from '#core/canvas/strokes'\nimport { lineStrokePath } from '#core/canvas/strokes/line'\nimport { fittedDashPattern } from '#core/canvas/strokes/sides'\nimport { computeContentBounds } from '#core/io/formats/raster'\n\nimport {\n nextDefId,\n formatSolidColor,\n createFilterDef,\n resolveFill,\n solidFillOpacity,\n SVG_STROKE_CAP,\n SVG_STROKE_JOIN,\n SVG_BLEND_MODE\n} from './defs'\nimport {\n round,\n geometryBlobToSVGPath,\n makePolygonPoints,\n roundedPolygonPath,\n hasRadius,\n hasSmoothCorners,\n boxOutlinePath,\n arcPath,\n shapeWithTextOutlinePath\n} from './paths'\n\nexport { geometryBlobToSVGPath, nodeOutlinePath, type OutlineNode } from './paths'\n\nimport type { SceneGraph, SceneNode, Fill, Stroke, VectorNetwork } from '@pairdraw/scene-graph'\nimport { looseSegments, regionSVGPaths } from '@pairdraw/scene-graph/vector-network'\n\nimport { arrowHeadElements, openPathElements, vectorArrowHeads } from './arrows'\nimport type { SVGExportContext, SVGFontAlias } from './defs'\nimport { svg, renderSVGNode } from './node'\nimport type { SVGNode } from './node'\nimport { alignedStroke, alignedStrokeElement, shapeWithTextDetailElements } from './strokes'\nimport { renderTextNode } from './text/export'\nimport type { SVGTextLayout } from './text/lines'\n\n// --- Node rendering ---\n\n/**\n * A vector network's paths: its regions as they are traced, and its open segments as the canvas\n * strokes them, rounded and pulled back under their heads.\n */\nfunction networkElements(\n node: SceneNode,\n network: VectorNetwork,\n common: Record<string, string | number | undefined>\n): SVGNode[] {\n const regions = regionSVGPaths(network).map((d) => svg('path', { d, ...common }))\n if (looseSegments(network).length === 0) return regions\n return [...regions, ...openPathElements(node, network, common, looseSegments)]\n}\n\n/** Paints one path's fill stack; a blended fill draws its stroke as a separate path. */\nfunction vectorFillElements(\n attrs: Record<string, string | number | undefined>,\n visibleFills: Fill[],\n strokeAttrs: Record<string, string | number | undefined>,\n common: Record<string, string | number | undefined>,\n node: SceneNode,\n ctx: SVGExportContext\n): SVGNode[] {\n const elements: SVGNode[] = []\n for (const [index, fill] of visibleFills.entries()) {\n const fillAttr = resolveFill(fill, node, ctx)\n if (!fillAttr) continue\n const style = paintBlendStyle(fill)\n const last = index === visibleFills.length - 1\n const splitStroke = style !== undefined && last && common.stroke !== 'none'\n const stroke = last && !splitStroke ? common.stroke : 'none'\n elements.push(\n svg('path', {\n ...attrs,\n fill: fillAttr,\n 'fill-opacity': solidFillOpacity(fill, ctx.colorSpace),\n style,\n stroke\n })\n )\n if (splitStroke) {\n elements.push(\n svg('path', {\n d: attrs.d,\n 'fill-rule': attrs['fill-rule'],\n fill: 'none',\n ...strokeAttrs\n })\n )\n }\n }\n return elements\n}\n\nfunction vectorShapeElements(\n node: SceneNode,\n common: Record<string, string | number | undefined>,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext,\n fallbackFills?: Fill[]\n): SVGNode[] {\n const elements: SVGNode[] = []\n if (node.fillGeometry.length > 0) {\n for (const geo of node.fillGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (!d) continue\n const attrs = {\n d,\n 'fill-rule': geo.windingRule === 'EVENODD' ? 'evenodd' : undefined,\n ...common\n }\n const pathFills = geo.fills?.length ? geo.fills : fallbackFills\n if (!pathFills) {\n elements.push(svg('path', attrs))\n continue\n }\n const visibleFills = pathFills.filter((fill) => fill.visible)\n if (visibleFills.length === 0) {\n elements.push(svg('path', { ...attrs, fill: 'none' }))\n continue\n }\n elements.push(...vectorFillElements(attrs, visibleFills, strokeAttrs, common, node, ctx))\n }\n } else if (node.vectorNetwork) {\n elements.push(...networkElements(node, node.vectorNetwork, common))\n }\n if (node.strokeGeometry.length > 0 && strokeAttrs.stroke && strokeAttrs.stroke !== 'none') {\n for (const geo of node.strokeGeometry) {\n const d = geometryBlobToSVGPath(geo.commandsBlob)\n if (d) {\n elements.push(\n svg('path', {\n d,\n fill: strokeAttrs.stroke,\n 'fill-opacity': strokeAttrs['stroke-opacity'],\n stroke: 'none'\n })\n )\n }\n }\n }\n if (node.vectorNetwork) elements.push(...vectorArrowHeads(node, node.vectorNetwork, strokeAttrs))\n return elements.length > 0\n ? elements\n : [svg('rect', { width: round(node.width), height: round(node.height), ...common })]\n}\n\n/** A line's dashes stretched along it as the canvas lays them, half a dash at each end. */\nfunction lineDashAttrs(stroke: Stroke | undefined, length: number) {\n const fitted = fittedDashPattern(length, normalizeDashPattern(stroke?.dashPattern))\n if (!fitted) return {}\n return {\n 'stroke-dasharray': fitted.intervals.map((size) => round(size)).join(' '),\n 'stroke-dashoffset': round(fitted.offset)\n }\n}\n\nfunction nodeShapeElements(\n node: SceneNode,\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext\n): SVGNode[] {\n const common: Record<string, string | number | undefined> = {\n fill: fillAttr ?? 'none',\n 'fill-opacity': fillOpacity,\n ...strokeAttrs\n }\n\n switch (node.type) {\n case 'ELLIPSE': {\n if (node.arcData) {\n return [svg('path', { d: arcPath(node), ...common })]\n }\n return [\n svg('ellipse', {\n cx: round(node.width / 2),\n cy: round(node.height / 2),\n rx: round(node.width / 2),\n ry: round(node.height / 2),\n ...common\n })\n ]\n }\n\n case 'LINE': {\n // Where the canvas strokes it: to one side of the line, with its caps inside its length.\n const stroke = node.strokes.find((item) => item.visible)\n const {\n network,\n from: start,\n to: end\n } = lineStrokePath(node, stroke?.weight ?? 0, stroke?.cap ?? node.strokeCap)\n return [\n svg('line', {\n x1: round(start.x),\n y1: round(start.y),\n x2: round(end.x),\n y2: round(end.y),\n fill: 'none',\n ...strokeAttrs,\n ...lineDashAttrs(stroke, Math.hypot(end.x - start.x, end.y - start.y))\n }),\n ...arrowHeadElements(node, network, stroke, strokeAttrs)\n ]\n }\n\n case 'STAR':\n case 'POLYGON':\n return node.cornerRadius > 0\n ? [svg('path', { d: roundedPolygonPath(node), ...common })]\n : [svg('polygon', { points: makePolygonPoints(node), ...common })]\n\n case 'VECTOR':\n return vectorShapeElements(node, common, strokeAttrs, ctx)\n\n case 'SHAPE_WITH_TEXT':\n return shapeWithTextElements(node, common, strokeAttrs, ctx)\n\n default:\n return [boxOutlineElement(node, common)]\n }\n}\n\n/**\n * A box layer's outline as one element: a rect, a rect with `rx`/`ry` for one radius, or the\n * shared box path for independent or smoothed corners, so fills and clips follow the same edge.\n */\nfunction boxOutlineElement(\n node: SceneNode,\n attrs: Record<string, string | number | undefined>\n): SVGNode {\n const width = round(node.width)\n const height = round(node.height)\n if (!hasRadius(node)) return svg('rect', { width, height, ...attrs })\n if (node.independentCorners || hasSmoothCorners(node)) {\n return svg('path', { d: boxOutlinePath(node), ...attrs })\n }\n // SVG clamps rx and ry to their own sides; the canvas keeps a too-large radius circular.\n const radius = round(Math.min(node.cornerRadius, node.width / 2, node.height / 2))\n return svg('rect', { width, height, rx: radius, ry: radius, ...attrs })\n}\n\n/**\n * A FigJam shape's outline, and its inner lines, such as a database's front rim, stroked as the\n * canvas strokes them: at the stroke's own weight, ending where the outline does.\n */\nfunction shapeWithTextElements(\n node: SceneNode,\n common: Record<string, string | number | undefined>,\n strokeAttrs: Record<string, string | number | undefined>,\n ctx: SVGExportContext\n): SVGNode[] {\n return [\n svg('path', { d: shapeWithTextOutlinePath(node), ...common }),\n ...shapeWithTextDetailElements(node, strokeAttrs, ctx)\n ]\n}\n\n// --- Main recursive renderer ---\n\nfunction buildTransformAttr(node: SceneNode): string | undefined {\n const transforms: string[] = []\n if (node.x !== 0 || node.y !== 0) transforms.push(`translate(${round(node.x)}, ${round(node.y)})`)\n if (node.rotation !== 0) {\n transforms.push(\n `rotate(${round(node.rotation)}, ${round(node.width / 2)}, ${round(node.height / 2)})`\n )\n }\n if (node.flipX || node.flipY) {\n const tx = node.flipX ? node.width : 0\n const ty = node.flipY ? node.height : 0\n const sx = node.flipX ? -1 : 1\n const sy = node.flipY ? -1 : 1\n transforms.push(`translate(${round(tx)}, ${round(ty)}) scale(${sx}, ${sy})`)\n }\n return transforms.length > 0 ? transforms.join(' ') : undefined\n}\n\nfunction buildGroupAttrs(\n node: SceneNode,\n ctx: SVGExportContext\n): { attrs: Record<string, string | number | undefined>; clipId?: string } {\n const attrs: Record<string, string | number | undefined> = {}\n\n const transform = buildTransformAttr(node)\n if (transform) attrs.transform = transform\n\n if (node.opacity < 1) attrs.opacity = round(node.opacity)\n\n const blend = SVG_BLEND_MODE[node.blendMode]\n if (blend && blend !== 'normal' && node.blendMode !== 'PASS_THROUGH') {\n attrs.style = `mix-blend-mode: ${blend}`\n }\n\n const filterDef = createFilterDef(node.effects, ctx)\n if (filterDef) {\n ctx.defs.push(filterDef.node)\n attrs.filter = `url(#${filterDef.id})`\n }\n\n let clipId: string | undefined\n if (node.clipsContent && node.childIds.length > 0) {\n clipId = nextDefId(ctx, 'clip')\n ctx.defs.push(svg('clipPath', { id: clipId }, boxOutlineElement(node, {})))\n }\n\n return { attrs, clipId }\n}\n\nfunction buildSVGStrokeAttrs(\n visibleStrokes: Stroke[],\n node: SceneNode,\n ctx: SVGExportContext\n): Record<string, string | number | undefined> {\n if (visibleStrokes.length === 0) return {}\n const stroke = visibleStrokes[0]\n const cap = stroke.cap ?? node.strokeCap\n const attrs: Record<string, string | number | undefined> = {\n // Opacity 1 keeps the color opaque. Display P3 must not also keep color alpha here, or a\n // viewer multiplies it by stroke-opacity; the canvas paints stroke.opacity alone.\n stroke:\n stroke.type === 'SOLID'\n ? formatSolidColor(stroke.color, 1, ctx.colorSpace)\n : (resolveFill(stroke, node, ctx) ?? formatSolidColor(stroke.color, 1, ctx.colorSpace)),\n 'stroke-width': round(stroke.weight)\n }\n if (stroke.opacity < 1) attrs['stroke-opacity'] = round(stroke.opacity)\n if (cap !== 'NONE') attrs['stroke-linecap'] = SVG_STROKE_CAP[cap] ?? 'butt'\n if (stroke.join && stroke.join !== 'MITER') {\n attrs['stroke-linejoin'] = SVG_STROKE_JOIN[stroke.join] ?? 'miter'\n }\n if (stroke.dashPattern && stroke.dashPattern.length > 0) {\n attrs['stroke-dasharray'] = stroke.dashPattern.map((n) => round(n)).join(' ')\n }\n return attrs\n}\n\n/** The blend CSS a paint adds, when the canvas would not composite it source-over. */\nfunction paintBlendStyle(fill: Fill | undefined): string | undefined {\n const blend = fill?.blendMode ? SVG_BLEND_MODE[fill.blendMode] : undefined\n return blend && blend !== 'normal' ? `mix-blend-mode: ${blend}` : undefined\n}\n\n/** Adds a paint's blend mode to the elements that draw it. */\nfunction withPaintBlend(elements: SVGNode[], fill: Fill | undefined): SVGNode[] {\n const style = paintBlendStyle(fill)\n if (style) for (const element of elements) element.attrs.style = style\n return elements\n}\n\n/**\n * Draws the fill and the stroke as separate elements when the fill blends, so the stroke keeps the\n * source-over canvas gives it instead of inheriting the fill's blend mode.\n */\nfunction shapeWithPaint(\n node: SceneNode,\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n fill: Fill | undefined,\n ctx: SVGExportContext\n): SVGNode[] {\n const blends = paintBlendStyle(fill) !== undefined\n if (!blends || !strokeAttrs.stroke) {\n return withPaintBlend(nodeShapeElements(node, fillAttr, fillOpacity, strokeAttrs, ctx), fill)\n }\n return [\n ...withPaintBlend(nodeShapeElements(node, fillAttr, fillOpacity, {}, ctx), fill),\n ...nodeShapeElements(node, null, undefined, strokeAttrs, ctx)\n ]\n}\n\nfunction hasPathLevelFills(node: SceneNode): boolean {\n return node.type === 'VECTOR' && node.fillGeometry.some((geometry) => geometry.fills?.length)\n}\n\nfunction buildShapeChildren(\n node: SceneNode,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n visibleStrokes: Stroke[],\n ctx: SVGExportContext\n): SVGNode[] {\n const aligned = hasPathLevelFills(node) ? null : alignedStroke(node, visibleStrokes[0])\n if (!aligned) {\n return fillAndStrokeElements(\n node,\n visibleFills,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleStrokes.length,\n ctx\n )\n }\n // The fill goes as it is, and the stroke over it inside or outside the outline.\n return [\n ...fillAndStrokeElements(node, visibleFills, fillAttr, fillOpacity, {}, 0, ctx),\n ...alignedStrokeElement(node, aligned, strokeAttrs, ctx),\n ...(node.type === 'SHAPE_WITH_TEXT' ? shapeWithTextDetailElements(node, strokeAttrs, ctx) : [])\n ]\n}\n\nfunction fillAndStrokeElements(\n node: SceneNode,\n visibleFills: Fill[],\n fillAttr: string | null,\n fillOpacity: number | undefined,\n strokeAttrs: Record<string, string | number | undefined>,\n visibleStrokeCount: number,\n ctx: SVGExportContext\n): SVGNode[] {\n if (hasPathLevelFills(node)) {\n return vectorShapeElements(\n node,\n { fill: fillAttr ?? 'none', 'fill-opacity': fillOpacity, ...strokeAttrs },\n strokeAttrs,\n ctx,\n visibleFills\n )\n }\n\n if (visibleFills.length > 1) {\n const elements: SVGNode[] = []\n for (const fill of visibleFills) {\n const ref = resolveFill(fill, node, ctx)\n if (ref) {\n elements.push(\n ...shapeWithPaint(\n node,\n ref,\n solidFillOpacity(fill, ctx.colorSpace),\n fill === visibleFills[visibleFills.length - 1] ? strokeAttrs : {},\n fill,\n ctx\n )\n )\n }\n }\n return elements\n }\n\n const hasFillOrStroke = fillAttr || visibleStrokeCount > 0\n if (hasFillOrStroke && !isGroupLike(node)) {\n return shapeWithPaint(\n node,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleFills.length === 1 ? visibleFills[0] : undefined,\n ctx\n )\n }\n\n return []\n}\n\n/** The paint CSS `color` sets, for a tinted icon path. */\nconst CURRENT_COLOR = 'currentColor'\n\n/** A paint's SVG color and, for an sRGB solid, the `fill-opacity` beside it. */\nfunction exportedFill(\n fill: Fill | undefined,\n node: SceneNode,\n ctx: SVGExportContext\n): { color: string | null; opacity: number | undefined } {\n if (!fill) return { color: null, opacity: undefined }\n return {\n color: resolveFill(fill, node, ctx),\n opacity: solidFillOpacity(fill, ctx.colorSpace)\n }\n}\n\nfunction renderNode(node: SceneNode, ctx: SVGExportContext): SVGNode | null {\n if (!node.visible) return null\n\n const { attrs: groupAttrs, clipId } = buildGroupAttrs(node, ctx)\n\n if (node.type === 'TEXT') {\n const fill = exportedFill(\n node.fills.find((f) => f.visible),\n node,\n ctx\n )\n return svg('g', groupAttrs, renderTextNode(node, fill.color, ctx, fill.opacity))\n }\n\n const visibleFills = node.fills.filter((f) => f.visible)\n const visibleStrokes = node.strokes.filter((s) => s.visible)\n const tint = ctx.tint?.(node) ?? []\n const ownFill = visibleFills.length > 0 && !hasPathLevelFills(node) ? visibleFills[0] : undefined\n const fill = exportedFill(ownFill, node, ctx)\n const tintedFill = fill.color !== null && tint.includes('fill')\n const fillAttr = tintedFill ? CURRENT_COLOR : fill.color\n // `currentColor` has no alpha. Display P3 normally bakes solid opacity into the color, which a\n // tint throws away, so a tinted solid keeps `fill-opacity` in every color space.\n const fillOpacity = ownFill ? solidFillOpacity(ownFill, ctx.colorSpace, tintedFill) : fill.opacity\n const ownStrokes = buildSVGStrokeAttrs(visibleStrokes, node, ctx)\n const strokeAttrs =\n ownStrokes.stroke && tint.includes('stroke')\n ? { ...ownStrokes, stroke: CURRENT_COLOR }\n : ownStrokes\n\n const children: (SVGNode | null)[] = buildShapeChildren(\n node,\n visibleFills,\n fillAttr,\n fillOpacity,\n strokeAttrs,\n visibleStrokes,\n ctx\n )\n\n const childNodes = ctx.graph.getChildren(node.id)\n const childContent: SVGNode[] = []\n for (const child of childNodes) {\n const rendered = renderNode(child, ctx)\n if (rendered) childContent.push(rendered)\n }\n\n if (clipId && childContent.length > 0) {\n children.push(svg('g', { 'clip-path': `url(#${clipId})` }, ...childContent))\n } else {\n children.push(...childContent)\n }\n\n const validChildren = children.filter((c): c is SVGNode => c !== null)\n\n if (validChildren.length === 0 && Object.keys(groupAttrs).length === 0) {\n return null\n }\n\n if (validChildren.length === 1 && Object.keys(groupAttrs).length === 0) {\n return validChildren[0]\n }\n\n return svg('g', groupAttrs, ...validChildren)\n}\n\nfunction isGroupLike(node: SceneNode): boolean {\n return node.type === 'GROUP'\n}\n\n// --- Public API ---\n\nexport interface SVGExportOptions {\n /** Include XML declaration (default: true) */\n xmlDeclaration?: boolean\n /** Target export color space (default: srgb) */\n colorSpace?: 'srgb' | 'display-p3'\n /**\n * Line breaks of text nodes as the editor laid them out, wraps included. Without them, only\n * explicit newlines start a new baseline, which renderers that do not wrap SVG text keep.\n */\n textLayout?: SVGTextLayout\n /**\n * A family to name a font face by instead of its own, such as the one a PDF embeds the face's\n * file under. Text in an aliased face is written in that family at normal weight and style.\n */\n fontAlias?: SVGFontAlias\n}\n\nexport function renderNodesToSVG(\n graph: SceneGraph,\n _pageId: string,\n nodeIds: string[],\n options: SVGExportOptions = {}\n): string | null {\n const bounds = computeContentBounds(graph, nodeIds)\n if (!bounds) return null\n\n const { minX, minY, maxX, maxY } = bounds\n const width = round(maxX - minX)\n const height = round(maxY - minY)\n\n const ctx: SVGExportContext = {\n defs: [],\n defIdCounter: 0,\n graph,\n colorSpace: options.colorSpace ?? 'srgb',\n textLayout: options.textLayout,\n fontAlias: options.fontAlias\n }\n\n const contentNodes: SVGNode[] = []\n\n for (const id of nodeIds) {\n const node = graph.getNode(id)\n if (!node?.visible) continue\n\n const abs = graph.getAbsolutePosition(id)\n const offsetX = abs.x - minX\n const offsetY = abs.y - minY\n\n const needsOffset = offsetX !== node.x || offsetY !== node.y\n const clone = needsOffset ? { ...node, x: round(offsetX), y: round(offsetY) } : node\n\n const rendered = renderNode(clone, ctx)\n if (rendered) contentNodes.push(rendered)\n }\n\n if (contentNodes.length === 0) return null\n\n const rootChildren: (SVGNode | string)[] = []\n if (ctx.defs.length > 0) {\n rootChildren.push(svg('defs', {}, ...ctx.defs))\n }\n rootChildren.push(...contentNodes)\n\n const root = svg(\n 'svg',\n {\n xmlns: 'http://www.w3.org/2000/svg',\n 'xmlns:xlink': 'http://www.w3.org/1999/xlink',\n width,\n height,\n viewBox: `0 0 ${width} ${height}`\n },\n ...(rootChildren as SVGNode[])\n )\n\n const svgStr = renderSVGNode(root)\n const xmlDecl = options.xmlDeclaration !== false ? '<?xml version=\"1.0\" encoding=\"UTF-8\"?>\\n' : ''\n return xmlDecl + svgStr\n}\n\n/**\n * One layer as an `<svg>` element sized to its box, for inlining in HTML where the box already\n * places, rotates, and fades it: the drawing starts at the layer's origin without its rotation\n * or opacity, and keeps its flips.\n */\nexport function renderNodeSVGElement(\n graph: SceneGraph,\n node: SceneNode,\n {\n idPrefix,\n colorSpace = 'srgb',\n tint\n }: Pick<SVGExportContext, 'tint'> & { idPrefix: string; colorSpace?: RenderColorSpace }\n): SVGNode | null {\n const ctx: SVGExportContext = { defs: [], defIdCounter: 0, graph, colorSpace, idPrefix, tint }\n const drawn = renderNode({ ...node, x: 0, y: 0, rotation: 0, opacity: 1 }, ctx)\n if (!drawn) return null\n // A straight line has no height or width, but its stroke still needs a viewport to draw in.\n const width = Math.max(1, round(node.width))\n const height = Math.max(1, round(node.height))\n return svg(\n 'svg',\n { width, height, viewBox: `0 0 ${width} ${height}` },\n ctx.defs.length > 0 ? svg('defs', {}, ...ctx.defs) : null,\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,IACX,OACA;EACE,OAAO;EACP,eAAe;EACf;EACA;EACA,SAAS,OAAO,MAAM,GAAG;CAC3B,GACA,GAAI,YACN;CAEA,MAAM,SAAS,cAAc,IAAI;CAEjC,QADgB,QAAQ,mBAAmB,QAAQ,iDAA6C,MAC/E;AACnB;;;;;;AAOA,SAAgB,qBACd,OACA,MACA,EACE,UACA,aAAa,QACb,QAEc;CAChB,MAAM,MAAwB;EAAE,MAAM,CAAC;EAAG,cAAc;EAAG;EAAO;EAAY;EAAU;CAAK;CAC7F,MAAM,QAAQ,WAAW;EAAE,GAAG;EAAM,GAAG;EAAG,GAAG;EAAG,UAAU;EAAG,SAAS;CAAE,GAAG,GAAG;CAC9E,IAAI,CAAC,OAAO,OAAO;CAEnB,MAAM,QAAQ,KAAK,IAAI,GAAG,MAAM,KAAK,KAAK,CAAC;CAC3C,MAAM,SAAS,KAAK,IAAI,GAAG,MAAM,KAAK,MAAM,CAAC;CAC7C,OAAO,IACL,OACA;EAAE;EAAO;EAAQ,SAAS,OAAO,MAAM,GAAG;CAAS,GACnD,IAAI,KAAK,SAAS,IAAI,IAAI,QAAQ,CAAC,GAAG,GAAG,IAAI,IAAI,IAAI,MACrD,KACF;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/layout/apply.ts"],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"apply.d.ts","names":[],"sources":["../../src/layout/apply.ts"],"mappings":";;;KAWY,mBAAmB,OAAO,YAAY;;;;;iBAuElC,mBAAmB,OAAO;iBA4S1B,gBACd,OAAO,YACP,OAAO,WACP,UAAU,MACV,eAAe"}
|
package/dist/layout/apply.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { keepsSavedLayout, usesDetachedDerivedLayout } from "./derived.js";
|
|
1
|
+
import { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from "./derived.js";
|
|
2
2
|
import { laidOutFlowBox } from "./flow-edges.js";
|
|
3
|
+
import { contentInsetsSize } from "./strokes.js";
|
|
3
4
|
import { layoutConstrainedChildRect, shapeGeometryChanges } from "@pairdraw/scene-graph/resize";
|
|
4
5
|
import { enforcedAspectRatio } from "@pairdraw/scene-graph/layout";
|
|
5
6
|
//#region src/layout/apply.ts
|
|
@@ -30,7 +31,8 @@ function writeLayoutGeometry(graph, id, geometry, computeLayout, before, constra
|
|
|
30
31
|
"height"
|
|
31
32
|
]) {
|
|
32
33
|
const value = geometry[key];
|
|
33
|
-
if (value
|
|
34
|
+
if (value === void 0 || !Number.isFinite(value) || value === node[key]) continue;
|
|
35
|
+
changes[key] = value;
|
|
34
36
|
}
|
|
35
37
|
const outlines = changes.width !== void 0 || changes.height !== void 0 ? shapeGeometryChanges(node, changes.width ?? node.width, changes.height ?? node.height) : {};
|
|
36
38
|
if (Object.keys(changes).length + Object.keys(outlines).length > 0) graph.updateNode(id, {
|
|
@@ -108,22 +110,58 @@ function hugStart(frame) {
|
|
|
108
110
|
height: hugsHeight && hugged ? hugged.height : frame.height
|
|
109
111
|
};
|
|
110
112
|
}
|
|
113
|
+
/**
|
|
114
|
+
* The smallest size a layout frame holds: what Yoga computed for it, or the room its padding and
|
|
115
|
+
* included inside strokes take, which Yoga's fixed size does not count. A saved frame nobody
|
|
116
|
+
* edited holds exactly what Yoga computed, so opening a file never grows it.
|
|
117
|
+
*/
|
|
118
|
+
function heldFrameSize(frame, yogaNode, holdsSavedSize) {
|
|
119
|
+
const insets = holdsSavedSize ? null : contentInsetsSize(frame);
|
|
120
|
+
return {
|
|
121
|
+
width: Math.max(yogaNode.getComputedWidth(), insets?.width ?? 0),
|
|
122
|
+
height: Math.max(yogaNode.getComputedHeight(), insets?.height ?? 0)
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/** A grid's size: automatic rows take their height, and a hugged axis takes what Yoga computed. */
|
|
126
|
+
function applyGridFrameSize(graph, frame, yogaNode, computeLayout) {
|
|
127
|
+
const updates = {};
|
|
128
|
+
const holds = keepsSavedFrameSize(graph, frame);
|
|
129
|
+
const held = heldFrameSize(frame, yogaNode, holds);
|
|
130
|
+
if (frame.primaryAxisSizing === "HUG") updates.width = held.width;
|
|
131
|
+
else if (!holds && held.width > frame.width) updates.width = held.width;
|
|
132
|
+
if (frame.gridTemplateRows.length === 0 || frame.counterAxisSizing === "HUG") updates.height = held.height;
|
|
133
|
+
else if (!holds && held.height > frame.height) updates.height = held.height;
|
|
134
|
+
writeLayoutGeometry(graph, frame.id, updates, computeLayout);
|
|
135
|
+
}
|
|
136
|
+
/** The sizes a flex frame takes: a fixed one grows to its padding, and a hugged one hugs. */
|
|
137
|
+
function flexFrameSizeUpdates(frame, held, computed, derived, keepsSavedSize, holdsSavedSize) {
|
|
138
|
+
const primary = frame.layoutMode === "HORIZONTAL" ? "width" : "height";
|
|
139
|
+
const counter = primary === "width" ? "height" : "width";
|
|
140
|
+
const updates = {};
|
|
141
|
+
if (frame.primaryAxisSizing === "FIXED" && !holdsSavedSize && held[primary] > frame[primary]) updates[primary] = held[primary];
|
|
142
|
+
if (frame.counterAxisSizing === "FIXED" && !holdsSavedSize && held[counter] > frame[counter]) updates[counter] = held[counter];
|
|
143
|
+
if (frame.primaryAxisSizing === "HUG") {
|
|
144
|
+
const floor = holdsSavedSize ? 0 : held[primary];
|
|
145
|
+
updates[primary] = Math.max(derived?.[primary] ?? computed(primary), floor);
|
|
146
|
+
}
|
|
147
|
+
if (frame.counterAxisSizing === "HUG") {
|
|
148
|
+
const floor = holdsSavedSize ? 0 : held[counter];
|
|
149
|
+
updates[counter] = Math.max(keepsSavedSize(counter) ? frame[counter] : derived?.[counter] ?? computed(counter), floor);
|
|
150
|
+
}
|
|
151
|
+
return updates;
|
|
152
|
+
}
|
|
111
153
|
function applyFrameSize(graph, frame, yogaNode, keepsSaved, computeLayout) {
|
|
112
154
|
if (frame.layoutMode === "GRID") {
|
|
113
|
-
|
|
155
|
+
applyGridFrameSize(graph, frame, yogaNode, computeLayout);
|
|
114
156
|
return;
|
|
115
157
|
}
|
|
116
158
|
const before = hugStart(frame);
|
|
117
|
-
if (!before) return;
|
|
118
|
-
const updates = {};
|
|
119
|
-
const derived = keepsSaved ? frame.derivedLayout : null;
|
|
120
|
-
const primary = frame.layoutMode === "HORIZONTAL" ? "width" : "height";
|
|
121
|
-
const counter = primary === "width" ? "height" : "width";
|
|
122
159
|
const computed = (axis) => axis === "width" ? yogaNode.getComputedWidth() : yogaNode.getComputedHeight();
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
160
|
+
const holds = keepsSavedFrameSize(graph, frame);
|
|
161
|
+
const updates = flexFrameSizeUpdates(frame, heldFrameSize(frame, yogaNode, holds), computed, keepsSaved ? frame.derivedLayout : null, (axis) => keepsSaved && preservesImportedHugCrossSize(graph, frame, axis), holds);
|
|
162
|
+
if (Object.keys(updates).length === 0) return;
|
|
163
|
+
writeLayoutGeometry(graph, frame.id, updates, computeLayout, before ?? void 0);
|
|
164
|
+
if (before) huggedSizes.set(frame, {
|
|
127
165
|
width: frame.width,
|
|
128
166
|
height: frame.height
|
|
129
167
|
});
|
package/dist/layout/apply.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apply.js","names":[],"sources":["../../src/layout/apply.ts"],"sourcesContent":["import type { Node as YogaNode } from 'yoga-layout'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { enforcedAspectRatio } from '@pairdraw/scene-graph/layout'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\nimport { layoutConstrainedChildRect, shapeGeometryChanges } from '@pairdraw/scene-graph/resize'\n\nimport { keepsSavedLayout, usesDetachedDerivedLayout } from './derived'\nimport { laidOutFlowBox } from './flow-edges'\n\nexport type ComputeLayoutFn = (graph: SceneGraph, frameId: string) => void\n\nfunction preservesImportedHugCrossSize(\n graph: SceneGraph,\n frame: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (frame.source.format !== 'fig' || frame.counterAxisSizing !== 'HUG') return false\n const expectedMode = axis === 'width' ? 'VERTICAL' : 'HORIZONTAL'\n if (frame.layoutMode !== expectedMode) return false\n return graph\n .getChildren(frame.id)\n .some(\n (child) => child.layoutAlignSelf === 'STRETCH' && child.derivedLayout?.[axis] !== undefined\n )\n}\n\ntype LayoutGeometry = Partial<Pick<SceneNode, 'x' | 'y' | 'width' | 'height'>>\n\n/**\n * Writes only the geometry layout changed. Laying out a large page leaves most layers where they\n * were, and each write would notify every graph listener for nothing. A frame it resizes from\n * `before`, by default the size it has, places the layers its constraints govern; `constrained`\n * marks a write those constraints made, which places its own children in turn.\n */\nfunction writeLayoutGeometry(\n graph: SceneGraph,\n id: string,\n geometry: LayoutGeometry,\n computeLayout: ComputeLayoutFn,\n before?: { width: number; height: number },\n constrained = false\n): void {\n const node = graph.getNode(id)\n if (!node) return\n const from = before ?? { width: node.width, height: node.height }\n const changes: LayoutGeometry = {}\n for (const key of ['x', 'y', 'width', 'height'] as const) {\n const value = geometry[key]\n if (value !== undefined && value !== node[key]) changes[key] = value\n }\n const resized = changes.width !== undefined || changes.height !== undefined\n const outlines = resized\n ? shapeGeometryChanges(node, changes.width ?? node.width, changes.height ?? node.height)\n : {}\n if (Object.keys(changes).length + Object.keys(outlines).length > 0) {\n graph.updateNode(id, { ...changes, ...outlines })\n }\n if (!CONSTRAINT_PARENT_TYPES.has(node.type)) return\n // Laying out what a file holds, as a page opens or its fonts arrive, resizes a frame only where\n // our layout differs from the one the file saved; its children keep the places it saved.\n if (graph.isApplyingDerivedLayout && !constrained) return\n if (from.width !== node.width || from.height !== node.height) {\n constrainChildren(graph, node, from, computeLayout)\n rememberPlacedSize(node)\n }\n}\n\n/**\n * The size each Hug frame's constrained children were last placed for by layout. Keyed by the\n * node, so a deleted frame's entry goes with it and a restored one starts afresh.\n */\nconst huggedSizes = new WeakMap<SceneNode, { width: number; height: number }>()\n\n/**\n * Records a frame's size as the one its constrained children were placed for, after a rescale\n * scaled them with it: the next hug moves them from the scaled size, not twice from the old one.\n */\nexport function restoredHuggedSize(frame: SceneNode): void {\n if (huggedSizes.has(frame)) huggedSizes.set(frame, { width: frame.width, height: frame.height })\n}\n\nfunction rememberPlacedSize(frame: SceneNode): void {\n const placed = huggedSizes.get(frame)\n if (!placed) return\n placed.width = frame.width\n placed.height = frame.height\n}\n\nconst CONSTRAINT_PARENT_TYPES: ReadonlySet<SceneNode['type']> = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/**\n * Places the children of a frame layout resized by their constraints: every child of a frame\n * without auto layout, and those that ignore an auto layout, as Figma keeps a badge pinned to the\n * right of a Hug button while its label grows. A child it resizes places its own children, and\n * lays out again when it has auto layout.\n */\nfunction constrainChildren(\n graph: SceneGraph,\n frame: SceneNode,\n before: { width: number; height: number },\n computeLayout: ComputeLayoutFn\n): void {\n for (const child of graph.getChildren(frame.id)) {\n if (frame.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE') continue\n const size = { width: child.width, height: child.height }\n writeLayoutGeometry(\n graph,\n child.id,\n layoutConstrainedChildRect(\n child,\n before,\n frame,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n ),\n computeLayout,\n undefined,\n true\n )\n const resized = child.width !== size.width || child.height !== size.height\n if (resized && child.layoutMode !== 'NONE') computeLayout(graph, child.id)\n }\n}\n\n/**\n * The size a frame's constrained children move from as it hugs, or null when it hugs no axis.\n * An editor that resizes a Hug frame places its children for the size it sets, which layout then\n * hugs back, as when a parent stretches it; its children move only from the size it last hugged\n * to. An axis it does not hug keeps the size it has.\n */\nfunction hugStart(frame: SceneNode): { width: number; height: number } | null {\n const row = frame.layoutMode === 'HORIZONTAL'\n const hugsWidth = (row ? frame.primaryAxisSizing : frame.counterAxisSizing) === 'HUG'\n const hugsHeight = (row ? frame.counterAxisSizing : frame.primaryAxisSizing) === 'HUG'\n if (!hugsWidth && !hugsHeight) {\n huggedSizes.delete(frame)\n return null\n }\n const hugged = huggedSizes.get(frame)\n return {\n width: hugsWidth && hugged ? hugged.width : frame.width,\n height: hugsHeight && hugged ? hugged.height : frame.height\n }\n}\n\nfunction applyFrameSize(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n keepsSaved: boolean,\n computeLayout: ComputeLayoutFn\n): void {\n if (frame.layoutMode === 'GRID') {\n if (frame.gridTemplateRows.length === 0) {\n writeLayoutGeometry(graph, frame.id, { height: yogaNode.getComputedHeight() }, computeLayout)\n }\n return\n }\n\n const before = hugStart(frame)\n if (!before) return\n\n const updates: LayoutGeometry = {}\n const derived = keepsSaved ? frame.derivedLayout : null\n const primary = frame.layoutMode === 'HORIZONTAL' ? 'width' : 'height'\n const counter = primary === 'width' ? 'height' : 'width'\n const computed = (axis: 'width' | 'height') =>\n axis === 'width' ? yogaNode.getComputedWidth() : yogaNode.getComputedHeight()\n if (frame.primaryAxisSizing === 'HUG') updates[primary] = derived?.[primary] ?? computed(primary)\n if (frame.counterAxisSizing === 'HUG') {\n updates[counter] =\n keepsSaved && preservesImportedHugCrossSize(graph, frame, counter)\n ? frame[counter]\n : (derived?.[counter] ?? computed(counter))\n }\n\n writeLayoutGeometry(graph, frame.id, updates, computeLayout, before)\n huggedSizes.set(frame, { width: frame.width, height: frame.height })\n}\n\nfunction computedChildPosition(\n child: SceneNode,\n yogaChild: YogaNode,\n axis: 'x' | 'y',\n origin: number,\n preservesImportedGeometry: boolean,\n keepsSaved: boolean\n): number {\n if (preservesImportedGeometry) return child[axis]\n const computed =\n origin + (axis === 'x' ? yogaChild.getComputedLeft() : yogaChild.getComputedTop())\n if (child.type === 'INSTANCE' || !keepsSaved) return computed\n return child.derivedLayout?.[axis] ?? computed\n}\n\nfunction preservesStaleImportedTextSize(child: SceneNode, axis: 'width' | 'height'): boolean {\n const derivedSize = child.derivedLayout?.[axis]\n return (\n child.type === 'TEXT' &&\n child.source.format === 'fig' &&\n derivedSize !== undefined &&\n Math.abs(child[axis] - derivedSize) > 0.001\n )\n}\n\nfunction computedChildSize(\n child: SceneNode,\n yogaChild: YogaNode,\n axis: 'width' | 'height',\n preservesImportedFrameGeometry: boolean,\n keepsSaved: boolean\n): number {\n if (\n preservesImportedFrameGeometry ||\n (keepsSaved && preservesStaleImportedTextSize(child, axis))\n ) {\n return child[axis]\n }\n const computed = axis === 'width' ? yogaChild.getComputedWidth() : yogaChild.getComputedHeight()\n if (child.type === 'TEXT' && child.source.format === 'fig') {\n return computed > 0 ? computed : child[axis]\n }\n if (!keepsSaved) return computed\n return child.derivedLayout?.[axis] ?? computed\n}\n\nfunction updateChildFromYoga(\n graph: SceneGraph,\n frame: SceneNode,\n child: SceneNode,\n yogaChild: YogaNode,\n origin: Vector,\n keepsSaved: boolean,\n computeLayout: ComputeLayoutFn\n): void {\n if (!child.visible || child.layoutPositioning === 'ABSOLUTE') return\n\n const savedFig = keepsSaved && child.source.format === 'fig'\n const preservesImportedFrameGeometry =\n savedFig && frame.source.format === 'fig' && (child.type === 'FRAME' || child.type === 'LINE')\n const preservesImportedPosition =\n preservesImportedFrameGeometry || (savedFig && Math.abs(child.rotation) > 0.001)\n writeLayoutGeometry(\n graph,\n child.id,\n {\n x: computedChildPosition(\n child,\n yogaChild,\n 'x',\n origin.x,\n preservesImportedPosition,\n keepsSaved\n ),\n y: computedChildPosition(\n child,\n yogaChild,\n 'y',\n origin.y,\n preservesImportedPosition,\n keepsSaved\n ),\n width: computedChildSize(\n child,\n yogaChild,\n 'width',\n preservesImportedFrameGeometry,\n keepsSaved\n ),\n height: computedChildSize(\n child,\n yogaChild,\n 'height',\n preservesImportedFrameGeometry,\n keepsSaved\n )\n },\n computeLayout\n )\n}\n\nfunction preservesImportedInstanceInternals(child: SceneNode): boolean {\n return child.type === 'INSTANCE' && child.source.format === 'fig'\n}\n\nfunction recomputeGridChild(\n graph: SceneGraph,\n child: SceneNode,\n computeLayout: ComputeLayoutFn\n): void {\n const updated = graph.getNode(child.id)\n if (!updated || updated.layoutMode === 'NONE') return\n\n const savedPrimary = updated.primaryAxisSizing\n const savedCounter = updated.counterAxisSizing\n const updates: Partial<SceneNode> = {}\n\n if (savedPrimary === 'HUG') updates.primaryAxisSizing = 'FIXED'\n if (savedCounter === 'HUG') updates.counterAxisSizing = 'FIXED'\n if (Object.keys(updates).length > 0) graph.updateNode(child.id, updates)\n\n computeLayout(graph, child.id)\n\n const restore: Partial<SceneNode> = {}\n if (updates.primaryAxisSizing) restore.primaryAxisSizing = savedPrimary\n if (updates.counterAxisSizing) restore.counterAxisSizing = savedCounter\n if (Object.keys(restore).length > 0) graph.updateNode(child.id, restore)\n}\n\nexport function applyYogaLayout(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n computeLayout: ComputeLayoutFn\n): void {\n const keepsSaved = keepsSavedLayout(graph, frame)\n applyFrameSize(graph, frame, yogaNode, keepsSaved, computeLayout)\n\n const children = graph.getChildren(frame.id)\n const box = laidOutFlowBox(yogaNode, frame)\n let yogaIndex = 0\n for (const child of children) {\n if (yogaIndex >= box.node.getChildCount()) continue\n const yogaChild = box.node.getChild(yogaIndex)\n yogaIndex++\n\n updateChildFromYoga(graph, frame, child, yogaChild, box.origin, keepsSaved, computeLayout)\n\n if (!child.visible) continue\n if (preservesImportedInstanceInternals(child)) continue\n\n if (usesDetachedDerivedLayout(graph, child)) {\n computeLayout(graph, child.id)\n continue\n }\n\n if (child.layoutMode !== 'NONE') {\n if (child.layoutMode === 'GRID' && child.layoutPositioning !== 'ABSOLUTE') {\n computeLayout(graph, child.id)\n } else if (frame.layoutMode === 'GRID' && child.layoutPositioning !== 'ABSOLUTE') {\n recomputeGridChild(graph, child, computeLayout)\n } else {\n applyYogaLayout(graph, child, yogaChild, computeLayout)\n }\n }\n }\n}\n"],"mappings":";;;;;AAYA,SAAS,8BACP,OACA,OACA,MACS;CACT,IAAI,MAAM,OAAO,WAAW,SAAS,MAAM,sBAAsB,OAAO,OAAO;CAC/E,MAAM,eAAe,SAAS,UAA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oB;CAC3D,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,GAAG,MAAM,WAAW,MAAM,IAAI,OAAO;AACzE;AAEA,SAAgB,gBACd,OACA,OACA,UACA,eACM;CACN,MAAM,aAAa,iBAAiB,OAAO,KAAK;CAChD,eAAe,OAAO,OAAO,UAAU,YAAY,aAAa;CAEhE,MAAM,WAAW,MAAM,YAAY,MAAM,EAAE;CAC3C,MAAM,MAAM,eAAe,UAAU,KAAK;CAC1C,IAAI,YAAY;CAChB,KAAK,MAAM,SAAS,UAAU;EAC5B,IAAI,aAAa,IAAI,KAAK,cAAc,GAAG;EAC3C,MAAM,YAAY,IAAI,KAAK,SAAS,SAAS;EAC7C;EAEA,oBAAoB,OAAO,OAAO,OAAO,WAAW,IAAI,QAAQ,YAAY,aAAa;EAEzF,IAAI,CAAC,MAAM,SAAS;EACpB,IAAI,mCAAmC,KAAK,GAAG;EAE/C,IAAI,0BAA0B,OAAO,KAAK,GAAG;GAC3C,cAAc,OAAO,MAAM,EAAE;GAC7B;EACF;EAEA,IAAI,MAAM,eAAe,QAAQ;GAC/B,IAAI,MAAM,eAAe,UAAU,MAAM,sBAAsB,YAC7D,cAAc,OAAO,MAAM,EAAE;QACxB,IAAI,MAAM,eAAe,UAAU,MAAM,sBAAsB,YACpE,mBAAmB,OAAO,OAAO,aAAa;QAE9C,gBAAgB,OAAO,OAAO,WAAW,aAAa;EAE1D;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"apply.js","names":[],"sources":["../../src/layout/apply.ts"],"sourcesContent":["import type { Node as YogaNode } from 'yoga-layout'\n\nimport type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { enforcedAspectRatio } from '@pairdraw/scene-graph/layout'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\nimport { layoutConstrainedChildRect, shapeGeometryChanges } from '@pairdraw/scene-graph/resize'\n\nimport { keepsSavedFrameSize, keepsSavedLayout, usesDetachedDerivedLayout } from './derived'\nimport { laidOutFlowBox } from './flow-edges'\nimport { contentInsetsSize } from './strokes'\n\nexport type ComputeLayoutFn = (graph: SceneGraph, frameId: string) => void\n\nfunction preservesImportedHugCrossSize(\n graph: SceneGraph,\n frame: SceneNode,\n axis: 'width' | 'height'\n): boolean {\n if (frame.source.format !== 'fig' || frame.counterAxisSizing !== 'HUG') return false\n const expectedMode = axis === 'width' ? 'VERTICAL' : 'HORIZONTAL'\n if (frame.layoutMode !== expectedMode) return false\n return graph\n .getChildren(frame.id)\n .some(\n (child) => child.layoutAlignSelf === 'STRETCH' && child.derivedLayout?.[axis] !== undefined\n )\n}\n\ntype LayoutGeometry = Partial<Pick<SceneNode, 'x' | 'y' | 'width' | 'height'>>\n\n/**\n * Writes only the geometry layout changed. Laying out a large page leaves most layers where they\n * were, and each write would notify every graph listener for nothing. A frame it resizes from\n * `before`, by default the size it has, places the layers its constraints govern; `constrained`\n * marks a write those constraints made, which places its own children in turn.\n */\nfunction writeLayoutGeometry(\n graph: SceneGraph,\n id: string,\n geometry: LayoutGeometry,\n computeLayout: ComputeLayoutFn,\n before?: { width: number; height: number },\n constrained = false\n): void {\n const node = graph.getNode(id)\n if (!node) return\n const from = before ?? { width: node.width, height: node.height }\n const changes: LayoutGeometry = {}\n for (const key of ['x', 'y', 'width', 'height'] as const) {\n const value = geometry[key]\n // A container whose size no arithmetic can use makes Yoga answer NaN for a child's place\n // (BASELINE alignment in a wrap is one); the layer stays where it was.\n if (value === undefined || !Number.isFinite(value) || value === node[key]) continue\n changes[key] = value\n }\n const resized = changes.width !== undefined || changes.height !== undefined\n const outlines = resized\n ? shapeGeometryChanges(node, changes.width ?? node.width, changes.height ?? node.height)\n : {}\n if (Object.keys(changes).length + Object.keys(outlines).length > 0) {\n graph.updateNode(id, { ...changes, ...outlines })\n }\n if (!CONSTRAINT_PARENT_TYPES.has(node.type)) return\n // Laying out what a file holds, as a page opens or its fonts arrive, resizes a frame only where\n // our layout differs from the one the file saved; its children keep the places it saved.\n if (graph.isApplyingDerivedLayout && !constrained) return\n if (from.width !== node.width || from.height !== node.height) {\n constrainChildren(graph, node, from, computeLayout)\n rememberPlacedSize(node)\n }\n}\n\n/**\n * The size each Hug frame's constrained children were last placed for by layout. Keyed by the\n * node, so a deleted frame's entry goes with it and a restored one starts afresh.\n */\nconst huggedSizes = new WeakMap<SceneNode, { width: number; height: number }>()\n\n/**\n * Records a frame's size as the one its constrained children were placed for, after a rescale\n * scaled them with it: the next hug moves them from the scaled size, not twice from the old one.\n */\nexport function restoredHuggedSize(frame: SceneNode): void {\n if (huggedSizes.has(frame)) huggedSizes.set(frame, { width: frame.width, height: frame.height })\n}\n\nfunction rememberPlacedSize(frame: SceneNode): void {\n const placed = huggedSizes.get(frame)\n if (!placed) return\n placed.width = frame.width\n placed.height = frame.height\n}\n\nconst CONSTRAINT_PARENT_TYPES: ReadonlySet<SceneNode['type']> = new Set([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/**\n * Places the children of a frame layout resized by their constraints: every child of a frame\n * without auto layout, and those that ignore an auto layout, as Figma keeps a badge pinned to the\n * right of a Hug button while its label grows. A child it resizes places its own children, and\n * lays out again when it has auto layout.\n */\nfunction constrainChildren(\n graph: SceneGraph,\n frame: SceneNode,\n before: { width: number; height: number },\n computeLayout: ComputeLayoutFn\n): void {\n for (const child of graph.getChildren(frame.id)) {\n if (frame.layoutMode !== 'NONE' && child.layoutPositioning !== 'ABSOLUTE') continue\n const size = { width: child.width, height: child.height }\n writeLayoutGeometry(\n graph,\n child.id,\n layoutConstrainedChildRect(\n child,\n before,\n frame,\n child.horizontalConstraint,\n child.verticalConstraint,\n enforcedAspectRatio(child)\n ),\n computeLayout,\n undefined,\n true\n )\n const resized = child.width !== size.width || child.height !== size.height\n if (resized && child.layoutMode !== 'NONE') computeLayout(graph, child.id)\n }\n}\n\n/**\n * The size a frame's constrained children move from as it hugs, or null when it hugs no axis.\n * An editor that resizes a Hug frame places its children for the size it sets, which layout then\n * hugs back, as when a parent stretches it; its children move only from the size it last hugged\n * to. An axis it does not hug keeps the size it has.\n */\nfunction hugStart(frame: SceneNode): { width: number; height: number } | null {\n const row = frame.layoutMode === 'HORIZONTAL'\n const hugsWidth = (row ? frame.primaryAxisSizing : frame.counterAxisSizing) === 'HUG'\n const hugsHeight = (row ? frame.counterAxisSizing : frame.primaryAxisSizing) === 'HUG'\n if (!hugsWidth && !hugsHeight) {\n huggedSizes.delete(frame)\n return null\n }\n const hugged = huggedSizes.get(frame)\n return {\n width: hugsWidth && hugged ? hugged.width : frame.width,\n height: hugsHeight && hugged ? hugged.height : frame.height\n }\n}\n\n/**\n * The smallest size a layout frame holds: what Yoga computed for it, or the room its padding and\n * included inside strokes take, which Yoga's fixed size does not count. A saved frame nobody\n * edited holds exactly what Yoga computed, so opening a file never grows it.\n */\nfunction heldFrameSize(\n frame: SceneNode,\n yogaNode: YogaNode,\n holdsSavedSize: boolean\n): { width: number; height: number } {\n const insets = holdsSavedSize ? null : contentInsetsSize(frame)\n return {\n width: Math.max(yogaNode.getComputedWidth(), insets?.width ?? 0),\n height: Math.max(yogaNode.getComputedHeight(), insets?.height ?? 0)\n }\n}\n\n/** A grid's size: automatic rows take their height, and a hugged axis takes what Yoga computed. */\nfunction applyGridFrameSize(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n computeLayout: ComputeLayoutFn\n): void {\n const updates: LayoutGeometry = {}\n const holds = keepsSavedFrameSize(graph, frame)\n const held = heldFrameSize(frame, yogaNode, holds)\n if (frame.primaryAxisSizing === 'HUG') updates.width = held.width\n else if (!holds && held.width > frame.width) updates.width = held.width\n const automaticRows = frame.gridTemplateRows.length === 0\n if (automaticRows || frame.counterAxisSizing === 'HUG') updates.height = held.height\n else if (!holds && held.height > frame.height) updates.height = held.height\n writeLayoutGeometry(graph, frame.id, updates, computeLayout)\n}\n\n/** The sizes a flex frame takes: a fixed one grows to its padding, and a hugged one hugs. */\nfunction flexFrameSizeUpdates(\n frame: SceneNode,\n held: { width: number; height: number },\n computed: (axis: 'width' | 'height') => number,\n derived: Partial<Record<'width' | 'height', number>> | null,\n keepsSavedSize: (axis: 'width' | 'height') => boolean,\n holdsSavedSize: boolean\n): LayoutGeometry {\n const primary = frame.layoutMode === 'HORIZONTAL' ? 'width' : 'height'\n const counter = primary === 'width' ? 'height' : 'width'\n const updates: LayoutGeometry = {}\n // The padding floor is an edit: a saved frame nobody touched keeps the size it has.\n if (frame.primaryAxisSizing === 'FIXED' && !holdsSavedSize && held[primary] > frame[primary]) {\n updates[primary] = held[primary]\n }\n if (frame.counterAxisSizing === 'FIXED' && !holdsSavedSize && held[counter] > frame[counter]) {\n updates[counter] = held[counter]\n }\n if (frame.primaryAxisSizing === 'HUG') {\n const floor = holdsSavedSize ? 0 : held[primary]\n updates[primary] = Math.max(derived?.[primary] ?? computed(primary), floor)\n }\n if (frame.counterAxisSizing === 'HUG') {\n const floor = holdsSavedSize ? 0 : held[counter]\n updates[counter] = Math.max(\n keepsSavedSize(counter) ? frame[counter] : (derived?.[counter] ?? computed(counter)),\n floor\n )\n }\n return updates\n}\n\nfunction applyFrameSize(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n keepsSaved: boolean,\n computeLayout: ComputeLayoutFn\n): void {\n if (frame.layoutMode === 'GRID') {\n applyGridFrameSize(graph, frame, yogaNode, computeLayout)\n return\n }\n\n const before = hugStart(frame)\n const computed = (axis: 'width' | 'height') =>\n axis === 'width' ? yogaNode.getComputedWidth() : yogaNode.getComputedHeight()\n const holds = keepsSavedFrameSize(graph, frame)\n const updates = flexFrameSizeUpdates(\n frame,\n heldFrameSize(frame, yogaNode, holds),\n computed,\n keepsSaved ? frame.derivedLayout : null,\n (axis) => keepsSaved && preservesImportedHugCrossSize(graph, frame, axis),\n holds\n )\n if (Object.keys(updates).length === 0) return\n writeLayoutGeometry(graph, frame.id, updates, computeLayout, before ?? undefined)\n if (before) huggedSizes.set(frame, { width: frame.width, height: frame.height })\n}\n\nfunction computedChildPosition(\n child: SceneNode,\n yogaChild: YogaNode,\n axis: 'x' | 'y',\n origin: number,\n preservesImportedGeometry: boolean,\n keepsSaved: boolean\n): number {\n if (preservesImportedGeometry) return child[axis]\n const computed =\n origin + (axis === 'x' ? yogaChild.getComputedLeft() : yogaChild.getComputedTop())\n if (child.type === 'INSTANCE' || !keepsSaved) return computed\n return child.derivedLayout?.[axis] ?? computed\n}\n\nfunction preservesStaleImportedTextSize(child: SceneNode, axis: 'width' | 'height'): boolean {\n const derivedSize = child.derivedLayout?.[axis]\n return (\n child.type === 'TEXT' &&\n child.source.format === 'fig' &&\n derivedSize !== undefined &&\n Math.abs(child[axis] - derivedSize) > 0.001\n )\n}\n\nfunction computedChildSize(\n child: SceneNode,\n yogaChild: YogaNode,\n axis: 'width' | 'height',\n preservesImportedFrameGeometry: boolean,\n keepsSaved: boolean\n): number {\n if (\n preservesImportedFrameGeometry ||\n (keepsSaved && preservesStaleImportedTextSize(child, axis))\n ) {\n return child[axis]\n }\n const computed = axis === 'width' ? yogaChild.getComputedWidth() : yogaChild.getComputedHeight()\n if (child.type === 'TEXT' && child.source.format === 'fig') {\n return computed > 0 ? computed : child[axis]\n }\n if (!keepsSaved) return computed\n return child.derivedLayout?.[axis] ?? computed\n}\n\nfunction updateChildFromYoga(\n graph: SceneGraph,\n frame: SceneNode,\n child: SceneNode,\n yogaChild: YogaNode,\n origin: Vector,\n keepsSaved: boolean,\n computeLayout: ComputeLayoutFn\n): void {\n if (!child.visible || child.layoutPositioning === 'ABSOLUTE') return\n\n const savedFig = keepsSaved && child.source.format === 'fig'\n const preservesImportedFrameGeometry =\n savedFig && frame.source.format === 'fig' && (child.type === 'FRAME' || child.type === 'LINE')\n const preservesImportedPosition =\n preservesImportedFrameGeometry || (savedFig && Math.abs(child.rotation) > 0.001)\n writeLayoutGeometry(\n graph,\n child.id,\n {\n x: computedChildPosition(\n child,\n yogaChild,\n 'x',\n origin.x,\n preservesImportedPosition,\n keepsSaved\n ),\n y: computedChildPosition(\n child,\n yogaChild,\n 'y',\n origin.y,\n preservesImportedPosition,\n keepsSaved\n ),\n width: computedChildSize(\n child,\n yogaChild,\n 'width',\n preservesImportedFrameGeometry,\n keepsSaved\n ),\n height: computedChildSize(\n child,\n yogaChild,\n 'height',\n preservesImportedFrameGeometry,\n keepsSaved\n )\n },\n computeLayout\n )\n}\n\nfunction preservesImportedInstanceInternals(child: SceneNode): boolean {\n return child.type === 'INSTANCE' && child.source.format === 'fig'\n}\n\nfunction recomputeGridChild(\n graph: SceneGraph,\n child: SceneNode,\n computeLayout: ComputeLayoutFn\n): void {\n const updated = graph.getNode(child.id)\n if (!updated || updated.layoutMode === 'NONE') return\n\n const savedPrimary = updated.primaryAxisSizing\n const savedCounter = updated.counterAxisSizing\n const updates: Partial<SceneNode> = {}\n\n if (savedPrimary === 'HUG') updates.primaryAxisSizing = 'FIXED'\n if (savedCounter === 'HUG') updates.counterAxisSizing = 'FIXED'\n if (Object.keys(updates).length > 0) graph.updateNode(child.id, updates)\n\n computeLayout(graph, child.id)\n\n const restore: Partial<SceneNode> = {}\n if (updates.primaryAxisSizing) restore.primaryAxisSizing = savedPrimary\n if (updates.counterAxisSizing) restore.counterAxisSizing = savedCounter\n if (Object.keys(restore).length > 0) graph.updateNode(child.id, restore)\n}\n\nexport function applyYogaLayout(\n graph: SceneGraph,\n frame: SceneNode,\n yogaNode: YogaNode,\n computeLayout: ComputeLayoutFn\n): void {\n const keepsSaved = keepsSavedLayout(graph, frame)\n applyFrameSize(graph, frame, yogaNode, keepsSaved, computeLayout)\n\n const children = graph.getChildren(frame.id)\n const box = laidOutFlowBox(yogaNode, frame)\n let yogaIndex = 0\n for (const child of children) {\n if (yogaIndex >= box.node.getChildCount()) continue\n const yogaChild = box.node.getChild(yogaIndex)\n yogaIndex++\n\n updateChildFromYoga(graph, frame, child, yogaChild, box.origin, keepsSaved, computeLayout)\n\n if (!child.visible) continue\n if (preservesImportedInstanceInternals(child)) continue\n\n if (usesDetachedDerivedLayout(graph, child)) {\n computeLayout(graph, child.id)\n continue\n }\n\n if (child.layoutMode !== 'NONE') {\n if (child.layoutMode === 'GRID' && child.layoutPositioning !== 'ABSOLUTE') {\n computeLayout(graph, child.id)\n } else if (frame.layoutMode === 'GRID' && child.layoutPositioning !== 'ABSOLUTE') {\n recomputeGridChild(graph, child, computeLayout)\n } else {\n applyYogaLayout(graph, child, yogaChild, computeLayout)\n }\n }\n }\n}\n"],"mappings":";;;;;;AAaA,SAAS,8BACP,OACA,OACA,MACS;CACT,IAAI,MAAM,OAAO,WAAW,SAAS,MAAM,sBAAsB,OAAO,OAAO;CAC/E,MAAM,eAAe,SAAS,UAAU,aAAa;CACrD,IAAI,MAAM,eAAe,cAAc,OAAO;CAC9C,OAAO,MACJ,YAAY,MAAM,EAAE,CAAC,CACrB,MACE,UAAU,MAAM,oBAAoB,aAAa,MAAM,gBAAgB,UAAU,KAAA,CACpF;AACJ;;;;;;;AAUA,SAAS,oBACP,OACA,IACA,UACA,eACA,QACA,cAAc,OACR;CACN,MAAM,OAAO,MAAM,QAAQ,EAAE;CAC7B,IAAI,CAAC,MAAM;CACX,MAAM,OAAO,UAAU;EAAE,OAAO,KAAK;EAAO,QAAQ,KAAK;CAAO;CAChE,MAAM,UAA0B,CAAC;CACjC,KAAK,MAAM,OAAO;EAAC;EAAK;EAAK;EAAS;CAAQ,GAAY;EACxD,MAAM,QAAQ,SAAS;EAGvB,IAAI,UAAU,KAAA,KAAa,CAAC,OAAO,SAAS,KAAK,KAAK,UAAU,KAAK,MAAM;EAC3E,QAAQ,OAAO;CACjB;CAEA,MAAM,WADU,QAAQ,UAAU,KAAA,KAAa,QAAQ,WAAW,KAAA,IAE9D,qBAAqB,MAAM,QAAQ,SAAS,KAAK,OAAO,QAAQ,UAAU,KAAK,MAAM,IACrF,CAAC;CACL,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,OAAO,KAAK,QAAQ,CAAC,CAAC,SAAS,GAC/D,MAAM,WAAW,IAAI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