@pooder/kit 4.3.1 → 5.0.1

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 (60) hide show
  1. package/.test-dist/src/CanvasService.js +249 -0
  2. package/.test-dist/src/ViewportSystem.js +75 -0
  3. package/.test-dist/src/background.js +203 -0
  4. package/.test-dist/src/bridgeSelection.js +20 -0
  5. package/.test-dist/src/constraints.js +237 -0
  6. package/.test-dist/src/coordinate.js +74 -0
  7. package/.test-dist/src/dieline.js +818 -0
  8. package/.test-dist/src/edgeScale.js +12 -0
  9. package/.test-dist/src/feature.js +754 -0
  10. package/.test-dist/src/featureComplete.js +32 -0
  11. package/.test-dist/src/film.js +167 -0
  12. package/.test-dist/src/geometry.js +506 -0
  13. package/.test-dist/src/image.js +1234 -0
  14. package/.test-dist/src/index.js +35 -0
  15. package/.test-dist/src/maskOps.js +270 -0
  16. package/.test-dist/src/mirror.js +104 -0
  17. package/.test-dist/src/renderSpec.js +2 -0
  18. package/.test-dist/src/ruler.js +343 -0
  19. package/.test-dist/src/sceneLayout.js +99 -0
  20. package/.test-dist/src/sceneLayoutModel.js +196 -0
  21. package/.test-dist/src/sceneView.js +40 -0
  22. package/.test-dist/src/sceneVisibility.js +42 -0
  23. package/.test-dist/src/size.js +332 -0
  24. package/.test-dist/src/tracer.js +544 -0
  25. package/.test-dist/src/units.js +30 -0
  26. package/.test-dist/src/white-ink.js +829 -0
  27. package/.test-dist/src/wrappedOffsets.js +33 -0
  28. package/.test-dist/tests/run.js +94 -0
  29. package/CHANGELOG.md +17 -0
  30. package/dist/index.d.mts +342 -37
  31. package/dist/index.d.ts +342 -37
  32. package/dist/index.js +3679 -865
  33. package/dist/index.mjs +3673 -868
  34. package/package.json +2 -2
  35. package/src/CanvasService.ts +300 -96
  36. package/src/ViewportSystem.ts +92 -92
  37. package/src/background.ts +230 -230
  38. package/src/bridgeSelection.ts +17 -0
  39. package/src/coordinate.ts +106 -106
  40. package/src/dieline.ts +1005 -973
  41. package/src/edgeScale.ts +19 -0
  42. package/src/feature.ts +83 -30
  43. package/src/film.ts +194 -194
  44. package/src/geometry.ts +242 -84
  45. package/src/image.ts +1582 -512
  46. package/src/index.ts +14 -10
  47. package/src/maskOps.ts +326 -0
  48. package/src/mirror.ts +128 -128
  49. package/src/renderSpec.ts +18 -0
  50. package/src/ruler.ts +449 -508
  51. package/src/sceneLayout.ts +121 -0
  52. package/src/sceneLayoutModel.ts +335 -0
  53. package/src/sceneVisibility.ts +49 -0
  54. package/src/size.ts +379 -0
  55. package/src/tracer.ts +719 -570
  56. package/src/units.ts +27 -27
  57. package/src/white-ink.ts +1018 -373
  58. package/src/wrappedOffsets.ts +33 -0
  59. package/tests/run.ts +118 -0
  60. package/tsconfig.test.json +15 -15
