AI-native design editor. Open-source Figma alternative.
fix(drawio): keep turned and mirrored layers in place, join curves by draw.io's side (#1509)
Danila Poyarkov02e82024db2c
diff --git a/changes/1446/added.md b/changes/1446/added.mdindex f689ee79d..23b75e78e 100644--- a/changes/1446/added.md+++ b/changes/1446/added.md@@ -1 +1 @@-- draw.io diagrams open: `.drawio` and `.dio` files and draw.io's editable PNG and SVG exports become pages of FigJam shapes with text and connectors joined to them, keeping their colours, labels, arrowheads, bend points, layers, and containers.+- draw.io diagrams open, in the desktop app also from the system: `.drawio` and `.dio` files and draw.io's editable PNG and SVG exports become pages of FigJam shapes with text and connectors joined to them, keeping their colours, labels, arrowheads, bend points, turns and mirroring, layers, and containers.diff --git a/changes/1447/added.md b/changes/1447/added.mdindex 8a4a89512..25ee169ab 100644--- a/changes/1447/added.md+++ b/changes/1447/added.md@@ -1 +1 @@-- Designs save as draw.io files: FigJam shapes, connectors, text, sections, frames, and groups as their draw.io counterparts, and anything else as an image, from the export menu for the document, a page, or a selection.+- Designs save as draw.io files: FigJam shapes, connectors, text, sections, frames, and groups as their draw.io counterparts, turned and mirrored where they are, and anything else as an image, from **File › Export selection** and the Export panel, for a selection or a page.diff --git a/desktop/generated/menu.json b/desktop/generated/menu.jsonindex a4fdac8d7..2ac32fe11 100644--- a/desktop/generated/menu.json+++ b/desktop/generated/menu.json@@ -72,6 +72,10 @@"id": "export-pptx","label": "PPTX"},+ {+ "id": "export-drawio",+ "label": "draw.io"+ },{"id": "export-fig","label": ".fig"diff --git a/desktop/src/launch/args.rs b/desktop/src/launch/args.rsindex 1d6bba5be..12d2cee02 100644--- a/desktop/src/launch/args.rs+++ b/desktop/src/launch/args.rs@@ -8,7 +8,7 @@ pub fn file_association_path(path: PathBuf) -> Option<PathBuf> {return None;}let ext = path.extension()?.to_string_lossy().to_lowercase();- matches!(ext.as_str(), "fig" | "pen").then_some(path)+ matches!(ext.as_str(), "fig" | "pen" | "drawio" | "dio").then_some(path)}fn path_from_arg(arg: String, cwd: &Path) -> Option<PathBuf> {diff --git a/desktop/tauri.conf.json b/desktop/tauri.conf.jsonindex d7b958bfd..00931134d 100644--- a/desktop/tauri.conf.json+++ b/desktop/tauri.conf.json@@ -49,6 +49,14 @@"role": "Editor","mimeType": "application/x-figma","rank": "Alternate"+ },+ {+ "ext": ["drawio", "dio"],+ "name": "draw.io Diagram",+ "description": "draw.io diagram",+ "role": "Editor",+ "mimeType": "application/vnd.jgraph.mxfile",+ "rank": "Alternate"}],"linux": {diff --git a/packages/core/src/io/formats/drawio/edges.ts b/packages/core/src/io/formats/drawio/edges.tsindex 288a38f2e..7e2229b5d 100644--- a/packages/core/src/io/formats/drawio/edges.ts+++ b/packages/core/src/io/formats/drawio/edges.ts@@ -20,6 +20,7 @@ import {freeEndpoint,layoutConnector} from '@open-pencil/scene-graph/connectors'+import { getAxisAlignedBoundsInParent } from '@open-pencil/scene-graph/coordinate'import type { Vector } from '@open-pencil/scene-graph/primitives'import { readLabel } from './label'@@ -138,13 +139,27 @@ export function createEdge(* edge stores when it joins nothing.*//**- * The side of `box` that faces `toward`, as an edge bent through a point leaves or enters by the- * side that point lies beyond; null for a point over the box.+ * The side of `box` that faces `toward`, as an edge bent through a point leaves or enters by; null+ * for a point over the box. An elbow runs square to the side the point lies beyond; a curve+ * leaves by the side a line from the box's centre to the point crosses, where draw.io ends one+ * that names no point on the layer.*/function sideFacing(box: Pick<SceneNode, 'x' | 'y' | 'width' | 'height'>,- toward: Vector+ toward: Vector,+ curved: boolean): ConnectorMagnet | null {+ const over =+ toward.x >= box.x &&+ toward.x <= box.x + box.width &&+ toward.y >= box.y &&+ toward.y <= box.y + box.height+ if (curved && !over) {+ const dx = toward.x - (box.x + box.width / 2)+ const dy = toward.y - (box.y + box.height / 2)+ if (Math.abs(dx) * box.height >= Math.abs(dy) * box.width) return dx > 0 ? 'RIGHT' : 'LEFT'+ return dy > 0 ? 'BOTTOM' : 'TOP'+ }if (toward.x > box.x + box.width) return 'RIGHT'if (toward.x < box.x) return 'LEFT'if (toward.y < box.y) return 'TOP'@@ -157,7 +172,7 @@ function endpointOf(layerOf: (cellId: string) => string | undefined,edge: DrawIOCell,end: 'source' | 'target',- straight: boolean+ lineType: ConnectorLineType): ConnectorEndpoint {const cellId = edge[end]const nodeId = cellId ? layerOf(cellId) : undefined@@ -175,10 +190,15 @@ function endpointOf(}const { points } = edge.geometryconst toward = end === 'source' ? points.at(0) : points.at(-1)- // Both share the edge's parent's axes when the layer is a sibling of the edge.- const facing =- toward && node.parentId === layerOf(edge.parent) ? sideFacing(node, toward) : null- return boundEndpoint(node.id, straight ? 'CENTER' : (facing ?? 'AUTO'))+ // The point is in the edge's parent's axes, so the layer's box is taken there too, for a+ // layer nested deeper than the edge as much as for a sibling.+ const edgeParentId = layerOf(edge.parent)+ const box =+ node.parentId === edgeParentId || !edgeParentId+ ? node+ : getAxisAlignedBoundsInParent([node], edgeParentId, graph)+ const facing = toward ? sideFacing(box, toward, lineType === 'CURVED') : null+ return boundEndpoint(node.id, lineType === 'STRAIGHT' ? 'CENTER' : (facing ?? 'AUTO'))}const point = end === 'source' ? edge.geometry.sourcePoint : edge.geometry.targetPointreturn freeEndpoint(point?.x ?? 0, point?.y ?? 0)@@ -217,10 +237,10 @@ export function bindEdge({ connector, edge, labels }: PendingEdge,layerOf: (cellId: string) => string | undefined): DrawIOCell[] {- const straight = connector.connectorLineType === 'STRAIGHT'+ const lineType = connector.connectorLineTypegraph.updateNode(connector.id, {- connectorStart: endpointOf(graph, layerOf, edge, 'source', straight),- connectorEnd: endpointOf(graph, layerOf, edge, 'target', straight)+ connectorStart: endpointOf(graph, layerOf, edge, 'source', lineType),+ connectorEnd: endpointOf(graph, layerOf, edge, 'target', lineType)})const own = edge.value ? [edge] : []const all = [...own, ...labels]diff --git a/packages/core/src/io/formats/drawio/export.ts b/packages/core/src/io/formats/drawio/export.tsindex ff0c7a0cc..141a6a421 100644--- a/packages/core/src/io/formats/drawio/export.ts+++ b/packages/core/src/io/formats/drawio/export.ts@@ -16,36 +16,26 @@ import {connectorSublayers,curveMidpoint} from '@open-pencil/scene-graph/connectors'-import { getParentWorldMatrix } from '@open-pencil/scene-graph/coordinate'+import { getParentWorldMatrix, getWorldMatrix } from '@open-pencil/scene-graph/coordinate'import {isGeneratedFrame,shapeWithTextLabel,stickySublayers} from '@open-pencil/scene-graph/generated'-import Matrix, { type Mat3 } from '@open-pencil/scene-graph/matrix'+import Matrix from '@open-pencil/scene-graph/matrix'import type { Vector } from '@open-pencil/scene-graph/primitives'+import { computeContentBounds } from '#core/io/formats/raster'import { renderNodesToSVG } from '#core/io/formats/svg'import { DEFAULT_FONT_FAMILY } from './paint'+import { EMPTY_GEOMETRY, placed, placedValues, round, type Placed } from './placement'import { drawioShapeValues } from './shapes'/** draw.io's id for its root cell and for its one layer, as it numbers new files. */const ROOT_ID = '0'const LAYER_ID = '1'-const EMPTY_GEOMETRY: DrawIOGeometry = {- x: 0,- y: 0,- width: 0,- height: 0,- relative: false,- points: [],- sourcePoint: null,- targetPoint: null,- offset: null-}-function style(names: string[], values: Record<string, string | undefined>): DrawIOStyle {return {names,@@ -53,68 +43,6 @@ function style(names: string[], values: Record<string, string | undefined>): Dra}}-function round(value: number): number {- return Math.round(value * 100) / 100-}--function box(node: SceneNode): DrawIOGeometry {- return {- ...EMPTY_GEOMETRY,- x: round(node.x),- y: round(node.y),- width: round(node.width),- height: round(node.height)- }-}--/**- * Carries a layer's parent's axes into the page's, for a selected layer whose parent is not- * written: draw.io places it on its one layer, which has the page's axes.- */-interface ToPage {- matrix: Mat3- /** How far the parent turns its axes, in degrees. */- turn: number-}--function toPageOf(graph: SceneGraph, node: SceneNode, pageId: string): ToPage | null {- if (!node.parentId || node.parentId === pageId) return null- const matrix = getParentWorldMatrix(graph.getNode(node.parentId), graph)- const origin = Matrix.mapPoint(matrix, { x: 0, y: 0 })- const across = Matrix.mapPoint(matrix, { x: 1, y: 0 })- const turn = (Math.atan2(across.y - origin.y, across.x - origin.x) * 180) / Math.PI- return { matrix, turn }-}--/** Where a layer sits and how far it turns about its centre, in draw.io's axes. */-interface Placed {- geometry: DrawIOGeometry- rotation: number-}--function placed(node: SceneNode, toPage: ToPage | null): Placed {- if (!toPage) return { geometry: box(node), rotation: node.rotation }- // draw.io turns a cell about its centre, as the layer turns, so the centre carries its place.- const centre = Matrix.mapPoint(toPage.matrix, {- x: node.x + node.width / 2,- y: node.y + node.height / 2- })- const rotation = ((((node.rotation + toPage.turn + 180) % 360) + 360) % 360) - 180- return {- geometry: {- ...box(node),- x: round(centre.x - node.width / 2),- y: round(centre.y - node.height / 2)- },- rotation- }-}--/** A turn as draw.io's `rotation` style value, which an unturned cell leaves out. */-function rotationValue(rotation: number): string | undefined {- return rotation === 0 ? undefined : String(round(rotation))-}-const escapeHTML = (text: string) =>text.replaceAll('&', '&').replaceAll('<', '<').replaceAll('>', '>')@@ -246,6 +174,8 @@ class PageWriter {private readonly ids = new Map<string, string>()/** Where each edge's line last ran from and to, in draw.io's axes. */private readonly drawnEnds = new Map<string, { start: DrawIOPoint; end: DrawIOPoint }>()+ /** Where each vertex's box starts on the page: draw.io measures its cells' boxes from there. */+ private readonly origins = new Map<string, Vector>([[LAYER_ID, { x: 0, y: 0 }]])private next = 2constructor(@@ -279,7 +209,7 @@ class PageWriter {for (const id of roots) assign(id)for (const id of roots) {const node = this.graph.getNode(id)- if (node) this.layer(node, LAYER_ID, toPageOf(this.graph, node, this.pageId))+ if (node) this.layer(node, LAYER_ID)}this.freeStrandedEnds()}@@ -310,8 +240,13 @@ class PageWriter {cell: Omit<DrawIOCell, 'id' | 'parent' | 'visible' | 'attributes' | 'source' | 'target'> &Partial<Pick<DrawIOCell, 'source' | 'target'>>) {+ const id = this.idOf(node.id)+ if (cell.kind === 'vertex') {+ const from = this.originOf(parent)+ this.origins.set(id, { x: from.x + cell.geometry.x, y: from.y + cell.geometry.y })+ }this.cells.push({- id: this.idOf(node.id),+ id,parent,visible: node.visible,attributes: {},@@ -321,18 +256,41 @@ class PageWriter {})}+ private originOf(parent: string): Vector {+ return this.origins.get(parent) ?? { x: 0, y: 0 }+ }++ private place(node: SceneNode, parent: string): Placed {+ return placed(node, getWorldMatrix(node, this.graph), this.originOf(parent))+ }++ /** The box a layer covers on the page, square to it, in its parent cell's axes. */+ private bounds(node: SceneNode, parent: string): DrawIOGeometry {+ const bounds = computeContentBounds(this.graph, [node.id])+ if (!bounds) return this.place(node, parent).geometry+ const from = this.originOf(parent)+ return {+ ...EMPTY_GEOMETRY,+ x: round(bounds.minX - from.x),+ y: round(bounds.minY - from.y),+ width: round(bounds.maxX - bounds.minX),+ height: round(bounds.maxY - bounds.minY)+ }+ }+private children(node: SceneNode) {for (const id of node.childIds) {const child = this.graph.getNode(id)- if (child) this.layer(child, this.idOf(node.id), null)+ if (child) this.layer(child, this.idOf(node.id))}}- private layer(node: SceneNode, parent: string, toPage: ToPage | null) {- const { geometry, rotation } = placed(node, toPage)+ private layer(node: SceneNode, parent: string) {+ const placement = this.place(node, parent)+ const { geometry } = placementswitch (node.type) {case 'SHAPE_WITH_TEXT':- return this.shape(node, parent, toPage)+ return this.shape(node, parent, placement)case 'TEXT':return this.push(node, parent, {kind: 'vertex',@@ -340,7 +298,7 @@ class PageWriter {style: style(['text'], {html: '1',whiteSpace: 'wrap',- rotation: rotationValue(rotation),+ ...placedValues(placement),...fontValues(node)}),geometry@@ -358,7 +316,7 @@ class PageWriter {align: 'left',verticalAlign: 'top',spacing: '20',- rotation: rotationValue(rotation),+ ...placedValues(placement),fontSize: body ? String(body.fontSize) : undefined}),geometry@@ -368,7 +326,12 @@ class PageWriter {this.push(node, parent, {kind: 'vertex',value: escapeHTML(node.name),- style: style(['swimlane'], { html: '1', startSize: '30', ...paintValues(node) }),+ style: style(['swimlane'], {+ html: '1',+ startSize: '30',+ ...paintValues(node),+ ...placedValues(placement)+ }),geometry})return this.children(node)@@ -377,14 +340,20 @@ class PageWriter {kind: 'vertex',value: '',style: style(['group'], {}),- geometry+ // A group draws nothing, so it holds what it groups square to the page.+ geometry: this.bounds(node, parent)})return this.children(node)case 'FRAME':this.push(node, parent, {kind: 'vertex',value: '',- style: style([], { container: '1', html: '1', ...paintValues(node) }),+ style: style([], {+ container: '1',+ html: '1',+ ...paintValues(node),+ ...placedValues(placement)+ }),geometry})return this.children(node)@@ -395,19 +364,19 @@ class PageWriter {value: '',style: style(node.type === 'ELLIPSE' ? ['ellipse'] : [], {rounded: node.cornerRadius > 0 ? '1' : undefined,- rotation: rotationValue(rotation),+ ...placedValues(placement),...paintValues(node)}),geometry})case 'CONNECTOR':- return this.edge(node, parent, toPage)+ return this.edge(node, parent)default:- return this.picture(node, parent, geometry)+ return this.picture(node, parent)}}- private shape(node: SceneNode, parent: string, toPage: ToPage | null) {+ private shape(node: SceneNode, parent: string, placement: Placed) {const label = shapeWithTextLabel(this.graph, node)const values: Record<string, string | undefined> = {...drawioShapeValues(node.shapeWithTextType),@@ -416,9 +385,11 @@ class PageWriter {...paintValues(node),...(label ? fontValues(label) : {})}- let { geometry, rotation } = placed(node, toPage)+ let { geometry, rotation } = placement// A triangle turned a quarter points the way draw.io's direction says, in the box it fills.- const quarter = Math.abs(rotation) === 90 && node.shapeWithTextType === 'TRIANGLE_UP'+ const mirrored = placement.flipH || placement.flipV+ const quarter =+ !mirrored && Math.abs(rotation) === 90 && node.shapeWithTextType === 'TRIANGLE_UP'if (quarter) {values.direction = rotation === 90 ? 'east' : 'west'geometry = {@@ -430,7 +401,12 @@ class PageWriter {}rotation = 0}- values.rotation = rotationValue(rotation)+ // A shape that is draw.io's mirrored one, as a left parallelogram is, mirrors back if the layer is.+ const ownFlipH = values.flipH === '1'+ Object.assign(+ values,+ placedValues({ ...placement, rotation, flipH: placement.flipH !== ownFlipH })+ )this.push(node, parent, {kind: 'vertex',value: label ? labelHTML(label) : '',@@ -439,8 +415,8 @@ class PageWriter {})}- /** A layer draw.io has no cell for, drawn as the SVG image it exports as. */- private picture(node: SceneNode, parent: string, geometry: DrawIOGeometry) {+ /** A layer draw.io has no cell for, drawn as the SVG image it exports as, where it covers. */+ private picture(node: SceneNode, parent: string) {const svg = renderNodesToSVG(this.graph, this.pageId, [node.id])if (!svg) returnconst data = fromUint8Array(new TextEncoder().encode(svg))@@ -449,7 +425,7 @@ class PageWriter {value: '',// draw.io keeps a data URI in its style without `;base64`, which would end the value.style: style([], { shape: 'image', image: `data:image/svg+xml,${data}`, aspect: 'fixed' }),- geometry+ geometry: this.bounds(node, parent)})}@@ -473,10 +449,15 @@ class PageWriter {* Where an edge's free ends sit, its bend points, and its label's place along it, with the* points carried into draw.io's axes.*/- private edgeGeometry(node: SceneNode, toPage: ToPage | null): DrawIOGeometry {+ private edgeGeometry(node: SceneNode, parent: string): DrawIOGeometry {+ const toPage = getParentWorldMatrix(+ node.parentId ? this.graph.getNode(node.parentId) : undefined,+ this.graph+ )+ const from = this.originOf(parent)const at = (point: Vector) => {- const mapped = toPage ? Matrix.mapPoint(toPage.matrix, point) : point- return { x: round(mapped.x), y: round(mapped.y) }+ const mapped = Matrix.mapPoint(toPage, point)+ return { x: round(mapped.x - from.x), y: round(mapped.y - from.y) }}const drawn = connectorRouteEnds(this.graph, node)if (drawn) {@@ -494,7 +475,7 @@ class PageWriter {}}- private edge(node: SceneNode, parent: string, toPage: ToPage | null) {+ private edge(node: SceneNode, parent: string) {// A connector without its line and label is not one draw.io could draw.const parts = connectorSublayers(this.graph, node)if (!parts) return@@ -516,7 +497,7 @@ class PageWriter {...this.end(node.connectorEnd, 'entry'),...fontValues(parts.label)}),- geometry: this.edgeGeometry(node, toPage),+ geometry: this.edgeGeometry(node, parent),source: startId ? (this.ids.get(startId) ?? null) : null,target: endId ? (this.ids.get(endId) ?? null) : null})diff --git a/packages/core/src/io/formats/drawio/index.ts b/packages/core/src/io/formats/drawio/index.tsindex 6d10e23cf..8f348a662 100644--- a/packages/core/src/io/formats/drawio/index.ts+++ b/packages/core/src/io/formats/drawio/index.ts@@ -1,4 +1,4 @@-import type { DrawIOCell, DrawIOFile, DrawIOPage } from '@open-pencil/drawio'+import type { DrawIOCell, DrawIOFile, DrawIOPage, DrawIOStyle } from '@open-pencil/drawio'import { SceneGraph, type SceneNode } from '@open-pencil/scene-graph'import { connectorRoute, placeConnectorLabel } from '@open-pencil/scene-graph/connectors'import { createShapeWithText } from '@open-pencil/scene-graph/generated'@@ -15,6 +15,19 @@ function labelOf(cell: DrawIOCell) {return { format, ...readLabel(cell.value, cell.style.values.html === '1', format) }}+/**+ * A cell's turn and mirrors as a layer's. draw.io mirrors a cell about its centre and then turns+ * it, negating the turn when it mirrors one way only; a layer turns and then mirrors, so that+ * turn is the layer's own. `ownFlipH` is a mirror the shape itself stands for, as a left+ * parallelogram is draw.io's mirrored one.+ */+function placementOf(style: DrawIOStyle, ownFlipH = false) {+ const flipX = style.values.flipH === '1' && !ownFlipH+ const flipY = style.values.flipV === '1'+ const turn = Number(style.values.rotation ?? 0) || 0+ return { flipX, flipY, rotation: flipX === flipY ? turn : -turn }+}+/** The first line of a label, as a layer's name. */function nameOf(text: string, fallback: string): string {return text.split('\n')[0]?.trim() || fallback@@ -99,6 +112,7 @@ class PageBuilder {if (kind.type === 'TEXT') {return graph.createNode('TEXT', parentId, {...box,+ ...placementOf(cell.style),name: nameOf(label.text, 'Text'),...labelFields(cell.style, label.format),text: label.text,@@ -127,13 +141,15 @@ class PageBuilder {? { x: x + (width - height) / 2, y: y + (height - width) / 2, width: height, height: width }: { x, y, width, height }const known = shapeName(cell.style)+ const own = placementOf(cell.style, kind.shape === 'PARALLELOGRAM_LEFT')return createShapeWithText(graph,parentId,{...placed,visible: cell.visible,- rotation: kind.rotation,+ ...own,+ rotation: own.rotation + kind.rotation,shapeWithTextType: kind.shape,// draw.io sized it, so it keeps its size, as a FigJam shape whose height was set does.shapeTruncates: true,diff --git a/packages/core/src/io/formats/drawio/placement.ts b/packages/core/src/io/formats/drawio/placement.tsnew file mode 100644index 000000000..7745bb4ba--- /dev/null+++ b/packages/core/src/io/formats/drawio/placement.ts@@ -0,0 +1,87 @@+import type { DrawIOGeometry } from '@open-pencil/drawio'+import type { SceneNode } from '@open-pencil/scene-graph'+import Matrix, { type Mat3 } from '@open-pencil/scene-graph/matrix'+import type { Vector } from '@open-pencil/scene-graph/primitives'++/** A cell with no box or points, for the fields a cell leaves unset. */+export const EMPTY_GEOMETRY: DrawIOGeometry = {+ x: 0,+ y: 0,+ width: 0,+ height: 0,+ relative: false,+ points: [],+ sourcePoint: null,+ targetPoint: null,+ offset: null+}++/** A length to the hundredth, as draw.io writes them. */+export function round(value: number): number {+ return Math.round(value * 100) / 100+}++function box(node: SceneNode): DrawIOGeometry {+ return {+ ...EMPTY_GEOMETRY,+ x: round(node.x),+ y: round(node.y),+ width: round(node.width),+ height: round(node.height)+ }+}++/** Where a layer sits, how far it turns about its centre, and how it is mirrored, as draw.io says. */+export interface Placed {+ geometry: DrawIOGeometry+ rotation: number+ flipH: boolean+ flipV: boolean+}++/** An angle in degrees between -180 and 180. */+function normalAngle(degrees: number): number {+ return ((((degrees + 180) % 360) + 360) % 360) - 180+}++/**+ * A layer drawn by `world`, its matrix on the page, as a draw.io cell whose parent's box starts at+ * `origin` on the page. draw.io mirrors a cell about its centre and then turns it, negating the+ * turn when it mirrors one way only, and turns or mirrors no cell inside another with it, so+ * each cell carries the whole of its own matrix. Either way a cell is mirrored, what its down+ * axis points to gives the turn.+ */+export function placed(node: SceneNode, world: Mat3, origin: Vector): Placed {+ const centre = Matrix.mapPoint(world, { x: node.width / 2, y: node.height / 2 })+ const [a, b, , c, d] = world+ const geometry = {+ ...box(node),+ x: round(centre.x - node.width / 2 - origin.x),+ y: round(centre.y - node.height / 2 - origin.y)+ }+ const turn = (Math.atan2(-b, d) * 180) / Math.PI+ if (a * d - b * c < 0) {+ // A layer mirrored up and down by itself stays so; any other mirror goes left to right.+ const flipV = node.flipY && !node.flipX+ const rotation = flipV ? (Math.atan2(b, -d) * 180) / Math.PI : turn+ return { geometry, rotation: normalAngle(rotation), flipH: !flipV, flipV }+ }+ // Mirrored both ways is a half turn, which a layer flipped both ways keeps as flips.+ if (node.flipX && node.flipY) {+ return { geometry, rotation: normalAngle(turn - 180), flipH: true, flipV: true }+ }+ return { geometry, rotation: normalAngle(turn), flipH: false, flipV: false }+}++/** A placed cell's turn and mirrors as style pairs, which an unturned, unmirrored cell leaves out. */+export function placedValues({+ rotation,+ flipH,+ flipV+}: Placed): Record<string, string | undefined> {+ return {+ rotation: Math.abs(rotation) < 1e-6 ? undefined : String(round(rotation)),+ flipH: flipH ? '1' : undefined,+ flipV: flipV ? '1' : undefined+ }+}diff --git a/packages/core/tests/io/formats/drawio/export.test.ts b/packages/core/tests/io/formats/drawio/export.test.tsindex cab9053a6..ec7a8f24c 100644--- a/packages/core/tests/io/formats/drawio/export.test.ts+++ b/packages/core/tests/io/formats/drawio/export.test.ts@@ -11,7 +11,9 @@ import {createConnector,freeEndpoint} from '@open-pencil/scene-graph/connectors'+import { getWorldMatrix } from '@open-pencil/scene-graph/coordinate'import { createShapeWithText } from '@open-pencil/scene-graph/generated'+import Matrix from '@open-pencil/scene-graph/matrix'import { BUILTIN_IO_FORMATS, IORegistry } from '#core/io'import type { ExportTarget } from '#core/io'@@ -144,6 +146,82 @@ describe('saving a draw.io file', () => {expect(cells.map((cell) => cell.style.values.rotation)).toEqual(['30', '-45', '15'])})+ test('turned and mirrored layers, also in a turned and mirrored group, open where they were', async () => {+ const graph = new SceneGraph()+ const page = graph.getPages()[0]+ const group = graph.createNode('GROUP', page.id, {+ x: 100,+ y: 80,+ width: 300,+ height: 200,+ rotation: 30,+ flipX: true+ })+ const shapes = [+ { text: 'Up', shapeWithTextType: 'TRIANGLE_UP', rotation: 20, flipY: true },+ { text: 'Quarter', shapeWithTextType: 'TRIANGLE_UP', rotation: 90 },+ { text: 'Left', shapeWithTextType: 'PARALLELOGRAM_LEFT', rotation: -10, flipX: true },+ { text: 'Both', shapeWithTextType: 'DIAMOND', rotation: 45, flipX: true, flipY: true }+ ] as const+ for (const [index, { text, ...fields }] of shapes.entries()) {+ const at = { x: 20 + index * 70, y: 30, width: 60, height: 40 }+ createShapeWithText(graph, page.id, { ...at, ...fields, name: text }, { text })+ const name = `${text} grouped`+ createShapeWithText(graph, group.id, { ...at, ...fields, name }, { text: name })+ }+ graph.createNode('TEXT', group.id, {+ name: 'Note',+ x: 10,+ y: 120,+ width: 80,+ height: 20,+ text: 'Note'+ })+ graph.createNode('TEXT', page.id, {+ x: 300,+ y: 300,+ width: 80,+ height: 20,+ rotation: 15,+ flipX: true,+ name: 'Mirrored',+ text: 'Mirrored'+ })++ /** Where each named layer's corners land on the page, in its own order. */+ const corners = (of: SceneGraph) =>+ Object.fromEntries(+ [...of.getAllNodes()]+ .filter((node) => node.type === 'SHAPE_WITH_TEXT' || node.type === 'TEXT')+ // A shape's label goes with its shape.+ .filter((node) => of.getNode(node.parentId ?? '')?.type !== 'SHAPE_WITH_TEXT')+ .map((node) => [+ node.name,+ Matrix.mapPoints(getWorldMatrix(node, of), [+ 0,+ 0,+ node.width,+ 0,+ node.width,+ node.height,+ 0,+ node.height+ ]).map((n) => Math.round(n * 10) / 10)+ ])+ )+ const opened = await read(await write(graph))+ const { Left: left, ...before } = corners(graph)+ const { Left: reopened, ...after } = corners(opened)+ expect(Object.keys(before)).toHaveLength(9)+ expect(after).toEqual(before)+ // A mirrored left parallelogram is a right one.+ const right = [...opened.getAllNodes()].find((node) => node.name === 'Left')+ expect(right?.shapeWithTextType).toBe('PARALLELOGRAM_RIGHT')+ const points = (flat: number[] = []) =>+ flat.flatMap((n, i) => (i % 2 ? [] : [`${n},${flat[i + 1]}`])).toSorted()+ expect(points(reopened)).toEqual(points(left))+ })+test('non-rectangular shapes name the outline edges attach to', async () => {const graph = new SceneGraph()const page = graph.getPages()[0]diff --git a/packages/core/tests/io/formats/drawio/import.test.ts b/packages/core/tests/io/formats/drawio/import.test.tsindex e37d047f9..9d9453b00 100644--- a/packages/core/tests/io/formats/drawio/import.test.ts+++ b/packages/core/tests/io/formats/drawio/import.test.ts@@ -2,12 +2,12 @@ import { describe, expect, test } from 'bun:test'import { expectDefined } from '#core-tests/helpers/assert'-import { BUILTIN_IO_FORMATS, IORegistry } from '#core/io'-import type { SceneGraph, SceneNode } from '@open-pencil/scene-graph'import { connectorSublayers } from '@open-pencil/scene-graph/connectors'import { shapeWithTextLabel } from '@open-pencil/scene-graph/generated'+import { BUILTIN_IO_FORMATS, IORegistry } from '#core/io'+const io = new IORegistry(BUILTIN_IO_FORMATS)/** A draw.io file whose first page holds `cells` on draw.io's default layer. */@@ -28,7 +28,10 @@ function onPage(graph: SceneGraph): SceneNode[] {}function byName(graph: SceneGraph, name: string): SceneNode {- return expectDefined([...graph.getAllNodes()].find((node) => node.name === name), name)+ return expectDefined(+ [...graph.getAllNodes()].find((node) => node.name === name),+ name+ )}describe('opening draw.io files', () => {@@ -54,14 +57,31 @@ describe('draw.io shapes', () => {test('become FigJam shapes with text of the same kind, sized and painted as drawn', async () => {const graph = await read(file(- vertex('a', 'rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;strokeWidth=2;', [40, 60, 120, 60], 'Start') +- vertex('b', 'rhombus;whiteSpace=wrap;html=1;fillColor=none;dashed=1;', [280, 40, 100, 100], '<b>Ok</b>?') ++ vertex(+ 'a',+ 'rounded=1;whiteSpace=wrap;html=1;fillColor=#dae8fc;strokeColor=#6c8ebf;strokeWidth=2;',+ [40, 60, 120, 60],+ 'Start'+ ) ++ vertex(+ 'b',+ 'rhombus;whiteSpace=wrap;html=1;fillColor=none;dashed=1;',+ [280, 40, 100, 100],+ '<b>Ok</b>?'+ ) +vertex('c', 'shape=cylinder3;whiteSpace=wrap;html=1;', [280, 240, 80, 100], 'Store') +vertex('d', 'shape=mxgraph.aws4.lambda;', [600, 40, 60, 60], 'Lambda')))expect(- onPage(graph).map((node) => [node.type, node.shapeWithTextType, node.x, node.y, node.width, node.height])+ onPage(graph).map((node) => [+ node.type,+ node.shapeWithTextType,+ node.x,+ node.y,+ node.width,+ node.height+ ])).toEqual([['SHAPE_WITH_TEXT', 'ROUNDED_RECTANGLE', 40, 60, 120, 60],['SHAPE_WITH_TEXT', 'DIAMOND', 280, 40, 100, 100],@@ -89,24 +109,44 @@ describe('draw.io shapes', () => {)const [right, down] = onPage(graph)// Turned a quarter about the centre of the box it fills.- expect([right.shapeWithTextType, right.rotation, right.x, right.y, right.width, right.height]).toEqual(['TRIANGLE_UP', 90, 490, 50, 80, 60])+ expect([+ right.shapeWithTextType,+ right.rotation,+ right.x,+ right.y,+ right.width,+ right.height+ ]).toEqual(['TRIANGLE_UP', 90, 490, 50, 80, 60])expect([down.shapeWithTextType, down.rotation]).toEqual(['TRIANGLE_DOWN', 0])})test('text stays text, and a swimlane is a section around its cells', async () => {const graph = await read(file(- vertex('t', 'text;html=1;align=left;verticalAlign=top;fontSize=20;fontColor=#ff0000;', [40, 20, 200, 30], 'Title') ++ vertex(+ 't',+ 'text;html=1;align=left;verticalAlign=top;fontSize=20;fontColor=#ff0000;',+ [40, 20, 200, 30],+ 'Title'+ ) +vertex('lane', 'swimlane;whiteSpace=wrap;html=1;', [40, 100, 300, 200], 'Team') +vertex('in', 'whiteSpace=wrap;html=1;', [20, 40, 100, 50], 'Task', 'lane')))const title = byName(graph, 'Title')- expect(title).toMatchObject({ type: 'TEXT', text: 'Title', fontSize: 20, textAlignHorizontal: 'LEFT', textAlignVertical: 'TOP' })+ expect(title).toMatchObject({+ type: 'TEXT',+ text: 'Title',+ fontSize: 20,+ textAlignHorizontal: 'LEFT',+ textAlignVertical: 'TOP'+ })expect(title.fills[0]?.color).toMatchObject({ r: 1, g: 0, b: 0 })const lane = byName(graph, 'Team')expect(lane).toMatchObject({ type: 'SECTION', x: 40, y: 100, width: 300, height: 200 })- expect(graph.getChildren(lane.id).map((node) => [node.name, node.x, node.y])).toEqual([['Task', 20, 40]])+ expect(graph.getChildren(lane.id).map((node) => [node.name, node.x, node.y])).toEqual([+ ['Task', 20, 40]+ ])})})@@ -135,7 +175,11 @@ describe('draw.io edges', () => {})const parts = expectDefined(connectorSublayers(graph, goes))expect(parts.label.text).toBe('goes')- expect(parts.line.strokes[0]).toMatchObject({ weight: 2, color: { r: 1, g: 0, b: 0 }, dashPattern: [6, 6] })+ expect(parts.line.strokes[0]).toMatchObject({+ weight: 2,+ color: { r: 1, g: 0, b: 0 },+ dashPattern: [6, 6]+ })// exitX/exitY pin an end to a point of its shape; an unfilled triangle is an open arrow.expect(exits).toMatchObject({connectorLineType: 'STRAIGHT',@@ -159,13 +203,50 @@ describe('draw.io edges', () => {))const connector = expectDefined(onPage(graph).find((node) => node.type === 'CONNECTOR'))- expect([connector.connectorStart?.magnet, connector.connectorEnd?.magnet]).toEqual(['RIGHT', 'RIGHT'])+ expect([connector.connectorStart?.magnet, connector.connectorEnd?.magnet]).toEqual([+ 'RIGHT',+ 'RIGHT'+ ])const { line } = expectDefined(connectorSublayers(graph, connector))- const points = (line.vectorNetwork?.vertices ?? []).map((v) => [connector.x + line.x + v.x, connector.y + line.y + v.y])+ const points = (line.vectorNetwork?.vertices ?? []).map((v) => [+ connector.x + line.x + v.x,+ connector.y + line.y + v.y+ ])expect(points.some(([x]) => x === 600)).toBe(true)expect(points.at(0)?.[0]).toBeGreaterThan(520)})+ test('curved through a point off a corner leave and enter where draw.io ends them', async () => {+ // Beyond both shapes' right sides but further below B and above C than across.+ const graph = await read(+ file(+ shapes ++ `<mxCell id="e" style="curved=1;" edge="1" parent="1" source="b" target="c"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="600" y="190"/></Array></mxGeometry></mxCell>`+ )+ )+ const connector = expectDefined(onPage(graph).find((node) => node.type === 'CONNECTOR'))+ expect([connector.connectorStart?.magnet, connector.connectorEnd?.magnet]).toEqual([+ 'BOTTOM',+ 'TOP'+ ])+ })++ test('bent toward a shape inside a group join it by the side facing the point', async () => {+ // The group holds C at 400, 260 on the page; the curve to it runs on the page.+ const graph = await read(+ file(+ vertex('a', 'whiteSpace=wrap;', [40, 60, 120, 60], 'A') ++ vertex('g', 'group;', [300, 200, 300, 200], '') ++ vertex('c', 'whiteSpace=wrap;', [100, 60, 120, 60], 'C', 'g') ++ `<mxCell id="e" style="curved=1;" edge="1" parent="1" source="a" target="c"><mxGeometry relative="1" as="geometry"><Array as="points"><mxPoint x="460" y="160"/></Array></mxGeometry></mxCell>`+ )+ )+ const connector = expectDefined(+ [...graph.getAllNodes()].find((node) => node.type === 'CONNECTOR')+ )+ expect(connector.connectorEnd?.magnet).toBe('TOP')+ })+test('take the labels draw.io keeps along them, where it keeps them', async () => {const graph = await read(file(@@ -176,7 +257,11 @@ describe('draw.io edges', () => {))const connector = expectDefined(onPage(graph).find((node) => node.type === 'CONNECTOR'))- expect(connector.connectorLabelPosition).toEqual({ section: 'MIDDLE_TO_START', offset: 0.5, offAxis: 'NONE' })+ expect(connector.connectorLabelPosition).toEqual({+ section: 'MIDDLE_TO_START',+ offset: 0.5,+ offAxis: 'NONE'+ })expect(connectorSublayers(graph, connector)?.label.text).toBe('first')// A second label draws as text by the edge.expect(byName(graph, 'second').type).toBe('TEXT')@@ -197,7 +282,12 @@ describe('draw.io edges', () => {test('style values named like built-in object members fall back as unknown values do', async () => {const graph = await read(file(- vertex('a', 'triangle;direction=constructor;align=constructor;verticalAlign=toString;', [0, 0, 80, 60], 'A') ++ vertex(+ 'a',+ 'triangle;direction=constructor;align=constructor;verticalAlign=toString;',+ [0, 0, 80, 60],+ 'A'+ ) +vertex('b', '', [200, 0, 80, 60], 'B') +`<mxCell id="e" style="endArrow=constructor;startArrow=valueOf;" edge="1" parent="1" source="a" target="b"><mxGeometry relative="1" as="geometry"/></mxCell>`)@@ -206,8 +296,13 @@ test('style values named like built-in object members fall back as unknown value// An unknown direction points east, as draw.io's default does: FigJam's triangle turned a quarter.expect(shape.rotation).toBe(90)const connector = expectDefined(onPage(graph).find((node) => node.type === 'CONNECTOR'))- expect([connector.connectorStartCap, connector.connectorEndCap]).toEqual(['ARROW_LINES', 'ARROW_LINES'])- const label = expectDefined([...graph.getAllNodes()].find((node) => node.type === 'TEXT' && node.text === 'A'))+ expect([connector.connectorStartCap, connector.connectorEndCap]).toEqual([+ 'ARROW_LINES',+ 'ARROW_LINES'+ ])+ const label = expectDefined(+ [...graph.getAllNodes()].find((node) => node.type === 'TEXT' && node.text === 'A')+ )expect([label.textAlignHorizontal, label.textAlignVertical]).toEqual(['CENTER', 'CENTER'])})@@ -218,20 +313,39 @@ describe('draw.io pages and layers', () => {)expect(graph.getPages().map((page) => page.name)).toEqual(['One', 'Two'])const [base, notes] = onPage(graph)- expect([base.type, base.name, notes.type, notes.name, notes.visible]).toEqual(['GROUP', 'Layer 1', 'GROUP', 'Notes', false])+ expect([base.type, base.name, notes.type, notes.name, notes.visible]).toEqual([+ 'GROUP',+ 'Layer 1',+ 'GROUP',+ 'Notes',+ false+ ])expect(graph.getChildren(base.id).map((node) => node.name)).toEqual(['Below', 'Above'])expect(graph.getChildren(notes.id).map((node) => node.name)).toEqual(['Hidden note'])})test('a single hidden or locked layer is a group that stays so', async () => {- const graph = await read(file(vertex('a', '', [0, 0, 50, 50], 'Shape'), '<mxCell id="1" value="Only" style="locked=1;" parent="0" visible="0"/>'))+ const graph = await read(+ file(+ vertex('a', '', [0, 0, 50, 50], 'Shape'),+ '<mxCell id="1" value="Only" style="locked=1;" parent="0" visible="0"/>'+ )+ )const [layer] = onPage(graph)- expect([layer.type, layer.name, layer.visible, layer.locked]).toEqual(['GROUP', 'Only', false, true])+ expect([layer.type, layer.name, layer.visible, layer.locked]).toEqual([+ 'GROUP',+ 'Only',+ false,+ true+ ])})test('a cell listed before its parent still lands inside it', async () => {const graph = await read(- file(vertex('child', '', [10, 10, 40, 40], 'Child', 'g') + vertex('g', 'group;', [100, 100, 60, 60], '', '1'))+ file(+ vertex('child', '', [10, 10, 40, 40], 'Child', 'g') ++ vertex('g', 'group;', [100, 100, 60, 60], '', '1')+ ))const child = byName(graph, 'Child')const group = expectDefined(graph.getNode(expectDefined(child.parentId)))@@ -247,7 +361,9 @@ describe('draw.io pages and layers', () => {'<mxCell id="1" parent="0"/><mxCell id="2" parent="0"/>'))- const connector = expectDefined([...graph.getAllNodes()].find((node) => node.type === 'CONNECTOR'))+ const connector = expectDefined(+ [...graph.getAllNodes()].find((node) => node.type === 'CONNECTOR')+ )const layer = expectDefined(graph.getNode(expectDefined(connector.parentId)))const end = expectDefined(connector.connectorEnd).positionexpect([layer.x + end.x, layer.y + end.y]).toEqual([700, 700])diff --git a/packages/drawio/tests/read.test.ts b/packages/drawio/tests/read.test.tsindex 21d83b5f8..21676e387 100644--- a/packages/drawio/tests/read.test.ts+++ b/packages/drawio/tests/read.test.ts@@ -202,6 +202,23 @@ describe('reading the diagram a draw.io export embeds', () => {expect(() => readDrawIOBytes(whole.subarray(0, -20))).toThrow('cut short')})+ test('counts what a PNG’s chunk unpacks to against the limit its pages share', () => {+ // The chunk and each page unpack within the limit; the chunk and both pages do not.+ const model = (share: number) =>+ `<mxGraphModel><root><mxCell id="0"/><mxCell id="1" parent="0" value="${'x'.repeat(+ MAX_INFLATED_BYTES * share+ )}"/></root></mxGraphModel>`+ const packed = compressed(model(0.3))+ const pages = ['First', 'Second'].map(+ (name) => `<diagram id="${name}" name="${name}">${packed}</diagram>`+ )+ const padding = 'x'.repeat(MAX_INFLATED_BYTES * 0.5)+ const embedded = encodeURIComponent(`<mxfile padding="${padding}">${pages.join('')}</mxfile>`)+ const file = readDrawIOBytes(png(chunk('zTXt', concat([latin1('mxfile\0\0'), zlib(embedded)]))))+ expect(file?.pages.map((p) => p.name)).toEqual(['First'])+ expect(file?.unreadable).toEqual(['Second'])+ })+test('takes an SVG’s comments before its root in stride', () => {const svg = `${'<!---->'.repeat(10_000)}x`expect(readDrawIOBytes(new TextEncoder().encode(svg))).toBeNull()diff --git a/packages/feedback/src/contract/schema.ts b/packages/feedback/src/contract/schema.tsindex 93379ab4c..84319cd8a 100644--- a/packages/feedback/src/contract/schema.ts+++ b/packages/feedback/src/contract/schema.ts@@ -12,6 +12,7 @@ export const LOCALES = ['en', 'de', 'es', 'fr', 'it', 'ja', 'pl', 'ru', 'zh-CN']export const DOCUMENT_FORMATS = ['fig','pen',+ 'drawio','png','jpg','webp',diff --git a/packages/scene-graph/src/export-format.ts b/packages/scene-graph/src/export-format.tsindex 44282b85a..e2248d376 100644--- a/packages/scene-graph/src/export-format.ts+++ b/packages/scene-graph/src/export-format.ts@@ -3,7 +3,7 @@* export adapter that supports node export; labels and options come from that* adapter, so this list only decides what the Export panel offers.*/-export const EXPORT_FORMAT_IDS = ['png', 'jpg', 'webp', 'svg', 'pdf', 'pptx'] as const+export const EXPORT_FORMAT_IDS = ['png', 'jpg', 'webp', 'svg', 'pdf', 'pptx', 'drawio'] as constexport type ExportFormatId = (typeof EXPORT_FORMAT_IDS)[number]diff --git a/packages/vue/src/document/export/helpers.ts b/packages/vue/src/document/export/helpers.tsindex 720e11fb2..39c62d8fc 100644--- a/packages/vue/src/document/export/helpers.ts+++ b/packages/vue/src/document/export/helpers.ts@@ -31,10 +31,13 @@ export { MIN_EXPORT_SCALE, MAX_EXPORT_SCALE, clampExportScale }const io = new IORegistry(BUILTIN_IO_FORMATS)+/** Formats known by a product name rather than their extension. */+const PRODUCT_LABELS: Partial<Record<ExportFormatId, string>> = { drawio: 'draw.io' }+/** Short, extension-style labels for the node export formats (PNG, PDF, PPTX, …). */export const EXPORT_FORMAT_OPTIONS: ExportFormatOption[] = EXPORT_FORMATS.map((id) => ({value: id,- label: (io.getFormat(id)?.extensions[0] ?? id).toUpperCase()+ label: PRODUCT_LABELS[id] ?? (io.getFormat(id)?.extensions[0] ?? id).toUpperCase()}))export function createDefaultExportSetting(): ExportSetting {diff --git a/packages/vue/src/i18n/locales/de/menu.json b/packages/vue/src/i18n/locales/de/menu.jsonindex 9a7e06566..a24733242 100644--- a/packages/vue/src/i18n/locales/de/menu.json+++ b/packages/vue/src/i18n/locales/de/menu.json@@ -77,6 +77,7 @@"exportSelectionAsPNG": "Auswahl als PNG exportieren","exportSelectionAsSVG": "Auswahl als SVG exportieren","exportSelectionAsPPTX": "Auswahl als PPTX exportieren",+ "exportSelectionAsDrawIO": "Auswahl als draw.io exportieren","exportSelectionAsFig": "Auswahl als .fig exportieren","togglePreview": "Vorschau","browseFiles": "Dateien durchsuchen…",diff --git a/packages/vue/src/i18n/locales/es/menu.json b/packages/vue/src/i18n/locales/es/menu.jsonindex 73d863bb5..a90d95a8a 100644--- a/packages/vue/src/i18n/locales/es/menu.json+++ b/packages/vue/src/i18n/locales/es/menu.json@@ -77,6 +77,7 @@"exportSelectionAsPNG": "Exportar selección como PNG","exportSelectionAsSVG": "Exportar selección como SVG","exportSelectionAsPPTX": "Exportar selección como PPTX",+ "exportSelectionAsDrawIO": "Exportar selección como draw.io","exportSelectionAsFig": "Exportar selección como .fig","togglePreview": "Vista previa","browseFiles": "Explorar archivos…",diff --git a/packages/vue/src/i18n/locales/fr/menu.json b/packages/vue/src/i18n/locales/fr/menu.jsonindex ac4d8a80b..7702a7ef9 100644--- a/packages/vue/src/i18n/locales/fr/menu.json+++ b/packages/vue/src/i18n/locales/fr/menu.json@@ -77,6 +77,7 @@"exportSelectionAsPNG": "Exporter la sélection en PNG","exportSelectionAsSVG": "Exporter la sélection en SVG","exportSelectionAsPPTX": "Exporter la sélection en PPTX",+ "exportSelectionAsDrawIO": "Exporter la sélection en draw.io","exportSelectionAsFig": "Exporter la sélection en .fig","togglePreview": "Aperçu","browseFiles": "Parcourir les fichiers…",diff --git a/packages/vue/src/i18n/locales/it/menu.json b/packages/vue/src/i18n/locales/it/menu.jsonindex 9d56292f4..aab3d2d17 100644--- a/packages/vue/src/i18n/locales/it/menu.json+++ b/packages/vue/src/i18n/locales/it/menu.json@@ -77,6 +77,7 @@"exportSelectionAsPNG": "Esporta selezione come PNG","exportSelectionAsSVG": "Esporta selezione come SVG","exportSelectionAsPPTX": "Esporta selezione come PPTX",+ "exportSelectionAsDrawIO": "Esporta selezione come draw.io","exportSelectionAsFig": "Esporta selezione come .fig","togglePreview": "Anteprima","browseFiles": "Sfoglia file…",diff --git a/packages/vue/src/i18n/locales/ja/menu.json b/packages/vue/src/i18n/locales/ja/menu.jsonindex 13036c22d..fb6c856ce 100644--- a/packages/vue/src/i18n/locales/ja/menu.json+++ b/packages/vue/src/i18n/locales/ja/menu.json@@ -77,6 +77,7 @@"exportSelectionAsPNG": "選択範囲を PNG としてエクスポート","exportSelectionAsSVG": "選択範囲を SVG としてエクスポート","exportSelectionAsPPTX": "選択範囲を PPTX としてエクスポート",+ "exportSelectionAsDrawIO": "選択範囲を draw.io としてエクスポート","exportSelectionAsFig": "選択範囲を .fig としてエクスポート","togglePreview": "プレビュー","browseFiles": "ファイルを表示…",diff --git a/packages/vue/src/i18n/locales/pl/menu.json b/packages/vue/src/i18n/locales/pl/menu.jsonindex f95edc62e..37f850bdc 100644--- a/packages/vue/src/i18n/locales/pl/menu.json+++ b/packages/vue/src/i18n/locales/pl/menu.json@@ -77,6 +77,7 @@"exportSelectionAsPNG": "Eksportuj zaznaczenie jako PNG","exportSelectionAsSVG": "Eksportuj zaznaczenie jako SVG","exportSelectionAsPPTX": "Eksportuj zaznaczenie jako PPTX",+ "exportSelectionAsDrawIO": "Eksportuj zaznaczenie jako draw.io","exportSelectionAsFig": "Eksportuj zaznaczenie jako .fig","togglePreview": "Podgląd","browseFiles": "Przeglądaj pliki…",diff --git a/packages/vue/src/i18n/locales/ru/menu.json b/packages/vue/src/i18n/locales/ru/menu.jsonindex ee5f6aa27..a62f6658d 100644--- a/packages/vue/src/i18n/locales/ru/menu.json+++ b/packages/vue/src/i18n/locales/ru/menu.json@@ -77,6 +77,7 @@"exportSelectionAsPNG": "Экспортировать выделение как PNG","exportSelectionAsSVG": "Экспортировать выделение как SVG","exportSelectionAsPPTX": "Экспортировать выделение как PPTX",+ "exportSelectionAsDrawIO": "Экспортировать выделение как draw.io","exportSelectionAsFig": "Экспортировать выделение как .fig","togglePreview": "Просмотр","browseFiles": "Обзор файлов…",diff --git a/packages/vue/src/i18n/locales/zh-cn/menu.json b/packages/vue/src/i18n/locales/zh-cn/menu.jsonindex d14915713..46762dead 100644--- a/packages/vue/src/i18n/locales/zh-cn/menu.json+++ b/packages/vue/src/i18n/locales/zh-cn/menu.json@@ -77,6 +77,7 @@"exportSelectionAsPNG": "将所选内容导出为 PNG","exportSelectionAsSVG": "将所选内容导出为 SVG","exportSelectionAsPPTX": "将所选内容导出为 PPTX",+ "exportSelectionAsDrawIO": "将所选内容导出为 draw.io","exportSelectionAsFig": "将所选内容导出为 .fig","togglePreview": "预览","browseFiles": "浏览文件…",diff --git a/packages/vue/src/i18n/messages/menu.ts b/packages/vue/src/i18n/messages/menu.tsindex c2d1d9f37..2763bff3c 100644--- a/packages/vue/src/i18n/messages/menu.ts+++ b/packages/vue/src/i18n/messages/menu.ts@@ -21,6 +21,7 @@ export const menuMessageDefaults = {exportSelectionAsPNG: 'Export selection as PNG',exportSelectionAsSVG: 'Export selection as SVG',exportSelectionAsPPTX: 'Export selection as PPTX',+ exportSelectionAsDrawIO: 'Export selection as draw.io',exportSelectionAsFig: 'Export selection as .fig',autosave: 'Auto-save to local file',closeTab: 'Close tab',diff --git a/src/app/shell/menu/app-menu.ts b/src/app/shell/menu/app-menu.tsindex fa2c338fc..5efba216b 100644--- a/src/app/shell/menu/app-menu.ts+++ b/src/app/shell/menu/app-menu.ts@@ -198,6 +198,7 @@ export function useAppMenu() {'export-png': () => exportSelection('png'),'export-svg': () => exportSelection('svg'),'export-pptx': () => exportSelection('pptx'),+ 'export-drawio': () => exportSelection('drawio'),'export-fig': () => exportSelection('fig'),...createSharedEditorMenuActions(setTheme)}diff --git a/src/app/shell/menu/editor.ts b/src/app/shell/menu/editor.tsindex 75fd19e2e..1417b0cd0 100644--- a/src/app/shell/menu/editor.ts+++ b/src/app/shell/menu/editor.ts@@ -56,6 +56,9 @@ export function useEditorMenu() {'export-pptx': () => {if (store.state.selectedIds.size > 0) void store.exportSelection(1, 'pptx')},+ 'export-drawio': () => {+ if (store.state.selectedIds.size > 0) void store.exportSelection(1, 'drawio')+ },'export-fig': () => {if (store.state.selectedIds.size > 0) void store.exportSelection(1, 'fig')},diff --git a/src/app/shell/menu/schema.ts b/src/app/shell/menu/schema.tsindex 10af51fbb..fff4b0f02 100644--- a/src/app/shell/menu/schema.ts+++ b/src/app/shell/menu/schema.ts@@ -22,6 +22,7 @@ export type AppMenuPaletteLabel =| 'exportSelectionAsPNG'| 'exportSelectionAsSVG'| 'exportSelectionAsPPTX'+ | 'exportSelectionAsDrawIO'| 'exportSelectionAsFig'export interface AppMenuPaletteMetadata {@@ -117,6 +118,11 @@ export const APP_MENU_SCHEMA = [label: 'PPTX',palette: { icon: 'download', label: 'exportSelectionAsPPTX' }},+ {+ id: 'export-drawio',+ label: 'draw.io',+ palette: { icon: 'download', label: 'exportSelectionAsDrawIO' }+ },{id: 'export-fig',label: '.fig',diff --git a/tests/e2e/export/basic.spec.ts b/tests/e2e/export/basic.spec.tsindex 82bde4fa8..ede0ad8f4 100644--- a/tests/e2e/export/basic.spec.ts+++ b/tests/e2e/export/basic.spec.ts@@ -111,7 +111,7 @@ test('format selector changes to JPG', async () => {await expect(formatTrigger).toHaveAttribute('aria-label', 'Export format')await formatTrigger.click()- for (const label of ['PNG', 'JPG', 'WEBP', 'SVG', 'PDF', 'PPTX']) {+ for (const label of ['PNG', 'JPG', 'WEBP', 'SVG', 'PDF', 'PPTX', 'draw.io']) {await expect(page.locator('[role="option"]').filter({ hasText: label })).toBeVisible()}@@ -230,6 +230,16 @@ test('a PPTX export setting downloads a PowerPoint file', async () => {canvas.assertNoErrors()})+test('a draw.io export setting downloads a draw.io file', async () => {+ await createExportableRect([{ scale: 1, format: 'drawio' }])+ await forceBlobDownload()++ await expect(exportItems().first().getByRole('textbox', { name: 'Export scale' })).toHaveCount(0)+ const [download] = await Promise.all([page.waitForEvent('download'), exportButton().click()])+ expect(download.suggestedFilename()).toBe('Export rect 1.drawio')+ canvas.assertNoErrors()+})+test('preview toggle shows image with blob src', async () => {const formatTrigger = exportItems().first().getByRole('combobox', { name: 'Export format' })await formatTrigger.click()diff --git a/tests/engine/io/export-formats.test.ts b/tests/engine/io/export-formats.test.tsindex b14867b66..02f028e86 100644--- a/tests/engine/io/export-formats.test.ts+++ b/tests/engine/io/export-formats.test.ts@@ -13,6 +13,7 @@ describe('export setting formats', () => {test('recognizes only persisted export formats', () => {expect(isExportFormatId('pptx')).toBe(true)+ expect(isExportFormatId('drawio')).toBe(true)expect(isExportFormatId('fig')).toBe(false)expect(isExportFormatId('PNG')).toBe(false)})diff --git a/tools/checks/i18n/mixed-script-baseline.txt b/tools/checks/i18n/mixed-script-baseline.txtindex c00cd97de..f6e39123c 100644--- a/tools/checks/i18n/mixed-script-baseline.txt+++ b/tools/checks/i18n/mixed-script-baseline.txt@@ -185,6 +185,7 @@ ja:menu.copyNodeIdja:menu.copyXPathja:menu.exportSelectionAsFigja:menu.exportSelectionAsPNG+ja:menu.exportSelectionAsDrawIOja:menu.exportSelectionAsPPTXja:menu.exportSelectionAsSVGja:menu.toggleUI@@ -408,6 +409,7 @@ zh-cn:menu.copyNodeIdzh-cn:menu.copyXPathzh-cn:menu.exportSelectionAsFigzh-cn:menu.exportSelectionAsPNG+zh-cn:menu.exportSelectionAsDrawIOzh-cn:menu.exportSelectionAsPPTXzh-cn:menu.exportSelectionAsSVGzh-cn:panels.behaviourAddVariants