@kitschpatrol/tldraw-cli 4.2.1 → 4.3.1
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 +104 -117
- package/dist/.DS_Store +0 -0
- package/dist/lib/index.js +73 -108
- package/dist/lib/inline/get-image.d.ts +6 -6
- package/dist/lib/tldraw-controller.d.ts +8 -5
- package/dist/lib/tldraw-to-image.d.ts +2 -0
- package/package.json +1 -1
- package/readme.md +30 -29
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import { type Editor
|
|
1
|
+
import { type Editor } from 'tldraw';
|
|
2
2
|
declare global {
|
|
3
3
|
interface Window {
|
|
4
4
|
editor: Editor;
|
|
5
5
|
getImage: (options: {
|
|
6
|
-
background
|
|
7
|
-
darkMode
|
|
8
|
-
format:
|
|
9
|
-
padding
|
|
10
|
-
scale
|
|
6
|
+
background?: boolean;
|
|
7
|
+
darkMode?: boolean;
|
|
8
|
+
format: 'json' | 'png' | 'svg';
|
|
9
|
+
padding?: number;
|
|
10
|
+
scale?: number;
|
|
11
11
|
}) => Promise<string>;
|
|
12
12
|
}
|
|
13
13
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { TldrawToImageOptions } from './tldraw-to-image';
|
|
2
|
+
type DownloadOptions = Omit<TldrawToImageOptions, 'frames'>;
|
|
2
3
|
export default class TldrawController {
|
|
3
4
|
private readonly href;
|
|
4
5
|
private page?;
|
|
@@ -8,10 +9,10 @@ export default class TldrawController {
|
|
|
8
9
|
private get isLocal();
|
|
9
10
|
start(): Promise<void>;
|
|
10
11
|
close(): Promise<void>;
|
|
11
|
-
download(
|
|
12
|
-
downloadFrame(
|
|
13
|
-
downloadFrames(
|
|
14
|
-
downloadAllFrames(
|
|
12
|
+
download(options: DownloadOptions): Promise<string[]>;
|
|
13
|
+
downloadFrame(frameNameOrId: string, options: DownloadOptions): Promise<string[]>;
|
|
14
|
+
downloadFrames(frameNamesOrIds: string[], options: DownloadOptions): Promise<string[]>;
|
|
15
|
+
downloadAllFrames(options: DownloadOptions): Promise<string[]>;
|
|
15
16
|
loadFile(filePath: string): Promise<void>;
|
|
16
17
|
getShareUrl(): Promise<string>;
|
|
17
18
|
private _download;
|
|
@@ -20,4 +21,6 @@ export default class TldrawController {
|
|
|
20
21
|
private getPageFrameWithNameOrId;
|
|
21
22
|
private getPageFrames;
|
|
22
23
|
private stripStyleElement;
|
|
24
|
+
private stripUndefined;
|
|
23
25
|
}
|
|
26
|
+
export {};
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,15 +1,23 @@
|
|
|
1
1
|
<!--+ Warning: Content inside HTML comment blocks was generated by mdat and may be overwritten. +-->
|
|
2
2
|
|
|
3
|
-
<!--
|
|
3
|
+
<!-- title -->
|
|
4
4
|
|
|
5
5
|
# @kitschpatrol/tldraw-cli
|
|
6
6
|
|
|
7
|
+
<!-- /title -->
|
|
8
|
+
|
|
9
|
+
<!-- badges -->
|
|
10
|
+
|
|
7
11
|
[](https://npmjs.com/package/@kitschpatrol/tldraw-cli)
|
|
8
12
|
[](https://opensource.org/licenses/MIT)
|
|
9
13
|
|
|
14
|
+
<!-- /badges -->
|
|
15
|
+
|
|
16
|
+
<!-- description -->
|
|
17
|
+
|
|
10
18
|
**A CLI tool for exporting tldraw sketch URLs and local .tldr files to SVG or PNG images.**
|
|
11
19
|
|
|
12
|
-
<!-- /
|
|
20
|
+
<!-- /description -->
|
|
13
21
|
|
|
14
22
|
<!-- table-of-contents { maxDepth: 2 } -->
|
|
15
23
|
|
|
@@ -101,19 +109,21 @@ tldraw-cli export <files-or-urls..>
|
|
|
101
109
|
| ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------- |
|
|
102
110
|
| `files-or-urls` | The tldraw sketch to export. May be one or more paths to local `.tldr` files, or tldraw\.com sketch URLs. Accepts a mix of both file paths and URLs, and supports glob matching via your shell. Prints the absolute path(s) to the exported image(s) to `stdout`. _(Required.)_ | `array` |
|
|
103
111
|
|
|
104
|
-
| Option | Alias | Description | Type | Default |
|
|
105
|
-
| --------------- | ----- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------------------------------------- |
|
|
106
|
-
| `--format` | `-f` | Output image format. | `string` | `"svg"` |
|
|
107
|
-
| `--output` | `-o` | Output image directory. | `string` | `"./"` |
|
|
108
|
-
| `--name` | `-n` | Output image name (without extension). | `string` | The original file name or URL id is used. |
|
|
109
|
-
| `--frames` | | Export each sketch "frame" as a separate image. Pass one or more frame names or IDs to export specific frames, or skip the arguments to export all frames. | `array` | `false` |
|
|
110
|
-
| `--transparent` | `-t` | Export an image with a transparent background. | `boolean` | `false` |
|
|
111
|
-
| `--dark` | `-d` | Export a dark theme version of the image. | `boolean` | `false` |
|
|
112
|
-
| `--
|
|
113
|
-
| `--
|
|
114
|
-
| `--
|
|
115
|
-
| `--
|
|
116
|
-
| `--
|
|
112
|
+
| Option | Alias | Argument | Description | Type | Default |
|
|
113
|
+
| --------------- | ----- | ---------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------- | ----------------------------------------- |
|
|
114
|
+
| `--format` | `-f` | | Output image format. | `string` | `"svg"` |
|
|
115
|
+
| `--output` | `-o` | | Output image directory. | `string` | `"./"` |
|
|
116
|
+
| `--name` | `-n` | | Output image name (without extension). | `string` | The original file name or URL id is used. |
|
|
117
|
+
| `--frames` | | | Export each sketch "frame" as a separate image. Pass one or more frame names or IDs to export specific frames, or skip the arguments to export all frames. | `array` | `false` |
|
|
118
|
+
| `--transparent` | `-t` | | Export an image with a transparent background. | `boolean` | `false` |
|
|
119
|
+
| `--dark` | `-d` | | Export a dark theme version of the image. | `boolean` | `false` |
|
|
120
|
+
| `--padding` | | `[number]` | Set a specific padding amount around the exported image. | | `32` |
|
|
121
|
+
| `--scale` | | `[number]` | Set a sampling amount for raster image exports. | | `1` |
|
|
122
|
+
| `--strip-style` | | | Remove `<style>` elements from SVG output, useful to lighten the load of embedded fonts if you intend to provide your own stylesheets. Applies to SVG output only. | `boolean` | `false` |
|
|
123
|
+
| `--print` | `-p` | | Print the exported image(s) to stdout instead of saving to a file. Incompatible with `--output`, and disregards `--name`. PNGs are printed as base64-encoded strings. | `boolean` | `false` |
|
|
124
|
+
| `--verbose` | | | Enable verbose logging. All verbose logs and prefixed with their log level and are printed to `stderr` for ease of redirection. | `boolean` | `false` |
|
|
125
|
+
| `--help` | `-h` | | Show help | `boolean` | |
|
|
126
|
+
| `--version` | `-v` | | Show version number | `boolean` | |
|
|
117
127
|
|
|
118
128
|
#### Subcommand: `tldraw-cli open`
|
|
119
129
|
|
|
@@ -269,6 +279,9 @@ The library exports a single async function, `tldrawToImage`, which takes an opt
|
|
|
269
279
|
frames?: boolean | string[]
|
|
270
280
|
name?: string
|
|
271
281
|
output?: string
|
|
282
|
+
padding?: number
|
|
283
|
+
print?: boolean
|
|
284
|
+
scale?: number
|
|
272
285
|
stripStyle?: boolean
|
|
273
286
|
transparent?: boolean
|
|
274
287
|
}): Promise<string[]>;
|
|
@@ -344,8 +357,8 @@ On GitHub:
|
|
|
344
357
|
|
|
345
358
|
On Discord:
|
|
346
359
|
|
|
347
|
-
- [@jorisjh in #
|
|
348
|
-
- [@Nitsuj in #
|
|
360
|
+
- [@jorisjh in #ideas_old](https://discord.com/channels/859816885297741824/859816885801713730/1156880056501665802)
|
|
361
|
+
- [@Nitsuj in #ideas_old](https://discord.com/channels/859816885297741824/859816885801713730/1020352607920869406)
|
|
349
362
|
|
|
350
363
|
## Implementation notes
|
|
351
364
|
|
|
@@ -363,18 +376,6 @@ Track the [tldraw changelog](https://github.com/tldraw/tldraw/blob/main/CHANGELO
|
|
|
363
376
|
|
|
364
377
|
## The future
|
|
365
378
|
|
|
366
|
-
Current plans for future improvements include the following:
|
|
367
|
-
|
|
368
|
-
- Add save button to local tldraw
|
|
369
|
-
- Accept globs and optimize batch processing with a single Puppeteer instance
|
|
370
|
-
- Add CLI tests
|
|
371
|
-
- Implement the ability to export specific pages as separate image files
|
|
372
|
-
- Add an option flag to set dpi when exporting to a bitmap format
|
|
373
|
-
- There's room for optimization in how tldraw functions are passed to Puppeteer
|
|
374
|
-
- There's room for optimization in the `--print` option implementation
|
|
375
|
-
|
|
376
|
-
Any other suggestions are welcome.
|
|
377
|
-
|
|
378
379
|
Eventually, I think it would make sense for some kind of CLI tool like this one to be part of the core tldraw project. (Similar to how [tldraw-vscode](https://github.com/tldraw/tldraw/tree/main/apps/vscode) is currently integrated.)
|
|
379
380
|
|
|
380
381
|
I'm consciously releasing this tool under the `@kitschpatrol` namespace on NPM to leave the `tldraw-cli` package name available to the core tldraw project.
|