@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 CHANGED
@@ -1,57 +1,42 @@
1
1
  # @draftably/runtime
2
2
 
3
- Render `.draft` source to SVG in Node or a browser. The package has no runtime dependencies, DOM shim, or install scripts.
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
- Start with [Use Draftably in your project](https://github.com/byronwall/draftably/blob/main/docs/integrations/README.md)
6
- for package installation and complete element, SVG, and Markdown examples.
7
+ ```sh
8
+ pnpm add @draftably/runtime
9
+ ```
7
10
 
8
11
  ```ts
9
- import { renderSvg, validate } from '@draftably/runtime';
12
+ import { renderSvg } from '@draftably/runtime';
10
13
 
11
- const result = await renderSvg('node api "API"\n');
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
- const result = await renderSvg(source, {
22
- target: 'inline',
23
- idPrefix: 'checkout-one',
24
- description: 'The web app calls the API and saves an order.',
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 { mountViewer } from '@draftably/runtime/viewer';
42
- import '@draftably/runtime/viewer.css';
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
- Give the host a height. The viewer requires an empty host and owns its children. Worker startup, timeout, and font failures return an error and preserve the last good drawing. The viewer does not fall back to main-thread compilation. Select `execution: { mode: 'main' }` for known small inputs or a host-provided link resolver. To use host fonts, import `@draftably/runtime/fonts.css` and set `render: { fonts: 'host' }`.
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
- See the [runtime guide](https://github.com/byronwall/draftably/blob/main/docs/integrations/runtime.md) and [consumer examples](https://github.com/byronwall/draftably/tree/main/integration-examples).
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