@pooder/kit 4.1.0 → 4.3.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.
- package/CHANGELOG.md +12 -0
- package/dist/index.d.mts +62 -10
- package/dist/index.d.ts +62 -10
- package/dist/index.js +756 -348
- package/dist/index.mjs +753 -347
- package/package.json +3 -2
- package/src/CanvasService.ts +96 -89
- package/src/ViewportSystem.ts +92 -0
- package/src/background.ts +230 -230
- package/src/constraints.ts +191 -27
- package/src/coordinate.ts +106 -106
- package/src/dieline.ts +955 -871
- package/src/feature.ts +282 -195
- package/src/featureComplete.ts +46 -0
- package/src/film.ts +194 -194
- package/src/geometry.ts +161 -30
- package/src/image.ts +512 -512
- package/src/index.ts +10 -9
- package/src/mirror.ts +128 -128
- package/src/ruler.ts +508 -500
- package/src/tracer.ts +570 -570
- package/src/units.ts +27 -0
- package/src/white-ink.ts +373 -373
- 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
|
+
}
|