See also: https://www.drawio.com/blog/custom-libraries
Libraries consist of an enclosing <mxlibrary>
node containing a JSON array, which in turn contains entries with either an xml
property with a compressed or uncompressed mxGraphModel or a data
property with an image data URI (in PNG, JPG or SVG). All entries must have a w
and h
property for the width and height of the cell(s) or image in the entry and an optional title
property for the title in the sidebar and preview. For entries with a data
property, an optional "aspect": "fixed"
may be specified to add aspect=fixed
to the style of the image cell, and an optional style
attribute can be specified to be added the default style of the image cell. Eg. for "data": "data:image/png,[...]", "aspect": "fixed", "style": "resizable=0;rotatable=0;"
the resulting cell style will be shape=image;verticalLabelPosition=bottom;verticalAlign=top;imageAspect=0;aspect=fixed;image=data:image/png,[...];resizable=0;rotatable=0;
For uncompressed xml
properties, <
must be writter as <
, >
must be written as >
and "
must written as \"
(escaped), eg. "xml": "<mxGraphModel><root><mxCell id=\"0\"/><mxCell id=\"1\" parent=\"0\"/><mxCell id=\"2\" value=\"Test3\" style=\"whiteSpace=wrap;html=1;fillColor=#ffffff;strokeColor=#000000;\" vertex=\"1\" parent=\"1\"><mxGeometry width=\"120\" height=\"60\" as=\"geometry\"/></mxCell></root></mxGraphModel>"
The compressed XML may be obtained by clicking on the Encode button at https://jgraph.github.io/drawio-tools/tools/convert.html, eg. "xml": "jVBLDoMgED3N7BE2XVdbV131BKROhASE4LTq7TsVWuPCpAuS95lH3gyo2s9t0tHcQocO1AVUnUKgjPxco3Mghe1ANSCl4AfyeuBWqyuiTjjQPwGZAy/tnpiVLIy0uCJwwMaRyXkylvAe9ePjTNyZNUOeSzcVw5D00GP5EBPhfFhqlUqjFoNHSguPTLYjkydOubcwaHtDe02Pmfe/5LYhg7Lkl27HXL3drd8="
Click on a link above to open a library or go to File, Open Library from URL in draw.io and enter an URL of the form https://jgraph.github.io/drawio-libs/libs/templates.xml