@yft-design/engine 0.0.16 → 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 +12 -55
- package/dist/model/compatObject.d.ts +0 -360
- package/dist/model/cropEdit.d.ts +0 -60
- package/dist/model/document.d.ts +3 -158
- 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 +32 -4
- 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 +5 -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 -526
- package/dist/interact/dblClick.js +0 -120
- package/dist/interact/expandSession.js +0 -281
- package/dist/interact/hotkeyActions.js +0 -41
- package/dist/interact/pageTransfer.js +0 -56
- package/dist/interact/pathSession.js +0 -480
- package/dist/interact/pointer.js +0 -1691
- 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 -206
- 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 -582
- package/dist/interact/wheelScroll.js +0 -100
- package/dist/model/alphaHit.js +0 -263
- 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 -73
- package/dist/model/compatObject.js +0 -1580
- package/dist/model/cropEdit.js +0 -497
- package/dist/model/document.js +0 -572
- 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 -136
- 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 -123
- 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 -188
- package/dist/render/maskRender.js +0 -217
- package/dist/render/multiPage.js +0 -419
- 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 -515
- package/dist/render/strokeMiterOutline.js +0 -224
- package/dist/render/strokePainter.js +0 -207
- package/dist/render/strokeSdf.js +0 -261
- 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 -382
- package/dist/render/workspaceBackdrop.js +0 -60
- package/dist/render/workspaceChecker.js +0 -170
- package/dist/render/workspaceGlow.js +0 -198
package/dist/model/pathEdit.js
DELETED
|
@@ -1,378 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 路径族锚点编辑算子(P4-7):只算不写——入参出参全是普通对象/命令数组,
|
|
3
|
-
* 节点落盘由 interact/pathSession 调 document.setProps 执行(cropEdit/expandEdit 同约定)。
|
|
4
|
-
*
|
|
5
|
-
* 对齐基准(应用 FabricPath + fabric 6.9.0 源码逐式):
|
|
6
|
-
* - 锚点/手柄布局 = fabric controlsUtils.createPathControls:每条非 Z 指令一个
|
|
7
|
-
* 锚点(key `c_{i}_{cmd}`,坐标起始下标 = cmd.length−2 即指令终点)、C 两个手柄
|
|
8
|
-
* (`_CP_1`@1 / `_CP_2`@3)、Q 一个手柄(`_CP_1`@1);连接线 C_CP_1↔上一指令
|
|
9
|
-
* 终点、C_CP_2↔自身终点、Q_CP_1↔自身终点(fabric PathControlPointControl 同布局)
|
|
10
|
-
* - 段上插点候选 = FabricPath._findInsertAnchorCandidate:线段点投影 / 曲线采样
|
|
11
|
-
* 投影(粗采样 100 + 邻域细化 20),命中 8px、端点让位 6px(均屏幕像素)
|
|
12
|
-
* - 插点 = de Casteljau 拆段(L/Z 插 L、C/Q 拆成两段同型曲线,形状不变)
|
|
13
|
-
* - L↔C 锚点类型转换 = FabricPath.setAnchorPointType(L→C 控制点落在弦 1/3、2/3)
|
|
14
|
-
* - 坐标系:本地位 = 指令坐标 − path bbox 中心(fabric pathOffset 语义;引擎
|
|
15
|
-
* buildPathGeometry/PathNode.dims 同源)——渲染/命中/写回三面共用
|
|
16
|
-
*
|
|
17
|
-
* polygon/polyline:points 数组的等价算子(fabric createPolyControls 布局
|
|
18
|
-
* `p_{i}` + factoryPolyActionHandler 拖点)。line 两端点无独立布局(x1..y2 直写)。
|
|
19
|
-
*/
|
|
20
|
-
import { getBoundsOfPath, parsePathData } from '../core/pathData';
|
|
21
|
-
import { transformPoint } from '../core/mat2d';
|
|
22
|
-
/** 应用 FabricPath 的命中/让位常量(屏幕像素;场景换算 /zoom 由调用方完成) */
|
|
23
|
-
export const PATH_INSERT_HIT_PX = 8;
|
|
24
|
-
export const PATH_INSERT_ENDPOINT_GAP_PX = 6;
|
|
25
|
-
// ── 基础:解析 / bbox 中心 / 段起点 ──
|
|
26
|
-
export const editablePathCommands = (raw) => parsePathData(raw);
|
|
27
|
-
/** path bbox 中心(= fabric pathOffset;null = 空路径) */
|
|
28
|
-
export const pathBBoxCenter = (commands) => {
|
|
29
|
-
if (!commands)
|
|
30
|
-
return null;
|
|
31
|
-
const b = getBoundsOfPath(commands);
|
|
32
|
-
return b ? { x: (b.left + b.right) / 2, y: (b.top + b.bottom) / 2 } : null;
|
|
33
|
-
};
|
|
34
|
-
/** 指令终点(M/L→(1,2),C→(5,6),Q→(3,4);Z→子路径 M 起点) */
|
|
35
|
-
const commandEndPoint = (commands, i) => {
|
|
36
|
-
const cmd = commands[i];
|
|
37
|
-
const t = String(cmd[0]).toUpperCase();
|
|
38
|
-
if (t === 'M' || t === 'L')
|
|
39
|
-
return { x: cmd[1], y: cmd[2] };
|
|
40
|
-
if (t === 'C')
|
|
41
|
-
return { x: cmd[5], y: cmd[6] };
|
|
42
|
-
if (t === 'Q')
|
|
43
|
-
return { x: cmd[3], y: cmd[4] };
|
|
44
|
-
// Z:回到本子路径 M 起点
|
|
45
|
-
for (let j = i; j >= 0; j--) {
|
|
46
|
-
if (String(commands[j][0]).toUpperCase() === 'M')
|
|
47
|
-
return { x: commands[j][1], y: commands[j][2] };
|
|
48
|
-
}
|
|
49
|
-
return { x: 0, y: 0 };
|
|
50
|
-
};
|
|
51
|
-
/** 段 i 的起点(上一指令终点;FabricPath._getSegmentStartPoint 同语义) */
|
|
52
|
-
export const segmentStartPoint = (commands, i) => {
|
|
53
|
-
for (let j = i - 1; j >= 0; j--) {
|
|
54
|
-
const t = String(commands[j][0]).toUpperCase();
|
|
55
|
-
if (t === 'M' || t === 'L')
|
|
56
|
-
return { x: commands[j][1], y: commands[j][2] };
|
|
57
|
-
if (t === 'C')
|
|
58
|
-
return { x: commands[j][5], y: commands[j][6] };
|
|
59
|
-
if (t === 'Q')
|
|
60
|
-
return { x: commands[j][3], y: commands[j][4] };
|
|
61
|
-
// Z:继续回溯到子路径 M(上一指令是 Z 时段起点取 M 点)
|
|
62
|
-
if (t === 'Z') {
|
|
63
|
-
for (let k = j; k >= 0; k--) {
|
|
64
|
-
if (String(commands[k][0]).toUpperCase() === 'M')
|
|
65
|
-
return { x: commands[k][1], y: commands[k][2] };
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return { x: 0, y: 0 };
|
|
70
|
-
};
|
|
71
|
-
// ── 布局:锚点/手柄枚举 + 连接线 ──
|
|
72
|
-
/** 指令内坐标位(fabric indexFromPrevCommand:C→5、Q→3、其余→1) */
|
|
73
|
-
const prevCommandPointIndex = (t) => (t === 'C' ? 5 : t === 'Q' ? 3 : 1);
|
|
74
|
-
const coordAt = (cmd, pointIndex, c) => ({ x: cmd[pointIndex] - c.x, y: cmd[pointIndex + 1] - c.y });
|
|
75
|
-
/** path 命令族控制点全集(createPathControls 同布局)+ 手柄连接线 */
|
|
76
|
-
export const describePathEdit = (commands, center) => {
|
|
77
|
-
const handles = [];
|
|
78
|
-
const connections = [];
|
|
79
|
-
commands.forEach((cmd, i) => {
|
|
80
|
-
const t = String(cmd[0]);
|
|
81
|
-
if (t !== 'Z') {
|
|
82
|
-
// 锚点 = 指令终点(fabric createControl(i, command.length - 2))
|
|
83
|
-
handles.push({ key: `c_${i}_${t}`, kind: 'anchor', commandIndex: i, pointIndex: cmd.length - 2, local: coordAt(cmd, cmd.length - 2, center) });
|
|
84
|
-
}
|
|
85
|
-
if (t === 'C') {
|
|
86
|
-
const cp1 = coordAt(cmd, 1, center);
|
|
87
|
-
const cp2 = coordAt(cmd, 3, center);
|
|
88
|
-
handles.push({ key: `c_${i}_C_CP_1`, kind: 'handle', commandIndex: i, pointIndex: 1, local: cp1 });
|
|
89
|
-
handles.push({ key: `c_${i}_C_CP_2`, kind: 'handle', commandIndex: i, pointIndex: 3, local: cp2 });
|
|
90
|
-
// CP_1 ↔ 上一指令终点;CP_2 ↔ 自身终点(fabric connectToCommandIndex/PointIndex 同对)
|
|
91
|
-
const prev = i > 0 ? String(commands[i - 1][0]).toUpperCase() : 'M';
|
|
92
|
-
const prevEnd = i > 0 ? coordAt(commands[i - 1], prevCommandPointIndex(prev), center) : cp1;
|
|
93
|
-
connections.push({ from: cp1, to: prevEnd }, { from: cp2, to: coordAt(cmd, 5, center) });
|
|
94
|
-
}
|
|
95
|
-
else if (t === 'Q') {
|
|
96
|
-
const cp = coordAt(cmd, 1, center);
|
|
97
|
-
handles.push({ key: `c_${i}_Q_CP_1`, kind: 'handle', commandIndex: i, pointIndex: 1, local: cp });
|
|
98
|
-
connections.push({ from: cp, to: coordAt(cmd, 3, center) });
|
|
99
|
-
}
|
|
100
|
-
});
|
|
101
|
-
return { handles, connections };
|
|
102
|
-
};
|
|
103
|
-
/** polygon/polyline 顶点全集(fabric createPolyControls 布局 `p_{i}`) */
|
|
104
|
-
export const describePolyEdit = (points, center) => points.map((p, i) => ({ key: `p_${i}`, kind: 'point', commandIndex: i, pointIndex: i, local: { x: p.x - center.x, y: p.y - center.y } }));
|
|
105
|
-
export const polyBBoxCenter = (points) => {
|
|
106
|
-
if (!points.length)
|
|
107
|
-
return null;
|
|
108
|
-
let minX = Infinity;
|
|
109
|
-
let minY = Infinity;
|
|
110
|
-
let maxX = -Infinity;
|
|
111
|
-
let maxY = -Infinity;
|
|
112
|
-
for (const p of points) {
|
|
113
|
-
if (minX > p.x)
|
|
114
|
-
minX = p.x;
|
|
115
|
-
if (minY > p.y)
|
|
116
|
-
minY = p.y;
|
|
117
|
-
if (maxX < p.x)
|
|
118
|
-
maxX = p.x;
|
|
119
|
-
if (maxY < p.y)
|
|
120
|
-
maxY = p.y;
|
|
121
|
-
}
|
|
122
|
-
return { x: (minX + maxX) / 2, y: (minY + maxY) / 2 };
|
|
123
|
-
};
|
|
124
|
-
// ── 投影:段上插点候选(FabricPath._findInsertAnchorCandidate 逐式) ──
|
|
125
|
-
const projectPointToSegment = (point, start, end) => {
|
|
126
|
-
const dx = end.x - start.x;
|
|
127
|
-
const dy = end.y - start.y;
|
|
128
|
-
const lengthSq = dx * dx + dy * dy;
|
|
129
|
-
if (!lengthSq)
|
|
130
|
-
return { distance: Math.hypot(point.x - start.x, point.y - start.y), t: 0, point: { ...start }, length: 0 };
|
|
131
|
-
const t = Math.max(0, Math.min(1, ((point.x - start.x) * dx + (point.y - start.y) * dy) / lengthSq));
|
|
132
|
-
const projected = { x: start.x + dx * t, y: start.y + dy * t };
|
|
133
|
-
return { distance: Math.hypot(point.x - projected.x, point.y - projected.y), t, point: projected, length: Math.sqrt(lengthSq) };
|
|
134
|
-
};
|
|
135
|
-
/** 曲线上离 point 最近的参数:粗采样定位 + 邻域细化(FabricPath.projectPointToCurve 同两段式) */
|
|
136
|
-
const projectPointToCurve = (point, evaluate, samples = 100) => {
|
|
137
|
-
const step = 1 / samples;
|
|
138
|
-
let bestT = 0;
|
|
139
|
-
let bestDistSq = Number.POSITIVE_INFINITY;
|
|
140
|
-
let curveLen = 0;
|
|
141
|
-
let prev = null;
|
|
142
|
-
for (let i = 0; i <= samples; i++) {
|
|
143
|
-
const t = i * step;
|
|
144
|
-
const p = evaluate(t);
|
|
145
|
-
if (prev)
|
|
146
|
-
curveLen += Math.hypot(p.x - prev.x, p.y - prev.y);
|
|
147
|
-
prev = p;
|
|
148
|
-
const d = (p.x - point.x) ** 2 + (p.y - point.y) ** 2;
|
|
149
|
-
if (d < bestDistSq) {
|
|
150
|
-
bestDistSq = d;
|
|
151
|
-
bestT = t;
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
const lo = Math.max(0, bestT - step);
|
|
155
|
-
const hi = Math.min(1, bestT + step);
|
|
156
|
-
const refineStep = (hi - lo) / 20;
|
|
157
|
-
for (let t = lo; t <= hi; t += refineStep) {
|
|
158
|
-
const p = evaluate(t);
|
|
159
|
-
const d = (p.x - point.x) ** 2 + (p.y - point.y) ** 2;
|
|
160
|
-
if (d < bestDistSq) {
|
|
161
|
-
bestDistSq = d;
|
|
162
|
-
bestT = t;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
return { distance: Math.sqrt(bestDistSq), t: bestT, point: evaluate(bestT), length: curveLen };
|
|
166
|
-
};
|
|
167
|
-
const cubicAt = (p0, p1, p2, p3, t) => {
|
|
168
|
-
const u = 1 - t;
|
|
169
|
-
const a = u * u * u;
|
|
170
|
-
const b = 3 * u * u * t;
|
|
171
|
-
const c = 3 * u * t * t;
|
|
172
|
-
const d = t * t * t;
|
|
173
|
-
return { x: a * p0.x + b * p1.x + c * p2.x + d * p3.x, y: a * p0.y + b * p1.y + c * p2.y + d * p3.y };
|
|
174
|
-
};
|
|
175
|
-
const quadAt = (p0, p1, p2, t) => {
|
|
176
|
-
const u = 1 - t;
|
|
177
|
-
const a = u * u;
|
|
178
|
-
const b = 2 * u * t;
|
|
179
|
-
const c = t * t;
|
|
180
|
-
return { x: a * p0.x + b * p1.x + c * p2.x, y: a * p0.y + b * p1.y + c * p2.y };
|
|
181
|
-
};
|
|
182
|
-
const lerpPt = (a, b, t) => ({ x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t });
|
|
183
|
-
/**
|
|
184
|
-
* 段上插点候选扫描(场景空间)。matrix = 本地(中心系)→ 场景;命中/让位距离按
|
|
185
|
-
* 屏幕像素除 zoom 折算场景单位(fabric PATH_INSERT_HIT_DISTANCE/zoom 同口径)。
|
|
186
|
-
*/
|
|
187
|
-
export const findInsertCandidate = (commands, center, scenePointer, matrix, zoom) => {
|
|
188
|
-
const hitDistance = PATH_INSERT_HIT_PX / zoom;
|
|
189
|
-
const endpointGap = PATH_INSERT_ENDPOINT_GAP_PX / zoom;
|
|
190
|
-
const toScene = (p) => transformPoint(matrix, p.x, p.y);
|
|
191
|
-
const toSceneRaw = (cmd, pointIndex) => toScene(coordAt(cmd, pointIndex, center));
|
|
192
|
-
let candidate;
|
|
193
|
-
let bestDistance = Number.POSITIVE_INFINITY;
|
|
194
|
-
commands.forEach((cmd, i) => {
|
|
195
|
-
const t = String(cmd[0]).toUpperCase();
|
|
196
|
-
if (t === 'C' || t === 'Q') {
|
|
197
|
-
const start = { x: segmentStartPoint(commands, i).x - center.x, y: segmentStartPoint(commands, i).y - center.y };
|
|
198
|
-
const p0 = toScene(start);
|
|
199
|
-
const p1 = toSceneRaw(cmd, 1);
|
|
200
|
-
const p3raw = t === 'C' ? coordAt(cmd, 5, center) : coordAt(cmd, 3, center);
|
|
201
|
-
const p3 = toScene(p3raw);
|
|
202
|
-
const evaluate = t === 'C' ? (u) => cubicAt(p0, p1, toSceneRaw(cmd, 3), p3, u) : (u) => quadAt(p0, p1, p3, u);
|
|
203
|
-
const projected = projectPointToCurve(scenePointer, evaluate);
|
|
204
|
-
if (projected.distance > hitDistance || projected.length <= endpointGap * 2 || projected.distance >= bestDistance)
|
|
205
|
-
return;
|
|
206
|
-
const endpointRatio = endpointGap / projected.length;
|
|
207
|
-
if (projected.t <= endpointRatio || projected.t >= 1 - endpointRatio)
|
|
208
|
-
return;
|
|
209
|
-
// 本地位上的同参求值(C/Q 的参数 t 在仿射变换下不变)
|
|
210
|
-
const startRaw = segmentStartPoint(commands, i);
|
|
211
|
-
const local = t === 'C'
|
|
212
|
-
? (() => {
|
|
213
|
-
const l0 = { x: startRaw.x - center.x, y: startRaw.y - center.y };
|
|
214
|
-
const l1 = coordAt(cmd, 1, center);
|
|
215
|
-
const l2 = coordAt(cmd, 3, center);
|
|
216
|
-
const l3 = { x: cmd[5] - center.x, y: cmd[6] - center.y };
|
|
217
|
-
return cubicAt(l0, l1, l2, l3, projected.t);
|
|
218
|
-
})()
|
|
219
|
-
: (() => {
|
|
220
|
-
const l0 = { x: startRaw.x - center.x, y: startRaw.y - center.y };
|
|
221
|
-
const l1 = coordAt(cmd, 1, center);
|
|
222
|
-
const l2 = { x: cmd[3] - center.x, y: cmd[4] - center.y };
|
|
223
|
-
return quadAt(l0, l1, l2, projected.t);
|
|
224
|
-
})();
|
|
225
|
-
bestDistance = projected.distance;
|
|
226
|
-
candidate = { commandIndex: i, commandType: t, t: projected.t, local, scene: projected.point };
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
if (t !== 'L' && t !== 'Z')
|
|
230
|
-
return;
|
|
231
|
-
// Z:起点 = 上一指令终点(本子路径最后一点),终点 = 子路径 M 起点(commandEndPoint 对 Z 自带回溯)
|
|
232
|
-
const startRaw = t === 'L' ? segmentStartPoint(commands, i) : commandEndPoint(commands, Math.max(0, i - 1));
|
|
233
|
-
const endRaw = commandEndPoint(commands, i);
|
|
234
|
-
const sceneStart = toScene({ x: startRaw.x - center.x, y: startRaw.y - center.y });
|
|
235
|
-
const sceneEnd = toScene({ x: endRaw.x - center.x, y: endRaw.y - center.y });
|
|
236
|
-
const projected = projectPointToSegment(scenePointer, sceneStart, sceneEnd);
|
|
237
|
-
if (projected.distance > hitDistance || projected.length <= endpointGap * 2 || projected.distance >= bestDistance)
|
|
238
|
-
return;
|
|
239
|
-
const endpointRatio = endpointGap / projected.length;
|
|
240
|
-
if (projected.t <= endpointRatio || projected.t >= 1 - endpointRatio)
|
|
241
|
-
return;
|
|
242
|
-
bestDistance = projected.distance;
|
|
243
|
-
const localStart = { x: startRaw.x - center.x, y: startRaw.y - center.y };
|
|
244
|
-
const localEnd = { x: endRaw.x - center.x, y: endRaw.y - center.y };
|
|
245
|
-
candidate = { commandIndex: i, commandType: t, t: projected.t, local: lerpPt(localStart, localEnd, projected.t), scene: projected.point };
|
|
246
|
-
});
|
|
247
|
-
return candidate;
|
|
248
|
-
};
|
|
249
|
-
// ── 写回:拖点 / 插点 / 类型转换 ──
|
|
250
|
-
/** 拖点写回:把指令坐标位写成中心系目标位(+center 还原原始坐标系)。返回新数组 */
|
|
251
|
-
export const writePathCoordinate = (commands, commandIndex, pointIndex, localTarget, center) => commands.map((cmd, i) => {
|
|
252
|
-
if (i !== commandIndex)
|
|
253
|
-
return cmd;
|
|
254
|
-
const next = [...cmd];
|
|
255
|
-
next[pointIndex] = localTarget.x + center.x;
|
|
256
|
-
next[pointIndex + 1] = localTarget.y + center.y;
|
|
257
|
-
return next;
|
|
258
|
-
});
|
|
259
|
-
/** polygon 顶点写回(fabric polyActionHandler:points[i] = local + pathOffset) */
|
|
260
|
-
export const writePolyPoint = (points, index, localTarget, center) => points.map((p, i) => (i === index ? { x: localTarget.x + center.x, y: localTarget.y + center.y } : p));
|
|
261
|
-
/**
|
|
262
|
-
* 插点(de Casteljau 拆段,形状不变):L 段插 L、C/Q 拆两段同型曲线、Z 段以
|
|
263
|
-
* L+Z 替换。返回 null = 段类型不可插。新锚点位于 commandIndex 处指令终点。
|
|
264
|
-
*/
|
|
265
|
-
export const insertAnchorAt = (commands, center, candidate) => {
|
|
266
|
-
const next = commands.map((cmd) => [...cmd]);
|
|
267
|
-
const ix = candidate.local.x + center.x;
|
|
268
|
-
const iy = candidate.local.y + center.y;
|
|
269
|
-
const i = candidate.commandIndex;
|
|
270
|
-
if (candidate.commandType === 'L') {
|
|
271
|
-
const original = next[i];
|
|
272
|
-
const endX = original[1];
|
|
273
|
-
const endY = original[2];
|
|
274
|
-
next[i] = ['L', ix, iy];
|
|
275
|
-
next.splice(i + 1, 0, ['L', endX, endY]);
|
|
276
|
-
return next;
|
|
277
|
-
}
|
|
278
|
-
if (candidate.commandType === 'C') {
|
|
279
|
-
const cmd = next[i];
|
|
280
|
-
const start = segmentStartPoint(commands, i);
|
|
281
|
-
const t = candidate.t;
|
|
282
|
-
const p1x = cmd[1];
|
|
283
|
-
const p1y = cmd[2];
|
|
284
|
-
const p2x = cmd[3];
|
|
285
|
-
const p2y = cmd[4];
|
|
286
|
-
const p3x = cmd[5];
|
|
287
|
-
const p3y = cmd[6];
|
|
288
|
-
const q0x = start.x + (p1x - start.x) * t;
|
|
289
|
-
const q0y = start.y + (p1y - start.y) * t;
|
|
290
|
-
const q1x = p1x + (p2x - p1x) * t;
|
|
291
|
-
const q1y = p1y + (p2y - p1y) * t;
|
|
292
|
-
const q2x = p2x + (p3x - p2x) * t;
|
|
293
|
-
const q2y = p2y + (p3y - p2y) * t;
|
|
294
|
-
const r0x = q0x + (q1x - q0x) * t;
|
|
295
|
-
const r0y = q0y + (q1y - q0y) * t;
|
|
296
|
-
const r1x = q1x + (q2x - q1x) * t;
|
|
297
|
-
const r1y = q1y + (q2y - q1y) * t;
|
|
298
|
-
next[i] = ['C', q0x, q0y, r0x, r0y, ix, iy];
|
|
299
|
-
next.splice(i + 1, 0, ['C', r1x, r1y, q2x, q2y, p3x, p3y]);
|
|
300
|
-
return next;
|
|
301
|
-
}
|
|
302
|
-
if (candidate.commandType === 'Q') {
|
|
303
|
-
const cmd = next[i];
|
|
304
|
-
const start = segmentStartPoint(commands, i);
|
|
305
|
-
const t = candidate.t;
|
|
306
|
-
const p1x = cmd[1];
|
|
307
|
-
const p1y = cmd[2];
|
|
308
|
-
const p2x = cmd[3];
|
|
309
|
-
const p2y = cmd[4];
|
|
310
|
-
const q0x = start.x + (p1x - start.x) * t;
|
|
311
|
-
const q0y = start.y + (p1y - start.y) * t;
|
|
312
|
-
const q1x = p1x + (p2x - p1x) * t;
|
|
313
|
-
const q1y = p1y + (p2y - p1y) * t;
|
|
314
|
-
next[i] = ['Q', q0x, q0y, ix, iy];
|
|
315
|
-
next.splice(i + 1, 0, ['Q', q1x, q1y, p2x, p2y]);
|
|
316
|
-
return next;
|
|
317
|
-
}
|
|
318
|
-
if (candidate.commandType === 'Z') {
|
|
319
|
-
next.splice(i, 1, ['L', ix, iy], ['Z']);
|
|
320
|
-
return next;
|
|
321
|
-
}
|
|
322
|
-
return null;
|
|
323
|
-
};
|
|
324
|
-
/**
|
|
325
|
-
* 锚点类型切换(FabricPath.setAnchorPointType):L→C 控制点落在弦 1/3、2/3
|
|
326
|
-
* (曲线与原直线重合);C/Q→L 丢弃控制点。M/Z 不可转换(返回 null)。
|
|
327
|
-
* changed=false 表示已是目标类型(仅重高亮语义,不写回)。
|
|
328
|
-
*/
|
|
329
|
-
export const setAnchorType = (commands, index, type) => {
|
|
330
|
-
if (index < 0 || index >= commands.length)
|
|
331
|
-
return null;
|
|
332
|
-
const segment = commands[index];
|
|
333
|
-
const command = String(segment[0]).toUpperCase();
|
|
334
|
-
if (command === 'M' || command === 'Z')
|
|
335
|
-
return null;
|
|
336
|
-
const isCurve = command === 'C' || command === 'Q';
|
|
337
|
-
const wantCurve = type.toUpperCase() === 'C';
|
|
338
|
-
if (isCurve === wantCurve)
|
|
339
|
-
return { commands, changed: false };
|
|
340
|
-
let currX;
|
|
341
|
-
let currY;
|
|
342
|
-
if (command === 'L') {
|
|
343
|
-
currX = segment[1];
|
|
344
|
-
currY = segment[2];
|
|
345
|
-
}
|
|
346
|
-
else if (command === 'C') {
|
|
347
|
-
currX = segment[5];
|
|
348
|
-
currY = segment[6];
|
|
349
|
-
}
|
|
350
|
-
else {
|
|
351
|
-
currX = segment[3];
|
|
352
|
-
currY = segment[4];
|
|
353
|
-
}
|
|
354
|
-
const start = segmentStartPoint(commands, index);
|
|
355
|
-
const next = commands.map((cmd) => [...cmd]);
|
|
356
|
-
next[index] = wantCurve ? ['C', start.x + (currX - start.x) / 3, start.y + (currY - start.y) / 3, currX - (currX - start.x) / 3, currY - (currY - start.y) / 3, currX, currY] : ['L', currX, currY];
|
|
357
|
-
return { commands: next, changed: true };
|
|
358
|
-
};
|
|
359
|
-
/** 指令锚点的线/曲风格(FabricPath.getAnchorPointStyleByIndex:C/Q/S/T/A → smooth) */
|
|
360
|
-
export const anchorStyleAt = (commands, index) => {
|
|
361
|
-
const cmd = commands?.[index]?.[0];
|
|
362
|
-
if (!cmd)
|
|
363
|
-
return 'line';
|
|
364
|
-
return ['C', 'Q', 'S', 'T', 'A'].includes(String(cmd).toUpperCase()) ? 'smooth' : 'line';
|
|
365
|
-
};
|
|
366
|
-
/**
|
|
367
|
-
* 拖点后的位置补偿(fabric movePathPoint/factoryPolyActionHandler 的参考点平移
|
|
368
|
-
* 补偿等价式):pathOffset(bbox 中心)从 oldC 移到 newC 时,把对象中心平移
|
|
369
|
-
* linear·(newC−oldC) 即可保持所有未拖动点场景位不动;line 族(无 pathOffset)
|
|
370
|
-
* 中心不动。linear = 节点自身矩阵线性部([m0,m1,m2,m3])。
|
|
371
|
-
*/
|
|
372
|
-
export const shiftedCenter = (oldCenter, oldC, newC, linear) => {
|
|
373
|
-
if (!newC)
|
|
374
|
-
return oldCenter;
|
|
375
|
-
const dx = newC.x - oldC.x;
|
|
376
|
-
const dy = newC.y - oldC.y;
|
|
377
|
-
return { x: oldCenter.x + linear[0] * dx + linear[2] * dy, y: oldCenter.y + linear[1] * dx + linear[3] * dy };
|
|
378
|
-
};
|