@@ -0,0 +1,33 @@
1
+ export function wrappedDistance(total: number, start: number, end: number): number {
2
+ if (!Number.isFinite(total) || total <= 0) return 0;
3
+ if (!Number.isFinite(start) || !Number.isFinite(end)) return 0;
4
+
5
+ const s = ((start % total) + total) % total;
6
+ const e = ((end % total) + total) % total;
7
+ return e >= s ? e - s : total - s + e;
8
+ }
9
+
10
+ export function sampleWrappedOffsets(
11
+ total: number,
12
+ start: number,
13
+ end: number,
14
+ count: number,
15
+ ): number[] {
16
+ if (!Number.isFinite(total) || total <= 0) return [];
17
+ if (!Number.isFinite(start) || !Number.isFinite(end)) return [];
18
+
19
+ const n = Math.max(0, Math.floor(count));
20
+ if (n <= 0) return [];
21
+
22
+ const dist = wrappedDistance(total, start, end);
23
+ if (n === 1) return [((start % total) + total) % total];
24
+
25
+ const step = dist / (n - 1);
26
+ const offsets: number[] = [];
27
+ for (let i = 0; i < n; i++) {
28
+ const raw = start + step * i;
29
+ const wrapped = ((raw % total) + total) % total;
30
+ offsets.push(wrapped);
31
+ }
32
+ return offsets;
33
+ }
package/tests/run.ts ADDED
@@ -0,0 +1,118 @@
1
+ import { pickExitIndex, scoreOutsideAbove } from "../src/bridgeSelection";
2
+ import { sampleWrappedOffsets, wrappedDistance } from "../src/wrappedOffsets";
3
+ import {
4
+ circularMorphology,
5
+ createMask,
6
+ fillHoles,
7
+ findMinimalConnectRadius,
8
+ isMaskConnected8,
9
+ } from "../src/maskOps";
10
+ import { computeDetectEdgeSize } from "../src/edgeScale";
11
+
12
+ function assert(condition: unknown, message: string) {
13
+ if (!condition) throw new Error(message);
14
+ }
15
+
16
+ function testWrappedOffsets() {
17
+ assert(wrappedDistance(100, 10, 30) === 20, "distance 10->30 should be 20");
18
+ assert(wrappedDistance(100, 90, 10) === 20, "distance 90->10 should wrap to 20");
19
+
20
+ const a = sampleWrappedOffsets(100, 10, 30, 5);
21
+ assert(
22
+ JSON.stringify(a) === JSON.stringify([10, 15, 20, 25, 30]),
23
+ `unexpected sample: ${JSON.stringify(a)}`,
24
+ );
25
+
26
+ const b = sampleWrappedOffsets(100, 90, 10, 3);
27
+ assert(
28
+ JSON.stringify(b) === JSON.stringify([90, 0, 10]),
29
+ `unexpected wrap sample: ${JSON.stringify(b)}`,
30
+ );
31
+ }
32
+
33
+ function testBridgeSelection() {
34
+ const idx = pickExitIndex([
35
+ { insideAbove: true, insideBelow: true },
36
+ { insideAbove: false, insideBelow: true },
37
+ { insideAbove: false, insideBelow: false },
38
+ ]);
39
+ assert(idx === 1, `expected exit index 1, got ${idx}`);
40
+
41
+ const none = pickExitIndex([{ insideAbove: true, insideBelow: true }]);
42
+ assert(none === -1, `expected -1, got ${none}`);
43
+
44
+ const score = scoreOutsideAbove([
45
+ { outsideAbove: true },
46
+ { outsideAbove: false },
47
+ { outsideAbove: true },
48
+ ]);
49
+ assert(score === 2, `expected score 2, got ${score}`);
50
+ }
51
+
52
+ function testMaskOps() {
53
+ const width = 50;
54
+ const height = 50;
55
+ const mask = new Uint8Array(width * height);
56
+ mask[10 * width + 10] = 1;
57
+ mask[10 * width + 20] = 1;
58
+
59
+ const r = findMinimalConnectRadius(mask, width, height, 20);
60
+ const closed = circularMorphology(mask, width, height, r, "closing");
61
+ assert(isMaskConnected8(closed, width, height), `closed mask should be connected (r=${r})`);
62
+ if (r > 0) {
63
+ const closedPrev = circularMorphology(mask, width, height, r - 1, "closing");
64
+ assert(
65
+ !isMaskConnected8(closedPrev, width, height),
66
+ `r should be minimal (r=${r})`,
67
+ );
68
+ }
69
+
70
+ const donut = new Uint8Array(9 * 9);
71
+ for (let y = 1; y <= 7; y++) {
72
+ for (let x = 1; x <= 7; x++) donut[y * 9 + x] = 1;
73
+ }
74
+ for (let y = 3; y <= 5; y++) {
75
+ for (let x = 3; x <= 5; x++) donut[y * 9 + x] = 0;
76
+ }
77
+ const filled = fillHoles(donut, 9, 9);
78
+ assert(filled[4 * 9 + 4] === 1, "hole should be filled");
79
+
80
+ const imgW = 2;
81
+ const imgH = 1;
82
+ const rgba = new Uint8ClampedArray([
83
+ 255, 255, 255, 255, 10, 10, 10, 254,
84
+ ]);
85
+ const imageData = { width: imgW, height: imgH, data: rgba } as unknown as ImageData;
86
+ const paddedWidth = imgW + 4;
87
+ const paddedHeight = imgH + 4;
88
+ const created = createMask(imageData, {
89
+ threshold: 10,
90
+ padding: 2,
91
+ paddedWidth,
92
+ paddedHeight,
93
+ maskMode: "auto",
94
+ alphaOpaqueCutoff: 250,
95
+ });
96
+ assert(created[2 * paddedWidth + 2] === 0, "white pixel should be background");
97
+ assert(created[2 * paddedWidth + 3] === 1, "non-white pixel should be foreground");
98
+ }
99
+
100
+ function testEdgeScale() {
101
+ const currentMax = 100;
102
+ const baseBounds = { width: 50, height: 20 };
103
+ const expandedBounds = { width: 70, height: 40 };
104
+ const { width, height, scale } = computeDetectEdgeSize(currentMax, baseBounds, expandedBounds);
105
+ assert(scale === 2, `expected scale 2, got ${scale}`);
106
+ assert(width === 140, `expected width 140, got ${width}`);
107
+ assert(height === 80, `expected height 80, got ${height}`);
108
+ }
109
+
110
+ function main() {
111
+ testWrappedOffsets();
112
+ testBridgeSelection();
113
+ testMaskOps();
114
+ testEdgeScale();
115
+ console.log("ok");
116
+ }
117
+
118
+ main();
@@ -1,15 +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
-
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
+