@yft-design/engine 0.0.0-stage → 0.0.1
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 +39 -2
- package/dist/EngineCanvas.d.ts +500 -0
- package/dist/EngineCanvas.js +927 -0
- package/dist/core/canvasPerf.d.ts +23 -0
- package/dist/core/canvasPerf.js +170 -0
- package/dist/core/color.d.ts +52 -0
- package/dist/core/color.js +107 -0
- package/dist/core/distanceField.d.ts +15 -0
- package/dist/core/distanceField.js +92 -0
- package/dist/core/events.d.ts +34 -0
- package/dist/core/events.js +52 -0
- package/dist/core/gradient.d.ts +97 -0
- package/dist/core/gradient.js +175 -0
- package/dist/core/imageFilters.d.ts +150 -0
- package/dist/core/imageFilters.js +330 -0
- package/dist/core/mat2d.d.ts +151 -0
- package/dist/core/mat2d.js +241 -0
- package/dist/core/pathData.d.ts +53 -0
- package/dist/core/pathData.js +926 -0
- package/dist/core/pattern.d.ts +38 -0
- package/dist/core/pattern.js +40 -0
- package/dist/core/point.d.ts +59 -0
- package/dist/core/point.js +119 -0
- package/dist/core/psdEffects.d.ts +126 -0
- package/dist/core/psdEffects.js +158 -0
- package/dist/core/roundedRect.d.ts +62 -0
- package/dist/core/roundedRect.js +163 -0
- package/dist/core/shadow.d.ts +51 -0
- package/dist/core/shadow.js +47 -0
- package/dist/core/snap.d.ts +232 -0
- package/dist/core/snap.js +793 -0
- package/dist/core/stroke.d.ts +41 -0
- package/dist/core/stroke.js +44 -0
- package/dist/core/triangulate.d.ts +24 -0
- package/dist/core/triangulate.js +118 -0
- package/dist/debug/canvasInspection.d.ts +92 -0
- package/dist/debug/canvasInspection.js +113 -0
- package/dist/debug/pixelDiff.d.ts +22 -0
- package/dist/debug/pixelDiff.js +64 -0
- package/dist/debug/seed.d.ts +473 -0
- package/dist/debug/seed.js +3803 -0
- package/dist/decoders/gif2sprite.d.ts +9 -0
- package/dist/decoders/gif2sprite.js +84 -0
- package/dist/decoders/webp2sprite.d.ts +22 -0
- package/dist/decoders/webp2sprite.js +133 -0
- package/dist/engineFlag.d.ts +72 -0
- package/dist/engineFlag.js +86 -0
- package/dist/export/SceneExporter.d.ts +92 -0
- package/dist/export/SceneExporter.js +280 -0
- package/dist/export/glExport.d.ts +66 -0
- package/dist/export/glExport.js +79 -0
- package/dist/export/svgExport.d.ts +277 -0
- package/dist/export/svgExport.js +1790 -0
- package/dist/index.d.ts +52 -0
- package/dist/index.js +48 -0
- package/dist/interact/animationPlayback.d.ts +125 -0
- package/dist/interact/animationPlayback.js +344 -0
- package/dist/interact/canvasInteractions.d.ts +50 -0
- package/dist/interact/canvasInteractions.js +150 -0
- package/dist/interact/cropSession.d.ts +123 -0
- package/dist/interact/cropSession.js +526 -0
- package/dist/interact/dblClick.d.ts +51 -0
- package/dist/interact/dblClick.js +106 -0
- package/dist/interact/expandSession.d.ts +107 -0
- package/dist/interact/expandSession.js +281 -0
- package/dist/interact/hotkeyActions.d.ts +16 -0
- package/dist/interact/hotkeyActions.js +41 -0
- package/dist/interact/pathSession.d.ts +141 -0
- package/dist/interact/pathSession.js +480 -0
- package/dist/interact/pointer.d.ts +106 -0
- package/dist/interact/pointer.js +1594 -0
- package/dist/interact/pointerTablePuzzle.d.ts +100 -0
- package/dist/interact/pointerTablePuzzle.js +358 -0
- package/dist/interact/pointerTransform.d.ts +86 -0
- package/dist/interact/pointerTransform.js +440 -0
- package/dist/interact/pointerTypes.d.ts +577 -0
- package/dist/interact/pointerTypes.js +96 -0
- package/dist/interact/snapGuide.d.ts +127 -0
- package/dist/interact/snapGuide.js +376 -0
- package/dist/interact/tableCellEditing.d.ts +61 -0
- package/dist/interact/tableCellEditing.js +198 -0
- package/dist/interact/tableInteraction.d.ts +55 -0
- package/dist/interact/tableInteraction.js +212 -0
- package/dist/interact/textEditing.d.ts +77 -0
- package/dist/interact/textEditing.js +410 -0
- package/dist/interact/warpFacade.d.ts +36 -0
- package/dist/interact/warpFacade.js +51 -0
- package/dist/interact/warpSession.d.ts +191 -0
- package/dist/interact/warpSession.js +582 -0
- package/dist/interact/wheelScroll.d.ts +62 -0
- package/dist/interact/wheelScroll.js +72 -0
- package/dist/model/alphaHit.d.ts +59 -0
- package/dist/model/alphaHit.js +262 -0
- package/dist/model/animation.d.ts +228 -0
- package/dist/model/animation.js +510 -0
- package/dist/model/arcLayout.d.ts +54 -0
- package/dist/model/arcLayout.js +307 -0
- package/dist/model/arcTextTransform.d.ts +7 -0
- package/dist/model/arcTextTransform.js +87 -0
- package/dist/model/compatEvents.d.ts +135 -0
- package/dist/model/compatEvents.js +73 -0
- package/dist/model/compatObject.d.ts +716 -0
- package/dist/model/compatObject.js +1579 -0
- package/dist/model/cropEdit.d.ts +118 -0
- package/dist/model/cropEdit.js +497 -0
- package/dist/model/document.d.ts +294 -0
- package/dist/model/document.js +572 -0
- package/dist/model/expandEdit.d.ts +93 -0
- package/dist/model/expandEdit.js +161 -0
- package/dist/model/fabricPrimitives.d.ts +156 -0
- package/dist/model/fabricPrimitives.js +9 -0
- package/dist/model/filler.d.ts +53 -0
- package/dist/model/filler.js +1 -0
- package/dist/model/groupAssemble.d.ts +7 -0
- package/dist/model/groupAssemble.js +98 -0
- package/dist/model/groupChildMove.d.ts +46 -0
- package/dist/model/groupChildMove.js +145 -0
- package/dist/model/groupResize.d.ts +78 -0
- package/dist/model/groupResize.js +108 -0
- package/dist/model/handles.d.ts +40 -0
- package/dist/model/handles.js +29 -0
- package/dist/model/imageMaskBake.d.ts +75 -0
- package/dist/model/imageMaskBake.js +136 -0
- package/dist/model/lineConstruct.d.ts +13 -0
- package/dist/model/lineConstruct.js +79 -0
- package/dist/model/maskCropEdit.d.ts +64 -0
- package/dist/model/maskCropEdit.js +90 -0
- package/dist/model/pathBackground.d.ts +51 -0
- package/dist/model/pathBackground.js +196 -0
- package/dist/model/pathConstruct.d.ts +27 -0
- package/dist/model/pathConstruct.js +55 -0
- package/dist/model/pathEdit.d.ts +114 -0
- package/dist/model/pathEdit.js +378 -0
- package/dist/model/puzzleEdit.d.ts +136 -0
- package/dist/model/puzzleEdit.js +742 -0
- package/dist/model/puzzleLayout.d.ts +91 -0
- package/dist/model/puzzleLayout.js +143 -0
- package/dist/model/scene.d.ts +1004 -0
- package/dist/model/scene.js +2841 -0
- package/dist/model/schema.d.ts +290 -0
- package/dist/model/schema.js +13 -0
- package/dist/model/shapePath.d.ts +14 -0
- package/dist/model/shapePath.js +136 -0
- package/dist/model/tableEdit.d.ts +196 -0
- package/dist/model/tableEdit.js +751 -0
- package/dist/model/tableFacade.d.ts +6 -0
- package/dist/model/tableFacade.js +808 -0
- package/dist/model/tableLayout.d.ts +85 -0
- package/dist/model/tableLayout.js +193 -0
- package/dist/model/textLayout.d.ts +357 -0
- package/dist/model/textLayout.js +822 -0
- package/dist/render/GLBlend.d.ts +40 -0
- package/dist/render/GLBlend.js +270 -0
- package/dist/render/GLContext.d.ts +25 -0
- package/dist/render/GLContext.js +48 -0
- package/dist/render/GLIsolate.d.ts +46 -0
- package/dist/render/GLIsolate.js +188 -0
- package/dist/render/GLTextureCache.d.ts +86 -0
- package/dist/render/GLTextureCache.js +187 -0
- package/dist/render/GlyphAtlas.d.ts +151 -0
- package/dist/render/GlyphAtlas.js +404 -0
- package/dist/render/MeshBatch.d.ts +123 -0
- package/dist/render/MeshBatch.js +416 -0
- package/dist/render/QuadBatch.d.ts +138 -0
- package/dist/render/QuadBatch.js +490 -0
- package/dist/render/SceneRenderer.d.ts +186 -0
- package/dist/render/SceneRenderer.js +700 -0
- package/dist/render/SourceManager.d.ts +121 -0
- package/dist/render/SourceManager.js +505 -0
- package/dist/render/TextRenderer.d.ts +140 -0
- package/dist/render/TextRenderer.js +795 -0
- package/dist/render/arcText.d.ts +40 -0
- package/dist/render/arcText.js +187 -0
- package/dist/render/batchOrder.d.ts +105 -0
- package/dist/render/batchOrder.js +168 -0
- package/dist/render/blendMode.d.ts +35 -0
- package/dist/render/blendMode.js +142 -0
- package/dist/render/clipMaskPainter.d.ts +17 -0
- package/dist/render/clipMaskPainter.js +121 -0
- package/dist/render/fontInvalidation.d.ts +25 -0
- package/dist/render/fontInvalidation.js +77 -0
- package/dist/render/fontInvalidationController.d.ts +76 -0
- package/dist/render/fontInvalidationController.js +114 -0
- package/dist/render/frameOverlay.d.ts +62 -0
- package/dist/render/frameOverlay.js +124 -0
- package/dist/render/framePipeline.d.ts +99 -0
- package/dist/render/framePipeline.js +95 -0
- package/dist/render/gpuFilterPasses.d.ts +25 -0
- package/dist/render/gpuFilterPasses.js +883 -0
- package/dist/render/gpuFx.d.ts +136 -0
- package/dist/render/gpuFx.js +614 -0
- package/dist/render/gpuImageFilters.d.ts +59 -0
- package/dist/render/gpuImageFilters.js +289 -0
- package/dist/render/gpuShadow.d.ts +52 -0
- package/dist/render/gpuShadow.js +289 -0
- package/dist/render/gradientRamp.d.ts +45 -0
- package/dist/render/gradientRamp.js +74 -0
- package/dist/render/imageEffects.d.ts +123 -0
- package/dist/render/imageEffects.js +390 -0
- package/dist/render/maskRender.d.ts +92 -0
- package/dist/render/maskRender.js +224 -0
- package/dist/render/progressiveLoad.d.ts +45 -0
- package/dist/render/progressiveLoad.js +86 -0
- package/dist/render/psdEffectPainter.d.ts +34 -0
- package/dist/render/psdEffectPainter.js +309 -0
- package/dist/render/puzzleClamp.d.ts +28 -0
- package/dist/render/puzzleClamp.js +30 -0
- package/dist/render/retainedFrame.d.ts +85 -0
- package/dist/render/retainedFrame.js +193 -0
- package/dist/render/ruler.d.ts +90 -0
- package/dist/render/ruler.js +287 -0
- package/dist/render/scrollText.d.ts +65 -0
- package/dist/render/scrollText.js +261 -0
- package/dist/render/selectionOverlay.d.ts +318 -0
- package/dist/render/selectionOverlay.js +921 -0
- package/dist/render/shaders.d.ts +38 -0
- package/dist/render/shaders.js +314 -0
- package/dist/render/shadowBake.d.ts +43 -0
- package/dist/render/shadowBake.js +202 -0
- package/dist/render/shadowPainter.d.ts +13 -0
- package/dist/render/shadowPainter.js +80 -0
- package/dist/render/sharedGpuPainters.d.ts +25 -0
- package/dist/render/sharedGpuPainters.js +40 -0
- package/dist/render/sourceHydration.d.ts +12 -0
- package/dist/render/sourceHydration.js +48 -0
- package/dist/render/strokeBake.d.ts +85 -0
- package/dist/render/strokeBake.js +515 -0
- package/dist/render/strokePainter.d.ts +28 -0
- package/dist/render/strokePainter.js +119 -0
- package/dist/render/strokeSdf.d.ts +35 -0
- package/dist/render/strokeSdf.js +74 -0
- package/dist/render/svgRaster.d.ts +46 -0
- package/dist/render/svgRaster.js +71 -0
- package/dist/render/tableOverlay.d.ts +38 -0
- package/dist/render/tableOverlay.js +233 -0
- package/dist/render/textHighlight.d.ts +117 -0
- package/dist/render/textHighlight.js +380 -0
- package/dist/render/textureUpload.d.ts +18 -0
- package/dist/render/textureUpload.js +26 -0
- package/dist/render/verticalText.d.ts +38 -0
- package/dist/render/verticalText.js +63 -0
- package/dist/render/warpText.d.ts +58 -0
- package/dist/render/warpText.js +380 -0
- package/dist/render/workspaceBackdrop.d.ts +35 -0
- package/dist/render/workspaceBackdrop.js +71 -0
- package/dist/render/workspaceChecker.d.ts +54 -0
- package/dist/render/workspaceChecker.js +170 -0
- package/dist/render/workspaceGlow.d.ts +51 -0
- package/dist/render/workspaceGlow.js +171 -0
- package/package.json +39 -3
|
@@ -0,0 +1,526 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 图片裁剪会话(B2):应用 cropping.mixin 的交互编排移植。
|
|
3
|
+
*
|
|
4
|
+
* 会话语义(应用口径):
|
|
5
|
+
* - 进入:单选静态图片(imageEl 已加载;GIF/Video 动画族不支持裁剪——B1 口径);
|
|
6
|
+
* 进入即吞没常规交互(应用 isolateObjectForEdit + findTarget 吞没 + selection
|
|
7
|
+
* 禁用)——pointer 的手柄/对象/空白命中全部让位
|
|
8
|
+
* - 12 手柄:4 角括号(X/Y 两轴独立裁剪,flip 走 *Flig 变体)/ 4 边条(窗随
|
|
9
|
+
* 指针、对边锚定)/ 4 整图角圆(等比缩放,|scaleX|≠|scaleY| 时隐藏——进入时
|
|
10
|
+
* 冻结判定,同应用 bind 时隐藏);cropAspectRatio 置位后边条消失、角括号走
|
|
11
|
+
* 比例约束(比例角手柄不区分 flip——应用 ratio 控件集同款)
|
|
12
|
+
* - 框内拖图:整图 quad 内按下即拖(含窗外的半透明幽灵区——应用 targetless
|
|
13
|
+
* 拖动同语义),cropX/cropY 钳制 [0, natural − window]
|
|
14
|
+
* - 退出三通道同径:点框外(应用 canvasMouseDown)/ ESC(useCanvasHotkey)/
|
|
15
|
+
* 程序化退出——保留当前裁剪、发一次 object:modified(应用 fireCropImageEvent
|
|
16
|
+
* 的 'cropImage' 事件每退必发;应用历史层显式跳过 crop 动作、提交归工具栏
|
|
17
|
+
* ✓/reset——P5-1/P5-4 接入时照此分流)
|
|
18
|
+
*
|
|
19
|
+
* 渲染(应用 _render 幽灵底图 + mixin 九宫格 + 控件层):
|
|
20
|
+
* - 暗层 = 整图 50% 幽灵垫在裁剪窗之下(SceneRenderer 图片分支消费
|
|
21
|
+
* host.cropGhostNode;应用 _render 同构——非全屏 fillRect,那是死代码)
|
|
22
|
+
* - 九宫格 #f6f7fa 1px(窗本地 ±1/3 线,随对象姿态旋转)
|
|
23
|
+
* - 整图外框 + 窗口边框;角括号/边条 #dfe2e8 圆头 sprite(lineCap round +
|
|
24
|
+
* 内向阴影,应用 renders 逐式同构);圆手柄白色 sprite。控件族全部屏幕
|
|
25
|
+
* 恒定 px(位置=对象全量矩阵,姿态=旋转/flip 跟随,尺寸不随对象 scale/
|
|
26
|
+
* zoom 变化——fabric 控件同语义);层级=fabric 注册序:圆手柄→边条→角括号
|
|
27
|
+
*/
|
|
28
|
+
import { parseColor } from '../core/color';
|
|
29
|
+
import { multiply, transformPoint } from '../core/mat2d';
|
|
30
|
+
import { AnimatedNode, MaskNode } from '../model/scene';
|
|
31
|
+
import { maskCropLiveState, maskCropWriteProps } from '../model/maskCropEdit';
|
|
32
|
+
import { applyCropCorner, applyCropEdge, applyCropRatioCorner, applyCropRatioPreset, applyScaleEquallyCrop, CROP_HANDLE_OFFSETS, fullImageCornerLocal, liveStateFromRaw, liveStateToRawProps, moveCropImage } from '../model/cropEdit';
|
|
33
|
+
import { isCornerHandle } from '../model/handles';
|
|
34
|
+
import { lineQuad } from '../render/selectionOverlay';
|
|
35
|
+
/** 手柄命中半径(屏幕 px;fabric 口径 cornerSize 13 方形域的圆近似)。
|
|
36
|
+
* 圆手柄贴视觉直径放大(16px)取 14——同心(crop=0)时让位角括号
|
|
37
|
+
* (判定序见 hitHandle),非同心(cropX/Y>0 整图角与窗角分离)时独占整图角 */
|
|
38
|
+
const HANDLE_HIT_PX = 12;
|
|
39
|
+
const CIRCLE_HIT_PX = 14;
|
|
40
|
+
/** 控件视觉常量(屏幕 px;应用 renders:角括号 cSize10/lineWidth6、边条
|
|
41
|
+
* cSize12/lineWidth4,#dfe2e8,lineCap round + 内向阴影——圆滑观感全靠
|
|
42
|
+
* 这两样,quad 直角矩形画不出来,走 sprite) */
|
|
43
|
+
const CIRCLE_R_PX = 7;
|
|
44
|
+
const GRID_LINE_PX = 1;
|
|
45
|
+
const FULL_IMG_BORDER_PX = 1;
|
|
46
|
+
const GRID_COLOR = parseColor('#f6f7fa');
|
|
47
|
+
const BORDER_COLOR = parseColor('#2f6fed');
|
|
48
|
+
/** 8 分圆光标方向表(fabric controls/scale.ts scaleMap 逐位复刻,末位 'e' 是
|
|
49
|
+
* Math.round(359/45)=8 的兜底)——圆手柄悬停斜角 resize 光标查表 */
|
|
50
|
+
const SCALE_CURSOR_MAP = ['e', 'se', 's', 'sw', 'w', 'nw', 'n', 'ne', 'e'];
|
|
51
|
+
const BRACKET_HANDLES = ['tl', 'tr', 'bl', 'br'];
|
|
52
|
+
const CIRCLE_HANDLES = ['tl', 'tr', 'bl', 'br'];
|
|
53
|
+
const EDGE_HANDLES = ['left', 'right', 'top', 'bottom'];
|
|
54
|
+
/** 圆手柄 sprite(白填 + 蓝环;模块级单例,经 GLTextureCache 上传) */
|
|
55
|
+
let circleSprite = null;
|
|
56
|
+
const getCircleSprite = () => {
|
|
57
|
+
if (circleSprite)
|
|
58
|
+
return circleSprite;
|
|
59
|
+
const size = Math.ceil((CIRCLE_R_PX + 2) * 2);
|
|
60
|
+
const canvas = document.createElement('canvas');
|
|
61
|
+
canvas.width = size;
|
|
62
|
+
canvas.height = size;
|
|
63
|
+
const ctx = canvas.getContext('2d');
|
|
64
|
+
ctx.beginPath();
|
|
65
|
+
ctx.arc(size / 2, size / 2, CIRCLE_R_PX, 0, Math.PI * 2);
|
|
66
|
+
ctx.fillStyle = '#ffffff';
|
|
67
|
+
ctx.fill();
|
|
68
|
+
ctx.lineWidth = 1.5;
|
|
69
|
+
ctx.strokeStyle = '#2f6fed';
|
|
70
|
+
ctx.stroke();
|
|
71
|
+
circleSprite = canvas;
|
|
72
|
+
return canvas;
|
|
73
|
+
};
|
|
74
|
+
// ── 角括号/边条 sprite(应用 cropping/clipping.controls.renders 的逐式复刻)──
|
|
75
|
+
// fabric 口径:lineCap='round' + renderWithShadows(rgba(12,18,28,.38) blur4、
|
|
76
|
+
// 阴影恒指向窗内)。quad 直角端头无圆头无阴影——观感「不圆滑」的根因,改
|
|
77
|
+
// sprite 烘焙。四角/四边各烘一张 TL/MT 姿态,落位时绕控制点旋 90° 步进:
|
|
78
|
+
// 旋转把阴影方向一并带走,恰与 fabric 各角 this.angle + 逐角阴影偏移同构
|
|
79
|
+
// (R90(2,2)=(-2,2)=TR、R180=(-2,-2)=BR、R270=(2,-2)=BL)。
|
|
80
|
+
/** sprite 逻辑尺寸/控制点位置(逻辑 px;光栅按 SPRITE_SS 倍常量直接烘——
|
|
81
|
+
* 不用 ctx.scale:shadowOffset/blur 不受 CTM 影响,scale 超采样会把阴影
|
|
82
|
+
* 相对线宽砍半) */
|
|
83
|
+
const BRACKET_BOX_PX = 30;
|
|
84
|
+
const BRACKET_ORIGIN_PX = 7;
|
|
85
|
+
const BAR_BOX_PX = { x: 28, y: 16 };
|
|
86
|
+
const BAR_ORIGIN_PX = { x: 14, y: 4 };
|
|
87
|
+
const SPRITE_SS = 2;
|
|
88
|
+
const makeSpriteCanvas = (w, h) => {
|
|
89
|
+
const canvas = document.createElement('canvas');
|
|
90
|
+
canvas.width = w * SPRITE_SS;
|
|
91
|
+
canvas.height = h * SPRITE_SS;
|
|
92
|
+
const ctx = canvas.getContext('2d');
|
|
93
|
+
if (!ctx)
|
|
94
|
+
return null;
|
|
95
|
+
return { canvas, ctx };
|
|
96
|
+
};
|
|
97
|
+
/** fabric 控件渲染常量(cropping/clipping.controls.renders)× 超采样倍数 */
|
|
98
|
+
const SS = (px) => px * SPRITE_SS;
|
|
99
|
+
let bracketSprite = null;
|
|
100
|
+
/** 角括号 sprite(TL 姿态:控制点在原点,双臂沿 +x/+y 伸入窗内;lineWidth6
|
|
101
|
+
* 圆头 + 阴影(2,2),含 blur 余量的 bounds [-3,13]+[2+6] → 30 盒、原点 (7,7)) */
|
|
102
|
+
const getBracketSprite = () => {
|
|
103
|
+
if (bracketSprite)
|
|
104
|
+
return bracketSprite;
|
|
105
|
+
const made = makeSpriteCanvas(BRACKET_BOX_PX, BRACKET_BOX_PX);
|
|
106
|
+
if (!made)
|
|
107
|
+
return (bracketSprite = document.createElement('canvas'));
|
|
108
|
+
const { canvas, ctx } = made;
|
|
109
|
+
ctx.translate(SS(BRACKET_ORIGIN_PX), SS(BRACKET_ORIGIN_PX));
|
|
110
|
+
ctx.shadowColor = 'rgba(12, 18, 28, 0.38)';
|
|
111
|
+
ctx.shadowBlur = SS(4);
|
|
112
|
+
ctx.shadowOffsetX = SS(2);
|
|
113
|
+
ctx.shadowOffsetY = SS(2);
|
|
114
|
+
ctx.beginPath();
|
|
115
|
+
ctx.lineWidth = SS(6);
|
|
116
|
+
ctx.lineCap = 'round';
|
|
117
|
+
ctx.strokeStyle = '#dfe2e8';
|
|
118
|
+
ctx.moveTo(0, SS(10));
|
|
119
|
+
ctx.lineTo(0, 0);
|
|
120
|
+
ctx.lineTo(SS(10), 0);
|
|
121
|
+
ctx.stroke();
|
|
122
|
+
bracketSprite = canvas;
|
|
123
|
+
return canvas;
|
|
124
|
+
};
|
|
125
|
+
let barSprite = null;
|
|
126
|
+
/** 边条 sprite(MT 姿态:条心在原点水平 ±6;lineWidth4 圆头 + 阴影(0,2)
|
|
127
|
+
* 向窗内,bounds x[-8,8] y[-2,2]+阴影 → 28×16 盒、原点 (14,4)) */
|
|
128
|
+
const getBarSprite = () => {
|
|
129
|
+
if (barSprite)
|
|
130
|
+
return barSprite;
|
|
131
|
+
const made = makeSpriteCanvas(BAR_BOX_PX.x, BAR_BOX_PX.y);
|
|
132
|
+
if (!made)
|
|
133
|
+
return (barSprite = document.createElement('canvas'));
|
|
134
|
+
const { canvas, ctx } = made;
|
|
135
|
+
ctx.translate(SS(BAR_ORIGIN_PX.x), SS(BAR_ORIGIN_PX.y));
|
|
136
|
+
ctx.shadowColor = 'rgba(12, 18, 28, 0.38)';
|
|
137
|
+
ctx.shadowBlur = SS(4);
|
|
138
|
+
ctx.shadowOffsetX = 0;
|
|
139
|
+
ctx.shadowOffsetY = SS(2);
|
|
140
|
+
ctx.beginPath();
|
|
141
|
+
ctx.lineWidth = SS(4);
|
|
142
|
+
ctx.lineCap = 'round';
|
|
143
|
+
ctx.strokeStyle = '#dfe2e8';
|
|
144
|
+
ctx.moveTo(SS(-6), 0);
|
|
145
|
+
ctx.lineTo(SS(6), 0);
|
|
146
|
+
ctx.stroke();
|
|
147
|
+
barSprite = canvas;
|
|
148
|
+
return canvas;
|
|
149
|
+
};
|
|
150
|
+
/** 节点矩阵的「列归一」线性:各列除以自身模长——保留旋转/flip(列方向),
|
|
151
|
+
* 丢弃缩放(列模)。fabric 控件语义:位置随对象全量矩阵(oCoords),大小/
|
|
152
|
+
* 姿态屏幕恒定(ctx.translate 到屏幕位后按固定像素画,只 rotate 不 scale)。
|
|
153
|
+
* sprite quad 若直接乘节点矩阵,dims 会被对象 scale 放大——拖圆手柄等比
|
|
154
|
+
* 缩放时角括号/边条/圆点跟着变大变小、锚点偏移同步漂移(用户报障) */
|
|
155
|
+
const normalizedLinear = (m) => {
|
|
156
|
+
const sx = Math.hypot(m[0], m[1]) || 1;
|
|
157
|
+
const sy = Math.hypot(m[2], m[3]) || 1;
|
|
158
|
+
return [m[0] / sx, m[1] / sx, m[2] / sy, m[3] / sy];
|
|
159
|
+
};
|
|
160
|
+
/** 控制点 sprite 落位:绕控制点旋 k·90° 的贴图 quad。sprite 内控制点位于
|
|
161
|
+
* (origin − box/2)(quad 中心系),旋转后把该偏移从平移里扣掉——控制点
|
|
162
|
+
* 恒钉在窗角/边中点上。平移用节点**全量**矩阵(scale 只该影响位置),
|
|
163
|
+
* 线性用列归一(姿态随对象旋转/flip、屏幕尺寸恒 box px);对象 flip 由
|
|
164
|
+
* 归一线性吸收(括号集合在镜像下自映射,双臂恒指向窗内) */
|
|
165
|
+
const spriteQuadAt = (matrix, controlX, controlY, rotDeg, box, origin, zoom, texture) => {
|
|
166
|
+
const rad = (rotDeg * Math.PI) / 180;
|
|
167
|
+
const cos = Math.cos(rad);
|
|
168
|
+
const sin = Math.sin(rad);
|
|
169
|
+
const [n0, n1, n2, n3] = normalizedLinear(matrix);
|
|
170
|
+
// 控制点场景位置(节点全量矩阵——scale 只该影响位置)
|
|
171
|
+
const px = matrix[0] * controlX + matrix[2] * controlY + matrix[4];
|
|
172
|
+
const py = matrix[1] * controlX + matrix[3] * controlY + matrix[5];
|
|
173
|
+
// 线性 = 归一线性 · 90° 步进旋转(multiply 代数,防手写列主分量错位);
|
|
174
|
+
// 平移 = 控制点 − 线性·(sprite 中心系控制点偏移/zoom)——纹理 quad 顶点为
|
|
175
|
+
// 中心系(shader (corner−0.5)·dim),local=偏移/zoom 经线性恰落在控制点上
|
|
176
|
+
const lin = multiply([n0, n1, n2, n3, 0, 0], [cos, sin, -sin, cos, 0, 0], true);
|
|
177
|
+
const dx = (origin.x - box.x / 2) / zoom;
|
|
178
|
+
const dy = (origin.y - box.y / 2) / zoom;
|
|
179
|
+
return {
|
|
180
|
+
matrix: [lin[0], lin[1], lin[2], lin[3], px - (lin[0] * dx + lin[2] * dy), py - (lin[1] * dx + lin[3] * dy)],
|
|
181
|
+
dims: { x: box.x / zoom, y: box.y / zoom },
|
|
182
|
+
color: [1, 1, 1, 1],
|
|
183
|
+
texture
|
|
184
|
+
};
|
|
185
|
+
};
|
|
186
|
+
/** 点是否在四边形内(射线奇偶;仿射变换保包含性,场景系即可判) */
|
|
187
|
+
const pointInQuad = (p, quad) => {
|
|
188
|
+
let inside = false;
|
|
189
|
+
for (let i = 0, j = quad.length - 1; i < quad.length; j = i++) {
|
|
190
|
+
const xi = quad[i].x;
|
|
191
|
+
const yi = quad[i].y;
|
|
192
|
+
const xj = quad[j].x;
|
|
193
|
+
const yj = quad[j].y;
|
|
194
|
+
if (yi > p.y !== yj > p.y && p.x < ((xj - xi) * (p.y - yi)) / (yj - yi) + xi)
|
|
195
|
+
inside = !inside;
|
|
196
|
+
}
|
|
197
|
+
return inside;
|
|
198
|
+
};
|
|
199
|
+
export class CropSessionController {
|
|
200
|
+
host;
|
|
201
|
+
node = null;
|
|
202
|
+
/** 等比圆手柄可见性(进入时冻结:|scaleX|≠|scaleY| 隐藏——应用 bind 语义) */
|
|
203
|
+
circlesVisible = true;
|
|
204
|
+
ratio = null;
|
|
205
|
+
detachKey = null;
|
|
206
|
+
constructor(host) {
|
|
207
|
+
this.host = host;
|
|
208
|
+
}
|
|
209
|
+
get active() {
|
|
210
|
+
return this.node !== null;
|
|
211
|
+
}
|
|
212
|
+
get target() {
|
|
213
|
+
return this.node;
|
|
214
|
+
}
|
|
215
|
+
get info() {
|
|
216
|
+
const node = this.node;
|
|
217
|
+
if (!node || !(node instanceof MaskNode ? node.clipImageEl : node.imageEl))
|
|
218
|
+
return null;
|
|
219
|
+
const live = this.liveState();
|
|
220
|
+
return {
|
|
221
|
+
nodeId: node.id,
|
|
222
|
+
handle: '',
|
|
223
|
+
ratio: this.ratio,
|
|
224
|
+
circlesVisible: this.circlesVisible,
|
|
225
|
+
cropX: live.cropX,
|
|
226
|
+
cropY: live.cropY,
|
|
227
|
+
width: live.width,
|
|
228
|
+
height: live.height,
|
|
229
|
+
isMask: node instanceof MaskNode
|
|
230
|
+
};
|
|
231
|
+
}
|
|
232
|
+
/** 进入裁剪(应用 ImageClip handleClipImage → set({__isCropping:true}))。
|
|
233
|
+
* 蒙版目标(B3 余量,应用 FabricMask.__isCropping 同款控件集):静态 clipImage
|
|
234
|
+
* 已加载 + 顶层(拼图内块的裁剪属拼图蒙版编辑域,余项登记);动态 clip
|
|
235
|
+
* (视频/GIF)排除——B1 动画族口径 */
|
|
236
|
+
enter(node) {
|
|
237
|
+
if (this.node)
|
|
238
|
+
this.exit();
|
|
239
|
+
if (node instanceof MaskNode) {
|
|
240
|
+
if (!this.host.document.nodes.includes(node) || node.clipDynamicKind || !node.clipImageRaw || !node.clipImageEl)
|
|
241
|
+
return false;
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
// 静态图片且源已加载(动画族不支持裁剪——B1 口径)
|
|
245
|
+
if (node instanceof AnimatedNode || !node.isImageType || !node.imageEl)
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
this.node = node;
|
|
249
|
+
this.ratio = null;
|
|
250
|
+
const sx = Math.abs(node.raw.scaleX ?? 1);
|
|
251
|
+
const sy = Math.abs(node.raw.scaleY ?? 1);
|
|
252
|
+
this.circlesVisible = sx === sy;
|
|
253
|
+
// 编辑态让位(裁剪吞没一切;应用 isolateObjectForEdit 禁取消选中)
|
|
254
|
+
this.host.document.exitEditing();
|
|
255
|
+
this.host.document.setSelection([node], 'update');
|
|
256
|
+
// Esc 退出仅图片目标(应用 useCanvasHotkey.exitImageCropping 只处理
|
|
257
|
+
// type==='image'——蒙版只能点框外/程序化退出,对拍不接 Esc)
|
|
258
|
+
if (!(node instanceof MaskNode)) {
|
|
259
|
+
const onKeyDown = (e) => {
|
|
260
|
+
if (e.key === 'Escape' && this.node)
|
|
261
|
+
this.exit();
|
|
262
|
+
};
|
|
263
|
+
window.addEventListener('keydown', onKeyDown);
|
|
264
|
+
this.detachKey = () => window.removeEventListener('keydown', onKeyDown);
|
|
265
|
+
}
|
|
266
|
+
this.host.requestRenderAll();
|
|
267
|
+
return true;
|
|
268
|
+
}
|
|
269
|
+
/** 退出(三通道同径:点框外/ESC/程序化;保留裁剪、发一条 object:modified) */
|
|
270
|
+
exit() {
|
|
271
|
+
if (!this.node)
|
|
272
|
+
return;
|
|
273
|
+
const node = this.node;
|
|
274
|
+
this.node = null;
|
|
275
|
+
this.ratio = null;
|
|
276
|
+
this.detachKey?.();
|
|
277
|
+
this.detachKey = null;
|
|
278
|
+
// 应用 fireCropImageEvent:每退必发(无变化也发——应用历史层按 action 分流)
|
|
279
|
+
this.host.document.applyTransform([node], () => ({}), 'modified', { action: 'crop' });
|
|
280
|
+
this.host.requestRenderAll();
|
|
281
|
+
}
|
|
282
|
+
/** pointer 点框外通道(应用 canvasMouseDown 的退出分支,同 exit) */
|
|
283
|
+
exitByOutsideClick() {
|
|
284
|
+
this.exit();
|
|
285
|
+
}
|
|
286
|
+
/** 设置比例约束(应用 presetImageClip 的 ratio 分支:整图内居中最大比例矩形 + 直写) */
|
|
287
|
+
setAspectRatio(ratio) {
|
|
288
|
+
if (!this.node)
|
|
289
|
+
return;
|
|
290
|
+
this.ratio = ratio;
|
|
291
|
+
if (ratio && ratio > 0) {
|
|
292
|
+
const next = applyCropRatioPreset(this.liveState(), ratio);
|
|
293
|
+
this.writeBack(next);
|
|
294
|
+
}
|
|
295
|
+
this.host.requestRenderAll();
|
|
296
|
+
}
|
|
297
|
+
/** 手柄命中(屏幕空间半径;比例模式边条不可见不可命中)。判定序 = fabric
|
|
298
|
+
* findControl 倒序遍历同构(oCoords 按注册序生成、从末位往回首中即返回):
|
|
299
|
+
* 角括号(cropCorner* 注册在最后) → 边条 → 圆手柄(tlS..brS 注册在最前)——
|
|
300
|
+
* 与渲染层级(注册序后画盖上,角括号最上)一致:同心(cropX=cropY=0 整图
|
|
301
|
+
* 角=窗角)时角括号先中、拖动改窗,圆手柄等比缩放让位(fabric 同款) */
|
|
302
|
+
hitHandle(cssX, cssY) {
|
|
303
|
+
const node = this.node;
|
|
304
|
+
if (!node)
|
|
305
|
+
return null;
|
|
306
|
+
const matrix = node.matrix;
|
|
307
|
+
const live = this.liveState();
|
|
308
|
+
for (const corner of BRACKET_HANDLES) {
|
|
309
|
+
const off = CROP_HANDLE_OFFSETS[corner];
|
|
310
|
+
const scene = transformPoint(matrix, off.x * live.width, off.y * live.height);
|
|
311
|
+
const screen = this.host.toScreen(scene.x, scene.y);
|
|
312
|
+
if (Math.hypot(screen.x - cssX, screen.y - cssY) <= HANDLE_HIT_PX)
|
|
313
|
+
return corner;
|
|
314
|
+
}
|
|
315
|
+
if (!this.ratio) {
|
|
316
|
+
for (const edge of EDGE_HANDLES) {
|
|
317
|
+
const off = CROP_HANDLE_OFFSETS[edge];
|
|
318
|
+
const scene = transformPoint(matrix, off.x * live.width, off.y * live.height);
|
|
319
|
+
const screen = this.host.toScreen(scene.x, scene.y);
|
|
320
|
+
if (Math.hypot(screen.x - cssX, screen.y - cssY) <= HANDLE_HIT_PX)
|
|
321
|
+
return edge;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (this.circlesVisible) {
|
|
325
|
+
for (const corner of CIRCLE_HANDLES) {
|
|
326
|
+
const local = fullImageCornerLocal(live, corner);
|
|
327
|
+
const scene = transformPoint(matrix, local.x, local.y);
|
|
328
|
+
const screen = this.host.toScreen(scene.x, scene.y);
|
|
329
|
+
if (Math.hypot(screen.x - cssX, screen.y - cssY) <= CIRCLE_HIT_PX)
|
|
330
|
+
return `${corner}S`;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
return null;
|
|
334
|
+
}
|
|
335
|
+
/**
|
|
336
|
+
* 拖图起拖区域:
|
|
337
|
+
* - 图片 = **裁剪窗** quad(应用 canvasMouseDown 的 containsPoint(calcOCoords
|
|
338
|
+
* 四角) 同语义——窗外 ghost 区按下走退出通道)。此前误用整图 quad(含窗外
|
|
339
|
+
* 幽灵区):从半透明延伸区起拖时内容在窗内滑动而非预期语义,手感「图在飘」。
|
|
340
|
+
* - 蒙版 = 窗 quad **屏幕系外扩 1.5 倍**(应用 clipping.mixin canvasMouseDown 的
|
|
341
|
+
* oCoords 角点 ±半宽/半高 扩张——蒙版无窗外 ghost,外扩给拖拽手感余量;
|
|
342
|
+
* 扩张沿屏幕轴不随对象旋转,与应用逐式同构)
|
|
343
|
+
*/
|
|
344
|
+
hitRect(sceneX, sceneY) {
|
|
345
|
+
const node = this.node;
|
|
346
|
+
if (!node)
|
|
347
|
+
return false;
|
|
348
|
+
const live = this.liveState();
|
|
349
|
+
const matrix = node.matrix;
|
|
350
|
+
if (!(node instanceof MaskNode)) {
|
|
351
|
+
const quad = ['tl', 'tr', 'br', 'bl'].map((c) => {
|
|
352
|
+
const lx = (c === 'tr' || c === 'br' ? 0.5 : -0.5) * live.width;
|
|
353
|
+
const ly = (c === 'bl' || c === 'br' ? 0.5 : -0.5) * live.height;
|
|
354
|
+
return transformPoint(matrix, lx, ly);
|
|
355
|
+
});
|
|
356
|
+
return pointInQuad({ x: sceneX, y: sceneY }, quad);
|
|
357
|
+
}
|
|
358
|
+
const cScreen = ['tl', 'tr', 'br', 'bl'].map((c) => {
|
|
359
|
+
const lx = (c === 'tr' || c === 'br' ? 0.5 : -0.5) * live.width;
|
|
360
|
+
const ly = (c === 'bl' || c === 'br' ? 0.5 : -0.5) * live.height;
|
|
361
|
+
const s = transformPoint(matrix, lx, ly);
|
|
362
|
+
return this.host.toScreen(s.x, s.y);
|
|
363
|
+
});
|
|
364
|
+
const ew = Math.abs(cScreen[1].x - cScreen[0].x) / 2;
|
|
365
|
+
const eh = Math.abs(cScreen[3].y - cScreen[0].y) / 2;
|
|
366
|
+
const expanded = [
|
|
367
|
+
{ x: cScreen[0].x - ew, y: cScreen[0].y - eh },
|
|
368
|
+
{ x: cScreen[1].x + ew, y: cScreen[1].y - eh },
|
|
369
|
+
{ x: cScreen[2].x + ew, y: cScreen[2].y + eh },
|
|
370
|
+
{ x: cScreen[3].x - ew, y: cScreen[3].y + eh }
|
|
371
|
+
];
|
|
372
|
+
return pointInQuad(this.host.toScreen(sceneX, sceneY), expanded);
|
|
373
|
+
}
|
|
374
|
+
/** 手柄拖拽逐帧(scene 指针;拒绝帧不写——应用 return false 同语义) */
|
|
375
|
+
applyHandle(handle, scenePoint) {
|
|
376
|
+
const node = this.node;
|
|
377
|
+
if (!node)
|
|
378
|
+
return;
|
|
379
|
+
const live = this.liveState();
|
|
380
|
+
let next = null;
|
|
381
|
+
if (handle.endsWith('S')) {
|
|
382
|
+
// 圆手柄 id = 角点 + 'S'(hitHandle 组装):等比缩放,仅圆可见时可拖
|
|
383
|
+
next = this.circlesVisible ? applyScaleEquallyCrop(live, handle.slice(0, 2), scenePoint) : null;
|
|
384
|
+
}
|
|
385
|
+
else if (isCornerHandle(handle)) {
|
|
386
|
+
next = this.ratio ? applyCropRatioCorner(live, handle, scenePoint, this.ratio) : applyCropCorner(live, handle, scenePoint);
|
|
387
|
+
}
|
|
388
|
+
else if (!this.ratio) {
|
|
389
|
+
next = applyCropEdge(live, handle, scenePoint);
|
|
390
|
+
}
|
|
391
|
+
if (next)
|
|
392
|
+
this.writeBack(next);
|
|
393
|
+
this.host.requestRenderAll();
|
|
394
|
+
}
|
|
395
|
+
/** 框内拖图逐帧(画布系增量 → 钳制后的 cropX/cropY)。整组 live 写回:
|
|
396
|
+
* legacy 口径 raw.width = 窗宽 + cropX(右缘语义)——只写 cropX 会让盘上
|
|
397
|
+
* 右缘不动、可视窗随拖变窄(B1 双口径的写侧契约) */
|
|
398
|
+
moveImageBy(delta) {
|
|
399
|
+
const node = this.node;
|
|
400
|
+
if (!node)
|
|
401
|
+
return;
|
|
402
|
+
const live = this.liveState();
|
|
403
|
+
const { cropX, cropY } = moveCropImage(live, delta);
|
|
404
|
+
this.writeBack({ ...live, cropX, cropY });
|
|
405
|
+
this.host.requestRenderAll();
|
|
406
|
+
}
|
|
407
|
+
/** 空闲态光标:角括号/边条 pointer(fabric Control 缺省 cursorStyle,裁剪
|
|
408
|
+
* 控件集未设 handler);圆手柄 = fabric scaleCursorStyleHandler 同构——
|
|
409
|
+
* 理论角位(CROP_HANDLE_OFFSETS 与 fabric control.x/y 同值,flip 不参与——
|
|
410
|
+
* flip 集换 positionHandler 不换 x/y)+ 对象角度 → 8 分圆 → scaleMap 斜角
|
|
411
|
+
* resize(tlS=nw-resize ↖ / trS=ne ↗ / brS=se ↘ / blS=sw ↙)。角度口径 =
|
|
412
|
+
* fabric getTotalAngle 顶层分支 raw.angle(引擎 worldAngle 的 atan2 在
|
|
413
|
+
* flipX 列负下翻 180°,不对齐);窗内 move(ghost 区默认——应用
|
|
414
|
+
* evented:false 无 hover 光标) */
|
|
415
|
+
hoverCursor(cssX, cssY, scenePoint) {
|
|
416
|
+
const hit = this.hitHandle(cssX, cssY);
|
|
417
|
+
if (hit) {
|
|
418
|
+
if (hit.endsWith('S') && this.node) {
|
|
419
|
+
const off = CROP_HANDLE_OFFSETS[hit.slice(0, 2)];
|
|
420
|
+
const angle = this.node.raw.angle ?? 0;
|
|
421
|
+
const cornerAngle = (angle + (Math.atan2(off.y, off.x) * 180) / Math.PI + 360) % 360;
|
|
422
|
+
return `${SCALE_CURSOR_MAP[Math.round(cornerAngle / 45)]}-resize`;
|
|
423
|
+
}
|
|
424
|
+
return 'pointer';
|
|
425
|
+
}
|
|
426
|
+
return this.hitRect(scenePoint.x, scenePoint.y) ? 'move' : '';
|
|
427
|
+
}
|
|
428
|
+
/** 裁剪覆盖层(画在选区覆盖层位置——会话态取代常规选区 UI) */
|
|
429
|
+
buildOverlay(zoom) {
|
|
430
|
+
const node = this.node;
|
|
431
|
+
if (!node || !node.imageEl)
|
|
432
|
+
return [];
|
|
433
|
+
const live = this.liveState();
|
|
434
|
+
const matrix = node.matrix;
|
|
435
|
+
const quads = [];
|
|
436
|
+
const sceneOf = (lx, ly) => transformPoint(matrix, lx, ly);
|
|
437
|
+
const w = live.width;
|
|
438
|
+
const h = live.height;
|
|
439
|
+
// 九宫格(窗本地三等分线:-w/2 + i·w/3, i∈{1,2} → ±w/6;随姿态旋转,
|
|
440
|
+
// 线宽 1 屏幕像素。首版误写成 -w/2 ± w/3 → -5w/6 落到窗外/图外——用户反馈)
|
|
441
|
+
const grid = GRID_LINE_PX / zoom;
|
|
442
|
+
for (const i of [1, 2]) {
|
|
443
|
+
const x = -w / 2 + (i * w) / 3;
|
|
444
|
+
const a = sceneOf(x, -h / 2);
|
|
445
|
+
const b = sceneOf(x, h / 2);
|
|
446
|
+
quads.push(lineQuad(a, b, grid, GRID_COLOR));
|
|
447
|
+
}
|
|
448
|
+
for (const i of [1, 2]) {
|
|
449
|
+
const y = -h / 2 + (i * h) / 3;
|
|
450
|
+
const a = sceneOf(-w / 2, y);
|
|
451
|
+
const b = sceneOf(w / 2, y);
|
|
452
|
+
quads.push(lineQuad(a, b, grid, GRID_COLOR));
|
|
453
|
+
}
|
|
454
|
+
// 整图外框(应用 _renderCroppingBorders:整图 rect 描边)
|
|
455
|
+
const border = FULL_IMG_BORDER_PX / zoom;
|
|
456
|
+
const corners = ['tl', 'tr', 'br', 'bl'].map((c) => sceneOf(fullImageCornerLocal(live, c).x, fullImageCornerLocal(live, c).y));
|
|
457
|
+
for (let i = 0; i < 4; i++)
|
|
458
|
+
quads.push(lineQuad(corners[i], corners[(i + 1) % 4], border, BORDER_COLOR));
|
|
459
|
+
// 窗口边框(选区主色;会话态替代常规选框)
|
|
460
|
+
const winBorder = 1.5 / zoom;
|
|
461
|
+
const win = ['tl', 'tr', 'br', 'bl'].map((c) => sceneOf(CROP_HANDLE_OFFSETS[c].x * w, CROP_HANDLE_OFFSETS[c].y * h));
|
|
462
|
+
for (let i = 0; i < 4; i++)
|
|
463
|
+
quads.push(lineQuad(win[i], win[(i + 1) % 4], winBorder, BORDER_COLOR));
|
|
464
|
+
// 控件族绘制序 = fabric croppingControlSet 注册序(Object.keys 遍历画,
|
|
465
|
+
// 后画的盖上面):圆手柄(tlS..brS) → 边条(cropLeft..cropBottom) →
|
|
466
|
+
// 角括号(cropCorner*最上)——用户对拍「角括号应在圆手柄上面」
|
|
467
|
+
//
|
|
468
|
+
// 整图四角圆手柄(sprite 纹理 quad;|scaleX|≠|scaleY| 隐藏。归一线性:
|
|
469
|
+
// dims 不再随对象 scale 放大,屏幕恒 sprite.width px;圆旋转对称,
|
|
470
|
+
// 姿态只需位置=全量矩阵投影)
|
|
471
|
+
if (this.circlesVisible) {
|
|
472
|
+
const sprite = getCircleSprite();
|
|
473
|
+
const [n0, n1, n2, n3] = normalizedLinear(matrix);
|
|
474
|
+
const size = sprite.width / zoom;
|
|
475
|
+
for (const corner of CIRCLE_HANDLES) {
|
|
476
|
+
const local = fullImageCornerLocal(live, corner);
|
|
477
|
+
quads.push({
|
|
478
|
+
matrix: [n0, n1, n2, n3, matrix[0] * local.x + matrix[2] * local.y + matrix[4], matrix[1] * local.x + matrix[3] * local.y + matrix[5]],
|
|
479
|
+
dims: { x: size, y: size },
|
|
480
|
+
color: [1, 1, 1, 1],
|
|
481
|
+
texture: sprite
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
// 边条(sprite 圆头短条 + 内向阴影;MT 姿态绕边中点旋 90° 步进。比例模式
|
|
486
|
+
// 不画——应用 ratio 控件集无边条)
|
|
487
|
+
if (!this.ratio) {
|
|
488
|
+
const barRot = { top: 0, right: 90, bottom: 180, left: 270 };
|
|
489
|
+
const barSprite = getBarSprite();
|
|
490
|
+
for (const edge of EDGE_HANDLES) {
|
|
491
|
+
const off = CROP_HANDLE_OFFSETS[edge];
|
|
492
|
+
quads.push(spriteQuadAt(matrix, off.x * w, off.y * h, barRot[edge], BAR_BOX_PX, BAR_ORIGIN_PX, zoom, barSprite));
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
// 角括号(sprite 圆头双臂 + 内向阴影;TL 姿态绕窗角旋 90° 步进落位,
|
|
496
|
+
// 旋转序 = 应用控件 this.angle:TL0/TR90/BR180/BL270)
|
|
497
|
+
const bracketRot = { tl: 0, tr: 90, br: 180, bl: 270 };
|
|
498
|
+
const bracketSprite = getBracketSprite();
|
|
499
|
+
for (const corner of BRACKET_HANDLES) {
|
|
500
|
+
const off = CROP_HANDLE_OFFSETS[corner];
|
|
501
|
+
quads.push(spriteQuadAt(matrix, off.x * w, off.y * h, bracketRot[corner], { x: BRACKET_BOX_PX, y: BRACKET_BOX_PX }, { x: BRACKET_ORIGIN_PX, y: BRACKET_ORIGIN_PX }, zoom, bracketSprite));
|
|
502
|
+
}
|
|
503
|
+
return quads;
|
|
504
|
+
}
|
|
505
|
+
dispose() {
|
|
506
|
+
this.detachKey?.();
|
|
507
|
+
this.detachKey = null;
|
|
508
|
+
this.node = null;
|
|
509
|
+
}
|
|
510
|
+
/** raw+natural → live(每帧无状态重算——手势幂等,同引擎其它手势的快照惯例)。
|
|
511
|
+
* 蒙版目标:clipX/clipY 无状态派生 crop(maskCropLiveState),源尺寸 = clipImage
|
|
512
|
+
* 缩放后尺寸;图片目标:raw.cropX 直读 + 元素 natural */
|
|
513
|
+
liveState() {
|
|
514
|
+
const node = this.node;
|
|
515
|
+
if (node instanceof MaskNode) {
|
|
516
|
+
return maskCropLiveState(node.raw, node.clipImageRaw, node.clipImageEl);
|
|
517
|
+
}
|
|
518
|
+
const el = node.imageEl;
|
|
519
|
+
return liveStateFromRaw(node.raw, el.naturalWidth, el.naturalHeight);
|
|
520
|
+
}
|
|
521
|
+
writeBack(next) {
|
|
522
|
+
const node = this.node;
|
|
523
|
+
const props = node instanceof MaskNode ? maskCropWriteProps(next) : liveStateToRawProps(next);
|
|
524
|
+
this.host.document.setProps(node, props, { deferIndexRebuild: true });
|
|
525
|
+
}
|
|
526
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 双击派发控制器(main-webgl2 P5-7)。
|
|
3
|
+
*
|
|
4
|
+
* 自 EngineCanvas.attachInteraction 内联拆出:三层会话分支(表格/拼图/文本)
|
|
5
|
+
* 行为平移,第四层图片族新增。命中走 doc.findTarget 顶层节点后**组穿透下钻**
|
|
6
|
+
* (P5-1 组交互片,应用 searchNonGroupTarget 双击同路径——fabric 的 dblclick
|
|
7
|
+
* target 落组内子元素):组内文本双击进编辑、组内图片族走智能对象/换图事件;
|
|
8
|
+
* Table/Puzzle/Mask 各自会话层不穿透(应用侧 type!=='group' 同口径,嵌套表
|
|
9
|
+
* 本就不在支持面)。按节点族派发:
|
|
10
|
+
* - Table → 命中格进入单元格编辑(P4-4b(2/2),应用 handleDoubleClick 同语义——
|
|
11
|
+
* 编辑 overlay 自身是 TextNode,编辑中双击仍走下面的选词分支)
|
|
12
|
+
* - Puzzle → 命中块进入蒙版编辑会话(P4-5b(3/3)——应用 interactive 切换的
|
|
13
|
+
* 引擎会话等价物;未选中先选组,selection 保持组=历史/parity 主体不变)
|
|
14
|
+
* - Text → 进入文本编辑(首次进入全选、编辑中双击选词,语义在
|
|
15
|
+
* TextEditingController)
|
|
16
|
+
* - 图片族带 smartObject 元数据 → 发 smartobject:open-requested(P5-7:PSD
|
|
17
|
+
* 智能对象双击进入子文档)。引擎只报事实(节点引用),参数映射与 store
|
|
18
|
+
* 调用留在应用桥接层——FabricImage.doubleClickHandler 同语义,src/engine
|
|
19
|
+
* 不反向依赖应用层
|
|
20
|
+
* - 图片族无 smartObject → 发 image:replace-requested(应用双击普通图片的
|
|
21
|
+
* showReplaceImage 等价);码图族(barcode/qrcode)豁免——fabric 侧
|
|
22
|
+
* BarCode/QRCode 刻意继承原生 FabricImage(构造器不挂 mousedblclick),
|
|
23
|
+
* 双击无动作,且内容按 codeContent/codeOption 重生成,换图语义不成立
|
|
24
|
+
*/
|
|
25
|
+
import type { EngineDocument } from '../model/document';
|
|
26
|
+
import { TableNode, TextNode, type SceneNode } from '../model/scene';
|
|
27
|
+
export interface DblClickHost {
|
|
28
|
+
canvasEl: HTMLCanvasElement;
|
|
29
|
+
/** 视口 CSS 坐标 → 场景坐标(EngineCanvas.toScene 同源) */
|
|
30
|
+
toScene: (cssX: number, cssY: number) => {
|
|
31
|
+
x: number;
|
|
32
|
+
y: number;
|
|
33
|
+
};
|
|
34
|
+
document: EngineDocument;
|
|
35
|
+
requestRenderAll: () => void;
|
|
36
|
+
/** 命中格进入单元格编辑(TableInteractionHost.startCellEditing 同源) */
|
|
37
|
+
startCellEditing: (table: TableNode, row: number, col: number) => boolean;
|
|
38
|
+
/** 双击点进入文本编辑(语义在 TextEditingController) */
|
|
39
|
+
enterTextEditingAtClick: (node: TextNode, x: number, y: number) => void;
|
|
40
|
+
/** 外部绘制会话挂起位(PointerHost 同名同义;可选=单测桩宿主免实现) */
|
|
41
|
+
interactionSuspended?: boolean;
|
|
42
|
+
}
|
|
43
|
+
export declare class DoubleClickController {
|
|
44
|
+
private readonly host;
|
|
45
|
+
private readonly onDblClick;
|
|
46
|
+
private disposed;
|
|
47
|
+
constructor(host: DblClickHost);
|
|
48
|
+
/** 命中后派发;监听只做坐标换算与命中,分支语义的单测直入口 */
|
|
49
|
+
dispatch(target: SceneNode | null, sceneX: number, sceneY: number): void;
|
|
50
|
+
dispose(): void;
|
|
51
|
+
}
|