@reekon-tools/boldr-utils 1.6.5 → 1.6.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,2 +1,10 @@
1
1
  export * from './exports.js';
2
+ export { evaluateFormula, createFormulaScope, createEnhancedFormulaScope, clearFormulaCache, type EnhancedMapping, type FormulaDefinition, type FormulaEvaluationOptions, } from './formulas/evaluateFormula.js';
3
+ export { calculateFormula } from './formulas/calculateFormula.js';
4
+ export { convertMicrometers } from './utils/micrometersToUnit.js';
5
+ export { parseMeasurement } from './utils/parseMeasurement.js';
6
+ export { useParseMeasurement } from './hooks/useParseMeasurement.js';
7
+ export * from './types/firestore.js';
8
+ export * from './types/layout.js';
9
+ export { getToleranceColor, getToleranceSecondaryColor, calculateDeviationPercentage, isWithinTolerance, generateToleranceGradient, createDefaultToleranceThresholds, DEFAULT_TOLERANCE_COLORS, DEFAULT_TOLERANCE_SECONDARY_COLORS, type ToleranceThreshold, type ToleranceConfig, } from './utils/tolerance.js';
2
10
  export { AnnotationCanvas, type AnnotationCanvasProps, type CanvasKitOpts, } from './canvas/AnnotationCanvas.js';
package/dist/index.js CHANGED
@@ -3,4 +3,12 @@
3
3
  // WithSkiaWeb. Metro/RN consumers resolve `index.native.ts` instead via
4
4
  // the `react-native` condition in package.json `exports`.
5
5
  export * from './exports.js';
6
+ export { evaluateFormula, createFormulaScope, createEnhancedFormulaScope, clearFormulaCache, } from './formulas/evaluateFormula.js';
7
+ export { calculateFormula } from './formulas/calculateFormula.js';
8
+ export { convertMicrometers } from './utils/micrometersToUnit.js';
9
+ export { parseMeasurement } from './utils/parseMeasurement.js';
10
+ export { useParseMeasurement } from './hooks/useParseMeasurement.js';
11
+ export * from './types/firestore.js';
12
+ export * from './types/layout.js';
13
+ export { getToleranceColor, getToleranceSecondaryColor, calculateDeviationPercentage, isWithinTolerance, generateToleranceGradient, createDefaultToleranceThresholds, DEFAULT_TOLERANCE_COLORS, DEFAULT_TOLERANCE_SECONDARY_COLORS, } from './utils/tolerance.js';
6
14
  export { AnnotationCanvas, } from './canvas/AnnotationCanvas.js';
@@ -105,7 +105,8 @@ export declare enum FileUploadType {
105
105
  LayoutGroup = "layoutGroup",
106
106
  Calculator = "calculator",
107
107
  Conversion = "conversion",
108
- Note = "note"
108
+ Note = "note",
109
+ Label = "label"
109
110
  }
