@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
package/src/coordinate.ts CHANGED
@@ -1,106 +1,106 @@
1
- export interface Point {
2
- x: number;
3
- y: number;
4
- }
5
-
6
- export interface Size {
7
- width: number;
8
- height: number;
9
- }
10
-
11
- export type Unit = "px" | "mm" | "cm" | "in";
12
-
13
- export interface Layout {
14
- scale: number;
15
- offsetX: number;
16
- offsetY: number;
17
- width: number;
18
- height: number;
19
- }
20
-
21
- export class Coordinate {
22
- /**
23
- * Calculate layout to fit content within container while preserving aspect ratio.
24
- */
25
- static calculateLayout(
26
- container: Size,
27
- content: Size,
28
- padding: number = 0,
29
- ): Layout {
30
- const availableWidth = Math.max(0, container.width - padding * 2);
31
- const availableHeight = Math.max(0, container.height - padding * 2);
32
-
33
- if (content.width === 0 || content.height === 0) {
34
- return { scale: 1, offsetX: 0, offsetY: 0, width: 0, height: 0 };
35
- }
36
-
37
- const scaleX = availableWidth / content.width;
38
- const scaleY = availableHeight / content.height;
39
- const scale = Math.min(scaleX, scaleY);
40
-
41
- const width = content.width * scale;
42
- const height = content.height * scale;
43
-
44
- const offsetX = (container.width - width) / 2;
45
- const offsetY = (container.height - height) / 2;
46
-
47
- return { scale, offsetX, offsetY, width, height };
48
- }
49
-
50
- /**
51
- * Convert an absolute value to a normalized value (0-1).
52
- * @param value Absolute value (e.g., pixels)
53
- * @param total Total dimension size (e.g., canvas width)
54
- */
55
- static toNormalized(value: number, total: number): number {
56
- return total === 0 ? 0 : value / total;
57
- }
58
-
59
- /**
60
- * Convert a normalized value (0-1) to an absolute value.
61
- * @param normalized Normalized value (0-1)
62
- * @param total Total dimension size (e.g., canvas width)
63
- */
64
- static toAbsolute(normalized: number, total: number): number {
65
- return normalized * total;
66
- }
67
-
68
- /**
69
- * Normalize a point's coordinates.
70
- */
71
- static normalizePoint(point: Point, size: Size): Point {
72
- return {
73
- x: this.toNormalized(point.x, size.width),
74
- y: this.toNormalized(point.y, size.height),
75
- };
76
- }
77
-
78
- /**
79
- * Denormalize a point's coordinates to absolute pixels.
80
- */
81
- static denormalizePoint(point: Point, size: Size): Point {
82
- return {
83
- x: this.toAbsolute(point.x, size.width),
84
- y: this.toAbsolute(point.y, size.height),
85
- };
86
- }
87
-
88
- static convertUnit(value: number, from: Unit, to: Unit): number {
89
- if (from === to) return value;
90
-
91
- // Base unit: mm
92
- const toMM: Record<Unit, number> = {
93
- px: 0.264583, // 1px = 0.264583mm (96 DPI)
94
- mm: 1,
95
- cm: 10,
96
- in: 25.4
97
- };
98
-
99
- const mmValue = value * (from === 'px' ? toMM.px : toMM[from] || 1);
100
-
101
- if (to === 'px') {
102
- return mmValue / toMM.px;
103
- }
104
- return mmValue / (toMM[to] || 1);
105
- }
106
- }
1
+ export interface Point {
2
+ x: number;
3
+ y: number;
4
+ }
5
+
6
+ export interface Size {
7
+ width: number;
8
+ height: number;
9
+ }
10
+
11
+ export type Unit = "px" | "mm" | "cm" | "in";
12
+
13
+ export interface Layout {
14
+ scale: number;
15
+ offsetX: number;
16
+ offsetY: number;
17
+ width: number;
18
+ height: number;
19
+ }
20
+
21
+ export class Coordinate {
22
+ /**
23
+ * Calculate layout to fit content within container while preserving aspect ratio.
24
+ */
25
+ static calculateLayout(
26
+ container: Size,
27
+ content: Size,
28
+ padding: number = 0,
29
+ ): Layout {
30
+ const availableWidth = Math.max(0, container.width - padding * 2);
31
+ const availableHeight = Math.max(0, container.height - padding * 2);
32
+
33
+ if (content.width === 0 || content.height === 0) {
34
+ return { scale: 1, offsetX: 0, offsetY: 0, width: 0, height: 0 };
35
+ }
36
+
37
+ const scaleX = availableWidth / content.width;
38
+ const scaleY = availableHeight / content.height;
39
+ const scale = Math.min(scaleX, scaleY);
40
+
41
+ const width = content.width * scale;
42
+ const height = content.height * scale;
43
+
44
+ const offsetX = (container.width - width) / 2;
45
+ const offsetY = (container.height - height) / 2;
46
+
47
+ return { scale, offsetX, offsetY, width, height };
48
+ }
49
+
50
+ /**
51
+ * Convert an absolute value to a normalized value (0-1).
52
+ * @param value Absolute value (e.g., pixels)
53
+ * @param total Total dimension size (e.g., canvas width)
54
+ */
55
+ static toNormalized(value: number, total: number): number {
56
+ return total === 0 ? 0 : value / total;
57
+ }
58
+
59
+ /**
60
+ * Convert a normalized value (0-1) to an absolute value.
61
+ * @param normalized Normalized value (0-1)
62
+ * @param total Total dimension size (e.g., canvas width)
63
+ */
64
+ static toAbsolute(normalized: number, total: number): number {
65
+ return normalized * total;
66
+ }
67
+
68
+ /**
69
+ * Normalize a point's coordinates.
70
+ */
71
+ static normalizePoint(point: Point, size: Size): Point {
72
+ return {
73
+ x: this.toNormalized(point.x, size.width),
74
+ y: this.toNormalized(point.y, size.height),
75
+ };
76
+ }
77
+
78
+ /**
79
+ * Denormalize a point's coordinates to absolute pixels.
80
+ */
81
+ static denormalizePoint(point: Point, size: Size): Point {
82
+ return {
83
+ x: this.toAbsolute(point.x, size.width),
84
+ y: this.toAbsolute(point.y, size.height),
85
+ };
86
+ }
87
+
88
+ static convertUnit(value: number, from: Unit, to: Unit): number {
89
+ if (from === to) return value;
90
+
91
+ // Base unit: mm
92
+ const toMM: Record<Unit, number> = {
93
+ px: 0.264583, // 1px = 0.264583mm (96 DPI)
94
+ mm: 1,
95
+ cm: 10,
96
+ in: 25.4
97
+ };
98
+
99
+ const mmValue = value * (from === 'px' ? toMM.px : toMM[from] || 1);
100
+
101
+ if (to === 'px') {
102
+ return mmValue / toMM.px;
103
+ }
104
+ return mmValue / (toMM[to] || 1);
105
+ }
106
+ }