nirs4all-ui 0.1.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 (42) hide show
  1. package/README.md +42 -0
  2. package/dist/components/RuntimeEngineBadge.d.ts +15 -0
  3. package/dist/components/RuntimeEngineBadge.d.ts.map +1 -0
  4. package/dist/components/RuntimeEngineBadge.js +12 -0
  5. package/dist/components/RuntimeEngineBadge.js.map +1 -0
  6. package/dist/components/index.d.ts +2 -0
  7. package/dist/components/index.d.ts.map +1 -0
  8. package/dist/components/index.js +2 -0
  9. package/dist/components/index.js.map +1 -0
  10. package/dist/index.d.ts +11 -0
  11. package/dist/index.d.ts.map +1 -0
  12. package/dist/index.js +11 -0
  13. package/dist/index.js.map +1 -0
  14. package/dist/runtime/index.d.ts +18 -0
  15. package/dist/runtime/index.d.ts.map +1 -0
  16. package/dist/runtime/index.js +20 -0
  17. package/dist/runtime/index.js.map +1 -0
  18. package/dist/runtime/resultMetadata.d.ts +64 -0
  19. package/dist/runtime/resultMetadata.d.ts.map +1 -0
  20. package/dist/runtime/resultMetadata.js +310 -0
  21. package/dist/runtime/resultMetadata.js.map +1 -0
  22. package/dist/runtime/statusDisplay.d.ts +38 -0
  23. package/dist/runtime/statusDisplay.d.ts.map +1 -0
  24. package/dist/runtime/statusDisplay.js +89 -0
  25. package/dist/runtime/statusDisplay.js.map +1 -0
  26. package/dist/score/index.d.ts +19 -0
  27. package/dist/score/index.d.ts.map +1 -0
  28. package/dist/score/index.js +19 -0
  29. package/dist/score/index.js.map +1 -0
  30. package/dist/score/metricKeys.d.ts +18 -0
  31. package/dist/score/metricKeys.d.ts.map +1 -0
  32. package/dist/score/metricKeys.js +63 -0
  33. package/dist/score/metricKeys.js.map +1 -0
  34. package/dist/score/scoreMetricCatalog.d.ts +59 -0
  35. package/dist/score/scoreMetricCatalog.d.ts.map +1 -0
  36. package/dist/score/scoreMetricCatalog.js +324 -0
  37. package/dist/score/scoreMetricCatalog.js.map +1 -0
  38. package/dist/score/scoreValues.d.ts +28 -0
  39. package/dist/score/scoreValues.d.ts.map +1 -0
  40. package/dist/score/scoreValues.js +92 -0
  41. package/dist/score/scoreValues.js.map +1 -0
  42. package/package.json +58 -0
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Pure score-value helpers: parsing, direction-aware comparison, and display
3
+ * formatting. These depend only on metric-key normalization (no metric
4
+ * catalog), so they form a small, self-contained, easily testable slice.
5
+ */
6
+ /** Coerce a value to a finite number, or null. Accepts numbers and numeric strings. */
7
+ export declare function parseScoreNumber(value: unknown): number | null;
8
+ export declare function parseJsonRecord(value: unknown): Record<string, unknown> | null;
9
+ export declare function isLowerBetter(metric: string | null | undefined): boolean;
10
+ /**
11
+ * Compare two scores, respecting the metric direction.
12
+ * Returns true if `a` is better than `b`.
13
+ */
14
+ export declare function isBetterScore(a: number, b: number, metric: string | null | undefined): boolean;
15
+ /**
16
+ * Format a score value to 4 decimal places (or 3 for error metrics).
17
+ */
18
+ export declare function formatScore(value: number | string | undefined | null): string;
19
+ /**
20
+ * Format a metric-specific value (3 decimals for error metrics, 4 for others).
21
+ */
22
+ export declare function formatMetricValue(value: number | string | undefined | null, metric?: string): string;
23
+ /**
24
+ * Format a metric name for display (uppercase).
25
+ */
26
+ export declare function formatMetricName(metric: string | null | undefined): string;
27
+ export declare function formatMetricDisplayName(metric: string | null | undefined): string;
28
+ //# sourceMappingURL=scoreValues.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scoreValues.d.ts","sourceRoot":"","sources":["../../src/score/scoreValues.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAUH,uFAAuF;AACvF,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,GAAG,IAAI,CAO9D;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAe9E;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAExE;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAE9F;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,MAAM,CAK7E;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,IAAI,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAMpG;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CAG1E;AAED,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,MAAM,CASjF"}
@@ -0,0 +1,92 @@
1
+ /**
2
+ * Pure score-value helpers: parsing, direction-aware comparison, and display
3
+ * formatting. These depend only on metric-key normalization (no metric
4
+ * catalog), so they form a small, self-contained, easily testable slice.
5
+ */
6
+ import { canonicalMetricKey, normalizeMetricLookupKey } from "./metricKeys.js";
7
+ /** Metrics where lower values are better (error-based). */
8
+ const LOWER_IS_BETTER = new Set([
9
+ "rmse", "rmsecv", "rmsep", "mse", "mae", "mape", "bias", "sep", "nrmse",
10
+ "nmse", "nmae", "max_error", "median_ae", "hamming_loss", "log_loss",
11
+ ]);
12
+ /** Coerce a value to a finite number, or null. Accepts numbers and numeric strings. */
13
+ export function parseScoreNumber(value) {
14
+ if (typeof value === "number")
15
+ return Number.isFinite(value) ? value : null;
16
+ if (typeof value === "string") {
17
+ const parsed = Number.parseFloat(value);
18
+ return Number.isFinite(parsed) ? parsed : null;
19
+ }
20
+ return null;
21
+ }
22
+ export function parseJsonRecord(value) {
23
+ if (!value)
24
+ return null;
25
+ if (typeof value === "string") {
26
+ try {
27
+ const parsed = JSON.parse(value);
28
+ return parsed && typeof parsed === "object" && !Array.isArray(parsed)
29
+ ? parsed
30
+ : null;
31
+ }
32
+ catch {
33
+ return null;
34
+ }
35
+ }
36
+ return typeof value === "object" && !Array.isArray(value)
37
+ ? value
38
+ : null;
39
+ }
40
+ export function isLowerBetter(metric) {
41
+ return LOWER_IS_BETTER.has(canonicalMetricKey(metric));
42
+ }
43
+ /**
44
+ * Compare two scores, respecting the metric direction.
45
+ * Returns true if `a` is better than `b`.
46
+ */
47
+ export function isBetterScore(a, b, metric) {
48
+ return isLowerBetter(metric) ? a < b : a > b;
49
+ }
50
+ /**
51
+ * Format a score value to 4 decimal places (or 3 for error metrics).
52
+ */
53
+ export function formatScore(value) {
54
+ if (value == null)
55
+ return "-";
56
+ const num = typeof value === "string" ? parseFloat(value) : value;
57
+ if (!Number.isFinite(num))
58
+ return "-";
59
+ return num.toFixed(4);
60
+ }
61
+ /**
62
+ * Format a metric-specific value (3 decimals for error metrics, 4 for others).
63
+ */
64
+ export function formatMetricValue(value, metric) {
65
+ if (value == null)
66
+ return "-";
67
+ const num = typeof value === "string" ? parseFloat(value) : value;
68
+ if (!Number.isFinite(num))
69
+ return "-";
70
+ if (metric && isLowerBetter(metric))
71
+ return num.toFixed(3);
72
+ return num.toFixed(4);
73
+ }
74
+ /**
75
+ * Format a metric name for display (uppercase).
76
+ */
77
+ export function formatMetricName(metric) {
78
+ if (!metric)
79
+ return "";
80
+ return (canonicalMetricKey(metric) || normalizeMetricLookupKey(metric)).toUpperCase();
81
+ }
82
+ export function formatMetricDisplayName(metric) {
83
+ const normalized = canonicalMetricKey(metric) || normalizeMetricLookupKey(metric);
84
+ if (!normalized)
85
+ return "";
86
+ return normalized
87
+ .split("_")
88
+ .filter(Boolean)
89
+ .map((part) => (part.length <= 4 ? part.toUpperCase() : part.charAt(0).toUpperCase() + part.slice(1)))
90
+ .join("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CAAC;IAClE,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC;QAAE,OAAO,GAAG,CAAC;IACtC,IAAI,MAAM,IAAI,aAAa,CAAC,MAAM,CAAC;QAAE,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;IAC3D,OAAO,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,MAAiC;IAChE,IAAI,CAAC,MAAM;QAAE,OAAO,EAAE,CAAC;IACvB,OAAO,CAAC,kBAAkB,CAAC,MAAM,CAAC,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC;AACxF,CAAC;AAED,MAAM,UAAU,uBAAuB,CAAC,MAAiC;IACvE,MAAM,UAAU,GAAG,kBAAkB,CAAC,MAAM,CAAC,IAAI,wBAAwB,CAAC,MAAM,CAAC,CAAC;IAClF,IAAI,CAAC,UAAU;QAAE,OAAO,EAAE,CAAC;IAE3B,OAAO,UAAU;SACd,KAAK,CAAC,GAAG,CAAC;SACV,MAAM,CAAC,OAAO,CAAC;SACf,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,MAAM,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC;SACrG,IAAI,CAAC,GAAG,CAAC,CAAC;AACf,CAAC"}
package/package.json ADDED
@@ -0,0 +1,58 @@
1
+ {
2
+ "name": "nirs4all-ui",
3
+ "version": "0.1.0",
4
+ "description": "Shared React UI components and pure view-model helpers for nirs4all apps.",
5
+ "type": "module",
6
+ "license": "(CECILL-2.1 OR AGPL-3.0-or-later)",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/GBeurier/nirs4all-ui.git"
10
+ },
11
+ "private": false,
12
+ "sideEffects": false,
13
+ "files": [
14
+ "dist",
15
+ "README.md"
16
+ ],
17
+ "main": "./dist/index.js",
18
+ "types": "./dist/index.d.ts",
19
+ "exports": {
20
+ ".": {
21
+ "types": "./dist/index.d.ts",
22
+ "import": "./dist/index.js"
23
+ },
24
+ "./score": {
25
+ "types": "./dist/score/index.d.ts",
26
+ "import": "./dist/score/index.js"
27
+ },
28
+ "./runtime": {
29
+ "types": "./dist/runtime/index.d.ts",
30
+ "import": "./dist/runtime/index.js"
31
+ },
32
+ "./components": {
33
+ "types": "./dist/components/index.d.ts",
34
+ "import": "./dist/components/index.js"
35
+ }
36
+ },
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.build.json",
39
+ "ci": "npm run prepublishOnly && npm run pack:smoke",
40
+ "pack:smoke": "npm pack --dry-run",
41
+ "typecheck": "tsc -p tsconfig.json --noEmit",
42
+ "test": "vitest run",
43
+ "prepack": "npm run build",
44
+ "prepublishOnly": "npm run typecheck && npm test && npm run build",
45
+ "test:watch": "vitest"
46
+ },
47
+ "peerDependencies": {
48
+ "react": ">=18 <20"
49
+ },
50
+ "devDependencies": {
51
+ "@types/react": "^19.2.7",
52
+ "@types/react-dom": "^19.2.3",
53
+ "react": "^19.2.3",
54
+ "react-dom": "^19.2.3",
55
+ "typescript": "^5.8.3",
56
+ "vitest": "^3.2.4"
57
+ }
58
+ }