@tscircuit/core 0.0.992 → 0.0.993

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/dist/index.d.ts CHANGED
@@ -123664,7 +123664,7 @@ declare class SchematicPath extends PrimitiveComponent<typeof schematicPathProps
123664
123664
  get config(): {
123665
123665
  componentName: string;
123666
123666
  zodProps: zod.ZodObject<{
123667
- points: zod.ZodArray<zod.ZodObject<{
123667
+ points: zod.ZodOptional<zod.ZodArray<zod.ZodObject<{
123668
123668
  x: zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>;
123669
123669
  y: zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>;
123670
123670
  }, "strip", zod.ZodTypeAny, {
@@ -123673,28 +123673,28 @@ declare class SchematicPath extends PrimitiveComponent<typeof schematicPathProps
123673
123673
  }, {
123674
123674
  x: string | number;
123675
123675
  y: string | number;
123676
- }>, "many">;
123676
+ }>, "many">>;
123677
123677
  svgPath: zod.ZodOptional<zod.ZodString>;
123678
123678
  strokeWidth: zod.ZodOptional<zod.ZodEffects<zod.ZodUnion<[zod.ZodString, zod.ZodNumber]>, number, string | number>>;
123679
123679
  strokeColor: zod.ZodOptional<zod.ZodString>;
123680
123680
  isFilled: zod.ZodDefault<zod.ZodOptional<zod.ZodBoolean>>;
123681
123681
  fillColor: zod.ZodOptional<zod.ZodEnum<["red", "blue"]>>;
123682
123682
  }, "strip", zod.ZodTypeAny, {
123683
- points: {
123684
- x: number;
123685
- y: number;
123686
- }[];
123687
123683
  isFilled: boolean;
123688
123684
  strokeWidth?: number | undefined;
123685
+ points?: {
123686
+ x: number;
123687
+ y: number;
123688
+ }[] | undefined;
123689
123689
  fillColor?: "red" | "blue" | undefined;
123690
123690
  svgPath?: string | undefined;
123691
123691
  strokeColor?: string | undefined;
123692
123692
  }, {
123693
- points: {
123693
+ strokeWidth?: string | number | undefined;
123694
+ points?: {
123694
123695
  x: string | number;
123695
123696
  y: string | number;
123696
- }[];
123697
- strokeWidth?: string | number | undefined;
123697
+ }[] | undefined;
123698
123698
  isFilled?: boolean | undefined;
123699
123699
  fillColor?: "red" | "blue" | undefined;
123700
123700
  svgPath?: string | undefined;
package/dist/index.js CHANGED
@@ -20340,6 +20340,136 @@ var SchematicCircle = class extends PrimitiveComponent2 {
20340
20340
 
20341
20341
  // lib/components/primitive-components/SchematicPath.ts
20342
20342
  import { schematicPathProps } from "@tscircuit/props";
20343
+
20344
+ // lib/utils/schematic/svgPathToPoints.ts
20345
+ import SVGPathCommander from "svg-path-commander";
20346
+ function sampleCurveSegment(segmentPath, samplesPerUnit) {
20347
+ const commander = new SVGPathCommander(segmentPath);
20348
+ const length7 = commander.getTotalLength();
20349
+ const numSamples = Math.max(2, Math.ceil(length7 * samplesPerUnit));
20350
+ const points = [];
20351
+ for (let i = 1; i <= numSamples; i++) {
20352
+ const t = i / numSamples * length7;
20353
+ const point6 = commander.getPointAtLength(t);
20354
+ points.push({ x: point6.x, y: point6.y });
20355
+ }
20356
+ return points;
20357
+ }
20358
+ function svgPathToPoints(svgPath, samplesPerUnit = 10) {
20359
+ const pathCommander = new SVGPathCommander(svgPath);
20360
+ pathCommander.toAbsolute();
20361
+ const segments = pathCommander.segments;
20362
+ const result = [];
20363
+ let currentPoints = [];
20364
+ let currentX = 0;
20365
+ let currentY = 0;
20366
+ let subpathStartX = 0;
20367
+ let subpathStartY = 0;
20368
+ for (const segment2 of segments) {
20369
+ const cmd = segment2[0];
20370
+ switch (cmd) {
20371
+ case "M": {
20372
+ if (currentPoints.length > 0) {
20373
+ result.push(currentPoints);
20374
+ }
20375
+ currentX = segment2[1];
20376
+ currentY = segment2[2];
20377
+ subpathStartX = currentX;
20378
+ subpathStartY = currentY;
20379
+ currentPoints = [{ x: currentX, y: currentY }];
20380
+ break;
20381
+ }
20382
+ case "L": {
20383
+ currentX = segment2[1];
20384
+ currentY = segment2[2];
20385
+ currentPoints.push({ x: currentX, y: currentY });
20386
+ break;
20387
+ }
20388
+ case "H": {
20389
+ currentX = segment2[1];
20390
+ currentPoints.push({ x: currentX, y: currentY });
20391
+ break;
20392
+ }
20393
+ case "V": {
20394
+ currentY = segment2[1];
20395
+ currentPoints.push({ x: currentX, y: currentY });
20396
+ break;
20397
+ }
20398
+ case "Z": {
20399
+ if (currentX !== subpathStartX || currentY !== subpathStartY) {
20400
+ currentPoints.push({ x: subpathStartX, y: subpathStartY });
20401
+ }
20402
+ currentX = subpathStartX;
20403
+ currentY = subpathStartY;
20404
+ break;
20405
+ }
20406
+ case "C": {
20407
+ const endX = segment2[5];
20408
+ const endY = segment2[6];
20409
+ const segmentPath = `M ${currentX} ${currentY} C ${segment2[1]} ${segment2[2]} ${segment2[3]} ${segment2[4]} ${endX} ${endY}`;
20410
+ const sampledPoints = sampleCurveSegment(segmentPath, samplesPerUnit);
20411
+ currentPoints.push(...sampledPoints);
20412
+ currentX = endX;
20413
+ currentY = endY;
20414
+ break;
20415
+ }
20416
+ case "S": {
20417
+ const endX = segment2[3];
20418
+ const endY = segment2[4];
20419
+ const segmentPath = `M ${currentX} ${currentY} S ${segment2[1]} ${segment2[2]} ${endX} ${endY}`;
20420
+ const sampledPoints = sampleCurveSegment(segmentPath, samplesPerUnit);
20421
+ currentPoints.push(...sampledPoints);
20422
+ currentX = endX;
20423
+ currentY = endY;
20424
+ break;
20425
+ }
20426
+ case "Q": {
20427
+ const endX = segment2[3];
20428
+ const endY = segment2[4];
20429
+ const segmentPath = `M ${currentX} ${currentY} Q ${segment2[1]} ${segment2[2]} ${endX} ${endY}`;
20430
+ const sampledPoints = sampleCurveSegment(segmentPath, samplesPerUnit);
20431
+ currentPoints.push(...sampledPoints);
20432
+ currentX = endX;
20433
+ currentY = endY;
20434
+ break;
20435
+ }
20436
+ case "T": {
20437
+ const endX = segment2[1];
20438
+ const endY = segment2[2];
20439
+ const segmentPath = `M ${currentX} ${currentY} T ${endX} ${endY}`;
20440
+ const sampledPoints = sampleCurveSegment(segmentPath, samplesPerUnit);
20441
+ currentPoints.push(...sampledPoints);
20442
+ currentX = endX;
20443
+ currentY = endY;
20444
+ break;
20445
+ }
20446
+ case "A": {
20447
+ const endX = segment2[6];
20448
+ const endY = segment2[7];
20449
+ const segmentPath = `M ${currentX} ${currentY} A ${segment2[1]} ${segment2[2]} ${segment2[3]} ${segment2[4]} ${segment2[5]} ${endX} ${endY}`;
20450
+ const sampledPoints = sampleCurveSegment(segmentPath, samplesPerUnit);
20451
+ currentPoints.push(...sampledPoints);
20452
+ currentX = endX;
20453
+ currentY = endY;
20454
+ break;
20455
+ }
20456
+ }
20457
+ }
20458
+ if (currentPoints.length > 0) {
20459
+ result.push(currentPoints);
20460
+ }
20461
+ return result.map((points) => {
20462
+ const deduped = [];
20463
+ for (const point6 of points) {
20464
+ if (deduped.length === 0 || Math.abs(deduped[deduped.length - 1].x - point6.x) > 1e-9 || Math.abs(deduped[deduped.length - 1].y - point6.y) > 1e-9) {
20465
+ deduped.push(point6);
20466
+ }
20467
+ }
20468
+ return deduped;
20469
+ });
20470
+ }
20471
+
20472
+ // lib/components/primitive-components/SchematicPath.ts
20343
20473
  var SchematicPath = class extends PrimitiveComponent2 {
20344
20474
  isSchematicPrimitive = true;
20345
20475
  get config() {
@@ -20354,19 +20484,37 @@ var SchematicPath = class extends PrimitiveComponent2 {
20354
20484
  const { _parsedProps: props } = this;
20355
20485
  const globalPos = this._getGlobalSchematicPositionBeforeLayout();
20356
20486
  const schematic_component_id = this.getPrimitiveContainer()?.parent?.schematic_component_id;
20357
- db.schematic_path.insert({
20358
- schematic_component_id,
20359
- points: props.points.map((point6) => ({
20360
- x: point6.x + globalPos.x,
20361
- y: point6.y + globalPos.y
20362
- })),
20363
- is_filled: props.isFilled,
20364
- fill_color: props.fillColor,
20365
- stroke_color: props.strokeColor,
20366
- stroke_width: props.strokeWidth,
20367
- svg_path: props.svgPath,
20368
- subcircuit_id: this.getSubcircuit().subcircuit_id ?? void 0
20369
- });
20487
+ const subcircuit_id = this.getSubcircuit().subcircuit_id ?? void 0;
20488
+ if (props.svgPath) {
20489
+ const subpaths = svgPathToPoints(props.svgPath);
20490
+ for (const subpathPoints of subpaths) {
20491
+ db.schematic_path.insert({
20492
+ schematic_component_id,
20493
+ points: subpathPoints.map((point6) => ({
20494
+ x: point6.x + globalPos.x,
20495
+ y: point6.y + globalPos.y
20496
+ })),
20497
+ is_filled: props.isFilled,
20498
+ fill_color: props.fillColor,
20499
+ stroke_color: props.strokeColor,
20500
+ stroke_width: props.strokeWidth,
20501
+ subcircuit_id
20502
+ });
20503
+ }
20504
+ } else if (props.points && props.points.length > 0) {
20505
+ db.schematic_path.insert({
20506
+ schematic_component_id,
20507
+ points: props.points.map((point6) => ({
20508
+ x: point6.x + globalPos.x,
20509
+ y: point6.y + globalPos.y
20510
+ })),
20511
+ is_filled: props.isFilled,
20512
+ fill_color: props.fillColor,
20513
+ stroke_color: props.strokeColor,
20514
+ stroke_width: props.strokeWidth,
20515
+ subcircuit_id
20516
+ });
20517
+ }
20370
20518
  }
20371
20519
  };
20372
20520
 
@@ -21036,7 +21184,7 @@ import { identity as identity5 } from "transformation-matrix";
21036
21184
  var package_default = {
21037
21185
  name: "@tscircuit/core",
21038
21186
  type: "module",
21039
- version: "0.0.991",
21187
+ version: "0.0.992",
21040
21188
  types: "dist/index.d.ts",
21041
21189
  main: "dist/index.js",
21042
21190
  module: "dist/index.js",
@@ -21079,7 +21227,7 @@ var package_default = {
21079
21227
  "@tscircuit/math-utils": "^0.0.29",
21080
21228
  "@tscircuit/miniflex": "^0.0.4",
21081
21229
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
21082
- "@tscircuit/props": "^0.0.455",
21230
+ "@tscircuit/props": "^0.0.456",
21083
21231
  "@tscircuit/schematic-match-adapt": "^0.0.16",
21084
21232
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
21085
21233
  "@tscircuit/solver-utils": "^0.0.3",
@@ -21092,7 +21240,7 @@ var package_default = {
21092
21240
  "bun-match-svg": "0.0.12",
21093
21241
  "calculate-elbow": "^0.0.12",
21094
21242
  "chokidar-cli": "^3.0.0",
21095
- "circuit-json": "^0.0.363",
21243
+ "circuit-json": "^0.0.364",
21096
21244
  "circuit-json-to-bpc": "^0.0.13",
21097
21245
  "circuit-json-to-connectivity-map": "^0.0.23",
21098
21246
  "circuit-json-to-gltf": "^0.0.31",
@@ -21145,6 +21293,7 @@ var package_default = {
21145
21293
  nanoid: "^5.0.7",
21146
21294
  "performance-now": "^2.1.0",
21147
21295
  "react-reconciler": "^0.32.0",
21296
+ "svg-path-commander": "^2.1.11",
21148
21297
  "transformation-matrix": "^2.16.1",
21149
21298
  zod: "^3.25.67"
21150
21299
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tscircuit/core",
3
3
  "type": "module",
4
- "version": "0.0.992",
4
+ "version": "0.0.993",
5
5
  "types": "dist/index.d.ts",
6
6
  "main": "dist/index.js",
7
7
  "module": "dist/index.js",
@@ -44,7 +44,7 @@
44
44
  "@tscircuit/math-utils": "^0.0.29",
45
45
  "@tscircuit/miniflex": "^0.0.4",
46
46
  "@tscircuit/ngspice-spice-engine": "^0.0.8",
47
- "@tscircuit/props": "^0.0.455",
47
+ "@tscircuit/props": "^0.0.456",
48
48
  "@tscircuit/schematic-match-adapt": "^0.0.16",
49
49
  "@tscircuit/schematic-trace-solver": "^v0.0.45",
50
50
  "@tscircuit/solver-utils": "^0.0.3",
@@ -57,7 +57,7 @@
57
57
  "bun-match-svg": "0.0.12",
58
58
  "calculate-elbow": "^0.0.12",
59
59
  "chokidar-cli": "^3.0.0",
60
- "circuit-json": "^0.0.363",
60
+ "circuit-json": "^0.0.364",
61
61
  "circuit-json-to-bpc": "^0.0.13",
62
62
  "circuit-json-to-connectivity-map": "^0.0.23",
63
63
  "circuit-json-to-gltf": "^0.0.31",
@@ -110,6 +110,7 @@
110
110
  "nanoid": "^5.0.7",
111
111
  "performance-now": "^2.1.0",
112
112
  "react-reconciler": "^0.32.0",
113
+ "svg-path-commander": "^2.1.11",
113
114
  "transformation-matrix": "^2.16.1",
114
115
  "zod": "^3.25.67"
115
116
  }