@pairdraw/drawio 0.19.2 → 0.21.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.
@@ -59,7 +59,7 @@ const NO_GEOMETRY = {
59
59
  function readGeometry(cell) {
60
60
  const geometry = childElements(cell, "mxGeometry").at(0);
61
61
  if (!geometry) return structuredClone(NO_GEOMETRY);
62
- const points = childElements(geometry, "Array").find((e) => e.getAttribute("as") === "points");
62
+ const points = childElements(geometry, "mxArray").find((e) => e.getAttribute("as") === "points");
63
63
  const point = (as) => {
64
64
  const found = childElements(geometry, "mxPoint").find((p) => p.getAttribute("as") === as);
65
65
  return found ? pointOf(found) : null;
@@ -225,7 +225,7 @@ function geometry(document, value) {
225
225
  if (value.sourcePoint) element.appendChild(point(document, value.sourcePoint, "sourcePoint"));
226
226
  if (value.targetPoint) element.appendChild(point(document, value.targetPoint, "targetPoint"));
227
227
  if (value.points.length > 0) {
228
- const points = document.createElement("Array");
228
+ const points = document.createElement("mxArray");
229
229
  points.setAttribute("as", "points");
230
230
  for (const at of value.points) points.appendChild(point(document, at));
231
231
  element.appendChild(points);
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/style.ts","../../src/read.ts","../../src/write.ts","../../src/index.ts"],"sourcesContent":["import type { DrawIOStyle } from './model'\n\n/** A `style` string as its style names and its pairs. */\nexport function parseStyle(style: string): DrawIOStyle {\n const result: DrawIOStyle = { names: [], values: {} }\n for (const part of style.split(';')) {\n const text = part.trim()\n if (!text) continue\n const eq = text.indexOf('=')\n if (eq === -1) result.names.push(text)\n else result.values[text.slice(0, eq)] = text.slice(eq + 1)\n }\n return result\n}\n\n/** A style as draw.io writes it: its names, then `key=value;` pairs, in order. */\nexport function formatStyle({ names, values }: DrawIOStyle): string {\n const pairs = Object.entries(values).flatMap(([key, value]) =>\n value === undefined ? [] : [`${key}=${value}`]\n )\n return [...names, ...pairs].map((part) => `${part};`).join('')\n}\n\n/** A number the style sets for `key`, or `fallback`. */\nexport function styleNumber(style: DrawIOStyle, key: string, fallback: number): number {\n const value = Number.parseFloat(style.values[key] ?? '')\n return Number.isFinite(value) ? value : fallback\n}\n\n/** Whether the style turns `key` on, as `key=1` does. */\nexport function styleFlag(style: DrawIOStyle, key: string): boolean {\n return style.values[key] === '1'\n}\n","import type { Element } from '@xmldom/xmldom'\nimport { isValid, toUint8Array } from 'js-base64'\n\nimport { boundedInflate, inflateBudget, percentDecoded, type InflateBudget } from './inflate'\nimport type {\n DrawIOCell,\n DrawIOFile,\n DrawIOGeometry,\n DrawIOLayer,\n DrawIOPage,\n DrawIOPoint\n} from './model'\nimport { parseStyle, styleFlag } from './style'\nimport { attributesOf, childElements, parseXML } from './xml'\n\n/** What a cell wrapper keeps for itself rather than as the cell's attributes. */\nconst WRAPPER_OWN = new Set(['id', 'label'])\n\nfunction number(element: Element, name: string, fallback = 0): number {\n const value = Number.parseFloat(element.getAttribute(name) ?? '')\n return Number.isFinite(value) ? value : fallback\n}\n\nfunction pointOf(element: Element): DrawIOPoint {\n return { x: number(element, 'x'), y: number(element, 'y') }\n}\n\nconst NO_GEOMETRY: DrawIOGeometry = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n relative: false,\n points: [],\n sourcePoint: null,\n targetPoint: null,\n offset: null\n}\n\nfunction readGeometry(cell: Element): DrawIOGeometry {\n const geometry = childElements(cell, 'mxGeometry').at(0)\n if (!geometry) return structuredClone(NO_GEOMETRY)\n const points = childElements(geometry, 'Array').find((e) => e.getAttribute('as') === 'points')\n const point = (as: string) => {\n const found = childElements(geometry, 'mxPoint').find((p) => p.getAttribute('as') === as)\n return found ? pointOf(found) : null\n }\n return {\n x: number(geometry, 'x'),\n y: number(geometry, 'y'),\n width: number(geometry, 'width'),\n height: number(geometry, 'height'),\n relative: geometry.getAttribute('relative') === '1',\n points: points ? childElements(points, 'mxPoint').map(pointOf) : [],\n sourcePoint: point('sourcePoint'),\n targetPoint: point('targetPoint'),\n offset: point('offset')\n }\n}\n\n/** A cell element, and the `UserObject` or `object` around it when there is one. */\ninterface CellElements {\n cell: Element\n wrapper: Element | null\n}\n\nfunction cellElements(element: Element): CellElements | null {\n if (element.localName === 'mxCell') return { cell: element, wrapper: null }\n if (element.localName !== 'UserObject' && element.localName !== 'object') return null\n const cell = childElements(element, 'mxCell').at(0)\n return cell ? { cell, wrapper: element } : null\n}\n\nfunction readCell({ cell, wrapper }: CellElements, id: string, parent: string): DrawIOCell {\n const isEdge = cell.getAttribute('edge') === '1'\n return {\n id,\n parent,\n kind: isEdge ? 'edge' : 'vertex',\n value: (wrapper ? wrapper.getAttribute('label') : cell.getAttribute('value')) ?? '',\n style: parseStyle(cell.getAttribute('style') ?? ''),\n geometry: readGeometry(cell),\n visible: cell.getAttribute('visible') !== '0',\n source: cell.getAttribute('source'),\n target: cell.getAttribute('target'),\n attributes: wrapper ? attributesOf(wrapper, WRAPPER_OWN) : {}\n }\n}\n\n/**\n * A model's cells. Its root is the one cell without a parent, and its layers are the cells under\n * the root that are neither shapes nor edges; draw.io names them `0` and `1` by default.\n */\nfunction readModel(model: Element, page: Pick<DrawIOPage, 'id' | 'name'>): DrawIOPage | null {\n const root = childElements(model, 'root').at(0)\n if (!root) return null\n const read: { elements: CellElements; id: string; parent: string | null }[] = []\n for (const element of childElements(root)) {\n const elements = cellElements(element)\n const id = (elements?.wrapper ?? elements?.cell)?.getAttribute('id')\n if (elements && id) read.push({ elements, id, parent: elements.cell.getAttribute('parent') })\n }\n const rootId = read.find((entry) => !entry.parent)?.id\n if (rootId === undefined) return null\n const layers: DrawIOLayer[] = []\n const cells: DrawIOCell[] = []\n for (const { elements, id, parent } of read) {\n if (!parent) continue\n const { cell } = elements\n const shown = cell.getAttribute('vertex') === '1' || cell.getAttribute('edge') === '1'\n if (!shown && parent === rootId) {\n layers.push({\n id,\n name: cell.getAttribute('value') ?? '',\n visible: cell.getAttribute('visible') !== '0',\n locked: styleFlag(parseStyle(cell.getAttribute('style') ?? ''), 'locked')\n })\n } else if (shown) {\n cells.push(readCell(elements, id, parent))\n }\n }\n return {\n ...page,\n attributes: attributesOf(model, new Set()),\n rootId,\n layers,\n cells\n }\n}\n\n/** The XML inside a compressed `<diagram>`: Base64, raw deflate, then percent-encoded text. */\nfunction inflateDiagram(text: string, budget: InflateBudget): string | null {\n const encoded = text.trim()\n if (!encoded || !isValid(encoded)) return null\n try {\n return percentDecoded(new TextDecoder().decode(boundedInflate(toUint8Array(encoded), budget)))\n } catch {\n return null\n }\n}\n\nfunction readDiagram(\n diagram: Element,\n index: number,\n budget: InflateBudget\n): DrawIOPage | { unreadable: string } {\n const name = diagram.getAttribute('name') || `Page ${index + 1}`\n const page = { id: diagram.getAttribute('id') ?? `page-${index + 1}`, name }\n let model = childElements(diagram, 'mxGraphModel').at(0) ?? null\n if (!model) {\n const xml = inflateDiagram(diagram.textContent ?? '', budget)\n const root = xml ? parseXML(xml) : null\n model = root?.localName === 'mxGraphModel' ? root : null\n }\n return (model ? readModel(model, page) : null) ?? { unreadable: name }\n}\n\n/**\n * The pages of a draw.io file, whether its diagrams are plain or compressed, with the names of\n * pages it could not read: damaged, or past what the file may unpack to. Null when the source\n * is not a draw.io file.\n */\nexport function parseDrawIOFile(source: string, budget = inflateBudget()): DrawIOFile | null {\n const root = parseXML(source)\n return root ? readDrawIORoot(root, budget) : null\n}\n\n/** The pages of a draw.io document from its parsed root, as `parseDrawIOFile` reads them. */\nexport function readDrawIORoot(root: Element, budget: InflateBudget): DrawIOFile | null {\n if (root.localName === 'mxGraphModel') {\n const page = readModel(root, { id: 'page-1', name: 'Page 1' })\n return page ? { pages: [page], unreadable: [] } : null\n }\n if (root.localName !== 'mxfile') return null\n const file: DrawIOFile = { pages: [], unreadable: [] }\n for (const [index, diagram] of childElements(root, 'diagram').entries()) {\n const read = readDiagram(diagram, index, budget)\n if ('unreadable' in read) file.unreadable.push(read.unreadable)\n else file.pages.push(read)\n }\n return file\n}\n","import { DOMImplementation, XMLSerializer, type Document, type Element } from '@xmldom/xmldom'\n\nimport type { DrawIOCell, DrawIOFile, DrawIOGeometry, DrawIOPage, DrawIOPoint } from './model'\nimport { formatStyle } from './style'\n\n/** What the writer puts on `<mxfile>`, so draw.io knows who wrote it. */\nconst HOST = 'Pairdraw'\n\nfunction setNumber(element: Element, name: string, value: number) {\n if (value !== 0) element.setAttribute(name, String(value))\n}\n\nfunction point(document: Document, at: DrawIOPoint, as?: string): Element {\n const element = document.createElement('mxPoint')\n element.setAttribute('x', String(at.x))\n element.setAttribute('y', String(at.y))\n if (as) element.setAttribute('as', as)\n return element\n}\n\nfunction geometry(document: Document, value: DrawIOGeometry): Element {\n const element = document.createElement('mxGeometry')\n setNumber(element, 'x', value.x)\n setNumber(element, 'y', value.y)\n setNumber(element, 'width', value.width)\n setNumber(element, 'height', value.height)\n if (value.relative) element.setAttribute('relative', '1')\n element.setAttribute('as', 'geometry')\n if (value.sourcePoint) element.appendChild(point(document, value.sourcePoint, 'sourcePoint'))\n if (value.targetPoint) element.appendChild(point(document, value.targetPoint, 'targetPoint'))\n if (value.points.length > 0) {\n const points = document.createElement('Array')\n points.setAttribute('as', 'points')\n for (const at of value.points) points.appendChild(point(document, at))\n element.appendChild(points)\n }\n if (value.offset) element.appendChild(point(document, value.offset, 'offset'))\n return element\n}\n\n/** A cell as draw.io writes it, wrapped in a `UserObject` when it carries attributes. */\nfunction cellElement(document: Document, cell: DrawIOCell): Element {\n const element = document.createElement('mxCell')\n const wrapped = Object.keys(cell.attributes).length > 0\n if (!wrapped) {\n element.setAttribute('id', cell.id)\n element.setAttribute('value', cell.value)\n }\n const style = formatStyle(cell.style)\n if (style) element.setAttribute('style', style)\n element.setAttribute(cell.kind, '1')\n if (!cell.visible) element.setAttribute('visible', '0')\n element.setAttribute('parent', cell.parent)\n if (cell.source) element.setAttribute('source', cell.source)\n if (cell.target) element.setAttribute('target', cell.target)\n element.appendChild(geometry(document, cell.geometry))\n if (!wrapped) return element\n const wrapper = document.createElement('UserObject')\n wrapper.setAttribute('label', cell.value)\n for (const [name, value] of Object.entries(cell.attributes)) wrapper.setAttribute(name, value)\n wrapper.setAttribute('id', cell.id)\n wrapper.appendChild(element)\n return wrapper\n}\n\nfunction pageElement(document: Document, page: DrawIOPage): Element {\n const diagram = document.createElement('diagram')\n diagram.setAttribute('id', page.id)\n diagram.setAttribute('name', page.name)\n const model = document.createElement('mxGraphModel')\n for (const [name, value] of Object.entries(page.attributes)) model.setAttribute(name, value)\n const root = document.createElement('root')\n const rootCell = document.createElement('mxCell')\n rootCell.setAttribute('id', page.rootId)\n root.appendChild(rootCell)\n for (const layer of page.layers) {\n const element = document.createElement('mxCell')\n element.setAttribute('id', layer.id)\n if (layer.name) element.setAttribute('value', layer.name)\n if (layer.locked) element.setAttribute('style', 'locked=1;')\n if (!layer.visible) element.setAttribute('visible', '0')\n element.setAttribute('parent', page.rootId)\n root.appendChild(element)\n }\n for (const cell of page.cells) root.appendChild(cellElement(document, cell))\n model.appendChild(root)\n diagram.appendChild(model)\n return diagram\n}\n\n/**\n * A draw.io file as XML draw.io opens: each page a `<diagram>` holding its model uncompressed,\n * as draw.io itself saves by default, so the file diffs and reads as text. A file with pages that\n * could not be read is refused, since writing it would drop them.\n */\nexport function writeDrawIOFile(file: DrawIOFile): string {\n if (file.unreadable.length > 0) {\n throw new Error(`Could not write the draw.io pages ${file.unreadable.join(', ')}`)\n }\n const document = new DOMImplementation().createDocument(null, 'mxfile', null)\n const root = document.documentElement\n if (!root) throw new Error('Could not create a draw.io document')\n root.setAttribute('host', HOST)\n for (const page of file.pages) root.appendChild(pageElement(document, page))\n return new XMLSerializer().serializeToString(document)\n}\n","import { drawioRoot } from './embedded'\nimport { inflateBudget } from './inflate'\nimport type { DrawIOFile } from './model'\nimport { readDrawIORoot } from './read'\n\nexport { isDrawIOExportFileName } from './embedded'\nexport { MAX_INFLATED_BYTES } from './inflate'\nexport type {\n DrawIOCell,\n DrawIOFile,\n DrawIOGeometry,\n DrawIOLayer,\n DrawIOPage,\n DrawIOPoint,\n DrawIOStyle\n} from './model'\nexport { parseDrawIOFile } from './read'\nexport { formatStyle, parseStyle, styleFlag, styleNumber } from './style'\nexport { writeDrawIOFile } from './write'\n\n/**\n * The draw.io file in `bytes`: a `.drawio` or `.dio` file, or the diagram a draw.io PNG or SVG\n * export embeds. Null when the bytes hold no draw.io diagram. Everything the file unpacks, its\n * compressed pages and image chunks together, shares one size limit.\n */\nexport function readDrawIOBytes(bytes: Uint8Array): DrawIOFile | null {\n const budget = inflateBudget()\n const root = drawioRoot(bytes, budget)\n return root ? readDrawIORoot(root, budget) : null\n}\n"],"mappings":";;;;;AAGA,SAAgB,WAAW,OAA4B;CACrD,MAAM,SAAsB;EAAE,OAAO,CAAC;EAAG,QAAQ,CAAC;CAAE;CACpD,KAAK,MAAM,QAAQ,MAAM,MAAM,GAAG,GAAG;EACnC,MAAM,OAAO,KAAK,KAAK;EACvB,IAAI,CAAC,MAAM;EACX,MAAM,KAAK,KAAK,QAAQ,GAAG;EAC3B,IAAI,OAAO,IAAI,OAAO,MAAM,KAAK,IAAI;OAChC,OAAO,OAAO,KAAK,MAAM,GAAG,EAAE,KAAK,KAAK,MAAM,KAAK,CAAC;CAC3D;CACA,OAAO;AACT;;AAGA,SAAgB,YAAY,EAAE,OAAO,UAA+B;CAClE,MAAM,QAAQ,OAAO,QAAQ,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,WAClD,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAC/C;CACA,OAAO,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC,CAAC,KAAK,SAAS,GAAG,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE;AAC/D;;AAGA,SAAgB,YAAY,OAAoB,KAAa,UAA0B;CACrF,MAAM,QAAQ,OAAO,WAAW,MAAM,OAAO,QAAQ,EAAE;CACvD,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;AAC1C;;AAGA,SAAgB,UAAU,OAAoB,KAAsB;C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AAM,qCAAqC,KAAK,WAAW,KAAK,IAAI,GAAG;CAEnF,MAAM,WAAW,IAAI,kBAAkB,CAAC,CAAC,eAAe,MAAM,UAAU,IAAI;CAC5E,MAAM,OAAO,SAAS;CACtB,IAAI,CAAC,MAAM,MAAM,IAAI,MAAM,qCAAqC;CAChE,KAAK,aAAa,QAAQ,IAAI;CAC9B,KAAK,MAAM,QAAQ,KAAK,OAAO,KAAK,YAAY,YAAY,UAAU,IAAI,CAAC;CAC3E,OAAO,IAAI,cAAc,CAAC,CAAC,kBAAkB,QAAQ;AACvD;;;;;;;;AChFA,SAAgB,gBAAgB,OAAsC;CACpE,MAAM,SAAS,cAAc;CAC7B,MAAM,OAAO,WAAW,OAAO,MAAM;CACrC,OAAO,OAAO,eAAe,MAAM,MAAM,IAAI;AAC/C"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/style.ts","../../src/read.ts","../../src/write.ts","../../src/index.ts"],"sourcesContent":["import type { DrawIOStyle } from './model'\n\n/** A `style` string as its style names and its pairs. */\nexport function parseStyle(style: string): DrawIOStyle {\n const result: DrawIOStyle = { names: [], values: {} }\n for (const part of style.split(';')) {\n const text = part.trim()\n if (!text) continue\n const eq = text.indexOf('=')\n if (eq === -1) result.names.push(text)\n else result.values[text.slice(0, eq)] = text.slice(eq + 1)\n }\n return result\n}\n\n/** A style as draw.io writes it: its names, then `key=value;` pairs, in order. */\nexport function formatStyle({ names, values }: DrawIOStyle): string {\n const pairs = Object.entries(values).flatMap(([key, value]) =>\n value === undefined ? [] : [`${key}=${value}`]\n )\n return [...names, ...pairs].map((part) => `${part};`).join('')\n}\n\n/** A number the style sets for `key`, or `fallback`. */\nexport function styleNumber(style: DrawIOStyle, key: string, fallback: number): number {\n const value = Number.parseFloat(style.values[key] ?? '')\n return Number.isFinite(value) ? value : fallback\n}\n\n/** Whether the style turns `key` on, as `key=1` does. */\nexport function styleFlag(style: DrawIOStyle, key: string): boolean {\n return style.values[key] === '1'\n}\n","import type { Element } from '@xmldom/xmldom'\nimport { isValid, toUint8Array } from 'js-base64'\n\nimport { boundedInflate, inflateBudget, percentDecoded, type InflateBudget } from './inflate'\nimport type {\n DrawIOCell,\n DrawIOFile,\n DrawIOGeometry,\n DrawIOLayer,\n DrawIOPage,\n DrawIOPoint\n} from './model'\nimport { parseStyle, styleFlag } from './style'\nimport { attributesOf, childElements, parseXML } from './xml'\n\n/** What a cell wrapper keeps for itself rather than as the cell's attributes. */\nconst WRAPPER_OWN = new Set(['id', 'label'])\n\nfunction number(element: Element, name: string, fallback = 0): number {\n const value = Number.parseFloat(element.getAttribute(name) ?? '')\n return Number.isFinite(value) ? value : fallback\n}\n\nfunction pointOf(element: Element): DrawIOPoint {\n return { x: number(element, 'x'), y: number(element, 'y') }\n}\n\nconst NO_GEOMETRY: DrawIOGeometry = {\n x: 0,\n y: 0,\n width: 0,\n height: 0,\n relative: false,\n points: [],\n sourcePoint: null,\n targetPoint: null,\n offset: null\n}\n\nfunction readGeometry(cell: Element): DrawIOGeometry {\n const geometry = childElements(cell, 'mxGeometry').at(0)\n if (!geometry) return structuredClone(NO_GEOMETRY)\n const points = childElements(geometry, 'mxArray').find((e) => e.getAttribute('as') === 'points')\n const point = (as: string) => {\n const found = childElements(geometry, 'mxPoint').find((p) => p.getAttribute('as') === as)\n return found ? pointOf(found) : null\n }\n return {\n x: number(geometry, 'x'),\n y: number(geometry, 'y'),\n width: number(geometry, 'width'),\n height: number(geometry, 'height'),\n relative: geometry.getAttribute('relative') === '1',\n points: points ? childElements(points, 'mxPoint').map(pointOf) : [],\n sourcePoint: point('sourcePoint'),\n targetPoint: point('targetPoint'),\n offset: point('offset')\n }\n}\n\n/** A cell element, and the `UserObject` or `object` around it when there is one. */\ninterface CellElements {\n cell: Element\n wrapper: Element | null\n}\n\nfunction cellElements(element: Element): CellElements | null {\n if (element.localName === 'mxCell') return { cell: element, wrapper: null }\n if (element.localName !== 'UserObject' && element.localName !== 'object') return null\n const cell = childElements(element, 'mxCell').at(0)\n return cell ? { cell, wrapper: element } : null\n}\n\nfunction readCell({ cell, wrapper }: CellElements, id: string, parent: string): DrawIOCell {\n const isEdge = cell.getAttribute('edge') === '1'\n return {\n id,\n parent,\n kind: isEdge ? 'edge' : 'vertex',\n value: (wrapper ? wrapper.getAttribute('label') : cell.getAttribute('value')) ?? '',\n style: parseStyle(cell.getAttribute('style') ?? ''),\n geometry: readGeometry(cell),\n visible: cell.getAttribute('visible') !== '0',\n source: cell.getAttribute('source'),\n target: cell.getAttribute('target'),\n attributes: wrapper ? attributesOf(wrapper, WRAPPER_OWN) : {}\n }\n}\n\n/**\n * A model's cells. Its root is the one cell without a parent, and its layers are the cells under\n * the root that are neither shapes nor edges; draw.io names them `0` and `1` by default.\n */\nfunction readModel(model: Element, page: Pick<DrawIOPage, 'id' | 'name'>): DrawIOPage | null {\n const root = childElements(model, 'root').at(0)\n if (!root) return null\n const read: { elements: CellElements; id: string; parent: string | null }[] = []\n for (const element of childElements(root)) {\n const elements = cellElements(element)\n const id = (elements?.wrapper ?? elements?.cell)?.getAttribute('id')\n if (elements && id) read.push({ elements, id, parent: elements.cell.getAttribute('parent') })\n }\n const rootId = read.find((entry) => !entry.parent)?.id\n if (rootId === undefined) return null\n const layers: DrawIOLayer[] = []\n const cells: DrawIOCell[] = []\n for (const { elements, id, parent } of read) {\n if (!parent) continue\n const { cell } = elements\n const shown = cell.getAttribute('vertex') === '1' || cell.getAttribute('edge') === '1'\n if (!shown && parent === rootId) {\n layers.push({\n id,\n name: cell.getAttribute('value') ?? '',\n visible: cell.getAttribute('visible') !== '0',\n locked: styleFlag(parseStyle(cell.getAttribute('style') ?? ''), 'locked')\n })\n } else if (shown) {\n cells.push(readCell(elements, id, parent))\n }\n }\n return {\n ...page,\n attributes: attributesOf(model, new Set()),\n rootId,\n layers,\n cells\n }\n}\n\n/** The XML inside a compressed `<diagram>`: Base64, raw deflate, then percent-encoded text. */\nfunction inflateDiagram(text: string, budget: InflateBudget): string | null {\n const encoded = text.trim()\n if (!encoded || !isValid(encoded)) return null\n try {\n return percentDecoded(new TextDecoder().decode(boundedInflate(toUint8Array(encoded), budget)))\n } catch {\n return null\n }\n}\n\nfunction readDiagram(\n diagram: Element,\n index: number,\n budget: InflateBudget\n): DrawIOPage | { unreadable: string } {\n const name = diagram.getAttribute('name') || `Page ${index + 1}`\n const page = { id: diagram.getAttribute('id') ?? `page-${index + 1}`, name }\n let model = childElements(diagram, 'mxGraphModel').at(0) ?? null\n if (!model) {\n const xml = inflateDiagram(diagram.textContent ?? '', budget)\n const root = xml ? parseXML(xml) : null\n model = root?.localName === 'mxGraphModel' ? root : null\n }\n return (model ? readModel(model, page) : null) ?? { unreadable: name }\n}\n\n/**\n * The pages of a draw.io file, whether its diagrams are plain or compressed, with the names of\n * pages it could not read: damaged, or past what the file may unpack to. Null when the source\n * is not a draw.io file.\n */\nexport function parseDrawIOFile(source: string, budget = inflateBudget()): DrawIOFile | null {\n const root = parseXML(source)\n return root ? readDrawIORoot(root, budget) : null\n}\n\n/** The pages of a draw.io document from its parsed root, as `parseDrawIOFile` reads them. */\nexport function readDrawIORoot(root: Element, budget: InflateBudget): DrawIOFile | null {\n if (root.localName === 'mxGraphModel') {\n const page = readModel(root, { id: 'page-1', name: 'Page 1' })\n return page ? { pages: [page], unreadable: [] } : null\n }\n if (root.localName !== 'mxfile') return null\n const file: DrawIOFile = { pages: [], unreadable: [] }\n for (const [index, diagram] of childElements(root, 'diagram').entries()) {\n const read = readDiagram(diagram, index, budget)\n if ('unreadable' in read) file.unreadable.push(read.unreadable)\n else file.pages.push(read)\n }\n return file\n}\n","import { DOMImplementation, XMLSerializer, type Document, type Element } from '@xmldom/xmldom'\n\nimport type { DrawIOCell, DrawIOFile, DrawIOGeometry, DrawIOPage, DrawIOPoint } from './model'\nimport { formatStyle } from './style'\n\n/** What the writer puts on `<mxfile>`, so draw.io knows who wrote it. */\nconst HOST = 'Pairdraw'\n\nfunction setNumber(element: Element, name: string, value: number) {\n if (value !== 0) element.setAttribute(name, String(value))\n}\n\nfunction point(document: Document, at: DrawIOPoint, as?: string): Element {\n const element = document.createElement('mxPoint')\n element.setAttribute('x', String(at.x))\n element.setAttribute('y', String(at.y))\n if (as) element.setAttribute('as', as)\n return element\n}\n\nfunction geometry(document: Document, value: DrawIOGeometry): Element {\n const element = document.createElement('mxGeometry')\n setNumber(element, 'x', value.x)\n setNumber(element, 'y', value.y)\n setNumber(element, 'width', value.width)\n setNumber(element, 'height', value.height)\n if (value.relative) element.setAttribute('relative', '1')\n element.setAttribute('as', 'geometry')\n if (value.sourcePoint) element.appendChild(point(document, value.sourcePoint, 'sourcePoint'))\n if (value.targetPoint) element.appendChild(point(document, value.targetPoint, 'targetPoint'))\n if (value.points.length > 0) {\n const points = document.createElement('mxArray')\n points.setAttribute('as', 'points')\n for (const at of value.points) points.appendChild(point(document, at))\n element.appendChild(points)\n }\n if (value.offset) element.appendChild(point(document, value.offset, 'offset'))\n return element\n}\n\n/** A cell as draw.io writes it, wrapped in a `UserObject` when it carries attributes. */\nfunction cellElement(document: Document, cell: DrawIOCell): Element {\n const element = document.createElement('mxCell')\n const wrapped = Object.keys(cell.attributes).length > 0\n if (!wrapped) {\n element.setAttribute('id', cell.id)\n element.setAttribute('value', cell.value)\n }\n const style = formatStyle(cell.style)\n if (style) element.setAttribute('style', style)\n element.setAttribute(cell.kind, '1')\n if (!cell.visible) element.setAttribute('visible', '0')\n element.setAttribute('parent', cell.parent)\n if (cell.source) element.setAttribute('source', cell.source)\n if (cell.target) element.setAttribute('target', cell.target)\n element.appendChild(geometry(document, cell.geometry))\n if (!wrapped) return element\n const wrapper = document.createElement('UserObject')\n wrapper.setAttribute('label', cell.value)\n for (const [name, value] of Object.entries(cell.attributes)) wrapper.setAttribute(name, value)\n wrapper.setAttribute('id', cell.id)\n wrapper.appendChild(element)\n return wrapper\n}\n\nfunction pageElement(document: Document, page: DrawIOPage): Element {\n const diagram = document.createElement('diagram')\n diagram.setAttribute('id', page.id)\n diagram.setAttribute('name', page.name)\n const model = document.createElement('mxGraphModel')\n for (const [name, value] of Object.entries(page.attributes)) model.setAttribute(name, value)\n const root = document.createElement('root')\n const rootCell = document.createElement('mxCell')\n rootCell.setAttribute('id', page.rootId)\n root.appendChild(rootCell)\n for (const layer of page.layers) {\n const element = document.createElement('mxCell')\n element.setAttribute('id', layer.id)\n if (layer.name) element.setAttribute('value', layer.name)\n if (layer.locked) element.setAttribute('style', 'locked=1;')\n if (!layer.visible) element.setAttribute('visible', '0')\n element.setAttribute('parent', page.rootId)\n root.appendChild(element)\n }\n for (const cell of page.cells) root.appendChild(cellElement(document, cell))\n model.appendChild(root)\n diagram.appendChild(model)\n return diagram\n}\n\n/**\n * A draw.io file as XML draw.io opens: each page a `<diagram>` holding its model uncompressed,\n * as draw.io itself saves by default, so the file diffs and reads as text. A file with pages that\n * could not be read is refused, since writing it would drop them.\n */\nexport function writeDrawIOFile(file: DrawIOFile): string {\n if (file.unreadable.length > 0) {\n throw new Error(`Could not write the draw.io pages ${file.unreadable.join(', ')}`)\n }\n const document = new DOMImplementation().createDocument(null, 'mxfile', null)\n const root = document.documentElement\n if (!root) throw new Error('Could not create a draw.io document')\n root.setAttribute('host', HOST)\n for (const page of file.pages) root.appendChild(pageElement(document, page))\n return new XMLSerializer().serializeToString(document)\n}\n","import { drawioRoot } from './embedded'\nimport { inflateBudget } from './inflate'\nimport type { DrawIOFile } from './model'\nimport { readDrawIORoot } from './read'\n\nexport { isDrawIOExportFileName } from './embedded'\nexport { MAX_INFLATED_BYTES } from './inflate'\nexport type {\n DrawIOCell,\n DrawIOFile,\n DrawIOGeometry,\n DrawIOLayer,\n DrawIOPage,\n DrawIOPoint,\n DrawIOStyle\n} from './model'\nexport { parseDrawIOFile } from './read'\nexport { formatStyle, parseStyle, styleFlag, styleNumber } from './style'\nexport { writeDrawIOFile } from './write'\n\n/**\n * The draw.io file in `bytes`: a `.drawio` or `.dio` file, or the diagram a draw.io PNG or SVG\n * export embeds. Null when the bytes hold no draw.io diagram. Everything the file unpacks, its\n * compressed pages and image chunks together, shares one size limit.\n */\nexport function readDrawIOBytes(bytes: Uint8Array): DrawIOFile | null {\n const budget = inflateBudget()\n const root = drawioRoot(bytes, budget)\n return root ? readDrawIORoot(root, budget) : null\n}\n"],"mappings":";;;;;AAGA,SAAgB,WAAW,OAA4B;CACrD,MAAM,SAAsB;EAAE,OAAO,CAAC;EAAG,QAAQ,CAAC;CAAE;CACpD,KAAK,MAAM,QAAQ,MAAM,MAAM,GAAG,GAAG;EACnC,MAAM,OAAO,KAAK,KAAK;EACvB,IAAI,CAAC,MAAM;EACX,MAAM,KAAK,KAAK,QAAQ,GAAG;EAC3B,IAAI,OAAO,IAAI,OAAO,MAAM,KAAK,IAAI;OAChC,OAAO,OAAO,KAAK,MAAM,GAAG,EAAE,KAAK,KAAK,MAAM,KAAK,CAAC;CAC3D;CACA,OAAO;AACT;;AAGA,SAAgB,YAAY,EAAE,OAAO,UAA+B;CAClE,MAAM,QAAQ,OAAO,QAAQ,MAAM,CAAC,CAAC,SAAS,CAAC,KAAK,WAClD,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,GAAG,IAAI,GAAG,OAAO,CAC/C;CACA,OAAO,CAAC,GAAG,OAAO,GAAG,KAAK,CAAC,CAAC,KAAK,SAAS,GAAG,KAAK,EAAE,CAAC,CAAC,KAAK,EAAE;AAC/D;;AAGA,SAAgB,YAAY,OAAoB,KAAa,UAA0B;CACrF,MAAM,QAAQ,OAAO,WAAW,MAAM,OAAO,QAAQ,EAAE;CACvD,OAAO,OAAO,SAAS,KAAK,IAAI,QAAQ;AAC1C;;AAGA,SAAgB,UAAU,OAAoB,KAAsB;CAClE,OAAO,MAAM,OAAO,SAAS;AAC/B;;;;AChBA,MAAM,8BAAc,IAAI,IAAI,CAAC,MAAM,OAAO,CAAC;AAE3C,SAAS,OAAO,SAAkB,MAAc,WAAW,GAAW;CACpE,MAAM,QAAQ,OAAO,WAAW,QAAQ,aAAa,IAAI,KAAK,EAAE;CAChE,OAA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,IAAI;CAC9B,KAAK,MAAM,QAAQ,KAAK,OAAO,KAAK,YAAY,YAAY,UAAU,IAAI,CAAC;CAC3E,OAAO,IAAI,cAAc,CAAC,CAAC,kBAAkB,QAAQ;AACvD;;;;;;;;AChFA,SAAgB,gBAAgB,OAAsC;CACpE,MAAM,SAAS,cAAc;CAC7B,MAAM,OAAO,WAAW,OAAO,MAAM;CACrC,OAAO,OAAO,eAAe,MAAM,MAAM,IAAI;AAC/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pairdraw/drawio",
3
- "version": "0.19.2",
3
+ "version": "0.21.0",
4
4
  "license": "MIT",
5
5
  "files": [
6
6
  "dist",
package/src/read.ts CHANGED
@@ -40,7 +40,7 @@ const NO_GEOMETRY: DrawIOGeometry = {
40
40
  function readGeometry(cell: Element): DrawIOGeometry {
41
41
  const geometry = childElements(cell, 'mxGeometry').at(0)
42
42
  if (!geometry) return structuredClone(NO_GEOMETRY)
43
- const points = childElements(geometry, 'Array').find((e) => e.getAttribute('as') === 'points')
43
+ const points = childElements(geometry, 'mxArray').find((e) => e.getAttribute('as') === 'points')
44
44
  const point = (as: string) => {
45
45
  const found = childElements(geometry, 'mxPoint').find((p) => p.getAttribute('as') === as)
46
46
  return found ? pointOf(found) : null
package/src/write.ts CHANGED
@@ -29,7 +29,7 @@ function geometry(document: Document, value: DrawIOGeometry): Element {
29
29
  if (value.sourcePoint) element.appendChild(point(document, value.sourcePoint, 'sourcePoint'))
30
30
  if (value.targetPoint) element.appendChild(point(document, value.targetPoint, 'targetPoint'))
31
31
  if (value.points.length > 0) {
32
- const points = document.createElement('Array')
32
+ const points = document.createElement('mxArray')
33
33
  points.setAttribute('as', 'points')
34
34
  for (const at of value.points) points.appendChild(point(document, at))
35
35
  element.appendChild(points)