@yft-design/engine 0.0.17 → 0.0.19

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (279) hide show
  1. package/README.md +23 -11
  2. package/dist/EngineCanvas.d.ts +0 -255
  3. package/dist/core/color.d.ts +0 -11
  4. package/dist/core/distanceField.d.ts +0 -13
  5. package/dist/core/events.d.ts +0 -25
  6. package/dist/core/gradient.d.ts +0 -47
  7. package/dist/core/homography.d.ts +0 -20
  8. package/dist/core/imageFilters.d.ts +0 -31
  9. package/dist/core/mat2d.d.ts +0 -62
  10. package/dist/core/pathData.d.ts +0 -36
  11. package/dist/core/pattern.d.ts +0 -14
  12. package/dist/core/point.d.ts +0 -14
  13. package/dist/core/psdEffects.d.ts +0 -48
  14. package/dist/core/roundedRect.d.ts +0 -48
  15. package/dist/core/shadow.d.ts +0 -23
  16. package/dist/core/snap.d.ts +0 -103
  17. package/dist/core/stroke.d.ts +0 -13
  18. package/dist/core/triangulate.d.ts +0 -31
  19. package/dist/core/warpMesh.d.ts +0 -38
  20. package/dist/debug/canvasInspection.d.ts +0 -20
  21. package/dist/debug/pixelDiff.d.ts +0 -7
  22. package/dist/debug/pixelDiff.js +1 -64
  23. package/dist/debug/seed.d.ts +0 -426
  24. package/dist/debug/seed.js +28 -3806
  25. package/dist/decoders/webp2sprite.d.ts +0 -16
  26. package/dist/engineFlag.d.ts +0 -76
  27. package/dist/export/SceneExporter.d.ts +0 -58
  28. package/dist/export/glExport.d.ts +0 -41
  29. package/dist/export/svgExport.d.ts +0 -181
  30. package/dist/index.d.ts +1 -14
  31. package/dist/index.js +1060 -64
  32. package/dist/interact/animationPlayback.d.ts +0 -62
  33. package/dist/interact/canvasInteractions.d.ts +1 -38
  34. package/dist/interact/cropSession.d.ts +0 -68
  35. package/dist/interact/dblClick.d.ts +0 -32
  36. package/dist/interact/expandSession.d.ts +0 -46
  37. package/dist/interact/hotkeyActions.d.ts +0 -12
  38. package/dist/interact/pageTransfer.d.ts +0 -2
  39. package/dist/interact/pathSession.d.ts +0 -42
  40. package/dist/interact/pointer.d.ts +0 -87
  41. package/dist/interact/pointerTablePuzzle.d.ts +0 -60
  42. package/dist/interact/pointerTransform.d.ts +0 -48
  43. package/dist/interact/pointerTypes.d.ts +6 -148
  44. package/dist/interact/snapGuide.d.ts +0 -68
  45. package/dist/interact/tableCellEditing.d.ts +0 -34
  46. package/dist/interact/tableInteraction.d.ts +0 -31
  47. package/dist/interact/textEditing.d.ts +0 -44
  48. package/dist/interact/warpFacade.d.ts +0 -5
  49. package/dist/interact/warpSession.d.ts +0 -55
  50. package/dist/interact/wheelScroll.d.ts +0 -42
  51. package/dist/model/alphaHit.d.ts +0 -51
  52. package/dist/model/animation.d.ts +0 -99
  53. package/dist/model/arcLayout.d.ts +0 -33
  54. package/dist/model/arcTextTransform.d.ts +0 -4
  55. package/dist/model/compatEvents.d.ts +0 -72
  56. package/dist/model/compatObject.d.ts +0 -360
  57. package/dist/model/cropEdit.d.ts +0 -60
  58. package/dist/model/document.d.ts +0 -167
  59. package/dist/model/elementTypes.d.ts +0 -47
  60. package/dist/model/expandEdit.d.ts +0 -36
  61. package/dist/model/fabricPrimitives.d.ts +0 -24
  62. package/dist/model/filler.d.ts +0 -12
  63. package/dist/model/groupAssemble.d.ts +0 -5
  64. package/dist/model/groupChildMove.d.ts +0 -37
  65. package/dist/model/groupResize.d.ts +0 -42
  66. package/dist/model/handles.d.ts +0 -24
  67. package/dist/model/imageMaskBake.d.ts +0 -50
  68. package/dist/model/lineConstruct.d.ts +0 -8
  69. package/dist/model/maskCropEdit.d.ts +0 -34
  70. package/dist/model/pathBackground.d.ts +0 -33
  71. package/dist/model/pathConstruct.d.ts +0 -24
  72. package/dist/model/pathEdit.d.ts +0 -55
  73. package/dist/model/puzzleEdit.d.ts +0 -66
  74. package/dist/model/puzzleLayout.d.ts +0 -31
  75. package/dist/model/scene.d.ts +0 -603
  76. package/dist/model/schema.d.ts +0 -48
  77. package/dist/model/shapePath.d.ts +0 -5
  78. package/dist/model/smartObjectBake.d.ts +0 -6
  79. package/dist/model/tableEdit.d.ts +0 -90
  80. package/dist/model/tableFacade.d.ts +0 -5
  81. package/dist/model/tableLayout.d.ts +0 -40
  82. package/dist/model/textAlign.d.ts +0 -22
  83. package/dist/model/textLayout.d.ts +0 -213
  84. package/dist/render/GLBlend.d.ts +0 -24
  85. package/dist/render/GLContext.d.ts +0 -11
  86. package/dist/render/GLIsolate.d.ts +0 -25
  87. package/dist/render/GLTextureCache.d.ts +0 -72
  88. package/dist/render/GlyphAtlas.d.ts +0 -98
  89. package/dist/render/MeshBatch.d.ts +0 -71
  90. package/dist/render/QuadBatch.d.ts +0 -87
  91. package/dist/render/SceneRenderer.d.ts +0 -137
  92. package/dist/render/SourceManager.d.ts +0 -82
  93. package/dist/render/TextRenderer.d.ts +0 -120
  94. package/dist/render/arcText.d.ts +0 -28
  95. package/dist/render/bakeGate.d.ts +0 -35
  96. package/dist/render/batchOrder.d.ts +0 -60
  97. package/dist/render/blendMode.d.ts +0 -27
  98. package/dist/render/clipMaskPainter.d.ts +0 -42
  99. package/dist/render/fontInvalidation.d.ts +0 -18
  100. package/dist/render/fontInvalidationController.d.ts +0 -52
  101. package/dist/render/frameOverlay.d.ts +0 -32
  102. package/dist/render/framePipeline.d.ts +0 -27
  103. package/dist/render/gpuFilterPasses.d.ts +0 -15
  104. package/dist/render/gpuFx.d.ts +0 -82
  105. package/dist/render/gpuImageFilters.d.ts +0 -41
  106. package/dist/render/gpuShadow.d.ts +0 -38
  107. package/dist/render/gradientRamp.d.ts +0 -14
  108. package/dist/render/imageEffects.d.ts +0 -99
  109. package/dist/render/lineDecorationSdf.d.ts +0 -32
  110. package/dist/render/maskRender.d.ts +0 -60
  111. package/dist/render/multiPage.d.ts +0 -91
  112. package/dist/render/progressiveLoad.d.ts +0 -27
  113. package/dist/render/psdEffectPainter.d.ts +0 -25
  114. package/dist/render/psdWarpText.d.ts +0 -19
  115. package/dist/render/puzzleClamp.d.ts +0 -15
  116. package/dist/render/renderEpoch.d.ts +0 -21
  117. package/dist/render/retainedFrame.d.ts +0 -36
  118. package/dist/render/ruler.d.ts +0 -36
  119. package/dist/render/screenClip.d.ts +0 -31
  120. package/dist/render/scrollText.d.ts +0 -46
  121. package/dist/render/segmentTable.d.ts +0 -30
  122. package/dist/render/selectionOverlay.d.ts +0 -203
  123. package/dist/render/settleScheduler.d.ts +0 -24
  124. package/dist/render/shaders.d.ts +4 -24
  125. package/dist/render/shadowBake.d.ts +0 -28
  126. package/dist/render/shadowPainter.d.ts +0 -8
  127. package/dist/render/sharedGpuPainters.d.ts +0 -13
  128. package/dist/render/sourceHydration.d.ts +0 -8
  129. package/dist/render/strokeBake.d.ts +0 -59
  130. package/dist/render/strokeMiterOutline.d.ts +0 -29
  131. package/dist/render/strokePainter.d.ts +0 -31
  132. package/dist/render/strokeSdf.d.ts +0 -52
  133. package/dist/render/svgRaster.d.ts +0 -34
  134. package/dist/render/tableOverlay.d.ts +0 -35
  135. package/dist/render/textHighlight.d.ts +0 -67
  136. package/dist/render/textureUpload.d.ts +0 -13
  137. package/dist/render/verticalText.d.ts +0 -21
  138. package/dist/render/warpText.d.ts +0 -48
  139. package/dist/render/workspaceBackdrop.d.ts +0 -22
  140. package/dist/render/workspaceChecker.d.ts +0 -34
  141. package/dist/render/workspaceGlow.d.ts +0 -38
  142. package/package.json +4 -3
  143. package/dist/EngineCanvas.js +0 -1202
  144. package/dist/core/canvasPerf.js +0 -170
  145. package/dist/core/color.js +0 -107
  146. package/dist/core/distanceField.js +0 -92
  147. package/dist/core/events.js +0 -80
  148. package/dist/core/gradient.js +0 -175
  149. package/dist/core/homography.js +0 -123
  150. package/dist/core/imageFilters.js +0 -330
  151. package/dist/core/mat2d.js +0 -241
  152. package/dist/core/pathData.js +0 -926
  153. package/dist/core/pattern.js +0 -40
  154. package/dist/core/point.js +0 -119
  155. package/dist/core/psdEffects.js +0 -158
  156. package/dist/core/roundedRect.js +0 -164
  157. package/dist/core/shadow.js +0 -47
  158. package/dist/core/snap.js +0 -793
  159. package/dist/core/stroke.js +0 -45
  160. package/dist/core/triangulate.js +0 -194
  161. package/dist/core/warpMesh.js +0 -469
  162. package/dist/debug/canvasInspection.js +0 -113
  163. package/dist/decoders/gif2sprite.js +0 -84
  164. package/dist/decoders/webp2sprite.js +0 -133
  165. package/dist/engineFlag.js +0 -104
  166. package/dist/export/SceneExporter.js +0 -286
  167. package/dist/export/glExport.js +0 -79
  168. package/dist/export/svgExport.js +0 -1803
  169. package/dist/interact/animationPlayback.js +0 -358
  170. package/dist/interact/canvasInteractions.js +0 -174
  171. package/dist/interact/cropSession.js +0 -527
  172. package/dist/interact/dblClick.js +0 -120
  173. package/dist/interact/expandSession.js +0 -282
  174. package/dist/interact/hotkeyActions.js +0 -42
  175. package/dist/interact/pageTransfer.js +0 -56
  176. package/dist/interact/pathSession.js +0 -480
  177. package/dist/interact/pointer.js +0 -1692
  178. package/dist/interact/pointerTablePuzzle.js +0 -358
  179. package/dist/interact/pointerTransform.js +0 -441
  180. package/dist/interact/pointerTypes.js +0 -96
  181. package/dist/interact/snapGuide.js +0 -377
  182. package/dist/interact/tableCellEditing.js +0 -207
  183. package/dist/interact/tableInteraction.js +0 -219
  184. package/dist/interact/textEditing.js +0 -423
  185. package/dist/interact/warpFacade.js +0 -51
  186. package/dist/interact/warpSession.js +0 -583
  187. package/dist/interact/wheelScroll.js +0 -100
  188. package/dist/model/alphaHit.js +0 -267
  189. package/dist/model/animation.js +0 -510
  190. package/dist/model/arcLayout.js +0 -308
  191. package/dist/model/arcTextTransform.js +0 -87
  192. package/dist/model/compatEvents.js +0 -96
  193. package/dist/model/compatObject.js +0 -1583
  194. package/dist/model/cropEdit.js +0 -497
  195. package/dist/model/document.js +0 -590
  196. package/dist/model/elementTypes.js +0 -119
  197. package/dist/model/expandEdit.js +0 -161
  198. package/dist/model/fabricPrimitives.js +0 -9
  199. package/dist/model/filler.js +0 -1
  200. package/dist/model/groupAssemble.js +0 -98
  201. package/dist/model/groupChildMove.js +0 -145
  202. package/dist/model/groupResize.js +0 -109
  203. package/dist/model/handles.js +0 -29
  204. package/dist/model/imageMaskBake.js +0 -136
  205. package/dist/model/lineConstruct.js +0 -79
  206. package/dist/model/maskCropEdit.js +0 -90
  207. package/dist/model/pathBackground.js +0 -196
  208. package/dist/model/pathConstruct.js +0 -55
  209. package/dist/model/pathEdit.js +0 -378
  210. package/dist/model/puzzleEdit.js +0 -742
  211. package/dist/model/puzzleLayout.js +0 -143
  212. package/dist/model/scene.js +0 -2930
  213. package/dist/model/schema.js +0 -13
  214. package/dist/model/shapePath.js +0 -137
  215. package/dist/model/smartObjectBake.js +0 -295
  216. package/dist/model/tableEdit.js +0 -751
  217. package/dist/model/tableFacade.js +0 -808
  218. package/dist/model/tableLayout.js +0 -194
  219. package/dist/model/textAlign.js +0 -36
  220. package/dist/model/textLayout.js +0 -842
  221. package/dist/render/GLBlend.js +0 -270
  222. package/dist/render/GLContext.js +0 -48
  223. package/dist/render/GLIsolate.js +0 -188
  224. package/dist/render/GLTextureCache.js +0 -224
  225. package/dist/render/GlyphAtlas.js +0 -412
  226. package/dist/render/MeshBatch.js +0 -416
  227. package/dist/render/QuadBatch.js +0 -561
  228. package/dist/render/SceneRenderer.js +0 -753
  229. package/dist/render/SourceManager.js +0 -523
  230. package/dist/render/TextRenderer.js +0 -854
  231. package/dist/render/arcText.js +0 -187
  232. package/dist/render/bakeGate.js +0 -32
  233. package/dist/render/batchOrder.js +0 -168
  234. package/dist/render/blendMode.js +0 -142
  235. package/dist/render/clipMaskPainter.js +0 -244
  236. package/dist/render/fontInvalidation.js +0 -77
  237. package/dist/render/fontInvalidationController.js +0 -119
  238. package/dist/render/frameOverlay.js +0 -124
  239. package/dist/render/framePipeline.js +0 -96
  240. package/dist/render/gpuFilterPasses.js +0 -883
  241. package/dist/render/gpuFx.js +0 -673
  242. package/dist/render/gpuImageFilters.js +0 -295
  243. package/dist/render/gpuShadow.js +0 -327
  244. package/dist/render/gradientRamp.js +0 -74
  245. package/dist/render/imageEffects.js +0 -415
  246. package/dist/render/lineDecorationSdf.js +0 -189
  247. package/dist/render/maskRender.js +0 -217
  248. package/dist/render/multiPage.js +0 -420
  249. package/dist/render/progressiveLoad.js +0 -86
  250. package/dist/render/psdEffectPainter.js +0 -333
  251. package/dist/render/psdWarpText.js +0 -212
  252. package/dist/render/puzzleClamp.js +0 -30
  253. package/dist/render/renderEpoch.js +0 -35
  254. package/dist/render/renderViewport.js +0 -18
  255. package/dist/render/retainedFrame.js +0 -192
  256. package/dist/render/ruler.js +0 -287
  257. package/dist/render/screenClip.js +0 -67
  258. package/dist/render/scrollText.js +0 -266
  259. package/dist/render/segmentTable.js +0 -117
  260. package/dist/render/selectionOverlay.js +0 -1008
  261. package/dist/render/settleScheduler.js +0 -51
  262. package/dist/render/shaders.js +0 -450
  263. package/dist/render/shadowBake.js +0 -203
  264. package/dist/render/shadowPainter.js +0 -93
  265. package/dist/render/sharedGpuPainters.js +0 -42
  266. package/dist/render/sourceHydration.js +0 -48
  267. package/dist/render/strokeBake.js +0 -516
  268. package/dist/render/strokeMiterOutline.js +0 -224
  269. package/dist/render/strokePainter.js +0 -207
  270. package/dist/render/strokeSdf.js +0 -262
  271. package/dist/render/svgRaster.js +0 -71
  272. package/dist/render/tableOverlay.js +0 -233
  273. package/dist/render/textHighlight.js +0 -380
  274. package/dist/render/textureUpload.js +0 -26
  275. package/dist/render/verticalText.js +0 -63
  276. package/dist/render/warpText.js +0 -384
  277. package/dist/render/workspaceBackdrop.js +0 -60
  278. package/dist/render/workspaceChecker.js +0 -170
  279. package/dist/render/workspaceGlow.js +0 -198
