@pooder/kit 5.3.0 → 5.4.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 (73) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/index.d.mts +249 -36
  3. package/dist/index.d.ts +249 -36
  4. package/dist/index.js +2374 -1049
  5. package/dist/index.mjs +2375 -1050
  6. package/package.json +1 -1
  7. package/src/extensions/background.ts +178 -85
  8. package/src/extensions/dieline.ts +1149 -1030
  9. package/src/extensions/dielineShape.ts +109 -0
  10. package/src/extensions/feature.ts +482 -366
  11. package/src/extensions/film.ts +148 -76
  12. package/src/extensions/geometry.ts +210 -44
  13. package/src/extensions/image.ts +244 -114
  14. package/src/extensions/ruler.ts +471 -268
  15. package/src/extensions/sceneLayoutModel.ts +28 -6
  16. package/src/extensions/sceneVisibility.ts +3 -10
  17. package/src/extensions/tracer.ts +1019 -980
  18. package/src/extensions/white-ink.ts +284 -231
  19. package/src/services/CanvasService.ts +543 -11
  20. package/src/services/renderSpec.ts +37 -2
  21. package/.test-dist/src/CanvasService.js +0 -249
  22. package/.test-dist/src/ViewportSystem.js +0 -75
  23. package/.test-dist/src/background.js +0 -203
  24. package/.test-dist/src/bridgeSelection.js +0 -20
  25. package/.test-dist/src/constraints.js +0 -237
  26. package/.test-dist/src/coordinate.js +0 -74
  27. package/.test-dist/src/dieline.js +0 -818
  28. package/.test-dist/src/edgeScale.js +0 -12
  29. package/.test-dist/src/extensions/background.js +0 -203
  30. package/.test-dist/src/extensions/bridgeSelection.js +0 -20
  31. package/.test-dist/src/extensions/constraints.js +0 -237
  32. package/.test-dist/src/extensions/dieline.js +0 -828
  33. package/.test-dist/src/extensions/edgeScale.js +0 -12
  34. package/.test-dist/src/extensions/feature.js +0 -825
  35. package/.test-dist/src/extensions/featureComplete.js +0 -32
  36. package/.test-dist/src/extensions/film.js +0 -167
  37. package/.test-dist/src/extensions/geometry.js +0 -545
  38. package/.test-dist/src/extensions/image.js +0 -1529
  39. package/.test-dist/src/extensions/index.js +0 -30
  40. package/.test-dist/src/extensions/maskOps.js +0 -279
  41. package/.test-dist/src/extensions/mirror.js +0 -104
  42. package/.test-dist/src/extensions/ruler.js +0 -345
  43. package/.test-dist/src/extensions/sceneLayout.js +0 -96
  44. package/.test-dist/src/extensions/sceneLayoutModel.js +0 -196
  45. package/.test-dist/src/extensions/sceneVisibility.js +0 -62
  46. package/.test-dist/src/extensions/size.js +0 -331
  47. package/.test-dist/src/extensions/tracer.js +0 -538
  48. package/.test-dist/src/extensions/white-ink.js +0 -1190
  49. package/.test-dist/src/extensions/wrappedOffsets.js +0 -33
  50. package/.test-dist/src/feature.js +0 -826
  51. package/.test-dist/src/featureComplete.js +0 -32
  52. package/.test-dist/src/film.js +0 -167
  53. package/.test-dist/src/geometry.js +0 -506
  54. package/.test-dist/src/image.js +0 -1250
  55. package/.test-dist/src/index.js +0 -18
  56. package/.test-dist/src/maskOps.js +0 -270
  57. package/.test-dist/src/mirror.js +0 -104
  58. package/.test-dist/src/renderSpec.js +0 -2
  59. package/.test-dist/src/ruler.js +0 -343
  60. package/.test-dist/src/sceneLayout.js +0 -99
  61. package/.test-dist/src/sceneLayoutModel.js +0 -196
  62. package/.test-dist/src/sceneView.js +0 -40
  63. package/.test-dist/src/sceneVisibility.js +0 -42
  64. package/.test-dist/src/services/CanvasService.js +0 -249
  65. package/.test-dist/src/services/ViewportSystem.js +0 -76
  66. package/.test-dist/src/services/index.js +0 -24
  67. package/.test-dist/src/services/renderSpec.js +0 -2
  68. package/.test-dist/src/size.js +0 -332
  69. package/.test-dist/src/tracer.js +0 -544
  70. package/.test-dist/src/units.js +0 -30
  71. package/.test-dist/src/white-ink.js +0 -829
  72. package/.test-dist/src/wrappedOffsets.js +0 -33
  73. package/.test-dist/tests/run.js +0 -94
@@ -1,237 +0,0 @@
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);
@@ -1,74 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Coordinate = void 0;
4
- class Coordinate {
5
- /**
6
- * Calculate layout to fit content within container while preserving aspect ratio.
7
- */
8
- static calculateLayout(container, content, padding = 0) {
9
- const availableWidth = Math.max(0, container.width - padding * 2);
10
- const availableHeight = Math.max(0, container.height - padding * 2);
11
- if (content.width === 0 || content.height === 0) {
12
- return { scale: 1, offsetX: 0, offsetY: 0, width: 0, height: 0 };
13
- }
14
- const scaleX = availableWidth / content.width;
15
- const scaleY = availableHeight / content.height;
16
- const scale = Math.min(scaleX, scaleY);
17
- const width = content.width * scale;
18
- const height = content.height * scale;
19
- const offsetX = (container.width - width) / 2;
20
- const offsetY = (container.height - height) / 2;
21
- return { scale, offsetX, offsetY, width, height };
22
- }
23
- /**
24
- * Convert an absolute value to a normalized value (0-1).
25
- * @param value Absolute value (e.g., pixels)
26
- * @param total Total dimension size (e.g., canvas width)
27
- */
28
- static toNormalized(value, total) {
29
- return total === 0 ? 0 : value / total;
30
- }
31
- /**
32
- * Convert a normalized value (0-1) to an absolute value.
33
- * @param normalized Normalized value (0-1)
34
- * @param total Total dimension size (e.g., canvas width)
35
- */
36
- static toAbsolute(normalized, total) {
37
- return normalized * total;
38
- }
39
- /**
40
- * Normalize a point's coordinates.
41
- */
42
- static normalizePoint(point, size) {
43
- return {
44
- x: this.toNormalized(point.x, size.width),
45
- y: this.toNormalized(point.y, size.height),
46
- };
47
- }
48
- /**
49
- * Denormalize a point's coordinates to absolute pixels.
50
- */
51
- static denormalizePoint(point, size) {
52
- return {
53
- x: this.toAbsolute(point.x, size.width),
54
- y: this.toAbsolute(point.y, size.height),
55
- };
56
- }
57
- static convertUnit(value, from, to) {
58
- if (from === to)
59
- return value;
60
- // Base unit: mm
61
- const toMM = {
62
- px: 0.264583, // 1px = 0.264583mm (96 DPI)
63
- mm: 1,
64
- cm: 10,
65
- in: 25.4
66
- };
67
- const mmValue = value * (from === 'px' ? toMM.px : toMM[from] || 1);
68
- if (to === 'px') {
69
- return mmValue / toMM.px;
70
- }
71
- return mmValue / (toMM[to] || 1);
72
- }
73
- }
74
- exports.Coordinate = Coordinate;