smithkit 0.1.0 → 0.2.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.
Files changed (132) hide show
  1. package/README.md +124 -59
  2. package/dist/lib/MarkerMeasurements.d.ts +6 -0
  3. package/dist/lib/MarkerMeasurements.js +22 -0
  4. package/dist/lib/Smith.d.ts +9 -2
  5. package/dist/lib/Smith.js +78 -35
  6. package/dist/lib/SmithFormatter.d.ts +10 -0
  7. package/dist/lib/SmithFormatter.js +19 -0
  8. package/dist/lib/grid/CircleLayerControl.d.ts +15 -0
  9. package/dist/lib/grid/CircleLayerControl.js +40 -0
  10. package/dist/lib/{draw → grid}/ConstCircles.d.ts +6 -6
  11. package/dist/lib/{draw → grid}/ConstCircles.js +12 -5
  12. package/dist/lib/{draw → grid}/ConstQCircles.d.ts +2 -2
  13. package/dist/lib/{draw → grid}/ConstQCircles.js +3 -3
  14. package/dist/lib/{draw → grid}/ConstSwrCircles.d.ts +2 -2
  15. package/dist/lib/{draw → grid}/ConstSwrCircles.js +3 -3
  16. package/dist/lib/grid/GridDefinitions.d.ts +12 -0
  17. package/dist/lib/grid/GridDefinitions.js +138 -0
  18. package/dist/lib/grid/GridGeometry.d.ts +26 -0
  19. package/dist/lib/grid/GridGeometry.js +58 -0
  20. package/dist/lib/grid/GridLabels.d.ts +8 -0
  21. package/dist/lib/grid/GridLabels.js +45 -0
  22. package/dist/lib/grid/GridLayerControl.d.ts +12 -0
  23. package/dist/lib/grid/GridLayerControl.js +39 -0
  24. package/dist/lib/grid/LayerControl.d.ts +6 -0
  25. package/dist/lib/grid/LayerControl.js +16 -0
  26. package/dist/lib/{draw → grid}/SmithGridLayer.d.ts +5 -4
  27. package/dist/lib/{draw → grid}/SmithGridLayer.js +26 -9
  28. package/dist/lib/grid/types.d.ts +1 -1
  29. package/dist/lib/index.d.ts +8 -10
  30. package/dist/lib/index.js +5 -7
  31. package/dist/lib/{draw → interaction}/SmithCursor.d.ts +3 -3
  32. package/dist/lib/{draw → interaction}/SmithCursor.js +6 -6
  33. package/dist/lib/io/Touchstone.d.ts +10 -0
  34. package/dist/lib/io/Touchstone.js +75 -0
  35. package/dist/lib/layers.d.ts +2 -8
  36. package/dist/lib/layers.js +1 -73
  37. package/dist/lib/{complex → math}/Complex.d.ts +1 -0
  38. package/dist/lib/{complex → math}/Complex.js +1 -1
  39. package/dist/lib/math/geometry.d.ts +14 -0
  40. package/dist/lib/measurements.d.ts +2 -4
  41. package/dist/lib/measurements.js +1 -19
  42. package/dist/lib/rf/RfCalculations.d.ts +65 -0
  43. package/dist/lib/rf/RfCalculations.js +161 -0
  44. package/dist/lib/{SmithConstantCircle.d.ts → rf/SmithConstantCircle.d.ts} +2 -3
  45. package/dist/lib/{SmithConstantCircle.js → rf/SmithConstantCircle.js} +3 -4
  46. package/dist/lib/scales/PeripheralScaleDefinitions.d.ts +16 -0
  47. package/dist/lib/scales/PeripheralScaleDefinitions.js +54 -0
  48. package/dist/lib/scales/RadialScaleDefinitions.d.ts +15 -0
  49. package/dist/lib/scales/RadialScaleDefinitions.js +112 -0
  50. package/dist/lib/scales/SmithPeripheralScales.d.ts +7 -2
  51. package/dist/lib/scales/SmithPeripheralScales.js +65 -28
  52. package/dist/lib/scales/SmithScales.d.ts +3 -1
  53. package/dist/lib/scales/SmithScales.js +20 -6
  54. package/dist/lib/svg/LabelLayout.d.ts +17 -0
  55. package/dist/lib/svg/LabelLayout.js +145 -0
  56. package/dist/lib/{draw → svg}/SmithArc.d.ts +1 -1
  57. package/dist/lib/{draw → svg}/SmithCircle.d.ts +1 -1
  58. package/dist/lib/{draw → svg}/SmithLine.d.ts +1 -1
  59. package/dist/lib/{draw → svg}/SmithScaler.d.ts +1 -4
  60. package/dist/lib/{draw → svg}/SmithText.d.ts +1 -1
  61. package/dist/lib/svg/SvgExporter.d.ts +14 -0
  62. package/dist/lib/svg/SvgExporter.js +137 -0
  63. package/dist/lib/{draw → traces}/SmithData.d.ts +24 -35
  64. package/dist/lib/traces/SmithData.js +195 -0
  65. package/dist/lib/{draw → traces}/SmithMarker.d.ts +14 -3
  66. package/dist/lib/traces/SmithMarker.js +237 -0
  67. package/dist/lib/traces/TraceModel.d.ts +31 -0
  68. package/dist/lib/traces/TraceModel.js +123 -0
  69. package/dist/lib/traces/TraceRenderer.d.ts +33 -0
  70. package/dist/lib/traces/TraceRenderer.js +152 -0
  71. package/package.json +4 -1
  72. package/dist/lib/SmithArcsDefs.d.ts +0 -10
  73. package/dist/lib/SmithArcsDefs.js +0 -10
  74. package/dist/lib/components.d.ts +0 -14
  75. package/dist/lib/components.js +0 -26
  76. package/dist/lib/draw/SmithData.js +0 -366
  77. package/dist/lib/draw/SmithMarker.js +0 -122
  78. package/dist/lib/formatting.d.ts +0 -7
  79. package/dist/lib/formatting.js +0 -16
  80. package/dist/lib/grid/definitions.d.ts +0 -3
  81. package/dist/lib/grid/definitions.js +0 -123
  82. package/dist/lib/grid/geometry.d.ts +0 -20
  83. package/dist/lib/grid/geometry.js +0 -55
  84. package/dist/lib/grid/labels.d.ts +0 -3
  85. package/dist/lib/grid/labels.js +0 -41
  86. package/dist/lib/io/touchstone.d.ts +0 -7
  87. package/dist/lib/io/touchstone.js +0 -72
  88. package/dist/lib/math/complexRatio.d.ts +0 -3
  89. package/dist/lib/math/complexRatio.js +0 -30
  90. package/dist/lib/renormalization.d.ts +0 -10
  91. package/dist/lib/renormalization.js +0 -62
  92. package/dist/lib/rf.d.ts +0 -35
  93. package/dist/lib/rf.js +0 -74
  94. package/dist/lib/scales/peripheralScales.d.ts +0 -12
  95. package/dist/lib/scales/peripheralScales.js +0 -49
  96. package/dist/lib/scales/radialScales.d.ts +0 -12
  97. package/dist/lib/scales/radialScales.js +0 -109
  98. package/dist/lib/shapes/Arc.d.ts +0 -6
  99. package/dist/lib/shapes/Circle.d.ts +0 -5
  100. package/dist/lib/shapes/Circle.js +0 -1
  101. package/dist/lib/shapes/Line.d.ts +0 -5
  102. package/dist/lib/shapes/Line.js +0 -1
  103. package/dist/lib/shapes/Point.d.ts +0 -1
  104. package/dist/lib/shapes/Point.js +0 -1
  105. /package/dist/lib/{draw → grid}/ConstConductance.d.ts +0 -0
  106. /package/dist/lib/{draw → grid}/ConstConductance.js +0 -0
  107. /package/dist/lib/{draw → grid}/ConstReactance.d.ts +0 -0
  108. /package/dist/lib/{draw → grid}/ConstReactance.js +0 -0
  109. /package/dist/lib/{draw → grid}/ConstResistance.d.ts +0 -0
  110. /package/dist/lib/{draw → grid}/ConstResistance.js +0 -0
  111. /package/dist/lib/{draw → grid}/ConstSusceptance.d.ts +0 -0
  112. /package/dist/lib/{draw → grid}/ConstSusceptance.js +0 -0
  113. /package/dist/lib/{arcs → grid}/Tick.d.ts +0 -0
  114. /package/dist/lib/{arcs → grid}/Tick.js +0 -0
  115. /package/dist/lib/{draw → interaction}/MouseGesture.d.ts +0 -0
  116. /package/dist/lib/{draw → interaction}/MouseGesture.js +0 -0
  117. /package/dist/lib/{draw/SmithDrawOptions.js → math/geometry.js} +0 -0
  118. /package/dist/lib/{draw → svg}/SmithArc.js +0 -0
  119. /package/dist/lib/{draw → svg}/SmithCircle.js +0 -0
  120. /package/dist/lib/{draw → svg}/SmithDrawOptions.d.ts +0 -0
  121. /package/dist/lib/{shapes/Arc.js → svg/SmithDrawOptions.js} +0 -0
  122. /package/dist/lib/{draw → svg}/SmithGroup.d.ts +0 -0
  123. /package/dist/lib/{draw → svg}/SmithGroup.js +0 -0
  124. /package/dist/lib/{draw → svg}/SmithLine.js +0 -0
  125. /package/dist/lib/{draw → svg}/SmithPath.d.ts +0 -0
  126. /package/dist/lib/{draw → svg}/SmithPath.js +0 -0
  127. /package/dist/lib/{draw → svg}/SmithScaler.js +0 -0
  128. /package/dist/lib/{draw → svg}/SmithShape.d.ts +0 -0
  129. /package/dist/lib/{draw → svg}/SmithShape.js +0 -0
  130. /package/dist/lib/{draw → svg}/SmithSvg.d.ts +0 -0
  131. /package/dist/lib/{draw → svg}/SmithSvg.js +0 -0
  132. /package/dist/lib/{draw → svg}/SmithText.js +0 -0