@@ -1,380 +0,0 @@
1
- /**
2
- * 文字划重点(批次62):应用定制 Textbox._renderHighlight(主仓
3
- * extension/object/Textbox.ts 1466-1767)的引擎承接。
4
- *
5
- * 数据面:raw.texts = [{ text, highlight?: { type:'svg', svgInfo } }]——compat 面
6
- * setTexts 直写已久(数据持久化供 fabric 模式往返),本模块补引擎渲染消费。
7
- *
8
- * 两段式:
9
- * 1. highlightRuns / planTextHighlight —— 纯函数(jsdom 可测):段 → 视觉行/
10
- * 字符盒区间切分(fabric 索引数学逐行复刻,含行尾虚拟游标盒)→ 本地系
11
- * 绘制计划(变换矩阵 + 画笔参数 + 出血余量)。
12
- * 2. bakeTextHighlight —— 浏览器面:按计划在 canvas2d 上 Path2D 绘制(fabric
13
- * 同一光栅器语义,线帽/拐角不设值=canvas 缺省 butt/miter,fabric
14
- * _renderHighlight 亦不设置——TextMark 配置里的 round 不生效是双栈共同 quirk)。
15
- *
16
- * 已知边界:
17
- * - 竖排(raw.vertical)不承接——fabric 侧行/列 charBounds 语义存疑,登记缺口;
18
- * - 阴影/PSD 特效剪影不含划重点墨迹(fabric _renderHighlight 在阴影域外,同构);
19
- * - SVG 导出序列化面不消费 texts(双栈同侪)。
20
- */
21
- import { getBoundsOfPath, parsePathData } from '../core/pathData';
22
- /**
23
- * 应用定制 _measureLine 的行尾游标盒(主仓 Textbox.ts 1319-1325):
24
- * left = 末字盒 left+width、宽 0、height = 对象级 fontSize。fabric 整行段的
25
- * width = curCharBoxs[end].left − startBox.left 依赖它(原生 fabric 无此盒,
26
- * 越界抛错被 try/catch 吞成全跳——应用补盒后整行段是主路径)。
27
- */
28
- export const trailingCharBox = (line, objectFontSize) => {
29
- const boxes = line.boxes;
30
- if (boxes.length === 0)
31
- return { left: 0, width: 0, kernedWidth: 0, height: objectFontSize };
32
- const last = boxes[boxes.length - 1];
33
- return { left: last.left + last.width, width: 0, kernedWidth: 0, height: objectFontSize };
34
- };
35
- /** 行内取盒:越界仅允许 == length(尾盒),再越界返回 null(调用方跳过该 run) */
36
- const boxAt = (line, i, objectFontSize) => {
37
- if (i < 0)
38
- return null;
39
- if (i < line.boxes.length)
40
- return line.boxes[i];
41
- if (i === line.boxes.length)
42
- return trailingCharBox(line, objectFontSize);
43
- return null;
44
- };
45
- /**
46
- * 段 → 视觉行/盒区间切分(fabric _renderHighlight 1480-1610 复刻)。
47
- *
48
- * 索引语义(与 fabric 同名变量一一对应):
49
- * - indexLineMap / index2IndexOfLine:grapheme 平铺序 → (视觉行号, 行内盒序);
50
- * - fullTextToLineIndexMap:text 的 **code unit** → grapheme 平铺序('\n' → -1;
51
- * 计数器按 code unit 递增——代理对字符双耗 grapheme 槽位的漂移是 fabric
52
- * 原 quirk,复刻不修)。
53
- *
54
- * 守卫同 fabric:Σ段长 ≠ text.length(code unit)整跳;非 svg highlight 跳段;
55
- * '\n' 单独段只推 idx。fabric 对查表越界段有 start=0 兜底/no-end-index 跳过的
56
- * 杂路(仅双重换行等病态段触达),此处统一按跳过处理(正常 UI 不会生成)。
57
- */
58
- export const highlightRuns = (text, layout, texts) => {
59
- if (!Array.isArray(texts) || texts.length === 0)
60
- return [];
61
- let total = 0;
62
- for (const t of texts) {
63
- if (!t || typeof t.text !== 'string')
64
- return [];
65
- total += t.text.length;
66
- }
67
- if (total !== text.length)
68
- return [];
69
- const indexLineMap = [];
70
- const index2IndexOfLine = [];
71
- for (let line = 0; line < layout.lines.length; line++) {
72
- const n = layout.lines[line].graphemes.length;
73
- for (let i = 0; i < n; i++) {
74
- index2IndexOfLine.push(i);
75
- indexLineMap.push(line);
76
- }
77
- }
78
- const fullTextToLineIndexMap = [];
79
- let lineTextIndex = 0;
80
- for (let i = 0; i < text.length; i++) {
81
- if (text[i] === '\n') {
82
- fullTextToLineIndexMap.push(-1);
83
- }
84
- else if (lineTextIndex < indexLineMap.length) {
85
- fullTextToLineIndexMap.push(lineTextIndex);
86
- lineTextIndex++;
87
- }
88
- else {
89
- fullTextToLineIndexMap.push(-1);
90
- }
91
- }
92
- const runs = [];
93
- const flatAt = (codeUnitIdx) => {
94
- const mapped = fullTextToLineIndexMap[codeUnitIdx];
95
- if (mapped === undefined || mapped === -1 || mapped >= indexLineMap.length)
96
- return -1;
97
- return mapped;
98
- };
99
- let idx = 0;
100
- for (const tObj of texts) {
101
- if (tObj.text.length === 0)
102
- continue;
103
- if (tObj.text === '\n') {
104
- idx += 1;
105
- continue;
106
- }
107
- if (!tObj.highlight || tObj.highlight.type !== 'svg' || !tObj.highlight.svgInfo) {
108
- idx += tObj.text.length;
109
- continue;
110
- }
111
- const info = tObj.highlight.svgInfo;
112
- const mappedStartIdx = flatAt(idx);
113
- if (mappedStartIdx === -1) {
114
- idx += tObj.text.length;
115
- continue;
116
- }
117
- let startLineIndex = indexLineMap[mappedStartIdx];
118
- let startIdx = 0;
119
- let lastValidLineIndex = startLineIndex;
120
- let lastValidCharIdx = 0;
121
- // exclusiveEnd = fabric 的 i(换行/跨行 flush)或段长(尾 flush)——
122
- // `startIdx < i` 守卫是段内 '\n' 紧跟换行边界的唯一分界(fabric 1552/1574:
123
- // 换行 flush 只推 startIdx 起至 i 前的已积累段,空段不推)
124
- const flush = (exclusiveEnd) => {
125
- if (startIdx >= exclusiveEnd)
126
- return;
127
- const startFlat = flatAt(idx + startIdx);
128
- const lastFlat = flatAt(idx + lastValidCharIdx);
129
- if (startFlat === -1 || lastFlat === -1)
130
- return;
131
- runs.push({
132
- lineIndex: lastValidLineIndex,
133
- start: index2IndexOfLine[startFlat],
134
- end: index2IndexOfLine[lastFlat] + 1,
135
- info
136
- });
137
- };
138
- for (let i = 0; i < tObj.text.length; i++) {
139
- const mappedIdx = flatAt(idx + i);
140
- if (mappedIdx === -1) {
141
- // fabric 1551-1565:段内 '\n'(映射 -1)——已累积部分按所在行截断成段
142
- flush(i);
143
- startIdx = i + 1;
144
- continue;
145
- }
146
- const curLineIndex = indexLineMap[mappedIdx];
147
- if (curLineIndex !== startLineIndex) {
148
- // fabric 1573-1588:跨行边界——前段按 lastValidLineIndex 截断
149
- flush(i);
150
- startIdx = i;
151
- startLineIndex = curLineIndex;
152
- }
153
- lastValidLineIndex = curLineIndex;
154
- lastValidCharIdx = i;
155
- }
156
- flush(tObj.text.length);
157
- idx += tObj.text.length;
158
- }
159
- return runs;
160
- };
161
- /** fabric getAlignedTranslateY(1657-1666)逐式复刻 */
162
- const alignedTranslateY = (targetTop, targetHeight, boxTop, rawBoxHeight, scale, alignVertical) => {
163
- const boxHeight = rawBoxHeight || targetHeight;
164
- if (alignVertical === 'bottom')
165
- return targetTop + targetHeight - (boxTop + boxHeight) * scale;
166
- if (alignVertical === 'top')
167
- return targetTop - boxTop * scale;
168
- return targetTop + (targetHeight - boxHeight * scale) / 2 - boxTop * scale;
169
- };
170
- const boundsOfPath = (d) => {
171
- const commands = parsePathData(d);
172
- if (!commands)
173
- return null;
174
- const b = getBoundsOfPath(commands);
175
- if (!b)
176
- return null;
177
- return { left: b.left, top: b.top, width: b.right - b.left, height: b.bottom - b.top };
178
- };
179
- /** fabric getFirstSingleHighlightSubPath(1634-1656):取首子路径并补闭合 */
180
- const firstSingleSubPath = (rawPath) => {
181
- const subPaths = rawPath
182
- .split(/[Zz]/)
183
- .map((p) => p.trim())
184
- .filter((p) => p.length > 0);
185
- if (subPaths.length === 0)
186
- return null;
187
- const p = subPaths[0];
188
- return p.endsWith('Z') || p.endsWith('z') ? p : `${p} Z`;
189
- };
190
- /**
191
- * 绘制计划:runs → 本地中心系 op 列表 + 出血余量。
192
- *
193
- * 本地系与字形管线同构:lineLeft = −layout.width/2 + line.leftOffset、
194
- * 行顶 y = contentTopY + line.top(contentTopY = −dims.y/2,可能深于
195
- * −layout.height/2——盒被 mt/mb 抬高时内容块上移,计划不假设居中)。
196
- *
197
- * span 模式(fabric 1722-1762):整段拉伸——scaleX = 段宽/path宽、
198
- * scaleY = 行字高/boxHeight(top/bottom 档按 pathBottom 参考高重算)、
199
- * translate 使 path 盒对齐段矩形左上(alignVertical 三档)。
200
- * isSingle 模式(fabric 1667-1719):首子路径逐字重复——uniformScale =
201
- * min(字宽/path宽, 字高/pathHeight)×svgInfo.scale、水平居中、跳空白字;
202
- * bottom 档走 fabric 特有的 cTop+cHeight−box.top×s 式(非 getAlignedTranslateY)。
203
- */
204
- export const planTextHighlight = (text, layout, texts, contentTopY, objectFontSize) => {
205
- const runs = highlightRuns(text, layout, texts);
206
- if (runs.length === 0)
207
- return null;
208
- const ops = [];
209
- // 真实墨迹累计包围盒(本地中心系)——pad 由其对内容盒的溢出量导出(批次62修:
210
- // isSingle scale>1 时墨迹超出字盒,如 mock 逐字圆点 scale 1.3 直径 104 超出 80
211
- // 字盒上下各 12px;原「isFill 零出血」口径把溢出弧线切在画布边缘)
212
- const ink = { minX: Infinity, minY: Infinity, maxX: -Infinity, maxY: -Infinity };
213
- // op 墨迹包围盒:path 盒经 translate+scale 变换 + 描边出血(各轴独立)
214
- const extendInk = (op, box) => {
215
- const hx = op.isFill ? 0 : ((op.strokeWidth || 0) * Math.abs(op.scaleX)) / 2;
216
- const hy = op.isFill ? 0 : ((op.strokeWidth || 0) * Math.abs(op.scaleY)) / 2;
217
- const x0 = op.translateX + box.left * op.scaleX - hx;
218
- const y0 = op.translateY + box.top * op.scaleY - hy;
219
- const x1 = op.translateX + (box.left + box.width) * op.scaleX + hx;
220
- const y1 = op.translateY + (box.top + box.height) * op.scaleY + hy;
221
- if (x0 < ink.minX)
222
- ink.minX = x0;
223
- if (y0 < ink.minY)
224
- ink.minY = y0;
225
- if (x1 > ink.maxX)
226
- ink.maxX = x1;
227
- if (y1 > ink.maxY)
228
- ink.maxY = y1;
229
- };
230
- for (const run of runs) {
231
- const line = layout.lines[run.lineIndex];
232
- if (!line)
233
- continue;
234
- const info = run.info;
235
- const rawPath = typeof info.path === 'string' ? info.path : '';
236
- if (!rawPath)
237
- continue;
238
- const alignVertical = info.alignVertical || 'center';
239
- const isFill = info.isFill === true;
240
- const strokeWidth = info.strokeWidth || 0;
241
- const lineLeft = -layout.width / 2 + line.leftOffset;
242
- const top = contentTopY + line.top;
243
- const startBox = boxAt(line, run.start, objectFontSize);
244
- if (!startBox)
245
- continue;
246
- if (info.isSingle === true) {
247
- // 首子路径逐字重复
248
- const subD = firstSingleSubPath(rawPath);
249
- if (!subD)
250
- continue;
251
- const box = boundsOfPath(subD);
252
- if (!box || !Number.isFinite(box.width) || !Number.isFinite(box.height))
253
- continue;
254
- const path2dSource = subD;
255
- for (let j = run.start; j < run.end; j++) {
256
- const ch = line.graphemes[j];
257
- if (!ch || /^\s$/.test(ch))
258
- continue;
259
- const charBox = boxAt(line, j, objectFontSize);
260
- const nextBox = boxAt(line, j + 1, objectFontSize);
261
- if (!charBox)
262
- continue;
263
- const cLeft = lineLeft + charBox.left;
264
- const cTop = top;
265
- const cWidth = charBox.kernedWidth || charBox.width || (nextBox ? nextBox.left : charBox.left) - charBox.left;
266
- const cHeight = charBox.height;
267
- let boxHeight = box.height;
268
- if (!boxHeight)
269
- boxHeight = cHeight;
270
- const scaleXCandidate = box.width ? cWidth / box.width : 1;
271
- const scaleYCandidate = boxHeight ? cHeight / boxHeight : 1;
272
- const scale = info.scale || 1;
273
- const uniformScale = Math.min(scaleXCandidate, scaleYCandidate) * scale;
274
- const scaledW = (box.width || 0) * uniformScale;
275
- const translateX = cLeft + (cWidth - scaledW) / 2 - box.left * uniformScale;
276
- const translateY = alignVertical === 'bottom' ? cTop + cHeight - box.top * uniformScale : alignedTranslateY(cTop, cHeight, box.top, boxHeight, uniformScale, alignVertical);
277
- const op = {
278
- d: path2dSource,
279
- translateX,
280
- translateY,
281
- scaleX: uniformScale,
282
- scaleY: uniformScale,
283
- isFill,
284
- fill: info.fill || '#9FFFFC',
285
- stroke: info.stroke || '#9FFFFC',
286
- strokeWidth
287
- };
288
- ops.push(op);
289
- extendInk(op, box);
290
- }
291
- continue;
292
- }
293
- // span 整段拉伸
294
- const endBox = boxAt(line, run.end, objectFontSize);
295
- if (!endBox)
296
- continue;
297
- const left = lineLeft + startBox.left;
298
- const width = endBox.left - startBox.left;
299
- const height = startBox.height;
300
- const box = boundsOfPath(rawPath);
301
- if (!box || !Number.isFinite(box.width) || !Number.isFinite(box.height) || box.width === 0)
302
- continue;
303
- let boxHeight = box.height;
304
- if (!boxHeight)
305
- boxHeight = height;
306
- const scaleX = width / box.width;
307
- let scaleY = height / boxHeight;
308
- const translateX = left - box.left * scaleX;
309
- let translateY = alignedTranslateY(top, height, box.top, boxHeight, scaleY, alignVertical);
310
- if (alignVertical === 'bottom' || alignVertical === 'top') {
311
- const pathBottom = box.top + boxHeight;
312
- const referenceHeight = pathBottom > 0 ? pathBottom : boxHeight || 1;
313
- scaleY = height / referenceHeight;
314
- translateY = alignedTranslateY(top, height, box.top, boxHeight, scaleY, alignVertical);
315
- }
316
- if (!box.height)
317
- translateY += height / 2;
318
- const op = {
319
- d: rawPath,
320
- translateX,
321
- translateY,
322
- scaleX,
323
- scaleY,
324
- isFill,
325
- fill: info.fill || '#9FFFFC',
326
- stroke: info.stroke || '#9FFFFC',
327
- strokeWidth
328
- };
329
- ops.push(op);
330
- extendInk(op, box);
331
- }
332
- if (ops.length === 0)
333
- return null;
334
- // pad = 墨迹溢出内容盒 [−w/2, w/2] × [contentTopY, contentTopY+h] 的量(四向
335
- // 取大——画布是单矩形);无溢出保底 2px(AA 余量)。左溢出 = −half − minX
336
- // (盒左缘是 −half——曾写反成 half − minX,贴盒左缘的段恒溢出 2×half)
337
- const half = layout.width / 2;
338
- const finite = Number.isFinite(ink.minX) && Number.isFinite(ink.minY);
339
- const padX = finite ? Math.max(2, -half - ink.minX, ink.maxX - half) : 2;
340
- const padY = finite ? Math.max(2, contentTopY - ink.minY, ink.maxY - (contentTopY + layout.height)) : 2;
341
- return { ops, padX, padY };
342
- };
343
- /**
344
- * canvas2d 烘焙:计划 → 纹理源。画布覆盖本地矩形
345
- * [−(layout.width/2+padX), +] × [contentTopY−padY, contentTopY+layout.height+padY]
346
- * (y 向锚内容块顶——盒抬高时 quad 由调用方按 contentTopY 偏心推送)。
347
- * scale = 分桶(同字形/虚线烘焙口径,超采样防放大糊)。
348
- */
349
- export const bakeTextHighlight = (plan, layout, contentTopY, scale) => {
350
- const logicalW = Math.ceil(layout.width + plan.padX * 2);
351
- const logicalH = Math.ceil(layout.height + plan.padY * 2);
352
- if (!(logicalW > 0) || !(logicalH > 0) || logicalW > 8192 || logicalH > 8192)
353
- return null;
354
- const canvas = document.createElement('canvas');
355
- canvas.width = Math.ceil(logicalW * scale);
356
- canvas.height = Math.ceil(logicalH * scale);
357
- const ctx = canvas.getContext('2d');
358
- if (!ctx)
359
- return null;
360
- ctx.setTransform(scale, 0, 0, scale, 0, 0);
361
- // 本地中心系 → 画布:x + logicalW/2;y − contentTopY + padY(锚内容块顶)
362
- ctx.translate(layout.width / 2 + plan.padX, plan.padY - contentTopY);
363
- for (const op of plan.ops) {
364
- const path = new Path2D(op.d);
365
- ctx.save();
366
- ctx.translate(op.translateX, op.translateY);
367
- ctx.scale(op.scaleX, op.scaleY);
368
- if (op.isFill) {
369
- ctx.fillStyle = op.fill;
370
- ctx.fill(path);
371
- }
372
- else {
373
- ctx.lineWidth = op.strokeWidth;
374
- ctx.strokeStyle = op.stroke;
375
- ctx.stroke(path);
376
- }
377
- ctx.restore();
378
- }
379
- return { canvas, logicalW, logicalH };
380
- };
@@ -1,26 +0,0 @@
1
- /**
2
- * GL 纹理上传工具(从 EngineCanvas 收编的样板,调用序逐处同构):
3
- * createTexture → bindTexture → texImage2D(RGBA/UNSIGNED_BYTE) →
4
- * (generateMipmap) → MIN_FILTER → MAG_FILTER → WRAP_S/T。
5
- *
6
- * 实际只有 3 种参数组合:缺省(LINEAR + CLAMP,位图/烘焙画布)、
7
- * mipmap(阴影类烘焙,MIN=LINEAR_MIPMAP_LINEAR)、mipmap+repeat
8
- * (图案纹理唯一——WebGL2 NPOT 可 REPEAT)。createTexture 失败返回
9
- * null,调用点原有 null 守卫语义不变。不收编 GLTextureCache.get
10
- * (FLIP_Y 语境)与 GLIsolator.ensureSize(null 数据重载)。
11
- */
12
- export const createTexture2D = (gl, source, options = {}) => {
13
- const tex = gl.createTexture();
14
- if (!tex)
15
- return null;
16
- gl.bindTexture(gl.TEXTURE_2D, tex);
17
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, source);
18
- if (options.mipmap)
19
- gl.generateMipmap(gl.TEXTURE_2D);
20
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, options.mipmap ? gl.LINEAR_MIPMAP_LINEAR : gl.LINEAR);
21
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR);
22
- const wrap = options.repeat ? gl.REPEAT : gl.CLAMP_TO_EDGE;
23
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, wrap);
24
- gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, wrap);
25
- return tex;
26
- };
@@ -1,63 +0,0 @@
1
- /**
2
- * 竖排文本的 canvas 逐字绘制助手(P4-5c)。
3
- *
4
- * shadowBake 剪影与 TextRenderer 虚线描边烘焙共用——两处都以 canvas2d 复刻
5
- * 应用 Textbox `_renderStr` 的竖排分支(内部坐标系:行沿 +x 行进、经对象
6
- * angle:90 的通用矩阵转竖,引擎不做任何角度特判)。quad 管线
7
- * (renderGlyphPass)不在此列——四类姿态在 GL 侧用矩阵等价实现。
8
- *
9
- * textOffsetY 隔字抖动不在此列(调用方以 charJitterY 平移 op.y——横排/
10
- * 竖排四姿态共用,fabric _renderStr 2714-2757 口径)。
11
- */
12
- import { verticalAnchorShiftX, verticalAnchorShiftY, verticalCharClass, verticalRenderAdvance } from '../model/textLayout';
13
- /**
14
- * 单行竖排逐字摆位(fabric _renderChars 2459-2478 笔位 + _renderStr
15
- * 2711-2743 姿态)。lineLeft/baselineY 为该行行首 x 与基线 y(对象中心系);
16
- * style/charSpacing 为对象级样式(逐字 fontSize 覆写用于锚点偏移)。
17
- */
18
- export const verticalGlyphOps = (line, lineLeft, baselineY, style, charSpacing) => {
19
- const ops = [];
20
- const vSpacing = charSpacing ? (style.fontSize * charSpacing) / 1000 : 0;
21
- let penV = 0;
22
- for (let i = 0; i < line.graphemes.length; i++) {
23
- const g = line.graphemes[i];
24
- const box = line.boxes[i];
25
- const fontSize = line.charStyles[i]?.fontSize ?? style.fontSize;
26
- const klass = verticalCharClass(g);
27
- if (klass === 'latin' || klass === 'bracket') {
28
- // 拉丁画位前移 kerned−width(fabric signWidth),括号原样平画
29
- ops.push({ ch: g, rotated: false, x: lineLeft + penV + (klass === 'latin' ? box.kernedWidth - box.width : 0), y: baselineY });
30
- }
31
- else {
32
- ops.push({ ch: g, rotated: true, x: lineLeft + penV + verticalAnchorShiftX(fontSize), y: baselineY + verticalAnchorShiftY(klass, box, fontSize) });
33
- }
34
- penV += verticalRenderAdvance(g, box, vSpacing);
35
- }
36
- return ops;
37
- };
38
- /** 按摆位画一个竖排字符(fill/stroke 二选一;font/描边参数由调用方预设) */
39
- export const drawVerticalGlyph = (ctx, op, method) => {
40
- if (!op.rotated) {
41
- ctx[method](op.ch, op.x, op.y);
42
- return;
43
- }
44
- ctx.save();
45
- ctx.translate(op.x, op.y);
46
- ctx.rotate(-Math.PI / 2);
47
- ctx[method](op.ch, 0, 0);
48
- ctx.restore();
49
- };
50
- /** 逐字字体四件套解析(glyph pass / bakes 同口径的覆写合并) */
51
- export const glyphStyleAt = (style, o) => {
52
- if (!o || (o.fontSize === undefined && o.fontFamily === undefined && o.fontWeight === undefined && o.fontStyle === undefined))
53
- return style;
54
- return {
55
- ...style,
56
- fontSize: o.fontSize ?? style.fontSize,
57
- fontFamily: o.fontFamily ?? style.fontFamily,
58
- fontWeight: o.fontWeight ?? style.fontWeight,
59
- fontStyle: o.fontStyle ?? style.fontStyle
60
- };
61
- };
62
- /** TextNode 是否竖排(引擎唯一判定源:vertical === true,无角度特判) */
63
- export const isVerticalText = (node) => node.raw.vertical === true;