@pooder/kit 4.0.0 → 4.1.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.
- package/CHANGELOG.md +6 -0
- package/dist/index.d.mts +4 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +147 -0
- package/dist/index.mjs +147 -0
- package/package.json +1 -1
- package/src/background.ts +230 -230
- package/src/constraints.ts +158 -0
- package/src/coordinate.ts +106 -106
- package/src/dieline.ts +35 -0
- package/src/feature.ts +25 -0
- package/src/film.ts +194 -194
- package/src/geometry.ts +4 -0
- package/src/image.ts +512 -512
- package/src/mirror.ts +128 -128
- package/src/ruler.ts +500 -500
- package/src/tracer.ts +570 -570
- package/src/white-ink.ts +373 -373
package/CHANGELOG.md
CHANGED
package/dist/index.d.mts
CHANGED
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -940,6 +940,105 @@ function getPathBounds(pathData) {
|
|
|
940
940
|
};
|
|
941
941
|
}
|
|
942
942
|
|
|
943
|
+
// src/constraints.ts
|
|
944
|
+
var ConstraintRegistry = class {
|
|
945
|
+
static register(type, handler) {
|
|
946
|
+
this.handlers.set(type, handler);
|
|
947
|
+
}
|
|
948
|
+
static apply(x, y, feature, context) {
|
|
949
|
+
if (!feature.constraints || !feature.constraints.type) {
|
|
950
|
+
return { x, y };
|
|
951
|
+
}
|
|
952
|
+
const handler = this.handlers.get(feature.constraints.type);
|
|
953
|
+
if (handler) {
|
|
954
|
+
return handler(x, y, feature, context);
|
|
955
|
+
}
|
|
956
|
+
return { x, y };
|
|
957
|
+
}
|
|
958
|
+
};
|
|
959
|
+
ConstraintRegistry.handlers = /* @__PURE__ */ new Map();
|
|
960
|
+
var edgeConstraint = (x, y, feature, context) => {
|
|
961
|
+
var _a;
|
|
962
|
+
const { dielineWidth, dielineHeight } = context;
|
|
963
|
+
const params = ((_a = feature.constraints) == null ? void 0 : _a.params) || {};
|
|
964
|
+
const allowedEdges = params.allowedEdges || [
|
|
965
|
+
"top",
|
|
966
|
+
"bottom",
|
|
967
|
+
"left",
|
|
968
|
+
"right"
|
|
969
|
+
];
|
|
970
|
+
const confine = params.confine || false;
|
|
971
|
+
const offset = params.offset || 0;
|
|
972
|
+
const distances = [];
|
|
973
|
+
if (allowedEdges.includes("top"))
|
|
974
|
+
distances.push({ edge: "top", dist: y * dielineHeight });
|
|
975
|
+
if (allowedEdges.includes("bottom"))
|
|
976
|
+
distances.push({ edge: "bottom", dist: (1 - y) * dielineHeight });
|
|
977
|
+
if (allowedEdges.includes("left"))
|
|
978
|
+
distances.push({ edge: "left", dist: x * dielineWidth });
|
|
979
|
+
if (allowedEdges.includes("right"))
|
|
980
|
+
distances.push({ edge: "right", dist: (1 - x) * dielineWidth });
|
|
981
|
+
if (distances.length === 0) return { x, y };
|
|
982
|
+
distances.sort((a, b) => a.dist - b.dist);
|
|
983
|
+
const nearest = distances[0].edge;
|
|
984
|
+
let newX = x;
|
|
985
|
+
let newY = y;
|
|
986
|
+
const fw = feature.width || 0;
|
|
987
|
+
const fh = feature.height || 0;
|
|
988
|
+
switch (nearest) {
|
|
989
|
+
case "top":
|
|
990
|
+
newY = 0 + offset / dielineHeight;
|
|
991
|
+
if (confine) {
|
|
992
|
+
const minX = fw / 2 / dielineWidth;
|
|
993
|
+
const maxX = 1 - minX;
|
|
994
|
+
newX = Math.max(minX, Math.min(newX, maxX));
|
|
995
|
+
}
|
|
996
|
+
break;
|
|
997
|
+
case "bottom":
|
|
998
|
+
newY = 1 - offset / dielineHeight;
|
|
999
|
+
if (confine) {
|
|
1000
|
+
const minX = fw / 2 / dielineWidth;
|
|
1001
|
+
const maxX = 1 - minX;
|
|
1002
|
+
newX = Math.max(minX, Math.min(newX, maxX));
|
|
1003
|
+
}
|
|
1004
|
+
break;
|
|
1005
|
+
case "left":
|
|
1006
|
+
newX = 0 + offset / dielineWidth;
|
|
1007
|
+
if (confine) {
|
|
1008
|
+
const minY = fh / 2 / dielineHeight;
|
|
1009
|
+
const maxY = 1 - minY;
|
|
1010
|
+
newY = Math.max(minY, Math.min(newY, maxY));
|
|
1011
|
+
}
|
|
1012
|
+
break;
|
|
1013
|
+
case "right":
|
|
1014
|
+
newX = 1 - offset / dielineWidth;
|
|
1015
|
+
if (confine) {
|
|
1016
|
+
const minY = fh / 2 / dielineHeight;
|
|
1017
|
+
const maxY = 1 - minY;
|
|
1018
|
+
newY = Math.max(minY, Math.min(newY, maxY));
|
|
1019
|
+
}
|
|
1020
|
+
break;
|
|
1021
|
+
}
|
|
1022
|
+
return { x: newX, y: newY };
|
|
1023
|
+
};
|
|
1024
|
+
var internalConstraint = (x, y, feature, context) => {
|
|
1025
|
+
var _a;
|
|
1026
|
+
const { dielineWidth, dielineHeight } = context;
|
|
1027
|
+
const params = ((_a = feature.constraints) == null ? void 0 : _a.params) || {};
|
|
1028
|
+
const margin = params.margin || 0;
|
|
1029
|
+
const fw = feature.width || 0;
|
|
1030
|
+
const fh = feature.height || 0;
|
|
1031
|
+
const minX = (margin + fw / 2) / dielineWidth;
|
|
1032
|
+
const maxX = 1 - (margin + fw / 2) / dielineWidth;
|
|
1033
|
+
const minY = (margin + fh / 2) / dielineHeight;
|
|
1034
|
+
const maxY = 1 - (margin + fh / 2) / dielineHeight;
|
|
1035
|
+
const clampedX = minX > maxX ? 0.5 : Math.max(minX, Math.min(x, maxX));
|
|
1036
|
+
const clampedY = minY > maxY ? 0.5 : Math.max(minY, Math.min(y, maxY));
|
|
1037
|
+
return { x: clampedX, y: clampedY };
|
|
1038
|
+
};
|
|
1039
|
+
ConstraintRegistry.register("edge", edgeConstraint);
|
|
1040
|
+
ConstraintRegistry.register("internal", internalConstraint);
|
|
1041
|
+
|
|
943
1042
|
// src/dieline.ts
|
|
944
1043
|
var DielineTool = class {
|
|
945
1044
|
constructor(options) {
|
|
@@ -1234,6 +1333,37 @@ var DielineTool = class {
|
|
|
1234
1333
|
}
|
|
1235
1334
|
],
|
|
1236
1335
|
[import_core2.ContributionPointIds.COMMANDS]: [
|
|
1336
|
+
{
|
|
1337
|
+
command: "updateFeaturePosition",
|
|
1338
|
+
title: "Update Feature Position",
|
|
1339
|
+
handler: (groupId, x, y) => {
|
|
1340
|
+
var _a;
|
|
1341
|
+
const configService = (_a = this.context) == null ? void 0 : _a.services.get(
|
|
1342
|
+
"ConfigurationService"
|
|
1343
|
+
);
|
|
1344
|
+
if (!configService) return;
|
|
1345
|
+
const features = configService.get("dieline.features") || [];
|
|
1346
|
+
const dielineWidth = configService.get("dieline.width") || 500;
|
|
1347
|
+
const dielineHeight = configService.get("dieline.height") || 500;
|
|
1348
|
+
let changed = false;
|
|
1349
|
+
const newFeatures = features.map((f) => {
|
|
1350
|
+
if (f.groupId === groupId) {
|
|
1351
|
+
const constrained = ConstraintRegistry.apply(x, y, f, {
|
|
1352
|
+
dielineWidth,
|
|
1353
|
+
dielineHeight
|
|
1354
|
+
});
|
|
1355
|
+
if (f.x !== constrained.x || f.y !== constrained.y) {
|
|
1356
|
+
changed = true;
|
|
1357
|
+
return { ...f, x: constrained.x, y: constrained.y };
|
|
1358
|
+
}
|
|
1359
|
+
}
|
|
1360
|
+
return f;
|
|
1361
|
+
});
|
|
1362
|
+
if (changed) {
|
|
1363
|
+
configService.update("dieline.features", newFeatures);
|
|
1364
|
+
}
|
|
1365
|
+
}
|
|
1366
|
+
},
|
|
1237
1367
|
{
|
|
1238
1368
|
command: "getGeometry",
|
|
1239
1369
|
title: "Get Geometry",
|
|
@@ -2124,6 +2254,23 @@ var FeatureTool = class {
|
|
|
2124
2254
|
this.canvasService.requestRenderAll();
|
|
2125
2255
|
}
|
|
2126
2256
|
constrainPosition(p, geometry, limit, feature) {
|
|
2257
|
+
if (feature && feature.constraints) {
|
|
2258
|
+
const minX = geometry.x - geometry.width / 2;
|
|
2259
|
+
const minY = geometry.y - geometry.height / 2;
|
|
2260
|
+
const nx = geometry.width > 0 ? (p.x - minX) / geometry.width : 0.5;
|
|
2261
|
+
const ny = geometry.height > 0 ? (p.y - minY) / geometry.height : 0.5;
|
|
2262
|
+
const scale2 = geometry.scale || 1;
|
|
2263
|
+
const dielineWidth = geometry.width / scale2;
|
|
2264
|
+
const dielineHeight = geometry.height / scale2;
|
|
2265
|
+
const constrained = ConstraintRegistry.apply(nx, ny, feature, {
|
|
2266
|
+
dielineWidth,
|
|
2267
|
+
dielineHeight
|
|
2268
|
+
});
|
|
2269
|
+
return {
|
|
2270
|
+
x: minX + constrained.x * geometry.width,
|
|
2271
|
+
y: minY + constrained.y * geometry.height
|
|
2272
|
+
};
|
|
2273
|
+
}
|
|
2127
2274
|
if (feature && feature.placement === "internal") {
|
|
2128
2275
|
const minX = geometry.x - geometry.width / 2;
|
|
2129
2276
|
const maxX = geometry.x + geometry.width / 2;
|
package/dist/index.mjs
CHANGED
|
@@ -900,6 +900,105 @@ function getPathBounds(pathData) {
|
|
|
900
900
|
};
|
|
901
901
|
}
|
|
902
902
|
|
|
903
|
+
// src/constraints.ts
|
|
904
|
+
var ConstraintRegistry = class {
|
|
905
|
+
static register(type, handler) {
|
|
906
|
+
this.handlers.set(type, handler);
|
|
907
|
+
}
|
|
908
|
+
static apply(x, y, feature, context) {
|
|
909
|
+
if (!feature.constraints || !feature.constraints.type) {
|
|
910
|
+
return { x, y };
|
|
911
|
+
}
|
|
912
|
+
const handler = this.handlers.get(feature.constraints.type);
|
|
913
|
+
if (handler) {
|
|
914
|
+
return handler(x, y, feature, context);
|
|
915
|
+
}
|
|
916
|
+
return { x, y };
|
|
917
|
+
}
|
|
918
|
+
};
|
|
919
|
+
ConstraintRegistry.handlers = /* @__PURE__ */ new Map();
|
|
920
|
+
var edgeConstraint = (x, y, feature, context) => {
|
|
921
|
+
var _a;
|
|
922
|
+
const { dielineWidth, dielineHeight } = context;
|
|
923
|
+
const params = ((_a = feature.constraints) == null ? void 0 : _a.params) || {};
|
|
924
|
+
const allowedEdges = params.allowedEdges || [
|
|
925
|
+
"top",
|
|
926
|
+
"bottom",
|
|
927
|
+
"left",
|
|
928
|
+
"right"
|
|
929
|
+
];
|
|
930
|
+
const confine = params.confine || false;
|
|
931
|
+
const offset = params.offset || 0;
|
|
932
|
+
const distances = [];
|
|
933
|
+
if (allowedEdges.includes("top"))
|
|
934
|
+
distances.push({ edge: "top", dist: y * dielineHeight });
|
|
935
|
+
if (allowedEdges.includes("bottom"))
|
|
936
|
+
distances.push({ edge: "bottom", dist: (1 - y) * dielineHeight });
|
|
937
|
+
if (allowedEdges.includes("left"))
|
|
938
|
+
distances.push({ edge: "left", dist: x * dielineWidth });
|
|
939
|
+
if (allowedEdges.includes("right"))
|
|
940
|
+
distances.push({ edge: "right", dist: (1 - x) * dielineWidth });
|
|
941
|
+
if (distances.length === 0) return { x, y };
|
|
942
|
+
distances.sort((a, b) => a.dist - b.dist);
|
|
943
|
+
const nearest = distances[0].edge;
|
|
944
|
+
let newX = x;
|
|
945
|
+
let newY = y;
|
|
946
|
+
const fw = feature.width || 0;
|
|
947
|
+
const fh = feature.height || 0;
|
|
948
|
+
switch (nearest) {
|
|
949
|
+
case "top":
|
|
950
|
+
newY = 0 + offset / dielineHeight;
|
|
951
|
+
if (confine) {
|
|
952
|
+
const minX = fw / 2 / dielineWidth;
|
|
953
|
+
const maxX = 1 - minX;
|
|
954
|
+
newX = Math.max(minX, Math.min(newX, maxX));
|
|
955
|
+
}
|
|
956
|
+
break;
|
|
957
|
+
case "bottom":
|
|
958
|
+
newY = 1 - offset / dielineHeight;
|
|
959
|
+
if (confine) {
|
|
960
|
+
const minX = fw / 2 / dielineWidth;
|
|
961
|
+
const maxX = 1 - minX;
|
|
962
|
+
newX = Math.max(minX, Math.min(newX, maxX));
|
|
963
|
+
}
|
|
964
|
+
break;
|
|
965
|
+
case "left":
|
|
966
|
+
newX = 0 + offset / dielineWidth;
|
|
967
|
+
if (confine) {
|
|
968
|
+
const minY = fh / 2 / dielineHeight;
|
|
969
|
+
const maxY = 1 - minY;
|
|
970
|
+
newY = Math.max(minY, Math.min(newY, maxY));
|
|
971
|
+
}
|
|
972
|
+
break;
|
|
973
|
+
case "right":
|
|
974
|
+
newX = 1 - offset / dielineWidth;
|
|
975
|
+
if (confine) {
|
|
976
|
+
const minY = fh / 2 / dielineHeight;
|
|
977
|
+
const maxY = 1 - minY;
|
|
978
|
+
newY = Math.max(minY, Math.min(newY, maxY));
|
|
979
|
+
}
|
|
980
|
+
break;
|
|
981
|
+
}
|
|
982
|
+
return { x: newX, y: newY };
|
|
983
|
+
};
|
|
984
|
+
var internalConstraint = (x, y, feature, context) => {
|
|
985
|
+
var _a;
|
|
986
|
+
const { dielineWidth, dielineHeight } = context;
|
|
987
|
+
const params = ((_a = feature.constraints) == null ? void 0 : _a.params) || {};
|
|
988
|
+
const margin = params.margin || 0;
|
|
989
|
+
const fw = feature.width || 0;
|
|
990
|
+
const fh = feature.height || 0;
|
|
991
|
+
const minX = (margin + fw / 2) / dielineWidth;
|
|
992
|
+
const maxX = 1 - (margin + fw / 2) / dielineWidth;
|
|
993
|
+
const minY = (margin + fh / 2) / dielineHeight;
|
|
994
|
+
const maxY = 1 - (margin + fh / 2) / dielineHeight;
|
|
995
|
+
const clampedX = minX > maxX ? 0.5 : Math.max(minX, Math.min(x, maxX));
|
|
996
|
+
const clampedY = minY > maxY ? 0.5 : Math.max(minY, Math.min(y, maxY));
|
|
997
|
+
return { x: clampedX, y: clampedY };
|
|
998
|
+
};
|
|
999
|
+
ConstraintRegistry.register("edge", edgeConstraint);
|
|
1000
|
+
ConstraintRegistry.register("internal", internalConstraint);
|
|
1001
|
+
|
|
903
1002
|
// src/dieline.ts
|
|
904
1003
|
var DielineTool = class {
|
|
905
1004
|
constructor(options) {
|
|
@@ -1194,6 +1293,37 @@ var DielineTool = class {
|
|
|
1194
1293
|
}
|
|
1195
1294
|
],
|
|
1196
1295
|
[ContributionPointIds2.COMMANDS]: [
|
|
1296
|
+
{
|
|
1297
|
+
command: "updateFeaturePosition",
|
|
1298
|
+
title: "Update Feature Position",
|
|
1299
|
+
handler: (groupId, x, y) => {
|
|
1300
|
+
var _a;
|
|
1301
|
+
const configService = (_a = this.context) == null ? void 0 : _a.services.get(
|
|
1302
|
+
"ConfigurationService"
|
|
1303
|
+
);
|
|
1304
|
+
if (!configService) return;
|
|
1305
|
+
const features = configService.get("dieline.features") || [];
|
|
1306
|
+
const dielineWidth = configService.get("dieline.width") || 500;
|
|
1307
|
+
const dielineHeight = configService.get("dieline.height") || 500;
|
|
1308
|
+
let changed = false;
|
|
1309
|
+
const newFeatures = features.map((f) => {
|
|
1310
|
+
if (f.groupId === groupId) {
|
|
1311
|
+
const constrained = ConstraintRegistry.apply(x, y, f, {
|
|
1312
|
+
dielineWidth,
|
|
1313
|
+
dielineHeight
|
|
1314
|
+
});
|
|
1315
|
+
if (f.x !== constrained.x || f.y !== constrained.y) {
|
|
1316
|
+
changed = true;
|
|
1317
|
+
return { ...f, x: constrained.x, y: constrained.y };
|
|
1318
|
+
}
|
|
1319
|
+
}
|
|
1320
|
+
return f;
|
|
1321
|
+
});
|
|
1322
|
+
if (changed) {
|
|
1323
|
+
configService.update("dieline.features", newFeatures);
|
|
1324
|
+
}
|
|
1325
|
+
}
|
|
1326
|
+
},
|
|
1197
1327
|
{
|
|
1198
1328
|
command: "getGeometry",
|
|
1199
1329
|
title: "Get Geometry",
|
|
@@ -2088,6 +2218,23 @@ var FeatureTool = class {
|
|
|
2088
2218
|
this.canvasService.requestRenderAll();
|
|
2089
2219
|
}
|
|
2090
2220
|
constrainPosition(p, geometry, limit, feature) {
|
|
2221
|
+
if (feature && feature.constraints) {
|
|
2222
|
+
const minX = geometry.x - geometry.width / 2;
|
|
2223
|
+
const minY = geometry.y - geometry.height / 2;
|
|
2224
|
+
const nx = geometry.width > 0 ? (p.x - minX) / geometry.width : 0.5;
|
|
2225
|
+
const ny = geometry.height > 0 ? (p.y - minY) / geometry.height : 0.5;
|
|
2226
|
+
const scale2 = geometry.scale || 1;
|
|
2227
|
+
const dielineWidth = geometry.width / scale2;
|
|
2228
|
+
const dielineHeight = geometry.height / scale2;
|
|
2229
|
+
const constrained = ConstraintRegistry.apply(nx, ny, feature, {
|
|
2230
|
+
dielineWidth,
|
|
2231
|
+
dielineHeight
|
|
2232
|
+
});
|
|
2233
|
+
return {
|
|
2234
|
+
x: minX + constrained.x * geometry.width,
|
|
2235
|
+
y: minY + constrained.y * geometry.height
|
|
2236
|
+
};
|
|
2237
|
+
}
|
|
2091
2238
|
if (feature && feature.placement === "internal") {
|
|
2092
2239
|
const minX = geometry.x - geometry.width / 2;
|
|
2093
2240
|
const maxX = geometry.x + geometry.width / 2;
|