@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.
Files changed (279) hide show
  1. package/README.md +23 -11
  2. package/dist/EngineCanvas.d.ts +0 -255
  3. package/dist/core/color.d.ts +0 -11
  4. package/dist/core/distanceField.d.ts +0 -13
  5. package/dist/core/events.d.ts +0 -25
  6. package/dist/core/gradient.d.ts +0 -47
  7. package/dist/core/homography.d.ts +0 -20
  8. package/dist/core/imageFilters.d.ts +0 -31
  9. package/dist/core/mat2d.d.ts +0 -62
  10. package/dist/core/pathData.d.ts +0 -36
  11. package/dist/core/pattern.d.ts +0 -14
  12. package/dist/core/point.d.ts +0 -14
  13. package/dist/core/psdEffects.d.ts +0 -48
  14. package/dist/core/roundedRect.d.ts +0 -48
  15. package/dist/core/shadow.d.ts +0 -23
  16. package/dist/core/snap.d.ts +0 -103
  17. package/dist/core/stroke.d.ts +0 -13
  18. package/dist/core/triangulate.d.ts +0 -31
  19. package/dist/core/warpMesh.d.ts +0 -38
  20. package/dist/debug/canvasInspection.d.ts +0 -20
  21. package/dist/debug/pixelDiff.d.ts +0 -7
  22. package/dist/debug/pixelDiff.js +1 -64
  23. package/dist/debug/seed.d.ts +0 -426
  24. package/dist/debug/seed.js +28 -3806
  25. package/dist/decoders/webp2sprite.d.ts +0 -16
  26. package/dist/engineFlag.d.ts +0 -76
  27. package/dist/export/SceneExporter.d.ts +0 -58
  28. package/dist/export/glExport.d.ts +0 -41
  29. package/dist/export/svgExport.d.ts +0 -181
  30. package/dist/index.d.ts +1 -14
  31. package/dist/index.js +1060 -64
  32. package/dist/interact/animationPlayback.d.ts +0 -62
  33. package/dist/interact/canvasInteractions.d.ts +1 -38
  34. package/dist/interact/cropSession.d.ts +0 -68
  35. package/dist/interact/dblClick.d.ts +0 -32
  36. package/dist/interact/expandSession.d.ts +0 -46
  37. package/dist/interact/hotkeyActions.d.ts +0 -12
  38. package/dist/interact/pageTransfer.d.ts +0 -2
  39. package/dist/interact/pathSession.d.ts +0 -42
  40. package/dist/interact/pointer.d.ts +0 -87
  41. package/dist/interact/pointerTablePuzzle.d.ts +0 -60
  42. package/dist/interact/pointerTransform.d.ts +0 -48
  43. package/dist/interact/pointerTypes.d.ts +6 -148
  44. package/dist/interact/snapGuide.d.ts +0 -68
  45. package/dist/interact/tableCellEditing.d.ts +0 -34
  46. package/dist/interact/tableInteraction.d.ts +0 -31
  47. package/dist/interact/textEditing.d.ts +0 -44
  48. package/dist/interact/warpFacade.d.ts +0 -5
  49. package/dist/interact/warpSession.d.ts +0 -55
  50. package/dist/interact/wheelScroll.d.ts +0 -42
  51. package/dist/model/alphaHit.d.ts +0 -51
  52. package/dist/model/animation.d.ts +0 -99
  53. package/dist/model/arcLayout.d.ts +0 -33
  54. package/dist/model/arcTextTransform.d.ts +0 -4
  55. package/dist/model/compatEvents.d.ts +0 -72
  56. package/dist/model/compatObject.d.ts +0 -360
  57. package/dist/model/cropEdit.d.ts +0 -60
  58. package/dist/model/document.d.ts +0 -167
  59. package/dist/model/elementTypes.d.ts +0 -47
  60. package/dist/model/expandEdit.d.ts +0 -36
  61. package/dist/model/fabricPrimitives.d.ts +0 -24
  62. package/dist/model/filler.d.ts +0 -12
  63. package/dist/model/groupAssemble.d.ts +0 -5
  64. package/dist/model/groupChildMove.d.ts +0 -37
  65. package/dist/model/groupResize.d.ts +0 -42
  66. package/dist/model/handles.d.ts +0 -24
  67. package/dist/model/imageMaskBake.d.ts +0 -50
  68. package/dist/model/lineConstruct.d.ts +0 -8
  69. package/dist/model/maskCropEdit.d.ts +0 -34
  70. package/dist/model/pathBackground.d.ts +0 -33
  71. package/dist/model/pathConstruct.d.ts +0 -24
  72. package/dist/model/pathEdit.d.ts +0 -55
  73. package/dist/model/puzzleEdit.d.ts +0 -66
  74. package/dist/model/puzzleLayout.d.ts +0 -31
  75. package/dist/model/scene.d.ts +0 -603
  76. package/dist/model/schema.d.ts +0 -48
  77. package/dist/model/shapePath.d.ts +0 -5
  78. package/dist/model/smartObjectBake.d.ts +0 -6
  79. package/dist/model/tableEdit.d.ts +0 -90
  80. package/dist/model/tableFacade.d.ts +0 -5
  81. package/dist/model/tableLayout.d.ts +0 -40
  82. package/dist/model/textAlign.d.ts +0 -22
  83. package/dist/model/textLayout.d.ts +0 -213
  84. package/dist/render/GLBlend.d.ts +0 -24
  85. package/dist/render/GLContext.d.ts +0 -11
  86. package/dist/render/GLIsolate.d.ts +0 -25
  87. package/dist/render/GLTextureCache.d.ts +0 -72
  88. package/dist/render/GlyphAtlas.d.ts +0 -98
  89. package/dist/render/MeshBatch.d.ts +0 -71
  90. package/dist/render/QuadBatch.d.ts +0 -87
  91. package/dist/render/SceneRenderer.d.ts +0 -137
  92. package/dist/render/SourceManager.d.ts +0 -82
  93. package/dist/render/TextRenderer.d.ts +0 -120
  94. package/dist/render/arcText.d.ts +0 -28
  95. package/dist/render/bakeGate.d.ts +0 -35
  96. package/dist/render/batchOrder.d.ts +0 -60
  97. package/dist/render/blendMode.d.ts +0 -27
  98. package/dist/render/clipMaskPainter.d.ts +0 -42
  99. package/dist/render/fontInvalidation.d.ts +0 -18
  100. package/dist/render/fontInvalidationController.d.ts +0 -52
  101. package/dist/render/frameOverlay.d.ts +0 -32
  102. package/dist/render/framePipeline.d.ts +0 -27
  103. package/dist/render/gpuFilterPasses.d.ts +0 -15
  104. package/dist/render/gpuFx.d.ts +0 -82
  105. package/dist/render/gpuImageFilters.d.ts +0 -41
  106. package/dist/render/gpuShadow.d.ts +0 -38
  107. package/dist/render/gradientRamp.d.ts +0 -14
  108. package/dist/render/imageEffects.d.ts +0 -99
  109. package/dist/render/lineDecorationSdf.d.ts +0 -32
  110. package/dist/render/maskRender.d.ts +0 -60
  111. package/dist/render/multiPage.d.ts +0 -91
  112. package/dist/render/progressiveLoad.d.ts +0 -27
  113. package/dist/render/psdEffectPainter.d.ts +0 -25
  114. package/dist/render/psdWarpText.d.ts +0 -19
  115. package/dist/render/puzzleClamp.d.ts +0 -15
  116. package/dist/render/renderEpoch.d.ts +0 -21
  117. package/dist/render/retainedFrame.d.ts +0 -36
  118. package/dist/render/ruler.d.ts +0 -36
  119. package/dist/render/screenClip.d.ts +0 -31
  120. package/dist/render/scrollText.d.ts +0 -46
  121. package/dist/render/segmentTable.d.ts +0 -30
  122. package/dist/render/selectionOverlay.d.ts +0 -203
  123. package/dist/render/settleScheduler.d.ts +0 -24
  124. package/dist/render/shaders.d.ts +4 -24
  125. package/dist/render/shadowBake.d.ts +0 -28
  126. package/dist/render/shadowPainter.d.ts +0 -8
  127. package/dist/render/sharedGpuPainters.d.ts +0 -13
  128. package/dist/render/sourceHydration.d.ts +0 -8
  129. package/dist/render/strokeBake.d.ts +0 -59
  130. package/dist/render/strokeMiterOutline.d.ts +0 -29
  131. package/dist/render/strokePainter.d.ts +0 -31
  132. package/dist/render/strokeSdf.d.ts +0 -52
  133. package/dist/render/svgRaster.d.ts +0 -34
  134. package/dist/render/tableOverlay.d.ts +0 -35
  135. package/dist/render/textHighlight.d.ts +0 -67
  136. package/dist/render/textureUpload.d.ts +0 -13
  137. package/dist/render/verticalText.d.ts +0 -21
  138. package/dist/render/warpText.d.ts +0 -48
  139. package/dist/render/workspaceBackdrop.d.ts +0 -22
  140. package/dist/render/workspaceChecker.d.ts +0 -34
  141. package/dist/render/workspaceGlow.d.ts +0 -38
  142. package/package.json +4 -3
  143. package/dist/EngineCanvas.js +0 -1202
  144. package/dist/core/canvasPerf.js +0 -170
  145. package/dist/core/color.js +0 -107
  146. package/dist/core/distanceField.js +0 -92
  147. package/dist/core/events.js +0 -80
  148. package/dist/core/gradient.js +0 -175
  149. package/dist/core/homography.js +0 -123
  150. package/dist/core/imageFilters.js +0 -330
  151. package/dist/core/mat2d.js +0 -241
  152. package/dist/core/pathData.js +0 -926
  153. package/dist/core/pattern.js +0 -40
  154. package/dist/core/point.js +0 -119
  155. package/dist/core/psdEffects.js +0 -158
  156. package/dist/core/roundedRect.js +0 -164
  157. package/dist/core/shadow.js +0 -47
  158. package/dist/core/snap.js +0 -793
  159. package/dist/core/stroke.js +0 -45
  160. package/dist/core/triangulate.js +0 -194
  161. package/dist/core/warpMesh.js +0 -469
  162. package/dist/debug/canvasInspection.js +0 -113
  163. package/dist/decoders/gif2sprite.js +0 -84
  164. package/dist/decoders/webp2sprite.js +0 -133
  165. package/dist/engineFlag.js +0 -104
  166. package/dist/export/SceneExporter.js +0 -286
  167. package/dist/export/glExport.js +0 -79
  168. package/dist/export/svgExport.js +0 -1803
  169. package/dist/interact/animationPlayback.js +0 -358
  170. package/dist/interact/canvasInteractions.js +0 -174
  171. package/dist/interact/cropSession.js +0 -527
  172. package/dist/interact/dblClick.js +0 -120
  173. package/dist/interact/expandSession.js +0 -282
  174. package/dist/interact/hotkeyActions.js +0 -42
  175. package/dist/interact/pageTransfer.js +0 -56
  176. package/dist/interact/pathSession.js +0 -480
  177. package/dist/interact/pointer.js +0 -1692
  178. package/dist/interact/pointerTablePuzzle.js +0 -358
  179. package/dist/interact/pointerTransform.js +0 -441
  180. package/dist/interact/pointerTypes.js +0 -96
  181. package/dist/interact/snapGuide.js +0 -377
  182. package/dist/interact/tableCellEditing.js +0 -207
  183. package/dist/interact/tableInteraction.js +0 -219
  184. package/dist/interact/textEditing.js +0 -423
  185. package/dist/interact/warpFacade.js +0 -51
  186. package/dist/interact/warpSession.js +0 -583
  187. package/dist/interact/wheelScroll.js +0 -100
  188. package/dist/model/alphaHit.js +0 -267
  189. package/dist/model/animation.js +0 -510
  190. package/dist/model/arcLayout.js +0 -308
  191. package/dist/model/arcTextTransform.js +0 -87
  192. package/dist/model/compatEvents.js +0 -96
  193. package/dist/model/compatObject.js +0 -1583
  194. package/dist/model/cropEdit.js +0 -497
  195. package/dist/model/document.js +0 -590
  196. package/dist/model/elementTypes.js +0 -119
  197. package/dist/model/expandEdit.js +0 -161
  198. package/dist/model/fabricPrimitives.js +0 -9
  199. package/dist/model/filler.js +0 -1
  200. package/dist/model/groupAssemble.js +0 -98
  201. package/dist/model/groupChildMove.js +0 -145
  202. package/dist/model/groupResize.js +0 -109
  203. package/dist/model/handles.js +0 -29
  204. package/dist/model/imageMaskBake.js +0 -136
  205. package/dist/model/lineConstruct.js +0 -79
  206. package/dist/model/maskCropEdit.js +0 -90
  207. package/dist/model/pathBackground.js +0 -196
  208. package/dist/model/pathConstruct.js +0 -55
  209. package/dist/model/pathEdit.js +0 -378
  210. package/dist/model/puzzleEdit.js +0 -742
  211. package/dist/model/puzzleLayout.js +0 -143
  212. package/dist/model/scene.js +0 -2930
  213. package/dist/model/schema.js +0 -13
  214. package/dist/model/shapePath.js +0 -137
  215. package/dist/model/smartObjectBake.js +0 -295
  216. package/dist/model/tableEdit.js +0 -751
  217. package/dist/model/tableFacade.js +0 -808
  218. package/dist/model/tableLayout.js +0 -194
  219. package/dist/model/textAlign.js +0 -36
  220. package/dist/model/textLayout.js +0 -842
  221. package/dist/render/GLBlend.js +0 -270
  222. package/dist/render/GLContext.js +0 -48
  223. package/dist/render/GLIsolate.js +0 -188
  224. package/dist/render/GLTextureCache.js +0 -224
  225. package/dist/render/GlyphAtlas.js +0 -412
  226. package/dist/render/MeshBatch.js +0 -416
  227. package/dist/render/QuadBatch.js +0 -561
  228. package/dist/render/SceneRenderer.js +0 -753
  229. package/dist/render/SourceManager.js +0 -523
  230. package/dist/render/TextRenderer.js +0 -854
  231. package/dist/render/arcText.js +0 -187
  232. package/dist/render/bakeGate.js +0 -32
  233. package/dist/render/batchOrder.js +0 -168
  234. package/dist/render/blendMode.js +0 -142
  235. package/dist/render/clipMaskPainter.js +0 -244
  236. package/dist/render/fontInvalidation.js +0 -77
  237. package/dist/render/fontInvalidationController.js +0 -119
  238. package/dist/render/frameOverlay.js +0 -124
  239. package/dist/render/framePipeline.js +0 -96
  240. package/dist/render/gpuFilterPasses.js +0 -883
  241. package/dist/render/gpuFx.js +0 -673
  242. package/dist/render/gpuImageFilters.js +0 -295
  243. package/dist/render/gpuShadow.js +0 -327
  244. package/dist/render/gradientRamp.js +0 -74
  245. package/dist/render/imageEffects.js +0 -415
  246. package/dist/render/lineDecorationSdf.js +0 -189
  247. package/dist/render/maskRender.js +0 -217
  248. package/dist/render/multiPage.js +0 -420
  249. package/dist/render/progressiveLoad.js +0 -86
  250. package/dist/render/psdEffectPainter.js +0 -333
  251. package/dist/render/psdWarpText.js +0 -212
  252. package/dist/render/puzzleClamp.js +0 -30
  253. package/dist/render/renderEpoch.js +0 -35
  254. package/dist/render/renderViewport.js +0 -18
  255. package/dist/render/retainedFrame.js +0 -192
  256. package/dist/render/ruler.js +0 -287
  257. package/dist/render/screenClip.js +0 -67
  258. package/dist/render/scrollText.js +0 -266
  259. package/dist/render/segmentTable.js +0 -117
  260. package/dist/render/selectionOverlay.js +0 -1008
  261. package/dist/render/settleScheduler.js +0 -51
  262. package/dist/render/shaders.js +0 -450
  263. package/dist/render/shadowBake.js +0 -203
  264. package/dist/render/shadowPainter.js +0 -93
  265. package/dist/render/sharedGpuPainters.js +0 -42
  266. package/dist/render/sourceHydration.js +0 -48
  267. package/dist/render/strokeBake.js +0 -516
  268. package/dist/render/strokeMiterOutline.js +0 -224
  269. package/dist/render/strokePainter.js +0 -207
  270. package/dist/render/strokeSdf.js +0 -262
  271. package/dist/render/svgRaster.js +0 -71
  272. package/dist/render/tableOverlay.js +0 -233
  273. package/dist/render/textHighlight.js +0 -380
  274. package/dist/render/textureUpload.js +0 -26
  275. package/dist/render/verticalText.js +0 -63
  276. package/dist/render/warpText.js +0 -384
  277. package/dist/render/workspaceBackdrop.js +0 -60
  278. package/dist/render/workspaceChecker.js +0 -170
  279. package/dist/render/workspaceGlow.js +0 -198
