@yft-design/engine 0.0.17 → 0.0.19
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 +1 -14
- 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
|
@@ -1,480 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 路径族锚点编辑会话(P4-7):应用 FabricPath/Polygon/Polyline/Line 的
|
|
3
|
-
* changeControls 编辑态引擎面(crop/expand 会话同模式)。
|
|
4
|
-
*
|
|
5
|
-
* 会话语义(应用口径):
|
|
6
|
-
* - 进入:单选路径族节点(Path=命令锚点+贝塞尔手柄 / polygon·polyline=顶点 /
|
|
7
|
-
* line=两端点);进入即吞没常规交互(选区 UI 换锚点覆盖层)
|
|
8
|
-
* - 命中序(应用 mouse:down:before → down 两段判定同序):锚点/手柄(12px 屏幕
|
|
9
|
-
* 半径)> 段上插点候选(8px,端点 6px 让位——悬停出预览点、点击插入)> 本体
|
|
10
|
-
* (拖动=移动对象)> 框外退出。**点外退出不吞没本次点击**——同击继续常规
|
|
11
|
-
* 命中/选区(应用 fabricCanvas._maybeExitEditingPath 同击换选语义,与 crop
|
|
12
|
-
* 会话整击吞没不同)
|
|
13
|
-
* - 拖锚点/手柄:逐帧绝对落点(幂等)——指针经逆矩阵入本地系写指令坐标位,
|
|
14
|
-
* 随后按 fabric movePathPoint 同式补偿 left/top(pathOffset 位移经线性部映
|
|
15
|
-
* 射进场景,未拖动点场景位恒定)
|
|
16
|
-
* - 插点(de Casteljau 拆段)与 L↔C 类型转换立即提交(fabric 在操作点即发
|
|
17
|
-
* object:modified:modifyPathInsert / modifyPathAnchorType);拖拽提交在 up
|
|
18
|
-
* - 退出(Esc/点外/程序化)不发 object:modified(应用 changeControls(false)
|
|
19
|
-
* 同口径——历史条目已由各操作提交)
|
|
20
|
-
* - 选中锚点变化发 document 事件 path:active-anchor-change(target, key)——
|
|
21
|
-
* 面板锚点类型切换消费(应用 canvas 事件同名透传)
|
|
22
|
-
*/
|
|
23
|
-
import { invert, objectOriginFromCenter, transformPoint } from '../core/mat2d';
|
|
24
|
-
import { getBoundsOfPath, parsePathData } from '../core/pathData';
|
|
25
|
-
import { parseColor } from '../core/color';
|
|
26
|
-
import { LineNode } from '../model/scene';
|
|
27
|
-
import { ElementTypes } from '../model/elementTypes';
|
|
28
|
-
import { describePathEdit, describePolyEdit, findInsertCandidate, insertAnchorAt, pathBBoxCenter, polyBBoxCenter, setAnchorType as setAnchorTypeOp, shiftedCenter, writePathCoordinate, writePolyPoint } from '../model/pathEdit';
|
|
29
|
-
import { buildNodeBorderOverlay, lineQuad } from '../render/selectionOverlay';
|
|
30
|
-
/** 锚点/手柄命中半径(屏幕 px;引擎手柄命中惯例同 selectionOverlay.HANDLE_HIT_PX) */
|
|
31
|
-
const ANCHOR_HIT_PX = 12;
|
|
32
|
-
/** 应用 FabricPath 的控件配色(PATH_CONTROL_STROKE) */
|
|
33
|
-
const PATH_CONTROL_COLOR = parseColor('#2254f4');
|
|
34
|
-
const CONTROL_WHITE = parseColor('#ffffff');
|
|
35
|
-
/** 控件视觉常量(屏幕 px):锚点方点 7、手柄圆点 5、连接线 1 */
|
|
36
|
-
const ANCHOR_SIZE_PX = 7;
|
|
37
|
-
const HANDLE_R_PX = 5;
|
|
38
|
-
const CONNECTION_PX = 1;
|
|
39
|
-
/** 插点预览与手柄共用的圆点 sprite(白填 + 蓝环;模块级单例,经 GLTextureCache 上传) */
|
|
40
|
-
let circleSprite = null;
|
|
41
|
-
const getCircleSprite = () => {
|
|
42
|
-
if (circleSprite)
|
|
43
|
-
return circleSprite;
|
|
44
|
-
const size = Math.ceil((HANDLE_R_PX + 2) * 2);
|
|
45
|
-
const canvas = document.createElement('canvas');
|
|
46
|
-
canvas.width = size;
|
|
47
|
-
canvas.height = size;
|
|
48
|
-
const ctx = canvas.getContext('2d');
|
|
49
|
-
ctx.beginPath();
|
|
50
|
-
ctx.arc(size / 2, size / 2, HANDLE_R_PX, 0, Math.PI * 2);
|
|
51
|
-
ctx.fillStyle = '#ffffff';
|
|
52
|
-
ctx.fill();
|
|
53
|
-
ctx.lineWidth = 1.5;
|
|
54
|
-
ctx.strokeStyle = '#2254f4';
|
|
55
|
-
ctx.stroke();
|
|
56
|
-
circleSprite = canvas;
|
|
57
|
-
return canvas;
|
|
58
|
-
};
|
|
59
|
-
/** 编辑族判定:Path(命令)/ polygon·polyline(points)/ Line(端点);null = 不可编辑 */
|
|
60
|
-
export const pathEditKindOf = (node) => {
|
|
61
|
-
const t = node.typeKey;
|
|
62
|
-
if (t === ElementTypes.PATH)
|
|
63
|
-
return 'path';
|
|
64
|
-
if (t === ElementTypes.POLYGON || t === ElementTypes.POLYLINE)
|
|
65
|
-
return 'poly';
|
|
66
|
-
if (t === ElementTypes.LINE)
|
|
67
|
-
return 'line';
|
|
68
|
-
return null;
|
|
69
|
-
};
|
|
70
|
-
export class PathSessionController {
|
|
71
|
-
host;
|
|
72
|
-
node = null;
|
|
73
|
-
kind = null;
|
|
74
|
-
activeAnchorKey;
|
|
75
|
-
insertCandidate;
|
|
76
|
-
detachKey = null;
|
|
77
|
-
constructor(host) {
|
|
78
|
-
this.host = host;
|
|
79
|
-
}
|
|
80
|
-
get active() {
|
|
81
|
-
return this.node !== null;
|
|
82
|
-
}
|
|
83
|
-
get target() {
|
|
84
|
-
return this.node;
|
|
85
|
-
}
|
|
86
|
-
get info() {
|
|
87
|
-
const node = this.node;
|
|
88
|
-
const kind = this.kind;
|
|
89
|
-
if (!node || !kind)
|
|
90
|
-
return null;
|
|
91
|
-
const matrix = node.matrix;
|
|
92
|
-
const anchors = this.currentHandles().map((h) => {
|
|
93
|
-
const scene = transformPoint(matrix, h.local.x, h.local.y);
|
|
94
|
-
return { key: h.key, kind: h.kind, x: scene.x, y: scene.y };
|
|
95
|
-
});
|
|
96
|
-
return {
|
|
97
|
-
nodeId: node.id,
|
|
98
|
-
kind,
|
|
99
|
-
anchors,
|
|
100
|
-
activeAnchorKey: this.activeAnchorKey,
|
|
101
|
-
activeAnchorIndex: this.activeAnchorIndex(),
|
|
102
|
-
insertCandidate: this.insertCandidate
|
|
103
|
-
? { commandIndex: this.insertCandidate.commandIndex, commandType: this.insertCandidate.commandType, x: this.insertCandidate.scene.x, y: this.insertCandidate.scene.y }
|
|
104
|
-
: undefined
|
|
105
|
-
};
|
|
106
|
-
}
|
|
107
|
-
/** 进入编辑(应用 changeControls(true)):吞没常规交互,选区 UI 换锚点覆盖层 */
|
|
108
|
-
enter(node) {
|
|
109
|
-
if (this.node)
|
|
110
|
-
this.exit();
|
|
111
|
-
const kind = pathEditKindOf(node);
|
|
112
|
-
if (!kind)
|
|
113
|
-
return false;
|
|
114
|
-
if (kind === 'path' && !parsePathData(node.raw.path))
|
|
115
|
-
return false;
|
|
116
|
-
if (kind === 'poly' && !Array.isArray(node.raw.points))
|
|
117
|
-
return false;
|
|
118
|
-
if (kind === 'line' && !(node instanceof LineNode))
|
|
119
|
-
return false;
|
|
120
|
-
this.node = node;
|
|
121
|
-
this.kind = kind;
|
|
122
|
-
this.activeAnchorKey = undefined;
|
|
123
|
-
this.insertCandidate = undefined;
|
|
124
|
-
// 编辑态让位(文本编辑退出;选中保持单选本节点)
|
|
125
|
-
this.host.document.exitEditing();
|
|
126
|
-
this.host.document.setSelection([node], 'update');
|
|
127
|
-
const onKeyDown = (e) => {
|
|
128
|
-
if (e.key === 'Escape' && this.node)
|
|
129
|
-
this.exit();
|
|
130
|
-
};
|
|
131
|
-
window.addEventListener('keydown', onKeyDown);
|
|
132
|
-
this.detachKey = () => window.removeEventListener('keydown', onKeyDown);
|
|
133
|
-
this.host.requestRenderAll();
|
|
134
|
-
return true;
|
|
135
|
-
}
|
|
136
|
-
/** 退出(Esc/点外/程序化同径):不发 object:modified——差量提交已在各操作点 */
|
|
137
|
-
exit() {
|
|
138
|
-
if (!this.node)
|
|
139
|
-
return;
|
|
140
|
-
this.node = null;
|
|
141
|
-
this.kind = null;
|
|
142
|
-
this.activeAnchorKey = undefined;
|
|
143
|
-
this.insertCandidate = undefined;
|
|
144
|
-
this.detachKey?.();
|
|
145
|
-
this.detachKey = null;
|
|
146
|
-
this.host.requestRenderAll();
|
|
147
|
-
}
|
|
148
|
-
exitByOutsideClick() {
|
|
149
|
-
this.exit();
|
|
150
|
-
}
|
|
151
|
-
// ── 命中(渲染/命中同源 currentHandles) ──
|
|
152
|
-
hitAnchor(cssX, cssY) {
|
|
153
|
-
const node = this.node;
|
|
154
|
-
if (!node)
|
|
155
|
-
return null;
|
|
156
|
-
const matrix = node.matrix;
|
|
157
|
-
let best = null;
|
|
158
|
-
let bestDist = ANCHOR_HIT_PX;
|
|
159
|
-
for (const h of this.currentHandles()) {
|
|
160
|
-
const scene = transformPoint(matrix, h.local.x, h.local.y);
|
|
161
|
-
const screen = this.host.toScreen(scene.x, scene.y);
|
|
162
|
-
const d = Math.hypot(screen.x - cssX, screen.y - cssY);
|
|
163
|
-
if (d <= bestDist) {
|
|
164
|
-
bestDist = d;
|
|
165
|
-
best = h.key;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
return best;
|
|
169
|
-
}
|
|
170
|
-
hitBody(sceneX, sceneY) {
|
|
171
|
-
const node = this.node;
|
|
172
|
-
if (!node)
|
|
173
|
-
return false;
|
|
174
|
-
// path/poly 按轮廓 fill 规则、line 按线段距离(containsPoint 多态)——
|
|
175
|
-
// 描边-only 开路径按轮廓内部的实用近似(fabric 编辑态点本体即可拖动)
|
|
176
|
-
return node.containsPoint(sceneX, sceneY);
|
|
177
|
-
}
|
|
178
|
-
findInsertCandidate(sceneX, sceneY) {
|
|
179
|
-
const node = this.node;
|
|
180
|
-
if (!node || this.kind !== 'path')
|
|
181
|
-
return null;
|
|
182
|
-
const commands = parsePathData(node.raw.path);
|
|
183
|
-
const center = pathBBoxCenter(commands);
|
|
184
|
-
if (!commands || !center)
|
|
185
|
-
return null;
|
|
186
|
-
return findInsertCandidate(commands, center, { x: sceneX, y: sceneY }, node.matrix, this.host.zoom) ?? null;
|
|
187
|
-
}
|
|
188
|
-
// ── 拖拽(逐帧绝对落点——幂等,同引擎其它手势的快照惯例) ──
|
|
189
|
-
startAnchorDrag(key) {
|
|
190
|
-
if (!this.node)
|
|
191
|
-
return false;
|
|
192
|
-
const exists = this.currentHandles().some((h) => h.key === key);
|
|
193
|
-
if (!exists)
|
|
194
|
-
return false;
|
|
195
|
-
this.captureDragBefore();
|
|
196
|
-
this.setActiveAnchor(key);
|
|
197
|
-
return true;
|
|
198
|
-
}
|
|
199
|
-
applyAnchorDrag(key, scenePoint) {
|
|
200
|
-
const node = this.node;
|
|
201
|
-
const kind = this.kind;
|
|
202
|
-
if (!node || !kind)
|
|
203
|
-
return;
|
|
204
|
-
const handle = this.currentHandles().find((h) => h.key === key);
|
|
205
|
-
if (!handle)
|
|
206
|
-
return;
|
|
207
|
-
const matrix = node.matrix;
|
|
208
|
-
const local = transformPoint(invert(matrix), scenePoint.x, scenePoint.y);
|
|
209
|
-
if (kind === 'path') {
|
|
210
|
-
const commands = parsePathData(node.raw.path);
|
|
211
|
-
const center = pathBBoxCenter(commands);
|
|
212
|
-
if (!commands || !center)
|
|
213
|
-
return;
|
|
214
|
-
const next = writePathCoordinate(commands, handle.commandIndex, handle.pointIndex, local, center);
|
|
215
|
-
this.writeBackWithCompensation(node, next, center, pathBBoxCenter(next), getBoundsOfPath(next));
|
|
216
|
-
}
|
|
217
|
-
else if (kind === 'poly') {
|
|
218
|
-
const points = node.raw.points;
|
|
219
|
-
const center = polyBBoxCenter(points);
|
|
220
|
-
if (!center)
|
|
221
|
-
return;
|
|
222
|
-
const next = writePolyPoint(points, handle.commandIndex, local, center);
|
|
223
|
-
let minX = Infinity;
|
|
224
|
-
let minY = Infinity;
|
|
225
|
-
let maxX = -Infinity;
|
|
226
|
-
let maxY = -Infinity;
|
|
227
|
-
for (const p of next) {
|
|
228
|
-
if (minX > p.x)
|
|
229
|
-
minX = p.x;
|
|
230
|
-
if (minY > p.y)
|
|
231
|
-
minY = p.y;
|
|
232
|
-
if (maxX < p.x)
|
|
233
|
-
maxX = p.x;
|
|
234
|
-
if (maxY < p.y)
|
|
235
|
-
maxY = p.y;
|
|
236
|
-
}
|
|
237
|
-
this.writeBackWithCompensation(node, next, center, polyBBoxCenter(next), { left: minX, top: minY, right: maxX, bottom: maxY });
|
|
238
|
-
}
|
|
239
|
-
else {
|
|
240
|
-
// line:x1..y2 即中心系本地位(无 pathOffset)——中心保持不动,left/top 按新 dims 反解
|
|
241
|
-
const props = handle.commandIndex === 0 ? { x1: local.x, y1: local.y } : { x2: local.x, y2: local.y };
|
|
242
|
-
const x1 = Number(props.x1 ?? node.raw.x1);
|
|
243
|
-
const y1 = Number(props.y1 ?? node.raw.y1);
|
|
244
|
-
const x2 = Number(props.x2 ?? node.raw.x2);
|
|
245
|
-
const y2 = Number(props.y2 ?? node.raw.y2);
|
|
246
|
-
const origin = objectOriginFromCenter({ ...node.raw, width: Math.abs(x2 - x1), height: Math.abs(y2 - y1) }, node.center);
|
|
247
|
-
this.host.document.setProps(node, { ...props, left: origin.x, top: origin.y }, { deferIndexRebuild: true });
|
|
248
|
-
}
|
|
249
|
-
this.host.requestRenderAll();
|
|
250
|
-
}
|
|
251
|
-
/** 本体拖动(fabric 编辑态拖对象体 = 移动对象) */
|
|
252
|
-
moveBodyBy(delta) {
|
|
253
|
-
const node = this.node;
|
|
254
|
-
if (!node)
|
|
255
|
-
return;
|
|
256
|
-
this.captureDragBefore();
|
|
257
|
-
this.host.document.setProps(node, { left: (node.raw.left ?? 0) + delta.x, top: (node.raw.top ?? 0) + delta.y }, { deferIndexRebuild: true });
|
|
258
|
-
this.host.requestRenderAll();
|
|
259
|
-
}
|
|
260
|
-
/** P5-4:拖拽起点的整对象快照(首次写入前一击捕获;提交后清空) */
|
|
261
|
-
captureDragBefore() {
|
|
262
|
-
this._dragBefore ??= this.node ? this.node.toObject() : null;
|
|
263
|
-
}
|
|
264
|
-
_dragBefore = null;
|
|
265
|
-
commit() {
|
|
266
|
-
const node = this.node;
|
|
267
|
-
if (!node)
|
|
268
|
-
return;
|
|
269
|
-
const before = this._dragBefore;
|
|
270
|
-
this._dragBefore = null;
|
|
271
|
-
this.host.document.applyTransform([node], () => ({}), 'modified', before ? { before: new Map([[node, before]]) } : undefined);
|
|
272
|
-
}
|
|
273
|
-
// ── 面板 API(compat changeControls 面消费) ──
|
|
274
|
-
/** 插点:立即提交(fabric modifyPathInsert);返回新锚点 key(随即可转拖拽) */
|
|
275
|
-
insertAnchor(candidate) {
|
|
276
|
-
const node = this.node;
|
|
277
|
-
if (!node || this.kind !== 'path')
|
|
278
|
-
return null;
|
|
279
|
-
const commands = parsePathData(node.raw.path);
|
|
280
|
-
const center = pathBBoxCenter(commands);
|
|
281
|
-
if (!commands || !center)
|
|
282
|
-
return null;
|
|
283
|
-
const next = insertAnchorAt(commands, center, candidate);
|
|
284
|
-
if (!next)
|
|
285
|
-
return null;
|
|
286
|
-
// 插点在段上(形状不变,bbox 不动)——无 left/top 补偿(fabric 同口径)
|
|
287
|
-
const before = node.toObject();
|
|
288
|
-
this.host.document.setProps(node, { path: next }, { deferIndexRebuild: true });
|
|
289
|
-
this.host.document.applyTransform([node], () => ({}), 'modified', { before: new Map([[node, before]]) });
|
|
290
|
-
const newCommand = candidate.commandType === 'Z' ? 'L' : candidate.commandType;
|
|
291
|
-
const key = `c_${candidate.commandIndex}_${newCommand}`;
|
|
292
|
-
this.insertCandidate = undefined;
|
|
293
|
-
this.setActiveAnchor(key);
|
|
294
|
-
this.host.requestRenderAll();
|
|
295
|
-
return key;
|
|
296
|
-
}
|
|
297
|
-
/** L↔C 锚点类型切换(fabric setAnchorPointType):changed 才写盘+提交;重高亮恒做 */
|
|
298
|
-
setAnchorType(index, type) {
|
|
299
|
-
const node = this.node;
|
|
300
|
-
if (!node || this.kind !== 'path')
|
|
301
|
-
return false;
|
|
302
|
-
const commands = parsePathData(node.raw.path);
|
|
303
|
-
if (!commands)
|
|
304
|
-
return false;
|
|
305
|
-
const r = setAnchorTypeOp(commands, index, type);
|
|
306
|
-
if (!r)
|
|
307
|
-
return false;
|
|
308
|
-
if (r.changed) {
|
|
309
|
-
const before = node.toObject();
|
|
310
|
-
this.host.document.setProps(node, { path: r.commands }, { deferIndexRebuild: true });
|
|
311
|
-
this.host.document.applyTransform([node], () => ({}), 'modified', { before: new Map([[node, before]]) });
|
|
312
|
-
}
|
|
313
|
-
this.setActiveAnchor(`c_${index}_${String(r.commands[index][0])}`);
|
|
314
|
-
this.host.requestRenderAll();
|
|
315
|
-
return r.changed;
|
|
316
|
-
}
|
|
317
|
-
/** 选中锚点(点击/插入/转换时):面板读位 + 覆盖层高亮 */
|
|
318
|
-
setActiveAnchor(key) {
|
|
319
|
-
if (this.activeAnchorKey === key)
|
|
320
|
-
return;
|
|
321
|
-
this.activeAnchorKey = key;
|
|
322
|
-
const node = this.node;
|
|
323
|
-
if (node)
|
|
324
|
-
this.host.document.events.fire('path:active-anchor-change', node, key);
|
|
325
|
-
this.host.requestRenderAll();
|
|
326
|
-
}
|
|
327
|
-
/** 应用 fabricCanvas 退出链的 resetAnchorStyles:清高亮(不发事件) */
|
|
328
|
-
resetAnchorStyles() {
|
|
329
|
-
if (this.activeAnchorKey === undefined)
|
|
330
|
-
return;
|
|
331
|
-
this.activeAnchorKey = undefined;
|
|
332
|
-
this.host.requestRenderAll();
|
|
333
|
-
}
|
|
334
|
-
activeAnchorIndex() {
|
|
335
|
-
const key = this.activeAnchorKey;
|
|
336
|
-
if (!key)
|
|
337
|
-
return undefined;
|
|
338
|
-
if (key.startsWith('c_')) {
|
|
339
|
-
const m = key.match(/^c_(\d+)_/);
|
|
340
|
-
const idx = m ? Number(m[1]) : NaN;
|
|
341
|
-
return Number.isFinite(idx) ? idx : undefined;
|
|
342
|
-
}
|
|
343
|
-
if (key.startsWith('p_'))
|
|
344
|
-
return Number(key.slice(2));
|
|
345
|
-
if (key === 'e0' || key === 'e1')
|
|
346
|
-
return Number(key[1]);
|
|
347
|
-
return undefined;
|
|
348
|
-
}
|
|
349
|
-
// ── 悬停(插点候选预览 + 光标) ──
|
|
350
|
-
hoverCursor(cssX, cssY, scenePoint) {
|
|
351
|
-
const anchor = this.hitAnchor(cssX, cssY);
|
|
352
|
-
if (anchor)
|
|
353
|
-
return anchor.includes('_CP_') ? 'crosshair' : 'default';
|
|
354
|
-
const candidate = this.findInsertCandidate(scenePoint.x, scenePoint.y);
|
|
355
|
-
if (candidate) {
|
|
356
|
-
this.updateInsertCandidate(candidate);
|
|
357
|
-
return 'copy';
|
|
358
|
-
}
|
|
359
|
-
this.updateInsertCandidate(undefined);
|
|
360
|
-
return this.hitBody(scenePoint.x, scenePoint.y) ? 'move' : '';
|
|
361
|
-
}
|
|
362
|
-
updateInsertCandidate(candidate) {
|
|
363
|
-
const prev = this.insertCandidate;
|
|
364
|
-
const same = !!prev &&
|
|
365
|
-
!!candidate &&
|
|
366
|
-
prev.commandIndex === candidate.commandIndex &&
|
|
367
|
-
prev.commandType === candidate.commandType &&
|
|
368
|
-
Math.abs(prev.scene.x - candidate.scene.x) < 0.1 &&
|
|
369
|
-
Math.abs(prev.scene.y - candidate.scene.y) < 0.1;
|
|
370
|
-
if (same || (!prev && !candidate))
|
|
371
|
-
return;
|
|
372
|
-
this.insertCandidate = candidate;
|
|
373
|
-
this.host.requestRenderAll();
|
|
374
|
-
}
|
|
375
|
-
// ── 覆盖层(两遍绘制:连接线在下、控制点在上——应用 _drawPathEditControls 同序) ──
|
|
376
|
-
buildOverlay(zoom) {
|
|
377
|
-
const node = this.node;
|
|
378
|
-
const kind = this.kind;
|
|
379
|
-
if (!node || !kind)
|
|
380
|
-
return [];
|
|
381
|
-
const matrix = node.matrix;
|
|
382
|
-
const quads = [...buildNodeBorderOverlay(node.aCoords, zoom)];
|
|
383
|
-
const sceneOf = (local) => transformPoint(matrix, local.x, local.y);
|
|
384
|
-
if (kind === 'path') {
|
|
385
|
-
const commands = parsePathData(node.raw.path);
|
|
386
|
-
const center = pathBBoxCenter(commands);
|
|
387
|
-
if (!commands || !center)
|
|
388
|
-
return quads;
|
|
389
|
-
const { handles, connections } = describePathEdit(commands, center);
|
|
390
|
-
// 第一遍:手柄↔锚点连接线
|
|
391
|
-
const lineW = CONNECTION_PX / zoom;
|
|
392
|
-
for (const c of connections)
|
|
393
|
-
quads.push(lineQuad(sceneOf(c.from), sceneOf(c.to), lineW, PATH_CONTROL_COLOR));
|
|
394
|
-
// 第二遍:控制点(锚点方点双层 / 手柄圆点 sprite / 选中锚点蓝填)
|
|
395
|
-
const anchorSize = ANCHOR_SIZE_PX / zoom;
|
|
396
|
-
const sprite = getCircleSprite();
|
|
397
|
-
const spriteSize = (sprite.width / 2) * 2 * (1 / zoom);
|
|
398
|
-
for (const h of handles) {
|
|
399
|
-
const scene = sceneOf(h.local);
|
|
400
|
-
if (h.kind === 'handle') {
|
|
401
|
-
quads.push({ matrix: [1, 0, 0, 1, scene.x, scene.y], dims: { x: spriteSize, y: spriteSize }, color: [1, 1, 1, 1], texture: sprite });
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
const active = h.key === this.activeAnchorKey;
|
|
405
|
-
quads.push({ matrix: [1, 0, 0, 1, scene.x, scene.y], dims: { x: anchorSize, y: anchorSize }, color: PATH_CONTROL_COLOR });
|
|
406
|
-
quads.push({ matrix: [1, 0, 0, 1, scene.x, scene.y], dims: { x: anchorSize - 2 / zoom, y: anchorSize - 2 / zoom }, color: active ? PATH_CONTROL_COLOR : CONTROL_WHITE });
|
|
407
|
-
}
|
|
408
|
-
}
|
|
409
|
-
// 插点预览(白填蓝环圆点)
|
|
410
|
-
if (this.insertCandidate) {
|
|
411
|
-
quads.push({ matrix: [1, 0, 0, 1, this.insertCandidate.scene.x, this.insertCandidate.scene.y], dims: { x: spriteSize, y: spriteSize }, color: [1, 1, 1, 1], texture: sprite });
|
|
412
|
-
}
|
|
413
|
-
}
|
|
414
|
-
else {
|
|
415
|
-
// poly/line:方点(双层蓝白;选中蓝填)
|
|
416
|
-
const anchorSize = ANCHOR_SIZE_PX / zoom;
|
|
417
|
-
for (const h of this.currentHandles()) {
|
|
418
|
-
const scene = sceneOf(h.local);
|
|
419
|
-
const active = h.key === this.activeAnchorKey;
|
|
420
|
-
quads.push({ matrix: [1, 0, 0, 1, scene.x, scene.y], dims: { x: anchorSize, y: anchorSize }, color: PATH_CONTROL_COLOR });
|
|
421
|
-
quads.push({ matrix: [1, 0, 0, 1, scene.x, scene.y], dims: { x: anchorSize - 2 / zoom, y: anchorSize - 2 / zoom }, color: active ? PATH_CONTROL_COLOR : CONTROL_WHITE });
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
return quads;
|
|
425
|
-
}
|
|
426
|
-
dispose() {
|
|
427
|
-
this.detachKey?.();
|
|
428
|
-
this.detachKey = null;
|
|
429
|
-
this.node = null;
|
|
430
|
-
this.kind = null;
|
|
431
|
-
}
|
|
432
|
-
// ── 内部 ──
|
|
433
|
-
currentHandles() {
|
|
434
|
-
const node = this.node;
|
|
435
|
-
const kind = this.kind;
|
|
436
|
-
if (!node || !kind)
|
|
437
|
-
return [];
|
|
438
|
-
if (kind === 'path') {
|
|
439
|
-
const commands = parsePathData(node.raw.path);
|
|
440
|
-
const center = pathBBoxCenter(commands);
|
|
441
|
-
if (!commands || !center)
|
|
442
|
-
return [];
|
|
443
|
-
return describePathEdit(commands, center).handles;
|
|
444
|
-
}
|
|
445
|
-
if (kind === 'poly') {
|
|
446
|
-
const points = node.raw.points;
|
|
447
|
-
const center = polyBBoxCenter(points);
|
|
448
|
-
if (!Array.isArray(points) || !center)
|
|
449
|
-
return [];
|
|
450
|
-
return describePolyEdit(points, center);
|
|
451
|
-
}
|
|
452
|
-
// line:两端点即中心系本地位(x1..y2 恒等映射)
|
|
453
|
-
const x1 = Number(node.raw.x1);
|
|
454
|
-
const y1 = Number(node.raw.y1);
|
|
455
|
-
const x2 = Number(node.raw.x2);
|
|
456
|
-
const y2 = Number(node.raw.y2);
|
|
457
|
-
if (![x1, y1, x2, y2].every(Number.isFinite))
|
|
458
|
-
return [];
|
|
459
|
-
return [
|
|
460
|
-
{ key: 'e0', kind: 'endpoint', commandIndex: 0, pointIndex: 0, local: { x: x1, y: y1 } },
|
|
461
|
-
{ key: 'e1', kind: 'endpoint', commandIndex: 1, pointIndex: 1, local: { x: x2, y: y2 } }
|
|
462
|
-
];
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* 拖点写盘 + left/top 补偿(fabric movePathPoint 参考点平移补偿的等价式):
|
|
466
|
-
* pathOffset 从 oldC 移到 newC 时中心平移 linear·(newC−oldC),未拖动点场景位
|
|
467
|
-
* 不动;left/top 由新 dims(新 bbox)反解。
|
|
468
|
-
*/
|
|
469
|
-
writeBackWithCompensation(node, nextPath, oldCenter, newC, bounds) {
|
|
470
|
-
if (!bounds)
|
|
471
|
-
return;
|
|
472
|
-
// 补偿系 = 父坐标系(center/left/top 同系):线性部取自身矩阵(fabric movePathPoint
|
|
473
|
-
// 的 calcOwnMatrix 口径——组内子节点用全矩阵会把父组缩放乘进平移量)
|
|
474
|
-
const own = node.ownMatrix;
|
|
475
|
-
const target = shiftedCenter(node.center, oldCenter, newC, [own[0], own[1], own[2], own[3]]);
|
|
476
|
-
const origin = objectOriginFromCenter({ ...node.raw, width: bounds.right - bounds.left, height: bounds.bottom - bounds.top }, target);
|
|
477
|
-
const props = this.kind === 'path' ? { path: nextPath } : { points: nextPath };
|
|
478
|
-
this.host.document.setProps(node, { ...props, left: origin.x, top: origin.y }, { deferIndexRebuild: true });
|
|
479
|
-
}
|
|
480
|
-
}
|