numbl 0.4.6 → 0.4.7

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 (50) hide show
  1. package/dist-cli/cli.js +2363 -220
  2. package/dist-graphics/graphics/FigureView.d.ts +6 -0
  3. package/dist-graphics/graphics/SurfView.d.ts +18 -0
  4. package/dist-graphics/graphics/axisLimits.d.ts +23 -0
  5. package/dist-graphics/graphics/drawPlot.d.ts +2 -0
  6. package/dist-graphics/graphics/exportFigureHdf5.d.ts +21 -0
  7. package/dist-graphics/graphics/figureHashTransport.d.ts +24 -0
  8. package/dist-graphics/graphics/figureHdf5Schema.d.ts +19 -0
  9. package/dist-graphics/graphics/figureUpload.d.ts +45 -0
  10. package/dist-graphics/graphics/figuresReducer.d.ts +86 -0
  11. package/dist-graphics/graphics/importFigureHdf5.d.ts +9 -0
  12. package/dist-graphics/graphics/openInFigureViewer.d.ts +26 -0
  13. package/dist-graphics/graphics/plotHelpers.d.ts +6 -0
  14. package/dist-graphics/graphics/plotLegend.d.ts +2 -0
  15. package/dist-graphics/graphics/plotMarkers.d.ts +2 -0
  16. package/dist-graphics/graphics/restoreNaNs.d.ts +2 -0
  17. package/dist-graphics/graphics/surfColormap.d.ts +2 -0
  18. package/dist-graphics/graphics/types.d.ts +423 -0
  19. package/dist-graphics/graphics/uihtmlSrcDoc.d.ts +23 -0
  20. package/dist-graphics/graphics-lib.d.ts +21 -0
  21. package/dist-graphics/index.js +35334 -0
  22. package/dist-lib/lib.js +2349 -216
  23. package/dist-lib/numbl-core/interpreter/builtins/gallery.d.ts +7 -0
  24. package/dist-lib/numbl-core/interpreter/builtins/geometry.d.ts +3 -3
  25. package/dist-lib/numbl-core/interpreter/builtins/graph.d.ts +29 -0
  26. package/dist-lib/numbl-core/interpreter/builtins/index.d.ts +2 -0
  27. package/dist-lib/numbl-core/interpreter/interpreter.d.ts +5 -0
  28. package/dist-lib/numbl-core/interpreter/interpreterExec.d.ts +14 -1
  29. package/dist-lib/numbl-core/interpreter/interpreterFunctions.d.ts +6 -0
  30. package/dist-lib/numbl-core/interpreter/interpreterSpecialBuiltins.d.ts +4 -0
  31. package/dist-lib/numbl-core/interpreter/types.d.ts +13 -0
  32. package/dist-lib/numbl-core/lowering/classInfo.d.ts +19 -2
  33. package/dist-lib/numbl-core/native/geometry-bridge.d.ts +10 -0
  34. package/dist-lib/numbl-core/parser/ArgumentsParser.d.ts +6 -1
  35. package/dist-lib/numbl-core/runtime/constructors.d.ts +2 -1
  36. package/dist-lib/numbl-core/runtime/runtime.d.ts +2 -1
  37. package/dist-lib/numbl-core/runtime/runtimeMemberAccess.d.ts +1 -1
  38. package/dist-lib/numbl-core/version.d.ts +1 -1
  39. package/dist-plot-viewer/assets/hdf5_hl-C9YUKPMe.js +24296 -0
  40. package/dist-plot-viewer/assets/index-YeXWXIxH.js +4504 -0
  41. package/dist-plot-viewer/index.html +1 -1
  42. package/dist-site-viewer/assets/hdf5_hl-C9YUKPMe.js +24296 -0
  43. package/dist-site-viewer/assets/index-RucHpf4b.js +4826 -0
  44. package/dist-site-viewer/assets/numbl-worker-IO39kohI.js +5228 -0
  45. package/dist-site-viewer/index.html +1 -1
  46. package/native/lapack_svd.cpp +50 -0
  47. package/package.json +21 -2
  48. package/dist-plot-viewer/assets/index-D4grNz8m.js +0 -4504
  49. package/dist-site-viewer/assets/index-B2mCFC55.js +0 -4826
  50. package/dist-site-viewer/assets/numbl-worker-DWZE29ck.js +0 -5116
