@yft-design/engine 0.0.17 → 0.0.18
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/README.md +23 -11
- package/dist/EngineCanvas.d.ts +0 -255
- package/dist/core/color.d.ts +0 -11
- package/dist/core/distanceField.d.ts +0 -13
- package/dist/core/events.d.ts +0 -25
- package/dist/core/gradient.d.ts +0 -47
- package/dist/core/homography.d.ts +0 -20
- package/dist/core/imageFilters.d.ts +0 -31
- package/dist/core/mat2d.d.ts +0 -62
- package/dist/core/pathData.d.ts +0 -36
- package/dist/core/pattern.d.ts +0 -14
- package/dist/core/point.d.ts +0 -14
- package/dist/core/psdEffects.d.ts +0 -48
- package/dist/core/roundedRect.d.ts +0 -48
- package/dist/core/shadow.d.ts +0 -23
- package/dist/core/snap.d.ts +0 -103
- package/dist/core/stroke.d.ts +0 -13
- package/dist/core/triangulate.d.ts +0 -31
- package/dist/core/warpMesh.d.ts +0 -38
- package/dist/debug/canvasInspection.d.ts +0 -20
- package/dist/debug/pixelDiff.d.ts +0 -7
- package/dist/debug/pixelDiff.js +1 -64
- package/dist/debug/seed.d.ts +0 -426
- package/dist/debug/seed.js +28 -3806
- package/dist/decoders/webp2sprite.d.ts +0 -16
- package/dist/engineFlag.d.ts +0 -76
- package/dist/export/SceneExporter.d.ts +0 -58
- package/dist/export/glExport.d.ts +0 -41
- package/dist/export/svgExport.d.ts +0 -181
- package/dist/index.d.ts +0 -13
- package/dist/index.js +1060 -64
- package/dist/interact/animationPlayback.d.ts +0 -62
- package/dist/interact/canvasInteractions.d.ts +1 -38
- package/dist/interact/cropSession.d.ts +0 -68
- package/dist/interact/dblClick.d.ts +0 -32
- package/dist/interact/expandSession.d.ts +0 -46
- package/dist/interact/hotkeyActions.d.ts +0 -12
- package/dist/interact/pageTransfer.d.ts +0 -2
- package/dist/interact/pathSession.d.ts +0 -42
- package/dist/interact/pointer.d.ts +0 -87
- package/dist/interact/pointerTablePuzzle.d.ts +0 -60
- package/dist/interact/pointerTransform.d.ts +0 -48
- package/dist/interact/pointerTypes.d.ts +6 -148
- package/dist/interact/snapGuide.d.ts +0 -68
- package/dist/interact/tableCellEditing.d.ts +0 -34
- package/dist/interact/tableInteraction.d.ts +0 -31
- package/dist/interact/textEditing.d.ts +0 -44
- package/dist/interact/warpFacade.d.ts +0 -5
- package/dist/interact/warpSession.d.ts +0 -55
- package/dist/interact/wheelScroll.d.ts +0 -42
- package/dist/model/alphaHit.d.ts +0 -51
- package/dist/model/animation.d.ts +0 -99
- package/dist/model/arcLayout.d.ts +0 -33
- package/dist/model/arcTextTransform.d.ts +0 -4
- package/dist/model/compatEvents.d.ts +0 -72
- package/dist/model/compatObject.d.ts +0 -360
- package/dist/model/cropEdit.d.ts +0 -60
- package/dist/model/document.d.ts +0 -167
- package/dist/model/elementTypes.d.ts +0 -47
- package/dist/model/expandEdit.d.ts +0 -36
- package/dist/model/fabricPrimitives.d.ts +0 -24
- package/dist/model/filler.d.ts +0 -12
- package/dist/model/groupAssemble.d.ts +0 -5
- package/dist/model/groupChildMove.d.ts +0 -37
- package/dist/model/groupResize.d.ts +0 -42
- package/dist/model/handles.d.ts +0 -24
- package/dist/model/imageMaskBake.d.ts +0 -50
- package/dist/model/lineConstruct.d.ts +0 -8
- package/dist/model/maskCropEdit.d.ts +0 -34
- package/dist/model/pathBackground.d.ts +0 -33
- package/dist/model/pathConstruct.d.ts +0 -24
- package/dist/model/pathEdit.d.ts +0 -55
- package/dist/model/puzzleEdit.d.ts +0 -66
- package/dist/model/puzzleLayout.d.ts +0 -31
- package/dist/model/scene.d.ts +0 -603
- package/dist/model/schema.d.ts +0 -48
- package/dist/model/shapePath.d.ts +0 -5
- package/dist/model/smartObjectBake.d.ts +0 -6
- package/dist/model/tableEdit.d.ts +0 -90
- package/dist/model/tableFacade.d.ts +0 -5
- package/dist/model/tableLayout.d.ts +0 -40
- package/dist/model/textAlign.d.ts +0 -22
- package/dist/model/textLayout.d.ts +0 -213
- package/dist/render/GLBlend.d.ts +0 -24
- package/dist/render/GLContext.d.ts +0 -11
- package/dist/render/GLIsolate.d.ts +0 -25
- package/dist/render/GLTextureCache.d.ts +0 -72
- package/dist/render/GlyphAtlas.d.ts +0 -98
- package/dist/render/MeshBatch.d.ts +0 -71
- package/dist/render/QuadBatch.d.ts +0 -87
- package/dist/render/SceneRenderer.d.ts +0 -137
- package/dist/render/SourceManager.d.ts +0 -82
- package/dist/render/TextRenderer.d.ts +0 -120
- package/dist/render/arcText.d.ts +0 -28
- package/dist/render/bakeGate.d.ts +0 -35
- package/dist/render/batchOrder.d.ts +0 -60
- package/dist/render/blendMode.d.ts +0 -27
- package/dist/render/clipMaskPainter.d.ts +0 -42
- package/dist/render/fontInvalidation.d.ts +0 -18
- package/dist/render/fontInvalidationController.d.ts +0 -52
- package/dist/render/frameOverlay.d.ts +0 -32
- package/dist/render/framePipeline.d.ts +0 -27
- package/dist/render/gpuFilterPasses.d.ts +0 -15
- package/dist/render/gpuFx.d.ts +0 -82
- package/dist/render/gpuImageFilters.d.ts +0 -41
- package/dist/render/gpuShadow.d.ts +0 -38
- package/dist/render/gradientRamp.d.ts +0 -14
- package/dist/render/imageEffects.d.ts +0 -99
- package/dist/render/lineDecorationSdf.d.ts +0 -32
- package/dist/render/maskRender.d.ts +0 -60
- package/dist/render/multiPage.d.ts +0 -91
- package/dist/render/progressiveLoad.d.ts +0 -27
- package/dist/render/psdEffectPainter.d.ts +0 -25
- package/dist/render/psdWarpText.d.ts +0 -19
- package/dist/render/puzzleClamp.d.ts +0 -15
- package/dist/render/renderEpoch.d.ts +0 -21
- package/dist/render/retainedFrame.d.ts +0 -36
- package/dist/render/ruler.d.ts +0 -36
- package/dist/render/screenClip.d.ts +0 -31
- package/dist/render/scrollText.d.ts +0 -46
- package/dist/render/segmentTable.d.ts +0 -30
- package/dist/render/selectionOverlay.d.ts +0 -203
- package/dist/render/settleScheduler.d.ts +0 -24
- package/dist/render/shaders.d.ts +4 -24
- package/dist/render/shadowBake.d.ts +0 -28
- package/dist/render/shadowPainter.d.ts +0 -8
- package/dist/render/sharedGpuPainters.d.ts +0 -13
- package/dist/render/sourceHydration.d.ts +0 -8
- package/dist/render/strokeBake.d.ts +0 -59
- package/dist/render/strokeMiterOutline.d.ts +0 -29
- package/dist/render/strokePainter.d.ts +0 -31
- package/dist/render/strokeSdf.d.ts +0 -52
- package/dist/render/svgRaster.d.ts +0 -34
- package/dist/render/tableOverlay.d.ts +0 -35
- package/dist/render/textHighlight.d.ts +0 -67
- package/dist/render/textureUpload.d.ts +0 -13
- package/dist/render/verticalText.d.ts +0 -21
- package/dist/render/warpText.d.ts +0 -48
- package/dist/render/workspaceBackdrop.d.ts +0 -22
- package/dist/render/workspaceChecker.d.ts +0 -34
- package/dist/render/workspaceGlow.d.ts +0 -38
- package/package.json +4 -3
- package/dist/EngineCanvas.js +0 -1202
- package/dist/core/canvasPerf.js +0 -170
- package/dist/core/color.js +0 -107
- package/dist/core/distanceField.js +0 -92
- package/dist/core/events.js +0 -80
- package/dist/core/gradient.js +0 -175
- package/dist/core/homography.js +0 -123
- package/dist/core/imageFilters.js +0 -330
- package/dist/core/mat2d.js +0 -241
- package/dist/core/pathData.js +0 -926
- package/dist/core/pattern.js +0 -40
- package/dist/core/point.js +0 -119
- package/dist/core/psdEffects.js +0 -158
- package/dist/core/roundedRect.js +0 -164
- package/dist/core/shadow.js +0 -47
- package/dist/core/snap.js +0 -793
- package/dist/core/stroke.js +0 -45
- package/dist/core/triangulate.js +0 -194
- package/dist/core/warpMesh.js +0 -469
- package/dist/debug/canvasInspection.js +0 -113
- package/dist/decoders/gif2sprite.js +0 -84
- package/dist/decoders/webp2sprite.js +0 -133
- package/dist/engineFlag.js +0 -104
- package/dist/export/SceneExporter.js +0 -286
- package/dist/export/glExport.js +0 -79
- package/dist/export/svgExport.js +0 -1803
- package/dist/interact/animationPlayback.js +0 -358
- package/dist/interact/canvasInteractions.js +0 -174
- package/dist/interact/cropSession.js +0 -527
- package/dist/interact/dblClick.js +0 -120
- package/dist/interact/expandSession.js +0 -282
- package/dist/interact/hotkeyActions.js +0 -42
- package/dist/interact/pageTransfer.js +0 -56
- package/dist/interact/pathSession.js +0 -480
- package/dist/interact/pointer.js +0 -1692
- package/dist/interact/pointerTablePuzzle.js +0 -358
- package/dist/interact/pointerTransform.js +0 -441
- package/dist/interact/pointerTypes.js +0 -96
- package/dist/interact/snapGuide.js +0 -377
- package/dist/interact/tableCellEditing.js +0 -207
- package/dist/interact/tableInteraction.js +0 -219
- package/dist/interact/textEditing.js +0 -423
- package/dist/interact/warpFacade.js +0 -51
- package/dist/interact/warpSession.js +0 -583
- package/dist/interact/wheelScroll.js +0 -100
- package/dist/model/alphaHit.js +0 -267
- package/dist/model/animation.js +0 -510
- package/dist/model/arcLayout.js +0 -308
- package/dist/model/arcTextTransform.js +0 -87
- package/dist/model/compatEvents.js +0 -96
- package/dist/model/compatObject.js +0 -1583
- package/dist/model/cropEdit.js +0 -497
- package/dist/model/document.js +0 -590
- package/dist/model/elementTypes.js +0 -119
- package/dist/model/expandEdit.js +0 -161
- package/dist/model/fabricPrimitives.js +0 -9
- package/dist/model/filler.js +0 -1
- package/dist/model/groupAssemble.js +0 -98
- package/dist/model/groupChildMove.js +0 -145
- package/dist/model/groupResize.js +0 -109
- package/dist/model/handles.js +0 -29
- package/dist/model/imageMaskBake.js +0 -136
- package/dist/model/lineConstruct.js +0 -79
- package/dist/model/maskCropEdit.js +0 -90
- package/dist/model/pathBackground.js +0 -196
- package/dist/model/pathConstruct.js +0 -55
- package/dist/model/pathEdit.js +0 -378
- package/dist/model/puzzleEdit.js +0 -742
- package/dist/model/puzzleLayout.js +0 -143
- package/dist/model/scene.js +0 -2930
- package/dist/model/schema.js +0 -13
- package/dist/model/shapePath.js +0 -137
- package/dist/model/smartObjectBake.js +0 -295
- package/dist/model/tableEdit.js +0 -751
- package/dist/model/tableFacade.js +0 -808
- package/dist/model/tableLayout.js +0 -194
- package/dist/model/textAlign.js +0 -36
- package/dist/model/textLayout.js +0 -842
- package/dist/render/GLBlend.js +0 -270
- package/dist/render/GLContext.js +0 -48
- package/dist/render/GLIsolate.js +0 -188
- package/dist/render/GLTextureCache.js +0 -224
- package/dist/render/GlyphAtlas.js +0 -412
- package/dist/render/MeshBatch.js +0 -416
- package/dist/render/QuadBatch.js +0 -561
- package/dist/render/SceneRenderer.js +0 -753
- package/dist/render/SourceManager.js +0 -523
- package/dist/render/TextRenderer.js +0 -854
- package/dist/render/arcText.js +0 -187
- package/dist/render/bakeGate.js +0 -32
- package/dist/render/batchOrder.js +0 -168
- package/dist/render/blendMode.js +0 -142
- package/dist/render/clipMaskPainter.js +0 -244
- package/dist/render/fontInvalidation.js +0 -77
- package/dist/render/fontInvalidationController.js +0 -119
- package/dist/render/frameOverlay.js +0 -124
- package/dist/render/framePipeline.js +0 -96
- package/dist/render/gpuFilterPasses.js +0 -883
- package/dist/render/gpuFx.js +0 -673
- package/dist/render/gpuImageFilters.js +0 -295
- package/dist/render/gpuShadow.js +0 -327
- package/dist/render/gradientRamp.js +0 -74
- package/dist/render/imageEffects.js +0 -415
- package/dist/render/lineDecorationSdf.js +0 -189
- package/dist/render/maskRender.js +0 -217
- package/dist/render/multiPage.js +0 -420
- package/dist/render/progressiveLoad.js +0 -86
- package/dist/render/psdEffectPainter.js +0 -333
- package/dist/render/psdWarpText.js +0 -212
- package/dist/render/puzzleClamp.js +0 -30
- package/dist/render/renderEpoch.js +0 -35
- package/dist/render/renderViewport.js +0 -18
- package/dist/render/retainedFrame.js +0 -192
- package/dist/render/ruler.js +0 -287
- package/dist/render/screenClip.js +0 -67
- package/dist/render/scrollText.js +0 -266
- package/dist/render/segmentTable.js +0 -117
- package/dist/render/selectionOverlay.js +0 -1008
- package/dist/render/settleScheduler.js +0 -51
- package/dist/render/shaders.js +0 -450
- package/dist/render/shadowBake.js +0 -203
- package/dist/render/shadowPainter.js +0 -93
- package/dist/render/sharedGpuPainters.js +0 -42
- package/dist/render/sourceHydration.js +0 -48
- package/dist/render/strokeBake.js +0 -516
- package/dist/render/strokeMiterOutline.js +0 -224
- package/dist/render/strokePainter.js +0 -207
- package/dist/render/strokeSdf.js +0 -262
- package/dist/render/svgRaster.js +0 -71
- package/dist/render/tableOverlay.js +0 -233
- package/dist/render/textHighlight.js +0 -380
- package/dist/render/textureUpload.js +0 -26
- package/dist/render/verticalText.js +0 -63
- package/dist/render/warpText.js +0 -384
- package/dist/render/workspaceBackdrop.js +0 -60
- package/dist/render/workspaceChecker.js +0 -170
- package/dist/render/workspaceGlow.js +0 -198
package/dist/model/puzzleEdit.js
DELETED
|
@@ -1,742 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 拼图 Mask 级编辑纯函数(B1(余) 第一片):应用 FabricPuzzle 的
|
|
3
|
-
* handleMaskWidthResize / handleMaskHeightResize / updateGapParams /
|
|
4
|
-
* applyMaskParams 逐行移植(分割线拖拽的「段守恒 + 同列联动」语义)。
|
|
5
|
-
*
|
|
6
|
-
* 本模块只算不写:入参出参都是普通数据视图,节点/raw 的落盘与手势接线由
|
|
7
|
-
* 调用方执行(pointer 手势属下一片——应用侧交互链路为 interactive 组内
|
|
8
|
-
* 选中 + maskControls 边中点,引擎侧循表格先例做编辑会话)。
|
|
9
|
-
*
|
|
10
|
-
* 与应用的结构对应:
|
|
11
|
-
* - `spans`(colStart/colEnd/rowStart/rowEnd)↔ 应用 Mask 的 `__colStart`
|
|
12
|
-
* 等运行时元信息(fromObject/create 由 layoutConfig.pieces 逐 idx 写入);
|
|
13
|
-
* 缺失时走几何对齐兜底(EPS 0.5,应用同款)
|
|
14
|
-
* - `clip` 视图 ↔ mask.clipImage(cover×用户缩放因子防累乘、clipX/clipY 按
|
|
15
|
-
* 块比例),原图尺寸入参 `clipSizes`(元素 natural 优先、序列化 width 兜底)
|
|
16
|
-
*/
|
|
17
|
-
import { maskClipView } from './puzzleLayout';
|
|
18
|
-
/** 应用 getHorizontalInnerCount:目标块左右两侧非外框的边数(innerRadius 门控用) */
|
|
19
|
-
const horizontalInnerCount = (m, cols) => {
|
|
20
|
-
if (typeof m.colStart !== 'number' || typeof m.colEnd !== 'number' || cols <= 0)
|
|
21
|
-
return 0;
|
|
22
|
-
let count = 0;
|
|
23
|
-
if (m.colStart > 0)
|
|
24
|
-
count += 1;
|
|
25
|
-
if (m.colEnd < cols - 1)
|
|
26
|
-
count += 1;
|
|
27
|
-
return count;
|
|
28
|
-
};
|
|
29
|
-
/** 应用 getVerticalInnerCount */
|
|
30
|
-
const verticalInnerCount = (m, rows) => {
|
|
31
|
-
if (typeof m.rowStart !== 'number' || typeof m.rowEnd !== 'number' || rows <= 0)
|
|
32
|
-
return 0;
|
|
33
|
-
let count = 0;
|
|
34
|
-
if (m.rowStart > 0)
|
|
35
|
-
count += 1;
|
|
36
|
-
if (m.rowEnd < rows - 1)
|
|
37
|
-
count += 1;
|
|
38
|
-
return count;
|
|
39
|
-
};
|
|
40
|
-
const box = (m) => ({
|
|
41
|
-
left: m.left - m.width / 2,
|
|
42
|
-
right: m.left + m.width / 2,
|
|
43
|
-
top: m.top - m.height / 2,
|
|
44
|
-
bottom: m.top + m.height / 2
|
|
45
|
-
});
|
|
46
|
-
/** clip 同步(应用同款三处复制体:cover×userFactor + clipX/clipY 按块比例) */
|
|
47
|
-
const syncClip = (mask, prevW, prevH, size) => {
|
|
48
|
-
if (!mask.clip)
|
|
49
|
-
return;
|
|
50
|
-
const newW = mask.width;
|
|
51
|
-
const newH = mask.height;
|
|
52
|
-
const ratioX = prevW ? newW / prevW : 1;
|
|
53
|
-
const ratioY = prevH ? newH / prevH : 1;
|
|
54
|
-
const s = size ?? { w: mask.clip.width, h: mask.clip.height };
|
|
55
|
-
if (s.w && s.h) {
|
|
56
|
-
const oldCover = Math.max(prevW / s.w, prevH / s.h);
|
|
57
|
-
const newCover = Math.max(newW / s.w, newH / s.h);
|
|
58
|
-
const prevScale = mask.clip.scaleX || mask.clip.scaleY || 1;
|
|
59
|
-
const userFactor = oldCover ? prevScale / oldCover : 1;
|
|
60
|
-
const nextScale = newCover * (userFactor || 1);
|
|
61
|
-
mask.clip.scaleX = nextScale;
|
|
62
|
-
mask.clip.scaleY = nextScale;
|
|
63
|
-
}
|
|
64
|
-
mask.clip.clipX = (mask.clip.clipX || 0) * ratioX;
|
|
65
|
-
mask.clip.clipY = (mask.clip.clipY || 0) * ratioY;
|
|
66
|
-
};
|
|
67
|
-
/**
|
|
68
|
-
* 拖拽目标块的右/左边缘改宽(段守恒框架承自应用 handleMaskWidthResize,
|
|
69
|
-
* 邻块重分配改为逐块远缘守恒——2026-10-08 马赛克布局报障):
|
|
70
|
-
* - 与拖拽方向上最近一列的邻块重分配:目标锚定对侧缘,各邻块近缘贴新
|
|
71
|
-
* 分割线(保留 hGap)、远缘各自守恒;双方都 ≥ minWidth(max(innerRadius+1, 12))。
|
|
72
|
-
* 应用原版把邻列联合边界(min 左缘/max 右缘)当段端且整列同宽同中心——
|
|
73
|
-
* 邻列内 span 不齐(单列格+跨列格同列起)时跨列格外缘污染段端,单列格被
|
|
74
|
-
* 钉到拼图外缘;均匀网格下本式与原版数值恒等
|
|
75
|
-
* - 同列的其它块跟随目标列新边界;只共享被拖分割线的块贴边跟随
|
|
76
|
-
* (span 元信息优先,几何对齐 EPS 0.5 兜底)
|
|
77
|
-
* - 无邻块(单列/退化):单块宽度钳制在拼图内部
|
|
78
|
-
* 返回是否发生宽度变化(false = 拒绝或无变化)。
|
|
79
|
-
*/
|
|
80
|
-
export const handlePuzzleMaskWidthResize = (state, targetIdx, newWidth, edge = 'right', clipSizes) => {
|
|
81
|
-
const target = state.masks[targetIdx];
|
|
82
|
-
if (!target)
|
|
83
|
-
return false;
|
|
84
|
-
const minWidth = Math.max(state.innerRadius + 1, 12);
|
|
85
|
-
if (newWidth <= minWidth)
|
|
86
|
-
return false;
|
|
87
|
-
if (!state.layoutWidth)
|
|
88
|
-
return false;
|
|
89
|
-
const padding = state.groupPadding || 0;
|
|
90
|
-
const innerW = Math.max(0, state.layoutWidth - padding * 2);
|
|
91
|
-
const minPieceWidth = 1;
|
|
92
|
-
const prevWidth = target.width || 0;
|
|
93
|
-
const prevHeight = target.height || 0;
|
|
94
|
-
if (!innerW || !prevWidth)
|
|
95
|
-
return false;
|
|
96
|
-
// innerRadius 门控:非外框的边须为圆角留出过渡区(应用同款上下限)
|
|
97
|
-
const perInnerMarginW = state.innerRadius + 1;
|
|
98
|
-
const minByInnerRuleW = horizontalInnerCount(target, state.cols) * perInnerMarginW;
|
|
99
|
-
if (newWidth < minByInnerRuleW)
|
|
100
|
-
return false;
|
|
101
|
-
const maxByInnerRuleW = innerW - minByInnerRuleW;
|
|
102
|
-
const limitedNewWidth = Math.min(newWidth, Math.max(minPieceWidth, maxByInnerRuleW));
|
|
103
|
-
const tb = box(target);
|
|
104
|
-
const hGap = state.hGap || 0;
|
|
105
|
-
// 邻块查找:同「行」(垂直重叠 ≥30%)、在拖拽方向一侧、最近一列(EPS 5)
|
|
106
|
-
const neighbors = [];
|
|
107
|
-
let bestCoord = null;
|
|
108
|
-
const COL_EPS = 5;
|
|
109
|
-
const V_OVERLAP_RATIO = 0.3;
|
|
110
|
-
state.masks.forEach((m, idx) => {
|
|
111
|
-
if (idx === targetIdx)
|
|
112
|
-
return;
|
|
113
|
-
const b = box(m);
|
|
114
|
-
const overlapV = Math.min(tb.bottom, b.bottom) - Math.max(tb.top, b.top);
|
|
115
|
-
if (overlapV <= 0 || overlapV < Math.min(target.height, m.height) * V_OVERLAP_RATIO)
|
|
116
|
-
return;
|
|
117
|
-
if (edge === 'right') {
|
|
118
|
-
if (b.left <= target.left)
|
|
119
|
-
return;
|
|
120
|
-
const coord = b.left;
|
|
121
|
-
if (bestCoord === null || coord < bestCoord - COL_EPS) {
|
|
122
|
-
bestCoord = coord;
|
|
123
|
-
neighbors.length = 0;
|
|
124
|
-
neighbors.push(idx);
|
|
125
|
-
}
|
|
126
|
-
else if (Math.abs(coord - bestCoord) <= COL_EPS) {
|
|
127
|
-
neighbors.push(idx);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
else {
|
|
131
|
-
if (b.right >= target.left)
|
|
132
|
-
return;
|
|
133
|
-
const coord = b.right;
|
|
134
|
-
if (bestCoord === null || coord > bestCoord + COL_EPS) {
|
|
135
|
-
bestCoord = coord;
|
|
136
|
-
neighbors.length = 0;
|
|
137
|
-
neighbors.push(idx);
|
|
138
|
-
}
|
|
139
|
-
else if (Math.abs(coord - bestCoord) <= COL_EPS) {
|
|
140
|
-
neighbors.push(idx);
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
const sizeOf = (idx) => clipSizes?.[idx] ?? null;
|
|
145
|
-
// 无邻块:锚定对侧边钳制在内区(拖右缘固定左缘、拖左缘固定右缘——旧版只改
|
|
146
|
-
// width 绕中心双向生长,块会压向邻列且被拖边跟不上指针;应用侧同批修复)
|
|
147
|
-
if (!neighbors.length) {
|
|
148
|
-
const halfInnerW = innerW / 2;
|
|
149
|
-
const maxByAnchor = edge === 'right' ? halfInnerW - tb.left : tb.right + halfInnerW;
|
|
150
|
-
const finalWidth = Math.max(minWidth, Math.min(limitedNewWidth, Math.max(minWidth, maxByAnchor)));
|
|
151
|
-
if (finalWidth === prevWidth)
|
|
152
|
-
return false;
|
|
153
|
-
target.left = edge === 'right' ? tb.left + finalWidth / 2 : tb.right - finalWidth / 2;
|
|
154
|
-
target.width = finalWidth;
|
|
155
|
-
syncClip(target, prevWidth, prevHeight, sizeOf(targetIdx));
|
|
156
|
-
return true;
|
|
157
|
-
}
|
|
158
|
-
// 邻块「近缘贴新分割线、远缘各自守恒」(马赛克报障改版):邻列内 span 不齐
|
|
159
|
-
// (同列起点既有单列格又有跨列格)时,旧版联合右缘 = max(邻块右缘) 会把跨列
|
|
160
|
-
// 邻块的外缘当成整列段端,单列邻块被改宽钉到拼图外缘。逐邻块按自身远缘守恒
|
|
161
|
-
// ——均匀网格(邻列远缘全同)下与旧段守恒公式数值恒等
|
|
162
|
-
let neighborOldLeft = Infinity;
|
|
163
|
-
let neighborOldRight = -Infinity;
|
|
164
|
-
for (const idx of neighbors) {
|
|
165
|
-
const b = box(state.masks[idx]);
|
|
166
|
-
if (b.left < neighborOldLeft)
|
|
167
|
-
neighborOldLeft = b.left;
|
|
168
|
-
if (b.right > neighborOldRight)
|
|
169
|
-
neighborOldRight = b.right;
|
|
170
|
-
}
|
|
171
|
-
const anchor = edge === 'right' ? tb.left : tb.right;
|
|
172
|
-
const farOf = (idx) => {
|
|
173
|
-
const b = box(state.masks[idx]);
|
|
174
|
-
return edge === 'right' ? b.right : b.left;
|
|
175
|
-
};
|
|
176
|
-
let maxTargetWidthRaw = Infinity;
|
|
177
|
-
for (const idx of neighbors) {
|
|
178
|
-
const room = (edge === 'right' ? farOf(idx) - anchor : anchor - farOf(idx)) - hGap - minWidth;
|
|
179
|
-
if (room < maxTargetWidthRaw)
|
|
180
|
-
maxTargetWidthRaw = room;
|
|
181
|
-
}
|
|
182
|
-
const clampedTargetWidth = Math.max(minWidth, Math.min(limitedNewWidth, Math.max(minWidth, maxTargetWidthRaw)));
|
|
183
|
-
const seamNew = edge === 'right' ? anchor + clampedTargetWidth : anchor - clampedTargetWidth;
|
|
184
|
-
// 任一邻块保不住 minWidth = 段内放不下(旧版 maxTargetWidthForNeighbor 拒绝
|
|
185
|
-
// 路径的等价形态),无写入直接拒;边界钳制时窄邻块恰落在 minWidth 上,
|
|
186
|
-
// 容浮点噪声 1e-6
|
|
187
|
-
for (const idx of neighbors) {
|
|
188
|
-
if ((edge === 'right' ? farOf(idx) - seamNew : seamNew - farOf(idx)) - hGap < minWidth - 1e-6)
|
|
189
|
-
return false;
|
|
190
|
-
}
|
|
191
|
-
if (clampedTargetWidth <= 0)
|
|
192
|
-
return false;
|
|
193
|
-
target.left = edge === 'right' ? anchor + clampedTargetWidth / 2 : anchor - clampedTargetWidth / 2;
|
|
194
|
-
target.width = clampedTargetWidth;
|
|
195
|
-
const prevMap = new Map();
|
|
196
|
-
prevMap.set(targetIdx, { width: prevWidth, height: prevHeight });
|
|
197
|
-
for (const idx of neighbors) {
|
|
198
|
-
const n = state.masks[idx];
|
|
199
|
-
prevMap.set(idx, { width: n.width, height: n.height });
|
|
200
|
-
const far = farOf(idx);
|
|
201
|
-
if (edge === 'right') {
|
|
202
|
-
n.width = far - seamNew - hGap;
|
|
203
|
-
n.left = (seamNew + hGap + far) / 2;
|
|
204
|
-
}
|
|
205
|
-
else {
|
|
206
|
-
n.width = seamNew - hGap - far;
|
|
207
|
-
n.left = (seamNew - hGap + far) / 2;
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
for (const idx of [targetIdx, ...neighbors]) {
|
|
211
|
-
const prev = prevMap.get(idx);
|
|
212
|
-
syncClip(state.masks[idx], prev.width, prev.height, sizeOf(idx));
|
|
213
|
-
}
|
|
214
|
-
// 同列/共边块联动(span 元信息优先,几何兜底)。列边界取变更后实盒:
|
|
215
|
-
// 目标列 = 目标自身新盒;邻列 = 首邻块新盒(近缘已贴新分割线、远缘守恒)
|
|
216
|
-
const tbNew = box(target);
|
|
217
|
-
const tNewLeft = tbNew.left;
|
|
218
|
-
const tNewRight = tbNew.right;
|
|
219
|
-
const nb0 = box(state.masks[neighbors[0]]);
|
|
220
|
-
const nNewLeft = nb0.left;
|
|
221
|
-
const nNewRight = nb0.right;
|
|
222
|
-
const internalOld = edge === 'right' ? tb.right : tb.left;
|
|
223
|
-
const internalNew = edge === 'right' ? tNewRight : tNewLeft;
|
|
224
|
-
const neighborSet = new Set(neighbors);
|
|
225
|
-
const targetSpan = typeof target.colStart === 'number' && typeof target.colEnd === 'number' ? { colStart: target.colStart, colEnd: target.colEnd } : null;
|
|
226
|
-
const firstNeighbor = state.masks[neighbors[0]];
|
|
227
|
-
const firstNeighborSpan = firstNeighbor && typeof firstNeighbor.colStart === 'number' && typeof firstNeighbor.colEnd === 'number' ? { colStart: firstNeighbor.colStart, colEnd: firstNeighbor.colEnd } : null;
|
|
228
|
-
const canUseIndex = state.cols > 0 && !!targetSpan && !!firstNeighborSpan;
|
|
229
|
-
const applyColResize = (idx, newLeft, newRight) => {
|
|
230
|
-
const m = state.masks[idx];
|
|
231
|
-
const prevW = m.width;
|
|
232
|
-
const prevH = m.height;
|
|
233
|
-
const newW = Math.max(minPieceWidth, newRight - newLeft);
|
|
234
|
-
m.left = (newLeft + newRight) / 2;
|
|
235
|
-
m.width = newW;
|
|
236
|
-
syncClip(m, prevW, prevH, sizeOf(idx));
|
|
237
|
-
};
|
|
238
|
-
state.masks.forEach((m, idx) => {
|
|
239
|
-
if (idx === targetIdx || neighborSet.has(idx))
|
|
240
|
-
return;
|
|
241
|
-
const b = box(m);
|
|
242
|
-
const oldLeft = b.left;
|
|
243
|
-
const oldRight = b.right;
|
|
244
|
-
if (canUseIndex && targetSpan && firstNeighborSpan && typeof m.colStart === 'number' && typeof m.colEnd === 'number') {
|
|
245
|
-
// 1. 与目标列完全一致 → 跟随目标列新边界
|
|
246
|
-
if (m.colStart === targetSpan.colStart && m.colEnd === targetSpan.colEnd) {
|
|
247
|
-
applyColResize(idx, tNewLeft, tNewRight);
|
|
248
|
-
return;
|
|
249
|
-
}
|
|
250
|
-
// 2. 与邻块列完全一致
|
|
251
|
-
if (m.colStart === firstNeighborSpan.colStart && m.colEnd === firstNeighborSpan.colEnd) {
|
|
252
|
-
applyColResize(idx, nNewLeft, nNewRight);
|
|
253
|
-
return;
|
|
254
|
-
}
|
|
255
|
-
// 3. 只共享被拖的内部竖向边界。缝在**邻侧**的共享边须让出 hGap(与邻块
|
|
256
|
-
// 主段摆位同口径:目标侧贴 internalNew、邻侧贴 internalNew ± hGap——
|
|
257
|
-
// 旧版两侧都贴 internalNew,共边块被拉过间隙抵住目标)
|
|
258
|
-
const internalBoundaryIndex = edge === 'right' ? targetSpan.colEnd + 1 : targetSpan.colStart;
|
|
259
|
-
const shareLeft = m.colStart === internalBoundaryIndex;
|
|
260
|
-
const shareRight = m.colEnd + 1 === internalBoundaryIndex;
|
|
261
|
-
if (!shareLeft && !shareRight)
|
|
262
|
-
return;
|
|
263
|
-
const newLeft = shareLeft ? internalNew + (edge === 'right' ? hGap : 0) : oldLeft;
|
|
264
|
-
const newRight = shareRight ? internalNew - (edge === 'left' ? hGap : 0) : oldRight;
|
|
265
|
-
if (newRight - newLeft <= 0)
|
|
266
|
-
return;
|
|
267
|
-
applyColResize(idx, newLeft, newRight);
|
|
268
|
-
return;
|
|
269
|
-
}
|
|
270
|
-
// 兜底:几何对齐(EPS 0.5)
|
|
271
|
-
const EPS = 0.5;
|
|
272
|
-
if (Math.abs(oldLeft - tb.left) < EPS && Math.abs(oldRight - tb.right) < EPS) {
|
|
273
|
-
applyColResize(idx, tNewLeft, tNewRight);
|
|
274
|
-
return;
|
|
275
|
-
}
|
|
276
|
-
if (Math.abs(oldLeft - neighborOldLeft) < EPS && Math.abs(oldRight - neighborOldRight) < EPS) {
|
|
277
|
-
applyColResize(idx, nNewLeft, nNewRight);
|
|
278
|
-
return;
|
|
279
|
-
}
|
|
280
|
-
const shareLeft = Math.abs(oldLeft - internalOld) < EPS;
|
|
281
|
-
const shareRight = Math.abs(oldRight - internalOld) < EPS;
|
|
282
|
-
if (!shareLeft && !shareRight)
|
|
283
|
-
return;
|
|
284
|
-
const newLeft = shareLeft ? internalNew : oldLeft;
|
|
285
|
-
const newRight = shareRight ? internalNew : oldRight;
|
|
286
|
-
if (newRight - newLeft <= 0)
|
|
287
|
-
return;
|
|
288
|
-
applyColResize(idx, newLeft, newRight);
|
|
289
|
-
});
|
|
290
|
-
return target.width !== prevWidth;
|
|
291
|
-
};
|
|
292
|
-
/**
|
|
293
|
-
* 拖拽目标块的下/上边缘改高(应用 handleMaskHeightResize 逐行同源;行版
|
|
294
|
-
* 邻块是「最近一块」而非一列):段总高守恒(保留 vGap)、双方 ≥ minHeight、
|
|
295
|
-
* 同行/共边块联动。共边块贴边(规则3 span 路径)缝在邻侧让出 vGap——应用
|
|
296
|
-
* 原版两侧都贴 internalNew,共边块被拉过间隙抵住目标(2026-10-08 续报障)。
|
|
297
|
-
* 返回是否发生高度变化。
|
|
298
|
-
*/
|
|
299
|
-
export const handlePuzzleMaskHeightResize = (state, targetIdx, newHeight, edge = 'bottom', clipSizes) => {
|
|
300
|
-
const target = state.masks[targetIdx];
|
|
301
|
-
if (!target)
|
|
302
|
-
return false;
|
|
303
|
-
const minHeight = Math.max(state.innerRadius + 1, 12);
|
|
304
|
-
if (newHeight <= minHeight)
|
|
305
|
-
return false;
|
|
306
|
-
if (!state.layoutHeight)
|
|
307
|
-
return false;
|
|
308
|
-
const padding = state.groupPadding || 0;
|
|
309
|
-
const innerH = Math.max(0, state.layoutHeight - padding * 2);
|
|
310
|
-
const minPieceHeight = 1;
|
|
311
|
-
const prevHeight = target.height || 0;
|
|
312
|
-
const prevWidth = target.width || 0;
|
|
313
|
-
if (!innerH || !prevHeight)
|
|
314
|
-
return false;
|
|
315
|
-
const perInnerMarginH = state.innerRadius + 1;
|
|
316
|
-
const minByInnerRuleH = verticalInnerCount(target, state.rows) * perInnerMarginH;
|
|
317
|
-
if (newHeight < minByInnerRuleH)
|
|
318
|
-
return false;
|
|
319
|
-
const maxByInnerRuleH = innerH - minByInnerRuleH;
|
|
320
|
-
const limitedNewHeight = Math.min(newHeight, Math.max(minPieceHeight, maxByInnerRuleH));
|
|
321
|
-
const tb = box(target);
|
|
322
|
-
const vGap = state.vGap || 0;
|
|
323
|
-
// 邻块:同「列」(水平重叠 ≥30%)、拖拽方向一侧、最近一块
|
|
324
|
-
let neighborIdx = -1;
|
|
325
|
-
let neighborTop = 0;
|
|
326
|
-
let neighborBottom = 0;
|
|
327
|
-
const H_OVERLAP_RATIO = 0.3;
|
|
328
|
-
state.masks.forEach((m, idx) => {
|
|
329
|
-
if (idx === targetIdx)
|
|
330
|
-
return;
|
|
331
|
-
const b = box(m);
|
|
332
|
-
const overlapH = Math.min(tb.right, b.right) - Math.max(tb.left, b.left);
|
|
333
|
-
if (overlapH <= 0 || overlapH < Math.min(target.width, m.width) * H_OVERLAP_RATIO)
|
|
334
|
-
return;
|
|
335
|
-
if (edge === 'bottom') {
|
|
336
|
-
if (b.top <= target.top)
|
|
337
|
-
return;
|
|
338
|
-
if (neighborIdx === -1 || b.top < neighborTop) {
|
|
339
|
-
neighborIdx = idx;
|
|
340
|
-
neighborTop = b.top;
|
|
341
|
-
neighborBottom = b.bottom;
|
|
342
|
-
}
|
|
343
|
-
}
|
|
344
|
-
else {
|
|
345
|
-
if (b.bottom >= target.top)
|
|
346
|
-
return;
|
|
347
|
-
if (neighborIdx === -1 || b.bottom > neighborBottom) {
|
|
348
|
-
neighborIdx = idx;
|
|
349
|
-
neighborTop = b.top;
|
|
350
|
-
neighborBottom = b.bottom;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
});
|
|
354
|
-
const sizeOf = (idx) => clipSizes?.[idx] ?? null;
|
|
355
|
-
// 无邻块:锚定对侧边钳制在内区(拖下缘固定上缘、拖上缘固定下缘——宽轴同批修复)
|
|
356
|
-
if (neighborIdx === -1) {
|
|
357
|
-
const halfInnerH = innerH / 2;
|
|
358
|
-
const maxByAnchor = edge === 'bottom' ? halfInnerH - tb.top : tb.bottom + halfInnerH;
|
|
359
|
-
const finalHeight = Math.max(minHeight, Math.min(limitedNewHeight, Math.max(minHeight, maxByAnchor)));
|
|
360
|
-
if (finalHeight === prevHeight)
|
|
361
|
-
return false;
|
|
362
|
-
target.top = edge === 'bottom' ? tb.top + finalHeight / 2 : tb.bottom - finalHeight / 2;
|
|
363
|
-
target.height = finalHeight;
|
|
364
|
-
syncClip(target, prevWidth, prevHeight, sizeOf(targetIdx));
|
|
365
|
-
return true;
|
|
366
|
-
}
|
|
367
|
-
const segmentTop = edge === 'bottom' ? tb.top : neighborTop;
|
|
368
|
-
const segmentBottom = edge === 'bottom' ? neighborBottom : tb.bottom;
|
|
369
|
-
const segmentHeight = segmentBottom - segmentTop;
|
|
370
|
-
const maxTargetHeight = Math.max(minHeight, segmentHeight - vGap - minHeight);
|
|
371
|
-
let clampedTargetHeight = Math.max(minHeight, Math.min(limitedNewHeight, maxTargetHeight));
|
|
372
|
-
let newNeighborHeight = segmentHeight - vGap - clampedTargetHeight;
|
|
373
|
-
if (newNeighborHeight < minHeight) {
|
|
374
|
-
const maxTargetHeightForNeighbor = segmentHeight - vGap - minHeight;
|
|
375
|
-
if (maxTargetHeightForNeighbor < minHeight)
|
|
376
|
-
return false;
|
|
377
|
-
clampedTargetHeight = Math.max(minHeight, Math.min(limitedNewHeight, maxTargetHeightForNeighbor));
|
|
378
|
-
newNeighborHeight = segmentHeight - vGap - clampedTargetHeight;
|
|
379
|
-
if (newNeighborHeight < minHeight)
|
|
380
|
-
return false;
|
|
381
|
-
}
|
|
382
|
-
if (clampedTargetHeight <= 0 || newNeighborHeight <= 0)
|
|
383
|
-
return false;
|
|
384
|
-
let newTargetCy;
|
|
385
|
-
let newNeighborCy;
|
|
386
|
-
if (edge === 'bottom') {
|
|
387
|
-
newTargetCy = segmentTop + clampedTargetHeight / 2;
|
|
388
|
-
newNeighborCy = segmentBottom - newNeighborHeight / 2;
|
|
389
|
-
}
|
|
390
|
-
else {
|
|
391
|
-
newNeighborCy = segmentTop + newNeighborHeight / 2;
|
|
392
|
-
newTargetCy = segmentBottom - clampedTargetHeight / 2;
|
|
393
|
-
}
|
|
394
|
-
const prevMap = new Map();
|
|
395
|
-
prevMap.set(targetIdx, { width: prevWidth, height: prevHeight });
|
|
396
|
-
prevMap.set(neighborIdx, { width: state.masks[neighborIdx].width, height: state.masks[neighborIdx].height });
|
|
397
|
-
target.top = newTargetCy;
|
|
398
|
-
target.height = clampedTargetHeight;
|
|
399
|
-
const nb = state.masks[neighborIdx];
|
|
400
|
-
nb.top = newNeighborCy;
|
|
401
|
-
nb.height = newNeighborHeight;
|
|
402
|
-
for (const idx of [targetIdx, neighborIdx]) {
|
|
403
|
-
const prev = prevMap.get(idx);
|
|
404
|
-
syncClip(state.masks[idx], prev.width, prev.height, sizeOf(idx));
|
|
405
|
-
}
|
|
406
|
-
// 同行/共边块联动
|
|
407
|
-
const tNewTop = newTargetCy - clampedTargetHeight / 2;
|
|
408
|
-
const tNewBottom = newTargetCy + clampedTargetHeight / 2;
|
|
409
|
-
const nNewTop = newNeighborCy - newNeighborHeight / 2;
|
|
410
|
-
const nNewBottom = newNeighborCy + newNeighborHeight / 2;
|
|
411
|
-
// 应用口径:upper = 段的上块、lower = 段的下块(新边界按行归属分发)
|
|
412
|
-
const targetIsUpper = edge === 'bottom';
|
|
413
|
-
const upperNewTop = targetIsUpper ? tNewTop : nNewTop;
|
|
414
|
-
const upperNewBottom = targetIsUpper ? tNewBottom : nNewBottom;
|
|
415
|
-
const lowerNewTop = targetIsUpper ? nNewTop : tNewTop;
|
|
416
|
-
const lowerNewBottom = targetIsUpper ? nNewBottom : tNewBottom;
|
|
417
|
-
const upperOldTop = targetIsUpper ? tb.top : neighborTop;
|
|
418
|
-
const upperOldBottom = targetIsUpper ? tb.bottom : neighborBottom;
|
|
419
|
-
const lowerOldTop = targetIsUpper ? neighborTop : tb.top;
|
|
420
|
-
const lowerOldBottom = targetIsUpper ? neighborBottom : tb.bottom;
|
|
421
|
-
const internalOld = edge === 'bottom' ? tb.bottom : tb.top;
|
|
422
|
-
const internalNew = edge === 'bottom' ? tNewBottom : tNewTop;
|
|
423
|
-
const targetRowSpan = typeof target.rowStart === 'number' && typeof target.rowEnd === 'number' ? { rowStart: target.rowStart, rowEnd: target.rowEnd } : null;
|
|
424
|
-
const nbSpan = state.masks[neighborIdx];
|
|
425
|
-
const neighborRowSpan = nbSpan && typeof nbSpan.rowStart === 'number' && typeof nbSpan.rowEnd === 'number' ? { rowStart: nbSpan.rowStart, rowEnd: nbSpan.rowEnd } : null;
|
|
426
|
-
const canUseIndex = state.rows > 0 && !!targetRowSpan && !!neighborRowSpan;
|
|
427
|
-
const upperRowSpan = canUseIndex && targetRowSpan && neighborRowSpan ? (targetRowSpan.rowStart <= neighborRowSpan.rowStart ? targetRowSpan : neighborRowSpan) : null;
|
|
428
|
-
const lowerRowSpan = canUseIndex && targetRowSpan && neighborRowSpan ? (upperRowSpan === targetRowSpan ? neighborRowSpan : targetRowSpan) : null;
|
|
429
|
-
const internalRowBoundaryIndex = upperRowSpan ? upperRowSpan.rowEnd + 1 : undefined;
|
|
430
|
-
const applyRowResize = (idx, newTop, newBottom) => {
|
|
431
|
-
const m = state.masks[idx];
|
|
432
|
-
const prevW = m.width;
|
|
433
|
-
const prevH = m.height;
|
|
434
|
-
const newH = Math.max(minPieceHeight, newBottom - newTop);
|
|
435
|
-
m.top = (newTop + newBottom) / 2;
|
|
436
|
-
m.height = newH;
|
|
437
|
-
syncClip(m, prevW, prevH, sizeOf(idx));
|
|
438
|
-
};
|
|
439
|
-
state.masks.forEach((m, idx) => {
|
|
440
|
-
if (idx === targetIdx || idx === neighborIdx)
|
|
441
|
-
return;
|
|
442
|
-
const b = box(m);
|
|
443
|
-
const oldTop = b.top;
|
|
444
|
-
const oldBottom = b.bottom;
|
|
445
|
-
if (canUseIndex && upperRowSpan && lowerRowSpan && internalRowBoundaryIndex !== undefined && typeof m.rowStart === 'number' && typeof m.rowEnd === 'number') {
|
|
446
|
-
if (m.rowStart === upperRowSpan.rowStart && m.rowEnd === upperRowSpan.rowEnd) {
|
|
447
|
-
applyRowResize(idx, upperNewTop, upperNewBottom);
|
|
448
|
-
return;
|
|
449
|
-
}
|
|
450
|
-
if (m.rowStart === lowerRowSpan.rowStart && m.rowEnd === lowerRowSpan.rowEnd) {
|
|
451
|
-
applyRowResize(idx, lowerNewTop, lowerNewBottom);
|
|
452
|
-
return;
|
|
453
|
-
}
|
|
454
|
-
// 只共享被拖的内部横向边界:缝在邻侧(shareTop 于 edge=bottom / shareBottom
|
|
455
|
-
// 于 edge=top)让出 vGap——宽度轴规则3 同批修复口径
|
|
456
|
-
const shareTop = m.rowStart === internalRowBoundaryIndex;
|
|
457
|
-
const shareBottom = m.rowEnd + 1 === internalRowBoundaryIndex;
|
|
458
|
-
if (!shareTop && !shareBottom)
|
|
459
|
-
return;
|
|
460
|
-
const newTop = shareTop ? internalNew + (edge === 'bottom' ? vGap : 0) : oldTop;
|
|
461
|
-
const newBottom = shareBottom ? internalNew - (edge === 'top' ? vGap : 0) : oldBottom;
|
|
462
|
-
if (newBottom - newTop <= 0)
|
|
463
|
-
return;
|
|
464
|
-
applyRowResize(idx, newTop, newBottom);
|
|
465
|
-
return;
|
|
466
|
-
}
|
|
467
|
-
const EPS = 0.5;
|
|
468
|
-
if (Math.abs(oldTop - upperOldTop) < EPS && Math.abs(oldBottom - upperOldBottom) < EPS) {
|
|
469
|
-
applyRowResize(idx, upperNewTop, upperNewBottom);
|
|
470
|
-
return;
|
|
471
|
-
}
|
|
472
|
-
if (Math.abs(oldTop - lowerOldTop) < EPS && Math.abs(oldBottom - lowerOldBottom) < EPS) {
|
|
473
|
-
applyRowResize(idx, lowerNewTop, lowerNewBottom);
|
|
474
|
-
return;
|
|
475
|
-
}
|
|
476
|
-
const shareTop = Math.abs(oldTop - internalOld) < EPS;
|
|
477
|
-
const shareBottom = Math.abs(oldBottom - internalOld) < EPS;
|
|
478
|
-
if (!shareTop && !shareBottom)
|
|
479
|
-
return;
|
|
480
|
-
const newTop = shareTop ? internalNew : oldTop;
|
|
481
|
-
const newBottom = shareBottom ? internalNew : oldBottom;
|
|
482
|
-
if (newBottom - newTop <= 0)
|
|
483
|
-
return;
|
|
484
|
-
applyRowResize(idx, newTop, newBottom);
|
|
485
|
-
});
|
|
486
|
-
return target.height !== prevHeight;
|
|
487
|
-
};
|
|
488
|
-
/**
|
|
489
|
-
* 间距/外框参数更新(应用 updateGapParams 逐行同源):保持拼图整体尺寸与
|
|
490
|
-
* 当前布局比例(不重置用户手动调整过的块),间距占用变化按 delta 均摊进
|
|
491
|
-
* 每块的宽高与中心;无变化早退 false。
|
|
492
|
-
*/
|
|
493
|
-
export const updatePuzzleGapParams = (state, pieces, next, clipSizes) => {
|
|
494
|
-
const prevHGap = state.hGap ?? 0;
|
|
495
|
-
const prevVGap = state.vGap ?? 0;
|
|
496
|
-
const prevGroupPadding = state.groupPadding ?? 0;
|
|
497
|
-
if (typeof next.hGap === 'number')
|
|
498
|
-
state.hGap = next.hGap;
|
|
499
|
-
if (typeof next.vGap === 'number')
|
|
500
|
-
state.vGap = next.vGap;
|
|
501
|
-
if (typeof next.groupPadding === 'number')
|
|
502
|
-
state.groupPadding = next.groupPadding;
|
|
503
|
-
const hGapDelta = (state.hGap ?? 0) - prevHGap;
|
|
504
|
-
const vGapDelta = (state.vGap ?? 0) - prevVGap;
|
|
505
|
-
const groupPaddingDelta = (state.groupPadding ?? 0) - prevGroupPadding;
|
|
506
|
-
if (hGapDelta === 0 && vGapDelta === 0 && groupPaddingDelta === 0)
|
|
507
|
-
return false;
|
|
508
|
-
if (state.masks.length === 0)
|
|
509
|
-
return false;
|
|
510
|
-
const { rows, cols } = state;
|
|
511
|
-
const totalHGapDelta = hGapDelta * Math.max(0, cols - 1);
|
|
512
|
-
const totalVGapDelta = vGapDelta * Math.max(0, rows - 1);
|
|
513
|
-
const innerWDelta = -groupPaddingDelta * 2 - totalHGapDelta;
|
|
514
|
-
const innerHDelta = -groupPaddingDelta * 2 - totalVGapDelta;
|
|
515
|
-
const cellWDelta = cols > 0 ? innerWDelta / cols : 0;
|
|
516
|
-
const cellHDelta = rows > 0 ? innerHDelta / rows : 0;
|
|
517
|
-
const stepXDelta = cellWDelta + hGapDelta;
|
|
518
|
-
const stepYDelta = cellHDelta + vGapDelta;
|
|
519
|
-
const centerColBase = (cols - 1) / 2;
|
|
520
|
-
const centerRowBase = (rows - 1) / 2;
|
|
521
|
-
pieces.forEach((piece, idx) => {
|
|
522
|
-
const mask = state.masks[idx];
|
|
523
|
-
if (!mask)
|
|
524
|
-
return;
|
|
525
|
-
const colSpan = piece.colSpan ?? 1;
|
|
526
|
-
const rowSpan = piece.rowSpan ?? 1;
|
|
527
|
-
const wDelta = cellWDelta * colSpan + hGapDelta * (colSpan - 1);
|
|
528
|
-
const hDelta = cellHDelta * rowSpan + vGapDelta * (rowSpan - 1);
|
|
529
|
-
const centerCol = piece.col + (colSpan - 1) / 2;
|
|
530
|
-
const centerRow = piece.row + (rowSpan - 1) / 2;
|
|
531
|
-
const cxDelta = (centerCol - centerColBase) * stepXDelta;
|
|
532
|
-
const cyDelta = (centerRow - centerRowBase) * stepYDelta;
|
|
533
|
-
const prevW = mask.width || 0;
|
|
534
|
-
const prevH = mask.height || 0;
|
|
535
|
-
mask.left = (mask.left || 0) + cxDelta;
|
|
536
|
-
mask.top = (mask.top || 0) + cyDelta;
|
|
537
|
-
mask.width = Math.max(prevW + wDelta, 1);
|
|
538
|
-
mask.height = Math.max(prevH + hDelta, 1);
|
|
539
|
-
syncClip(mask, prevW, prevH, clipSizes?.[idx] ?? null);
|
|
540
|
-
});
|
|
541
|
-
return true;
|
|
542
|
-
};
|
|
543
|
-
/**
|
|
544
|
-
* 形状参数下发(应用 applyMaskParams):cornerRadius/innerRadius/outerRadius/
|
|
545
|
-
* seamlessMode/seamlessNess 逐块写入。引擎渲染消费 cornerRadius(烘焙圆角,
|
|
546
|
-
* raw 即签名自动失效);innerRadius 进分割线手势的 minWidth 门;其余为
|
|
547
|
-
* 往返字段(应用侧同为保留参数——applyMaskShape 当前只实现圆角)。
|
|
548
|
-
* 返回实际生效的参数(缺省不覆盖,应用 `if (typeof === 'number')` 同语义)。
|
|
549
|
-
*/
|
|
550
|
-
export const applyPuzzleMaskParams = (state, params) => {
|
|
551
|
-
const applied = {};
|
|
552
|
-
if (typeof params.cornerRadius === 'number') {
|
|
553
|
-
applied.cornerRadius = params.cornerRadius;
|
|
554
|
-
for (const m of state.masks)
|
|
555
|
-
m.cornerRadius = params.cornerRadius;
|
|
556
|
-
}
|
|
557
|
-
if (typeof params.innerRadius === 'number') {
|
|
558
|
-
applied.innerRadius = params.innerRadius;
|
|
559
|
-
state.innerRadius = params.innerRadius;
|
|
560
|
-
}
|
|
561
|
-
if (typeof params.outerRadius === 'number')
|
|
562
|
-
applied.outerRadius = params.outerRadius;
|
|
563
|
-
if (typeof params.seamlessMode === 'boolean')
|
|
564
|
-
applied.seamlessMode = params.seamlessMode;
|
|
565
|
-
if (typeof params.seamlessNess === 'number')
|
|
566
|
-
applied.seamlessNess = params.seamlessNess;
|
|
567
|
-
return applied;
|
|
568
|
-
};
|
|
569
|
-
/** 序列化 mask 数组 → 编辑视图(spans 从 layoutConfig.pieces 逐 idx 对齐——应用 fromObject/create 同规则) */
|
|
570
|
-
export const buildPuzzleEditState = (puzzle, masks, clipEls = []) => {
|
|
571
|
-
const layout = puzzle.layoutConfig;
|
|
572
|
-
const rawPieces = (layout && typeof layout === 'object' && Array.isArray(layout.pieces) ? layout.pieces : []);
|
|
573
|
-
const boxes = masks.map((m) => ({
|
|
574
|
-
left: m.left ?? 0,
|
|
575
|
-
top: m.top ?? 0,
|
|
576
|
-
width: m.width ?? 0,
|
|
577
|
-
height: m.height ?? 0,
|
|
578
|
-
clip: maskClipView(m)
|
|
579
|
-
}));
|
|
580
|
-
const clipSizes = masks.map((m, i) => {
|
|
581
|
-
const c = m.clipImage;
|
|
582
|
-
if (!c || typeof c.src !== 'string')
|
|
583
|
-
return null;
|
|
584
|
-
const el = clipEls[i];
|
|
585
|
-
if (el && el.naturalWidth && el.naturalHeight)
|
|
586
|
-
return { w: el.naturalWidth, h: el.naturalHeight };
|
|
587
|
-
return { w: c.width ?? 0, h: c.height ?? 0 };
|
|
588
|
-
});
|
|
589
|
-
// spans 与 pieces 对齐(缺省按 1×1)
|
|
590
|
-
rawPieces.forEach((p, idx) => {
|
|
591
|
-
const b = boxes[idx];
|
|
592
|
-
if (!b || typeof p.col !== 'number' || typeof p.row !== 'number')
|
|
593
|
-
return;
|
|
594
|
-
b.colStart = p.col;
|
|
595
|
-
b.colEnd = p.col + (p.colSpan ?? 1) - 1;
|
|
596
|
-
b.rowStart = p.row;
|
|
597
|
-
b.rowEnd = p.row + (p.rowSpan ?? 1) - 1;
|
|
598
|
-
});
|
|
599
|
-
const state = {
|
|
600
|
-
layoutWidth: puzzle.layoutWidth ?? 600,
|
|
601
|
-
layoutHeight: puzzle.layoutHeight ?? 600,
|
|
602
|
-
hGap: puzzle.hGap ?? 12,
|
|
603
|
-
vGap: puzzle.vGap ?? 12,
|
|
604
|
-
groupPadding: puzzle.groupPadding ?? 0,
|
|
605
|
-
innerRadius: puzzle.innerRadius ?? 12,
|
|
606
|
-
cols: (layout && typeof layout.cols === 'number' ? layout.cols : 0) || 1,
|
|
607
|
-
rows: (layout && typeof layout.rows === 'number' ? layout.rows : 0) || 1,
|
|
608
|
-
masks: boxes
|
|
609
|
-
};
|
|
610
|
-
const pieces = rawPieces
|
|
611
|
-
.filter((p) => typeof p.row === 'number' && typeof p.col === 'number')
|
|
612
|
-
.map((p) => ({ row: p.row, col: p.col, rowSpan: p.rowSpan, colSpan: p.colSpan }));
|
|
613
|
-
return { state, pieces, clipSizes };
|
|
614
|
-
};
|
|
615
|
-
/**
|
|
616
|
-
* 删列并自动填充(应用 removeCol :1318-1397 纯函数化):colSpan=1 且起始列命中
|
|
617
|
-
* 的块删除;跨列块 colSpan 缩 1;被删空间由同行 absorbCol(删第 0 列取右邻、
|
|
618
|
-
* 否则取左邻)的块 colSpan+1 吸收(吸收者在右则左移补位);右列索引整体 -1。
|
|
619
|
-
* 原地改 pieces;cols 的 -1 与落盘由消费方执行。cols<=1 守卫拒绝返回 null。
|
|
620
|
-
*/
|
|
621
|
-
export const removePuzzleCol = (pieces, cols, colIndex) => {
|
|
622
|
-
if (cols <= 1)
|
|
623
|
-
return null;
|
|
624
|
-
const toDelete = [];
|
|
625
|
-
pieces.forEach((piece, idx) => {
|
|
626
|
-
const colStart = piece.col;
|
|
627
|
-
const colEnd = piece.col + (piece.colSpan ?? 1) - 1;
|
|
628
|
-
if (colStart === colIndex && (piece.colSpan ?? 1) === 1) {
|
|
629
|
-
toDelete.push(idx);
|
|
630
|
-
}
|
|
631
|
-
else if (colIndex >= colStart && colIndex <= colEnd) {
|
|
632
|
-
piece.colSpan = (piece.colSpan ?? 1) - 1;
|
|
633
|
-
}
|
|
634
|
-
});
|
|
635
|
-
toDelete.forEach((delIdx) => {
|
|
636
|
-
const target = pieces[delIdx];
|
|
637
|
-
const absorbCol = colIndex > 0 ? colIndex - 1 : colIndex + 1;
|
|
638
|
-
// 应用简单逻辑:找起始行一致、覆盖 absorbCol 的第一块(find 首个命中同款)
|
|
639
|
-
const neighbor = pieces.find((p, idx) => !toDelete.includes(idx) && p.row === target.row && p.col <= absorbCol && p.col + (p.colSpan ?? 1) - 1 >= absorbCol);
|
|
640
|
-
if (neighbor) {
|
|
641
|
-
neighbor.colSpan = (neighbor.colSpan ?? 1) + 1;
|
|
642
|
-
if (neighbor.col > colIndex)
|
|
643
|
-
neighbor.col = colIndex;
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
pieces.forEach((p) => {
|
|
647
|
-
if (p.col > colIndex)
|
|
648
|
-
p.col -= 1;
|
|
649
|
-
});
|
|
650
|
-
for (const idx of [...toDelete].sort((a, b) => b - a))
|
|
651
|
-
pieces.splice(idx, 1);
|
|
652
|
-
return { removed: toDelete };
|
|
653
|
-
};
|
|
654
|
-
/** 删行(应用 removeRow :1403-1458,列版同构:吸收按同列、行界匹配) */
|
|
655
|
-
export const removePuzzleRow = (pieces, rows, rowIndex) => {
|
|
656
|
-
if (rows <= 1)
|
|
657
|
-
return null;
|
|
658
|
-
const toDelete = [];
|
|
659
|
-
pieces.forEach((piece, idx) => {
|
|
660
|
-
const rowStart = piece.row;
|
|
661
|
-
const rowEnd = piece.row + (piece.rowSpan ?? 1) - 1;
|
|
662
|
-
if (rowStart === rowIndex && (piece.rowSpan ?? 1) === 1) {
|
|
663
|
-
toDelete.push(idx);
|
|
664
|
-
}
|
|
665
|
-
else if (rowIndex >= rowStart && rowIndex <= rowEnd) {
|
|
666
|
-
piece.rowSpan = (piece.rowSpan ?? 1) - 1;
|
|
667
|
-
}
|
|
668
|
-
});
|
|
669
|
-
toDelete.forEach((delIdx) => {
|
|
670
|
-
const target = pieces[delIdx];
|
|
671
|
-
const absorbRow = rowIndex > 0 ? rowIndex - 1 : rowIndex + 1;
|
|
672
|
-
const neighbor = pieces.find((p, idx) => !toDelete.includes(idx) && p.col === target.col && p.row <= absorbRow && p.row + (p.rowSpan ?? 1) - 1 >= absorbRow);
|
|
673
|
-
if (neighbor) {
|
|
674
|
-
neighbor.rowSpan = (neighbor.rowSpan ?? 1) + 1;
|
|
675
|
-
if (neighbor.row > rowIndex)
|
|
676
|
-
neighbor.row = rowIndex;
|
|
677
|
-
}
|
|
678
|
-
});
|
|
679
|
-
pieces.forEach((p) => {
|
|
680
|
-
if (p.row > rowIndex)
|
|
681
|
-
p.row -= 1;
|
|
682
|
-
});
|
|
683
|
-
for (const idx of [...toDelete].sort((a, b) => b - a))
|
|
684
|
-
pieces.splice(idx, 1);
|
|
685
|
-
return { removed: toDelete };
|
|
686
|
-
};
|
|
687
|
-
/**
|
|
688
|
-
* 删单块 + 四向邻居整排填充(应用 removePiece :1467-1565):优先上方整排
|
|
689
|
-
* (colSpan 和恰等于目标宽)纵向拉伸;次下方(同条件,上移补位);次左方
|
|
690
|
-
* (rowSpan 和恰等于目标高)横向拉伸;次右方(同条件,左移补位);无整排
|
|
691
|
-
* 邻居时**仍删除不填充**(应用 console.warn 分支)。目标不存在或仅剩一块拒绝。
|
|
692
|
-
*/
|
|
693
|
-
export const removePuzzlePiece = (pieces, pos) => {
|
|
694
|
-
const targetIdx = pieces.findIndex((p) => p.row === pos.row && p.col === pos.col);
|
|
695
|
-
if (targetIdx === -1 || pieces.length <= 1)
|
|
696
|
-
return null;
|
|
697
|
-
const target = pieces[targetIdx];
|
|
698
|
-
const tR = target.row;
|
|
699
|
-
const tC = target.col;
|
|
700
|
-
const tRS = target.rowSpan ?? 1;
|
|
701
|
-
const tCS = target.colSpan ?? 1;
|
|
702
|
-
let neighbors = [];
|
|
703
|
-
let type = 'v';
|
|
704
|
-
const topNeighbors = pieces.filter((p) => p !== target && p.row + (p.rowSpan ?? 1) === tR && p.col >= tC && p.col + (p.colSpan ?? 1) <= tC + tCS);
|
|
705
|
-
if (topNeighbors.reduce((sum, p) => sum + (p.colSpan ?? 1), 0) === tCS) {
|
|
706
|
-
neighbors = topNeighbors;
|
|
707
|
-
type = 'v';
|
|
708
|
-
}
|
|
709
|
-
else {
|
|
710
|
-
const bottomNeighbors = pieces.filter((p) => p !== target && p.row === tR + tRS && p.col >= tC && p.col + (p.colSpan ?? 1) <= tC + tCS);
|
|
711
|
-
if (bottomNeighbors.reduce((sum, p) => sum + (p.colSpan ?? 1), 0) === tCS) {
|
|
712
|
-
neighbors = bottomNeighbors;
|
|
713
|
-
type = 'v';
|
|
714
|
-
neighbors.forEach((n) => (n.row = tR));
|
|
715
|
-
}
|
|
716
|
-
else {
|
|
717
|
-
const leftNeighbors = pieces.filter((p) => p !== target && p.col + (p.colSpan ?? 1) === tC && p.row >= tR && p.row + (p.rowSpan ?? 1) <= tR + tRS);
|
|
718
|
-
if (leftNeighbors.reduce((sum, p) => sum + (p.rowSpan ?? 1), 0) === tRS) {
|
|
719
|
-
neighbors = leftNeighbors;
|
|
720
|
-
type = 'h';
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
const rightNeighbors = pieces.filter((p) => p !== target && p.col === tC + tCS && p.row >= tR && p.row + (p.rowSpan ?? 1) <= tR + tRS);
|
|
724
|
-
if (rightNeighbors.reduce((sum, p) => sum + (p.rowSpan ?? 1), 0) === tRS) {
|
|
725
|
-
neighbors = rightNeighbors;
|
|
726
|
-
type = 'h';
|
|
727
|
-
neighbors.forEach((n) => (n.col = tC));
|
|
728
|
-
}
|
|
729
|
-
}
|
|
730
|
-
}
|
|
731
|
-
}
|
|
732
|
-
if (neighbors.length > 0) {
|
|
733
|
-
neighbors.forEach((n) => {
|
|
734
|
-
if (type === 'v')
|
|
735
|
-
n.rowSpan = (n.rowSpan ?? 1) + tRS;
|
|
736
|
-
else
|
|
737
|
-
n.colSpan = (n.colSpan ?? 1) + tCS;
|
|
738
|
-
});
|
|
739
|
-
}
|
|
740
|
-
pieces.splice(targetIdx, 1);
|
|
741
|
-
return { removed: [targetIdx] };
|
|
742
|
-
};
|