@tscircuit/cli 0.1.1033 → 0.1.1035

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.
@@ -11586,7 +11586,8 @@ async function generateCircuitJson({
11586
11586
  outputDir,
11587
11587
  outputFileName,
11588
11588
  saveToFile = false,
11589
- platformConfig
11589
+ platformConfig,
11590
+ injectedProps
11590
11591
  }) {
11591
11592
  debug(`Generating circuit JSON for ${filePath}`);
11592
11593
  const React = await importFromUserLand("react");
@@ -11633,7 +11634,9 @@ async function generateCircuitJson({
11633
11634
  if (!Component) {
11634
11635
  throw new Error(`No component found in "${absoluteFilePath}". Make sure you export a component.`);
11635
11636
  }
11636
- runner.add(/* @__PURE__ */ jsxDEV(Component, {}, undefined, false, undefined, this));
11637
+ runner.add(/* @__PURE__ */ jsxDEV(Component, {
11638
+ ...injectedProps ?? {}
11639
+ }, undefined, false, undefined, this));
11637
11640
  await runner.renderUntilSettled();
11638
11641
  const circuitJson = await runner.getCircuitJson();
11639
11642
  if (saveToFile) {
@@ -13341,7 +13344,8 @@ var handleBuildFile = async (filePath, outputPath, projectDir, options) => {
13341
13344
  })()
13342
13345
  } : await generateCircuitJson({
13343
13346
  filePath,
13344
- platformConfig: completePlatformConfig
13347
+ platformConfig: completePlatformConfig,
13348
+ injectedProps: options?.injectedProps
13345
13349
  });
13346
13350
  fs9.mkdirSync(path12.dirname(outputPath), { recursive: true });
13347
13351
  fs9.writeFileSync(outputPath, JSON.stringify(result.circuitJson, null, 2));
package/dist/cli/main.js CHANGED
@@ -71664,7 +71664,7 @@ var registerStaticAssetLoaders = () => {
71664
71664
  // cli/main.ts
71665
71665
  var import_perfect_cli = __toESM2(require_dist2(), 1);
71666
71666
  // package.json
71667
- var version = "0.1.1032";
71667
+ var version = "0.1.1034";
71668
71668
  var package_default = {
71669
71669
  name: "@tscircuit/cli",
71670
71670
  version,
@@ -80562,7 +80562,8 @@ async function generateCircuitJson({
80562
80562
  outputDir,
80563
80563
  outputFileName,
80564
80564
  saveToFile = false,
80565
- platformConfig
80565
+ platformConfig,
80566
+ injectedProps
80566
80567
  }) {
80567
80568
  debug(`Generating circuit JSON for ${filePath}`);
80568
80569
  const React = await importFromUserLand("react");
@@ -80609,7 +80610,9 @@ async function generateCircuitJson({
80609
80610
  if (!Component) {
80610
80611
  throw new Error(`No component found in "${absoluteFilePath}". Make sure you export a component.`);
80611
80612
  }
80612
- runner.add(/* @__PURE__ */ jsxDEV2(Component, {}, undefined, false, undefined, this));
80613
+ runner.add(/* @__PURE__ */ jsxDEV2(Component, {
80614
+ ...injectedProps ?? {}
80615
+ }, undefined, false, undefined, this));
80613
80616
  await runner.renderUntilSettled();
80614
80617
  const circuitJson = await runner.getCircuitJson();
80615
80618
  if (saveToFile) {
@@ -80637,7 +80640,8 @@ var buildFile = async (input, output, projectDir, options) => {
80637
80640
  if (!isPrebuiltCircuitJson) {
80638
80641
  const result = await generateCircuitJson({
80639
80642
  filePath: input,
80640
- platformConfig: completePlatformConfig
80643
+ platformConfig: completePlatformConfig,
80644
+ injectedProps: options?.injectedProps
80641
80645
  });
80642
80646
  circuitJson = result.circuitJson;
80643
80647
  }
@@ -82220,6 +82224,35 @@ var standalone_min_default = '(function(U2,VG){typeof exports=="object"&&typeof
82220
82224
 
82221
82225
  // cli/build/register.ts
82222
82226
  var normalizeRelativePath = (projectDir, targetPath) => path38.relative(projectDir, targetPath).split(path38.sep).join("/");
82227
+ var parseInjectedProps = ({
82228
+ injectProps,
82229
+ injectPropsFile,
82230
+ projectDir
82231
+ }) => {
82232
+ if (injectProps && injectPropsFile) {
82233
+ throw new Error("Cannot use --inject-props and --inject-props-file together");
82234
+ }
82235
+ const rawProps = (() => {
82236
+ if (injectPropsFile) {
82237
+ const resolvedPropsPath = path38.resolve(projectDir, injectPropsFile);
82238
+ return fs37.readFileSync(resolvedPropsPath, "utf-8");
82239
+ }
82240
+ return injectProps;
82241
+ })();
82242
+ if (!rawProps) {
82243
+ return;
82244
+ }
82245
+ let parsed;
82246
+ try {
82247
+ parsed = JSON.parse(rawProps);
82248
+ } catch (error) {
82249
+ throw new Error(`Failed to parse injected props JSON: ${error instanceof Error ? error.message : String(error)}`);
82250
+ }
82251
+ if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) {
82252
+ throw new Error("Injected props must be a JSON object");
82253
+ }
82254
+ return parsed;
82255
+ };
82223
82256
  var getOutputDirName = (relativePath) => {
82224
82257
  const normalizedRelativePath = relativePath.toLowerCase().replaceAll("\\", "/");
82225
82258
  if (normalizedRelativePath === "circuit.json" || normalizedRelativePath.endsWith("/circuit.json")) {
@@ -82228,7 +82261,7 @@ var getOutputDirName = (relativePath) => {
82228
82261
  return relativePath.replace(/(\.board|\.circuit)?\.tsx$/, "").replace(/\.circuit\.json$/, "");
82229
82262
  };
82230
82263
  var registerBuild = (program2) => {
82231
- program2.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ci", "Run install and optional prebuild/build commands (or default CI build)").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--ignore-config", "Ignore options from tscircuit.config.json").option("--disable-pcb", "Disable PCB outputs").option("--disable-parts-engine", "Disable the parts engine").option("--site", "Generate a static site in the dist directory").option("--transpile", "Transpile the entry file to JavaScript").option("--preview-images", "Generate preview images in the dist directory").option("--all-images", "Generate preview images for every successful build output").option("--kicad-project", "Generate KiCad project directories for each successful build output").option("--kicad-library", "Generate KiCad library in dist/kicad-library").option("--kicad-library-name <name>", "Specify the name of the KiCad library").option("--preview-gltf", "Generate a GLTF file from the preview entrypoint").option("--glbs", "Generate GLB 3D model files for every successful build").option("--profile", "Log per-circuit circuit.json generation time during build").option("--kicad-pcm", "Generate KiCad PCM (Plugin and Content Manager) assets in dist/pcm").option("--use-cdn-javascript", "Use CDN-hosted JavaScript instead of bundled standalone file for --site").option("--concurrency <number>", "Number of files to build in parallel (default: 1)", "1").action(async (file, options) => {
82264
+ program2.command("build").description("Run tscircuit eval and output circuit json").argument("[file]", "Path to the entry file").option("--ci", "Run install and optional prebuild/build commands (or default CI build)").option("--ignore-errors", "Do not exit with code 1 on errors").option("--ignore-warnings", "Do not log warnings").option("--ignore-config", "Ignore options from tscircuit.config.json").option("--disable-pcb", "Disable PCB outputs").option("--disable-parts-engine", "Disable the parts engine").option("--site", "Generate a static site in the dist directory").option("--transpile", "Transpile the entry file to JavaScript").option("--preview-images", "Generate preview images in the dist directory").option("--all-images", "Generate preview images for every successful build output").option("--kicad-project", "Generate KiCad project directories for each successful build output").option("--kicad-library", "Generate KiCad library in dist/kicad-library").option("--kicad-library-name <name>", "Specify the name of the KiCad library").option("--preview-gltf", "Generate a GLTF file from the preview entrypoint").option("--glbs", "Generate GLB 3D model files for every successful build").option("--profile", "Log per-circuit circuit.json generation time during build").option("--kicad-pcm", "Generate KiCad PCM (Plugin and Content Manager) assets in dist/pcm").option("--use-cdn-javascript", "Use CDN-hosted JavaScript instead of bundled standalone file for --site").option("--concurrency <number>", "Number of files to build in parallel (default: 1)", "1").option("--inject-props <json>", "Inject JSON props into the built file's default export").option("--inject-props-file <path>", "Inject JSON props from a file into the built file's default export").action(async (file, options) => {
82232
82265
  try {
82233
82266
  const transpileExplicitlyRequested = options?.transpile === true;
82234
82267
  const resolvedRoot = path38.resolve(process.cwd());
@@ -82302,11 +82335,17 @@ var registerBuild = (program2) => {
82302
82335
  const kicadProjects = [];
82303
82336
  const profileEntries = [];
82304
82337
  const shouldGenerateKicadProject = resolvedOptions?.kicadProject || resolvedOptions?.kicadLibrary;
82338
+ const injectedProps = parseInjectedProps({
82339
+ injectProps: resolvedOptions?.injectProps,
82340
+ injectPropsFile: resolvedOptions?.injectPropsFile,
82341
+ projectDir
82342
+ });
82305
82343
  const buildOptions = {
82306
82344
  ignoreErrors: resolvedOptions?.ignoreErrors,
82307
82345
  ignoreWarnings: resolvedOptions?.ignoreWarnings,
82308
82346
  platformConfig,
82309
- profile: resolvedOptions?.profile
82347
+ profile: resolvedOptions?.profile,
82348
+ injectedProps
82310
82349
  };
82311
82350
  const processBuildResult = async (filePath, outputPath, buildOutcome) => {
82312
82351
  const relative3 = path38.relative(projectDir, filePath);
@@ -177544,15 +177583,18 @@ var registerSimulate = (program3) => {
177544
177583
  };
177545
177584
 
177546
177585
  // lib/shared/camera-presets.ts
177586
+ function normalizeDir(dir) {
177587
+ const len = Math.sqrt(dir[0] ** 2 + dir[1] ** 2 + dir[2] ** 2);
177588
+ if (len === 0)
177589
+ return [0, 1, 0];
177590
+ return [dir[0] / len, dir[1] / len, dir[2] / len];
177591
+ }
177547
177592
  function distance5(a3, b3) {
177548
177593
  return Math.sqrt((a3[0] - b3[0]) ** 2 + (a3[1] - b3[1]) ** 2 + (a3[2] - b3[2]) ** 2);
177549
177594
  }
177550
- function repositionCamera(cam, dir) {
177551
- const dist = distance5(cam.camPos, cam.lookAt);
177552
- const len = Math.sqrt(dir[0] ** 2 + dir[1] ** 2 + dir[2] ** 2);
177553
- const nx2 = dir[0] / len;
177554
- const ny2 = dir[1] / len;
177555
- const nz = dir[2] / len;
177595
+ function repositionCamera(cam, dir, distOverride) {
177596
+ const dist = distOverride ?? distance5(cam.camPos, cam.lookAt);
177597
+ const [nx2, ny2, nz] = normalizeDir(dir);
177556
177598
  return {
177557
177599
  camPos: [
177558
177600
  cam.lookAt[0] + nx2 * dist,
@@ -177564,7 +177606,20 @@ function repositionCamera(cam, dir) {
177564
177606
  };
177565
177607
  }
177566
177608
  var CAMERA_PRESETS = {
177567
- "top-down": (cam) => repositionCamera(cam, [0.0001, 1, -0.01]),
177609
+ "top-down": (cam) => repositionCamera(cam, [0.00000001, 1, -0.001]),
177610
+ "top-down-ortho": (cam) => {
177611
+ const desiredFov = 3;
177612
+ const dir = [0.00000001, 1, -0.001];
177613
+ const origDist = distance5(cam.camPos, cam.lookAt);
177614
+ const origFovRad = Math.max(cam.fov * Math.PI / 180, 0.01);
177615
+ const desiredFovRad = Math.max(desiredFov * Math.PI / 180, 0.01);
177616
+ const tanOrig = Math.tan(origFovRad / 2);
177617
+ const tanDesired = Math.max(Math.tan(desiredFovRad / 2), 0.0001);
177618
+ const distScale = Number.isFinite(tanOrig / tanDesired) && tanOrig > 0 ? tanOrig / tanDesired : 1;
177619
+ const newDist = origDist * distScale;
177620
+ const repositioned = repositionCamera(cam, dir, newDist);
177621
+ return { ...repositioned, fov: desiredFov };
177622
+ },
177568
177623
  "top-left-corner": (cam) => repositionCamera(cam, [0.7, 1.2, -0.8]),
177569
177624
  "top-left": (cam) => repositionCamera(cam, [1, 1.2, 0]),
177570
177625
  "top-right-corner": (cam) => repositionCamera(cam, [-0.7, 1.2, -0.8]),
package/dist/lib/index.js CHANGED
@@ -60435,7 +60435,7 @@ var getNodeHandler = (winterSpec, { port, middleware = [] }) => {
60435
60435
  }));
60436
60436
  };
60437
60437
  // package.json
60438
- var version = "0.1.1032";
60438
+ var version = "0.1.1034";
60439
60439
  var package_default = {
60440
60440
  name: "@tscircuit/cli",
60441
60441
  version,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tscircuit/cli",
3
- "version": "0.1.1033",
3
+ "version": "0.1.1035",
4
4
  "main": "dist/cli/main.js",
5
5
  "exports": {
6
6
  ".": "./dist/cli/main.js",