@tscircuit/cli 0.1.1534 → 0.1.1535

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.
@@ -12169,6 +12169,190 @@ var resolveImageFormatSelection = (options) => {
12169
12169
  import fs9 from "node:fs";
12170
12170
  import path13 from "node:path";
12171
12171
 
12172
+ // node_modules/circuit-json-to-3d-png/dist/index.js
12173
+ function normalizeDir(dir) {
12174
+ const len = Math.sqrt(dir[0] ** 2 + dir[1] ** 2 + dir[2] ** 2);
12175
+ if (len === 0)
12176
+ return [0, 1, 0];
12177
+ return [dir[0] / len, dir[1] / len, dir[2] / len];
12178
+ }
12179
+ function distance(a, b) {
12180
+ return Math.sqrt((a[0] - b[0]) ** 2 + (a[1] - b[1]) ** 2 + (a[2] - b[2]) ** 2);
12181
+ }
12182
+ function repositionCamera(cam, dir, distOverride) {
12183
+ const dist = distOverride ?? distance(cam.camPos, cam.lookAt);
12184
+ const [nx, ny, nz] = normalizeDir(dir);
12185
+ return {
12186
+ camPos: [
12187
+ cam.lookAt[0] + nx * dist,
12188
+ cam.lookAt[1] + ny * dist,
12189
+ cam.lookAt[2] + nz * dist
12190
+ ],
12191
+ lookAt: cam.lookAt,
12192
+ fov: cam.fov
12193
+ };
12194
+ }
12195
+ var CAMERA_PRESETS = {
12196
+ "top-down": (cam) => repositionCamera(cam, [0.00000001, 1, -0.001]),
12197
+ "top-down-ortho": (cam) => {
12198
+ const desiredFov = 3;
12199
+ const dir = [0.00000001, 1, -0.001];
12200
+ const origDist = distance(cam.camPos, cam.lookAt);
12201
+ const origFovRad = Math.max(cam.fov * Math.PI / 180, 0.01);
12202
+ const desiredFovRad = Math.max(desiredFov * Math.PI / 180, 0.01);
12203
+ const tanOrig = Math.tan(origFovRad / 2);
12204
+ const tanDesired = Math.max(Math.tan(desiredFovRad / 2), 0.0001);
12205
+ const distScale = Number.isFinite(tanOrig / tanDesired) && tanOrig > 0 ? tanOrig / tanDesired : 1;
12206
+ const newDist = origDist * distScale;
12207
+ const repositioned = repositionCamera(cam, dir, newDist);
12208
+ return { ...repositioned, fov: desiredFov };
12209
+ },
12210
+ "top-left-corner": (cam) => repositionCamera(cam, [0.7, 1.2, -0.8]),
12211
+ "top-left": (cam) => repositionCamera(cam, [1, 1.2, 0]),
12212
+ "top-right-corner": (cam) => repositionCamera(cam, [-0.7, 1.2, -0.8]),
12213
+ "top-right": (cam) => repositionCamera(cam, [-1, 1.2, 0]),
12214
+ "left-sideview": (cam) => repositionCamera(cam, [1, 0.05, 0]),
12215
+ "right-sideview": (cam) => repositionCamera(cam, [-1, 0.05, 0]),
12216
+ front: (cam) => repositionCamera(cam, [0, 0.05, -1]),
12217
+ "top-center-angled": (cam) => repositionCamera(cam, [0, 1, -1])
12218
+ };
12219
+ var CAMERA_PRESET_NAMES = Object.keys(CAMERA_PRESETS);
12220
+ function applyCameraPreset(preset, cam) {
12221
+ if (!(preset in CAMERA_PRESETS)) {
12222
+ throw new Error(`Unknown camera preset "${preset}". Valid presets: ${CAMERA_PRESET_NAMES.join(", ")}`);
12223
+ }
12224
+ return CAMERA_PRESETS[preset](cam);
12225
+ }
12226
+ var viewToArrayBuffer = (view) => {
12227
+ const copy = new Uint8Array(view.byteLength);
12228
+ copy.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
12229
+ return copy.buffer;
12230
+ };
12231
+ var normalizeToArrayBuffer = async (value) => {
12232
+ if (value instanceof ArrayBuffer) {
12233
+ return value;
12234
+ }
12235
+ if (ArrayBuffer.isView(value)) {
12236
+ return viewToArrayBuffer(value);
12237
+ }
12238
+ if ("arrayBuffer" in value && typeof value.arrayBuffer === "function") {
12239
+ const result = value.arrayBuffer();
12240
+ return result instanceof Promise ? await result : result;
12241
+ }
12242
+ throw new Error("Expected ArrayBuffer, ArrayBufferView, or Buffer-compatible object");
12243
+ };
12244
+ var normalizeToUint8Array = (value) => {
12245
+ if (value instanceof Uint8Array) {
12246
+ return value;
12247
+ }
12248
+ if (value instanceof ArrayBuffer) {
12249
+ return new Uint8Array(value);
12250
+ }
12251
+ if (ArrayBuffer.isView(value)) {
12252
+ return new Uint8Array(viewToArrayBuffer(value));
12253
+ }
12254
+ throw new Error("Expected Uint8Array, ArrayBuffer, or ArrayBufferView");
12255
+ };
12256
+ var circuitJsonToGltfModulePromise = null;
12257
+ var poppyGlModulePromise = null;
12258
+ var loadCircuitJsonToGltf = async () => {
12259
+ circuitJsonToGltfModulePromise ??= import("circuit-json-to-gltf");
12260
+ return circuitJsonToGltfModulePromise;
12261
+ };
12262
+ var loadPoppyGl = async () => {
12263
+ poppyGlModulePromise ??= import("poppygl");
12264
+ return poppyGlModulePromise;
12265
+ };
12266
+ var modelUrlKeys = [
12267
+ "model_glb_url",
12268
+ "glb_model_url",
12269
+ "model_stl_url",
12270
+ "stl_model_url",
12271
+ "model_obj_url",
12272
+ "obj_model_url",
12273
+ "model_gltf_url",
12274
+ "gltf_model_url",
12275
+ "model_step_url",
12276
+ "step_model_url"
12277
+ ];
12278
+ var hasUriScheme = (value) => /^[a-zA-Z][a-zA-Z\d+\-.]*:/.test(value) && !/^[a-zA-Z]:[\\/]/.test(value);
12279
+ var isWindowsAbsolutePath = (value) => /^[a-zA-Z]:[\\/]/.test(value);
12280
+ var getDefaultBaseDir = () => {
12281
+ if (typeof process !== "undefined" && process && typeof process.cwd === "function") {
12282
+ return process.cwd();
12283
+ }
12284
+ return;
12285
+ };
12286
+ var toFileUrl = (value) => {
12287
+ const normalizedPath = value.replace(/\\/g, "/");
12288
+ const pathname = isWindowsAbsolutePath(value) ? `/${normalizedPath}` : normalizedPath;
12289
+ return new URL(`file://${encodeURI(pathname)}`).href;
12290
+ };
12291
+ var toDirectoryUrl = (value) => {
12292
+ if (hasUriScheme(value)) {
12293
+ return value.endsWith("/") ? value : `${value}/`;
12294
+ }
12295
+ const directoryPath = value.endsWith("/") || value.endsWith("\\") ? value : `${value}/`;
12296
+ return toFileUrl(directoryPath);
12297
+ };
12298
+ var normalizeModelUrls = (circuitJson, options = {}) => {
12299
+ const baseDir = options.modelPathBaseDir ?? getDefaultBaseDir();
12300
+ const hasModelPathBaseDir = options.modelPathBaseDir != null;
12301
+ const preserveRelativeModelUrls = Boolean(options.projectBaseUrl);
12302
+ return circuitJson.map((element) => {
12303
+ if (!element || typeof element !== "object")
12304
+ return element;
12305
+ const updated = { ...element };
12306
+ for (const key of modelUrlKeys) {
12307
+ const value = updated[key];
12308
+ if (!value)
12309
+ continue;
12310
+ if (hasUriScheme(value))
12311
+ continue;
12312
+ if (value.startsWith("/") && preserveRelativeModelUrls) {
12313
+ updated[key] = value;
12314
+ } else if (value.startsWith("/") || isWindowsAbsolutePath(value)) {
12315
+ updated[key] = toFileUrl(value);
12316
+ } else if (preserveRelativeModelUrls && !hasModelPathBaseDir) {
12317
+ updated[key] = value;
12318
+ } else if (!baseDir) {
12319
+ updated[key] = value;
12320
+ } else {
12321
+ updated[key] = new URL(value, toDirectoryUrl(baseDir)).href;
12322
+ }
12323
+ }
12324
+ return updated;
12325
+ });
12326
+ };
12327
+ var getRenderCamera = (circuitJson, defaultCamera, options = {}) => {
12328
+ if (options.camera) {
12329
+ return options.camera;
12330
+ }
12331
+ if (!options.cameraPreset) {
12332
+ return defaultCamera;
12333
+ }
12334
+ return applyCameraPreset(options.cameraPreset, defaultCamera);
12335
+ };
12336
+ var getConversionOptions = (format, options = {}) => ({
12337
+ format,
12338
+ ...options.projectBaseUrl ? { projectBaseUrl: options.projectBaseUrl } : {},
12339
+ ...options.authHeaders ? { authHeaders: options.authHeaders } : {},
12340
+ ...options.boardTextureResolution ? { boardTextureResolution: options.boardTextureResolution } : {}
12341
+ });
12342
+ var convertCircuitJsonTo3dGlb = async (circuitJson, options = {}) => {
12343
+ const normalizedCircuitJson = normalizeModelUrls(circuitJson, options);
12344
+ const { convertCircuitJsonToGltf } = await loadCircuitJsonToGltf();
12345
+ const glbBuffer = await convertCircuitJsonToGltf(normalizedCircuitJson, getConversionOptions("glb", options));
12346
+ return normalizeToUint8Array(await normalizeToArrayBuffer(glbBuffer));
12347
+ };
12348
+ var renderCircuitJsonTo3dPng = async (circuitJson, options = {}) => {
12349
+ const [{ getBestCameraPosition }, { renderGLTFToPNGFromGLB }] = await Promise.all([loadCircuitJsonToGltf(), loadPoppyGl()]);
12350
+ const glbBuffer = await convertCircuitJsonTo3dGlb(circuitJson, options);
12351
+ const glbArrayBuffer = await normalizeToArrayBuffer(glbBuffer);
12352
+ const defaultCamera = getBestCameraPosition(circuitJson);
12353
+ return renderGLTFToPNGFromGLB(glbArrayBuffer, getRenderCamera(circuitJson, defaultCamera, options));
12354
+ };
12355
+
12172
12356
  // node_modules/circuit-json-to-step/node_modules/stepts/dist/index.js
12173
12357
  var Entity = class {
12174
12358
  static parse(_a, _ctx) {
@@ -14455,15 +14639,11 @@ async function circuitJsonToStep(circuitJson, options = {}) {
14455
14639
  }
14456
14640
 
14457
14641
  // cli/build/worker-output-generators.ts
14458
- import {
14459
- convertCircuitJsonToGltf,
14460
- getBestCameraPosition
14461
- } from "circuit-json-to-gltf";
14642
+ import { convertCircuitJsonToGltf } from "circuit-json-to-gltf";
14462
14643
  import {
14463
14644
  convertCircuitJsonToPcbSvg,
14464
14645
  convertCircuitJsonToSchematicSvg
14465
14646
  } from "circuit-to-svg";
14466
- import { renderGLTFToPNGFromGLB } from "poppygl";
14467
14647
 
14468
14648
  // node_modules/conf/dist/source/index.js
14469
14649
  import { isDeepStrictEqual } from "node:util";
@@ -15952,7 +16132,7 @@ var getCircuitJsonToGltfOptions = ({
15952
16132
  import path11 from "node:path";
15953
16133
  import { pathToFileURL as pathToFileURL2 } from "node:url";
15954
16134
  var convertModelUrlsToFileUrls = (circuitJson) => {
15955
- const modelUrlKeys = [
16135
+ const modelUrlKeys2 = [
15956
16136
  "model_glb_url",
15957
16137
  "glb_model_url",
15958
16138
  "model_stl_url",
@@ -15968,7 +16148,7 @@ var convertModelUrlsToFileUrls = (circuitJson) => {
15968
16148
  if (!element || typeof element !== "object")
15969
16149
  return element;
15970
16150
  const updated = { ...element };
15971
- for (const key of modelUrlKeys) {
16151
+ for (const key of modelUrlKeys2) {
15972
16152
  const value = updated[key];
15973
16153
  if (typeof value === "string" && value.length > 0) {
15974
16154
  if (value.match(/^[a-zA-Z]+:\/\//))
@@ -15985,12 +16165,12 @@ var convertModelUrlsToFileUrls = (circuitJson) => {
15985
16165
  };
15986
16166
 
15987
16167
  // cli/build/worker-binary-utils.ts
15988
- var viewToArrayBuffer = (view) => {
16168
+ var viewToArrayBuffer2 = (view) => {
15989
16169
  const copy = new Uint8Array(view.byteLength);
15990
16170
  copy.set(new Uint8Array(view.buffer, view.byteOffset, view.byteLength));
15991
16171
  return copy.buffer;
15992
16172
  };
15993
- var normalizeToUint8Array = (value) => {
16173
+ var normalizeToUint8Array2 = (value) => {
15994
16174
  if (value instanceof Uint8Array) {
15995
16175
  return value;
15996
16176
  }
@@ -15998,26 +16178,10 @@ var normalizeToUint8Array = (value) => {
15998
16178
  return new Uint8Array(value);
15999
16179
  }
16000
16180
  if (ArrayBuffer.isView(value)) {
16001
- return new Uint8Array(viewToArrayBuffer(value));
16181
+ return new Uint8Array(viewToArrayBuffer2(value));
16002
16182
  }
16003
16183
  throw new Error("Expected Uint8Array, ArrayBuffer, or ArrayBufferView for binary data");
16004
16184
  };
16005
- var normalizeToArrayBuffer = async (value) => {
16006
- if (value instanceof ArrayBuffer) {
16007
- return value;
16008
- }
16009
- if (ArrayBuffer.isView(value)) {
16010
- return viewToArrayBuffer(value);
16011
- }
16012
- if (value && typeof value === "object") {
16013
- const maybeArrayBufferLike = value;
16014
- if (typeof maybeArrayBufferLike.arrayBuffer === "function") {
16015
- const result = maybeArrayBufferLike.arrayBuffer();
16016
- return result instanceof Promise ? await result : result;
16017
- }
16018
- }
16019
- throw new Error("Expected ArrayBuffer, ArrayBufferView, or Buffer-compatible object");
16020
- };
16021
16185
 
16022
16186
  // cli/build/svg-to-png.ts
16023
16187
  import { Resvg } from "@resvg/resvg-js";
@@ -16107,7 +16271,7 @@ var writeSimulationSvgAssetsFromCircuitJson = (circuitJson, outputDir, imageForm
16107
16271
  var writeGlbFromCircuitJson = async (circuitJson, glbOutputPath) => {
16108
16272
  const circuitJsonWithFileUrls = convertModelUrlsToFileUrls(circuitJson);
16109
16273
  const glbBuffer = await convertCircuitJsonToGltf(circuitJsonWithFileUrls, getCircuitJsonToGltfOptions({ format: "glb" }));
16110
- const glbData = normalizeToUint8Array(glbBuffer);
16274
+ const glbData = normalizeToUint8Array2(glbBuffer);
16111
16275
  fs9.mkdirSync(path13.dirname(glbOutputPath), { recursive: true });
16112
16276
  fs9.writeFileSync(glbOutputPath, Buffer.from(glbData));
16113
16277
  };
@@ -16137,11 +16301,8 @@ var writeImageAssetsFromCircuitJson = async (circuitJson, options) => {
16137
16301
  }
16138
16302
  writeSimulationSvgAssetsFromCircuitJson(circuitJson, outputDir, imageFormats);
16139
16303
  if (imageFormats.threeDPngs) {
16140
- const circuitJsonWithFileUrls = convertModelUrlsToFileUrls(circuitJson);
16141
- const glbBuffer = await convertCircuitJsonToGltf(circuitJsonWithFileUrls, getCircuitJsonToGltfOptions({ format: "glb" }));
16142
- const glbArrayBuffer = await normalizeToArrayBuffer(glbBuffer);
16143
- const pngBuffer = await renderGLTFToPNGFromGLB(glbArrayBuffer, getBestCameraPosition(circuitJson));
16144
- fs9.writeFileSync(path13.join(outputDir, "3d.png"), Buffer.from(normalizeToUint8Array(pngBuffer)));
16304
+ const pngBuffer = await renderCircuitJsonTo3dPng(circuitJson);
16305
+ fs9.writeFileSync(path13.join(outputDir, "3d.png"), Buffer.from(pngBuffer));
16145
16306
  }
16146
16307
  };
16147
16308