@kitschpatrol/tldraw-cli 5.0.12 → 5.0.13

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.
@@ -1,3 +1,49 @@
1
- export { tldrawOpen, type TldrawOpenOptions, type TldrawOpenResult } from './tldraw-open.js';
2
- export { type TldrawFormat, tldrawToImage, type TldrawToImageOptions } from './tldraw-to-image.js';
3
- export { default as log } from './utilities/log.js';
1
+ import { ChildProcess } from "node:child_process";
2
+
3
+ //#region src/lib/tldraw-open.d.ts
4
+ type TldrawOpenOptions = {
5
+ location: 'local' | 'remote';
6
+ };
7
+ type TldrawOpenResult = {
8
+ browserExitPromise: Promise<ChildProcess>;
9
+ openedSketchUrl: string;
10
+ };
11
+ /**
12
+ * Opens a tldraw file or URL in a browser.
13
+ */
14
+ declare function tldrawOpen(tldrPathOrUrl?: string, options?: Partial<TldrawOpenOptions>): Promise<TldrawOpenResult>;
15
+ //#endregion
16
+ //#region src/lib/tldraw-to-image.d.ts
17
+ type TldrawFormat = 'png' | 'svg' | 'tldr';
18
+ type TldrawToImageOptions = {
19
+ dark?: boolean;
20
+ format?: TldrawFormat;
21
+ frames?: boolean | string[];
22
+ name?: string;
23
+ output?: string;
24
+ padding?: number;
25
+ pages?: boolean | number[] | string[];
26
+ print?: boolean;
27
+ scale?: number;
28
+ stripStyle?: boolean;
29
+ transparent?: boolean;
30
+ };
31
+ /**
32
+ * Downloads a tldraw file or URL as an image.
33
+ */
34
+ declare function tldrawToImage(tldrPathOrUrl: string, options?: TldrawToImageOptions): Promise<string[]>;
35
+ //#endregion
36
+ //#region src/lib/utilities/log.d.ts
37
+ declare const log: {
38
+ verbose: boolean;
39
+ log(...data: unknown[]): void;
40
+ logPrefixed(prefix: string, ...data: unknown[]): void;
41
+ info(...data: unknown[]): void;
42
+ infoPrefixed(prefix: string, ...data: unknown[]): void;
43
+ warn(...data: unknown[]): void;
44
+ warnPrefixed(prefix: string, ...data: unknown[]): void;
45
+ error(...data: unknown[]): void;
46
+ errorPrefixed(prefix: string, ...data: unknown[]): void;
47
+ };
48
+ //#endregion
49
+ export { type TldrawFormat, type TldrawOpenOptions, type TldrawOpenResult, type TldrawToImageOptions, log, tldrawOpen, tldrawToImage };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kitschpatrol/tldraw-cli",
3
- "version": "5.0.12",
3
+ "version": "5.0.13",
4
4
  "description": "A CLI tool and TypeScript library for exporting tldraw sketches to PNG or SVG images.",
5
5
  "keywords": [
6
6
  "tldraw",
@@ -62,6 +62,8 @@
62
62
  "yargs": "^18.0.0"
63
63
  },
64
64
  "devDependencies": {
65
+ "@arethetypeswrong/core": "^0.18.2",
66
+ "@blazediff/vitest": "^1.1.11",
65
67
  "@fontsource/inter": "^5.2.8",
66
68
  "@kitschpatrol/shared-config": "^6.0.3",
67
69
  "@tldraw/assets": "^4.5.3",
@@ -74,12 +76,11 @@
74
76
  "mdat-plugin-cli-help": "^1.0.7",
75
77
  "node-addon-api": "^8.6.0",
76
78
  "node-gyp": "^12.2.0",
79
+ "publint": "^0.3.18",
77
80
  "react": "^19.2.4",
78
81
  "react-dom": "^19.2.4",
79
82
  "rolldown": "1.0.0-rc.10",
80
83
  "safe-stable-stringify": "^2.5.0",
81
- "sharp": "^0.34.5",
82
- "sharp-phash": "^2.2.0",
83
84
  "strip-ansi": "^7.2.0",
84
85
  "tldraw": "^4.5.3",
85
86
  "tsdown": "^0.21.4",
@@ -96,7 +97,7 @@
96
97
  },
