This document provides guidance for AI assistants and developers working on this repository.
draw.io Tools is a collection of web-based utilities for working with draw.io diagrams. The tools are built as static HTML files with vanilla JavaScript and can be hosted on any static web server (including GitHub Pages) without any build step.
drawio-tools/
├── index.html # Landing page with tool picker
├── styles/ # CSS styles
│ ├── main.css # Main stylesheet (imports all)
│ ├── variables.css # CSS custom properties
│ ├── base.css # Reset and base styles
│ └── components.css # Reusable component styles
├── utils/ # Shared JavaScript utilities
│ └── drawio-tools.js # Combined utility library (global namespace)
├── assets/ # Static assets
│ ├── logo.svg # draw.io logo
│ └── favicon.svg # Favicon
├── tools/ # Individual tool pages
│ ├── text-tools.html # Text encoding/decoding
│ ├── mxfile-tools.html # MxFile validation
│ ├── generate.html # AI diagram generation
│ ├── base64.html # Image to Base64
│ ├── viewer.html # Diagram viewer
│ ├── csv.html # CSV import
│ ├── link.html # Custom links builder (deprecated: now built into the draw.io Edit Link dialog)
│ ├── merge.html # Image merge
│ └── convert.html # Redirect to text-tools.html (backward compat)
├── package.json # npm metadata (no dependencies required)
└── CLAUDE.md # This file
- No Build Required: Pure static HTML/CSS/JS
- JavaScript: Vanilla JS with IIFE pattern, no ES modules
- CSS: CSS Custom Properties with light/dark mode via
@import - Compression: pako library loaded from CDN
- Global Namespace:
window.DrawioToolsfor shared utilities
No installation or build step required. Simply:
- Open any HTML file directly in your browser, OR
- Serve with any static server:
# Python python -m http.server 8080 # Node.js (npx) npx serve . # VS Code Live Server extension
- IIFE Pattern: All JavaScript uses Immediately Invoked Function Expressions
- Global Namespace: Utilities exposed via
window.DrawioTools - CSS Variables: Use CSS custom properties from
variables.css - Dark Mode: Automatic via
prefers-color-schememedia query - CDN Loading: pako loaded from cdnjs before drawio-tools.js
- Use Allman brace style: opening braces go on their own line, aligned with the control statement
function example() { if (condition) { // ... } else { // ... } }
- Use 2-space indentation
- Use single quotes for JavaScript strings (except in HTML attributes)
- Use
varfor compatibility (noconst/let) - Functions should have comments for clarity
- Prefer vanilla JS over modern syntax for browser compatibility
draw.io uses an XML-based format called mxfile:
<mxfile>
<diagram name="Page-1">
<!-- Base64 encoded, deflated, URL-encoded content -->
</diagram>
</mxfile>The diagram content is processed through this pipeline:
- XML → URL encode → Deflate compress → Base64 encode
- Decoding reverses the process
Encoding Functions:
encode(data, options)- Full encoding pipelinedecode(data, options)- Full decoding pipelineurlEncode(data)/urlDecode(data)- URL encodingbase64Encode(data)/base64Decode(data)- Base64 encodingdeflate(data)/inflate(data)- Deflate compression
MxFile Functions:
validateMxFile(content)- Returns validation errorscorrectMxFile(content)- Attempts to fix corrupted filesgetMxFileInfo(content)- Extract metadataisMxFile(content)- Check if content is valid mxfilegetDiagramNames(content)- Get page names
File Functions:
setupDropZone(element, onDrop)- Drag and drop handlerdownloadFile(content, filename)- Trigger file downloadcopyToClipboard(text)- Copy to clipboardreadFileAsText(file)- Read file as textreadFileAsDataURL(file)- Read file as data URL
Text Functions:
formatXml(xml)- Pretty-print XMLnormalizeXml(xml)- Minify XMLformatJson(json)- Pretty-print JSONnormalizeJson(json)- Minify JSONescapeString(str)/unescapeString(str)- Escape sequences
- Create HTML file in
tools/ - Use the standard page structure (see existing tools)
- Include scripts at the end of body:
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.1.0/pako.min.js"></script> <script src="../utils/drawio-tools.js"></script> <script> (function() { var DT = window.DrawioTools; // Tool logic here })(); </script>
- Add link in
index.htmllanding page - Update this documentation
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Tool Name - draw.io Tools</title>
<link rel="icon" type="image/svg+xml" href="../assets/favicon.svg">
<link rel="stylesheet" href="../styles/main.css">
</head>
<body>
<div class="page">
<header class="header"><!-- Standard header --></header>
<main class="main-content">
<div class="container tool-page">
<!-- Tool content -->
</div>
</main>
<footer class="footer"><!-- Standard footer --></footer>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/pako/2.1.0/pako.min.js"></script>
<script src="../utils/drawio-tools.js"></script>
<script>
(function() {
var DT = window.DrawioTools;
// Tool logic
})();
</script>
</body>
</html>Old URLs are preserved:
/tools/convert.html→ redirects to/tools/text-tools.html
No automated tests. Test manually by:
- Opening HTML files directly in browser
- Testing each tool with various inputs
- Verifying encoding/decoding roundtrip
- Testing file drag-and-drop
- Checking dark mode appearance
- Testing in different browsers
The site is fully static and can be deployed anywhere:
- GitHub Pages: Deploy root directory directly
- Netlify/Vercel: Point to root as publish directory
- Any Web Server: Copy all contents
No build step required.
- pako not loading: Ensure CDN script is included before drawio-tools.js
- Path issues: Tools use
../assets/,../styles/,../utils/(relative to tools/) - CORS errors: AI tools need valid API keys and may have CORS restrictions
- Dark mode flickering: CSS uses system preference, no JS toggle needed