@@ -1,497 +0,0 @@
1
- /**
2
- * 图片裁剪模式纯函数层(B2):应用 cropping.controls.handlers / cropping.mixin /
3
- * ImageClip 预设的逐式移植。只算不写——入参出参都是普通对象,节点落盘由
4
- * 调用方(interact/cropSession)执行。
5
- *
6
- * 数据模型(与应用 live 对象同构,区别于盘上序列化形态):
7
- * - `width/height` = 裁剪窗尺寸(源像素);`scaleX/scaleY` 把窗映射到画布
8
- * - `cropX/cropY` = 窗左上角在源图内的偏移(源像素);整图 = naturalWidth/Height
9
- * - 盘上 legacy 口径 raw.width = width + cropX(右缘坐标语义)、visible 口径
10
- * raw.width = width——`liveStateFromRaw/applyLiveState` 做双向映射(B1 契约:
11
- * raw 不改写语义、toObject 原样回写)
12
- *
13
- * 几何原语与 fabric 6.9 逐位同源(口径实测锚定):
14
- * - 数值型 origin 分数 resolve(v) = v − 0.5(字符串 left/top/center/right/bottom
15
- * = −0.5/−0.5/0/0.5/0.5——应用 utils/resolveOrigin 与 fabric 同式)
16
- * - `translateToGivenOrigin` 底层是**轴对齐**偏移(offset = fracDelta·缩放后尺寸,
17
- * 不含旋转);旋转在包装层:translateToOriginPoint 绕 center 正转、
18
- * translateToCenterPoint 绕 pos 正转
19
- * - normalizePoint = 指针绕 center 反转(去旋转、不去缩放)− origin 偏移
20
- * (origin 偏移同样轴对齐)——边手柄公式里的 `/scaleX` 即由此而来
21
- */
22
- const ORIGIN_OFFSET = { left: -0.5, top: -0.5, center: 0, bottom: 0.5, right: 0.5 };
23
- /** fabric resolveOrigin 同式:字符串查表、数值 v → v − 0.5 */
24
- export const resolveCropOrigin = (v) => (typeof v === 'string' ? ORIGIN_OFFSET[v] ?? 0 : v - 0.5);
25
- const rotateAbout = (p, byRad, origin) => {
26
- const c = Math.cos(byRad);
27
- const s = Math.sin(byRad);
28
- const dx = p.x - origin.x;
29
- const dy = p.y - origin.y;
30
- return { x: origin.x + c * dx - s * dy, y: origin.y + s * dx + c * dy };
31
- };
32
- /** 缩放后(未旋转)尺寸 = width·scaleX——fabric _getTransformedDimensions(stroke=0 图片族) */
33
- export const scaledDimsOf = (s) => ({ x: s.width * s.scaleX, y: s.height * s.scaleY });
34
- const scaledDims = scaledDimsOf;
35
- const rad = (d) => (d * Math.PI) / 180;
36
- /** 源空间局部点 (fx·W, fy·H) 的场景位(含旋转)。flip 参数=锚定几何的翻转
37
- * 感知(scene = center + R·S·F·local,有意偏差侧——见 cropLocalPoint 注;
38
- * 无 flip 时与 fabric translateToOriginPoint 逐位同源) */
39
- export const originFromCenter = (center, fx, fy, dims, angleDeg, flipX = false, flipY = false) => {
40
- const ux = flipX ? -1 : 1;
41
- const uy = flipY ? -1 : 1;
42
- let p = { x: center.x + fx * dims.x * ux, y: center.y + fy * dims.y * uy };
43
- if (angleDeg)
44
- p = rotateAbout(p, rad(angleDeg), center);
45
- return p;
46
- };
47
- /** originFromCenter 的逆(锚定回钉;flip 感知同上) */
48
- export const centerFromOrigin = (pos, fx, fy, dims, angleDeg, flipX = false, flipY = false) => {
49
- const ux = flipX ? -1 : 1;
50
- const uy = flipY ? -1 : 1;
51
- let p = { x: pos.x - fx * dims.x * ux, y: pos.y - fy * dims.y * uy };
52
- if (angleDeg)
53
- p = rotateAbout(p, rad(angleDeg), pos);
54
- return p;
55
- };
56
- /** 自身 origin 位置(left/top 写入口径) */
57
- export const positionFromCenter = (center, ownOX, ownOY, dims, angleDeg) => originFromCenter(center, resolveCropOrigin(ownOX), resolveCropOrigin(ownOY), dims, angleDeg);
58
- /** 自身 origin 位置 → center(fabric getRelativeCenterPoint) */
59
- export const centerFromPosition = (left, top, ownOX, ownOY, dims, angleDeg) => centerFromOrigin({ x: left, y: top }, resolveCropOrigin(ownOX), resolveCropOrigin(ownOY), dims, angleDeg);
60
- /** fabric normalizePoint:指针去旋转(不去缩放)再减 origin 偏移(轴对齐)。
61
- * **有意偏差(应用 bug 修正,2026-09-20 用户反馈「对角点一拖就合到一起」)**:
62
- * fabric 的 local 坐标不去翻转(实测实证:flipX 图边/角手柄外拖 → 宽 0 塌缩),
63
- * 引擎补上翻转逆变换(local = S⁻¹·F⁻¹·R⁻¹·δ)后恒走非 Flig 手柄——翻转镜像
64
- * 下手柄语义自然正确;应用的 *Flig 变体是错位补偿(保留导出仅作语义参考,不再被分发),
65
- * 应用侧修复后同步回归(竖排 right/center 先例) */
66
- export const cropLocalPoint = (s, pointer, fx = 0, fy = 0) => {
67
- const center = centerFromPosition(s.left, s.top, s.originX, s.originY, scaledDims(s), s.angle);
68
- let p = pointer;
69
- if (s.angle)
70
- p = rotateAbout(p, -rad(s.angle), center);
71
- const dims = scaledDims(s);
72
- const unflipX = s.flipX ? -1 : 1;
73
- const unflipY = s.flipY ? -1 : 1;
74
- return { x: (p.x - center.x) * unflipX - fx * dims.x, y: (p.y - center.y) * unflipY - fy * dims.y };
75
- };
76
- /** 各 handler 共用的「锚定→改窗→回钉」收口:返回新 left/top */
77
- const setByAnchor = (s, anchorFx, anchorFy, next) => {
78
- const oldDims = scaledDims(s);
79
- const center = centerFromPosition(s.left, s.top, s.originX, s.originY, oldDims, s.angle);
80
- const constraint = originFromCenter(center, anchorFx, anchorFy, oldDims, s.angle, s.flipX, s.flipY);
81
- const scaleX = next.scaleX ?? s.scaleX;
82
- const scaleY = next.scaleY ?? s.scaleY;
83
- const newDims = { x: next.width * scaleX, y: next.height * scaleY };
84
- const newCenter = centerFromOrigin(constraint, anchorFx, anchorFy, newDims, s.angle, s.flipX, s.flipY);
85
- const pos = positionFromCenter(newCenter, s.originX, s.originY, newDims, s.angle);
86
- return { ...s, ...next, scaleX, scaleY, left: pos.x, top: pos.y };
87
- };
88
- // ── 边手柄(窗随指针走、对边锚定;cropX/cropY 吸收位移)──────────────────────
89
- // anchor 分数 = fabric transform origin(cropLeft 控件 x:-0.5,y:0 → originX 'left'),
90
- // 窗口「左/右/上/下」边移动时锚定对边('right'/'left'/'bottom'/'top'),Y 锚 originY。
91
- const cropFromLeft = (s, pointer) => {
92
- const { width, cropX } = s;
93
- const local = cropLocalPoint(s, pointer);
94
- let changeX = local.x / s.scaleX - -(width / 2);
95
- let newWidth = width - changeX;
96
- if (cropX + changeX < 0) {
97
- changeX = -cropX;
98
- newWidth = width + cropX;
99
- }
100
- if (newWidth <= 0) {
101
- changeX += newWidth;
102
- newWidth = 0;
103
- }
104
- return setByAnchor(s, 0.5, 0, { width: newWidth, height: s.height, cropX: cropX + changeX, cropY: s.cropY });
105
- };
106
- export const cropFromLeftFlig = (s, pointer) => {
107
- const { width, cropX } = s;
108
- const local = cropLocalPoint(s, pointer);
109
- let newWidth = width - (local.x / s.scaleX - -(width / 2));
110
- if (newWidth + cropX > s.naturalWidth)
111
- newWidth = s.naturalWidth - cropX;
112
- if (newWidth < 0)
113
- newWidth = 0;
114
- return setByAnchor(s, 0.5, 0, { width: newWidth, height: s.height, cropX, cropY: s.cropY });
115
- };
116
- const cropFromRight = (s, pointer) => {
117
- const { width, cropX } = s;
118
- const local = cropLocalPoint(s, pointer);
119
- let newWidth = width - (width / 2 - local.x / s.scaleX);
120
- if (newWidth + cropX > s.naturalWidth)
121
- newWidth = s.naturalWidth - cropX;
122
- if (newWidth < 0)
123
- newWidth = 0;
124
- return setByAnchor(s, -0.5, 0, { width: newWidth, height: s.height, cropX, cropY: s.cropY });
125
- };
126
- export const cropFromRightFlig = (s, pointer) => {
127
- const { width, cropX } = s;
128
- const local = cropLocalPoint(s, pointer);
129
- let changeX = width / 2 - local.x / s.scaleX;
130
- let newWidth = width - changeX;
131
- if (cropX + changeX < 0) {
132
- changeX = -cropX;
133
- newWidth = width + cropX;
134
- }
135
- if (newWidth <= 0) {
136
- changeX += newWidth;
137
- newWidth = 0;
138
- }
139
- return setByAnchor(s, -0.5, 0, { width: newWidth, height: s.height, cropX: cropX + changeX, cropY: s.cropY });
140
- };
141
- const cropFromTop = (s, pointer) => {
142
- const { height, cropY } = s;
143
- const local = cropLocalPoint(s, pointer);
144
- let changeY = local.y / s.scaleY - -(height / 2);
145
- let newHeight = height - changeY;
146
- if (cropY + changeY < 0) {
147
- changeY = -cropY;
148
- newHeight = height + cropY;
149
- }
150
- if (newHeight <= 0) {
151
- changeY += newHeight;
152
- newHeight = 0;
153
- }
154
- return setByAnchor(s, 0, 0.5, { width: s.width, height: newHeight, cropX: s.cropX, cropY: cropY + changeY });
155
- };
156
- export const cropFromTopFlig = (s, pointer) => {
157
- const { height, cropY } = s;
158
- const local = cropLocalPoint(s, pointer);
159
- let newHeight = height - (local.y / s.scaleY - -(height / 2));
160
- if (newHeight + cropY > s.naturalHeight)
161
- newHeight = s.naturalHeight - cropY;
162
- if (newHeight < 0)
163
- newHeight = 0;
164
- return setByAnchor(s, 0, 0.5, { width: s.width, height: newHeight, cropX: s.cropX, cropY });
165
- };
166
- const cropFromBottom = (s, pointer) => {
167
- const { height, cropY } = s;
168
- const local = cropLocalPoint(s, pointer);
169
- let newHeight = height - (height / 2 - local.y / s.scaleY);
170
- if (newHeight + cropY > s.naturalHeight)
171
- newHeight = s.naturalHeight - cropY;
172
- if (newHeight < 0)
173
- newHeight = 0;
174
- return setByAnchor(s, 0, -0.5, { width: s.width, height: newHeight, cropX: s.cropX, cropY });
175
- };
176
- export const cropFromBottomFlig = (s, pointer) => {
177
- const { height, cropY } = s;
178
- const local = cropLocalPoint(s, pointer);
179
- let changeY = height / 2 - local.y / s.scaleY;
180
- let newHeight = height - changeY;
181
- if (cropY + changeY < 0) {
182
- changeY = -cropY;
183
- newHeight = height + cropY;
184
- }
185
- if (newHeight <= 0) {
186
- changeY += newHeight;
187
- newHeight = 0;
188
- }
189
- return setByAnchor(s, 0, -0.5, { width: s.width, height: newHeight, cropX: s.cropX, cropY: cropY + changeY });
190
- };
191
- /** 边手柄分发(有意偏差:恒走非 Flig——见 cropLocalPoint 的翻转修正注;
192
- * 手柄 id = 源空间侧(offset 经翻转矩阵渲染到镜像侧),un-flip 后语义自然对齐) */
193
- export const applyCropEdge = (s, edge, pointer) => {
194
- if (edge === 'left' || edge === 'right') {
195
- return edge === 'left' ? cropFromLeft(s, pointer) : cropFromRight(s, pointer);
196
- }
197
- return edge === 'top' ? cropFromTop(s, pointer) : cropFromBottom(s, pointer);
198
- };
199
- /**
200
- * 角括号手柄 = X/Y 两轴独立裁剪(应用 cropFromTopLeft 组合:left 先 top 后,
201
- * 后者读前者已改的 width/height——Y 轴锚定用更新后的 dims,逐步组合同源)。
202
- */
203
- export const applyCropCorner = (s, corner, pointer) => {
204
- const horizontal = corner === 'tl' || corner === 'bl' ? 'left' : 'right';
205
- const vertical = corner === 'tl' || corner === 'tr' ? 'top' : 'bottom';
206
- const afterX = applyCropEdge(s, horizontal, pointer);
207
- return applyCropEdge(afterX, vertical, pointer);
208
- };
209
- // ── 比例约束角手柄(cropAspectRatio = height/width;锚定对角)────────────────
210
- export const constrainToRatio = (rawWidth, rawHeight, ratio) => {
211
- const widthByHeight = rawHeight / ratio;
212
- if (rawWidth <= widthByHeight) {
213
- return { width: rawWidth, height: rawWidth * ratio };
214
- }
215
- return { width: rawHeight / ratio, height: rawHeight };
216
- };
217
- export const applyCropRatioCorner = (s, corner, pointer, ratio) => {
218
- const local = cropLocalPoint(s, pointer);
219
- const px = local.x / s.scaleX;
220
- const py = local.y / s.scaleY;
221
- if (corner === 'br') {
222
- // 锚定左上:从左上到指针的可用空间
223
- let rawWidth = px - -s.width / 2;
224
- let rawHeight = py - -s.height / 2;
225
- rawWidth = Math.min(rawWidth, s.naturalWidth - s.cropX);
226
- rawHeight = Math.min(rawHeight, s.naturalHeight - s.cropY);
227
- if (rawWidth <= 0 || rawHeight <= 0)
228
- return null;
229
- const { width, height } = constrainToRatio(rawWidth, rawHeight, ratio);
230
- return setByAnchor(s, -0.5, -0.5, { width, height, cropX: s.cropX, cropY: s.cropY });
231
- }
232
- if (corner === 'tl') {
233
- // 锚定右下:指针到右/下边缘的可用空间;cropX/Y 随窗缩左移
234
- let rawWidth = s.width / 2 - px;
235
- let rawHeight = s.height / 2 - py;
236
- rawWidth = Math.min(rawWidth, s.width + s.cropX);
237
- rawHeight = Math.min(rawHeight, s.height + s.cropY);
238
- if (rawWidth <= 0 || rawHeight <= 0)
239
- return null;
240
- const { width, height } = constrainToRatio(rawWidth, rawHeight, ratio);
241
- const changeX = s.width - width;
242
- const changeY = s.height - height;
243
- if (s.cropX + changeX < 0 || s.cropY + changeY < 0)
244
- return null;
245
- return setByAnchor(s, 0.5, 0.5, { width, height, cropX: s.cropX + changeX, cropY: s.cropY + changeY });
246
- }
247
- if (corner === 'tr') {
248
- // 锚定左下:水平从左缘到指针(扩展)、垂直从指针到下缘(收缩)
249
- let rawWidth = px - -s.width / 2;
250
- let rawHeight = s.height / 2 - py;
251
- rawWidth = Math.min(rawWidth, s.naturalWidth - s.cropX);
252
- rawHeight = Math.min(rawHeight, s.height + s.cropY);
253
- if (rawWidth <= 0 || rawHeight <= 0)
254
- return null;
255
- const { width, height } = constrainToRatio(rawWidth, rawHeight, ratio);
256
- const changeY = s.height - height;
257
- if (s.cropY + changeY < 0)
258
- return null;
259
- return setByAnchor(s, -0.5, 0.5, { width, height, cropX: s.cropX, cropY: s.cropY + changeY });
260
- }
261
- // bl:锚定右上:水平从指针到右缘(收缩)、垂直从上缘到指针(扩展)
262
- let rawWidth = s.width / 2 - px;
263
- let rawHeight = py - -s.height / 2;
264
- rawWidth = Math.min(rawWidth, s.width + s.cropX);
265
- rawHeight = Math.min(rawHeight, s.naturalHeight - s.cropY);
266
- if (rawWidth <= 0 || rawHeight <= 0)
267
- return null;
268
- const { width, height } = constrainToRatio(rawWidth, rawHeight, ratio);
269
- const changeX = s.width - width;
270
- if (s.cropX + changeX < 0)
271
- return null;
272
- return setByAnchor(s, 0.5, -0.5, { width, height, cropX: s.cropX + changeX, cropY: s.cropY });
273
- };
274
- // ── 整图四角圆手柄(等比缩放;锚定对侧整图角,溢出拒绝)────────────────────
275
- /** 等比 scale(有意偏差:恒取 min——local 已 un-flip,应用的 flip 取 max 是
276
- * 同一未补偿坐标系的另一半错位补偿) */
277
- const calcScaleOf = (p, fullHeight, fullWidth, flipX, flipY) => {
278
- const sx = Math.abs(p.x / fullWidth);
279
- const sy = Math.abs(p.y / fullHeight);
280
- void flipX;
281
- void flipY;
282
- return Math.min(sx, sy);
283
- };
284
- export const applyScaleEquallyCrop = (s, corner, pointer) => {
285
- if (s.width <= 0 || s.height <= 0)
286
- return null;
287
- const { naturalWidth: fullWidth, naturalHeight: fullHeight } = s;
288
- const remainderX = fullWidth - s.width - s.cropX;
289
- const remainderY = fullHeight - s.height - s.cropY;
290
- // 各角的锚定 origin 原值(应用的 anchorOrigin 组合;resolve 后进 origin 系)
291
- let anchorRawX;
292
- let anchorRawY;
293
- if (corner === 'br') {
294
- anchorRawX = -s.cropX / s.width;
295
- anchorRawY = -s.cropY / s.height;
296
- }
297
- else if (corner === 'tl') {
298
- anchorRawX = 1 + remainderX / s.width;
299
- anchorRawY = 1 + remainderY / s.height;
300
- }
301
- else if (corner === 'tr') {
302
- anchorRawX = -s.cropX / s.width;
303
- anchorRawY = 1 + remainderY / s.height;
304
- }
305
- else {
306
- anchorRawX = 1 + remainderX / s.width;
307
- anchorRawY = -s.cropY / s.height;
308
- }
309
- // 指针相对锚定 origin 的本地量(getLocalPoint:去旋转 + 轴对齐 origin 偏移)
310
- const local = cropLocalPoint(s, pointer, resolveCropOrigin(anchorRawX), resolveCropOrigin(anchorRawY));
311
- const scale = calcScaleOf(local, fullHeight, fullWidth, s.flipX, s.flipY);
312
- const scaleChangeX = scale / s.scaleX;
313
- const scaleChangeY = scale / s.scaleY;
314
- const newWidth = s.width / scaleChangeX;
315
- const newHeight = s.height / scaleChangeY;
316
- const scaledRemainderX = remainderX / scaleChangeX;
317
- const scaledRemainderY = remainderY / scaleChangeY;
318
- let newCropX;
319
- let newCropY;
320
- if (corner === 'br') {
321
- newCropX = s.cropX / scaleChangeX;
322
- newCropY = s.cropY / scaleChangeY;
323
- if (newCropX + newWidth > fullWidth || newCropY + newHeight > fullHeight)
324
- return null;
325
- }
326
- else if (corner === 'tl') {
327
- newCropX = fullWidth - newWidth - scaledRemainderX;
328
- newCropY = fullHeight - newHeight - scaledRemainderY;
329
- if (newWidth + scaledRemainderX > fullWidth || newHeight + scaledRemainderY > fullHeight)
330
- return null;
331
- }
332
- else if (corner === 'tr') {
333
- newCropX = s.cropX / scaleChangeX;
334
- newCropY = fullHeight - newHeight - scaledRemainderY;
335
- if (newCropX + newWidth > fullWidth || scaledRemainderY + newHeight > fullHeight)
336
- return null;
337
- }
338
- else {
339
- newCropX = fullWidth - newWidth - scaledRemainderX;
340
- newCropY = s.cropY / scaleChangeY;
341
- if (newWidth + scaledRemainderX > fullWidth || newHeight + newCropY > fullHeight)
342
- return null;
343
- }
344
- // 回钉:锚定整图角冻结(new 锚定分数按新窗取——应用的 newExtraAnchor 组合)
345
- let newAnchorRawX;
346
- let newAnchorRawY;
347
- if (corner === 'br') {
348
- newAnchorRawX = -newCropX / newWidth;
349
- newAnchorRawY = -newCropY / newHeight;
350
- }
351
- else if (corner === 'tl') {
352
- newAnchorRawX = 1 + scaledRemainderX / newWidth;
353
- newAnchorRawY = 1 + scaledRemainderY / newHeight;
354
- }
355
- else if (corner === 'tr') {
356
- newAnchorRawX = -newCropX / newWidth;
357
- newAnchorRawY = 1 + scaledRemainderY / newHeight;
358
- }
359
- else {
360
- newAnchorRawX = 1 + scaledRemainderX / newWidth;
361
- newAnchorRawY = -newCropY / newHeight;
362
- }
363
- const oldDims = scaledDims(s);
364
- const center = centerFromPosition(s.left, s.top, s.originX, s.originY, oldDims, s.angle);
365
- const constraint = originFromCenter(center, resolveCropOrigin(anchorRawX), resolveCropOrigin(anchorRawY), oldDims, s.angle, s.flipX, s.flipY);
366
- const newDims = { x: newWidth * scale, y: newHeight * scale };
367
- const newCenter = centerFromOrigin(constraint, resolveCropOrigin(newAnchorRawX), resolveCropOrigin(newAnchorRawY), newDims, s.angle, s.flipX, s.flipY);
368
- const pos = positionFromCenter(newCenter, s.originX, s.originY, newDims, s.angle);
369
- return { ...s, width: newWidth, height: newHeight, cropX: newCropX, cropY: newCropY, scaleX: scale, scaleY: scale, left: pos.x, top: pos.y };
370
- };
371
- // ── 框内拖图(应用 cropModeHandlerMoveImage / canvasMouseMove 同一套钳制)────
372
- /** 拖图增量(画布系)→ 新 cropX/cropY;增量先过「去平移逆变换」(fabric
373
- * moveTransformationMatrix = invert(calcTransformMatrix) 去平移——旋转/缩放/
374
- * 翻转全随图),再取负(拖图视觉方向 = 内容滚动反向)。
375
- * 旋转方向修正(2026-09-22 用户反馈「有旋转角时拖底图发飘」):去旋转应乘
376
- * R(−θ)——rx/ry 两式即「按 −φ 展开」,φ 必须传 +θ;首版传了 −θ 双重取负,
377
- * 等效乘 R(+θ),指针与内容运动方向差 2θ(45° 垂直、90° 反向) */
378
- export const moveCropImage = (s, deltaScene) => {
379
- const c = Math.cos(rad(s.angle));
380
- const sn = Math.sin(rad(s.angle));
381
- // 逆线性 = S⁻¹·F⁻¹·R(−θ):先去旋转,再除 scale(flip 并入除子)
382
- const fx = s.flipX ? -1 : 1;
383
- const fy = s.flipY ? -1 : 1;
384
- const rx = c * deltaScene.x + sn * deltaScene.y;
385
- const ry = -sn * deltaScene.x + c * deltaScene.y;
386
- const changeX = -rx / (fx * s.scaleX);
387
- const changeY = -ry / (fy * s.scaleY);
388
- let cropX = s.cropX + changeX;
389
- let cropY = s.cropY + changeY;
390
- if (cropX < 0)
391
- cropX = 0;
392
- else if (cropX + s.width > s.naturalWidth)
393
- cropX = s.naturalWidth - s.width;
394
- if (cropY < 0)
395
- cropY = 0;
396
- else if (cropY + s.height > s.naturalHeight)
397
- cropY = s.naturalHeight - s.height;
398
- return { cropX, cropY };
399
- };
400
- // ── 比例预设(ImageClip presetImageClip 的 ratio 分支:整图内居中最大比例矩形)──
401
- export const applyCropRatioPreset = (s, ratio) => {
402
- const imageRatio = s.naturalHeight / s.naturalWidth;
403
- let newWidth;
404
- let newHeight;
405
- if (imageRatio > ratio) {
406
- newWidth = s.naturalWidth;
407
- newHeight = s.naturalWidth * ratio;
408
- }
409
- else {
410
- newHeight = s.naturalHeight;
411
- newWidth = s.naturalHeight / ratio;
412
- }
413
- const newCropX = (s.naturalWidth - newWidth) / 2;
414
- const newCropY = (s.naturalHeight - newHeight) / 2;
415
- // 预设直写 width/cropX 且 setCoords+setupDragMatrix——left/top 不动(窗锚点跟随
416
- // origin,尺寸变化后中心平移由引擎 position 语义自动呈现);应用不重钉位置
417
- return { ...s, width: newWidth, height: newHeight, cropX: newCropX, cropY: newCropY };
418
- };
419
- // ── live ↔ raw(盘上序列化双口径映射;B1 契约 raw 派生层换算)─────────────────
420
- /** raw(盘上形态)→ live 状态。naturalW/H 由调用方给(imageEl 已加载)。
421
- * 越界防御(批次 319):换源后未重排几何的病态存盘(旧窗/旧偏移溢出新自然
422
- * 尺寸)会让会话几何发散——整图框/等比手柄锚定分数进负数域、moveCropImage
423
- * 的右缘钳制产出负 cropX。窗优先保(窗是可视内容盒)钳进 [0, natural],再把
424
- * 偏移收进余量;sane 数据(cropX+width ≤ natural 恒成立)零改写,natural
425
- * 未知(0,无内禀尺寸 SVG 等)不钳保持原语义 */
426
- export const liveStateFromRaw = (raw, naturalWidth, naturalHeight) => {
427
- const visible = raw.cropSizeMode === 'visible';
428
- let cropX = raw.cropX ?? 0;
429
- let cropY = raw.cropY ?? 0;
430
- const rawW = raw.width ?? naturalWidth;
431
- const rawH = raw.height ?? naturalHeight;
432
- let width = visible ? rawW : rawW - cropX;
433
- let height = visible ? rawH : rawH - cropY;
434
- if (naturalWidth > 0 && naturalHeight > 0) {
435
- width = Math.min(Math.max(width, 0), naturalWidth);
436
- height = Math.min(Math.max(height, 0), naturalHeight);
437
- cropX = Math.min(Math.max(cropX, 0), naturalWidth - width);
438
- cropY = Math.min(Math.max(cropY, 0), naturalHeight - height);
439
- }
440
- return {
441
- left: raw.left ?? 0,
442
- top: raw.top ?? 0,
443
- angle: raw.angle ?? 0,
444
- originX: raw.originX ?? 'left',
445
- originY: raw.originY ?? 'top',
446
- flipX: raw.flipX === true,
447
- flipY: raw.flipY === true,
448
- width,
449
- height,
450
- cropX,
451
- cropY,
452
- scaleX: raw.scaleX ?? 1,
453
- scaleY: raw.scaleY ?? 1,
454
- naturalWidth,
455
- naturalHeight,
456
- cropSizeMode: raw.cropSizeMode ?? 'legacy'
457
- };
458
- };
459
- /** live 状态 → raw 写回字段(left/top/width/height/cropX/cropY/scale;cropSizeMode 保持盘上原值) */
460
- export const liveStateToRawProps = (s) => {
461
- const visible = s.cropSizeMode === 'visible';
462
- return {
463
- left: s.left,
464
- top: s.top,
465
- width: visible ? s.width : s.width + s.cropX,
466
- height: visible ? s.height : s.height + s.cropY,
467
- cropX: s.cropX,
468
- cropY: s.cropY,
469
- scaleX: s.scaleX,
470
- scaleY: s.scaleY
471
- };
472
- };
473
- /** 手柄在「窗本地系」的归一化位置(渲染/命中共用) */
474
- export const CROP_HANDLE_OFFSETS = {
475
- tl: { x: -0.5, y: -0.5 },
476
- tr: { x: 0.5, y: -0.5 },
477
- bl: { x: -0.5, y: 0.5 },
478
- br: { x: 0.5, y: 0.5 },
479
- left: { x: -0.5, y: 0 },
480
- right: { x: 0.5, y: 0 },
481
- top: { x: 0, y: -0.5 },
482
- bottom: { x: 0, y: 0.5 }
483
- };
484
- /** 整图四角(tlS 等)在窗本地系的坐标(应用 imageCorner* 同式) */
485
- export const fullImageCornerLocal = (s, corner) => {
486
- const xLeft = -s.width / 2 - s.cropX;
487
- const yTop = -s.height / 2 - s.cropY;
488
- const xRight = s.naturalWidth - s.width / 2 - s.cropX;
489
- const yBottom = s.naturalHeight - s.height / 2 - s.cropY;
490
- if (corner === 'tl')
491
- return { x: xLeft, y: yTop };
492
- if (corner === 'tr')
493
- return { x: xRight, y: yTop };
494
- if (corner === 'bl')
495
- return { x: xLeft, y: yBottom };
496
- return { x: xRight, y: yBottom };
497
- };