@reekon-tools/boldr-cad 1.0.0 → 1.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 (85) hide show
  1. package/README.md +38 -8
  2. package/dist/data/memory.d.ts +4 -1
  3. package/dist/data/memory.js +11 -6
  4. package/dist/data/memory.js.map +1 -1
  5. package/dist/data/provider.d.ts +11 -3
  6. package/dist/data/sync.d.ts +7 -1
  7. package/dist/data/sync.js +18 -2
  8. package/dist/data/sync.js.map +1 -1
  9. package/dist/editor/actions.js +13 -1
  10. package/dist/editor/actions.js.map +1 -1
  11. package/dist/editor/elevation.js +1 -1
  12. package/dist/editor/elevation.js.map +1 -1
  13. package/dist/editor/face.js +2 -2
  14. package/dist/editor/face.js.map +1 -1
  15. package/dist/editor/keypad.d.ts +1 -1
  16. package/dist/editor/keypad.js +24 -7
  17. package/dist/editor/keypad.js.map +1 -1
  18. package/dist/editor/ports.d.ts +2 -0
  19. package/dist/editor/ports.js.map +1 -1
  20. package/dist/editor/project.d.ts +2 -2
  21. package/dist/editor/project.js +7 -4
  22. package/dist/editor/project.js.map +1 -1
  23. package/dist/index.d.ts +3 -2
  24. package/dist/index.js +1 -1
  25. package/dist/index.js.map +1 -1
  26. package/dist/model/planGeom.js +2 -2
  27. package/dist/model/planGeom.js.map +1 -1
  28. package/dist/react/CadEditor.d.ts +8 -1
  29. package/dist/react/CadEditor.js +3 -2
  30. package/dist/react/CadEditor.js.map +1 -1
  31. package/dist/react/Popovers.js +2 -2
  32. package/dist/react/Popovers.js.map +1 -1
  33. package/dist/react/host.d.ts +10 -0
  34. package/dist/react/host.js +19 -1
  35. package/dist/react/host.js.map +1 -1
  36. package/dist/tools/chamfer.js +3 -3
  37. package/dist/tools/chamfer.js.map +1 -1
  38. package/dist/tools/dim.js +4 -4
  39. package/dist/tools/dim.js.map +1 -1
  40. package/dist/tools/elevation.js +4 -4
  41. package/dist/tools/elevation.js.map +1 -1
  42. package/dist/tools/fillet.js +1 -1
  43. package/dist/tools/fillet.js.map +1 -1
  44. package/dist/tools/index.d.ts +1 -0
  45. package/dist/tools/index.js +3 -0
  46. package/dist/tools/index.js.map +1 -1
  47. package/dist/tools/openings.js +3 -3
  48. package/dist/tools/openings.js.map +1 -1
  49. package/dist/tools/survey.d.ts +24 -0
  50. package/dist/tools/survey.js +233 -0
  51. package/dist/tools/survey.js.map +1 -0
  52. package/dist/units/format.d.ts +1 -1
  53. package/dist/units/format.js +9 -3
  54. package/dist/units/format.js.map +1 -1
  55. package/dist/units/parse.d.ts +2 -1
  56. package/dist/units/parse.js +5 -4
  57. package/dist/units/parse.js.map +1 -1
  58. package/dist/units/prefs.d.ts +9 -1
  59. package/dist/units/prefs.js +6 -0
  60. package/dist/units/prefs.js.map +1 -1
  61. package/package.json +1 -1
  62. package/src/data/memory.ts +13 -8
  63. package/src/data/provider.ts +10 -3
  64. package/src/data/sync.ts +20 -3
  65. package/src/editor/actions.ts +14 -3
  66. package/src/editor/elevation.ts +1 -1
  67. package/src/editor/face.ts +2 -2
  68. package/src/editor/keypad.ts +24 -7
  69. package/src/editor/ports.ts +2 -0
  70. package/src/editor/project.ts +7 -5
  71. package/src/index.ts +3 -2
  72. package/src/model/planGeom.ts +2 -2
  73. package/src/react/CadEditor.tsx +10 -5
  74. package/src/react/Popovers.tsx +3 -3
  75. package/src/react/host.ts +19 -1
  76. package/src/tools/chamfer.ts +3 -3
  77. package/src/tools/dim.ts +4 -4
  78. package/src/tools/elevation.ts +4 -4
  79. package/src/tools/fillet.ts +1 -1
  80. package/src/tools/index.ts +4 -0
  81. package/src/tools/openings.ts +3 -3
  82. package/src/tools/survey.ts +216 -0
  83. package/src/units/format.ts +6 -3
  84. package/src/units/parse.ts +4 -3
  85. package/src/units/prefs.ts +13 -1
@@ -1,4 +1,4 @@
1
- import { getUnitPrefs, type UnitPrefs } from './prefs';
1
+ import { getUnitPrefs, isMetric, type UnitPrefs } from './prefs';
2
2
 
3
3
  let custom: ((inches: number) => string) | null = null;
4
4
  let hostPrefs: UnitPrefs | null = null;
