@yft-design/engine 0.0.17 → 0.0.19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -11
- package/dist/EngineCanvas.d.ts +0 -255
- package/dist/core/color.d.ts +0 -11
- package/dist/core/distanceField.d.ts +0 -13
- package/dist/core/events.d.ts +0 -25
- package/dist/core/gradient.d.ts +0 -47
- package/dist/core/homography.d.ts +0 -20
- package/dist/core/imageFilters.d.ts +0 -31
- package/dist/core/mat2d.d.ts +0 -62
- package/dist/core/pathData.d.ts +0 -36
- package/dist/core/pattern.d.ts +0 -14
- package/dist/core/point.d.ts +0 -14
- package/dist/core/psdEffects.d.ts +0 -48
- package/dist/core/roundedRect.d.ts +0 -48
- package/dist/core/shadow.d.ts +0 -23
- package/dist/core/snap.d.ts +0 -103
- package/dist/core/stroke.d.ts +0 -13
- package/dist/core/triangulate.d.ts +0 -31
- package/dist/core/warpMesh.d.ts +0 -38
- package/dist/debug/canvasInspection.d.ts +0 -20
- package/dist/debug/pixelDiff.d.ts +0 -7
- package/dist/debug/pixelDiff.js +1 -64
- package/dist/debug/seed.d.ts +0 -426
- package/dist/debug/seed.js +28 -3806
- package/dist/decoders/webp2sprite.d.ts +0 -16
- package/dist/engineFlag.d.ts +0 -76
- package/dist/export/SceneExporter.d.ts +0 -58
- package/dist/export/glExport.d.ts +0 -41
- package/dist/export/svgExport.d.ts +0 -181
- package/dist/index.d.ts +1 -14
- package/dist/index.js +1060 -64
- package/dist/interact/animationPlayback.d.ts +0 -62
- package/dist/interact/canvasInteractions.d.ts +1 -38
- package/dist/interact/cropSession.d.ts +0 -68
- package/dist/interact/dblClick.d.ts +0 -32
- package/dist/interact/expandSession.d.ts +0 -46
- package/dist/interact/hotkeyActions.d.ts +0 -12
- package/dist/interact/pageTransfer.d.ts +0 -2
- package/dist/interact/pathSession.d.ts +0 -42
- package/dist/interact/pointer.d.ts +0 -87
- package/dist/interact/pointerTablePuzzle.d.ts +0 -60
- package/dist/interact/pointerTransform.d.ts +0 -48
- package/dist/interact/pointerTypes.d.ts +6 -148
- package/dist/interact/snapGuide.d.ts +0 -68
- package/dist/interact/tableCellEditing.d.ts +0 -34
- package/dist/interact/tableInteraction.d.ts +0 -31
- package/dist/interact/textEditing.d.ts +0 -44
- package/dist/interact/warpFacade.d.ts +0 -5
- package/dist/interact/warpSession.d.ts +0 -55
- package/dist/interact/wheelScroll.d.ts +0 -42
- package/dist/model/alphaHit.d.ts +0 -51
- package/dist/model/animation.d.ts +0 -99
- package/dist/model/arcLayout.d.ts +0 -33
- package/dist/model/arcTextTransform.d.ts +0 -4
- package/dist/model/compatEvents.d.ts +0 -72
- package/dist/model/compatObject.d.ts +0 -360
- package/dist/model/cropEdit.d.ts +0 -60
- package/dist/model/document.d.ts +0 -167
- package/dist/model/elementTypes.d.ts +0 -47
- package/dist/model/expandEdit.d.ts +0 -36
- package/dist/model/fabricPrimitives.d.ts +0 -24
- package/dist/model/filler.d.ts +0 -12
- package/dist/model/groupAssemble.d.ts +0 -5
- package/dist/model/groupChildMove.d.ts +0 -37
- package/dist/model/groupResize.d.ts +0 -42
- package/dist/model/handles.d.ts +0 -24
- package/dist/model/imageMaskBake.d.ts +0 -50
- package/dist/model/lineConstruct.d.ts +0 -8
- package/dist/model/maskCropEdit.d.ts +0 -34
- package/dist/model/pathBackground.d.ts +0 -33
- package/dist/model/pathConstruct.d.ts +0 -24
- package/dist/model/pathEdit.d.ts +0 -55
- package/dist/model/puzzleEdit.d.ts +0 -66
- package/dist/model/puzzleLayout.d.ts +0 -31
- package/dist/model/scene.d.ts +0 -603
- package/dist/model/schema.d.ts +0 -48
- package/dist/model/shapePath.d.ts +0 -5
- package/dist/model/smartObjectBake.d.ts +0 -6
- package/dist/model/tableEdit.d.ts +0 -90
- package/dist/model/tableFacade.d.ts +0 -5
- package/dist/model/tableLayout.d.ts +0 -40
- package/dist/model/textAlign.d.ts +0 -22
- package/dist/model/textLayout.d.ts +0 -213
- package/dist/render/GLBlend.d.ts +0 -24
- package/dist/render/GLContext.d.ts +0 -11
- package/dist/render/GLIsolate.d.ts +0 -25
- package/dist/render/GLTextureCache.d.ts +0 -72
- package/dist/render/GlyphAtlas.d.ts +0 -98
- package/dist/render/MeshBatch.d.ts +0 -71
- package/dist/render/QuadBatch.d.ts +0 -87
- package/dist/render/SceneRenderer.d.ts +0 -137
- package/dist/render/SourceManager.d.ts +0 -82
- package/dist/render/TextRenderer.d.ts +0 -120
- package/dist/render/arcText.d.ts +0 -28
- package/dist/render/bakeGate.d.ts +0 -35
- package/dist/render/batchOrder.d.ts +0 -60
- package/dist/render/blendMode.d.ts +0 -27
- package/dist/render/clipMaskPainter.d.ts +0 -42
- package/dist/render/fontInvalidation.d.ts +0 -18
- package/dist/render/fontInvalidationController.d.ts +0 -52
- package/dist/render/frameOverlay.d.ts +0 -32
- package/dist/render/framePipeline.d.ts +0 -27
- package/dist/render/gpuFilterPasses.d.ts +0 -15
- package/dist/render/gpuFx.d.ts +0 -82
- package/dist/render/gpuImageFilters.d.ts +0 -41
- package/dist/render/gpuShadow.d.ts +0 -38
- package/dist/render/gradientRamp.d.ts +0 -14
- package/dist/render/imageEffects.d.ts +0 -99
- package/dist/render/lineDecorationSdf.d.ts +0 -32
- package/dist/render/maskRender.d.ts +0 -60
- package/dist/render/multiPage.d.ts +0 -91
- package/dist/render/progressiveLoad.d.ts +0 -27
- package/dist/render/psdEffectPainter.d.ts +0 -25
- package/dist/render/psdWarpText.d.ts +0 -19
- package/dist/render/puzzleClamp.d.ts +0 -15
- package/dist/render/renderEpoch.d.ts +0 -21
- package/dist/render/retainedFrame.d.ts +0 -36
- package/dist/render/ruler.d.ts +0 -36
- package/dist/render/screenClip.d.ts +0 -31
- package/dist/render/scrollText.d.ts +0 -46
- package/dist/render/segmentTable.d.ts +0 -30
- package/dist/render/selectionOverlay.d.ts +0 -203
- package/dist/render/settleScheduler.d.ts +0 -24
- package/dist/render/shaders.d.ts +4 -24
- package/dist/render/shadowBake.d.ts +0 -28
- package/dist/render/shadowPainter.d.ts +0 -8
- package/dist/render/sharedGpuPainters.d.ts +0 -13
- package/dist/render/sourceHydration.d.ts +0 -8
- package/dist/render/strokeBake.d.ts +0 -59
- package/dist/render/strokeMiterOutline.d.ts +0 -29
- package/dist/render/strokePainter.d.ts +0 -31
- package/dist/render/strokeSdf.d.ts +0 -52
- package/dist/render/svgRaster.d.ts +0 -34
- package/dist/render/tableOverlay.d.ts +0 -35
- package/dist/render/textHighlight.d.ts +0 -67
- package/dist/render/textureUpload.d.ts +0 -13
- package/dist/render/verticalText.d.ts +0 -21
- package/dist/render/warpText.d.ts +0 -48
- package/dist/render/workspaceBackdrop.d.ts +0 -22
- package/dist/render/workspaceChecker.d.ts +0 -34
- package/dist/render/workspaceGlow.d.ts +0 -38
- package/package.json +4 -3
- package/dist/EngineCanvas.js +0 -1202
- package/dist/core/canvasPerf.js +0 -170
- package/dist/core/color.js +0 -107
- package/dist/core/distanceField.js +0 -92
- package/dist/core/events.js +0 -80
- package/dist/core/gradient.js +0 -175
- package/dist/core/homography.js +0 -123
- package/dist/core/imageFilters.js +0 -330
- package/dist/core/mat2d.js +0 -241
- package/dist/core/pathData.js +0 -926
- package/dist/core/pattern.js +0 -40
- package/dist/core/point.js +0 -119
- package/dist/core/psdEffects.js +0 -158
- package/dist/core/roundedRect.js +0 -164
- package/dist/core/shadow.js +0 -47
- package/dist/core/snap.js +0 -793
- package/dist/core/stroke.js +0 -45
- package/dist/core/triangulate.js +0 -194
- package/dist/core/warpMesh.js +0 -469
- package/dist/debug/canvasInspection.js +0 -113
- package/dist/decoders/gif2sprite.js +0 -84
- package/dist/decoders/webp2sprite.js +0 -133
- package/dist/engineFlag.js +0 -104
- package/dist/export/SceneExporter.js +0 -286
- package/dist/export/glExport.js +0 -79
- package/dist/export/svgExport.js +0 -1803
- package/dist/interact/animationPlayback.js +0 -358
- package/dist/interact/canvasInteractions.js +0 -174
- package/dist/interact/cropSession.js +0 -527
- package/dist/interact/dblClick.js +0 -120
- package/dist/interact/expandSession.js +0 -282
- package/dist/interact/hotkeyActions.js +0 -42
- package/dist/interact/pageTransfer.js +0 -56
- package/dist/interact/pathSession.js +0 -480
- package/dist/interact/pointer.js +0 -1692
- package/dist/interact/pointerTablePuzzle.js +0 -358
- package/dist/interact/pointerTransform.js +0 -441
- package/dist/interact/pointerTypes.js +0 -96
- package/dist/interact/snapGuide.js +0 -377
- package/dist/interact/tableCellEditing.js +0 -207
- package/dist/interact/tableInteraction.js +0 -219
- package/dist/interact/textEditing.js +0 -423
- package/dist/interact/warpFacade.js +0 -51
- package/dist/interact/warpSession.js +0 -583
- package/dist/interact/wheelScroll.js +0 -100
- package/dist/model/alphaHit.js +0 -267
- package/dist/model/animation.js +0 -510
- package/dist/model/arcLayout.js +0 -308
- package/dist/model/arcTextTransform.js +0 -87
- package/dist/model/compatEvents.js +0 -96
- package/dist/model/compatObject.js +0 -1583
- package/dist/model/cropEdit.js +0 -497
- package/dist/model/document.js +0 -590
- package/dist/model/elementTypes.js +0 -119
- package/dist/model/expandEdit.js +0 -161
- package/dist/model/fabricPrimitives.js +0 -9
- package/dist/model/filler.js +0 -1
- package/dist/model/groupAssemble.js +0 -98
- package/dist/model/groupChildMove.js +0 -145
- package/dist/model/groupResize.js +0 -109
- package/dist/model/handles.js +0 -29
- package/dist/model/imageMaskBake.js +0 -136
- package/dist/model/lineConstruct.js +0 -79
- package/dist/model/maskCropEdit.js +0 -90
- package/dist/model/pathBackground.js +0 -196
- package/dist/model/pathConstruct.js +0 -55
- package/dist/model/pathEdit.js +0 -378
- package/dist/model/puzzleEdit.js +0 -742
- package/dist/model/puzzleLayout.js +0 -143
- package/dist/model/scene.js +0 -2930
- package/dist/model/schema.js +0 -13
- package/dist/model/shapePath.js +0 -137
- package/dist/model/smartObjectBake.js +0 -295
- package/dist/model/tableEdit.js +0 -751
- package/dist/model/tableFacade.js +0 -808
- package/dist/model/tableLayout.js +0 -194
- package/dist/model/textAlign.js +0 -36
- package/dist/model/textLayout.js +0 -842
- package/dist/render/GLBlend.js +0 -270
- package/dist/render/GLContext.js +0 -48
- package/dist/render/GLIsolate.js +0 -188
- package/dist/render/GLTextureCache.js +0 -224
- package/dist/render/GlyphAtlas.js +0 -412
- package/dist/render/MeshBatch.js +0 -416
- package/dist/render/QuadBatch.js +0 -561
- package/dist/render/SceneRenderer.js +0 -753
- package/dist/render/SourceManager.js +0 -523
- package/dist/render/TextRenderer.js +0 -854
- package/dist/render/arcText.js +0 -187
- package/dist/render/bakeGate.js +0 -32
- package/dist/render/batchOrder.js +0 -168
- package/dist/render/blendMode.js +0 -142
- package/dist/render/clipMaskPainter.js +0 -244
- package/dist/render/fontInvalidation.js +0 -77
- package/dist/render/fontInvalidationController.js +0 -119
- package/dist/render/frameOverlay.js +0 -124
- package/dist/render/framePipeline.js +0 -96
- package/dist/render/gpuFilterPasses.js +0 -883
- package/dist/render/gpuFx.js +0 -673
- package/dist/render/gpuImageFilters.js +0 -295
- package/dist/render/gpuShadow.js +0 -327
- package/dist/render/gradientRamp.js +0 -74
- package/dist/render/imageEffects.js +0 -415
- package/dist/render/lineDecorationSdf.js +0 -189
- package/dist/render/maskRender.js +0 -217
- package/dist/render/multiPage.js +0 -420
- package/dist/render/progressiveLoad.js +0 -86
- package/dist/render/psdEffectPainter.js +0 -333
- package/dist/render/psdWarpText.js +0 -212
- package/dist/render/puzzleClamp.js +0 -30
- package/dist/render/renderEpoch.js +0 -35
- package/dist/render/renderViewport.js +0 -18
- package/dist/render/retainedFrame.js +0 -192
- package/dist/render/ruler.js +0 -287
- package/dist/render/screenClip.js +0 -67
- package/dist/render/scrollText.js +0 -266
- package/dist/render/segmentTable.js +0 -117
- package/dist/render/selectionOverlay.js +0 -1008
- package/dist/render/settleScheduler.js +0 -51
- package/dist/render/shaders.js +0 -450
- package/dist/render/shadowBake.js +0 -203
- package/dist/render/shadowPainter.js +0 -93
- package/dist/render/sharedGpuPainters.js +0 -42
- package/dist/render/sourceHydration.js +0 -48
- package/dist/render/strokeBake.js +0 -516
- package/dist/render/strokeMiterOutline.js +0 -224
- package/dist/render/strokePainter.js +0 -207
- package/dist/render/strokeSdf.js +0 -262
- package/dist/render/svgRaster.js +0 -71
- package/dist/render/tableOverlay.js +0 -233
- package/dist/render/textHighlight.js +0 -380
- package/dist/render/textureUpload.js +0 -26
- package/dist/render/verticalText.js +0 -63
- package/dist/render/warpText.js +0 -384
- package/dist/render/workspaceBackdrop.js +0 -60
- package/dist/render/workspaceChecker.js +0 -170
- package/dist/render/workspaceGlow.js +0 -198
|
@@ -1,1583 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* compat 对象面基座(批次 289——自主仓 app/engineCompatObject.ts verbatim 迁入,
|
|
3
|
-
* 立项勘定=docs/2026-10-07_compatobject-sink-plan.md)。
|
|
4
|
-
*
|
|
5
|
-
* CompatObject 是 SceneNode 的 fabric 习惯包装:具名方法覆盖高频 API,其余属性
|
|
6
|
-
* 经 Proxy 直通——读走 node.raw,写走 setNodeProps(引擎内建缓存失效+重绘请求)。
|
|
7
|
-
* 画布侧操作经构造器 ctx(CompatObjectContext 18 方法委托面——控制反转在位)。
|
|
8
|
-
*
|
|
9
|
-
* **四缝钩化(app 深链不进引擎)**:stylesToObjectForm/stylesToArrayForm(批次 34
|
|
10
|
-
* 双序列化约定边界——依赖 app TextCommon 字素切分口径)、serializationProps
|
|
11
|
-
* (app 配置 propertiesToInclude)、toPathEffectLayers(textEffectLayers 深链)——
|
|
12
|
-
* 引擎侧给缺省(passthrough/空层),宿主侧安装编解码(主仓 engineCompatObject
|
|
13
|
-
* 安装器,装载期 prototype 覆写——attachTableFacade 同款 mixin 先例)。
|
|
14
|
-
*
|
|
15
|
-
* 已知口径差(源批登记):instanceof 判别不可用(按 raw.type);
|
|
16
|
-
* toDataURL/toCanvasElement/clone 未承接;dirty 写入被吞
|
|
17
|
-
* (引擎缓存失效内建)。group/topGroup 组链读位已收口(派生访问器)。
|
|
18
|
-
*/
|
|
19
|
-
import { CompatPoint } from '../core/point';
|
|
20
|
-
import { AnimatedNode, GroupNode, IMAGE_LIKE_TYPES, MASK_TYPES, PathNode, PuzzleNode, TableNode, TextNode } from './scene';
|
|
21
|
-
import { ElementTypes, typeKeyOf } from './elementTypes';
|
|
22
|
-
import { anchorStyleAt } from './pathEdit';
|
|
23
|
-
import { parsePathData } from '../core/pathData';
|
|
24
|
-
import { pathEditKindOf } from '../interact/pathSession';
|
|
25
|
-
import { arcTextKind } from './arcLayout';
|
|
26
|
-
import { objectOriginFromCenter } from '../core/mat2d';
|
|
27
|
-
import { isGroupWidthHandleNode } from './groupResize';
|
|
28
|
-
import { deriveArcCharTransformations } from './arcTextTransform';
|
|
29
|
-
import { buildEngineShapePath } from './shapePath';
|
|
30
|
-
import { attachTableFacade } from './tableFacade';
|
|
31
|
-
/** 变形文字族(archtext/waisttext/flagtext):setWarpStrength/clearCache 门
|
|
32
|
-
* (const 对象数组 includes 对 string 协变拒绝——模块级 string 集合单源) */
|
|
33
|
-
const WARP_TEXT_TYPES = new Set([ElementTypes.ARCHTEXT, ElementTypes.WAISTTEXT, ElementTypes.FLAGTEXT]);
|
|
34
|
-
/** 文本排版三件的快照形态校验(svgExport.parseTextLayout 同口径——string[] 行 +
|
|
35
|
-
* 逐行 charBox 数组 + finite 行高;不引引擎 export 模块防依赖倒挂) */
|
|
36
|
-
const isValidTextLayoutSnapshot = (o) => {
|
|
37
|
-
const tl = o.textLines;
|
|
38
|
-
const cb = o.charBounds;
|
|
39
|
-
const lh = o.lineHeights;
|
|
40
|
-
if (!Array.isArray(tl) || !Array.isArray(cb) || !Array.isArray(lh))
|
|
41
|
-
return false;
|
|
42
|
-
if (tl.length === 0 || cb.length !== tl.length || lh.length !== tl.length)
|
|
43
|
-
return false;
|
|
44
|
-
for (let i = 0; i < tl.length; i++) {
|
|
45
|
-
if (typeof tl[i] !== 'string' || !Array.isArray(cb[i]) || cb[i].length === 0)
|
|
46
|
-
return false;
|
|
47
|
-
if (typeof lh[i] !== 'number' || !Number.isFinite(lh[i]))
|
|
48
|
-
return false;
|
|
49
|
-
}
|
|
50
|
-
return true;
|
|
51
|
-
};
|
|
52
|
-
export class CompatObject {
|
|
53
|
-
node;
|
|
54
|
-
ctx;
|
|
55
|
-
constructor(node, ctx) {
|
|
56
|
-
this.node = node;
|
|
57
|
-
this.ctx = ctx;
|
|
58
|
-
}
|
|
59
|
-
/** fabric set:单键或对象批量;返回 this 供链式 */
|
|
60
|
-
set(key, value) {
|
|
61
|
-
const props = typeof key === 'string' ? { [key]: value } : key;
|
|
62
|
-
// 会话键路由(批次 54):set({__isCropping/__isExpand}) 是右栏裁切/AI扩图
|
|
63
|
-
// 按钮与退出链的口——走 accessor 路由引擎会话而非落 raw(引擎不消费,
|
|
64
|
-
// 落盘只留脏值)。路由先于其余键落盘:beforeState 快照必须捕获写入前状态
|
|
65
|
-
// (fabric 对象键序同语义:__isCropping setter 先于 cropX 等直写执行)
|
|
66
|
-
if ('cropAspectRatio' in props) {
|
|
67
|
-
// 比例约束先落盘——__isCropping 路由进会话时读 raw 应用(引擎
|
|
68
|
-
// setCropAspectRatio 居中重摆窗与面板数学一致,幂等)
|
|
69
|
-
const early = { cropAspectRatio: props.cropAspectRatio };
|
|
70
|
-
delete props.cropAspectRatio;
|
|
71
|
-
this.ctx.setNodeProps(this.node, early);
|
|
72
|
-
}
|
|
73
|
-
if ('__isCropping' in props) {
|
|
74
|
-
const sessionValue = !!props.__isCropping;
|
|
75
|
-
delete props.__isCropping;
|
|
76
|
-
this.clearSessionFlagDirty('__isCropping');
|
|
77
|
-
this.__isCropping = sessionValue;
|
|
78
|
-
}
|
|
79
|
-
if ('__isExpand' in props) {
|
|
80
|
-
const sessionValue = !!props.__isExpand;
|
|
81
|
-
delete props.__isExpand;
|
|
82
|
-
this.clearSessionFlagDirty('__isExpand');
|
|
83
|
-
this.__isExpand = sessionValue;
|
|
84
|
-
}
|
|
85
|
-
// 组合改宽再分配(批次 104,用户报「组合修改宽度的时候,如果里面有文本
|
|
86
|
-
// 需要过滤下只修改文本的宽度,而不是修改缩放」):组的 width 写入路由引擎
|
|
87
|
-
// 再分配——组宽直写 + 组内固定盒文本 width 回流 + 其余子 scaleX,组自身
|
|
88
|
-
// scale 不落。此前 raw 直写视觉无效(右栏 W 只改选框不改内容)。历史回放
|
|
89
|
-
// 的全量快照写回经 children 按 id 回写终态幂等覆盖(engineModify),宽度
|
|
90
|
-
// 差量回退乘法自洽(k 逆乘恰还原)。
|
|
91
|
-
if (typeof props.width === 'number' && isGroupWidthHandleNode(this.node)) {
|
|
92
|
-
const width = props.width;
|
|
93
|
-
delete props.width;
|
|
94
|
-
if (this.ctx.setGroupWidth) {
|
|
95
|
-
this.ctx.setGroupWidth(this.node, width);
|
|
96
|
-
}
|
|
97
|
-
else {
|
|
98
|
-
this.ctx.setNodeProps(this.node, { width });
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
this.bumpTextboxWidthToLayoutBox(props);
|
|
102
|
-
this.bridgeImageSizeProps(props);
|
|
103
|
-
// 批次 129:Mask 宽高直写联动 clipImage cover 重缩放——右栏 W/H 走 scaleX
|
|
104
|
-
// 等比(useHandleActive MASK 分支)天然保持;直写 raw.width/height 的面
|
|
105
|
-
//(程序化/会话窗)此前 cover 破坏(maskRender 烘焙签名含 width 重烘但声明
|
|
106
|
-
// scaleX/Y 不重算,填充图不铺满)。userFactor 保持(ElementMask 换形状/
|
|
107
|
-
// 拼图 resizeByContainer 同语义):next = cover(new) × (prev / cover(old)),
|
|
108
|
-
// 幂等。同批显式写 clipImage 的面自带语义跳过(防双重折算)。
|
|
109
|
-
let propsToWrite = props;
|
|
110
|
-
if ((typeof props.width === 'number' || typeof props.height === 'number') && !('clipImage' in props) && MASK_TYPES.has(typeKeyOf(this.node.raw))) {
|
|
111
|
-
const clip = clipImageRawOf(this.node);
|
|
112
|
-
const raw = this.node.raw;
|
|
113
|
-
const prevW = Number(raw.width) || 0;
|
|
114
|
-
const prevH = Number(raw.height) || 0;
|
|
115
|
-
const nextW = typeof props.width === 'number' ? props.width : prevW;
|
|
116
|
-
const nextH = typeof props.height === 'number' ? props.height : prevH;
|
|
117
|
-
const clipEl = this.node.clipImageEl;
|
|
118
|
-
// 原图尺寸口径同 getElementOriginalSize:装载元素 natural 优先、声明宽兜底
|
|
119
|
-
const cw = clipEl?.naturalWidth || Number(clip?.width) || 0;
|
|
120
|
-
const ch = clipEl?.naturalHeight || Number(clip?.height) || 0;
|
|
121
|
-
if (clip && prevW > 0 && prevH > 0 && nextW > 0 && nextH > 0 && cw > 0 && ch > 0) {
|
|
122
|
-
const cover = (w, h) => Math.max(w / cw, h / ch);
|
|
123
|
-
const prev = Number(clip.scaleX) || 1;
|
|
124
|
-
const next = cover(nextW, nextH) * (prev / cover(prevW, prevH));
|
|
125
|
-
propsToWrite = { ...props, clipImage: { ...clip, scaleX: next, scaleY: next } };
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
if (Object.keys(propsToWrite).length > 0)
|
|
129
|
-
this.ctx.setNodeProps(this.node, propsToWrite);
|
|
130
|
-
return this;
|
|
131
|
-
}
|
|
132
|
-
/** Textbox 宽度写入的 dynamicMinWidth 抬回(fabric Textbox.set 语义承接):
|
|
133
|
-
* fabric 的 width ∈ textLayoutProperties → set 触发 initDimensions →
|
|
134
|
-
* `dynamicMinWidth > width && _set('width', dynamicMinWidth)`——不可断词
|
|
135
|
-
* (splitByGrapheme=false 时整句中文即一词)宽于目标盒时实例 width 被
|
|
136
|
-
* 抬回词宽,数据/显示/视觉恒一致。引擎 raw 直写会留下低于词宽的假值
|
|
137
|
-
* (dims/排版/选中框仍按词宽撑盒)→ 右栏宽度框(watchEffect 读
|
|
138
|
-
* getWidth=dims 口径)与数据(raw/store 序列化)分裂,表现为「宽度输入/
|
|
139
|
-
* 拖动后又被弹回」+ 假数据入库。写后按排版盒宽(node.dims.x 懒重排,
|
|
140
|
-
* 纯计算)抬回:effective > 目标值才补写(幂等,正常路径零额外排版)。
|
|
141
|
-
* 非 textbox 型文本不传盒宽(textLayout 的 boxWidth 判定同口径),width
|
|
142
|
-
* 不参与排版,无抬回语义;弧形族 dims 是 arc bbox,另行排除 */
|
|
143
|
-
bumpTextboxWidthToLayoutBox(props) {
|
|
144
|
-
if (typeof props.width !== 'number' || !(this.node instanceof TextNode))
|
|
145
|
-
return;
|
|
146
|
-
if (props.width < 0)
|
|
147
|
-
return;
|
|
148
|
-
const rawType = typeKeyOf(this.node.raw);
|
|
149
|
-
if (rawType !== ElementTypes.TEXTBOX)
|
|
150
|
-
return;
|
|
151
|
-
if (arcTextKind(this.node.raw))
|
|
152
|
-
return;
|
|
153
|
-
const target = props.width;
|
|
154
|
-
delete props.width;
|
|
155
|
-
this.ctx.setNodeProps(this.node, { width: target });
|
|
156
|
-
const effective = this.node.dims.x;
|
|
157
|
-
if (Number.isFinite(effective) && effective > target + 0.01) {
|
|
158
|
-
this.ctx.setNodeProps(this.node, { width: effective });
|
|
159
|
-
}
|
|
160
|
-
}
|
|
161
|
-
/** 修前脏值清理:会话标志曾被 setProps 直写 raw(引擎不消费的静默假象读位),
|
|
162
|
-
* 路由会话进/退时顺带抹除,防序列化携带与旧读位误判 */
|
|
163
|
-
clearSessionFlagDirty(flag) {
|
|
164
|
-
if (this.node.raw[flag] !== undefined) {
|
|
165
|
-
this.ctx.setNodeProps(this.node, { [flag]: undefined });
|
|
166
|
-
}
|
|
167
|
-
}
|
|
168
|
-
get(key) {
|
|
169
|
-
return this.node.raw[key];
|
|
170
|
-
}
|
|
171
|
-
/** fabric setCoords:刷新坐标缓存。引擎矩阵每帧现算、无缓存可刷——恒等空操作,
|
|
172
|
-
* 保留签名让面板的三连调用原样通过 */
|
|
173
|
-
setCoords() { }
|
|
174
|
-
getCenterPoint() {
|
|
175
|
-
return { ...this.node.center };
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* fabric getRelativeCenterPoint:origin 换算的对象中心(getObjectsBoundingBox/
|
|
179
|
-
* fabricAnimater 消费)。顶层对象等价场景中心(引擎 center 同口径——不含 vpt)。
|
|
180
|
-
* 批次 187:返回位换 CompatPoint(fabric Point 值引用清零;类型层仍声明
|
|
181
|
-
* fabric Point——消费面 subtract/add/scalarDivide 链 lite 同数学)。
|
|
182
|
-
*/
|
|
183
|
-
getRelativeCenterPoint() {
|
|
184
|
-
return new CompatPoint(this.node.center.x, this.node.center.y);
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* fabric translateToOriginPoint(TEXT_TO_PATH 回放锚点复位消费,P5-1 押后项
|
|
188
|
-
* 补位):中心点 → 给定 origin 的 position 点,对象角度参与(绕 center 旋转)。
|
|
189
|
-
* 数学同 fabric FabricObject.translateToOriginPoint:offset = resolveOrigin(to) −
|
|
190
|
-
* resolveOrigin(center)(±0.5)× _getTransformedDimensions,angle≠0 再旋转。
|
|
191
|
-
*/
|
|
192
|
-
translateToOriginPoint(center, originX = 'center', originY = 'center') {
|
|
193
|
-
const resolve = (value) => (value === 'left' || value === 'top' ? -0.5 : value === 'right' || value === 'bottom' ? 0.5 : 0);
|
|
194
|
-
const offsetX = resolve(originX);
|
|
195
|
-
const offsetY = resolve(originY);
|
|
196
|
-
const dim = offsetX || offsetY ? this._getTransformedDimensions() : new CompatPoint(0, 0);
|
|
197
|
-
let p = new CompatPoint(center.x + offsetX * dim.x, center.y + offsetY * dim.y);
|
|
198
|
-
const angle = this.node.raw.angle;
|
|
199
|
-
if (typeof angle === 'number' && angle)
|
|
200
|
-
p = p.rotate((angle * Math.PI) / 180, center);
|
|
201
|
-
return p;
|
|
202
|
-
}
|
|
203
|
-
/**
|
|
204
|
-
* fabric toPath mixin 的引擎承接:右栏转曲 / 布尔运算族按
|
|
205
|
-
* `object.toPath?.()` duck 消费。文本族走 ctx 字形桥(opentype 轮廓,
|
|
206
|
-
* 盒中心系——与 mixin 从 charPaths 拼串同口径,批次 78);形状族(批次 181
|
|
207
|
-
* 多选布尔运算)走 buildEngineShapePath 的 raw 分档几何——path/rect(圆角)/
|
|
208
|
-
* circle/ellipse/triangle/polygon/polyline/line + 非形状族可视尺寸矩形兜底;
|
|
209
|
-
* 文本字形缺失/空几何返回 undefined 由调用方过滤。
|
|
210
|
-
*/
|
|
211
|
-
toPath() {
|
|
212
|
-
const glyph = this.ctx.getTextGlyphPath?.(this.node);
|
|
213
|
-
if (glyph)
|
|
214
|
-
return glyph;
|
|
215
|
-
return buildEngineShapePath(this.node);
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
* 转曲装饰(批次 78 一补):fabric Textbox.toPathDecorations 的引擎
|
|
219
|
-
* 承接(ElementText.createDecorationPathElements 的 duck 消费面)——划重点
|
|
220
|
-
* 绘制计划与 pathBackground 声明盒拉伸烘焙为独立 path 层,本地中心系与
|
|
221
|
-
* 主路径同坐标(background 垫底、highlight 其上,层序同 fabric)。
|
|
222
|
-
*/
|
|
223
|
-
toPathDecorations() {
|
|
224
|
-
return this.ctx.getTextDecorations?.(this.node) ?? [];
|
|
225
|
-
}
|
|
226
|
-
/**
|
|
227
|
-
* fabric Textbox.toPathEffectLayers 的引擎承接(批次 197;此前 compat 面缺席=
|
|
228
|
-
* 面板 duck 调用 `toPathEffectLayers?.(path) || []` 恒空——引擎模式转曲丢
|
|
229
|
-
* 效果描边/叠加填充层的根因)。raw.effects / raw.fill 直供纯数据函数
|
|
230
|
-
* buildTextEffectLayers(与 fabric 原型方法同一实现,两栈同口径;对弧形/
|
|
231
|
-
* 圆形文本同样生效——fabric 原型方法无类型门)。层的 fill/stroke 可能是
|
|
232
|
-
* fabric Filler 实例(效果描边渐变/图案),引擎盘只认序列化声明——经
|
|
233
|
-
* toObject() 转换(fabric Gradient.toObject 即引擎 parseGradientDecl 的
|
|
234
|
-
* 消费面);fill 描述为声明对象(非实例形态),出向类型放宽 unknown。
|
|
235
|
-
*/
|
|
236
|
-
toPathEffectLayers(_path) {
|
|
237
|
-
// 四缝之一:textEffectLayers 为 app 深链——宿主侧安装器覆写(缺省空层,duck 消费面 || [] 同语义)
|
|
238
|
-
return [];
|
|
239
|
-
}
|
|
240
|
-
/**
|
|
241
|
-
* fabric _getTransformedDimensions:原始尺寸 × 缩放(不含 stroke——引擎 dims
|
|
242
|
-
* 同口径)。返回 Point 供 scalarDivide 链(getObjectsBoundingBox)——批次 187
|
|
243
|
-
* 换 CompatPoint(同数学)。
|
|
244
|
-
*/
|
|
245
|
-
_getTransformedDimensions() {
|
|
246
|
-
const raw = this.node.raw;
|
|
247
|
-
return new CompatPoint(this.node.dims.x * (raw.scaleX ?? 1), this.node.dims.y * (raw.scaleY ?? 1));
|
|
248
|
-
}
|
|
249
|
-
/** fabric getBoundingRect(absolute 口径):场景空间 AABB */
|
|
250
|
-
getBoundingRect() {
|
|
251
|
-
const b = this.node.bounds;
|
|
252
|
-
return { left: b.left, top: b.top, width: b.right - b.left, height: b.bottom - b.top };
|
|
253
|
-
}
|
|
254
|
-
get aCoords() {
|
|
255
|
-
return this.node.aCoords;
|
|
256
|
-
}
|
|
257
|
-
/** fabric getCoords:四角坐标(tl/tr/br/bl 顺序) */
|
|
258
|
-
getCoords() {
|
|
259
|
-
const c = this.node.aCoords;
|
|
260
|
-
return [c.tl, c.tr, c.br, c.bl];
|
|
261
|
-
}
|
|
262
|
-
/**
|
|
263
|
-
* fabric calcOCoords 等价读位:oCoords 屏幕系四角(aCoords × viewportTransform)。
|
|
264
|
-
* 应用消费面 setActivePoint(Toolbar 浮动定位,取全键 min)——控制点扩展键
|
|
265
|
-
* (mtr/corner/touchCorner/cropCornerTL)不带,包围盒取四角近似(登记)。
|
|
266
|
-
*/
|
|
267
|
-
calcOCoords() {
|
|
268
|
-
const m = this.ctx.getViewportTransform?.() ?? [1, 0, 0, 1, 0, 0];
|
|
269
|
-
const apply = (p) => ({ x: m[0] * p.x + m[2] * p.y + m[4], y: m[1] * p.x + m[3] * p.y + m[5] });
|
|
270
|
-
const c = this.node.aCoords;
|
|
271
|
-
return { tl: apply(c.tl), tr: apply(c.tr), br: apply(c.br), bl: apply(c.bl) };
|
|
272
|
-
}
|
|
273
|
-
// —— fabric 对象方法族(P5-1 第四片盘点收口,2026-09-22)——
|
|
274
|
-
/** fabric rotate(angle):centeredRotation=true 口径(应用 initConf 显式打开)——
|
|
275
|
-
* 绕自身中心转、left/top 由 origin 反解(引擎 rotateAroundCenter 同源数学) */
|
|
276
|
-
rotate(degrees) {
|
|
277
|
-
const { angle, left, top } = this.node.rotateAroundCenter(degrees);
|
|
278
|
-
return this.set({ angle, left, top });
|
|
279
|
-
}
|
|
280
|
-
/**
|
|
281
|
-
* fabric setPositionByOrigin:把对象摆到「pos 作为 (originX, originY) 锚点」的
|
|
282
|
-
* 位置(ToolStroke/PathStylePanel 的 handleSetCenterPointOrigin 消费——描边
|
|
283
|
-
* 宽度/对齐变化时归一 origin 到 center 并保持视觉位置)。数学与引擎
|
|
284
|
-
* objectOriginFromCenter 同源:请求锚点按中心相对制分数(left=-0.5/
|
|
285
|
-
* center=0/right=+0.5)取含 scale 的有效尺寸偏移,经角度旋转后从 pos 反解
|
|
286
|
-
* 中心,再按自身 origin 反解 left/top。
|
|
287
|
-
*/
|
|
288
|
-
setPositionByOrigin(pos, originX, originY) {
|
|
289
|
-
const raw = this.node.raw;
|
|
290
|
-
const scaleX = typeof raw.scaleX === 'number' ? raw.scaleX : 1;
|
|
291
|
-
const scaleY = typeof raw.scaleY === 'number' ? raw.scaleY : 1;
|
|
292
|
-
const w = this.node.dims.x * scaleX;
|
|
293
|
-
const h = this.node.dims.y * scaleY;
|
|
294
|
-
const fracX = originX === 'center' ? 0 : originX === 'right' ? 0.5 : -0.5;
|
|
295
|
-
const fracY = originY === 'center' ? 0 : originY === 'bottom' ? 0.5 : -0.5;
|
|
296
|
-
const ax = fracX * w;
|
|
297
|
-
const ay = fracY * h;
|
|
298
|
-
const rad = ((typeof raw.angle === 'number' ? raw.angle : 0) * Math.PI) / 180;
|
|
299
|
-
const cos = Math.cos(rad);
|
|
300
|
-
const sin = Math.sin(rad);
|
|
301
|
-
const center = { x: pos.x - (ax * cos - ay * sin), y: pos.y - (ax * sin + ay * cos) };
|
|
302
|
-
const originPoint = objectOriginFromCenter({ ...raw }, center);
|
|
303
|
-
return this.set({ left: originPoint.x, top: originPoint.y });
|
|
304
|
-
}
|
|
305
|
-
/** fabric scale(factor):相对乘当前缩放 */
|
|
306
|
-
scale(factor) {
|
|
307
|
-
const raw = this.node.raw;
|
|
308
|
-
return this.set({ scaleX: (raw.scaleX ?? 1) * factor, scaleY: (raw.scaleY ?? 1) * factor });
|
|
309
|
-
}
|
|
310
|
-
/** fabric getScaledWidth/getScaledHeight:有效尺寸 × 缩放 */
|
|
311
|
-
getScaledWidth() {
|
|
312
|
-
return this.node.dims.x * (this.node.raw.scaleX ?? 1);
|
|
313
|
-
}
|
|
314
|
-
getScaledHeight() {
|
|
315
|
-
return this.node.dims.y * (this.node.raw.scaleY ?? 1);
|
|
316
|
-
}
|
|
317
|
-
/** fabric getObjectScaling:缩放原始读位 */
|
|
318
|
-
getObjectScaling() {
|
|
319
|
-
const raw = this.node.raw;
|
|
320
|
-
return { scaleX: raw.scaleX ?? 1, scaleY: raw.scaleY ?? 1 };
|
|
321
|
-
}
|
|
322
|
-
/**
|
|
323
|
-
* fabric Group.getObjects(templateFontFamily 收集、disableObjectCaching 递归等
|
|
324
|
-
* 消费面):仅组节点暴露——返回子节点包装;非组 undefined(fabric 平面对象无此
|
|
325
|
-
* 方法,font.ts 的 typeof 兜底链据此回落 raw 读取)。
|
|
326
|
-
*/
|
|
327
|
-
get getObjects() {
|
|
328
|
-
if (!(this.node instanceof GroupNode))
|
|
329
|
-
return undefined;
|
|
330
|
-
return () => this.node.children.map((child) => this.ctx.wrapNode(child));
|
|
331
|
-
}
|
|
332
|
-
/** fabric Group._objects 直读位(批次 93 图层面板):check.isCollection 的
|
|
333
|
-
* Array.isArray 判据 + getTreeData 子树递归的直读源——仅组节点暴露(fabric
|
|
334
|
-
* 平面对象无此字段),子节点包装快照(wrapperCache 恒等,indexOf 消费面可靠) */
|
|
335
|
-
get _objects() {
|
|
336
|
-
if (!(this.node instanceof GroupNode))
|
|
337
|
-
return undefined;
|
|
338
|
-
return this.node.children.map((child) => this.ctx.wrapNode(child));
|
|
339
|
-
}
|
|
340
|
-
/** fabric 对象的 toRef 响应桥读位 `object.ref`(批次 93 图层面板):fabric 侧由
|
|
341
|
-
* Collection add/insertAt 装配 toRef 代理,图层树 objectRef(锁图标/LayerName
|
|
342
|
-
* canEdit/LayerText 行内容)全系此读位——compat 包装本身就是可读写门面(Proxy
|
|
343
|
-
* get/set 走 raw/引擎失效链),duck 返回自身;markRaw 消费面经 symbol set 直落
|
|
344
|
-
* target 不进失效链 */
|
|
345
|
-
get ref() {
|
|
346
|
-
return this;
|
|
347
|
-
}
|
|
348
|
-
// —— 图源族(fabric FabricImage 面,批次 33):右栏蒙版/条码/二维码/矢量/滤镜
|
|
349
|
-
// 面板的换图与图源读位。方法存在性=类型判别器(main.ts 背景图/AI 技法/useChat
|
|
350
|
-
// 以 typeof getSrc 判图像族后回落 raw.src),仅图像族暴露——fabric 同款缺席语义 ——
|
|
351
|
-
/** 图像族判定:IMAGE_LIKE_TYPES + Mask(ElementMask 面板蒙版源)+ gif/video
|
|
352
|
-
* (AnimatedNode 图像管线)。小写键口径(typeKeyOf 坍缩,批次 360) */
|
|
353
|
-
get isImageLikeNode() {
|
|
354
|
-
const t = typeKeyOf(this.node.raw);
|
|
355
|
-
return IMAGE_LIKE_TYPES.has(t) || MASK_TYPES.has(t) || t === ElementTypes.GIF || t === ElementTypes.VIDEO;
|
|
356
|
-
}
|
|
357
|
-
/** 应用 FabricImage.getSrc 覆写语义:originalSrc 优先(换图后历史快照 before/after
|
|
358
|
-
* 以 originalSrc 判等回放);无则 src。filtered 位不承接(引擎无滤镜后源缓存) */
|
|
359
|
-
get getSrc() {
|
|
360
|
-
if (!this.isImageLikeNode)
|
|
361
|
-
return undefined;
|
|
362
|
-
return () => {
|
|
363
|
-
const raw = this.node.raw;
|
|
364
|
-
if (typeof raw.originalSrc === 'string' && raw.originalSrc)
|
|
365
|
-
return raw.originalSrc;
|
|
366
|
-
return typeof raw.src === 'string' ? raw.src : '';
|
|
367
|
-
};
|
|
368
|
-
}
|
|
369
|
-
/** fabric FabricImage.getRealSrc 同语义读位(批次 93 图层面板行缩略图):
|
|
370
|
-
* originalSrc || getSrc()——与上面 getSrc duck 同门(引擎无滤镜后源缓存) */
|
|
371
|
-
get getRealSrc() {
|
|
372
|
-
const getSrc = this.getSrc;
|
|
373
|
-
if (!getSrc)
|
|
374
|
-
return undefined;
|
|
375
|
-
return () => getSrc();
|
|
376
|
-
}
|
|
377
|
-
/** 应用 FabricImage.replaceSrc(util/replaceSrc 同语义):换 src + crossOrigin +
|
|
378
|
-
* originalSrc 同步 + 纹理重载。返回 this 供 await 链(调用点均 await) */
|
|
379
|
-
get replaceSrc() {
|
|
380
|
-
if (!this.isImageLikeNode)
|
|
381
|
-
return undefined;
|
|
382
|
-
return async (url) => {
|
|
383
|
-
this.set({ src: url, crossOrigin: 'anonymous', originalSrc: url });
|
|
384
|
-
await this.ctx.reloadNodeImage?.(this.node);
|
|
385
|
-
return this;
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
/** fabric FabricImage.setElement:元素直换(QR/条码重生成位图入口)。引擎 imageEl
|
|
389
|
-
* setter 内建几何缓存失效,纹理按元素懒上传(GLTextureCache.get 缺席重传);
|
|
390
|
-
* 面板随后 set({src}) 落序列化位 */
|
|
391
|
-
get setElement() {
|
|
392
|
-
if (!this.isImageLikeNode)
|
|
393
|
-
return undefined;
|
|
394
|
-
return (element, sizeOptions) => {
|
|
395
|
-
this.node.imageEl = element;
|
|
396
|
-
if (sizeOptions)
|
|
397
|
-
this.set(sizeOptions);
|
|
398
|
-
return this;
|
|
399
|
-
};
|
|
400
|
-
}
|
|
401
|
-
/** fabric getElement:底层位图元素(纹理/预览消费位)。动画族(批次 116)动态源
|
|
402
|
-
* 优先——视频元素/GIF 帧缓冲(视频站点 getElement().play() 与预览 drawImage
|
|
403
|
-
* 消费;此前恒回静态 imageEl,视频创建链 play() 拿 null 即断),静态回退 imageEl */
|
|
404
|
-
get getElement() {
|
|
405
|
-
if (!this.isImageLikeNode)
|
|
406
|
-
return undefined;
|
|
407
|
-
const node = this.node;
|
|
408
|
-
if (node instanceof AnimatedNode) {
|
|
409
|
-
return () => (node.paintSource ?? node.imageEl);
|
|
410
|
-
}
|
|
411
|
-
return () => node.imageEl;
|
|
412
|
-
}
|
|
413
|
-
/** fabric _element:矢量面板预览 drawImage 直读位——非图像族 undefined(fabric 同) */
|
|
414
|
-
get _element() {
|
|
415
|
-
if (!this.isImageLikeNode)
|
|
416
|
-
return undefined;
|
|
417
|
-
return this.node.imageEl;
|
|
418
|
-
}
|
|
419
|
-
/** fabric FabricMask.clipImage:序列化子对象的 fabric 习惯包装(ElementMask 换蒙版
|
|
420
|
-
* 形状/取消蒙版、ImageMatting 抠图链、蒙版历史回放的 .set/.toObject/.setCoords
|
|
421
|
-
* 消费面)。引擎侧 clipImage 非场景节点——Proxy 直通只给 raw 普通对象,面板的
|
|
422
|
-
* clipImage.set 即 TypeError(用户报「设置蒙版 clipImage.set is not a function」)。
|
|
423
|
-
* 非 Mask/坏声明 undefined(fabric 对象无此属性时同款缺席语义) */
|
|
424
|
-
get clipImage() {
|
|
425
|
-
return clipImageRawOf(this.node) ? wrapClipImage(this.node, this.ctx) : undefined;
|
|
426
|
-
}
|
|
427
|
-
/** clipImage 直写承接(fabricGuide 拖图入蒙版格/历史回放的 mask.clipImage = x):
|
|
428
|
-
* fabric 实例先序列化(propertiesToInclude 保 id 等自定义字段,与 store 序列化
|
|
429
|
-
* 同口径),普通对象原样落盘。setter 先于 getter 定义在此,防 getter-only 在
|
|
430
|
-
* 严格模式直写抛错 */
|
|
431
|
-
set clipImage(value) {
|
|
432
|
-
const serialized = value && typeof value === 'object' && typeof value.toObject === 'function'
|
|
433
|
-
? value.toObject(this.serializationProps())
|
|
434
|
-
: value;
|
|
435
|
-
this.ctx.setNodeProps(this.node, { clipImage: serialized });
|
|
436
|
-
}
|
|
437
|
-
// —— 应用原型补丁口径(useCanvas.ts initConf 的 Object.assign(FabricObject.prototype, mixin)
|
|
438
|
-
// ——fabric 6.9 对象本无 getWidth/getHeight,应用侧补丁;compat 对象不继承 fabric 原型,
|
|
439
|
-
// 需同源承接,否则 useHandleActive/ElementPosition 的宽高读位抛 TypeError(批次 20 遗留①)——
|
|
440
|
-
/** 同应用补丁:有效尺寸 − strokeWidth(noFixed 分支在应用实现里是空操作,保留签名) */
|
|
441
|
-
getWidthHeight(_noFixed = false) {
|
|
442
|
-
const dim = this._getTransformedDimensions();
|
|
443
|
-
const strokeWidth = (this.node.raw.strokeWidth ?? 0) || 0;
|
|
444
|
-
return { x: dim.x - strokeWidth, y: dim.y - strokeWidth };
|
|
445
|
-
}
|
|
446
|
-
getWidth() {
|
|
447
|
-
return this.getWidthHeight().x;
|
|
448
|
-
}
|
|
449
|
-
getHeight() {
|
|
450
|
-
return this.getWidthHeight().y;
|
|
451
|
-
}
|
|
452
|
-
// —— 应用 FabricImage 子族原图尺寸读位(批次 32:ImageClip 比例裁剪按钮
|
|
453
|
-
// presetImageClip 直调 getOriginalElementWidth/Height——缺席即 TypeError 被
|
|
454
|
-
// Vue errorHandler 吞成「点了没反应」)——
|
|
455
|
-
/** 位图源自然尺寸单点:imageEl(图片族/蒙版,加载后挂载、同 src 共享)→
|
|
456
|
-
* AnimatedNode.paintSource(GIF 单帧缓冲=全图尺寸/视频 videoWidth)→ 0 */
|
|
457
|
-
sourceNaturalSize() {
|
|
458
|
-
const el = this.node.imageEl;
|
|
459
|
-
if (el)
|
|
460
|
-
return { width: el.naturalWidth || el.width || 0, height: el.naturalHeight || el.height || 0 };
|
|
461
|
-
if (this.node instanceof AnimatedNode) {
|
|
462
|
-
const src = this.node.paintSource;
|
|
463
|
-
if (src)
|
|
464
|
-
return { width: ('videoWidth' in src ? src.videoWidth : src.width) || src.width || 0, height: ('videoHeight' in src ? src.videoHeight : src.height) || src.height || 0 };
|
|
465
|
-
}
|
|
466
|
-
return { width: 0, height: 0 };
|
|
467
|
-
}
|
|
468
|
-
/** 同应用 FabricImage.getOriginalElementWidth/Height:原图(未裁剪源)自然尺寸
|
|
469
|
-
* ——比例裁剪的基准,不随 cropX/cropY/width 缩。引擎 imageEl 即 fabric
|
|
470
|
-
* _originalElement 等价物;未加载返回 0(fabric _originalElement 缺席同值) */
|
|
471
|
-
getOriginalElementWidth() {
|
|
472
|
-
return this.sourceNaturalSize().width;
|
|
473
|
-
}
|
|
474
|
-
getOriginalElementHeight() {
|
|
475
|
-
return this.sourceNaturalSize().height;
|
|
476
|
-
}
|
|
477
|
-
/** 同应用 FabricImage.getElementWidth/Height:过滤后元素尺寸。引擎无过滤副本
|
|
478
|
-
* 元素(滤镜在渲染管线,源恒原样),与原图同源——fabricGuide/mask 控件的
|
|
479
|
-
* `getOriginalElementWidth?.() || getElementWidth?.() || width` 回退链天然成立 */
|
|
480
|
-
getElementWidth() {
|
|
481
|
-
return this.sourceNaturalSize().width;
|
|
482
|
-
}
|
|
483
|
-
getElementHeight() {
|
|
484
|
-
return this.sourceNaturalSize().height;
|
|
485
|
-
}
|
|
486
|
-
// —— 图片族 width/height 口径桥(批次 54):fabric FabricImage 实例的 width/
|
|
487
|
-
// height 恒为裁剪窗可见宽(cropX/cropY 为窗偏移,独立字段),序列化才按
|
|
488
|
-
// cropSizeMode 合成 legacy(width+cropX——FabricImage.toObject L1499);引擎
|
|
489
|
-
// 盘上(dims/cropRect/liveState/历史回放)统一按 legacy 解析(imageCropRect:
|
|
490
|
-
// 非 visible 一律 width−cropX)。此前面板直写可见口径进 raw,引擎读成
|
|
491
|
-
// legacy 窗偏小——比例预设裁剪的窗/扩图框/静态渲染全部缩水。桥=raw 维持
|
|
492
|
-
// 引擎 legacy 口径,accessor 对外呈现 fabric 可见口径(读写双向换算)——
|
|
493
|
-
/** 非可见口径(legacy)下的窗偏移读位(图片族外恒 0——桥只对裁剪图生效) */
|
|
494
|
-
cropOffset() {
|
|
495
|
-
if (!this.isImageLikeNode)
|
|
496
|
-
return { x: 0, y: 0 };
|
|
497
|
-
const raw = this.node.raw;
|
|
498
|
-
if (raw.cropSizeMode === 'visible')
|
|
499
|
-
return { x: 0, y: 0 };
|
|
500
|
-
return { x: Number(raw.cropX) || 0, y: Number(raw.cropY) || 0 };
|
|
501
|
-
}
|
|
502
|
-
// —— 基座访问器(批次 237,F3 翻转前置):CanvasObject 契约的 13 基座键补齐
|
|
503
|
-
// 声明位——此前经索引签名提供 unknown(结构性不可赋 number 声明,批次 231
|
|
504
|
-
// 勘定缺口);getter 转发 raw + 引擎缺省语义,setter 经 set 走失效链 ——
|
|
505
|
-
get left() {
|
|
506
|
-
return this.node.raw.left ?? 0;
|
|
507
|
-
}
|
|
508
|
-
set left(value) {
|
|
509
|
-
this.set({ left: value });
|
|
510
|
-
}
|
|
511
|
-
get top() {
|
|
512
|
-
return this.node.raw.top ?? 0;
|
|
513
|
-
}
|
|
514
|
-
set top(value) {
|
|
515
|
-
this.set({ top: value });
|
|
516
|
-
}
|
|
517
|
-
get scaleX() {
|
|
518
|
-
return this.node.raw.scaleX ?? 1;
|
|
519
|
-
}
|
|
520
|
-
set scaleX(value) {
|
|
521
|
-
this.set({ scaleX: value });
|
|
522
|
-
}
|
|
523
|
-
get scaleY() {
|
|
524
|
-
return this.node.raw.scaleY ?? 1;
|
|
525
|
-
}
|
|
526
|
-
set scaleY(value) {
|
|
527
|
-
this.set({ scaleY: value });
|
|
528
|
-
}
|
|
529
|
-
get angle() {
|
|
530
|
-
return this.node.raw.angle ?? 0;
|
|
531
|
-
}
|
|
532
|
-
set angle(value) {
|
|
533
|
-
this.set({ angle: value });
|
|
534
|
-
}
|
|
535
|
-
get skewX() {
|
|
536
|
-
return this.node.raw.skewX ?? 0;
|
|
537
|
-
}
|
|
538
|
-
set skewX(value) {
|
|
539
|
-
this.set({ skewX: value });
|
|
540
|
-
}
|
|
541
|
-
get skewY() {
|
|
542
|
-
return this.node.raw.skewY ?? 0;
|
|
543
|
-
}
|
|
544
|
-
set skewY(value) {
|
|
545
|
-
this.set({ skewY: value });
|
|
546
|
-
}
|
|
547
|
-
get flipX() {
|
|
548
|
-
return this.node.raw.flipX ?? false;
|
|
549
|
-
}
|
|
550
|
-
set flipX(value) {
|
|
551
|
-
this.set({ flipX: value });
|
|
552
|
-
}
|
|
553
|
-
get flipY() {
|
|
554
|
-
return this.node.raw.flipY ?? false;
|
|
555
|
-
}
|
|
556
|
-
set flipY(value) {
|
|
557
|
-
this.set({ flipY: value });
|
|
558
|
-
}
|
|
559
|
-
get originX() {
|
|
560
|
-
return this.node.raw.originX ?? 'left';
|
|
561
|
-
}
|
|
562
|
-
set originX(value) {
|
|
563
|
-
this.set({ originX: value });
|
|
564
|
-
}
|
|
565
|
-
get originY() {
|
|
566
|
-
return this.node.raw.originY ?? 'top';
|
|
567
|
-
}
|
|
568
|
-
set originY(value) {
|
|
569
|
-
this.set({ originY: value });
|
|
570
|
-
}
|
|
571
|
-
get width() {
|
|
572
|
-
const raw = this.node.raw;
|
|
573
|
-
return (raw.width ?? 0) - this.cropOffset().x;
|
|
574
|
-
}
|
|
575
|
-
set width(value) {
|
|
576
|
-
// 组合直写同批 set() 路由(批次 104):改宽再分配而非 raw 落盘
|
|
577
|
-
if (isGroupWidthHandleNode(this.node)) {
|
|
578
|
-
if (this.ctx.setGroupWidth) {
|
|
579
|
-
this.ctx.setGroupWidth(this.node, value);
|
|
580
|
-
return;
|
|
581
|
-
}
|
|
582
|
-
this.ctx.setNodeProps(this.node, { width: value });
|
|
583
|
-
return;
|
|
584
|
-
}
|
|
585
|
-
const offset = this.cropOffset();
|
|
586
|
-
this.ctx.setNodeProps(this.node, { width: value + offset.x });
|
|
587
|
-
}
|
|
588
|
-
get height() {
|
|
589
|
-
const raw = this.node.raw;
|
|
590
|
-
return (raw.height ?? 0) - this.cropOffset().y;
|
|
591
|
-
}
|
|
592
|
-
set height(value) {
|
|
593
|
-
const offset = this.cropOffset();
|
|
594
|
-
this.ctx.setNodeProps(this.node, { height: value + offset.y });
|
|
595
|
-
}
|
|
596
|
-
/** set() 批量的口径合成:width/height 用同批 cropX/cropY(缺省读盘)按
|
|
597
|
-
* legacy 合成——fabric 面板「cropX/width 同批直写」的组合语义等价还原 */
|
|
598
|
-
bridgeImageSizeProps(props) {
|
|
599
|
-
if (!this.isImageLikeNode)
|
|
600
|
-
return;
|
|
601
|
-
const raw = this.node.raw;
|
|
602
|
-
if (raw.cropSizeMode === 'visible')
|
|
603
|
-
return;
|
|
604
|
-
const cropX = typeof props.cropX === 'number' ? props.cropX : Number(raw.cropX) || 0;
|
|
605
|
-
const cropY = typeof props.cropY === 'number' ? props.cropY : Number(raw.cropY) || 0;
|
|
606
|
-
if (typeof props.width === 'number' && cropX > 0)
|
|
607
|
-
props.width = props.width + cropX;
|
|
608
|
-
if (typeof props.height === 'number' && cropY > 0)
|
|
609
|
-
props.height = props.height + cropY;
|
|
610
|
-
}
|
|
611
|
-
// —— 裁切/扩图会话(批次 54):右栏 ImageClip「裁切」/比例预设与 ImageTools
|
|
612
|
-
// 「AI扩图」按钮链 image.set({__isCropping/__isExpand}) 的承接。fabric 侧是
|
|
613
|
-
// FabricImage 原型 accessor(快照 beforeState + 切控件集 + 绑 moving 手柄 +
|
|
614
|
-
// 会话专属渲染),引擎侧等价物 = cropSession/expandSession 控制器(手势/
|
|
615
|
-
// 覆盖层/三通道退出内建——B2/B3 已验收);compat 只路由会话进出与读位。
|
|
616
|
-
// 此前断链形态:setProps 把 __isCropping 原样写 raw,引擎不消费——按钮点了
|
|
617
|
-
// 画布零反应(读位 raw.__isCropping=true 的脏值是静默假象)——
|
|
618
|
-
/** 裁切会话进入前快照(工具条 reset/✓ 的守卫与历史基线;fabric beforeState
|
|
619
|
-
* 同语义:仅首次进入捕获,会话内预设切换不覆盖,退出即清) */
|
|
620
|
-
cropBeforeState;
|
|
621
|
-
/** fabric FabricImage.__isCropping 读位:会话真值现算(不再读 raw 脏值) */
|
|
622
|
-
get __isCropping() {
|
|
623
|
-
return this.isImageLikeNode && this.ctx.cropSessionNodeId?.() === this.node.id;
|
|
624
|
-
}
|
|
625
|
-
set __isCropping(value) {
|
|
626
|
-
if (!this.isImageLikeNode)
|
|
627
|
-
return;
|
|
628
|
-
if (value) {
|
|
629
|
-
const firstEnter = this.ctx.cropSessionNodeId?.() !== this.node.id;
|
|
630
|
-
if (!this.ctx.enterCropSession?.(this.node))
|
|
631
|
-
return;
|
|
632
|
-
if (firstEnter)
|
|
633
|
-
this.cropBeforeState = this.toObject();
|
|
634
|
-
// 比例预设(presetImageClip ratio 分支)先直写 cropAspectRatio 落盘再
|
|
635
|
-
// set(__isCropping)——进入即应用约束(整图内居中最大比例窗重摆,引擎
|
|
636
|
-
// setCropAspectRatio 同数学;面板随后直写的同值窗口幂等)
|
|
637
|
-
const ratio = this.node.raw.cropAspectRatio;
|
|
638
|
-
if (typeof ratio === 'number' && ratio > 0)
|
|
639
|
-
this.ctx.setCropSessionAspectRatio?.(ratio);
|
|
640
|
-
}
|
|
641
|
-
else {
|
|
642
|
-
this.ctx.exitCropSession?.(this.node);
|
|
643
|
-
this.cropBeforeState = undefined;
|
|
644
|
-
}
|
|
645
|
-
}
|
|
646
|
-
/** fabric FabricImage.__isExpand 读位:扩图会话真值现算 */
|
|
647
|
-
get __isExpand() {
|
|
648
|
-
return this.isImageLikeNode && this.ctx.expandSessionNodeId?.() === this.node.id;
|
|
649
|
-
}
|
|
650
|
-
set __isExpand(value) {
|
|
651
|
-
if (!this.isImageLikeNode)
|
|
652
|
-
return;
|
|
653
|
-
if (value) {
|
|
654
|
-
this.ctx.enterExpandSession?.(this.node);
|
|
655
|
-
}
|
|
656
|
-
else {
|
|
657
|
-
this.ctx.exitExpandSession?.(this.node);
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
get beforeState() {
|
|
661
|
-
return this.cropBeforeState;
|
|
662
|
-
}
|
|
663
|
-
/**
|
|
664
|
-
* fabric 裁切/扩图会话收尾(ESC useCanvasHotkey.exitImageCropping / 工具条 ✓
|
|
665
|
-
* reset / handleOutpaintImage 消费):两会话退出幂等(引擎 exit 无会话即
|
|
666
|
-
* 空操作——ESC 双监听竞态安全),beforeState 同 fabric 退出即清。
|
|
667
|
-
*/
|
|
668
|
-
onDeselectEvent() {
|
|
669
|
-
this.ctx.exitCropSession?.(this.node);
|
|
670
|
-
this.ctx.exitExpandSession?.(this.node);
|
|
671
|
-
this.cropBeforeState = undefined;
|
|
672
|
-
}
|
|
673
|
-
/** 扩图四向外扩量读位:会话期从引擎 info 现算(引擎 offsets 退出时才结算写盘,
|
|
674
|
-
* handleOutpaintImage 在 onDeselectEvent 之前读——正是会话活期);无会话回落
|
|
675
|
-
* raw(fabric setExpandOffset 常维护实例字段的持久残留) */
|
|
676
|
-
expandOffsetOf(key) {
|
|
677
|
-
const live = this.ctx.expandSessionOffsets?.(this.node);
|
|
678
|
-
if (live)
|
|
679
|
-
return live[key];
|
|
680
|
-
const suffix = key === 'left' ? 'Left' : key === 'right' ? 'Right' : key === 'top' ? 'Top' : 'Bottom';
|
|
681
|
-
const value = this.node.raw[`expand${suffix}Offset`];
|
|
682
|
-
return typeof value === 'number' ? value : undefined;
|
|
683
|
-
}
|
|
684
|
-
get expandLeftOffset() {
|
|
685
|
-
return this.isImageLikeNode ? this.expandOffsetOf('left') : undefined;
|
|
686
|
-
}
|
|
687
|
-
get expandRightOffset() {
|
|
688
|
-
return this.isImageLikeNode ? this.expandOffsetOf('right') : undefined;
|
|
689
|
-
}
|
|
690
|
-
get expandTopOffset() {
|
|
691
|
-
return this.isImageLikeNode ? this.expandOffsetOf('top') : undefined;
|
|
692
|
-
}
|
|
693
|
-
get expandBottomOffset() {
|
|
694
|
-
return this.isImageLikeNode ? this.expandOffsetOf('bottom') : undefined;
|
|
695
|
-
}
|
|
696
|
-
/** fabric setExpandOffset:会话活期把现算 offsets 写盘(Toolbar 滑杆帧调用;
|
|
697
|
-
* fabric 语义=常维护实例字段,此处维护 raw——非会话期空操作) */
|
|
698
|
-
setExpandOffset() {
|
|
699
|
-
const live = this.ctx.expandSessionOffsets?.(this.node);
|
|
700
|
-
if (!live)
|
|
701
|
-
return;
|
|
702
|
-
this.set({ expandLeftOffset: live.left, expandRightOffset: live.right, expandTopOffset: live.top, expandBottomOffset: live.bottom });
|
|
703
|
-
}
|
|
704
|
-
/**
|
|
705
|
-
* 应用 cropping.mixin.updateCropScale 同源数学(裁切会话中工具条缩放滑杆):
|
|
706
|
-
* 以裁剪窗中心缩放窗(新窗 = 旧窗 × 旧 scale/新 scale),越界拒绝整帧。
|
|
707
|
-
* 返回是否应用(fabric 同款 true/false)。
|
|
708
|
-
*/
|
|
709
|
-
updateCropScale(newScale) {
|
|
710
|
-
if (!this.__isCropping)
|
|
711
|
-
return false;
|
|
712
|
-
const el = this.node.imageEl;
|
|
713
|
-
if (!el)
|
|
714
|
-
return false;
|
|
715
|
-
const raw = this.node.raw;
|
|
716
|
-
const fullWidth = el.naturalWidth || el.width;
|
|
717
|
-
const fullHeight = el.naturalHeight || el.height;
|
|
718
|
-
const oldScaleX = raw.scaleX ?? 1;
|
|
719
|
-
const scaleChangeX = newScale / oldScaleX;
|
|
720
|
-
const scaleChangeY = newScale / (raw.scaleY ?? 1);
|
|
721
|
-
// 可见窗宽(fabric 实例口径——raw legacy 换算)
|
|
722
|
-
const width = this.width;
|
|
723
|
-
const height = this.height;
|
|
724
|
-
const newWidth = width / scaleChangeX;
|
|
725
|
-
const newHeight = height / scaleChangeY;
|
|
726
|
-
const newCropX = (raw.cropX ?? 0) + width / 2 - newWidth / 2;
|
|
727
|
-
const newCropY = (raw.cropY ?? 0) + height / 2 - newHeight / 2;
|
|
728
|
-
if (newCropX < 0 || newCropY < 0 || newCropX + newWidth > fullWidth || newCropY + newHeight > fullHeight)
|
|
729
|
-
return false;
|
|
730
|
-
this.set({ cropScale: newScale, scaleX: newScale, scaleY: newScale, width: newWidth, height: newHeight, cropX: newCropX, cropY: newCropY });
|
|
731
|
-
return true;
|
|
732
|
-
}
|
|
733
|
-
/** fabric mixin getMaxEffectPadding 同源移植(fabricObject.ts:614——下载元素导出
|
|
734
|
-
* 画布外扩量:效果偏移/模糊/描边/原生阴影取最大 + 基础 20)。纯数据读(effects/
|
|
735
|
-
* shadow/stroke 族全在 raw),无 fabric 运行时依赖;不做签名缓存(调用点为导出
|
|
736
|
-
* 冷路径,包装对象生命周期也短)。边界:文本高亮(texts 分支)依赖 fabric
|
|
737
|
-
* __charBounds/_measureLine 运行时,不承接——高亮文本导出外扩可能偏小(下载
|
|
738
|
-
* 画面裁切风险与 fabric 有差,登记后续片) */
|
|
739
|
-
getMaxEffectPadding() {
|
|
740
|
-
const raw = this.node.raw;
|
|
741
|
-
let padding = 0;
|
|
742
|
-
const effects = (raw.effects ?? {});
|
|
743
|
-
const enabled = (list) => (list ?? []).filter((effect) => effect.enabled && effect.showInDialog);
|
|
744
|
-
const solidFills = enabled(effects.solidFill);
|
|
745
|
-
if (solidFills.length > 0) {
|
|
746
|
-
padding = Math.max(padding, solidFills.reduce((max, effect) => Math.max(max, Math.abs(Number(effect.offsetX) || 0), Math.abs(Number(effect.offsetY) || 0)), 0));
|
|
747
|
-
}
|
|
748
|
-
const shadows = enabled(effects.dropShadow);
|
|
749
|
-
if (shadows.length > 0) {
|
|
750
|
-
padding = Math.max(padding, shadows.reduce((max, effect) => {
|
|
751
|
-
const blurPadding = (Number(effect.blur) || 0) * 5;
|
|
752
|
-
return Math.max(max, Math.abs(Number(effect.offsetX) || 0) + blurPadding, Math.abs(Number(effect.offsetY) || 0) + blurPadding);
|
|
753
|
-
}, 0));
|
|
754
|
-
}
|
|
755
|
-
const strokes = enabled(effects.stroke);
|
|
756
|
-
if (strokes.length > 0) {
|
|
757
|
-
padding = Math.max(padding, strokes.reduce((max, effect) => {
|
|
758
|
-
const size = effect.size;
|
|
759
|
-
const strokeWidth = Number(effect.strokeWidth) || Number(size?.value) || 0;
|
|
760
|
-
return Math.max(max, strokeWidth + Math.abs(Number(effect.offsetX) || 0), strokeWidth + Math.abs(Number(effect.offsetY) || 0));
|
|
761
|
-
}, 0));
|
|
762
|
-
}
|
|
763
|
-
const shadow = raw.shadow;
|
|
764
|
-
if (shadow) {
|
|
765
|
-
const blurPadding = (Number(shadow.blur) || 0) * 5;
|
|
766
|
-
padding = Math.max(padding, Math.abs(Number(shadow.offsetX) || 0) + blurPadding, Math.abs(Number(shadow.offsetY) || 0) + blurPadding);
|
|
767
|
-
}
|
|
768
|
-
const strokeWidth = Number(raw.strokeWidth) || 0;
|
|
769
|
-
if (raw.stroke && strokeWidth) {
|
|
770
|
-
const strokePad = raw.strokeAlignment === 'outside' ? strokeWidth * 2 : strokeWidth;
|
|
771
|
-
padding = Math.max(padding, strokePad);
|
|
772
|
-
}
|
|
773
|
-
return padding + 20;
|
|
774
|
-
}
|
|
775
|
-
/** fabric isType:types 含 constructor.type 或 this.type——引擎 raw.type 兼存小写
|
|
776
|
-
* 形态('rect')而应用调用恒用规范名,改大小写不敏感比对(check.isTextObject 等消费) */
|
|
777
|
-
isType(...types) {
|
|
778
|
-
const own = typeKeyOf(this.node.raw);
|
|
779
|
-
return types.some((type) => type.toLowerCase() === own);
|
|
780
|
-
}
|
|
781
|
-
/** fabric getStyleAtPosition(fontSize 多值检测等消费):扁平字符位按 '\n' 分解到
|
|
782
|
-
* 原始行/字查 raw.styles——fabric 经视觉行 + styleMap 平移后落在同一原始格(引擎
|
|
783
|
-
* textLayout.styleAt 同键位)。非文本/越界返回 {}(fabric 缺省 false 的消费只读
|
|
784
|
-
* .fontSize,等价) */
|
|
785
|
-
getStyleAtPosition(position) {
|
|
786
|
-
if (!(this.node instanceof TextNode))
|
|
787
|
-
return {};
|
|
788
|
-
const text = typeof this.node.raw.text === 'string' ? this.node.raw.text : '';
|
|
789
|
-
if (position < 0 || position >= text.length)
|
|
790
|
-
return {};
|
|
791
|
-
let rest = position;
|
|
792
|
-
const lines = text.split('\n');
|
|
793
|
-
for (let line = 0; line < lines.length; line++) {
|
|
794
|
-
if (rest <= lines[line].length) {
|
|
795
|
-
return this.objectStyles()?.[line]?.[rest] ?? {};
|
|
796
|
-
}
|
|
797
|
-
rest -= lines[line].length + 1;
|
|
798
|
-
}
|
|
799
|
-
return {};
|
|
800
|
-
}
|
|
801
|
-
/** fabric calcTransformMatrix:引擎矩阵即 fabric 形态(mat2d 同源移植、每帧
|
|
802
|
-
* 现算);返回副本防调用方改写污染缓存 */
|
|
803
|
-
calcTransformMatrix() {
|
|
804
|
-
return [...this.node.matrix];
|
|
805
|
-
}
|
|
806
|
-
// —— fabric 扩展 Table 的整体尺寸写位(useHandleActive 宽高面板 TABLE 分支:
|
|
807
|
-
// 改宽高按比例缩放全列/全行而非落 scale——布局语义由引擎 rebuildTable 承担)——
|
|
808
|
-
/**
|
|
809
|
-
* fabric Table.setTableWidth 同数学:按当前列宽比例缩放(手动调过的列保持
|
|
810
|
-
* 比例不还原、minCellWidth 钳下限)。左上角位置不变——锚定由引擎 rebuildTable
|
|
811
|
-
* 的 reflowOrigin 角回锚承担(缺省 left/top,与 fabric getPointByOrigin 同位)。
|
|
812
|
-
* 非表格节点 no-op(对齐 fabric `!this.strategy` 早退)。
|
|
813
|
-
*/
|
|
814
|
-
setTableWidth(width) {
|
|
815
|
-
if (!(this.node instanceof TableNode))
|
|
816
|
-
return;
|
|
817
|
-
const raw = this.node.raw;
|
|
818
|
-
const cols = raw.cols ?? 0;
|
|
819
|
-
const columnWidths = raw.columnWidths;
|
|
820
|
-
if (cols <= 0 || !Array.isArray(columnWidths) || columnWidths.length === 0)
|
|
821
|
-
return;
|
|
822
|
-
const cellStrokeWidth = raw.cellStrokeWidth ?? 0;
|
|
823
|
-
const cellSpacing = raw.cellSpacing ?? 0;
|
|
824
|
-
const currentTotal = columnWidths.reduce((sum, w) => sum + w, 0);
|
|
825
|
-
if (currentTotal <= 0)
|
|
826
|
-
return;
|
|
827
|
-
const scale = (width - cellStrokeWidth - (cols - 1) * cellSpacing) / currentTotal;
|
|
828
|
-
const minCellWidth = raw.minCellWidth ?? 0;
|
|
829
|
-
this.set({ columnWidths: columnWidths.map((w) => Math.max(minCellWidth, w * scale)) });
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* fabric Table.setTableHeight 同数学:读生效行高(raw.rowHeights——rebuildTable
|
|
833
|
-
* 每轮回写)、按比例写 manualRowHeights(引擎 STRUCTURE_KEYS → 重排)。
|
|
834
|
-
* 非表格节点 no-op。
|
|
835
|
-
*/
|
|
836
|
-
setTableHeight(height) {
|
|
837
|
-
if (!(this.node instanceof TableNode))
|
|
838
|
-
return;
|
|
839
|
-
const raw = this.node.raw;
|
|
840
|
-
const rows = raw.rows ?? 0;
|
|
841
|
-
const rowHeights = raw.rowHeights;
|
|
842
|
-
if (rows <= 0 || !Array.isArray(rowHeights) || rowHeights.length === 0)
|
|
843
|
-
return;
|
|
844
|
-
const cellStrokeWidth = raw.cellStrokeWidth ?? 0;
|
|
845
|
-
const cellSpacing = raw.cellSpacing ?? 0;
|
|
846
|
-
const currentTotal = rowHeights.reduce((sum, h) => sum + h, 0);
|
|
847
|
-
if (currentTotal <= 0)
|
|
848
|
-
return;
|
|
849
|
-
const scale = (height - cellStrokeWidth - (rows - 1) * cellSpacing) / currentTotal;
|
|
850
|
-
const minCellHeight = raw.minCellHeight ?? 0;
|
|
851
|
-
this.set({ manualRowHeights: rowHeights.map((h) => Math.max(minCellHeight, h * scale)) });
|
|
852
|
-
}
|
|
853
|
-
// —— fabric 文本样式族(批次 29:右栏文字按钮链的统一前奏是 cleanStyle → set,
|
|
854
|
-
// editing 态走 setSelectionStyles/getSelectionStyles——缺席即 TypeError 被
|
|
855
|
-
// Vue errorHandler 吞掉,面板表现为「点了没反应」。引擎 styles 键位 =
|
|
856
|
-
// fabric 逻辑行/字(getStyleAtPosition 同口径),直接改 raw.styles 后经
|
|
857
|
-
// set({styles}) 走引擎失效链触发 textLayout 重排——
|
|
858
|
-
/** fabric get2DCursorLocation:扁平字符位分解逻辑行/字('\n' 分隔,styles 键口径) */
|
|
859
|
-
cursor2D(position) {
|
|
860
|
-
const text = typeof this.node.raw.text === 'string' ? this.node.raw.text : '';
|
|
861
|
-
let rest = Math.max(0, Math.min(position, text.length));
|
|
862
|
-
const lines = text.split('\n');
|
|
863
|
-
for (let line = 0; line < lines.length; line++) {
|
|
864
|
-
if (rest <= lines[line].length)
|
|
865
|
-
return { line, char: rest };
|
|
866
|
-
rest -= lines[line].length + 1;
|
|
867
|
-
}
|
|
868
|
-
return { line: Math.max(0, lines.length - 1), char: lines[lines.length - 1]?.length ?? 0 };
|
|
869
|
-
}
|
|
870
|
-
/** 四缝:游程数组→对象归一(app TextCommon 字素口径——宿主安装器覆写;缺省 passthrough,裸用仅对象形态) */
|
|
871
|
-
stylesToEngineForm(styles, _text) {
|
|
872
|
-
return styles;
|
|
873
|
-
}
|
|
874
|
-
/** 四缝:对象→游程数组出向序列化(同上宿主覆写;缺省 passthrough cast) */
|
|
875
|
-
stylesToPersistForm(styles, _text) {
|
|
876
|
-
return styles;
|
|
877
|
-
}
|
|
878
|
-
/** 四缝:clipImage 写时序列化键表(app 配置 propertiesToInclude 口径——宿主覆写;缺省 undefined) */
|
|
879
|
-
serializationProps() {
|
|
880
|
-
return undefined;
|
|
881
|
-
}
|
|
882
|
-
stylesMap() {
|
|
883
|
-
const raw = this.node.raw;
|
|
884
|
-
if (Array.isArray(raw.styles)) {
|
|
885
|
-
// 混入的应用游程数组形态(漏网写入口)就地归一为对象形态——杜绝「数组按
|
|
886
|
-
// 下标写出 [{0:{...}}] 混血形态」(批次 34,两套序列化约定见 engineCompatStyles 头注)
|
|
887
|
-
raw.styles = this.stylesToEngineForm(raw.styles, typeof raw.text === 'string' ? raw.text : '') ?? {};
|
|
888
|
-
}
|
|
889
|
-
if (!raw.styles)
|
|
890
|
-
raw.styles = {};
|
|
891
|
-
return raw.styles;
|
|
892
|
-
}
|
|
893
|
-
/** styles 只读位(不创建):数组形态就地归一后返回,缺省 undefined */
|
|
894
|
-
objectStyles() {
|
|
895
|
-
const raw = this.node.raw;
|
|
896
|
-
if (Array.isArray(raw.styles)) {
|
|
897
|
-
raw.styles = this.stylesToEngineForm(raw.styles, typeof raw.text === 'string' ? raw.text : '') ?? {};
|
|
898
|
-
}
|
|
899
|
-
return raw.styles;
|
|
900
|
-
}
|
|
901
|
-
/** fabric selectionStart/selectionEnd(编辑会话选区,grapheme 口径;非编辑恒 0) */
|
|
902
|
-
get selectionStart() {
|
|
903
|
-
return this.ctx.getNodeSelectionRange?.(this.node)?.start ?? 0;
|
|
904
|
-
}
|
|
905
|
-
get selectionEnd() {
|
|
906
|
-
return this.ctx.getNodeSelectionRange?.(this.node)?.end ?? 0;
|
|
907
|
-
}
|
|
908
|
-
/**
|
|
909
|
-
* fabric Text.cleanStyle 逐字移植:清逐字样式里与父级同值的键;全文字样式
|
|
910
|
-
* 一致时提升为父级属性并整族清空。graphemeCount 按逻辑行合计(fabric 用视觉
|
|
911
|
-
* 行——wrapped 文本有口径差,登记近似:只影响「是否提升到父级」的判定,
|
|
912
|
-
* 清同值键的主路径不受影响)。
|
|
913
|
-
*/
|
|
914
|
-
cleanStyle(property) {
|
|
915
|
-
const raw = this.node.raw;
|
|
916
|
-
const obj = this.objectStyles();
|
|
917
|
-
if (!obj)
|
|
918
|
-
return false;
|
|
919
|
-
let stylesCount = 0;
|
|
920
|
-
let letterCount;
|
|
921
|
-
let stylePropertyValue;
|
|
922
|
-
let allStyleObjectPropertiesMatch = true;
|
|
923
|
-
let graphemeCount = 0;
|
|
924
|
-
for (const p1 in obj) {
|
|
925
|
-
letterCount = 0;
|
|
926
|
-
for (const p2 in obj[p1]) {
|
|
927
|
-
const styleObject = obj[p1][p2] || {};
|
|
928
|
-
const stylePropertyHasBeenSet = styleObject[property] !== undefined;
|
|
929
|
-
stylesCount++;
|
|
930
|
-
if (stylePropertyHasBeenSet) {
|
|
931
|
-
if (stylePropertyValue === undefined)
|
|
932
|
-
stylePropertyValue = styleObject[property];
|
|
933
|
-
else if (styleObject[property] !== stylePropertyValue)
|
|
934
|
-
allStyleObjectPropertiesMatch = false;
|
|
935
|
-
if (styleObject[property] === raw[property])
|
|
936
|
-
delete styleObject[property];
|
|
937
|
-
}
|
|
938
|
-
else {
|
|
939
|
-
allStyleObjectPropertiesMatch = false;
|
|
940
|
-
}
|
|
941
|
-
if (Object.keys(styleObject).length !== 0) {
|
|
942
|
-
letterCount++;
|
|
943
|
-
}
|
|
944
|
-
else {
|
|
945
|
-
delete obj[p1][p2];
|
|
946
|
-
}
|
|
947
|
-
}
|
|
948
|
-
if (letterCount === 0)
|
|
949
|
-
delete obj[p1];
|
|
950
|
-
}
|
|
951
|
-
if (typeof raw.text === 'string')
|
|
952
|
-
for (const line of raw.text.split('\n'))
|
|
953
|
-
graphemeCount += line.length;
|
|
954
|
-
if (allStyleObjectPropertiesMatch && stylesCount === graphemeCount && stylesCount > 0 && stylePropertyValue !== undefined) {
|
|
955
|
-
this.set({ [property]: stylePropertyValue });
|
|
956
|
-
this.removeStyle?.(property);
|
|
957
|
-
return true;
|
|
958
|
-
}
|
|
959
|
-
if (stylesCount > 0)
|
|
960
|
-
this.set({ styles: raw.styles });
|
|
961
|
-
return false;
|
|
962
|
-
}
|
|
963
|
-
/** fabric Text.removeStyle 逐字移植:删全族逐字样式键,空格对象回收 */
|
|
964
|
-
removeStyle(property) {
|
|
965
|
-
const obj = this.objectStyles();
|
|
966
|
-
if (!obj)
|
|
967
|
-
return;
|
|
968
|
-
for (const lineNum in obj) {
|
|
969
|
-
const line = obj[lineNum];
|
|
970
|
-
for (const charNum in line) {
|
|
971
|
-
delete line[charNum][property];
|
|
972
|
-
if (Object.keys(line[charNum]).length === 0)
|
|
973
|
-
delete line[charNum];
|
|
974
|
-
}
|
|
975
|
-
if (Object.keys(line).length === 0)
|
|
976
|
-
delete obj[lineNum];
|
|
977
|
-
}
|
|
978
|
-
this.set({ styles: obj });
|
|
979
|
-
}
|
|
980
|
-
/** fabric IText.setSelectionStyles:选区逐字下发(区间缺省取编辑会话选区;
|
|
981
|
-
* undefined 键不下发——fabric pickBy 语义) */
|
|
982
|
-
setSelectionStyles(styles, startIndex, endIndex) {
|
|
983
|
-
if (!(this.node instanceof TextNode))
|
|
984
|
-
return;
|
|
985
|
-
const range = this.ctx.getNodeSelectionRange?.(this.node);
|
|
986
|
-
const start = startIndex ?? range?.start ?? 0;
|
|
987
|
-
const end = endIndex ?? range?.end ?? 0;
|
|
988
|
-
if (end <= start)
|
|
989
|
-
return;
|
|
990
|
-
const map = this.stylesMap();
|
|
991
|
-
for (let i = start; i < end; i++) {
|
|
992
|
-
const { line, char } = this.cursor2D(i);
|
|
993
|
-
if (!map[line])
|
|
994
|
-
map[line] = {};
|
|
995
|
-
const decl = map[line][char] ?? {};
|
|
996
|
-
const merged = { ...decl };
|
|
997
|
-
for (const key of Object.keys(styles)) {
|
|
998
|
-
if (styles[key] !== undefined)
|
|
999
|
-
merged[key] = styles[key];
|
|
1000
|
-
}
|
|
1001
|
-
map[line][char] = merged;
|
|
1002
|
-
}
|
|
1003
|
-
this.set({ styles: this.stylesMap() });
|
|
1004
|
-
}
|
|
1005
|
-
/** fabric IText.getSelectionStyles:选区逐字读回(区间缺省取编辑会话选区) */
|
|
1006
|
-
getSelectionStyles(startIndex, endIndex) {
|
|
1007
|
-
if (!(this.node instanceof TextNode))
|
|
1008
|
-
return [];
|
|
1009
|
-
const range = this.ctx.getNodeSelectionRange?.(this.node);
|
|
1010
|
-
const start = startIndex ?? range?.start ?? 0;
|
|
1011
|
-
const end = endIndex ?? range?.end ?? start;
|
|
1012
|
-
const out = [];
|
|
1013
|
-
for (let i = start; i < end; i++)
|
|
1014
|
-
out.push(this.getStyleAtPosition(i));
|
|
1015
|
-
return out;
|
|
1016
|
-
}
|
|
1017
|
-
/**
|
|
1018
|
-
* 应用 Textbox.setFontFamily 引擎等价:写 fontFamily(textLayout 重排内建)。
|
|
1019
|
-
* 选项 expandWidthToFitSingleLineText 不承接——调用点按
|
|
1020
|
-
* `typeof shouldExpandWidthForFontFamilyChange === 'function'` 判缺席即 false,
|
|
1021
|
-
* 「宽度保持」语义天然成立。
|
|
1022
|
-
*/
|
|
1023
|
-
setFontFamily(fontFamily, _options) {
|
|
1024
|
-
this.set({ fontFamily });
|
|
1025
|
-
}
|
|
1026
|
-
/** 应用 Textbox.fontFamily 读位(批次 157:agent add_text 字体回退检测等直读
|
|
1027
|
-
* 消费——此前包装直读 undefined 会误判「字体不可用」恒走回退) */
|
|
1028
|
-
get fontFamily() {
|
|
1029
|
-
return String(this.node.raw.fontFamily ?? '');
|
|
1030
|
-
}
|
|
1031
|
-
/** fabric obj.type 直读位(批次 164:外部拖拽 guide 的鸭子消费
|
|
1032
|
-
* `image.type` 判动态源分档——GIF/视频不接管;isType 方法位之外的面) */
|
|
1033
|
-
get type() {
|
|
1034
|
-
return String(this.node.raw.type ?? '');
|
|
1035
|
-
}
|
|
1036
|
-
/** 应用 Textbox.initDimensions:引擎排版失效链内建(set 后 dims 懒重排同步
|
|
1037
|
-
* 可读),显式重测为 no-op——批次 157 autoFitTextWidth 调用面 */
|
|
1038
|
-
initDimensions() { }
|
|
1039
|
-
/** 应用 Textbox.calcTextWidth:最长行自然宽(textLayout.lines[].width 即
|
|
1040
|
-
* fabric __lineWidths 口径——批次 157 autoFitTextWidth 调用面);非文本 0 */
|
|
1041
|
-
calcTextWidth() {
|
|
1042
|
-
if (!(this.node instanceof TextNode))
|
|
1043
|
-
return 0;
|
|
1044
|
-
return this.node.textLayout.lines.reduce((max, line) => Math.max(max, line.width), 0);
|
|
1045
|
-
}
|
|
1046
|
-
/** 应用 Textbox.refreshTextDimensions:引擎 dims 每帧派生,无需手动刷新——no-op */
|
|
1047
|
-
refreshTextDimensions() { }
|
|
1048
|
-
/** 应用 Textbox.replaceFontFamily 逐字移植:对象级 + 逐字 styles 同步替换 */
|
|
1049
|
-
replaceFontFamily(oldFont, newFont) {
|
|
1050
|
-
const raw = this.node.raw;
|
|
1051
|
-
let changed = false;
|
|
1052
|
-
if (raw.fontFamily === oldFont) {
|
|
1053
|
-
this.set({ fontFamily: newFont });
|
|
1054
|
-
changed = true;
|
|
1055
|
-
}
|
|
1056
|
-
if (raw.styles) {
|
|
1057
|
-
for (const line of Object.values(raw.styles)) {
|
|
1058
|
-
if (!line)
|
|
1059
|
-
continue;
|
|
1060
|
-
for (const style of Object.values(line)) {
|
|
1061
|
-
if (style?.fontFamily === oldFont) {
|
|
1062
|
-
style.fontFamily = newFont;
|
|
1063
|
-
changed = true;
|
|
1064
|
-
}
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
if (changed)
|
|
1068
|
-
this.set({ styles: raw.styles });
|
|
1069
|
-
}
|
|
1070
|
-
return changed;
|
|
1071
|
-
}
|
|
1072
|
-
// —— 特殊文本变形参数写位(批次 33):右栏 ElementTransform 滑杆族。fabric 方法
|
|
1073
|
-
// 存在性=类型判别器(ARC/WARP/CIRCLE 变形面板按 typeof 判可写),按文本子类型
|
|
1074
|
-
// 条件暴露;引擎布局键同名直读 raw(arcLayout 消费 curvature/circle*、warpText
|
|
1075
|
-
// 消费 warpStrength),写值经 set 触发排版重算与重绘 ——
|
|
1076
|
-
/** 引擎 raw.type 小写归一(类型键两形态并存;typeKeyOf 单源) */
|
|
1077
|
-
get rawTypeLower() {
|
|
1078
|
-
return typeKeyOf(this.node.raw);
|
|
1079
|
-
}
|
|
1080
|
-
/** 应用 ArcText.setRadius(→setCurvature):曲率直写(引擎 arcLayout 同键消费,
|
|
1081
|
-
* curvature=1° 也经 radius=1e5 近直渲染——0 值合法) */
|
|
1082
|
-
get setRadius() {
|
|
1083
|
-
if (this.rawTypeLower !== ElementTypes.ARCTEXT)
|
|
1084
|
-
return undefined;
|
|
1085
|
-
return (value) => this.set({ curvature: value });
|
|
1086
|
-
}
|
|
1087
|
-
/** 应用 ArchText/WaistText/FlagText.setWarpStrength:钳 [-1,1] 后直写(引擎
|
|
1088
|
-
* warpText 同键消费;原实现的 store setElement 同步由面板历史链承接,不重复) */
|
|
1089
|
-
get setWarpStrength() {
|
|
1090
|
-
if (!WARP_TEXT_TYPES.has(this.rawTypeLower))
|
|
1091
|
-
return undefined;
|
|
1092
|
-
return (value) => this.set({ warpStrength: Math.max(-1, Math.min(1, value)) });
|
|
1093
|
-
}
|
|
1094
|
-
/** 应用 WaistText/FlagText.clearCache(批次 39):fabric 变形像素缓存作废的引擎
|
|
1095
|
-
* 等价物——节点级烘焙整删 + 重渲染。handleRenderEffects(特效面板)对这两个
|
|
1096
|
-
* 类型无守卫直调,缺席会 TypeError 断掉 modifedElement(特效撤销历史丢失);
|
|
1097
|
-
* font.ts rerenderTextObjects/refreshReplacedTextElements 的 typeof 守卫消费面
|
|
1098
|
-
* 同步点亮。ArchText 同烘焙族顺带覆盖(fabric 侧由各自 _render 缓存键自愈) */
|
|
1099
|
-
get clearCache() {
|
|
1100
|
-
if (!WARP_TEXT_TYPES.has(this.rawTypeLower))
|
|
1101
|
-
return undefined;
|
|
1102
|
-
return () => {
|
|
1103
|
-
this.ctx.invalidateNodeBakes?.(this.node);
|
|
1104
|
-
this.ctx.getCanvas?.()?.requestRenderAll?.();
|
|
1105
|
-
};
|
|
1106
|
-
}
|
|
1107
|
-
/** 应用 CircleText.setCircleParams:补丁直写(circleSize/circleStartAngle/
|
|
1108
|
-
* circleSweep/circleEccentricity/circleDirection——引擎 arcLayout 同键消费) */
|
|
1109
|
-
get setCircleParams() {
|
|
1110
|
-
if (this.rawTypeLower !== ElementTypes.CIRCLETEXT)
|
|
1111
|
-
return undefined;
|
|
1112
|
-
return (patch) => this.set(patch);
|
|
1113
|
-
}
|
|
1114
|
-
/** 应用 Textbox.setTexts:分段高亮文本数组直写(fabric 侧的 merge/normalize 是
|
|
1115
|
-
* 相邻同段合并的去重优化,透传无害)。引擎渲染消费见批次62(textHighlight),
|
|
1116
|
-
* 数据位持久化供 fabric 模式往返 */
|
|
1117
|
-
get setTexts() {
|
|
1118
|
-
if (!(this.node instanceof TextNode))
|
|
1119
|
-
return undefined;
|
|
1120
|
-
return (texts) => this.set({ texts });
|
|
1121
|
-
}
|
|
1122
|
-
/** 应用 Textbox.texts 读位(批次62):ElementMark 的 existingHighlight 回显/
|
|
1123
|
-
* initMarkState/历史 original 快照/既有段合并分支消费——缺席则每次整段重写
|
|
1124
|
-
* 且弹层状态不复现。fabric 侧 setTexts 后有值,这里读 raw 同源。返回型=应用
|
|
1125
|
-
* 契约的划重点段形态(写路径均经 set({texts}) 批量——无属性直写,getter-only
|
|
1126
|
-
* 无吞写) */
|
|
1127
|
-
get texts() {
|
|
1128
|
-
if (!(this.node instanceof TextNode))
|
|
1129
|
-
return undefined;
|
|
1130
|
-
const texts = this.node.raw.texts;
|
|
1131
|
-
return Array.isArray(texts) ? texts : [];
|
|
1132
|
-
}
|
|
1133
|
-
/** 序列化往返:引擎 toObject 本就产出 fabric 兼容 JSON(含 raw 自定义字段);
|
|
1134
|
-
* propertiesToInclude 兜底补 raw 里已有但主序列化遗漏的字段。
|
|
1135
|
-
* 文本对象追加排版三件(P6-5 批次 24):textLines/charBounds/lineHeights 从
|
|
1136
|
-
* 引擎排版派生(Phase 2 布局级 parity 已锁,CharBox 四字段同名同义)——生产
|
|
1137
|
-
* 模板 JSON 恒带三件(模板 authored 写入),引擎模式实时同步的 store JSON 缺
|
|
1138
|
-
* → SVG 引擎路径对刚编辑页恒回退(text-layout-missing)。补在 compat 面
|
|
1139
|
-
* (store 序列化契约),引擎核心 toObject 不动(历史快照/parity 不膨胀);
|
|
1140
|
-
* 盘上三件可能是 fabric 运行时形态(textLines: string[][] / charBounds 空),
|
|
1141
|
-
* 形状不合法即派生覆写;fabric 模式实时创建的对象仍缺三件(fabric toObject
|
|
1142
|
-
* 不出)→ 引擎 SVG 路径在 fabric 模式对新建文本回退,登记已知边界 */
|
|
1143
|
-
toObject(propertiesToInclude) {
|
|
1144
|
-
const out = { ...this.node.toObject() };
|
|
1145
|
-
// 图片族 width/height 补齐(与文本排版三件同思路——补在 compat 面/store 序列化
|
|
1146
|
-
// 契约,引擎核心 toObject 不动,「raw 不改写」红线不破):引擎盘上图片族可缺
|
|
1147
|
-
// width/height 键(dims/渲染按 imageEl 自然尺寸回填,raw 不落键),而 fabric
|
|
1148
|
-
// 序列化契约恒带(未裁剪 Image.width/height=元素自然尺寸,FabricImage.setElement
|
|
1149
|
-
// 同义)。缺键的裸 JSON 消费方(PDF/PPTX worker 的 element.width*scaleX 裸数学)
|
|
1150
|
-
// 会产出 NaN 操作数——内容流被渲染器整段跳过即「导出缺图」。imageEl 未加载
|
|
1151
|
-
// (自然尺寸 0)不补,保留缺席语义
|
|
1152
|
-
if (this.isImageLikeNode) {
|
|
1153
|
-
const natural = this.sourceNaturalSize();
|
|
1154
|
-
if (out.width === undefined && natural.width > 0)
|
|
1155
|
-
out.width = natural.width;
|
|
1156
|
-
if (out.height === undefined && natural.height > 0)
|
|
1157
|
-
out.height = natural.height;
|
|
1158
|
-
}
|
|
1159
|
-
if (this.node instanceof TextNode) {
|
|
1160
|
-
const layout = this.node.textLayout;
|
|
1161
|
-
const lineHeight = this.node.textStyle.lineHeight ?? 1.16;
|
|
1162
|
-
// 弧形/圆形文本 cts 出向恒派生覆写(批次 111):raw 里的 cts 只可能来自
|
|
1163
|
-
// fabric 实例时代(引擎不产该字段)——新建链定格的是构造期清空后的空数组、
|
|
1164
|
-
// 编辑过的存量是旧文本几何;PDF/PPTX 导出绘制器按 cts 摆位,空即静默丢、
|
|
1165
|
-
// 陈旧即错位。引擎布局(=引擎渲染所据)派生,与排版三件同思路
|
|
1166
|
-
const arcCts = deriveArcCharTransformations(layout, this.node.raw, lineHeight);
|
|
1167
|
-
if (arcCts)
|
|
1168
|
-
out.charTransformations = arcCts;
|
|
1169
|
-
if (layout.lines.length > 0 && !isValidTextLayoutSnapshot(out)) {
|
|
1170
|
-
// 盘上三件可能是 fabric 运行时形态(textLines: string[][] / charBounds 空)——
|
|
1171
|
-
// SVG 序列化器要的是快照形态(string[] + 逐行 charBox + finite 行高),形状
|
|
1172
|
-
// 不合法即引擎排版派生覆写(undefined 亦然)
|
|
1173
|
-
out.textLines = layout.lines.map((l) => l.graphemes.join(''));
|
|
1174
|
-
// 行尾补 fabric 形态哨兵盒(零宽,left=ΣkernedWidth):fabric __charBounds
|
|
1175
|
-
// 每行比 grapheme 多一个行末游标盒(_measureLine 落位),引擎 boxes 无此
|
|
1176
|
-
// 哨兵。下游按 fabric 形态消费 boxes[end](end=段末字+1)——PDF 导出划重点
|
|
1177
|
-
// 的尾段高亮(isSingle 逐字圈点,如「yft你好」的「你好」粉圈)缺哨兵即被
|
|
1178
|
-
// undefined 守卫整段跳过;行宽推导(lastBox.left+width)在末字
|
|
1179
|
-
// kernedWidth≠width 时也偏离 fabric 口径
|
|
1180
|
-
out.charBounds = layout.lines.map((l) => {
|
|
1181
|
-
const boxes = l.boxes.map((b) => ({ left: b.left, width: b.width, kernedWidth: b.kernedWidth, height: b.height }));
|
|
1182
|
-
if (boxes.length > 0) {
|
|
1183
|
-
const kernedSum = boxes.reduce((sum, b) => sum + (b.kernedWidth || 0), 0);
|
|
1184
|
-
boxes.push({ left: kernedSum, width: 0, kernedWidth: 0, height: boxes[boxes.length - 1].height });
|
|
1185
|
-
}
|
|
1186
|
-
return boxes;
|
|
1187
|
-
});
|
|
1188
|
-
out.lineHeights = layout.lines.map((l) => l.implHeight * lineHeight);
|
|
1189
|
-
}
|
|
1190
|
-
// styles 出向 = 应用持久化游程数组(Textbox.toObject 同源——persisted JSON/
|
|
1191
|
-
// 历史快照/跨模式装载口径不变;raw 内的对象形态不外泄,批次 34)
|
|
1192
|
-
const raw = this.node.raw;
|
|
1193
|
-
out.styles = this.stylesToPersistForm(out.styles, typeof raw.text === 'string' ? raw.text : '');
|
|
1194
|
-
}
|
|
1195
|
-
if (propertiesToInclude?.length) {
|
|
1196
|
-
const raw = this.node.raw;
|
|
1197
|
-
const target = out;
|
|
1198
|
-
for (const key of propertiesToInclude) {
|
|
1199
|
-
if (target[key] === undefined && raw[key] !== undefined)
|
|
1200
|
-
target[key] = raw[key];
|
|
1201
|
-
}
|
|
1202
|
-
}
|
|
1203
|
-
return out;
|
|
1204
|
-
}
|
|
1205
|
-
// —— 引擎派生量的虚拟读位(raw 里没有)——
|
|
1206
|
-
get id() {
|
|
1207
|
-
return this.node.id;
|
|
1208
|
-
}
|
|
1209
|
-
/** fabric 对象的 canvas 读位(useCanvas pathCreatedHandler 以
|
|
1210
|
-
* path.canvas._objects.indexOf(path) 取图层索引——fabric 侧是宿主画布注入;
|
|
1211
|
-
* 组内成员的 canvas 语义差异登记:fabric 是父 Group,本层恒顶层视角返回
|
|
1212
|
-
* 所属 compat 画布,绘制产物均为顶层对象不受影响)。返回型=宿主画布鸭子
|
|
1213
|
-
* (方法全可选——宿主 compat 画布天然满足;桩宿主 getCanvas 缺省 undefined),
|
|
1214
|
-
* 消费面 requestRenderAll/invalidateGeometryCaches 等可选链直调 */
|
|
1215
|
-
get canvas() {
|
|
1216
|
-
return this.ctx.getCanvas?.();
|
|
1217
|
-
}
|
|
1218
|
-
/** fabric 对象的 group 读位(useToolbarMaskActions 蒙版工具栏的拼图 OUTSIDE 链
|
|
1219
|
-
* 消费 element.group?.type === PUZZLE):直属父组包装——fabric 语义=立即父
|
|
1220
|
-
* Group(嵌套组返回中间组而非顶组);顶层/不在组内 undefined(fabric 同款
|
|
1221
|
-
* 缺席语义)。引擎节点无父指针,自场景树顶向下找 children 直含本节点的
|
|
1222
|
-
* GroupNode(文档树量级小,拖拽逐帧读可承受;批次 136 勘注④的缺口收口) */
|
|
1223
|
-
get group() {
|
|
1224
|
-
const canvas = this.ctx.getCanvas?.();
|
|
1225
|
-
const parent = findParentGroupOf(canvas?.document, this.node);
|
|
1226
|
-
return parent ? this.ctx.wrapNode(parent) : undefined;
|
|
1227
|
-
}
|
|
1228
|
-
/** fabric 对象的 topGroup 读位(fabricStore.setActivePoint 的 Toolbar 浮动定位
|
|
1229
|
-
* 消费——组内下钻态工具栏按整组包围盒定位;fabric 侧是组合约定挂的
|
|
1230
|
-
* child.topGroup,引擎等价=沿父组链派生最外层 GroupNode):与 group 读位同走
|
|
1231
|
-
* 场景树查找,逐层上溯到顶;顶层自身/不在组内 undefined(fabric 同款缺席)。
|
|
1232
|
-
* 包装经 ctx.wrapNode 恒等复用;应用侧写点(bindTopGroupForChildren 等
|
|
1233
|
-
* 组合链 topGroup=)落 getter-only 访问器被静默吞——派生读位不需写入 */
|
|
1234
|
-
get topGroup() {
|
|
1235
|
-
const canvas = this.ctx.getCanvas?.();
|
|
1236
|
-
let top;
|
|
1237
|
-
let current = this.node;
|
|
1238
|
-
for (;;) {
|
|
1239
|
-
const parent = findParentGroupOf(canvas?.document, current);
|
|
1240
|
-
if (!parent)
|
|
1241
|
-
break;
|
|
1242
|
-
top = parent;
|
|
1243
|
-
current = parent;
|
|
1244
|
-
}
|
|
1245
|
-
return top ? this.ctx.wrapNode(top) : undefined;
|
|
1246
|
-
}
|
|
1247
|
-
/** fabric 对象的 parent 读位(Toolbar.handleElement 的 GROUP/TABLE 判定——组内
|
|
1248
|
-
* 下钻态工具栏出示解组按钮、main.setCanvasObject 表格子早退、Layer 拖拽容器
|
|
1249
|
-
* 兜底消费):直属父组包装,顶层/不在组内 undefined(fabric 语义 parent=直属
|
|
1250
|
-
* 容器,顶层对象不挂)。与 group 读位同源同值——引擎场景直属容器即父组,
|
|
1251
|
-
* 项目消费面无两读位分化用例 */
|
|
1252
|
-
get parent() {
|
|
1253
|
-
return this.group;
|
|
1254
|
-
}
|
|
1255
|
-
/** 应用 FabricPuzzle.applyMaskParams(批次 142):右栏 PuzzleStylePanel 形状滑杆
|
|
1256
|
-
* 的消费面——此前 compat 无此方法(Proxy 直通 raw 取 undefined),面板守卫
|
|
1257
|
-
* `if (g && g.applyMaskParams)` 恒假=每个拼图的面板操作全静默 no-op。非拼图
|
|
1258
|
-
* undefined(fabric 平面对象同款缺席) */
|
|
1259
|
-
get applyMaskParams() {
|
|
1260
|
-
if (!(this.node instanceof PuzzleNode))
|
|
1261
|
-
return undefined;
|
|
1262
|
-
return (params) => {
|
|
1263
|
-
;
|
|
1264
|
-
this.node.applyMaskParams(params);
|
|
1265
|
-
this.ctx.getCanvas?.()?.requestRenderAll?.();
|
|
1266
|
-
};
|
|
1267
|
-
}
|
|
1268
|
-
/** 应用 FabricPuzzle.updateGapParams(批次 142):右栏间距滑杆消费面(同上守卫
|
|
1269
|
-
* 病根);引擎实现=写间距字段+按新 layoutParams 全量重摆 */
|
|
1270
|
-
get updateGapParams() {
|
|
1271
|
-
if (!(this.node instanceof PuzzleNode))
|
|
1272
|
-
return undefined;
|
|
1273
|
-
return (params) => {
|
|
1274
|
-
;
|
|
1275
|
-
this.node.updateGapParams(params);
|
|
1276
|
-
this.ctx.getCanvas?.()?.requestRenderAll?.();
|
|
1277
|
-
};
|
|
1278
|
-
}
|
|
1279
|
-
/** 应用 FabricPuzzle.updateLayout(批次 313):右栏「适应画板尺度」按钮消费面
|
|
1280
|
-
* ——PuzzleStylePanel handleAdaptToCanvasSize 的 `updateLayout?.()` 可选链
|
|
1281
|
-
* 守卫此前恒跳过=按钮只重置 scale/angle 居中,块不随画板尺寸重摆(视觉
|
|
1282
|
-
* 「没生效」)。引擎实现=PuzzleNode.updateLayout(relayoutFromConfig 同公式
|
|
1283
|
-
* 全量重摆+组宽高落盘)。非拼图 undefined(fabric 平面对象同款缺席) */
|
|
1284
|
-
get updateLayout() {
|
|
1285
|
-
if (!(this.node instanceof PuzzleNode))
|
|
1286
|
-
return undefined;
|
|
1287
|
-
return (params) => {
|
|
1288
|
-
;
|
|
1289
|
-
this.node.updateLayout(params);
|
|
1290
|
-
this.ctx.getCanvas?.()?.requestRenderAll?.();
|
|
1291
|
-
};
|
|
1292
|
-
}
|
|
1293
|
-
get visible() {
|
|
1294
|
-
return this.node.visible;
|
|
1295
|
-
}
|
|
1296
|
-
/** fabric 图层面板/右栏显隐直写位(useHandleElement.visibleElement 的
|
|
1297
|
-
* element.visible = !element.visible):getter-only 会被 wrapCompatObject
|
|
1298
|
-
* 的 Proxy set 陷阱静默吞掉(key in target 命中原型访问器 → Reflect.set
|
|
1299
|
-
* 假成功,同 opacity 注释)——落 set({visible}) 走引擎失效链(raw 落盘 +
|
|
1300
|
-
* 命中索引按 visible 重建 + 重绘;renderSceneNode/containsPoint 均按
|
|
1301
|
-
* node.visible 跳过)。fabricMaskPromote 的 mask.visible 直写同汇此口 */
|
|
1302
|
-
set visible(v) {
|
|
1303
|
-
this.set({ visible: v });
|
|
1304
|
-
}
|
|
1305
|
-
/** fabric opacity 是 stateProperties:对象上恒有值(缺省 1,toObject 恒出),面板
|
|
1306
|
-
* ElementOpacity 直读 el.opacity 喂 SliderInput(Number prop)。引擎 raw 缺省不
|
|
1307
|
-
* 落盘(renderOpacity 同为 ?? 1 汇聚口径),Proxy 直通会读到 undefined——触发
|
|
1308
|
-
* Vue prop 告警 + 数值框显 0(displayValue 对 undefined 兜 0)。setter 承接
|
|
1309
|
-
* ToolBorder 边框色的 element.opacity = a 直写位(getter-only 会被 Proxy set
|
|
1310
|
-
* 陷阱静默吞掉——原型访问器无 setter 时 Reflect.set 假成功) */
|
|
1311
|
-
get opacity() {
|
|
1312
|
-
const v = this.node.raw.opacity;
|
|
1313
|
-
return typeof v === 'number' ? v : 1;
|
|
1314
|
-
}
|
|
1315
|
-
set opacity(v) {
|
|
1316
|
-
this.set({ opacity: v });
|
|
1317
|
-
}
|
|
1318
|
-
/** strokeWidth 同 opacity 的缺省读位(fabric 缺省 1),且是 PathStylePanel/
|
|
1319
|
-
* LineStylePanel 的 v-model 直读直写位——SliderInput Number prop 缺键即告警,
|
|
1320
|
-
* 直写必须 setter 成对(吞写即滑杆失灵),引擎 raw 缺键 population=存量模板
|
|
1321
|
-
* JSON(建形配置全量带键) */
|
|
1322
|
-
get strokeWidth() {
|
|
1323
|
-
const v = this.node.raw.strokeWidth;
|
|
1324
|
-
return typeof v === 'number' ? v : 1;
|
|
1325
|
-
}
|
|
1326
|
-
set strokeWidth(v) {
|
|
1327
|
-
this.set({ strokeWidth: v });
|
|
1328
|
-
}
|
|
1329
|
-
// —— fabric 位图缓存生命周期(objectCaching 缓存画布,批次 33):引擎无对象级
|
|
1330
|
-
// 位图缓存(纹理直渲 + GLTextureCache 按元素缓存),no-op 保留签名——ToolStroke
|
|
1331
|
-
// 启用描边 / EffectStylePanel 描边对齐三分支无守卫直调,缺席即 TypeError 打断
|
|
1332
|
-
// 后续重渲与入史 ——
|
|
1333
|
-
_createCacheCanvas() { }
|
|
1334
|
-
_removeCacheCanvas() { }
|
|
1335
|
-
get isEditing() {
|
|
1336
|
-
return this.ctx.isEditingNode(this.node);
|
|
1337
|
-
}
|
|
1338
|
-
enterEditing() {
|
|
1339
|
-
if (this.node.isTextType)
|
|
1340
|
-
this.ctx.enterNodeEditing(this.node);
|
|
1341
|
-
return this;
|
|
1342
|
-
}
|
|
1343
|
-
exitEditing() {
|
|
1344
|
-
this.ctx.exitEditing();
|
|
1345
|
-
return this;
|
|
1346
|
-
}
|
|
1347
|
-
// —— z 序与增删(fabric 对象方法委托给画布)——
|
|
1348
|
-
bringToFront() {
|
|
1349
|
-
this.ctx.bringToFront(this.node);
|
|
1350
|
-
}
|
|
1351
|
-
sendToBack() {
|
|
1352
|
-
this.ctx.sendToBack(this.node);
|
|
1353
|
-
}
|
|
1354
|
-
bringForward() {
|
|
1355
|
-
this.ctx.bringForward(this.node);
|
|
1356
|
-
}
|
|
1357
|
-
sendBackwards() {
|
|
1358
|
-
this.ctx.sendBackwards(this.node);
|
|
1359
|
-
}
|
|
1360
|
-
moveTo(index) {
|
|
1361
|
-
this.ctx.moveNodeTo(this.node, index);
|
|
1362
|
-
}
|
|
1363
|
-
remove() {
|
|
1364
|
-
this.ctx.removeNode(this.node);
|
|
1365
|
-
}
|
|
1366
|
-
// —— 路径族锚点编辑面(P4-7):getter 按节点类型条件暴露——应用
|
|
1367
|
-
// canEditShape/isFabricPath 以 `typeof changeControls === 'function'` 等
|
|
1368
|
-
// 方法存在性判(PathStylePanel),非路径族必须取到 undefined 保持按钮隐藏 ——
|
|
1369
|
-
get changeControls() {
|
|
1370
|
-
if (!pathEditKindOf(this.node))
|
|
1371
|
-
return undefined;
|
|
1372
|
-
return (status, _reselect = true) => {
|
|
1373
|
-
this.ctx.changeNodeControls(this.node, status);
|
|
1374
|
-
};
|
|
1375
|
-
}
|
|
1376
|
-
get isEditingPath() {
|
|
1377
|
-
return this.ctx.isPathEditingNode(this.node);
|
|
1378
|
-
}
|
|
1379
|
-
get setAnchorPointType() {
|
|
1380
|
-
if (pathEditKindOf(this.node) !== 'path')
|
|
1381
|
-
return undefined;
|
|
1382
|
-
return (index, type) => this.ctx.setNodeAnchorType(this.node, index, type);
|
|
1383
|
-
}
|
|
1384
|
-
get getActiveAnchorKey() {
|
|
1385
|
-
if (!pathEditKindOf(this.node))
|
|
1386
|
-
return undefined;
|
|
1387
|
-
return () => this.ctx.getNodePathEditInfo(this.node)?.activeAnchorKey;
|
|
1388
|
-
}
|
|
1389
|
-
get getActiveAnchorIndex() {
|
|
1390
|
-
if (!pathEditKindOf(this.node))
|
|
1391
|
-
return undefined;
|
|
1392
|
-
return () => this.ctx.getNodePathEditInfo(this.node)?.activeAnchorIndex;
|
|
1393
|
-
}
|
|
1394
|
-
/** 指令风格读位不依赖会话(fabric 同:直接读 path 指令) */
|
|
1395
|
-
get getAnchorPointStyleByIndex() {
|
|
1396
|
-
if (pathEditKindOf(this.node) !== 'path')
|
|
1397
|
-
return undefined;
|
|
1398
|
-
return (index) => anchorStyleAt(parsePathData(this.node.raw.path), index);
|
|
1399
|
-
}
|
|
1400
|
-
get highlightAnchor() {
|
|
1401
|
-
if (!pathEditKindOf(this.node))
|
|
1402
|
-
return undefined;
|
|
1403
|
-
return (anchorKey) => {
|
|
1404
|
-
this.ctx.highlightNodeAnchor(this.node, anchorKey);
|
|
1405
|
-
};
|
|
1406
|
-
}
|
|
1407
|
-
get resetAnchorStyles() {
|
|
1408
|
-
if (!pathEditKindOf(this.node))
|
|
1409
|
-
return undefined;
|
|
1410
|
-
return () => {
|
|
1411
|
-
this.ctx.resetNodeAnchorStyles(this.node);
|
|
1412
|
-
};
|
|
1413
|
-
}
|
|
1414
|
-
}
|
|
1415
|
-
// —— 蒙版 clipImage 子对象面(引擎侧是 raw 序列化声明,fabric 是独立图像实例;
|
|
1416
|
-
// MaskNode.clipImageRaw 同口径:无 src 的坏声明按无填充图处理)——
|
|
1417
|
-
/** clipImage 序列化声明读位(非 Mask 节点/坏声明 null——type 两形态同 isImageLikeNode 口径) */
|
|
1418
|
-
const clipImageRawOf = (node) => {
|
|
1419
|
-
const raw = node.raw;
|
|
1420
|
-
if (!MASK_TYPES.has(typeKeyOf(raw)))
|
|
1421
|
-
return null;
|
|
1422
|
-
const c = raw.clipImage;
|
|
1423
|
-
if (!c || typeof c !== 'object' || typeof c.src !== 'string')
|
|
1424
|
-
return null;
|
|
1425
|
-
return c;
|
|
1426
|
-
};
|
|
1427
|
-
/** fabric 渲染缓存/引用键:吞掉不入序列化(_cacheCanvas 合成缓存、dirty 渲染提示
|
|
1428
|
-
* ——setNodeProps 吞 dirty 同口径、canvas 画布引用非数据) */
|
|
1429
|
-
const CLIP_IMAGE_CACHE_KEYS = new Set(['_cacheCanvas', 'dirty', 'canvas']);
|
|
1430
|
-
/** clipImage 的 fabric 习惯包装:具名三件(set/toObject/setCoords),其余属性 Proxy
|
|
1431
|
-
* 直通 raw(getElementOriginalSize/calculateClipImageScale 的 width/scaleX 读位) */
|
|
1432
|
-
class CompatClipImage {
|
|
1433
|
-
node;
|
|
1434
|
-
ctx;
|
|
1435
|
-
constructor(node, ctx) {
|
|
1436
|
-
this.node = node;
|
|
1437
|
-
this.ctx = ctx;
|
|
1438
|
-
}
|
|
1439
|
-
/** fabric set:过滤缓存键后 {...raw, ...props} 整体写回(引擎 node.set 对
|
|
1440
|
-
* clipImage 是顶层替换——scene.ts relayoutFromConfig 同款手动展开先例;
|
|
1441
|
-
* maskRender 烘焙签名内含 clip.scaleX/scaleY,改缩放自然重烘) */
|
|
1442
|
-
set(props) {
|
|
1443
|
-
const raw = clipImageRawOf(this.node);
|
|
1444
|
-
if (!raw)
|
|
1445
|
-
return this;
|
|
1446
|
-
const merged = { ...raw };
|
|
1447
|
-
for (const [key, value] of Object.entries(props)) {
|
|
1448
|
-
if (CLIP_IMAGE_CACHE_KEYS.has(key))
|
|
1449
|
-
continue;
|
|
1450
|
-
merged[key] = value;
|
|
1451
|
-
}
|
|
1452
|
-
this.ctx.setNodeProps(this.node, { clipImage: merged });
|
|
1453
|
-
return this;
|
|
1454
|
-
}
|
|
1455
|
-
/** fabric toObject:序列化浅拷贝(取消蒙版分支 createClipClone 的入参形态) */
|
|
1456
|
-
toObject(_propertiesToInclude) {
|
|
1457
|
-
const raw = clipImageRawOf(this.node);
|
|
1458
|
-
return raw ? { ...raw } : {};
|
|
1459
|
-
}
|
|
1460
|
-
/** fabric setCoords:坐标缓存刷新——引擎矩阵逐帧现算,恒等空操作 */
|
|
1461
|
-
setCoords() { }
|
|
1462
|
-
/** 同应用 FabricImage.getSrc(CompatObject 同式):originalSrc 优先(换图后
|
|
1463
|
-
* 历史快照 before/after 判等),无则 src——useToolbarMaskActions 拖填充图
|
|
1464
|
-
* 的 DOM 幽灵预览图 src 读位(此前 Proxy 直通 raw 取到 undefined 调用即
|
|
1465
|
-
* TypeError 被 catch 吞——幽灵图不显示,批次 126) */
|
|
1466
|
-
getSrc() {
|
|
1467
|
-
const raw = clipImageRawOf(this.node);
|
|
1468
|
-
if (raw && typeof raw.originalSrc === 'string' && raw.originalSrc)
|
|
1469
|
-
return raw.originalSrc;
|
|
1470
|
-
return raw && typeof raw.src === 'string' ? raw.src : '';
|
|
1471
|
-
}
|
|
1472
|
-
/** 同应用 FabricImage.getOriginalElementWidth/Height:填充源自然尺寸(cover
|
|
1473
|
-
* 约束/缩放柄的「原图」基准,不随 cropX/width 缩)——源=MaskNode.clipImageEl
|
|
1474
|
-
* (批次 71/113 装载链挂载),缺席回退声明宽(toolbar 的守卫回退链同款) */
|
|
1475
|
-
getOriginalElementWidth() {
|
|
1476
|
-
const el = this.node.clipImageEl;
|
|
1477
|
-
return el?.naturalWidth || el?.width || Number(clipImageRawOf(this.node)?.width) || 0;
|
|
1478
|
-
}
|
|
1479
|
-
getOriginalElementHeight() {
|
|
1480
|
-
const el = this.node.clipImageEl;
|
|
1481
|
-
return el?.naturalHeight || el?.height || Number(clipImageRawOf(this.node)?.height) || 0;
|
|
1482
|
-
}
|
|
1483
|
-
}
|
|
1484
|
-
/** 场景树中找节点的直属父组(引擎节点无父指针——自顶向下找 children 直含;
|
|
1485
|
-
* 组包装 group 读位与 compat remove 的组内子摘除共用,批次 141 抽出) */
|
|
1486
|
-
export const findParentGroupOf = (doc, node) => {
|
|
1487
|
-
if (!doc)
|
|
1488
|
-
return undefined;
|
|
1489
|
-
const walk = (nodes) => {
|
|
1490
|
-
for (const n of nodes) {
|
|
1491
|
-
if (!(n instanceof GroupNode))
|
|
1492
|
-
continue;
|
|
1493
|
-
if (n.children.some((c) => c === node))
|
|
1494
|
-
return n;
|
|
1495
|
-
const deep = walk(n.children);
|
|
1496
|
-
if (deep)
|
|
1497
|
-
return deep;
|
|
1498
|
-
}
|
|
1499
|
-
return undefined;
|
|
1500
|
-
};
|
|
1501
|
-
return walk(doc.nodes);
|
|
1502
|
-
};
|
|
1503
|
-
/** clipImage 包装:具名方法优先,其余属性直通 raw(wrapCompatObject 同构) */
|
|
1504
|
-
const wrapClipImage = (node, ctx) => {
|
|
1505
|
-
const base = new CompatClipImage(node, ctx);
|
|
1506
|
-
return new Proxy(base, {
|
|
1507
|
-
get(target, key, receiver) {
|
|
1508
|
-
if (typeof key === 'symbol')
|
|
1509
|
-
return Reflect.get(target, key, receiver);
|
|
1510
|
-
if (key === 'then')
|
|
1511
|
-
return undefined;
|
|
1512
|
-
if (key in target)
|
|
1513
|
-
return Reflect.get(target, key, receiver);
|
|
1514
|
-
const raw = clipImageRawOf(target.node);
|
|
1515
|
-
return raw ? raw[key] : undefined;
|
|
1516
|
-
},
|
|
1517
|
-
set(target, key, value, receiver) {
|
|
1518
|
-
if (typeof key === 'symbol' || key in target) {
|
|
1519
|
-
Reflect.set(target, key, value, receiver);
|
|
1520
|
-
return true;
|
|
1521
|
-
}
|
|
1522
|
-
target.set({ [key]: value });
|
|
1523
|
-
return true;
|
|
1524
|
-
}
|
|
1525
|
-
});
|
|
1526
|
-
};
|
|
1527
|
-
// 批次 41:fabric Table 应用侧消费族(选区查询/结构算子/样式/尺寸/cell-text 门面)
|
|
1528
|
-
// 挂原型——Proxy get 的 `key in target` 命中原型链,非表格节点方法自守卫缺席语义
|
|
1529
|
-
attachTableFacade(CompatObject.prototype);
|
|
1530
|
-
/** fabric Path._calcDimensions 的口径体(批次 105 实例方法位):序列化 raw 直读,
|
|
1531
|
-
* pathOffset 缺失回落 bbox 中心 */
|
|
1532
|
-
const pathCalcDimensionsOf = (node) => {
|
|
1533
|
-
const raw = node.raw;
|
|
1534
|
-
const width = typeof raw.width === 'number' ? raw.width : node.dims.x;
|
|
1535
|
-
const height = typeof raw.height === 'number' ? raw.height : node.dims.y;
|
|
1536
|
-
const offset = raw.pathOffset;
|
|
1537
|
-
return {
|
|
1538
|
-
left: typeof raw.left === 'number' ? raw.left : 0,
|
|
1539
|
-
top: typeof raw.top === 'number' ? raw.top : 0,
|
|
1540
|
-
width,
|
|
1541
|
-
height,
|
|
1542
|
-
pathOffset: {
|
|
1543
|
-
x: typeof offset?.x === 'number' ? offset.x : width / 2,
|
|
1544
|
-
y: typeof offset?.y === 'number' ? offset.y : height / 2
|
|
1545
|
-
}
|
|
1546
|
-
};
|
|
1547
|
-
};
|
|
1548
|
-
/** SceneNode → fabric 习惯对象:具名方法优先,其余属性直通 raw */
|
|
1549
|
-
export const wrapCompatObject = (node, ctx) => {
|
|
1550
|
-
const base = new CompatObject(node, ctx);
|
|
1551
|
-
// _calcDimensions 实例方法位(批次 105):仅 PathNode 挂载——declare 字段
|
|
1552
|
-
// 类型不落运行时属性,非路径包装 `'_calcDimensions' in base` 为 false,Proxy
|
|
1553
|
-
// 直通 raw 恒 undefined(fabric 非路径对象同款 duck 缺席语义)
|
|
1554
|
-
if (node instanceof PathNode) {
|
|
1555
|
-
base._calcDimensions = () => pathCalcDimensionsOf(node);
|
|
1556
|
-
}
|
|
1557
|
-
return new Proxy(base, {
|
|
1558
|
-
get(target, key, receiver) {
|
|
1559
|
-
if (typeof key === 'symbol')
|
|
1560
|
-
return Reflect.get(target, key, receiver);
|
|
1561
|
-
// Promise 化检测守卫:then 走直通会被误当 thenable,await 一个包装对象会挂死
|
|
1562
|
-
if (key === 'then')
|
|
1563
|
-
return undefined;
|
|
1564
|
-
if (key in target)
|
|
1565
|
-
return Reflect.get(target, key, receiver);
|
|
1566
|
-
const raw = target.node.raw;
|
|
1567
|
-
return raw[key];
|
|
1568
|
-
},
|
|
1569
|
-
set(target, key, value, receiver) {
|
|
1570
|
-
if (typeof key === 'symbol') {
|
|
1571
|
-
Reflect.set(target, key, value, receiver);
|
|
1572
|
-
return true;
|
|
1573
|
-
}
|
|
1574
|
-
// 类自身字段(node)不外写;其余一律按属性写入走引擎失效链
|
|
1575
|
-
if (key in target) {
|
|
1576
|
-
Reflect.set(target, key, value, receiver);
|
|
1577
|
-
return true;
|
|
1578
|
-
}
|
|
1579
|
-
target.set({ [key]: value });
|
|
1580
|
-
return true;
|
|
1581
|
-
}
|
|
1582
|
-
});
|
|
1583
|
-
};
|