@pooder/kit 4.0.0 → 4.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 (44) hide show
  1. package/.test-dist/src/CanvasService.js +83 -0
  2. package/.test-dist/src/ViewportSystem.js +75 -0
  3. package/.test-dist/src/background.js +203 -0
  4. package/.test-dist/src/constraints.js +153 -0
  5. package/.test-dist/src/coordinate.js +74 -0
  6. package/.test-dist/src/dieline.js +758 -0
  7. package/.test-dist/src/feature.js +687 -0
  8. package/.test-dist/src/featureComplete.js +31 -0
  9. package/.test-dist/src/featureDraft.js +31 -0
  10. package/.test-dist/src/film.js +167 -0
  11. package/.test-dist/src/geometry.js +292 -0
  12. package/.test-dist/src/image.js +421 -0
  13. package/.test-dist/src/index.js +31 -0
  14. package/.test-dist/src/mirror.js +104 -0
  15. package/.test-dist/src/ruler.js +383 -0
  16. package/.test-dist/src/tracer.js +448 -0
  17. package/.test-dist/src/units.js +30 -0
  18. package/.test-dist/src/white-ink.js +310 -0
  19. package/.test-dist/tests/run.js +60 -0
  20. package/CHANGELOG.md +12 -0
  21. package/dist/index.d.mts +54 -5
  22. package/dist/index.d.ts +54 -5
  23. package/dist/index.js +584 -190
  24. package/dist/index.mjs +581 -189
  25. package/package.json +3 -2
  26. package/src/CanvasService.ts +7 -0
  27. package/src/ViewportSystem.ts +92 -0
  28. package/src/background.ts +230 -230
  29. package/src/constraints.ts +207 -0
  30. package/src/coordinate.ts +106 -106
  31. package/src/dieline.ts +194 -75
  32. package/src/feature.ts +239 -147
  33. package/src/featureComplete.ts +45 -0
  34. package/src/film.ts +194 -194
  35. package/src/geometry.ts +4 -0
  36. package/src/image.ts +512 -512
  37. package/src/index.ts +1 -0
  38. package/src/mirror.ts +128 -128
  39. package/src/ruler.ts +508 -500
  40. package/src/tracer.ts +570 -570
  41. package/src/units.ts +27 -0
  42. package/src/white-ink.ts +373 -373
  43. package/tests/run.ts +81 -0
  44. package/tsconfig.test.json +15 -0
package/src/units.ts ADDED
@@ -0,0 +1,27 @@
1
+ import { Coordinate, Unit } from "./coordinate";
2
+
3
+ export function parseLengthToMm(input: number | string, defaultUnit: Unit): number {
4
+ if (typeof input === "number") {
5
+ if (!Number.isFinite(input)) return 0;
6
+ return Coordinate.convertUnit(input, defaultUnit, "mm");
7
+ }
8
+
9
+ const raw = input.trim();
10
+ if (!raw) return 0;
11
+
12
+ const match = raw.match(/^([+-]?\d+(?:\.\d+)?)\s*(px|mm|cm|in)?$/i);
13
+ if (!match) return 0;
14
+
15
+ const value = Number(match[1]);
16
+ if (!Number.isFinite(value)) return 0;
17
+
18
+ const unit = (match[2]?.toLowerCase() as Unit | undefined) ?? defaultUnit;
19
+ return Coordinate.convertUnit(value, unit, "mm");
20
+ }
21
+
22
+ export function formatMm(valueMm: number, displayUnit: Unit, fractionDigits: number = 2): string {
23
+ if (!Number.isFinite(valueMm)) return "0";
24
+ const value = Coordinate.convertUnit(valueMm, "mm", displayUnit);
25
+ const rounded = Number(value.toFixed(fractionDigits));
26
+ return rounded.toString();
27
+ }