@lucablockltd/ultimate-packaging 1.2.0 → 1.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.
package/dist/index.js CHANGED
@@ -446,12 +446,14 @@ var BaseCanvas = react.forwardRef(
446
446
  const svgRef = react.useRef(null);
447
447
  const dragRef = react.useRef(null);
448
448
  const hasInitialFit = react.useRef(false);
449
+ const frozenViewBox = react.useRef(null);
449
450
  const [zoom, setZoom] = react.useState(1);
450
451
  const [panX, setPanX] = react.useState(0);
451
452
  const [panY, setPanY] = react.useState(0);
452
453
  const [dragging, setDragging] = react.useState(false);
453
- const vbWidth = initialViewBox.width / zoom;
454
- const vbHeight = initialViewBox.height / zoom;
454
+ const refVB = frozenViewBox.current ?? initialViewBox;
455
+ const vbWidth = refVB.width / zoom;
456
+ const vbHeight = refVB.height / zoom;
455
457
  const centerX = initialViewBox.x + initialViewBox.width / 2;
456
458
  const centerY = initialViewBox.y + initialViewBox.height / 2;
457
459
  const vbX = centerX - vbWidth / 2 - panX;
@@ -459,10 +461,11 @@ var BaseCanvas = react.forwardRef(
459
461
  const fitView = react.useCallback(() => {
460
462
  const container = containerRef.current;
461
463
  if (!container) return;
464
+ frozenViewBox.current = { ...initialViewBox };
462
465
  setZoom(clamp(fitPadding, minZoom, maxZoom));
463
466
  setPanX(0);
464
467
  setPanY(0);
465
- }, [initialViewBox.width, initialViewBox.height, fitPadding, minZoom, maxZoom]);
468
+ }, [initialViewBox.x, initialViewBox.y, initialViewBox.width, initialViewBox.height, fitPadding, minZoom, maxZoom]);
466
469
  const resetView = react.useCallback(() => {
467
470
  fitView();
468
471
  }, [fitView]);
@@ -476,10 +479,6 @@ var BaseCanvas = react.forwardRef(
476
479
  hasInitialFit.current = true;
477
480
  fitView();
478
481
  }, [fitView]);
