@pairdraw/drawio 0.0.0-stage → 0.16.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/LICENSE +21 -0
- package/README.md +4 -2
- package/dist/chunks/embedded.js +167 -0
- package/dist/chunks/embedded.js.map +1 -0
- package/dist/chunks/index.js +313 -0
- package/dist/chunks/index.js.map +1 -0
- package/dist/index.d.ts +124 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/package.json +30 -4
- package/src/embedded.ts +98 -0
- package/src/index.ts +30 -0
- package/src/inflate.ts +65 -0
- package/src/model.ts +77 -0
- package/src/read.ts +182 -0
- package/src/style.ts +33 -0
- package/src/write.ts +106 -0
- package/src/xml.ts +38 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Danila Poyarkov and OpenPencil contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @pairdraw/drawio
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
The draw.io (diagrams.net) file format: its document model, and a reader and writer for `.drawio` and `.dio` files and the diagrams draw.io embeds in its PNG and SVG exports.
|
|
4
|
+
|
|
5
|
+
The reader takes plain and compressed pages, keeps cells in draw.io's drawing order with their layers, styles, geometry and `UserObject` attributes, and unpacks everything a file holds within one size limit. The writer saves pages uncompressed, as draw.io does by default. Neither depends on `@pairdraw/scene-graph`; converting diagrams to and from design layers happens in `@pairdraw/core`.
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { imageSize } from "image-size";
|
|
2
|
+
import { Inflate } from "fflate";
|
|
3
|
+
import { DOMParser } from "@xmldom/xmldom";
|
|
4
|
+
//#region src/inflate.ts
|
|
5
|
+
/**
|
|
6
|
+
* The most a file's compressed parts may unpack to, all together, so a small crafted file with
|
|
7
|
+
* many diagrams or image chunks cannot exhaust memory.
|
|
8
|
+
*/
|
|
9
|
+
const MAX_INFLATED_BYTES = 33554432;
|
|
10
|
+
/** Input fed per step; deflate expands at most about 1032 times, so each step stays small. */
|
|
11
|
+
const STEP_BYTES = 4096;
|
|
12
|
+
function inflateBudget(bytes = MAX_INFLATED_BYTES) {
|
|
13
|
+
return { remaining: bytes };
|
|
14
|
+
}
|
|
15
|
+
/** Raw deflate, charged to `budget`; throws once the file would unpack to more than it allows. */
|
|
16
|
+
function boundedInflate(data, budget) {
|
|
17
|
+
const chunks = [];
|
|
18
|
+
let size = 0;
|
|
19
|
+
const inflater = new Inflate((chunk) => {
|
|
20
|
+
size += chunk.length;
|
|
21
|
+
budget.remaining -= chunk.length;
|
|
22
|
+
if (budget.remaining < 0) throw new RangeError("The draw.io file unpacks to too much data");
|
|
23
|
+
chunks.push(chunk);
|
|
24
|
+
});
|
|
25
|
+
for (let start = 0; start < data.length; start += STEP_BYTES) {
|
|
26
|
+
const end = start + STEP_BYTES;
|
|
27
|
+
inflater.push(data.subarray(start, end), end >= data.length);
|
|
28
|
+
}
|
|
29
|
+
const output = new Uint8Array(size);
|
|
30
|
+
let offset = 0;
|
|
31
|
+
for (const chunk of chunks) {
|
|
32
|
+
output.set(chunk, offset);
|
|
33
|
+
offset += chunk.length;
|
|
34
|
+
}
|
|
35
|
+
return output;
|
|
36
|
+
}
|
|
37
|
+
/** A `%` that does not start an escape, as in "50% done". */
|
|
38
|
+
const STRAY_PERCENT = /%(?![0-9A-Fa-f]{2})/g;
|
|
39
|
+
/** A run of escapes, decoded together so a character spread over several bytes stays whole. */
|
|
40
|
+
const ESCAPE_RUN = /(?:%[0-9A-Fa-f]{2})+/g;
|
|
41
|
+
/**
|
|
42
|
+
* The text with its percent escapes decoded. A stray `%` is kept as it is, and an escape run that
|
|
43
|
+
* is not valid UTF-8 stays encoded, so neither stops the rest of the text from decoding.
|
|
44
|
+
*/
|
|
45
|
+
function percentDecoded(text) {
|
|
46
|
+
const escaped = text.replace(STRAY_PERCENT, "%25");
|
|
47
|
+
try {
|
|
48
|
+
return decodeURIComponent(escaped);
|
|
49
|
+
} catch {
|
|
50
|
+
return escaped.replace(ESCAPE_RUN, (run) => {
|
|
51
|
+
try {
|
|
52
|
+
return decodeURIComponent(run);
|
|
53
|
+
} catch {
|
|
54
|
+
return run;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
//#endregion
|
|
60
|
+
//#region src/xml.ts
|
|
61
|
+
/** The root element of `source`, or null when it is not well-formed XML. */
|
|
62
|
+
function parseXML(source) {
|
|
63
|
+
try {
|
|
64
|
+
return new DOMParser({ onError: (level, message) => {
|
|
65
|
+
if (level !== "warning") throw new Error(message);
|
|
66
|
+
} }).parseFromString(source, "text/xml").documentElement;
|
|
67
|
+
} catch {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/** The element children of `element`, named `name` when given. */
|
|
72
|
+
function childElements(element, name) {
|
|
73
|
+
const found = [];
|
|
74
|
+
for (let node = element.firstChild; node; node = node.nextSibling) if (node.nodeType === node.ELEMENT_NODE && (!name || node.localName === name)) found.push(node);
|
|
75
|
+
return found;
|
|
76
|
+
}
|
|
77
|
+
/** All of an element's attributes but those in `except`. */
|
|
78
|
+
function attributesOf(element, except) {
|
|
79
|
+
const attributes = {};
|
|
80
|
+
for (const attribute of Array.from(element.attributes)) if (!except.has(attribute.name)) attributes[attribute.name] = attribute.value;
|
|
81
|
+
return attributes;
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/embedded.ts
|
|
85
|
+
/** A PNG's chunks start after its eight-byte signature. */
|
|
86
|
+
const PNG_SIGNATURE_LENGTH = 8;
|
|
87
|
+
/** The keyword draw.io stores its diagram under in a PNG's text chunks. */
|
|
88
|
+
const DRAWIO_KEYWORD = "mxfile";
|
|
89
|
+
const latin1 = new TextDecoder("latin1");
|
|
90
|
+
const utf8 = new TextDecoder();
|
|
91
|
+
function isPNG(bytes) {
|
|
92
|
+
try {
|
|
93
|
+
return imageSize(bytes).type === "png";
|
|
94
|
+
} catch {
|
|
95
|
+
return false;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
/** Where a NUL byte ends the field that starts at `from`, or -1. */
|
|
99
|
+
function fieldEnd(data, from) {
|
|
100
|
+
return data.indexOf(0, from);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* The diagram a text chunk holds when its keyword is draw.io's: `tEXt` as Latin-1, `zTXt`
|
|
104
|
+
* zlib-compressed, `iTXt` as UTF-8, compressed or not. draw.io percent-encodes the XML in all three.
|
|
105
|
+
*/
|
|
106
|
+
function chunkDiagram(type, data, budget) {
|
|
107
|
+
const keywordEnd = fieldEnd(data, 0);
|
|
108
|
+
if (keywordEnd === -1 || latin1.decode(data.subarray(0, keywordEnd)) !== DRAWIO_KEYWORD) return null;
|
|
109
|
+
if (type === "tEXt") return percentDecoded(latin1.decode(data.subarray(keywordEnd + 1)));
|
|
110
|
+
if (type === "zTXt") {
|
|
111
|
+
const inflated = boundedInflate(data.subarray(keywordEnd + 4), budget);
|
|
112
|
+
return percentDecoded(latin1.decode(inflated));
|
|
113
|
+
}
|
|
114
|
+
const compressed = data[keywordEnd + 1] === 1;
|
|
115
|
+
const languageEnd = fieldEnd(data, keywordEnd + 3);
|
|
116
|
+
const translatedEnd = languageEnd === -1 ? -1 : fieldEnd(data, languageEnd + 1);
|
|
117
|
+
if (translatedEnd === -1) return null;
|
|
118
|
+
const text = data.subarray(translatedEnd + 1);
|
|
119
|
+
return percentDecoded(utf8.decode(compressed ? boundedInflate(text.subarray(2), budget) : text));
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* The draw.io diagram a PNG export carries, or null when it carries none. A compressed chunk that
|
|
123
|
+
* is damaged or too large to unpack is an error that says so.
|
|
124
|
+
*/
|
|
125
|
+
function diagramInPNG(bytes, budget) {
|
|
126
|
+
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
127
|
+
let offset = PNG_SIGNATURE_LENGTH;
|
|
128
|
+
while (offset + 8 <= bytes.length) {
|
|
129
|
+
const length = view.getUint32(offset);
|
|
130
|
+
const type = latin1.decode(bytes.subarray(offset + 4, offset + 8));
|
|
131
|
+
const start = offset + 8;
|
|
132
|
+
if (type === "IEND") return null;
|
|
133
|
+
if (start + length > bytes.length) throw new Error("Could not read the draw.io diagram in this image: it is cut short");
|
|
134
|
+
if (type === "tEXt" || type === "zTXt" || type === "iTXt") {
|
|
135
|
+
let diagram;
|
|
136
|
+
try {
|
|
137
|
+
diagram = chunkDiagram(type, bytes.subarray(start, start + length), budget);
|
|
138
|
+
} catch (error) {
|
|
139
|
+
throw new Error("Could not read the draw.io diagram in this image", { cause: error });
|
|
140
|
+
}
|
|
141
|
+
if (diagram) return diagram;
|
|
142
|
+
}
|
|
143
|
+
offset = start + length + 4;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* The root element of the draw.io XML a file holds: the file itself for `.drawio` and `.dio`, or
|
|
149
|
+
* the diagram a PNG export embeds in a text chunk or an SVG export in its root's `content`. Null
|
|
150
|
+
* when the file is not XML or an export embeds no diagram.
|
|
151
|
+
*/
|
|
152
|
+
function drawioRoot(bytes, budget) {
|
|
153
|
+
const source = isPNG(bytes) ? diagramInPNG(bytes, budget) : utf8.decode(bytes);
|
|
154
|
+
const root = source === null ? null : parseXML(source);
|
|
155
|
+
if (root?.localName !== "svg") return root;
|
|
156
|
+
const content = root.getAttribute("content");
|
|
157
|
+
return content ? parseXML(content) : null;
|
|
158
|
+
}
|
|
159
|
+
/** Whether a file name is draw.io's for an editable export, such as `flow.drawio.png`. */
|
|
160
|
+
function isDrawIOExportFileName(fileName) {
|
|
161
|
+
const name = fileName.toLowerCase();
|
|
162
|
+
return name.endsWith(".drawio.png") || name.endsWith(".drawio.svg");
|
|
163
|
+
}
|
|
164
|
+
//#endregion
|
|
165
|
+
export { MAX_INFLATED_BYTES, attributesOf, boundedInflate, childElements, drawioRoot, inflateBudget, isDrawIOExportFileName, parseXML, percentDecoded };
|
|
166
|
+
|
|
167
|
+
//# sourceMappingURL=embedded.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"embedded.js","names":[],"sources":["../../src/inflate.ts","../../src/xml.ts","../../src/embedded.ts"],"sourcesContent":["import { Inflate } from 'fflate'\n\n/**\n * The most a file's compressed parts may unpack to, all together, so a small crafted file with\n * many diagrams or image chunks cannot exhaust memory.\n */\nexport const MAX_INFLATED_BYTES = 32 * 1024 * 1024\n/** Input fed per step; deflate expands at most about 1032 times, so each step stays small. */\nconst STEP_BYTES = 4096\n\n/** What is left of a file's unpacking allowance, shared by every part it unpacks. */\nexport interface InflateBudget {\n remaining: number\n}\n\nexport function inflateBudget(bytes = MAX_INFLATED_BYTES): InflateBudget {\n return { remaining: bytes }\n}\n\n/** Raw deflate, charged to `budget`; throws once the file would unpack to more than it allows. */\nexport function boundedInflate(data: Uint8Array, budget: InflateBudget): Uint8Array {\n const chunks: Uint8Array[] = []\n let size = 0\n const inflater = new Inflate((chunk) => {\n size += chunk.length\n budget.remaining -= chunk.length\n if (budget.remaining < 0) throw new RangeError('The draw.io file unpacks to too much data')\n chunks.push(chunk)\n })\n for (let start = 0; start < data.length; start += STEP_BYTES) {\n const end = start + STEP_BYTES\n inflater.push(data.subarray(start, end), end >= data.length)\n }\n const output = new Uint8Array(size)\n let offset = 0\n for (const chunk of chunks) {\n output.set(chunk, offset)\n offset += chunk.length\n }\n return output\n}\n\n/** A `%` that does not start an escape, as in \"50% done\". */\nconst STRAY_PERCENT = /%(?![0-9A-Fa-f]{2})/g\n/** A run of escapes, decoded together so a character spread over several bytes stays whole. */\nconst ESCAPE_RUN = /(?:%[0-9A-Fa-f]{2})+/g\n\n/**\n * The text with its percent escapes decoded. A stray `%` is kept as it is, and an escape run that\n * is not valid UTF-8 stays encoded, so neither stops the rest of the text from decoding.\n */\nexport function percentDecoded(text: string): string {\n const escaped = text.replace(STRAY_PERCENT, '%25')\n try {\n return decodeURIComponent(escaped)\n } catch {\n return escaped.replace(ESCAPE_RUN, (run) => {\n try {\n return decodeURIComponent(run)\n } catch {\n return run\n }\n })\n }\n}\n","import { DOMParser, type Element } from '@xmldom/xmldom'\n\n/** The root element of `source`, or null when it is not well-formed XML. */\nexport function parseXML(source: string): Element | null {\n try {\n const parsed = new DOMParser({\n onError: (level, message) => {\n if (level !== 'warning') throw new Error(message)\n }\n }).parseFromString(source, 'text/xml')\n return parsed.documentElement\n } catch {\n return null\n }\n}\n\n/** The element children of `element`, named `name` when given. */\nexport function childElements(element: Element, name?: string): Element[] {\n const found: Element[] = []\n for (let node = element.firstChild; node; node = node.nextSibling) {\n if (node.nodeType === node.ELEMENT_NODE && (!name || (node as Element).localName === name)) {\n found.push(node as Element)\n }\n }\n return found\n}\n\n/** All of an element's attributes but those in `except`. */\nexport function attributesOf(\n element: Element,\n except: ReadonlySet<string>\n): Record<string, string> {\n const attributes: Record<string, string> = {}\n for (const attribute of Array.from(element.attributes)) {\n if (!except.has(attribute.name)) attributes[attribute.name] = attribute.value\n }\n return attributes\n}\n","import type { Element } from '@xmldom/xmldom'\nimport { imageSize } from 'image-size'\n\nimport { boundedInflate, percentDecoded, type InflateBudget } from './inflate'\nimport { parseXML } from './xml'\n\n/** A PNG's chunks start after its eight-byte signature. */\nconst PNG_SIGNATURE_LENGTH = 8\n/** The keyword draw.io stores its diagram under in a PNG's text chunks. */\nconst DRAWIO_KEYWORD = 'mxfile'\n\nconst latin1 = new TextDecoder('latin1')\nconst utf8 = new TextDecoder()\n\nfunction isPNG(bytes: Uint8Array): boolean {\n try {\n return imageSize(bytes).type === 'png'\n } catch {\n return false\n }\n}\n\n/** Where a NUL byte ends the field that starts at `from`, or -1. */\nfunction fieldEnd(data: Uint8Array, from: number): number {\n return data.indexOf(0, from)\n}\n\n/**\n * The diagram a text chunk holds when its keyword is draw.io's: `tEXt` as Latin-1, `zTXt`\n * zlib-compressed, `iTXt` as UTF-8, compressed or not. draw.io percent-encodes the XML in all three.\n */\nfunction chunkDiagram(type: string, data: Uint8Array, budget: InflateBudget): string | null {\n const keywordEnd = fieldEnd(data, 0)\n if (keywordEnd === -1 || latin1.decode(data.subarray(0, keywordEnd)) !== DRAWIO_KEYWORD)\n return null\n if (type === 'tEXt') return percentDecoded(latin1.decode(data.subarray(keywordEnd + 1)))\n if (type === 'zTXt') {\n // The compression method byte, then a zlib stream: a 2-byte header before raw deflate.\n const inflated = boundedInflate(data.subarray(keywordEnd + 4), budget)\n return percentDecoded(latin1.decode(inflated))\n }\n // iTXt: compressed flag and method, then language and translated keyword, each NUL-ended.\n const compressed = data[keywordEnd + 1] === 1\n const languageEnd = fieldEnd(data, keywordEnd + 3)\n const translatedEnd = languageEnd === -1 ? -1 : fieldEnd(data, languageEnd + 1)\n if (translatedEnd === -1) return null\n const text = data.subarray(translatedEnd + 1)\n return percentDecoded(utf8.decode(compressed ? boundedInflate(text.subarray(2), budget) : text))\n}\n\n/**\n * The draw.io diagram a PNG export carries, or null when it carries none. A compressed chunk that\n * is damaged or too large to unpack is an error that says so.\n */\nfunction diagramInPNG(bytes: Uint8Array, budget: InflateBudget): string | null {\n const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength)\n let offset = PNG_SIGNATURE_LENGTH\n while (offset + 8 <= bytes.length) {\n const length = view.getUint32(offset)\n const type = latin1.decode(bytes.subarray(offset + 4, offset + 8))\n const start = offset + 8\n if (type === 'IEND') return null\n if (start + length > bytes.length) {\n throw new Error('Could not read the draw.io diagram in this image: it is cut short')\n }\n if (type === 'tEXt' || type === 'zTXt' || type === 'iTXt') {\n let diagram: string | null\n try {\n diagram = chunkDiagram(type, bytes.subarray(start, start + length), budget)\n } catch (error) {\n throw new Error('Could not read the draw.io diagram in this image', { cause: error })\n }\n if (diagram) return diagram\n }\n // The chunk's data, then its 4-byte CRC.\n offset = start + length + 4\n }\n return null\n}\n\n/**\n * The root element of the draw.io XML a file holds: the file itself for `.drawio` and `.dio`, or\n * the diagram a PNG export embeds in a text chunk or an SVG export in its root's `content`. Null\n * when the file is not XML or an export embeds no diagram.\n */\nexport function drawioRoot(bytes: Uint8Array, budget: InflateBudget): Element | null {\n const source = isPNG(bytes) ? diagramInPNG(bytes, budget) : utf8.decode(bytes)\n const root = source === null ? null : parseXML(source)\n if (root?.localName !== 'svg') return root\n const content = root.getAttribute('content')\n return content ? parseXML(content) : null\n}\n\n/** Whether a file name is draw.io's for an editable export, such as `flow.drawio.png`. */\nexport function isDrawIOExportFileName(fileName: string): boolean {\n const name = fileName.toLowerCase()\n return name.endsWith('.drawio.png') || name.endsWith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OAAO,SAAS,YAAY;CAClC,OAAO,KAAK,SAAS,aAAa,KAAK,KAAK,SAAS,aAAa;AACpE"}
|
|
@@ -0,0 +1,313 @@
|
|
|
1
|
+
import { attributesOf, boundedInflate, childElements, drawioRoot, inflateBudget, parseXML, percentDecoded } from "./embedded.js";
|
|
2
|
+
import { DOMImplementation, XMLSerializer } from "@xmldom/xmldom";
|
|
3
|
+
import { isValid, toUint8Array } from "js-base64";
|
|
4
|
+
//#region src/style.ts
|
|
5
|
+
/** A `style` string as its style names and its pairs. */
|
|
6
|
+
function parseStyle(style) {
|
|
7
|
+
const result = {
|
|
8
|
+
names: [],
|
|
9
|
+
values: {}
|
|
10
|
+
};
|
|
11
|
+
for (const part of style.split(";")) {
|
|
12
|
+
const text = part.trim();
|
|
13
|
+
if (!text) continue;
|
|
14
|
+
const eq = text.indexOf("=");
|
|
15
|
+
if (eq === -1) result.names.push(text);
|
|
16
|
+
else result.values[text.slice(0, eq)] = text.slice(eq + 1);
|
|
17
|
+
}
|
|
18
|
+
return result;
|
|
19
|
+
}
|
|
20
|
+
/** A style as draw.io writes it: its names, then `key=value;` pairs, in order. */
|
|
21
|
+
function formatStyle({ names, values }) {
|
|
22
|
+
const pairs = Object.entries(values).flatMap(([key, value]) => value === void 0 ? [] : [`${key}=${value}`]);
|
|
23
|
+
return [...names, ...pairs].map((part) => `${part};`).join("");
|
|
24
|
+
}
|
|
25
|
+
/** A number the style sets for `key`, or `fallback`. */
|
|
26
|
+
function styleNumber(style, key, fallback) {
|
|
27
|
+
const value = Number.parseFloat(style.values[key] ?? "");
|
|
28
|
+
return Number.isFinite(value) ? value : fallback;
|
|
29
|
+
}
|
|
30
|
+
/** Whether the style turns `key` on, as `key=1` does. */
|
|
31
|
+
function styleFlag(style, key) {
|
|
32
|
+
return style.values[key] === "1";
|
|
33
|
+
}
|
|
34
|
+
//#endregion
|
|
35
|
+
//#region src/read.ts
|
|
36
|
+
/** What a cell wrapper keeps for itself rather than as the cell's attributes. */
|
|
37
|
+
const WRAPPER_OWN = /* @__PURE__ */ new Set(["id", "label"]);
|
|
38
|
+
function number(element, name, fallback = 0) {
|
|
39
|
+
const value = Number.parseFloat(element.getAttribute(name) ?? "");
|
|
40
|
+
return Number.isFinite(value) ? value : fallback;
|
|
41
|
+
}
|
|
42
|
+
function pointOf(element) {
|
|
43
|
+
return {
|
|
44
|
+
x: number(element, "x"),
|
|
45
|
+
y: number(element, "y")
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
const NO_GEOMETRY = {
|
|
49
|
+
x: 0,
|
|
50
|
+
y: 0,
|
|
51
|
+
width: 0,
|
|
52
|
+
height: 0,
|
|
53
|
+
relative: false,
|
|
54
|
+
points: [],
|
|
55
|
+
sourcePoint: null,
|
|
56
|
+
targetPoint: null,
|
|
57
|
+
offset: null
|
|
58
|
+
};
|
|
59
|
+
function readGeometry(cell) {
|
|
60
|
+
const geometry = childElements(cell, "mxGeometry").at(0);
|
|
61
|
+
if (!geometry) return structuredClone(NO_GEOMETRY);
|
|
62
|
+
const points = childElements(geometry, "Array").find((e) => e.getAttribute("as") === "points");
|
|
63
|
+
const point = (as) => {
|
|
64
|
+
const found = childElements(geometry, "mxPoint").find((p) => p.getAttribute("as") === as);
|
|
65
|
+
return found ? pointOf(found) : null;
|
|
66
|
+
};
|
|
67
|
+
return {
|
|
68
|
+
x: number(geometry, "x"),
|
|
69
|
+
y: number(geometry, "y"),
|
|
70
|
+
width: number(geometry, "width"),
|
|
71
|
+
height: number(geometry, "height"),
|
|
72
|
+
relative: geometry.getAttribute("relative") === "1",
|
|
73
|
+
points: points ? childElements(points, "mxPoint").map(pointOf) : [],
|
|
74
|
+
sourcePoint: point("sourcePoint"),
|
|
75
|
+
targetPoint: point("targetPoint"),
|
|
76
|
+
offset: point("offset")
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
function cellElements(element) {
|
|
80
|
+
if (element.localName === "mxCell") return {
|
|
81
|
+
cell: element,
|
|
82
|
+
wrapper: null
|
|
83
|
+
};
|
|
84
|
+
if (element.localName !== "UserObject" && element.localName !== "object") return null;
|
|
85
|
+
const cell = childElements(element, "mxCell").at(0);
|
|
86
|
+
return cell ? {
|
|
87
|
+
cell,
|
|
88
|
+
wrapper: element
|
|
89
|
+
} : null;
|
|
90
|
+
}
|
|
91
|
+
function readCell({ cell, wrapper }, id, parent) {
|
|
92
|
+
return {
|
|
93
|
+
id,
|
|
94
|
+
parent,
|
|
95
|
+
kind: cell.getAttribute("edge") === "1" ? "edge" : "vertex",
|
|
96
|
+
value: (wrapper ? wrapper.getAttribute("label") : cell.getAttribute("value")) ?? "",
|
|
97
|
+
style: parseStyle(cell.getAttribute("style") ?? ""),
|
|
98
|
+
geometry: readGeometry(cell),
|
|
99
|
+
visible: cell.getAttribute("visible") !== "0",
|
|
100
|
+
source: cell.getAttribute("source"),
|
|
101
|
+
target: cell.getAttribute("target"),
|
|
102
|
+
attributes: wrapper ? attributesOf(wrapper, WRAPPER_OWN) : {}
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* A model's cells. Its root is the one cell without a parent, and its layers are the cells under
|
|
107
|
+
* the root that are neither shapes nor edges; draw.io names them `0` and `1` by default.
|
|
108
|
+
*/
|
|
109
|
+
function readModel(model, page) {
|
|
110
|
+
const root = childElements(model, "root").at(0);
|
|
111
|
+
if (!root) return null;
|
|
112
|
+
const read = [];
|
|
113
|
+
for (const element of childElements(root)) {
|
|
114
|
+
const elements = cellElements(element);
|
|
115
|
+
const id = (elements?.wrapper ?? elements?.cell)?.getAttribute("id");
|
|
116
|
+
if (elements && id) read.push({
|
|
117
|
+
elements,
|
|
118
|
+
id,
|
|
119
|
+
parent: elements.cell.getAttribute("parent")
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
const rootId = read.find((entry) => !entry.parent)?.id;
|
|
123
|
+
if (rootId === void 0) return null;
|
|
124
|
+
const layers = [];
|
|
125
|
+
const cells = [];
|
|
126
|
+
for (const { elements, id, parent } of read) {
|
|
127
|
+
if (!parent) continue;
|
|
128
|
+
const { cell } = elements;
|
|
129
|
+
const shown = cell.getAttribute("vertex") === "1" || cell.getAttribute("edge") === "1";
|
|
130
|
+
if (!shown && parent === rootId) layers.push({
|
|
131
|
+
id,
|
|
132
|
+
name: cell.getAttribute("value") ?? "",
|
|
133
|
+
visible: cell.getAttribute("visible") !== "0",
|
|
134
|
+
locked: styleFlag(parseStyle(cell.getAttribute("style") ?? ""), "locked")
|
|
135
|
+
});
|
|
136
|
+
else if (shown) cells.push(readCell(elements, id, parent));
|
|
137
|
+
}
|
|
138
|
+
return {
|
|
139
|
+
...page,
|
|
140
|
+
attributes: attributesOf(model, /* @__PURE__ */ new Set()),
|
|
141
|
+
rootId,
|
|
142
|
+
layers,
|
|
143
|
+
cells
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
/** The XML inside a compressed `<diagram>`: Base64, raw deflate, then percent-encoded text. */
|
|
147
|
+
function inflateDiagram(text, budget) {
|
|
148
|
+
const encoded = text.trim();
|
|
149
|
+
if (!encoded || !isValid(encoded)) return null;
|
|
150
|
+
try {
|
|
151
|
+
return percentDecoded(new TextDecoder().decode(boundedInflate(toUint8Array(encoded), budget)));
|
|
152
|
+
} catch {
|
|
153
|
+
return null;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
function readDiagram(diagram, index, budget) {
|
|
157
|
+
const name = diagram.getAttribute("name") || `Page ${index + 1}`;
|
|
158
|
+
const page = {
|
|
159
|
+
id: diagram.getAttribute("id") ?? `page-${index + 1}`,
|
|
160
|
+
name
|
|
161
|
+
};
|
|
162
|
+
let model = childElements(diagram, "mxGraphModel").at(0) ?? null;
|
|
163
|
+
if (!model) {
|
|
164
|
+
const xml = inflateDiagram(diagram.textContent ?? "", budget);
|
|
165
|
+
const root = xml ? parseXML(xml) : null;
|
|
166
|
+
model = root?.localName === "mxGraphModel" ? root : null;
|
|
167
|
+
}
|
|
168
|
+
return (model ? readModel(model, page) : null) ?? { unreadable: name };
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* The pages of a draw.io file, whether its diagrams are plain or compressed, with the names of
|
|
172
|
+
* pages it could not read: damaged, or past what the file may unpack to. Null when the source
|
|
173
|
+
* is not a draw.io file.
|
|
174
|
+
*/
|
|
175
|
+
function parseDrawIOFile(source, budget = inflateBudget()) {
|
|
176
|
+
const root = parseXML(source);
|
|
177
|
+
return root ? readDrawIORoot(root, budget) : null;
|
|
178
|
+
}
|
|
179
|
+
/** The pages of a draw.io document from its parsed root, as `parseDrawIOFile` reads them. */
|
|
180
|
+
function readDrawIORoot(root, budget) {
|
|
181
|
+
if (root.localName === "mxGraphModel") {
|
|
182
|
+
const page = readModel(root, {
|
|
183
|
+
id: "page-1",
|
|
184
|
+
name: "Page 1"
|
|
185
|
+
});
|
|
186
|
+
return page ? {
|
|
187
|
+
pages: [page],
|
|
188
|
+
unreadable: []
|
|
189
|
+
} : null;
|
|
190
|
+
}
|
|
191
|
+
if (root.localName !== "mxfile") return null;
|
|
192
|
+
const file = {
|
|
193
|
+
pages: [],
|
|
194
|
+
unreadable: []
|
|
195
|
+
};
|
|
196
|
+
for (const [index, diagram] of childElements(root, "diagram").entries()) {
|
|
197
|
+
const read = readDiagram(diagram, index, budget);
|
|
198
|
+
if ("unreadable" in read) file.unreadable.push(read.unreadable);
|
|
199
|
+
else file.pages.push(read);
|
|
200
|
+
}
|
|
201
|
+
return file;
|
|
202
|
+
}
|
|
203
|
+
//#endregion
|
|
204
|
+
//#region src/write.ts
|
|
205
|
+
/** What the writer puts on `<mxfile>`, so draw.io knows who wrote it. */
|
|
206
|
+
const HOST = "Pairdraw";
|
|
207
|
+
function setNumber(element, name, value) {
|
|
208
|
+
if (value !== 0) element.setAttribute(name, String(value));
|
|
209
|
+
}
|
|
210
|
+
function point(document, at, as) {
|
|
211
|
+
const element = document.createElement("mxPoint");
|
|
212
|
+
element.setAttribute("x", String(at.x));
|
|
213
|
+
element.setAttribute("y", String(at.y));
|
|
214
|
+
if (as) element.setAttribute("as", as);
|
|
215
|
+
return element;
|
|
216
|
+
}
|
|
217
|
+
function geometry(document, value) {
|
|
218
|
+
const element = document.createElement("mxGeometry");
|
|
219
|
+
setNumber(element, "x", value.x);
|
|
220
|
+
setNumber(element, "y", value.y);
|
|
221
|
+
setNumber(element, "width", value.width);
|
|
222
|
+
setNumber(element, "height", value.height);
|
|
223
|
+
if (value.relative) element.setAttribute("relative", "1");
|
|
224
|
+
element.setAttribute("as", "geometry");
|
|
225
|
+
if (value.sourcePoint) element.appendChild(point(document, value.sourcePoint, "sourcePoint"));
|
|
226
|
+
if (value.targetPoint) element.appendChild(point(document, value.targetPoint, "targetPoint"));
|
|
227
|
+
if (value.points.length > 0) {
|
|
228
|
+
const points = document.createElement("Array");
|
|
229
|
+
points.setAttribute("as", "points");
|
|
230
|
+
for (const at of value.points) points.appendChild(point(document, at));
|
|
231
|
+
element.appendChild(points);
|
|
232
|
+
}
|
|
233
|
+
if (value.offset) element.appendChild(point(document, value.offset, "offset"));
|
|
234
|
+
return element;
|
|
235
|
+
}
|
|
236
|
+
/** A cell as draw.io writes it, wrapped in a `UserObject` when it carries attributes. */
|
|
237
|
+
function cellElement(document, cell) {
|
|
238
|
+
const element = document.createElement("mxCell");
|
|
239
|
+
const wrapped = Object.keys(cell.attributes).length > 0;
|
|
240
|
+
if (!wrapped) {
|
|
241
|
+
element.setAttribute("id", cell.id);
|
|
242
|
+
element.setAttribute("value", cell.value);
|
|
243
|
+
}
|
|
244
|
+
const style = formatStyle(cell.style);
|
|
245
|
+
if (style) element.setAttribute("style", style);
|
|
246
|
+
element.setAttribute(cell.kind, "1");
|
|
247
|
+
if (!cell.visible) element.setAttribute("visible", "0");
|
|
248
|
+
element.setAttribute("parent", cell.parent);
|
|
249
|
+
if (cell.source) element.setAttribute("source", cell.source);
|
|
250
|
+
if (cell.target) element.setAttribute("target", cell.target);
|
|
251
|
+
element.appendChild(geometry(document, cell.geometry));
|
|
252
|
+
if (!wrapped) return element;
|
|
253
|
+
const wrapper = document.createElement("UserObject");
|
|
254
|
+
wrapper.setAttribute("label", cell.value);
|
|
255
|
+
for (const [name, value] of Object.entries(cell.attributes)) wrapper.setAttribute(name, value);
|
|
256
|
+
wrapper.setAttribute("id", cell.id);
|
|
257
|
+
wrapper.appendChild(element);
|
|
258
|
+
return wrapper;
|
|
259
|
+
}
|
|
260
|
+
function pageElement(document, page) {
|
|
261
|
+
const diagram = document.createElement("diagram");
|
|
262
|
+
diagram.setAttribute("id", page.id);
|
|
263
|
+
diagram.setAttribute("name", page.name);
|
|
264
|
+
const model = document.createElement("mxGraphModel");
|
|
265
|
+
for (const [name, value] of Object.entries(page.attributes)) model.setAttribute(name, value);
|
|
266
|
+
const root = document.createElement("root");
|
|
267
|
+
const rootCell = document.createElement("mxCell");
|
|
268
|
+
rootCell.setAttribute("id", page.rootId);
|
|
269
|
+
root.appendChild(rootCell);
|
|
270
|
+
for (const layer of page.layers) {
|
|
271
|
+
const element = document.createElement("mxCell");
|
|
272
|
+
element.setAttribute("id", layer.id);
|
|
273
|
+
if (layer.name) element.setAttribute("value", layer.name);
|
|
274
|
+
if (layer.locked) element.setAttribute("style", "locked=1;");
|
|
275
|
+
if (!layer.visible) element.setAttribute("visible", "0");
|
|
276
|
+
element.setAttribute("parent", page.rootId);
|
|
277
|
+
root.appendChild(element);
|
|
278
|
+
}
|
|
279
|
+
for (const cell of page.cells) root.appendChild(cellElement(document, cell));
|
|
280
|
+
model.appendChild(root);
|
|
281
|
+
diagram.appendChild(model);
|
|
282
|
+
return diagram;
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* A draw.io file as XML draw.io opens: each page a `<diagram>` holding its model uncompressed,
|
|
286
|
+
* as draw.io itself saves by default, so the file diffs and reads as text. A file with pages that
|
|
287
|
+
* could not be read is refused, since writing it would drop them.
|
|
288
|
+
*/
|
|
289
|
+
function writeDrawIOFile(file) {
|
|
290
|
+
if (file.unreadable.length > 0) throw new Error(`Could not write the draw.io pages ${file.unreadable.join(", ")}`);
|
|
291
|
+
const document = new DOMImplementation().createDocument(null, "mxfile", null);
|
|
292
|
+
const root = document.documentElement;
|
|
293
|
+
if (!root) throw new Error("Could not create a draw.io document");
|
|
294
|
+
root.setAttribute("host", HOST);
|
|
295
|
+
for (const page of file.pages) root.appendChild(pageElement(document, page));
|
|
296
|
+
return new XMLSerializer().serializeToString(document);
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/index.ts
|
|
300
|
+
/**
|
|
301
|
+
* The draw.io file in `bytes`: a `.drawio` or `.dio` file, or the diagram a draw.io PNG or SVG
|
|
302
|
+
* export embeds. Null when the bytes hold no draw.io diagram. Everything the file unpacks, its
|
|
303
|
+
* compressed pages and image chunks together, shares one size limit.
|
|
304
|
+
*/
|
|
305
|
+
function readDrawIOBytes(bytes) {
|
|
306
|
+
const budget = inflateBudget();
|
|
307
|
+
const root = drawioRoot(bytes, budget);
|
|
308
|
+
return root ? readDrawIORoot(root, budget) : null;
|
|
309
|
+
}
|
|
310
|
+
//#endregion
|
|
311
|
+
export { formatStyle, parseDrawIOFile, parseStyle, readDrawIOBytes, styleFlag, styleNumber, writeDrawIOFile };
|
|
312
|
+
|
|
313
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +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,O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