@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/tests/run.ts ADDED
@@ -0,0 +1,81 @@
1
+ import { ConstraintRegistry } from "../src/constraints";
2
+ import { completeFeaturesStrict } from "../src/featureComplete";
3
+ import { ConstraintFeature } from "../src/constraints";
4
+
5
+ function assert(condition: any, message: string) {
6
+ if (!condition) throw new Error(message);
7
+ }
8
+
9
+ function closeTo(a: number, b: number, eps: number = 1e-6) {
10
+ return Math.abs(a - b) <= eps;
11
+ }
12
+
13
+ function testTangentBottom() {
14
+ const feature: ConstraintFeature = {
15
+ id: "stand",
16
+ operation: "add",
17
+ shape: "rect",
18
+ x: 0.5,
19
+ y: 0.2,
20
+ width: 40,
21
+ height: 20,
22
+ constraints: { type: "tangent-bottom", params: { gap: 0 } },
23
+ };
24
+
25
+ const out = ConstraintRegistry.apply(feature.x, feature.y, feature, {
26
+ dielineWidth: 100,
27
+ dielineHeight: 100,
28
+ });
29
+
30
+ assert(closeTo(out.y, 1.1), `tangent-bottom y expected 1.1, got ${out.y}`);
31
+ assert(closeTo(out.x, 0.5), `tangent-bottom x expected 0.5, got ${out.x}`);
32
+ }
33
+
34
+ function testCompleteFeaturesStrict() {
35
+ const updates: any[] = [];
36
+
37
+ const illegal: ConstraintFeature = {
38
+ id: "stand",
39
+ operation: "add",
40
+ shape: "rect",
41
+ x: 0.5,
42
+ y: 0.5,
43
+ width: 40,
44
+ height: 20,
45
+ constraints: { type: "tangent-bottom", params: { gap: 0 } },
46
+ };
47
+
48
+ const failed = completeFeaturesStrict(
49
+ [illegal],
50
+ { dielineWidth: 100, dielineHeight: 100 },
51
+ (next) => updates.push({ key: "dieline.features", value: next }),
52
+ );
53
+ assert(failed.ok === false, "completeFeatures should fail for illegal features");
54
+ assert(updates.length === 0, "illegal draft should not update configuration");
55
+
56
+ const legal: ConstraintFeature = {
57
+ ...illegal,
58
+ y: 1.1,
59
+ };
60
+
61
+ const ok = completeFeaturesStrict(
62
+ [legal],
63
+ { dielineWidth: 100, dielineHeight: 100 },
64
+ (next) => updates.push({ key: "dieline.features", value: next }),
65
+ );
66
+ assert(ok.ok === true, "completeFeatures should succeed for legal features");
67
+ assert(updates.length === 1, "legal draft should update configuration once");
68
+ assert(updates[0].key === "dieline.features", "should update dieline.features");
69
+ assert(
70
+ closeTo(updates[0].value[0].y, 1.1),
71
+ "saved feature y should remain 1.1",
72
+ );
73
+ }
74
+
75
+ function main() {
76
+ testTangentBottom();
77
+ testCompleteFeaturesStrict();
78
+ console.log("ok");
79
+ }
80
+
81
+ main();
@@ -0,0 +1,15 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2020",
4
+ "module": "CommonJS",
5
+ "lib": ["ES2020", "DOM"],
6
+ "moduleResolution": "Node",
7
+ "esModuleInterop": true,
8
+ "skipLibCheck": true,
9
+ "strict": true,
10
+ "outDir": ".test-dist",
11
+ "rootDir": "."
12
+ },
13
+ "include": ["tests/**/*.ts", "src/**/*.ts"]
14
+ }
15
+