@pairdraw/core 0.16.2 → 0.18.0
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/outline-stroke.d.ts.map +1 -1
- package/dist/canvas/outline-stroke.js.map +1 -1
- package/dist/canvas/overlays/prototype.d.ts +2 -5
- package/dist/canvas/overlays/prototype.d.ts.map +1 -1
- package/dist/canvas/overlays/prototype.js +3 -19
- package/dist/canvas/overlays/prototype.js.map +1 -1
- package/dist/canvas/renderer/fonts.js +2 -1
- package/dist/canvas/renderer/fonts.js.map +1 -1
- package/dist/canvas/renderer.d.ts +4 -0
- package/dist/canvas/renderer.d.ts.map +1 -1
- package/dist/canvas/renderer.js +4 -0
- package/dist/canvas/renderer.js.map +1 -1
- package/dist/canvas/rulers.js +1 -1
- package/dist/canvas/rulers.js.map +1 -1
- package/dist/canvas/scene.d.ts.map +1 -1
- package/dist/canvas/scene.js +61 -37
- package/dist/canvas/scene.js.map +1 -1
- package/dist/canvas/text/font-families.d.ts +4 -3
- package/dist/canvas/text/font-families.d.ts.map +1 -1
- package/dist/canvas/text/font-families.js +8 -7
- package/dist/canvas/text/font-families.js.map +1 -1
- package/dist/canvas/text/index.d.ts.map +1 -1
- package/dist/canvas/text/index.js +1 -1
- package/dist/canvas/text/index.js.map +1 -1
- package/dist/canvas/text/paragraph/index.js +2 -2
- package/dist/canvas/text/paragraph/index.js.map +1 -1
- package/dist/canvas/text/placed.js +2 -2
- package/dist/canvas/text/placed.js.map +1 -1
- package/dist/canvas/text/renderer.d.ts +2 -0
- package/dist/canvas/text/renderer.d.ts.map +1 -1
- package/dist/clipboard/pairdraw.d.ts.map +1 -1
- package/dist/clipboard/pairdraw.js +53 -7
- package/dist/clipboard/pairdraw.js.map +1 -1
- package/dist/design-jsx/preview/picture.js +6 -1
- package/dist/design-jsx/preview/picture.js.map +1 -1
- package/dist/design-jsx/renderer.d.ts.map +1 -1
- package/dist/editor/alignment.d.ts.map +1 -1
- package/dist/editor/alignment.js +35 -27
- package/dist/editor/alignment.js.map +1 -1
- package/dist/editor/bridges/undo.d.ts +1 -1
- package/dist/editor/clipboard/detach.d.ts.map +1 -1
- package/dist/editor/clipboard/detach.js +3 -3
- package/dist/editor/clipboard/detach.js.map +1 -1
- package/dist/editor/clipboard/paste/properties.d.ts.map +1 -1
- package/dist/editor/clipboard/paste/properties.js +3 -1
- package/dist/editor/clipboard/paste/properties.js.map +1 -1
- package/dist/editor/create.d.ts +1 -1
- package/dist/editor/structure.d.ts.map +1 -1
- package/dist/editor/structure.js +3 -1
- package/dist/editor/structure.js.map +1 -1
- package/dist/editor/viewport.js +2 -2
- package/dist/editor/viewport.js.map +1 -1
- package/dist/figma-api/index.d.ts +43 -8
- package/dist/figma-api/index.d.ts.map +1 -1
- package/dist/figma-api/index.js +48 -6
- package/dist/figma-api/index.js.map +1 -1
- package/dist/figma-api/serialization.js +10 -0
- package/dist/figma-api/serialization.js.map +1 -1
- package/dist/figma-api/text/bindings.d.ts.map +1 -1
- package/dist/figma-api/text/bindings.js +20 -8
- package/dist/figma-api/text/bindings.js.map +1 -1
- package/dist/figma-api/text/index.js +1 -1
- package/dist/geometry/connectors.js +2 -14
- package/dist/geometry/connectors.js.map +1 -1
- package/dist/geometry/index.d.ts +2 -2
- package/dist/geometry/scene.d.ts +3 -1
- package/dist/geometry/scene.d.ts.map +1 -1
- package/dist/geometry/scene.js +16 -1
- package/dist/geometry/scene.js.map +1 -1
- package/dist/geometry/types.d.ts +7 -1
- package/dist/geometry/types.d.ts.map +1 -1
- package/dist/io/formats/drawio/export.d.ts.map +1 -1
- package/dist/io/formats/drawio/export.js +10 -0
- package/dist/io/formats/drawio/export.js.map +1 -1
- package/dist/io/formats/drawio/index.d.ts.map +1 -1
- package/dist/io/formats/drawio/index.js +32 -1
- package/dist/io/formats/drawio/index.js.map +1 -1
- package/dist/io/formats/drawio/shapes.d.ts +10 -5
- package/dist/io/formats/drawio/shapes.d.ts.map +1 -1
- package/dist/io/formats/drawio/shapes.js +10 -6
- package/dist/io/formats/drawio/shapes.js.map +1 -1
- package/dist/io/formats/drawio/warnings.d.ts +11 -0
- package/dist/io/formats/drawio/warnings.d.ts.map +1 -0
- package/dist/io/formats/drawio/warnings.js +23 -0
- package/dist/io/formats/drawio/warnings.js.map +1 -0
- package/dist/io/formats/pdf/dom.d.ts +10 -1
- package/dist/io/formats/pdf/dom.d.ts.map +1 -1
- package/dist/io/formats/pdf/dom.js +31 -1
- package/dist/io/formats/pdf/dom.js.map +1 -1
- package/dist/io/formats/pdf/export.js +3 -2
- package/dist/io/formats/pdf/export.js.map +1 -1
- package/dist/io/formats/raster/headless.d.ts +2 -2
- package/dist/io/formats/raster/headless.d.ts.map +1 -1
- package/dist/io/formats/raster/headless.js +2 -2
- package/dist/io/formats/raster/headless.js.map +1 -1
- package/dist/io/formats/raster/render.d.ts +1 -1
- package/dist/io/formats/raster/render.d.ts.map +1 -1
- package/dist/io/formats/raster/render.js +2 -2
- package/dist/io/formats/raster/render.js.map +1 -1
- package/dist/io/formats.d.ts.map +1 -1
- package/dist/io/formats.js +6 -6
- package/dist/io/formats.js.map +1 -1
- package/dist/io/registry.d.ts +2 -0
- package/dist/io/registry.d.ts.map +1 -1
- package/dist/io/registry.js +5 -0
- package/dist/io/registry.js.map +1 -1
- package/dist/io/types.d.ts +2 -0
- package/dist/io/types.d.ts.map +1 -1
- package/dist/library/snapshot.d.ts.map +1 -1
- package/dist/library/snapshot.js +1 -0
- package/dist/library/snapshot.js.map +1 -1
- package/dist/lint/linter.d.ts.map +1 -1
- package/dist/lint/linter.js +11 -2
- package/dist/lint/linter.js.map +1 -1
- package/dist/rpc/variables-command.d.ts.map +1 -1
- package/dist/rpc/variables-command.js +4 -2
- package/dist/rpc/variables-command.js.map +1 -1
- package/dist/text/character-style.d.ts.map +1 -1
- package/dist/text/character-style.js +2 -1
- package/dist/text/character-style.js.map +1 -1
- package/dist/text/coverage.d.ts.map +1 -1
- package/dist/text/coverage.js +6 -3
- package/dist/text/coverage.js.map +1 -1
- package/dist/text/fallbacks.d.ts +8 -2
- package/dist/text/fallbacks.d.ts.map +1 -1
- package/dist/text/fallbacks.js +73 -7
- package/dist/text/fallbacks.js.map +1 -1
- package/dist/text/font/manager.d.ts +14 -6
- package/dist/text/font/manager.d.ts.map +1 -1
- package/dist/text/font/manager.js +40 -14
- package/dist/text/font/manager.js.map +1 -1
- package/dist/text/index.d.ts +2 -2
- package/dist/text/index.js +3 -3
- package/dist/text/outlines.js +1 -1
- package/dist/text/outlines.js.map +1 -1
- package/dist/text/path/caret.d.ts +2 -4
- package/dist/text/path/caret.d.ts.map +1 -1
- package/dist/text/path/caret.js.map +1 -1
- package/dist/text/prepare.d.ts +5 -1
- package/dist/text/prepare.d.ts.map +1 -1
- package/dist/text/prepare.js +19 -2
- package/dist/text/prepare.js.map +1 -1
- package/dist/text/web-font/assets.d.ts.map +1 -1
- package/dist/text/web-font/assets.js +13 -21
- package/dist/text/web-font/assets.js.map +1 -1
- package/dist/text/web-font/resolver.d.ts.map +1 -1
- package/dist/text/web-font/resolver.js +4 -1
- package/dist/text/web-font/resolver.js.map +1 -1
- package/dist/tools/create/components.d.ts +2 -1
- package/dist/tools/create/components.d.ts.map +1 -1
- package/dist/tools/create/components.js +27 -1
- package/dist/tools/create/components.js.map +1 -1
- package/dist/tools/create/icons.d.ts.map +1 -1
- package/dist/tools/create/icons.js +11 -5
- package/dist/tools/create/icons.js.map +1 -1
- package/dist/tools/create/vector.d.ts.map +1 -1
- package/dist/tools/create/vector.js +9 -6
- package/dist/tools/create/vector.js.map +1 -1
- package/dist/tools/create.d.ts +2 -2
- package/dist/tools/create.js +2 -2
- package/dist/tools/modify/effects.d.ts.map +1 -1
- package/dist/tools/modify/effects.js +5 -3
- package/dist/tools/modify/effects.js.map +1 -1
- package/dist/tools/modify/matching.d.ts.map +1 -1
- package/dist/tools/modify/matching.js +9 -6
- package/dist/tools/modify/matching.js.map +1 -1
- package/dist/tools/modify/paint.d.ts.map +1 -1
- package/dist/tools/modify/paint.js +7 -5
- package/dist/tools/modify/paint.js.map +1 -1
- package/dist/tools/modify/text.d.ts.map +1 -1
- package/dist/tools/modify/text.js +28 -8
- package/dist/tools/modify/text.js.map +1 -1
- package/dist/tools/read/libraries.d.ts.map +1 -1
- package/dist/tools/read/libraries.js +20 -8
- package/dist/tools/read/libraries.js.map +1 -1
- package/dist/tools/read/pages.d.ts.map +1 -1
- package/dist/tools/read/pages.js.map +1 -1
- package/dist/tools/registry/extended.d.ts.map +1 -1
- package/dist/tools/registry/extended.js +2 -1
- package/dist/tools/registry/extended.js.map +1 -1
- package/dist/tools/schema.d.ts +24 -5
- package/dist/tools/schema.d.ts.map +1 -1
- package/dist/tools/schema.js +80 -6
- package/dist/tools/schema.js.map +1 -1
- package/dist/tools/structure/batch.d.ts.map +1 -1
- package/dist/tools/structure/batch.js +4 -3
- package/dist/tools/structure/batch.js.map +1 -1
- package/dist/tools/variables/values.d.ts.map +1 -1
- package/dist/tools/variables/values.js +4 -2
- package/dist/tools/variables/values.js.map +1 -1
- package/dist/tools/vector/export.d.ts.map +1 -1
- package/dist/tools/vector/export.js +5 -2
- package/dist/tools/vector/export.js.map +1 -1
- package/package.json +9 -9
- package/src/canvas/outline-stroke.ts +2 -6
- package/src/canvas/overlays/prototype.ts +5 -27
- package/src/canvas/renderer/fonts.ts +2 -1
- package/src/canvas/renderer.ts +4 -0
- package/src/canvas/rulers.ts +1 -1
- package/src/canvas/scene.ts +92 -63
- package/src/canvas/text/font-families.ts +8 -7
- package/src/canvas/text/index.ts +3 -1
- package/src/canvas/text/paragraph/index.ts +2 -2
- package/src/canvas/text/placed.ts +2 -2
- package/src/canvas/text/renderer.ts +2 -0
- package/src/clipboard/pairdraw.ts +51 -7
- package/src/design-jsx/preview/picture.ts +8 -2
- package/src/editor/alignment.ts +33 -29
- package/src/editor/clipboard/detach.ts +9 -3
- package/src/editor/clipboard/paste/properties.ts +3 -1
- package/src/editor/structure.ts +3 -1
- package/src/editor/viewport.ts +2 -2
- package/src/figma-api/index.ts +90 -9
- package/src/figma-api/serialization.ts +14 -0
- package/src/figma-api/text/bindings.ts +26 -8
- package/src/geometry/connectors.ts +2 -12
- package/src/geometry/index.ts +1 -1
- package/src/geometry/scene.ts +19 -0
- package/src/geometry/types.ts +8 -0
- package/src/io/formats/drawio/export.ts +11 -0
- package/src/io/formats/drawio/index.ts +36 -1
- package/src/io/formats/drawio/shapes.ts +13 -9
- package/src/io/formats/drawio/warnings.ts +27 -0
- package/src/io/formats/pdf/dom.ts +29 -0
- package/src/io/formats/pdf/export.ts +3 -2
- package/src/io/formats/raster/headless.ts +10 -3
- package/src/io/formats/raster/render.ts +4 -2
- package/src/io/formats.ts +8 -10
- package/src/io/registry.ts +12 -0
- package/src/io/types.ts +2 -0
- package/src/library/snapshot.ts +1 -0
- package/src/lint/linter.ts +12 -2
- package/src/rpc/variables-command.ts +6 -5
- package/src/text/character-style.ts +8 -4
- package/src/text/coverage.ts +17 -2
- package/src/text/fallbacks.ts +81 -7
- package/src/text/font/manager.ts +50 -17
- package/src/text/outlines.ts +1 -1
- package/src/text/path/caret.ts +3 -4
- package/src/text/prepare.ts +34 -2
- package/src/text/web-font/assets.ts +11 -15
- package/src/text/web-font/resolver.ts +7 -1
- package/src/tools/create/components.ts +33 -0
- package/src/tools/create/icons.ts +13 -5
- package/src/tools/create/vector.ts +16 -6
- package/src/tools/create.ts +1 -0
- package/src/tools/modify/effects.ts +11 -4
- package/src/tools/modify/matching.ts +10 -6
- package/src/tools/modify/paint.ts +13 -5
- package/src/tools/modify/text.ts +53 -20
- package/src/tools/read/libraries.ts +35 -11
- package/src/tools/read/pages.ts +1 -0
- package/src/tools/registry/extended.ts +2 -0
- package/src/tools/schema.ts +109 -5
- package/src/tools/structure/batch.ts +10 -5
- package/src/tools/variables/values.ts +6 -3
- package/src/tools/vector/export.ts +5 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scene.js","names":[],"sources":["../../src/geometry/scene.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n getAxisAlignedWorldBounds,\n getNodeLocalMatrix,\n getNodeRotationOrigin,\n getWorldHandles,\n getWorldMatrix\n} from '@pairdraw/scene-graph/coordinate'\nimport Matrix from '@pairdraw/scene-graph/matrix'\nimport type { Vector, Rect } from '@pairdraw/scene-graph/primitives'\n\nimport type { RotationPreview, ViewportTransform } from './types'\n\nexport function projectedNode(node: SceneNode, preview?: RotationPreview | null): SceneNode {\n return node.id === preview?.nodeId ? { ...node, rotation: preview.angle } : node\n}\n\n/** Shares the scene graph's pivot/reflection convention; excludes separately applied x/y. */\nexport function nodeOrientationMatrix(node: SceneNode, preview?: RotationPreview | null) {\n return getNodeLocalMatrix(projectedNode(node, preview), { x: 0, y: 0 })\n}\n\nexport function viewportMatrix(viewport: ViewportTransform) {\n return Matrix.multiply(\n Matrix.translated(viewport.panX, viewport.panY),\n Matrix.scaled(viewport.zoom, viewport.zoom)\n )\n}\n\n/** A read-only view for one draw or input operation. Recreate when the preview changes. */\nexport function createSceneGeometry(graph: SceneGraph, preview?: RotationPreview | null) {\n const node = (source: SceneNode) => projectedNode(source, preview)\n const reader = {\n getNode(id: string) {\n const source = graph.getNode(id)\n return source ? node(source) : undefined\n }\n }\n const worldMatrix = (source: SceneNode) => getWorldMatrix(node(source), reader)\n const screenMatrix = (source: SceneNode, viewport: ViewportTransform) =>\n Matrix.multiply(viewportMatrix(viewport), worldMatrix(source))\n\n function toLocal(source: SceneNode, point: Vector): Vector | null {\n const inverse = Matrix.invert(worldMatrix(source))\n return inverse ? Matrix.mapPoint(inverse, point) : null\n }\n\n function screenToLocal(\n source: SceneNode,\n point: Vector,\n viewport: ViewportTransform\n ): Vector | null {\n const inverse = Matrix.invert(screenMatrix(source, viewport))\n return inverse ? Matrix.mapPoint(inverse, point) : null\n }\n\n function reflections(source: SceneNode): Vector {\n let current: SceneNode | undefined = node(source)\n let x = 1\n let y = 1\n while (current) {\n if (current.flipX) x *= -1\n if (current.flipY) y *= -1\n current = current.parentId ? reader.getNode(current.parentId) : undefined\n }\n return { x, y }\n }\n\n return {\n node,\n reflections,\n worldMatrix,\n screenMatrix,\n toLocal,\n screenToLocal,\n localMatrix: (source: SceneNode) => getNodeLocalMatrix(node(source)),\n toWorld: (source: SceneNode, point: Vector) => Matrix.mapPoint(worldMatrix(source), point),\n toScreen: (source: SceneNode, point: Vector, viewport: ViewportTransform) =>\n Matrix.mapPoint(screenMatrix(source, viewport), point),\n bounds: (source: SceneNode) => getAxisAlignedWorldBounds(node(source), reader),\n handles: (source: SceneNode, rect?: Rect) => getWorldHandles(node(source), reader, rect),\n direction(source: SceneNode, vector: Vector): Vector {\n const m = worldMatrix(source)\n return { x: m[0] * vector.x + m[1] * vector.y, y: m[3] * vector.x + m[4] * vector.y }\n },\n /** Same world-space rectangle, with reflected axes removed for readable labels. */\n unreflectedWorldMatrix(source: SceneNode) {\n const world = worldMatrix(source)\n const { x: flipX, y: flipY } = reflections(source)\n const origin = Matrix.mapPoint(world, {\n x: flipX < 0 ? source.width : 0,\n y: flipY < 0 ? source.height : 0\n })\n world[0] *= flipX\n world[3] *= flipX\n world[1] *= flipY\n world[4] *= flipY\n world[2] = origin.x\n world[5] = origin.y\n return world\n },\n rotationOrigin(source: SceneNode): Vector {\n return Matrix.mapPoint(worldMatrix(source), getNodeRotationOrigin(node(source)))\n },\n rotationDirection(source: SceneNode): 1 | -1 {\n const m = worldMatrix(source)\n return m[0] * m[4] - m[1] * m[3] < 0 ? -1 : 1\n },\n rotation(source: SceneNode) {\n const world = worldMatrix(source)\n return (Math.atan2(world[3], world[0]) * 180) / Math.PI\n }\n }\n}\n\nexport type SceneGeometry = ReturnType<typeof createSceneGeometry>\n"],"mappings":";;;AAaA,SAAgB,cAAc,MAAiB,SAA6C;CAC1F,OAAO,KAAK,OAAO,SAAS,SAAS;EAAE,GAAG;EAAM,UAAU,QAAQ;CAAM,IAAI;AAC9E;;AAGA,SAA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[],"sources":["../../src/geometry/scene.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n getAxisAlignedWorldBounds,\n getNodeLocalMatrix,\n getNodeRotationOrigin,\n getWorldHandles,\n getWorldMatrix\n} from '@pairdraw/scene-graph/coordinate'\nimport Matrix from '@pairdraw/scene-graph/matrix'\nimport type { Vector, Rect } from '@pairdraw/scene-graph/primitives'\n\nimport type { RotationPreview, ViewportTransform } from './types'\n\nexport function projectedNode(node: SceneNode, preview?: RotationPreview | null): SceneNode {\n return node.id === preview?.nodeId ? { ...node, rotation: preview.angle } : node\n}\n\n/** Shares the scene graph's pivot/reflection convention; excludes separately applied x/y. */\nexport function nodeOrientationMatrix(node: SceneNode, preview?: RotationPreview | null) {\n return getNodeLocalMatrix(projectedNode(node, preview), { x: 0, y: 0 })\n}\n\nexport function viewportMatrix(viewport: ViewportTransform) {\n return Matrix.multiply(\n Matrix.translated(viewport.panX, viewport.panY),\n Matrix.scaled(viewport.zoom, viewport.zoom)\n )\n}\n\n/** A node's axis-aligned box on screen, around its corners as drawn. */\nexport function nodeScreenBounds(\n graph: SceneGraph,\n node: SceneNode,\n viewport: ViewportTransform,\n preview?: RotationPreview | null\n): Rect {\n const [x0, y0, x1, y1] = Matrix.mapPoints(\n createSceneGeometry(graph, preview).screenMatrix(node, viewport),\n [0, 0, node.width, node.height]\n )\n return {\n x: Math.min(x0, x1),\n y: Math.min(y0, y1),\n width: Math.abs(x1 - x0),\n height: Math.abs(y1 - y0)\n }\n}\n\n/** A read-only view for one draw or input operation. Recreate when the preview changes. */\nexport function createSceneGeometry(graph: SceneGraph, preview?: RotationPreview | null) {\n const node = (source: SceneNode) => projectedNode(source, preview)\n const reader = {\n getNode(id: string) {\n const source = graph.getNode(id)\n return source ? node(source) : undefined\n }\n }\n const worldMatrix = (source: SceneNode) => getWorldMatrix(node(source), reader)\n const screenMatrix = (source: SceneNode, viewport: ViewportTransform) =>\n Matrix.multiply(viewportMatrix(viewport), worldMatrix(source))\n\n function toLocal(source: SceneNode, point: Vector): Vector | null {\n const inverse = Matrix.invert(worldMatrix(source))\n return inverse ? Matrix.mapPoint(inverse, point) : null\n }\n\n function screenToLocal(\n source: SceneNode,\n point: Vector,\n viewport: ViewportTransform\n ): Vector | null {\n const inverse = Matrix.invert(screenMatrix(source, viewport))\n return inverse ? Matrix.mapPoint(inverse, point) : null\n }\n\n function reflections(source: SceneNode): Vector {\n let current: SceneNode | undefined = node(source)\n let x = 1\n let y = 1\n while (current) {\n if (current.flipX) x *= -1\n if (current.flipY) y *= -1\n current = current.parentId ? reader.getNode(current.parentId) : undefined\n }\n return { x, y }\n }\n\n return {\n node,\n reflections,\n worldMatrix,\n screenMatrix,\n toLocal,\n screenToLocal,\n localMatrix: (source: SceneNode) => getNodeLocalMatrix(node(source)),\n toWorld: (source: SceneNode, point: Vector) => Matrix.mapPoint(worldMatrix(source), point),\n toScreen: (source: SceneNode, point: Vector, viewport: ViewportTransform) =>\n Matrix.mapPoint(screenMatrix(source, viewport), point),\n bounds: (source: SceneNode) => getAxisAlignedWorldBounds(node(source), reader),\n handles: (source: SceneNode, rect?: Rect) => getWorldHandles(node(source), reader, rect),\n direction(source: SceneNode, vector: Vector): Vector {\n const m = worldMatrix(source)\n return { x: m[0] * vector.x + m[1] * vector.y, y: m[3] * vector.x + m[4] * vector.y }\n },\n /** Same world-space rectangle, with reflected axes removed for readable labels. */\n unreflectedWorldMatrix(source: SceneNode) {\n const world = worldMatrix(source)\n const { x: flipX, y: flipY } = reflections(source)\n const origin = Matrix.mapPoint(world, {\n x: flipX < 0 ? source.width : 0,\n y: flipY < 0 ? source.height : 0\n })\n world[0] *= flipX\n world[3] *= flipX\n world[1] *= flipY\n world[4] *= flipY\n world[2] = origin.x\n world[5] = origin.y\n return world\n },\n rotationOrigin(source: SceneNode): Vector {\n return Matrix.mapPoint(worldMatrix(source), getNodeRotationOrigin(node(source)))\n },\n rotationDirection(source: SceneNode): 1 | -1 {\n const m = worldMatrix(source)\n return m[0] * m[4] - m[1] * m[3] < 0 ? -1 : 1\n },\n rotation(source: SceneNode) {\n const world = worldMatrix(source)\n return (Math.atan2(world[3], world[0]) * 180) / Math.PI\n }\n }\n}\n\nexport type SceneGeometry = ReturnType<typeof createSceneGeometry>\n"],"mappings":";;;AAaA,SAAgB,cAAc,MAAiB,SAA6C;CAC1F,OAAO,KAAK,OAAO,SAAS,SAAS;EAAE,GAAG;EAAM,UAAU,QAAQ;CAAM,IAAI;AAC9E;;AAGA,SAAgB,sBAAsB,MAAiB,SAAkC;CACvF,OAAO,mBAAmB,cAAc,MAAM,OAAO,GAAG;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC;AACxE;AAEA,SAAgB,eAAe,UAA6B;CAC1D,OAAO,OAAO,SACZ,OAAO,WAAW,SAAS,MAAM,SAAS,IAAI,GAC9C,OAAO,OAAO,SAAS,MAAM,SAAS,IAAI,CAC5C;AACF;;AAGA,SAAgB,iBACd,OACA,MACA,UACA,SACM;CACN,MAAM,CAAC,IAAI,IAAI,IAAI,MAAM,OAAO,UAC9B,oBAAoB,OAAO,OAAO,CAAC,CAAC,aAAa,MAAM,QAAQ,GAC/D;EAAC;EAAG;EAAG,KAAK;EAAO,KAAK;CAAM,CAChC;CACA,OAAO;EACL,GAAG,KAAK,IAAI,IAAI,EAAE;EAClB,GAAG,KAAK,IAAI,IAAI,EAAE;EAClB,OAAO,KAAK,IAAI,KAAK,EAAE;EACvB,QAAQ,KAAK,IAAI,KAAK,EAAE;CAC1B;AACF;;AAGA,SAAgB,oBAAoB,OAAmB,SAAkC;CACvF,MAAM,QAAQ,WAAsB,cAAc,QAAQ,OAAO;CACjE,MAAM,SAAS,EACb,QAAQ,IAAY;EAClB,MAAM,SAAS,MAAM,QAAQ,EAAE;EAC/B,OAAO,SAAS,KAAK,MAAM,IAAI,KAAA;CACjC,EACF;CACA,MAAM,eAAe,WAAsB,eAAe,KAAK,MAAM,GAAG,MAAM;CAC9E,MAAM,gBAAgB,Q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AO,GAAG,UAAU,YAAY,MAAM;GACjD,MAAM,SAAS,OAAO,SAAS,OAAO;IACpC,GAAG,QAAQ,IAAI,OAAO,QAAQ;IAC9B,GAAG,QAAQ,IAAI,OAAO,SAAS;GACjC,CAAC;GACD,MAAM,MAAM;GACZ,MAAM,MAAM;GACZ,MAAM,MAAM;GACZ,MAAM,MAAM;GACZ,MAAM,KAAK,OAAO;GAClB,MAAM,KAAK,OAAO;GAClB,OAAO;EACT;EACA,eAAe,QAA2B;GACxC,OAAO,OAAO,SAAS,YAAY,MAAM,GAAG,sBAAsB,KAAK,MAAM,CAAC,CAAC;EACjF;EACA,kBAAkB,QAA2B;GAC3C,MAAM,IAAI,YAAY,MAAM;GAC5B,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,IAAI,KAAK;EAC9C;EACA,SAAS,QAAmB;GAC1B,MAAM,QAAQ,YAAY,MAAM;GAChC,OAAQ,KAAK,MAAM,MAAM,IAAI,MAAM,EAAE,IAAI,MAAO,KAAK;EACvD;CACF;AACF"}
|
package/dist/geometry/types.d.ts
CHANGED
|
@@ -1,4 +1,10 @@
|
|
|
1
|
+
import { Vector } from "@pairdraw/scene-graph/primitives";
|
|
1
2
|
//#region src/geometry/types.d.ts
|
|
3
|
+
/** A straight segment between two points. */
|
|
4
|
+
interface LineSegment {
|
|
5
|
+
from: Vector;
|
|
6
|
+
to: Vector;
|
|
7
|
+
}
|
|
2
8
|
interface RotationPreview {
|
|
3
9
|
nodeId: string;
|
|
4
10
|
angle: number;
|
|
@@ -9,5 +15,5 @@ interface ViewportTransform {
|
|
|
9
15
|
zoom: number;
|
|
10
16
|
}
|
|
11
17
|
//#endregion
|
|
12
|
-
export { RotationPreview, ViewportTransform };
|
|
18
|
+
export { LineSegment, RotationPreview, ViewportTransform };
|
|
13
19
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/geometry/types.ts"],"mappings":";
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../src/geometry/types.ts"],"mappings":";;;UAGiB;EACf,MAAM;EACN,IAAI;;UAGW;EACf;EACA;;UAGe;EACf;EACA;EACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/export.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"export.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/export.ts"],"mappings":";;;;KAkiBY;EACN;;EACA;EAAgB;;;;;;;;iBAQN,mBAAmB,OAAO,YAAY,QAAQ,qBAAqB"}
|
|
@@ -20,6 +20,10 @@ function style(names, values) {
|
|
|
20
20
|
values: Object.fromEntries(Object.entries(values).filter(([, v]) => v !== void 0))
|
|
21
21
|
};
|
|
22
22
|
}
|
|
23
|
+
/** A layer's name, which draw.io has no field of its own for, so it travels in the style. */
|
|
24
|
+
function nameValues(node) {
|
|
25
|
+
return { pairdrawName: encodeURIComponent(node.name) };
|
|
26
|
+
}
|
|
23
27
|
/** A layer's first visible solid fill, or the first stop of a gradient, as draw.io's colour. */
|
|
24
28
|
function fillColor(node) {
|
|
25
29
|
const fill = node.fills.find((paint) => paint.visible);
|
|
@@ -248,6 +252,7 @@ var PageWriter = class {
|
|
|
248
252
|
style: style(["text"], {
|
|
249
253
|
html: "1",
|
|
250
254
|
whiteSpace: "wrap",
|
|
255
|
+
...nameValues(node),
|
|
251
256
|
...placedValues(placement),
|
|
252
257
|
...fontValues(node)
|
|
253
258
|
}),
|
|
@@ -300,6 +305,7 @@ var PageWriter = class {
|
|
|
300
305
|
style: style([], {
|
|
301
306
|
container: "1",
|
|
302
307
|
html: "1",
|
|
308
|
+
...nameValues(node),
|
|
303
309
|
...paintValues(node),
|
|
304
310
|
...placedValues(placement)
|
|
305
311
|
}),
|
|
@@ -311,7 +317,10 @@ var PageWriter = class {
|
|
|
311
317
|
kind: "vertex",
|
|
312
318
|
value: "",
|
|
313
319
|
style: style(node.type === "ELLIPSE" ? ["ellipse"] : [], {
|
|
320
|
+
...node.type === "RECTANGLE" ? { pairdrawType: "RECTANGLE" } : {},
|
|
314
321
|
rounded: node.cornerRadius > 0 ? "1" : void 0,
|
|
322
|
+
pairdrawCornerRadius: node.cornerRadius > 0 ? String(node.cornerRadius) : void 0,
|
|
323
|
+
...nameValues(node),
|
|
315
324
|
...placedValues(placement),
|
|
316
325
|
...paintValues(node)
|
|
317
326
|
}),
|
|
@@ -325,6 +334,7 @@ var PageWriter = class {
|
|
|
325
334
|
const label = shapeWithTextLabel(this.graph, node);
|
|
326
335
|
const values = {
|
|
327
336
|
...drawioShapeValues(node.shapeWithTextType),
|
|
337
|
+
...nameValues(node),
|
|
328
338
|
whiteSpace: "wrap",
|
|
329
339
|
html: "1",
|
|
330
340
|
...paintValues(node),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"export.js","names":[],"sources":["../../../../src/io/formats/drawio/export.ts"],"sourcesContent":["import { escapeText } from 'entities'\nimport { fromUint8Array } from 'js-base64'\n\nimport type {\n DrawIOCell,\n DrawIOFile,\n DrawIOGeometry,\n DrawIOPage,\n DrawIOPoint,\n DrawIOStyle\n} from '@pairdraw/drawio'\nimport type { ConnectorEndpoint, SceneGraph, SceneNode, StrokeCap } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport {\n connectorRoute,\n connectorRouteEnds,\n connectorSublayers,\n curveMidpoint\n} from '@pairdraw/scene-graph/connectors'\nimport { getParentWorldMatrix, getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport {\n isGeneratedFrame,\n shapeWithTextLabel,\n stickySublayers\n} from '@pairdraw/scene-graph/generated'\nimport Matrix from '@pairdraw/scene-graph/matrix'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { computeContentBounds } from '#core/io/formats/raster'\nimport { renderNodesToSVG } from '#core/io/formats/svg'\n\nimport { DEFAULT_FONT_FAMILY } from './paint'\nimport { EMPTY_GEOMETRY, placed, placedValues, round, type Placed } from './placement'\nimport { drawioShapeValues } from './shapes'\n\n/** draw.io's id for its root cell and for its one layer, as it numbers new files. */\nconst ROOT_ID = '0'\nconst LAYER_ID = '1'\n\nfunction style(names: string[], values: Record<string, string | undefined>): DrawIOStyle {\n return {\n names,\n values: Object.fromEntries(Object.entries(values).filter(([, v]) => v !== undefined))\n }\n}\n\n/** A layer's first visible solid fill, or the first stop of a gradient, as draw.io's colour. */\nfunction fillColor(node: SceneNode): string {\n const fill = node.fills.find((paint) => paint.visible)\n if (!fill) return 'none'\n if (fill.type === 'SOLID') return colorToHex(fill.color)\n const stop = fill.gradientStops?.at(0)\n return stop ? colorToHex(stop.color) : 'none'\n}\n\n/** A layer's fill, outline, dash, and opacity as style pairs. */\nfunction paintValues(node: SceneNode): Record<string, string | undefined> {\n const stroke = node.strokes.find((paint) => paint.visible)\n const weight = stroke?.weight ?? node.strokeWeight\n const dash = stroke?.dashPattern ?? node.dashPattern\n return {\n fillColor: fillColor(node),\n strokeColor: stroke ? colorToHex(stroke.color) : 'none',\n strokeWidth: stroke && weight !== 1 ? String(weight) : undefined,\n dashed: dash.length > 0 ? '1' : undefined,\n dashPattern: dash.length > 0 ? dash.map((n) => round(n / (weight || 1))).join(' ') : undefined,\n opacity: node.opacity < 1 ? String(Math.round(node.opacity * 100)) : undefined\n }\n}\n\nconst ALIGN: Record<SceneNode['textAlignHorizontal'], string> = {\n LEFT: 'left',\n CENTER: 'center',\n RIGHT: 'right',\n JUSTIFIED: 'left'\n}\nconst VERTICAL_ALIGN: Record<SceneNode['textAlignVertical'], string> = {\n TOP: 'top',\n CENTER: 'middle',\n BOTTOM: 'bottom'\n}\n\n/** A text layer's font and alignment as a label's style pairs. */\nfunction fontValues(text: SceneNode): Record<string, string | undefined> {\n const fill = text.fills.find((paint) => paint.visible && paint.type === 'SOLID')\n const bits =\n (text.fontWeight >= 600 ? 1 : 0) |\n (text.italic ? 2 : 0) |\n (text.textDecoration === 'UNDERLINE' ? 4 : 0)\n return {\n fontSize: String(text.fontSize),\n // The font draw.io's default stands for on import goes back as that default.\n fontFamily: text.fontFamily === DEFAULT_FONT_FAMILY ? undefined : text.fontFamily,\n fontColor: fill ? colorToHex(fill.color) : undefined,\n fontStyle: bits ? String(bits) : undefined,\n align: ALIGN[text.textAlignHorizontal],\n verticalAlign: VERTICAL_ALIGN[text.textAlignVertical]\n }\n}\n\n/**\n * A text layer's characters as an HTML label: each style run in a span that sets what it\n * changes, and a line break for each new line.\n */\nfunction labelHTML(text: SceneNode): string {\n const { text: characters, styleRuns } = text\n let html = ''\n let at = 0\n const plain = (to: number) => {\n html += escapeText(characters.slice(at, to)).replaceAll('\\n', '<br>')\n at = to\n }\n for (const run of [...styleRuns].sort((a, b) => a.start - b.start)) {\n plain(run.start)\n const css: string[] = []\n const { style: s } = run\n if (s.fontWeight !== undefined) css.push(`font-weight: ${s.fontWeight}`)\n if (s.italic !== undefined) css.push(`font-style: ${s.italic ? 'italic' : 'normal'}`)\n if (s.textDecoration)\n css.push(`text-decoration: ${s.textDecoration === 'UNDERLINE' ? 'underline' : 'none'}`)\n if (s.fontSize !== undefined) css.push(`font-size: ${s.fontSize}px`)\n if (s.fontFamily) css.push(`font-family: ${s.fontFamily}`)\n const fill = s.fills?.find((paint) => paint.type === 'SOLID')\n if (fill?.type === 'SOLID') css.push(`color: ${colorToHex(fill.color)}`)\n const inner = escapeText(characters.slice(run.start, run.start + run.length)).replaceAll(\n '\\n',\n '<br>'\n )\n html += css.length > 0 ? `<span style=\"${css.join('; ')}\">${inner}</span>` : inner\n at = run.start + run.length\n }\n plain(characters.length)\n return html\n}\n\n/** A connector line's colour, width, and dash as an edge's style pairs. */\nfunction lineValues(line: SceneNode): Record<string, string | undefined> {\n const stroke = line.strokes.find((paint) => paint.visible)\n const weight = stroke?.weight ?? 1\n const dash = stroke?.dashPattern ?? []\n return {\n strokeColor: stroke ? colorToHex(stroke.color) : 'none',\n strokeWidth: weight !== 1 ? String(weight) : undefined,\n dashed: dash.length > 0 ? '1' : undefined,\n dashPattern: dash.length > 0 ? dash.map((n) => round(n / weight)).join(' ') : undefined\n }\n}\n\n/** FigJam's ends and the draw.io arrowheads that draw them. */\nconst ARROWS: Record<StrokeCap, string> = {\n NONE: 'none',\n ROUND: 'none',\n SQUARE: 'none',\n ARROW_LINES: 'open',\n ARROW_EQUILATERAL: 'classic',\n TRIANGLE_FILLED: 'classic',\n DIAMOND_FILLED: 'diamond',\n CIRCLE_FILLED: 'oval'\n}\n\n/** Where a side magnet pins an end, as shares of the layer's box. */\nconst SIDE_POINTS: Partial<Record<ConnectorEndpoint['magnet'], [number, number]>> = {\n TOP: [0.5, 0],\n RIGHT: [1, 0.5],\n BOTTOM: [0.5, 1],\n LEFT: [0, 0.5]\n}\n\n/** Writes one page's layers as draw.io cells, in drawing order. */\nclass PageWriter {\n readonly cells: DrawIOCell[] = []\n private readonly ids = new Map<string, string>()\n /** Where each edge's line last ran from and to, in draw.io's axes. */\n private readonly drawnEnds = new Map<string, { start: DrawIOPoint; end: DrawIOPoint }>()\n /** Where each vertex's box starts on the page: draw.io measures its cells' boxes from there. */\n private readonly origins = new Map<string, Vector>([[LAYER_ID, { x: 0, y: 0 }]])\n private next = 2\n\n constructor(\n private readonly graph: SceneGraph,\n private readonly pageId: string\n ) {}\n\n private idOf(nodeId: string): string {\n let id = this.ids.get(nodeId)\n if (!id) {\n id = String(this.next++)\n this.ids.set(nodeId, id)\n }\n return id\n }\n\n write(nodeIds: readonly string[]) {\n // Every layer gets its id first, so an edge can name a layer drawn above it.\n const assign = (id: string) => {\n const node = this.graph.getNode(id)\n if (!node) return\n this.idOf(id)\n if (!isGeneratedFrame(node)) for (const child of node.childIds) assign(child)\n }\n // A layer inside another chosen one goes with it, as a cell of its own or drawn in its picture.\n const chosen = new Set(nodeIds)\n const roots = nodeIds.filter((id) => {\n const parentId = this.graph.getNode(id)?.parentId\n return !parentId || !this.graph.closest(parentId, (node) => chosen.has(node.id))\n })\n for (const id of roots) assign(id)\n for (const id of roots) {\n const node = this.graph.getNode(id)\n if (node) this.layer(node, LAYER_ID)\n }\n this.freeStrandedEnds()\n }\n\n /**\n * An edge end joined to a layer that has no cell, such as one left out of a selection or\n * drawn inside a picture, goes as a free point where the line last ran.\n */\n private freeStrandedEnds() {\n const written = new Set(this.cells.map((cell) => cell.id))\n for (const cell of this.cells) {\n const drawn = this.drawnEnds.get(cell.id)\n if (!drawn) continue\n if (!cell.source || !written.has(cell.source)) {\n cell.source = null\n cell.geometry.sourcePoint = drawn.start\n }\n if (!cell.target || !written.has(cell.target)) {\n cell.target = null\n cell.geometry.targetPoint = drawn.end\n }\n }\n }\n\n private push(\n node: SceneNode,\n parent: string,\n cell: Omit<DrawIOCell, 'id' | 'parent' | 'visible' | 'attributes' | 'source' | 'target'> &\n Partial<Pick<DrawIOCell, 'source' | 'target'>>\n ) {\n const id = this.idOf(node.id)\n if (cell.kind === 'vertex') {\n const from = this.originOf(parent)\n this.origins.set(id, { x: from.x + cell.geometry.x, y: from.y + cell.geometry.y })\n }\n this.cells.push({\n id,\n parent,\n visible: node.visible,\n attributes: {},\n source: null,\n target: null,\n ...cell\n })\n }\n\n private originOf(parent: string): Vector {\n return this.origins.get(parent) ?? { x: 0, y: 0 }\n }\n\n private place(node: SceneNode, parent: string): Placed {\n return placed(node, getWorldMatrix(node, this.graph), this.originOf(parent))\n }\n\n /** The box a layer covers on the page, square to it, in its parent cell's axes. */\n private bounds(node: SceneNode, parent: string): DrawIOGeometry {\n const bounds = computeContentBounds(this.graph, [node.id])\n if (!bounds) return this.place(node, parent).geometry\n const from = this.originOf(parent)\n return {\n ...EMPTY_GEOMETRY,\n x: round(bounds.minX - from.x),\n y: round(bounds.minY - from.y),\n width: round(bounds.maxX - bounds.minX),\n height: round(bounds.maxY - bounds.minY)\n }\n }\n\n private children(node: SceneNode) {\n for (const id of node.childIds) {\n const child = this.graph.getNode(id)\n if (child) this.layer(child, this.idOf(node.id))\n }\n }\n\n private layer(node: SceneNode, parent: string) {\n const placement = this.place(node, parent)\n const { geometry } = placement\n switch (node.type) {\n case 'SHAPE_WITH_TEXT':\n return this.shape(node, parent, placement)\n case 'TEXT':\n return this.push(node, parent, {\n kind: 'vertex',\n value: labelHTML(node),\n style: style(['text'], {\n html: '1',\n whiteSpace: 'wrap',\n ...placedValues(placement),\n ...fontValues(node)\n }),\n geometry\n })\n case 'STICKY': {\n const body = stickySublayers(this.graph, node)?.body\n return this.push(node, parent, {\n kind: 'vertex',\n value: body ? labelHTML(body) : '',\n style: style([], {\n whiteSpace: 'wrap',\n html: '1',\n ...paintValues(node),\n strokeColor: 'none',\n align: 'left',\n verticalAlign: 'top',\n spacing: '20',\n ...placedValues(placement),\n fontSize: body ? String(body.fontSize) : undefined\n }),\n geometry\n })\n }\n case 'SECTION':\n this.push(node, parent, {\n kind: 'vertex',\n value: escapeText(node.name),\n style: style(['swimlane'], {\n html: '1',\n startSize: '30',\n ...paintValues(node),\n ...placedValues(placement)\n }),\n geometry\n })\n return this.children(node)\n case 'GROUP':\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style(['group'], {}),\n // A group draws nothing, so it holds what it groups square to the page.\n geometry: this.bounds(node, parent)\n })\n return this.children(node)\n case 'FRAME':\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style([], {\n container: '1',\n html: '1',\n ...paintValues(node),\n ...placedValues(placement)\n }),\n geometry\n })\n return this.children(node)\n case 'RECTANGLE':\n case 'ELLIPSE':\n return this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style(node.type === 'ELLIPSE' ? ['ellipse'] : [], {\n rounded: node.cornerRadius > 0 ? '1' : undefined,\n ...placedValues(placement),\n ...paintValues(node)\n }),\n geometry\n })\n case 'CONNECTOR':\n return this.edge(node, parent)\n default:\n return this.picture(node, parent)\n }\n }\n\n private shape(node: SceneNode, parent: string, placement: Placed) {\n const label = shapeWithTextLabel(this.graph, node)\n const values: Record<string, string | undefined> = {\n ...drawioShapeValues(node.shapeWithTextType),\n whiteSpace: 'wrap',\n html: '1',\n ...paintValues(node),\n ...(label ? fontValues(label) : {})\n }\n let { geometry, rotation } = placement\n // A triangle turned a quarter points the way draw.io's direction says, in the box it fills.\n const mirrored = placement.flipH || placement.flipV\n const quarter =\n !mirrored && Math.abs(rotation) === 90 && node.shapeWithTextType === 'TRIANGLE_UP'\n if (quarter) {\n values.direction = rotation === 90 ? 'east' : 'west'\n geometry = {\n ...geometry,\n x: round(geometry.x + (node.width - node.height) / 2),\n y: round(geometry.y + (node.height - node.width) / 2),\n width: round(node.height),\n height: round(node.width)\n }\n rotation = 0\n }\n // A shape that is draw.io's mirrored one, as a left parallelogram is, mirrors back if the layer is.\n const ownFlipH = values.flipH === '1'\n Object.assign(\n values,\n placedValues({ ...placement, rotation, flipH: placement.flipH !== ownFlipH })\n )\n this.push(node, parent, {\n kind: 'vertex',\n value: label ? labelHTML(label) : '',\n style: style([], values),\n geometry\n })\n }\n\n /** A layer draw.io has no cell for, drawn as the SVG image it exports as, where it covers. */\n private picture(node: SceneNode, parent: string) {\n const svg = renderNodesToSVG(this.graph, this.pageId, [node.id])\n if (!svg) return\n const data = fromUint8Array(new TextEncoder().encode(svg))\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n // draw.io keeps a data URI in its style without `;base64`, which would end the value.\n style: style([], { shape: 'image', image: `data:image/svg+xml,${data}`, aspect: 'fixed' }),\n geometry: this.bounds(node, parent)\n })\n }\n\n private end(\n endpoint: ConnectorEndpoint | null,\n prefix: 'exit' | 'entry'\n ): Record<string, string> {\n const node = endpoint?.nodeId ? this.graph.getNode(endpoint.nodeId) : undefined\n if (!endpoint || !node) return {}\n const side = SIDE_POINTS[endpoint.magnet]\n const point: [number, number] | null =\n side ??\n (endpoint.magnet === 'NONE' || endpoint.magnet === 'ABSOLUTE'\n ? [endpoint.position.x / (node.width || 1), endpoint.position.y / (node.height || 1)]\n : null)\n if (!point) return {}\n return { [`${prefix}X`]: String(round(point[0])), [`${prefix}Y`]: String(round(point[1])) }\n }\n\n /**\n * Where an edge's free ends sit, its bend points, and its label's place along it, with the\n * points carried into draw.io's axes.\n */\n private edgeGeometry(node: SceneNode, parent: string): DrawIOGeometry {\n const toPage = getParentWorldMatrix(\n node.parentId ? this.graph.getNode(node.parentId) : undefined,\n this.graph\n )\n const from = this.originOf(parent)\n const at = (point: Vector) => {\n const mapped = Matrix.mapPoint(toPage, point)\n return { x: round(mapped.x - from.x), y: round(mapped.y - from.y) }\n }\n const drawn = connectorRouteEnds(this.graph, node)\n if (drawn) {\n this.drawnEnds.set(this.idOf(node.id), { start: at(drawn.start), end: at(drawn.end) })\n }\n const position = node.connectorLabelPosition\n const along = position?.section === 'MIDDLE_TO_START' ? -position.offset : position?.offset\n return {\n ...EMPTY_GEOMETRY,\n relative: true,\n x: round(along ?? 0),\n sourcePoint: !node.connectorStart?.nodeId && drawn ? at(drawn.start) : null,\n targetPoint: !node.connectorEnd?.nodeId && drawn ? at(drawn.end) : null,\n points: this.waypoints(node).map(at)\n }\n }\n\n private edge(node: SceneNode, parent: string) {\n // A connector without its line and label is not one draw.io could draw.\n const parts = connectorSublayers(this.graph, node)\n if (!parts) return\n const startId = node.connectorStart?.nodeId\n const endId = node.connectorEnd?.nodeId\n const lineType = node.connectorLineType\n this.push(node, parent, {\n kind: 'edge',\n value: parts.label.text ? labelHTML(parts.label) : '',\n style: style([], {\n edgeStyle: lineType === 'ELBOWED' ? 'orthogonalEdgeStyle' : undefined,\n rounded: lineType === 'ELBOWED' ? '1' : undefined,\n curved: lineType === 'CURVED' ? '1' : undefined,\n html: '1',\n startArrow: ARROWS[node.connectorStartCap],\n endArrow: ARROWS[node.connectorEndCap],\n ...lineValues(parts.line),\n ...this.end(node.connectorStart, 'exit'),\n ...this.end(node.connectorEnd, 'entry'),\n ...fontValues(parts.label)\n }),\n geometry: this.edgeGeometry(node, parent),\n source: startId ? (this.ids.get(startId) ?? null) : null,\n target: endId ? (this.ids.get(endId) ?? null) : null\n })\n }\n\n /**\n * The points a dragged connector bends through, for draw.io to run its edge the same way: an\n * elbow's corners, or the middle of a curve. A connector routing itself leaves draw.io to route.\n */\n private waypoints(node: SceneNode): Vector[] {\n const route = connectorRoute(this.graph, node)\n if (!route) return []\n if (node.connectorLineType === 'CURVED' && node.connectorCurveHandles) {\n const curve = route.pieces.at(0)\n return curve ? [curveMidpoint(curve)] : []\n }\n if (node.connectorLineType !== 'ELBOWED' || node.connectorControlPoints.length === 0) return []\n return route.pieces.slice(0, -1).map((piece) => piece.to)\n }\n}\n\n/** One page of layers as a draw.io page, holding `nodeIds` or every layer on it. */\nfunction pageOf(graph: SceneGraph, pageId: string, nodeIds?: readonly string[]): DrawIOPage {\n const page = graph.getNode(pageId)\n const writer = new PageWriter(graph, pageId)\n writer.write(nodeIds ?? page?.childIds ?? [])\n return {\n id: pageId,\n name: page?.name ?? 'Page',\n attributes: { grid: '1', gridSize: '10' },\n rootId: ROOT_ID,\n layers: [{ id: LAYER_ID, name: '', visible: true, locked: false }],\n cells: writer.cells\n }\n}\n\n/** What a draw.io export holds: whole pages, or some layers of one page. */\nexport type DrawIOExportTarget =\n | { pageIds: readonly string[] }\n | { pageId: string; nodeIds: readonly string[] }\n\n/**\n * Layers as a draw.io file: FigJam shapes as draw.io's shapes of the same meaning, connectors as\n * edges joined to them, bent the way they were dragged, text as text, sections as swimlanes, and\n * frames and groups as containers. A layer draw.io has no cell for goes as an SVG image of\n * itself, so nothing is lost.\n */\nexport function sceneGraphToDrawIO(graph: SceneGraph, target: DrawIOExportTarget): DrawIOFile {\n const pages =\n 'pageIds' in target\n ? target.pageIds.map((pageId) => pageOf(graph, pageId))\n : [pageOf(graph, target.pageId, target.nodeIds)]\n return { pages, unreadable: [] }\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,MAAM,UAAU;AAChB,MAAM,WAAW;AAEjB,SAAS,MAAM,OAAiB,QAAyD;CACvF,OAAO;EACL;EACA,QAAQ,OAAO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","names":[],"sources":["../../../../src/io/formats/drawio/export.ts"],"sourcesContent":["import { escapeText } from 'entities'\nimport { fromUint8Array } from 'js-base64'\n\nimport type {\n DrawIOCell,\n DrawIOFile,\n DrawIOGeometry,\n DrawIOPage,\n DrawIOPoint,\n DrawIOStyle\n} from '@pairdraw/drawio'\nimport type { ConnectorEndpoint, SceneGraph, SceneNode, StrokeCap } from '@pairdraw/scene-graph'\nimport { colorToHex } from '@pairdraw/scene-graph/color'\nimport {\n connectorRoute,\n connectorRouteEnds,\n connectorSublayers,\n curveMidpoint\n} from '@pairdraw/scene-graph/connectors'\nimport { getParentWorldMatrix, getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport {\n isGeneratedFrame,\n shapeWithTextLabel,\n stickySublayers\n} from '@pairdraw/scene-graph/generated'\nimport Matrix from '@pairdraw/scene-graph/matrix'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\nimport { computeContentBounds } from '#core/io/formats/raster'\nimport { renderNodesToSVG } from '#core/io/formats/svg'\n\nimport { DEFAULT_FONT_FAMILY } from './paint'\nimport { EMPTY_GEOMETRY, placed, placedValues, round, type Placed } from './placement'\nimport { drawioShapeValues } from './shapes'\n\n/** draw.io's id for its root cell and for its one layer, as it numbers new files. */\nconst ROOT_ID = '0'\nconst LAYER_ID = '1'\n\nfunction style(names: string[], values: Record<string, string | undefined>): DrawIOStyle {\n return {\n names,\n values: Object.fromEntries(Object.entries(values).filter(([, v]) => v !== undefined))\n }\n}\n\n/** A layer's name, which draw.io has no field of its own for, so it travels in the style. */\nfunction nameValues(node: SceneNode): Record<string, string> {\n return { pairdrawName: encodeURIComponent(node.name) }\n}\n\n/** A layer's first visible solid fill, or the first stop of a gradient, as draw.io's colour. */\nfunction fillColor(node: SceneNode): string {\n const fill = node.fills.find((paint) => paint.visible)\n if (!fill) return 'none'\n if (fill.type === 'SOLID') return colorToHex(fill.color)\n const stop = fill.gradientStops?.at(0)\n return stop ? colorToHex(stop.color) : 'none'\n}\n\n/** A layer's fill, outline, dash, and opacity as style pairs. */\nfunction paintValues(node: SceneNode): Record<string, string | undefined> {\n const stroke = node.strokes.find((paint) => paint.visible)\n const weight = stroke?.weight ?? node.strokeWeight\n const dash = stroke?.dashPattern ?? node.dashPattern\n return {\n fillColor: fillColor(node),\n strokeColor: stroke ? colorToHex(stroke.color) : 'none',\n strokeWidth: stroke && weight !== 1 ? String(weight) : undefined,\n dashed: dash.length > 0 ? '1' : undefined,\n dashPattern: dash.length > 0 ? dash.map((n) => round(n / (weight || 1))).join(' ') : undefined,\n opacity: node.opacity < 1 ? String(Math.round(node.opacity * 100)) : undefined\n }\n}\n\nconst ALIGN: Record<SceneNode['textAlignHorizontal'], string> = {\n LEFT: 'left',\n CENTER: 'center',\n RIGHT: 'right',\n JUSTIFIED: 'left'\n}\nconst VERTICAL_ALIGN: Record<SceneNode['textAlignVertical'], string> = {\n TOP: 'top',\n CENTER: 'middle',\n BOTTOM: 'bottom'\n}\n\n/** A text layer's font and alignment as a label's style pairs. */\nfunction fontValues(text: SceneNode): Record<string, string | undefined> {\n const fill = text.fills.find((paint) => paint.visible && paint.type === 'SOLID')\n const bits =\n (text.fontWeight >= 600 ? 1 : 0) |\n (text.italic ? 2 : 0) |\n (text.textDecoration === 'UNDERLINE' ? 4 : 0)\n return {\n fontSize: String(text.fontSize),\n // The font draw.io's default stands for on import goes back as that default.\n fontFamily: text.fontFamily === DEFAULT_FONT_FAMILY ? undefined : text.fontFamily,\n fontColor: fill ? colorToHex(fill.color) : undefined,\n fontStyle: bits ? String(bits) : undefined,\n align: ALIGN[text.textAlignHorizontal],\n verticalAlign: VERTICAL_ALIGN[text.textAlignVertical]\n }\n}\n\n/**\n * A text layer's characters as an HTML label: each style run in a span that sets what it\n * changes, and a line break for each new line.\n */\nfunction labelHTML(text: SceneNode): string {\n const { text: characters, styleRuns } = text\n let html = ''\n let at = 0\n const plain = (to: number) => {\n html += escapeText(characters.slice(at, to)).replaceAll('\\n', '<br>')\n at = to\n }\n for (const run of [...styleRuns].sort((a, b) => a.start - b.start)) {\n plain(run.start)\n const css: string[] = []\n const { style: s } = run\n if (s.fontWeight !== undefined) css.push(`font-weight: ${s.fontWeight}`)\n if (s.italic !== undefined) css.push(`font-style: ${s.italic ? 'italic' : 'normal'}`)\n if (s.textDecoration)\n css.push(`text-decoration: ${s.textDecoration === 'UNDERLINE' ? 'underline' : 'none'}`)\n if (s.fontSize !== undefined) css.push(`font-size: ${s.fontSize}px`)\n if (s.fontFamily) css.push(`font-family: ${s.fontFamily}`)\n const fill = s.fills?.find((paint) => paint.type === 'SOLID')\n if (fill?.type === 'SOLID') css.push(`color: ${colorToHex(fill.color)}`)\n const inner = escapeText(characters.slice(run.start, run.start + run.length)).replaceAll(\n '\\n',\n '<br>'\n )\n html += css.length > 0 ? `<span style=\"${css.join('; ')}\">${inner}</span>` : inner\n at = run.start + run.length\n }\n plain(characters.length)\n return html\n}\n\n/** A connector line's colour, width, and dash as an edge's style pairs. */\nfunction lineValues(line: SceneNode): Record<string, string | undefined> {\n const stroke = line.strokes.find((paint) => paint.visible)\n const weight = stroke?.weight ?? 1\n const dash = stroke?.dashPattern ?? []\n return {\n strokeColor: stroke ? colorToHex(stroke.color) : 'none',\n strokeWidth: weight !== 1 ? String(weight) : undefined,\n dashed: dash.length > 0 ? '1' : undefined,\n dashPattern: dash.length > 0 ? dash.map((n) => round(n / weight)).join(' ') : undefined\n }\n}\n\n/** FigJam's ends and the draw.io arrowheads that draw them. */\nconst ARROWS: Record<StrokeCap, string> = {\n NONE: 'none',\n ROUND: 'none',\n SQUARE: 'none',\n ARROW_LINES: 'open',\n ARROW_EQUILATERAL: 'classic',\n TRIANGLE_FILLED: 'classic',\n DIAMOND_FILLED: 'diamond',\n CIRCLE_FILLED: 'oval'\n}\n\n/** Where a side magnet pins an end, as shares of the layer's box. */\nconst SIDE_POINTS: Partial<Record<ConnectorEndpoint['magnet'], [number, number]>> = {\n TOP: [0.5, 0],\n RIGHT: [1, 0.5],\n BOTTOM: [0.5, 1],\n LEFT: [0, 0.5]\n}\n\n/** Writes one page's layers as draw.io cells, in drawing order. */\nclass PageWriter {\n readonly cells: DrawIOCell[] = []\n private readonly ids = new Map<string, string>()\n /** Where each edge's line last ran from and to, in draw.io's axes. */\n private readonly drawnEnds = new Map<string, { start: DrawIOPoint; end: DrawIOPoint }>()\n /** Where each vertex's box starts on the page: draw.io measures its cells' boxes from there. */\n private readonly origins = new Map<string, Vector>([[LAYER_ID, { x: 0, y: 0 }]])\n private next = 2\n\n constructor(\n private readonly graph: SceneGraph,\n private readonly pageId: string\n ) {}\n\n private idOf(nodeId: string): string {\n let id = this.ids.get(nodeId)\n if (!id) {\n id = String(this.next++)\n this.ids.set(nodeId, id)\n }\n return id\n }\n\n write(nodeIds: readonly string[]) {\n // Every layer gets its id first, so an edge can name a layer drawn above it.\n const assign = (id: string) => {\n const node = this.graph.getNode(id)\n if (!node) return\n this.idOf(id)\n if (!isGeneratedFrame(node)) for (const child of node.childIds) assign(child)\n }\n // A layer inside another chosen one goes with it, as a cell of its own or drawn in its picture.\n const chosen = new Set(nodeIds)\n const roots = nodeIds.filter((id) => {\n const parentId = this.graph.getNode(id)?.parentId\n return !parentId || !this.graph.closest(parentId, (node) => chosen.has(node.id))\n })\n for (const id of roots) assign(id)\n for (const id of roots) {\n const node = this.graph.getNode(id)\n if (node) this.layer(node, LAYER_ID)\n }\n this.freeStrandedEnds()\n }\n\n /**\n * An edge end joined to a layer that has no cell, such as one left out of a selection or\n * drawn inside a picture, goes as a free point where the line last ran.\n */\n private freeStrandedEnds() {\n const written = new Set(this.cells.map((cell) => cell.id))\n for (const cell of this.cells) {\n const drawn = this.drawnEnds.get(cell.id)\n if (!drawn) continue\n if (!cell.source || !written.has(cell.source)) {\n cell.source = null\n cell.geometry.sourcePoint = drawn.start\n }\n if (!cell.target || !written.has(cell.target)) {\n cell.target = null\n cell.geometry.targetPoint = drawn.end\n }\n }\n }\n\n private push(\n node: SceneNode,\n parent: string,\n cell: Omit<DrawIOCell, 'id' | 'parent' | 'visible' | 'attributes' | 'source' | 'target'> &\n Partial<Pick<DrawIOCell, 'source' | 'target'>>\n ) {\n const id = this.idOf(node.id)\n if (cell.kind === 'vertex') {\n const from = this.originOf(parent)\n this.origins.set(id, { x: from.x + cell.geometry.x, y: from.y + cell.geometry.y })\n }\n this.cells.push({\n id,\n parent,\n visible: node.visible,\n attributes: {},\n source: null,\n target: null,\n ...cell\n })\n }\n\n private originOf(parent: string): Vector {\n return this.origins.get(parent) ?? { x: 0, y: 0 }\n }\n\n private place(node: SceneNode, parent: string): Placed {\n return placed(node, getWorldMatrix(node, this.graph), this.originOf(parent))\n }\n\n /** The box a layer covers on the page, square to it, in its parent cell's axes. */\n private bounds(node: SceneNode, parent: string): DrawIOGeometry {\n const bounds = computeContentBounds(this.graph, [node.id])\n if (!bounds) return this.place(node, parent).geometry\n const from = this.originOf(parent)\n return {\n ...EMPTY_GEOMETRY,\n x: round(bounds.minX - from.x),\n y: round(bounds.minY - from.y),\n width: round(bounds.maxX - bounds.minX),\n height: round(bounds.maxY - bounds.minY)\n }\n }\n\n private children(node: SceneNode) {\n for (const id of node.childIds) {\n const child = this.graph.getNode(id)\n if (child) this.layer(child, this.idOf(node.id))\n }\n }\n\n private layer(node: SceneNode, parent: string) {\n const placement = this.place(node, parent)\n const { geometry } = placement\n switch (node.type) {\n case 'SHAPE_WITH_TEXT':\n return this.shape(node, parent, placement)\n case 'TEXT':\n return this.push(node, parent, {\n kind: 'vertex',\n value: labelHTML(node),\n style: style(['text'], {\n html: '1',\n whiteSpace: 'wrap',\n ...nameValues(node),\n ...placedValues(placement),\n ...fontValues(node)\n }),\n geometry\n })\n case 'STICKY': {\n const body = stickySublayers(this.graph, node)?.body\n return this.push(node, parent, {\n kind: 'vertex',\n value: body ? labelHTML(body) : '',\n style: style([], {\n whiteSpace: 'wrap',\n html: '1',\n ...paintValues(node),\n strokeColor: 'none',\n align: 'left',\n verticalAlign: 'top',\n spacing: '20',\n ...placedValues(placement),\n fontSize: body ? String(body.fontSize) : undefined\n }),\n geometry\n })\n }\n case 'SECTION':\n this.push(node, parent, {\n kind: 'vertex',\n value: escapeText(node.name),\n style: style(['swimlane'], {\n html: '1',\n startSize: '30',\n ...paintValues(node),\n ...placedValues(placement)\n }),\n geometry\n })\n return this.children(node)\n case 'GROUP':\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style(['group'], {}),\n // A group draws nothing, so it holds what it groups square to the page.\n geometry: this.bounds(node, parent)\n })\n return this.children(node)\n case 'FRAME':\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style([], {\n container: '1',\n html: '1',\n ...nameValues(node),\n ...paintValues(node),\n ...placedValues(placement)\n }),\n geometry\n })\n return this.children(node)\n case 'RECTANGLE':\n case 'ELLIPSE':\n return this.push(node, parent, {\n kind: 'vertex',\n value: '',\n style: style(node.type === 'ELLIPSE' ? ['ellipse'] : [], {\n ...(node.type === 'RECTANGLE' ? { pairdrawType: 'RECTANGLE' } : {}),\n rounded: node.cornerRadius > 0 ? '1' : undefined,\n pairdrawCornerRadius: node.cornerRadius > 0 ? String(node.cornerRadius) : undefined,\n ...nameValues(node),\n ...placedValues(placement),\n ...paintValues(node)\n }),\n geometry\n })\n case 'CONNECTOR':\n return this.edge(node, parent)\n default:\n return this.picture(node, parent)\n }\n }\n\n private shape(node: SceneNode, parent: string, placement: Placed) {\n const label = shapeWithTextLabel(this.graph, node)\n const values: Record<string, string | undefined> = {\n ...drawioShapeValues(node.shapeWithTextType),\n ...nameValues(node),\n whiteSpace: 'wrap',\n html: '1',\n ...paintValues(node),\n ...(label ? fontValues(label) : {})\n }\n let { geometry, rotation } = placement\n // A triangle turned a quarter points the way draw.io's direction says, in the box it fills.\n const mirrored = placement.flipH || placement.flipV\n const quarter =\n !mirrored && Math.abs(rotation) === 90 && node.shapeWithTextType === 'TRIANGLE_UP'\n if (quarter) {\n values.direction = rotation === 90 ? 'east' : 'west'\n geometry = {\n ...geometry,\n x: round(geometry.x + (node.width - node.height) / 2),\n y: round(geometry.y + (node.height - node.width) / 2),\n width: round(node.height),\n height: round(node.width)\n }\n rotation = 0\n }\n // A shape that is draw.io's mirrored one, as a left parallelogram is, mirrors back if the layer is.\n const ownFlipH = values.flipH === '1'\n Object.assign(\n values,\n placedValues({ ...placement, rotation, flipH: placement.flipH !== ownFlipH })\n )\n this.push(node, parent, {\n kind: 'vertex',\n value: label ? labelHTML(label) : '',\n style: style([], values),\n geometry\n })\n }\n\n /** A layer draw.io has no cell for, drawn as the SVG image it exports as, where it covers. */\n private picture(node: SceneNode, parent: string) {\n const svg = renderNodesToSVG(this.graph, this.pageId, [node.id])\n if (!svg) return\n const data = fromUint8Array(new TextEncoder().encode(svg))\n this.push(node, parent, {\n kind: 'vertex',\n value: '',\n // draw.io keeps a data URI in its style without `;base64`, which would end the value.\n style: style([], { shape: 'image', image: `data:image/svg+xml,${data}`, aspect: 'fixed' }),\n geometry: this.bounds(node, parent)\n })\n }\n\n private end(\n endpoint: ConnectorEndpoint | null,\n prefix: 'exit' | 'entry'\n ): Record<string, string> {\n const node = endpoint?.nodeId ? this.graph.getNode(endpoint.nodeId) : undefined\n if (!endpoint || !node) return {}\n const side = SIDE_POINTS[endpoint.magnet]\n const point: [number, number] | null =\n side ??\n (endpoint.magnet === 'NONE' || endpoint.magnet === 'ABSOLUTE'\n ? [endpoint.position.x / (node.width || 1), endpoint.position.y / (node.height || 1)]\n : null)\n if (!point) return {}\n return { [`${prefix}X`]: String(round(point[0])), [`${prefix}Y`]: String(round(point[1])) }\n }\n\n /**\n * Where an edge's free ends sit, its bend points, and its label's place along it, with the\n * points carried into draw.io's axes.\n */\n private edgeGeometry(node: SceneNode, parent: string): DrawIOGeometry {\n const toPage = getParentWorldMatrix(\n node.parentId ? this.graph.getNode(node.parentId) : undefined,\n this.graph\n )\n const from = this.originOf(parent)\n const at = (point: Vector) => {\n const mapped = Matrix.mapPoint(toPage, point)\n return { x: round(mapped.x - from.x), y: round(mapped.y - from.y) }\n }\n const drawn = connectorRouteEnds(this.graph, node)\n if (drawn) {\n this.drawnEnds.set(this.idOf(node.id), { start: at(drawn.start), end: at(drawn.end) })\n }\n const position = node.connectorLabelPosition\n const along = position?.section === 'MIDDLE_TO_START' ? -position.offset : position?.offset\n return {\n ...EMPTY_GEOMETRY,\n relative: true,\n x: round(along ?? 0),\n sourcePoint: !node.connectorStart?.nodeId && drawn ? at(drawn.start) : null,\n targetPoint: !node.connectorEnd?.nodeId && drawn ? at(drawn.end) : null,\n points: this.waypoints(node).map(at)\n }\n }\n\n private edge(node: SceneNode, parent: string) {\n // A connector without its line and label is not one draw.io could draw.\n const parts = connectorSublayers(this.graph, node)\n if (!parts) return\n const startId = node.connectorStart?.nodeId\n const endId = node.connectorEnd?.nodeId\n const lineType = node.connectorLineType\n this.push(node, parent, {\n kind: 'edge',\n value: parts.label.text ? labelHTML(parts.label) : '',\n style: style([], {\n edgeStyle: lineType === 'ELBOWED' ? 'orthogonalEdgeStyle' : undefined,\n rounded: lineType === 'ELBOWED' ? '1' : undefined,\n curved: lineType === 'CURVED' ? '1' : undefined,\n html: '1',\n startArrow: ARROWS[node.connectorStartCap],\n endArrow: ARROWS[node.connectorEndCap],\n ...lineValues(parts.line),\n ...this.end(node.connectorStart, 'exit'),\n ...this.end(node.connectorEnd, 'entry'),\n ...fontValues(parts.label)\n }),\n geometry: this.edgeGeometry(node, parent),\n source: startId ? (this.ids.get(startId) ?? null) : null,\n target: endId ? (this.ids.get(endId) ?? null) : null\n })\n }\n\n /**\n * The points a dragged connector bends through, for draw.io to run its edge the same way: an\n * elbow's corners, or the middle of a curve. A connector routing itself leaves draw.io to route.\n */\n private waypoints(node: SceneNode): Vector[] {\n const route = connectorRoute(this.graph, node)\n if (!route) return []\n if (node.connectorLineType === 'CURVED' && node.connectorCurveHandles) {\n const curve = route.pieces.at(0)\n return curve ? [curveMidpoint(curve)] : []\n }\n if (node.connectorLineType !== 'ELBOWED' || node.connectorControlPoints.length === 0) return []\n return route.pieces.slice(0, -1).map((piece) => piece.to)\n }\n}\n\n/** One page of layers as a draw.io page, holding `nodeIds` or every layer on it. */\nfunction pageOf(graph: SceneGraph, pageId: string, nodeIds?: readonly string[]): DrawIOPage {\n const page = graph.getNode(pageId)\n const writer = new PageWriter(graph, pageId)\n writer.write(nodeIds ?? page?.childIds ?? [])\n return {\n id: pageId,\n name: page?.name ?? 'Page',\n attributes: { grid: '1', gridSize: '10' },\n rootId: ROOT_ID,\n layers: [{ id: LAYER_ID, name: '', visible: true, locked: false }],\n cells: writer.cells\n }\n}\n\n/** What a draw.io export holds: whole pages, or some layers of one page. */\nexport type DrawIOExportTarget =\n | { pageIds: readonly string[] }\n | { pageId: string; nodeIds: readonly string[] }\n\n/**\n * Layers as a draw.io file: FigJam shapes as draw.io's shapes of the same meaning, connectors as\n * edges joined to them, bent the way they were dragged, text as text, sections as swimlanes, and\n * frames and groups as containers. A layer draw.io has no cell for goes as an SVG image of\n * itself, so nothing is lost.\n */\nexport function sceneGraphToDrawIO(graph: SceneGraph, target: DrawIOExportTarget): DrawIOFile {\n const pages =\n 'pageIds' in target\n ? target.pageIds.map((pageId) => pageOf(graph, pageId))\n : [pageOf(graph, target.pageId, target.nodeIds)]\n return { pages, unreadable: [] }\n}\n"],"mappings":";;;;;;;;;;;;;;AAoCA,MAAM,UAAU;AAChB,MAAM,WAAW;AAEjB,SAAS,MAAM,OAAiB,QAAyD;CACvF,OAAO;EACL;EACA,QAAQ,OAAO,YAAY,OAAO,QAAQ,MAAM,CAAC,CAAC,QAAQ,GAAG,OAAO,MAAM,KAAA,CAAS,CAAC;CACtF;AACF;;AAGA,SAAS,WAAW,MAAyC;CAC3D,OAAO,EAAE,cAAc,mBAAmB,KAAK,IAAI,EAAE;AACvD;;AAGA,SAAS,UAAU,MAAyB;CAC1C,MAAM,OAAO,KAAK,MAAM,MAAM,UAAU,MAAM,OAAO;CACrD,IAAI,CAAC,MAAM,OAAO;CAClB,IAAI,KAAK,SAAS,SAAS,OAAO,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d.ts","names":[],"sources":["../../../../src/io/formats/drawio/index.ts"],"mappings":";;;;;;;;;
|
|
1
|
+
{"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/index.ts"],"mappings":";;;;;;;;;iBAkOgB,mBAAmB,MAAM,aAAa"}
|
|
@@ -36,6 +36,23 @@ function placementOf(style, ownFlipH = false) {
|
|
|
36
36
|
function nameOf(text, fallback) {
|
|
37
37
|
return text.split("\n")[0]?.trim() || fallback;
|
|
38
38
|
}
|
|
39
|
+
/**
|
|
40
|
+
* The name Pairdraw wrote into a cell's style. draw.io has no field of its own for a layer whose
|
|
41
|
+
* cell draws no text, and a text cell's label is its content, so the name travels beside them.
|
|
42
|
+
*/
|
|
43
|
+
function writtenName(style) {
|
|
44
|
+
const value = style.values.pairdrawName;
|
|
45
|
+
if (value === void 0) return void 0;
|
|
46
|
+
try {
|
|
47
|
+
return decodeURIComponent(value);
|
|
48
|
+
} catch {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/** A layer's name: the one Pairdraw wrote, else the first line of its label. */
|
|
53
|
+
function layerName(style, text, fallback) {
|
|
54
|
+
return writtenName(style) ?? nameOf(text, fallback);
|
|
55
|
+
}
|
|
39
56
|
/** Builds one draw.io page's cells into `pageId`, in draw.io's drawing order. */
|
|
40
57
|
var PageBuilder = class {
|
|
41
58
|
graph;
|
|
@@ -110,12 +127,26 @@ var PageBuilder = class {
|
|
|
110
127
|
if (kind.type === "TEXT") return graph.createNode("TEXT", parentId, {
|
|
111
128
|
...box,
|
|
112
129
|
...placementOf(cell.style),
|
|
113
|
-
name:
|
|
130
|
+
name: layerName(cell.style, label.text, "Text"),
|
|
114
131
|
...labelFields(cell.style, label.format),
|
|
115
132
|
text: label.text,
|
|
116
133
|
styleRuns: label.runs,
|
|
117
134
|
textAutoResize: "NONE"
|
|
118
135
|
});
|
|
136
|
+
if (kind.type === "FRAME") return graph.createNode("FRAME", parentId, {
|
|
137
|
+
...box,
|
|
138
|
+
...shapePaint(cell.style),
|
|
139
|
+
name: layerName(cell.style, label.text, "Frame")
|
|
140
|
+
});
|
|
141
|
+
if (kind.type === "RECTANGLE") {
|
|
142
|
+
const radius = Number.parseFloat(cell.style.values.pairdrawCornerRadius ?? "");
|
|
143
|
+
return graph.createNode("RECTANGLE", parentId, {
|
|
144
|
+
...box,
|
|
145
|
+
...shapePaint(cell.style),
|
|
146
|
+
...radius > 0 ? { cornerRadius: radius } : {},
|
|
147
|
+
name: layerName(cell.style, label.text, "Rectangle")
|
|
148
|
+
});
|
|
149
|
+
}
|
|
119
150
|
if (kind.type === "SECTION") return graph.createNode("SECTION", parentId, {
|
|
120
151
|
...box,
|
|
121
152
|
...shapePaint(cell.style),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/io/formats/drawio/index.ts"],"sourcesContent":["import type { DrawIOCell, DrawIOFile, DrawIOPage, DrawIOStyle } from '@pairdraw/drawio'\nimport { SceneGraph, type SceneNode } from '@pairdraw/scene-graph'\nimport { connectorRoute, placeConnectorLabel } from '@pairdraw/scene-graph/connectors'\nimport { createShapeWithText } from '@pairdraw/scene-graph/generated'\nimport { fitEnclosingGroups } from '@pairdraw/scene-graph/group-bounds'\n\nimport { bindEdge, createEdge, labelPositionOf, type PendingEdge } from './edges'\nimport { readLabel } from './label'\nimport { labelFields, labelFormat, shapePaint } from './paint'\nimport { shapeName, vertexKind } from './shapes'\n\n/** A cell's label as text and runs, in the cell's own style. */\nfunction labelOf(cell: DrawIOCell) {\n const format = labelFormat(cell.style)\n return { format, ...readLabel(cell.value, cell.style.values.html === '1', format) }\n}\n\n/**\n * A cell's turn and mirrors as a layer's. draw.io mirrors a cell about its centre and then turns\n * it, negating the turn when it mirrors one way only; a layer turns and then mirrors, so that\n * turn is the layer's own. `ownFlipH` is a mirror the shape itself stands for, as a left\n * parallelogram is draw.io's mirrored one.\n */\nfunction placementOf(style: DrawIOStyle, ownFlipH = false) {\n const flipX = style.values.flipH === '1' && !ownFlipH\n const flipY = style.values.flipV === '1'\n const turn = Number(style.values.rotation ?? 0) || 0\n return { flipX, flipY, rotation: flipX === flipY ? turn : -turn }\n}\n\n/** The first line of a label, as a layer's name. */\nfunction nameOf(text: string, fallback: string): string {\n return text.split('\\n')[0]?.trim() || fallback\n}\n\n/** Builds one draw.io page's cells into `pageId`, in draw.io's drawing order. */\nclass PageBuilder {\n /** The layer each draw.io cell or layer became. */\n private readonly layers = new Map<string, string>()\n private readonly edges: PendingEdge[] = []\n private readonly groups: string[] = []\n\n constructor(\n private readonly graph: SceneGraph,\n private readonly page: DrawIOPage,\n private readonly pageId: string\n ) {}\n\n build() {\n const { graph, page, pageId } = this\n // One layer draws straight onto the page; several each become a group named after it, as\n // does a single layer that is hidden or locked, so it stays so.\n for (const [index, layer] of page.layers.entries()) {\n if (page.layers.length === 1 && layer.visible && !layer.locked) {\n this.layers.set(layer.id, pageId)\n continue\n }\n const group = graph.createNode('GROUP', pageId, {\n name: layer.name || `Layer ${index + 1}`,\n visible: layer.visible,\n locked: layer.locked\n })\n this.layers.set(layer.id, group.id)\n this.groups.push(group.id)\n }\n const parents = new Set(page.cells.map((cell) => cell.parent))\n const labelsOf = new Map<string, DrawIOCell[]>()\n const edgeIds = new Set(\n page.cells.filter((cell) => cell.kind === 'edge').map((cell) => cell.id)\n )\n for (const cell of page.cells) {\n // A vertex inside an edge is one of its labels.\n if (edgeIds.has(cell.parent)) {\n const labels = labelsOf.get(cell.parent) ?? []\n labels.push(cell)\n labelsOf.set(cell.parent, labels)\n }\n }\n const cells = new Map(page.cells.map((cell) => [cell.id, cell]))\n const placing = new Set<string>()\n const place = (cell: DrawIOCell) => {\n if (edgeIds.has(cell.parent) || this.layers.has(cell.id) || placing.has(cell.id)) return\n placing.add(cell.id)\n // A cell listed before its parent, as draw.io's format allows, waits for the parent.\n const parent = cells.get(cell.parent)\n if (parent) place(parent)\n const parentId = this.layers.get(cell.parent) ?? pageId\n if (cell.kind === 'edge') {\n const pending = createEdge(graph, parentId, cell, labelsOf.get(cell.id) ?? [])\n this.layers.set(cell.id, pending.connector.id)\n this.edges.push(pending)\n return\n }\n const node = this.vertex(cell, parentId, parents.has(cell.id))\n this.layers.set(cell.id, node.id)\n }\n for (const cell of page.cells) place(cell)\n const layerOf = (cellId: string) => this.layers.get(cellId)\n for (const pending of this.edges) {\n for (const extra of bindEdge(graph, pending, layerOf)) this.edgeText(pending, extra)\n }\n // Groups fit around what they hold, the innermost first.\n for (const id of this.groups.toReversed()) fitEnclosingGroups(graph, [id])\n }\n\n private vertex(cell: DrawIOCell, parentId: string, hasChildren: boolean): SceneNode {\n const { graph } = this\n const { x, y, width, height } = cell.geometry\n const kind = vertexKind(cell.style, hasChildren)\n const label = labelOf(cell)\n const box = { x, y, width, height, visible: cell.visible }\n if (kind.type === 'TEXT') {\n return graph.createNode('TEXT', parentId, {\n ...box,\n ...placementOf(cell.style),\n name: nameOf(label.text, 'Text'),\n ...labelFields(cell.style, label.format),\n text: label.text,\n styleRuns: label.runs,\n textAutoResize: 'NONE'\n })\n }\n if (kind.type === 'SECTION') {\n return graph.createNode('SECTION', parentId, {\n ...box,\n ...shapePaint(cell.style),\n name: nameOf(label.text, 'Section')\n })\n }\n if (kind.type === 'GROUP') {\n const group = graph.createNode('GROUP', parentId, {\n ...box,\n name: nameOf(label.text, 'Group')\n })\n this.groups.push(group.id)\n return group\n }\n // A shape turned a quarter swaps its sides, about the centre of the box it fills.\n const quarter = Math.abs(kind.rotation) === 90\n const placed = quarter\n ? { x: x + (width - height) / 2, y: y + (height - width) / 2, width: height, height: width }\n : { x, y, width, height }\n const known = shapeName(cell.style)\n const own = placementOf(cell.style, kind.shape === 'PARALLELOGRAM_LEFT')\n return createShapeWithText(\n graph,\n parentId,\n {\n ...placed,\n visible: cell.visible,\n ...own,\n rotation: own.rotation + kind.rotation,\n shapeWithTextType: kind.shape,\n // draw.io sized it, so it keeps its size, as a FigJam shape whose height was set does.\n shapeTruncates: true,\n ...shapePaint(cell.style),\n // A stencil FigJam has no shape for keeps its name, so it can be found and replaced.\n name: kind.stencil ? known : nameOf(label.text, 'Shape with text')\n },\n { ...labelFields(cell.style, label.format), text: label.text, styleRuns: label.runs }\n )\n }\n\n /** A label beyond an edge's first, as text where draw.io placed it along the edge. */\n private edgeText({ connector }: PendingEdge, cell: DrawIOCell) {\n const { graph } = this\n const node = graph.getNode(connector.id)\n const route = node ? connectorRoute(graph, node) : null\n if (!node?.parentId || !route) return\n const label = labelOf(cell)\n const size = { width: cell.geometry.width, height: cell.geometry.height }\n const plate = placeConnectorLabel(route.pieces, size, labelPositionOf(cell.geometry.x))?.plate\n const offset = cell.geometry.offset ?? { x: 0, y: 0 }\n graph.createNode('TEXT', node.parentId, {\n x: (plate?.x ?? 0) + offset.x,\n y: (plate?.y ?? 0) + offset.y,\n visible: cell.visible,\n name: nameOf(label.text, 'Text'),\n ...labelFields(cell.style, label.format),\n text: label.text,\n styleRuns: label.runs,\n textAutoResize: 'WIDTH_AND_HEIGHT'\n })\n }\n}\n\n/**\n * A draw.io file as layers: each page a page, its shapes FigJam shapes with text, its edges\n * connectors joined to them, its layers groups when there are several, in draw.io's drawing order.\n * Text sizes are left for layout, which measures them once fonts load.\n */\nexport function drawioToSceneGraph(file: DrawIOFile): SceneGraph {\n const graph = new SceneGraph()\n const first = graph.getPages().at(0)\n for (const [index, page] of file.pages.entries()) {\n const pageNode = index === 0 && first ? first : graph.addPage(page.name)\n if (index === 0) graph.updateNode(pageNode.id, { name: page.name })\n new PageBuilder(graph, page, pageNode.id).build()\n }\n return graph\n}\n\nexport { sceneGraphToDrawIO } from './export'\n"],"mappings":";;;;;;;;;;;AAYA,SAAS,QAAQ,MAAkB;CACjC,MAAM,SAAS,YAAY,KAAK,KAAK;CACrC,OAAO;EAAE;EAAQ,GAAG,UAAU,KAAK,OAAO,KAAK,MAAM,OAAO,SAAS,KAAK,MAAM;CAAE;AACpF;;;;;;;AAQA,SAAS,YAAY,OA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,SAAS,IAAI,EAAE,MAAM,KAAK,KAAK,CAAC;EAClE,IAAI,YAAY,OAAO,MAAM,SAAS,EAAE,CAAC,CAAC,MAAM;CAClD;CACA,OAAO;AACT"}
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../../../src/io/formats/drawio/index.ts"],"sourcesContent":["import type { DrawIOCell, DrawIOFile, DrawIOPage, DrawIOStyle } from '@pairdraw/drawio'\nimport { SceneGraph, type SceneNode } from '@pairdraw/scene-graph'\nimport { connectorRoute, placeConnectorLabel } from '@pairdraw/scene-graph/connectors'\nimport { createShapeWithText } from '@pairdraw/scene-graph/generated'\nimport { fitEnclosingGroups } from '@pairdraw/scene-graph/group-bounds'\n\nimport { bindEdge, createEdge, labelPositionOf, type PendingEdge } from './edges'\nimport { readLabel } from './label'\nimport { labelFields, labelFormat, shapePaint } from './paint'\nimport { shapeName, vertexKind } from './shapes'\n\n/** A cell's label as text and runs, in the cell's own style. */\nfunction labelOf(cell: DrawIOCell) {\n const format = labelFormat(cell.style)\n return { format, ...readLabel(cell.value, cell.style.values.html === '1', format) }\n}\n\n/**\n * A cell's turn and mirrors as a layer's. draw.io mirrors a cell about its centre and then turns\n * it, negating the turn when it mirrors one way only; a layer turns and then mirrors, so that\n * turn is the layer's own. `ownFlipH` is a mirror the shape itself stands for, as a left\n * parallelogram is draw.io's mirrored one.\n */\nfunction placementOf(style: DrawIOStyle, ownFlipH = false) {\n const flipX = style.values.flipH === '1' && !ownFlipH\n const flipY = style.values.flipV === '1'\n const turn = Number(style.values.rotation ?? 0) || 0\n return { flipX, flipY, rotation: flipX === flipY ? turn : -turn }\n}\n\n/** The first line of a label, as a layer's name. */\nfunction nameOf(text: string, fallback: string): string {\n return text.split('\\n')[0]?.trim() || fallback\n}\n\n/**\n * The name Pairdraw wrote into a cell's style. draw.io has no field of its own for a layer whose\n * cell draws no text, and a text cell's label is its content, so the name travels beside them.\n */\nfunction writtenName(style: DrawIOStyle): string | undefined {\n const value = style.values.pairdrawName\n if (value === undefined) return undefined\n try {\n return decodeURIComponent(value)\n } catch {\n return undefined\n }\n}\n\n/** A layer's name: the one Pairdraw wrote, else the first line of its label. */\nfunction layerName(style: DrawIOStyle, text: string, fallback: string): string {\n return writtenName(style) ?? nameOf(text, fallback)\n}\n\n/** Builds one draw.io page's cells into `pageId`, in draw.io's drawing order. */\nclass PageBuilder {\n /** The layer each draw.io cell or layer became. */\n private readonly layers = new Map<string, string>()\n private readonly edges: PendingEdge[] = []\n private readonly groups: string[] = []\n\n constructor(\n private readonly graph: SceneGraph,\n private readonly page: DrawIOPage,\n private readonly pageId: string\n ) {}\n\n build() {\n const { graph, page, pageId } = this\n // One layer draws straight onto the page; several each become a group named after it, as\n // does a single layer that is hidden or locked, so it stays so.\n for (const [index, layer] of page.layers.entries()) {\n if (page.layers.length === 1 && layer.visible && !layer.locked) {\n this.layers.set(layer.id, pageId)\n continue\n }\n const group = graph.createNode('GROUP', pageId, {\n name: layer.name || `Layer ${index + 1}`,\n visible: layer.visible,\n locked: layer.locked\n })\n this.layers.set(layer.id, group.id)\n this.groups.push(group.id)\n }\n const parents = new Set(page.cells.map((cell) => cell.parent))\n const labelsOf = new Map<string, DrawIOCell[]>()\n const edgeIds = new Set(\n page.cells.filter((cell) => cell.kind === 'edge').map((cell) => cell.id)\n )\n for (const cell of page.cells) {\n // A vertex inside an edge is one of its labels.\n if (edgeIds.has(cell.parent)) {\n const labels = labelsOf.get(cell.parent) ?? []\n labels.push(cell)\n labelsOf.set(cell.parent, labels)\n }\n }\n const cells = new Map(page.cells.map((cell) => [cell.id, cell]))\n const placing = new Set<string>()\n const place = (cell: DrawIOCell) => {\n if (edgeIds.has(cell.parent) || this.layers.has(cell.id) || placing.has(cell.id)) return\n placing.add(cell.id)\n // A cell listed before its parent, as draw.io's format allows, waits for the parent.\n const parent = cells.get(cell.parent)\n if (parent) place(parent)\n const parentId = this.layers.get(cell.parent) ?? pageId\n if (cell.kind === 'edge') {\n const pending = createEdge(graph, parentId, cell, labelsOf.get(cell.id) ?? [])\n this.layers.set(cell.id, pending.connector.id)\n this.edges.push(pending)\n return\n }\n const node = this.vertex(cell, parentId, parents.has(cell.id))\n this.layers.set(cell.id, node.id)\n }\n for (const cell of page.cells) place(cell)\n const layerOf = (cellId: string) => this.layers.get(cellId)\n for (const pending of this.edges) {\n for (const extra of bindEdge(graph, pending, layerOf)) this.edgeText(pending, extra)\n }\n // Groups fit around what they hold, the innermost first.\n for (const id of this.groups.toReversed()) fitEnclosingGroups(graph, [id])\n }\n\n private vertex(cell: DrawIOCell, parentId: string, hasChildren: boolean): SceneNode {\n const { graph } = this\n const { x, y, width, height } = cell.geometry\n const kind = vertexKind(cell.style, hasChildren)\n const label = labelOf(cell)\n const box = { x, y, width, height, visible: cell.visible }\n if (kind.type === 'TEXT') {\n return graph.createNode('TEXT', parentId, {\n ...box,\n ...placementOf(cell.style),\n name: layerName(cell.style, label.text, 'Text'),\n ...labelFields(cell.style, label.format),\n text: label.text,\n styleRuns: label.runs,\n textAutoResize: 'NONE'\n })\n }\n if (kind.type === 'FRAME') {\n return graph.createNode('FRAME', parentId, {\n ...box,\n ...shapePaint(cell.style),\n name: layerName(cell.style, label.text, 'Frame')\n })\n }\n if (kind.type === 'RECTANGLE') {\n const radius = Number.parseFloat(cell.style.values.pairdrawCornerRadius ?? '')\n return graph.createNode('RECTANGLE', parentId, {\n ...box,\n ...shapePaint(cell.style),\n ...(radius > 0 ? { cornerRadius: radius } : {}),\n name: layerName(cell.style, label.text, 'Rectangle')\n })\n }\n if (kind.type === 'SECTION') {\n return graph.createNode('SECTION', parentId, {\n ...box,\n ...shapePaint(cell.style),\n name: nameOf(label.text, 'Section')\n })\n }\n if (kind.type === 'GROUP') {\n const group = graph.createNode('GROUP', parentId, {\n ...box,\n name: nameOf(label.text, 'Group')\n })\n this.groups.push(group.id)\n return group\n }\n // A shape turned a quarter swaps its sides, about the centre of the box it fills.\n const quarter = Math.abs(kind.rotation) === 90\n const placed = quarter\n ? { x: x + (width - height) / 2, y: y + (height - width) / 2, width: height, height: width }\n : { x, y, width, height }\n const known = shapeName(cell.style)\n const own = placementOf(cell.style, kind.shape === 'PARALLELOGRAM_LEFT')\n return createShapeWithText(\n graph,\n parentId,\n {\n ...placed,\n visible: cell.visible,\n ...own,\n rotation: own.rotation + kind.rotation,\n shapeWithTextType: kind.shape,\n // draw.io sized it, so it keeps its size, as a FigJam shape whose height was set does.\n shapeTruncates: true,\n ...shapePaint(cell.style),\n // A stencil FigJam has no shape for keeps its name, so it can be found and replaced.\n name: kind.stencil ? known : nameOf(label.text, 'Shape with text')\n },\n { ...labelFields(cell.style, label.format), text: label.text, styleRuns: label.runs }\n )\n }\n\n /** A label beyond an edge's first, as text where draw.io placed it along the edge. */\n private edgeText({ connector }: PendingEdge, cell: DrawIOCell) {\n const { graph } = this\n const node = graph.getNode(connector.id)\n const route = node ? connectorRoute(graph, node) : null\n if (!node?.parentId || !route) return\n const label = labelOf(cell)\n const size = { width: cell.geometry.width, height: cell.geometry.height }\n const plate = placeConnectorLabel(route.pieces, size, labelPositionOf(cell.geometry.x))?.plate\n const offset = cell.geometry.offset ?? { x: 0, y: 0 }\n graph.createNode('TEXT', node.parentId, {\n x: (plate?.x ?? 0) + offset.x,\n y: (plate?.y ?? 0) + offset.y,\n visible: cell.visible,\n name: nameOf(label.text, 'Text'),\n ...labelFields(cell.style, label.format),\n text: label.text,\n styleRuns: label.runs,\n textAutoResize: 'WIDTH_AND_HEIGHT'\n })\n }\n}\n\n/**\n * A draw.io file as layers: each page a page, its shapes FigJam shapes with text, its edges\n * connectors joined to them, its layers groups when there are several, in draw.io's drawing order.\n * Text sizes are left for layout, which measures them once fonts load.\n */\nexport function drawioToSceneGraph(file: DrawIOFile): SceneGraph {\n const graph = new SceneGraph()\n const first = graph.getPages().at(0)\n for (const [index, page] of file.pages.entries()) {\n const pageNode = index === 0 && first ? first : graph.addPage(page.name)\n if (index === 0) graph.updateNode(pageNode.id, { name: page.name })\n new PageBuilder(graph, page, p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@pairdraw/drawio";
|
|
3
3
|
//#region src/io/formats/drawio/shapes.d.ts
|
|
4
|
-
/** What a draw.io vertex becomes: a
|
|
4
|
+
/** What a draw.io vertex becomes: a shape, text, a frame or section around its cells, or a group. */
|
|
5
5
|
type VertexKind =
|
|
6
6
|
/** A FigJam shape, turned clockwise by `rotation` degrees about its centre. */
|
|
7
7
|
{
|
|
@@ -11,18 +11,23 @@ type VertexKind =
|
|
|
11
11
|
stencil: boolean;
|
|
12
12
|
} | {
|
|
13
13
|
type: 'TEXT';
|
|
14
|
+
} | {
|
|
15
|
+
type: 'FRAME';
|
|
14
16
|
} | {
|
|
15
17
|
type: 'SECTION';
|
|
18
|
+
} | {
|
|
19
|
+
type: 'RECTANGLE';
|
|
16
20
|
} | {
|
|
17
21
|
type: 'GROUP';
|
|
18
22
|
};
|
|
19
23
|
/** The shape a style draws: its `shape`, else the stylesheet style it names, else a rectangle. */
|
|
20
24
|
declare function shapeName(style: DrawIOStyle): string;
|
|
21
25
|
/**
|
|
22
|
-
* What a vertex becomes. Text stays text; a swimlane
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
+
* What a vertex becomes. Text stays text; a swimlane becomes a section holding its cells, and
|
|
27
|
+
* any other vertex its style makes a container becomes a frame, as Pairdraw writes one; a group
|
|
28
|
+
* stays a group. A style Pairdraw wrote says when it drew a rectangle, which draw.io has no
|
|
29
|
+
* style of its own for. A shape draw.io turns by `direction` keeps its turn. Any other shape, a
|
|
30
|
+
* stencil FigJam has no shape for among them, becomes a shape named after the stencil.
|
|
26
31
|
*/
|
|
27
32
|
declare function vertexKind(style: DrawIOStyle, hasChildren: boolean): VertexKind;
|
|
28
33
|
declare function drawioShapeValues(shape: ShapeWithTextType): Record<string, string>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapes.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/shapes.ts"],"mappings":";;;;KAIY;;;EAEN;EAAyB,OAAO;EAAmB;EAAkB;;EACrE;;EACA;;EACA;;;iBA8DU,UAAU,OAAO
|
|
1
|
+
{"version":3,"file":"shapes.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/shapes.ts"],"mappings":";;;;KAIY;;;EAEN;EAAyB,OAAO;EAAmB;EAAkB;;EACrE;;EACA;;EACA;;EACA;;EACA;;;iBA8DU,UAAU,OAAO;;;;;;;;iBAmBjB,WAAW,OAAO,aAAa,uBAAuB;iBAgEtD,kBAAkB,OAAO,oBAAoB"}
|
|
@@ -74,16 +74,20 @@ const DIRECTION_TURN = /* @__PURE__ */ new Map([
|
|
|
74
74
|
["south", -90]
|
|
75
75
|
]);
|
|
76
76
|
/**
|
|
77
|
-
* What a vertex becomes. Text stays text; a swimlane
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
77
|
+
* What a vertex becomes. Text stays text; a swimlane becomes a section holding its cells, and
|
|
78
|
+
* any other vertex its style makes a container becomes a frame, as Pairdraw writes one; a group
|
|
79
|
+
* stays a group. A style Pairdraw wrote says when it drew a rectangle, which draw.io has no
|
|
80
|
+
* style of its own for. A shape draw.io turns by `direction` keeps its turn. Any other shape, a
|
|
81
|
+
* stencil FigJam has no shape for among them, becomes a shape named after the stencil.
|
|
81
82
|
*/
|
|
82
83
|
function vertexKind(style, hasChildren) {
|
|
83
84
|
const name = shapeName(style);
|
|
84
85
|
if (name === "text") return { type: "TEXT" };
|
|
85
|
-
if (
|
|
86
|
-
if (name === "
|
|
86
|
+
if (style.values.pairdrawType === "RECTANGLE") return { type: "RECTANGLE" };
|
|
87
|
+
if (name === "swimlane") return { type: "SECTION" };
|
|
88
|
+
if (name === "group") return { type: "GROUP" };
|
|
89
|
+
if (style.values.container === "1") return { type: "FRAME" };
|
|
90
|
+
if (hasChildren && !SHAPES.has(name)) return { type: "GROUP" };
|
|
87
91
|
let shape = SHAPES.get(name) ?? "SQUARE";
|
|
88
92
|
const direction = style.values.direction ?? "east";
|
|
89
93
|
let rotation = 0;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shapes.js","names":[],"sources":["../../../../src/io/formats/drawio/shapes.ts"],"sourcesContent":["import type { DrawIOStyle } from '@pairdraw/drawio'\nimport type { ShapeWithTextType } from '@pairdraw/scene-graph/shape-with-text'\n\n/** What a draw.io vertex becomes: a FigJam shape, text, a section around its cells, or a group. */\nexport type VertexKind =\n /** A FigJam shape, turned clockwise by `rotation` degrees about its centre. */\n | { type: 'SHAPE_WITH_TEXT'; shape: ShapeWithTextType; rotation: number; stencil: boolean }\n | { type: 'TEXT' }\n | { type: 'SECTION' }\n | { type: 'GROUP' }\n\n/**\n * draw.io shapes, by their `shape` value or stylesheet name, and the FigJam shapes with text that\n * draw them. Flowchart stencils map to the FigJam flowchart shape of the same meaning.\n */\nconst SHAPES = new Map<string, ShapeWithTextType>([\n ['rectangle', 'SQUARE'],\n ['label', 'SQUARE'],\n ['ellipse', 'ELLIPSE'],\n ['doubleEllipse', 'ELLIPSE'],\n ['rhombus', 'DIAMOND'],\n ['triangle', 'TRIANGLE_UP'],\n ['parallelogram', 'PARALLELOGRAM_RIGHT'],\n ['trapezoid', 'TRAPEZOID'],\n ['hexagon', 'HEXAGON'],\n ['cylinder', 'ENG_DATABASE'],\n ['cylinder3', 'ENG_DATABASE'],\n ['datastore', 'ENG_DATABASE'],\n ['document', 'DOCUMENT_SINGLE'],\n ['process', 'PREDEFINED_PROCESS'],\n ['manualInput', 'MANUAL_INPUT'],\n ['internalStorage', 'INTERNAL_STORAGE'],\n ['step', 'CHEVRON'],\n ['note', 'ENG_FILE'],\n ['folder', 'ENG_FOLDER'],\n ['cross', 'PLUS'],\n ['singleArrow', 'ARROW_RIGHT'],\n ['callout', 'SPEECH_BUBBLE'],\n ['sumEllipse', 'SUMMING_JUNCTION'],\n ['orEllipse', 'OR'],\n ['mxgraph.flowchart.process', 'SQUARE'],\n ['mxgraph.flowchart.decision', 'DIAMOND'],\n ['mxgraph.flowchart.terminator', 'ROUNDED_RECTANGLE'],\n ['mxgraph.flowchart.start_1', 'ELLIPSE'],\n ['mxgraph.flowchart.start_2', 'ELLIPSE'],\n ['mxgraph.flowchart.on-page_reference', 'ELLIPSE'],\n ['mxgraph.flowchart.data', 'PARALLELOGRAM_RIGHT'],\n ['mxgraph.flowchart.database', 'ENG_DATABASE'],\n ['mxgraph.flowchart.stored_data', 'ENG_DATABASE'],\n ['mxgraph.flowchart.direct_data', 'ENG_QUEUE'],\n ['mxgraph.flowchart.document', 'DOCUMENT_SINGLE'],\n ['mxgraph.flowchart.multi-document', 'DOCUMENT_MULTIPLE'],\n ['mxgraph.flowchart.predefined_process', 'PREDEFINED_PROCESS'],\n ['mxgraph.flowchart.manual_input', 'MANUAL_INPUT'],\n ['mxgraph.flowchart.internal_storage', 'INTERNAL_STORAGE'],\n ['mxgraph.flowchart.summing_function', 'SUMMING_JUNCTION'],\n ['mxgraph.flowchart.or', 'OR'],\n ['mxgraph.flowchart.extract_or_measurement', 'TRIANGLE_UP'],\n ['mxgraph.flowchart.merge_or_storage', 'TRIANGLE_DOWN'],\n ['mxgraph.basic.pentagon', 'PENTAGON'],\n ['mxgraph.basic.octagon2', 'OCTAGON'],\n ['mxgraph.basic.star', 'STAR'],\n ['mxgraph.basic.plus', 'PLUS'],\n ['mxgraph.basic.rectCallout', 'SPEECH_BUBBLE'],\n ['mxgraph.basic.oval_callout', 'SPEECH_BUBBLE']\n])\n\n/** Stylesheet names that pick a shape, as `ellipse` in `ellipse;whiteSpace=wrap;` does. */\nconst SHAPE_NAMES = new Set([...SHAPES.keys(), 'text', 'swimlane', 'group', 'image'])\n\n/** The shape a style draws: its `shape`, else the stylesheet style it names, else a rectangle. */\nexport function shapeName(style: DrawIOStyle): string {\n return style.values.shape ?? style.names.find((name) => SHAPE_NAMES.has(name)) ?? 'rectangle'\n}\n\n/** Which way `direction` points, in degrees anticlockwise from pointing right. */\nconst DIRECTION_TURN = new Map([\n ['east', 0],\n ['north', 90],\n ['west', 180],\n ['south', -90]\n])\n\n/**\n * What a vertex becomes. Text stays text; a swimlane, or a vertex its style makes a container,\n * becomes a section holding its cells; a group stays a group. A shape draw.io turns by\n * `direction` keeps its turn. Any other shape, a stencil FigJam has no shape for among them,\n * becomes a rectangle, named after the stencil so it can be found.\n */\nexport function vertexKind(style: DrawIOStyle, hasChildren: boolean): VertexKind {\n const name = shapeName(style)\n if (name === 'text') return { type: 'TEXT' }\n if (name === 'swimlane' || (hasChildren && style.values.container === '1')) {\n return { type: 'SECTION' }\n }\n if (name === 'group' || (hasChildren && !SHAPES.has(name))) return { type: 'GROUP' }\n let shape = SHAPES.get(name) ?? 'SQUARE'\n const direction = style.values.direction ?? 'east'\n let rotation = 0\n if (shape === 'TRIANGLE_UP' && name === 'triangle') {\n // draw.io's triangle points right; FigJam's points up and turns, clockwise for a positive\n // rotation, to point elsewhere.\n rotation = 90 - (DIRECTION_TURN.get(direction) ?? 0)\n if (rotation === 180) {\n shape = 'TRIANGLE_DOWN'\n rotation = 0\n }\n } else if (shape === 'ARROW_RIGHT' && direction === 'west') shape = 'ARROW_LEFT'\n else if (shape === 'PARALLELOGRAM_RIGHT' && style.values.flipH === '1') {\n shape = 'PARALLELOGRAM_LEFT'\n } else if (shape === 'SQUARE' && style.values.rounded === '1') shape = 'ROUNDED_RECTANGLE'\n return { type: 'SHAPE_WITH_TEXT', shape, rotation, stencil: !SHAPES.has(name) }\n}\n\n/**\n * The draw.io style that draws each FigJam shape, the other way round: built-in shapes where\n * draw.io has one, its flowchart and basic stencils otherwise. A shield, which draw.io has no\n * shape for, goes as a rectangle.\n */\nconst DRAWIO_SHAPES: Record<ShapeWithTextType, Record<string, string>> = {\n SQUARE: {},\n ROUNDED_RECTANGLE: { rounded: '1' },\n ELLIPSE: { shape: 'ellipse', perimeter: 'ellipsePerimeter' },\n DIAMOND: { shape: 'rhombus', perimeter: 'rhombusPerimeter' },\n TRIANGLE_UP: { shape: 'triangle', direction: 'north', perimeter: 'trianglePerimeter' },\n TRIANGLE_DOWN: { shape: 'triangle', direction: 'south', perimeter: 'trianglePerimeter' },\n PARALLELOGRAM_RIGHT: { shape: 'parallelogram', perimeter: 'parallelogramPerimeter' },\n PARALLELOGRAM_LEFT: { shape: 'parallelogram', flipH: '1', perimeter: 'parallelogramPerimeter' },\n ENG_DATABASE: { shape: 'cylinder3' },\n ENG_QUEUE: { shape: 'mxgraph.flowchart.direct_data' },\n ENG_FILE: { shape: 'note' },\n ENG_FOLDER: { shape: 'folder' },\n TRAPEZOID: { shape: 'trapezoid', perimeter: 'trapezoidPerimeter' },\n PREDEFINED_PROCESS: { shape: 'process' },\n SHIELD: {},\n DOCUMENT_SINGLE: { shape: 'document' },\n DOCUMENT_MULTIPLE: { shape: 'mxgraph.flowchart.multi-document' },\n MANUAL_INPUT: { shape: 'manualInput' },\n HEXAGON: { shape: 'hexagon', perimeter: 'hexagonPerimeter2' },\n CHEVRON: { shape: 'step' },\n PENTAGON: { shape: 'mxgraph.basic.pentagon' },\n OCTAGON: { shape: 'mxgraph.basic.octagon2' },\n STAR: { shape: 'mxgraph.basic.star' },\n PLUS: { shape: 'cross' },\n ARROW_LEFT: { shape: 'singleArrow', direction: 'west' },\n ARROW_RIGHT: { shape: 'singleArrow' },\n SUMMING_JUNCTION: { shape: 'sumEllipse', perimeter: 'ellipsePerimeter' },\n OR: { shape: 'orEllipse', perimeter: 'ellipsePerimeter' },\n SPEECH_BUBBLE: { shape: 'callout' },\n INTERNAL_STORAGE: { shape: 'internalStorage' }\n}\n\nexport function drawioShapeValues(shape: ShapeWithTextType): Record<string, string> {\n return { ...DRAWIO_SHAPES[shape] }\n}\n"],"mappings":";;;;;AAeA,MAAM,yBAAS,IAAI,IAA+B;CAChD,CAAC,aAAa,QAAQ;CACtB,CAAC,SAAS,QAAQ;CAClB,CAAC,WAAW,SAAS;CACrB,CAAC,iBAAiB,SAAS;CAC3B,CAAC,WAAW,SAAS;CACrB,CAAC,YAAY,aAAa;CAC1B,CAAC,iBAAiB,qBAAqB;CACvC,CAAC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CAAoB;CACrF,eAAe;EAAE,OAAO;EAAY,WAAW;EAAS,WAAW;CAAoB;CACvF,qBAAqB;EAAE,OAAO;EAAiB,WAAW;CAAyB;CACnF,oBAAoB;EAAE,OAAO;EAAiB,OAAO;EAAK,WAAW;CAAyB;CAC9F,cAAc,EAAE,OAAO,YAAY;CACnC,WAAW,EAAE,OAAO,gCAAgC;CACpD,UAAU,EAAE,OAAO,OAAO;CAC1B,YAAY,EAAE,OAAO,SAAS;CAC9B,WAAW;EAAE,OAAO;EAAa,WAAW;CAAqB;CACjE,oBAAoB,EAAE,OAAO,UAAU;CACvC,QAAQ,CAAC;CACT,iBAAiB,EAAE,OAAO,WAAW;CACrC,mBAAmB,EAAE,OAAO,mCAAmC;CAC/D,cAAc,EAAE,OAAO,cAAc;CACrC,SAAS;EAAE,OAAO;EAAW,WAAW;CAAoB;CAC5D,SAAS,EAAE,OAAO,OAAO;CACzB,UAAU,EAAE,OAAO,yBAAyB;CAC5C,SAAS,EAAE,OAAO,yBAAyB;CAC3C,MAAM,EAAE,OAAO,qBAAqB;CACpC,MAAM,EAAE,OAAO,QAAQ;CACvB,YAAY;EAAE,OAAO;EAAe,WAAW;CAAO;CACtD,aAAa,EAAE,OAAO,cAAc;CACpC,kBAAkB;EAAE,OAAO;EAAc,WAAW;CAAmB;CACvE,IAAI;EAAE,OAAO;EAAa,WAAW;CAAmB;CACxD,eAAe,EAAE,OAAO,UAAU;CAClC,kBAAkB,EAAE,OAAO,kBAAkB;AAC/C;AAEA,SAAgB,kBAAkB,OAAkD;CAClF,OAAO,EAAE,GAAG,cAAc,OAAO;AACnC"}
|
|
1
|
+
{"version":3,"file":"shapes.js","names":[],"sources":["../../../../src/io/formats/drawio/shapes.ts"],"sourcesContent":["import type { DrawIOStyle } from '@pairdraw/drawio'\nimport type { ShapeWithTextType } from '@pairdraw/scene-graph/shape-with-text'\n\n/** What a draw.io vertex becomes: a shape, text, a frame or section around its cells, or a group. */\nexport type VertexKind =\n /** A FigJam shape, turned clockwise by `rotation` degrees about its centre. */\n | { type: 'SHAPE_WITH_TEXT'; shape: ShapeWithTextType; rotation: number; stencil: boolean }\n | { type: 'TEXT' }\n | { type: 'FRAME' }\n | { type: 'SECTION' }\n | { type: 'RECTANGLE' }\n | { type: 'GROUP' }\n\n/**\n * draw.io shapes, by their `shape` value or stylesheet name, and the FigJam shapes with text that\n * draw them. Flowchart stencils map to the FigJam flowchart shape of the same meaning.\n */\nconst SHAPES = new Map<string, ShapeWithTextType>([\n ['rectangle', 'SQUARE'],\n ['label', 'SQUARE'],\n ['ellipse', 'ELLIPSE'],\n ['doubleEllipse', 'ELLIPSE'],\n ['rhombus', 'DIAMOND'],\n ['triangle', 'TRIANGLE_UP'],\n ['parallelogram', 'PARALLELOGRAM_RIGHT'],\n ['trapezoid', 'TRAPEZOID'],\n ['hexagon', 'HEXAGON'],\n ['cylinder', 'ENG_DATABASE'],\n ['cylinder3', 'ENG_DATABASE'],\n ['datastore', 'ENG_DATABASE'],\n ['document', 'DOCUMENT_SINGLE'],\n ['process', 'PREDEFINED_PROCESS'],\n ['manualInput', 'MANUAL_INPUT'],\n ['internalStorage', 'INTERNAL_STORAGE'],\n ['step', 'CHEVRON'],\n ['note', 'ENG_FILE'],\n ['folder', 'ENG_FOLDER'],\n ['cross', 'PLUS'],\n ['singleArrow', 'ARROW_RIGHT'],\n ['callout', 'SPEECH_BUBBLE'],\n ['sumEllipse', 'SUMMING_JUNCTION'],\n ['orEllipse', 'OR'],\n ['mxgraph.flowchart.process', 'SQUARE'],\n ['mxgraph.flowchart.decision', 'DIAMOND'],\n ['mxgraph.flowchart.terminator', 'ROUNDED_RECTANGLE'],\n ['mxgraph.flowchart.start_1', 'ELLIPSE'],\n ['mxgraph.flowchart.start_2', 'ELLIPSE'],\n ['mxgraph.flowchart.on-page_reference', 'ELLIPSE'],\n ['mxgraph.flowchart.data', 'PARALLELOGRAM_RIGHT'],\n ['mxgraph.flowchart.database', 'ENG_DATABASE'],\n ['mxgraph.flowchart.stored_data', 'ENG_DATABASE'],\n ['mxgraph.flowchart.direct_data', 'ENG_QUEUE'],\n ['mxgraph.flowchart.document', 'DOCUMENT_SINGLE'],\n ['mxgraph.flowchart.multi-document', 'DOCUMENT_MULTIPLE'],\n ['mxgraph.flowchart.predefined_process', 'PREDEFINED_PROCESS'],\n ['mxgraph.flowchart.manual_input', 'MANUAL_INPUT'],\n ['mxgraph.flowchart.internal_storage', 'INTERNAL_STORAGE'],\n ['mxgraph.flowchart.summing_function', 'SUMMING_JUNCTION'],\n ['mxgraph.flowchart.or', 'OR'],\n ['mxgraph.flowchart.extract_or_measurement', 'TRIANGLE_UP'],\n ['mxgraph.flowchart.merge_or_storage', 'TRIANGLE_DOWN'],\n ['mxgraph.basic.pentagon', 'PENTAGON'],\n ['mxgraph.basic.octagon2', 'OCTAGON'],\n ['mxgraph.basic.star', 'STAR'],\n ['mxgraph.basic.plus', 'PLUS'],\n ['mxgraph.basic.rectCallout', 'SPEECH_BUBBLE'],\n ['mxgraph.basic.oval_callout', 'SPEECH_BUBBLE']\n])\n\n/** Stylesheet names that pick a shape, as `ellipse` in `ellipse;whiteSpace=wrap;` does. */\nconst SHAPE_NAMES = new Set([...SHAPES.keys(), 'text', 'swimlane', 'group', 'image'])\n\n/** The shape a style draws: its `shape`, else the stylesheet style it names, else a rectangle. */\nexport function shapeName(style: DrawIOStyle): string {\n return style.values.shape ?? style.names.find((name) => SHAPE_NAMES.has(name)) ?? 'rectangle'\n}\n\n/** Which way `direction` points, in degrees anticlockwise from pointing right. */\nconst DIRECTION_TURN = new Map([\n ['east', 0],\n ['north', 90],\n ['west', 180],\n ['south', -90]\n])\n\n/**\n * What a vertex becomes. Text stays text; a swimlane becomes a section holding its cells, and\n * any other vertex its style makes a container becomes a frame, as Pairdraw writes one; a group\n * stays a group. A style Pairdraw wrote says when it drew a rectangle, which draw.io has no\n * style of its own for. A shape draw.io turns by `direction` keeps its turn. Any other shape, a\n * stencil FigJam has no shape for among them, becomes a shape named after the stencil.\n */\nexport function vertexKind(style: DrawIOStyle, hasChildren: boolean): VertexKind {\n const name = shapeName(style)\n if (name === 'text') return { type: 'TEXT' }\n if (style.values.pairdrawType === 'RECTANGLE') return { type: 'RECTANGLE' }\n if (name === 'swimlane') return { type: 'SECTION' }\n if (name === 'group') return { type: 'GROUP' }\n if (style.values.container === '1') return { type: 'FRAME' }\n if (hasChildren && !SHAPES.has(name)) return { type: 'GROUP' }\n let shape = SHAPES.get(name) ?? 'SQUARE'\n const direction = style.values.direction ?? 'east'\n let rotation = 0\n if (shape === 'TRIANGLE_UP' && name === 'triangle') {\n // draw.io's triangle points right; FigJam's points up and turns, clockwise for a positive\n // rotation, to point elsewhere.\n rotation = 90 - (DIRECTION_TURN.get(direction) ?? 0)\n if (rotation === 180) {\n shape = 'TRIANGLE_DOWN'\n rotation = 0\n }\n } else if (shape === 'ARROW_RIGHT' && direction === 'west') shape = 'ARROW_LEFT'\n else if (shape === 'PARALLELOGRAM_RIGHT' && style.values.flipH === '1') {\n shape = 'PARALLELOGRAM_LEFT'\n } else if (shape === 'SQUARE' && style.values.rounded === '1') shape = 'ROUNDED_RECTANGLE'\n return { type: 'SHAPE_WITH_TEXT', shape, rotation, stencil: !SHAPES.has(name) }\n}\n\n/**\n * The draw.io style that draws each FigJam shape, the other way round: built-in shapes where\n * draw.io has one, its flowchart and basic stencils otherwise. A shield, which draw.io has no\n * shape for, goes as a rectangle.\n */\nconst DRAWIO_SHAPES: Record<ShapeWithTextType, Record<string, string>> = {\n SQUARE: {},\n ROUNDED_RECTANGLE: { rounded: '1' },\n ELLIPSE: { shape: 'ellipse', perimeter: 'ellipsePerimeter' },\n DIAMOND: { shape: 'rhombus', perimeter: 'rhombusPerimeter' },\n TRIANGLE_UP: { shape: 'triangle', direction: 'north', perimeter: 'trianglePerimeter' },\n TRIANGLE_DOWN: { shape: 'triangle', direction: 'south', perimeter: 'trianglePerimeter' },\n PARALLELOGRAM_RIGHT: { shape: 'parallelogram', perimeter: 'parallelogramPerimeter' },\n PARALLELOGRAM_LEFT: { shape: 'parallelogram', flipH: '1', perimeter: 'parallelogramPerimeter' },\n ENG_DATABASE: { shape: 'cylinder3' },\n ENG_QUEUE: { shape: 'mxgraph.flowchart.direct_data' },\n ENG_FILE: { shape: 'note' },\n ENG_FOLDER: { shape: 'folder' },\n TRAPEZOID: { shape: 'trapezoid', perimeter: 'trapezoidPerimeter' },\n PREDEFINED_PROCESS: { shape: 'process' },\n SHIELD: {},\n DOCUMENT_SINGLE: { shape: 'document' },\n DOCUMENT_MULTIPLE: { shape: 'mxgraph.flowchart.multi-document' },\n MANUAL_INPUT: { shape: 'manualInput' },\n HEXAGON: { shape: 'hexagon', perimeter: 'hexagonPerimeter2' },\n CHEVRON: { shape: 'step' },\n PENTAGON: { shape: 'mxgraph.basic.pentagon' },\n OCTAGON: { shape: 'mxgraph.basic.octagon2' },\n STAR: { shape: 'mxgraph.basic.star' },\n PLUS: { shape: 'cross' },\n ARROW_LEFT: { shape: 'singleArrow', direction: 'west' },\n ARROW_RIGHT: { shape: 'singleArrow' },\n SUMMING_JUNCTION: { shape: 'sumEllipse', perimeter: 'ellipsePerimeter' },\n OR: { shape: 'orEllipse', perimeter: 'ellipsePerimeter' },\n SPEECH_BUBBLE: { shape: 'callout' },\n INTERNAL_STORAGE: { shape: 'internalStorage' }\n}\n\nexport function drawioShapeValues(shape: ShapeWithTextType): Record<string, string> {\n return { ...DRAWIO_SHAPES[shape] }\n}\n"],"mappings":";;;;;AAiBA,MAAM,yBAAS,IAAI,IAA+B;CAChD,CAAC,aAAa,QAAQ;CACtB,CAAC,SAAS,QAAQ;CAClB,CAAC,WAAW,SAAS;CACrB,CAAC,iBAAiB,SAAS;CAC3B,CAAC,WAAW,SAAS;CACrB,CAAC,YAAY,aAAa;CAC1B,CAAC,iBAAiB,qBAAqB;CACvC,CAAC,aAAa,WAAW;CACzB,CAAC,WAAW,SAAS;CACrB,CAAC,YAAY,cAAc;CAC3B,CAAC,aAAa,cAAc;CA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3D,aAAa;EAAE,OAAO;EAAY,WAAW;EAAS,WAAW;CAAoB;CACrF,eAAe;EAAE,OAAO;EAAY,WAAW;EAAS,WAAW;CAAoB;CACvF,qBAAqB;EAAE,OAAO;EAAiB,WAAW;CAAyB;CACnF,oBAAoB;EAAE,OAAO;EAAiB,OAAO;EAAK,WAAW;CAAyB;CAC9F,cAAc,EAAE,OAAO,YAAY;CACnC,WAAW,EAAE,OAAO,gCAAgC;CACpD,UAAU,EAAE,OAAO,OAAO;CAC1B,YAAY,EAAE,OAAO,SAAS;CAC9B,WAAW;EAAE,OAAO;EAAa,WAAW;CAAqB;CACjE,oBAAoB,EAAE,OAAO,UAAU;CACvC,QAAQ,CAAC;CACT,iBAAiB,EAAE,OAAO,WAAW;CACrC,mBAAmB,EAAE,OAAO,mCAAmC;CAC/D,cAAc,EAAE,OAAO,cAAc;CACrC,SAAS;EAAE,OAAO;EAAW,WAAW;CAAoB;CAC5D,SAAS,EAAE,OAAO,OAAO;CACzB,UAAU,EAAE,OAAO,yBAAyB;CAC5C,SAAS,EAAE,OAAO,yBAAyB;CAC3C,MAAM,EAAE,OAAO,qBAAqB;CACpC,MAAM,EAAE,OAAO,QAAQ;CACvB,YAAY;EAAE,OAAO;EAAe,WAAW;CAAO;CACtD,aAAa,EAAE,OAAO,cAAc;CACpC,kBAAkB;EAAE,OAAO;EAAc,WAAW;CAAmB;CACvE,IAAI;EAAE,OAAO;EAAa,WAAW;CAAmB;CACxD,eAAe,EAAE,OAAO,UAAU;CAClC,kBAAkB,EAAE,OAAO,kBAAkB;AAC/C;AAEA,SAAgB,kBAAkB,OAAkD;CAClF,OAAO,EAAE,GAAG,cAAc,OAAO;AACnC"}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { SceneGraph } from "@pairdraw/scene-graph";
|
|
2
|
+
//#region src/io/formats/drawio/warnings.d.ts
|
|
3
|
+
/**
|
|
4
|
+
* What a draw.io file cannot hold. draw.io has no variable model and no style that reads one, so
|
|
5
|
+
* a document that paints with variables arrives in draw.io as plain colours and comes back
|
|
6
|
+
* unbound. The writer names that loss instead of writing a file that looks complete.
|
|
7
|
+
*/
|
|
8
|
+
declare function drawioDroppedWarnings(graph: SceneGraph): string[];
|
|
9
|
+
//#endregion
|
|
10
|
+
export { drawioDroppedWarnings };
|
|
11
|
+
//# sourceMappingURL=warnings.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.d.ts","names":[],"sources":["../../../../src/io/formats/drawio/warnings.ts"],"mappings":";;;;;;;iBAYgB,sBAAsB,OAAO"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
//#region src/io/formats/drawio/warnings.ts
|
|
2
|
+
/** `3 variables`, with the noun matching the count. */
|
|
3
|
+
function counted(count, one, many) {
|
|
4
|
+
return `${count} ${count === 1 ? one : many}`;
|
|
5
|
+
}
|
|
6
|
+
/**
|
|
7
|
+
* What a draw.io file cannot hold. draw.io has no variable model and no style that reads one, so
|
|
8
|
+
* a document that paints with variables arrives in draw.io as plain colours and comes back
|
|
9
|
+
* unbound. The writer names that loss instead of writing a file that looks complete.
|
|
10
|
+
*/
|
|
11
|
+
function drawioDroppedWarnings(graph) {
|
|
12
|
+
const variables = graph.variables.size;
|
|
13
|
+
if (variables === 0) return [];
|
|
14
|
+
const names = [...graph.variableCollections.values()].map((collection) => collection.name);
|
|
15
|
+
const dropped = `draw.io has no variables: ${counted(variables, "variable", "variables")} in ${counted(names.length, "collection", "collections")} (${names.join(", ")}) not written`;
|
|
16
|
+
const bound = [...graph.nodes.values()].filter((node) => Object.keys(node.boundVariables).length > 0).length;
|
|
17
|
+
if (bound === 0) return [dropped];
|
|
18
|
+
return [`${dropped}, and ${bound === 1 ? "1 layer that uses one lost the binding" : `${counted(bound, "layer", "layers")} that use them lost the binding`}`];
|
|
19
|
+
}
|
|
20
|
+
//#endregion
|
|
21
|
+
export { drawioDroppedWarnings };
|
|
22
|
+
|
|
23
|
+
//# sourceMappingURL=warnings.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"warnings.js","names":[],"sources":["../../../../src/io/formats/drawio/warnings.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\n\n/** `3 variables`, with the noun matching the count. */\nfunction counted(count: number, one: string, many: string): string {\n return `${count} ${count === 1 ? one : many}`\n}\n\n/**\n * What a draw.io file cannot hold. draw.io has no variable model and no style that reads one, so\n * a document that paints with variables arrives in draw.io as plain colours and comes back\n * unbound. The writer names that loss instead of writing a file that looks complete.\n */\nexport function drawioDroppedWarnings(graph: SceneGraph): string[] {\n const variables = graph.variables.size\n if (variables === 0) return []\n const names = [...graph.variableCollections.values()].map((collection) => collection.name)\n const dropped = `draw.io has no variables: ${counted(variables, 'variable', 'variables')} in ${counted(names.length, 'collection', 'collections')} (${names.join(', ')}) not written`\n const bound = [...graph.nodes.values()].filter(\n (node) => Object.keys(node.boundVariables).length > 0\n ).length\n if (bound === 0) return [dropped]\n const users =\n bound === 1\n ? '1 layer that uses one lost the binding'\n : `${counted(bound, 'layer', 'layers')} that use them lost the binding`\n return [`${dropped}, and ${users}`]\n}\n"],"mappings":";;AAGA,SAAS,QAAQ,OAAe,KAAa,MAAsB;CACjE,OAAO,GAAG,MAAM,GAAG,UAAU,IAAI,MAAM;AACzC;;;;;;AAOA,SAAgB,sBAAsB,OAA6B;CACjE,MAAM,YAAY,MAAM,UAAU;CAClC,IAAI,cAAc,GAAG,OAAO,CAAC;CAC7B,MAAM,QAAQ,CAAC,GAAG,MAAM,oBAAoB,OAAO,CAAC,CAAC,CAAC,KAAK,eAAe,WAAW,IAAI;CACzF,MAAM,UAAU,6BAA6B,QAAQ,WAAW,YAAY,WAAW,EAAE,MAAM,QAAQ,MAAM,QAAQ,cAAc,aAAa,EAAE,IAAI,MAAM,KAAK,IAAI,EAAE;CACvK,MAAM,QAAQ,CAAC,GAAG,MAAM,MAAM,OAAO,CAAC,CAAC,CAAC,QACrC,SAAS,OAAO,KAAK,KAAK,cAAc,CAAC,CAAC,SAAS,CACtD,CAAC,CAAC;CACF,IAAI,UAAU,GAAG,OAAO,CAAC,OAAO;CAKhC,OAAO,CAAC,GAAG,QAAQ,QAHjB,UAAU,IACN,2CACA,GAAG,QAAQ,OAAO,SAAS,QAAQ,EAAE,kCACT;AACpC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { svg2pdf } from "svg2pdf.js";
|
|
1
2
|
//#region src/io/formats/pdf/dom.d.ts
|
|
2
3
|
/** A page's SVG markup as the element svg2pdf draws, or null when it does not parse. */
|
|
3
4
|
type SVGPageParser = (svg: string) => Element | null;
|
|
@@ -7,6 +8,14 @@ type SVGPageParser = (svg: string) => Element | null;
|
|
|
7
8
|
* only while `draw` runs, one export at a time, and restored after.
|
|
8
9
|
*/
|
|
9
10
|
declare function withPDFDOM<T>(draw: (parse: SVGPageParser) => Promise<T>): Promise<T>;
|
|
11
|
+
/**
|
|
12
|
+
* Loads `svg2pdf.js`. Its package publishes a UMD build only, whose factory reads jsPDF from the
|
|
13
|
+
* global `jspdf` and, with no CommonJS `exports`, writes the function to the global `svg2pdf`; a
|
|
14
|
+
* bundler supplies both, a bare Node install supplies neither, and the module then fails on load.
|
|
15
|
+
* The two globals exist only while the import evaluates, and the function the module made keeps
|
|
16
|
+
* the jsPDF it read, so the rest of the export needs nothing from them.
|
|
17
|
+
*/
|
|
18
|
+
declare function loadSVG2PDF(jsPDF: unknown): Promise<typeof svg2pdf>;
|
|
10
19
|
//#endregion
|
|
11
|
-
export { SVGPageParser, withPDFDOM };
|
|
20
|
+
export { SVGPageParser, loadSVG2PDF, withPDFDOM };
|
|
12
21
|
//# sourceMappingURL=dom.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dom.d.ts","names":[],"sources":["../../../../src/io/formats/pdf/dom.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"dom.d.ts","names":[],"sources":["../../../../src/io/formats/pdf/dom.ts"],"mappings":";;;KAMY,iBAAiB,gBAAgB;;;;;;iBAyD7B,WAAW,GAAG,OAAO,OAAO,kBAAkB,QAAQ,KAAK,QAAQ;;;;;;;;iBA+C7D,YAAY,iBAAiB,eAAe"}
|