479
- react.useEffect(() => {
480
- if (!hasInitialFit.current) return;
481
- fitView();
482
- }, [initialViewBox.width, initialViewBox.height, fitView]);
483
482
  react.useEffect(() => {
484
483
  const container = containerRef.current;
485
484
  if (!container) return;
@@ -491,12 +490,13 @@ var BaseCanvas = react.forwardRef(
491
490
  const cursorXRatio = (e.clientX - rect.left) / rect.width;
492
491
  const cursorYRatio = (e.clientY - rect.top) / rect.height;
493
492
  const zoomFactor = Math.exp(-e.deltaY * 2e-3);
493
+ const currentRefVB = frozenViewBox.current ?? initialViewBox;
494
494
  setZoom((prevZoom) => {
495
495
  const nextZoom = clamp(prevZoom * zoomFactor, minZoom, maxZoom);
496
- const prevW = initialViewBox.width / prevZoom;
497
- const prevH = initialViewBox.height / prevZoom;
498
- const nextW = initialViewBox.width / nextZoom;
499
- const nextH = initialViewBox.height / nextZoom;
496
+ const prevW = currentRefVB.width / prevZoom;
497
+ const prevH = currentRefVB.height / prevZoom;
498
+ const nextW = currentRefVB.width / nextZoom;
499
+ const nextH = currentRefVB.height / nextZoom;
500
500
  const dx = (prevW - nextW) * (cursorXRatio - 0.5);
501
501
  const dy = (prevH - nextH) * (cursorYRatio - 0.5);
502
502
  setPanX((prev) => prev + dx);
@@ -506,7 +506,7 @@ var BaseCanvas = react.forwardRef(
506
506
  };
507
507
  container.addEventListener("wheel", handleWheel, { passive: false });
508
508
  return () => container.removeEventListener("wheel", handleWheel);
509
- }, [initialViewBox.width, initialViewBox.height, minZoom, maxZoom]);
509
+ }, [initialViewBox, minZoom, maxZoom]);
510
510
  const onPointerDown = (e) => {
511
511
  dragRef.current = { pointerId: e.pointerId, x: e.clientX, y: e.clientY };
512
512
  setDragging(true);
@@ -3761,13 +3761,48 @@ function generateOuterContour6(attr) {
3761
3761
  const { length: A, width: B, height: C, glueArea } = attr;
3762
3762
  const D = calcD2(C, B);
3763
3763
  const kulak = glueArea ?? calcKulak2(B);
3764
- const totalWidth = kulak + 2 * A + 2 * B - 2;
3765
- const totalHeight = D + C + B / 2 + DIP2;
3764
+ const xFront = kulak;
3765
+ const xSide1 = kulak + A;
3766
+ const xBack = kulak + A + B;
3767
+ const xSide2 = kulak + 2 * A + B;
3768
+ const xEnd = kulak + 2 * A + 2 * B - 2;
3769
+ const yFoldBottom = D + C;
3770
+ const yNotchStart = yFoldBottom + NOTCH_Y;
3771
+ const yEnd = D + C + B / 2 + DIP2;
3766
3772
  return [
3773
+ // Top edge
3767
3774
  { x: 0, y: 0 },
3768
- { x: totalWidth, y: 0 },
3769
- { x: totalWidth, y: totalHeight },
3770
- { x: 0, y: totalHeight }
3775
+ { x: xEnd, y: 0 },
3776
+ // Right edge (stops at yFoldBottom)
3777
+ { x: xEnd, y: yFoldBottom },
3778
+ // xEnd V-notch (left side only — last boundary)
3779
+ { x: xEnd - NOTCH_X, y: yNotchStart },
3780
+ { x: xEnd - NOTCH_X, y: yEnd },
3781
+ // Bottom segment → xSide2 notch
3782
+ { x: xSide2 + NOTCH_X, y: yEnd },
3783
+ { x: xSide2 + NOTCH_X, y: yNotchStart },
3784
+ { x: xSide2, y: yFoldBottom },
3785
+ { x: xSide2 - NOTCH_X, y: yNotchStart },
3786
+ { x: xSide2 - NOTCH_X, y: yEnd },
3787
+ // Bottom segment → xBack notch
3788
+ { x: xBack + NOTCH_X, y: yEnd },
3789
+ { x: xBack + NOTCH_X, y: yNotchStart },
3790
+ { x: xBack, y: yFoldBottom },
3791
+ { x: xBack - NOTCH_X, y: yNotchStart },
3792
+ { x: xBack - NOTCH_X, y: yEnd },
3793
+ // Bottom segment → xSide1 notch
3794
+ { x: xSide1 + NOTCH_X, y: yEnd },
3795
+ { x: xSide1 + NOTCH_X, y: yNotchStart },
3796
+ { x: xSide1, y: yFoldBottom },
3797
+ { x: xSide1 - NOTCH_X, y: yNotchStart },
3798
+ { x: xSide1 - NOTCH_X, y: yEnd },
3799
+ // Bottom segment → xFront notch (right side only — first boundary)
3800
+ { x: xFront + NOTCH_X, y: yEnd },
3801
+ { x: xFront + NOTCH_X, y: yNotchStart },
3802
+ { x: xFront, y: yFoldBottom },
3803
+ // Glue flap diagonal
3804
+ { x: 0, y: yFoldBottom - kulak }
3805
+ // Left edge back to top
3771
3806
  ];
3772
3807
  }
3773
3808
  function offsetContour6(points, distance) {
@@ -4187,192 +4222,2575 @@ var MODEL_BECF_12109 = react.forwardRef(
4187
4222
  }
4188
4223
  );
4189
4224
 
4190
- // src/utils/autoLayout/rasterize.ts
4191
- function rasterizePolygon(points, resolution) {
4192
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
4193
- for (const p of points) {
4194
- if (p.x < minX) minX = p.x;
4195
- if (p.y < minY) minY = p.y;
4196
- if (p.x > maxX) maxX = p.x;
4197
- if (p.y > maxY) maxY = p.y;
4198
- }
4199
- const offsetX = Math.floor(minX / resolution);
4200
- const offsetY = Math.floor(minY / resolution);
4201
- const w = Math.ceil((maxX - offsetX * resolution) / resolution) + 1;
4202
- const h = Math.ceil((maxY - offsetY * resolution) / resolution) + 1;
4203
- const data = new Uint8Array(w * h);
4204
- for (let gy = 0; gy < h; gy++) {
4205
- const worldY = (offsetY + gy) * resolution + resolution / 2;
4206
- const crossings = [];
4207
- for (let i = 0, j = points.length - 1; i < points.length; j = i++) {
4208
- const yi = points[i].y, yj = points[j].y;
4209
- if (yi <= worldY && yj > worldY || yj <= worldY && yi > worldY) {
4210
- const t = (worldY - yi) / (yj - yi);
4211
- crossings.push(points[i].x + t * (points[j].x - points[i].x));
4212
- }
4213
- }
4214
- crossings.sort((a, b) => a - b);
4215
- for (let c = 0; c < crossings.length - 1; c += 2) {
4216
- const startGx = Math.max(0, Math.floor((crossings[c] - offsetX * resolution) / resolution));
4217
- const endGx = Math.min(w - 1, Math.ceil((crossings[c + 1] - offsetX * resolution) / resolution));
4218
- for (let gx = startGx; gx <= endGx; gx++) {
4219
- data[gy * w + gx] = 1;
4220
- }
4221
- }
4222
- }
4223
- return { data, width: w, height: h, offsetX, offsetY };
4224
- }
4225
- function canPlace(paperGrid, paperW, paperH, piece, px, py) {
4226
- for (let y = 0; y < piece.height; y++) {
4227
- const paperY = py + y;
4228
- if (paperY < 0 || paperY >= paperH) {
4229
- for (let x = 0; x < piece.width; x++) {
4230
- if (piece.data[y * piece.width + x]) return false;
4231
- }
4232
- continue;
4233
- }
4234
- for (let x = 0; x < piece.width; x++) {
4235
- if (!piece.data[y * piece.width + x]) continue;
4236
- const paperX = px + x;
4237
- if (paperX < 0 || paperX >= paperW) return false;
4238
- if (paperGrid[paperY * paperW + paperX]) return false;
4239
- }
4240
- }
4241
- return true;
4225
+ // src/components/dieline/bags-pillows/becf-c-12101/generate.ts
4226
+ var DIP3 = 15;
4227
+ var RIBBON_HALF_W = 9;
4228
+ var RIBBON_DX = 2;
4229
+ var RIBBON_DY = 2;
4230
+ var D_MAX3 = 40;
4231
+ function calcD3(c, b) {
4232
+ return Math.min(c - 2 - b / 2, D_MAX3);
4233
+ }
4234
+ function calcKulak3(b) {
4235
+ if (b <= 13) return b - 1;
4236
+ if (b <= 99) return 13;
4237
+ if (b <= 249) return 20;
4238
+ if (b <= 499) return 25;
4239
+ return 30;
4242
4240
  }
4243
- function placePiece(paperGrid, paperW, piece, px, py) {
4244
- for (let y = 0; y < piece.height; y++) {
4245
- for (let x = 0; x < piece.width; x++) {
4246
- if (piece.data[y * piece.width + x]) {
4247
- paperGrid[(py + y) * paperW + (px + x)] = 1;
4248
- }
4249
- }
4250
- }
4241
+ function calcX3(a) {
4242
+ return Math.min(a / 2, 110);
4251
4243
  }
4252
-
4253
- // src/utils/autoLayout/calculate/shared.ts
4254
- var RESOLUTION = 1;
4255
- function resolveGripperSide(paperWidth, paperHeight) {
4256
- if (paperWidth >= paperHeight) return "bottom";
4257
- return "left";
4244
+ function getAutoCalcValues3(attr) {
4245
+ const { length: A, width: B, height: C, glueArea } = attr;
4246
+ const D = calcD3(C, B);
4247
+ const kulak = glueArea ?? calcKulak3(B);
4248
+ const X = calcX3(A);
4249
+ return { d: D, kulak, dip: DIP3, ribbonHW: RIBBON_HALF_W, ribbonDX: RIBBON_DX, ribbonDY: RIBBON_DY, ribbonX: X };
4258
4250
  }
4259
- function computeUsableBounds(paperWidth, paperHeight, gripperSide, spacing, griper, colorbarDepth) {
4260
- switch (gripperSide) {
4261
- case "bottom":
4262
- return {
4263
- top: colorbarDepth + spacing,
4264
- bottom: paperHeight - griper,
4265
- left: spacing,
4266
- right: paperWidth - spacing
4267
- };
4268
- case "top":
4269
- return {
4270
- top: griper,
4271
- bottom: paperHeight - colorbarDepth - spacing,
4272
- left: spacing,
4273
- right: paperWidth - spacing
4274
- };
4275
- case "left":
4276
- return {
4277
- top: spacing,
4278
- bottom: paperHeight - spacing,
4279
- left: griper,
4280
- right: paperWidth - colorbarDepth - spacing
4281
- };
4282
- case "right":
4283
- return {
4284
- top: spacing,
4285
- bottom: paperHeight - spacing,
4286
- left: colorbarDepth + spacing,
4287
- right: paperWidth - griper
4288
- };
4289
- }
4251
+ function line7(x1, y1, x2, y2) {
4252
+ return `M${x1} ${y1} L${x2} ${y2}`;
4290
4253
  }
4291
- function normalizePoints(points, degrees) {
4292
- const rad = degrees * Math.PI / 180;
4293
- const cos = Math.cos(rad);
4294
- const sin = Math.sin(rad);
4295
- const rotated = points.map((p) => ({
4296
- x: p.x * cos - p.y * sin,
4297
- y: p.x * sin + p.y * cos
4298
- }));
4299
- let minX = Infinity, minY = Infinity;
4300
- for (const p of rotated) {
4301
- if (p.x < minX) minX = p.x;
4302
- if (p.y < minY) minY = p.y;
4303
- }
4304
- return rotated.map((p) => ({ x: p.x - minX, y: p.y - minY }));
4254
+ function generateBecfC12101(attr) {
4255
+ const { length: A, width: B, height: C, glueArea } = attr;
4256
+ const D = calcD3(C, B);
4257
+ const kulak = glueArea ?? calcKulak3(B);
4258
+ const X = calcX3(A);
4259
+ const xFront = kulak;
4260
+ const xSide1 = kulak + A;
4261
+ const xSide1Mid = kulak + A + B / 2;
4262
+ const xBack = kulak + A + B;
4263
+ const xSide2 = kulak + 2 * A + B;
4264
+ const xSide2Mid = kulak + 2 * A + B + B / 2;
4265
+ const xEnd = kulak + 2 * A + 2 * B - 2;
4266
+ const yFoldTop = D;
4267
+ const yFoldBottomStart = D + C - B / 2;
4268
+ const yFoldBottom = D + C;
4269
+ const yBottomFlap = D + C + B / 2;
4270
+ const yEnd = D + C + B / 2 + DIP3;
4271
+ const totalWidth = xEnd;
4272
+ const totalHeight = yEnd;
4273
+ const cut = [];
4274
+ const crease = [];
4275
+ cut.push(line7(0, 0, totalWidth, 0));
4276
+ cut.push(line7(totalWidth, 0, totalWidth, totalHeight));
4277
+ cut.push(line7(totalWidth, totalHeight, 0, totalHeight));
4278
+ cut.push(line7(0, totalHeight, 0, 0));
4279
+ cut.push(line7(kulak + B / 2, yBottomFlap, kulak + B / 2, yEnd));
4280
+ cut.push(line7(kulak + A - B / 2, yBottomFlap, kulak + A - B / 2, yEnd));
4281
+ cut.push(line7(kulak + A + B + B / 2, yBottomFlap, kulak + A + B + B / 2, yEnd));
4282
+ cut.push(line7(kulak + 2 * A + B - B / 2, yBottomFlap, kulak + 2 * A + B - B / 2, yEnd));
4283
+ const frontCx = kulak + A / 2;
4284
+ const backCx = kulak + A + B + A / 2;
4285
+ const yNotchTop = yFoldTop - RIBBON_DY / 2;
4286
+ const yNotchBot = yFoldTop + RIBBON_DY / 2;
4287
+ function addRibbonNotch(cx) {
4288
+ cut.push(line7(cx - RIBBON_HALF_W, yNotchBot, cx + RIBBON_HALF_W, yNotchBot));
4289
+ cut.push(line7(cx - RIBBON_HALF_W - RIBBON_DX, yNotchTop, cx - RIBBON_HALF_W, yNotchBot));
4290
+ cut.push(line7(cx + RIBBON_HALF_W + RIBBON_DX, yNotchTop, cx + RIBBON_HALF_W, yNotchBot));
4291
+ }
4292
+ addRibbonNotch(frontCx - X / 2);
4293
+ addRibbonNotch(frontCx + X / 2);
4294
+ addRibbonNotch(backCx - X / 2);
4295
+ addRibbonNotch(backCx + X / 2);
4296
+ crease.push(line7(0, yFoldTop, totalWidth, yFoldTop));
4297
+ crease.push(line7(0, yFoldBottomStart, totalWidth, yFoldBottomStart));
4298
+ crease.push(line7(0, yFoldBottom, totalWidth, yFoldBottom));
4299
+ crease.push(line7(xFront, 0, xFront, totalHeight));
4300
+ crease.push(line7(xSide1, 0, xSide1, totalHeight));
4301
+ crease.push(line7(xSide1Mid, 0, xSide1Mid, totalHeight));
4302
+ crease.push(line7(xBack, 0, xBack, totalHeight));
4303
+ crease.push(line7(xSide2, 0, xSide2, totalHeight));
4304
+ crease.push(line7(xSide2Mid, 0, xSide2Mid, totalHeight));
4305
+ crease.push(line7(0, yFoldBottom - kulak, kulak + B / 2, yBottomFlap));
4306
+ crease.push(line7(kulak + A - B / 2, yBottomFlap, xSide1Mid, yFoldBottomStart));
4307
+ crease.push(line7(xSide1Mid, yFoldBottomStart, kulak + A + B + B / 2, yBottomFlap));
4308
+ crease.push(line7(kulak + 2 * A + B - B / 2, yBottomFlap, xSide2Mid, yFoldBottomStart));
4309
+ crease.push(line7(xSide2Mid, yFoldBottomStart, xEnd, D + C - 2));
4310
+ return { cut, crease, viewBox: { width: totalWidth, height: totalHeight } };
4305
4311
  }
4306
- function computeDielineBBOffset(offsetContourPoints, dielineW, dielineH, degrees) {
4307
- const rad = degrees * Math.PI / 180;
4308
- const cos = Math.cos(rad);
4309
- const sin = Math.sin(rad);
4310
- let ocMinX = Infinity, ocMinY = Infinity;
4311
- for (const p of offsetContourPoints) {
4312
- const rx = p.x * cos - p.y * sin;
4313
- const ry = p.x * sin + p.y * cos;
4314
- if (rx < ocMinX) ocMinX = rx;
4315
- if (ry < ocMinY) ocMinY = ry;
4316
- }
4317
- const corners = [[0, 0], [dielineW, 0], [0, dielineH], [dielineW, dielineH]];
4318
- let dlMinX = Infinity, dlMinY = Infinity;
4319
- for (const [cx, cy] of corners) {
4320
- const rx = cx * cos - cy * sin;
4321
- const ry = cx * sin + cy * cos;
4322
- if (rx < dlMinX) dlMinX = rx;
4323
- if (ry < dlMinY) dlMinY = ry;
4324
- }
4325
- return { dx: dlMinX - ocMinX, dy: dlMinY - ocMinY };
4312
+ function generateOuterContour7(attr) {
4313
+ const { length: A, width: B, height: C, glueArea } = attr;
4314
+ const D = calcD3(C, B);
4315
+ const kulak = glueArea ?? calcKulak3(B);
4316
+ const totalWidth = kulak + 2 * A + 2 * B - 2;
4317
+ const totalHeight = D + C + B / 2 + DIP3;
4318
+ return [
4319
+ { x: 0, y: 0 },
4320
+ { x: totalWidth, y: 0 },
4321
+ { x: totalWidth, y: totalHeight },
4322
+ { x: 0, y: totalHeight }
4323
+ ];
4326
4324
  }
4327
- function computeLayoutForPaperDefault(contourPoints, dielineW, dielineH, paperWidth, paperHeight, bounds) {
4328
- const usableLeft = Math.ceil(bounds.left / RESOLUTION);
4329
- const usableTop = Math.ceil(bounds.top / RESOLUTION);
4330
- const usableRight = Math.floor(bounds.right / RESOLUTION);
4331
- const usableBottom = Math.floor(bounds.bottom / RESOLUTION);
4332
- const paperW = Math.floor(paperWidth / RESOLUTION);
4333
- const paperH = Math.floor(paperHeight / RESOLUTION);
4334
- let bestCandidate = { rotation: 0, placements: [], producedPerSheet: 0 };
4335
- let bestGridPositions = [];
4336
- let bestBitmapW = 0;
4337
- let bestBitmapH = 0;
4338
- for (const deg of [0, 90, 180, 270]) {
4339
- const rotatedContour = normalizePoints(contourPoints, deg);
4340
- const pieceBitmap = rasterizePolygon(rotatedContour, RESOLUTION);
4341
- const bbOffset = computeDielineBBOffset(contourPoints, dielineW, dielineH, deg);
4342
- const paperGrid = new Uint8Array(paperW * paperH);
4343
- const placements = [];
4344
- const gridPositions = [];
4345
- for (let py = usableTop; py <= usableBottom - pieceBitmap.height; py++) {
4346
- for (let px = usableLeft; px <= usableRight - pieceBitmap.width; px++) {
4347
- if (canPlace(paperGrid, paperW, paperH, pieceBitmap, px, py)) {
4348
- placePiece(paperGrid, paperW, pieceBitmap, px, py);
4349
- gridPositions.push({ px, py });
4350
- placements.push({
4351
- x: px * RESOLUTION + bbOffset.dx,
4352
- y: py * RESOLUTION + bbOffset.dy,
4353
- rotation: deg
4354
- });
4355
- }
4356
- }
4325
+ function offsetContour7(points, distance) {
4326
+ const n = points.length;
4327
+ const result = [];
4328
+ for (let i = 0; i < n; i++) {
4329
+ const prev = points[(i - 1 + n) % n];
4330
+ const curr = points[i];
4331
+ const next = points[(i + 1) % n];
4332
+ const e1x = curr.x - prev.x;
4333
+ const e1y = curr.y - prev.y;
4334
+ const e2x = next.x - curr.x;
4335
+ const e2y = next.y - curr.y;
4336
+ const len1 = Math.sqrt(e1x * e1x + e1y * e1y);
4337
+ const len2 = Math.sqrt(e2x * e2x + e2y * e2y);
4338
+ if (len1 === 0 || len2 === 0) {
4339
+ result.push(curr);
4340
+ continue;
4357
4341
  }
4358
- if (placements.length > bestCandidate.producedPerSheet) {
4359
- bestCandidate = { rotation: deg, placements, producedPerSheet: placements.length };
4360
- bestGridPositions = gridPositions;
4361
- bestBitmapW = pieceBitmap.width;
4362
- bestBitmapH = pieceBitmap.height;
4342
+ const n1x = e1y / len1;
4343
+ const n1y = -e1x / len1;
4344
+ const n2x = e2y / len2;
4345
+ const n2y = -e2x / len2;
4346
+ const ax = n1x + n2x;
4347
+ const ay = n1y + n2y;
4348
+ const aLen = Math.sqrt(ax * ax + ay * ay);
4349
+ if (aLen < 1e-3) {
4350
+ result.push({ x: curr.x + n1x * distance, y: curr.y + n1y * distance });
4351
+ continue;
4363
4352
  }
4353
+ const nx = ax / aLen;
4354
+ const ny = ay / aLen;
4355
+ const dot = n1x * nx + n1y * ny;
4356
+ const d = distance / Math.max(dot, 0.1);
4357
+ result.push({ x: curr.x + nx * d, y: curr.y + ny * d });
4364
4358
  }
4365
- if (bestCandidate.placements.length > 0) {
4366
- let gridMinX = Infinity;
4367
- let gridMinY = Infinity;
4368
- let gridMaxX = -Infinity;
4369
- let gridMaxY = -Infinity;
4370
- for (const { px, py } of bestGridPositions) {
4371
- if (px < gridMinX) gridMinX = px;
4372
- if (py < gridMinY) gridMinY = py;
4373
- if (px + bestBitmapW > gridMaxX) gridMaxX = px + bestBitmapW;
4374
- if (py + bestBitmapH > gridMaxY) gridMaxY = py + bestBitmapH;
4375
- }
4359
+ return result;
4360
+ }
4361
+ function contourToPath7(points) {
4362
+ if (points.length === 0) return "";
4363
+ let d = `M${points[0].x} ${points[0].y}`;
4364
+ for (let i = 1; i < points.length; i++) {
4365
+ d += ` L${points[i].x} ${points[i].y}`;
4366
+ }
4367
+ d += " Z";
4368
+ return d;
4369
+ }
4370
+ function generateDimensions7(attr, unit) {
4371
+ const { length: A, width: B, height: C, glueArea } = attr;
4372
+ const D = calcD3(C, B);
4373
+ const kulak = glueArea ?? calcKulak3(B);
4374
+ const factor = unit === "cm" ? 0.1 : unit === "in" ? 1 / 25.4 : 1;
4375
+ const suffix = unit;
4376
+ const fmt = (v) => `${(v * factor).toFixed(2)} ${suffix}`;
4377
+ const xFront = kulak;
4378
+ const xSide1 = kulak + A;
4379
+ const xBack = kulak + A + B;
4380
+ const yFoldTop = D;
4381
+ const yFoldBottom = D + C;
4382
+ const yEnd = D + C + B / 2 + DIP3;
4383
+ const totalWidth = kulak + 2 * A + 2 * B - 2;
4384
+ const totalHeight = yEnd;
4385
+ const bottomSection = B / 2 + DIP3;
4386
+ return [
4387
+ {
4388
+ x1: 0,
4389
+ y1: 0,
4390
+ x2: totalWidth,
4391
+ y2: 0,
4392
+ label: `Overall Width : ${fmt(totalWidth)}`,
4393
+ orientation: "horizontal",
4394
+ offset: -12
4395
+ },
4396
+ {
4397
+ x1: 0,
4398
+ y1: 0,
4399
+ x2: 0,
4400
+ y2: totalHeight,
4401
+ label: `Overall Height : ${fmt(totalHeight)}`,
4402
+ orientation: "vertical",
4403
+ offset: -12
4404
+ },
4405
+ {
4406
+ x1: xBack + A * 0.6,
4407
+ y1: yFoldTop,
4408
+ x2: xBack + A * 0.6,
4409
+ y2: yFoldBottom,
4410
+ label: fmt(C),
4411
+ orientation: "vertical",
4412
+ offset: -10
4413
+ },
4414
+ {
4415
+ x1: xBack + A * 0.6,
4416
+ y1: 0,
4417
+ x2: xBack + A * 0.6,
4418
+ y2: yFoldTop,
4419
+ label: fmt(D),
4420
+ orientation: "vertical",
4421
+ offset: -10
4422
+ },
4423
+ {
4424
+ x1: xBack + A * 0.6,
4425
+ y1: yFoldBottom,
4426
+ x2: xBack + A * 0.6,
4427
+ y2: yEnd,
4428
+ label: fmt(bottomSection),
4429
+ orientation: "vertical",
4430
+ offset: -10
4431
+ },
4432
+ {
4433
+ x1: xFront,
4434
+ y1: yFoldTop + C * 0.65,
4435
+ x2: xSide1,
4436
+ y2: yFoldTop + C * 0.65,
4437
+ label: fmt(A),
4438
+ orientation: "horizontal",
4439
+ offset: -20
4440
+ },
4441
+ {
4442
+ x1: xSide1,
4443
+ y1: yFoldTop + C * 0.65,
4444
+ x2: xBack,
4445
+ y2: yFoldTop + C * 0.65,
4446
+ label: fmt(B),
4447
+ orientation: "horizontal",
4448
+ offset: -20
4449
+ },
4450
+ {
4451
+ x1: 0,
4452
+ y1: yFoldTop + C * 0.65,
4453
+ x2: xFront,
4454
+ y2: yFoldTop + C * 0.65,
4455
+ label: fmt(kulak),
4456
+ orientation: "horizontal",
4457
+ offset: -20
4458
+ }
4459
+ ];
4460
+ }
4461
+ var MODEL_ID7 = "BECF-C-12101";
4462
+ var UNIT_FACTOR7 = {
4463
+ mm: 1,
4464
+ cm: 0.1,
4465
+ in: 1 / 25.4
4466
+ };
4467
+ var PX_PER_MM7 = 96 / 25.4;
4468
+ function renderDimension7(dim, i, fs) {
4469
+ const { x1, y1, x2, y2, label, orientation, offset } = dim;
4470
+ const tick = 1.5;
4471
+ if (orientation === "horizontal") {
4472
+ const y = y1 + offset;
4473
+ const midX = (x1 + x2) / 2;
4474
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
4475
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y, x2, y2: y, stroke: "#000", strokeWidth: 0.2 }),
4476
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y - tick, x2: x1, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
4477
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x2, y1: y - tick, x2, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
4478
+ /* @__PURE__ */ jsxRuntime.jsx(
4479
+ "text",
4480
+ {
4481
+ x: midX,
4482
+ y: y - 1.5,
4483
+ textAnchor: "middle",
4484
+ fontSize: fs,
4485
+ fontFamily: "sans-serif",
4486
+ fill: "#000",
4487
+ children: label
4488
+ }
4489
+ )
4490
+ ] }, `dim-${i}`);
4491
+ }
4492
+ const x = x1 + offset;
4493
+ const midY = (y1 + y2) / 2;
4494
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
4495
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x, y1, x2: x, y2, stroke: "#000", strokeWidth: 0.2 }),
4496
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1, x2: x + tick, y2: y1, stroke: "#000", strokeWidth: 0.3 }),
4497
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1: y2, x2: x + tick, y2, stroke: "#000", strokeWidth: 0.3 }),
4498
+ /* @__PURE__ */ jsxRuntime.jsx(
4499
+ "text",
4500
+ {
4501
+ x: x - 1.5,
4502
+ y: midY - 1,
4503
+ textAnchor: "middle",
4504
+ dominantBaseline: "central",
4505
+ fontSize: fs,
4506
+ fontFamily: "sans-serif",
4507
+ fill: "#000",
4508
+ transform: `rotate(-90, ${x - 1.5}, ${midY})`,
4509
+ children: label
4510
+ }
4511
+ )
4512
+ ] }, `dim-${i}`);
4513
+ }
4514
+ var DIE_LINE_BECF_C_12101 = react.forwardRef(
4515
+ ({
4516
+ attributes,
4517
+ unit = "mm",
4518
+ isShowDimensions = false,
4519
+ renderAs = "svg"
4520
+ }, ref) => {
4521
+ const theme = react.useMemo(
4522
+ () => getModelTheme(),
4523
+ []
4524
+ );
4525
+ const svgRef = react.useRef(null);
4526
+ const dieline = react.useMemo(() => generateBecfC12101(attributes), [attributes]);
4527
+ const dimensions = react.useMemo(
4528
+ () => generateDimensions7(attributes, unit),
4529
+ [attributes, unit]
4530
+ );
4531
+ const factor = UNIT_FACTOR7[unit] ?? 1;
4532
+ const serializeSvg = react.useCallback(
4533
+ (showDimensions) => {
4534
+ const svg = svgRef.current;
4535
+ if (!svg) throw new Error("SVG not mounted");
4536
+ const clone = svg.cloneNode(true);
4537
+ if (!showDimensions) {
4538
+ const dimGroup = clone.querySelector("#dimensions");
4539
+ dimGroup?.remove();
4540
+ }
4541
+ return new XMLSerializer().serializeToString(clone);
4542
+ },
4543
+ []
4544
+ );
4545
+ react.useImperativeHandle(
4546
+ ref,
4547
+ () => {
4548
+ const auto = getAutoCalcValues3(attributes);
4549
+ return {
4550
+ getAttributes: () => ({
4551
+ modelId: MODEL_ID7,
4552
+ overallWidth: dieline.viewBox.width * factor,
4553
+ overallHeight: dieline.viewBox.height * factor,
4554
+ length: attributes.length * factor,
4555
+ width: attributes.width * factor,
4556
+ height: attributes.height * factor,
4557
+ glueArea: auto.kulak * factor,
4558
+ d: auto.d * factor,
4559
+ kulak: auto.kulak * factor,
4560
+ dip: auto.dip * factor,
4561
+ ribbonHW: auto.ribbonHW * factor,
4562
+ ribbonDX: auto.ribbonDX * factor,
4563
+ ribbonDY: auto.ribbonDY * factor,
4564
+ ribbonX: auto.ribbonX * factor
4565
+ }),
4566
+ exportImage: async (options) => {
4567
+ const svgStr = serializeSvg(options.isShowDimension);
4568
+ const blob = new Blob([svgStr], {
4569
+ type: "image/svg+xml;charset=utf-8"
4570
+ });
4571
+ const url = URL.createObjectURL(blob);
4572
+ const img = new Image();
4573
+ await new Promise((resolve, reject) => {
4574
+ img.onload = () => resolve();
4575
+ img.onerror = reject;
4576
+ img.src = url;
4577
+ });
4578
+ const canvas = document.createElement("canvas");
4579
+ if (options.originalSize) {
4580
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM7);
4581
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM7);
4582
+ } else {
4583
+ canvas.width = 1920;
4584
+ canvas.height = 1080;
4585
+ }
4586
+ const ctx = canvas.getContext("2d");
4587
+ ctx.fillStyle = "#ffffff";
4588
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
4589
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
4590
+ URL.revokeObjectURL(url);
4591
+ return new Promise((resolve, reject) => {
4592
+ canvas.toBlob(
4593
+ (b) => b ? resolve(b) : reject(new Error("Export failed")),
4594
+ "image/png"
4595
+ );
4596
+ });
4597
+ },
4598
+ exportDimension: async () => {
4599
+ const dimData = generateDimensions7(attributes, unit);
4600
+ return exportDimensionPdf({
4601
+ modelId: MODEL_ID7,
4602
+ dieline,
4603
+ dimensions: dimData,
4604
+ attributes,
4605
+ unit,
4606
+ factor,
4607
+ theme
4608
+ });
4609
+ }
4610
+ };
4611
+ },
4612
+ [attributes, dieline, factor, unit, serializeSvg, theme]
4613
+ );
4614
+ const padding = isShowDimensions ? 15 : 0;
4615
+ const vbX = -padding;
4616
+ const vbY = -padding;
4617
+ const vbW = dieline.viewBox.width + padding * 2;
4618
+ const vbH = dieline.viewBox.height + padding * 2;
4619
+ const svgChildren = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
4620
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "crease", children: dieline.crease.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorFoldLine, strokeWidth: 0.5, strokeDasharray: "2,1" }, `c-${i}`)) }),
4621
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "cut", children: dieline.cut.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorDieLine, strokeWidth: 0.5 }, `t-${i}`)) }),
4622
+ isShowDimensions && /* @__PURE__ */ jsxRuntime.jsx("g", { id: "dimensions", children: dimensions.map((d, i) => renderDimension7(d, i, getFontDimensionSize())) })
4623
+ ] });
4624
+ if (renderAs === "group") {
4625
+ return /* @__PURE__ */ jsxRuntime.jsx("g", { children: svgChildren });
4626
+ }
4627
+ return /* @__PURE__ */ jsxRuntime.jsx(
4628
+ "svg",
4629
+ {
4630
+ ref: svgRef,
4631
+ xmlns: "http://www.w3.org/2000/svg",
4632
+ viewBox: `${vbX} ${vbY} ${vbW} ${vbH}`,
4633
+ preserveAspectRatio: "xMidYMid meet",
4634
+ style: { backgroundColor: theme.colorBackground },
4635
+ children: svgChildren
4636
+ }
4637
+ );
4638
+ }
4639
+ );
4640
+ var CANVAS_BECF_C_12101 = react.forwardRef(
4641
+ (props, ref) => {
4642
+ const dieLineRef = react.useRef(null);
4643
+ const canvasRef = react.useRef(null);
4644
+ const {
4645
+ attributes
4646
+ } = props;
4647
+ const theme = react.useMemo(
4648
+ () => getModelTheme(),
4649
+ []
4650
+ );
4651
+ const dieline = react.useMemo(() => generateBecfC12101(attributes), [attributes]);
4652
+ const stablePadding = 15;
4653
+ const viewBox = react.useMemo(
4654
+ () => ({
4655
+ x: -stablePadding,
4656
+ y: -stablePadding,
4657
+ width: dieline.viewBox.width + stablePadding * 2,
4658
+ height: dieline.viewBox.height + stablePadding * 2
4659
+ }),
4660
+ [dieline.viewBox.width, dieline.viewBox.height]
4661
+ );
4662
+ const serializeCanvasSvg = react.useCallback((showDimensions) => {
4663
+ const svg = canvasRef.current?.getSvgElement();
4664
+ if (!svg) throw new Error("SVG not mounted");
4665
+ const clone = svg.cloneNode(true);
4666
+ if (!showDimensions) {
4667
+ const dimGroup = clone.querySelector("#dimensions");
4668
+ dimGroup?.remove();
4669
+ }
4670
+ return new XMLSerializer().serializeToString(clone);
4671
+ }, []);
4672
+ react.useImperativeHandle(ref, () => ({
4673
+ getAttributes: () => dieLineRef.current.getAttributes(),
4674
+ exportImage: async (options) => {
4675
+ const svgStr = serializeCanvasSvg(options.isShowDimension);
4676
+ const blob = new Blob([svgStr], { type: "image/svg+xml;charset=utf-8" });
4677
+ const url = URL.createObjectURL(blob);
4678
+ const img = new Image();
4679
+ await new Promise((resolve, reject) => {
4680
+ img.onload = () => resolve();
4681
+ img.onerror = reject;
4682
+ img.src = url;
4683
+ });
4684
+ const canvas = document.createElement("canvas");
4685
+ if (options.originalSize) {
4686
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM7);
4687
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM7);
4688
+ } else {
4689
+ canvas.width = 1920;
4690
+ canvas.height = 1080;
4691
+ }
4692
+ const ctx = canvas.getContext("2d");
4693
+ ctx.fillStyle = "#ffffff";
4694
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
4695
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
4696
+ URL.revokeObjectURL(url);
4697
+ return new Promise((resolve, reject) => {
4698
+ canvas.toBlob(
4699
+ (b) => b ? resolve(b) : reject(new Error("Export failed")),
4700
+ "image/png"
4701
+ );
4702
+ });
4703
+ },
4704
+ exportDimension: () => dieLineRef.current.exportDimension(),
4705
+ resetView: () => canvasRef.current?.resetView(),
4706
+ fitView: () => canvasRef.current?.fitView()
4707
+ }), [serializeCanvasSvg, dieline.viewBox.width, dieline.viewBox.height]);
4708
+ return /* @__PURE__ */ jsxRuntime.jsx(
4709
+ BaseCanvas,
4710
+ {
4711
+ ref: canvasRef,
4712
+ viewBox,
4713
+ backgroundColor: theme.colorBackground,
4714
+ children: /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_C_12101, { ref: dieLineRef, ...props, renderAs: "group" })
4715
+ }
4716
+ );
4717
+ }
4718
+ );
4719
+ var MODEL_BECF_C_12101 = react.forwardRef(
4720
+ ({ mode = "DIE_LINE", ...props }, ref) => {
4721
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: (() => {
4722
+ switch (mode) {
4723
+ case "DIE_LINE":
4724
+ return /* @__PURE__ */ jsxRuntime.jsx(CANVAS_BECF_C_12101, { ref, ...props });
4725
+ case "3D":
4726
+ return null;
4727
+ case "AUTO_LAYOUT":
4728
+ return /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_C_12101, { ref, ...props });
4729
+ default:
4730
+ return null;
4731
+ }
4732
+ })() });
4733
+ }
4734
+ );
4735
+
4736
+ // src/components/dieline/bags-pillows/becf-c-12109/generate.ts
4737
+ var DIP4 = 13;
4738
+ var RIBBON_HALF_W2 = 9;
4739
+ var RIBBON_DX2 = 2;
4740
+ var RIBBON_DY2 = 2;
4741
+ var D_MAX4 = 40;
4742
+ var NOTCH_X2 = 3;
4743
+ var NOTCH_Y2 = 5;
4744
+ function calcD4(c, b) {
4745
+ return Math.min(c - 2 - b / 2, D_MAX4);
4746
+ }
4747
+ function calcKulak4(b) {
4748
+ if (b <= 13) return b - 1;
4749
+ if (b <= 99) return 13;
4750
+ if (b <= 249) return 20;
4751
+ if (b <= 499) return 25;
4752
+ return 30;
4753
+ }
4754
+ function calcX4(a) {
4755
+ return a / 2;
4756
+ }
4757
+ function getAutoCalcValues4(attr) {
4758
+ const { length: A, width: B, height: C, glueArea } = attr;
4759
+ const D = calcD4(C, B);
4760
+ const kulak = glueArea ?? calcKulak4(B);
4761
+ const X = calcX4(A);
4762
+ return { d: D, kulak, dip: DIP4, ribbonHW: RIBBON_HALF_W2, ribbonDX: RIBBON_DX2, ribbonDY: RIBBON_DY2, ribbonX: X };
4763
+ }
4764
+ function line8(x1, y1, x2, y2) {
4765
+ return `M${x1} ${y1} L${x2} ${y2}`;
4766
+ }
4767
+ function generateBecfC12109(attr) {
4768
+ const { length: A, width: B, height: C, glueArea } = attr;
4769
+ const D = calcD4(C, B);
4770
+ const kulak = glueArea ?? calcKulak4(B);
4771
+ const X = calcX4(A);
4772
+ const xFront = kulak;
4773
+ const xSide1 = kulak + A;
4774
+ const xSide1Mid = kulak + A + B / 2;
4775
+ const xBack = kulak + A + B;
4776
+ const xSide2 = kulak + 2 * A + B;
4777
+ const xSide2Mid = kulak + 2 * A + B + B / 2;
4778
+ const xEnd = kulak + 2 * A + 2 * B - 2;
4779
+ const yFoldTop = D;
4780
+ const yFoldBottomStart = D + C - B / 2;
4781
+ const yFoldBottom = D + C;
4782
+ const yNotchStart = yFoldBottom + NOTCH_Y2;
4783
+ const yEnd = D + C + B / 2 + DIP4;
4784
+ const totalWidth = xEnd;
4785
+ const totalHeight = yEnd;
4786
+ const cut = [];
4787
+ const crease = [];
4788
+ cut.push(line8(0, 0, 0, yFoldBottom - kulak));
4789
+ cut.push(line8(0, 0, totalWidth, 0));
4790
+ cut.push(line8(totalWidth, 0, totalWidth, yFoldBottom));
4791
+ cut.push(line8(0, yFoldBottom - kulak, kulak, yFoldBottom));
4792
+ const boundaries = [xFront, xSide1, xBack, xSide2, xEnd];
4793
+ for (let i = 0; i < boundaries.length; i++) {
4794
+ const xb = boundaries[i];
4795
+ const isFirst = i === 0;
4796
+ const isLast = i === boundaries.length - 1;
4797
+ if (!isFirst) {
4798
+ cut.push(line8(xb - NOTCH_X2, yNotchStart, xb - NOTCH_X2, totalHeight));
4799
+ cut.push(line8(xb - NOTCH_X2, yNotchStart, xb, yFoldBottom));
4800
+ }
4801
+ if (!isLast) {
4802
+ cut.push(line8(xb + NOTCH_X2, yNotchStart, xb + NOTCH_X2, totalHeight));
4803
+ cut.push(line8(xb + NOTCH_X2, yNotchStart, xb, yFoldBottom));
4804
+ }
4805
+ }
4806
+ cut.push(line8(xFront + NOTCH_X2, totalHeight, xSide1 - NOTCH_X2, totalHeight));
4807
+ cut.push(line8(xSide1 + NOTCH_X2, totalHeight, xBack - NOTCH_X2, totalHeight));
4808
+ cut.push(line8(xBack + NOTCH_X2, totalHeight, xSide2 - NOTCH_X2, totalHeight));
4809
+ cut.push(line8(xSide2 + NOTCH_X2, totalHeight, xEnd - NOTCH_X2, totalHeight));
4810
+ const frontCx = kulak + A / 2;
4811
+ const backCx = kulak + A + B + A / 2;
4812
+ const yRibbonTop = yFoldTop - RIBBON_DY2 / 2;
4813
+ const yRibbonBot = yFoldTop + RIBBON_DY2 / 2;
4814
+ function addRibbonNotch(cx) {
4815
+ cut.push(line8(cx - RIBBON_HALF_W2, yRibbonBot, cx + RIBBON_HALF_W2, yRibbonBot));
4816
+ cut.push(line8(cx - RIBBON_HALF_W2 - RIBBON_DX2, yRibbonTop, cx - RIBBON_HALF_W2, yRibbonBot));
4817
+ cut.push(line8(cx + RIBBON_HALF_W2 + RIBBON_DX2, yRibbonTop, cx + RIBBON_HALF_W2, yRibbonBot));
4818
+ }
4819
+ addRibbonNotch(frontCx - X / 2);
4820
+ addRibbonNotch(frontCx + X / 2);
4821
+ addRibbonNotch(backCx - X / 2);
4822
+ addRibbonNotch(backCx + X / 2);
4823
+ crease.push(line8(0, yFoldTop, totalWidth, yFoldTop));
4824
+ crease.push(line8(0, yFoldBottomStart, totalWidth, yFoldBottomStart));
4825
+ crease.push(line8(kulak, yFoldBottom, xEnd, yFoldBottom));
4826
+ crease.push(line8(xFront, 0, xFront, yFoldBottom));
4827
+ crease.push(line8(xSide1, 0, xSide1, yFoldBottom));
4828
+ crease.push(line8(xBack, 0, xBack, yFoldBottom));
4829
+ crease.push(line8(xSide2, 0, xSide2, yFoldBottom));
4830
+ crease.push(line8(xSide1Mid, 0, xSide1Mid, totalHeight));
4831
+ crease.push(line8(xSide2Mid, 0, xSide2Mid, totalHeight));
4832
+ crease.push(line8(xBack, yFoldBottom, xSide1Mid, yFoldBottomStart));
4833
+ crease.push(line8(xSide1Mid, yFoldBottomStart, xSide1, yFoldBottom));
4834
+ crease.push(line8(xSide2Mid, yFoldBottomStart, xSide2, yFoldBottom));
4835
+ crease.push(line8(xSide2Mid, yFoldBottomStart, xEnd, D + C - 2));
4836
+ return { cut, crease, viewBox: { width: totalWidth, height: totalHeight } };
4837
+ }
4838
+ function generateOuterContour8(attr) {
4839
+ const { length: A, width: B, height: C, glueArea } = attr;
4840
+ const D = calcD4(C, B);
4841
+ const kulak = glueArea ?? calcKulak4(B);
4842
+ const xFront = kulak;
4843
+ const xSide1 = kulak + A;
4844
+ const xBack = kulak + A + B;
4845
+ const xSide2 = kulak + 2 * A + B;
4846
+ const xEnd = kulak + 2 * A + 2 * B - 2;
4847
+ const yFoldBottom = D + C;
4848
+ const yNotchStart = yFoldBottom + NOTCH_Y2;
4849
+ const yEnd = D + C + B / 2 + DIP4;
4850
+ return [
4851
+ { x: 0, y: 0 },
4852
+ { x: xEnd, y: 0 },
4853
+ { x: xEnd, y: yFoldBottom },
4854
+ { x: xEnd - NOTCH_X2, y: yNotchStart },
4855
+ { x: xEnd - NOTCH_X2, y: yEnd },
4856
+ { x: xSide2 + NOTCH_X2, y: yEnd },
4857
+ { x: xSide2 + NOTCH_X2, y: yNotchStart },
4858
+ { x: xSide2, y: yFoldBottom },
4859
+ { x: xSide2 - NOTCH_X2, y: yNotchStart },
4860
+ { x: xSide2 - NOTCH_X2, y: yEnd },
4861
+ { x: xBack + NOTCH_X2, y: yEnd },
4862
+ { x: xBack + NOTCH_X2, y: yNotchStart },
4863
+ { x: xBack, y: yFoldBottom },
4864
+ { x: xBack - NOTCH_X2, y: yNotchStart },
4865
+ { x: xBack - NOTCH_X2, y: yEnd },
4866
+ { x: xSide1 + NOTCH_X2, y: yEnd },
4867
+ { x: xSide1 + NOTCH_X2, y: yNotchStart },
4868
+ { x: xSide1, y: yFoldBottom },
4869
+ { x: xSide1 - NOTCH_X2, y: yNotchStart },
4870
+ { x: xSide1 - NOTCH_X2, y: yEnd },
4871
+ { x: xFront + NOTCH_X2, y: yEnd },
4872
+ { x: xFront + NOTCH_X2, y: yNotchStart },
4873
+ { x: xFront, y: yFoldBottom },
4874
+ { x: 0, y: yFoldBottom - kulak }
4875
+ ];
4876
+ }
4877
+ function offsetContour8(points, distance) {
4878
+ const n = points.length;
4879
+ const result = [];
4880
+ for (let i = 0; i < n; i++) {
4881
+ const prev = points[(i - 1 + n) % n];
4882
+ const curr = points[i];
4883
+ const next = points[(i + 1) % n];
4884
+ const e1x = curr.x - prev.x;
4885
+ const e1y = curr.y - prev.y;
4886
+ const e2x = next.x - curr.x;
4887
+ const e2y = next.y - curr.y;
4888
+ const len1 = Math.sqrt(e1x * e1x + e1y * e1y);
4889
+ const len2 = Math.sqrt(e2x * e2x + e2y * e2y);
4890
+ if (len1 === 0 || len2 === 0) {
4891
+ result.push(curr);
4892
+ continue;
4893
+ }
4894
+ const n1x = e1y / len1;
4895
+ const n1y = -e1x / len1;
4896
+ const n2x = e2y / len2;
4897
+ const n2y = -e2x / len2;
4898
+ const ax = n1x + n2x;
4899
+ const ay = n1y + n2y;
4900
+ const aLen = Math.sqrt(ax * ax + ay * ay);
4901
+ if (aLen < 1e-3) {
4902
+ result.push({ x: curr.x + n1x * distance, y: curr.y + n1y * distance });
4903
+ continue;
4904
+ }
4905
+ const nx = ax / aLen;
4906
+ const ny = ay / aLen;
4907
+ const dot = n1x * nx + n1y * ny;
4908
+ const d = distance / Math.max(dot, 0.1);
4909
+ result.push({ x: curr.x + nx * d, y: curr.y + ny * d });
4910
+ }
4911
+ return result;
4912
+ }
4913
+ function contourToPath8(points) {
4914
+ if (points.length === 0) return "";
4915
+ let d = `M${points[0].x} ${points[0].y}`;
4916
+ for (let i = 1; i < points.length; i++) {
4917
+ d += ` L${points[i].x} ${points[i].y}`;
4918
+ }
4919
+ d += " Z";
4920
+ return d;
4921
+ }
4922
+ function generateDimensions8(attr, unit) {
4923
+ const { length: A, width: B, height: C, glueArea } = attr;
4924
+ const D = calcD4(C, B);
4925
+ const kulak = glueArea ?? calcKulak4(B);
4926
+ const factor = unit === "cm" ? 0.1 : unit === "in" ? 1 / 25.4 : 1;
4927
+ const suffix = unit;
4928
+ const fmt = (v) => `${(v * factor).toFixed(2)} ${suffix}`;
4929
+ const xFront = kulak;
4930
+ const xSide1 = kulak + A;
4931
+ const xBack = kulak + A + B;
4932
+ const yFoldTop = D;
4933
+ const yFoldBottom = D + C;
4934
+ const yEnd = D + C + B / 2 + DIP4;
4935
+ const totalWidth = kulak + 2 * A + 2 * B - 2;
4936
+ const totalHeight = yEnd;
4937
+ const bottomSection = B / 2 + DIP4;
4938
+ return [
4939
+ {
4940
+ x1: 0,
4941
+ y1: 0,
4942
+ x2: totalWidth,
4943
+ y2: 0,
4944
+ label: `Overall Width : ${fmt(totalWidth)}`,
4945
+ orientation: "horizontal",
4946
+ offset: -12
4947
+ },
4948
+ {
4949
+ x1: 0,
4950
+ y1: 0,
4951
+ x2: 0,
4952
+ y2: totalHeight,
4953
+ label: `Overall Height : ${fmt(totalHeight)}`,
4954
+ orientation: "vertical",
4955
+ offset: -12
4956
+ },
4957
+ {
4958
+ x1: xBack + A * 0.6,
4959
+ y1: yFoldTop,
4960
+ x2: xBack + A * 0.6,
4961
+ y2: yFoldBottom,
4962
+ label: fmt(C),
4963
+ orientation: "vertical",
4964
+ offset: -10
4965
+ },
4966
+ {
4967
+ x1: xBack + A * 0.6,
4968
+ y1: 0,
4969
+ x2: xBack + A * 0.6,
4970
+ y2: yFoldTop,
4971
+ label: fmt(D),
4972
+ orientation: "vertical",
4973
+ offset: -10
4974
+ },
4975
+ {
4976
+ x1: xBack + A * 0.6,
4977
+ y1: yFoldBottom,
4978
+ x2: xBack + A * 0.6,
4979
+ y2: yEnd,
4980
+ label: fmt(bottomSection),
4981
+ orientation: "vertical",
4982
+ offset: -10
4983
+ },
4984
+ {
4985
+ x1: xFront,
4986
+ y1: yFoldTop + C * 0.65,
4987
+ x2: xSide1,
4988
+ y2: yFoldTop + C * 0.65,
4989
+ label: fmt(A),
4990
+ orientation: "horizontal",
4991
+ offset: -20
4992
+ },
4993
+ {
4994
+ x1: xSide1,
4995
+ y1: yFoldTop + C * 0.65,
4996
+ x2: xBack,
4997
+ y2: yFoldTop + C * 0.65,
4998
+ label: fmt(B),
4999
+ orientation: "horizontal",
5000
+ offset: -20
5001
+ },
5002
+ {
5003
+ x1: 0,
5004
+ y1: yFoldTop + C * 0.65,
5005
+ x2: xFront,
5006
+ y2: yFoldTop + C * 0.65,
5007
+ label: fmt(kulak),
5008
+ orientation: "horizontal",
5009
+ offset: -20
5010
+ }
5011
+ ];
5012
+ }
5013
+ var MODEL_ID8 = "BECF-C-12109";
5014
+ var UNIT_FACTOR8 = {
5015
+ mm: 1,
5016
+ cm: 0.1,
5017
+ in: 1 / 25.4
5018
+ };
5019
+ var PX_PER_MM8 = 96 / 25.4;
5020
+ function renderDimension8(dim, i, fs) {
5021
+ const { x1, y1, x2, y2, label, orientation, offset } = dim;
5022
+ const tick = 1.5;
5023
+ if (orientation === "horizontal") {
5024
+ const y = y1 + offset;
5025
+ const midX = (x1 + x2) / 2;
5026
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
5027
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y, x2, y2: y, stroke: "#000", strokeWidth: 0.2 }),
5028
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y - tick, x2: x1, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
5029
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x2, y1: y - tick, x2, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
5030
+ /* @__PURE__ */ jsxRuntime.jsx(
5031
+ "text",
5032
+ {
5033
+ x: midX,
5034
+ y: y - 1.5,
5035
+ textAnchor: "middle",
5036
+ fontSize: fs,
5037
+ fontFamily: "sans-serif",
5038
+ fill: "#000",
5039
+ children: label
5040
+ }
5041
+ )
5042
+ ] }, `dim-${i}`);
5043
+ }
5044
+ const x = x1 + offset;
5045
+ const midY = (y1 + y2) / 2;
5046
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
5047
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x, y1, x2: x, y2, stroke: "#000", strokeWidth: 0.2 }),
5048
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1, x2: x + tick, y2: y1, stroke: "#000", strokeWidth: 0.3 }),
5049
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1: y2, x2: x + tick, y2, stroke: "#000", strokeWidth: 0.3 }),
5050
+ /* @__PURE__ */ jsxRuntime.jsx(
5051
+ "text",
5052
+ {
5053
+ x: x - 1.5,
5054
+ y: midY - 1,
5055
+ textAnchor: "middle",
5056
+ dominantBaseline: "central",
5057
+ fontSize: fs,
5058
+ fontFamily: "sans-serif",
5059
+ fill: "#000",
5060
+ transform: `rotate(-90, ${x - 1.5}, ${midY})`,
5061
+ children: label
5062
+ }
5063
+ )
5064
+ ] }, `dim-${i}`);
5065
+ }
5066
+ var DIE_LINE_BECF_C_12109 = react.forwardRef(
5067
+ ({
5068
+ attributes,
5069
+ unit = "mm",
5070
+ isShowDimensions = false,
5071
+ renderAs = "svg"
5072
+ }, ref) => {
5073
+ const theme = react.useMemo(
5074
+ () => getModelTheme(),
5075
+ []
5076
+ );
5077
+ const svgRef = react.useRef(null);
5078
+ const dieline = react.useMemo(() => generateBecfC12109(attributes), [attributes]);
5079
+ const dimensions = react.useMemo(
5080
+ () => generateDimensions8(attributes, unit),
5081
+ [attributes, unit]
5082
+ );
5083
+ const factor = UNIT_FACTOR8[unit] ?? 1;
5084
+ const serializeSvg = react.useCallback(
5085
+ (showDimensions) => {
5086
+ const svg = svgRef.current;
5087
+ if (!svg) throw new Error("SVG not mounted");
5088
+ const clone = svg.cloneNode(true);
5089
+ if (!showDimensions) {
5090
+ const dimGroup = clone.querySelector("#dimensions");
5091
+ dimGroup?.remove();
5092
+ }
5093
+ return new XMLSerializer().serializeToString(clone);
5094
+ },
5095
+ []
5096
+ );
5097
+ react.useImperativeHandle(
5098
+ ref,
5099
+ () => {
5100
+ const auto = getAutoCalcValues4(attributes);
5101
+ return {
5102
+ getAttributes: () => ({
5103
+ modelId: MODEL_ID8,
5104
+ overallWidth: dieline.viewBox.width * factor,
5105
+ overallHeight: dieline.viewBox.height * factor,
5106
+ length: attributes.length * factor,
5107
+ width: attributes.width * factor,
5108
+ height: attributes.height * factor,
5109
+ glueArea: auto.kulak * factor,
5110
+ d: auto.d * factor,
5111
+ kulak: auto.kulak * factor,
5112
+ dip: auto.dip * factor,
5113
+ ribbonHW: auto.ribbonHW * factor,
5114
+ ribbonDX: auto.ribbonDX * factor,
5115
+ ribbonDY: auto.ribbonDY * factor,
5116
+ ribbonX: auto.ribbonX * factor
5117
+ }),
5118
+ exportImage: async (options) => {
5119
+ const svgStr = serializeSvg(options.isShowDimension);
5120
+ const blob = new Blob([svgStr], {
5121
+ type: "image/svg+xml;charset=utf-8"
5122
+ });
5123
+ const url = URL.createObjectURL(blob);
5124
+ const img = new Image();
5125
+ await new Promise((resolve, reject) => {
5126
+ img.onload = () => resolve();
5127
+ img.onerror = reject;
5128
+ img.src = url;
5129
+ });
5130
+ const canvas = document.createElement("canvas");
5131
+ if (options.originalSize) {
5132
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM8);
5133
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM8);
5134
+ } else {
5135
+ canvas.width = 1920;
5136
+ canvas.height = 1080;
5137
+ }
5138
+ const ctx = canvas.getContext("2d");
5139
+ ctx.fillStyle = "#ffffff";
5140
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
5141
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
5142
+ URL.revokeObjectURL(url);
5143
+ return new Promise((resolve, reject) => {
5144
+ canvas.toBlob(
5145
+ (b) => b ? resolve(b) : reject(new Error("Export failed")),
5146
+ "image/png"
5147
+ );
5148
+ });
5149
+ },
5150
+ exportDimension: async () => {
5151
+ const dimData = generateDimensions8(attributes, unit);
5152
+ return exportDimensionPdf({
5153
+ modelId: MODEL_ID8,
5154
+ dieline,
5155
+ dimensions: dimData,
5156
+ attributes,
5157
+ unit,
5158
+ factor,
5159
+ theme
5160
+ });
5161
+ }
5162
+ };
5163
+ },
5164
+ [attributes, dieline, factor, unit, serializeSvg, theme]
5165
+ );
5166
+ const padding = isShowDimensions ? 15 : 0;
5167
+ const vbX = -padding;
5168
+ const vbY = -padding;
5169
+ const vbW = dieline.viewBox.width + padding * 2;
5170
+ const vbH = dieline.viewBox.height + padding * 2;
5171
+ const svgChildren = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5172
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "crease", children: dieline.crease.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorFoldLine, strokeWidth: 0.5, strokeDasharray: "2,1" }, `c-${i}`)) }),
5173
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "cut", children: dieline.cut.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorDieLine, strokeWidth: 0.5 }, `t-${i}`)) }),
5174
+ isShowDimensions && /* @__PURE__ */ jsxRuntime.jsx("g", { id: "dimensions", children: dimensions.map((d, i) => renderDimension8(d, i, getFontDimensionSize())) })
5175
+ ] });
5176
+ if (renderAs === "group") {
5177
+ return /* @__PURE__ */ jsxRuntime.jsx("g", { children: svgChildren });
5178
+ }
5179
+ return /* @__PURE__ */ jsxRuntime.jsx(
5180
+ "svg",
5181
+ {
5182
+ ref: svgRef,
5183
+ xmlns: "http://www.w3.org/2000/svg",
5184
+ viewBox: `${vbX} ${vbY} ${vbW} ${vbH}`,
5185
+ preserveAspectRatio: "xMidYMid meet",
5186
+ style: { backgroundColor: theme.colorBackground },
5187
+ children: svgChildren
5188
+ }
5189
+ );
5190
+ }
5191
+ );
5192
+ var CANVAS_BECF_C_12109 = react.forwardRef(
5193
+ (props, ref) => {
5194
+ const dieLineRef = react.useRef(null);
5195
+ const canvasRef = react.useRef(null);
5196
+ const {
5197
+ attributes
5198
+ } = props;
5199
+ const theme = react.useMemo(
5200
+ () => getModelTheme(),
5201
+ []
5202
+ );
5203
+ const dieline = react.useMemo(() => generateBecfC12109(attributes), [attributes]);
5204
+ const stablePadding = 15;
5205
+ const viewBox = react.useMemo(
5206
+ () => ({
5207
+ x: -stablePadding,
5208
+ y: -stablePadding,
5209
+ width: dieline.viewBox.width + stablePadding * 2,
5210
+ height: dieline.viewBox.height + stablePadding * 2
5211
+ }),
5212
+ [dieline.viewBox.width, dieline.viewBox.height]
5213
+ );
5214
+ const serializeCanvasSvg = react.useCallback((showDimensions) => {
5215
+ const svg = canvasRef.current?.getSvgElement();
5216
+ if (!svg) throw new Error("SVG not mounted");
5217
+ const clone = svg.cloneNode(true);
5218
+ if (!showDimensions) {
5219
+ const dimGroup = clone.querySelector("#dimensions");
5220
+ dimGroup?.remove();
5221
+ }
5222
+ return new XMLSerializer().serializeToString(clone);
5223
+ }, []);
5224
+ react.useImperativeHandle(ref, () => ({
5225
+ getAttributes: () => dieLineRef.current.getAttributes(),
5226
+ exportImage: async (options) => {
5227
+ const svgStr = serializeCanvasSvg(options.isShowDimension);
5228
+ const blob = new Blob([svgStr], { type: "image/svg+xml;charset=utf-8" });
5229
+ const url = URL.createObjectURL(blob);
5230
+ const img = new Image();
5231
+ await new Promise((resolve, reject) => {
5232
+ img.onload = () => resolve();
5233
+ img.onerror = reject;
5234
+ img.src = url;
5235
+ });
5236
+ const canvas = document.createElement("canvas");
5237
+ if (options.originalSize) {
5238
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM8);
5239
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM8);
5240
+ } else {
5241
+ canvas.width = 1920;
5242
+ canvas.height = 1080;
5243
+ }
5244
+ const ctx = canvas.getContext("2d");
5245
+ ctx.fillStyle = "#ffffff";
5246
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
5247
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
5248
+ URL.revokeObjectURL(url);
5249
+ return new Promise((resolve, reject) => {
5250
+ canvas.toBlob(
5251
+ (b) => b ? resolve(b) : reject(new Error("Export failed")),
5252
+ "image/png"
5253
+ );
5254
+ });
5255
+ },
5256
+ exportDimension: () => dieLineRef.current.exportDimension(),
5257
+ resetView: () => canvasRef.current?.resetView(),
5258
+ fitView: () => canvasRef.current?.fitView()
5259
+ }), [serializeCanvasSvg, dieline.viewBox.width, dieline.viewBox.height]);
5260
+ return /* @__PURE__ */ jsxRuntime.jsx(
5261
+ BaseCanvas,
5262
+ {
5263
+ ref: canvasRef,
5264
+ viewBox,
5265
+ backgroundColor: theme.colorBackground,
5266
+ children: /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_C_12109, { ref: dieLineRef, ...props, renderAs: "group" })
5267
+ }
5268
+ );
5269
+ }
5270
+ );
5271
+ var MODEL_BECF_C_12109 = react.forwardRef(
5272
+ ({ mode = "DIE_LINE", ...props }, ref) => {
5273
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: (() => {
5274
+ switch (mode) {
5275
+ case "DIE_LINE":
5276
+ return /* @__PURE__ */ jsxRuntime.jsx(CANVAS_BECF_C_12109, { ref, ...props });
5277
+ case "3D":
5278
+ return null;
5279
+ case "AUTO_LAYOUT":
5280
+ return /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_C_12109, { ref, ...props });
5281
+ default:
5282
+ return null;
5283
+ }
5284
+ })() });
5285
+ }
5286
+ );
5287
+
5288
+ // src/components/dieline/bags-pillows/becf-b-12101/generate.ts
5289
+ var DIP5 = 15;
5290
+ function calcKulak5(b) {
5291
+ if (b <= 13) return b - 1;
5292
+ if (b <= 99) return 13;
5293
+ if (b <= 249) return 20;
5294
+ if (b <= 499) return 25;
5295
+ return 30;
5296
+ }
5297
+ function getAutoCalcValues5(attr) {
5298
+ const { width: B, glueArea } = attr;
5299
+ const kulak = glueArea ?? calcKulak5(B);
5300
+ return { kulak, dip: DIP5 };
5301
+ }
5302
+ function line9(x1, y1, x2, y2) {
5303
+ return `M${x1} ${y1} L${x2} ${y2}`;
5304
+ }
5305
+ function generateBecfB12101(attr) {
5306
+ const { length: A, width: B, height: C, glueArea } = attr;
5307
+ const kulak = glueArea ?? calcKulak5(B);
5308
+ const xFront = kulak;
5309
+ const xSide1 = kulak + A;
5310
+ const xSide1Mid = kulak + A + B / 2;
5311
+ const xBack = kulak + A + B;
5312
+ const xSide2 = kulak + 2 * A + B;
5313
+ const xSide2Mid = kulak + 2 * A + B + B / 2;
5314
+ const xEnd = kulak + 2 * A + 2 * B - 2;
5315
+ const yFoldBottomStart = C - B / 2;
5316
+ const yFoldBottom = C;
5317
+ const yBottomFlap = C + B / 2;
5318
+ const yEnd = C + B / 2 + DIP5;
5319
+ const totalWidth = xEnd;
5320
+ const totalHeight = yEnd;
5321
+ const cut = [];
5322
+ const crease = [];
5323
+ cut.push(line9(0, 0, totalWidth, 0));
5324
+ cut.push(line9(totalWidth, 0, totalWidth, totalHeight));
5325
+ cut.push(line9(totalWidth, totalHeight, 0, totalHeight));
5326
+ cut.push(line9(0, totalHeight, 0, 0));
5327
+ cut.push(line9(kulak + B / 2, yBottomFlap, kulak + B / 2, yEnd));
5328
+ cut.push(line9(kulak + A - B / 2, yBottomFlap, kulak + A - B / 2, yEnd));
5329
+ cut.push(line9(kulak + A + B + B / 2, yBottomFlap, kulak + A + B + B / 2, yEnd));
5330
+ cut.push(line9(kulak + 2 * A + B - B / 2, yBottomFlap, kulak + 2 * A + B - B / 2, yEnd));
5331
+ crease.push(line9(0, yFoldBottomStart, totalWidth, yFoldBottomStart));
5332
+ crease.push(line9(0, yFoldBottom, totalWidth, yFoldBottom));
5333
+ crease.push(line9(xFront, 0, xFront, totalHeight));
5334
+ crease.push(line9(xSide1, 0, xSide1, totalHeight));
5335
+ crease.push(line9(xSide1Mid, 0, xSide1Mid, totalHeight));
5336
+ crease.push(line9(xBack, 0, xBack, totalHeight));
5337
+ crease.push(line9(xSide2, 0, xSide2, totalHeight));
5338
+ crease.push(line9(xSide2Mid, 0, xSide2Mid, totalHeight));
5339
+ crease.push(line9(0, yFoldBottom - kulak, kulak + B / 2, yBottomFlap));
5340
+ crease.push(line9(kulak + A - B / 2, yBottomFlap, xSide1Mid, yFoldBottomStart));
5341
+ crease.push(line9(xSide1Mid, yFoldBottomStart, kulak + A + B + B / 2, yBottomFlap));
5342
+ crease.push(line9(kulak + 2 * A + B - B / 2, yBottomFlap, xSide2Mid, yFoldBottomStart));
5343
+ crease.push(line9(xSide2Mid, yFoldBottomStart, xEnd, C - 2));
5344
+ return { cut, crease, viewBox: { width: totalWidth, height: totalHeight } };
5345
+ }
5346
+ function generateOuterContour9(attr) {
5347
+ const { length: A, width: B, height: C, glueArea } = attr;
5348
+ const kulak = glueArea ?? calcKulak5(B);
5349
+ const totalWidth = kulak + 2 * A + 2 * B - 2;
5350
+ const totalHeight = C + B / 2 + DIP5;
5351
+ return [
5352
+ { x: 0, y: 0 },
5353
+ { x: totalWidth, y: 0 },
5354
+ { x: totalWidth, y: totalHeight },
5355
+ { x: 0, y: totalHeight }
5356
+ ];
5357
+ }
5358
+ function offsetContour9(points, distance) {
5359
+ const n = points.length;
5360
+ const result = [];
5361
+ for (let i = 0; i < n; i++) {
5362
+ const prev = points[(i - 1 + n) % n];
5363
+ const curr = points[i];
5364
+ const next = points[(i + 1) % n];
5365
+ const e1x = curr.x - prev.x;
5366
+ const e1y = curr.y - prev.y;
5367
+ const e2x = next.x - curr.x;
5368
+ const e2y = next.y - curr.y;
5369
+ const len1 = Math.sqrt(e1x * e1x + e1y * e1y);
5370
+ const len2 = Math.sqrt(e2x * e2x + e2y * e2y);
5371
+ if (len1 === 0 || len2 === 0) {
5372
+ result.push(curr);
5373
+ continue;
5374
+ }
5375
+ const n1x = e1y / len1;
5376
+ const n1y = -e1x / len1;
5377
+ const n2x = e2y / len2;
5378
+ const n2y = -e2x / len2;
5379
+ const ax = n1x + n2x;
5380
+ const ay = n1y + n2y;
5381
+ const aLen = Math.sqrt(ax * ax + ay * ay);
5382
+ if (aLen < 1e-3) {
5383
+ result.push({ x: curr.x + n1x * distance, y: curr.y + n1y * distance });
5384
+ continue;
5385
+ }
5386
+ const nx = ax / aLen;
5387
+ const ny = ay / aLen;
5388
+ const dot = n1x * nx + n1y * ny;
5389
+ const d = distance / Math.max(dot, 0.1);
5390
+ result.push({ x: curr.x + nx * d, y: curr.y + ny * d });
5391
+ }
5392
+ return result;
5393
+ }
5394
+ function contourToPath9(points) {
5395
+ if (points.length === 0) return "";
5396
+ let d = `M${points[0].x} ${points[0].y}`;
5397
+ for (let i = 1; i < points.length; i++) {
5398
+ d += ` L${points[i].x} ${points[i].y}`;
5399
+ }
5400
+ d += " Z";
5401
+ return d;
5402
+ }
5403
+ function generateDimensions9(attr, unit) {
5404
+ const { length: A, width: B, height: C, glueArea } = attr;
5405
+ const kulak = glueArea ?? calcKulak5(B);
5406
+ const factor = unit === "cm" ? 0.1 : unit === "in" ? 1 / 25.4 : 1;
5407
+ const suffix = unit;
5408
+ const fmt = (v) => `${(v * factor).toFixed(2)} ${suffix}`;
5409
+ const xFront = kulak;
5410
+ const xSide1 = kulak + A;
5411
+ const xBack = kulak + A + B;
5412
+ const yFoldBottom = C;
5413
+ const yEnd = C + B / 2 + DIP5;
5414
+ const totalWidth = kulak + 2 * A + 2 * B - 2;
5415
+ const totalHeight = yEnd;
5416
+ const bottomSection = B / 2 + DIP5;
5417
+ return [
5418
+ {
5419
+ x1: 0,
5420
+ y1: 0,
5421
+ x2: totalWidth,
5422
+ y2: 0,
5423
+ label: `Overall Width : ${fmt(totalWidth)}`,
5424
+ orientation: "horizontal",
5425
+ offset: -12
5426
+ },
5427
+ {
5428
+ x1: 0,
5429
+ y1: 0,
5430
+ x2: 0,
5431
+ y2: totalHeight,
5432
+ label: `Overall Height : ${fmt(totalHeight)}`,
5433
+ orientation: "vertical",
5434
+ offset: -12
5435
+ },
5436
+ // Height (C) — body area
5437
+ {
5438
+ x1: xBack + A * 0.6,
5439
+ y1: 0,
5440
+ x2: xBack + A * 0.6,
5441
+ y2: yFoldBottom,
5442
+ label: fmt(C),
5443
+ orientation: "vertical",
5444
+ offset: -10
5445
+ },
5446
+ // Bottom section (B/2 + DIP)
5447
+ {
5448
+ x1: xBack + A * 0.6,
5449
+ y1: yFoldBottom,
5450
+ x2: xBack + A * 0.6,
5451
+ y2: yEnd,
5452
+ label: fmt(bottomSection),
5453
+ orientation: "vertical",
5454
+ offset: -10
5455
+ },
5456
+ // Length (A)
5457
+ {
5458
+ x1: xFront,
5459
+ y1: C * 0.65,
5460
+ x2: xSide1,
5461
+ y2: C * 0.65,
5462
+ label: fmt(A),
5463
+ orientation: "horizontal",
5464
+ offset: -20
5465
+ },
5466
+ // Width (B)
5467
+ {
5468
+ x1: xSide1,
5469
+ y1: C * 0.65,
5470
+ x2: xBack,
5471
+ y2: C * 0.65,
5472
+ label: fmt(B),
5473
+ orientation: "horizontal",
5474
+ offset: -20
5475
+ },
5476
+ // Glue Area (kulak)
5477
+ {
5478
+ x1: 0,
5479
+ y1: C * 0.65,
5480
+ x2: xFront,
5481
+ y2: C * 0.65,
5482
+ label: fmt(kulak),
5483
+ orientation: "horizontal",
5484
+ offset: -20
5485
+ }
5486
+ ];
5487
+ }
5488
+ var MODEL_ID9 = "BECF-B-12101";
5489
+ var UNIT_FACTOR9 = {
5490
+ mm: 1,
5491
+ cm: 0.1,
5492
+ in: 1 / 25.4
5493
+ };
5494
+ var PX_PER_MM9 = 96 / 25.4;
5495
+ function renderDimension9(dim, i, fs) {
5496
+ const { x1, y1, x2, y2, label, orientation, offset } = dim;
5497
+ const tick = 1.5;
5498
+ if (orientation === "horizontal") {
5499
+ const y = y1 + offset;
5500
+ const midX = (x1 + x2) / 2;
5501
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
5502
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y, x2, y2: y, stroke: "#000", strokeWidth: 0.2 }),
5503
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y - tick, x2: x1, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
5504
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x2, y1: y - tick, x2, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
5505
+ /* @__PURE__ */ jsxRuntime.jsx("text", { x: midX, y: y - 1.5, textAnchor: "middle", fontSize: fs, fontFamily: "sans-serif", fill: "#000", children: label })
5506
+ ] }, `dim-${i}`);
5507
+ }
5508
+ const x = x1 + offset;
5509
+ const midY = (y1 + y2) / 2;
5510
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
5511
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x, y1, x2: x, y2, stroke: "#000", strokeWidth: 0.2 }),
5512
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1, x2: x + tick, y2: y1, stroke: "#000", strokeWidth: 0.3 }),
5513
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1: y2, x2: x + tick, y2, stroke: "#000", strokeWidth: 0.3 }),
5514
+ /* @__PURE__ */ jsxRuntime.jsx("text", { x: x - 1.5, y: midY - 1, textAnchor: "middle", dominantBaseline: "central", fontSize: fs, fontFamily: "sans-serif", fill: "#000", transform: `rotate(-90, ${x - 1.5}, ${midY})`, children: label })
5515
+ ] }, `dim-${i}`);
5516
+ }
5517
+ var DIE_LINE_BECF_B_12101 = react.forwardRef(
5518
+ ({ attributes, unit = "mm", isShowDimensions = false, renderAs = "svg" }, ref) => {
5519
+ const theme = react.useMemo(() => getModelTheme(), []);
5520
+ const svgRef = react.useRef(null);
5521
+ const dieline = react.useMemo(() => generateBecfB12101(attributes), [attributes]);
5522
+ const dimensions = react.useMemo(() => generateDimensions9(attributes, unit), [attributes, unit]);
5523
+ const factor = UNIT_FACTOR9[unit] ?? 1;
5524
+ const serializeSvg = react.useCallback((showDimensions) => {
5525
+ const svg = svgRef.current;
5526
+ if (!svg) throw new Error("SVG not mounted");
5527
+ const clone = svg.cloneNode(true);
5528
+ if (!showDimensions) {
5529
+ clone.querySelector("#dimensions")?.remove();
5530
+ }
5531
+ return new XMLSerializer().serializeToString(clone);
5532
+ }, []);
5533
+ react.useImperativeHandle(ref, () => {
5534
+ const auto = getAutoCalcValues5(attributes);
5535
+ return {
5536
+ getAttributes: () => ({
5537
+ modelId: MODEL_ID9,
5538
+ overallWidth: dieline.viewBox.width * factor,
5539
+ overallHeight: dieline.viewBox.height * factor,
5540
+ length: attributes.length * factor,
5541
+ width: attributes.width * factor,
5542
+ height: attributes.height * factor,
5543
+ glueArea: auto.kulak * factor,
5544
+ kulak: auto.kulak * factor,
5545
+ dip: auto.dip * factor
5546
+ }),
5547
+ exportImage: async (options) => {
5548
+ const svgStr = serializeSvg(options.isShowDimension);
5549
+ const blob = new Blob([svgStr], { type: "image/svg+xml;charset=utf-8" });
5550
+ const url = URL.createObjectURL(blob);
5551
+ const img = new Image();
5552
+ await new Promise((resolve, reject) => {
5553
+ img.onload = () => resolve();
5554
+ img.onerror = reject;
5555
+ img.src = url;
5556
+ });
5557
+ const canvas = document.createElement("canvas");
5558
+ if (options.originalSize) {
5559
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM9);
5560
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM9);
5561
+ } else {
5562
+ canvas.width = 1920;
5563
+ canvas.height = 1080;
5564
+ }
5565
+ const ctx = canvas.getContext("2d");
5566
+ ctx.fillStyle = "#ffffff";
5567
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
5568
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
5569
+ URL.revokeObjectURL(url);
5570
+ return new Promise((resolve, reject) => {
5571
+ canvas.toBlob((b) => b ? resolve(b) : reject(new Error("Export failed")), "image/png");
5572
+ });
5573
+ },
5574
+ exportDimension: async () => {
5575
+ const dimData = generateDimensions9(attributes, unit);
5576
+ return exportDimensionPdf({ modelId: MODEL_ID9, dieline, dimensions: dimData, attributes, unit, factor, theme });
5577
+ }
5578
+ };
5579
+ }, [attributes, dieline, factor, unit, serializeSvg, theme]);
5580
+ const padding = isShowDimensions ? 15 : 0;
5581
+ const vbX = -padding;
5582
+ const vbY = -padding;
5583
+ const vbW = dieline.viewBox.width + padding * 2;
5584
+ const vbH = dieline.viewBox.height + padding * 2;
5585
+ const svgChildren = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5586
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "crease", children: dieline.crease.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorFoldLine, strokeWidth: 0.5, strokeDasharray: "2,1" }, `c-${i}`)) }),
5587
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "cut", children: dieline.cut.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorDieLine, strokeWidth: 0.5 }, `t-${i}`)) }),
5588
+ isShowDimensions && /* @__PURE__ */ jsxRuntime.jsx("g", { id: "dimensions", children: dimensions.map((d, i) => renderDimension9(d, i, getFontDimensionSize())) })
5589
+ ] });
5590
+ if (renderAs === "group") return /* @__PURE__ */ jsxRuntime.jsx("g", { children: svgChildren });
5591
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { ref: svgRef, xmlns: "http://www.w3.org/2000/svg", viewBox: `${vbX} ${vbY} ${vbW} ${vbH}`, preserveAspectRatio: "xMidYMid meet", style: { backgroundColor: theme.colorBackground }, children: svgChildren });
5592
+ }
5593
+ );
5594
+ var CANVAS_BECF_B_12101 = react.forwardRef(
5595
+ (props, ref) => {
5596
+ const dieLineRef = react.useRef(null);
5597
+ const canvasRef = react.useRef(null);
5598
+ const { attributes } = props;
5599
+ const theme = react.useMemo(() => getModelTheme(), []);
5600
+ const dieline = react.useMemo(() => generateBecfB12101(attributes), [attributes]);
5601
+ const stablePadding = 15;
5602
+ const viewBox = react.useMemo(() => ({ x: -stablePadding, y: -stablePadding, width: dieline.viewBox.width + stablePadding * 2, height: dieline.viewBox.height + stablePadding * 2 }), [dieline.viewBox.width, dieline.viewBox.height]);
5603
+ const serializeCanvasSvg = react.useCallback((showDimensions) => {
5604
+ const svg = canvasRef.current?.getSvgElement();
5605
+ if (!svg) throw new Error("SVG not mounted");
5606
+ const clone = svg.cloneNode(true);
5607
+ if (!showDimensions) {
5608
+ clone.querySelector("#dimensions")?.remove();
5609
+ }
5610
+ return new XMLSerializer().serializeToString(clone);
5611
+ }, []);
5612
+ react.useImperativeHandle(ref, () => ({
5613
+ getAttributes: () => dieLineRef.current.getAttributes(),
5614
+ exportImage: async (options) => {
5615
+ const svgStr = serializeCanvasSvg(options.isShowDimension);
5616
+ const blob = new Blob([svgStr], { type: "image/svg+xml;charset=utf-8" });
5617
+ const url = URL.createObjectURL(blob);
5618
+ const img = new Image();
5619
+ await new Promise((resolve, reject) => {
5620
+ img.onload = () => resolve();
5621
+ img.onerror = reject;
5622
+ img.src = url;
5623
+ });
5624
+ const canvas = document.createElement("canvas");
5625
+ if (options.originalSize) {
5626
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM9);
5627
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM9);
5628
+ } else {
5629
+ canvas.width = 1920;
5630
+ canvas.height = 1080;
5631
+ }
5632
+ const ctx = canvas.getContext("2d");
5633
+ ctx.fillStyle = "#ffffff";
5634
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
5635
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
5636
+ URL.revokeObjectURL(url);
5637
+ return new Promise((resolve, reject) => {
5638
+ canvas.toBlob((b) => b ? resolve(b) : reject(new Error("Export failed")), "image/png");
5639
+ });
5640
+ },
5641
+ exportDimension: () => dieLineRef.current.exportDimension(),
5642
+ resetView: () => canvasRef.current?.resetView(),
5643
+ fitView: () => canvasRef.current?.fitView()
5644
+ }), [serializeCanvasSvg, dieline.viewBox.width, dieline.viewBox.height]);
5645
+ return /* @__PURE__ */ jsxRuntime.jsx(BaseCanvas, { ref: canvasRef, viewBox, backgroundColor: theme.colorBackground, children: /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_B_12101, { ref: dieLineRef, ...props, renderAs: "group" }) });
5646
+ }
5647
+ );
5648
+ var MODEL_BECF_B_12101 = react.forwardRef(
5649
+ ({ mode = "DIE_LINE", ...props }, ref) => {
5650
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: (() => {
5651
+ switch (mode) {
5652
+ case "DIE_LINE":
5653
+ return /* @__PURE__ */ jsxRuntime.jsx(CANVAS_BECF_B_12101, { ref, ...props });
5654
+ case "3D":
5655
+ return null;
5656
+ case "AUTO_LAYOUT":
5657
+ return /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_B_12101, { ref, ...props });
5658
+ default:
5659
+ return null;
5660
+ }
5661
+ })() });
5662
+ }
5663
+ );
5664
+
5665
+ // src/components/dieline/bags-pillows/becf-b-12109/generate.ts
5666
+ var DIP6 = 13;
5667
+ var NOTCH_X3 = 3;
5668
+ var NOTCH_Y3 = 5;
5669
+ function calcKulak6(b) {
5670
+ if (b <= 13) return b - 1;
5671
+ if (b <= 99) return 13;
5672
+ if (b <= 249) return 20;
5673
+ if (b <= 499) return 25;
5674
+ return 30;
5675
+ }
5676
+ function getAutoCalcValues6(attr) {
5677
+ const { width: B, glueArea } = attr;
5678
+ const kulak = glueArea ?? calcKulak6(B);
5679
+ return { kulak, dip: DIP6 };
5680
+ }
5681
+ function line10(x1, y1, x2, y2) {
5682
+ return `M${x1} ${y1} L${x2} ${y2}`;
5683
+ }
5684
+ function generateBecfB12109(attr) {
5685
+ const { length: A, width: B, height: C, glueArea } = attr;
5686
+ const kulak = glueArea ?? calcKulak6(B);
5687
+ const xFront = kulak;
5688
+ const xSide1 = kulak + A;
5689
+ const xSide1Mid = kulak + A + B / 2;
5690
+ const xBack = kulak + A + B;
5691
+ const xSide2 = kulak + 2 * A + B;
5692
+ const xSide2Mid = kulak + 2 * A + B + B / 2;
5693
+ const xEnd = kulak + 2 * A + 2 * B - 2;
5694
+ const yFoldBottomStart = C - B / 2;
5695
+ const yFoldBottom = C;
5696
+ const yNotchStart = yFoldBottom + NOTCH_Y3;
5697
+ const yEnd = C + B / 2 + DIP6;
5698
+ const totalWidth = xEnd;
5699
+ const totalHeight = yEnd;
5700
+ const cut = [];
5701
+ const crease = [];
5702
+ cut.push(line10(0, 0, 0, yFoldBottom - kulak));
5703
+ cut.push(line10(0, 0, totalWidth, 0));
5704
+ cut.push(line10(totalWidth, 0, totalWidth, yFoldBottom));
5705
+ cut.push(line10(0, yFoldBottom - kulak, kulak, yFoldBottom));
5706
+ const boundaries = [xFront, xSide1, xBack, xSide2, xEnd];
5707
+ for (let i = 0; i < boundaries.length; i++) {
5708
+ const xb = boundaries[i];
5709
+ const isFirst = i === 0;
5710
+ const isLast = i === boundaries.length - 1;
5711
+ if (!isFirst) {
5712
+ cut.push(line10(xb - NOTCH_X3, yNotchStart, xb - NOTCH_X3, totalHeight));
5713
+ cut.push(line10(xb - NOTCH_X3, yNotchStart, xb, yFoldBottom));
5714
+ }
5715
+ if (!isLast) {
5716
+ cut.push(line10(xb + NOTCH_X3, yNotchStart, xb + NOTCH_X3, totalHeight));
5717
+ cut.push(line10(xb + NOTCH_X3, yNotchStart, xb, yFoldBottom));
5718
+ }
5719
+ }
5720
+ cut.push(line10(xFront + NOTCH_X3, totalHeight, xSide1 - NOTCH_X3, totalHeight));
5721
+ cut.push(line10(xSide1 + NOTCH_X3, totalHeight, xBack - NOTCH_X3, totalHeight));
5722
+ cut.push(line10(xBack + NOTCH_X3, totalHeight, xSide2 - NOTCH_X3, totalHeight));
5723
+ cut.push(line10(xSide2 + NOTCH_X3, totalHeight, xEnd - NOTCH_X3, totalHeight));
5724
+ crease.push(line10(0, yFoldBottomStart, totalWidth, yFoldBottomStart));
5725
+ crease.push(line10(kulak, yFoldBottom, xEnd, yFoldBottom));
5726
+ crease.push(line10(xFront, 0, xFront, yFoldBottom));
5727
+ crease.push(line10(xSide1, 0, xSide1, yFoldBottom));
5728
+ crease.push(line10(xBack, 0, xBack, yFoldBottom));
5729
+ crease.push(line10(xSide2, 0, xSide2, yFoldBottom));
5730
+ crease.push(line10(xSide1Mid, 0, xSide1Mid, totalHeight));
5731
+ crease.push(line10(xSide2Mid, 0, xSide2Mid, totalHeight));
5732
+ crease.push(line10(xBack, yFoldBottom, xSide1Mid, yFoldBottomStart));
5733
+ crease.push(line10(xSide1Mid, yFoldBottomStart, xSide1, yFoldBottom));
5734
+ crease.push(line10(xSide2Mid, yFoldBottomStart, xSide2, yFoldBottom));
5735
+ crease.push(line10(xSide2Mid, yFoldBottomStart, xEnd, C - 2));
5736
+ return { cut, crease, viewBox: { width: totalWidth, height: totalHeight } };
5737
+ }
5738
+ function generateOuterContour10(attr) {
5739
+ const { length: A, width: B, height: C, glueArea } = attr;
5740
+ const kulak = glueArea ?? calcKulak6(B);
5741
+ const xFront = kulak;
5742
+ const xSide1 = kulak + A;
5743
+ const xBack = kulak + A + B;
5744
+ const xSide2 = kulak + 2 * A + B;
5745
+ const xEnd = kulak + 2 * A + 2 * B - 2;
5746
+ const yFoldBottom = C;
5747
+ const yNotchStart = yFoldBottom + NOTCH_Y3;
5748
+ const yEnd = C + B / 2 + DIP6;
5749
+ return [
5750
+ { x: 0, y: 0 },
5751
+ { x: xEnd, y: 0 },
5752
+ { x: xEnd, y: yFoldBottom },
5753
+ { x: xEnd - NOTCH_X3, y: yNotchStart },
5754
+ { x: xEnd - NOTCH_X3, y: yEnd },
5755
+ { x: xSide2 + NOTCH_X3, y: yEnd },
5756
+ { x: xSide2 + NOTCH_X3, y: yNotchStart },
5757
+ { x: xSide2, y: yFoldBottom },
5758
+ { x: xSide2 - NOTCH_X3, y: yNotchStart },
5759
+ { x: xSide2 - NOTCH_X3, y: yEnd },
5760
+ { x: xBack + NOTCH_X3, y: yEnd },
5761
+ { x: xBack + NOTCH_X3, y: yNotchStart },
5762
+ { x: xBack, y: yFoldBottom },
5763
+ { x: xBack - NOTCH_X3, y: yNotchStart },
5764
+ { x: xBack - NOTCH_X3, y: yEnd },
5765
+ { x: xSide1 + NOTCH_X3, y: yEnd },
5766
+ { x: xSide1 + NOTCH_X3, y: yNotchStart },
5767
+ { x: xSide1, y: yFoldBottom },
5768
+ { x: xSide1 - NOTCH_X3, y: yNotchStart },
5769
+ { x: xSide1 - NOTCH_X3, y: yEnd },
5770
+ { x: xFront + NOTCH_X3, y: yEnd },
5771
+ { x: xFront + NOTCH_X3, y: yNotchStart },
5772
+ { x: xFront, y: yFoldBottom },
5773
+ { x: 0, y: yFoldBottom - kulak }
5774
+ ];
5775
+ }
5776
+ function offsetContour10(points, distance) {
5777
+ const n = points.length;
5778
+ const result = [];
5779
+ for (let i = 0; i < n; i++) {
5780
+ const prev = points[(i - 1 + n) % n];
5781
+ const curr = points[i];
5782
+ const next = points[(i + 1) % n];
5783
+ const e1x = curr.x - prev.x;
5784
+ const e1y = curr.y - prev.y;
5785
+ const e2x = next.x - curr.x;
5786
+ const e2y = next.y - curr.y;
5787
+ const len1 = Math.sqrt(e1x * e1x + e1y * e1y);
5788
+ const len2 = Math.sqrt(e2x * e2x + e2y * e2y);
5789
+ if (len1 === 0 || len2 === 0) {
5790
+ result.push(curr);
5791
+ continue;
5792
+ }
5793
+ const n1x = e1y / len1;
5794
+ const n1y = -e1x / len1;
5795
+ const n2x = e2y / len2;
5796
+ const n2y = -e2x / len2;
5797
+ const ax = n1x + n2x;
5798
+ const ay = n1y + n2y;
5799
+ const aLen = Math.sqrt(ax * ax + ay * ay);
5800
+ if (aLen < 1e-3) {
5801
+ result.push({ x: curr.x + n1x * distance, y: curr.y + n1y * distance });
5802
+ continue;
5803
+ }
5804
+ const nx = ax / aLen;
5805
+ const ny = ay / aLen;
5806
+ const dot = n1x * nx + n1y * ny;
5807
+ const d = distance / Math.max(dot, 0.1);
5808
+ result.push({ x: curr.x + nx * d, y: curr.y + ny * d });
5809
+ }
5810
+ return result;
5811
+ }
5812
+ function contourToPath10(points) {
5813
+ if (points.length === 0) return "";
5814
+ let d = `M${points[0].x} ${points[0].y}`;
5815
+ for (let i = 1; i < points.length; i++) {
5816
+ d += ` L${points[i].x} ${points[i].y}`;
5817
+ }
5818
+ d += " Z";
5819
+ return d;
5820
+ }
5821
+ function generateDimensions10(attr, unit) {
5822
+ const { length: A, width: B, height: C, glueArea } = attr;
5823
+ const kulak = glueArea ?? calcKulak6(B);
5824
+ const factor = unit === "cm" ? 0.1 : unit === "in" ? 1 / 25.4 : 1;
5825
+ const suffix = unit;
5826
+ const fmt = (v) => `${(v * factor).toFixed(2)} ${suffix}`;
5827
+ const xFront = kulak;
5828
+ const xSide1 = kulak + A;
5829
+ const xBack = kulak + A + B;
5830
+ const yFoldBottom = C;
5831
+ const yEnd = C + B / 2 + DIP6;
5832
+ const totalWidth = kulak + 2 * A + 2 * B - 2;
5833
+ const totalHeight = yEnd;
5834
+ const bottomSection = B / 2 + DIP6;
5835
+ return [
5836
+ {
5837
+ x1: 0,
5838
+ y1: 0,
5839
+ x2: totalWidth,
5840
+ y2: 0,
5841
+ label: `Overall Width : ${fmt(totalWidth)}`,
5842
+ orientation: "horizontal",
5843
+ offset: -12
5844
+ },
5845
+ {
5846
+ x1: 0,
5847
+ y1: 0,
5848
+ x2: 0,
5849
+ y2: totalHeight,
5850
+ label: `Overall Height : ${fmt(totalHeight)}`,
5851
+ orientation: "vertical",
5852
+ offset: -12
5853
+ },
5854
+ {
5855
+ x1: xBack + A * 0.6,
5856
+ y1: 0,
5857
+ x2: xBack + A * 0.6,
5858
+ y2: yFoldBottom,
5859
+ label: fmt(C),
5860
+ orientation: "vertical",
5861
+ offset: -10
5862
+ },
5863
+ {
5864
+ x1: xBack + A * 0.6,
5865
+ y1: yFoldBottom,
5866
+ x2: xBack + A * 0.6,
5867
+ y2: yEnd,
5868
+ label: fmt(bottomSection),
5869
+ orientation: "vertical",
5870
+ offset: -10
5871
+ },
5872
+ {
5873
+ x1: xFront,
5874
+ y1: C * 0.65,
5875
+ x2: xSide1,
5876
+ y2: C * 0.65,
5877
+ label: fmt(A),
5878
+ orientation: "horizontal",
5879
+ offset: -20
5880
+ },
5881
+ {
5882
+ x1: xSide1,
5883
+ y1: C * 0.65,
5884
+ x2: xBack,
5885
+ y2: C * 0.65,
5886
+ label: fmt(B),
5887
+ orientation: "horizontal",
5888
+ offset: -20
5889
+ },
5890
+ {
5891
+ x1: 0,
5892
+ y1: C * 0.65,
5893
+ x2: xFront,
5894
+ y2: C * 0.65,
5895
+ label: fmt(kulak),
5896
+ orientation: "horizontal",
5897
+ offset: -20
5898
+ }
5899
+ ];
5900
+ }
5901
+ var MODEL_ID10 = "BECF-B-12109";
5902
+ var UNIT_FACTOR10 = {
5903
+ mm: 1,
5904
+ cm: 0.1,
5905
+ in: 1 / 25.4
5906
+ };
5907
+ var PX_PER_MM10 = 96 / 25.4;
5908
+ function renderDimension10(dim, i, fs) {
5909
+ const { x1, y1, x2, y2, label, orientation, offset } = dim;
5910
+ const tick = 1.5;
5911
+ if (orientation === "horizontal") {
5912
+ const y = y1 + offset;
5913
+ const midX = (x1 + x2) / 2;
5914
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
5915
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y, x2, y2: y, stroke: "#000", strokeWidth: 0.2 }),
5916
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y - tick, x2: x1, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
5917
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x2, y1: y - tick, x2, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
5918
+ /* @__PURE__ */ jsxRuntime.jsx("text", { x: midX, y: y - 1.5, textAnchor: "middle", fontSize: fs, fontFamily: "sans-serif", fill: "#000", children: label })
5919
+ ] }, `dim-${i}`);
5920
+ }
5921
+ const x = x1 + offset;
5922
+ const midY = (y1 + y2) / 2;
5923
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
5924
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x, y1, x2: x, y2, stroke: "#000", strokeWidth: 0.2 }),
5925
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1, x2: x + tick, y2: y1, stroke: "#000", strokeWidth: 0.3 }),
5926
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1: y2, x2: x + tick, y2, stroke: "#000", strokeWidth: 0.3 }),
5927
+ /* @__PURE__ */ jsxRuntime.jsx("text", { x: x - 1.5, y: midY - 1, textAnchor: "middle", dominantBaseline: "central", fontSize: fs, fontFamily: "sans-serif", fill: "#000", transform: `rotate(-90, ${x - 1.5}, ${midY})`, children: label })
5928
+ ] }, `dim-${i}`);
5929
+ }
5930
+ var DIE_LINE_BECF_B_12109 = react.forwardRef(
5931
+ ({ attributes, unit = "mm", isShowDimensions = false, renderAs = "svg" }, ref) => {
5932
+ const theme = react.useMemo(() => getModelTheme(), []);
5933
+ const svgRef = react.useRef(null);
5934
+ const dieline = react.useMemo(() => generateBecfB12109(attributes), [attributes]);
5935
+ const dimensions = react.useMemo(() => generateDimensions10(attributes, unit), [attributes, unit]);
5936
+ const factor = UNIT_FACTOR10[unit] ?? 1;
5937
+ const serializeSvg = react.useCallback((showDimensions) => {
5938
+ const svg = svgRef.current;
5939
+ if (!svg) throw new Error("SVG not mounted");
5940
+ const clone = svg.cloneNode(true);
5941
+ if (!showDimensions) {
5942
+ clone.querySelector("#dimensions")?.remove();
5943
+ }
5944
+ return new XMLSerializer().serializeToString(clone);
5945
+ }, []);
5946
+ react.useImperativeHandle(ref, () => {
5947
+ const auto = getAutoCalcValues6(attributes);
5948
+ return {
5949
+ getAttributes: () => ({
5950
+ modelId: MODEL_ID10,
5951
+ overallWidth: dieline.viewBox.width * factor,
5952
+ overallHeight: dieline.viewBox.height * factor,
5953
+ length: attributes.length * factor,
5954
+ width: attributes.width * factor,
5955
+ height: attributes.height * factor,
5956
+ glueArea: auto.kulak * factor,
5957
+ kulak: auto.kulak * factor,
5958
+ dip: auto.dip * factor
5959
+ }),
5960
+ exportImage: async (options) => {
5961
+ const svgStr = serializeSvg(options.isShowDimension);
5962
+ const blob = new Blob([svgStr], { type: "image/svg+xml;charset=utf-8" });
5963
+ const url = URL.createObjectURL(blob);
5964
+ const img = new Image();
5965
+ await new Promise((resolve, reject) => {
5966
+ img.onload = () => resolve();
5967
+ img.onerror = reject;
5968
+ img.src = url;
5969
+ });
5970
+ const canvas = document.createElement("canvas");
5971
+ if (options.originalSize) {
5972
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM10);
5973
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM10);
5974
+ } else {
5975
+ canvas.width = 1920;
5976
+ canvas.height = 1080;
5977
+ }
5978
+ const ctx = canvas.getContext("2d");
5979
+ ctx.fillStyle = "#ffffff";
5980
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
5981
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
5982
+ URL.revokeObjectURL(url);
5983
+ return new Promise((resolve, reject) => {
5984
+ canvas.toBlob((b) => b ? resolve(b) : reject(new Error("Export failed")), "image/png");
5985
+ });
5986
+ },
5987
+ exportDimension: async () => {
5988
+ const dimData = generateDimensions10(attributes, unit);
5989
+ return exportDimensionPdf({ modelId: MODEL_ID10, dieline, dimensions: dimData, attributes, unit, factor, theme });
5990
+ }
5991
+ };
5992
+ }, [attributes, dieline, factor, unit, serializeSvg, theme]);
5993
+ const padding = isShowDimensions ? 15 : 0;
5994
+ const vbX = -padding;
5995
+ const vbY = -padding;
5996
+ const vbW = dieline.viewBox.width + padding * 2;
5997
+ const vbH = dieline.viewBox.height + padding * 2;
5998
+ const svgChildren = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
5999
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "crease", children: dieline.crease.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorFoldLine, strokeWidth: 0.5, strokeDasharray: "2,1" }, `c-${i}`)) }),
6000
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "cut", children: dieline.cut.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorDieLine, strokeWidth: 0.5 }, `t-${i}`)) }),
6001
+ isShowDimensions && /* @__PURE__ */ jsxRuntime.jsx("g", { id: "dimensions", children: dimensions.map((d, i) => renderDimension10(d, i, getFontDimensionSize())) })
6002
+ ] });
6003
+ if (renderAs === "group") return /* @__PURE__ */ jsxRuntime.jsx("g", { children: svgChildren });
6004
+ return /* @__PURE__ */ jsxRuntime.jsx("svg", { ref: svgRef, xmlns: "http://www.w3.org/2000/svg", viewBox: `${vbX} ${vbY} ${vbW} ${vbH}`, preserveAspectRatio: "xMidYMid meet", style: { backgroundColor: theme.colorBackground }, children: svgChildren });
6005
+ }
6006
+ );
6007
+ var CANVAS_BECF_B_12109 = react.forwardRef(
6008
+ (props, ref) => {
6009
+ const dieLineRef = react.useRef(null);
6010
+ const canvasRef = react.useRef(null);
6011
+ const { attributes } = props;
6012
+ const theme = react.useMemo(() => getModelTheme(), []);
6013
+ const dieline = react.useMemo(() => generateBecfB12109(attributes), [attributes]);
6014
+ const stablePadding = 15;
6015
+ const viewBox = react.useMemo(() => ({ x: -stablePadding, y: -stablePadding, width: dieline.viewBox.width + stablePadding * 2, height: dieline.viewBox.height + stablePadding * 2 }), [dieline.viewBox.width, dieline.viewBox.height]);
6016
+ const serializeCanvasSvg = react.useCallback((showDimensions) => {
6017
+ const svg = canvasRef.current?.getSvgElement();
6018
+ if (!svg) throw new Error("SVG not mounted");
6019
+ const clone = svg.cloneNode(true);
6020
+ if (!showDimensions) {
6021
+ clone.querySelector("#dimensions")?.remove();
6022
+ }
6023
+ return new XMLSerializer().serializeToString(clone);
6024
+ }, []);
6025
+ react.useImperativeHandle(ref, () => ({
6026
+ getAttributes: () => dieLineRef.current.getAttributes(),
6027
+ exportImage: async (options) => {
6028
+ const svgStr = serializeCanvasSvg(options.isShowDimension);
6029
+ const blob = new Blob([svgStr], { type: "image/svg+xml;charset=utf-8" });
6030
+ const url = URL.createObjectURL(blob);
6031
+ const img = new Image();
6032
+ await new Promise((resolve, reject) => {
6033
+ img.onload = () => resolve();
6034
+ img.onerror = reject;
6035
+ img.src = url;
6036
+ });
6037
+ const canvas = document.createElement("canvas");
6038
+ if (options.originalSize) {
6039
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM10);
6040
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM10);
6041
+ } else {
6042
+ canvas.width = 1920;
6043
+ canvas.height = 1080;
6044
+ }
6045
+ const ctx = canvas.getContext("2d");
6046
+ ctx.fillStyle = "#ffffff";
6047
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
6048
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
6049
+ URL.revokeObjectURL(url);
6050
+ return new Promise((resolve, reject) => {
6051
+ canvas.toBlob((b) => b ? resolve(b) : reject(new Error("Export failed")), "image/png");
6052
+ });
6053
+ },
6054
+ exportDimension: () => dieLineRef.current.exportDimension(),
6055
+ resetView: () => canvasRef.current?.resetView(),
6056
+ fitView: () => canvasRef.current?.fitView()
6057
+ }), [serializeCanvasSvg, dieline.viewBox.width, dieline.viewBox.height]);
6058
+ return /* @__PURE__ */ jsxRuntime.jsx(BaseCanvas, { ref: canvasRef, viewBox, backgroundColor: theme.colorBackground, children: /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_B_12109, { ref: dieLineRef, ...props, renderAs: "group" }) });
6059
+ }
6060
+ );
6061
+ var MODEL_BECF_B_12109 = react.forwardRef(
6062
+ ({ mode = "DIE_LINE", ...props }, ref) => {
6063
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: (() => {
6064
+ switch (mode) {
6065
+ case "DIE_LINE":
6066
+ return /* @__PURE__ */ jsxRuntime.jsx(CANVAS_BECF_B_12109, { ref, ...props });
6067
+ case "3D":
6068
+ return null;
6069
+ case "AUTO_LAYOUT":
6070
+ return /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_B_12109, { ref, ...props });
6071
+ default:
6072
+ return null;
6073
+ }
6074
+ })() });
6075
+ }
6076
+ );
6077
+
6078
+ // src/components/dieline/snap-lock-boxes/becf-10a0a/generate.ts
6079
+ var MT5 = 0.5;
6080
+ var ARC_R4 = 5;
6081
+ var SNAP_R = 3;
6082
+ var TAPER = Math.tan(15 * Math.PI / 180);
6083
+ var TAB_W = 8;
6084
+ var CORNER = 3;
6085
+ var NOTCH = 10;
6086
+ function calcKulak7(b) {
6087
+ if (b < 100) return 13;
6088
+ if (b < 250) return 15;
6089
+ if (b < 500) return 20;
6090
+ return 25;
6091
+ }
6092
+ function calcDil(a, b, c) {
6093
+ const base = Math.max(15, Math.min(30, (a + b + 50) / 20));
6094
+ return Math.max(9, Math.min(a / 2, b - 1, c / 2, base));
6095
+ }
6096
+ function calcDip(b) {
6097
+ if (b <= 22) return 9;
6098
+ if (b <= 28) return Math.floor((b - 4) / 2);
6099
+ if (b <= 77) return 12;
6100
+ if (b <= 120) return Math.floor(b / 6);
6101
+ if (b <= 167) return 20;
6102
+ if (b <= 199) return Math.floor(b / 8);
6103
+ if (b < 300) return 30;
6104
+ if (b < 400) return 35;
6105
+ return 40;
6106
+ }
6107
+ function generateBecf10a0a(attr) {
6108
+ const { length: A, width: B, height: C } = attr;
6109
+ const kulak = calcKulak7(B);
6110
+ const dil = calcDil(A, B, C);
6111
+ const dip = calcDip(B);
6112
+ const glueTaper = kulak * TAPER;
6113
+ const tuckH = B / 2 + ARC_R4;
6114
+ const xFront = kulak;
6115
+ const xSide1 = kulak + A;
6116
+ const xBack = kulak + A + B;
6117
+ const xSide2 = kulak + 2 * A + B;
6118
+ const xEnd = kulak + 2 * A + 2 * B - 0.5;
6119
+ const yTop = 0;
6120
+ const yTuckTop = dil - 1;
6121
+ const yLockCrease = dil;
6122
+ const yTuckFlapTop = B + dil - 1 - tuckH;
6123
+ const yFoldTop = B + dil - 1;
6124
+ const yFoldBottom = yFoldTop + C;
6125
+ const yFoldBottomB2 = yFoldBottom + B / 2;
6126
+ const ySideBottom = yFoldBottom + A / 4 + dip + SNAP_R;
6127
+ const yBottom = yFoldBottom + B / 2 + dip + SNAP_R;
6128
+ const totalWidth = xEnd;
6129
+ const totalHeight = yBottom;
6130
+ const cut = [];
6131
+ const crease = [];
6132
+ crease.push(
6133
+ line11(xFront, yFoldTop, xFront, yFoldBottom),
6134
+ line11(xSide1, yFoldTop, xSide1, yFoldBottom),
6135
+ line11(xBack, yFoldTop, xBack, yFoldBottom),
6136
+ line11(xSide2, yFoldTop, xSide2, yFoldBottom)
6137
+ );
6138
+ crease.push(
6139
+ line11(xFront, yFoldBottom, xSide1, yFoldBottom),
6140
+ line11(xSide1, yFoldBottom, xBack, yFoldBottom),
6141
+ line11(xBack, yFoldBottom, xSide2, yFoldBottom),
6142
+ line11(xSide2, yFoldBottom, xEnd, yFoldBottom)
6143
+ );
6144
+ crease.push(
6145
+ line11(xBack, yFoldTop, xSide1 + MT5, yFoldTop),
6146
+ // Side1 panel
6147
+ line11(xBack, yFoldTop - MT5, xSide2, yFoldTop - MT5),
6148
+ // Back panel (MT offset)
6149
+ line11(xSide2, yFoldTop, xEnd, yFoldTop)
6150
+ // Side2 panel
6151
+ );
6152
+ crease.push(
6153
+ line11(xBack + NOTCH, yLockCrease, xSide2 - NOTCH, yLockCrease)
6154
+ );
6155
+ cut.push(
6156
+ line11(xSide1, yFoldTop, xFront, yFoldTop),
6157
+ line11(xSide1, yFoldTop, xSide1 + MT5, yFoldTop)
6158
+ );
6159
+ cut.push(
6160
+ `M${xFront} ${yFoldBottom} L${0} ${yFoldBottom - glueTaper} L${0} ${yFoldTop + glueTaper} L${xFront} ${yFoldTop}`
6161
+ );
6162
+ cut.push(line11(xEnd, yFoldTop, xEnd, yFoldBottom));
6163
+ cut.push(...lockTab(xBack, xSide2, yTop, yTuckTop, yLockCrease, yFoldTop));
6164
+ cut.push(...side1TuckFlap(xSide1, xBack, yFoldTop, yTuckFlapTop, tuckH));
6165
+ cut.push(...side2TuckFlap(xSide2, xEnd, yFoldTop, yTuckFlapTop, tuckH));
6166
+ cut.push(...frontPanelBottom(xFront, xSide1, A, yFoldBottom, yFoldBottomB2, yBottom, dip));
6167
+ cut.push(...backPanelBottom(xBack, xSide2, A, yFoldBottom, yFoldBottomB2, yBottom, ySideBottom, dip));
6168
+ cut.push(...side1Bottom(xSide1, xBack, B, A, yFoldBottom, ySideBottom, dip));
6169
+ cut.push(...side2Bottom(xSide2, xEnd, B, A, yFoldBottom, ySideBottom, dip));
6170
+ return { cut, crease, viewBox: { width: totalWidth, height: totalHeight } };
6171
+ }
6172
+ function line11(x1, y1, x2, y2) {
6173
+ return `M${x1} ${y1} L${x2} ${y2}`;
6174
+ }
6175
+ function lockTab(xBack, xSide2, yTop, yTuckTop, yLockCrease, yFoldTop) {
6176
+ const paths = [];
6177
+ paths.push(line11(xBack, yFoldTop, xBack, yTuckTop));
6178
+ paths.push(line11(xSide2, yTuckTop, xSide2, yFoldTop));
6179
+ paths.push(line11(xBack, yTuckTop, xBack + NOTCH, yTuckTop));
6180
+ paths.push(line11(xSide2 - NOTCH, yTuckTop, xSide2, yTuckTop));
6181
+ paths.push(line11(xBack + NOTCH, yTuckTop, xBack + NOTCH, yLockCrease));
6182
+ paths.push(line11(xSide2 - NOTCH, yLockCrease, xSide2 - NOTCH, yTuckTop));
6183
+ paths.push(line11(xBack + MT5, yTuckTop, xBack + MT5, ARC_R4));
6184
+ paths.push(line11(xSide2 - MT5, yTuckTop, xSide2 - MT5, ARC_R4));
6185
+ paths.push(line11(xBack + MT5 + ARC_R4, yTop, xSide2 - MT5 - ARC_R4, yTop));
6186
+ paths.push(
6187
+ `M${xBack + MT5 + ARC_R4} ${yTop} A${ARC_R4} ${ARC_R4} 0 0 0 ${xBack + MT5} ${ARC_R4}`
6188
+ );
6189
+ paths.push(
6190
+ `M${xSide2 - MT5} ${ARC_R4} A${ARC_R4} ${ARC_R4} 0 0 0 ${xSide2 - MT5 - ARC_R4} ${yTop}`
6191
+ );
6192
+ return paths;
6193
+ }
6194
+ function side1TuckFlap(xSide1, xBack, yFoldTop, yTuckFlapTop, tuckH) {
6195
+ const slopeV = tuckH - TAB_W - CORNER;
6196
+ const slopeH = slopeV * TAPER;
6197
+ const leftTargetX = xSide1 + MT5 + CORNER + slopeH;
6198
+ const rightTargetX = xBack - ARC_R4;
6199
+ const leftPath = `M${xSide1 + MT5} ${yFoldTop} L${xSide1 + MT5} ${yFoldTop - TAB_W} L${xSide1 + MT5 + CORNER} ${yFoldTop - TAB_W - CORNER} L${leftTargetX} ${yTuckFlapTop}`;
6200
+ const topRight = `M${leftTargetX} ${yTuckFlapTop} L${rightTargetX} ${yTuckFlapTop} L${xBack - CORNER} ${yFoldTop - CORNER} L${xBack} ${yFoldTop}`;
6201
+ return [leftPath, topRight];
6202
+ }
6203
+ function side2TuckFlap(xSide2, xEnd, yFoldTop, yTuckFlapTop, tuckH) {
6204
+ const slopeV = tuckH - TAB_W - CORNER;
6205
+ const slopeH = slopeV * TAPER;
6206
+ const leftTargetX = xSide2 + ARC_R4;
6207
+ const rightTargetX = xEnd - CORNER - slopeH;
6208
+ const leftTop = `M${xSide2} ${yFoldTop} L${xSide2 + CORNER} ${yFoldTop - CORNER} L${leftTargetX} ${yTuckFlapTop} L${rightTargetX} ${yTuckFlapTop}`;
6209
+ const rightPath = `M${rightTargetX} ${yTuckFlapTop} L${xEnd - CORNER} ${yFoldTop - TAB_W - CORNER} L${xEnd} ${yFoldTop - TAB_W} L${xEnd} ${yFoldTop}`;
6210
+ return [leftTop, rightPath];
6211
+ }
6212
+ function frontPanelBottom(xFront, xSide1, A, yFoldBottom, yFoldBottomB2, yBottom, dip) {
6213
+ const paths = [];
6214
+ paths.push(line11(xFront, yFoldBottom, xFront, yBottom));
6215
+ paths.push(line11(xSide1, yBottom, xSide1, yFoldBottom));
6216
+ const notchHalfTop = A / 4 + MT5;
6217
+ const notchTaperH = (dip + SNAP_R) * TAPER;
6218
+ const center = xFront + A / 2;
6219
+ const nlt = center - notchHalfTop;
6220
+ const nrt = center + notchHalfTop;
6221
+ const nlb = nlt + notchTaperH;
6222
+ const nrb = nrt - notchTaperH;
6223
+ paths.push(line11(xFront, yBottom, nlb, yBottom));
6224
+ paths.push(line11(nlb, yBottom, nlt, yFoldBottomB2));
6225
+ paths.push(line11(nlt, yFoldBottomB2, nrt, yFoldBottomB2));
6226
+ paths.push(line11(nrt, yFoldBottomB2, nrb, yBottom));
6227
+ paths.push(line11(nrb, yBottom, xSide1, yBottom));
6228
+ return paths;
6229
+ }
6230
+ function backPanelBottom(xBack, xSide2, A, yFoldBottom, yFoldBottomB2, yBottom, ySideBottom, dip) {
6231
+ const paths = [];
6232
+ const diagH = A / 4;
6233
+ paths.push(line11(xBack, yFoldBottom, xBack, ySideBottom));
6234
+ paths.push(line11(xSide2, ySideBottom, xSide2, yFoldBottom));
6235
+ paths.push(line11(xBack, yFoldBottom, xBack + diagH, yFoldBottomB2));
6236
+ paths.push(line11(xSide2, yFoldBottom, xSide2 - diagH, yFoldBottomB2));
6237
+ paths.push(line11(xBack + diagH, yFoldBottomB2, xBack + diagH, yFoldBottomB2 + dip));
6238
+ paths.push(line11(xSide2 - diagH, yFoldBottomB2 + dip, xSide2 - diagH, yFoldBottomB2));
6239
+ paths.push(
6240
+ `M${xBack + diagH} ${yFoldBottomB2 + dip} A${SNAP_R} ${SNAP_R} 0 0 0 ${xBack + diagH + SNAP_R} ${yBottom}`
6241
+ );
6242
+ paths.push(
6243
+ `M${xSide2 - diagH - SNAP_R} ${yBottom} A${SNAP_R} ${SNAP_R} 0 0 0 ${xSide2 - diagH} ${yFoldBottomB2 + dip}`
6244
+ );
6245
+ paths.push(line11(xBack + diagH + SNAP_R, yBottom, xSide2 - diagH - SNAP_R, yBottom));
6246
+ return paths;
6247
+ }
6248
+ function side1Bottom(xSide1, xBack, B, A, yFoldBottom, ySideBottom, dip) {
6249
+ const paths = [];
6250
+ const diagEndX = xSide1 + B / 2;
6251
+ const diagEndY = yFoldBottom + A / 4;
6252
+ const taperV = dip + SNAP_R;
6253
+ const taperH = taperV * TAPER;
6254
+ paths.push(line11(xSide1, yFoldBottom, diagEndX, diagEndY));
6255
+ paths.push(line11(diagEndX, diagEndY, diagEndX - taperH, ySideBottom));
6256
+ paths.push(line11(diagEndX - taperH, ySideBottom, xBack, ySideBottom));
6257
+ return paths;
6258
+ }
6259
+ function side2Bottom(xSide2, xEnd, B, A, yFoldBottom, ySideBottom, dip) {
6260
+ const paths = [];
6261
+ const diagEndX = xSide2 + B / 2;
6262
+ const diagEndY = yFoldBottom + A / 4;
6263
+ const taperV = dip + SNAP_R;
6264
+ const taperH = taperV * TAPER;
6265
+ paths.push(line11(xEnd, yFoldBottom, diagEndX, diagEndY));
6266
+ paths.push(line11(diagEndX, diagEndY, diagEndX + taperH, ySideBottom));
6267
+ paths.push(line11(diagEndX + taperH, ySideBottom, xSide2, ySideBottom));
6268
+ return paths;
6269
+ }
6270
+ function generateDimensions11(attr, unit) {
6271
+ const { length: A, width: B, height: C } = attr;
6272
+ const kulak = calcKulak7(B);
6273
+ const dil = calcDil(A, B, C);
6274
+ const dip = calcDip(B);
6275
+ const xFront = kulak;
6276
+ const xSide1 = kulak + A;
6277
+ const xSide2 = kulak + 2 * A + B;
6278
+ const xEnd = kulak + 2 * A + 2 * B - 0.5;
6279
+ const yFoldTop = B + dil - 1;
6280
+ const yFoldBottom = yFoldTop + C;
6281
+ const yBottom = yFoldBottom + B / 2 + dip + SNAP_R;
6282
+ const totalWidth = xEnd;
6283
+ const totalHeight = yBottom;
6284
+ const factor = unit === "cm" ? 0.1 : unit === "in" ? 1 / 25.4 : 1;
6285
+ const suffix = unit;
6286
+ const fmt = (v) => `${(v * factor).toFixed(2)} ${suffix}`;
6287
+ return [
6288
+ {
6289
+ x1: 0,
6290
+ y1: 0,
6291
+ x2: 0,
6292
+ y2: totalHeight,
6293
+ label: `Overall Height : ${fmt(totalHeight)}`,
6294
+ orientation: "vertical",
6295
+ offset: -12
6296
+ },
6297
+ {
6298
+ x1: 0,
6299
+ y1: 0,
6300
+ x2: totalWidth,
6301
+ y2: 0,
6302
+ label: `Overall Width : ${fmt(totalWidth)}`,
6303
+ orientation: "horizontal",
6304
+ offset: -12
6305
+ },
6306
+ {
6307
+ x1: xSide2,
6308
+ y1: yFoldTop,
6309
+ x2: xSide2,
6310
+ y2: yFoldBottom,
6311
+ label: fmt(C),
6312
+ orientation: "vertical",
6313
+ offset: -14
6314
+ },
6315
+ {
6316
+ x1: xFront,
6317
+ y1: yFoldBottom,
6318
+ x2: xSide1,
6319
+ y2: yFoldBottom,
6320
+ label: fmt(A),
6321
+ orientation: "horizontal",
6322
+ offset: -20
6323
+ },
6324
+ {
6325
+ x1: xSide1,
6326
+ y1: yFoldBottom,
6327
+ x2: xSide1 + B,
6328
+ y2: yFoldBottom,
6329
+ label: fmt(B),
6330
+ orientation: "horizontal",
6331
+ offset: -20
6332
+ }
6333
+ ];
6334
+ }
6335
+ var MODEL_ID11 = "BECF-10A0A";
6336
+ var UNIT_FACTOR11 = {
6337
+ mm: 1,
6338
+ cm: 0.1,
6339
+ in: 1 / 25.4
6340
+ };
6341
+ var PX_PER_MM11 = 96 / 25.4;
6342
+ function renderDimension11(dim, i, fs) {
6343
+ const { x1, y1, x2, y2, label, orientation, offset } = dim;
6344
+ const tick = 1.5;
6345
+ if (orientation === "horizontal") {
6346
+ const y = y1 + offset;
6347
+ const midX = (x1 + x2) / 2;
6348
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
6349
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y, x2, y2: y, stroke: "#000", strokeWidth: 0.2 }),
6350
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1, y1: y - tick, x2: x1, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
6351
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x2, y1: y - tick, x2, y2: y + tick, stroke: "#000", strokeWidth: 0.3 }),
6352
+ /* @__PURE__ */ jsxRuntime.jsx(
6353
+ "text",
6354
+ {
6355
+ x: midX,
6356
+ y: y - 1.5,
6357
+ textAnchor: "middle",
6358
+ fontSize: fs,
6359
+ fontFamily: "sans-serif",
6360
+ fill: "#000",
6361
+ children: label
6362
+ }
6363
+ )
6364
+ ] }, `dim-${i}`);
6365
+ }
6366
+ const x = x1 + offset;
6367
+ const midY = (y1 + y2) / 2;
6368
+ return /* @__PURE__ */ jsxRuntime.jsxs("g", { children: [
6369
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x, y1, x2: x, y2, stroke: "#000", strokeWidth: 0.2 }),
6370
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1, x2: x + tick, y2: y1, stroke: "#000", strokeWidth: 0.3 }),
6371
+ /* @__PURE__ */ jsxRuntime.jsx("line", { x1: x - tick, y1: y2, x2: x + tick, y2, stroke: "#000", strokeWidth: 0.3 }),
6372
+ /* @__PURE__ */ jsxRuntime.jsx(
6373
+ "text",
6374
+ {
6375
+ x: x - 1.5,
6376
+ y: midY - 1,
6377
+ textAnchor: "middle",
6378
+ dominantBaseline: "central",
6379
+ fontSize: fs,
6380
+ fontFamily: "sans-serif",
6381
+ fill: "#000",
6382
+ transform: `rotate(-90, ${x - 1.5}, ${midY})`,
6383
+ children: label
6384
+ }
6385
+ )
6386
+ ] }, `dim-${i}`);
6387
+ }
6388
+ var DIE_LINE_BECF_10A0A = react.forwardRef(
6389
+ ({
6390
+ attributes,
6391
+ unit = "mm",
6392
+ isShowDimensions = false,
6393
+ renderAs = "svg"
6394
+ }, ref) => {
6395
+ const theme = react.useMemo(
6396
+ () => getModelTheme(),
6397
+ []
6398
+ );
6399
+ const svgRef = react.useRef(null);
6400
+ const dieline = react.useMemo(() => generateBecf10a0a(attributes), [attributes]);
6401
+ const dimensions = react.useMemo(
6402
+ () => generateDimensions11(attributes, unit),
6403
+ [attributes, unit]
6404
+ );
6405
+ const factor = UNIT_FACTOR11[unit] ?? 1;
6406
+ const serializeSvg = react.useCallback(
6407
+ (showDimensions) => {
6408
+ const svg = svgRef.current;
6409
+ if (!svg) throw new Error("SVG not mounted");
6410
+ const clone = svg.cloneNode(true);
6411
+ if (!showDimensions) {
6412
+ const dimGroup = clone.querySelector("#dimensions");
6413
+ dimGroup?.remove();
6414
+ }
6415
+ return new XMLSerializer().serializeToString(clone);
6416
+ },
6417
+ []
6418
+ );
6419
+ react.useImperativeHandle(
6420
+ ref,
6421
+ () => {
6422
+ const { length: A, width: B, height: C } = attributes;
6423
+ const kulak = calcKulak7(B);
6424
+ const dil = calcDil(A, B, C);
6425
+ const dip = calcDip(B);
6426
+ const flap = Math.min(A / 2, B / 2 + dil / 2 - 0.5);
6427
+ return {
6428
+ getAttributes: () => ({
6429
+ modelId: MODEL_ID11,
6430
+ overallWidth: dieline.viewBox.width * factor,
6431
+ overallHeight: dieline.viewBox.height * factor,
6432
+ length: A * factor,
6433
+ width: B * factor,
6434
+ height: C * factor,
6435
+ kulak: kulak * factor,
6436
+ dil: dil * factor,
6437
+ flap: flap * factor,
6438
+ dip: dip * factor
6439
+ }),
6440
+ exportImage: async (options) => {
6441
+ const svgStr = serializeSvg(options.isShowDimension);
6442
+ const blob = new Blob([svgStr], {
6443
+ type: "image/svg+xml;charset=utf-8"
6444
+ });
6445
+ const url = URL.createObjectURL(blob);
6446
+ const img = new Image();
6447
+ await new Promise((resolve, reject) => {
6448
+ img.onload = () => resolve();
6449
+ img.onerror = reject;
6450
+ img.src = url;
6451
+ });
6452
+ const canvas = document.createElement("canvas");
6453
+ if (options.originalSize) {
6454
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM11);
6455
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM11);
6456
+ } else {
6457
+ canvas.width = 1920;
6458
+ canvas.height = 1080;
6459
+ }
6460
+ const ctx = canvas.getContext("2d");
6461
+ ctx.fillStyle = "#ffffff";
6462
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
6463
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
6464
+ URL.revokeObjectURL(url);
6465
+ return new Promise((resolve, reject) => {
6466
+ canvas.toBlob(
6467
+ (b) => b ? resolve(b) : reject(new Error("Export failed")),
6468
+ "image/png"
6469
+ );
6470
+ });
6471
+ },
6472
+ exportDimension: async () => {
6473
+ const dimData = generateDimensions11(attributes, unit);
6474
+ return exportDimensionPdf({
6475
+ modelId: MODEL_ID11,
6476
+ dieline,
6477
+ dimensions: dimData,
6478
+ attributes,
6479
+ unit,
6480
+ factor,
6481
+ theme
6482
+ });
6483
+ }
6484
+ };
6485
+ },
6486
+ [attributes, dieline, factor, unit, serializeSvg, theme]
6487
+ );
6488
+ const padding = isShowDimensions ? 15 : 0;
6489
+ const vbX = -padding;
6490
+ const vbY = -padding;
6491
+ const vbW = dieline.viewBox.width + padding * 2;
6492
+ const vbH = dieline.viewBox.height + padding * 2;
6493
+ const svgChildren = /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
6494
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "crease", children: dieline.crease.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorFoldLine, strokeWidth: 0.5, strokeDasharray: "2,1" }, `c-${i}`)) }),
6495
+ /* @__PURE__ */ jsxRuntime.jsx("g", { id: "cut", children: dieline.cut.map((d, i) => /* @__PURE__ */ jsxRuntime.jsx("path", { d, fill: "none", stroke: theme.colorDieLine, strokeWidth: 0.5 }, `t-${i}`)) }),
6496
+ isShowDimensions && /* @__PURE__ */ jsxRuntime.jsx("g", { id: "dimensions", children: dimensions.map((d, i) => renderDimension11(d, i, getFontDimensionSize())) })
6497
+ ] });
6498
+ if (renderAs === "group") {
6499
+ return /* @__PURE__ */ jsxRuntime.jsx("g", { children: svgChildren });
6500
+ }
6501
+ return /* @__PURE__ */ jsxRuntime.jsx(
6502
+ "svg",
6503
+ {
6504
+ ref: svgRef,
6505
+ xmlns: "http://www.w3.org/2000/svg",
6506
+ viewBox: `${vbX} ${vbY} ${vbW} ${vbH}`,
6507
+ preserveAspectRatio: "xMidYMid meet",
6508
+ style: { backgroundColor: theme.colorBackground },
6509
+ children: svgChildren
6510
+ }
6511
+ );
6512
+ }
6513
+ );
6514
+ var CANVAS_BECF_10A0A = react.forwardRef(
6515
+ (props, ref) => {
6516
+ const dieLineRef = react.useRef(null);
6517
+ const canvasRef = react.useRef(null);
6518
+ const { attributes } = props;
6519
+ const theme = react.useMemo(
6520
+ () => getModelTheme(),
6521
+ []
6522
+ );
6523
+ const dieline = react.useMemo(() => generateBecf10a0a(attributes), [attributes]);
6524
+ const stablePadding = 15;
6525
+ const viewBox = react.useMemo(
6526
+ () => ({
6527
+ x: -stablePadding,
6528
+ y: -stablePadding,
6529
+ width: dieline.viewBox.width + stablePadding * 2,
6530
+ height: dieline.viewBox.height + stablePadding * 2
6531
+ }),
6532
+ [dieline.viewBox.width, dieline.viewBox.height]
6533
+ );
6534
+ const serializeCanvasSvg = react.useCallback((showDimensions) => {
6535
+ const svg = canvasRef.current?.getSvgElement();
6536
+ if (!svg) throw new Error("SVG not mounted");
6537
+ const clone = svg.cloneNode(true);
6538
+ if (!showDimensions) {
6539
+ const dimGroup = clone.querySelector("#dimensions");
6540
+ dimGroup?.remove();
6541
+ }
6542
+ return new XMLSerializer().serializeToString(clone);
6543
+ }, []);
6544
+ react.useImperativeHandle(ref, () => ({
6545
+ getAttributes: () => dieLineRef.current.getAttributes(),
6546
+ exportImage: async (options) => {
6547
+ const svgStr = serializeCanvasSvg(options.isShowDimension);
6548
+ const blob = new Blob([svgStr], { type: "image/svg+xml;charset=utf-8" });
6549
+ const url = URL.createObjectURL(blob);
6550
+ const img = new Image();
6551
+ await new Promise((resolve, reject) => {
6552
+ img.onload = () => resolve();
6553
+ img.onerror = reject;
6554
+ img.src = url;
6555
+ });
6556
+ const canvas = document.createElement("canvas");
6557
+ if (options.originalSize) {
6558
+ canvas.width = Math.round(dieline.viewBox.width * PX_PER_MM11);
6559
+ canvas.height = Math.round(dieline.viewBox.height * PX_PER_MM11);
6560
+ } else {
6561
+ canvas.width = 1920;
6562
+ canvas.height = 1080;
6563
+ }
6564
+ const ctx = canvas.getContext("2d");
6565
+ ctx.fillStyle = "#ffffff";
6566
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
6567
+ ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
6568
+ URL.revokeObjectURL(url);
6569
+ return new Promise((resolve, reject) => {
6570
+ canvas.toBlob(
6571
+ (b) => b ? resolve(b) : reject(new Error("Export failed")),
6572
+ "image/png"
6573
+ );
6574
+ });
6575
+ },
6576
+ exportDimension: () => dieLineRef.current.exportDimension(),
6577
+ resetView: () => canvasRef.current?.resetView(),
6578
+ fitView: () => canvasRef.current?.fitView()
6579
+ }), [serializeCanvasSvg, dieline.viewBox.width, dieline.viewBox.height]);
6580
+ return /* @__PURE__ */ jsxRuntime.jsx(
6581
+ BaseCanvas,
6582
+ {
6583
+ ref: canvasRef,
6584
+ viewBox,
6585
+ backgroundColor: theme.colorBackground,
6586
+ children: /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_10A0A, { ref: dieLineRef, ...props, renderAs: "group" })
6587
+ }
6588
+ );
6589
+ }
6590
+ );
6591
+ var MODEL_BECF_10A0A = react.forwardRef(
6592
+ ({ mode = "DIE_LINE", ...props }, ref) => {
6593
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: (() => {
6594
+ switch (mode) {
6595
+ case "DIE_LINE":
6596
+ return /* @__PURE__ */ jsxRuntime.jsx(CANVAS_BECF_10A0A, { ref, ...props });
6597
+ case "3D":
6598
+ return null;
6599
+ case "AUTO_LAYOUT":
6600
+ return /* @__PURE__ */ jsxRuntime.jsx(DIE_LINE_BECF_10A0A, { ref, ...props });
6601
+ default:
6602
+ return null;
6603
+ }
6604
+ })() });
6605
+ }
6606
+ );
6607
+
6608
+ // src/utils/autoLayout/rasterize.ts
6609
+ function rasterizePolygon(points, resolution) {
6610
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
6611
+ for (const p of points) {
6612
+ if (p.x < minX) minX = p.x;
6613
+ if (p.y < minY) minY = p.y;
6614
+ if (p.x > maxX) maxX = p.x;
6615
+ if (p.y > maxY) maxY = p.y;
6616
+ }
6617
+ const offsetX = Math.floor(minX / resolution);
6618
+ const offsetY = Math.floor(minY / resolution);
6619
+ const w = Math.ceil((maxX - offsetX * resolution) / resolution) + 1;
6620
+ const h = Math.ceil((maxY - offsetY * resolution) / resolution) + 1;
6621
+ const data = new Uint8Array(w * h);
6622
+ for (let gy = 0; gy < h; gy++) {
6623
+ const worldY = (offsetY + gy) * resolution + resolution / 2;
6624
+ const crossings = [];
6625
+ for (let i = 0, j = points.length - 1; i < points.length; j = i++) {
6626
+ const yi = points[i].y, yj = points[j].y;
6627
+ if (yi <= worldY && yj > worldY || yj <= worldY && yi > worldY) {
6628
+ const t = (worldY - yi) / (yj - yi);
6629
+ crossings.push(points[i].x + t * (points[j].x - points[i].x));
6630
+ }
6631
+ }
6632
+ crossings.sort((a, b) => a - b);
6633
+ for (let c = 0; c < crossings.length - 1; c += 2) {
6634
+ const startGx = Math.max(0, Math.floor((crossings[c] - offsetX * resolution) / resolution));
6635
+ const endGx = Math.min(w - 1, Math.ceil((crossings[c + 1] - offsetX * resolution) / resolution));
6636
+ for (let gx = startGx; gx <= endGx; gx++) {
6637
+ data[gy * w + gx] = 1;
6638
+ }
6639
+ }
6640
+ }
6641
+ return { data, width: w, height: h, offsetX, offsetY };
6642
+ }
6643
+ function canPlace(paperGrid, paperW, paperH, piece, px, py) {
6644
+ for (let y = 0; y < piece.height; y++) {
6645
+ const paperY = py + y;
6646
+ if (paperY < 0 || paperY >= paperH) {
6647
+ for (let x = 0; x < piece.width; x++) {
6648
+ if (piece.data[y * piece.width + x]) return false;
6649
+ }
6650
+ continue;
6651
+ }
6652
+ for (let x = 0; x < piece.width; x++) {
6653
+ if (!piece.data[y * piece.width + x]) continue;
6654
+ const paperX = px + x;
6655
+ if (paperX < 0 || paperX >= paperW) return false;
6656
+ if (paperGrid[paperY * paperW + paperX]) return false;
6657
+ }
6658
+ }
6659
+ return true;
6660
+ }
6661
+ function placePiece(paperGrid, paperW, piece, px, py) {
6662
+ for (let y = 0; y < piece.height; y++) {
6663
+ for (let x = 0; x < piece.width; x++) {
6664
+ if (piece.data[y * piece.width + x]) {
6665
+ paperGrid[(py + y) * paperW + (px + x)] = 1;
6666
+ }
6667
+ }
6668
+ }
6669
+ }
6670
+
6671
+ // src/utils/autoLayout/calculate/shared.ts
6672
+ var RESOLUTION = 1;
6673
+ function resolveGripperSide(paperWidth, paperHeight) {
6674
+ if (paperWidth >= paperHeight) return "bottom";
6675
+ return "left";
6676
+ }
6677
+ function computeUsableBounds(paperWidth, paperHeight, gripperSide, spacing, griper, colorbarDepth) {
6678
+ switch (gripperSide) {
6679
+ case "bottom":
6680
+ return {
6681
+ top: colorbarDepth + spacing,
6682
+ bottom: paperHeight - griper,
6683
+ left: spacing,
6684
+ right: paperWidth - spacing
6685
+ };
6686
+ case "top":
6687
+ return {
6688
+ top: griper,
6689
+ bottom: paperHeight - colorbarDepth - spacing,
6690
+ left: spacing,
6691
+ right: paperWidth - spacing
6692
+ };
6693
+ case "left":
6694
+ return {
6695
+ top: spacing,
6696
+ bottom: paperHeight - spacing,
6697
+ left: griper,
6698
+ right: paperWidth - colorbarDepth - spacing
6699
+ };
6700
+ case "right":
6701
+ return {
6702
+ top: spacing,
6703
+ bottom: paperHeight - spacing,
6704
+ left: colorbarDepth + spacing,
6705
+ right: paperWidth - griper
6706
+ };
6707
+ }
6708
+ }
6709
+ function normalizePoints(points, degrees) {
6710
+ const rad = degrees * Math.PI / 180;
6711
+ const cos = Math.cos(rad);
6712
+ const sin = Math.sin(rad);
6713
+ const rotated = points.map((p) => ({
6714
+ x: p.x * cos - p.y * sin,
6715
+ y: p.x * sin + p.y * cos
6716
+ }));
6717
+ let minX = Infinity, minY = Infinity;
6718
+ for (const p of rotated) {
6719
+ if (p.x < minX) minX = p.x;
6720
+ if (p.y < minY) minY = p.y;
6721
+ }
6722
+ return rotated.map((p) => ({ x: p.x - minX, y: p.y - minY }));
6723
+ }
6724
+ function computeDielineBBOffset(offsetContourPoints, dielineW, dielineH, degrees) {
6725
+ const rad = degrees * Math.PI / 180;
6726
+ const cos = Math.cos(rad);
6727
+ const sin = Math.sin(rad);
6728
+ let ocMinX = Infinity, ocMinY = Infinity;
6729
+ for (const p of offsetContourPoints) {
6730
+ const rx = p.x * cos - p.y * sin;
6731
+ const ry = p.x * sin + p.y * cos;
6732
+ if (rx < ocMinX) ocMinX = rx;
6733
+ if (ry < ocMinY) ocMinY = ry;
6734
+ }
6735
+ const corners = [[0, 0], [dielineW, 0], [0, dielineH], [dielineW, dielineH]];
6736
+ let dlMinX = Infinity, dlMinY = Infinity;
6737
+ for (const [cx, cy] of corners) {
6738
+ const rx = cx * cos - cy * sin;
6739
+ const ry = cx * sin + cy * cos;
6740
+ if (rx < dlMinX) dlMinX = rx;
6741
+ if (ry < dlMinY) dlMinY = ry;
6742
+ }
6743
+ return { dx: dlMinX - ocMinX, dy: dlMinY - ocMinY };
6744
+ }
6745
+ function computeLayoutForPaperDefault(contourPoints, dielineW, dielineH, paperWidth, paperHeight, bounds) {
6746
+ const usableLeft = Math.ceil(bounds.left / RESOLUTION);
6747
+ const usableTop = Math.ceil(bounds.top / RESOLUTION);
6748
+ const usableRight = Math.floor(bounds.right / RESOLUTION);
6749
+ const usableBottom = Math.floor(bounds.bottom / RESOLUTION);
6750
+ const paperW = Math.floor(paperWidth / RESOLUTION);
6751
+ const paperH = Math.floor(paperHeight / RESOLUTION);
6752
+ let bestCandidate = { rotation: 0, placements: [], producedPerSheet: 0 };
6753
+ let bestGridPositions = [];
6754
+ let bestBitmapW = 0;
6755
+ let bestBitmapH = 0;
6756
+ for (const deg of [0, 90, 180, 270]) {
6757
+ const rotatedContour = normalizePoints(contourPoints, deg);
6758
+ const pieceBitmap = rasterizePolygon(rotatedContour, RESOLUTION);
6759
+ const bbOffset = computeDielineBBOffset(contourPoints, dielineW, dielineH, deg);
6760
+ const paperGrid = new Uint8Array(paperW * paperH);
6761
+ const placements = [];
6762
+ const gridPositions = [];
6763
+ for (let py = usableTop; py <= usableBottom - pieceBitmap.height; py++) {
6764
+ for (let px = usableLeft; px <= usableRight - pieceBitmap.width; px++) {
6765
+ if (canPlace(paperGrid, paperW, paperH, pieceBitmap, px, py)) {
6766
+ placePiece(paperGrid, paperW, pieceBitmap, px, py);
6767
+ gridPositions.push({ px, py });
6768
+ placements.push({
6769
+ x: px * RESOLUTION + bbOffset.dx,
6770
+ y: py * RESOLUTION + bbOffset.dy,
6771
+ rotation: deg
6772
+ });
6773
+ }
6774
+ }
6775
+ }
6776
+ if (placements.length > bestCandidate.producedPerSheet) {
6777
+ bestCandidate = { rotation: deg, placements, producedPerSheet: placements.length };
6778
+ bestGridPositions = gridPositions;
6779
+ bestBitmapW = pieceBitmap.width;
6780
+ bestBitmapH = pieceBitmap.height;
6781
+ }
6782
+ }
6783
+ if (bestCandidate.placements.length > 0) {
6784
+ let gridMinX = Infinity;
6785
+ let gridMinY = Infinity;
6786
+ let gridMaxX = -Infinity;
6787
+ let gridMaxY = -Infinity;
6788
+ for (const { px, py } of bestGridPositions) {
6789
+ if (px < gridMinX) gridMinX = px;
6790
+ if (py < gridMinY) gridMinY = py;
6791
+ if (px + bestBitmapW > gridMaxX) gridMaxX = px + bestBitmapW;
6792
+ if (py + bestBitmapH > gridMaxY) gridMaxY = py + bestBitmapH;
6793
+ }
4376
6794
  const groupW = gridMaxX - gridMinX;
4377
6795
  const groupH = gridMaxY - gridMinY;
4378
6796
  const usableW = usableRight - usableLeft;
@@ -4384,52 +6802,615 @@ function computeLayoutForPaperDefault(contourPoints, dielineW, dielineH, paperWi
4384
6802
  p.y += offsetY;
4385
6803
  }
4386
6804
  }
4387
- return bestCandidate;
6805
+ return bestCandidate;
6806
+ }
6807
+
6808
+ // src/utils/autoLayout/calculate/tuck-end-boxes/becf-1010a/index.ts
6809
+ var SAMPLE_STEP = 0.1;
6810
+ function buildProfile(points) {
6811
+ let maxX = 0, maxY = 0;
6812
+ for (const p of points) {
6813
+ if (p.x > maxX) maxX = p.x;
6814
+ if (p.y > maxY) maxY = p.y;
6815
+ }
6816
+ const width = maxX, height = maxY;
6817
+ const nY = Math.ceil(height / SAMPLE_STEP) + 1;
6818
+ const nX = Math.ceil(width / SAMPLE_STEP) + 1;
6819
+ const rightX = new Float64Array(nY).fill(-Infinity);
6820
+ const leftX = new Float64Array(nY).fill(Infinity);
6821
+ const bottomY = new Float64Array(nX).fill(-Infinity);
6822
+ const topY = new Float64Array(nX).fill(Infinity);
6823
+ const nPts = points.length;
6824
+ for (let iy = 0; iy < nY; iy++) {
6825
+ const y = iy * SAMPLE_STEP;
6826
+ for (let j = 0, k = nPts - 1; j < nPts; k = j++) {
6827
+ const yj = points[j].y, yk = points[k].y;
6828
+ if (yj <= y && yk > y || yk <= y && yj > y) {
6829
+ const t = (y - yj) / (yk - yj);
6830
+ const x = points[j].x + t * (points[k].x - points[j].x);
6831
+ if (x > rightX[iy]) rightX[iy] = x;
6832
+ if (x < leftX[iy]) leftX[iy] = x;
6833
+ }
6834
+ }
6835
+ }
6836
+ for (let ix = 0; ix < nX; ix++) {
6837
+ const x = ix * SAMPLE_STEP;
6838
+ for (let j = 0, k = nPts - 1; j < nPts; k = j++) {
6839
+ const xj = points[j].x, xk = points[k].x;
6840
+ if (xj <= x && xk > x || xk <= x && xj > x) {
6841
+ const t = (x - xj) / (xk - xj);
6842
+ const y = points[j].y + t * (points[k].y - points[j].y);
6843
+ if (y > bottomY[ix]) bottomY[ix] = y;
6844
+ if (y < topY[ix]) topY[ix] = y;
6845
+ }
6846
+ }
6847
+ }
6848
+ return { width, height, nY, nX, rightX, leftX, bottomY, topY };
6849
+ }
6850
+ function prepareRotation(contourPoints, dielineW, dielineH, deg) {
6851
+ const rotated = normalizePoints(contourPoints, deg);
6852
+ return {
6853
+ profile: buildProfile(rotated),
6854
+ bbOffset: computeDielineBBOffset(contourPoints, dielineW, dielineH, deg),
6855
+ deg
6856
+ };
6857
+ }
6858
+ function findMinStepX(a, b, dyMm) {
6859
+ const dySamples = Math.round(dyMm / SAMPLE_STEP);
6860
+ let maxOverlap = -Infinity;
6861
+ for (let ia = 0; ia < a.nY; ia++) {
6862
+ const ib = ia - dySamples;
6863
+ if (ib < 0 || ib >= b.nY) continue;
6864
+ if (a.rightX[ia] === -Infinity || b.leftX[ib] === Infinity) continue;
6865
+ const overlap = a.rightX[ia] - b.leftX[ib];
6866
+ if (overlap > maxOverlap) maxOverlap = overlap;
6867
+ }
6868
+ return maxOverlap <= -Infinity ? 0 : maxOverlap;
6869
+ }
6870
+ function findMinStepY(a, b, dxMm) {
6871
+ const dxSamples = Math.round(dxMm / SAMPLE_STEP);
6872
+ let maxOverlap = -Infinity;
6873
+ for (let ia = 0; ia < a.nX; ia++) {
6874
+ const ib = ia - dxSamples;
6875
+ if (ib < 0 || ib >= b.nX) continue;
6876
+ if (a.bottomY[ia] === -Infinity || b.topY[ib] === Infinity) continue;
6877
+ const overlap = a.bottomY[ia] - b.topY[ib];
6878
+ if (overlap > maxOverlap) maxOverlap = overlap;
6879
+ }
6880
+ return maxOverlap <= -Infinity ? 0 : maxOverlap;
6881
+ }
6882
+ function findMinStepY_multi(profA, stepX_A, profB, offsetX) {
6883
+ const reach = Math.max(profA.width, profB.width);
6884
+ let maxStep = 0;
6885
+ const nMin = Math.floor((offsetX - reach) / stepX_A);
6886
+ const nMax = Math.ceil((offsetX + reach) / stepX_A);
6887
+ for (let n = nMin; n <= nMax; n++) {
6888
+ const s = findMinStepY(profA, profB, offsetX - n * stepX_A);
6889
+ if (s > maxStep) maxStep = s;
6890
+ }
6891
+ return maxStep;
6892
+ }
6893
+ function emptyResult() {
6894
+ return { placements: [], count: 0, minX: 0, minY: 0, maxX: 0, maxY: 0 };
6895
+ }
6896
+ function singleRotGrid(rd, bounds) {
6897
+ const p = rd.profile;
6898
+ const stepX = findMinStepX(p, p, 0);
6899
+ const stepY = findMinStepY(p, p, 0);
6900
+ if (stepX <= 0 || stepY <= 0) return emptyResult();
6901
+ const cols = Math.max(0, Math.floor((bounds.right - bounds.left - p.width) / stepX) + 1);
6902
+ const rows = Math.max(0, Math.floor((bounds.bottom - bounds.top - p.height) / stepY) + 1);
6903
+ if (cols === 0 || rows === 0) return emptyResult();
6904
+ const placements = [];
6905
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
6906
+ for (let r = 0; r < rows; r++) {
6907
+ for (let c = 0; c < cols; c++) {
6908
+ const ox = bounds.left + c * stepX;
6909
+ const oy = bounds.top + r * stepY;
6910
+ placements.push({ x: ox + rd.bbOffset.dx, y: oy + rd.bbOffset.dy, rotation: rd.deg });
6911
+ if (ox < minX) minX = ox;
6912
+ if (oy < minY) minY = oy;
6913
+ if (ox + p.width > maxX) maxX = ox + p.width;
6914
+ if (oy + p.height > maxY) maxY = oy + p.height;
6915
+ }
6916
+ }
6917
+ return { placements, count: placements.length, minX, minY, maxX, maxY };
6918
+ }
6919
+ function dualRotGrid(rdA, rdB, offsetX, bounds) {
6920
+ const pA = rdA.profile, pB = rdB.profile;
6921
+ const stepX_A = findMinStepX(pA, pA, 0);
6922
+ const stepX_B = findMinStepX(pB, pB, 0);
6923
+ if (stepX_A <= 0 || stepX_B <= 0) return emptyResult();
6924
+ let stepY_AB = findMinStepY_multi(pA, stepX_A, pB, offsetX);
6925
+ let stepY_BA = findMinStepY_multi(pB, stepX_B, pA, -offsetX);
6926
+ if (stepY_AB + stepY_BA <= 0) return emptyResult();
6927
+ const minAA = findMinStepY_multi(pA, stepX_A, pA, 0);
6928
+ const minBB = findMinStepY_multi(pB, stepX_B, pB, 0);
6929
+ const cycle = stepY_AB + stepY_BA;
6930
+ const neededCycle = Math.max(cycle, minAA, minBB);
6931
+ if (neededCycle > cycle) {
6932
+ const scale = neededCycle / cycle;
6933
+ stepY_AB *= scale;
6934
+ stepY_BA *= scale;
6935
+ }
6936
+ const placements = [];
6937
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
6938
+ let oy = bounds.top;
6939
+ let isRowA = true;
6940
+ while (true) {
6941
+ const rd = isRowA ? rdA : rdB;
6942
+ const p = rd.profile;
6943
+ const stepX = isRowA ? stepX_A : stepX_B;
6944
+ if (oy + p.height > bounds.bottom) break;
6945
+ let sx = isRowA ? bounds.left : bounds.left + offsetX;
6946
+ if (sx < bounds.left) sx += stepX * Math.ceil((bounds.left - sx) / stepX);
6947
+ for (let ox = sx; ox + p.width <= bounds.right; ox += stepX) {
6948
+ placements.push({ x: ox + rd.bbOffset.dx, y: oy + rd.bbOffset.dy, rotation: rd.deg });
6949
+ if (ox < minX) minX = ox;
6950
+ if (oy < minY) minY = oy;
6951
+ if (ox + p.width > maxX) maxX = ox + p.width;
6952
+ if (oy + p.height > maxY) maxY = oy + p.height;
6953
+ }
6954
+ oy += isRowA ? stepY_AB : stepY_BA;
6955
+ isRowA = !isRowA;
6956
+ }
6957
+ if (placements.length === 0) return emptyResult();
6958
+ return { placements, count: placements.length, minX, minY, maxX, maxY };
6959
+ }
6960
+ function centerLayout(result, bounds) {
6961
+ if (result.count === 0) return;
6962
+ const offX = (bounds.right - bounds.left - (result.maxX - result.minX)) / 2 - (result.minX - bounds.left);
6963
+ const offY = (bounds.bottom - bounds.top - (result.maxY - result.minY)) / 2 - (result.minY - bounds.top);
6964
+ for (const p of result.placements) {
6965
+ p.x += offX;
6966
+ p.y += offY;
6967
+ }
6968
+ }
6969
+ function computeLayoutForPaper(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
6970
+ const rots = [0, 90, 180, 270];
6971
+ const rd = /* @__PURE__ */ new Map();
6972
+ for (const deg of rots) {
6973
+ rd.set(deg, prepareRotation(contourPoints, dielineW, dielineH, deg));
6974
+ }
6975
+ const results = [];
6976
+ for (const deg of rots) {
6977
+ results.push(singleRotGrid(rd.get(deg), bounds));
6978
+ }
6979
+ const pairs = [
6980
+ [0, 180],
6981
+ [90, 270],
6982
+ [0, 90],
6983
+ [0, 270],
6984
+ [90, 180],
6985
+ [180, 270]
6986
+ ];
6987
+ for (const [a, b] of pairs) {
6988
+ const rdA = rd.get(a), rdB = rd.get(b);
6989
+ const stepA = findMinStepX(rdA.profile, rdA.profile, 0);
6990
+ if (stepA <= 0) continue;
6991
+ for (let off = 0; off < stepA; off += 1) {
6992
+ results.push(dualRotGrid(rdA, rdB, off, bounds));
6993
+ results.push(dualRotGrid(rdB, rdA, off, bounds));
6994
+ }
6995
+ }
6996
+ let best = results[0];
6997
+ for (const r of results) {
6998
+ if (r.count > best.count) best = r;
6999
+ }
7000
+ centerLayout(best, bounds);
7001
+ return {
7002
+ rotation: best.placements[0]?.rotation ?? 0,
7003
+ placements: best.placements,
7004
+ producedPerSheet: best.count
7005
+ };
7006
+ }
7007
+
7008
+ // src/utils/autoLayout/calculate/tuck-end-boxes/becf-1030a/index.ts
7009
+ function prepareRotation2(contourPoints, dielineW, dielineH, deg) {
7010
+ const rotated = normalizePoints(contourPoints, deg);
7011
+ return {
7012
+ profile: buildProfile(rotated),
7013
+ bbOffset: computeDielineBBOffset(contourPoints, dielineW, dielineH, deg),
7014
+ deg
7015
+ };
7016
+ }
7017
+ function findPairRowStepY(pA, pB, gapAB, pairStepX) {
7018
+ const reach = Math.max(pA.width, pB.width) + Math.abs(gapAB);
7019
+ const nMin = Math.floor(-reach / pairStepX) - 1;
7020
+ const nMax = Math.ceil(reach / pairStepX) + 1;
7021
+ let maxStep = 0;
7022
+ for (let n = nMin; n <= nMax; n++) {
7023
+ const dx = n * pairStepX;
7024
+ const s1 = findMinStepY(pA, pA, dx);
7025
+ if (s1 > maxStep) maxStep = s1;
7026
+ const s2 = findMinStepY(pA, pB, dx + gapAB);
7027
+ if (s2 > maxStep) maxStep = s2;
7028
+ const s3 = findMinStepY(pB, pA, dx - gapAB);
7029
+ if (s3 > maxStep) maxStep = s3;
7030
+ const s4 = findMinStepY(pB, pB, dx);
7031
+ if (s4 > maxStep) maxStep = s4;
7032
+ }
7033
+ return maxStep;
7034
+ }
7035
+ function pairGrid(rdA, rdB, bounds) {
7036
+ const pA = rdA.profile, pB = rdB.profile;
7037
+ const gapAB = findMinStepX(pA, pB, 0);
7038
+ if (gapAB <= 0) return emptyResult();
7039
+ const pairW = gapAB + pB.width;
7040
+ const pairH = Math.max(pA.height, pB.height);
7041
+ const pairStepX = Math.max(
7042
+ gapAB + findMinStepX(pB, pA, 0),
7043
+ findMinStepX(pA, pA, 0),
7044
+ findMinStepX(pB, pB, 0)
7045
+ );
7046
+ const pairStepY = findPairRowStepY(pA, pB, gapAB, pairStepX);
7047
+ if (pairStepX <= 0 || pairStepY <= 0) return emptyResult();
7048
+ const usableW = bounds.right - bounds.left;
7049
+ const usableH = bounds.bottom - bounds.top;
7050
+ const pairCols = Math.max(0, Math.floor((usableW - pairW) / pairStepX) + 1);
7051
+ const pairRows = Math.max(0, Math.floor((usableH - pairH) / pairStepY) + 1);
7052
+ if (pairCols === 0 || pairRows === 0) return emptyResult();
7053
+ const placements = [];
7054
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
7055
+ for (let r = 0; r < pairRows; r++) {
7056
+ for (let c = 0; c < pairCols; c++) {
7057
+ const baseX = bounds.left + c * pairStepX;
7058
+ const baseY = bounds.top + r * pairStepY;
7059
+ const oxA = baseX;
7060
+ const oyA = baseY;
7061
+ placements.push({ x: oxA + rdA.bbOffset.dx, y: oyA + rdA.bbOffset.dy, rotation: rdA.deg });
7062
+ if (oxA < minX) minX = oxA;
7063
+ if (oyA < minY) minY = oyA;
7064
+ if (oxA + pA.width > maxX) maxX = oxA + pA.width;
7065
+ if (oyA + pA.height > maxY) maxY = oyA + pA.height;
7066
+ const oxB = baseX + gapAB;
7067
+ const oyB = baseY;
7068
+ placements.push({ x: oxB + rdB.bbOffset.dx, y: oyB + rdB.bbOffset.dy, rotation: rdB.deg });
7069
+ if (oxB < minX) minX = oxB;
7070
+ if (oyB < minY) minY = oyB;
7071
+ if (oxB + pB.width > maxX) maxX = oxB + pB.width;
7072
+ if (oyB + pB.height > maxY) maxY = oyB + pB.height;
7073
+ }
7074
+ }
7075
+ const pairsRightEdge = bounds.left + (pairCols - 1) * pairStepX + pairW;
7076
+ const pairsBottomEdge = bounds.top + (pairRows - 1) * pairStepY + pairH;
7077
+ const gapRight = bounds.right - pairsRightEdge;
7078
+ const gapBottom = bounds.bottom - pairsBottomEdge;
7079
+ const extraRotations = [rdA, rdB];
7080
+ for (const rdExtra of extraRotations) {
7081
+ const pe = rdExtra.profile;
7082
+ if (pe.width <= gapRight) {
7083
+ for (let r = 0; r < pairRows; r++) {
7084
+ const ox = pairsRightEdge;
7085
+ const oy = bounds.top + r * pairStepY;
7086
+ if (ox + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7087
+ placements.push({ x: ox + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7088
+ if (ox + pe.width > maxX) maxX = ox + pe.width;
7089
+ }
7090
+ }
7091
+ break;
7092
+ }
7093
+ }
7094
+ for (const rdExtra of extraRotations) {
7095
+ const pe = rdExtra.profile;
7096
+ if (pe.height <= gapBottom) {
7097
+ for (let c = 0; c < pairCols; c++) {
7098
+ const oxA = bounds.left + c * pairStepX;
7099
+ const oy = pairsBottomEdge;
7100
+ if (oxA + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7101
+ placements.push({ x: oxA + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7102
+ if (oy + pe.height > maxY) maxY = oy + pe.height;
7103
+ }
7104
+ }
7105
+ break;
7106
+ }
7107
+ }
7108
+ return { placements, count: placements.length, minX, minY, maxX, maxY };
7109
+ }
7110
+ function computeLayoutForPaper2(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
7111
+ const rots = [0, 90, 180, 270];
7112
+ const rd = /* @__PURE__ */ new Map();
7113
+ for (const deg of rots) {
7114
+ rd.set(deg, prepareRotation2(contourPoints, dielineW, dielineH, deg));
7115
+ }
7116
+ const results = [];
7117
+ for (const deg of rots) {
7118
+ results.push(singleRotGrid(rd.get(deg), bounds));
7119
+ }
7120
+ const allPairs = [
7121
+ [0, 180],
7122
+ [90, 270],
7123
+ [0, 90],
7124
+ [0, 270],
7125
+ [90, 180],
7126
+ [180, 270]
7127
+ ];
7128
+ for (const [a, b] of allPairs) {
7129
+ const rdA = rd.get(a), rdB = rd.get(b);
7130
+ const stepA = findMinStepX(rdA.profile, rdA.profile, 0);
7131
+ if (stepA <= 0) continue;
7132
+ for (let off = 0; off < stepA; off += 1) {
7133
+ results.push(dualRotGrid(rdA, rdB, off, bounds));
7134
+ results.push(dualRotGrid(rdB, rdA, off, bounds));
7135
+ }
7136
+ }
7137
+ for (const [a, b] of allPairs) {
7138
+ results.push(pairGrid(rd.get(a), rd.get(b), bounds));
7139
+ results.push(pairGrid(rd.get(b), rd.get(a), bounds));
7140
+ }
7141
+ const singleResults = [];
7142
+ const multiResults = [];
7143
+ for (const r of results) {
7144
+ if (r.count === 0) continue;
7145
+ const rotations = new Set(r.placements.map((p) => p.rotation));
7146
+ if (rotations.size > 1) {
7147
+ multiResults.push(r);
7148
+ } else {
7149
+ singleResults.push(r);
7150
+ }
7151
+ }
7152
+ function pickBest(arr) {
7153
+ let b = arr[0] ?? emptyResult();
7154
+ let bArea = (b.maxX - b.minX) * (b.maxY - b.minY);
7155
+ for (const r of arr) {
7156
+ const area = (r.maxX - r.minX) * (r.maxY - r.minY);
7157
+ if (r.count > b.count || r.count === b.count && area < bArea) {
7158
+ b = r;
7159
+ bArea = area;
7160
+ }
7161
+ }
7162
+ return b;
7163
+ }
7164
+ const bestSingle = pickBest(singleResults);
7165
+ const bestMulti = pickBest(multiResults);
7166
+ const best = bestMulti.count >= bestSingle.count && bestMulti.count > 0 ? bestMulti : bestSingle;
7167
+ centerLayout(best, bounds);
7168
+ return {
7169
+ rotation: best.placements[0]?.rotation ?? 0,
7170
+ placements: best.placements,
7171
+ producedPerSheet: best.count
7172
+ };
4388
7173
  }
4389
7174
 
4390
- // src/utils/autoLayout/calculate/tuck-end-boxes/becf-1010a/index.ts
4391
- var SAMPLE_STEP = 0.1;
4392
- function buildProfile(points) {
4393
- let maxX = 0, maxY = 0;
4394
- for (const p of points) {
4395
- if (p.x > maxX) maxX = p.x;
4396
- if (p.y > maxY) maxY = p.y;
7175
+ // src/utils/autoLayout/calculate/tuck-end-boxes/becf-1040a/index.ts
7176
+ function prepareRotation3(contourPoints, dielineW, dielineH, deg) {
7177
+ const rotated = normalizePoints(contourPoints, deg);
7178
+ return {
7179
+ profile: buildProfile(rotated),
7180
+ bbOffset: computeDielineBBOffset(contourPoints, dielineW, dielineH, deg),
7181
+ deg
7182
+ };
7183
+ }
7184
+ function findPairRowStepY2(pA, pB, gapAB, pairStepX) {
7185
+ const reach = Math.max(pA.width, pB.width) + Math.abs(gapAB);
7186
+ const nMin = Math.floor(-reach / pairStepX) - 1;
7187
+ const nMax = Math.ceil(reach / pairStepX) + 1;
7188
+ let maxStep = 0;
7189
+ for (let n = nMin; n <= nMax; n++) {
7190
+ const dx = n * pairStepX;
7191
+ const s1 = findMinStepY(pA, pA, dx);
7192
+ if (s1 > maxStep) maxStep = s1;
7193
+ const s2 = findMinStepY(pA, pB, dx + gapAB);
7194
+ if (s2 > maxStep) maxStep = s2;
7195
+ const s3 = findMinStepY(pB, pA, dx - gapAB);
7196
+ if (s3 > maxStep) maxStep = s3;
7197
+ const s4 = findMinStepY(pB, pB, dx);
7198
+ if (s4 > maxStep) maxStep = s4;
4397
7199
  }
4398
- const width = maxX, height = maxY;
4399
- const nY = Math.ceil(height / SAMPLE_STEP) + 1;
4400
- const nX = Math.ceil(width / SAMPLE_STEP) + 1;
4401
- const rightX = new Float64Array(nY).fill(-Infinity);
4402
- const leftX = new Float64Array(nY).fill(Infinity);
4403
- const bottomY = new Float64Array(nX).fill(-Infinity);
4404
- const topY = new Float64Array(nX).fill(Infinity);
4405
- const nPts = points.length;
4406
- for (let iy = 0; iy < nY; iy++) {
4407
- const y = iy * SAMPLE_STEP;
4408
- for (let j = 0, k = nPts - 1; j < nPts; k = j++) {
4409
- const yj = points[j].y, yk = points[k].y;
4410
- if (yj <= y && yk > y || yk <= y && yj > y) {
4411
- const t = (y - yj) / (yk - yj);
4412
- const x = points[j].x + t * (points[k].x - points[j].x);
4413
- if (x > rightX[iy]) rightX[iy] = x;
4414
- if (x < leftX[iy]) leftX[iy] = x;
7200
+ return maxStep;
7201
+ }
7202
+ function pairGrid2(rdA, rdB, bounds) {
7203
+ const pA = rdA.profile, pB = rdB.profile;
7204
+ const gapAB = findMinStepX(pA, pB, 0);
7205
+ if (gapAB <= 0) return emptyResult();
7206
+ const pairW = gapAB + pB.width;
7207
+ const pairH = Math.max(pA.height, pB.height);
7208
+ const pairStepX = Math.max(
7209
+ gapAB + findMinStepX(pB, pA, 0),
7210
+ findMinStepX(pA, pA, 0),
7211
+ findMinStepX(pB, pB, 0)
7212
+ );
7213
+ if (pairStepX <= 0) return emptyResult();
7214
+ const pairStepY = findPairRowStepY2(pA, pB, gapAB, pairStepX);
7215
+ if (pairStepY <= 0) return emptyResult();
7216
+ const usableW = bounds.right - bounds.left;
7217
+ const usableH = bounds.bottom - bounds.top;
7218
+ const pairCols = Math.max(0, Math.floor((usableW - pairW) / pairStepX) + 1);
7219
+ const pairRows = Math.max(0, Math.floor((usableH - pairH) / pairStepY) + 1);
7220
+ if (pairCols === 0 || pairRows === 0) return emptyResult();
7221
+ const placements = [];
7222
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
7223
+ for (let r = 0; r < pairRows; r++) {
7224
+ for (let c = 0; c < pairCols; c++) {
7225
+ const baseX = bounds.left + c * pairStepX;
7226
+ const baseY = bounds.top + r * pairStepY;
7227
+ placements.push({ x: baseX + rdA.bbOffset.dx, y: baseY + rdA.bbOffset.dy, rotation: rdA.deg });
7228
+ if (baseX < minX) minX = baseX;
7229
+ if (baseY < minY) minY = baseY;
7230
+ if (baseX + pA.width > maxX) maxX = baseX + pA.width;
7231
+ if (baseY + pA.height > maxY) maxY = baseY + pA.height;
7232
+ const bx = baseX + gapAB;
7233
+ placements.push({ x: bx + rdB.bbOffset.dx, y: baseY + rdB.bbOffset.dy, rotation: rdB.deg });
7234
+ if (bx < minX) minX = bx;
7235
+ if (bx + pB.width > maxX) maxX = bx + pB.width;
7236
+ if (baseY + pB.height > maxY) maxY = baseY + pB.height;
7237
+ }
7238
+ }
7239
+ const pairsRightEdge = bounds.left + (pairCols - 1) * pairStepX + pairW;
7240
+ const gapRight = bounds.right - pairsRightEdge;
7241
+ for (const rdExtra of [rdA, rdB]) {
7242
+ const pe = rdExtra.profile;
7243
+ if (pe.width > gapRight) continue;
7244
+ const dxFromB = pairsRightEdge - (bounds.left + (pairCols - 1) * pairStepX + gapAB);
7245
+ const dxFromA = pairsRightEdge - bounds.left - (pairCols - 1) * pairStepX;
7246
+ const extraStepY = Math.max(
7247
+ findMinStepY(pA, pe, dxFromA),
7248
+ findMinStepY(pB, pe, dxFromB),
7249
+ findMinStepY(pe, pe, 0)
7250
+ );
7251
+ if (extraStepY <= 0) continue;
7252
+ const effectiveStepY = Math.max(pairStepY, extraStepY);
7253
+ const extraRows = Math.max(0, Math.floor((usableH - pe.height) / effectiveStepY) + 1);
7254
+ for (let r = 0; r < extraRows; r++) {
7255
+ const ox = pairsRightEdge;
7256
+ const oy = bounds.top + r * effectiveStepY;
7257
+ if (ox + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7258
+ placements.push({ x: ox + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7259
+ if (ox + pe.width > maxX) maxX = ox + pe.width;
7260
+ if (oy + pe.height > maxY) maxY = oy + pe.height;
4415
7261
  }
4416
7262
  }
7263
+ break;
4417
7264
  }
4418
- for (let ix = 0; ix < nX; ix++) {
4419
- const x = ix * SAMPLE_STEP;
4420
- for (let j = 0, k = nPts - 1; j < nPts; k = j++) {
4421
- const xj = points[j].x, xk = points[k].x;
4422
- if (xj <= x && xk > x || xk <= x && xj > x) {
4423
- const t = (x - xj) / (xk - xj);
4424
- const y = points[j].y + t * (points[k].y - points[j].y);
4425
- if (y > bottomY[ix]) bottomY[ix] = y;
4426
- if (y < topY[ix]) topY[ix] = y;
7265
+ const pairsBottomEdge = bounds.top + (pairRows - 1) * pairStepY + pairH;
7266
+ const gapBottom = bounds.bottom - pairsBottomEdge;
7267
+ for (const rdExtra of [rdA, rdB]) {
7268
+ const pe = rdExtra.profile;
7269
+ if (pe.height > gapBottom) continue;
7270
+ const extraStepX = findMinStepX(pe, pe, 0);
7271
+ if (extraStepX <= 0) continue;
7272
+ const dyFromPairRow = pairsBottomEdge - (bounds.top + (pairRows - 1) * pairStepY);
7273
+ const stepFromA = findMinStepY(pA, pe, 0);
7274
+ const stepFromB = findMinStepY(pB, pe, gapAB);
7275
+ if (dyFromPairRow < stepFromA || dyFromPairRow < stepFromB) continue;
7276
+ const extraCols = Math.max(0, Math.floor((usableW - pe.width) / extraStepX) + 1);
7277
+ for (let c = 0; c < extraCols; c++) {
7278
+ const ox = bounds.left + c * extraStepX;
7279
+ const oy = pairsBottomEdge;
7280
+ if (ox + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7281
+ placements.push({ x: ox + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7282
+ if (ox + pe.width > maxX) maxX = ox + pe.width;
7283
+ if (oy + pe.height > maxY) maxY = oy + pe.height;
7284
+ }
7285
+ }
7286
+ break;
7287
+ }
7288
+ return { placements, count: placements.length, minX, minY, maxX, maxY };
7289
+ }
7290
+ function verticalPairGrid(rdA, rdB, bounds) {
7291
+ const pA = rdA.profile, pB = rdB.profile;
7292
+ const gapAB_Y = findMinStepY(pA, pB, 0);
7293
+ if (gapAB_Y <= 0) return emptyResult();
7294
+ const vpairH = gapAB_Y + pB.height;
7295
+ const vpairW = Math.max(pA.width, pB.width);
7296
+ const stepXAA = findMinStepX(pA, pA, 0);
7297
+ const stepXAB = findMinStepX(pA, pB, -gapAB_Y);
7298
+ const stepXBA = findMinStepX(pB, pA, gapAB_Y);
7299
+ const stepXBB = findMinStepX(pB, pB, 0);
7300
+ const vpairStepX = Math.max(stepXAA, stepXAB, stepXBA, stepXBB);
7301
+ if (vpairStepX <= 0) return emptyResult();
7302
+ let vpairStepY = 0;
7303
+ {
7304
+ const reach = Math.max(pA.width, pB.width);
7305
+ const nMin = Math.floor(-reach / vpairStepX) - 1;
7306
+ const nMax = Math.ceil(reach / vpairStepX) + 1;
7307
+ for (let n = nMin; n <= nMax; n++) {
7308
+ const dx = n * vpairStepX;
7309
+ const sAA = findMinStepY(pA, pA, dx);
7310
+ if (sAA > vpairStepY) vpairStepY = sAA;
7311
+ const sAB = findMinStepY(pA, pB, dx) - gapAB_Y;
7312
+ if (sAB > vpairStepY) vpairStepY = sAB;
7313
+ const sBA = findMinStepY(pB, pA, dx) + gapAB_Y;
7314
+ if (sBA > vpairStepY) vpairStepY = sBA;
7315
+ const sBB = findMinStepY(pB, pB, dx);
7316
+ if (sBB > vpairStepY) vpairStepY = sBB;
7317
+ }
7318
+ }
7319
+ if (vpairStepY <= 0) return emptyResult();
7320
+ const usableW = bounds.right - bounds.left;
7321
+ const usableH = bounds.bottom - bounds.top;
7322
+ const cols = Math.max(0, Math.floor((usableW - vpairW) / vpairStepX) + 1);
7323
+ const rows = Math.max(0, Math.floor((usableH - vpairH) / vpairStepY) + 1);
7324
+ if (cols === 0 || rows === 0) return emptyResult();
7325
+ const placements = [];
7326
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
7327
+ for (let r = 0; r < rows; r++) {
7328
+ for (let c = 0; c < cols; c++) {
7329
+ const baseX = bounds.left + c * vpairStepX;
7330
+ const baseY = bounds.top + r * vpairStepY;
7331
+ placements.push({ x: baseX + rdA.bbOffset.dx, y: baseY + rdA.bbOffset.dy, rotation: rdA.deg });
7332
+ if (baseX < minX) minX = baseX;
7333
+ if (baseY < minY) minY = baseY;
7334
+ if (baseX + pA.width > maxX) maxX = baseX + pA.width;
7335
+ if (baseY + pA.height > maxY) maxY = baseY + pA.height;
7336
+ const by = baseY + gapAB_Y;
7337
+ placements.push({ x: baseX + rdB.bbOffset.dx, y: by + rdB.bbOffset.dy, rotation: rdB.deg });
7338
+ if (by + pB.height > maxY) maxY = by + pB.height;
7339
+ }
7340
+ }
7341
+ return { placements, count: placements.length, minX, minY, maxX, maxY };
7342
+ }
7343
+ function computeLayoutForPaper3(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
7344
+ const rots = [0, 90, 180, 270];
7345
+ const rd = /* @__PURE__ */ new Map();
7346
+ for (const deg of rots) {
7347
+ rd.set(deg, prepareRotation3(contourPoints, dielineW, dielineH, deg));
7348
+ }
7349
+ const results = [];
7350
+ for (const deg of rots) {
7351
+ results.push(singleRotGrid(rd.get(deg), bounds));
7352
+ }
7353
+ const allPairs = [
7354
+ [0, 180],
7355
+ [90, 270],
7356
+ [0, 90],
7357
+ [0, 270],
7358
+ [90, 180],
7359
+ [180, 270]
7360
+ ];
7361
+ for (const [a, b] of allPairs) {
7362
+ const rdA = rd.get(a), rdB = rd.get(b);
7363
+ const stepA = findMinStepX(rdA.profile, rdA.profile, 0);
7364
+ if (stepA <= 0) continue;
7365
+ for (let off = 0; off < stepA; off += 1) {
7366
+ results.push(dualRotGrid(rdA, rdB, off, bounds));
7367
+ results.push(dualRotGrid(rdB, rdA, off, bounds));
7368
+ }
7369
+ }
7370
+ for (const [a, b] of allPairs) {
7371
+ results.push(pairGrid2(rd.get(a), rd.get(b), bounds));
7372
+ results.push(pairGrid2(rd.get(b), rd.get(a), bounds));
7373
+ }
7374
+ for (const [a, b] of allPairs) {
7375
+ results.push(verticalPairGrid(rd.get(a), rd.get(b), bounds));
7376
+ results.push(verticalPairGrid(rd.get(b), rd.get(a), bounds));
7377
+ }
7378
+ const singleResults = [];
7379
+ const multiResults = [];
7380
+ for (const r of results) {
7381
+ if (r.count === 0) continue;
7382
+ const rotations = new Set(r.placements.map((p) => p.rotation));
7383
+ if (rotations.size > 1) {
7384
+ multiResults.push(r);
7385
+ } else {
7386
+ singleResults.push(r);
7387
+ }
7388
+ }
7389
+ function pickBest(arr) {
7390
+ let b = arr[0] ?? emptyResult();
7391
+ let bArea = (b.maxX - b.minX) * (b.maxY - b.minY);
7392
+ for (const r of arr) {
7393
+ const area = (r.maxX - r.minX) * (r.maxY - r.minY);
7394
+ if (r.count > b.count || r.count === b.count && area < bArea) {
7395
+ b = r;
7396
+ bArea = area;
4427
7397
  }
4428
7398
  }
7399
+ return b;
4429
7400
  }
4430
- return { width, height, nY, nX, rightX, leftX, bottomY, topY };
7401
+ const bestSingle = pickBest(singleResults);
7402
+ const bestMulti = pickBest(multiResults);
7403
+ const best = bestMulti.count >= bestSingle.count && bestMulti.count > 0 ? bestMulti : bestSingle;
7404
+ centerLayout(best, bounds);
7405
+ return {
7406
+ rotation: best.placements[0]?.rotation ?? 0,
7407
+ placements: best.placements,
7408
+ producedPerSheet: best.count
7409
+ };
4431
7410
  }
4432
- function prepareRotation(contourPoints, dielineW, dielineH, deg) {
7411
+
7412
+ // src/utils/autoLayout/calculate/bags-pillows/becf-12101/index.ts
7413
+ function prepareRotation4(contourPoints, dielineW, dielineH, deg) {
4433
7414
  const rotated = normalizePoints(contourPoints, deg);
4434
7415
  return {
4435
7416
  profile: buildProfile(rotated),
@@ -4437,119 +7418,243 @@ function prepareRotation(contourPoints, dielineW, dielineH, deg) {
4437
7418
  deg
4438
7419
  };
4439
7420
  }
4440
- function findMinStepX(a, b, dyMm) {
4441
- const dySamples = Math.round(dyMm / SAMPLE_STEP);
4442
- let maxOverlap = -Infinity;
4443
- for (let ia = 0; ia < a.nY; ia++) {
4444
- const ib = ia - dySamples;
4445
- if (ib < 0 || ib >= b.nY) continue;
4446
- if (a.rightX[ia] === -Infinity || b.leftX[ib] === Infinity) continue;
4447
- const overlap = a.rightX[ia] - b.leftX[ib];
4448
- if (overlap > maxOverlap) maxOverlap = overlap;
7421
+ function pairGrid3(rdA, rdB, bounds) {
7422
+ const pA = rdA.profile, pB = rdB.profile;
7423
+ const gapAB = findMinStepX(pA, pB, 0);
7424
+ if (gapAB <= 0) return emptyResult();
7425
+ const pairW = gapAB + pB.width;
7426
+ const pairH = Math.max(pA.height, pB.height);
7427
+ const pairStepX = gapAB + findMinStepX(pB, pA, 0);
7428
+ const pairStepY = Math.max(
7429
+ findMinStepY(pA, pA, 0),
7430
+ findMinStepY(pA, pB, gapAB),
7431
+ findMinStepY(pB, pA, -gapAB),
7432
+ findMinStepY(pB, pB, 0)
7433
+ );
7434
+ if (pairStepX <= 0 || pairStepY <= 0) return emptyResult();
7435
+ const usableW = bounds.right - bounds.left;
7436
+ const usableH = bounds.bottom - bounds.top;
7437
+ const pairCols = Math.max(0, Math.floor((usableW - pairW) / pairStepX) + 1);
7438
+ const pairRows = Math.max(0, Math.floor((usableH - pairH) / pairStepY) + 1);
7439
+ if (pairCols === 0 || pairRows === 0) return emptyResult();
7440
+ const placements = [];
7441
+ let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
7442
+ for (let r = 0; r < pairRows; r++) {
7443
+ for (let c = 0; c < pairCols; c++) {
7444
+ const baseX = bounds.left + c * pairStepX;
7445
+ const baseY = bounds.top + r * pairStepY;
7446
+ const oxA = baseX;
7447
+ const oyA = baseY;
7448
+ placements.push({ x: oxA + rdA.bbOffset.dx, y: oyA + rdA.bbOffset.dy, rotation: rdA.deg });
7449
+ if (oxA < minX) minX = oxA;
7450
+ if (oyA < minY) minY = oyA;
7451
+ if (oxA + pA.width > maxX) maxX = oxA + pA.width;
7452
+ if (oyA + pA.height > maxY) maxY = oyA + pA.height;
7453
+ const oxB = baseX + gapAB;
7454
+ const oyB = baseY;
7455
+ placements.push({ x: oxB + rdB.bbOffset.dx, y: oyB + rdB.bbOffset.dy, rotation: rdB.deg });
7456
+ if (oxB < minX) minX = oxB;
7457
+ if (oyB < minY) minY = oyB;
7458
+ if (oxB + pB.width > maxX) maxX = oxB + pB.width;
7459
+ if (oyB + pB.height > maxY) maxY = oyB + pB.height;
7460
+ }
4449
7461
  }
4450
- return maxOverlap <= -Infinity ? 0 : maxOverlap;
4451
- }
4452
- function findMinStepY(a, b, dxMm) {
4453
- const dxSamples = Math.round(dxMm / SAMPLE_STEP);
4454
- let maxOverlap = -Infinity;
4455
- for (let ia = 0; ia < a.nX; ia++) {
4456
- const ib = ia - dxSamples;
4457
- if (ib < 0 || ib >= b.nX) continue;
4458
- if (a.bottomY[ia] === -Infinity || b.topY[ib] === Infinity) continue;
4459
- const overlap = a.bottomY[ia] - b.topY[ib];
4460
- if (overlap > maxOverlap) maxOverlap = overlap;
7462
+ const pairsRightEdge = bounds.left + (pairCols - 1) * pairStepX + pairW;
7463
+ const pairsBottomEdge = bounds.top + (pairRows - 1) * pairStepY + pairH;
7464
+ const gapRight = bounds.right - pairsRightEdge;
7465
+ const gapBottom = bounds.bottom - pairsBottomEdge;
7466
+ const extraRotations = [rdA, rdB];
7467
+ for (const rdExtra of extraRotations) {
7468
+ const pe = rdExtra.profile;
7469
+ if (pe.width <= gapRight) {
7470
+ for (let r = 0; r < pairRows; r++) {
7471
+ const ox = pairsRightEdge;
7472
+ const oy = bounds.top + r * pairStepY;
7473
+ if (ox + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7474
+ placements.push({ x: ox + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7475
+ if (ox + pe.width > maxX) maxX = ox + pe.width;
7476
+ }
7477
+ }
7478
+ break;
7479
+ }
4461
7480
  }
4462
- return maxOverlap <= -Infinity ? 0 : maxOverlap;
7481
+ for (const rdExtra of extraRotations) {
7482
+ const pe = rdExtra.profile;
7483
+ if (pe.height <= gapBottom) {
7484
+ for (let c = 0; c < pairCols; c++) {
7485
+ const oxA = bounds.left + c * pairStepX;
7486
+ const oy = pairsBottomEdge;
7487
+ if (oxA + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7488
+ placements.push({ x: oxA + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7489
+ if (oy + pe.height > maxY) maxY = oy + pe.height;
7490
+ }
7491
+ }
7492
+ break;
7493
+ }
7494
+ }
7495
+ return { placements, count: placements.length, minX, minY, maxX, maxY };
4463
7496
  }
4464
- function findMinStepY_multi(profA, stepX_A, profB, offsetX) {
4465
- const reach = Math.max(profA.width, profB.width);
4466
- let maxStep = 0;
4467
- const nMin = Math.floor((offsetX - reach) / stepX_A);
4468
- const nMax = Math.ceil((offsetX + reach) / stepX_A);
4469
- for (let n = nMin; n <= nMax; n++) {
4470
- const s = findMinStepY(profA, profB, offsetX - n * stepX_A);
4471
- if (s > maxStep) maxStep = s;
7497
+ function computeLayoutForPaper4(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
7498
+ const rots = [0, 90, 180, 270];
7499
+ const rd = /* @__PURE__ */ new Map();
7500
+ for (const deg of rots) {
7501
+ rd.set(deg, prepareRotation4(contourPoints, dielineW, dielineH, deg));
4472
7502
  }
4473
- return maxStep;
7503
+ const results = [];
7504
+ for (const deg of rots) {
7505
+ results.push(singleRotGrid(rd.get(deg), bounds));
7506
+ }
7507
+ const allPairs = [
7508
+ [0, 180],
7509
+ [90, 270],
7510
+ [0, 90],
7511
+ [0, 270],
7512
+ [90, 180],
7513
+ [180, 270]
7514
+ ];
7515
+ for (const [a, b] of allPairs) {
7516
+ const rdA = rd.get(a), rdB = rd.get(b);
7517
+ const stepA = findMinStepX(rdA.profile, rdA.profile, 0);
7518
+ if (stepA <= 0) continue;
7519
+ for (let off = 0; off < stepA; off += 1) {
7520
+ results.push(dualRotGrid(rdA, rdB, off, bounds));
7521
+ results.push(dualRotGrid(rdB, rdA, off, bounds));
7522
+ }
7523
+ }
7524
+ for (const [a, b] of allPairs) {
7525
+ results.push(pairGrid3(rd.get(a), rd.get(b), bounds));
7526
+ results.push(pairGrid3(rd.get(b), rd.get(a), bounds));
7527
+ }
7528
+ const singleResults = [];
7529
+ const multiResults = [];
7530
+ for (const r of results) {
7531
+ if (r.count === 0) continue;
7532
+ const rotations = new Set(r.placements.map((p) => p.rotation));
7533
+ if (rotations.size > 1) {
7534
+ multiResults.push(r);
7535
+ } else {
7536
+ singleResults.push(r);
7537
+ }
7538
+ }
7539
+ function pickBest(arr) {
7540
+ let b = arr[0] ?? emptyResult();
7541
+ let bArea = (b.maxX - b.minX) * (b.maxY - b.minY);
7542
+ for (const r of arr) {
7543
+ const area = (r.maxX - r.minX) * (r.maxY - r.minY);
7544
+ if (r.count > b.count || r.count === b.count && area < bArea) {
7545
+ b = r;
7546
+ bArea = area;
7547
+ }
7548
+ }
7549
+ return b;
7550
+ }
7551
+ const bestSingle = pickBest(singleResults);
7552
+ const bestMulti = pickBest(multiResults);
7553
+ const best = bestMulti.count >= bestSingle.count && bestMulti.count > 0 ? bestMulti : bestSingle;
7554
+ centerLayout(best, bounds);
7555
+ return {
7556
+ rotation: best.placements[0]?.rotation ?? 0,
7557
+ placements: best.placements,
7558
+ producedPerSheet: best.count
7559
+ };
4474
7560
  }
4475
- function emptyResult() {
4476
- return { placements: [], count: 0, minX: 0, minY: 0, maxX: 0, maxY: 0 };
7561
+
7562
+ // src/utils/autoLayout/calculate/bags-pillows/becf-12109/index.ts
7563
+ function prepareRotation5(contourPoints, dielineW, dielineH, deg) {
7564
+ const rotated = normalizePoints(contourPoints, deg);
7565
+ return {
7566
+ profile: buildProfile(rotated),
7567
+ bbOffset: computeDielineBBOffset(contourPoints, dielineW, dielineH, deg),
7568
+ deg
7569
+ };
4477
7570
  }
4478
- function singleRotGrid(rd, bounds) {
4479
- const p = rd.profile;
4480
- const stepX = findMinStepX(p, p, 0);
4481
- const stepY = findMinStepY(p, p, 0);
4482
- if (stepX <= 0 || stepY <= 0) return emptyResult();
4483
- const cols = Math.max(0, Math.floor((bounds.right - bounds.left - p.width) / stepX) + 1);
4484
- const rows = Math.max(0, Math.floor((bounds.bottom - bounds.top - p.height) / stepY) + 1);
4485
- if (cols === 0 || rows === 0) return emptyResult();
7571
+ function pairGrid4(rdA, rdB, bounds) {
7572
+ const pA = rdA.profile, pB = rdB.profile;
7573
+ const gapAB = findMinStepX(pA, pB, 0);
7574
+ if (gapAB <= 0) return emptyResult();
7575
+ const pairW = gapAB + pB.width;
7576
+ const pairH = Math.max(pA.height, pB.height);
7577
+ const pairStepX = gapAB + findMinStepX(pB, pA, 0);
7578
+ const pairStepY = Math.max(
7579
+ findMinStepY(pA, pA, 0),
7580
+ findMinStepY(pA, pB, gapAB),
7581
+ findMinStepY(pB, pA, -gapAB),
7582
+ findMinStepY(pB, pB, 0)
7583
+ );
7584
+ if (pairStepX <= 0 || pairStepY <= 0) return emptyResult();
7585
+ const usableW = bounds.right - bounds.left;
7586
+ const usableH = bounds.bottom - bounds.top;
7587
+ const pairCols = Math.max(0, Math.floor((usableW - pairW) / pairStepX) + 1);
7588
+ const pairRows = Math.max(0, Math.floor((usableH - pairH) / pairStepY) + 1);
7589
+ if (pairCols === 0 || pairRows === 0) return emptyResult();
4486
7590
  const placements = [];
4487
7591
  let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
4488
- for (let r = 0; r < rows; r++) {
4489
- for (let c = 0; c < cols; c++) {
4490
- const ox = bounds.left + c * stepX;
4491
- const oy = bounds.top + r * stepY;
4492
- placements.push({ x: ox + rd.bbOffset.dx, y: oy + rd.bbOffset.dy, rotation: rd.deg });
4493
- if (ox < minX) minX = ox;
4494
- if (oy < minY) minY = oy;
4495
- if (ox + p.width > maxX) maxX = ox + p.width;
4496
- if (oy + p.height > maxY) maxY = oy + p.height;
7592
+ for (let r = 0; r < pairRows; r++) {
7593
+ for (let c = 0; c < pairCols; c++) {
7594
+ const baseX = bounds.left + c * pairStepX;
7595
+ const baseY = bounds.top + r * pairStepY;
7596
+ const oxA = baseX;
7597
+ const oyA = baseY;
7598
+ placements.push({ x: oxA + rdA.bbOffset.dx, y: oyA + rdA.bbOffset.dy, rotation: rdA.deg });
7599
+ if (oxA < minX) minX = oxA;
7600
+ if (oyA < minY) minY = oyA;
7601
+ if (oxA + pA.width > maxX) maxX = oxA + pA.width;
7602
+ if (oyA + pA.height > maxY) maxY = oyA + pA.height;
7603
+ const oxB = baseX + gapAB;
7604
+ const oyB = baseY;
7605
+ placements.push({ x: oxB + rdB.bbOffset.dx, y: oyB + rdB.bbOffset.dy, rotation: rdB.deg });
7606
+ if (oxB < minX) minX = oxB;
7607
+ if (oyB < minY) minY = oyB;
7608
+ if (oxB + pB.width > maxX) maxX = oxB + pB.width;
7609
+ if (oyB + pB.height > maxY) maxY = oyB + pB.height;
4497
7610
  }
4498
7611
  }
4499
- return { placements, count: placements.length, minX, minY, maxX, maxY };
4500
- }
4501
- function dualRotGrid(rdA, rdB, offsetX, bounds) {
4502
- const pA = rdA.profile, pB = rdB.profile;
4503
- const stepX_A = findMinStepX(pA, pA, 0);
4504
- const stepX_B = findMinStepX(pB, pB, 0);
4505
- if (stepX_A <= 0 || stepX_B <= 0) return emptyResult();
4506
- const stepY_AB = findMinStepY_multi(pA, stepX_A, pB, offsetX);
4507
- const stepY_BA = findMinStepY_multi(pB, stepX_B, pA, -offsetX);
4508
- if (stepY_AB + stepY_BA <= 0) return emptyResult();
4509
- const placements = [];
4510
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
4511
- let oy = bounds.top;
4512
- let isRowA = true;
4513
- while (true) {
4514
- const rd = isRowA ? rdA : rdB;
4515
- const p = rd.profile;
4516
- const stepX = isRowA ? stepX_A : stepX_B;
4517
- if (oy + p.height > bounds.bottom) break;
4518
- let sx = isRowA ? bounds.left : bounds.left + offsetX;
4519
- if (sx < bounds.left) sx += stepX * Math.ceil((bounds.left - sx) / stepX);
4520
- for (let ox = sx; ox + p.width <= bounds.right; ox += stepX) {
4521
- placements.push({ x: ox + rd.bbOffset.dx, y: oy + rd.bbOffset.dy, rotation: rd.deg });
4522
- if (ox < minX) minX = ox;
4523
- if (oy < minY) minY = oy;
4524
- if (ox + p.width > maxX) maxX = ox + p.width;
4525
- if (oy + p.height > maxY) maxY = oy + p.height;
7612
+ const pairsRightEdge = bounds.left + (pairCols - 1) * pairStepX + pairW;
7613
+ const pairsBottomEdge = bounds.top + (pairRows - 1) * pairStepY + pairH;
7614
+ const gapRight = bounds.right - pairsRightEdge;
7615
+ const gapBottom = bounds.bottom - pairsBottomEdge;
7616
+ const extraRotations = [rdA, rdB];
7617
+ for (const rdExtra of extraRotations) {
7618
+ const pe = rdExtra.profile;
7619
+ if (pe.width <= gapRight) {
7620
+ for (let r = 0; r < pairRows; r++) {
7621
+ const ox = pairsRightEdge;
7622
+ const oy = bounds.top + r * pairStepY;
7623
+ if (ox + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7624
+ placements.push({ x: ox + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7625
+ if (ox + pe.width > maxX) maxX = ox + pe.width;
7626
+ }
7627
+ }
7628
+ break;
4526
7629
  }
4527
- oy += isRowA ? stepY_AB : stepY_BA;
4528
- isRowA = !isRowA;
4529
7630
  }
4530
- if (placements.length === 0) return emptyResult();
4531
- return { placements, count: placements.length, minX, minY, maxX, maxY };
4532
- }
4533
- function centerLayout(result, bounds) {
4534
- if (result.count === 0) return;
4535
- const offX = (bounds.right - bounds.left - (result.maxX - result.minX)) / 2 - (result.minX - bounds.left);
4536
- const offY = (bounds.bottom - bounds.top - (result.maxY - result.minY)) / 2 - (result.minY - bounds.top);
4537
- for (const p of result.placements) {
4538
- p.x += offX;
4539
- p.y += offY;
7631
+ for (const rdExtra of extraRotations) {
7632
+ const pe = rdExtra.profile;
7633
+ if (pe.height <= gapBottom) {
7634
+ for (let c = 0; c < pairCols; c++) {
7635
+ const oxA = bounds.left + c * pairStepX;
7636
+ const oy = pairsBottomEdge;
7637
+ if (oxA + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7638
+ placements.push({ x: oxA + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7639
+ if (oy + pe.height > maxY) maxY = oy + pe.height;
7640
+ }
7641
+ }
7642
+ break;
7643
+ }
4540
7644
  }
7645
+ return { placements, count: placements.length, minX, minY, maxX, maxY };
4541
7646
  }
4542
- function computeLayoutForPaper(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
7647
+ function computeLayoutForPaper5(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
4543
7648
  const rots = [0, 90, 180, 270];
4544
7649
  const rd = /* @__PURE__ */ new Map();
4545
7650
  for (const deg of rots) {
4546
- rd.set(deg, prepareRotation(contourPoints, dielineW, dielineH, deg));
7651
+ rd.set(deg, prepareRotation5(contourPoints, dielineW, dielineH, deg));
4547
7652
  }
4548
7653
  const results = [];
4549
7654
  for (const deg of rots) {
4550
7655
  results.push(singleRotGrid(rd.get(deg), bounds));
4551
7656
  }
4552
- const pairs = [
7657
+ const allPairs = [
4553
7658
  [0, 180],
4554
7659
  [90, 270],
4555
7660
  [0, 90],
@@ -4557,7 +7662,7 @@ function computeLayoutForPaper(contourPoints, dielineW, dielineH, _paperWidth, _
4557
7662
  [90, 180],
4558
7663
  [180, 270]
4559
7664
  ];
4560
- for (const [a, b] of pairs) {
7665
+ for (const [a, b] of allPairs) {
4561
7666
  const rdA = rd.get(a), rdB = rd.get(b);
4562
7667
  const stepA = findMinStepX(rdA.profile, rdA.profile, 0);
4563
7668
  if (stepA <= 0) continue;
@@ -4566,10 +7671,36 @@ function computeLayoutForPaper(contourPoints, dielineW, dielineH, _paperWidth, _
4566
7671
  results.push(dualRotGrid(rdB, rdA, off, bounds));
4567
7672
  }
4568
7673
  }
4569
- let best = results[0];
7674
+ for (const [a, b] of allPairs) {
7675
+ results.push(pairGrid4(rd.get(a), rd.get(b), bounds));
7676
+ results.push(pairGrid4(rd.get(b), rd.get(a), bounds));
7677
+ }
7678
+ const singleResults = [];
7679
+ const multiResults = [];
4570
7680
  for (const r of results) {
4571
- if (r.count > best.count) best = r;
7681
+ if (r.count === 0) continue;
7682
+ const rotations = new Set(r.placements.map((p) => p.rotation));
7683
+ if (rotations.size > 1) {
7684
+ multiResults.push(r);
7685
+ } else {
7686
+ singleResults.push(r);
7687
+ }
7688
+ }
7689
+ function pickBest(arr) {
7690
+ let b = arr[0] ?? emptyResult();
7691
+ let bArea = (b.maxX - b.minX) * (b.maxY - b.minY);
7692
+ for (const r of arr) {
7693
+ const area = (r.maxX - r.minX) * (r.maxY - r.minY);
7694
+ if (r.count > b.count || r.count === b.count && area < bArea) {
7695
+ b = r;
7696
+ bArea = area;
7697
+ }
7698
+ }
7699
+ return b;
4572
7700
  }
7701
+ const bestSingle = pickBest(singleResults);
7702
+ const bestMulti = pickBest(multiResults);
7703
+ const best = bestMulti.count >= bestSingle.count && bestMulti.count > 0 ? bestMulti : bestSingle;
4573
7704
  centerLayout(best, bounds);
4574
7705
  return {
4575
7706
  rotation: best.placements[0]?.rotation ?? 0,
@@ -4578,8 +7709,8 @@ function computeLayoutForPaper(contourPoints, dielineW, dielineH, _paperWidth, _
4578
7709
  };
4579
7710
  }
4580
7711
 
4581
- // src/utils/autoLayout/calculate/tuck-end-boxes/becf-1030a/index.ts
4582
- function prepareRotation2(contourPoints, dielineW, dielineH, deg) {
7712
+ // src/utils/autoLayout/calculate/bags-pillows/becf-c-12101/index.ts
7713
+ function prepareRotation6(contourPoints, dielineW, dielineH, deg) {
4583
7714
  const rotated = normalizePoints(contourPoints, deg);
4584
7715
  return {
4585
7716
  profile: buildProfile(rotated),
@@ -4587,7 +7718,7 @@ function prepareRotation2(contourPoints, dielineW, dielineH, deg) {
4587
7718
  deg
4588
7719
  };
4589
7720
  }
4590
- function pairGrid(rdA, rdB, bounds) {
7721
+ function pairGrid5(rdA, rdB, bounds) {
4591
7722
  const pA = rdA.profile, pB = rdB.profile;
4592
7723
  const gapAB = findMinStepX(pA, pB, 0);
4593
7724
  if (gapAB <= 0) return emptyResult();
@@ -4663,11 +7794,11 @@ function pairGrid(rdA, rdB, bounds) {
4663
7794
  }
4664
7795
  return { placements, count: placements.length, minX, minY, maxX, maxY };
4665
7796
  }
4666
- function computeLayoutForPaper2(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
7797
+ function computeLayoutForPaper6(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
4667
7798
  const rots = [0, 90, 180, 270];
4668
7799
  const rd = /* @__PURE__ */ new Map();
4669
7800
  for (const deg of rots) {
4670
- rd.set(deg, prepareRotation2(contourPoints, dielineW, dielineH, deg));
7801
+ rd.set(deg, prepareRotation6(contourPoints, dielineW, dielineH, deg));
4671
7802
  }
4672
7803
  const results = [];
4673
7804
  for (const deg of rots) {
@@ -4691,8 +7822,8 @@ function computeLayoutForPaper2(contourPoints, dielineW, dielineH, _paperWidth,
4691
7822
  }
4692
7823
  }
4693
7824
  for (const [a, b] of allPairs) {
4694
- results.push(pairGrid(rd.get(a), rd.get(b), bounds));
4695
- results.push(pairGrid(rd.get(b), rd.get(a), bounds));
7825
+ results.push(pairGrid5(rd.get(a), rd.get(b), bounds));
7826
+ results.push(pairGrid5(rd.get(b), rd.get(a), bounds));
4696
7827
  }
4697
7828
  const singleResults = [];
4698
7829
  const multiResults = [];
@@ -4728,8 +7859,8 @@ function computeLayoutForPaper2(contourPoints, dielineW, dielineH, _paperWidth,
4728
7859
  };
4729
7860
  }
4730
7861
 
4731
- // src/utils/autoLayout/calculate/tuck-end-boxes/becf-1040a/index.ts
4732
- function prepareRotation3(contourPoints, dielineW, dielineH, deg) {
7862
+ // src/utils/autoLayout/calculate/bags-pillows/becf-c-12109/index.ts
7863
+ function prepareRotation7(contourPoints, dielineW, dielineH, deg) {
4733
7864
  const rotated = normalizePoints(contourPoints, deg);
4734
7865
  return {
4735
7866
  profile: buildProfile(rotated),
@@ -4737,34 +7868,20 @@ function prepareRotation3(contourPoints, dielineW, dielineH, deg) {
4737
7868
  deg
4738
7869
  };
4739
7870
  }
4740
- function findPairRowStepY(pA, pB, gapAB, pairStepX) {
4741
- const reach = Math.max(pA.width, pB.width) + Math.abs(gapAB);
4742
- const nMin = Math.floor(-reach / pairStepX) - 1;
4743
- const nMax = Math.ceil(reach / pairStepX) + 1;
4744
- let maxStep = 0;
4745
- for (let n = nMin; n <= nMax; n++) {
4746
- const dx = n * pairStepX;
4747
- const s1 = findMinStepY(pA, pA, dx);
4748
- if (s1 > maxStep) maxStep = s1;
4749
- const s2 = findMinStepY(pA, pB, dx + gapAB);
4750
- if (s2 > maxStep) maxStep = s2;
4751
- const s3 = findMinStepY(pB, pA, dx - gapAB);
4752
- if (s3 > maxStep) maxStep = s3;
4753
- const s4 = findMinStepY(pB, pB, dx);
4754
- if (s4 > maxStep) maxStep = s4;
4755
- }
4756
- return maxStep;
4757
- }
4758
- function pairGrid2(rdA, rdB, bounds) {
7871
+ function pairGrid6(rdA, rdB, bounds) {
4759
7872
  const pA = rdA.profile, pB = rdB.profile;
4760
7873
  const gapAB = findMinStepX(pA, pB, 0);
4761
7874
  if (gapAB <= 0) return emptyResult();
4762
7875
  const pairW = gapAB + pB.width;
4763
7876
  const pairH = Math.max(pA.height, pB.height);
4764
7877
  const pairStepX = gapAB + findMinStepX(pB, pA, 0);
4765
- if (pairStepX <= 0) return emptyResult();
4766
- const pairStepY = findPairRowStepY(pA, pB, gapAB, pairStepX);
4767
- if (pairStepY <= 0) return emptyResult();
7878
+ const pairStepY = Math.max(
7879
+ findMinStepY(pA, pA, 0),
7880
+ findMinStepY(pA, pB, gapAB),
7881
+ findMinStepY(pB, pA, -gapAB),
7882
+ findMinStepY(pB, pB, 0)
7883
+ );
7884
+ if (pairStepX <= 0 || pairStepY <= 0) return emptyResult();
4768
7885
  const usableW = bounds.right - bounds.left;
4769
7886
  const usableH = bounds.bottom - bounds.top;
4770
7887
  const pairCols = Math.max(0, Math.floor((usableW - pairW) / pairStepX) + 1);
@@ -4776,115 +7893,62 @@ function pairGrid2(rdA, rdB, bounds) {
4776
7893
  for (let c = 0; c < pairCols; c++) {
4777
7894
  const baseX = bounds.left + c * pairStepX;
4778
7895
  const baseY = bounds.top + r * pairStepY;
4779
- placements.push({ x: baseX + rdA.bbOffset.dx, y: baseY + rdA.bbOffset.dy, rotation: rdA.deg });
4780
- if (baseX < minX) minX = baseX;
4781
- if (baseY < minY) minY = baseY;
4782
- if (baseX + pA.width > maxX) maxX = baseX + pA.width;
4783
- if (baseY + pA.height > maxY) maxY = baseY + pA.height;
4784
- const bx = baseX + gapAB;
4785
- placements.push({ x: bx + rdB.bbOffset.dx, y: baseY + rdB.bbOffset.dy, rotation: rdB.deg });
4786
- if (bx < minX) minX = bx;
4787
- if (bx + pB.width > maxX) maxX = bx + pB.width;
4788
- if (baseY + pB.height > maxY) maxY = baseY + pB.height;
7896
+ const oxA = baseX;
7897
+ const oyA = baseY;
7898
+ placements.push({ x: oxA + rdA.bbOffset.dx, y: oyA + rdA.bbOffset.dy, rotation: rdA.deg });
7899
+ if (oxA < minX) minX = oxA;
7900
+ if (oyA < minY) minY = oyA;
7901
+ if (oxA + pA.width > maxX) maxX = oxA + pA.width;
7902
+ if (oyA + pA.height > maxY) maxY = oyA + pA.height;
7903
+ const oxB = baseX + gapAB;
7904
+ const oyB = baseY;
7905
+ placements.push({ x: oxB + rdB.bbOffset.dx, y: oyB + rdB.bbOffset.dy, rotation: rdB.deg });
7906
+ if (oxB < minX) minX = oxB;
7907
+ if (oyB < minY) minY = oyB;
7908
+ if (oxB + pB.width > maxX) maxX = oxB + pB.width;
7909
+ if (oyB + pB.height > maxY) maxY = oyB + pB.height;
4789
7910
  }
4790
7911
  }
4791
7912
  const pairsRightEdge = bounds.left + (pairCols - 1) * pairStepX + pairW;
4792
- const gapRight = bounds.right - pairsRightEdge;
4793
- for (const rdExtra of [rdA, rdB]) {
4794
- const pe = rdExtra.profile;
4795
- if (pe.width > gapRight) continue;
4796
- const dxFromB = pairsRightEdge - (bounds.left + (pairCols - 1) * pairStepX + gapAB);
4797
- const dxFromA = pairsRightEdge - bounds.left - (pairCols - 1) * pairStepX;
4798
- const extraStepY = Math.max(
4799
- findMinStepY(pA, pe, dxFromA),
4800
- findMinStepY(pB, pe, dxFromB),
4801
- findMinStepY(pe, pe, 0)
4802
- );
4803
- if (extraStepY <= 0) continue;
4804
- const effectiveStepY = Math.max(pairStepY, extraStepY);
4805
- const extraRows = Math.max(0, Math.floor((usableH - pe.height) / effectiveStepY) + 1);
4806
- for (let r = 0; r < extraRows; r++) {
4807
- const ox = pairsRightEdge;
4808
- const oy = bounds.top + r * effectiveStepY;
4809
- if (ox + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
4810
- placements.push({ x: ox + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
4811
- if (ox + pe.width > maxX) maxX = ox + pe.width;
4812
- if (oy + pe.height > maxY) maxY = oy + pe.height;
4813
- }
4814
- }
4815
- break;
4816
- }
4817
7913
  const pairsBottomEdge = bounds.top + (pairRows - 1) * pairStepY + pairH;
7914
+ const gapRight = bounds.right - pairsRightEdge;
4818
7915
  const gapBottom = bounds.bottom - pairsBottomEdge;
4819
- for (const rdExtra of [rdA, rdB]) {
7916
+ const extraRotations = [rdA, rdB];
7917
+ for (const rdExtra of extraRotations) {
4820
7918
  const pe = rdExtra.profile;
4821
- if (pe.height > gapBottom) continue;
4822
- const extraStepX = findMinStepX(pe, pe, 0);
4823
- if (extraStepX <= 0) continue;
4824
- const dyFromPairRow = pairsBottomEdge - (bounds.top + (pairRows - 1) * pairStepY);
4825
- const stepFromA = findMinStepY(pA, pe, 0);
4826
- const stepFromB = findMinStepY(pB, pe, gapAB);
4827
- if (dyFromPairRow < stepFromA || dyFromPairRow < stepFromB) continue;
4828
- const extraCols = Math.max(0, Math.floor((usableW - pe.width) / extraStepX) + 1);
4829
- for (let c = 0; c < extraCols; c++) {
4830
- const ox = bounds.left + c * extraStepX;
4831
- const oy = pairsBottomEdge;
4832
- if (ox + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
4833
- placements.push({ x: ox + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
4834
- if (ox + pe.width > maxX) maxX = ox + pe.width;
4835
- if (oy + pe.height > maxY) maxY = oy + pe.height;
7919
+ if (pe.width <= gapRight) {
7920
+ for (let r = 0; r < pairRows; r++) {
7921
+ const ox = pairsRightEdge;
7922
+ const oy = bounds.top + r * pairStepY;
7923
+ if (ox + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7924
+ placements.push({ x: ox + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7925
+ if (ox + pe.width > maxX) maxX = ox + pe.width;
7926
+ }
4836
7927
  }
7928
+ break;
4837
7929
  }
4838
- break;
4839
7930
  }
4840
- return { placements, count: placements.length, minX, minY, maxX, maxY };
4841
- }
4842
- function verticalPairGrid(rdA, rdB, bounds) {
4843
- const pA = rdA.profile, pB = rdB.profile;
4844
- const gapAB_Y = findMinStepY(pA, pB, 0);
4845
- if (gapAB_Y <= 0) return emptyResult();
4846
- const vpairH = gapAB_Y + pB.height;
4847
- const vpairW = Math.max(pA.width, pB.width);
4848
- Math.max(pA.height, pB.height) + Math.abs(gapAB_Y);
4849
- let vpairStepX = 0;
4850
- {
4851
- const stepXAA = findMinStepX(pA, pA, 0);
4852
- const stepXAB = findMinStepX(pA, pB, -gapAB_Y);
4853
- const stepXBA = findMinStepX(pB, pA, gapAB_Y);
4854
- const stepXBB = findMinStepX(pB, pB, 0);
4855
- vpairStepX = Math.max(stepXAA, stepXAB, stepXBA, stepXBB);
4856
- }
4857
- if (vpairStepX <= 0) return emptyResult();
4858
- const vpairStepY = gapAB_Y + findMinStepY(pB, pA, 0);
4859
- if (vpairStepY <= 0) return emptyResult();
4860
- const usableW = bounds.right - bounds.left;
4861
- const usableH = bounds.bottom - bounds.top;
4862
- const cols = Math.max(0, Math.floor((usableW - vpairW) / vpairStepX) + 1);
4863
- const rows = Math.max(0, Math.floor((usableH - vpairH) / vpairStepY) + 1);
4864
- if (cols === 0 || rows === 0) return emptyResult();
4865
- const placements = [];
4866
- let minX = Infinity, minY = Infinity, maxX = -Infinity, maxY = -Infinity;
4867
- for (let r = 0; r < rows; r++) {
4868
- for (let c = 0; c < cols; c++) {
4869
- const baseX = bounds.left + c * vpairStepX;
4870
- const baseY = bounds.top + r * vpairStepY;
4871
- placements.push({ x: baseX + rdA.bbOffset.dx, y: baseY + rdA.bbOffset.dy, rotation: rdA.deg });
4872
- if (baseX < minX) minX = baseX;
4873
- if (baseY < minY) minY = baseY;
4874
- if (baseX + pA.width > maxX) maxX = baseX + pA.width;
4875
- if (baseY + pA.height > maxY) maxY = baseY + pA.height;
4876
- const by = baseY + gapAB_Y;
4877
- placements.push({ x: baseX + rdB.bbOffset.dx, y: by + rdB.bbOffset.dy, rotation: rdB.deg });
4878
- if (by + pB.height > maxY) maxY = by + pB.height;
7931
+ for (const rdExtra of extraRotations) {
7932
+ const pe = rdExtra.profile;
7933
+ if (pe.height <= gapBottom) {
7934
+ for (let c = 0; c < pairCols; c++) {
7935
+ const oxA = bounds.left + c * pairStepX;
7936
+ const oy = pairsBottomEdge;
7937
+ if (oxA + pe.width <= bounds.right && oy + pe.height <= bounds.bottom) {
7938
+ placements.push({ x: oxA + rdExtra.bbOffset.dx, y: oy + rdExtra.bbOffset.dy, rotation: rdExtra.deg });
7939
+ if (oy + pe.height > maxY) maxY = oy + pe.height;
7940
+ }
7941
+ }
7942
+ break;
4879
7943
  }
4880
7944
  }
4881
7945
  return { placements, count: placements.length, minX, minY, maxX, maxY };
4882
7946
  }
4883
- function computeLayoutForPaper3(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
7947
+ function computeLayoutForPaper7(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
4884
7948
  const rots = [0, 90, 180, 270];
4885
7949
  const rd = /* @__PURE__ */ new Map();
4886
7950
  for (const deg of rots) {
4887
- rd.set(deg, prepareRotation3(contourPoints, dielineW, dielineH, deg));
7951
+ rd.set(deg, prepareRotation7(contourPoints, dielineW, dielineH, deg));
4888
7952
  }
4889
7953
  const results = [];
4890
7954
  for (const deg of rots) {
@@ -4908,12 +7972,8 @@ function computeLayoutForPaper3(contourPoints, dielineW, dielineH, _paperWidth,
4908
7972
  }
4909
7973
  }
4910
7974
  for (const [a, b] of allPairs) {
4911
- results.push(pairGrid2(rd.get(a), rd.get(b), bounds));
4912
- results.push(pairGrid2(rd.get(b), rd.get(a), bounds));
4913
- }
4914
- for (const [a, b] of allPairs) {
4915
- results.push(verticalPairGrid(rd.get(a), rd.get(b), bounds));
4916
- results.push(verticalPairGrid(rd.get(b), rd.get(a), bounds));
7975
+ results.push(pairGrid6(rd.get(a), rd.get(b), bounds));
7976
+ results.push(pairGrid6(rd.get(b), rd.get(a), bounds));
4917
7977
  }
4918
7978
  const singleResults = [];
4919
7979
  const multiResults = [];
@@ -4949,8 +8009,8 @@ function computeLayoutForPaper3(contourPoints, dielineW, dielineH, _paperWidth,
4949
8009
  };
4950
8010
  }
4951
8011
 
4952
- // src/utils/autoLayout/calculate/bags-pillows/becf-12101/index.ts
4953
- function prepareRotation4(contourPoints, dielineW, dielineH, deg) {
8012
+ // src/utils/autoLayout/calculate/bags-pillows/becf-b-12101/index.ts
8013
+ function prepareRotation8(contourPoints, dielineW, dielineH, deg) {
4954
8014
  const rotated = normalizePoints(contourPoints, deg);
4955
8015
  return {
4956
8016
  profile: buildProfile(rotated),
@@ -4958,7 +8018,7 @@ function prepareRotation4(contourPoints, dielineW, dielineH, deg) {
4958
8018
  deg
4959
8019
  };
4960
8020
  }
4961
- function pairGrid3(rdA, rdB, bounds) {
8021
+ function pairGrid7(rdA, rdB, bounds) {
4962
8022
  const pA = rdA.profile, pB = rdB.profile;
4963
8023
  const gapAB = findMinStepX(pA, pB, 0);
4964
8024
  if (gapAB <= 0) return emptyResult();
@@ -4983,28 +8043,23 @@ function pairGrid3(rdA, rdB, bounds) {
4983
8043
  for (let c = 0; c < pairCols; c++) {
4984
8044
  const baseX = bounds.left + c * pairStepX;
4985
8045
  const baseY = bounds.top + r * pairStepY;
4986
- const oxA = baseX;
4987
- const oyA = baseY;
4988
- placements.push({ x: oxA + rdA.bbOffset.dx, y: oyA + rdA.bbOffset.dy, rotation: rdA.deg });
4989
- if (oxA < minX) minX = oxA;
4990
- if (oyA < minY) minY = oyA;
4991
- if (oxA + pA.width > maxX) maxX = oxA + pA.width;
4992
- if (oyA + pA.height > maxY) maxY = oyA + pA.height;
8046
+ placements.push({ x: baseX + rdA.bbOffset.dx, y: baseY + rdA.bbOffset.dy, rotation: rdA.deg });
8047
+ if (baseX < minX) minX = baseX;
8048
+ if (baseY < minY) minY = baseY;
8049
+ if (baseX + pA.width > maxX) maxX = baseX + pA.width;
8050
+ if (baseY + pA.height > maxY) maxY = baseY + pA.height;
4993
8051
  const oxB = baseX + gapAB;
4994
- const oyB = baseY;
4995
- placements.push({ x: oxB + rdB.bbOffset.dx, y: oyB + rdB.bbOffset.dy, rotation: rdB.deg });
8052
+ placements.push({ x: oxB + rdB.bbOffset.dx, y: baseY + rdB.bbOffset.dy, rotation: rdB.deg });
4996
8053
  if (oxB < minX) minX = oxB;
4997
- if (oyB < minY) minY = oyB;
4998
8054
  if (oxB + pB.width > maxX) maxX = oxB + pB.width;
4999
- if (oyB + pB.height > maxY) maxY = oyB + pB.height;
8055
+ if (baseY + pB.height > maxY) maxY = baseY + pB.height;
5000
8056
  }
5001
8057
  }
5002
8058
  const pairsRightEdge = bounds.left + (pairCols - 1) * pairStepX + pairW;
5003
8059
  const pairsBottomEdge = bounds.top + (pairRows - 1) * pairStepY + pairH;
5004
8060
  const gapRight = bounds.right - pairsRightEdge;
5005
8061
  const gapBottom = bounds.bottom - pairsBottomEdge;
5006
- const extraRotations = [rdA, rdB];
5007
- for (const rdExtra of extraRotations) {
8062
+ for (const rdExtra of [rdA, rdB]) {
5008
8063
  const pe = rdExtra.profile;
5009
8064
  if (pe.width <= gapRight) {
5010
8065
  for (let r = 0; r < pairRows; r++) {
@@ -5018,7 +8073,7 @@ function pairGrid3(rdA, rdB, bounds) {
5018
8073
  break;
5019
8074
  }
5020
8075
  }
5021
- for (const rdExtra of extraRotations) {
8076
+ for (const rdExtra of [rdA, rdB]) {
5022
8077
  const pe = rdExtra.profile;
5023
8078
  if (pe.height <= gapBottom) {
5024
8079
  for (let c = 0; c < pairCols; c++) {
@@ -5034,24 +8089,13 @@ function pairGrid3(rdA, rdB, bounds) {
5034
8089
  }
5035
8090
  return { placements, count: placements.length, minX, minY, maxX, maxY };
5036
8091
  }
5037
- function computeLayoutForPaper4(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
8092
+ function computeLayoutForPaper8(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
5038
8093
  const rots = [0, 90, 180, 270];
5039
8094
  const rd = /* @__PURE__ */ new Map();
5040
- for (const deg of rots) {
5041
- rd.set(deg, prepareRotation4(contourPoints, dielineW, dielineH, deg));
5042
- }
8095
+ for (const deg of rots) rd.set(deg, prepareRotation8(contourPoints, dielineW, dielineH, deg));
5043
8096
  const results = [];
5044
- for (const deg of rots) {
5045
- results.push(singleRotGrid(rd.get(deg), bounds));
5046
- }
5047
- const allPairs = [
5048
- [0, 180],
5049
- [90, 270],
5050
- [0, 90],
5051
- [0, 270],
5052
- [90, 180],
5053
- [180, 270]
5054
- ];
8097
+ for (const deg of rots) results.push(singleRotGrid(rd.get(deg), bounds));
8098
+ const allPairs = [[0, 180], [90, 270], [0, 90], [0, 270], [90, 180], [180, 270]];
5055
8099
  for (const [a, b] of allPairs) {
5056
8100
  const rdA = rd.get(a), rdB = rd.get(b);
5057
8101
  const stepA = findMinStepX(rdA.profile, rdA.profile, 0);
@@ -5062,19 +8106,15 @@ function computeLayoutForPaper4(contourPoints, dielineW, dielineH, _paperWidth,
5062
8106
  }
5063
8107
  }
5064
8108
  for (const [a, b] of allPairs) {
5065
- results.push(pairGrid3(rd.get(a), rd.get(b), bounds));
5066
- results.push(pairGrid3(rd.get(b), rd.get(a), bounds));
8109
+ results.push(pairGrid7(rd.get(a), rd.get(b), bounds));
8110
+ results.push(pairGrid7(rd.get(b), rd.get(a), bounds));
5067
8111
  }
5068
8112
  const singleResults = [];
5069
8113
  const multiResults = [];
5070
8114
  for (const r of results) {
5071
8115
  if (r.count === 0) continue;
5072
8116
  const rotations = new Set(r.placements.map((p) => p.rotation));
5073
- if (rotations.size > 1) {
5074
- multiResults.push(r);
5075
- } else {
5076
- singleResults.push(r);
5077
- }
8117
+ (rotations.size > 1 ? multiResults : singleResults).push(r);
5078
8118
  }
5079
8119
  function pickBest(arr) {
5080
8120
  let b = arr[0] ?? emptyResult();
@@ -5092,15 +8132,11 @@ function computeLayoutForPaper4(contourPoints, dielineW, dielineH, _paperWidth,
5092
8132
  const bestMulti = pickBest(multiResults);
5093
8133
  const best = bestMulti.count >= bestSingle.count && bestMulti.count > 0 ? bestMulti : bestSingle;
5094
8134
  centerLayout(best, bounds);
5095
- return {
5096
- rotation: best.placements[0]?.rotation ?? 0,
5097
- placements: best.placements,
5098
- producedPerSheet: best.count
5099
- };
8135
+ return { rotation: best.placements[0]?.rotation ?? 0, placements: best.placements, producedPerSheet: best.count };
5100
8136
  }
5101
8137
 
5102
- // src/utils/autoLayout/calculate/bags-pillows/becf-12109/index.ts
5103
- function prepareRotation5(contourPoints, dielineW, dielineH, deg) {
8138
+ // src/utils/autoLayout/calculate/bags-pillows/becf-b-12109/index.ts
8139
+ function prepareRotation9(contourPoints, dielineW, dielineH, deg) {
5104
8140
  const rotated = normalizePoints(contourPoints, deg);
5105
8141
  return {
5106
8142
  profile: buildProfile(rotated),
@@ -5108,7 +8144,7 @@ function prepareRotation5(contourPoints, dielineW, dielineH, deg) {
5108
8144
  deg
5109
8145
  };
5110
8146
  }
5111
- function pairGrid4(rdA, rdB, bounds) {
8147
+ function pairGrid8(rdA, rdB, bounds) {
5112
8148
  const pA = rdA.profile, pB = rdB.profile;
5113
8149
  const gapAB = findMinStepX(pA, pB, 0);
5114
8150
  if (gapAB <= 0) return emptyResult();
@@ -5133,28 +8169,23 @@ function pairGrid4(rdA, rdB, bounds) {
5133
8169
  for (let c = 0; c < pairCols; c++) {
5134
8170
  const baseX = bounds.left + c * pairStepX;
5135
8171
  const baseY = bounds.top + r * pairStepY;
5136
- const oxA = baseX;
5137
- const oyA = baseY;
5138
- placements.push({ x: oxA + rdA.bbOffset.dx, y: oyA + rdA.bbOffset.dy, rotation: rdA.deg });
5139
- if (oxA < minX) minX = oxA;
5140
- if (oyA < minY) minY = oyA;
5141
- if (oxA + pA.width > maxX) maxX = oxA + pA.width;
5142
- if (oyA + pA.height > maxY) maxY = oyA + pA.height;
8172
+ placements.push({ x: baseX + rdA.bbOffset.dx, y: baseY + rdA.bbOffset.dy, rotation: rdA.deg });
8173
+ if (baseX < minX) minX = baseX;
8174
+ if (baseY < minY) minY = baseY;
8175
+ if (baseX + pA.width > maxX) maxX = baseX + pA.width;
8176
+ if (baseY + pA.height > maxY) maxY = baseY + pA.height;
5143
8177
  const oxB = baseX + gapAB;
5144
- const oyB = baseY;
5145
- placements.push({ x: oxB + rdB.bbOffset.dx, y: oyB + rdB.bbOffset.dy, rotation: rdB.deg });
8178
+ placements.push({ x: oxB + rdB.bbOffset.dx, y: baseY + rdB.bbOffset.dy, rotation: rdB.deg });
5146
8179
  if (oxB < minX) minX = oxB;
5147
- if (oyB < minY) minY = oyB;
5148
8180
  if (oxB + pB.width > maxX) maxX = oxB + pB.width;
5149
- if (oyB + pB.height > maxY) maxY = oyB + pB.height;
8181
+ if (baseY + pB.height > maxY) maxY = baseY + pB.height;
5150
8182
  }
5151
8183
  }
5152
8184
  const pairsRightEdge = bounds.left + (pairCols - 1) * pairStepX + pairW;
5153
8185
  const pairsBottomEdge = bounds.top + (pairRows - 1) * pairStepY + pairH;
5154
8186
  const gapRight = bounds.right - pairsRightEdge;
5155
8187
  const gapBottom = bounds.bottom - pairsBottomEdge;
5156
- const extraRotations = [rdA, rdB];
5157
- for (const rdExtra of extraRotations) {
8188
+ for (const rdExtra of [rdA, rdB]) {
5158
8189
  const pe = rdExtra.profile;
5159
8190
  if (pe.width <= gapRight) {
5160
8191
  for (let r = 0; r < pairRows; r++) {
@@ -5168,7 +8199,7 @@ function pairGrid4(rdA, rdB, bounds) {
5168
8199
  break;
5169
8200
  }
5170
8201
  }
5171
- for (const rdExtra of extraRotations) {
8202
+ for (const rdExtra of [rdA, rdB]) {
5172
8203
  const pe = rdExtra.profile;
5173
8204
  if (pe.height <= gapBottom) {
5174
8205
  for (let c = 0; c < pairCols; c++) {
@@ -5184,24 +8215,13 @@ function pairGrid4(rdA, rdB, bounds) {
5184
8215
  }
5185
8216
  return { placements, count: placements.length, minX, minY, maxX, maxY };
5186
8217
  }
5187
- function computeLayoutForPaper5(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
8218
+ function computeLayoutForPaper9(contourPoints, dielineW, dielineH, _paperWidth, _paperHeight, bounds) {
5188
8219
  const rots = [0, 90, 180, 270];
5189
8220
  const rd = /* @__PURE__ */ new Map();
5190
- for (const deg of rots) {
5191
- rd.set(deg, prepareRotation5(contourPoints, dielineW, dielineH, deg));
5192
- }
8221
+ for (const deg of rots) rd.set(deg, prepareRotation9(contourPoints, dielineW, dielineH, deg));
5193
8222
  const results = [];
5194
- for (const deg of rots) {
5195
- results.push(singleRotGrid(rd.get(deg), bounds));
5196
- }
5197
- const allPairs = [
5198
- [0, 180],
5199
- [90, 270],
5200
- [0, 90],
5201
- [0, 270],
5202
- [90, 180],
5203
- [180, 270]
5204
- ];
8223
+ for (const deg of rots) results.push(singleRotGrid(rd.get(deg), bounds));
8224
+ const allPairs = [[0, 180], [90, 270], [0, 90], [0, 270], [90, 180], [180, 270]];
5205
8225
  for (const [a, b] of allPairs) {
5206
8226
  const rdA = rd.get(a), rdB = rd.get(b);
5207
8227
  const stepA = findMinStepX(rdA.profile, rdA.profile, 0);
@@ -5212,19 +8232,15 @@ function computeLayoutForPaper5(contourPoints, dielineW, dielineH, _paperWidth,
5212
8232
  }
5213
8233
  }
5214
8234
  for (const [a, b] of allPairs) {
5215
- results.push(pairGrid4(rd.get(a), rd.get(b), bounds));
5216
- results.push(pairGrid4(rd.get(b), rd.get(a), bounds));
8235
+ results.push(pairGrid8(rd.get(a), rd.get(b), bounds));
8236
+ results.push(pairGrid8(rd.get(b), rd.get(a), bounds));
5217
8237
  }
5218
8238
  const singleResults = [];
5219
8239
  const multiResults = [];
5220
8240
  for (const r of results) {
5221
8241
  if (r.count === 0) continue;
5222
8242
  const rotations = new Set(r.placements.map((p) => p.rotation));
5223
- if (rotations.size > 1) {
5224
- multiResults.push(r);
5225
- } else {
5226
- singleResults.push(r);
5227
- }
8243
+ (rotations.size > 1 ? multiResults : singleResults).push(r);
5228
8244
  }
5229
8245
  function pickBest(arr) {
5230
8246
  let b = arr[0] ?? emptyResult();
@@ -5242,11 +8258,7 @@ function computeLayoutForPaper5(contourPoints, dielineW, dielineH, _paperWidth,
5242
8258
  const bestMulti = pickBest(multiResults);
5243
8259
  const best = bestMulti.count >= bestSingle.count && bestMulti.count > 0 ? bestMulti : bestSingle;
5244
8260
  centerLayout(best, bounds);
5245
- return {
5246
- rotation: best.placements[0]?.rotation ?? 0,
5247
- placements: best.placements,
5248
- producedPerSheet: best.count
5249
- };
8261
+ return { rotation: best.placements[0]?.rotation ?? 0, placements: best.placements, producedPerSheet: best.count };
5250
8262
  }
5251
8263
 
5252
8264
  // src/utils/autoLayout/calculate/index.ts
@@ -5292,6 +8304,38 @@ function resolveModelFunctions(modelId, attrs) {
5292
8304
  offsetContour: offsetContour6
5293
8305
  };
5294
8306
  }
8307
+ case "BECF-C-12101": {
8308
+ const a = attrs;
8309
+ return {
8310
+ contour: generateOuterContour7(a),
8311
+ dieline: generateBecfC12101(a),
8312
+ offsetContour: offsetContour7
8313
+ };
8314
+ }
8315
+ case "BECF-C-12109": {
8316
+ const a = attrs;
8317
+ return {
8318
+ contour: generateOuterContour8(a),
8319
+ dieline: generateBecfC12109(a),
8320
+ offsetContour: offsetContour8
8321
+ };
8322
+ }
8323
+ case "BECF-B-12101": {
8324
+ const a = attrs;
8325
+ return {
8326
+ contour: generateOuterContour9(a),
8327
+ dieline: generateBecfB12101(a),
8328
+ offsetContour: offsetContour9
8329
+ };
8330
+ }
8331
+ case "BECF-B-12109": {
8332
+ const a = attrs;
8333
+ return {
8334
+ contour: generateOuterContour10(a),
8335
+ dieline: generateBecfB12109(a),
8336
+ offsetContour: offsetContour10
8337
+ };
8338
+ }
5295
8339
  case "BECF-1010A":
5296
8340
  default: {
5297
8341
  const a = attrs;
@@ -5315,6 +8359,14 @@ function resolveLayoutCalculator(modelId) {
5315
8359
  return computeLayoutForPaper4;
5316
8360
  case "BECF-12109":
5317
8361
  return computeLayoutForPaper5;
8362
+ case "BECF-C-12101":
8363
+ return computeLayoutForPaper6;
8364
+ case "BECF-C-12109":
8365
+ return computeLayoutForPaper7;
8366
+ case "BECF-B-12101":
8367
+ return computeLayoutForPaper8;
8368
+ case "BECF-B-12109":
8369
+ return computeLayoutForPaper9;
5318
8370
  default:
5319
8371
  return computeLayoutForPaperDefault;
5320
8372
  }
@@ -5328,11 +8380,11 @@ function calculateAutoLayout(rawConfig) {
5328
8380
  colorbarHeight: rawConfig.colorbarHeight ?? 5,
5329
8381
  isShowColorbar: rawConfig.isShowColorbar ?? true
5330
8382
  };
5331
- const { contour, dieline, offsetContour: offsetContour7 } = resolveModelFunctions(
8383
+ const { contour, dieline, offsetContour: offsetContour11 } = resolveModelFunctions(
5332
8384
  config.model.modelId,
5333
8385
  config.model.attributes
5334
8386
  );
5335
- const offsetContourPoints = config.layoutDistance > 0 ? offsetContour7(contour, config.layoutDistance / 2) : contour;
8387
+ const offsetContourPoints = config.layoutDistance > 0 ? offsetContour11(contour, config.layoutDistance / 2) : contour;
5336
8388
  const cbDepth = config.isShowColorbar ? config.colorbarHeight : 0;
5337
8389
  const computeLayout = resolveLayoutCalculator(config.model.modelId);
5338
8390
  const paperResults = [];
@@ -5693,6 +8745,46 @@ function renderDieLine(modelId, attrs) {
5693
8745
  renderAs: "group"
5694
8746
  }
5695
8747
  );
8748
+ case "BECF-12109":
8749
+ return /* @__PURE__ */ jsxRuntime.jsx(
8750
+ DIE_LINE_BECF_12109,
8751
+ {
8752
+ attributes: attrs,
8753
+ renderAs: "group"
8754
+ }
8755
+ );
8756
+ case "BECF-C-12101":
8757
+ return /* @__PURE__ */ jsxRuntime.jsx(
8758
+ DIE_LINE_BECF_C_12101,
8759
+ {
8760
+ attributes: attrs,
8761
+ renderAs: "group"
8762
+ }
8763
+ );
8764
+ case "BECF-C-12109":
8765
+ return /* @__PURE__ */ jsxRuntime.jsx(
8766
+ DIE_LINE_BECF_C_12109,
8767
+ {
8768
+ attributes: attrs,
8769
+ renderAs: "group"
8770
+ }
8771
+ );
8772
+ case "BECF-B-12101":
8773
+ return /* @__PURE__ */ jsxRuntime.jsx(
8774
+ DIE_LINE_BECF_B_12101,
8775
+ {
8776
+ attributes: attrs,
8777
+ renderAs: "group"
8778
+ }
8779
+ );
8780
+ case "BECF-B-12109":
8781
+ return /* @__PURE__ */ jsxRuntime.jsx(
8782
+ DIE_LINE_BECF_B_12109,
8783
+ {
8784
+ attributes: attrs,
8785
+ renderAs: "group"
8786
+ }
8787
+ );
5696
8788
  case "BECF-1010A":
5697
8789
  default:
5698
8790
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -6283,6 +9375,50 @@ function resolveModel(modelId, attrs, layoutDistance) {
6283
9375
  generateContour: (a) => generateOuterContour6(a)
6284
9376
  };
6285
9377
  }
9378
+ case "BECF-C-12101": {
9379
+ const typedAttrs = attrs;
9380
+ const contour = generateOuterContour7(typedAttrs);
9381
+ return {
9382
+ dieline: generateBecfC12101(typedAttrs),
9383
+ contourPath: contourToPath7(contour),
9384
+ offsetContourPoints: layoutDistance > 0 ? offsetContour7(contour, layoutDistance / 2) : contour,
9385
+ generate: (a) => generateBecfC12101(a),
9386
+ generateContour: (a) => generateOuterContour7(a)
9387
+ };
9388
+ }
9389
+ case "BECF-C-12109": {
9390
+ const typedAttrs = attrs;
9391
+ const contour = generateOuterContour8(typedAttrs);
9392
+ return {
9393
+ dieline: generateBecfC12109(typedAttrs),
9394
+ contourPath: contourToPath8(contour),
9395
+ offsetContourPoints: layoutDistance > 0 ? offsetContour8(contour, layoutDistance / 2) : contour,
9396
+ generate: (a) => generateBecfC12109(a),
9397
+ generateContour: (a) => generateOuterContour8(a)
9398
+ };
9399
+ }
9400
+ case "BECF-B-12101": {
9401
+ const typedAttrs = attrs;
9402
+ const contour = generateOuterContour9(typedAttrs);
9403
+ return {
9404
+ dieline: generateBecfB12101(typedAttrs),
9405
+ contourPath: contourToPath9(contour),
9406
+ offsetContourPoints: layoutDistance > 0 ? offsetContour9(contour, layoutDistance / 2) : contour,
9407
+ generate: (a) => generateBecfB12101(a),
9408
+ generateContour: (a) => generateOuterContour9(a)
9409
+ };
9410
+ }
9411
+ case "BECF-B-12109": {
9412
+ const typedAttrs = attrs;
9413
+ const contour = generateOuterContour10(typedAttrs);
9414
+ return {
9415
+ dieline: generateBecfB12109(typedAttrs),
9416
+ contourPath: contourToPath10(contour),
9417
+ offsetContourPoints: layoutDistance > 0 ? offsetContour10(contour, layoutDistance / 2) : contour,
9418
+ generate: (a) => generateBecfB12109(a),
9419
+ generateContour: (a) => generateOuterContour10(a)
9420
+ };
9421
+ }
6286
9422
  case "BECF-1010A":
6287
9423
  default: {
6288
9424
  const typedAttrs = attrs;
@@ -6340,6 +9476,38 @@ function renderDieLine2(modelId, attrs) {
6340
9476
  renderAs: "group"
6341
9477
  }
6342
9478
  );
9479
+ case "BECF-C-12101":
9480
+ return /* @__PURE__ */ jsxRuntime.jsx(
9481
+ DIE_LINE_BECF_C_12101,
9482
+ {
9483
+ attributes: attrs,
9484
+ renderAs: "group"
9485
+ }
9486
+ );
9487
+ case "BECF-C-12109":
9488
+ return /* @__PURE__ */ jsxRuntime.jsx(
9489
+ DIE_LINE_BECF_C_12109,
9490
+ {
9491
+ attributes: attrs,
9492
+ renderAs: "group"
9493
+ }
9494
+ );
9495
+ case "BECF-B-12101":
9496
+ return /* @__PURE__ */ jsxRuntime.jsx(
9497
+ DIE_LINE_BECF_B_12101,
9498
+ {
9499
+ attributes: attrs,
9500
+ renderAs: "group"
9501
+ }
9502
+ );
9503
+ case "BECF-B-12109":
9504
+ return /* @__PURE__ */ jsxRuntime.jsx(
9505
+ DIE_LINE_BECF_B_12109,
9506
+ {
9507
+ attributes: attrs,
9508
+ renderAs: "group"
9509
+ }
9510
+ );
6343
9511
  case "BECF-1010A":
6344
9512
  default:
6345
9513
  return /* @__PURE__ */ jsxRuntime.jsx(
@@ -6353,7 +9521,7 @@ function renderDieLine2(modelId, attrs) {
6353
9521
  })();
6354
9522
  }
6355
9523
  var PAPER_GAP = 20;
6356
- var PX_PER_MM7 = 96 / 25.4;
9524
+ var PX_PER_MM12 = 96 / 25.4;
6357
9525
  var RESULT_PANEL_HEIGHT = 55;
6358
9526
  var RESULT_GAP = 5;
6359
9527
  function getOpposite2(side) {
@@ -6530,8 +9698,8 @@ var AUTO_LAYOUT = react.forwardRef(
6530
9698
  const svg = document.createElementNS(svgNs, "svg");
6531
9699
  svg.setAttribute("xmlns", svgNs);
6532
9700
  svg.setAttribute("viewBox", `0 0 ${vw} ${vh}`);
6533
- svg.setAttribute("width", String(Math.round(vw * PX_PER_MM7)));
6534
- svg.setAttribute("height", String(Math.round(vh * PX_PER_MM7)));
9701
+ svg.setAttribute("width", String(Math.round(vw * PX_PER_MM12)));
9702
+ svg.setAttribute("height", String(Math.round(vh * PX_PER_MM12)));
6535
9703
  const bg = document.createElementNS(svgNs, "rect");
6536
9704
  bg.setAttribute("width", String(vw));
6537
9705
  bg.setAttribute("height", String(vh));
@@ -6564,8 +9732,8 @@ var AUTO_LAYOUT = react.forwardRef(
6564
9732
  img.src = url;
6565
9733
  });
6566
9734
  const canvas = document.createElement("canvas");
6567
- canvas.width = Math.round(vw * PX_PER_MM7);
6568
- canvas.height = Math.round(vh * PX_PER_MM7);
9735
+ canvas.width = Math.round(vw * PX_PER_MM12);
9736
+ canvas.height = Math.round(vh * PX_PER_MM12);
6569
9737
  const ctx = canvas.getContext("2d");
6570
9738
  ctx.fillStyle = "#ffffff";
6571
9739
  ctx.fillRect(0, 0, canvas.width, canvas.height);
@@ -6589,8 +9757,8 @@ var AUTO_LAYOUT = react.forwardRef(
6589
9757
  const svg = document.createElementNS(svgNs, "svg");
6590
9758
  svg.setAttribute("xmlns", svgNs);
6591
9759
  svg.setAttribute("viewBox", `0 0 ${paperResult.paperWidth} ${paperResult.paperHeight}`);
6592
- svg.setAttribute("width", String(Math.round(paperResult.paperWidth * PX_PER_MM7)));
6593
- svg.setAttribute("height", String(Math.round(paperResult.paperHeight * PX_PER_MM7)));
9760
+ svg.setAttribute("width", String(Math.round(paperResult.paperWidth * PX_PER_MM12)));
9761
+ svg.setAttribute("height", String(Math.round(paperResult.paperHeight * PX_PER_MM12)));
6594
9762
  const bg = document.createElementNS(svgNs, "rect");
6595
9763
  bg.setAttribute("width", String(paperResult.paperWidth));
6596
9764
  bg.setAttribute("height", String(paperResult.paperHeight));
@@ -6694,8 +9862,8 @@ var AUTO_LAYOUT = react.forwardRef(
6694
9862
  img.src = url;
6695
9863
  });
6696
9864
  const canvas = document.createElement("canvas");
6697
- canvas.width = Math.round(paperResult.paperWidth * PX_PER_MM7);
6698
- canvas.height = Math.round(paperResult.paperHeight * PX_PER_MM7);
9865
+ canvas.width = Math.round(paperResult.paperWidth * PX_PER_MM12);
9866
+ canvas.height = Math.round(paperResult.paperHeight * PX_PER_MM12);
6699
9867
  const ctx = canvas.getContext("2d");
6700
9868
  ctx.fillStyle = theme.colorPaperFill;
6701
9869
  ctx.fillRect(0, 0, canvas.width, canvas.height);
@@ -7204,6 +10372,16 @@ var DIE_LINE_LAYOUT = react.forwardRef(
7204
10372
  return /* @__PURE__ */ jsxRuntime.jsx(MODEL_BECF_12101, { ref, ...props });
7205
10373
  case "BECF-12109":
7206
10374
  return /* @__PURE__ */ jsxRuntime.jsx(MODEL_BECF_12109, { ref, ...props });
10375
+ case "BECF-C-12101":
10376
+ return /* @__PURE__ */ jsxRuntime.jsx(MODEL_BECF_C_12101, { ref, ...props });
10377
+ case "BECF-C-12109":
10378
+ return /* @__PURE__ */ jsxRuntime.jsx(MODEL_BECF_C_12109, { ref, ...props });
10379
+ case "BECF-B-12101":
10380
+ return /* @__PURE__ */ jsxRuntime.jsx(MODEL_BECF_B_12101, { ref, ...props });
10381
+ case "BECF-B-12109":
10382
+ return /* @__PURE__ */ jsxRuntime.jsx(MODEL_BECF_B_12109, { ref, ...props });
10383
+ case "BECF-10A0A":
10384
+ return /* @__PURE__ */ jsxRuntime.jsx(MODEL_BECF_10A0A, { ref, ...props });
7207
10385
  default:
7208
10386
  return null;
7209
10387
  }
@@ -7256,7 +10434,58 @@ var BECF_12109_DEFAULT_ATTRIBUTES = {
7256
10434
  glueArea: 13
7257
10435
  };
7258
10436
 
10437
+ // src/statics/bags-pillows/becf-c-12101/DEFAULT_ATTRIBUTES.ts
10438
+ var BECF_C_12101_DEFAULT_ATTRIBUTES = {
10439
+ length: 100,
10440
+ width: 50,
10441
+ height: 150,
10442
+ glueArea: 13
10443
+ };
10444
+
10445
+ // src/statics/bags-pillows/becf-c-12109/DEFAULT_ATTRIBUTES.ts
10446
+ var BECF_C_12109_DEFAULT_ATTRIBUTES = {
10447
+ length: 100,
10448
+ width: 50,
10449
+ height: 150,
10450
+ glueArea: 13
10451
+ };
10452
+
10453
+ // src/statics/bags-pillows/becf-b-12101/DEFAULT_ATTRIBUTES.ts
10454
+ var BECF_B_12101_DEFAULT_ATTRIBUTES = {
10455
+ length: 100,
10456
+ width: 50,
10457
+ height: 150,
10458
+ glueArea: 13
10459
+ };
10460
+
10461
+ // src/statics/bags-pillows/becf-b-12109/DEFAULT_ATTRIBUTES.ts
10462
+ var BECF_B_12109_DEFAULT_ATTRIBUTES = {
10463
+ length: 100,
10464
+ width: 50,
10465
+ height: 150,
10466
+ glueArea: 13
10467
+ };
10468
+
10469
+ // src/statics/snap-lock-boxes/becf-10a0a/DEFAULT_ATTRIBUTES.ts
10470
+ var BECF_10A0A_DEFAULT_ATTRIBUTES = {
10471
+ length: 150,
10472
+ width: 50,
10473
+ height: 150
10474
+ };
10475
+
7259
10476
  // src/statics/modelList.ts
10477
+ var MODEL_DEFAULT_ATTRIBUTES = {
10478
+ "BECF-1010A": { ...BECF_1010A_DEFAULT_ATTRIBUTES },
10479
+ "BECF-1040A": { ...BECF_1040A_DEFAULT_ATTRIBUTES },
10480
+ "BECF-1030A": { ...BECF_1030A_DEFAULT_ATTRIBUTES },
10481
+ "BECF-12101": { ...BECF_12101_DEFAULT_ATTRIBUTES },
10482
+ "BECF-12109": { ...BECF_12109_DEFAULT_ATTRIBUTES },
10483
+ "BECF-B-12101": { ...BECF_B_12101_DEFAULT_ATTRIBUTES },
10484
+ "BECF-B-12109": { ...BECF_B_12109_DEFAULT_ATTRIBUTES },
10485
+ "BECF-C-12101": { ...BECF_C_12101_DEFAULT_ATTRIBUTES },
10486
+ "BECF-C-12109": { ...BECF_C_12109_DEFAULT_ATTRIBUTES },
10487
+ "BECF-10A0A": { ...BECF_10A0A_DEFAULT_ATTRIBUTES }
10488
+ };
7260
10489
  var modelList = [
7261
10490
  {
7262
10491
  id: "BECF-1010A",
@@ -7295,10 +10524,45 @@ var modelList = [
7295
10524
  },
7296
10525
  {
7297
10526
  id: "BECF-12109",
7298
- nameEN: "SHOPPING BAGS TYPE B",
7299
- nameTH: "\u0E16\u0E38\u0E07\u0E23\u0E49\u0E2D\u0E22\u0E40\u0E0A\u0E37\u0E2D\u0E01\u0E40\u0E1B\u0E35\u0E22 \u0E21\u0E31\u0E14\u0E1B\u0E21 B",
10527
+ nameEN: "SHOPPING BAGS TYPE A1",
10528
+ nameTH: "\u0E16\u0E38\u0E07\u0E23\u0E49\u0E2D\u0E22\u0E40\u0E0A\u0E37\u0E2D\u0E01\u0E40\u0E1B\u0E35\u0E22 \u0E21\u0E31\u0E14\u0E1B\u0E21 A1",
7300
10529
  dimension: ["DIE_LINE"],
7301
10530
  attributes: { ...BECF_12109_DEFAULT_ATTRIBUTES }
10531
+ },
10532
+ {
10533
+ id: "BECF-B-12101",
10534
+ nameEN: "SHOPPING BAGS TYPE B",
10535
+ nameTH: "\u0E16\u0E38\u0E07\u0E2B\u0E39\u0E40\u0E01\u0E25\u0E35\u0E22\u0E27\u0E01\u0E23\u0E30\u0E14\u0E32\u0E29 B",
10536
+ dimension: ["DIE_LINE"],
10537
+ attributes: { ...BECF_B_12101_DEFAULT_ATTRIBUTES }
10538
+ },
10539
+ {
10540
+ id: "BECF-B-12109",
10541
+ nameEN: "SHOPPING BAGS TYPE B1",
10542
+ nameTH: "\u0E16\u0E38\u0E07\u0E2B\u0E39\u0E40\u0E01\u0E25\u0E35\u0E22\u0E27\u0E01\u0E23\u0E30\u0E14\u0E32\u0E29 B1",
10543
+ dimension: ["DIE_LINE"],
10544
+ attributes: { ...BECF_B_12109_DEFAULT_ATTRIBUTES }
10545
+ },
10546
+ {
10547
+ id: "BECF-C-12101",
10548
+ nameEN: "SHOPPING BAGS TYPE C",
10549
+ nameTH: "\u0E16\u0E38\u0E07\u0E2B\u0E39\u0E23\u0E34\u0E1A\u0E1A\u0E34\u0E49\u0E19 C",
10550
+ dimension: ["DIE_LINE"],
10551
+ attributes: { ...BECF_C_12101_DEFAULT_ATTRIBUTES }
10552
+ },
10553
+ {
10554
+ id: "BECF-C-12109",
10555
+ nameEN: "SHOPPING BAGS TYPE C1",
10556
+ nameTH: "\u0E16\u0E38\u0E07\u0E2B\u0E39\u0E23\u0E34\u0E1A\u0E1A\u0E34\u0E49\u0E19 C1",
10557
+ dimension: ["DIE_LINE"],
10558
+ attributes: { ...BECF_C_12109_DEFAULT_ATTRIBUTES }
10559
+ },
10560
+ {
10561
+ id: "BECF-10A0A",
10562
+ nameEN: "SNAP LOCK BOTTOM BOX",
10563
+ nameTH: "\u0E01\u0E25\u0E48\u0E2D\u0E07\u0E01\u0E49\u0E19\u0E25\u0E47\u0E2D\u0E04",
10564
+ dimension: ["DIE_LINE"],
10565
+ attributes: { ...BECF_10A0A_DEFAULT_ATTRIBUTES }
7302
10566
  }
7303
10567
  ];
7304
10568
 
@@ -7316,18 +10580,29 @@ exports.AUTO_LAYOUT_THEME_CONFIG = AUTO_LAYOUT_THEME_CONFIG;
7316
10580
  exports.BECF_1010A_DEFAULT_ATTRIBUTES = BECF_1010A_DEFAULT_ATTRIBUTES;
7317
10581
  exports.BECF_1030A_DEFAULT_ATTRIBUTES = BECF_1030A_DEFAULT_ATTRIBUTES;
7318
10582
  exports.BECF_1040A_DEFAULT_ATTRIBUTES = BECF_1040A_DEFAULT_ATTRIBUTES;
10583
+ exports.BECF_10A0A_DEFAULT_ATTRIBUTES = BECF_10A0A_DEFAULT_ATTRIBUTES;
7319
10584
  exports.BECF_11D01_DEFAULT_ATTRIBUTES = BECF_11D01_DEFAULT_ATTRIBUTES;
7320
10585
  exports.BECF_12101_DEFAULT_ATTRIBUTES = BECF_12101_DEFAULT_ATTRIBUTES;
7321
10586
  exports.BECF_12109_DEFAULT_ATTRIBUTES = BECF_12109_DEFAULT_ATTRIBUTES;
10587
+ exports.BECF_B_12101_DEFAULT_ATTRIBUTES = BECF_B_12101_DEFAULT_ATTRIBUTES;
10588
+ exports.BECF_B_12109_DEFAULT_ATTRIBUTES = BECF_B_12109_DEFAULT_ATTRIBUTES;
10589
+ exports.BECF_C_12101_DEFAULT_ATTRIBUTES = BECF_C_12101_DEFAULT_ATTRIBUTES;
10590
+ exports.BECF_C_12109_DEFAULT_ATTRIBUTES = BECF_C_12109_DEFAULT_ATTRIBUTES;
7322
10591
  exports.Colorbar = Colorbar;
7323
10592
  exports.DIE_LINE_LAYOUT = DIE_LINE_LAYOUT;
7324
10593
  exports.Gripper = Gripper;
7325
10594
  exports.MODEL_BECF_1010A = MODEL_BECF_1010A;
7326
10595
  exports.MODEL_BECF_1030A = MODEL_BECF_1030A;
7327
10596
  exports.MODEL_BECF_1040A = MODEL_BECF_1040A;
10597
+ exports.MODEL_BECF_10A0A = MODEL_BECF_10A0A;
7328
10598
  exports.MODEL_BECF_11D01 = MODEL_BECF_11D01;
7329
10599
  exports.MODEL_BECF_12101 = MODEL_BECF_12101;
7330
10600
  exports.MODEL_BECF_12109 = MODEL_BECF_12109;
10601
+ exports.MODEL_BECF_B_12101 = MODEL_BECF_B_12101;
10602
+ exports.MODEL_BECF_B_12109 = MODEL_BECF_B_12109;
10603
+ exports.MODEL_BECF_C_12101 = MODEL_BECF_C_12101;
10604
+ exports.MODEL_BECF_C_12109 = MODEL_BECF_C_12109;
10605
+ exports.MODEL_DEFAULT_ATTRIBUTES = MODEL_DEFAULT_ATTRIBUTES;
7331
10606
  exports.MODEL_THEME_CONFIG = MODEL_THEME_CONFIG;
7332
10607
  exports.appendColorbarToSvg = appendColorbarToSvg;
7333
10608
  exports.appendGripperToSvg = appendGripperToSvg;