@yft-design/engine 0.0.0-stage → 0.0.2

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 (255) hide show
  1. package/README.md +39 -2
  2. package/assets/images/greyfloral.png +0 -0
  3. package/assets/images/honey_im_subtle.png +0 -0
  4. package/assets/images/nasty_fabric.png +0 -0
  5. package/assets/images/retina_wood.png +0 -0
  6. package/assets/images/rotate.png +0 -0
  7. package/dist/EngineCanvas.d.ts +500 -0
  8. package/dist/EngineCanvas.js +927 -0
  9. package/dist/core/canvasPerf.d.ts +23 -0
  10. package/dist/core/canvasPerf.js +170 -0
  11. package/dist/core/color.d.ts +52 -0
  12. package/dist/core/color.js +107 -0
  13. package/dist/core/distanceField.d.ts +15 -0
  14. package/dist/core/distanceField.js +92 -0
  15. package/dist/core/events.d.ts +34 -0
  16. package/dist/core/events.js +52 -0
  17. package/dist/core/gradient.d.ts +97 -0
  18. package/dist/core/gradient.js +175 -0
  19. package/dist/core/imageFilters.d.ts +150 -0
  20. package/dist/core/imageFilters.js +330 -0
  21. package/dist/core/mat2d.d.ts +151 -0
  22. package/dist/core/mat2d.js +241 -0
  23. package/dist/core/pathData.d.ts +53 -0
  24. package/dist/core/pathData.js +926 -0
  25. package/dist/core/pattern.d.ts +38 -0
  26. package/dist/core/pattern.js +40 -0
  27. package/dist/core/point.d.ts +59 -0
  28. package/dist/core/point.js +119 -0
  29. package/dist/core/psdEffects.d.ts +126 -0
  30. package/dist/core/psdEffects.js +158 -0
  31. package/dist/core/roundedRect.d.ts +62 -0
  32. package/dist/core/roundedRect.js +163 -0
  33. package/dist/core/shadow.d.ts +51 -0
  34. package/dist/core/shadow.js +47 -0
  35. package/dist/core/snap.d.ts +232 -0
  36. package/dist/core/snap.js +793 -0
  37. package/dist/core/stroke.d.ts +41 -0
  38. package/dist/core/stroke.js +44 -0
  39. package/dist/core/triangulate.d.ts +24 -0
  40. package/dist/core/triangulate.js +118 -0
  41. package/dist/debug/canvasInspection.d.ts +92 -0
  42. package/dist/debug/canvasInspection.js +113 -0
  43. package/dist/debug/pixelDiff.d.ts +22 -0
  44. package/dist/debug/pixelDiff.js +64 -0
  45. package/dist/debug/seed.d.ts +473 -0
  46. package/dist/debug/seed.js +3803 -0
  47. package/dist/decoders/gif2sprite.d.ts +9 -0
  48. package/dist/decoders/gif2sprite.js +84 -0
  49. package/dist/decoders/webp2sprite.d.ts +22 -0
  50. package/dist/decoders/webp2sprite.js +133 -0
  51. package/dist/engineFlag.d.ts +72 -0
  52. package/dist/engineFlag.js +86 -0
  53. package/dist/export/SceneExporter.d.ts +92 -0
  54. package/dist/export/SceneExporter.js +280 -0
  55. package/dist/export/glExport.d.ts +66 -0
  56. package/dist/export/glExport.js +79 -0
  57. package/dist/export/svgExport.d.ts +277 -0
  58. package/dist/export/svgExport.js +1790 -0
  59. package/dist/index.d.ts +52 -0
  60. package/dist/index.js +48 -0
  61. package/dist/interact/animationPlayback.d.ts +125 -0
  62. package/dist/interact/animationPlayback.js +344 -0
  63. package/dist/interact/canvasInteractions.d.ts +50 -0
  64. package/dist/interact/canvasInteractions.js +150 -0
  65. package/dist/interact/cropSession.d.ts +123 -0
  66. package/dist/interact/cropSession.js +526 -0
  67. package/dist/interact/dblClick.d.ts +51 -0
  68. package/dist/interact/dblClick.js +106 -0
  69. package/dist/interact/expandSession.d.ts +107 -0
  70. package/dist/interact/expandSession.js +281 -0
  71. package/dist/interact/hotkeyActions.d.ts +16 -0
  72. package/dist/interact/hotkeyActions.js +41 -0
  73. package/dist/interact/pathSession.d.ts +141 -0
  74. package/dist/interact/pathSession.js +480 -0
  75. package/dist/interact/pointer.d.ts +106 -0
  76. package/dist/interact/pointer.js +1594 -0
  77. package/dist/interact/pointerTablePuzzle.d.ts +100 -0
  78. package/dist/interact/pointerTablePuzzle.js +358 -0
  79. package/dist/interact/pointerTransform.d.ts +86 -0
  80. package/dist/interact/pointerTransform.js +440 -0
  81. package/dist/interact/pointerTypes.d.ts +577 -0
  82. package/dist/interact/pointerTypes.js +96 -0
  83. package/dist/interact/snapGuide.d.ts +127 -0
  84. package/dist/interact/snapGuide.js +376 -0
  85. package/dist/interact/tableCellEditing.d.ts +61 -0
  86. package/dist/interact/tableCellEditing.js +198 -0
  87. package/dist/interact/tableInteraction.d.ts +55 -0
  88. package/dist/interact/tableInteraction.js +212 -0
  89. package/dist/interact/textEditing.d.ts +77 -0
  90. package/dist/interact/textEditing.js +410 -0
  91. package/dist/interact/warpFacade.d.ts +36 -0
  92. package/dist/interact/warpFacade.js +51 -0
  93. package/dist/interact/warpSession.d.ts +191 -0
  94. package/dist/interact/warpSession.js +582 -0
  95. package/dist/interact/wheelScroll.d.ts +62 -0
  96. package/dist/interact/wheelScroll.js +72 -0
  97. package/dist/model/alphaHit.d.ts +59 -0
  98. package/dist/model/alphaHit.js +262 -0
  99. package/dist/model/animation.d.ts +228 -0
  100. package/dist/model/animation.js +510 -0
  101. package/dist/model/arcLayout.d.ts +54 -0
  102. package/dist/model/arcLayout.js +307 -0
  103. package/dist/model/arcTextTransform.d.ts +7 -0
  104. package/dist/model/arcTextTransform.js +87 -0
  105. package/dist/model/compatEvents.d.ts +135 -0
  106. package/dist/model/compatEvents.js +73 -0
  107. package/dist/model/compatObject.d.ts +716 -0
  108. package/dist/model/compatObject.js +1579 -0
  109. package/dist/model/cropEdit.d.ts +118 -0
  110. package/dist/model/cropEdit.js +497 -0
  111. package/dist/model/document.d.ts +294 -0
  112. package/dist/model/document.js +572 -0
  113. package/dist/model/expandEdit.d.ts +93 -0
  114. package/dist/model/expandEdit.js +161 -0
  115. package/dist/model/fabricPrimitives.d.ts +156 -0
  116. package/dist/model/fabricPrimitives.js +9 -0
  117. package/dist/model/filler.d.ts +53 -0
  118. package/dist/model/filler.js +1 -0
  119. package/dist/model/groupAssemble.d.ts +7 -0
  120. package/dist/model/groupAssemble.js +98 -0
  121. package/dist/model/groupChildMove.d.ts +46 -0
  122. package/dist/model/groupChildMove.js +145 -0
  123. package/dist/model/groupResize.d.ts +78 -0
  124. package/dist/model/groupResize.js +108 -0
  125. package/dist/model/handles.d.ts +40 -0
  126. package/dist/model/handles.js +29 -0
  127. package/dist/model/imageMaskBake.d.ts +75 -0
  128. package/dist/model/imageMaskBake.js +136 -0
  129. package/dist/model/lineConstruct.d.ts +13 -0
  130. package/dist/model/lineConstruct.js +79 -0
  131. package/dist/model/maskCropEdit.d.ts +64 -0
  132. package/dist/model/maskCropEdit.js +90 -0
  133. package/dist/model/pathBackground.d.ts +51 -0
  134. package/dist/model/pathBackground.js +196 -0
  135. package/dist/model/pathConstruct.d.ts +27 -0
  136. package/dist/model/pathConstruct.js +55 -0
  137. package/dist/model/pathEdit.d.ts +114 -0
  138. package/dist/model/pathEdit.js +378 -0
  139. package/dist/model/puzzleEdit.d.ts +136 -0
  140. package/dist/model/puzzleEdit.js +742 -0
  141. package/dist/model/puzzleLayout.d.ts +91 -0
  142. package/dist/model/puzzleLayout.js +143 -0
  143. package/dist/model/scene.d.ts +1004 -0
  144. package/dist/model/scene.js +2841 -0
  145. package/dist/model/schema.d.ts +290 -0
  146. package/dist/model/schema.js +13 -0
  147. package/dist/model/shapePath.d.ts +14 -0
  148. package/dist/model/shapePath.js +136 -0
  149. package/dist/model/tableEdit.d.ts +196 -0
  150. package/dist/model/tableEdit.js +751 -0
  151. package/dist/model/tableFacade.d.ts +6 -0
  152. package/dist/model/tableFacade.js +808 -0
  153. package/dist/model/tableLayout.d.ts +85 -0
  154. package/dist/model/tableLayout.js +193 -0
  155. package/dist/model/textLayout.d.ts +357 -0
  156. package/dist/model/textLayout.js +822 -0
  157. package/dist/render/GLBlend.d.ts +40 -0
  158. package/dist/render/GLBlend.js +270 -0
  159. package/dist/render/GLContext.d.ts +25 -0
  160. package/dist/render/GLContext.js +48 -0
  161. package/dist/render/GLIsolate.d.ts +46 -0
  162. package/dist/render/GLIsolate.js +188 -0
  163. package/dist/render/GLTextureCache.d.ts +86 -0
  164. package/dist/render/GLTextureCache.js +187 -0
  165. package/dist/render/GlyphAtlas.d.ts +151 -0
  166. package/dist/render/GlyphAtlas.js +404 -0
  167. package/dist/render/MeshBatch.d.ts +123 -0
  168. package/dist/render/MeshBatch.js +416 -0
  169. package/dist/render/QuadBatch.d.ts +138 -0
  170. package/dist/render/QuadBatch.js +490 -0
  171. package/dist/render/SceneRenderer.d.ts +186 -0
  172. package/dist/render/SceneRenderer.js +700 -0
  173. package/dist/render/SourceManager.d.ts +121 -0
  174. package/dist/render/SourceManager.js +505 -0
  175. package/dist/render/TextRenderer.d.ts +140 -0
  176. package/dist/render/TextRenderer.js +795 -0
  177. package/dist/render/arcText.d.ts +40 -0
  178. package/dist/render/arcText.js +187 -0
  179. package/dist/render/batchOrder.d.ts +105 -0
  180. package/dist/render/batchOrder.js +168 -0
  181. package/dist/render/blendMode.d.ts +35 -0
  182. package/dist/render/blendMode.js +142 -0
  183. package/dist/render/clipMaskPainter.d.ts +17 -0
  184. package/dist/render/clipMaskPainter.js +121 -0
  185. package/dist/render/fontInvalidation.d.ts +25 -0
  186. package/dist/render/fontInvalidation.js +77 -0
  187. package/dist/render/fontInvalidationController.d.ts +76 -0
  188. package/dist/render/fontInvalidationController.js +114 -0
  189. package/dist/render/frameOverlay.d.ts +62 -0
  190. package/dist/render/frameOverlay.js +124 -0
  191. package/dist/render/framePipeline.d.ts +99 -0
  192. package/dist/render/framePipeline.js +95 -0
  193. package/dist/render/gpuFilterPasses.d.ts +25 -0
  194. package/dist/render/gpuFilterPasses.js +883 -0
  195. package/dist/render/gpuFx.d.ts +136 -0
  196. package/dist/render/gpuFx.js +614 -0
  197. package/dist/render/gpuImageFilters.d.ts +59 -0
  198. package/dist/render/gpuImageFilters.js +289 -0
  199. package/dist/render/gpuShadow.d.ts +52 -0
  200. package/dist/render/gpuShadow.js +289 -0
  201. package/dist/render/gradientRamp.d.ts +45 -0
  202. package/dist/render/gradientRamp.js +74 -0
  203. package/dist/render/imageEffects.d.ts +123 -0
  204. package/dist/render/imageEffects.js +390 -0
  205. package/dist/render/maskRender.d.ts +92 -0
  206. package/dist/render/maskRender.js +224 -0
  207. package/dist/render/progressiveLoad.d.ts +45 -0
  208. package/dist/render/progressiveLoad.js +86 -0
  209. package/dist/render/psdEffectPainter.d.ts +34 -0
  210. package/dist/render/psdEffectPainter.js +309 -0
  211. package/dist/render/puzzleClamp.d.ts +28 -0
  212. package/dist/render/puzzleClamp.js +30 -0
  213. package/dist/render/retainedFrame.d.ts +85 -0
  214. package/dist/render/retainedFrame.js +193 -0
  215. package/dist/render/ruler.d.ts +90 -0
  216. package/dist/render/ruler.js +287 -0
  217. package/dist/render/scrollText.d.ts +65 -0
  218. package/dist/render/scrollText.js +261 -0
  219. package/dist/render/selectionOverlay.d.ts +318 -0
  220. package/dist/render/selectionOverlay.js +921 -0
  221. package/dist/render/shaders.d.ts +38 -0
  222. package/dist/render/shaders.js +314 -0
  223. package/dist/render/shadowBake.d.ts +43 -0
  224. package/dist/render/shadowBake.js +202 -0
  225. package/dist/render/shadowPainter.d.ts +13 -0
  226. package/dist/render/shadowPainter.js +80 -0
  227. package/dist/render/sharedGpuPainters.d.ts +25 -0
  228. package/dist/render/sharedGpuPainters.js +40 -0
  229. package/dist/render/sourceHydration.d.ts +12 -0
  230. package/dist/render/sourceHydration.js +48 -0
  231. package/dist/render/strokeBake.d.ts +85 -0
  232. package/dist/render/strokeBake.js +515 -0
  233. package/dist/render/strokePainter.d.ts +28 -0
  234. package/dist/render/strokePainter.js +119 -0
  235. package/dist/render/strokeSdf.d.ts +35 -0
  236. package/dist/render/strokeSdf.js +74 -0
  237. package/dist/render/svgRaster.d.ts +46 -0
  238. package/dist/render/svgRaster.js +71 -0
  239. package/dist/render/tableOverlay.d.ts +38 -0
  240. package/dist/render/tableOverlay.js +233 -0
  241. package/dist/render/textHighlight.d.ts +117 -0
  242. package/dist/render/textHighlight.js +380 -0
  243. package/dist/render/textureUpload.d.ts +18 -0
  244. package/dist/render/textureUpload.js +26 -0
  245. package/dist/render/verticalText.d.ts +38 -0
  246. package/dist/render/verticalText.js +63 -0
  247. package/dist/render/warpText.d.ts +58 -0
  248. package/dist/render/warpText.js +380 -0
  249. package/dist/render/workspaceBackdrop.d.ts +35 -0
  250. package/dist/render/workspaceBackdrop.js +71 -0
  251. package/dist/render/workspaceChecker.d.ts +54 -0
  252. package/dist/render/workspaceChecker.js +170 -0
  253. package/dist/render/workspaceGlow.d.ts +51 -0
  254. package/dist/render/workspaceGlow.js +171 -0
  255. package/package.json +44 -3
