|
1 |
| -# pkg-placeholder |
| 1 | +# @trbn/jsoncanvas |
2 | 2 |
|
3 | 3 | [![npm version][npm-version-src]][npm-version-href]
|
4 | 4 | [![npm downloads][npm-downloads-src]][npm-downloads-href]
|
5 | 5 | [![bundle][bundle-src]][bundle-href]
|
6 | 6 | [![JSDocs][jsdocs-src]][jsdocs-href]
|
7 | 7 | [![License][license-src]][license-href]
|
8 | 8 |
|
9 |
| -_description_ |
| 9 | +`@trbn/jsoncanvas` is an implementation of the [JSONCanvas Spec](https://jsoncanvas.org/spec/1.0/) in TypeScript. |
10 | 10 |
|
11 |
| -> **Note**: |
12 |
| -> Replace `pkg-placeholder`, `_description_` and `antfu` globally to use this template. |
| 11 | +> Note: This package does NOT include a rendering engine. It is only a data structure for a canvas. |
13 | 12 |
|
14 |
| -## Sponsors |
| 13 | +## Installation |
15 | 14 |
|
16 |
| -<p align="center"> |
17 |
| - <a href="https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg"> |
18 |
| - <img src='https://cdn.jsdelivr.net/gh/antfu/static/sponsors.svg'/> |
19 |
| - </a> |
20 |
| -</p> |
| 15 | +With pnpm: |
| 16 | + |
| 17 | +```bash |
| 18 | +pnpm install @trbn/jsoncanvas |
| 19 | +``` |
| 20 | + |
| 21 | + |
| 22 | +## Example Usage |
| 23 | + |
| 24 | +```typescript |
| 25 | +import { JSONCanvas } from '@trbn/jsoncanvas'; |
| 26 | + |
| 27 | +const canvas = new JSONCanvas(); |
| 28 | + |
| 29 | +// Adds a text node to the canvas |
| 30 | +canvas.addNode({ |
| 31 | + id: 'node1', |
| 32 | + type: 'text', |
| 33 | + text: 'Hello, World!', |
| 34 | + x: 100, |
| 35 | + y: 100, |
| 36 | + width: 100, |
| 37 | + height: 100, |
| 38 | +}); |
| 39 | + |
| 40 | +// Adds another text node to the canvas |
| 41 | +canvas.addNode({ |
| 42 | + id: 'node2', |
| 43 | + type: 'text', |
| 44 | + text: 'Hello, World 2!', |
| 45 | + x: 200, |
| 46 | + y: 200, |
| 47 | + radius: 50, |
| 48 | +}); |
| 49 | + |
| 50 | +// Adds an connection between node1 and node2 |
| 51 | +canvas.addEdge({ |
| 52 | + id: 'edge1', |
| 53 | + fromNode: 'node1', |
| 54 | + toNode: 'node2', |
| 55 | + label: 'Edge 1', |
| 56 | +}); |
| 57 | + |
| 58 | +// Removes node2 and all connections to it |
| 59 | +canvas.removeNode('node2'); |
| 60 | + |
| 61 | +// Outputs the canvas as a string |
| 62 | +console.log(canvas.toString()); |
| 63 | +``` |
21 | 64 |
|
22 | 65 | ## License
|
23 | 66 |
|
24 |
| -[MIT](./LICENSE) License © 2023-PRESENT [Anthony Fu](https://github.com/antfu) |
| 67 | +[MIT](./LICENSE) License © 2024-PRESENT [Torben Haack](https://github.com/haackt) |
25 | 68 |
|
26 | 69 | <!-- Badges -->
|
27 | 70 |
|
28 |
| -[npm-version-src]: https://img.shields.io/npm/v/pkg-placeholder?style=flat&colorA=080f12&colorB=1fa669 |
29 |
| -[npm-version-href]: https://npmjs.com/package/pkg-placeholder |
30 |
| -[npm-downloads-src]: https://img.shields.io/npm/dm/pkg-placeholder?style=flat&colorA=080f12&colorB=1fa669 |
31 |
| -[npm-downloads-href]: https://npmjs.com/package/pkg-placeholder |
32 |
| -[bundle-src]: https://img.shields.io/bundlephobia/minzip/pkg-placeholder?style=flat&colorA=080f12&colorB=1fa669&label=minzip |
33 |
| -[bundle-href]: https://bundlephobia.com/result?p=pkg-placeholder |
34 |
| -[license-src]: https://img.shields.io/github/license/antfu/pkg-placeholder.svg?style=flat&colorA=080f12&colorB=1fa669 |
35 |
| -[license-href]: https://github.com/antfu/pkg-placeholder/blob/main/LICENSE |
36 |
| -[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669 |
37 |
| -[jsdocs-href]: https://www.jsdocs.io/package/pkg-placeholder |
| 71 | +[npm-version-src]: https://img.shields.io/npm/v/@trbn/jsoncanvas?style=flat&colorA=080f12&colorB=1fa669 |
| 72 | +[npm-version-href]: https://npmjs.com/package/@trbn/jsoncanvas |
| 73 | +[npm-downloads-src]: https://img.shields.io/npm/dm/@trbn/jsoncanvas?style=flat&colorA=080f12&colorB=1fa669 |
| 74 | +[npm-downloads-href]: https://npmjs.com/package/@trbn/jsoncanvas |
| 75 | +[bundle-src]: https://img.shields.io/bundlephobia/minzip/@trbn/jsoncanvas?style=flat&colorA=080f12&colorB=1fa669&label=minzip |
| 76 | +[bundle-href]: https://bundlephobia.com/result?p=@trbn/jsoncanvas |
| 77 | +[license-src]: https://img.shields.io/github/license/haackt/@trbn/jsoncanvas.svg?style=flat&colorA=080f12&colorB=1fa669 |
| 78 | +[license-href]: https://github.com/haackt/@trbn/jsoncanvas/blob/main/LICENSE |
| 79 | +[jsdocs-src]: https://img.shields.io/badge/@trbn/jsoncanvas-080f12?style=flat&colorA=080f12&colorB=1fa669 |
| 80 | +[jsdocs-href]: https://www.jsdocs.io/package/@trbn/jsoncanvas |
0 commit comments