package/dist/lib/rf.js DELETED
@@ -1,74 +0,0 @@
1
- import { Complex } from './complex/Complex.js';
2
- import { SmithConstantCircle } from './SmithConstantCircle.js';
3
- const calcs = new SmithConstantCircle();
4
- function validateReference(referenceImpedanceOhms) {
5
- if (!Number.isFinite(referenceImpedanceOhms) || referenceImpedanceOhms <= 0) {
6
- throw new RangeError('Reference impedance must be positive and finite.');
7
- }
8
- }
9
- function validateComplex(value) {
10
- if (!Number.isFinite(value.re) || !Number.isFinite(value.im)) {
11
- throw new RangeError('Complex components must be finite.');
12
- }
13
- }
14
- function finite(value) {
15
- return value && Number.isFinite(value.re) && Number.isFinite(value.im) ? value : undefined;
16
- }
17
- /** Convert Γ to physical impedance in ohms; undefined at the open circuit Γ = 1. */
18
- export function reflectionToImpedance(gamma, referenceImpedanceOhms = 50) {
19
- validateReference(referenceImpedanceOhms);
20
- validateComplex(gamma);
21
- return finite(calcs.rflCoeffToImpedance(gamma)?.mul(referenceImpedanceOhms));
22
- }
23
- /** Convert physical impedance in ohms to Γ. Undefined for a singular result. */
24
- export function impedanceToReflection(impedanceOhms, referenceImpedanceOhms = 50) {
25
- validateReference(referenceImpedanceOhms);
26
- validateComplex(impedanceOhms);
27
- return finite(calcs.impedanceToRflCoeff(impedanceOhms.div(referenceImpedanceOhms)));
28
- }
29
- /** Convert Γ to physical admittance in siemens; undefined at the short circuit Γ = −1. */
30
- export function reflectionToAdmittance(gamma, referenceImpedanceOhms = 50) {
31
- validateReference(referenceImpedanceOhms);
32
- validateComplex(gamma);
33
- return finite(calcs.rflCoeffToAdmittance(gamma)?.div(referenceImpedanceOhms));
34
- }
35
- /** Convert physical admittance in siemens to Γ. Undefined for a singular result. */
36
- export function admittanceToReflection(admittanceSiemens, referenceImpedanceOhms = 50) {
37
- validateReference(referenceImpedanceOhms);
38
- validateComplex(admittanceSiemens);
39
- return finite(calcs.admittanceToRflCoeff(admittanceSiemens.mul(referenceImpedanceOhms)));
40
- }
41
- /**
42
- * Read Γ without a chart or DOM. Undefined means a singular or inapplicable quantity.
43
- * Passive-load quantities are undefined outside |Γ| ≤ 1; exact infinite limits are retained.
44
- * Attenuation assumes a fully reflecting termination and is half the return loss.
45
- */
46
- export function readReflection(gamma, referenceImpedanceOhms = 50) {
47
- const impedanceOhms = reflectionToImpedance(gamma, referenceImpedanceOhms);
48
- const admittanceSiemens = reflectionToAdmittance(gamma, referenceImpedanceOhms);
49
- const magnitude = gamma.abs();
50
- const passive = magnitude <= 1;
51
- const returnLossDb = -20 * Math.log10(magnitude);
52
- const vswr = passive ? (1 + magnitude) / (1 - magnitude) : undefined;
53
- return {
54
- reflectionCoefficient: gamma,
55
- impedanceOhms,
56
- admittanceSiemens,
57
- phaseDegrees: magnitude === 0 ? undefined : (gamma.arg() * 180) / Math.PI,
58
- vswr,
59
- standingWaveRatioDb: vswr === undefined ? undefined : 20 * Math.log10(vswr),
60
- returnLossDb,
61
- reflectionLossDb: passive ? (-10 / Math.LN10) * Math.log1p(-(magnitude ** 2)) : undefined,
62
- attenuationDb: passive ? returnLossDb / 2 : undefined,
63
- q: impedanceOhms && (impedanceOhms.re !== 0 || impedanceOhms.im !== 0)
64
- ? Math.abs(impedanceOhms.im / impedanceOhms.re)
65
- : undefined,
66
- powerReflectionCoefficient: magnitude ** 2,
67
- voltageReflectionCoefficientMagnitude: magnitude,
68
- powerTransmissionCoefficient: passive ? 1 - magnitude ** 2 : undefined,
69
- voltageTransmissionCoefficientMagnitude: gamma.add(1).abs(),
70
- currentTransmissionCoefficientMagnitude: Complex.one().sub(gamma).abs(),
71
- standingWavePeak: vswr === undefined ? undefined : Math.sqrt(vswr),
72
- standingWaveLossCoefficient: passive ? (1 + magnitude ** 2) / (1 - magnitude ** 2) : undefined,
73
- };
74
- }
@@ -1,12 +0,0 @@
1
- import type { Complex } from '../complex/Complex.js';
2
- export interface PeripheralScale {
3
- id: string;
4
- title: string;
5
- unit: '°' | 'λ';
6
- ticks: number[];
7
- major: (value: number) => boolean;
8
- angle: (value: number) => number;
9
- read: (gamma: Complex) => number | null;
10
- }
11
- /** A full reflection-coefficient rotation represents half a wavelength along the line. */
12
- export declare function peripheralScales(): PeripheralScale[];
@@ -1,49 +0,0 @@
1
- function phase(gamma) {
2
- return gamma.re === 0 && gamma.im === 0 ? null : (Math.atan2(gamma.im, gamma.re) * 180) / Math.PI;
3
- }
4
- /** A full reflection-coefficient rotation represents half a wavelength along the line. */
5
- export function peripheralScales() {
6
- const wavelengths = (gamma, direction) => {
7
- const degrees = phase(gamma);
8
- return degrees === null ? null : (0.25 + (direction * degrees) / 720 + 0.5) % 0.5;
9
- };
10
- return [
11
- {
12
- id: 'transmission-phase',
13
- title: 'Transmission phase · °',
14
- unit: '°',
15
- ticks: Array.from({ length: 179 }, (_, i) => -89 + i),
16
- major: (v) => v % 5 === 0,
17
- // Project from Γ = −1 to the perimeter, not from the chart center.
18
- angle: (v) => 2 * v,
19
- read: (gamma) => phase({ re: 1 + gamma.re, im: gamma.im }),
20
- },
21
- {
22
- id: 'reflection-phase',
23
- title: 'Reflection phase · °',
24
- unit: '°',
25
- ticks: Array.from({ length: 180 }, (_, i) => -178 + i * 2),
26
- major: (v) => v % 10 === 0,
27
- angle: (v) => v,
28
- read: phase,
29
- },
30
- {
31
- id: 'wavelengths-load',
32
- title: 'Wavelengths → load',
33
- unit: 'λ',
34
- ticks: Array.from({ length: 250 }, (_, i) => i / 500),
35
- major: (v) => Math.round(v * 500) % 5 === 0,
36
- angle: (v) => 720 * v - 180,
37
- read: (gamma) => wavelengths(gamma, 1),
38
- },
39
- {
40
- id: 'wavelengths-generator',
41
- title: 'Wavelengths → generator',
42
- unit: 'λ',
43
- ticks: Array.from({ length: 250 }, (_, i) => i / 500),
44
- major: (v) => Math.round(v * 500) % 5 === 0,
45
- angle: (v) => 180 - 720 * v,
46
- read: (gamma) => wavelengths(gamma, -1),
47
- },
48
- ];
49
- }
@@ -1,12 +0,0 @@
1
- import type { Complex } from '../complex/Complex.js';
2
- export interface RadialScale {
3
- id: string;
4
- title: string;
5
- description?: string;
6
- unit: 'dB' | 'ratio';
7
- read: (gamma: Complex) => number;
8
- values: number[];
9
- position: (value: number) => number;
10
- }
11
- /** Normalized positions along each scale, from zero to one. */
12
- export declare function radialScales(): RadialScale[];
@@ -1,109 +0,0 @@
1
- import { SmithConstantCircle } from '../SmithConstantCircle.js';
2
- /** Normalized positions along each scale, from zero to one. */
3
- export function radialScales() {
4
- const calcs = new SmithConstantCircle();
5
- return [
6
- {
7
- id: 'vswr',
8
- unit: 'ratio',
9
- read: (gamma) => calcs.rflCoeffToSwr(gamma),
10
- title: 'VSWR',
11
- values: [1, 1.5, 2, 3, 5, 10, Infinity],
12
- position: (v) => (v === Infinity ? 1 : calcs.swrToRflCoeffEOrI(v)),
13
- },
14
- {
15
- id: 'vswr-db',
16
- unit: 'dB',
17
- read: (gamma) => calcs.rflCoeffToDBS(gamma),
18
- title: 'Standing-wave ratio · dB',
19
- values: [0, 3, 6, 10, 15, 20, Infinity],
20
- position: (v) => (v === Infinity ? 1 : calcs.dBSToAbsRflCoeff(v)),
21
- },
22
- {
23
- id: 'return-loss',
24
- unit: 'dB',
25
- read: (gamma) => calcs.rflCoeffToReturnLoss(gamma),
26
- title: 'Return loss · dB',
27
- values: [Infinity, 20, 14, 10, 6, 3, 0],
28
- position: (v) => calcs.returnLossToRflCoeffEOrI(v),
29
- },
30
- {
31
- id: 'mismatch-loss',
32
- unit: 'dB',
33
- read: (gamma) => calcs.rflCoeffToMismatchLoss(gamma),
34
- title: 'Reflection loss · dB',
35
- description: 'Reflection loss (mismatch loss): −10 log10(1 − |Γ|²), in dB.',
36
- values: [0, 0.1, 0.5, 1, 2, 4, Infinity],
37
- position: (v) => calcs.mismatchLossToRflCoeffEOrI(v),
38
- },
39
- {
40
- id: 'reflected-power',
41
- unit: 'ratio',
42
- read: (gamma) => calcs.rflCoeffP(gamma),
43
- title: 'Power reflection coefficient',
44
- description: 'Reflected power divided by incident power: |Γ|² (dimensionless).',
45
- values: [0, 0.01, 0.1, 0.25, 0.5, 0.75, 1],
46
- position: (v) => calcs.rflCoeffPToEOrI(v),
47
- },
48
- {
49
- id: 'transmitted-power',
50
- unit: 'ratio',
51
- read: (gamma) => calcs.rflCoeffToTransmCoeffP(gamma),
52
- title: 'Power transmission coefficient',
53
- description: 'Net power delivered to the load divided by incident power: 1 − |Γ|² (dimensionless).',
54
- values: [1, 0.99, 0.9, 0.75, 0.5, 0.25, 0],
55
- position: (v) => calcs.transmCoeffPToRflCoeffEOrI(v),
56
- },
57
- {
58
- id: 'standing-wave-loss',
59
- unit: 'ratio',
60
- read: (gamma) => calcs.rflCoeffToSwLossCoeff(gamma),
61
- title: 'Standing-wave loss coefficient',
62
- values: [1, 1.1, 1.5, 2, 3, 5, Infinity],
63
- position: (v) => (v === Infinity ? 1 : calcs.swLossCoeffToRflCoeffEOrI(v)),
64
- },
65
- {
66
- id: 'standing-wave-peak',
67
- unit: 'ratio',
68
- read: (gamma) => calcs.rflCoeffToSwPeakConstP(gamma),
69
- title: 'Standing-wave peak · constant power',
70
- values: [1, 1.2, 1.5, 2, 3, Infinity],
71
- position: (v) => (v === Infinity ? 1 : calcs.swPeakConstPToRflCoeffEOrI(v)),
72
- },
73
- {
74
- id: 'reflection-coefficient',
75
- unit: 'ratio',
76
- read: (gamma) => calcs.rflCoeffEOrI(gamma),
77
- title: 'Reflection coefficient · |Γ|',
78
- values: [0, 0.2, 0.4, 0.6, 0.8, 1],
79
- position: (v) => v,
80
- },
81
- {
82
- id: 'attenuation',
83
- unit: 'dB',
84
- read: (gamma) => calcs.rflCoeffToAttenuation(gamma),
85
- title: 'Attenuation · dB',
86
- description: 'One-way attenuation of a matched line or attenuator terminated in an open or short circuit. Not insertion loss of an arbitrary load.',
87
- values: [Infinity, 10, 7, 5, 3, 1, 0],
88
- position: (v) => calcs.attenuationToRflCoeff(v),
89
- },
90
- {
91
- id: 'voltage-transmission',
92
- unit: 'ratio',
93
- read: (gamma) => calcs.rflCoeffToTransmCoeffEOrI(gamma),
94
- title: 'Voltage transmission coefficient',
95
- description: 'Voltage transmission magnitude: |1 + Γ| (dimensionless).',
96
- values: [0, 0.4, 0.8, 1.2, 1.6, 2],
97
- position: (v) => v / 2,
98
- },
99
- {
100
- id: 'current-transmission',
101
- unit: 'ratio',
102
- read: (gamma) => calcs.rflCoeffToCurrentTransmission(gamma),
103
- title: 'Current transmission coefficient',
104
- description: 'Current transmission magnitude: |1 − Γ|, using the voltage reflection coefficient Γ (dimensionless).',
105
- values: [0, 0.4, 0.8, 1.2, 1.6, 2],
106
- position: (v) => v / 2,
107
- },
108
- ];
109
- }
@@ -1,6 +0,0 @@
1
- import { Point } from './Point.js';
2
- export interface Arc {
3
- p1: Point;
4
- p2: Point;
5
- r: number;
6
- }
@@ -1,5 +0,0 @@
1
- import { Point } from './Point.js';
2
- export interface Circle {
3
- p: Point;
4
- r: number;
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,5 +0,0 @@
1
- import { Point } from './Point.js';
2
- export interface Line {
3
- p1: Point;
4
- p2: Point;
5
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export type Point = [number, number];
@@ -1 +0,0 @@
1
- export {};
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes