@draftably/runtime 0.1.0 → 0.3.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/README.md +25 -40
- package/dist/assets/render.worker-dvseyGmC.js +8310 -0
- package/dist/compile-Csfz4rk4.js +7267 -0
- package/dist/element.js +21 -12
- package/dist/{font-data-DbrpaYkG.js → font-data-DLXJur0j.js} +1 -1
- package/dist/graph.js +669 -0
- package/dist/index.js +5 -4
- package/dist/render-Dgo42PR4.js +1146 -0
- package/dist/types/src/dsl/compile.d.ts +13 -0
- package/dist/types/src/dsl/corridors.d.ts +38 -0
- package/dist/types/src/graph-api/core.d.ts +125 -0
- package/dist/types/src/graph-api/cytoscape.d.ts +48 -0
- package/dist/types/src/graph-api/dagre.d.ts +33 -0
- package/dist/types/src/graph-api/elk.d.ts +91 -0
- package/dist/types/src/graph-api/index.d.ts +60 -0
- package/dist/types/src/graph-api/react-flow.d.ts +100 -0
- package/dist/types/src/graph-api/transform.d.ts +6 -0
- package/dist/types/src/model/types.d.ts +9 -0
- package/dist/types/src/runtime/element.d.ts +2 -0
- package/dist/types/src/runtime/viewer.d.ts +5 -0
- package/dist/viewer.css +20 -0
- package/dist/viewer.js +101 -99
- package/package.json +9 -5
- package/dist/assets/render.worker-BpUp6NY_.js +0 -7618
- package/dist/render-BOAZBzVa.js +0 -7633
package/README.md
CHANGED
|
@@ -1,57 +1,42 @@
|
|
|
1
1
|
# @draftably/runtime
|
|
2
2
|
|
|
3
|
-
Render `.draft`
|
|
3
|
+
Render `.draft` diagrams to SVG in Node or a browser, or show them in an interactive
|
|
4
|
+
`<draft-diagram>` element. No runtime dependencies, DOM shim or install scripts. Needs Node 22.21
|
|
5
|
+
or later.
|
|
4
6
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
+
```sh
|
|
8
|
+
pnpm add @draftably/runtime
|
|
9
|
+
```
|
|
7
10
|
|
|
8
11
|
```ts
|
|
9
|
-
import { renderSvg
|
|
12
|
+
import { renderSvg } from '@draftably/runtime';
|
|
10
13
|
|
|
11
|
-
const result = await renderSvg('node api "API"
|
|
14
|
+
const result = await renderSvg('node api "API"');
|
|
12
15
|
if (result.ok) console.log(result.value.svg);
|
|
13
|
-
else console.error(result.diagnostics);
|
|
14
|
-
|
|
15
|
-
await validate('node api "API"\n');
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
-
Image output embeds its used fonts. Links and source metadata are disabled by default. Inline output needs a unique `idPrefix`:
|
|
19
|
-
|
|
20
18
|
```ts
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
19
|
+
import { layout } from '@draftably/runtime/graph';
|
|
20
|
+
|
|
21
|
+
// Positions, routed lines and label boxes for a graph your app draws.
|
|
22
|
+
const placed = await layout({
|
|
23
|
+
nodes: [{ id: 'a' }, { id: 'b' }],
|
|
24
|
+
edges: [{ source: 'a', target: 'b' }],
|
|
25
25
|
});
|
|
26
26
|
```
|
|
27
27
|
|
|
28
|
-
To use exact host fonts, import `@draftably/runtime/fonts.css` and set `fonts: 'host'` with inline output. Copy the full `dist` directory for a no-bundler browser module; its font chunk and CSS font files use relative paths.
|
|
29
|
-
|
|
30
|
-
## Interactive viewer
|
|
31
|
-
|
|
32
|
-
For automatic setup, import `@draftably/runtime/element` once and use
|
|
33
|
-
`<draft-diagram source='node api "API"'></draft-diagram>`. It supplies styles,
|
|
34
|
-
default sizing, updates, and cleanup. Put an image inside it for a static
|
|
35
|
-
fallback. See the [element guide](https://github.com/byronwall/draftably/blob/main/docs/integrations/element.md)
|
|
36
|
-
for the complete Vite configuration and source update example.
|
|
37
|
-
|
|
38
|
-
The optional `/viewer` entry mounts an independent, read-only viewer. Its default module worker and embedded fonts keep compilation off the main thread and visuals self-contained:
|
|
39
|
-
|
|
40
28
|
```ts
|
|
41
|
-
import
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
const viewer = mountViewer(document.querySelector('#diagram')!, { label: 'Checkout flow' });
|
|
45
|
-
void viewer.update(source).then(result => {
|
|
46
|
-
if (result.status === 'error') console.error(result.error.diagnostics);
|
|
47
|
-
});
|
|
48
|
-
// Call viewer.destroy() when the host is removed.
|
|
29
|
+
import '@draftably/runtime/element';
|
|
30
|
+
// <draft-diagram source='node api "API"' label="API diagram"></draft-diagram>
|
|
49
31
|
```
|
|
50
32
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
Read the [viewer integration guide](https://github.com/byronwall/draftably/blob/main/docs/integrations/viewer.md) for lifecycle, accessibility, framework, and SSR recipes.
|
|
54
|
-
|
|
55
|
-
Requires Node 22.21 or later. Browser ESM is checked in Chromium. Cancellation on the calling thread is cooperative. A host must choose worker or process isolation for an enforced deadline.
|
|
33
|
+
## Docs
|
|
56
34
|
|
|
57
|
-
|
|
35
|
+
- [Render SVG](https://draftably.dev/docs/render-svg): options, validation, inline output, links
|
|
36
|
+
and limits
|
|
37
|
+
- [Layout API](https://draftably.dev/docs/layout-api): lay out and route a graph your app draws
|
|
38
|
+
- [Drop in your graph layout](https://draftably.dev/docs/layout-drop-in): replace the layout in
|
|
39
|
+
React Flow, Svelte Flow, elkjs, dagre or Cytoscape.js with one changed call
|
|
40
|
+
- [Element and viewer](https://draftably.dev/docs/element): the element, `mountViewer`, fallback
|
|
41
|
+
images and SSR
|
|
42
|
+
- [Embed diagrams](https://draftably.dev/docs/embed): every route, including framework components
|