@simtest-js/funnel 1.0.0-beta.2 → 1.0.0-beta.20

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/README.md ADDED
@@ -0,0 +1,176 @@
1
+ # @simtest-js/funnel
2
+
3
+ TypeScript / JavaScript SDK for the
4
+ [simtest-funnel](https://github.com/Symoptia/simtest-funnel) trajectory
5
+ comparison library. Thin wrapper around the Rust core compiled to
6
+ WebAssembly via `wasm-bindgen`.
7
+
8
+ See the workspace
9
+ [`README.md`](https://github.com/Symoptia/simtest-funnel#differences-from-lbnl-funnel)
10
+ for how this library differs from LBNL Funnel (signed errors,
11
+ `MissingReference` / `MissingTest` statuses, default tolerances).
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ pnpm add @simtest-js/funnel
17
+ # or: npm install @simtest-js/funnel
18
+ ```
19
+
20
+ ## Quick start
21
+
22
+ ```ts
23
+ import { compare, Status } from '@simtest-js/funnel';
24
+
25
+ const tRef = Float64Array.from({ length: 101 }, (_, i) => i / 100);
26
+ const yRef = tRef.map((t) => Math.sin(2 * Math.PI * t));
27
+ const yTest = yRef.map((y) => y + 0.01);
28
+
29
+ const result = compare(tRef, yRef, tRef, yTest, {
30
+ tolerances: { atoly: 0.05 },
31
+ });
32
+
33
+ if (result.status === Status.Pass) {
34
+ console.log('inside funnel');
35
+ } else {
36
+ console.log('status:', result.status, 'signed errors:', result.errorsY);
37
+ }
38
+ ```
39
+
40
+ `compare()` accepts `ArrayLike<number>` or `Float64Array` inputs and
41
+ returns a `CompareResult` whose `errorsY` array is **signed** — positive
42
+ above the upper bound, negative below the lower bound.
43
+
44
+ ## Tolerances
45
+
46
+ A tolerance field that is omitted, `undefined` or `null` is "not
47
+ given". The given coefficients are resolved **per axis** by the Rust
48
+ core — the same rule as the Rust, Python and CLI front ends, so
49
+ identical inputs give identical verdicts everywhere:
50
+
51
+ - x axis: `atolx`, `ltolx`, `rtolx`; y axis: `atoly`, `ltoly`, `rtoly`.
52
+ - An axis with **no** coefficient given gets its default: the x axis
53
+ all `0` (no time tolerance), the y axis `rtoly = 2e-3` (other
54
+ coefficients `0`).
55
+ - An axis with **at least one** coefficient given uses the given values
56
+ and `0` for the rest of that axis.
57
+ - An explicit `0` counts as given.
58
+
59
+ | You pass | Effective tolerances |
60
+ | --------------------------------------------- | --------------------------------------- |
61
+ | no `options`, `{}`, `{ tolerances: {} }` | `rtoly = 2e-3`, rest `0` |
62
+ | `{ tolerances: { atoly: 0.05 } }` | `atoly = 0.05`, rest `0` |
63
+ | `{ tolerances: { atolx: 0.5 } }` | `atolx = 0.5`, `rtoly = 2e-3`, rest `0` |
64
+ | `{ tolerances: { atolx: 0.5, atoly: 0.05 } }` | `atolx = 0.5`, `atoly = 0.05`, rest `0` |
65
+
66
+ There is **no tolerance in x (time) unless you give one**. With zero x
67
+ tolerance the x half-width is the `1e-10` floor: each test point is
68
+ checked only against the y band around the reference at the same x, so a
69
+ test curve that is shifted or delayed in time fails at steep edges even
70
+ when the shift is tiny. Give `atolx` (time units) when such shifts are
71
+ acceptable; a range-relative `rtolx` grows with the length of the record.
72
+
73
+ `xRange` restricts the comparison to an x-window; each bound is optional
74
+ (omitted, `undefined` or `null` = unbounded), so `{ xRange: { lo: 0.5 } }`
75
+ compares `x >= 0.5`. Results report ranges as `ResolvedXRange` with both
76
+ bounds present (`-Infinity` / `Infinity` when unbounded).
77
+
78
+ Only test points inside the window are judged, but the tube is built from
79
+ the reference extended beyond the window as far as needed for it to equal
80
+ the full-range tube there (two x half-widths plus three samples per side
81
+ to start with, and past the end of any collinear or constant run of
82
+ reference samples the window edge falls in), so a test point near a
83
+ window edge that is shifted by less than the x tolerance passes exactly
84
+ as in a comparison over the full range (without `rtolx` / `rtoly`, every
85
+ point in the window gets the same deviation and verdict as in the
86
+ full-range comparison; see the core crate's README for the precise
87
+ guarantee). At the first and last reference sample there is nothing to
88
+ extend with.
89
+ `rtolx` / `rtoly` are relative to the reference inside the window.
90
+ `lowerX` / `upperX` reach beyond the window by the extension;
91
+ `errorsY` is `0` for test points outside `xRange`.
92
+
93
+ `defaultOptions()` returns the six default values explicitly (passing
94
+ them is identical to omitting `options`), and `summarize()` echoes the
95
+ six resolved values (`ResolvedTolerances`).
96
+
97
+ ## Violation summary
98
+
99
+ `summarize()` condenses an existing comparison into how much the given
100
+ tolerances were violated: violation intervals, the worst deviation with
101
+ the tube half-width at that x, and the share of test points and of the
102
+ compared x-span outside the tube. It is computed by the Rust core, so
103
+ the numbers match the Rust and Python APIs exactly.
104
+
105
+ ```ts
106
+ import { compare, summarize } from '@simtest-js/funnel';
107
+
108
+ const options = { tolerances: { atoly: 0.005 } };
109
+ const result = compare(tRef, yRef, tRef, yTest, options);
110
+ const s = summarize(result, tRef, options); // same reference x and options
111
+ for (const iv of s.intervals) {
112
+ console.log(iv.startX, iv.endX, iv.direction, iv.worstDeviation);
113
+ }
114
+ console.log(s.worst, s.fractionOfPointsOutside, s.fractionOfSpanOutside);
115
+ ```
116
+
117
+ Only test points inside the compared range (`xRange` intersected with
118
+ the reference x-extent) count. For validation statuses (e.g.
119
+ `NonMonotonic`) `worst`, `comparedRange` and both fractions are `null`.
120
+
121
+ ## Downsampling for plots
122
+
123
+ `downsampleMinMax(x, y, buckets, pinnedX?)` reduces a long signal for
124
+ plotting or reporting. It is post-processing only: `compare()` and
125
+ `summarize()` always use the full signal. `createFunnelPlot()` does not
126
+ downsample; pass downsampled traces yourself if needed.
127
+
128
+ ```ts
129
+ import { downsampleMinMax } from '@simtest-js/funnel';
130
+
131
+ const s = summarize(result, tRef, options);
132
+ const pins = s.intervals.map((iv) => iv.worstX); // keep every violation visible
133
+ const d = downsampleMinMax(tTest, yTest, 500, pins);
134
+ // d.x, d.y: Float64Array; d.indices: Uint32Array into the input
135
+ const errorsKept = Array.from(d.indices, (i) => result.errorsY[i]);
136
+ ```
137
+
138
+ The x-extent is split into `buckets` buckets of equal x-width; the
139
+ lowest and highest sample of each bucket are kept (first occurrence on
140
+ ties, `NaN` y never selected), plus the first and last sample. Each
141
+ finite pin keeps the sample with the nearest x (ties go to the lower x)
142
+ and every sample sharing that x; `NaN` pins are ignored. At most
143
+ `min(n, 2 * buckets + 2 + M)` samples are returned (`M` = samples
144
+ selected by pins); signals with `n <= 2 * buckets` are returned
145
+ unchanged. An `Error` is thrown for a length mismatch, a non-finite or
146
+ decreasing x, a non-integer `buckets` or `buckets < 1`. Results are
147
+ identical to the Rust and Python APIs.
148
+
149
+ ## Status codes
150
+
151
+ Mirror `simtest_funnel_core::Status`:
152
+
153
+ | Name | Code |
154
+ | ------------------ | ---: |
155
+ | `Pass` | 0 |
156
+ | `Fail` | -1 |
157
+ | `MissingReference` | 1 |
158
+ | `MissingTest` | 2 |
159
+ | `NonMonotonic` | 10 |
160
+ | `LengthMismatch` | 11 |
161
+ | `EmptyRange` | 12 |
162
+ | `BufferTooSmall` | 13 |
163
+ | `InsufficientData` | 14 |
164
+
165
+ `MissingReference` / `MissingTest` are judged within `xRange`: both
166
+ x-extents are clipped to it first, so a window inside the overlap of the
167
+ two trajectories yields `Pass` or `Fail`.
168
+
169
+ ## Reference documentation
170
+
171
+ A full `typedoc`-generated API reference is published alongside every
172
+ release. To build it locally:
173
+
174
+ ```bash
175
+ make docs-js # writes target/doc/js/index.html
176
+ ```
@@ -0,0 +1,238 @@
1
+ /**
2
+ * Tolerances passed to {@link compare} / {@link summarize}. A field that is
3
+ * omitted, `undefined` or `null` is "not given"; any number (including `0`)
4
+ * is given.
5
+ *
6
+ * Coefficients are resolved per axis by the Rust core, identically in every
7
+ * simtest-funnel API (x axis: `atolx`/`ltolx`/`rtolx`; y axis:
8
+ * `atoly`/`ltoly`/`rtoly`):
9
+ *
10
+ * - an axis with no coefficient given gets its default: the x axis all `0`
11
+ * (no time tolerance), the y axis `rtoly = 2e-3` (other coefficients `0`);
12
+ * - an axis with at least one coefficient given uses the given values and
13
+ * `0` for its other coefficients;
14
+ * - an explicit `0` counts as given.
15
+ *
16
+ * So `{ atoly: 0.05 }` means `atoly = 0.05` and every other coefficient
17
+ * `0`. Give an x coefficient, e.g. `{ atolx: 0.5, atoly: 0.05 }`, to allow
18
+ * the test to be shifted in time: with zero x tolerance the x half-width is
19
+ * the `1e-10` floor, so each test point is checked only against the y band
20
+ * around the reference at the same x and a slightly delayed steep edge
21
+ * fails.
22
+ */
23
+ export interface Tolerances {
24
+ atolx?: number | null;
25
+ atoly?: number | null;
26
+ ltolx?: number | null;
27
+ ltoly?: number | null;
28
+ rtolx?: number | null;
29
+ rtoly?: number | null;
30
+ }
31
+ /** The six effective tolerance coefficients after resolution. */
32
+ export type ResolvedTolerances = {
33
+ [K in keyof Tolerances]-?: number;
34
+ };
35
+ /**
36
+ * X-range window passed in {@link Options}: only test points with x in
37
+ * `[lo, hi]` are judged. A bound that is omitted, `undefined` or `null` is
38
+ * unbounded on that side, so `{ lo: 0.5 }` means `[0.5, Infinity]` (same as
39
+ * the Python `Range`).
40
+ *
41
+ * The tube for the window is built from the reference extended beyond it
42
+ * by the x tolerance (two x half-widths plus three samples per side), so a
43
+ * test point near a window edge that is shifted by less than the x
44
+ * tolerance is judged as in a full-range comparison; without `rtolx` /
45
+ * `rtoly` every point in the window gets the same verdict as in the
46
+ * full-range comparison. At the first and last reference sample there is
47
+ * nothing to extend with. `rtolx` / `rtoly` are relative to the reference
48
+ * inside the window, and coverage (`MissingReference` / `MissingTest`) is
49
+ * judged inside the window.
50
+ */
51
+ export interface XRange {
52
+ lo?: number | null;
53
+ hi?: number | null;
54
+ }
55
+ /**
56
+ * A range as returned by the library: both bounds present, unbounded
57
+ * sides are `-Infinity` / `Infinity`.
58
+ */
59
+ export interface ResolvedXRange {
60
+ lo: number;
61
+ hi: number;
62
+ }
63
+ /**
64
+ * Options for {@link compare}. Omitting `options`, or omitting
65
+ * `tolerances`, means the default tolerances (`rtoly = 2e-3`, no tolerance
66
+ * in x).
67
+ */
68
+ export interface Options {
69
+ tolerances?: Tolerances;
70
+ xRange?: XRange;
71
+ }
72
+ /** Fully explicit options, as returned by {@link defaultOptions}. */
73
+ export interface ResolvedOptions {
74
+ tolerances: ResolvedTolerances;
75
+ xRange: ResolvedXRange;
76
+ }
77
+ /** Status codes (mirror `simtest_funnel_core::Status`). */
78
+ export declare const Status: {
79
+ readonly Pass: 0;
80
+ readonly Fail: -1;
81
+ readonly MissingReference: 1;
82
+ readonly MissingTest: 2;
83
+ readonly NonMonotonic: 10;
84
+ readonly LengthMismatch: 11;
85
+ readonly EmptyRange: 12;
86
+ readonly BufferTooSmall: 13;
87
+ readonly InsufficientData: 14;
88
+ };
89
+ export type StatusCode = (typeof Status)[keyof typeof Status];
90
+ /**
91
+ * Result of {@link compare}. `errorsX` is the test x-grid and `errorsY` the
92
+ * signed deviation there (positive above the upper bound, negative below the
93
+ * lower bound, `0` inside the tube and for test points outside `xRange`).
94
+ * With an `xRange`, `lowerX` / `upperX` reach beyond the window by the
95
+ * extension the tube is built from.
96
+ */
97
+ export interface CompareResult {
98
+ status: StatusCode;
99
+ lowerX: Float64Array;
100
+ lowerY: Float64Array;
101
+ upperX: Float64Array;
102
+ upperY: Float64Array;
103
+ errorsX: Float64Array;
104
+ errorsY: Float64Array;
105
+ }
106
+ /**
107
+ * Compare a test trajectory against a reference. Errors are signed
108
+ * (positive above upper, negative below lower). Partially specified
109
+ * tolerances are resolved per axis (see {@link Tolerances}); `options`
110
+ * omitted means the defaults reported by {@link defaultOptions}.
111
+ */
112
+ export declare function compare(referenceX: ArrayLike<number> | Float64Array, referenceY: ArrayLike<number> | Float64Array, testX: ArrayLike<number> | Float64Array, testY: ArrayLike<number> | Float64Array, options?: Options): CompareResult;
113
+ /** Side of the tube on which a violation lies. */
114
+ export type ViolationDirection = 'above' | 'below';
115
+ /**
116
+ * A maximal run of consecutive judged test points outside the tube on the
117
+ * same side. `startX` / `endX` are the x of the first / last test point of
118
+ * the run (equal for a single-point violation).
119
+ */
120
+ export interface ViolationInterval {
121
+ startX: number;
122
+ endX: number;
123
+ direction: ViolationDirection;
124
+ pointCount: number;
125
+ /** Signed deviation with the largest magnitude in the run. */
126
+ worstDeviation: number;
127
+ worstX: number;
128
+ }
129
+ /** Overall worst deviation of a comparison. */
130
+ export interface WorstDeviation {
131
+ x: number;
132
+ /** Signed deviation with the largest magnitude (first on ties). */
133
+ deviation: number;
134
+ /** Half the distance between upper and lower bound at `x`. */
135
+ tubeHalfWidthY: number;
136
+ }
137
+ /**
138
+ * How much a comparison violated the tolerances it was run with. Only
139
+ * judged test points (x inside `xRange` intersected with the reference
140
+ * x-extent) contribute. For validation statuses, or when no point is
141
+ * judged, `comparedRange`, `worst` and both fractions are `null`.
142
+ */
143
+ export interface ViolationSummary {
144
+ status: StatusCode;
145
+ /** The six resolved tolerance values used. */
146
+ tolerances: ResolvedTolerances;
147
+ xRange: ResolvedXRange;
148
+ /** First to last judged test point. */
149
+ comparedRange: ResolvedXRange | null;
150
+ intervals: ViolationInterval[];
151
+ worst: WorstDeviation | null;
152
+ pointsCompared: number;
153
+ pointsOutside: number;
154
+ fractionOfPointsOutside: number | null;
155
+ /**
156
+ * Each judged point represents the x-length halfway to its neighbours;
157
+ * share of that length lying outside the tube.
158
+ */
159
+ fractionOfSpanOutside: number | null;
160
+ }
161
+ /**
162
+ * Summarize how much `result` violated its tolerances. `referenceX` and
163
+ * `options` must be the reference x-values and options passed to
164
+ * {@link compare} for `result` (`undefined` means the same defaults
165
+ * `compare` uses). Computed by the Rust core, so numbers are identical to
166
+ * the Rust and Python APIs.
167
+ */
168
+ export declare function summarize(result: CompareResult, referenceX: ArrayLike<number> | Float64Array, options?: Options): ViolationSummary;
169
+ /**
170
+ * Samples kept by {@link downsampleMinMax}, in input order:
171
+ * `x[k] === inputX[indices[k]]` and `y[k] === inputY[indices[k]]`. Use
172
+ * `indices` to select the same samples from further arrays on the same
173
+ * x-grid (e.g. `result.errorsY` of a comparison).
174
+ */
175
+ export interface Downsampled {
176
+ indices: Uint32Array;
177
+ x: Float64Array;
178
+ y: Float64Array;
179
+ }
180
+ /**
181
+ * Reduce a signal to the extremes of `buckets` equal-width x-buckets, for
182
+ * output only (plots, reports); never feed the result back into
183
+ * {@link compare}.
184
+ *
185
+ * The lowest and highest sample of each bucket are kept (first occurrence
186
+ * on ties, `NaN` y never selected), plus the first and last sample. Each
187
+ * finite value of `pinnedX` keeps the sample with the nearest x (ties go to
188
+ * the lower x) and every sample sharing that x; `NaN` pins are ignored. Pin
189
+ * the `worstX` of every interval of {@link summarize} so a plot never hides
190
+ * a violation.
191
+ *
192
+ * At most `min(n, 2 * buckets + 2 + M)` samples are returned (`M` = samples
193
+ * selected by pins); if `n <= 2 * buckets` every sample is returned.
194
+ * Computed by the Rust core, so results are identical to the Rust and
195
+ * Python APIs.
196
+ *
197
+ * @throws Error for a length mismatch, a non-finite or decreasing x, a
198
+ * non-integer `buckets` or `buckets < 1`.
199
+ */
200
+ export declare function downsampleMinMax(x: ArrayLike<number> | Float64Array, y: ArrayLike<number> | Float64Array, buckets: number, pinnedX?: ArrayLike<number> | Float64Array): Downsampled;
201
+ /**
202
+ * Returns the default options with all six tolerances explicit
203
+ * (`rtoly = 2e-3`, others `0`: no tolerance in x). Passing them to {@link compare}
204
+ * is identical to omitting `options`.
205
+ */
206
+ export declare function defaultOptions(): ResolvedOptions;
207
+ /** Returns the core crate version. */
208
+ export declare function version(): string;
209
+ /**
210
+ * Plot interface shared with Plotly.js. We declare only the minimal
211
+ * surface we need so that users can bring their own Plotly build
212
+ * (peer dependency).
213
+ */
214
+ export interface PlotlyLike {
215
+ newPlot(el: HTMLElement, data: unknown[], layout?: unknown, config?: unknown): Promise<unknown>;
216
+ }
217
+ /** Trace inputs to {@link createFunnelPlot}. */
218
+ export interface CreateFunnelPlotInputs {
219
+ reference: {
220
+ x: ArrayLike<number>;
221
+ y: ArrayLike<number>;
222
+ name?: string;
223
+ };
224
+ test: {
225
+ x: ArrayLike<number>;
226
+ y: ArrayLike<number>;
227
+ name?: string;
228
+ };
229
+ result: CompareResult;
230
+ }
231
+ /**
232
+ * Render a funnel plot into `el`: reference, test, both tube bounds and the
233
+ * absolute deviations. For a comparison with an `xRange` the bounds cover
234
+ * the window plus the extension the tube was built from and the deviations
235
+ * are `0` outside the window; pass e.g. `{ xaxis: { range: [lo, hi] } }` as
236
+ * `layout` to show only the window.
237
+ */
238
+ export declare function createFunnelPlot(plotly: PlotlyLike, el: HTMLElement, inputs: CreateFunnelPlotInputs, layout?: Record<string, unknown>): Promise<unknown>;
package/dist/index.js ADDED
@@ -0,0 +1,147 @@
1
+ import * as wasm from './wasm/simtest_funnel_wasm.js';
2
+ /** Status codes (mirror `simtest_funnel_core::Status`). */
3
+ export const Status = {
4
+ Pass: 0,
5
+ Fail: -1,
6
+ MissingReference: 1,
7
+ MissingTest: 2,
8
+ NonMonotonic: 10,
9
+ LengthMismatch: 11,
10
+ EmptyRange: 12,
11
+ BufferTooSmall: 13,
12
+ InsufficientData: 14,
13
+ };
14
+ function toF64(v) {
15
+ return v instanceof Float64Array
16
+ ? v
17
+ : Float64Array.from(v);
18
+ }
19
+ /**
20
+ * Compare a test trajectory against a reference. Errors are signed
21
+ * (positive above upper, negative below lower). Partially specified
22
+ * tolerances are resolved per axis (see {@link Tolerances}); `options`
23
+ * omitted means the defaults reported by {@link defaultOptions}.
24
+ */
25
+ export function compare(referenceX, referenceY, testX, testY, options) {
26
+ const raw = wasm.compare(toF64(referenceX), toF64(referenceY), toF64(testX), toF64(testY),
27
+ // biome-ignore lint/suspicious/noExplicitAny: WASM glue returns `any`
28
+ (options ?? null));
29
+ const r = raw;
30
+ return {
31
+ status: r.status,
32
+ lowerX: Float64Array.from(r.lowerX),
33
+ lowerY: Float64Array.from(r.lowerY),
34
+ upperX: Float64Array.from(r.upperX),
35
+ upperY: Float64Array.from(r.upperY),
36
+ errorsX: Float64Array.from(r.errorsX),
37
+ errorsY: Float64Array.from(r.errorsY),
38
+ };
39
+ }
40
+ /**
41
+ * Summarize how much `result` violated its tolerances. `referenceX` and
42
+ * `options` must be the reference x-values and options passed to
43
+ * {@link compare} for `result` (`undefined` means the same defaults
44
+ * `compare` uses). Computed by the Rust core, so numbers are identical to
45
+ * the Rust and Python APIs.
46
+ */
47
+ export function summarize(result, referenceX, options) {
48
+ return wasm.summarize(toF64(referenceX), result.status, result.lowerX, result.lowerY, result.upperX, result.upperY, result.errorsX, result.errorsY, options ?? null);
49
+ }
50
+ /**
51
+ * Reduce a signal to the extremes of `buckets` equal-width x-buckets, for
52
+ * output only (plots, reports); never feed the result back into
53
+ * {@link compare}.
54
+ *
55
+ * The lowest and highest sample of each bucket are kept (first occurrence
56
+ * on ties, `NaN` y never selected), plus the first and last sample. Each
57
+ * finite value of `pinnedX` keeps the sample with the nearest x (ties go to
58
+ * the lower x) and every sample sharing that x; `NaN` pins are ignored. Pin
59
+ * the `worstX` of every interval of {@link summarize} so a plot never hides
60
+ * a violation.
61
+ *
62
+ * At most `min(n, 2 * buckets + 2 + M)` samples are returned (`M` = samples
63
+ * selected by pins); if `n <= 2 * buckets` every sample is returned.
64
+ * Computed by the Rust core, so results are identical to the Rust and
65
+ * Python APIs.
66
+ *
67
+ * @throws Error for a length mismatch, a non-finite or decreasing x, a
68
+ * non-integer `buckets` or `buckets < 1`.
69
+ */
70
+ export function downsampleMinMax(x, y, buckets, pinnedX) {
71
+ try {
72
+ return wasm.downsampleMinMax(toF64(x), toF64(y), buckets, toF64(pinnedX ?? []));
73
+ }
74
+ catch (e) {
75
+ // The WASM glue throws the core's message as a plain string.
76
+ throw e instanceof Error ? e : new Error(String(e));
77
+ }
78
+ }
79
+ /**
80
+ * Returns the default options with all six tolerances explicit
81
+ * (`rtoly = 2e-3`, others `0`: no tolerance in x). Passing them to {@link compare}
82
+ * is identical to omitting `options`.
83
+ */
84
+ export function defaultOptions() {
85
+ return wasm.defaultOptions();
86
+ }
87
+ /** Returns the core crate version. */
88
+ export function version() {
89
+ return wasm.version();
90
+ }
91
+ /**
92
+ * Render a funnel plot into `el`: reference, test, both tube bounds and the
93
+ * absolute deviations. For a comparison with an `xRange` the bounds cover
94
+ * the window plus the extension the tube was built from and the deviations
95
+ * are `0` outside the window; pass e.g. `{ xaxis: { range: [lo, hi] } }` as
96
+ * `layout` to show only the window.
97
+ */
98
+ export async function createFunnelPlot(plotly, el, inputs, layout) {
99
+ const traces = [
100
+ {
101
+ x: Array.from(inputs.reference.x),
102
+ y: Array.from(inputs.reference.y),
103
+ name: inputs.reference.name ?? 'reference',
104
+ mode: 'lines',
105
+ type: 'scatter',
106
+ },
107
+ {
108
+ x: Array.from(inputs.test.x),
109
+ y: Array.from(inputs.test.y),
110
+ name: inputs.test.name ?? 'test',
111
+ mode: 'lines',
112
+ type: 'scatter',
113
+ },
114
+ {
115
+ x: Array.from(inputs.result.lowerX),
116
+ y: Array.from(inputs.result.lowerY),
117
+ name: 'lower bound',
118
+ mode: 'lines',
119
+ line: { dash: 'dot' },
120
+ type: 'scatter',
121
+ },
122
+ {
123
+ x: Array.from(inputs.result.upperX),
124
+ y: Array.from(inputs.result.upperY),
125
+ name: 'upper bound',
126
+ mode: 'lines',
127
+ line: { dash: 'dot' },
128
+ type: 'scatter',
129
+ },
130
+ {
131
+ x: Array.from(inputs.result.errorsX),
132
+ y: Array.from(inputs.result.errorsY).map((v) => Math.abs(v)),
133
+ name: 'error',
134
+ mode: 'lines',
135
+ type: 'scatter',
136
+ yaxis: 'y2',
137
+ },
138
+ ];
139
+ const finalLayout = {
140
+ title: 'Funnel comparison',
141
+ yaxis: { title: 'value' },
142
+ yaxis2: { title: '|error|', overlaying: 'y', side: 'right' },
143
+ ...(layout ?? {}),
144
+ };
145
+ return plotly.newPlot(el, traces, finalLayout);
146
+ }
147
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,IAAI,MAAM,+BAA+B,CAAC;AAkFtD,2DAA2D;AAC3D,MAAM,CAAC,MAAM,MAAM,GAAG;IACpB,IAAI,EAAE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AE,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;YAC5D,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,OAAO;YACb,IAAI,EAAE,SAAS;YACf,KAAK,EAAE,IAAI;SACZ;KACF,CAAC;IACF,MAAM,WAAW,GAAG;QAClB,KAAK,EAAE,mBAAmB;QAC1B,KAAK,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE;QACzB,MAAM,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,GAAG,EAAE,IAAI,EAAE,OAAO,EAAE;QAC5D,GAAG,CAAC,MAAM,IAAI,EAAE,CAAC;KAClB,CAAC;IACF,OAAO,MAAM,CAAC,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,WAAW,CAAC,CAAC;AACjD,CAAC"}
@@ -0,0 +1,32 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * Compare `test` against `reference`.
6
+ */
7
+ export function compare(reference_x: Float64Array, reference_y: Float64Array, test_x: Float64Array, test_y: Float64Array, options: any): any;
8
+
9
+ /**
10
+ * Returns the default options as a JS object with all six tolerance
11
+ * values explicit (`Options::default_options()` from the core).
12
+ */
13
+ export function defaultOptions(): any;
14
+
15
+ /**
16
+ * Min/max-per-bucket downsampling of a signal, computed by the core.
17
+ * Returns `{ indices: Uint32Array, x: Float64Array, y: Float64Array }`;
18
+ * invalid input throws with the core's error message.
19
+ */
20
+ export function downsampleMinMax(x: Float64Array, y: Float64Array, buckets: number, pinned_x: Float64Array): any;
21
+
22
+ /**
23
+ * Violation summary of an existing comparison. The result arrays are
24
+ * marshalled back into a core `CompareResult`; the summary itself is
25
+ * computed by the Rust core. Absent values are `null`.
26
+ */
27
+ export function summarize(reference_x: Float64Array, status: number, lower_x: Float64Array, lower_y: Float64Array, upper_x: Float64Array, upper_y: Float64Array, errors_x: Float64Array, errors_y: Float64Array, options: any): any;
28
+
29
+ /**
30
+ * Returns the core crate version.
31
+ */
32
+ export function version(): string;
@@ -0,0 +1,9 @@
1
+ /* @ts-self-types="./simtest_funnel_wasm.d.ts" */
2
+ import * as wasm from "./simtest_funnel_wasm_bg.wasm";
3
+ import { __wbg_set_wasm } from "./simtest_funnel_wasm_bg.js";
4
+
5
+ __wbg_set_wasm(wasm);
6
+ wasm.__wbindgen_start();
7
+ export {
8
+ compare, defaultOptions, downsampleMinMax, summarize, version
9
+ } from "./simtest_funnel_wasm_bg.js";
@@ -0,0 +1,442 @@
1
+ /**
2
+ * Compare `test` against `reference`.
3
+ * @param {Float64Array} reference_x
4
+ * @param {Float64Array} reference_y
5
+ * @param {Float64Array} test_x
6
+ * @param {Float64Array} test_y
7
+ * @param {any} options
8
+ * @returns {any}
9
+ */
10
+ export function compare(reference_x, reference_y, test_x, test_y, options) {
11
+ const ret = wasm.compare(reference_x, reference_y, test_x, test_y, options);
12
+ if (ret[2]) {
13
+ throw takeFromExternrefTable0(ret[1]);
14
+ }
15
+ return takeFromExternrefTable0(ret[0]);
16
+ }
17
+
18
+ /**
19
+ * Returns the default options as a JS object with all six tolerance
20
+ * values explicit (`Options::default_options()` from the core).
21
+ * @returns {any}
22
+ */
23
+ export function defaultOptions() {
24
+ const ret = wasm.defaultOptions();
25
+ return ret;
26
+ }
27
+
28
+ /**
29
+ * Min/max-per-bucket downsampling of a signal, computed by the core.
30
+ * Returns `{ indices: Uint32Array, x: Float64Array, y: Float64Array }`;
31
+ * invalid input throws with the core's error message.
32
+ * @param {Float64Array} x
33
+ * @param {Float64Array} y
34
+ * @param {number} buckets
35
+ * @param {Float64Array} pinned_x
36
+ * @returns {any}
37
+ */
38
+ export function downsampleMinMax(x, y, buckets, pinned_x) {
39
+ const ret = wasm.downsampleMinMax(x, y, buckets, pinned_x);
40
+ if (ret[2]) {
41
+ throw takeFromExternrefTable0(ret[1]);
42
+ }
43
+ return takeFromExternrefTable0(ret[0]);
44
+ }
45
+
46
+ /**
47
+ * Violation summary of an existing comparison. The result arrays are
48
+ * marshalled back into a core `CompareResult`; the summary itself is
49
+ * computed by the Rust core. Absent values are `null`.
50
+ * @param {Float64Array} reference_x
51
+ * @param {number} status
52
+ * @param {Float64Array} lower_x
53
+ * @param {Float64Array} lower_y
54
+ * @param {Float64Array} upper_x
55
+ * @param {Float64Array} upper_y
56
+ * @param {Float64Array} errors_x
57
+ * @param {Float64Array} errors_y
58
+ * @param {any} options
59
+ * @returns {any}
60
+ */
61
+ export function summarize(reference_x, status, lower_x, lower_y, upper_x, upper_y, errors_x, errors_y, options) {
62
+ const ret = wasm.summarize(reference_x, status, lower_x, lower_y, upper_x, upper_y, errors_x, errors_y, options);
63
+ if (ret[2]) {
64
+ throw takeFromExternrefTable0(ret[1]);
65
+ }
66
+ return takeFromExternrefTable0(ret[0]);
67
+ }
68
+
69
+ /**
70
+ * Returns the core crate version.
71
+ * @returns {string}
72
+ */
73
+ export function version() {
74
+ let deferred1_0;
75
+ let deferred1_1;
76
+ try {
77
+ const ret = wasm.version();
78
+ deferred1_0 = ret[0];
79
+ deferred1_1 = ret[1];
80
+ return getStringFromWasm0(ret[0], ret[1]);
81
+ } finally {
82
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
83
+ }
84
+ }
85
+ export function __wbg_Error_208446807d0d1e30(arg0, arg1) {
86
+ const ret = Error(getStringFromWasm0(arg0, arg1));
87
+ return ret;
88
+ }
89
+ export function __wbg_String_8564e559799eccda(arg0, arg1) {
90
+ const ret = String(arg1);
91
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
92
+ const len1 = WASM_VECTOR_LEN;
93
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
94
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
95
+ }
96
+ export function __wbg___wbindgen_boolean_get_4f1baf9a00be3c74(arg0) {
97
+ const v = arg0;
98
+ const ret = typeof(v) === 'boolean' ? v : undefined;
99
+ return isLikeNone(ret) ? 0xFFFFFF : ret ? 1 : 0;
100
+ }
101
+ export function __wbg___wbindgen_debug_string_f249a2a76caa9a55(arg0, arg1) {
102
+ const ret = debugString(arg1);
103
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
104
+ const len1 = WASM_VECTOR_LEN;
105
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
106
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
107
+ }
108
+ export function __wbg___wbindgen_in_3f58a9d3b3a7eed2(arg0, arg1) {
109
+ const ret = arg0 in arg1;
110
+ return ret;
111
+ }
112
+ export function __wbg___wbindgen_is_null_c22311b1cc228e3a(arg0) {
113
+ const ret = arg0 === null;
114
+ return ret;
115
+ }
116
+ export function __wbg___wbindgen_is_object_8b968c3ab8e96595(arg0) {
117
+ const val = arg0;
118
+ const ret = typeof(val) === 'object' && val !== null;
119
+ return ret;
120
+ }
121
+ export function __wbg___wbindgen_is_undefined_be5b34249ff1fc15(arg0) {
122
+ const ret = arg0 === undefined;
123
+ return ret;
124
+ }
125
+ export function __wbg___wbindgen_jsval_loose_eq_b2f214e2e4b30e36(arg0, arg1) {
126
+ const ret = arg0 == arg1;
127
+ return ret;
128
+ }
129
+ export function __wbg___wbindgen_number_get_934b640d0889af78(arg0, arg1) {
130
+ const obj = arg1;
131
+ const ret = typeof(obj) === 'number' ? obj : undefined;
132
+ getDataViewMemory0().setFloat64((arg0 >>> 0) + 8 * 1, isLikeNone(ret) ? 0 : ret, true);
133
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, !isLikeNone(ret), true);
134
+ }
135
+ export function __wbg___wbindgen_string_get_7ce8eee7fd327545(arg0, arg1) {
136
+ const obj = arg1;
137
+ const ret = typeof(obj) === 'string' ? obj : undefined;
138
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
139
+ var len1 = WASM_VECTOR_LEN;
140
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 1, len1, true);
141
+ getDataViewMemory0().setInt32((arg0 >>> 0) + 4 * 0, ptr1, true);
142
+ }
143
+ export function __wbg___wbindgen_throw_4c88d8bf264fd984(arg0, arg1) {
144
+ throw new Error(getStringFromWasm0(arg0, arg1));
145
+ }
146
+ export function __wbg_get_with_ref_key_fc601247060b7204(arg0, arg1) {
147
+ const ret = arg0[arg1];
148
+ return ret;
149
+ }
150
+ export function __wbg_instanceof_ArrayBuffer_12cdaa4161423e6b(arg0) {
151
+ let result;
152
+ try {
153
+ result = arg0 instanceof ArrayBuffer;
154
+ } catch (_) {
155
+ result = false;
156
+ }
157
+ const ret = result;
158
+ return ret;
159
+ }
160
+ export function __wbg_instanceof_Uint8Array_d7aeb0dcb3108fea(arg0) {
161
+ let result;
162
+ try {
163
+ result = arg0 instanceof Uint8Array;
164
+ } catch (_) {
165
+ result = false;
166
+ }
167
+ const ret = result;
168
+ return ret;
169
+ }
170
+ export function __wbg_length_186163212ffe79c3(arg0) {
171
+ const ret = arg0.length;
172
+ return ret;
173
+ }
174
+ export function __wbg_length_5a8bb8abe1e54e15(arg0) {
175
+ const ret = arg0.length;
176
+ return ret;
177
+ }
178
+ export function __wbg_new_13de428334042d26(arg0) {
179
+ const ret = new Uint8Array(arg0);
180
+ return ret;
181
+ }
182
+ export function __wbg_new_37eb45aaf5eeb820() {
183
+ const ret = new Array();
184
+ return ret;
185
+ }
186
+ export function __wbg_new_cd4348290afae586() {
187
+ const ret = new Object();
188
+ return ret;
189
+ }
190
+ export function __wbg_new_from_slice_3512352010266e02(arg0, arg1) {
191
+ const ret = new Uint32Array(getArrayU32FromWasm0(arg0, arg1));
192
+ return ret;
193
+ }
194
+ export function __wbg_new_from_slice_aaf85a9746711968(arg0, arg1) {
195
+ const ret = new Float64Array(getArrayF64FromWasm0(arg0, arg1));
196
+ return ret;
197
+ }
198
+ export function __wbg_prototypesetcall_13162965d1fe7aa3(arg0, arg1, arg2) {
199
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
200
+ }
201
+ export function __wbg_prototypesetcall_a366c038a3918afa(arg0, arg1, arg2) {
202
+ Float64Array.prototype.set.call(getArrayF64FromWasm0(arg0, arg1), arg2);
203
+ }
204
+ export function __wbg_set_2793479888329cb6() { return handleError(function (arg0, arg1, arg2) {
205
+ const ret = Reflect.set(arg0, arg1, arg2);
206
+ return ret;
207
+ }, arguments); }
208
+ export function __wbg_set_d2d33b52458e984a(arg0, arg1, arg2) {
209
+ arg0[arg1 >>> 0] = arg2;
210
+ }
211
+ export function __wbg_set_e4b9a833d288759a(arg0, arg1, arg2) {
212
+ arg0[arg1] = arg2;
213
+ }
214
+ export function __wbindgen_generic_0000000000000001(arg0) {
215
+ // Cast intrinsic for `F64 -> Externref`.
216
+ const ret = arg0;
217
+ return ret;
218
+ }
219
+ export function __wbindgen_generic_0000000000000002(arg0, arg1) {
220
+ // Cast intrinsic for `Ref(String) -> Externref`.
221
+ const ret = getStringFromWasm0(arg0, arg1);
222
+ return ret;
223
+ }
224
+ export function __wbindgen_generic_0000000000000003(arg0) {
225
+ // Cast intrinsic for `U64 -> Externref`.
226
+ const ret = BigInt.asUintN(64, arg0);
227
+ return ret;
228
+ }
229
+ export function __wbindgen_init_externref_table() {
230
+ const table = wasm.__wbindgen_externrefs;
231
+ table.set(0, undefined);
232
+ table.set(1024, undefined);
233
+ table.set(1025, null);
234
+ table.set(1026, true);
235
+ table.set(1027, false);
236
+ }
237
+ function addToExternrefTable0(obj) {
238
+ const idx = wasm.__externref_table_alloc();
239
+ wasm.__wbindgen_externrefs.set(idx, obj);
240
+ return idx;
241
+ }
242
+
243
+ function debugString(val) {
244
+ switch (typeof val) {
245
+ // primitive types
246
+ case 'number':
247
+ case 'boolean':
248
+ case 'undefined':
249
+ return `${val}`;
250
+ case 'string':
251
+ return JSON.stringify(val);
252
+ case 'bigint':
253
+ return `${val}n`;
254
+ case 'symbol':
255
+ return val.description !== undefined
256
+ ? `Symbol(${val.description})`
257
+ : 'Symbol';
258
+ case 'function':
259
+ return typeof val.name === 'string' && val.name !== ''
260
+ ? `Function(${val.name})`
261
+ : 'Function';
262
+ case 'object': {
263
+ if (val === null) {
264
+ return 'null';
265
+ }
266
+ // objects
267
+ if (Array.isArray(val)) {
268
+ return '[' + Array.from(val, debugString).join(', ') + ']';
269
+ }
270
+ // errors
271
+ if (val instanceof Error) {
272
+ return `${val.name}: ${val.message}\n${val.stack}`;
273
+ }
274
+
275
+ const toStringOutput = toString.call(val);
276
+ // Test for built-in
277
+ const className = /\[object ([^\]]+)\]/.exec(toStringOutput)?.[1];
278
+
279
+ // Failed to match the standard '[object ClassName]'
280
+ if (className === undefined) {
281
+ return toStringOutput;
282
+ }
283
+ if (className === 'Object') {
284
+ // we're a user defined class or Object
285
+ // JSON.stringify avoids problems with cycles, and is generally much
286
+ // easier than looping through ownProperties of `val`.
287
+ try {
288
+ return 'Object(' + JSON.stringify(val) + ')';
289
+ } catch (_) {
290
+ return 'Object';
291
+ }
292
+ }
293
+ // TODO we could test for more things here, like `Set`s and `Map`s.
294
+ return className;
295
+ }
296
+ // Per MDN: 'This list of values is exhaustive.'
297
+ // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/typeof#description
298
+ }
299
+ }
300
+
301
+ function getArrayF64FromWasm0(ptr, len) {
302
+ ptr = ptr >>> 0;
303
+ return getFloat64ArrayMemory0().subarray(ptr / 8, ptr / 8 + len);
304
+ }
305
+
306
+ function getArrayU32FromWasm0(ptr, len) {
307
+ ptr = ptr >>> 0;
308
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
309
+ }
310
+
311
+ function getArrayU8FromWasm0(ptr, len) {
312
+ ptr = ptr >>> 0;
313
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
314
+ }
315
+
316
+ let cachedDataViewMemory0 = null;
317
+ function getDataViewMemory0() {
318
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
319
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
320
+ }
321
+ return cachedDataViewMemory0;
322
+ }
323
+
324
+ let cachedFloat64ArrayMemory0 = null;
325
+ function getFloat64ArrayMemory0() {
326
+ if (cachedFloat64ArrayMemory0 === null || cachedFloat64ArrayMemory0.byteLength === 0) {
327
+ cachedFloat64ArrayMemory0 = new Float64Array(wasm.memory.buffer);
328
+ }
329
+ return cachedFloat64ArrayMemory0;
330
+ }
331
+
332
+ function getStringFromWasm0(ptr, len) {
333
+ ptr = ptr >>> 0;
334
+ return decodeText(getUint8ArrayMemory0().subarray(ptr, ptr + len));
335
+ }
336
+
337
+ let cachedUint32ArrayMemory0 = null;
338
+ function getUint32ArrayMemory0() {
339
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
340
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
341
+ }
342
+ return cachedUint32ArrayMemory0;
343
+ }
344
+
345
+ let cachedUint8ArrayMemory0 = null;
346
+ function getUint8ArrayMemory0() {
347
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
348
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
349
+ }
350
+ return cachedUint8ArrayMemory0;
351
+ }
352
+
353
+ function handleError(f, args) {
354
+ try {
355
+ return f.apply(this, args);
356
+ } catch (e) {
357
+ const idx = addToExternrefTable0(e);
358
+ wasm.__wbindgen_exn_store(idx);
359
+ }
360
+ }
361
+
362
+ function isLikeNone(x) {
363
+ return x === undefined || x === null;
364
+ }
365
+
366
+ function passStringToWasm0(arg, malloc, realloc) {
367
+ if (realloc === undefined) {
368
+ const buf = cachedTextEncoder.encode(arg);
369
+ const ptr = malloc(buf.length, 1) >>> 0;
370
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
371
+ WASM_VECTOR_LEN = buf.length;
372
+ return ptr;
373
+ }
374
+
375
+ let len = arg.length;
376
+ let ptr = malloc(len, 1) >>> 0;
377
+
378
+ const mem = getUint8ArrayMemory0();
379
+
380
+ let offset = 0;
381
+
382
+ for (; offset < len; offset++) {
383
+ const code = arg.charCodeAt(offset);
384
+ if (code > 0x7F) break;
385
+ mem[ptr + offset] = code;
386
+ }
387
+ if (offset !== len) {
388
+ if (offset !== 0) {
389
+ arg = arg.slice(offset);
390
+ }
391
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
392
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
393
+ const ret = cachedTextEncoder.encodeInto(arg, view);
394
+
395
+ offset += ret.written;
396
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
397
+ }
398
+
399
+ WASM_VECTOR_LEN = offset;
400
+ return ptr;
401
+ }
402
+
403
+ function takeFromExternrefTable0(idx) {
404
+ const value = wasm.__wbindgen_externrefs.get(idx);
405
+ wasm.__externref_table_dealloc(idx);
406
+ return value;
407
+ }
408
+
409
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
410
+ cachedTextDecoder.decode();
411
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
412
+ let numBytesDecoded = 0;
413
+ function decodeText(bytes) {
414
+ numBytesDecoded += bytes.length;
415
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
416
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true });
417
+ cachedTextDecoder.decode();
418
+ numBytesDecoded = bytes.length;
419
+ }
420
+ return cachedTextDecoder.decode(bytes);
421
+ }
422
+
423
+ const cachedTextEncoder = new TextEncoder();
424
+
425
+ if (!('encodeInto' in cachedTextEncoder)) {
426
+ cachedTextEncoder.encodeInto = function (arg, view) {
427
+ const buf = cachedTextEncoder.encode(arg);
428
+ view.set(buf);
429
+ return {
430
+ read: arg.length,
431
+ written: buf.length
432
+ };
433
+ };
434
+ }
435
+
436
+ let WASM_VECTOR_LEN = 0;
437
+
438
+
439
+ let wasm;
440
+ export function __wbg_set_wasm(val) {
441
+ wasm = val;
442
+ }
@@ -0,0 +1,16 @@
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const compare: (a: any, b: any, c: any, d: any, e: any) => [number, number, number];
5
+ export const defaultOptions: () => any;
6
+ export const downsampleMinMax: (a: any, b: any, c: number, d: any) => [number, number, number];
7
+ export const summarize: (a: any, b: number, c: any, d: any, e: any, f: any, g: any, h: any, i: any) => [number, number, number];
8
+ export const version: () => [number, number];
9
+ export const __wbindgen_malloc: (a: number, b: number) => number;
10
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
11
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
12
+ export const __wbindgen_exn_store: (a: number) => void;
13
+ export const __externref_table_alloc: () => number;
14
+ export const __wbindgen_externrefs: WebAssembly.Table;
15
+ export const __externref_table_dealloc: (a: number) => void;
16
+ export const __wbindgen_start: () => void;
package/package.json CHANGED
@@ -1,31 +1,35 @@
1
1
  {
2
2
  "name": "@simtest-js/funnel",
3
- "version": "1.0.0-beta.2",
3
+ "version": "1.0.0-beta.20",
4
4
  "description": "Trajectory comparison library (WASM + TypeScript)",
5
5
  "type": "module",
6
6
  "license": "MIT",
7
- "repository": "https://github.com/Symoptia/simtest-funnel.git",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/Symoptia/simtest-funnel.git"
10
+ },
8
11
  "main": "./dist/index.js",
9
12
  "types": "./dist/index.d.ts",
10
13
  "publishConfig": {
11
14
  "access": "public"
12
15
  },
13
16
  "files": [
14
- "dist",
15
- "src"
17
+ "dist"
16
18
  ],
17
19
  "scripts": {
18
- "build:wasm": "wasm-pack build ../../crates/simtest-funnel-wasm --target bundler --out-dir ./src/wasm",
19
- "build": "pnpm build:wasm && tsc",
20
+ "build:wasm": "wasm-pack build ../../crates/simtest-funnel-wasm --target bundler --out-dir ../../packages/sdk/src/wasm",
21
+ "build:dist": "tsc && cp -r src/wasm dist/wasm && rm -f dist/wasm/.gitignore dist/wasm/package.json",
22
+ "build": "pnpm build:wasm && pnpm build:dist",
20
23
  "test": "vitest run",
21
24
  "lint": "biome check .",
22
- "format": "biome format . --write"
25
+ "format": "biome format . --write",
26
+ "docs": "typedoc src/index.ts --out ../../target/doc/js"
23
27
  },
24
28
  "devDependencies": {
25
- "@biomejs/biome": "^1.7.0",
26
- "typescript": "^5.3.0",
27
- "vite-plugin-wasm": "^3.3.0",
28
- "vite-plugin-top-level-await": "^1.4.0",
29
- "vitest": "^1.0.0"
29
+ "@biomejs/biome": "^2.6.8",
30
+ "typedoc": "^0.28.20",
31
+ "typescript": "^6.0.3",
32
+ "vite-plugin-wasm": "^3.6.0",
33
+ "vitest": "^5.1.0"
30
34
  }
31
35
  }
package/src/index.ts DELETED
@@ -1 +0,0 @@
1
- export { compare, version } from './wasm/simtest_funnel_wasm.js';