97
98
  "scripts": {
98
99
  "build": "pnpm run build:tldraw && pnpm run build:src",
99
- "build:src": "tsdown && tsc -p tsconfig.build.json",
100
+ "build:src": "tsdown",
100
101
  "build:tldraw": "pnpm run tldraw:copy-assets && vite build",
101
102
  "clean": "git rm -f pnpm-lock.yaml ; git clean -fdX",
102
103
  "dev": "pnpm run dev:tldraw",
package/readme.md CHANGED
@@ -48,6 +48,8 @@ A CLI app to automate conversion and export of [tldraw](https://tldraw.dev) URLs
48
48
 
49
49
  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.
50
50
 
51
+ _Please note that this tool, which is all about image export, should not be confused with the official [tldraw project scaffolding CLI](https://www.npmjs.com/package/create-tldraw) which is all about creating new tldraw-powered projects._
52
+
51
53
  _For `.tldr` file import support in Vite projects, please see [@kitschpatrol/vite-plugin-tldraw](https://github.com/kitschpatrol/vite-plugin-tldraw)._
52
54
 
53
55
  ## Installation
@@ -374,7 +376,7 @@ await tldrawToImage('https://www.tldraw.com/s/v2_c_JsxJk8dag6QsrqExukis4')
374
376
  Mirrors the `tldraw open` CLI command.
375
377
 
376
378
  > [!IMPORTANT]
377
- > Due to recent tldraw\.com requirements to login before sharing a sketch, opening a _local_ .tldr file with the `location: 'remote'` option is no longer supported.
379
+ > Due to recent tldraw.com requirements to login before sharing a sketch, opening a _local_ .tldr file with the `location: 'remote'` option is no longer supported.
378
380
 
379
381
  ```tsx
380
382
  async function tldrawOpen(
@@ -486,6 +488,7 @@ On GitHub:
486
488
  - [AWS Lambda-based approach](https://gist.github.com/steveruizok/c30fc99b9b3d95a14c82c59bdcc69201)
487
489
  - [Added exporting of shapes and pages as images](https://github.com/tldraw/tldraw/pull/468)
488
490
  - [\[feature\] Copy/Share as PNG](https://github.com/tldraw/tldraw-v1/issues/361)
491
+ - [Create tldraw CLI tools](https://github.com/tldraw/tldraw/issues/7539)
489
492
 
490
493
  On Discord:
491
494
 
@@ -494,7 +497,7 @@ On Discord:
494
497
 
495
498
  ## Implementation notes
496
499
 
497
- This tool is not a part of the official tldraw project.
500
+ This tool is _not_ a part of the official tldraw project.
498
501
 
499
502
  Due to the architecture of tldraw, export depends on functionality provided by a web browser. So, behind the scenes, this app serves a local instance of tldraw, then loads a `.tldr` and invokes the export download via the [Puppeteer](https://pptr.dev) headless browser automation tool.
500
503
 
@@ -1,13 +0,0 @@
1
- import type { Editor } from 'tldraw';
2
- declare global {
3
- interface Window {
4
- editor: Editor;
5
- getImage: (options: {
6
- background?: boolean;
7
- darkMode?: boolean;
8
- format: 'png' | 'svg';
9
- padding?: number;
10
- scale?: number;
11
- }) => Promise<string>;
12
- }
13
- }
@@ -1,7 +0,0 @@
1
- import type { Editor } from 'tldraw';
2
- declare global {
3
- interface Window {
4
- editor: Editor;
5
- getTldr: () => Promise<string>;
6
- }
7
- }
@@ -1,10 +0,0 @@
1
- export default class LocalTldrawServer {
2
- private readonly tldrData?;
3
- get href(): string;
4
- private port?;
5
- private server?;
6
- constructor(tldrData?: string | undefined);
7
- close(): void;
8
- start(): Promise<void>;
9
- private waitForServer;
10
- }
@@ -1,22 +0,0 @@
1
- import type { TldrawToImageOptions } from './tldraw-to-image.js';
2
- export default class TldrawController {
3
- private readonly href;
4
- private browser?;
5
- private isEmpty?;
6
- private page?;
7
- private get isLocal();
8
- constructor(href: string);
9
- close(): Promise<void>;
10
- download(options: TldrawToImageOptions): Promise<string[]>;
11
- start(): Promise<void>;
12
- private getCurrentPage;
13
- private getDownloadPlans;
14
- private getPageFrames;
15
- private getPages;
16
- private getSketchStructure;
17
- private setCurrentPage;
18
- private stripStyleElement;
19
- private stripUndefined;
20
- private validateFrames;
21
- private validatePages;
22
- }
@@ -1,12 +0,0 @@
1
- import type { ChildProcess } from 'node:child_process';
2
- export type TldrawOpenOptions = {
3
- location: 'local' | 'remote';
4
- };
5
- export type TldrawOpenResult = {
6
- browserExitPromise: Promise<ChildProcess>;
7
- openedSketchUrl: string;
8
- };
9
- /**
10
- * Opens a tldraw file or URL in a browser.
11
- */
12
- export declare function tldrawOpen(tldrPathOrUrl?: string, options?: Partial<TldrawOpenOptions>): Promise<TldrawOpenResult>;
@@ -1,18 +0,0 @@
1
- export type TldrawFormat = 'png' | 'svg' | 'tldr';
2
- export type TldrawToImageOptions = {
3
- dark?: boolean;
4
- format?: TldrawFormat;
5
- frames?: boolean | string[];
6
- name?: string;
7
- output?: string;
8
- padding?: number;
9
- pages?: boolean | number[] | string[];
10
- print?: boolean;
11
- scale?: number;
12
- stripStyle?: boolean;
13
- transparent?: boolean;
14
- };
15
- /**
16
- * Downloads a tldraw file or URL as an image.
17
- */
18
- export declare function tldrawToImage(tldrPathOrUrl: string, options?: TldrawToImageOptions): Promise<string[]>;
@@ -1,12 +0,0 @@
1
- declare const log: {
2
- verbose: boolean;
3
- log(...data: unknown[]): void;
4
- logPrefixed(prefix: string, ...data: unknown[]): void;
5
- info(...data: unknown[]): void;
6
- infoPrefixed(prefix: string, ...data: unknown[]): void;
7
- warn(...data: unknown[]): void;
8
- warnPrefixed(prefix: string, ...data: unknown[]): void;
9
- error(...data: unknown[]): void;
10
- errorPrefixed(prefix: string, ...data: unknown[]): void;
11
- };
12
- export default log;
@@ -1,8 +0,0 @@
1
- /**
2
- * Validates a path or URL.
3
- */
4
- export declare function validatePathOrUrl(pathOrUrl: string, options?: {
5
- requireFileExistence?: boolean;
6
- validFileExtensions?: string[];
7
- validHostnames?: string[];
8
- }): string | URL;