@pooder/kit 5.4.0 → 6.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 (69) hide show
  1. package/.test-dist/src/coordinate.js +74 -0
  2. package/.test-dist/src/extensions/background.js +547 -0
  3. package/.test-dist/src/extensions/bridgeSelection.js +20 -0
  4. package/.test-dist/src/extensions/constraints.js +237 -0
  5. package/.test-dist/src/extensions/dieline.js +935 -0
  6. package/.test-dist/src/extensions/dielineShape.js +66 -0
  7. package/.test-dist/src/extensions/edgeScale.js +12 -0
  8. package/.test-dist/src/extensions/feature.js +910 -0
  9. package/.test-dist/src/extensions/featureComplete.js +32 -0
  10. package/.test-dist/src/extensions/film.js +226 -0
  11. package/.test-dist/src/extensions/geometry.js +609 -0
  12. package/.test-dist/src/extensions/image.js +1788 -0
  13. package/.test-dist/src/extensions/index.js +28 -0
  14. package/.test-dist/src/extensions/maskOps.js +334 -0
  15. package/.test-dist/src/extensions/mirror.js +104 -0
  16. package/.test-dist/src/extensions/ruler.js +442 -0
  17. package/.test-dist/src/extensions/sceneLayout.js +96 -0
  18. package/.test-dist/src/extensions/sceneLayoutModel.js +202 -0
  19. package/.test-dist/src/extensions/sceneVisibility.js +55 -0
  20. package/.test-dist/src/extensions/size.js +331 -0
  21. package/.test-dist/src/extensions/tracer.js +709 -0
  22. package/.test-dist/src/extensions/white-ink.js +1200 -0
  23. package/.test-dist/src/extensions/wrappedOffsets.js +33 -0
  24. package/.test-dist/src/index.js +18 -0
  25. package/.test-dist/src/services/CanvasService.js +1032 -0
  26. package/.test-dist/src/services/ViewportSystem.js +76 -0
  27. package/.test-dist/src/services/index.js +25 -0
  28. package/.test-dist/src/services/renderSpec.js +2 -0
  29. package/.test-dist/src/services/visibility.js +57 -0
  30. package/.test-dist/src/units.js +30 -0
  31. package/.test-dist/tests/run.js +150 -0
  32. package/CHANGELOG.md +12 -0
  33. package/dist/index.d.mts +164 -62
  34. package/dist/index.d.ts +164 -62
  35. package/dist/index.js +2433 -1719
  36. package/dist/index.mjs +2442 -1723
  37. package/package.json +1 -1
  38. package/src/coordinate.ts +106 -106
  39. package/src/extensions/background.ts +716 -323
  40. package/src/extensions/bridgeSelection.ts +17 -17
  41. package/src/extensions/constraints.ts +322 -322
  42. package/src/extensions/dieline.ts +1173 -1149
  43. package/src/extensions/dielineShape.ts +109 -109
  44. package/src/extensions/edgeScale.ts +19 -19
  45. package/src/extensions/feature.ts +1140 -1137
  46. package/src/extensions/featureComplete.ts +46 -46
  47. package/src/extensions/film.ts +270 -266
  48. package/src/extensions/geometry.ts +851 -885
  49. package/src/extensions/image.ts +2240 -2054
  50. package/src/extensions/index.ts +10 -11
  51. package/src/extensions/maskOps.ts +283 -283
  52. package/src/extensions/mirror.ts +128 -128
  53. package/src/extensions/ruler.ts +664 -654
  54. package/src/extensions/sceneLayout.ts +140 -140
  55. package/src/extensions/sceneLayoutModel.ts +364 -364
  56. package/src/extensions/size.ts +389 -389
  57. package/src/extensions/tracer.ts +1019 -1019
  58. package/src/extensions/white-ink.ts +1508 -1575
  59. package/src/extensions/wrappedOffsets.ts +33 -33
  60. package/src/index.ts +2 -2
  61. package/src/services/CanvasService.ts +1317 -832
  62. package/src/services/ViewportSystem.ts +95 -95
  63. package/src/services/index.ts +4 -3
  64. package/src/services/renderSpec.ts +85 -53
  65. package/src/services/visibility.ts +83 -0
  66. package/src/units.ts +27 -27
  67. package/tests/run.ts +258 -118
  68. package/tsconfig.test.json +15 -15
  69. package/src/extensions/sceneVisibility.ts +0 -64
