@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
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 引擎模式扭曲门面(批次 290 Phase C——自主仓 app/engineCompatWarp.ts verbatim
|
|
3
|
-
* 迁入;源=批次 66 ensureWarpvas 的引擎分支装配体)。
|
|
4
|
-
*
|
|
5
|
-
* 应用侧消费面(ImageTools 入口/useCanvasHotkey 的 ESC·Ctrl+Z·Y/fabricStore
|
|
6
|
-
* 旋钮态)以 FabricWarpvas 同形门面承接:undo/redo → warpUndo/warpRedo;
|
|
7
|
-
* 退出 → exitWarpMode(commit)(烘焙替换+raw 回放数据落盘在引擎侧完成);
|
|
8
|
-
* onWarpHistoryChange 回调 → 宿主 store 旋钮态(ports 注入)。
|
|
9
|
-
*/
|
|
10
|
-
import { CompatObject } from '../model/compatObject';
|
|
11
|
-
export const createEngineWarpvasFacade = (engine, ports) => {
|
|
12
|
-
engine.onWarpHistoryChange = (undoable, redoable) => {
|
|
13
|
-
ports.setWarpUndoable(undoable);
|
|
14
|
-
ports.setWarpRedoable(redoable);
|
|
15
|
-
};
|
|
16
|
-
const syncKnobs = () => {
|
|
17
|
-
const session = engine.warpSession;
|
|
18
|
-
ports.setWarpUndoable(session?.undoable ?? false);
|
|
19
|
-
ports.setWarpRedoable(session?.redoable ?? false);
|
|
20
|
-
};
|
|
21
|
-
return {
|
|
22
|
-
active: () => !!engine.warpSession,
|
|
23
|
-
async enter(target) {
|
|
24
|
-
const node = target instanceof CompatObject ? target.node : target?.node;
|
|
25
|
-
if (!node)
|
|
26
|
-
return false;
|
|
27
|
-
const ok = await engine.enterWarpMode(node);
|
|
28
|
-
syncKnobs();
|
|
29
|
-
return ok;
|
|
30
|
-
},
|
|
31
|
-
undo() {
|
|
32
|
-
const ok = engine.warpUndo();
|
|
33
|
-
syncKnobs();
|
|
34
|
-
return ok;
|
|
35
|
-
},
|
|
36
|
-
redo() {
|
|
37
|
-
const ok = engine.warpRedo();
|
|
38
|
-
syncKnobs();
|
|
39
|
-
return ok;
|
|
40
|
-
},
|
|
41
|
-
async exit(commit) {
|
|
42
|
-
// 历史提交已收口引擎侧:退出时 applyTransform('modified',
|
|
43
|
-
// action warpvas-image, before=会话前快照) → recordEngineObjectModified
|
|
44
|
-
// 录 MODIFY + objectModifiedDirtyHandler 刷内存 templates[i](单一录制
|
|
45
|
-
// 路径——门面不再手工 modifedElement,避免双条目)
|
|
46
|
-
const committed = await engine.exitWarpMode(commit).then((payload) => !!payload?.committed);
|
|
47
|
-
syncKnobs();
|
|
48
|
-
return committed;
|
|
49
|
-
}
|
|
50
|
-
};
|
|
51
|
-
};
|
|
@@ -1,582 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 图片扭曲编辑会话(批次 66):fabric-warpvas Warp 模式的引擎移植。
|
|
3
|
-
*
|
|
4
|
-
* 分层(fabric 模式同源栈):核心数学/渲染 = `warpvas` 纯库(区域模型/
|
|
5
|
-
* Bezier 边界/网格渲染 canvas2d+webgl/WarpState 序列化);交互层(fabric
|
|
6
|
-
* 绑定层 fabric-warpvas 的 fabric 对象网格/锚点)不进引擎——本控制器按
|
|
7
|
-
* cropSession 同款会话模式自建:
|
|
8
|
-
* - 进入:单选静态位图(imageEl 已加载;cropX/cropY 裁剪图与动画族不支持
|
|
9
|
-
* ——应用入口 croppedNotSupportWarp 同口径);核心库以 imageEl 原图建
|
|
10
|
-
* 3×3 网格(PS 默认口径);raw.warpvasState 存在则回放(重编辑链——
|
|
11
|
-
* **源必须异步装载 warpOriginalSrc 原图**,此前克隆当前 imageEl(=烘焙
|
|
12
|
-
* 结果)重放 = 二次扭曲;显示映射用退出时存的 warpDisplayScale/
|
|
13
|
-
* warpCoreAnchor——当前节点框是烘焙 bbox 的框,不能按 dims/core 直接算)
|
|
14
|
-
* - 锚点两族:region 顶点(相邻 region 共享顶点由核心库 updateVertexCoord
|
|
15
|
-
* 内建联动)+ 边界 Bezier 控制点(pm0/pm1,updateRegionBoundCoords 整边
|
|
16
|
-
* 写回)。顶点坐标由「边的端点几何求交」推导(top∩left=tl 等)——核心
|
|
17
|
-
* 库各边控制点列的遍历方向无契约,端点配对法对其免疫
|
|
18
|
-
* - 预览:核心库 render() 单例 canvas(GLTextureCache update 逐帧重传)作
|
|
19
|
-
* overlay 纹理 quad(fabric warpvasObject canvas.add 顶层同语义);网格
|
|
20
|
-
* 折线 + 锚点为屏幕恒定尺寸 overlay quad
|
|
21
|
-
* - 会话内历史:WarpState 栈 undo/redo(fabric enableHistory 同源),
|
|
22
|
-
* onWarpHistoryChange → 宿主(应用 fabricStore.warpUndoable/warpRedoable)
|
|
23
|
-
* - 退出(commit):render() 烘焙 dataURL 落 raw.src + 几何按
|
|
24
|
-
* getBoundingBoxInfo 重摆(objectOriginFromCenter 中心锚定)+
|
|
25
|
-
* warpvasState/warpOriginalSrc 回放数据;**会话期 raw 零写入**(取消
|
|
26
|
-
* 退出天然无损);项目历史提交归宿主 onExit 回调(应用
|
|
27
|
-
* templatesStore.modifedElement WarpvasAction.IMAGE 同 fabric 流)
|
|
28
|
-
*
|
|
29
|
-
* 坐标系(三层):核心画布系(warpvas——natural × warp.scale;fabric 绑定层
|
|
30
|
-
* 同款 setInputLimitSize(2000) 输入限值,超限图降采样后全部区域/边界/bbox
|
|
31
|
-
* 坐标都在缩放画布系)→ 本地中心系(node.localPoint,映射 =
|
|
32
|
-
* srcPx×(dims/coreSize) − dims/2)→ 场景系(node.matrix)。
|
|
33
|
-
*/
|
|
34
|
-
import { Warpvas } from 'warpvas';
|
|
35
|
-
import { AnimatedNode } from '../model/scene';
|
|
36
|
-
import { objectOriginFromCenter, transformPoint } from '../core/mat2d';
|
|
37
|
-
import { lineQuad } from '../render/selectionOverlay';
|
|
38
|
-
/** 锚点命中半径(屏幕 px;fabric controls cornerSize 口径的圆近似) */
|
|
39
|
-
const ANCHOR_HIT_PX = 12;
|
|
40
|
-
/** 顶点锚点半径(屏幕 px 恒定;应用 registerStyleSetter radius/zoom 的屏幕口径) */
|
|
41
|
-
const VERTEX_R_PX = 5;
|
|
42
|
-
/** 边控制点半径(屏幕 px,略小于顶点) */
|
|
43
|
-
const CURVE_R_PX = 4;
|
|
44
|
-
/** 网格线宽(屏幕 px 恒定) */
|
|
45
|
-
const MESH_LINE_PX = 1;
|
|
46
|
-
/** 默认网格密度(PS 口径 3×3) */
|
|
47
|
-
const DEFAULT_GRID = 3;
|
|
48
|
-
/** 输入限值(fabric 绑定层同款 2000——超大图降采样;无此限值时变形输出画布
|
|
49
|
-
* 无上限增长,浏览器画布尺寸超限会整幅空白(核心库文档明示),且每帧渲染
|
|
50
|
-
* 成本失控——用户报「一拖动就看不到了」的根因族) */
|
|
51
|
-
const WARP_INPUT_LIMIT = 2000;
|
|
52
|
-
/** Bezier 边界采样段数(overlay 折线化) */
|
|
53
|
-
const EDGE_SAMPLES = 10;
|
|
54
|
-
const MESH_COLOR = [0.2, 0.2, 0.2, 0.6];
|
|
55
|
-
const VERTEX_COLOR = [0.11, 0.35, 0.96, 1];
|
|
56
|
-
const CURVE_COLOR = [1, 1, 1, 0.9];
|
|
57
|
-
export class WarpSessionController {
|
|
58
|
-
host;
|
|
59
|
-
warp = null;
|
|
60
|
-
node = null;
|
|
61
|
-
beforeRaw = null;
|
|
62
|
-
/** 回放原图 src(首进 = 当前 src;重进 = warpOriginalSrc——烘焙图不再是原图) */
|
|
63
|
-
originalSrc = null;
|
|
64
|
-
undoStack = [];
|
|
65
|
-
redoStack = [];
|
|
66
|
-
/** 预览 canvas(核心库 render 产物);version 变化才重传纹理 */
|
|
67
|
-
previewCanvas = null;
|
|
68
|
-
previewVersion = 0;
|
|
69
|
-
renderedVersion = -1;
|
|
70
|
-
/** 会话源尺寸(首次 = 当前图 natural×scale;重进 = 装载的原图——坐标基准) */
|
|
71
|
-
coreSize = { w: 0, h: 0 };
|
|
72
|
-
/** 会话显示映射:core→node 本地系的缩放(首进 = dims/core;重进 = 退出时
|
|
73
|
-
* 存的 warpDisplayScale——节点框是烘焙 bbox 的框,dims/core 会把网格放大) */
|
|
74
|
-
displayScale = { x: 1, y: 1 };
|
|
75
|
-
/** 会话显示映射:映射到节点中心(本地原点)的 core 坐标点(首进 = core 中心;
|
|
76
|
-
* 重进 = 退出时存的 warpCoreAnchor = 当时 bbox 中心) */
|
|
77
|
-
coreAnchor = { x: 0, y: 0 };
|
|
78
|
-
/** 会话自持渲染画布(fabric 绑定层同款 setRenderingCanvas):destination
|
|
79
|
-
* 缺省时核心库每次 render 新建画布并 getContext('webgl')——**每次拖帧泄漏
|
|
80
|
-
* 一个活上下文**,连续拖拽撞浏览器上下文数上限(Chrome ~16)时浏览器强制
|
|
81
|
-
* 丢弃最老上下文 = 引擎主画布 →「一拖控制点整个画板不见了」(无头
|
|
82
|
-
* SwiftShader 不执行该上限故 e2e 难复现,真机 GPU 必现族)。自持画布让
|
|
83
|
-
* 全会话复用一个上下文,且 render 产物对象恒定(纹理缓存免逐帧换 key) */
|
|
84
|
-
renderCanvas = null;
|
|
85
|
-
constructor(host) {
|
|
86
|
-
this.host = host;
|
|
87
|
-
}
|
|
88
|
-
// —— WarpSessionHost 直通(EngineCanvas 以自身为宿主构造) ——
|
|
89
|
-
get document() {
|
|
90
|
-
return this.host.document;
|
|
91
|
-
}
|
|
92
|
-
get zoom() {
|
|
93
|
-
return this.host.zoom;
|
|
94
|
-
}
|
|
95
|
-
get textures() {
|
|
96
|
-
return this.host.textures;
|
|
97
|
-
}
|
|
98
|
-
toScreen(x, y) {
|
|
99
|
-
return this.host.toScreen(x, y);
|
|
100
|
-
}
|
|
101
|
-
requestRenderAll() {
|
|
102
|
-
this.host.requestRenderAll();
|
|
103
|
-
}
|
|
104
|
-
reloadNodeImage(nodeId) {
|
|
105
|
-
return this.host.reloadNodeImage(nodeId);
|
|
106
|
-
}
|
|
107
|
-
get active() {
|
|
108
|
-
return !!this.warp;
|
|
109
|
-
}
|
|
110
|
-
/** 会话目标(渲染层跳过常规绘制 / 门面读位) */
|
|
111
|
-
get target() {
|
|
112
|
-
return this.node;
|
|
113
|
-
}
|
|
114
|
-
/** 调试读位:全部锚点的源/屏幕坐标(hitAnchor 同路径自诊断) */
|
|
115
|
-
get debugAnchors() {
|
|
116
|
-
if (!this.warp || !this.node)
|
|
117
|
-
return [];
|
|
118
|
-
const out = [];
|
|
119
|
-
const bounds = this.currentBounds();
|
|
120
|
-
for (let row = 0; row < bounds.length; row++) {
|
|
121
|
-
for (let col = 0; col < bounds[row].length; col++) {
|
|
122
|
-
const region = bounds[row][col];
|
|
123
|
-
for (const dir of EDGE_DIR_LIST) {
|
|
124
|
-
const pts = region[dir];
|
|
125
|
-
if (!pts)
|
|
126
|
-
continue;
|
|
127
|
-
pts.forEach((pt, i) => {
|
|
128
|
-
const scene = this.toScene(pt);
|
|
129
|
-
out.push({ row, col, dir, i, srcX: Math.round(pt.x), srcY: Math.round(pt.y), sceneX: Math.round(scene.x), sceneY: Math.round(scene.y) });
|
|
130
|
-
});
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
return out;
|
|
135
|
-
}
|
|
136
|
-
/** 调试读位:预览画布指纹(对象恒等性——render 是否复用单例画布)+ 纹理缓存统计 */
|
|
137
|
-
get debugPreviewInfo() {
|
|
138
|
-
if (!this.previewCanvas)
|
|
139
|
-
return null;
|
|
140
|
-
const c = this.previewCanvas;
|
|
141
|
-
if (c.__probeId === undefined)
|
|
142
|
-
c.__probeId = Math.random();
|
|
143
|
-
const box = this.warp ? this.warp.getBoundingBoxInfo() : null;
|
|
144
|
-
return { canvasId: c.__probeId, width: c.width, height: c.height, version: this.previewVersion, box, dataURL: c.width * c.height <= 400000 ? c.toDataURL('image/png') : undefined };
|
|
145
|
-
}
|
|
146
|
-
/** 调试读位:首个 region 边界样本 + 会话源尺寸(重进须 = 原图——烘焙图即二次扭曲) */
|
|
147
|
-
get debugBoundsSample() {
|
|
148
|
-
if (!this.warp || !this.coreSize.w)
|
|
149
|
-
return null;
|
|
150
|
-
return { region: this.currentBounds()[0]?.[0] ?? null, natural: { w: this.coreSize.w, h: this.coreSize.h } };
|
|
151
|
-
}
|
|
152
|
-
/** 应用入口:进入扭曲会话(imageEl 未挂/裁剪图/动画族拒绝)。重编辑链异步
|
|
153
|
-
* 装载 warpOriginalSrc 原图(克隆当前 imageEl 是烘焙结果——其上重放旧态
|
|
154
|
-
* = 二次扭曲,用户报「第二次进去不应该用已经扭曲的」根因) */
|
|
155
|
-
async enter(node, opts) {
|
|
156
|
-
if (this.warp)
|
|
157
|
-
void this.cancel();
|
|
158
|
-
if (!node.imageEl || node.cropRect || node instanceof AnimatedNode)
|
|
159
|
-
return false;
|
|
160
|
-
if (!node.imageEl.naturalWidth || !node.imageEl.naturalHeight)
|
|
161
|
-
return false;
|
|
162
|
-
const raw = node.raw;
|
|
163
|
-
this.originalSrc = raw.warpOriginalSrc ?? raw.src ?? null;
|
|
164
|
-
const el = node.imageEl;
|
|
165
|
-
// 重编辑:装载原图作核心源(失败降级 = 烘焙图全新会话,不回放)
|
|
166
|
-
const warpOriginalSrc = raw.warpOriginalSrc;
|
|
167
|
-
let source = el;
|
|
168
|
-
let originalLoaded = false;
|
|
169
|
-
if (warpOriginalSrc) {
|
|
170
|
-
try {
|
|
171
|
-
const original = await this.host.loadImage(warpOriginalSrc, raw.crossOrigin ?? undefined);
|
|
172
|
-
if (original?.naturalWidth) {
|
|
173
|
-
source = original;
|
|
174
|
-
originalLoaded = true;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
catch {
|
|
178
|
-
/* 装载失败降级 */
|
|
179
|
-
}
|
|
180
|
-
}
|
|
181
|
-
const warp = new Warpvas(source, opts?.gridRows ?? DEFAULT_GRID, opts?.gridCols ?? DEFAULT_GRID);
|
|
182
|
-
// fabric 绑定层同款输入限值:超大图降采样(无限制时变形输出画布无上限,
|
|
183
|
-
// 超浏览器画布上限 = 整幅空白预览)。此后全部核心坐标在降采样画布系
|
|
184
|
-
warp.setInputLimitSize({ width: WARP_INPUT_LIMIT, height: WARP_INPUT_LIMIT });
|
|
185
|
-
// fabric 绑定层同款自持渲染画布(上下文泄漏防护,见 renderCanvas 字注)
|
|
186
|
-
this.renderCanvas = document.createElement('canvas');
|
|
187
|
-
warp.setRenderingCanvas(this.renderCanvas);
|
|
188
|
-
const sourceNatural = source === el ? el : source;
|
|
189
|
-
this.coreSize = { w: sourceNatural.naturalWidth * warp.scale.x, h: sourceNatural.naturalHeight * warp.scale.y };
|
|
190
|
-
// 会话显示映射:重进用退出时存的(节点框是烘焙 bbox 的框);首进 = 默认
|
|
191
|
-
const storedScale = raw.warpDisplayScale;
|
|
192
|
-
const storedAnchor = raw.warpCoreAnchor;
|
|
193
|
-
if (originalLoaded && storedScale && typeof storedScale.x === 'number' && storedAnchor && typeof storedAnchor.x === 'number') {
|
|
194
|
-
this.displayScale = { x: storedScale.x, y: storedScale.y ?? storedScale.x };
|
|
195
|
-
this.coreAnchor = { x: storedAnchor.x, y: storedAnchor.y ?? storedAnchor.x };
|
|
196
|
-
}
|
|
197
|
-
else {
|
|
198
|
-
this.displayScale = { x: node.dims.x / this.coreSize.w, y: node.dims.y / this.coreSize.h };
|
|
199
|
-
this.coreAnchor = { x: this.coreSize.w / 2, y: this.coreSize.h / 2 };
|
|
200
|
-
}
|
|
201
|
-
const replay = originalLoaded ? raw.warpvasState : undefined;
|
|
202
|
-
if (replay && Array.isArray(replay.splitPoints)) {
|
|
203
|
-
try {
|
|
204
|
-
warp.setWarpState(replay.splitPoints, replay.regionBounds ?? null);
|
|
205
|
-
}
|
|
206
|
-
catch {
|
|
207
|
-
/* 状态损坏按全新会话继续 */
|
|
208
|
-
}
|
|
209
|
-
}
|
|
210
|
-
this.node = node;
|
|
211
|
-
this.warp = warp;
|
|
212
|
-
this.beforeRaw = node.toObject();
|
|
213
|
-
this.undoStack = [this.snapshot()];
|
|
214
|
-
this.redoStack = [];
|
|
215
|
-
this.fireHistory();
|
|
216
|
-
this.refreshPreview();
|
|
217
|
-
this.requestRenderAll();
|
|
218
|
-
return true;
|
|
219
|
-
}
|
|
220
|
-
/** 锚点命中(屏幕 px)。**顶点必须先于边控制点**:边控制点落在角点旁
|
|
221
|
-
* 1/3 边长处,低缩放/小图下两者屏幕距离 < 命中半径——若 curve 先判,
|
|
222
|
-
* 抓角会抓成边控制点(角不动、边鼓包——「拖动发飘」的根因,实测 120px
|
|
223
|
-
* 图 @0.48 缩放下角点旁 curve 控点仅 6.2 屏幕像素) */
|
|
224
|
-
hitAnchor(cssX, cssY) {
|
|
225
|
-
const vertex = this.hitAnchorsOfKind(cssX, cssY, 'vertex');
|
|
226
|
-
if (vertex)
|
|
227
|
-
return vertex;
|
|
228
|
-
return this.hitAnchorsOfKind(cssX, cssY, 'curve');
|
|
229
|
-
}
|
|
230
|
-
hitAnchorsOfKind(cssX, cssY, kind) {
|
|
231
|
-
const bounds = this.currentBounds();
|
|
232
|
-
let best = null;
|
|
233
|
-
for (let row = 0; row < bounds.length; row++) {
|
|
234
|
-
for (let col = 0; col < bounds[row].length; col++) {
|
|
235
|
-
const region = bounds[row][col];
|
|
236
|
-
if (kind === 'vertex') {
|
|
237
|
-
for (const pos of VERTEX_POS_LIST) {
|
|
238
|
-
const pt = vertexCoord(region, pos);
|
|
239
|
-
if (!pt)
|
|
240
|
-
continue;
|
|
241
|
-
const dist = this.screenDist(pt, cssX, cssY);
|
|
242
|
-
if (dist <= ANCHOR_HIT_PX && (!best || dist < best.dist))
|
|
243
|
-
best = { anchor: { kind: 'vertex', row, col, pos }, dist };
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
else {
|
|
247
|
-
for (const dir of EDGE_DIR_LIST) {
|
|
248
|
-
const pts = region[dir];
|
|
249
|
-
if (!pts || pts.length < 4)
|
|
250
|
-
continue;
|
|
251
|
-
for (const index of [0, 1]) {
|
|
252
|
-
const dist = this.screenDist(pts[index + 1], cssX, cssY);
|
|
253
|
-
if (dist <= ANCHOR_HIT_PX && (!best || dist < best.dist))
|
|
254
|
-
best = { anchor: { kind: 'curve', row, col, dir, index }, dist };
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
}
|
|
259
|
-
}
|
|
260
|
-
return best?.anchor ?? null;
|
|
261
|
-
}
|
|
262
|
-
/** 拖拽应用(场景系坐标 → 源像素系 → 核心库更新) */
|
|
263
|
-
applyAnchorDrag(anchor, scenePoint) {
|
|
264
|
-
const warp = this.warp;
|
|
265
|
-
if (!warp)
|
|
266
|
-
return;
|
|
267
|
-
const src = this.toSource(scenePoint);
|
|
268
|
-
if (anchor.kind === 'vertex') {
|
|
269
|
-
warp.updateVertexCoord(anchor.row, anchor.col, anchor.pos, src);
|
|
270
|
-
}
|
|
271
|
-
else {
|
|
272
|
-
const pts = this.currentBounds()[anchor.row]?.[anchor.col]?.[anchor.dir];
|
|
273
|
-
if (!pts || pts.length < 4)
|
|
274
|
-
return;
|
|
275
|
-
const next = pts.map((p) => ({ ...p }));
|
|
276
|
-
next[anchor.index + 1] = src;
|
|
277
|
-
warp.updateRegionBoundCoords(anchor.row, anchor.col, anchor.dir, [next[0], next[1], next[2], next[3]]);
|
|
278
|
-
}
|
|
279
|
-
this.refreshPreview();
|
|
280
|
-
this.requestRenderAll();
|
|
281
|
-
}
|
|
282
|
-
/** 手势收尾:状态入撤销栈 */
|
|
283
|
-
endDrag() {
|
|
284
|
-
if (!this.warp)
|
|
285
|
-
return;
|
|
286
|
-
this.undoStack.push(this.snapshot());
|
|
287
|
-
this.redoStack = [];
|
|
288
|
-
this.fireHistory();
|
|
289
|
-
}
|
|
290
|
-
undo() {
|
|
291
|
-
if (!this.warp || this.undoStack.length <= 1)
|
|
292
|
-
return false;
|
|
293
|
-
this.redoStack.push(this.undoStack.pop());
|
|
294
|
-
this.restore(this.undoStack[this.undoStack.length - 1]);
|
|
295
|
-
this.afterHistoryStep();
|
|
296
|
-
return true;
|
|
297
|
-
}
|
|
298
|
-
redo() {
|
|
299
|
-
if (!this.warp)
|
|
300
|
-
return false;
|
|
301
|
-
const next = this.redoStack.pop();
|
|
302
|
-
if (!next)
|
|
303
|
-
return false;
|
|
304
|
-
this.undoStack.push(next);
|
|
305
|
-
this.restore(next);
|
|
306
|
-
this.afterHistoryStep();
|
|
307
|
-
return true;
|
|
308
|
-
}
|
|
309
|
-
afterHistoryStep() {
|
|
310
|
-
this.fireHistory();
|
|
311
|
-
this.refreshPreview();
|
|
312
|
-
this.requestRenderAll();
|
|
313
|
-
}
|
|
314
|
-
get undoable() {
|
|
315
|
-
return this.undoStack.length > 1;
|
|
316
|
-
}
|
|
317
|
-
get redoable() {
|
|
318
|
-
return this.redoStack.length > 0;
|
|
319
|
-
}
|
|
320
|
-
/** 当前 WarpState(门面读位) */
|
|
321
|
-
getWarpState() {
|
|
322
|
-
return this.warp ? this.snapshot() : null;
|
|
323
|
-
}
|
|
324
|
-
/** 会话覆盖层:预览纹理 quad + 网格折线 + 锚点(屏幕恒定尺寸) */
|
|
325
|
-
buildOverlay() {
|
|
326
|
-
if (!this.warp || !this.node)
|
|
327
|
-
return [];
|
|
328
|
-
const zoom = this.zoom;
|
|
329
|
-
const quads = [];
|
|
330
|
-
// 预览 quad:烘焙 canvas 覆盖 bbox(源像素 → 本地中心系偏移 → 场景矩阵)
|
|
331
|
-
if (this.previewCanvas) {
|
|
332
|
-
if (this.renderedVersion !== this.previewVersion) {
|
|
333
|
-
this.textures.update(this.previewCanvas);
|
|
334
|
-
this.renderedVersion = this.previewVersion;
|
|
335
|
-
}
|
|
336
|
-
const local = this.localFromSourceBox(this.warp.getBoundingBoxInfo());
|
|
337
|
-
quads.push({
|
|
338
|
-
matrix: this.quadMatrix(local.cx, local.cy),
|
|
339
|
-
dims: { x: local.w, y: local.h },
|
|
340
|
-
color: [1, 1, 1, 1],
|
|
341
|
-
texture: this.previewCanvas
|
|
342
|
-
});
|
|
343
|
-
}
|
|
344
|
-
// 网格 + 锚点
|
|
345
|
-
const bounds = this.currentBounds();
|
|
346
|
-
const seenVertex = new Set();
|
|
347
|
-
const seenCurve = new Set();
|
|
348
|
-
for (const regionRow of bounds) {
|
|
349
|
-
for (const region of regionRow) {
|
|
350
|
-
for (const dir of EDGE_DIR_LIST) {
|
|
351
|
-
const pts = region[dir];
|
|
352
|
-
if (!pts || pts.length < 4)
|
|
353
|
-
continue;
|
|
354
|
-
let prev = this.toScene(pts[0]);
|
|
355
|
-
for (let s = 1; s <= EDGE_SAMPLES; s++) {
|
|
356
|
-
const scene = this.toScene(cubicPoint(pts[0], pts[1], pts[2], pts[3], s / EDGE_SAMPLES));
|
|
357
|
-
quads.push(lineQuad(prev, scene, MESH_LINE_PX / zoom, MESH_COLOR));
|
|
358
|
-
prev = scene;
|
|
359
|
-
}
|
|
360
|
-
for (const index of [0, 1]) {
|
|
361
|
-
const pt = pts[index + 1];
|
|
362
|
-
const key = `${Math.round(pt.x)},${Math.round(pt.y)}`;
|
|
363
|
-
if (!seenCurve.has(key)) {
|
|
364
|
-
seenCurve.add(key);
|
|
365
|
-
quads.push(dotQuad(this.toScene(pt), CURVE_R_PX, CURVE_COLOR, zoom));
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
for (const pos of VERTEX_POS_LIST) {
|
|
370
|
-
const pt = vertexCoord(region, pos);
|
|
371
|
-
if (!pt)
|
|
372
|
-
continue;
|
|
373
|
-
const key = `${Math.round(pt.x)},${Math.round(pt.y)}`;
|
|
374
|
-
if (seenVertex.has(key))
|
|
375
|
-
continue;
|
|
376
|
-
seenVertex.add(key);
|
|
377
|
-
quads.push(dotQuad(this.toScene(pt), VERTEX_R_PX, VERTEX_COLOR, zoom));
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
}
|
|
381
|
-
return quads;
|
|
382
|
-
}
|
|
383
|
-
/** 悬停光标(pointer 消费) */
|
|
384
|
-
hoverCursor(cssX, cssY) {
|
|
385
|
-
return this.hitAnchor(cssX, cssY) ? 'pointer' : 'default';
|
|
386
|
-
}
|
|
387
|
-
/** 退出(commit=true 烘焙替换;false 取消——会话期 raw 零写入,天然无损)。
|
|
388
|
-
* 烘焙产物与几何在摘态前同步算好,随后**立即同步摘除会话态**(覆盖层撤销、
|
|
389
|
-
* 目标节点恢复常规绘制、核心库 dispose),再异步落 raw + 纹理重载——杜绝
|
|
390
|
-
* 「覆盖层已撤但节点仍被渲染层跳过」的不可见窗口(烘焙大图可达秒级),
|
|
391
|
-
* enter 内联 cancel 的异步 teardown 也不再可能抹掉新会话态 */
|
|
392
|
-
async exit(commit) {
|
|
393
|
-
const warp = this.warp;
|
|
394
|
-
const node = this.node;
|
|
395
|
-
if (!warp || !node)
|
|
396
|
-
return null;
|
|
397
|
-
const before = this.beforeRaw;
|
|
398
|
-
let bake = null;
|
|
399
|
-
if (commit && !warp.isUnwarped()) {
|
|
400
|
-
const dataURL = warp.render().toDataURL('image/png');
|
|
401
|
-
const box = warp.getBoundingBoxInfo();
|
|
402
|
-
const state = warp.getWarpState();
|
|
403
|
-
const local = this.localFromSourceBox(box);
|
|
404
|
-
const scale = this.sourceToDisplayScale();
|
|
405
|
-
const nextWidth = Math.max(1, Math.round(box.width * scale.x));
|
|
406
|
-
const nextHeight = Math.max(1, Math.round(box.height * scale.y));
|
|
407
|
-
// 新中心 = 旧中心 + bbox 中心本地偏移经矩阵线性部投影(fabric warpvasObject
|
|
408
|
-
// 居中锚定口径);left/top 由 objectOriginFromCenter 按新宽高反解
|
|
409
|
-
const matrix = node.matrix;
|
|
410
|
-
const newCenter = {
|
|
411
|
-
x: node.center.x + matrix[0] * local.cx + matrix[2] * local.cy,
|
|
412
|
-
y: node.center.y + matrix[1] * local.cx + matrix[3] * local.cy
|
|
413
|
-
};
|
|
414
|
-
const origin = objectOriginFromCenter({ ...node.raw, width: nextWidth, height: nextHeight }, newCenter);
|
|
415
|
-
// 会话映射存档:重进时节点框 = 本次烘焙 bbox 的框,core→显示映射(缩放
|
|
416
|
-
// 与锚定)必须存档复用——bbox 中心(core 系)即下次会话的锚点
|
|
417
|
-
const boxCenter = { x: box.width / 2 - box.offsetX, y: box.height / 2 - box.offsetY };
|
|
418
|
-
bake = {
|
|
419
|
-
dataURL,
|
|
420
|
-
state,
|
|
421
|
-
nextWidth,
|
|
422
|
-
nextHeight,
|
|
423
|
-
left: origin.x,
|
|
424
|
-
top: origin.y,
|
|
425
|
-
originalSrc: this.originalSrc,
|
|
426
|
-
displayScale: { x: this.displayScale.x, y: this.displayScale.y },
|
|
427
|
-
coreAnchor: boxCenter
|
|
428
|
-
};
|
|
429
|
-
}
|
|
430
|
-
this.teardown(warp);
|
|
431
|
-
let committed = false;
|
|
432
|
-
if (bake) {
|
|
433
|
-
node.set({
|
|
434
|
-
src: bake.dataURL,
|
|
435
|
-
width: bake.nextWidth,
|
|
436
|
-
height: bake.nextHeight,
|
|
437
|
-
left: bake.left,
|
|
438
|
-
top: bake.top,
|
|
439
|
-
warpvasState: bake.state,
|
|
440
|
-
warpOriginalSrc: bake.originalSrc ?? undefined,
|
|
441
|
-
warpDisplayScale: bake.displayScale,
|
|
442
|
-
warpCoreAnchor: bake.coreAnchor
|
|
443
|
-
});
|
|
444
|
-
await this.reloadNodeImage(node.id);
|
|
445
|
-
// 事件驱动收尾(cropSession.exit 同款通路):object:modified(action
|
|
446
|
-
// warpvas-image, before=会话前快照)——应用侧 recordEngineObjectModified
|
|
447
|
-
// 录 MODIFY 历史(替代门面手工提交,单一录制路径)+
|
|
448
|
-
// objectModifiedDirtyHandler 标脏/刷内存 templates[i](扭曲状态入
|
|
449
|
-
// templates[i]——保存/翻页真正读的数据源;此前退出零事件,store 不知
|
|
450
|
-
// 情 =「扭曲状态没有记录」根因:保存回旧图、翻页回旧图)
|
|
451
|
-
this.host.document.applyTransform([node], () => ({}), 'modified', { action: 'warpvas-image', before: new Map([[node, before]]) });
|
|
452
|
-
committed = true;
|
|
453
|
-
}
|
|
454
|
-
this.requestRenderAll();
|
|
455
|
-
return { committed, node, before, after: node.toObject() };
|
|
456
|
-
}
|
|
457
|
-
/** 取消退出(ESC/异常清理——应用 forceCleanupWarp 等价物) */
|
|
458
|
-
async cancel() {
|
|
459
|
-
await this.exit(false);
|
|
460
|
-
}
|
|
461
|
-
teardown(warp = this.warp) {
|
|
462
|
-
if (this.previewCanvas)
|
|
463
|
-
this.textures.remove(this.previewCanvas);
|
|
464
|
-
warp?.dispose?.();
|
|
465
|
-
this.warp = null;
|
|
466
|
-
this.node = null;
|
|
467
|
-
this.beforeRaw = null;
|
|
468
|
-
this.originalSrc = null;
|
|
469
|
-
this.undoStack = [];
|
|
470
|
-
this.redoStack = [];
|
|
471
|
-
this.previewCanvas = null;
|
|
472
|
-
this.previewVersion = 0;
|
|
473
|
-
this.renderedVersion = -1;
|
|
474
|
-
this.coreSize = { w: 0, h: 0 };
|
|
475
|
-
this.displayScale = { x: 1, y: 1 };
|
|
476
|
-
this.coreAnchor = { x: 0, y: 0 };
|
|
477
|
-
this.renderCanvas = null;
|
|
478
|
-
}
|
|
479
|
-
// —— 内部:状态读写 / 坐标映射 ——
|
|
480
|
-
snapshot() {
|
|
481
|
-
return this.warp.getWarpState();
|
|
482
|
-
}
|
|
483
|
-
restore(state) {
|
|
484
|
-
this.warp.setWarpState(state.splitPoints, state.regionBounds);
|
|
485
|
-
}
|
|
486
|
-
/** 当前变形区域边界(getWarpState 权威读位——originalRegions 是未变形网格) */
|
|
487
|
-
currentBounds() {
|
|
488
|
-
if (!this.warp)
|
|
489
|
-
return [];
|
|
490
|
-
return this.warp.getWarpState().regionBounds ?? [];
|
|
491
|
-
}
|
|
492
|
-
/** 核心画布系 → 显示系缩放(会话映射——重进时非 dims/core) */
|
|
493
|
-
sourceToDisplayScale() {
|
|
494
|
-
return { x: this.displayScale.x, y: this.displayScale.y };
|
|
495
|
-
}
|
|
496
|
-
/** 预览/锚点 quad 矩阵:节点矩阵 × 纯平移(cropGhostNode 同构——线性部保持节点姿态) */
|
|
497
|
-
quadMatrix(localX, localY) {
|
|
498
|
-
return multiplyTranslate(this.node.matrix, localX, localY);
|
|
499
|
-
}
|
|
500
|
-
/** 核心画布系点 → 场景点(会话映射:coreAnchor 映射到节点中心 + displayScale) */
|
|
501
|
-
toScene(src) {
|
|
502
|
-
const node = this.node;
|
|
503
|
-
return transformPoint(node.matrix, (src.x - this.coreAnchor.x) * this.displayScale.x, (src.y - this.coreAnchor.y) * this.displayScale.y);
|
|
504
|
-
}
|
|
505
|
-
/** 场景点 → 核心画布系点(toScene 逆映射) */
|
|
506
|
-
toSource(scene) {
|
|
507
|
-
const node = this.node;
|
|
508
|
-
const local = node.localPoint(scene.x, scene.y);
|
|
509
|
-
return { x: local.x / this.displayScale.x + this.coreAnchor.x, y: local.y / this.displayScale.y + this.coreAnchor.y };
|
|
510
|
-
}
|
|
511
|
-
screenDist(src, cssX, cssY) {
|
|
512
|
-
const scene = this.toScene(src);
|
|
513
|
-
const s = this.toScreen(scene.x, scene.y);
|
|
514
|
-
return Math.hypot(s.x - cssX, s.y - cssY);
|
|
515
|
-
}
|
|
516
|
-
/** bbox → 本地中心系矩形(预览 quad 定位/几何重摆共用)。
|
|
517
|
-
* 核心库 box 语义(render 画布实测标定):offsetX/Y 是**渲染画布相对 core
|
|
518
|
-
* 原点的位移量**(内容向上/右凸出为正),画布像素 p ↔ core 坐标 p − offset
|
|
519
|
-
* ——即画布内容区在 core 系 = [−offset, −offset+size]。quad 中心因此取
|
|
520
|
-
* (−offset + size/2 − core/2);此前把 offset 当 core 系 bbox 顶用,拖动
|
|
521
|
-
* 顶边控制点时整图平移 2×offset×scale(用户报「拖顶控图片下移」根因) */
|
|
522
|
-
localFromSourceBox(box) {
|
|
523
|
-
return {
|
|
524
|
-
cx: (box.width / 2 - box.offsetX - this.coreAnchor.x) * this.displayScale.x,
|
|
525
|
-
cy: (box.height / 2 - box.offsetY - this.coreAnchor.y) * this.displayScale.y,
|
|
526
|
-
w: box.width * this.displayScale.x,
|
|
527
|
-
h: box.height * this.displayScale.y
|
|
528
|
-
};
|
|
529
|
-
}
|
|
530
|
-
refreshPreview() {
|
|
531
|
-
if (!this.warp)
|
|
532
|
-
return;
|
|
533
|
-
const prev = this.previewCanvas;
|
|
534
|
-
this.previewCanvas = this.warp.render();
|
|
535
|
-
// 核心库在包围盒变化时返回**新 canvas 对象**(单例复用仅限尺寸不变——
|
|
536
|
-
// 实测对象恒等性逐帧漂移):旧对象若留在纹理缓存会逐帧堆积,即时回收
|
|
537
|
-
if (prev && prev !== this.previewCanvas)
|
|
538
|
-
this.textures.remove(prev);
|
|
539
|
-
this.previewVersion++;
|
|
540
|
-
}
|
|
541
|
-
fireHistory() {
|
|
542
|
-
this.host.onWarpHistoryChange?.(this.undoable, this.redoable);
|
|
543
|
-
}
|
|
544
|
-
}
|
|
545
|
-
const VERTEX_POS_LIST = ['tl', 'tr', 'bl', 'br'];
|
|
546
|
-
const EDGE_DIR_LIST = ['top', 'right', 'bottom', 'left'];
|
|
547
|
-
/**
|
|
548
|
-
* region 顶点坐标:边的端点几何求交推导。核心库各边控制点列(p0..p3)的
|
|
549
|
-
* 遍历方向无契约(top 从 tl 起还是从 tr 起未文档化),取「两条邻边端点中
|
|
550
|
-
* 距离最近的一对」作为共享角——对遍历方向/形变后内凹均免疫。
|
|
551
|
-
*/
|
|
552
|
-
const vertexCoord = (region, pos) => {
|
|
553
|
-
const hEdge = region[pos === 'tl' || pos === 'tr' ? 'top' : 'bottom'];
|
|
554
|
-
const vEdge = region[pos === 'tl' || pos === 'bl' ? 'left' : 'right'];
|
|
555
|
-
if (!hEdge || hEdge.length < 4 || !vEdge || vEdge.length < 4)
|
|
556
|
-
return null;
|
|
557
|
-
let best = null;
|
|
558
|
-
for (const h of [hEdge[0], hEdge[3]]) {
|
|
559
|
-
for (const v of [vEdge[0], vEdge[3]]) {
|
|
560
|
-
const dist = Math.hypot(h.x - v.x, h.y - v.y);
|
|
561
|
-
if (!best || dist < best.dist)
|
|
562
|
-
best = { pt: { x: (h.x + v.x) / 2, y: (h.y + v.y) / 2 }, dist };
|
|
563
|
-
}
|
|
564
|
-
}
|
|
565
|
-
return best?.pt ?? null;
|
|
566
|
-
};
|
|
567
|
-
/** 立方 Bezier 取点(网格边采样) */
|
|
568
|
-
const cubicPoint = (p0, p1, p2, p3, t) => {
|
|
569
|
-
const u = 1 - t;
|
|
570
|
-
return {
|
|
571
|
-
x: u * u * u * p0.x + 3 * u * u * t * p1.x + 3 * u * t * t * p2.x + t * t * t * p3.x,
|
|
572
|
-
y: u * u * u * p0.y + 3 * u * u * t * p1.y + 3 * u * t * t * p2.y + t * t * t * p3.y
|
|
573
|
-
};
|
|
574
|
-
};
|
|
575
|
-
/** 屏幕恒定尺寸圆点 quad(正方形近似——半径 ≤5px 视觉差异不可辨,省 sprite 烘焙) */
|
|
576
|
-
const dotQuad = (scene, radiusPx, color, zoom) => ({
|
|
577
|
-
matrix: [1, 0, 0, 1, scene.x, scene.y],
|
|
578
|
-
dims: { x: (radiusPx * 2) / zoom, y: (radiusPx * 2) / zoom },
|
|
579
|
-
color
|
|
580
|
-
});
|
|
581
|
-
/** 矩阵 × 纯平移(quad 定位用——线性部保持节点姿态) */
|
|
582
|
-
const multiplyTranslate = (m, tx, ty) => [m[0], m[1], m[2], m[3], m[0] * tx + m[2] * ty + m[4], m[1] * tx + m[3] * ty + m[5]];
|