@@ -0,0 +1,6 @@
1
+ import type { FigureState } from "./figuresReducer.js";
2
+ interface FigureViewProps {
3
+ figure: FigureState;
4
+ }
5
+ export declare function FigureView({ figure }: FigureViewProps): import("react/jsx-runtime").JSX.Element | null;
6
+ export {};
@@ -0,0 +1,18 @@
1
+ import type { SurfTrace, Plot3Trace, Bar3Trace, Quiver3Trace, PatchTrace } from "./types.js";
2
+ interface SurfViewProps {
3
+ surfTraces: SurfTrace[];
4
+ plot3Traces?: Plot3Trace[];
5
+ bar3Traces?: Bar3Trace[];
6
+ bar3hTraces?: Bar3Trace[];
7
+ quiver3Traces?: Quiver3Trace[];
8
+ /** 3-D patches (e.g. from trimesh(T,x,y,z)). 2-D patches are placed at z=0. */
9
+ patchTraces?: PatchTrace[];
10
+ shading?: "faceted" | "flat" | "interp";
11
+ colorbar?: boolean;
12
+ colorbarLocation?: string;
13
+ colormap?: string;
14
+ /** `axis off` hides the axes box/lines (the plotted surfaces remain). */
15
+ axisVisible?: boolean;
16
+ }
17
+ export declare function SurfView({ surfTraces, plot3Traces, bar3Traces, bar3hTraces, quiver3Traces, patchTraces, shading, colorbar, colorbarLocation, colormap, axisVisible, }: SurfViewProps): import("react/jsx-runtime").JSX.Element;
18
+ export {};
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Pure computation of the current axis limits for an `AxesState`.
3
+ *
4
+ * This is the source of truth for the query form `lim = axis`: the numbl
5
+ * runtime reduces its accumulated plot instructions into an `AxesState` and
6
+ * asks this module for the limit vector. It is deliberately rendering-free
7
+ * (no canvas, no DOM) so numbl-core can import it.
8
+ *
9
+ * For an axis with an explicit limit, that limit is returned verbatim (a
10
+ * `null` bound falls back to the data-derived bound). For a fully automatic
11
+ * axis the data extent is computed across every trace type and padded the
12
+ * same way `drawPlot` pads a default 2-D view, so the reported limits track
13
+ * what is drawn.
14
+ */
15
+ import type { AxesState } from "./figuresReducer.js";
16
+ /** Does this axes hold any 3-D content (so limits are a 6-vector)? */
17
+ export declare function axesIs3D(axes: AxesState): boolean;
18
+ /**
19
+ * Compute the limit vector for `lim = axis`.
20
+ * Returns 4 elements `[xmin xmax ymin ymax]` for a 2-D view, or 6 elements
21
+ * `[xmin xmax ymin ymax zmin zmax]` when the axes holds 3-D content.
22
+ */
23
+ export declare function computeAxisLimits(axes: AxesState): number[];
@@ -0,0 +1,2 @@
1
+ import type { PlotTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, PatchTrace } from "./types.js";
2
+ export declare function drawPlot(canvas: HTMLCanvasElement, traces: PlotTrace[], title?: string, xlabel?: string, ylabel?: string, legend?: string[], gridOn?: boolean, imagescTrace?: ImagescTrace, contourTraces?: ContourTrace[], colormap?: string, axisMode?: string, axisScale?: "linear" | "semilogx" | "semilogy" | "loglog", barTraces?: BarTrace[], barhTraces?: BarTrace[], errorBarTraces?: ErrorBarTrace[], boxTraces?: BoxTrace[], pieTrace?: PieTrace, heatmapTrace?: HeatmapTrace, areaTraces?: PlotTrace[], areaBaseValue?: number, pcolorTraces?: PcolorTrace[], shading?: "faceted" | "flat" | "interp", colorbar?: boolean, colorbarLocation?: string, caxis?: [number, number], colormapData?: number[][], quiverTraces?: QuiverTrace[], xlim?: [number | null, number | null], ylim?: [number | null, number | null], yDir?: "normal" | "reverse", axisVisible?: boolean, boxOn?: boolean, patchTraces?: PatchTrace[]): void;
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Export a figure's data to a self-describing HDF5 file ("numbl figure HDF5
3
+ * layout v1"). The file holds everything needed to recreate the figure:
4
+ * numeric data arrays are stored as gzip-compressed datasets, and all styling /
5
+ * scalar metadata as attributes. The schema is documented in
6
+ * docs/figure-hdf5-format.md.
7
+ *
8
+ * h5wasm (the only mature in-browser HDF5 writer) is loaded lazily via dynamic
9
+ * import so its ~MB of JS+wasm never enters the main bundle — it is fetched the
10
+ * first time a user actually downloads a figure. h5wasm's browser build needs
11
+ * no COOP/COEP (no SharedArrayBuffer), and in Node it reads its wasm from disk.
12
+ *
13
+ * Tensors in numbl are column-major; 2-D grids (surf/imagesc/pcolor/...) are
14
+ * transposed to row-major [rows, cols] datasets so generic HDF5 viewers
15
+ * (h5web, Panoply, h5py) render them correctly without numbl conventions.
16
+ */
17
+ import type { FigureState } from "./figuresReducer.js";
18
+ export declare function exportFigureHdf5(figure: FigureState): Promise<Uint8Array>;
19
+ /** Build the HDF5 bytes for a figure and trigger a browser download.
20
+ * Browser-only (uses the DOM). `handle` is used for the default filename. */
21
+ export declare function downloadFigureHdf5(figure: FigureState, handle: number): Promise<void>;
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Encode/decode a figure into a URL hash fragment, for handing a figure from
3
+ * numbl to the figure viewer in a new tab.
4
+ *
5
+ * Why the URL and not postMessage: numbl sets COOP `same-origin` (for
6
+ * SharedArrayBuffer / crossOriginIsolated), which severs the opener⇄popup
7
+ * relationship for a cross-origin viewer tab — `window.opener` is null and the
8
+ * opener's window handle reports `closed`, so postMessage can't reach it. The
9
+ * navigation URL is the one channel that survives, so the figure rides in the
10
+ * hash.
11
+ *
12
+ * Payload = gzip(JSON(figure)) → base64url. JSON is made NaN/Infinity-safe with
13
+ * sentinels (JSON.stringify would otherwise turn them into null). Encoding is
14
+ * synchronous so the caller can `window.open` within the click gesture.
15
+ */
16
+ import type { FigureState } from "./figuresReducer.js";
17
+ export declare const FIGURE_HASH_KEY = "fig";
18
+ export declare function bytesToBase64url(bytes: Uint8Array): string;
19
+ export declare function base64urlToBytes(s: string): Uint8Array;
20
+ /** `fig=<base64url(gzip(json))>` — append to a viewer URL after `#`. */
21
+ export declare function encodeFigureToHash(figure: FigureState): string;
22
+ /** Parse a figure out of a `location.hash` (or any `fig=…` string); null if
23
+ * absent or malformed. */
24
+ export declare function decodeFigureFromHash(hash: string): FigureState | null;
@@ -0,0 +1,19 @@
1
+ /** Shared constants for the "numbl figure HDF5 layout". The on-disk schema is
2
+ * documented in docs/figure-hdf5-format.md; the writer is exportFigureHdf5.ts
3
+ * and the reader is importFigureHdf5.ts. Keeping these tables in one place
4
+ * keeps the two directions in sync. */
5
+ /** Version written as the root `numbl_figure_version` attribute. Bump on
6
+ * incompatible schema changes. */
7
+ export declare const FIGURE_HDF5_VERSION = 1;
8
+ /** Per-kind fields that are flat column-major rows×cols grids — stored as
9
+ * row-major `[rows, cols]` datasets (transposed on write, untransposed on
10
+ * read). */
11
+ export declare const GRID_FIELDS: Record<string, string[]>;
12
+ /** Maps a trace's `kind` attribute to the AxesState field it belongs in.
13
+ * `single` marks the one-per-axes traces (imagesc/pie/heatmap). */
14
+ export declare const KIND_TO_CATEGORY: Record<string, {
15
+ field: string;
16
+ single?: boolean;
17
+ }>;
18
+ /** Trace boolean fields, stored as 0/1 int attributes; coerced back on read. */
19
+ export declare const TRACE_BOOLEAN_FIELDS: Set<string>;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Fallback figure hand-off for figures too large to fit in a URL hash: upload
3
+ * the figure (as an encrypted `.h5`) to a temporary file host and pass only the
4
+ * download URL + decryption key to the viewer.
5
+ *
6
+ * Privacy: the figure is AES-GCM encrypted in the browser before upload, and the
7
+ * key travels only in the viewer URL's fragment (never sent to any server), so
8
+ * the host stores opaque bytes. See loadFigureFromHash for the viewer side.
9
+ *
10
+ * The uploader is pluggable (FigureUploader) — numbl's own figure-store relay
11
+ * (a Cloudflare Worker on a numbl.org subdomain) is the default; swap it via
12
+ * setFigureUploader for any service that returns its own download URL. The
13
+ * viewer just fetches whatever URL it's handed.
14
+ */
15
+ import type { FigureState } from "./figuresReducer.js";
16
+ /** Uploads bytes to a temporary host and resolves to a URL the viewer can GET
17
+ * (cross-origin) to retrieve them. Throws on failure. */
18
+ export type FigureUploader = (data: Uint8Array, filename: string) => Promise<string>;
19
+ /** numbl's figure-store relay (Cloudflare Worker). See figure-store-spec.md.
20
+ * Override for local/staging via: localStorage["numblFigureStoreUrl"]. */
21
+ export declare const DEFAULT_FIGURE_STORE_URL = "https://figures.numbl.org/";
22
+ /** Default uploader: numbl's figure-store relay. Uploads the opaque (encrypted)
23
+ * bytes as a raw octet-stream body and returns the download URL from the
24
+ * response `{ url }`. Until the service is deployed, this rejects and the
25
+ * caller falls back to the manual download/upload message. */
26
+ export declare const numblStoreUploader: FigureUploader;
27
+ /** Swap the temporary-host uploader (e.g. a self-hosted service). */
28
+ export declare function setFigureUploader(uploader: FigureUploader): void;
29
+ /**
30
+ * Export the figure to an encrypted `.h5`, upload it, and return a viewer URL
31
+ * referencing it: `<base>#u=<download-url>&k=<key>&iv=<iv>`. Throws if the
32
+ * upload fails (callers fall back to manual download). Asynchronous, so the
33
+ * caller can't `window.open` the result directly (popup blocking) — surface the
34
+ * URL as a link for the user to click.
35
+ */
36
+ export declare function uploadFigureForViewer(figure: FigureState, opts?: {
37
+ viewerUrl?: string;
38
+ uploader?: FigureUploader;
39
+ }): Promise<string>;
40
+ /**
41
+ * Viewer side: load a figure from a viewer URL hash. Handles both the direct
42
+ * (`fig=…`) and uploaded (`u=…&k=…&iv=…`) forms. Returns null if the hash
43
+ * carries no figure; throws if a referenced upload can't be fetched/decrypted.
44
+ */
45
+ export declare function loadFigureFromHash(hash: string): Promise<FigureState | null>;
@@ -0,0 +1,86 @@
1
+ import type { PlotTrace, Plot3Trace, PatchTrace, SurfTrace, ImagescTrace, PcolorTrace, ContourTrace, BarTrace, Bar3Trace, ErrorBarTrace, BoxTrace, PieTrace, HeatmapTrace, QuiverTrace, Quiver3Trace, PlotInstruction } from "./types.js";
2
+ export type AxesState = {
3
+ holdOn: boolean;
4
+ traces: PlotTrace[];
5
+ plot3Traces: Plot3Trace[];
6
+ surfTraces: SurfTrace[];
7
+ imagescTrace?: ImagescTrace;
8
+ pcolorTraces: PcolorTrace[];
9
+ contourTraces: ContourTrace[];
10
+ barTraces: BarTrace[];
11
+ barhTraces: BarTrace[];
12
+ bar3Traces: Bar3Trace[];
13
+ bar3hTraces: Bar3Trace[];
14
+ errorBarTraces: ErrorBarTrace[];
15
+ boxTraces: BoxTrace[];
16
+ pieTrace?: PieTrace;
17
+ heatmapTrace?: HeatmapTrace;
18
+ quiverTraces: QuiverTrace[];
19
+ quiver3Traces: Quiver3Trace[];
20
+ areaTraces: PlotTrace[];
21
+ areaBaseValue: number;
22
+ patchTraces: PatchTrace[];
23
+ title?: string;
24
+ xlabel?: string;
25
+ ylabel?: string;
26
+ zlabel?: string;
27
+ shading?: "faceted" | "flat" | "interp";
28
+ legend?: string[];
29
+ gridOn?: boolean;
30
+ /** Axes border. Undefined/true → full rectangle (numbl's default, matching
31
+ * MATLAB `box on`); false → only the left and bottom axis lines (`box off`). */
32
+ boxOn?: boolean;
33
+ colorbar?: boolean;
34
+ colorbarLocation?: string;
35
+ colormap?: string;
36
+ colormapData?: number[][];
37
+ view?: {
38
+ az: number;
39
+ el: number;
40
+ };
41
+ axisMode?: string;
42
+ axisScale?: "linear" | "semilogx" | "semilogy" | "loglog";
43
+ caxis?: [number, number];
44
+ /** Explicit axis limits from `axis([...])` / `xlim` / `ylim`. Each bound
45
+ * may be `null`, meaning "use the data-derived bound" (partial limits). An
46
+ * absent field means the whole axis is automatic. */
47
+ xlim?: [number | null, number | null];
48
+ ylim?: [number | null, number | null];
49
+ zlim?: [number | null, number | null];
50
+ /** y-axis direction: "reverse" is `axis ij` (origin at top-left). */
51
+ yDir?: "normal" | "reverse";
52
+ /** Axes lines/background visibility (`axis off` sets this false). */
53
+ axisVisible?: boolean;
54
+ };
55
+ export type FigureState = {
56
+ subplotGrid?: {
57
+ rows: number;
58
+ cols: number;
59
+ };
60
+ currentAxesIndex: number;
61
+ sgtitle?: string;
62
+ axes: {
63
+ [index: number]: AxesState;
64
+ };
65
+ /** When set, this figure is an HTML UI component (MATLAB `uihtml`): the
66
+ * `html` string is rendered in an iframe instead of the axes/trace canvas.
67
+ * Takes precedence over `axes`. `data` is the JSON-encoded `Data` property
68
+ * (from `jsonencode`), pushed into the page's `htmlComponent`. */
69
+ uihtml?: {
70
+ id: string;
71
+ html: string;
72
+ data?: string;
73
+ };
74
+ };
75
+ export type FiguresState = {
76
+ currentHandle: number;
77
+ figs: {
78
+ [handle: number]: FigureState;
79
+ };
80
+ };
81
+ /** Actions accepted by the figures reducer: any PlotInstruction, plus "clear" for UI resets. */
82
+ export type FiguresAction = PlotInstruction | {
83
+ type: "clear";
84
+ };
85
+ export declare const initialFiguresState: FiguresState;
86
+ export declare const figuresReducer: (state: FiguresState, action: FiguresAction) => FiguresState;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Read a "numbl figure HDF5 layout v1" file (see docs/figure-hdf5-format.md)
3
+ * back into a `FigureState` that `FigureView` can render. The inverse of
4
+ * exportFigureHdf5.ts. h5wasm is loaded lazily via dynamic import, same as the
5
+ * writer.
6
+ */
7
+ import type { FigureState } from "./figuresReducer.js";
8
+ /** Parse a numbl-figure HDF5 file into a renderable `FigureState`. */
9
+ export declare function importFigureHdf5(bytes: Uint8Array): Promise<FigureState>;
@@ -0,0 +1,26 @@
1
+ import type { FigureState } from "./figuresReducer.js";
2
+ /** Deployed numbl figure viewer (concept-collection). */
3
+ export declare const DEFAULT_FIGURE_VIEWER_URL = "https://concept-collection.github.io/numbl-figure-viewer/";
4
+ /** Resolve the viewer URL: explicit arg › localStorage dev override › default.
5
+ * For local development, set in the numbl tab's console:
6
+ * localStorage.setItem("numblFigureViewerUrl", "http://localhost:5173/") */
7
+ export declare function resolveFigureViewerUrl(explicit?: string): string;
8
+ export interface FigureViewerLink {
9
+ /** Viewer URL with the figure embedded in the hash, or null if too large. */
10
+ url: string | null;
11
+ /** Viewer base URL (open empty, for loading a downloaded .h5 manually). */
12
+ baseUrl: string;
13
+ /** True when the figure won't fit in a URL and must be handed over as a file. */
14
+ tooLarge: boolean;
15
+ }
16
+ /**
17
+ * Build the link that opens the figure viewer with `figure` embedded in the URL
18
+ * hash (gzip+base64url, NaN-safe — see figureHashTransport). The hash is the one
19
+ * channel that survives numbl's COOP isolation (postMessage to a cross-origin
20
+ * popup is blocked there).
21
+ *
22
+ * Pure — it opens nothing. The caller decides: open `url` in response to the
23
+ * user's click when it fits, or, when `tooLarge`, show an in-page message with a
24
+ * link to `baseUrl` so the user can open the viewer and load a downloaded .h5.
25
+ */
26
+ export declare function buildFigureViewerLink(figure: FigureState, viewerUrl?: string): FigureViewerLink;
@@ -0,0 +1,6 @@
1
+ import type { PlotTrace } from "./types.js";
2
+ export declare function rgbToCSS(rgb: [number, number, number]): string;
3
+ export declare function traceColor(trace: PlotTrace, index: number): string;
4
+ export declare function getLineDash(style: string | undefined): number[];
5
+ export declare function generateTicks(min: number, max: number, maxTicks: number): number[];
6
+ export declare function formatTick(v: number): string;
@@ -0,0 +1,2 @@
1
+ import type { PlotTrace } from "./types.js";
2
+ export declare function drawLegend(ctx: CanvasRenderingContext2D, traces: PlotTrace[], labels: string[], plotRight: number, plotTop: number): void;
@@ -0,0 +1,2 @@
1
+ import type { PlotTrace } from "./types.js";
2
+ export declare function drawMarkers(ctx: CanvasRenderingContext2D, trace: PlotTrace, toCanvasX: (v: number) => number, toCanvasY: (v: number) => number, defaultColor: string): void;
@@ -0,0 +1,2 @@
1
+ import type { PlotInstruction } from "./types.js";
2
+ export declare function restoreNaNs(instr: PlotInstruction): void;
@@ -0,0 +1,2 @@
1
+ /** Parula-inspired colormap for surface plots */
2
+ export declare function colormapLookup(t: number): [number, number, number];