@kitschpatrol/tldraw-cli 4.5.5 → 4.6.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 +99 -116
- package/dist/lib/index.d.ts +2 -0
- package/dist/lib/index.js +563 -6
- package/dist/lib/tldraw-open.d.ts +10 -0
- package/dist/lib/tldraw-to-share-url.d.ts +1 -0
- package/package.json +3 -3
- package/readme.md +70 -8
package/bin/cli.js
CHANGED
|
@@ -786,7 +786,7 @@ var require_irregular_plurals2 = __commonJS({
|
|
|
786
786
|
});
|
|
787
787
|
|
|
788
788
|
// package.json
|
|
789
|
-
var version = "4.
|
|
789
|
+
var version = "4.6.0";
|
|
790
790
|
|
|
791
791
|
// node_modules/.pnpm/chalk@5.3.0/node_modules/chalk/source/vendor/ansi-styles/index.js
|
|
792
792
|
var ANSI_BACKGROUND_OFFSET = 10;
|
|
@@ -17221,7 +17221,9 @@ var TldrawController = class {
|
|
|
17221
17221
|
log_default.errorPrefixed("Browser", messageText);
|
|
17222
17222
|
}
|
|
17223
17223
|
} else if (messageType === "warn") {
|
|
17224
|
-
|
|
17224
|
+
if (messageText !== "[tldraw] `Store.loadSnapshot` is deprecated and will be removed in a future release. Use `loadSnapshot` from the 'tldraw' package instead.") {
|
|
17225
|
+
log_default.warnPrefixed("Browser", messageText);
|
|
17226
|
+
}
|
|
17225
17227
|
} else {
|
|
17226
17228
|
log_default.infoPrefixed("Browser", messageText);
|
|
17227
17229
|
}
|
|
@@ -17832,6 +17834,7 @@ function nanoid(size = 21) {
|
|
|
17832
17834
|
// src/lib/tldraw-open.ts
|
|
17833
17835
|
import fs8 from "node:fs/promises";
|
|
17834
17836
|
import os5 from "node:os";
|
|
17837
|
+
import { URL as URL2 } from "node:url";
|
|
17835
17838
|
|
|
17836
17839
|
// node_modules/.pnpm/open@10.1.0/node_modules/open/index.js
|
|
17837
17840
|
import process7 from "node:process";
|
|
@@ -18273,79 +18276,64 @@ defineLazyProperty(apps, "browserPrivate", () => "browserPrivate");
|
|
|
18273
18276
|
var open_default = open;
|
|
18274
18277
|
|
|
18275
18278
|
// src/lib/tldraw-open.ts
|
|
18276
|
-
|
|
18279
|
+
var tldrawOpenDefaultOptions = {
|
|
18280
|
+
location: "remote"
|
|
18281
|
+
};
|
|
18282
|
+
async function tldrawOpen(tldrPathOrUrl, options) {
|
|
18277
18283
|
const tldrawRemoteUrl = "https://www.tldraw.com";
|
|
18278
|
-
|
|
18284
|
+
const { location } = { ...tldrawOpenDefaultOptions, ...options };
|
|
18285
|
+
let urlToOpen;
|
|
18286
|
+
const validatedPathOrUrl = tldrPathOrUrl === void 0 ? void 0 : validatePathOrUrl(tldrPathOrUrl, {
|
|
18287
|
+
requireFileExistence: true,
|
|
18288
|
+
validFileExtensions: [".tldr"],
|
|
18289
|
+
validHostnames: ["www.tldraw.com"]
|
|
18290
|
+
});
|
|
18291
|
+
if (location === "local" && validatedPathOrUrl === void 0) {
|
|
18279
18292
|
const tldrawServer = new LocalTldrawServer();
|
|
18280
18293
|
await tldrawServer.start();
|
|
18281
|
-
|
|
18282
|
-
|
|
18283
|
-
|
|
18284
|
-
await
|
|
18285
|
-
|
|
18286
|
-
|
|
18287
|
-
|
|
18288
|
-
|
|
18289
|
-
|
|
18290
|
-
|
|
18291
|
-
|
|
18292
|
-
|
|
18293
|
-
|
|
18294
|
-
if (tldrPathOrUrl !== void 0) {
|
|
18295
|
-
const validatedPathOrUrl = validatePathOrUrl(tldrPathOrUrl, {
|
|
18296
|
-
requireFileExistence: true,
|
|
18297
|
-
validFileExtensions: [".tldr"],
|
|
18298
|
-
validHostnames: ["www.tldraw.com"]
|
|
18294
|
+
urlToOpen = tldrawServer.href;
|
|
18295
|
+
log_default.info(`Opened blank tldraw sketch locally at "${urlToOpen}"`);
|
|
18296
|
+
} else if (location === "local" && typeof validatedPathOrUrl === "string") {
|
|
18297
|
+
const tldrData = await fs8.readFile(validatedPathOrUrl, "utf8");
|
|
18298
|
+
const tldrawServer = new LocalTldrawServer(tldrData);
|
|
18299
|
+
await tldrawServer.start();
|
|
18300
|
+
urlToOpen = tldrawServer.href;
|
|
18301
|
+
log_default.info(`Opened copy of tldraw sketch "${validatedPathOrUrl}" locally at "${urlToOpen}"`);
|
|
18302
|
+
} else if (location === "local" && validatedPathOrUrl instanceof URL2) {
|
|
18303
|
+
const [savedFile] = await tldrawToImage(validatedPathOrUrl.href, {
|
|
18304
|
+
format: "tldr",
|
|
18305
|
+
name: nanoid(),
|
|
18306
|
+
output: os5.tmpdir()
|
|
18299
18307
|
});
|
|
18300
|
-
|
|
18301
|
-
|
|
18302
|
-
|
|
18303
|
-
|
|
18304
|
-
|
|
18305
|
-
|
|
18306
|
-
|
|
18307
|
-
|
|
18308
|
-
|
|
18309
|
-
|
|
18310
|
-
|
|
18311
|
-
|
|
18312
|
-
|
|
18313
|
-
|
|
18314
|
-
|
|
18315
|
-
|
|
18316
|
-
|
|
18317
|
-
|
|
18318
|
-
|
|
18319
|
-
|
|
18320
|
-
|
|
18321
|
-
}
|
|
18322
|
-
if (typeof validatedPathOrUrl !== "string" && local) {
|
|
18323
|
-
const [savedFile] = await tldrawToImage(validatedPathOrUrl.href, {
|
|
18324
|
-
format: "tldr",
|
|
18325
|
-
name: nanoid(),
|
|
18326
|
-
output: os5.tmpdir()
|
|
18327
|
-
});
|
|
18328
|
-
const tldrData = await fs8.readFile(savedFile, "utf8");
|
|
18329
|
-
await fs8.rm(savedFile, { force: true });
|
|
18330
|
-
const tldrawServer = new LocalTldrawServer(tldrData);
|
|
18331
|
-
await tldrawServer.start();
|
|
18332
|
-
log_default.info(
|
|
18333
|
-
`Opened a local copy of tldraw sketch url "${validatedPathOrUrl.href}" locally at ${tldrawServer.href}`
|
|
18334
|
-
);
|
|
18335
|
-
process.stdout.write(`${tldrawServer.href}
|
|
18336
|
-
`);
|
|
18337
|
-
await open_default(tldrawServer.href, { wait: true });
|
|
18338
|
-
return tldrawServer.href;
|
|
18339
|
-
}
|
|
18340
|
-
if (typeof validatedPathOrUrl !== "string" && !local) {
|
|
18341
|
-
await open_default(validatedPathOrUrl.href);
|
|
18342
|
-
log_default.info(`Opened tldraw sketch url at ${validatedPathOrUrl.href}`);
|
|
18343
|
-
process.stdout.write(`${validatedPathOrUrl.href}
|
|
18344
|
-
`);
|
|
18345
|
-
return validatedPathOrUrl.href;
|
|
18346
|
-
}
|
|
18308
|
+
const tldrData = await fs8.readFile(savedFile, "utf8");
|
|
18309
|
+
await fs8.rm(savedFile, { force: true });
|
|
18310
|
+
const tldrawServer = new LocalTldrawServer(tldrData);
|
|
18311
|
+
await tldrawServer.start();
|
|
18312
|
+
urlToOpen = tldrawServer.href;
|
|
18313
|
+
log_default.info(
|
|
18314
|
+
`Opened a local copy of tldraw sketch url "${validatedPathOrUrl.href}" locally at ${urlToOpen}`
|
|
18315
|
+
);
|
|
18316
|
+
} else if (location === "remote" && validatedPathOrUrl === void 0) {
|
|
18317
|
+
urlToOpen = tldrawRemoteUrl;
|
|
18318
|
+
log_default.info(`Opened tldraw.com`);
|
|
18319
|
+
} else if (location === "remote" && typeof validatedPathOrUrl === "string") {
|
|
18320
|
+
urlToOpen = await tldrawToShareUrl(validatedPathOrUrl);
|
|
18321
|
+
log_default.info(
|
|
18322
|
+
`Opened copy of local tldraw sketch "${validatedPathOrUrl}" remotely at "${urlToOpen}"`
|
|
18323
|
+
);
|
|
18324
|
+
} else if (location === "remote" && validatedPathOrUrl instanceof URL2) {
|
|
18325
|
+
urlToOpen = validatedPathOrUrl.href;
|
|
18326
|
+
log_default.info(`Opened tldraw sketch url at ${urlToOpen}`);
|
|
18327
|
+
} else {
|
|
18328
|
+
throw new Error("Invalid tldrawOpen options");
|
|
18347
18329
|
}
|
|
18348
|
-
|
|
18330
|
+
const exitPromise = open_default(urlToOpen, {
|
|
18331
|
+
wait: true
|
|
18332
|
+
});
|
|
18333
|
+
return {
|
|
18334
|
+
browserExitPromise: exitPromise,
|
|
18335
|
+
openedSketchUrl: urlToOpen
|
|
18336
|
+
};
|
|
18349
18337
|
}
|
|
18350
18338
|
|
|
18351
18339
|
// node_modules/.pnpm/plur@5.1.0/node_modules/plur/index.js
|
|
@@ -18463,29 +18451,29 @@ await yargsInstance.scriptName("tldraw").command("$0 <command>", "CLI tools for
|
|
|
18463
18451
|
}
|
|
18464
18452
|
return true;
|
|
18465
18453
|
}),
|
|
18466
|
-
async (
|
|
18467
|
-
|
|
18468
|
-
|
|
18469
|
-
|
|
18470
|
-
|
|
18471
|
-
|
|
18472
|
-
|
|
18473
|
-
|
|
18474
|
-
|
|
18475
|
-
|
|
18476
|
-
|
|
18477
|
-
|
|
18478
|
-
|
|
18479
|
-
|
|
18480
|
-
|
|
18481
|
-
|
|
18454
|
+
async ({
|
|
18455
|
+
dark,
|
|
18456
|
+
filesOrUrls,
|
|
18457
|
+
format,
|
|
18458
|
+
frames,
|
|
18459
|
+
name,
|
|
18460
|
+
output,
|
|
18461
|
+
padding,
|
|
18462
|
+
pages,
|
|
18463
|
+
print,
|
|
18464
|
+
scale,
|
|
18465
|
+
stripStyle,
|
|
18466
|
+
transparent,
|
|
18467
|
+
verbose
|
|
18468
|
+
}) => {
|
|
18469
|
+
const cleanFilesOrUrls = filesOrUrls.filter((fileOrUrl) => fileOrUrl !== void 0);
|
|
18482
18470
|
log_default.verbose = verbose;
|
|
18483
|
-
log_default.info(`Exporting ${
|
|
18471
|
+
log_default.info(`Exporting ${cleanFilesOrUrls.length} ${plur("sketch", cleanFilesOrUrls.length)}...`);
|
|
18484
18472
|
let nameIndex = 0;
|
|
18485
18473
|
const errorReport = [];
|
|
18486
|
-
for (const fileOrUrl of
|
|
18474
|
+
for (const fileOrUrl of cleanFilesOrUrls) {
|
|
18487
18475
|
try {
|
|
18488
|
-
const resolvedName =
|
|
18476
|
+
const resolvedName = cleanFilesOrUrls.length > 1 && name !== void 0 ? `${name}-${nameIndex++}` : name;
|
|
18489
18477
|
const exportList = await tldrawToImage(fileOrUrl, {
|
|
18490
18478
|
dark,
|
|
18491
18479
|
format,
|
|
@@ -18508,26 +18496,28 @@ await yargsInstance.scriptName("tldraw").command("$0 <command>", "CLI tools for
|
|
|
18508
18496
|
);
|
|
18509
18497
|
}
|
|
18510
18498
|
}
|
|
18511
|
-
const successCount =
|
|
18499
|
+
const successCount = cleanFilesOrUrls.length - errorReport.length;
|
|
18512
18500
|
if (errorReport.length > 0) {
|
|
18513
18501
|
log_default.error(
|
|
18514
|
-
`${successCount} of ${
|
|
18502
|
+
`${successCount} of ${cleanFilesOrUrls.length} ${plur("sketch", cleanFilesOrUrls.length)} exported successfully`
|
|
18515
18503
|
);
|
|
18516
18504
|
log_default.error(errorReport.join("\n"));
|
|
18517
18505
|
process.exit(1);
|
|
18518
18506
|
}
|
|
18519
18507
|
if (successCount === 0) {
|
|
18520
18508
|
log_default.error(
|
|
18521
|
-
`${successCount} of ${
|
|
18509
|
+
`${successCount} of ${cleanFilesOrUrls.length} ${plur("sketch", cleanFilesOrUrls.length)} exported successfully`
|
|
18522
18510
|
);
|
|
18523
18511
|
} else {
|
|
18524
|
-
log_default.info(
|
|
18512
|
+
log_default.info(
|
|
18513
|
+
`All ${successCount} ${plur("sketch", cleanFilesOrUrls.length)} exported successfully`
|
|
18514
|
+
);
|
|
18525
18515
|
}
|
|
18526
18516
|
process.exit(0);
|
|
18527
18517
|
}
|
|
18528
18518
|
).command(
|
|
18529
18519
|
"open [files-or-urls..]",
|
|
18530
|
-
"Open a tldraw `.tldr` file or tldraw.com URL in your default browser with either the official tldraw.com site or a locally-hosted instance of the editor. Call `open` without an argument to open a blank sketch. Sketches opened via URL with the `--local` flag will be temporarily copied to the local system, and will not be kept in sync with tldraw.com. This process does not exit until the browser is closed.",
|
|
18520
|
+
"Open a tldraw `.tldr` file or tldraw.com URL in your default browser with either the official tldraw.com site or a locally-hosted instance of the editor. Call `open` without an argument to open a blank sketch. Sketches opened via URL with the `--local` flag will be temporarily copied to the local system, and will not be kept in sync with tldraw.com. This process does not exit until the browser is closed. Warning: Passing a local .tldr file without the `--local` option will upload and share the sketch on tldraw.com.",
|
|
18531
18521
|
(yargs2) => yargs2.positional("files-or-urls", {
|
|
18532
18522
|
array: true,
|
|
18533
18523
|
default: void 0,
|
|
@@ -18543,37 +18533,30 @@ await yargsInstance.scriptName("tldraw").command("$0 <command>", "CLI tools for
|
|
|
18543
18533
|
describe: "Enable verbose logging. All verbose logs and prefixed with their log level and are printed to `stderr` for ease of redirection.",
|
|
18544
18534
|
type: "boolean"
|
|
18545
18535
|
}),
|
|
18546
|
-
async (
|
|
18547
|
-
const
|
|
18548
|
-
const { local
|
|
18536
|
+
async ({ filesOrUrls, local, verbose }) => {
|
|
18537
|
+
const cleanFilesOrUrls = filesOrUrls === void 0 ? [void 0] : filesOrUrls.length > 1 ? filesOrUrls.filter((fileOrUrl) => fileOrUrl !== void 0) : filesOrUrls;
|
|
18538
|
+
const tlDrawOpenOptions = { location: local ? "local" : "remote" };
|
|
18549
18539
|
log_default.verbose = verbose;
|
|
18550
|
-
const resultPromises = [];
|
|
18551
18540
|
let errorCount = 0;
|
|
18552
|
-
|
|
18541
|
+
const browserExitPromises = [];
|
|
18542
|
+
for (const fileOrUrl of cleanFilesOrUrls) {
|
|
18543
|
+
console.log("opening----------------------------------");
|
|
18544
|
+
console.log(fileOrUrl);
|
|
18553
18545
|
try {
|
|
18554
|
-
|
|
18546
|
+
const openResult = await tldrawOpen(fileOrUrl, tlDrawOpenOptions);
|
|
18547
|
+
process.stdout.write(`${openResult.openedSketchUrl}
|
|
18548
|
+
`);
|
|
18549
|
+
browserExitPromises.push(openResult.browserExitPromise);
|
|
18555
18550
|
} catch (error) {
|
|
18556
18551
|
errorCount++;
|
|
18557
|
-
log_default.error(
|
|
18558
|
-
|
|
18559
|
-
|
|
18560
|
-
for (const fileOrUrl of filesOrUrls) {
|
|
18561
|
-
if (fileOrUrl === void 0 || fileOrUrl === null) continue;
|
|
18562
|
-
try {
|
|
18563
|
-
resultPromises.push(tldrawOpen(fileOrUrl, local));
|
|
18564
|
-
} catch (error) {
|
|
18565
|
-
errorCount++;
|
|
18566
|
-
log_default.error(
|
|
18567
|
-
`Failed to open "${fileOrUrl}": ${error instanceof Error ? error.message : "Unknown Error"}`
|
|
18568
|
-
);
|
|
18569
|
-
}
|
|
18552
|
+
log_default.error(
|
|
18553
|
+
`Failed to open "${fileOrUrl}": ${error instanceof Error ? error.message : "Unknown Error"}`
|
|
18554
|
+
);
|
|
18570
18555
|
}
|
|
18571
18556
|
}
|
|
18572
18557
|
if (local) {
|
|
18573
18558
|
log_default.info(source_default.yellow(`Note: This process will exit once the browser is closed.`));
|
|
18574
|
-
|
|
18575
|
-
await Promise.all(resultPromises);
|
|
18576
|
-
if (local) {
|
|
18559
|
+
await Promise.allSettled(browserExitPromises);
|
|
18577
18560
|
log_default.info(`Closing local tldraw ${plur("server", filesOrUrls ? filesOrUrls.length : 1)}`);
|
|
18578
18561
|
}
|
|
18579
18562
|
if (errorCount === 0) {
|
package/dist/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,4 @@
|
|
|
1
|
+
export { type TldrawOpenOptions, type TldrawOpenResult, tldrawOpen } from './tldraw-open';
|
|
1
2
|
export { type TldrawFormat, type TldrawToImageOptions, tldrawToImage } from './tldraw-to-image';
|
|
3
|
+
export { tldrawToShareUrl } from './tldraw-to-share-url';
|
|
2
4
|
export { default as log } from './utilities/log';
|
package/dist/lib/index.js
CHANGED
|
@@ -1031,18 +1031,18 @@ var proto = Object.defineProperties(() => {
|
|
|
1031
1031
|
}
|
|
1032
1032
|
}
|
|
1033
1033
|
});
|
|
1034
|
-
var createStyler = (
|
|
1034
|
+
var createStyler = (open2, close, parent2) => {
|
|
1035
1035
|
let openAll;
|
|
1036
1036
|
let closeAll;
|
|
1037
1037
|
if (parent2 === void 0) {
|
|
1038
|
-
openAll =
|
|
1038
|
+
openAll = open2;
|
|
1039
1039
|
closeAll = close;
|
|
1040
1040
|
} else {
|
|
1041
|
-
openAll = parent2.openAll +
|
|
1041
|
+
openAll = parent2.openAll + open2;
|
|
1042
1042
|
closeAll = close + parent2.closeAll;
|
|
1043
1043
|
}
|
|
1044
1044
|
return {
|
|
1045
|
-
open,
|
|
1045
|
+
open: open2,
|
|
1046
1046
|
close,
|
|
1047
1047
|
openAll,
|
|
1048
1048
|
closeAll,
|
|
@@ -17027,7 +17027,9 @@ var TldrawController = class {
|
|
|
17027
17027
|
log_default.errorPrefixed("Browser", messageText);
|
|
17028
17028
|
}
|
|
17029
17029
|
} else if (messageType === "warn") {
|
|
17030
|
-
|
|
17030
|
+
if (messageText !== "[tldraw] `Store.loadSnapshot` is deprecated and will be removed in a future release. Use `loadSnapshot` from the 'tldraw' package instead.") {
|
|
17031
|
+
log_default.warnPrefixed("Browser", messageText);
|
|
17032
|
+
}
|
|
17031
17033
|
} else {
|
|
17032
17034
|
log_default.infoPrefixed("Browser", messageText);
|
|
17033
17035
|
}
|
|
@@ -17586,7 +17588,562 @@ function sanitizeName(name, format) {
|
|
|
17586
17588
|
}
|
|
17587
17589
|
return path4.basename(name);
|
|
17588
17590
|
}
|
|
17591
|
+
|
|
17592
|
+
// src/lib/tldraw-to-share-url.ts
|
|
17593
|
+
async function tldrawToShareUrl(tldrPathOrUrl) {
|
|
17594
|
+
const validatedPathOrUrl = validatePathOrUrl(tldrPathOrUrl, {
|
|
17595
|
+
requireFileExistence: true,
|
|
17596
|
+
validFileExtensions: [".tldr"],
|
|
17597
|
+
validHostnames: ["www.tldraw.com"]
|
|
17598
|
+
});
|
|
17599
|
+
if (typeof validatedPathOrUrl === "string") {
|
|
17600
|
+
const tldrawController = new TldrawController("https://www.tldraw.com");
|
|
17601
|
+
await tldrawController.start();
|
|
17602
|
+
await tldrawController.loadFile(validatedPathOrUrl);
|
|
17603
|
+
const shareUrl = await tldrawController.getShareUrl();
|
|
17604
|
+
await tldrawController.close();
|
|
17605
|
+
return shareUrl;
|
|
17606
|
+
}
|
|
17607
|
+
return validatedPathOrUrl.href;
|
|
17608
|
+
}
|
|
17609
|
+
|
|
17610
|
+
// node_modules/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.js
|
|
17611
|
+
import { webcrypto as crypto } from "node:crypto";
|
|
17612
|
+
|
|
17613
|
+
// node_modules/.pnpm/nanoid@5.0.7/node_modules/nanoid/url-alphabet/index.js
|
|
17614
|
+
var urlAlphabet = "useandom-26T198340PX75pxJACKVERYMINDBUSHWOLF_GQZbfghjklqvwyzrict";
|
|
17615
|
+
|
|
17616
|
+
// node_modules/.pnpm/nanoid@5.0.7/node_modules/nanoid/index.js
|
|
17617
|
+
var POOL_SIZE_MULTIPLIER = 128;
|
|
17618
|
+
var pool;
|
|
17619
|
+
var poolOffset;
|
|
17620
|
+
function fillPool(bytes) {
|
|
17621
|
+
if (!pool || pool.length < bytes) {
|
|
17622
|
+
pool = Buffer.allocUnsafe(bytes * POOL_SIZE_MULTIPLIER);
|
|
17623
|
+
crypto.getRandomValues(pool);
|
|
17624
|
+
poolOffset = 0;
|
|
17625
|
+
} else if (poolOffset + bytes > pool.length) {
|
|
17626
|
+
crypto.getRandomValues(pool);
|
|
17627
|
+
poolOffset = 0;
|
|
17628
|
+
}
|
|
17629
|
+
poolOffset += bytes;
|
|
17630
|
+
}
|
|
17631
|
+
function nanoid(size = 21) {
|
|
17632
|
+
fillPool(size -= 0);
|
|
17633
|
+
let id = "";
|
|
17634
|
+
for (let i = poolOffset - size; i < poolOffset; i++) {
|
|
17635
|
+
id += urlAlphabet[pool[i] & 63];
|
|
17636
|
+
}
|
|
17637
|
+
return id;
|
|
17638
|
+
}
|
|
17639
|
+
|
|
17640
|
+
// src/lib/tldraw-open.ts
|
|
17641
|
+
import fs8 from "node:fs/promises";
|
|
17642
|
+
import os5 from "node:os";
|
|
17643
|
+
import { URL as URL2 } from "node:url";
|
|
17644
|
+
|
|
17645
|
+
// node_modules/.pnpm/open@10.1.0/node_modules/open/index.js
|
|
17646
|
+
import process7 from "node:process";
|
|
17647
|
+
import { Buffer as Buffer2 } from "node:buffer";
|
|
17648
|
+
import path5 from "node:path";
|
|
17649
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
17650
|
+
import childProcess from "node:child_process";
|
|
17651
|
+
import fs7, { constants as fsConstants } from "node:fs/promises";
|
|
17652
|
+
|
|
17653
|
+
// node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
|
|
17654
|
+
import process3 from "node:process";
|
|
17655
|
+
import os4 from "node:os";
|
|
17656
|
+
import fs6 from "node:fs";
|
|
17657
|
+
|
|
17658
|
+
// node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
|
|
17659
|
+
import fs5 from "node:fs";
|
|
17660
|
+
|
|
17661
|
+
// node_modules/.pnpm/is-docker@3.0.0/node_modules/is-docker/index.js
|
|
17662
|
+
import fs4 from "node:fs";
|
|
17663
|
+
var isDockerCached;
|
|
17664
|
+
function hasDockerEnv() {
|
|
17665
|
+
try {
|
|
17666
|
+
fs4.statSync("/.dockerenv");
|
|
17667
|
+
return true;
|
|
17668
|
+
} catch {
|
|
17669
|
+
return false;
|
|
17670
|
+
}
|
|
17671
|
+
}
|
|
17672
|
+
function hasDockerCGroup() {
|
|
17673
|
+
try {
|
|
17674
|
+
return fs4.readFileSync("/proc/self/cgroup", "utf8").includes("docker");
|
|
17675
|
+
} catch {
|
|
17676
|
+
return false;
|
|
17677
|
+
}
|
|
17678
|
+
}
|
|
17679
|
+
function isDocker() {
|
|
17680
|
+
if (isDockerCached === void 0) {
|
|
17681
|
+
isDockerCached = hasDockerEnv() || hasDockerCGroup();
|
|
17682
|
+
}
|
|
17683
|
+
return isDockerCached;
|
|
17684
|
+
}
|
|
17685
|
+
|
|
17686
|
+
// node_modules/.pnpm/is-inside-container@1.0.0/node_modules/is-inside-container/index.js
|
|
17687
|
+
var cachedResult;
|
|
17688
|
+
var hasContainerEnv = () => {
|
|
17689
|
+
try {
|
|
17690
|
+
fs5.statSync("/run/.containerenv");
|
|
17691
|
+
return true;
|
|
17692
|
+
} catch {
|
|
17693
|
+
return false;
|
|
17694
|
+
}
|
|
17695
|
+
};
|
|
17696
|
+
function isInsideContainer() {
|
|
17697
|
+
if (cachedResult === void 0) {
|
|
17698
|
+
cachedResult = hasContainerEnv() || isDocker();
|
|
17699
|
+
}
|
|
17700
|
+
return cachedResult;
|
|
17701
|
+
}
|
|
17702
|
+
|
|
17703
|
+
// node_modules/.pnpm/is-wsl@3.1.0/node_modules/is-wsl/index.js
|
|
17704
|
+
var isWsl = () => {
|
|
17705
|
+
if (process3.platform !== "linux") {
|
|
17706
|
+
return false;
|
|
17707
|
+
}
|
|
17708
|
+
if (os4.release().toLowerCase().includes("microsoft")) {
|
|
17709
|
+
if (isInsideContainer()) {
|
|
17710
|
+
return false;
|
|
17711
|
+
}
|
|
17712
|
+
return true;
|
|
17713
|
+
}
|
|
17714
|
+
try {
|
|
17715
|
+
return fs6.readFileSync("/proc/version", "utf8").toLowerCase().includes("microsoft") ? !isInsideContainer() : false;
|
|
17716
|
+
} catch {
|
|
17717
|
+
return false;
|
|
17718
|
+
}
|
|
17719
|
+
};
|
|
17720
|
+
var is_wsl_default = process3.env.__IS_WSL_TEST__ ? isWsl : isWsl();
|
|
17721
|
+
|
|
17722
|
+
// node_modules/.pnpm/define-lazy-prop@3.0.0/node_modules/define-lazy-prop/index.js
|
|
17723
|
+
function defineLazyProperty(object, propertyName, valueGetter) {
|
|
17724
|
+
const define = (value) => Object.defineProperty(object, propertyName, { value, enumerable: true, writable: true });
|
|
17725
|
+
Object.defineProperty(object, propertyName, {
|
|
17726
|
+
configurable: true,
|
|
17727
|
+
enumerable: true,
|
|
17728
|
+
get() {
|
|
17729
|
+
const result = valueGetter();
|
|
17730
|
+
define(result);
|
|
17731
|
+
return result;
|
|
17732
|
+
},
|
|
17733
|
+
set(value) {
|
|
17734
|
+
define(value);
|
|
17735
|
+
}
|
|
17736
|
+
});
|
|
17737
|
+
return object;
|
|
17738
|
+
}
|
|
17739
|
+
|
|
17740
|
+
// node_modules/.pnpm/default-browser@5.2.1/node_modules/default-browser/index.js
|
|
17741
|
+
import { promisify as promisify4 } from "node:util";
|
|
17742
|
+
import process6 from "node:process";
|
|
17743
|
+
import { execFile as execFile4 } from "node:child_process";
|
|
17744
|
+
|
|
17745
|
+
// node_modules/.pnpm/default-browser-id@5.0.0/node_modules/default-browser-id/index.js
|
|
17746
|
+
import { promisify } from "node:util";
|
|
17747
|
+
import process4 from "node:process";
|
|
17748
|
+
import { execFile } from "node:child_process";
|
|
17749
|
+
var execFileAsync = promisify(execFile);
|
|
17750
|
+
async function defaultBrowserId() {
|
|
17751
|
+
if (process4.platform !== "darwin") {
|
|
17752
|
+
throw new Error("macOS only");
|
|
17753
|
+
}
|
|
17754
|
+
const { stdout } = await execFileAsync("defaults", ["read", "com.apple.LaunchServices/com.apple.launchservices.secure", "LSHandlers"]);
|
|
17755
|
+
const match = /LSHandlerRoleAll = "(?!-)(?<id>[^"]+?)";\s+?LSHandlerURLScheme = (?:http|https);/.exec(stdout);
|
|
17756
|
+
return match?.groups.id ?? "com.apple.Safari";
|
|
17757
|
+
}
|
|
17758
|
+
|
|
17759
|
+
// node_modules/.pnpm/run-applescript@7.0.0/node_modules/run-applescript/index.js
|
|
17760
|
+
import process5 from "node:process";
|
|
17761
|
+
import { promisify as promisify2 } from "node:util";
|
|
17762
|
+
import { execFile as execFile2, execFileSync } from "node:child_process";
|
|
17763
|
+
var execFileAsync2 = promisify2(execFile2);
|
|
17764
|
+
async function runAppleScript(script, { humanReadableOutput = true } = {}) {
|
|
17765
|
+
if (process5.platform !== "darwin") {
|
|
17766
|
+
throw new Error("macOS only");
|
|
17767
|
+
}
|
|
17768
|
+
const outputArguments = humanReadableOutput ? [] : ["-ss"];
|
|
17769
|
+
const { stdout } = await execFileAsync2("osascript", ["-e", script, outputArguments]);
|
|
17770
|
+
return stdout.trim();
|
|
17771
|
+
}
|
|
17772
|
+
|
|
17773
|
+
// node_modules/.pnpm/bundle-name@4.1.0/node_modules/bundle-name/index.js
|
|
17774
|
+
async function bundleName(bundleId) {
|
|
17775
|
+
return runAppleScript(`tell application "Finder" to set app_path to application file id "${bundleId}" as string
|
|
17776
|
+
tell application "System Events" to get value of property list item "CFBundleName" of property list file (app_path & ":Contents:Info.plist")`);
|
|
17777
|
+
}
|
|
17778
|
+
|
|
17779
|
+
// node_modules/.pnpm/default-browser@5.2.1/node_modules/default-browser/windows.js
|
|
17780
|
+
import { promisify as promisify3 } from "node:util";
|
|
17781
|
+
import { execFile as execFile3 } from "node:child_process";
|
|
17782
|
+
var execFileAsync3 = promisify3(execFile3);
|
|
17783
|
+
var windowsBrowserProgIds = {
|
|
17784
|
+
AppXq0fevzme2pys62n3e0fbqa7peapykr8v: { name: "Edge", id: "com.microsoft.edge.old" },
|
|
17785
|
+
MSEdgeDHTML: { name: "Edge", id: "com.microsoft.edge" },
|
|
17786
|
+
// On macOS, it's "com.microsoft.edgemac"
|
|
17787
|
+
MSEdgeHTM: { name: "Edge", id: "com.microsoft.edge" },
|
|
17788
|
+
// Newer Edge/Win10 releases
|
|
17789
|
+
"IE.HTTP": { name: "Internet Explorer", id: "com.microsoft.ie" },
|
|
17790
|
+
FirefoxURL: { name: "Firefox", id: "org.mozilla.firefox" },
|
|
17791
|
+
ChromeHTML: { name: "Chrome", id: "com.google.chrome" },
|
|
17792
|
+
BraveHTML: { name: "Brave", id: "com.brave.Browser" },
|
|
17793
|
+
BraveBHTML: { name: "Brave Beta", id: "com.brave.Browser.beta" },
|
|
17794
|
+
BraveSSHTM: { name: "Brave Nightly", id: "com.brave.Browser.nightly" }
|
|
17795
|
+
};
|
|
17796
|
+
var UnknownBrowserError = class extends Error {
|
|
17797
|
+
};
|
|
17798
|
+
async function defaultBrowser(_execFileAsync = execFileAsync3) {
|
|
17799
|
+
const { stdout } = await _execFileAsync("reg", [
|
|
17800
|
+
"QUERY",
|
|
17801
|
+
" HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice",
|
|
17802
|
+
"/v",
|
|
17803
|
+
"ProgId"
|
|
17804
|
+
]);
|
|
17805
|
+
const match = /ProgId\s*REG_SZ\s*(?<id>\S+)/.exec(stdout);
|
|
17806
|
+
if (!match) {
|
|
17807
|
+
throw new UnknownBrowserError(`Cannot find Windows browser in stdout: ${JSON.stringify(stdout)}`);
|
|
17808
|
+
}
|
|
17809
|
+
const { id } = match.groups;
|
|
17810
|
+
const browser = windowsBrowserProgIds[id];
|
|
17811
|
+
if (!browser) {
|
|
17812
|
+
throw new UnknownBrowserError(`Unknown browser ID: ${id}`);
|
|
17813
|
+
}
|
|
17814
|
+
return browser;
|
|
17815
|
+
}
|
|
17816
|
+
|
|
17817
|
+
// node_modules/.pnpm/default-browser@5.2.1/node_modules/default-browser/index.js
|
|
17818
|
+
var execFileAsync4 = promisify4(execFile4);
|
|
17819
|
+
var titleize = (string) => string.toLowerCase().replaceAll(/(?:^|\s|-)\S/g, (x) => x.toUpperCase());
|
|
17820
|
+
async function defaultBrowser2() {
|
|
17821
|
+
if (process6.platform === "darwin") {
|
|
17822
|
+
const id = await defaultBrowserId();
|
|
17823
|
+
const name = await bundleName(id);
|
|
17824
|
+
return { name, id };
|
|
17825
|
+
}
|
|
17826
|
+
if (process6.platform === "linux") {
|
|
17827
|
+
const { stdout } = await execFileAsync4("xdg-mime", ["query", "default", "x-scheme-handler/http"]);
|
|
17828
|
+
const id = stdout.trim();
|
|
17829
|
+
const name = titleize(id.replace(/.desktop$/, "").replace("-", " "));
|
|
17830
|
+
return { name, id };
|
|
17831
|
+
}
|
|
17832
|
+
if (process6.platform === "win32") {
|
|
17833
|
+
return defaultBrowser();
|
|
17834
|
+
}
|
|
17835
|
+
throw new Error("Only macOS, Linux, and Windows are supported");
|
|
17836
|
+
}
|
|
17837
|
+
|
|
17838
|
+
// node_modules/.pnpm/open@10.1.0/node_modules/open/index.js
|
|
17839
|
+
var __dirname = path5.dirname(fileURLToPath3(import.meta.url));
|
|
17840
|
+
var localXdgOpenPath = path5.join(__dirname, "xdg-open");
|
|
17841
|
+
var { platform, arch } = process7;
|
|
17842
|
+
var getWslDrivesMountPoint = /* @__PURE__ */ (() => {
|
|
17843
|
+
const defaultMountPoint = "/mnt/";
|
|
17844
|
+
let mountPoint;
|
|
17845
|
+
return async function() {
|
|
17846
|
+
if (mountPoint) {
|
|
17847
|
+
return mountPoint;
|
|
17848
|
+
}
|
|
17849
|
+
const configFilePath = "/etc/wsl.conf";
|
|
17850
|
+
let isConfigFileExists = false;
|
|
17851
|
+
try {
|
|
17852
|
+
await fs7.access(configFilePath, fsConstants.F_OK);
|
|
17853
|
+
isConfigFileExists = true;
|
|
17854
|
+
} catch {
|
|
17855
|
+
}
|
|
17856
|
+
if (!isConfigFileExists) {
|
|
17857
|
+
return defaultMountPoint;
|
|
17858
|
+
}
|
|
17859
|
+
const configContent = await fs7.readFile(configFilePath, { encoding: "utf8" });
|
|
17860
|
+
const configMountPoint = /(?<!#.*)root\s*=\s*(?<mountPoint>.*)/g.exec(configContent);
|
|
17861
|
+
if (!configMountPoint) {
|
|
17862
|
+
return defaultMountPoint;
|
|
17863
|
+
}
|
|
17864
|
+
mountPoint = configMountPoint.groups.mountPoint.trim();
|
|
17865
|
+
mountPoint = mountPoint.endsWith("/") ? mountPoint : `${mountPoint}/`;
|
|
17866
|
+
return mountPoint;
|
|
17867
|
+
};
|
|
17868
|
+
})();
|
|
17869
|
+
var pTryEach = async (array, mapper) => {
|
|
17870
|
+
let latestError;
|
|
17871
|
+
for (const item of array) {
|
|
17872
|
+
try {
|
|
17873
|
+
return await mapper(item);
|
|
17874
|
+
} catch (error) {
|
|
17875
|
+
latestError = error;
|
|
17876
|
+
}
|
|
17877
|
+
}
|
|
17878
|
+
throw latestError;
|
|
17879
|
+
};
|
|
17880
|
+
var baseOpen = async (options) => {
|
|
17881
|
+
options = {
|
|
17882
|
+
wait: false,
|
|
17883
|
+
background: false,
|
|
17884
|
+
newInstance: false,
|
|
17885
|
+
allowNonzeroExitCode: false,
|
|
17886
|
+
...options
|
|
17887
|
+
};
|
|
17888
|
+
if (Array.isArray(options.app)) {
|
|
17889
|
+
return pTryEach(options.app, (singleApp) => baseOpen({
|
|
17890
|
+
...options,
|
|
17891
|
+
app: singleApp
|
|
17892
|
+
}));
|
|
17893
|
+
}
|
|
17894
|
+
let { name: app, arguments: appArguments = [] } = options.app ?? {};
|
|
17895
|
+
appArguments = [...appArguments];
|
|
17896
|
+
if (Array.isArray(app)) {
|
|
17897
|
+
return pTryEach(app, (appName) => baseOpen({
|
|
17898
|
+
...options,
|
|
17899
|
+
app: {
|
|
17900
|
+
name: appName,
|
|
17901
|
+
arguments: appArguments
|
|
17902
|
+
}
|
|
17903
|
+
}));
|
|
17904
|
+
}
|
|
17905
|
+
if (app === "browser" || app === "browserPrivate") {
|
|
17906
|
+
const ids = {
|
|
17907
|
+
"com.google.chrome": "chrome",
|
|
17908
|
+
"google-chrome.desktop": "chrome",
|
|
17909
|
+
"org.mozilla.firefox": "firefox",
|
|
17910
|
+
"firefox.desktop": "firefox",
|
|
17911
|
+
"com.microsoft.msedge": "edge",
|
|
17912
|
+
"com.microsoft.edge": "edge",
|
|
17913
|
+
"microsoft-edge.desktop": "edge"
|
|
17914
|
+
};
|
|
17915
|
+
const flags = {
|
|
17916
|
+
chrome: "--incognito",
|
|
17917
|
+
firefox: "--private-window",
|
|
17918
|
+
edge: "--inPrivate"
|
|
17919
|
+
};
|
|
17920
|
+
const browser = await defaultBrowser2();
|
|
17921
|
+
if (browser.id in ids) {
|
|
17922
|
+
const browserName = ids[browser.id];
|
|
17923
|
+
if (app === "browserPrivate") {
|
|
17924
|
+
appArguments.push(flags[browserName]);
|
|
17925
|
+
}
|
|
17926
|
+
return baseOpen({
|
|
17927
|
+
...options,
|
|
17928
|
+
app: {
|
|
17929
|
+
name: apps[browserName],
|
|
17930
|
+
arguments: appArguments
|
|
17931
|
+
}
|
|
17932
|
+
});
|
|
17933
|
+
}
|
|
17934
|
+
throw new Error(`${browser.name} is not supported as a default browser`);
|
|
17935
|
+
}
|
|
17936
|
+
let command;
|
|
17937
|
+
const cliArguments = [];
|
|
17938
|
+
const childProcessOptions = {};
|
|
17939
|
+
if (platform === "darwin") {
|
|
17940
|
+
command = "open";
|
|
17941
|
+
if (options.wait) {
|
|
17942
|
+
cliArguments.push("--wait-apps");
|
|
17943
|
+
}
|
|
17944
|
+
if (options.background) {
|
|
17945
|
+
cliArguments.push("--background");
|
|
17946
|
+
}
|
|
17947
|
+
if (options.newInstance) {
|
|
17948
|
+
cliArguments.push("--new");
|
|
17949
|
+
}
|
|
17950
|
+
if (app) {
|
|
17951
|
+
cliArguments.push("-a", app);
|
|
17952
|
+
}
|
|
17953
|
+
} else if (platform === "win32" || is_wsl_default && !isInsideContainer() && !app) {
|
|
17954
|
+
const mountPoint = await getWslDrivesMountPoint();
|
|
17955
|
+
command = is_wsl_default ? `${mountPoint}c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe` : `${process7.env.SYSTEMROOT || process7.env.windir || "C:\\Windows"}\\System32\\WindowsPowerShell\\v1.0\\powershell`;
|
|
17956
|
+
cliArguments.push(
|
|
17957
|
+
"-NoProfile",
|
|
17958
|
+
"-NonInteractive",
|
|
17959
|
+
"-ExecutionPolicy",
|
|
17960
|
+
"Bypass",
|
|
17961
|
+
"-EncodedCommand"
|
|
17962
|
+
);
|
|
17963
|
+
if (!is_wsl_default) {
|
|
17964
|
+
childProcessOptions.windowsVerbatimArguments = true;
|
|
17965
|
+
}
|
|
17966
|
+
const encodedArguments = ["Start"];
|
|
17967
|
+
if (options.wait) {
|
|
17968
|
+
encodedArguments.push("-Wait");
|
|
17969
|
+
}
|
|
17970
|
+
if (app) {
|
|
17971
|
+
encodedArguments.push(`"\`"${app}\`""`);
|
|
17972
|
+
if (options.target) {
|
|
17973
|
+
appArguments.push(options.target);
|
|
17974
|
+
}
|
|
17975
|
+
} else if (options.target) {
|
|
17976
|
+
encodedArguments.push(`"${options.target}"`);
|
|
17977
|
+
}
|
|
17978
|
+
if (appArguments.length > 0) {
|
|
17979
|
+
appArguments = appArguments.map((argument) => `"\`"${argument}\`""`);
|
|
17980
|
+
encodedArguments.push("-ArgumentList", appArguments.join(","));
|
|
17981
|
+
}
|
|
17982
|
+
options.target = Buffer2.from(encodedArguments.join(" "), "utf16le").toString("base64");
|
|
17983
|
+
} else {
|
|
17984
|
+
if (app) {
|
|
17985
|
+
command = app;
|
|
17986
|
+
} else {
|
|
17987
|
+
const isBundled = !__dirname || __dirname === "/";
|
|
17988
|
+
let exeLocalXdgOpen = false;
|
|
17989
|
+
try {
|
|
17990
|
+
await fs7.access(localXdgOpenPath, fsConstants.X_OK);
|
|
17991
|
+
exeLocalXdgOpen = true;
|
|
17992
|
+
} catch {
|
|
17993
|
+
}
|
|
17994
|
+
const useSystemXdgOpen = process7.versions.electron ?? (platform === "android" || isBundled || !exeLocalXdgOpen);
|
|
17995
|
+
command = useSystemXdgOpen ? "xdg-open" : localXdgOpenPath;
|
|
17996
|
+
}
|
|
17997
|
+
if (appArguments.length > 0) {
|
|
17998
|
+
cliArguments.push(...appArguments);
|
|
17999
|
+
}
|
|
18000
|
+
if (!options.wait) {
|
|
18001
|
+
childProcessOptions.stdio = "ignore";
|
|
18002
|
+
childProcessOptions.detached = true;
|
|
18003
|
+
}
|
|
18004
|
+
}
|
|
18005
|
+
if (platform === "darwin" && appArguments.length > 0) {
|
|
18006
|
+
cliArguments.push("--args", ...appArguments);
|
|
18007
|
+
}
|
|
18008
|
+
if (options.target) {
|
|
18009
|
+
cliArguments.push(options.target);
|
|
18010
|
+
}
|
|
18011
|
+
const subprocess = childProcess.spawn(command, cliArguments, childProcessOptions);
|
|
18012
|
+
if (options.wait) {
|
|
18013
|
+
return new Promise((resolve, reject) => {
|
|
18014
|
+
subprocess.once("error", reject);
|
|
18015
|
+
subprocess.once("close", (exitCode) => {
|
|
18016
|
+
if (!options.allowNonzeroExitCode && exitCode > 0) {
|
|
18017
|
+
reject(new Error(`Exited with code ${exitCode}`));
|
|
18018
|
+
return;
|
|
18019
|
+
}
|
|
18020
|
+
resolve(subprocess);
|
|
18021
|
+
});
|
|
18022
|
+
});
|
|
18023
|
+
}
|
|
18024
|
+
subprocess.unref();
|
|
18025
|
+
return subprocess;
|
|
18026
|
+
};
|
|
18027
|
+
var open = (target, options) => {
|
|
18028
|
+
if (typeof target !== "string") {
|
|
18029
|
+
throw new TypeError("Expected a `target`");
|
|
18030
|
+
}
|
|
18031
|
+
return baseOpen({
|
|
18032
|
+
...options,
|
|
18033
|
+
target
|
|
18034
|
+
});
|
|
18035
|
+
};
|
|
18036
|
+
function detectArchBinary(binary) {
|
|
18037
|
+
if (typeof binary === "string" || Array.isArray(binary)) {
|
|
18038
|
+
return binary;
|
|
18039
|
+
}
|
|
18040
|
+
const { [arch]: archBinary } = binary;
|
|
18041
|
+
if (!archBinary) {
|
|
18042
|
+
throw new Error(`${arch} is not supported`);
|
|
18043
|
+
}
|
|
18044
|
+
return archBinary;
|
|
18045
|
+
}
|
|
18046
|
+
function detectPlatformBinary({ [platform]: platformBinary }, { wsl }) {
|
|
18047
|
+
if (wsl && is_wsl_default) {
|
|
18048
|
+
return detectArchBinary(wsl);
|
|
18049
|
+
}
|
|
18050
|
+
if (!platformBinary) {
|
|
18051
|
+
throw new Error(`${platform} is not supported`);
|
|
18052
|
+
}
|
|
18053
|
+
return detectArchBinary(platformBinary);
|
|
18054
|
+
}
|
|
18055
|
+
var apps = {};
|
|
18056
|
+
defineLazyProperty(apps, "chrome", () => detectPlatformBinary({
|
|
18057
|
+
darwin: "google chrome",
|
|
18058
|
+
win32: "chrome",
|
|
18059
|
+
linux: ["google-chrome", "google-chrome-stable", "chromium"]
|
|
18060
|
+
}, {
|
|
18061
|
+
wsl: {
|
|
18062
|
+
ia32: "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe",
|
|
18063
|
+
x64: ["/mnt/c/Program Files/Google/Chrome/Application/chrome.exe", "/mnt/c/Program Files (x86)/Google/Chrome/Application/chrome.exe"]
|
|
18064
|
+
}
|
|
18065
|
+
}));
|
|
18066
|
+
defineLazyProperty(apps, "firefox", () => detectPlatformBinary({
|
|
18067
|
+
darwin: "firefox",
|
|
18068
|
+
win32: "C:\\Program Files\\Mozilla Firefox\\firefox.exe",
|
|
18069
|
+
linux: "firefox"
|
|
18070
|
+
}, {
|
|
18071
|
+
wsl: "/mnt/c/Program Files/Mozilla Firefox/firefox.exe"
|
|
18072
|
+
}));
|
|
18073
|
+
defineLazyProperty(apps, "edge", () => detectPlatformBinary({
|
|
18074
|
+
darwin: "microsoft edge",
|
|
18075
|
+
win32: "msedge",
|
|
18076
|
+
linux: ["microsoft-edge", "microsoft-edge-dev"]
|
|
18077
|
+
}, {
|
|
18078
|
+
wsl: "/mnt/c/Program Files (x86)/Microsoft/Edge/Application/msedge.exe"
|
|
18079
|
+
}));
|
|
18080
|
+
defineLazyProperty(apps, "browser", () => "browser");
|
|
18081
|
+
defineLazyProperty(apps, "browserPrivate", () => "browserPrivate");
|
|
18082
|
+
var open_default = open;
|
|
18083
|
+
|
|
18084
|
+
// src/lib/tldraw-open.ts
|
|
18085
|
+
var tldrawOpenDefaultOptions = {
|
|
18086
|
+
location: "remote"
|
|
18087
|
+
};
|
|
18088
|
+
async function tldrawOpen(tldrPathOrUrl, options) {
|
|
18089
|
+
const tldrawRemoteUrl = "https://www.tldraw.com";
|
|
18090
|
+
const { location } = { ...tldrawOpenDefaultOptions, ...options };
|
|
18091
|
+
let urlToOpen;
|
|
18092
|
+
const validatedPathOrUrl = tldrPathOrUrl === void 0 ? void 0 : validatePathOrUrl(tldrPathOrUrl, {
|
|
18093
|
+
requireFileExistence: true,
|
|
18094
|
+
validFileExtensions: [".tldr"],
|
|
18095
|
+
validHostnames: ["www.tldraw.com"]
|
|
18096
|
+
});
|
|
18097
|
+
if (location === "local" && validatedPathOrUrl === void 0) {
|
|
18098
|
+
const tldrawServer = new LocalTldrawServer();
|
|
18099
|
+
await tldrawServer.start();
|
|
18100
|
+
urlToOpen = tldrawServer.href;
|
|
18101
|
+
log_default.info(`Opened blank tldraw sketch locally at "${urlToOpen}"`);
|
|
18102
|
+
} else if (location === "local" && typeof validatedPathOrUrl === "string") {
|
|
18103
|
+
const tldrData = await fs8.readFile(validatedPathOrUrl, "utf8");
|
|
18104
|
+
const tldrawServer = new LocalTldrawServer(tldrData);
|
|
18105
|
+
await tldrawServer.start();
|
|
18106
|
+
urlToOpen = tldrawServer.href;
|
|
18107
|
+
log_default.info(`Opened copy of tldraw sketch "${validatedPathOrUrl}" locally at "${urlToOpen}"`);
|
|
18108
|
+
} else if (location === "local" && validatedPathOrUrl instanceof URL2) {
|
|
18109
|
+
const [savedFile] = await tldrawToImage(validatedPathOrUrl.href, {
|
|
18110
|
+
format: "tldr",
|
|
18111
|
+
name: nanoid(),
|
|
18112
|
+
output: os5.tmpdir()
|
|
18113
|
+
});
|
|
18114
|
+
const tldrData = await fs8.readFile(savedFile, "utf8");
|
|
18115
|
+
await fs8.rm(savedFile, { force: true });
|
|
18116
|
+
const tldrawServer = new LocalTldrawServer(tldrData);
|
|
18117
|
+
await tldrawServer.start();
|
|
18118
|
+
urlToOpen = tldrawServer.href;
|
|
18119
|
+
log_default.info(
|
|
18120
|
+
`Opened a local copy of tldraw sketch url "${validatedPathOrUrl.href}" locally at ${urlToOpen}`
|
|
18121
|
+
);
|
|
18122
|
+
} else if (location === "remote" && validatedPathOrUrl === void 0) {
|
|
18123
|
+
urlToOpen = tldrawRemoteUrl;
|
|
18124
|
+
log_default.info(`Opened tldraw.com`);
|
|
18125
|
+
} else if (location === "remote" && typeof validatedPathOrUrl === "string") {
|
|
18126
|
+
urlToOpen = await tldrawToShareUrl(validatedPathOrUrl);
|
|
18127
|
+
log_default.info(
|
|
18128
|
+
`Opened copy of local tldraw sketch "${validatedPathOrUrl}" remotely at "${urlToOpen}"`
|
|
18129
|
+
);
|
|
18130
|
+
} else if (location === "remote" && validatedPathOrUrl instanceof URL2) {
|
|
18131
|
+
urlToOpen = validatedPathOrUrl.href;
|
|
18132
|
+
log_default.info(`Opened tldraw sketch url at ${urlToOpen}`);
|
|
18133
|
+
} else {
|
|
18134
|
+
throw new Error("Invalid tldrawOpen options");
|
|
18135
|
+
}
|
|
18136
|
+
const exitPromise = open_default(urlToOpen, {
|
|
18137
|
+
wait: true
|
|
18138
|
+
});
|
|
18139
|
+
return {
|
|
18140
|
+
browserExitPromise: exitPromise,
|
|
18141
|
+
openedSketchUrl: urlToOpen
|
|
18142
|
+
};
|
|
18143
|
+
}
|
|
17589
18144
|
export {
|
|
17590
18145
|
log_default as log,
|
|
17591
|
-
|
|
18146
|
+
tldrawOpen,
|
|
18147
|
+
tldrawToImage,
|
|
18148
|
+
tldrawToShareUrl
|
|
17592
18149
|
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { type ChildProcess } from 'node:child_process';
|
|
3
|
+
export type TldrawOpenOptions = {
|
|
4
|
+
location: 'local' | 'remote';
|
|
5
|
+
};
|
|
6
|
+
export type TldrawOpenResult = {
|
|
7
|
+
browserExitPromise: Promise<ChildProcess>;
|
|
8
|
+
openedSketchUrl: string;
|
|
9
|
+
};
|
|
10
|
+
export declare function tldrawOpen(tldrPathOrUrl?: string, options?: Partial<TldrawOpenOptions>): Promise<TldrawOpenResult>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function tldrawToShareUrl(tldrPathOrUrl: string): Promise<string>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kitschpatrol/tldraw-cli",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.6.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "A CLI tool for exporting tldraw sketch URLs and local .tldr files to SVG or PNG images.",
|
|
6
6
|
"repository": {
|
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
"preview": "pnpm run preview:tldraw",
|
|
101
101
|
"preview:tldraw": "vite preview",
|
|
102
102
|
"release": "pnpm bumpp --commit 'Release: %s' && pnpm build && pnpm publish --otp $(op read 'op://Personal/Npmjs/one-time password?attribute=otp')",
|
|
103
|
-
"test": "
|
|
104
|
-
"test:
|
|
103
|
+
"test": "vitest --run",
|
|
104
|
+
"test:watch": "pnpm run build && vitest",
|
|
105
105
|
"tldraw:copy-assets": "rsync -av --include='/*/' --exclude='/*' --exclude='favicon.ico' ./node_modules/@tldraw/assets/ ./src/tldraw/public/"
|
|
106
106
|
}
|
|
107
107
|
}
|
package/readme.md
CHANGED
|
@@ -88,10 +88,10 @@ Usage:
|
|
|
88
88
|
tldraw <command>
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
| Command | Argument | Description
|
|
92
|
-
| -------- | ------------------- |
|
|
93
|
-
| `export` | `<files-or-urls..>` | Export a local tldraw ".tldr" file or a tldraw\.com URL to an svg, png, json, or tldr file. Prints the absolute path(s) to the exported image(s) to stdout.
|
|
94
|
-
| `open` | `[files-or-urls..]` | Open a tldraw `.tldr` file or tldraw\.com URL in your default browser with either the official tldraw\.com site or a locally-hosted instance of the editor. Call `open` without an argument to open a blank sketch. Sketches opened via URL with the `--local` flag will be temporarily copied to the local system, and will not be kept in sync with tldraw\.com. This process does not exit until the browser is closed. |
|
|
91
|
+
| Command | Argument | Description |
|
|
92
|
+
| -------- | ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
93
|
+
| `export` | `<files-or-urls..>` | Export a local tldraw ".tldr" file or a tldraw\.com URL to an svg, png, json, or tldr file. Prints the absolute path(s) to the exported image(s) to stdout. |
|
|
94
|
+
| `open` | `[files-or-urls..]` | Open a tldraw `.tldr` file or tldraw\.com URL in your default browser with either the official tldraw\.com site or a locally-hosted instance of the editor. Call `open` without an argument to open a blank sketch. Sketches opened via URL with the `--local` flag will be temporarily copied to the local system, and will not be kept in sync with tldraw\.com. This process does not exit until the browser is closed. Warning: Passing a local .tldr file without the `--local` option will upload and share the sketch on tldraw\.com. |
|
|
95
95
|
|
|
96
96
|
| Option | Alias | Description | Type |
|
|
97
97
|
| ----------- | ----- | ------------------- | --------- |
|
|
@@ -133,7 +133,7 @@ tldraw export <files-or-urls..>
|
|
|
133
133
|
|
|
134
134
|
#### Subcommand: `tldraw open`
|
|
135
135
|
|
|
136
|
-
Open a tldraw `.tldr` file or tldraw\.com URL in your default browser with either the official tldraw\.com site or a locally-hosted instance of the editor. Call `open` without an argument to open a blank sketch. Sketches opened via URL with the `--local` flag will be temporarily copied to the local system, and will not be kept in sync with tldraw\.com. This process does not exit until the browser is closed.
|
|
136
|
+
Open a tldraw `.tldr` file or tldraw\.com URL in your default browser with either the official tldraw\.com site or a locally-hosted instance of the editor. Call `open` without an argument to open a blank sketch. Sketches opened via URL with the `--local` flag will be temporarily copied to the local system, and will not be kept in sync with tldraw\.com. This process does not exit until the browser is closed. Warning: Passing a local .tldr file without the `--local` option will upload and share the sketch on tldraw\.com.
|
|
137
137
|
|
|
138
138
|
Usage:
|
|
139
139
|
|
|
@@ -290,9 +290,15 @@ The remote sketch is copied to a locally-hosted instance of tldraw, which is the
|
|
|
290
290
|
|
|
291
291
|
### API
|
|
292
292
|
|
|
293
|
-
The `
|
|
293
|
+
The `tldraw-cli` command line functionality is also provided in module form for programmatic use in TypeScript or JavaScript Node projects.
|
|
294
294
|
|
|
295
|
-
The library exports
|
|
295
|
+
The library exports two async function, `tldrawToImage`, and `tldrawOpen`.
|
|
296
|
+
|
|
297
|
+
#### `tldrawToImage`
|
|
298
|
+
|
|
299
|
+
This mirrors the `tldraw export` CLI command.
|
|
300
|
+
|
|
301
|
+
It takes an options argument mirroring the arguments available via the command line. The same default values apply:
|
|
296
302
|
|
|
297
303
|
```ts
|
|
298
304
|
async function tldrawToImage(
|
|
@@ -367,7 +373,63 @@ log.verbose = false
|
|
|
367
373
|
await tldrawToImage('https://www.tldraw.com/s/v2_c_JsxJk8dag6QsrqExukis4')
|
|
368
374
|
```
|
|
369
375
|
|
|
370
|
-
|
|
376
|
+
#### `tldrawOpen`
|
|
377
|
+
|
|
378
|
+
Mirrors the `tldraw open` CLI command.
|
|
379
|
+
|
|
380
|
+
> \[!CAUTION]
|
|
381
|
+
> Passing a local .tldr file with the `location: 'remote'` option will upload and share your sketch on tldraw\.com.
|
|
382
|
+
|
|
383
|
+
```tsx
|
|
384
|
+
async function tldrawOpen(
|
|
385
|
+
tldrPathOrUrl?: string,
|
|
386
|
+
options?: Partial<{
|
|
387
|
+
location: 'local' | 'remote'
|
|
388
|
+
}>,
|
|
389
|
+
): Promise<{
|
|
390
|
+
browserExitPromise: Promise<ChildProcess>
|
|
391
|
+
openedSketchUrl: string
|
|
392
|
+
}>
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
It's important to note that the returned result includes `browserExitPromise`, which resolves when the user has completely exited the web browser used to open the tldr file or url.
|
|
396
|
+
|
|
397
|
+
You _must_ await the `browserExitPromise` (or somehow keep script's process alive) if you're opening a tldr file with the \`location: 'local'\`. This prevents the local server from closing prematurely, which would interfere with any server-dependent actions in tldraw.
|
|
398
|
+
|
|
399
|
+
Example of opening a local file:
|
|
400
|
+
|
|
401
|
+
```ts
|
|
402
|
+
import { tldrawOpen } from 'tldraw-cli'
|
|
403
|
+
|
|
404
|
+
const { browserExitPromise } = await tldrawOpen('./sketch.tldr', {
|
|
405
|
+
location: 'local',
|
|
406
|
+
})
|
|
407
|
+
|
|
408
|
+
// Wait for the browser to close to keep
|
|
409
|
+
// the local tldraw instance running!
|
|
410
|
+
await browserExitPromise
|
|
411
|
+
```
|
|
412
|
+
|
|
413
|
+
While opening the file remotely on tldraw\.com is more casual:
|
|
414
|
+
|
|
415
|
+
```ts
|
|
416
|
+
import { tldrawOpen } from 'tldraw-cli'
|
|
417
|
+
|
|
418
|
+
await tldrawOpen('./sketch.tldr', {
|
|
419
|
+
location: 'remote',
|
|
420
|
+
})
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
#### `tldrawToShareUrl`
|
|
424
|
+
|
|
425
|
+
```ts
|
|
426
|
+
async function tldrawToShareUrl(tldrPathOrUrl: string): Promise<string>
|
|
427
|
+
```
|
|
428
|
+
|
|
429
|
+
Returns a live "share" url for a given local or remote tldraw sketch URL.
|
|
430
|
+
|
|
431
|
+
> \[!CAUTION]
|
|
432
|
+
> Passing a local .tldr file to this function will upload and share your local file to tldraw\.com.
|
|
371
433
|
|
|
372
434
|
## Background
|
|
373
435
|
|