@@ -19,11 +19,14 @@ export const hostUnits = (): UnitPrefs | null => (custom ? hostPrefs ?? { unit:
19
19
  export const followingHostUnits = (): boolean => !!custom && !own;
20
20
  export function setOwnUnits(v: boolean): void { own = v; }
21
21
 
22
- /** Format a length in inches: 150.5 → 12'-6 1/2" (ft-in), 150 1/2" (in), 3,823 mm (mm). */
22
+ /** Format a length in inches: 150.5 → 12'-6 1/2" (ft-in), 150 1/2" (in), 12.54' (ft), 3,823 mm (mm), 382.27 cm (cm), 3.823 m (m). */
23
23
  export function fmtLen(v: number, u: UnitPrefs = getUnitPrefs()): string {
24
24
  v = Math.abs(v);
25
25
  if (custom && !own && u === getUnitPrefs()) return custom(v);
26
26
  if (u.unit === 'mm') return Math.round(v * 25.4).toLocaleString() + ' mm';
27
+ if (u.unit === 'cm') return (v * 2.54).toFixed(2) + ' cm';
28
+ if (u.unit === 'm') return (v * 0.0254).toFixed(3) + ' m';
29
+ if (u.unit === 'ft') return (v / 12).toFixed(2) + "'";
27
30
  const d = u.denom;
28
31
  const t = Math.round(v * d) / d;
29
32
  let ft = u.unit === 'ftin' ? Math.floor(t / 12 + 1e-9) : 0;
@@ -41,7 +44,7 @@ export function fmtLen(v: number, u: UnitPrefs = getUnitPrefs()): string {
41
44
 
42
45
  /** Format an area given in square inches. */
43
46
  export function fmtArea(sqin: number, u: UnitPrefs = getUnitPrefs()): string {
44
- if (u.unit === 'mm') return (sqin * 0.00064516).toFixed(2) + ' m²';
47
+ if (isMetric(u.unit)) return (sqin * 0.00064516).toFixed(2) + ' m²';
45
48
  return (sqin / 144).toFixed(1) + ' sq ft';
46
49
  }
47
50
 
@@ -1,4 +1,4 @@
1
- import { getUnitPrefs, type UnitPrefs } from './prefs';
1
+ import { bareScale, getUnitPrefs, type UnitPrefs } from './prefs';
2
2
 
3
3
  /** Tiny recursive-descent evaluator for + - * / and parentheses. Throws on bad input. */
4
4
  export function evalExpr(src: string): number {
@@ -41,7 +41,8 @@ export function evalExpr(src: string): number {
41
41
  /**
42
42
  * Parse a length and return inches, or null if it can't be read.
43
43
  * Accepts 12' 6 1/2", 12ft 6in, 150.5, 3.2m, 25mm, and arithmetic (10'+6).
44
- * Bare numbers are inches in ft-in / in mode and millimetres in mm mode.
44
+ * Bare numbers are read in the current unit: inches in ft-in and in modes, feet in ft, millimetres, centimetres or
45
+ * metres in those.
45
46
  */
46
47
  export function parseLen(str: string | null | undefined, u: UnitPrefs = getUnitPrefs()): number | null {
47
48
  if (str == null) return null;
@@ -58,7 +59,7 @@ export function parseLen(str: string | null | undefined, u: UnitPrefs = getUnitP
58
59
  let v: number;
59
60
  try { v = evalExpr(s); } catch { return null; }
60
61
  if (!isFinite(v)) return null;
61
- if (u.unit === 'mm' && !hasUnit) v /= 25.4;
62
+ if (!hasUnit) v *= bareScale(u.unit);
62
63
  return v;
63
64
  }
64
65
 
@@ -1,10 +1,12 @@
1
- export type Unit = 'ftin' | 'in' | 'mm';
1
+ export type Unit = 'ftin' | 'in' | 'ft' | 'mm' | 'cm' | 'm';
2
2
 
3
3
  /** Display preferences. Geometry is always stored in inches; these only change how values read. */
4
4
  export interface UnitPrefs {
5
5
  unit: Unit;
6
6
  /** Fraction precision for imperial display: 16 → 1/16". */
7
7
  denom: number;
8
+ /** Whether lengths are typed and read with fractions (the fraction keys, Precision). Unset: feet-inches and inches are. */
9
+ fractions?: boolean;
8
10
  }
9
11
 
10
12
  let current: UnitPrefs = { unit: 'ftin', denom: 16 };
@@ -17,3 +19,13 @@ export function useUnitPrefs(p: UnitPrefs): void {
17
19
  export function getUnitPrefs(): UnitPrefs {
18
20
  return current;
19
21
  }
22
+
23
+ /** Metric units: bare numbers, the grid and areas are metric. */
24
+ export const isMetric = (unit: Unit): boolean => unit === 'mm' || unit === 'cm' || unit === 'm';
25
+
26
+ /** Inches per unit typed as a bare number: what a number with no unit means in `unit`. */
27
+ export const bareScale = (unit: Unit): number =>
28
+ unit === 'ft' ? 12 : unit === 'mm' ? 1 / 25.4 : unit === 'cm' ? 1 / 2.54 : unit === 'm' ? 1 / 0.0254 : 1;
29
+
30
+ /** Whether lengths read with fractions (the fraction keys, Precision): as the prefs say, else for feet-inches and inches. */
31
+ export const showFractions = (u: UnitPrefs = getUnitPrefs()): boolean => u.fractions ?? (u.unit === 'ftin' || u.unit === 'in');