@kitschpatrol/tldraw-cli 1.2.1 → 2.0.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/bin/cli.js +18 -15
- package/dist/.DS_Store +0 -0
- package/dist/lib/index.js +4 -1
- package/dist/lib/tldraw-to-image.d.ts +8 -1
- package/dist/tldraw/assets/{index-a71XA0Xq.js → index--JsGxma4.js} +39 -39
- package/dist/tldraw/index.html +1 -1
- package/package.json +5 -6
- package/readme.md +32 -17
package/dist/tldraw/index.html
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>tldraw export helper</title>
|
|
7
|
-
<script type="module" crossorigin src="/assets/index
|
|
7
|
+
<script type="module" crossorigin src="/assets/index--JsGxma4.js"></script>
|
|
8
8
|
<link rel="stylesheet" crossorigin href="/assets/index-Go1mR3Ch.css">
|
|
9
9
|
</head>
|
|
10
10
|
<body>
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/tldraw-cli",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"description": "A tiny little CLI tool for
|
|
5
|
+
"description": "A tiny little CLI tool for rendering tldraw URLs and .tldr files into svg or png images.",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git+https://github.com/kitschpatrol/tldraw-cli.git"
|
|
@@ -48,10 +48,9 @@
|
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@kitschpatrol/shared-config": "^4.3.3",
|
|
50
50
|
"@tldraw/assets": "2.0.0-beta.2",
|
|
51
|
-
"@tldraw/editor": "2.0.0-beta.2",
|
|
52
51
|
"@tldraw/tldraw": "2.0.0-beta.2",
|
|
53
52
|
"@types/express": "^4.17.21",
|
|
54
|
-
"@types/react": "^18.2.
|
|
53
|
+
"@types/react": "^18.2.48",
|
|
55
54
|
"@types/react-dom": "^18.2.18",
|
|
56
55
|
"@types/yargs": "^17.0.32",
|
|
57
56
|
"@vitejs/plugin-react-swc": "^3.5.0",
|
|
@@ -66,6 +65,7 @@
|
|
|
66
65
|
"typescript": "^5.3.3",
|
|
67
66
|
"untildify": "^5.0.0",
|
|
68
67
|
"vite": "^5.0.11",
|
|
68
|
+
"vitest": "^1.2.0",
|
|
69
69
|
"yargs": "^17.7.2"
|
|
70
70
|
},
|
|
71
71
|
"publishConfig": {
|
|
@@ -77,12 +77,11 @@
|
|
|
77
77
|
"build:lib": "tsx ./scripts/build-lib.ts && tsc -p tsconfig.lib.json",
|
|
78
78
|
"build:tldraw": "pnpm run tldraw-copy-assets && vite build",
|
|
79
79
|
"dev": "pnpm run tldraw-copy-assets && vite",
|
|
80
|
-
"dev-cli": "pnpm run build:tldraw && tsx ./src/cli/tldraw-cli.ts ./test-assets/box.tldr --verbose",
|
|
81
|
-
"dev-cli-url": "pnpm run build && tsx ./src/cli/tldraw-cli.ts https://www.tldraw.com/s/v2_c_cQCtLu41OH97xkTl2Mt-9 --format png --verbose",
|
|
82
80
|
"fix": "shared-config --fix",
|
|
83
81
|
"lint": "shared-config --lint",
|
|
84
82
|
"preview": "vite preview",
|
|
85
83
|
"release": "pnpm build && pnpm bumpp --commit 'Release: %s' && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
|
|
84
|
+
"test": "vitest",
|
|
86
85
|
"tldraw-copy-assets": "rsync -av --include='/*/' --exclude='/*' ./node_modules/@tldraw/assets/ ./src/tldraw/public/"
|
|
87
86
|
}
|
|
88
87
|
}
|
package/readme.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
## Overview
|
|
6
6
|
|
|
7
|
-
**A minimal CLI app to automate conversion and export of [tldraw](https://tldraw.dev) `.tldr` files into svg or png image formats.**
|
|
7
|
+
**A minimal CLI app to automate conversion and export of [tldraw](https://tldraw.dev) URLs and `.tldr` files into svg or png image formats.**
|
|
8
8
|
|
|
9
9
|
This could be useful in the context of a content publishing pipeline where you want to use a `.tldr` file (perhaps under version control) as the "source of truth" for assets to be embedded elsewhere, and you don't want to manage the export of that diagram manually.
|
|
10
10
|
|
|
@@ -38,17 +38,19 @@ npm --install --global @kitschpatrol/tldraw-cli
|
|
|
38
38
|
tldraw-cli file-or-url {options}
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
-
| Argument | Description
|
|
42
|
-
| ------------- |
|
|
43
|
-
| `file-or-url` | The sketch to convert to an image — either a path to a local ".tldr" file, or a tldraw\.com sketch URL |
|
|
41
|
+
| Argument | Description |
|
|
42
|
+
| ------------- | ------------------------------------------------------------------------------------------------------- |
|
|
43
|
+
| `file-or-url` | The sketch to convert to an image — either a path to a local ".tldr" file, or a tldraw\.com sketch URL. |
|
|
44
44
|
|
|
45
|
-
| Option
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
| `--
|
|
45
|
+
| Option | Alias | Description | Default |
|
|
46
|
+
| --------------- | ----- | --------------------------------------------- | ----------- |
|
|
47
|
+
| `--format` | `-f` | Output image format, one of "png" or "svg" | `svg` |
|
|
48
|
+
| `--dark-mode` | `-d` | Output a dark theme version of the image |
|
|
49
|
+
| `--transparent` | `-t` | Output an image with a transparent background | `undefined` |
|
|
50
|
+
| `--output` | `-o` | Output directory | `./` |
|
|
51
|
+
| `--help` | `-h` | Show help | |
|
|
52
|
+
| `--version` | `-v` | Show version number | |
|
|
53
|
+
| `--verbose` | | Enable verbose output | `false` |
|
|
52
54
|
|
|
53
55
|
## Examples
|
|
54
56
|
|
|
@@ -72,6 +74,12 @@ npx @kitschpatrol/tldraw-cli https://www.tldraw.com/s/v2_c_JsxJk8dag6QsrqExukis4
|
|
|
72
74
|
npx @kitschpatrol/tldraw-cli your-drawing.tldr --format png
|
|
73
75
|
```
|
|
74
76
|
|
|
77
|
+
### Export with a transparent background
|
|
78
|
+
|
|
79
|
+
```sh
|
|
80
|
+
npx @kitschpatrol/tldraw-cli your-drawing.tldr --transparent --format png
|
|
81
|
+
```
|
|
82
|
+
|
|
75
83
|
### Export to a specific destination
|
|
76
84
|
|
|
77
85
|
```sh
|
|
@@ -82,10 +90,18 @@ npx @kitschpatrol/tldraw-cli your-drawing.tldr --output ~/Desktop
|
|
|
82
90
|
|
|
83
91
|
The conversion tool's functionality is also exposed as a module for use in TypeScript or JavaScript Node projects.
|
|
84
92
|
|
|
85
|
-
The library exports a single async function, `tldrawToImage
|
|
93
|
+
The library exports a single async function, `tldrawToImage`, which takes an options argument mirroring the arguments available via the command line. The same default values apply:
|
|
86
94
|
|
|
87
95
|
```ts
|
|
88
|
-
tldrawToImage(
|
|
96
|
+
tldrawToImage(
|
|
97
|
+
tldrPathOrUrl: string,
|
|
98
|
+
{
|
|
99
|
+
darkMode?: boolean
|
|
100
|
+
output?: string
|
|
101
|
+
format?: ExportFormat
|
|
102
|
+
transparent?: boolean
|
|
103
|
+
verbose?: boolean
|
|
104
|
+
}): Promise<string>;
|
|
89
105
|
```
|
|
90
106
|
|
|
91
107
|
The function exports the image in the requested format returns the full path to the output image.
|
|
@@ -97,8 +113,8 @@ Assuming you've installed `@kitschpatrol/tldraw-cli` locally in your project, it
|
|
|
97
113
|
|
|
98
114
|
import { tldrawToImage } from '@kitschpatrol/tldraw-cli'
|
|
99
115
|
|
|
100
|
-
//
|
|
101
|
-
const imagePathFromLocal = await tldrawToImage('./some-file.tldr', 'png', './'
|
|
116
|
+
// Converting a local file
|
|
117
|
+
const imagePathFromLocal = await tldrawToImage('./some-file.tldr', { format: 'png', output: './' })
|
|
102
118
|
|
|
103
119
|
// Image saved to: "[...]/some-file.png"
|
|
104
120
|
console.log(`Image saved to: "${imagePathFromLocal}"`)
|
|
@@ -135,10 +151,9 @@ The local instance of tldraw includes its assets dependencies, so the tool shoul
|
|
|
135
151
|
|
|
136
152
|
This is a very minimal implementation. Current plans for future improvements include the following:
|
|
137
153
|
|
|
138
|
-
- Add
|
|
154
|
+
- Add CLI tests
|
|
139
155
|
- Implement the ability to export specific frames or pages as separate image files
|
|
140
156
|
- Add an option flag to set dpi when exporting to a bitmap format
|
|
141
|
-
- Add option flag for transparent background
|
|
142
157
|
|
|
143
158
|
Any other suggestions are welcome.
|
|
144
159
|
|