@@ -0,0 +1,85 @@
1
+ /**
2
+ * 表格布局(main-webgl2 P4-4):应用 TableLayoutStrategy 的纯函数移植。
3
+ *
4
+ * 契约:引擎不信任序列化的 objects/rowHeights——与应用 Table.fromObject 同源,
5
+ * 由 rows/cols/columnWidths/manualRowHeights/cellData 重算(两侧同策略 ⇒ 同布局)。
6
+ * 应用侧语义(源码逐行核对):
7
+ * - 行高 = max(manualRowHeights[r] ?? minCellHeight, 行内文本高 + cellPadding×2);
8
+ * 文本高 = 该格 Textbox 在 colspan 合并宽下 splitByGrapheme 排版的 calcTextHeight
9
+ * (fromObject 的 text.set 触发 initDimensions——fabric Text.set 对
10
+ * textLayoutProperties 含 width 的键自动重排,策略里的 _splitText 是幂等冗余)
11
+ * - 列宽恒按 columnWidths(序列化保留用户拖拽);content 尺寸含 (n−1)×cellSpacing
12
+ * - 单元格(合并主格)矩形与文本定位在**组中心相对空间**:中心 x = 列前缀 −
13
+ * contentWidth/2 + cellWidth/2(行向同理);文本 y 按 verticalAlign 以
14
+ * calcTextHeight 收边(top 贴上 +padding / bottom 贴底 −padding / middle 居中)
15
+ * - 组尺寸 = (contentWidth + cellStrokeWidth, contentHeight + cellStrokeWidth)
16
+ * - 合并从格(isMerged)opacity 0 不可见——引擎直接不合成(视觉等价)
17
+ *
18
+ * fromObject 摆位 quirk(必须复刻,否则整表错位):fromObject = 构造期布局
19
+ * (等列宽 + 空文本行高)→ 写 cellData → triggerLayout(imperative:以**旧宽高**
20
+ * 的组中心为锚,重设宽高后 setPositionByOrigin 回锚)。故最终 left/top ≠ 序列化
21
+ * left/top:列宽不等(Δw)或文本撑高行(Δh)时整表平移 (Δw/2, Δh/2)(带旋转)。
22
+ * 引擎在 TableNode 构造时施加同款平移;toObject 反向扣除,保证 JSON 往返
23
+ * (engine → app fromObject → 同视觉位置)自洽。
24
+ */
25
+ import { type MeasureFn } from './textLayout';
26
+ import type { SerializedNode } from './scene';
27
+ /** 应用单元格序列化条目(Table.toObject 的 cellData 元素;row/col 必有) */
28
+ export interface TableCellData {
29
+ row: number;
30
+ col: number;
31
+ fill?: string;
32
+ stroke?: string;
33
+ text?: string;
34
+ textFill?: string;
35
+ fontSize?: number;
36
+ fontWeight?: string;
37
+ fontStyle?: string;
38
+ fontFamily?: string;
39
+ textAlign?: string;
40
+ verticalAlign?: 'top' | 'middle' | 'bottom';
41
+ colspan?: number;
42
+ rowspan?: number;
43
+ isMerged?: boolean;
44
+ /** 合并从格的主格位置(P4-4b 单元格编辑) */
45
+ mergeParent?: {
46
+ row: number;
47
+ col: number;
48
+ } | null;
49
+ [key: string]: unknown;
50
+ }
51
+ export interface TableLayoutResult {
52
+ /** 最终行高(重算值——序列化 rowHeights 不作数) */
53
+ rowHeights: number[];
54
+ /** 归一列宽(缺段回退首列宽;tableView 命中数学消费) */
55
+ columnWidths: number[];
56
+ /** 行的文本需求下限(maxTextHeight + 2×cellPadding,未叠加 manual/min)——
57
+ * 行边框拖拽的 getRowMinHeight 钳制输入(P4-4b) */
58
+ rowTextFloors: number[];
59
+ contentWidth: number;
60
+ contentHeight: number;
61
+ /** 组尺寸 = content + cellStrokeWidth(应用策略 size 口径) */
62
+ width: number;
63
+ height: number;
64
+ /** 合成子节点(行主序 rect/text 交错、合并从格与空文本格跳过) */
65
+ children: SerializedNode[];
66
+ /** 构造期布局的组尺寸(摆位 quirk 输入:TableNode 以旧尺寸中心锚定换算最终
67
+ * left/top——平移随 scaleX/scaleY 缩放、随 angle 旋转,须走 mat2d 中心换算) */
68
+ constructorDims: {
69
+ width: number;
70
+ height: number;
71
+ };
72
+ }
73
+ export interface TableLayoutOptions {
74
+ /** 单元格编辑期(P4-4b(2/2)):跳过该主格的 textbox 子节点合成——应用
75
+ * startCellEditing 把格文本对象 opacity 置 0 的渲染等价物(引擎不合成即
76
+ * 不渲染);行高仍按 cellData.text 计算(布局不受编辑态影响) */
77
+ hideTextCell?: {
78
+ row: number;
79
+ col: number;
80
+ };
81
+ }
82
+ /**
83
+ * 表格布局重算。measure 仅单测注入(缺省真实 canvas 度量,与 TextNode 同源)。
84
+ */
85
+ export declare const computeTableLayout: (raw: SerializedNode, measure?: MeasureFn, opts?: TableLayoutOptions) => TableLayoutResult;
@@ -0,0 +1,193 @@
1
+ /**
2
+ * 表格布局(main-webgl2 P4-4):应用 TableLayoutStrategy 的纯函数移植。
3
+ *
4
+ * 契约:引擎不信任序列化的 objects/rowHeights——与应用 Table.fromObject 同源,
5
+ * 由 rows/cols/columnWidths/manualRowHeights/cellData 重算(两侧同策略 ⇒ 同布局)。
6
+ * 应用侧语义(源码逐行核对):
7
+ * - 行高 = max(manualRowHeights[r] ?? minCellHeight, 行内文本高 + cellPadding×2);
8
+ * 文本高 = 该格 Textbox 在 colspan 合并宽下 splitByGrapheme 排版的 calcTextHeight
9
+ * (fromObject 的 text.set 触发 initDimensions——fabric Text.set 对
10
+ * textLayoutProperties 含 width 的键自动重排,策略里的 _splitText 是幂等冗余)
11
+ * - 列宽恒按 columnWidths(序列化保留用户拖拽);content 尺寸含 (n−1)×cellSpacing
12
+ * - 单元格(合并主格)矩形与文本定位在**组中心相对空间**:中心 x = 列前缀 −
13
+ * contentWidth/2 + cellWidth/2(行向同理);文本 y 按 verticalAlign 以
14
+ * calcTextHeight 收边(top 贴上 +padding / bottom 贴底 −padding / middle 居中)
15
+ * - 组尺寸 = (contentWidth + cellStrokeWidth, contentHeight + cellStrokeWidth)
16
+ * - 合并从格(isMerged)opacity 0 不可见——引擎直接不合成(视觉等价)
17
+ *
18
+ * fromObject 摆位 quirk(必须复刻,否则整表错位):fromObject = 构造期布局
19
+ * (等列宽 + 空文本行高)→ 写 cellData → triggerLayout(imperative:以**旧宽高**
20
+ * 的组中心为锚,重设宽高后 setPositionByOrigin 回锚)。故最终 left/top ≠ 序列化
21
+ * left/top:列宽不等(Δw)或文本撑高行(Δh)时整表平移 (Δw/2, Δh/2)(带旋转)。
22
+ * 引擎在 TableNode 构造时施加同款平移;toObject 反向扣除,保证 JSON 往返
23
+ * (engine → app fromObject → 同视觉位置)自洽。
24
+ */
25
+ import { FONT_SIZE_MULT, layoutTextbox } from './textLayout';
26
+ import { buildCellMap } from './tableEdit';
27
+ /** 应用 TableDefaultOptions.fontSize——fromObject 不透传 fontSize,构造期空单元格
28
+ * 以它度量行高(摆位 quirk 的 h0 依赖;应用默认值变更时须同步此处) */
29
+ const CONSTRUCTOR_FONT_SIZE = 14;
30
+ /** 累加前缀位(应用 buildPositions:positions[0]=0,其后前位 + 尺寸 + 间距) */
31
+ const buildPositions = (count, sizes, spacing) => {
32
+ const positions = [0];
33
+ for (let i = 0; i < count - 1; i++)
34
+ positions.push(positions[i] + sizes[i] + spacing);
35
+ return positions;
36
+ };
37
+ /** colspan 跨列总宽(含中间 spacing;应用 positionCells 同式) */
38
+ const spanWidth = (start, span, sizes, spacing) => {
39
+ let w = 0;
40
+ for (let i = 0; i < span; i++) {
41
+ w += sizes[start + i] ?? 0;
42
+ if (i > 0)
43
+ w += spacing;
44
+ }
45
+ return w;
46
+ };
47
+ /**
48
+ * 表格布局重算。measure 仅单测注入(缺省真实 canvas 度量,与 TextNode 同源)。
49
+ */
50
+ export const computeTableLayout = (raw, measure, opts) => {
51
+ const rows = raw.rows ?? 3;
52
+ const cols = raw.cols ?? 3;
53
+ const columnWidthsRaw = Array.isArray(raw.columnWidths) ? raw.columnWidths : [];
54
+ const firstWidth = columnWidthsRaw[0] ?? 100;
55
+ // 列宽缺段回退首列宽(toObject 恒写全量——回退仅防手写 JSON 的 NaN)
56
+ const columnWidths = Array.from({ length: cols }, (_, i) => columnWidthsRaw[i] ?? firstWidth);
57
+ const minCellHeight = raw.minCellHeight ?? 40;
58
+ const cellPadding = raw.cellPadding ?? 8;
59
+ const cellSpacing = raw.cellSpacing ?? 0;
60
+ const cellStrokeWidth = raw.cellStrokeWidth ?? 1;
61
+ const cellFill = raw.cellFill;
62
+ const cellStroke = raw.cellStroke;
63
+ const textFillDefault = raw.textFill;
64
+ // 应用 Table.defaults.fontFamily(fromObject 不透传 fontFamily——表格级字体恒为
65
+ // 应用默认;改应用默认值时须同步此处)
66
+ const tableFontFamily = raw.fontFamily || '仓耳小丸子';
67
+ const manualRaw = Array.isArray(raw.manualRowHeights) ? raw.manualRowHeights : [];
68
+ const manualRowHeights = Array.from({ length: rows }, (_, i) => (typeof manualRaw[i] === 'number' ? manualRaw[i] : null));
69
+ const cellData = Array.isArray(raw.cellData) ? raw.cellData : [];
70
+ // buildCellMap 补全被合并覆盖的缺格为从格条目(应用契约恒每格一条;种子/
71
+ // 外部数据可缺)——下方行高 continue 与合成 continue 对缺格形态同口径生效
72
+ const dataByCell = buildCellMap(cellData);
73
+ // 每格排版(行高与摆位共用;从格跳过——应用侧文本已清空不参与行高)
74
+ const layoutByCell = new Map();
75
+ for (const data of cellData) {
76
+ if (data.isMerged)
77
+ continue;
78
+ const textWidth = Math.max(0, spanWidth(data.col, data.colspan ?? 1, columnWidths, cellSpacing) - cellPadding * 2);
79
+ layoutByCell.set(`${data.row},${data.col}`, {
80
+ layout: layoutTextbox(data.text ?? '', {
81
+ fontFamily: data.fontFamily || tableFontFamily,
82
+ fontSize: data.fontSize ?? CONSTRUCTOR_FONT_SIZE,
83
+ fontWeight: data.fontWeight,
84
+ fontStyle: data.fontStyle,
85
+ lineHeight: 1.16,
86
+ charSpacing: 0,
87
+ textAlign: data.textAlign ?? 'center'
88
+ }, { boxWidth: textWidth, splitByGrapheme: true, measure }),
89
+ data
90
+ });
91
+ }
92
+ // 行高:应用 calculateRowHeights(cellData 缺格 = 空文本对象,以构造期字号 14
93
+ // 计高;合并从格 continue 跳过——不贡献行高,勿与缺格混同)
94
+ const emptyCellHeight = CONSTRUCTOR_FONT_SIZE * FONT_SIZE_MULT;
95
+ const rowHeights = [];
96
+ const rowTextFloors = [];
97
+ for (let r = 0; r < rows; r++) {
98
+ let maxTextHeight = 0;
99
+ for (let c = 0; c < cols; c++) {
100
+ if (dataByCell.get(`${r},${c}`)?.isMerged)
101
+ continue;
102
+ const entry = layoutByCell.get(`${r},${c}`);
103
+ maxTextHeight = Math.max(maxTextHeight, entry ? entry.layout.height : emptyCellHeight);
104
+ }
105
+ const manualHeight = manualRowHeights[r];
106
+ const textNeeds = maxTextHeight + cellPadding * 2;
107
+ const baseHeight = manualHeight !== null ? manualHeight : minCellHeight;
108
+ rowTextFloors.push(textNeeds);
109
+ rowHeights.push(Math.max(baseHeight, textNeeds));
110
+ }
111
+ const contentWidth = columnWidths.reduce((s, w) => s + w, 0) + (cols - 1) * cellSpacing;
112
+ const contentHeight = rowHeights.reduce((s, h) => s + h, 0) + (rows - 1) * cellSpacing;
113
+ const columnX = buildPositions(cols, columnWidths, cellSpacing);
114
+ const rowY = buildPositions(rows, rowHeights, cellSpacing);
115
+ // 子节点合成(行主序 rect/text 交错——应用 createCells 的对象序)
116
+ const idPrefix = typeof raw.id === 'string' && raw.id ? raw.id : 'table';
117
+ const children = [];
118
+ for (let r = 0; r < rows; r++) {
119
+ for (let c = 0; c < cols; c++) {
120
+ const data = dataByCell.get(`${r},${c}`);
121
+ if (data?.isMerged)
122
+ continue;
123
+ const colspan = data?.colspan ?? 1;
124
+ const rowspan = data?.rowspan ?? 1;
125
+ const cellWidth = spanWidth(c, colspan, columnWidths, cellSpacing);
126
+ const cellHeight = spanWidth(r, rowspan, rowHeights, cellSpacing);
127
+ const x = columnX[c] - contentWidth / 2 + cellWidth / 2;
128
+ const y = rowY[r] - contentHeight / 2 + cellHeight / 2;
129
+ children.push({
130
+ type: 'rect',
131
+ id: `${idPrefix}-r${r}c${c}-rect`,
132
+ left: x,
133
+ top: y,
134
+ width: cellWidth,
135
+ height: cellHeight,
136
+ originX: 'center',
137
+ originY: 'center',
138
+ fill: data ? data.fill : cellFill,
139
+ stroke: data ? data.stroke : cellStroke,
140
+ strokeWidth: cellStrokeWidth,
141
+ scaleX: 1,
142
+ scaleY: 1,
143
+ angle: 0,
144
+ opacity: 1,
145
+ visible: true
146
+ });
147
+ const entry = data ? layoutByCell.get(`${r},${c}`) : undefined;
148
+ // 编辑期隐藏格:只跳过子节点合成(渲染层),行高/摆位照常(上方 rowHeights 已算)
149
+ const hidden = opts?.hideTextCell !== undefined && opts.hideTextCell.row === r && opts.hideTextCell.col === c;
150
+ if (entry && !hidden && (data?.text ?? '') !== '') {
151
+ const textHeight = entry.layout.height;
152
+ const vAlign = data?.verticalAlign ?? 'middle';
153
+ let textY = y;
154
+ if (vAlign === 'top')
155
+ textY = y - cellHeight / 2 + textHeight / 2 + cellPadding;
156
+ else if (vAlign === 'bottom')
157
+ textY = y + cellHeight / 2 - textHeight / 2 - cellPadding;
158
+ children.push({
159
+ type: 'textbox',
160
+ id: `${idPrefix}-r${r}c${c}-text`,
161
+ left: x,
162
+ top: textY,
163
+ width: Math.max(0, cellWidth - cellPadding * 2),
164
+ text: data?.text ?? '',
165
+ fill: data?.textFill ?? textFillDefault,
166
+ fontFamily: data?.fontFamily || tableFontFamily,
167
+ fontSize: data?.fontSize ?? CONSTRUCTOR_FONT_SIZE,
168
+ fontWeight: data?.fontWeight,
169
+ fontStyle: data?.fontStyle,
170
+ textAlign: data?.textAlign ?? 'center',
171
+ lineHeight: 1.16,
172
+ splitByGrapheme: true,
173
+ originX: 'center',
174
+ originY: 'center',
175
+ scaleX: 1,
176
+ scaleY: 1,
177
+ angle: 0,
178
+ opacity: 1,
179
+ visible: true
180
+ });
181
+ }
182
+ }
183
+ }
184
+ // fromObject 摆位 quirk:构造期布局(等列宽 + 空文本行高)的组尺寸 → triggerLayout
185
+ // 以旧中心为锚重设宽高 → 最终 left/top 平移(w0−w1)/2(列宽不等时)与
186
+ // (h0−h1)/2(文本撑高行时);空文本单行高 = fontSize×1.13(calcTextHeight 末行不乘 lineHeight)
187
+ const constructorRow = Math.max(minCellHeight, CONSTRUCTOR_FONT_SIZE * FONT_SIZE_MULT + cellPadding * 2);
188
+ const w0 = cols * firstWidth + (cols - 1) * cellSpacing + cellStrokeWidth;
189
+ const h0 = rows * constructorRow + (rows - 1) * cellSpacing + cellStrokeWidth;
190
+ const width = contentWidth + cellStrokeWidth;
191
+ const height = contentHeight + cellStrokeWidth;
192
+ return { rowHeights, rowTextFloors, columnWidths, contentWidth, contentHeight, width, height, children, constructorDims: { width: w0, height: h0 } };
193
+ };
@@ -0,0 +1,357 @@
1
+ /**
2
+ * fabric 文本排版算法的纯函数移植(main-webgl2 Phase 2a)。
3
+ *
4
+ * 与 fabric 6.9.0 的 Text/Textbox 逐公式对齐(源码精读结论):
5
+ * - 度量:共享 ctx 上以 CACHE_FONT_SIZE=400px 度量并按 fontSize/400 缩放,
6
+ * kernedWidth 用「前字+当前字 couple 度量 − 前字宽度」实现字偶字距(_measureChar);
7
+ * couple 只在前后字字体声明(含逐字 fontSize/fontFamily/weight/style)一致时生效
8
+ * (fabric stylesAreEqual = 实际字号下的 fontDeclaration 逐串相等)
9
+ * - charSpacing:fontSize×charSpacing/1000 同时加到 width 与 kernedWidth;
10
+ * 行宽额外减去末尾一次(measureLine)
11
+ * - 换行(Textbox):wordSplit 按 /[ \t\r]/ 分词 → 逐词 grapheme 度量(样式按
12
+ * 原始行/原始偏移解析)→ _wrapLine 的累加/回退状态机(含 infix 空格按其
13
+ * 原始偏移样式度量与 additionalSpace 的加减)
14
+ * - 行高:impl = 行内逐字 max(fontSize)×1.13(getHeightOfLineImpl,空行取行首
15
+ * 原始位样式);calcTextHeight 末行不乘 lineHeight,其余行乘(fabric 历史语义)
16
+ * - 字符盒 left:prev.left + prev.width + kernedWidth − width(_getGraphemeBox)
17
+ * - 行偏移:center=(W−w)/2、right=W−w、left/justify=0(ltr 子集)
18
+ * - 字体声明:`${fontStyle} ${fontWeight} ${size}px ${family}`,非 generic 字体加引号
19
+ *
20
+ * 逐字度量(P2-2):styles 里 fontSize/fontFamily/fontWeight/fontStyle 参与
21
+ * 度量(getCompleteStyleDeclaration 合并语义);fill/textBackgroundColor 等
22
+ * 视觉属性照旧透传。deltaY 仍属后续阶段。
23
+ * 描边(P2-3):stroke/strokeWidth 逐字覆写只影响渲染(TextStrokeDecl),
24
+ * 与 fabric 一致不进度量——盒宽/行高/换行结果与无描边时逐值相同。
25
+ * 装饰线(P2-4):underline/overline/linethrough 不进度量,渲染侧由
26
+ * lineDecorationRuns 按 fabric _renderTextDecoration 的 run 状态机产出线段 quad;
27
+ * 颜色逐字跟 fill(fabric ctx.fillStyle = getValueOfPropertyAt(FILL) 同语义)。
28
+ * Phase 2a 范围注记:ltr 子集(rtl 反向对齐不做);justify 全家已实现
29
+ * (enlargeSpaces 移植:空格均摊加宽 + 字符盒平移,纯 justify 含末行、
30
+ * justify-left/center/right 变体段末行豁免并按对应方式收尾),grapheme
31
+ * 切分用码点级(CJK/拉丁与 fabric 一致,emoji 簇差异已知,后续对齐)。
32
+ * splitByGrapheme(P4-4 表格单元格模式):LayoutOptions.splitByGrapheme ——
33
+ * 词=单字素、无 infix 空格、样式映射不吃空格(fabric 三处守卫逐条对齐)。
34
+ * 竖排(P4-5c):LayoutOptions.vertical —— 应用 Textbox vertical:true 的
35
+ * 内部坐标系移植(fabric 竖排 = 横排布局 + 对象 angle:90 + CJK 类字形逆旋转,
36
+ * 引擎只移植 advance/尺寸/装饰线口径,姿态在渲染侧);四套 advance 各站点
37
+ * 照抄互不通用:行宽 CJK 用盒高拉丁用 width、渲染 advance CJK 用盒高+spacing
38
+ * 拉丁用 width、装饰线 CJK 用盒高拉丁用 kernedWidth、calcTextWidth 双类都
39
+ * 加 space;换行判定轴不覆写(fabric 原样近似)。
40
+ * 布局级 parity 由 e2e 直接对比 fabric Textbox 的 _textLines/__lineWidths/height。
41
+ */
42
+ /** fabric CACHE_FONT_SIZE:所有字体度量在固定字号下做缓存 */
43
+ export declare const CACHE_FONT_SIZE = 400;
44
+ /** fabric _fontSizeMult:行高实现值 = max(fontSize) × 1.13 */
45
+ export declare const FONT_SIZE_MULT = 1.13;
46
+ /** fabric _fontSizeFraction:基线上移比例——首基线 = impl×(1−0.222),实测自
47
+ * fillText 拦截(两行文本 y=−h/2+Σimpl×lineHeight+impl×0.778 逐点吻合) */
48
+ export declare const FONT_SIZE_FRACTION = 0.222;
49
+ /** fabric Textbox 默认 dynamicMinWidth(换行最大宽下限之一) */
50
+ export declare const DYNAMIC_MIN_WIDTH = 2;
51
+ /** fabric textDefaultValues.offsets:装饰线 y = 基线 + offsetY ×(run 起始字符 fontSize) */
52
+ export declare const DECORATION_OFFSETS: {
53
+ readonly underline: 0.1;
54
+ readonly linethrough: -0.28167;
55
+ readonly overline: -0.81333;
56
+ };
57
+ /** fabric textDecorationThickness 类缺省(对象 fontSize 的千分比) */
58
+ export declare const DEFAULT_DECORATION_THICKNESS = 66.667;
59
+ export declare const isLatinChar: (ch: string) => boolean;
60
+ /** 竖排四类字形姿态(fabric _renderStr 2711-2743 的分支键):
61
+ * latin=平画(对象旋转后躺倒)、bracket=平画(括号转向)、
62
+ * symbol/cjk=逆旋转 −90°(直立),后两者仅锚点 y 偏移不同 */
63
+ export type VerticalCharClass = 'latin' | 'bracket' | 'symbol' | 'cjk';
64
+ export declare const verticalCharClass: (ch: string) => VerticalCharClass;
65
+ /** 竖排逐字渲染 advance(fabric _renderChars 2459-2478 per-char 口径):
66
+ * 拉丁 = charBox.width(已含 charSpacing),CJK 族 = charBox.height(=逐字
67
+ * fontSize) + verticalCharSpacing(对象 fontSize × charSpacing / 1000,
68
+ * fabric _getWidthOfCharSpacing——CJK 的 spacing 不在 kernedWidth 里须手动加) */
69
+ export declare const verticalRenderAdvance: (ch: string, box: CharBox, verticalCharSpacing: number) => number;
70
+ /** 竖排旋转类的 translate 锚点偏移(fabric _renderStr 2728/2734 经验魔数照抄):
71
+ * x 恒 +fontSize/1.1;y 普通CJK = +charBox.height/2 − fontSize/3.14,
72
+ * 标点 = −fontSize/3.14(句读推向字面上侧)。仅 symbol/cjk 类消费。 */
73
+ export declare const verticalAnchorShiftX: (fontSize: number) => number;
74
+ export declare const verticalAnchorShiftY: (klass: VerticalCharClass, box: CharBox, fontSize: number) => number;
75
+ /** K-line 垂直偏移的逐字抖动量(fabric Textbox._renderStr 2714-2757,应用
76
+ * 「上下上下」变形):偶字不动、奇字偏移 (textOffsetY/300)·fontSize/2——
77
+ * textOffsetY∈[-300,300](面板滑杆界),正下负上;fontSize 取该字有效字号
78
+ * (逐字覆写优先)。globalCharIndex 按视觉行字素数跨行累计(fabric 对
79
+ * _textLines 逐行求和口径,不含 \n 分隔符——勿用 styleMap.flatStart,它含
80
+ * 分隔符会错位奇偶)。竖排同式偏移落在锚点 y 上(fabric 对 charTop 加偏移
81
+ * 后再算旋转锚点,对象经 angle:90 后视觉呈左右交错)。 */
82
+ export declare const charJitterY: (textOffsetY: number, fontSize: number, globalCharIndex: number) => number;
83
+ /** 节点级抖动上界(虚线烘焙/特效剪影的画布余量用):|textOffsetY|/300·0.5·
84
+ * 全字最大有效字号——逐字覆写 fontSize 会抬高峰值,保守取 max。 */
85
+ export declare const maxCharJitterY: (textOffsetY: number, style: TextStyleProps, lines: TextLineLayout[]) => number;
86
+ /** 字形墨迹度量(P4-5c 补丁):measureText actualBoundingBox 同源——与
87
+ * GlyphAtlas cell(asc/desc/inkLeft)一套度量,保证布局侧推的墨迹范围与
88
+ * 渲染侧画出来的逐像素自洽。left/right 为墨迹相对笔位的 signed 偏移
89
+ * (left = −actualBoundingBoxLeft)。 */
90
+ export interface GlyphInkMetrics {
91
+ left: number;
92
+ right: number;
93
+ ascent: number;
94
+ descent: number;
95
+ }
96
+ export type InkMeasureFn = (decl: string, text: string, fontSize: number) => GlyphInkMetrics;
97
+ /** 缺省墨迹度量:共享 canvas;无 2d 上下文/缺实际边界度量时回退 em 比例
98
+ * (同 glyphAtlas 的 0.88/0.24 口径——right/center 对齐量略保守收入盒内) */
99
+ export declare const defaultInkMeasure: InkMeasureFn;
100
+ /**
101
+ * 竖排行沿流向(内部坐标 +x,即对象 angle:90 后的屏幕 +y)的墨迹范围,相对
102
+ * 行首笔位。渲染链口径(与 renderGlyphPass / verticalGlyphOps 同一摆位公式):
103
+ * - 旋转类(symbol/cjk):锚点 = 笔位 + fontSize/1.1,rotate(−π/2) 后墨迹相对
104
+ * 锚点 = [−ascent, +descent](GL cell 摆位 relY 投影;40px「中」探针实测
105
+ * [3,41] vs 36.36−asc34/+desc6 逐像素吻合);
106
+ * - 平画类(latin/bracket):墨迹相对笔位 = [ink.left, ink.right],latin 画位
107
+ * 再前移 kerned−width(fabric signWidth)。
108
+ * 供竖排 center/right 对齐量消费(见 layoutTextbox 行偏移处的补丁注释);
109
+ * left 对齐不调用(offset 恒 0,与 fabric 逐像素一致的主路径不动)。
110
+ */
111
+ export declare const verticalLineInkRun: (line: TextLineLayout, style: TextStyleProps, inkMeasure?: InkMeasureFn) => {
112
+ start: number;
113
+ end: number;
114
+ };
115
+ export declare const GENERIC_FONTS: Set<string>;
116
+ export interface TextStyleProps {
117
+ fontFamily: string;
118
+ fontSize: number;
119
+ fontWeight?: string | number;
120
+ fontStyle?: string;
121
+ lineHeight?: number;
122
+ charSpacing?: number;
123
+ textAlign?: string;
124
+ }
125
+ /** 与 fabric _getFontDeclaration 同构的字体声明(forMeasuring 时用 CACHE_FONT_SIZE) */
126
+ export declare const fontDeclaration: (style: TextStyleProps, size: number) => string;
127
+ export interface CharBox {
128
+ left: number;
129
+ width: number;
130
+ kernedWidth: number;
131
+ /** fabric _getGraphemeBox:height = 逐字 fontSize(竖排 CJK 的 advance 基数) */
132
+ height: number;
133
+ }
134
+ /**
135
+ * 列表前缀声明(fabric IParagraphContent:右栏 ElementParagraph 写入 paragraph)。
136
+ * id=0 有序列表(前缀 = 视觉行号+1 自动编号);其余用 content 字符做前缀
137
+ * ('·'/'☺' 等无序符号);content 空串 = 无前缀(fabric `content || undefined`)。
138
+ */
139
+ export interface ParagraphDecl {
140
+ id: number;
141
+ type?: number;
142
+ content?: string;
143
+ }
144
+ /** 前缀串(fabric Textbox._getParagraphPrefix:id=0 按视觉行号编号,含空行) */
145
+ export declare const paragraphPrefixOf: (paragraph: ParagraphDecl | null | undefined, lineIndex: number) => string | undefined;
146
+ /** 行首列表前缀(fabric _measureLine 前缀分支的排版产物) */
147
+ export interface LinePrefixInfo {
148
+ text: string;
149
+ /** 整串宽度(行首字符字体声明在实际字号下度量;fabric _getParagraphPrefixWidth) */
150
+ width: number;
151
+ /** 逐字素 advance(GL 图集管线定位用;丢 pair kerning——数字/单符号前缀无感) */
152
+ advances: number[];
153
+ /** 行首字符解析后样式(前缀的字体四件套,fabric getCompleteStyleDeclaration(l,0)) */
154
+ style: TextStyleProps;
155
+ }
156
+ /** 逐字符样式覆盖(fabric TextStyleDeclaration 的引擎子集:视觉属性 +
157
+ * 影响度量的字体四件套——fabric _styleProperties 中度量相关的部分) */
158
+ export interface CharStyleOverride {
159
+ fill?: string;
160
+ textBackgroundColor?: string;
161
+ fontSize?: number;
162
+ fontFamily?: string;
163
+ fontWeight?: string | number;
164
+ fontStyle?: string;
165
+ /** P2-3:逐字描边(fabric fullDecl.stroke/strokeWidth,仅视觉、不参与度量) */
166
+ stroke?: string;
167
+ strokeWidth?: number;
168
+ /** P2-4:逐字装饰线开关(fabric textDecorationProperties,仅视觉、不参与度量) */
169
+ underline?: boolean;
170
+ overline?: boolean;
171
+ linethrough?: boolean;
172
+ /** P2-4:逐字线宽千分比(对象 fontSize 基数;fabric textDecorationThickness) */
173
+ textDecorationThickness?: number;
174
+ }
175
+ /**
176
+ * 文本描边声明(P2-3)。
177
+ *
178
+ * fabric 的描边走 canvas2d `strokeText`:线宽以**文本本地空间**为单位、
179
+ * 沿字形轮廓居中展开(一半压进填充、一半露在外),lineJoin/miterLimit 决定
180
+ * 尖角外扩量。引擎侧把它编译成图集里独立的一层(白色描边环 + alpha 通道),
181
+ * 渲染时按描边色调制——与填充层同走一个 quad 管线,缩放/平移下与填充同步清晰。
182
+ */
183
+ export interface TextStrokeDecl {
184
+ color: string;
185
+ /** 文本空间线宽(fabric strokeWidth 同口径,不受对象 scale 影响——由 quad 变换承担) */
186
+ width: number;
187
+ /** fabric 缺省 'miter' */
188
+ lineJoin?: string;
189
+ /** fabric 缺省 4(canvas2d 自带缺省是 10,必须显式下发否则尖角外扩量不同) */
190
+ miterLimit?: number;
191
+ /** fabric 缺省 'butt' */
192
+ lineCap?: string;
193
+ }
194
+ /**
195
+ * 逐字描边解析(fabric getCompleteStyleDeclaration 语义:逐字覆写优先、对象级兜底)。
196
+ * 对象无描边但逐字给了 stroke+strokeWidth 时同样成声明——fabric 的
197
+ * `_renderTextStroke` 只因 isEmptyStyles() 才整体跳过。
198
+ *
199
+ * 已知缺口:strokeDashArray/strokeDashOffset 不在此列——fabric 按行(无逐字样式时)
200
+ * 或按 run 一次 strokeText,虚线相位在整行/整 run 内连续;引擎图集是逐字形 cell,
201
+ * 相位会逐字重来。虚线描边留待 P3-2(描边展开与对齐)按 run 级栅格化处理。
202
+ */
203
+ export declare const resolveStrokeDecl: (base: TextStrokeDecl | null, o?: CharStyleOverride) => TextStrokeDecl | null;
204
+ /** 装饰线三类型(fabric _renderTextDecoration 的三趟 pass) */
205
+ export type TextDecorationType = 'underline' | 'overline' | 'linethrough';
206
+ /**
207
+ * 行末 x(相对行首):fabric `_measureLine` 的**行末哨兵盒**口径 =
208
+ * 末字符盒 left + width(width 含行尾 charSpacing)。justify 拉伸行的空格
209
+ * 加宽/平移同样作用于末盒 → 端点落在拉伸末端(fabric enlargeSpaces 对哨兵盒
210
+ * 的 acc 平移同语义)。`line.width` 保持自然行宽(fabric `__lineWidths` 口径,
211
+ * 布局对拍用),行末光标/选区端点一律走本口径,两者不可混用。
212
+ */
213
+ export declare const lineEndOffset: (line: TextLineLayout) => number;
214
+ export interface ParagraphPrefixDrawOpts {
215
+ /** 前缀填充色(fabric fullDecl.fill = 逐字覆写 ?? 对象 fill 的字符串侧);
216
+ * null/缺省 = 不画填充;'keep' = 不改 ctx.fillStyle 直接 fillText(剪影烘焙外层定色) */
217
+ fill?: string | 'keep' | null;
218
+ /** 描边声明(fabric fullDecl.stroke/strokeWidth);null/缺省 = 不画描边 */
219
+ stroke?: TextStrokeDecl | null;
220
+ }
221
+ /**
222
+ * 行首列表前缀的 canvas 绘制(fabric _renderChars 前缀块 2408-2444 的等价抽取):
223
+ * 在 (x, baselineY) 以行首字符的字体声明 fillText/strokeText 前缀串(一次出笔,
224
+ * 前缀内 kerning 保留——GL 图集管线的逐字 advance 是其近似)。竖排同样在此
225
+ * 出笔(fabric 前缀块无竖排分支:不旋转、画在列首行基线)。返回前缀宽
226
+ * (无前缀 = 0),供调用方把正文 run 起点 `left += prefixWidth`(fabric 同款)。
227
+ */
228
+ export declare const drawParagraphPrefix: (ctx: CanvasRenderingContext2D, line: TextLineLayout, x: number, baselineY: number, opts?: ParagraphPrefixDrawOpts) => number;
229
+ /** lineDecorationRuns 的对象级缺省(fabric getValueOfPropertyAt 的 this.* 兜底侧) */
230
+ export interface DecorationDefaults {
231
+ underline?: boolean;
232
+ overline?: boolean;
233
+ linethrough?: boolean;
234
+ /** 线宽千分比(fabric 类缺省 66.667,基数是**对象** fontSize) */
235
+ textDecorationThickness?: number;
236
+ /** 对象 fontSize(finalTickness 乘数与 charSpacing 宽度基数都用它,非逐字) */
237
+ fontSize: number;
238
+ /** 对象 fill(装饰色兜底;空字符串 = 无色不画,fabric lastFill 真值判定同语义) */
239
+ fill?: string;
240
+ /** 对象 charSpacing(行末 flush 宽度扣除一次) */
241
+ charSpacing?: number;
242
+ /** P4-5c 竖排:装饰 run 的 advance 换轴(应用 Textbox._renderTextDecoration 1261/1269) */
243
+ vertical?: boolean;
244
+ }
245
+ /** 一条装饰线段(行首/行基线相对坐标,对象中心系渲染侧再加盒偏移) */
246
+ export interface DecorationRun {
247
+ /** run 左缘相对行首(= fabric drawStart 里的 boxStart,字符盒 left) */
248
+ x: number;
249
+ width: number;
250
+ /** 矩形顶相对行基线 = offsetY×size − aligner×thickness(fabric top+…−… 的基线换算) */
251
+ y: number;
252
+ thickness: number;
253
+ /** run 起始字符的填充色(装饰色跟 fill,fabric ctx.fillStyle = lastFill) */
254
+ color: string;
255
+ }
256
+ /**
257
+ * 单行装饰线 run(P2-4,fabric `_renderTextDecoration` 状态机的纯函数移植)。
258
+ *
259
+ * 语义要点(源码逐行核对):
260
+ * - run 分段键 = (开关, fill, 逐字 fontSize, thickness)——任一变化即断段;
261
+ * 断段后的新 run 首字符贡献**普通 width**(非 kernedWidth,fabric 原样行为),
262
+ * 续段字符累加 kernedWidth;
263
+ * - 线宽 = **对象** fontSize × thickness‰ / 1000(fabric finalTickness 用 this.fontSize,
264
+ * 逐字大字号不会加粗装饰线);y 偏移的 size 乘数则取 run 起始字符的逐字 fontSize;
265
+ * - 末次 flush 的宽度额外扣除一次对象级 charSpacing(fillRect(boxWidth − charSpacing));
266
+ * - 开关/色/线宽任一为假则该段不产出(fabric lastDecoration && lastFill && lastTickness)。
267
+ * 行内逐字全 false 时返回空(fabric 整行跳过 styleHas 判定的视觉等价)。
268
+ * deltaY 参与 fabric 的分段键与 y 公式,引擎暂不支持逐字 deltaY(恒 0),后续接。
269
+ */
270
+ export declare const lineDecorationRuns: (line: TextLineLayout, type: TextDecorationType, defaults: DecorationDefaults) => DecorationRun[];
271
+ /** fabric styles 结构:原始行号 → 原始字符号 → 样式 */
272
+ export type SerializedStyles = Record<number, Record<number, CharStyleOverride>>;
273
+ export interface LineStyleMapEntry {
274
+ /** 该视觉行对应的原始行(按 \n 切分) */
275
+ line: number;
276
+ /** 视觉行首字符在原始行内的偏移 */
277
+ offset: number;
278
+ /** 视觉行首字符在整段 flat grapheme 序列中的偏移(含 \n/空格分隔符) */
279
+ flatStart: number;
280
+ }
281
+ export interface TextLineLayout {
282
+ graphemes: string[];
283
+ boxes: CharBox[];
284
+ width: number;
285
+ /** 行首到盒左的偏移(textAlign) */
286
+ leftOffset: number;
287
+ /** 行基线相对文本块顶部的 y */
288
+ baseline: number;
289
+ /** 行顶相对文本块顶部的 y(背景高亮/选区用:−h/2 + Σ前行 impl×lineHeight) */
290
+ top: number;
291
+ /** fabric getHeightOfLineImpl:行内逐字 max(fontSize)×1.13,不乘 lineHeight */
292
+ implHeight: number;
293
+ /** 视觉行 → 原始行/偏移(样式解析与光标映射) */
294
+ styleMap: LineStyleMapEntry;
295
+ /** 逐字符解析后的样式(undefined = 对象默认) */
296
+ charStyles: Array<CharStyleOverride | undefined>;
297
+ /** 行首列表前缀(paragraph 声明时恒存;盒平移只在前缀宽 > 0 时发生) */
298
+ prefix?: LinePrefixInfo;
299
+ }
300
+ export interface TextLayout {
301
+ lines: TextLineLayout[];
302
+ /** 盒宽:textbox 为固定盒宽,text/itext 为最长行宽 */
303
+ width: number;
304
+ /** calcTextHeight */
305
+ height: number;
306
+ /** flat grapheme(Array.from(text),含 \n)→ UTF-16 码元偏移(textarea 同步用) */
307
+ graphemeCodeUnitOffsets: number[];
308
+ /** 竖排 calcTextWidth 口径宽(应用 Textbox 覆写分支:逐字累加 + cursorWidth(2),
309
+ * 与盒宽不同源——boxWidth 存在时 width 不走该式而本值恒算);横排 undefined */
310
+ verticalWidth?: number;
311
+ }
312
+ export type MeasureFn = (decl: string, text: string) => number;
313
+ export declare const defaultMeasure: MeasureFn;
314
+ /** grapheme 切分:码点级(Intl.Segmenter 的 grapheme 级差异属后续对齐项) */
315
+ export declare const graphemeSplit: (value: string) => string[];
316
+ /** 字体迟到失效的度量总清(EngineCanvas.handleFontsLoaded 消费):字符宽/字距宽/墨迹
317
+ * 三类按「字体声明串」键的缓存全部作废。声明串不含字体加载态——同族从回退变真实后
318
+ * 键不变,旧缓存命中会把 fallback 宽度带进重排(字形换了但折行/行宽仍错,且字距
319
+ * couple 键按声明串命中无法自愈)。调用时机稀有(字体到达),粗粒度全清安全。 */
320
+ export declare const clearAllMeasureCaches: () => void;
321
+ /** 换行期的词数据(含词首在原始行内的字素偏移——逐字样式按此解析) */
322
+ export interface WrapWordData {
323
+ graphemes: string[];
324
+ width: number;
325
+ charOffset: number;
326
+ }
327
+ export interface LayoutOptions {
328
+ /** 盒宽(textbox 用);null/undefined = 不换行(text/itext) */
329
+ boxWidth?: number | null;
330
+ /** 度量函数注入(单测用 mock;缺省走共享 canvas ctx) */
331
+ measure?: MeasureFn;
332
+ /** 逐字符样式(fabric styles 结构:原始行/原始字符索引) */
333
+ styles?: SerializedStyles;
334
+ /** fabric Textbox.splitByGrapheme(P4-4 表格单元格):逐字素换行——无 infix
335
+ * 空格(词=单字素)、样式映射不吃尾随空格(fabric getGraphemeDataForRender/
336
+ * _wrapLine/_generateStyleMap 的 splitByGrapheme 分支逐条对齐) */
337
+ splitByGrapheme?: boolean;
338
+ /** P4-5c 竖排(应用 Textbox vertical: true):行宽按列长口径累加(CJK 用
339
+ * 盒高)、text/itext 盒宽走 calcTextWidth 竖排分支;换行判定轴不覆写
340
+ * (fabric 原样近似,两侧共享该 quirk) */
341
+ vertical?: boolean;
342
+ /** 墨迹度量注入(单测用 mock;缺省走共享 canvas 的 actualBoundingBox)。
343
+ * 仅竖排 center/right 对齐量消费(P4-5c 补丁的渲染链墨迹口径) */
344
+ inkMeasure?: InkMeasureFn;
345
+ /** 列表前缀(fabric Textbox.paragraph):前缀宽并入行宽并平移该行全部
346
+ * 字符盒(fabric _measureLine——换行判定在度量前不受影响;竖排同生效,
347
+ * 列宽增长)。ArcText 覆写 _measureLine 不含前缀——弧形节点不传(scene 侧门控) */
348
+ paragraph?: ParagraphDecl | null;
349
+ }
350
+ /**
351
+ * 完整排版:text + 样式 → 行切分 + 字符盒 + 尺寸。
352
+ * 字符盒 left/width/kernedWidth 与 fabric __charBounds 同单位(对象本地坐标,
353
+ * fontSize 像素、scale=1),渲染侧直接消费。
354
+ * 逐字 fontSize/fontFamily/fontWeight/fontStyle 按原始行/字索引参与度量
355
+ * (换行期词宽、最终字符盒、行高 impl 全部走逐字样式)。
356
+ */
357
+ export declare const layoutTextbox: (text: string, style: TextStyleProps, options?: LayoutOptions) => TextLayout;