110
111
  export interface AnnotationFileData {
111
112
  fileType: 'sketch' | 'document';
@@ -175,6 +176,9 @@ export type FileUpload = FileUploadBase & ({
175
176
  } | {
176
177
  type: FileUploadType.Template;
177
178
  fileData?: undefined;
179
+ } | {
180
+ type: FileUploadType.Label;
181
+ fileData: Label;
178
182
  });
179
183
  export interface Folder extends FirestoreDoc, Timestamps {
180
184
  name: string;
@@ -247,7 +251,8 @@ export declare enum ColumnType {
247
251
  SingleSelect = "singleSelect",
248
252
  MultiSelect = "multiSelect",
249
253
  Angle = "angle",
250
- ConversionTable = "conversionTable"
254
+ ConversionTable = "conversionTable",
255
+ Instructions = "instructions"
251
256
  }
252
257
  export interface Formula extends FirestoreDoc, Timestamps {
253
258
  expression: string;
@@ -269,6 +274,11 @@ export interface SelectColumnData {
269
274
  export interface ConversionTableColumnData {
270
275
  conversions: Conversion[];
271
276
  }
277
+ export interface InstructionsColumnData {
278
+ text: string;
279
+ textColor: string;
280
+ backgroundColor: string;
281
+ }
272
282
  interface ColumnConfigBase {
273
283
  id: string;
274
284
  name: string;
@@ -300,6 +310,9 @@ export type ColumnConfig = ColumnConfigBase & ({
300
310
  } | {
301
311
  type: ColumnType.Angle;
302
312
  columnData?: undefined;
313
+ } | {
314
+ type: ColumnType.Instructions;
315
+ columnData: InstructionsColumnData;
303
316
  });
304
317
  export interface Row {
305
318
  [key: string]: any;
@@ -24,6 +24,7 @@ export var FileUploadType;
24
24
  FileUploadType["Calculator"] = "calculator";
25
25
  FileUploadType["Conversion"] = "conversion";
26
26
  FileUploadType["Note"] = "note";
27
+ FileUploadType["Label"] = "label";
27
28
  })(FileUploadType || (FileUploadType = {}));
28
29
  export var GroupType;
29
30
  (function (GroupType) {
@@ -41,6 +42,7 @@ export var ColumnType;
41
42
  ColumnType["MultiSelect"] = "multiSelect";
42
43
  ColumnType["Angle"] = "angle";
43
44
  ColumnType["ConversionTable"] = "conversionTable";
45
+ ColumnType["Instructions"] = "instructions";
44
46
  })(ColumnType || (ColumnType = {}));
45
47
  export var MeasurementType;
46
48
  (function (MeasurementType) {
@@ -1,4 +1,5 @@
1
1
  import { DecimalTolerance, FractionalTolerance, Units } from '../types/firestore.js';
2
+ export declare const roundToT1Values: (value: number, u: Units) => number;
2
3
  export declare const convertMicrometers: (micrometers: number | null | undefined, unit: Units, fractionalTolerance: FractionalTolerance, decimalTolerance: DecimalTolerance) => {
3
4
  value: string;
4
5
  unit: string;
@@ -1,12 +1,35 @@
1
1
  import { Units, convertUnitsToReadable, } from '../types/firestore.js';
2
2
  import { create, all } from 'mathjs';
3
3
  const math = create(all);
4
+ // The T1 rounds differently depending on the selected measurement unit.
5
+ // This function mirrors the rounding behavior implemented on the firmware.
6
+ // The value being rounded is in microns.
7
+ export const roundToT1Values = (value, u) => {
8
+ switch (u) {
9
+ case Units.Millimeters:
10
+ case Units.Centimeters:
11
+ return Math.round(value / 500) * 500;
12
+ case Units.Meters:
13
+ return Math.round(value / 1000) * 1000;
14
+ case Units.Inches:
15
+ return Math.round(value / 508) * 508;
16
+ case Units.Feet:
17
+ return Math.round(value / 304.8) * 304.8;
18
+ case Units.FeetInchesDecimal:
19
+ return Math.round(value / 508) * 508;
20
+ case Units.FractionalInches:
21
+ case Units.FeetInchesFractional:
22
+ return value;
23
+ default:
24
+ return Math.round(value / 500) * 500;
25
+ }
26
+ };
4
27
  export const convertMicrometers = (micrometers, unit, fractionalTolerance, decimalTolerance) => {
5
28
  if (micrometers == null || isNaN(micrometers)) {
6
29
  return { value: 'NaN', unit: '' };
7
30
  }
8
31
  try {
9
- const converted = math.unit(micrometers, 'um');
32
+ const converted = math.unit(roundToT1Values(micrometers, unit), 'um');
10
33
  let value = 0;
11
34
  let displayUnit = '';
12
35
  switch (unit) {
@@ -16,6 +16,10 @@ export declare const DEFAULT_TOLERANCE_COLORS: {
16
16
  readonly IN_TOLERANCE: "#22c55e";
17
17
  readonly OUT_OF_TOLERANCE: "#ef4444";
18
18
  };
19
+ export declare const DEFAULT_TOLERANCE_SECONDARY_COLORS: {
20
+ readonly IN_TOLERANCE: "#268F0A";
21
+ readonly OUT_OF_TOLERANCE: "#A91507";
22
+ };
19
23
  /**
20
24
  * Calculates the appropriate color for a measurement based on tolerance thresholds
21
25
  *
@@ -27,6 +31,17 @@ export declare const DEFAULT_TOLERANCE_COLORS: {
27
31
  * @returns The color hex string to use for the measurement
28
32
  */
29
33
  export declare function getToleranceColor(actualValue: number, target: number, min: number, max: number, toleranceConfig?: ToleranceConfig | null): string;
34
+ /**
35
+ * Calculates the appropriate color for a measurement based on tolerance thresholds
36
+ *
37
+ * @param actualValue - The measured value
38
+ * @param target - The target/nominal value
39
+ * @param min - The minimum acceptable value (used as negative tolerance from target)
40
+ * @param max - The maximum acceptable value (used as positive tolerance from target)
41
+ * @param toleranceConfig - Optional tolerance configuration with custom thresholds
42
+ * @returns The color hex string to use for the measurement
43
+ */
44
+ export declare function getToleranceSecondaryColor(actualValue: number, target: number, min: number, max: number, toleranceConfig?: ToleranceConfig | null): string;
30
45
  /**
31
46
  * Calculates the deviation percentage of a measurement from its target
32
47
  *
@@ -5,6 +5,10 @@ export const DEFAULT_TOLERANCE_COLORS = {
5
5
  IN_TOLERANCE: '#22c55e', // Green
6
6
  OUT_OF_TOLERANCE: '#ef4444', // Red
7
7
  };
8
+ export const DEFAULT_TOLERANCE_SECONDARY_COLORS = {
9
+ IN_TOLERANCE: '#268F0A', // Green
10
+ OUT_OF_TOLERANCE: '#A91507', // Red
11
+ };
8
12
  /**
9
13
  * Calculates the appropriate color for a measurement based on tolerance thresholds
10
14
  *
@@ -42,6 +46,43 @@ export function getToleranceColor(actualValue, target, min, max, toleranceConfig
42
46
  }
43
47
  return applicableColor;
44
48
  }
49
+ /**
50
+ * Calculates the appropriate color for a measurement based on tolerance thresholds
51
+ *
52
+ * @param actualValue - The measured value
53
+ * @param target - The target/nominal value
54
+ * @param min - The minimum acceptable value (used as negative tolerance from target)
55
+ * @param max - The maximum acceptable value (used as positive tolerance from target)
56
+ * @param toleranceConfig - Optional tolerance configuration with custom thresholds
57
+ * @returns The color hex string to use for the measurement
58
+ */
59
+ export function getToleranceSecondaryColor(actualValue, target, min, max, toleranceConfig) {
60
+ // If no tolerance config provided, use simple green/red logic
61
+ if (!toleranceConfig?.thresholds || toleranceConfig.thresholds.length === 0) {
62
+ const isWithinTolerance = actualValue >= target - min && actualValue <= target + max;
63
+ return isWithinTolerance
64
+ ? DEFAULT_TOLERANCE_SECONDARY_COLORS.IN_TOLERANCE
65
+ : DEFAULT_TOLERANCE_SECONDARY_COLORS.OUT_OF_TOLERANCE;
66
+ }
67
+ // Calculate deviation percentage
68
+ const deviation = Math.abs(actualValue - target);
69
+ const toleranceRange = max + min; // Fixed: total tolerance range
70
+ const deviationPercentage = toleranceRange > 0 ? (deviation / toleranceRange) * 100 : 0;
71
+ // Sort thresholds by percentage to ensure correct evaluation order
72
+ const sortedThresholds = toleranceConfig.thresholds.sort((a, b) => a.percentage - b.percentage);
73
+ // If deviation is below the first threshold, it's in tolerance (green)
74
+ if (deviationPercentage < sortedThresholds[0].percentage) {
75
+ return DEFAULT_TOLERANCE_SECONDARY_COLORS.IN_TOLERANCE;
76
+ }
77
+ // Find the highest threshold that the deviation exceeds
78
+ let applicableColor = sortedThresholds[0].color;
79
+ for (const threshold of sortedThresholds) {
80
+ if (deviationPercentage >= threshold.percentage) {
81
+ applicableColor = threshold.color;
82
+ }
83
+ }
84
+ return applicableColor;
85
+ }
45
86
  /**
46
87
  * Calculates the deviation percentage of a measurement from its target
47
88
  *
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@reekon-tools/boldr-utils",
3
- "version": "1.6.5",
3
+ "version": "1.6.8",
4
4
  "description": "Shared utilities for formulas and measurement conversion used in Reekon apps",
5
5
  "author": "REEKON Tools",
6
6
  "license": "MIT",
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "scripts": {
25
25
  "build": "tsc",
26
+ "prepack": "yarn run build",
26
27
  "test": "vitest",
27
28
  "coverage": "vitest run --coverage",
28
29
  "format": "prettier --write .",