@@ -0,0 +1,237 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ConstraintRegistry = void 0;
4
+ const geometry_1 = require("./geometry");
5
+ class ConstraintRegistry {
6
+ static register(type, handler) {
7
+ this.handlers.set(type, handler);
8
+ }
9
+ static apply(x, y, feature, context, constraints // Optional override, defaults to feature.constraints
10
+ ) {
11
+ const list = constraints || feature.constraints;
12
+ if (!list || list.length === 0) {
13
+ return { x, y };
14
+ }
15
+ let currentX = x;
16
+ let currentY = y;
17
+ for (const constraint of list) {
18
+ const handler = this.handlers.get(constraint.type);
19
+ if (handler) {
20
+ const result = handler(currentX, currentY, feature, context, constraint.params || {});
21
+ currentX = result.x;
22
+ currentY = result.y;
23
+ }
24
+ }
25
+ return { x: currentX, y: currentY };
26
+ }
27
+ }
28
+ exports.ConstraintRegistry = ConstraintRegistry;
29
+ ConstraintRegistry.handlers = new Map();
30
+ // --- Built-in Strategies ---
31
+ /**
32
+ * Path Constraint Strategy (formerly placement='edge')
33
+ * Snaps the feature to the nearest point on the Dieline Path.
34
+ */
35
+ const pathConstraint = (x, y, feature, context, params) => {
36
+ // We need to denormalize, find nearest, then normalize back
37
+ // This is expensive but accurate.
38
+ const { dielineWidth, dielineHeight, geometry } = context;
39
+ if (!geometry)
40
+ return { x, y }; // Cannot snap without geometry
41
+ // Geometry is centered at (cx, cy)
42
+ // x, y are normalized (0-1) relative to bounding box
43
+ const minX = geometry.x - geometry.width / 2;
44
+ const minY = geometry.y - geometry.height / 2;
45
+ const absX = minX + x * geometry.width;
46
+ const absY = minY + y * geometry.height;
47
+ // Use geometry helper
48
+ // Note: getNearestPointOnDieline creates a fresh paper scope each time.
49
+ // Optimization: geometry object passed in context could be a reusable paper path?
50
+ // For now, keep it simple as per existing logic.
51
+ const nearest = (0, geometry_1.getNearestPointOnDieline)({ x: absX, y: absY }, geometry);
52
+ let finalX = nearest.x;
53
+ let finalY = nearest.y;
54
+ // Only allow vertical offset if explicit offset limits are provided
55
+ // Otherwise, we snap strictly to the path (offset = 0)
56
+ const hasOffsetParams = params.minOffset !== undefined || params.maxOffset !== undefined;
57
+ if (hasOffsetParams && nearest.normal) {
58
+ // Project the cursor vector onto the normal vector
59
+ // This ensures the feature stays on the "normal line" of the nearest path point
60
+ const dx = absX - nearest.x;
61
+ const dy = absY - nearest.y;
62
+ const nx = nearest.normal.x;
63
+ const ny = nearest.normal.y;
64
+ // Dot product to get scalar projection
65
+ const dist = dx * nx + dy * ny;
66
+ // Limit the offset
67
+ // geometry.width is in pixels, dielineWidth is in physical units (e.g. mm)
68
+ // We assume dielineWidth corresponds to geometry.width
69
+ const scale = dielineWidth > 0 ? geometry.width / dielineWidth : 1;
70
+ // If one is provided but the other is not, default the other to 0.
71
+ // If neither is provided (shouldn't happen due to hasOffsetParams check), default to 0.
72
+ const rawMin = params.minOffset !== undefined ? params.minOffset : 0;
73
+ const rawMax = params.maxOffset !== undefined ? params.maxOffset : 0;
74
+ // However, if we want to allow one-sided infinity, user must explicitly provide Infinity?
75
+ // Wait, user requirement: "If only one is passed, the other defaults to 0."
76
+ // This implies:
77
+ // { minOffset: -5 } -> maxOffset = 0 (range: -5 to 0)
78
+ // { maxOffset: 5 } -> minOffset = 0 (range: 0 to 5)
79
+ // { minOffset: -5, maxOffset: 5 } -> (range: -5 to 5)
80
+ const minOffset = rawMin * scale;
81
+ const maxOffset = rawMax * scale;
82
+ const clampedDist = Math.max(minOffset, Math.min(dist, maxOffset));
83
+ finalX = nearest.x + nx * clampedDist;
84
+ finalY = nearest.y + ny * clampedDist;
85
+ }
86
+ // Re-normalize
87
+ const nx = geometry.width > 0 ? (finalX - minX) / geometry.width : 0.5;
88
+ const ny = geometry.height > 0 ? (finalY - minY) / geometry.height : 0.5;
89
+ return { x: nx, y: ny };
90
+ };
91
+ /**
92
+ * Edge Constraint Strategy (Box Edge)
93
+ * Snaps the feature to the nearest allowed edge of the BOUNDING BOX.
94
+ */
95
+ const edgeConstraint = (x, y, feature, context, params) => {
96
+ const { dielineWidth, dielineHeight } = context;
97
+ const allowedEdges = params.allowedEdges || [
98
+ "top",
99
+ "bottom",
100
+ "left",
101
+ "right",
102
+ ];
103
+ const confine = params.confine || false;
104
+ const offset = params.offset || 0;
105
+ // Calculate physical distances to allowed edges
106
+ const distances = [];
107
+ if (allowedEdges.includes("top"))
108
+ distances.push({ edge: "top", dist: y * dielineHeight });
109
+ if (allowedEdges.includes("bottom"))
110
+ distances.push({ edge: "bottom", dist: (1 - y) * dielineHeight });
111
+ if (allowedEdges.includes("left"))
112
+ distances.push({ edge: "left", dist: x * dielineWidth });
113
+ if (allowedEdges.includes("right"))
114
+ distances.push({ edge: "right", dist: (1 - x) * dielineWidth });
115
+ if (distances.length === 0)
116
+ return { x, y };
117
+ // Find nearest
118
+ distances.sort((a, b) => a.dist - b.dist);
119
+ const nearest = distances[0].edge;
120
+ let newX = x;
121
+ let newY = y;
122
+ const fw = feature.width || 0;
123
+ const fh = feature.height || 0;
124
+ // Snap to edge
125
+ switch (nearest) {
126
+ case "top":
127
+ newY = 0 + offset / dielineHeight;
128
+ if (confine) {
129
+ const minX = (fw / 2) / dielineWidth;
130
+ const maxX = 1 - minX;
131
+ newX = Math.max(minX, Math.min(newX, maxX));
132
+ }
133
+ break;
134
+ case "bottom":
135
+ newY = 1 - offset / dielineHeight;
136
+ if (confine) {
137
+ const minX = (fw / 2) / dielineWidth;
138
+ const maxX = 1 - minX;
139
+ newX = Math.max(minX, Math.min(newX, maxX));
140
+ }
141
+ break;
142
+ case "left":
143
+ newX = 0 + offset / dielineWidth;
144
+ if (confine) {
145
+ const minY = (fh / 2) / dielineHeight;
146
+ const maxY = 1 - minY;
147
+ newY = Math.max(minY, Math.min(newY, maxY));
148
+ }
149
+ break;
150
+ case "right":
151
+ newX = 1 - offset / dielineWidth;
152
+ if (confine) {
153
+ const minY = (fh / 2) / dielineHeight;
154
+ const maxY = 1 - minY;
155
+ newY = Math.max(minY, Math.min(newY, maxY));
156
+ }
157
+ break;
158
+ }
159
+ return { x: newX, y: newY };
160
+ };
161
+ /**
162
+ * Internal Constraint Strategy
163
+ * Keeps the feature strictly inside the dieline bounds with optional margin.
164
+ */
165
+ const internalConstraint = (x, y, feature, context, params) => {
166
+ const { dielineWidth, dielineHeight } = context;
167
+ const margin = params.margin || 0;
168
+ const fw = feature.width || 0;
169
+ const fh = feature.height || 0;
170
+ const minX = (margin + fw / 2) / dielineWidth;
171
+ const maxX = 1 - (margin + fw / 2) / dielineWidth;
172
+ const minY = (margin + fh / 2) / dielineHeight;
173
+ const maxY = 1 - (margin + fh / 2) / dielineHeight;
174
+ // Handle case where feature is larger than container
175
+ const clampedX = minX > maxX ? 0.5 : Math.max(minX, Math.min(x, maxX));
176
+ const clampedY = minY > maxY ? 0.5 : Math.max(minY, Math.min(y, maxY));
177
+ return { x: clampedX, y: clampedY };
178
+ };
179
+ /**
180
+ * Bottom Tangent Strategy (stand protrusion)
181
+ * Forces a feature to be tangent to the dieline bottom edge from outside (below).
182
+ */
183
+ const tangentBottomConstraint = (x, y, feature, context, params) => {
184
+ const { dielineWidth, dielineHeight } = context;
185
+ const gap = params.gap || 0;
186
+ const confineX = params.confineX !== false;
187
+ const extentY = feature.shape === "circle"
188
+ ? feature.radius || 0
189
+ : (feature.height || 0) / 2;
190
+ const newY = 1 + (extentY + gap) / dielineHeight;
191
+ let newX = x;
192
+ if (confineX) {
193
+ const extentX = feature.shape === "circle"
194
+ ? feature.radius || 0
195
+ : (feature.width || 0) / 2;
196
+ const minX = extentX / dielineWidth;
197
+ const maxX = 1 - extentX / dielineWidth;
198
+ newX = minX > maxX ? 0.5 : Math.max(minX, Math.min(newX, maxX));
199
+ }
200
+ return { x: newX, y: newY };
201
+ };
202
+ /**
203
+ * Lowest Tangent Strategy (Lowest Point Lock)
204
+ * Finds the lowest point of the Dieline geometry and locks the feature's Y to that level.
205
+ * Allows horizontal movement (X).
206
+ */
207
+ const lowestTangentConstraint = (x, y, feature, context, params) => {
208
+ const { dielineWidth, dielineHeight, geometry } = context;
209
+ if (!geometry)
210
+ return { x, y };
211
+ const lowest = (0, geometry_1.getLowestPointOnDieline)(geometry);
212
+ // Calculate normalized Y of the lowest point
213
+ const minY = geometry.y - geometry.height / 2;
214
+ const normY = (lowest.y - minY) / geometry.height;
215
+ const gap = params.gap || 0;
216
+ const confineX = params.confineX !== false;
217
+ const extentY = feature.shape === "circle"
218
+ ? feature.radius || 0
219
+ : (feature.height || 0) / 2;
220
+ const newY = normY + (extentY + gap) / dielineHeight;
221
+ let newX = x;
222
+ if (confineX) {
223
+ const extentX = feature.shape === "circle"
224
+ ? feature.radius || 0
225
+ : (feature.width || 0) / 2;
226
+ const minX = extentX / dielineWidth;
227
+ const maxX = 1 - extentX / dielineWidth;
228
+ newX = minX > maxX ? 0.5 : Math.max(minX, Math.min(newX, maxX));
229
+ }
230
+ return { x: newX, y: newY };
231
+ };
232
+ // Register built-ins
233
+ ConstraintRegistry.register("path", pathConstraint);
234
+ ConstraintRegistry.register("edge", edgeConstraint);
235
+ ConstraintRegistry.register("internal", internalConstraint);
236
+ ConstraintRegistry.register("tangent-bottom", tangentBottomConstraint);
237
+ ConstraintRegistry.register("lowest-tangent", lowestTangentConstraint);