@pairdraw/core 0.18.0 → 0.19.0

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 (913) hide show
  1. package/dist/canvas/effects.d.ts +5 -11
  2. package/dist/canvas/effects.d.ts.map +1 -1
  3. package/dist/canvas/effects.js +25 -30
  4. package/dist/canvas/effects.js.map +1 -1
  5. package/dist/canvas/labels/hit-test.d.ts +5 -0
  6. package/dist/canvas/labels/hit-test.d.ts.map +1 -1
  7. package/dist/canvas/labels/hit-test.js +1 -1
  8. package/dist/canvas/labels/hit-test.js.map +1 -1
  9. package/dist/canvas/labels/paragraph-cache.d.ts.map +1 -1
  10. package/dist/canvas/labels/paragraph-cache.js +3 -2
  11. package/dist/canvas/labels/paragraph-cache.js.map +1 -1
  12. package/dist/canvas/labels/selection.js +3 -2
  13. package/dist/canvas/labels/selection.js.map +1 -1
  14. package/dist/canvas/labels/style.d.ts +1 -1
  15. package/dist/canvas/node-edit-overlay.js +2 -2
  16. package/dist/canvas/node-edit-overlay.js.map +1 -1
  17. package/dist/canvas/overlays/index.d.ts +2 -2
  18. package/dist/canvas/overlays/index.js +2 -2
  19. package/dist/canvas/overlays/selection.d.ts +1 -2
  20. package/dist/canvas/overlays/selection.d.ts.map +1 -1
  21. package/dist/canvas/overlays/selection.js +4 -37
  22. package/dist/canvas/overlays/selection.js.map +1 -1
  23. package/dist/canvas/region-hatch.js +3 -2
  24. package/dist/canvas/region-hatch.js.map +1 -1
  25. package/dist/canvas/renderer/colors.d.ts.map +1 -1
  26. package/dist/canvas/renderer/colors.js +36 -18
  27. package/dist/canvas/renderer/colors.js.map +1 -1
  28. package/dist/canvas/renderer/font-waiters.d.ts +9 -0
  29. package/dist/canvas/renderer/font-waiters.d.ts.map +1 -0
  30. package/dist/canvas/renderer/font-waiters.js +26 -0
  31. package/dist/canvas/renderer/font-waiters.js.map +1 -0
  32. package/dist/canvas/renderer/fonts.d.ts +4 -2
  33. package/dist/canvas/renderer/fonts.d.ts.map +1 -1
  34. package/dist/canvas/renderer/fonts.js +23 -9
  35. package/dist/canvas/renderer/fonts.js.map +1 -1
  36. package/dist/canvas/renderer/lifecycle.d.ts.map +1 -1
  37. package/dist/canvas/renderer/lifecycle.js +6 -9
  38. package/dist/canvas/renderer/lifecycle.js.map +1 -1
  39. package/dist/canvas/renderer/methods.d.ts +4 -5
  40. package/dist/canvas/renderer/methods.d.ts.map +1 -1
  41. package/dist/canvas/renderer/methods.js +1 -4
  42. package/dist/canvas/renderer/methods.js.map +1 -1
  43. package/dist/canvas/renderer/paints.d.ts.map +1 -1
  44. package/dist/canvas/renderer/paints.js +0 -6
  45. package/dist/canvas/renderer/paints.js.map +1 -1
  46. package/dist/canvas/renderer/pipeline.d.ts.map +1 -1
  47. package/dist/canvas/renderer/pipeline.js +20 -2
  48. package/dist/canvas/renderer/pipeline.js.map +1 -1
  49. package/dist/canvas/renderer/retained-backing.js +4 -4
  50. package/dist/canvas/renderer/retained-backing.js.map +1 -1
  51. package/dist/canvas/renderer/state.js +1 -1
  52. package/dist/canvas/renderer/state.js.map +1 -1
  53. package/dist/canvas/renderer/tiles/controller.d.ts +2 -0
  54. package/dist/canvas/renderer/tiles/controller.d.ts.map +1 -1
  55. package/dist/canvas/renderer/tiles/controller.js +8 -0
  56. package/dist/canvas/renderer/tiles/controller.js.map +1 -1
  57. package/dist/canvas/renderer/tiles/surface-pool.js +1 -1
  58. package/dist/canvas/renderer/tiles/surface-pool.js.map +1 -1
  59. package/dist/canvas/renderer/visual-bounds.d.ts.map +1 -1
  60. package/dist/canvas/renderer/visual-bounds.js +7 -5
  61. package/dist/canvas/renderer/visual-bounds.js.map +1 -1
  62. package/dist/canvas/renderer.d.ts +22 -7
  63. package/dist/canvas/renderer.d.ts.map +1 -1
  64. package/dist/canvas/renderer.js +46 -11
  65. package/dist/canvas/renderer.js.map +1 -1
  66. package/dist/canvas/rulers.d.ts +8 -1
  67. package/dist/canvas/rulers.d.ts.map +1 -1
  68. package/dist/canvas/rulers.js +30 -5
  69. package/dist/canvas/rulers.js.map +1 -1
  70. package/dist/canvas/scene.d.ts +2 -1
  71. package/dist/canvas/scene.d.ts.map +1 -1
  72. package/dist/canvas/scene.js +30 -18
  73. package/dist/canvas/scene.js.map +1 -1
  74. package/dist/canvas/shadows/shape.js +1 -1
  75. package/dist/canvas/shadows/shape.js.map +1 -1
  76. package/dist/canvas/shadows/silhouette.d.ts.map +1 -1
  77. package/dist/canvas/shadows/silhouette.js +4 -2
  78. package/dist/canvas/shadows/silhouette.js.map +1 -1
  79. package/dist/canvas/shadows.d.ts.map +1 -1
  80. package/dist/canvas/shadows.js +3 -2
  81. package/dist/canvas/shadows.js.map +1 -1
  82. package/dist/canvas/text/derived.d.ts +1 -2
  83. package/dist/canvas/text/derived.d.ts.map +1 -1
  84. package/dist/canvas/text/derived.js +1 -7
  85. package/dist/canvas/text/derived.js.map +1 -1
  86. package/dist/canvas/text/emoji/index.js +1 -1
  87. package/dist/canvas/text/emoji/raster.d.ts.map +1 -1
  88. package/dist/canvas/text/emoji/raster.js +14 -10
  89. package/dist/canvas/text/emoji/raster.js.map +1 -1
  90. package/dist/canvas/text/font-families.d.ts.map +1 -1
  91. package/dist/canvas/text/font-families.js +5 -2
  92. package/dist/canvas/text/font-families.js.map +1 -1
  93. package/dist/canvas/text/index.d.ts +1 -3
  94. package/dist/canvas/text/index.d.ts.map +1 -1
  95. package/dist/canvas/text/index.js +1 -8
  96. package/dist/canvas/text/index.js.map +1 -1
  97. package/dist/canvas/text/layout/build.d.ts.map +1 -1
  98. package/dist/canvas/text/layout/build.js +25 -9
  99. package/dist/canvas/text/layout/build.js.map +1 -1
  100. package/dist/canvas/text/layout/index.d.ts.map +1 -1
  101. package/dist/canvas/text/layout/index.js +8 -4
  102. package/dist/canvas/text/layout/index.js.map +1 -1
  103. package/dist/canvas/text/layout/lines.js +5 -3
  104. package/dist/canvas/text/layout/lines.js.map +1 -1
  105. package/dist/canvas/text/paragraph/index.d.ts +5 -0
  106. package/dist/canvas/text/paragraph/index.d.ts.map +1 -1
  107. package/dist/canvas/text/paragraph/index.js +16 -7
  108. package/dist/canvas/text/paragraph/index.js.map +1 -1
  109. package/dist/canvas/text/paragraph/inputs.d.ts +1 -1
  110. package/dist/canvas/text/paragraph/inputs.d.ts.map +1 -1
  111. package/dist/canvas/text/paragraph/inputs.js +9 -2
  112. package/dist/canvas/text/paragraph/inputs.js.map +1 -1
  113. package/dist/canvas/text/placed.js +1 -1
  114. package/dist/canvas/text/shape.d.ts +4 -3
  115. package/dist/canvas/text/shape.d.ts.map +1 -1
  116. package/dist/canvas/text/shape.js +9 -22
  117. package/dist/canvas/text/shape.js.map +1 -1
  118. package/dist/constants.d.ts +6 -2
  119. package/dist/constants.d.ts.map +1 -1
  120. package/dist/constants.js +6 -2
  121. package/dist/constants.js.map +1 -1
  122. package/dist/editor/bridges/clipboard.d.ts +1 -0
  123. package/dist/editor/bridges/clipboard.js +1 -0
  124. package/dist/editor/bridges/clipboard.js.map +1 -1
  125. package/dist/editor/bridges/components.d.ts +2 -0
  126. package/dist/editor/bridges/components.d.ts.map +1 -1
  127. package/dist/editor/bridges/components.js +2 -0
  128. package/dist/editor/bridges/components.js.map +1 -1
  129. package/dist/editor/bridges/frames.d.ts +4 -3
  130. package/dist/editor/bridges/frames.d.ts.map +1 -1
  131. package/dist/editor/bridges/frames.js +6 -4
  132. package/dist/editor/bridges/frames.js.map +1 -1
  133. package/dist/editor/bridges/structure.d.ts +1 -0
  134. package/dist/editor/bridges/structure.d.ts.map +1 -1
  135. package/dist/editor/bridges/structure.js +1 -0
  136. package/dist/editor/bridges/structure.js.map +1 -1
  137. package/dist/editor/clipboard/detach.js +2 -2
  138. package/dist/editor/clipboard/detach.js.map +1 -1
  139. package/dist/editor/clipboard/paste/properties.js +1 -1
  140. package/dist/editor/clipboard/paste/target.js +2 -2
  141. package/dist/editor/clipboard/paste/target.js.map +1 -1
  142. package/dist/editor/clipboard/snapshot.d.ts +3 -0
  143. package/dist/editor/clipboard/snapshot.d.ts.map +1 -1
  144. package/dist/editor/clipboard/snapshot.js +2 -0
  145. package/dist/editor/clipboard/snapshot.js.map +1 -1
  146. package/dist/editor/clipboard/variables.d.ts.map +1 -1
  147. package/dist/editor/clipboard/variables.js +14 -1
  148. package/dist/editor/clipboard/variables.js.map +1 -1
  149. package/dist/editor/clipboard.d.ts +1 -0
  150. package/dist/editor/clipboard.d.ts.map +1 -1
  151. package/dist/editor/clipboard.js +122 -16
  152. package/dist/editor/clipboard.js.map +1 -1
  153. package/dist/editor/component-sync.d.ts +10 -1
  154. package/dist/editor/component-sync.d.ts.map +1 -1
  155. package/dist/editor/component-sync.js +25 -8
  156. package/dist/editor/component-sync.js.map +1 -1
  157. package/dist/editor/components/authoring/text-edit.d.ts.map +1 -1
  158. package/dist/editor/components/authoring/text-edit.js +11 -2
  159. package/dist/editor/components/authoring/text-edit.js.map +1 -1
  160. package/dist/editor/components/authoring/visibility-edit.d.ts.map +1 -1
  161. package/dist/editor/components/authoring/visibility-edit.js +7 -3
  162. package/dist/editor/components/authoring/visibility-edit.js.map +1 -1
  163. package/dist/editor/components/instances.d.ts +2 -0
  164. package/dist/editor/components/instances.d.ts.map +1 -1
  165. package/dist/editor/components/instances.js +37 -7
  166. package/dist/editor/components/instances.js.map +1 -1
  167. package/dist/editor/components/properties.d.ts.map +1 -1
  168. package/dist/editor/components/properties.js +3 -0
  169. package/dist/editor/components/properties.js.map +1 -1
  170. package/dist/editor/components/slots/authoring.js +2 -1
  171. package/dist/editor/components/slots/authoring.js.map +1 -1
  172. package/dist/editor/components.d.ts +2 -0
  173. package/dist/editor/components.d.ts.map +1 -1
  174. package/dist/editor/create.d.ts +17 -3
  175. package/dist/editor/create.d.ts.map +1 -1
  176. package/dist/editor/create.js +43 -6
  177. package/dist/editor/create.js.map +1 -1
  178. package/dist/editor/guides.d.ts.map +1 -1
  179. package/dist/editor/guides.js +20 -13
  180. package/dist/editor/guides.js.map +1 -1
  181. package/dist/editor/history/document-change.d.ts +19 -3
  182. package/dist/editor/history/document-change.d.ts.map +1 -1
  183. package/dist/editor/history/document-change.js +94 -8
  184. package/dist/editor/history/document-change.js.map +1 -1
  185. package/dist/editor/history/edit.d.ts.map +1 -1
  186. package/dist/editor/history/edit.js +56 -12
  187. package/dist/editor/history/edit.js.map +1 -1
  188. package/dist/editor/history/position.js +1 -4
  189. package/dist/editor/history/position.js.map +1 -1
  190. package/dist/editor/history/sources.d.ts +14 -0
  191. package/dist/editor/history/sources.d.ts.map +1 -0
  192. package/dist/editor/history/sources.js +24 -0
  193. package/dist/editor/history/sources.js.map +1 -0
  194. package/dist/editor/index.d.ts +2 -2
  195. package/dist/editor/index.js +1 -1
  196. package/dist/editor/layout-mode.d.ts.map +1 -1
  197. package/dist/editor/layout-mode.js +16 -1
  198. package/dist/editor/layout-mode.js.map +1 -1
  199. package/dist/editor/node-preview.d.ts.map +1 -1
  200. package/dist/editor/node-preview.js +26 -7
  201. package/dist/editor/node-preview.js.map +1 -1
  202. package/dist/editor/nodes.d.ts.map +1 -1
  203. package/dist/editor/nodes.js +33 -10
  204. package/dist/editor/nodes.js.map +1 -1
  205. package/dist/editor/nudge.d.ts.map +1 -1
  206. package/dist/editor/nudge.js +12 -2
  207. package/dist/editor/nudge.js.map +1 -1
  208. package/dist/editor/pages.d.ts +2 -1
  209. package/dist/editor/pages.d.ts.map +1 -1
  210. package/dist/editor/pages.js +94 -15
  211. package/dist/editor/pages.js.map +1 -1
  212. package/dist/editor/play/states.d.ts.map +1 -1
  213. package/dist/editor/play/states.js +0 -5
  214. package/dist/editor/play/states.js.map +1 -1
  215. package/dist/editor/read-only/actions.js +3 -0
  216. package/dist/editor/read-only/actions.js.map +1 -1
  217. package/dist/editor/selection/hit-test.d.ts +2 -1
  218. package/dist/editor/selection/hit-test.d.ts.map +1 -1
  219. package/dist/editor/selection/hit-test.js +29 -4
  220. package/dist/editor/selection/hit-test.js.map +1 -1
  221. package/dist/editor/selection.d.ts +2 -2
  222. package/dist/editor/selection.d.ts.map +1 -1
  223. package/dist/editor/shapes/pen.js +6 -2
  224. package/dist/editor/shapes/pen.js.map +1 -1
  225. package/dist/editor/shapes.d.ts.map +1 -1
  226. package/dist/editor/shapes.js +2 -1
  227. package/dist/editor/shapes.js.map +1 -1
  228. package/dist/editor/structure/auto-layout-wrap.d.ts.map +1 -1
  229. package/dist/editor/structure/auto-layout-wrap.js +12 -0
  230. package/dist/editor/structure/auto-layout-wrap.js.map +1 -1
  231. package/dist/editor/structure/boolean.js +1 -1
  232. package/dist/editor/structure/group/bounds.d.ts +4 -2
  233. package/dist/editor/structure/group/bounds.d.ts.map +1 -1
  234. package/dist/editor/structure/group/bounds.js +17 -4
  235. package/dist/editor/structure/group/bounds.js.map +1 -1
  236. package/dist/editor/structure/rename.d.ts +2 -3
  237. package/dist/editor/structure/rename.d.ts.map +1 -1
  238. package/dist/editor/structure/rename.js +2 -5
  239. package/dist/editor/structure/rename.js.map +1 -1
  240. package/dist/editor/structure/reorder.d.ts.map +1 -1
  241. package/dist/editor/structure/reorder.js +20 -9
  242. package/dist/editor/structure/reorder.js.map +1 -1
  243. package/dist/editor/structure/state.js +1 -1
  244. package/dist/editor/structure.d.ts +1 -0
  245. package/dist/editor/structure.d.ts.map +1 -1
  246. package/dist/editor/structure.js +76 -20
  247. package/dist/editor/structure.js.map +1 -1
  248. package/dist/editor/text/hyperlink.d.ts.map +1 -1
  249. package/dist/editor/text/hyperlink.js +1 -1
  250. package/dist/editor/text/hyperlink.js.map +1 -1
  251. package/dist/editor/text/name.d.ts +13 -5
  252. package/dist/editor/text/name.d.ts.map +1 -1
  253. package/dist/editor/text/name.js +47 -17
  254. package/dist/editor/text/name.js.map +1 -1
  255. package/dist/editor/text/pending-layout.d.ts +2 -1
  256. package/dist/editor/text/pending-layout.d.ts.map +1 -1
  257. package/dist/editor/text/pending-layout.js +33 -6
  258. package/dist/editor/text/pending-layout.js.map +1 -1
  259. package/dist/editor/text/selection-style.d.ts +1 -0
  260. package/dist/editor/text/selection-style.d.ts.map +1 -1
  261. package/dist/editor/text/selection-style.js +16 -4
  262. package/dist/editor/text/selection-style.js.map +1 -1
  263. package/dist/editor/text.d.ts +5 -0
  264. package/dist/editor/text.d.ts.map +1 -1
  265. package/dist/editor/text.js +70 -3
  266. package/dist/editor/text.js.map +1 -1
  267. package/dist/editor/types.d.ts +18 -1
  268. package/dist/editor/types.d.ts.map +1 -1
  269. package/dist/editor/undo.d.ts.map +1 -1
  270. package/dist/editor/undo.js +14 -2
  271. package/dist/editor/undo.js.map +1 -1
  272. package/dist/editor/variable-bindings.d.ts.map +1 -1
  273. package/dist/editor/variable-bindings.js +21 -2
  274. package/dist/editor/variable-bindings.js.map +1 -1
  275. package/dist/editor/variables.d.ts +1 -1
  276. package/dist/editor/variables.d.ts.map +1 -1
  277. package/dist/editor/variables.js +7 -8
  278. package/dist/editor/variables.js.map +1 -1
  279. package/dist/editor/viewport.d.ts +11 -2
  280. package/dist/editor/viewport.d.ts.map +1 -1
  281. package/dist/editor/viewport.js +61 -21
  282. package/dist/editor/viewport.js.map +1 -1
  283. package/dist/editor/views/actions.d.ts.map +1 -1
  284. package/dist/editor/views/actions.js +13 -5
  285. package/dist/editor/views/actions.js.map +1 -1
  286. package/dist/editor/views/present.d.ts +6 -4
  287. package/dist/editor/views/present.d.ts.map +1 -1
  288. package/dist/editor/views/present.js +12 -10
  289. package/dist/editor/views/present.js.map +1 -1
  290. package/dist/editor/views/types.d.ts +11 -5
  291. package/dist/editor/views/types.d.ts.map +1 -1
  292. package/dist/figma-api/accessor-utils.d.ts.map +1 -1
  293. package/dist/figma-api/accessor-utils.js +4 -1
  294. package/dist/figma-api/accessor-utils.js.map +1 -1
  295. package/dist/figma-api/accessors/basic.d.ts.map +1 -1
  296. package/dist/figma-api/accessors/basic.js +41 -21
  297. package/dist/figma-api/accessors/basic.js.map +1 -1
  298. package/dist/figma-api/accessors/layout.d.ts.map +1 -1
  299. package/dist/figma-api/accessors/layout.js +37 -7
  300. package/dist/figma-api/accessors/layout.js.map +1 -1
  301. package/dist/figma-api/accessors/reactions.d.ts +11 -0
  302. package/dist/figma-api/accessors/reactions.d.ts.map +1 -0
  303. package/dist/figma-api/accessors/reactions.js +30 -0
  304. package/dist/figma-api/accessors/reactions.js.map +1 -0
  305. package/dist/figma-api/accessors/strokes.d.ts.map +1 -1
  306. package/dist/figma-api/accessors/strokes.js +12 -4
  307. package/dist/figma-api/accessors/strokes.js.map +1 -1
  308. package/dist/figma-api/accessors/text/index.d.ts.map +1 -1
  309. package/dist/figma-api/accessors/text/index.js +3 -1
  310. package/dist/figma-api/accessors/text/index.js.map +1 -1
  311. package/dist/figma-api/accessors/vector.d.ts.map +1 -1
  312. package/dist/figma-api/accessors/vector.js +1 -1
  313. package/dist/figma-api/accessors/vector.js.map +1 -1
  314. package/dist/figma-api/accessors/visual.d.ts +6 -5
  315. package/dist/figma-api/accessors/visual.d.ts.map +1 -1
  316. package/dist/figma-api/accessors/visual.js +20 -17
  317. package/dist/figma-api/accessors/visual.js.map +1 -1
  318. package/dist/figma-api/components.d.ts.map +1 -1
  319. package/dist/figma-api/components.js +2 -1
  320. package/dist/figma-api/components.js.map +1 -1
  321. package/dist/figma-api/finite.d.ts +27 -0
  322. package/dist/figma-api/finite.d.ts.map +1 -0
  323. package/dist/figma-api/finite.js +69 -0
  324. package/dist/figma-api/finite.js.map +1 -0
  325. package/dist/figma-api/fonts/list.d.ts +13 -0
  326. package/dist/figma-api/fonts/list.d.ts.map +1 -0
  327. package/dist/figma-api/fonts/list.js +25 -0
  328. package/dist/figma-api/fonts/list.js.map +1 -0
  329. package/dist/figma-api/index.d.ts +21 -3
  330. package/dist/figma-api/index.d.ts.map +1 -1
  331. package/dist/figma-api/index.js +58 -13
  332. package/dist/figma-api/index.js.map +1 -1
  333. package/dist/figma-api/overrides.d.ts +6 -1
  334. package/dist/figma-api/overrides.d.ts.map +1 -1
  335. package/dist/figma-api/overrides.js +2 -2
  336. package/dist/figma-api/overrides.js.map +1 -1
  337. package/dist/figma-api/pending-layout.d.ts +12 -2
  338. package/dist/figma-api/pending-layout.d.ts.map +1 -1
  339. package/dist/figma-api/pending-layout.js +41 -1
  340. package/dist/figma-api/pending-layout.js.map +1 -1
  341. package/dist/figma-api/pending-sync.d.ts +19 -0
  342. package/dist/figma-api/pending-sync.d.ts.map +1 -0
  343. package/dist/figma-api/pending-sync.js +52 -0
  344. package/dist/figma-api/pending-sync.js.map +1 -0
  345. package/dist/figma-api/proxy.d.ts +15 -2
  346. package/dist/figma-api/proxy.d.ts.map +1 -1
  347. package/dist/figma-api/proxy.js +23 -3
  348. package/dist/figma-api/proxy.js.map +1 -1
  349. package/dist/figma-api/reactions.d.ts +104 -0
  350. package/dist/figma-api/reactions.d.ts.map +1 -0
  351. package/dist/figma-api/reactions.js +157 -0
  352. package/dist/figma-api/reactions.js.map +1 -0
  353. package/dist/figma-api/render-bounds.d.ts.map +1 -1
  354. package/dist/figma-api/render-bounds.js +4 -4
  355. package/dist/figma-api/render-bounds.js.map +1 -1
  356. package/dist/figma-api/serialization.js +2 -2
  357. package/dist/figma-api/serialization.js.map +1 -1
  358. package/dist/figma-api/slots.d.ts +7 -1
  359. package/dist/figma-api/slots.d.ts.map +1 -1
  360. package/dist/figma-api/slots.js +12 -4
  361. package/dist/figma-api/slots.js.map +1 -1
  362. package/dist/figma-api/strokes.d.ts +5 -2
  363. package/dist/figma-api/strokes.d.ts.map +1 -1
  364. package/dist/figma-api/strokes.js +12 -19
  365. package/dist/figma-api/strokes.js.map +1 -1
  366. package/dist/figma-api/text/bindings.js +1 -1
  367. package/dist/figma-api/text/index.d.ts +2 -3
  368. package/dist/figma-api/text/index.d.ts.map +1 -1
  369. package/dist/figma-api/text/index.js +2 -12
  370. package/dist/figma-api/text/index.js.map +1 -1
  371. package/dist/figma-api/variables/bindings.js +1 -1
  372. package/dist/figma-api/variables/variable.d.ts.map +1 -1
  373. package/dist/figma-api/variables/variable.js +2 -2
  374. package/dist/figma-api/variables/variable.js.map +1 -1
  375. package/dist/geometry/figma.d.ts +6 -1
  376. package/dist/geometry/figma.d.ts.map +1 -1
  377. package/dist/geometry/figma.js +8 -1
  378. package/dist/geometry/figma.js.map +1 -1
  379. package/dist/geometry/index.d.ts +2 -2
  380. package/dist/geometry/index.js +2 -2
  381. package/dist/icons/api.d.ts +3 -2
  382. package/dist/icons/api.d.ts.map +1 -1
  383. package/dist/icons/api.js +12 -12
  384. package/dist/icons/api.js.map +1 -1
  385. package/dist/icons/provider.d.ts +4 -3
  386. package/dist/icons/provider.d.ts.map +1 -1
  387. package/dist/icons/provider.js +6 -13
  388. package/dist/icons/provider.js.map +1 -1
  389. package/dist/icons/schema.d.ts +33 -1
  390. package/dist/icons/schema.d.ts.map +1 -1
  391. package/dist/icons/schema.js +30 -1
  392. package/dist/icons/schema.js.map +1 -1
  393. package/dist/icons/svg/presentation.d.ts +8 -1
  394. package/dist/icons/svg/presentation.d.ts.map +1 -1
  395. package/dist/icons/svg/presentation.js +21 -3
  396. package/dist/icons/svg/presentation.js.map +1 -1
  397. package/dist/icons/svg/text.js +1 -1
  398. package/dist/icons/svg/text.js.map +1 -1
  399. package/dist/icons/svg.d.ts +8 -3
  400. package/dist/icons/svg.d.ts.map +1 -1
  401. package/dist/icons/svg.js +15 -13
  402. package/dist/icons/svg.js.map +1 -1
  403. package/dist/icons/types.d.ts +1 -19
  404. package/dist/icons/types.d.ts.map +1 -1
  405. package/dist/index.d.ts +2 -2
  406. package/dist/index.js +1 -1
  407. package/dist/io/formats/design-tokens/apply.d.ts +1 -1
  408. package/dist/io/formats/design-tokens/css/read.js +1 -1
  409. package/dist/io/formats/design-tokens/decode.js +1 -1
  410. package/dist/io/formats/design-tokens/plan/index.js +4 -2
  411. package/dist/io/formats/design-tokens/plan/index.js.map +1 -1
  412. package/dist/io/formats/design-tokens/plan/styles.d.ts +9 -1
  413. package/dist/io/formats/design-tokens/plan/styles.d.ts.map +1 -1
  414. package/dist/io/formats/design-tokens/plan/styles.js +23 -3
  415. package/dist/io/formats/design-tokens/plan/styles.js.map +1 -1
  416. package/dist/io/formats/design-tokens/styles.d.ts +9 -1
  417. package/dist/io/formats/design-tokens/styles.d.ts.map +1 -1
  418. package/dist/io/formats/design-tokens/styles.js +41 -4
  419. package/dist/io/formats/design-tokens/styles.js.map +1 -1
  420. package/dist/io/formats/design-tokens/types.d.ts +5 -0
  421. package/dist/io/formats/design-tokens/types.d.ts.map +1 -1
  422. package/dist/io/formats/design-tokens/types.js +1 -0
  423. package/dist/io/formats/design-tokens/types.js.map +1 -1
  424. package/dist/io/formats/fig/export/setup.d.ts.map +1 -1
  425. package/dist/io/formats/fig/export/setup.js +8 -4
  426. package/dist/io/formats/fig/export/setup.js.map +1 -1
  427. package/dist/io/formats/fig/export/variables.d.ts.map +1 -1
  428. package/dist/io/formats/fig/export/variables.js +2 -2
  429. package/dist/io/formats/fig/export/variables.js.map +1 -1
  430. package/dist/io/formats/fig/index.d.ts +2 -2
  431. package/dist/io/formats/fig/index.js +2 -2
  432. package/dist/io/formats/fig/read.d.ts +9 -2
  433. package/dist/io/formats/fig/read.d.ts.map +1 -1
  434. package/dist/io/formats/fig/read.js +44 -20
  435. package/dist/io/formats/fig/read.js.map +1 -1
  436. package/dist/io/formats/html/index.d.ts.map +1 -1
  437. package/dist/io/formats/html/index.js +2 -6
  438. package/dist/io/formats/html/index.js.map +1 -1
  439. package/dist/io/formats/pdf/dom.d.ts.map +1 -1
  440. package/dist/io/formats/pdf/dom.js +65 -1
  441. package/dist/io/formats/pdf/dom.js.map +1 -1
  442. package/dist/io/formats/pdf/prepare.js +1 -1
  443. package/dist/io/formats/pen/fonts.d.ts +14 -0
  444. package/dist/io/formats/pen/fonts.d.ts.map +1 -0
  445. package/dist/io/formats/pen/fonts.js +39 -0
  446. package/dist/io/formats/pen/fonts.js.map +1 -0
  447. package/dist/io/formats/pen/index.d.ts.map +1 -1
  448. package/dist/io/formats/pen/index.js +25 -6
  449. package/dist/io/formats/pen/index.js.map +1 -1
  450. package/dist/io/formats/raster/headless.d.ts +2 -2
  451. package/dist/io/formats/raster/headless.d.ts.map +1 -1
  452. package/dist/io/formats/raster/headless.js +24 -13
  453. package/dist/io/formats/raster/headless.js.map +1 -1
  454. package/dist/io/formats/raster/index.d.ts +2 -2
  455. package/dist/io/formats/raster/index.js +2 -2
  456. package/dist/io/formats/raster/render.d.ts +7 -1
  457. package/dist/io/formats/raster/render.d.ts.map +1 -1
  458. package/dist/io/formats/raster/render.js +40 -6
  459. package/dist/io/formats/raster/render.js.map +1 -1
  460. package/dist/io/formats/svg/export.d.ts.map +1 -1
  461. package/dist/io/formats/svg/export.js +28 -24
  462. package/dist/io/formats/svg/export.js.map +1 -1
  463. package/dist/io/formats/svg/paths.d.ts +8 -2
  464. package/dist/io/formats/svg/paths.d.ts.map +1 -1
  465. package/dist/io/formats/svg/paths.js +11 -3
  466. package/dist/io/formats/svg/paths.js.map +1 -1
  467. package/dist/io/formats/svg/strokes.d.ts.map +1 -1
  468. package/dist/io/formats/svg/strokes.js +2 -5
  469. package/dist/io/formats/svg/strokes.js.map +1 -1
  470. package/dist/io/formats/svg/text/export.d.ts.map +1 -1
  471. package/dist/io/formats/svg/text/export.js +19 -1
  472. package/dist/io/formats/svg/text/export.js.map +1 -1
  473. package/dist/io/formats/svg/text/import.d.ts.map +1 -1
  474. package/dist/io/formats/svg/text/import.js +2 -1
  475. package/dist/io/formats/svg/text/import.js.map +1 -1
  476. package/dist/io/subgraph.d.ts.map +1 -1
  477. package/dist/io/subgraph.js +5 -2
  478. package/dist/io/subgraph.js.map +1 -1
  479. package/dist/kiwi/fig/population/client.d.ts.map +1 -1
  480. package/dist/kiwi/fig/population/client.js +63 -45
  481. package/dist/kiwi/fig/population/client.js.map +1 -1
  482. package/dist/kiwi/fig/population/delta.d.ts +34 -3
  483. package/dist/kiwi/fig/population/delta.d.ts.map +1 -1
  484. package/dist/kiwi/fig/population/delta.js +99 -16
  485. package/dist/kiwi/fig/population/delta.js.map +1 -1
  486. package/dist/kiwi/fig/population/edits.d.ts +51 -0
  487. package/dist/kiwi/fig/population/edits.d.ts.map +1 -0
  488. package/dist/kiwi/fig/population/edits.js +169 -0
  489. package/dist/kiwi/fig/population/edits.js.map +1 -0
  490. package/dist/kiwi/fig/session/archive/access.d.ts +3 -0
  491. package/dist/kiwi/fig/session/archive/access.d.ts.map +1 -1
  492. package/dist/kiwi/fig/session/archive/access.js +8 -1
  493. package/dist/kiwi/fig/session/archive/access.js.map +1 -1
  494. package/dist/kiwi/fig/session/archive/changes.d.ts +2 -1
  495. package/dist/kiwi/fig/session/archive/changes.d.ts.map +1 -1
  496. package/dist/kiwi/fig/session/archive/changes.js +12 -5
  497. package/dist/kiwi/fig/session/archive/changes.js.map +1 -1
  498. package/dist/kiwi/fig/session/document-state.d.ts +7 -1
  499. package/dist/kiwi/fig/session/document-state.d.ts.map +1 -1
  500. package/dist/kiwi/fig/session/document-state.js +16 -2
  501. package/dist/kiwi/fig/session/document-state.js.map +1 -1
  502. package/dist/kiwi/fig/session/protocol.d.ts +31 -3
  503. package/dist/kiwi/fig/session/protocol.d.ts.map +1 -1
  504. package/dist/kiwi/fig/session/worker.js +33 -8
  505. package/dist/kiwi/fig/session/worker.js.map +1 -1
  506. package/dist/layout/apply.d.ts +6 -1
  507. package/dist/layout/apply.d.ts.map +1 -1
  508. package/dist/layout/apply.js +39 -14
  509. package/dist/layout/apply.js.map +1 -1
  510. package/dist/layout/arrange/boxes.d.ts.map +1 -1
  511. package/dist/layout/arrange/boxes.js +31 -0
  512. package/dist/layout/arrange/boxes.js.map +1 -1
  513. package/dist/layout/flow-edges.d.ts +26 -0
  514. package/dist/layout/flow-edges.d.ts.map +1 -0
  515. package/dist/layout/flow-edges.js +105 -0
  516. package/dist/layout/flow-edges.js.map +1 -0
  517. package/dist/layout/grid.d.ts.map +1 -1
  518. package/dist/layout/grid.js +9 -5
  519. package/dist/layout/grid.js.map +1 -1
  520. package/dist/layout/text-auto-resize.d.ts.map +1 -1
  521. package/dist/layout/text-auto-resize.js +9 -4
  522. package/dist/layout/text-auto-resize.js.map +1 -1
  523. package/dist/layout/text-measurement.d.ts +15 -1
  524. package/dist/layout/text-measurement.d.ts.map +1 -1
  525. package/dist/layout/text-measurement.js +40 -4
  526. package/dist/layout/text-measurement.js.map +1 -1
  527. package/dist/layout/variables.d.ts +1 -1
  528. package/dist/layout.d.ts.map +1 -1
  529. package/dist/layout.js +35 -35
  530. package/dist/layout.js.map +1 -1
  531. package/dist/library/asset-keys.d.ts +3 -2
  532. package/dist/library/asset-keys.d.ts.map +1 -1
  533. package/dist/library/asset-keys.js +4 -3
  534. package/dist/library/asset-keys.js.map +1 -1
  535. package/dist/library/copied-references.d.ts +8 -3
  536. package/dist/library/copied-references.d.ts.map +1 -1
  537. package/dist/library/copied-references.js +15 -5
  538. package/dist/library/copied-references.js.map +1 -1
  539. package/dist/library/materialize.js +1 -1
  540. package/dist/library/materialize.js.map +1 -1
  541. package/dist/library/schema.js.map +1 -1
  542. package/dist/library/snapshot.d.ts.map +1 -1
  543. package/dist/library/snapshot.js +10 -2
  544. package/dist/library/snapshot.js.map +1 -1
  545. package/dist/pairdraw-api/variables.d.ts.map +1 -1
  546. package/dist/pairdraw-api/variables.js +0 -2
  547. package/dist/pairdraw-api/variables.js.map +1 -1
  548. package/dist/profiler/hud-controller.d.ts +4 -3
  549. package/dist/profiler/hud-controller.d.ts.map +1 -1
  550. package/dist/profiler/hud-controller.js +7 -5
  551. package/dist/profiler/hud-controller.js.map +1 -1
  552. package/dist/profiler/hud-renderer.d.ts +5 -2
  553. package/dist/profiler/hud-renderer.d.ts.map +1 -1
  554. package/dist/profiler/hud-renderer.js +8 -5
  555. package/dist/profiler/hud-renderer.js.map +1 -1
  556. package/dist/profiler/render-profiler.d.ts +3 -2
  557. package/dist/profiler/render-profiler.d.ts.map +1 -1
  558. package/dist/profiler/render-profiler.js +3 -2
  559. package/dist/profiler/render-profiler.js.map +1 -1
  560. package/dist/text/character-style.d.ts +11 -1
  561. package/dist/text/character-style.d.ts.map +1 -1
  562. package/dist/text/character-style.js +27 -5
  563. package/dist/text/character-style.js.map +1 -1
  564. package/dist/text/coverage.d.ts.map +1 -1
  565. package/dist/text/coverage.js +15 -16
  566. package/dist/text/coverage.js.map +1 -1
  567. package/dist/text/editor.d.ts.map +1 -1
  568. package/dist/text/editor.js +3 -8
  569. package/dist/text/editor.js.map +1 -1
  570. package/dist/text/fallbacks.d.ts +19 -2
  571. package/dist/text/fallbacks.d.ts.map +1 -1
  572. package/dist/text/fallbacks.js +63 -12
  573. package/dist/text/fallbacks.js.map +1 -1
  574. package/dist/text/font/catalog.d.ts +4 -0
  575. package/dist/text/font/catalog.d.ts.map +1 -1
  576. package/dist/text/font/catalog.js +8 -0
  577. package/dist/text/font/catalog.js.map +1 -1
  578. package/dist/text/font/collection.d.ts +13 -0
  579. package/dist/text/font/collection.d.ts.map +1 -0
  580. package/dist/text/font/collection.js +51 -0
  581. package/dist/text/font/collection.js.map +1 -0
  582. package/dist/text/font/faces.d.ts +2 -1
  583. package/dist/text/font/faces.d.ts.map +1 -1
  584. package/dist/text/font/faces.js +9 -5
  585. package/dist/text/font/faces.js.map +1 -1
  586. package/dist/text/font/glyphs.d.ts +14 -3
  587. package/dist/text/font/glyphs.d.ts.map +1 -1
  588. package/dist/text/font/glyphs.js +22 -5
  589. package/dist/text/font/glyphs.js.map +1 -1
  590. package/dist/text/font/local.js +2 -2
  591. package/dist/text/font/local.js.map +1 -1
  592. package/dist/text/font/manager.d.ts +36 -0
  593. package/dist/text/font/manager.d.ts.map +1 -1
  594. package/dist/text/font/manager.js +139 -19
  595. package/dist/text/font/manager.js.map +1 -1
  596. package/dist/text/font/style.d.ts +7 -2
  597. package/dist/text/font/style.d.ts.map +1 -1
  598. package/dist/text/font/style.js +31 -3
  599. package/dist/text/font/style.js.map +1 -1
  600. package/dist/text/index.d.ts +5 -4
  601. package/dist/text/index.js +5 -4
  602. package/dist/text/outlines.d.ts.map +1 -1
  603. package/dist/text/outlines.js +70 -70
  604. package/dist/text/outlines.js.map +1 -1
  605. package/dist/text/prepare.d.ts.map +1 -1
  606. package/dist/text/prepare.js +7 -1
  607. package/dist/text/prepare.js.map +1 -1
  608. package/dist/text/style-runs.d.ts +14 -2
  609. package/dist/text/style-runs.d.ts.map +1 -1
  610. package/dist/text/style-runs.js +22 -14
  611. package/dist/text/style-runs.js.map +1 -1
  612. package/dist/tools/analyze/overlaps/helpers.d.ts.map +1 -1
  613. package/dist/tools/analyze/overlaps/helpers.js +9 -1
  614. package/dist/tools/analyze/overlaps/helpers.js.map +1 -1
  615. package/dist/tools/analyze/overlaps/index.d.ts.map +1 -1
  616. package/dist/tools/analyze/overlaps/index.js +27 -5
  617. package/dist/tools/analyze/overlaps/index.js.map +1 -1
  618. package/dist/tools/codegen/component-map.js +3 -3
  619. package/dist/tools/codegen/component-map.js.map +1 -1
  620. package/dist/tools/create/basic.d.ts.map +1 -1
  621. package/dist/tools/create/basic.js +5 -4
  622. package/dist/tools/create/basic.js.map +1 -1
  623. package/dist/tools/create/html.d.ts.map +1 -1
  624. package/dist/tools/create/html.js +4 -2
  625. package/dist/tools/create/html.js.map +1 -1
  626. package/dist/tools/create/icons.d.ts.map +1 -1
  627. package/dist/tools/create/icons.js +3 -1
  628. package/dist/tools/create/icons.js.map +1 -1
  629. package/dist/tools/create/mermaid.d.ts.map +1 -1
  630. package/dist/tools/create/mermaid.js +2 -0
  631. package/dist/tools/create/mermaid.js.map +1 -1
  632. package/dist/tools/create/render.d.ts.map +1 -1
  633. package/dist/tools/create/render.js +2 -0
  634. package/dist/tools/create/render.js.map +1 -1
  635. package/dist/tools/create/script.js +3 -1
  636. package/dist/tools/create/script.js.map +1 -1
  637. package/dist/tools/create/svg.d.ts.map +1 -1
  638. package/dist/tools/create/svg.js +4 -1
  639. package/dist/tools/create/svg.js.map +1 -1
  640. package/dist/tools/create/vector.d.ts.map +1 -1
  641. package/dist/tools/create/vector.js +4 -4
  642. package/dist/tools/create/vector.js.map +1 -1
  643. package/dist/tools/image-ai/apply.js +1 -1
  644. package/dist/tools/image-ai/generate.d.ts.map +1 -1
  645. package/dist/tools/image-ai/generate.js +3 -0
  646. package/dist/tools/image-ai/generate.js.map +1 -1
  647. package/dist/tools/modify/matching.js +1 -1
  648. package/dist/tools/modify/reactions.d.ts +6 -0
  649. package/dist/tools/modify/reactions.d.ts.map +1 -0
  650. package/dist/tools/modify/reactions.js +35 -0
  651. package/dist/tools/modify/reactions.js.map +1 -0
  652. package/dist/tools/modify.d.ts +2 -1
  653. package/dist/tools/modify.js +2 -1
  654. package/dist/tools/read/components.js +20 -22
  655. package/dist/tools/read/components.js.map +1 -1
  656. package/dist/tools/read/fonts.js +1 -1
  657. package/dist/tools/read/fonts.js.map +1 -1
  658. package/dist/tools/read/libraries.d.ts.map +1 -1
  659. package/dist/tools/read/libraries.js +2 -0
  660. package/dist/tools/read/libraries.js.map +1 -1
  661. package/dist/tools/read/nodes.d.ts.map +1 -1
  662. package/dist/tools/read/nodes.js +38 -16
  663. package/dist/tools/read/nodes.js.map +1 -1
  664. package/dist/tools/read/pages.d.ts.map +1 -1
  665. package/dist/tools/read/pages.js +4 -3
  666. package/dist/tools/read/pages.js.map +1 -1
  667. package/dist/tools/read/query.js +1 -0
  668. package/dist/tools/read/query.js.map +1 -1
  669. package/dist/tools/read/reactions.d.ts +6 -0
  670. package/dist/tools/read/reactions.d.ts.map +1 -0
  671. package/dist/tools/read/reactions.js +24 -0
  672. package/dist/tools/read/reactions.js.map +1 -0
  673. package/dist/tools/read/space.js +1 -1
  674. package/dist/tools/read.d.ts +2 -1
  675. package/dist/tools/read.js +2 -1
  676. package/dist/tools/registry/extended.d.ts.map +1 -1
  677. package/dist/tools/registry/extended.js +4 -0
  678. package/dist/tools/registry/extended.js.map +1 -1
  679. package/dist/tools/schema.d.ts +6 -0
  680. package/dist/tools/schema.d.ts.map +1 -1
  681. package/dist/tools/schema.js +53 -9
  682. package/dist/tools/schema.js.map +1 -1
  683. package/dist/tools/stock-photo/apply.js +8 -9
  684. package/dist/tools/stock-photo/apply.js.map +1 -1
  685. package/dist/tools/structure/batch.d.ts.map +1 -1
  686. package/dist/tools/structure/batch.js +85 -90
  687. package/dist/tools/structure/batch.js.map +1 -1
  688. package/dist/vector/fill-geometry.d.ts +4 -1
  689. package/dist/vector/fill-geometry.d.ts.map +1 -1
  690. package/dist/vector/fill-geometry.js +8 -5
  691. package/dist/vector/fill-geometry.js.map +1 -1
  692. package/dist/vector/index.js +1 -1
  693. package/dist/vector/index.js.map +1 -1
  694. package/dist/vector/path-helpers.d.ts +1 -1
  695. package/dist/vector/path-helpers.d.ts.map +1 -1
  696. package/dist/vector/path-helpers.js +24 -7
  697. package/dist/vector/path-helpers.js.map +1 -1
  698. package/dist/vector/placement.js +1 -1
  699. package/dist/vector/placement.js.map +1 -1
  700. package/dist/vector/vectorize/preprocess.js +1 -1
  701. package/dist/vector/vectorize/preprocess.js.map +1 -1
  702. package/package.json +10 -10
  703. package/src/canvas/effects.ts +29 -33
  704. package/src/canvas/labels/hit-test.ts +6 -2
  705. package/src/canvas/labels/paragraph-cache.ts +2 -1
  706. package/src/canvas/labels/selection.ts +3 -3
  707. package/src/canvas/node-edit-overlay.ts +3 -2
  708. package/src/canvas/overlays/index.ts +0 -1
  709. package/src/canvas/overlays/selection.ts +4 -52
  710. package/src/canvas/region-hatch.ts +7 -2
  711. package/src/canvas/renderer/colors.ts +41 -26
  712. package/src/canvas/renderer/font-waiters.ts +25 -0
  713. package/src/canvas/renderer/fonts.ts +40 -17
  714. package/src/canvas/renderer/lifecycle.ts +8 -10
  715. package/src/canvas/renderer/methods.ts +9 -13
  716. package/src/canvas/renderer/paints.ts +0 -10
  717. package/src/canvas/renderer/pipeline.ts +29 -3
  718. package/src/canvas/renderer/retained-backing.ts +4 -4
  719. package/src/canvas/renderer/state.ts +1 -1
  720. package/src/canvas/renderer/tiles/controller.ts +8 -0
  721. package/src/canvas/renderer/tiles/surface-pool.ts +1 -1
  722. package/src/canvas/renderer/visual-bounds.ts +7 -6
  723. package/src/canvas/renderer.ts +39 -11
  724. package/src/canvas/rulers.ts +55 -26
  725. package/src/canvas/scene.ts +37 -16
  726. package/src/canvas/shadows/shape.ts +1 -1
  727. package/src/canvas/shadows/silhouette.ts +4 -2
  728. package/src/canvas/shadows.ts +4 -2
  729. package/src/canvas/text/derived.ts +0 -9
  730. package/src/canvas/text/emoji/raster.ts +14 -10
  731. package/src/canvas/text/font-families.ts +6 -0
  732. package/src/canvas/text/index.ts +0 -8
  733. package/src/canvas/text/layout/build.ts +35 -18
  734. package/src/canvas/text/layout/index.ts +15 -6
  735. package/src/canvas/text/layout/lines.ts +10 -4
  736. package/src/canvas/text/paragraph/index.ts +17 -8
  737. package/src/canvas/text/paragraph/inputs.ts +4 -2
  738. package/src/canvas/text/shape.ts +20 -31
  739. package/src/constants.ts +6 -1
  740. package/src/editor/bridges/clipboard.ts +1 -0
  741. package/src/editor/bridges/components.ts +2 -0
  742. package/src/editor/bridges/frames.ts +6 -4
  743. package/src/editor/bridges/structure.ts +1 -0
  744. package/src/editor/clipboard/detach.ts +3 -3
  745. package/src/editor/clipboard/paste/target.ts +2 -2
  746. package/src/editor/clipboard/snapshot.ts +7 -0
  747. package/src/editor/clipboard/variables.ts +20 -0
  748. package/src/editor/clipboard.ts +133 -14
  749. package/src/editor/component-sync.ts +28 -7
  750. package/src/editor/components/authoring/text-edit.ts +15 -2
  751. package/src/editor/components/authoring/visibility-edit.ts +11 -3
  752. package/src/editor/components/instances.ts +61 -11
  753. package/src/editor/components/properties.ts +10 -0
  754. package/src/editor/components/slots/authoring.ts +4 -1
  755. package/src/editor/create.ts +58 -8
  756. package/src/editor/guides.ts +27 -12
  757. package/src/editor/history/document-change.ts +115 -7
  758. package/src/editor/history/edit.ts +62 -14
  759. package/src/editor/history/position.ts +1 -4
  760. package/src/editor/history/sources.ts +25 -0
  761. package/src/editor/index.ts +3 -1
  762. package/src/editor/layout-mode.ts +20 -1
  763. package/src/editor/node-preview.ts +44 -8
  764. package/src/editor/nodes.ts +52 -12
  765. package/src/editor/nudge.ts +16 -2
  766. package/src/editor/pages.ts +100 -17
  767. package/src/editor/play/states.ts +0 -7
  768. package/src/editor/read-only/actions.ts +4 -0
  769. package/src/editor/selection/hit-test.ts +37 -4
  770. package/src/editor/shapes/pen.ts +6 -3
  771. package/src/editor/shapes.ts +2 -1
  772. package/src/editor/structure/auto-layout-wrap.ts +26 -0
  773. package/src/editor/structure/group/bounds.ts +22 -4
  774. package/src/editor/structure/rename.ts +2 -6
  775. package/src/editor/structure/reorder.ts +26 -8
  776. package/src/editor/structure.ts +88 -24
  777. package/src/editor/text/hyperlink.ts +2 -1
  778. package/src/editor/text/name.ts +51 -15
  779. package/src/editor/text/pending-layout.ts +42 -4
  780. package/src/editor/text/selection-style.ts +17 -3
  781. package/src/editor/text.ts +86 -4
  782. package/src/editor/types.ts +19 -0
  783. package/src/editor/undo.ts +21 -2
  784. package/src/editor/variable-bindings.ts +22 -2
  785. package/src/editor/variables.ts +10 -6
  786. package/src/editor/viewport.ts +55 -21
  787. package/src/editor/views/actions.ts +17 -7
  788. package/src/editor/views/present.ts +20 -11
  789. package/src/editor/views/types.ts +11 -5
  790. package/src/figma-api/accessor-utils.ts +4 -1
  791. package/src/figma-api/accessors/basic.ts +54 -18
  792. package/src/figma-api/accessors/layout.ts +46 -7
  793. package/src/figma-api/accessors/reactions.ts +29 -0
  794. package/src/figma-api/accessors/strokes.ts +28 -8
  795. package/src/figma-api/accessors/text/index.ts +4 -0
  796. package/src/figma-api/accessors/vector.ts +3 -1
  797. package/src/figma-api/accessors/visual.ts +25 -28
  798. package/src/figma-api/components.ts +9 -7
  799. package/src/figma-api/finite.ts +102 -0
  800. package/src/figma-api/fonts/list.ts +24 -0
  801. package/src/figma-api/index.ts +82 -12
  802. package/src/figma-api/overrides.ts +1 -1
  803. package/src/figma-api/pending-layout.ts +50 -1
  804. package/src/figma-api/pending-sync.ts +61 -0
  805. package/src/figma-api/proxy.ts +35 -2
  806. package/src/figma-api/reactions.ts +212 -0
  807. package/src/figma-api/render-bounds.ts +13 -4
  808. package/src/figma-api/serialization.ts +2 -2
  809. package/src/figma-api/slots.ts +12 -3
  810. package/src/figma-api/strokes.ts +16 -12
  811. package/src/figma-api/text/index.ts +9 -15
  812. package/src/figma-api/variables/variable.ts +3 -2
  813. package/src/geometry/figma.ts +9 -0
  814. package/src/geometry/index.ts +1 -0
  815. package/src/global.d.ts +6 -0
  816. package/src/icons/api.ts +27 -16
  817. package/src/icons/provider.ts +9 -20
  818. package/src/icons/schema.ts +31 -0
  819. package/src/icons/svg/presentation.ts +27 -3
  820. package/src/icons/svg/text.ts +1 -1
  821. package/src/icons/svg.ts +21 -19
  822. package/src/icons/types.ts +0 -14
  823. package/src/io/formats/design-tokens/plan/index.ts +7 -1
  824. package/src/io/formats/design-tokens/plan/styles.ts +40 -4
  825. package/src/io/formats/design-tokens/styles.ts +60 -3
  826. package/src/io/formats/design-tokens/types.ts +3 -0
  827. package/src/io/formats/fig/export/setup.ts +16 -14
  828. package/src/io/formats/fig/export/variables.ts +7 -8
  829. package/src/io/formats/fig/index.ts +1 -0
  830. package/src/io/formats/fig/read.ts +66 -23
  831. package/src/io/formats/html/index.ts +2 -6
  832. package/src/io/formats/pdf/dom.ts +96 -3
  833. package/src/io/formats/pen/fonts.ts +45 -0
  834. package/src/io/formats/pen/index.ts +30 -6
  835. package/src/io/formats/raster/headless.ts +31 -12
  836. package/src/io/formats/raster/index.ts +3 -0
  837. package/src/io/formats/raster/render.ts +62 -6
  838. package/src/io/formats/svg/export.ts +24 -25
  839. package/src/io/formats/svg/paths.ts +11 -2
  840. package/src/io/formats/svg/strokes.ts +8 -2
  841. package/src/io/formats/svg/text/export.ts +23 -0
  842. package/src/io/formats/svg/text/import.ts +2 -1
  843. package/src/io/subgraph.ts +3 -1
  844. package/src/kiwi/fig/population/client.ts +77 -43
  845. package/src/kiwi/fig/population/delta.ts +141 -18
  846. package/src/kiwi/fig/population/edits.ts +235 -0
  847. package/src/kiwi/fig/session/archive/access.ts +15 -0
  848. package/src/kiwi/fig/session/archive/changes.ts +27 -6
  849. package/src/kiwi/fig/session/document-state.ts +23 -1
  850. package/src/kiwi/fig/session/protocol.ts +26 -1
  851. package/src/kiwi/fig/session/worker.ts +38 -11
  852. package/src/layout/apply.ts +52 -10
  853. package/src/layout/arrange/boxes.ts +36 -0
  854. package/src/layout/flow-edges.ts +139 -0
  855. package/src/layout/grid.ts +14 -4
  856. package/src/layout/text-auto-resize.ts +13 -4
  857. package/src/layout/text-measurement.ts +46 -3
  858. package/src/layout.ts +60 -66
  859. package/src/library/asset-keys.ts +4 -3
  860. package/src/library/copied-references.ts +29 -5
  861. package/src/library/materialize.ts +1 -1
  862. package/src/library/schema.ts +1 -1
  863. package/src/library/snapshot.ts +11 -2
  864. package/src/pairdraw-api/variables.ts +1 -3
  865. package/src/profiler/hud-controller.ts +8 -6
  866. package/src/profiler/hud-renderer.ts +9 -6
  867. package/src/profiler/render-profiler.ts +4 -3
  868. package/src/text/character-style.ts +29 -9
  869. package/src/text/coverage.ts +17 -18
  870. package/src/text/editor.ts +3 -8
  871. package/src/text/fallbacks.ts +82 -15
  872. package/src/text/font/catalog.ts +10 -0
  873. package/src/text/font/collection.ts +60 -0
  874. package/src/text/font/faces.ts +9 -5
  875. package/src/text/font/glyphs.ts +29 -4
  876. package/src/text/font/local.ts +2 -2
  877. package/src/text/font/manager.ts +170 -32
  878. package/src/text/font/style.ts +52 -3
  879. package/src/text/index.ts +1 -0
  880. package/src/text/outlines.ts +105 -89
  881. package/src/text/prepare.ts +17 -0
  882. package/src/text/style-runs.ts +43 -16
  883. package/src/tools/analyze/overlaps/helpers.ts +18 -1
  884. package/src/tools/analyze/overlaps/index.ts +37 -6
  885. package/src/tools/codegen/component-map.ts +3 -3
  886. package/src/tools/create/basic.ts +6 -4
  887. package/src/tools/create/html.ts +3 -1
  888. package/src/tools/create/icons.ts +3 -1
  889. package/src/tools/create/mermaid.ts +2 -0
  890. package/src/tools/create/render.ts +2 -0
  891. package/src/tools/create/script.ts +5 -1
  892. package/src/tools/create/svg.ts +4 -1
  893. package/src/tools/create/vector.ts +4 -4
  894. package/src/tools/image-ai/generate.ts +3 -0
  895. package/src/tools/modify/reactions.ts +40 -0
  896. package/src/tools/modify.ts +1 -0
  897. package/src/tools/read/components.ts +28 -25
  898. package/src/tools/read/fonts.ts +1 -1
  899. package/src/tools/read/libraries.ts +3 -0
  900. package/src/tools/read/nodes.ts +47 -17
  901. package/src/tools/read/pages.ts +7 -4
  902. package/src/tools/read/query.ts +2 -0
  903. package/src/tools/read/reactions.ts +21 -0
  904. package/src/tools/read.ts +1 -0
  905. package/src/tools/registry/extended.ts +4 -0
  906. package/src/tools/schema.ts +68 -12
  907. package/src/tools/stock-photo/apply.ts +17 -5
  908. package/src/tools/structure/batch.ts +82 -101
  909. package/src/vector/fill-geometry.ts +11 -5
  910. package/src/vector/index.ts +1 -1
  911. package/src/vector/path-helpers.ts +34 -8
  912. package/src/vector/placement.ts +1 -1
  913. package/src/vector/vectorize/preprocess.ts +1 -1
@@ -2,10 +2,11 @@ import "../../../constants.js";
2
2
  import { shownText } from "../../../text/case.js";
3
3
  import { textFontFace } from "../../../text/requirements/collect.js";
4
4
  import { glyphAdvanceSync } from "../../../text/font/glyphs.js";
5
+ import { autoWidthWrapWidth } from "../../../layout/text-measurement.js";
5
6
  import { buildSkParagraph, buildTruncateOpts, resolveParagraphLayoutWidth } from "../paragraph/index.js";
6
7
  import { utf8Length } from "../utf8.js";
7
8
  import { TextLayout } from "./index.js";
8
- import { hasParagraphSpacing, hasTextList, lineHeightPixels, paragraphSpacingAt, paragraphStyleAt, textListItems, textParagraphRanges, topLevelNumberDigits } from "@pairdraw/scene-graph/text";
9
+ import { hasParagraphSpacing, hasTextList, lineHeightPixels, lineStepPixels, paragraphSpacingAt, paragraphStyleAt, textListItems, textParagraphRanges, topLevelNumberDigits } from "@pairdraw/scene-graph/text";
9
10
  import { rangeFontStyle } from "@pairdraw/scene-graph/shared-styles";
10
11
  import { resolveNodeTextDirection } from "@pairdraw/scene-graph/text/direction";
11
12
  //#region src/canvas/text/layout/build.ts
@@ -39,7 +40,8 @@ function sliceStyleRuns(runs, start, end) {
39
40
  }
40
41
  /** Line heights by paragraph index, `lead` places before the text: each run's, the text's elsewhere. */
41
42
  function lineHeightRuns(node, lead) {
42
- const own = (fontSize = node.fontSize) => lineHeightPixels(node.lineHeight, fontSize) || null;
43
+ const step = (lineHeight, fontSize) => lineHeightPixels(lineHeight, fontSize) ? lineStepPixels(lineHeight, fontSize) : null;
44
+ const own = (fontSize = node.fontSize) => step(node.lineHeight, fontSize);
43
45
  const runs = [];
44
46
  const add = (start, end, lineHeight) => {
45
47
  const last = runs.at(-1);
@@ -54,7 +56,7 @@ function lineHeightRuns(node, lead) {
54
56
  for (const run of node.styleRuns) {
55
57
  if (position < run.start) add(position + lead, run.start + lead, own());
56
58
  const runSize = run.style.fontSize ?? node.fontSize;
57
- const lineHeight = run.style.lineHeight !== void 0 ? lineHeightPixels(run.style.lineHeight, runSize) || null : own(runSize);
59
+ const lineHeight = run.style.lineHeight !== void 0 ? step(run.style.lineHeight, runSize) : own(runSize);
58
60
  add(run.start + lead, run.start + run.length + lead, lineHeight);
59
61
  position = run.start + run.length;
60
62
  }
@@ -100,10 +102,22 @@ function needsParagraphLayout(node) {
100
102
  return hasTextList(node) || node.paragraphSpacing !== 0 || node.paragraphIndent !== 0 || node.textParagraphs.some(hasParagraphSpacing);
101
103
  }
102
104
  function layoutForNode(layout, node) {
103
- if (node.textAutoResize === "WIDTH_AND_HEIGHT") {
104
- layout.layout(1e6);
105
- layout.layout(Math.max(node.width || 1, Math.ceil(layout.getLongestLine())));
106
- } else layout.layout(resolveParagraphLayoutWidth(node));
105
+ if (node.textAutoResize !== "WIDTH_AND_HEIGHT") {
106
+ layout.layout(resolveParagraphLayoutWidth(node));
107
+ return;
108
+ }
109
+ const wrapWidth = resolveParagraphLayoutWidth(node);
110
+ if (truncatesAtMaxWidth(node)) {
111
+ layout.layout(Math.min(node.width || wrapWidth, wrapWidth));
112
+ return;
113
+ }
114
+ layout.layout(wrapWidth);
115
+ const widestLine = Math.ceil(layout.getLongestLine());
116
+ const width = Math.min(wrapWidth, Math.max(node.width || 1, widestLine));
117
+ if (width !== wrapWidth) layout.layout(width);
118
+ }
119
+ function truncatesAtMaxWidth(node) {
120
+ return node.textTruncation === "ENDING" && autoWidthWrapWidth(node) !== void 0;
107
121
  }
108
122
  function listStyle(node, firstCharacter) {
109
123
  const override = styleAt(node.styleRuns, firstCharacter);
@@ -266,7 +280,9 @@ function buildMarker(r, node, item, list, color, options) {
266
280
  };
267
281
  }
268
282
  function createTextLayout(r, node, color, options) {
269
- return needsParagraphLayout(node) ? buildBlocks(r, node, color, options) : TextLayout.ofParagraph(r.ck, buildSkParagraph(r, node, color, options), shownText(node).length, paragraphLines(r, node, color, options));
283
+ if (needsParagraphLayout(node)) return buildBlocks(r, node, color, options);
284
+ const truncation = buildTruncateOpts(node);
285
+ return TextLayout.ofParagraph(r.ck, buildSkParagraph(r, node, color, options, truncation.ellipsis ? { truncation } : void 0), shownText(node).length, paragraphLines(r, node, color, options));
270
286
  }
271
287
  /** How many laid-out line boxes fit the fixed height, preserving the first line. */
272
288
  function linesWithinHeight(layout, height) {
@@ -277,7 +293,7 @@ function linesWithinHeight(layout, height) {
277
293
  /** Lay a text node out as the renderer draws it, at its own width. */
278
294
  function buildParagraph(r, node, color, options = {}) {
279
295
  const layout = createTextLayout(r, node, color, options);
280
- const heightTruncation = node.textTruncation === "ENDING" && node.height > 0 && (node.maxLines == null || node.maxLines <= 0);
296
+ const heightTruncation = (node.textTruncation === "ENDING" || node.textAutoResize === "TRUNCATE") && node.height > 0 && (node.maxLines == null || node.maxLines <= 0);
281
297
  let fittingLines;
282
298
  try {
283
299
  layoutForNode(layout, node);
@@ -1 +1 @@
1
- {"version":3,"file":"build.js","names":[],"sources":["../../../../src/canvas/text/layout/build.ts"],"sourcesContent":["import type { Paragraph } from 'canvaskit-wasm'\n\nimport type { CharacterStyleOverride, StyleRun } from '@pairdraw/scene-graph'\nimport { rangeFontStyle } from '@pairdraw/scene-graph/shared-styles'\nimport {\n hasParagraphSpacing,\n hasTextList,\n paragraphSpacingAt,\n paragraphStyleAt,\n textListItems,\n textParagraphRanges,\n lineHeightPixels,\n topLevelNumberDigits,\n type TextListItem,\n type TextParagraphRange\n} from '@pairdraw/scene-graph/text'\nimport { resolveNodeTextDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport { TextLayout, type TextLayoutBlock, type TextLayoutMarker } from '#core/canvas/text/layout'\nimport type { LineHeightRun, TextLayoutBlockLines } from '#core/canvas/text/layout/lines'\nimport type { ParagraphBuildOptions } from '#core/canvas/text/paint'\nimport {\n buildSkParagraph,\n buildTruncateOpts,\n resolveParagraphLayoutWidth,\n type ParagraphBlockOptions\n} from '#core/canvas/text/paragraph'\nimport type { ParagraphNode } from '#core/canvas/text/paragraph/inputs'\nimport type { TextRenderer } from '#core/canvas/text/renderer'\nimport { utf8Length } from '#core/canvas/text/utf8'\nimport { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from '#core/constants'\nimport { shownText } from '#core/text/case'\nimport { glyphAdvanceSync } from '#core/text/font/glyphs'\nimport { textFontFace } from '#core/text/requirements/collect'\n\n/** A list item's indent per level, in ems of the list's first character. */\nconst LIST_INDENT_EMS = 1.5\n/**\n * Figma widens ordered lists by the advance of glyph 48 per extra digit: the character code of\n * \"0\" read as a glyph ID. Measured in live Figma for Inter, Roboto, DM Sans, and others.\n */\nconst LIST_DIGIT_GLYPH_ID = 48\n/** A digit's width, in ems, for a font whose glyphs cannot be read. */\nconst FALLBACK_DIGIT_EMS = 0.6\n/** The placeholder a first-line indent puts before the text takes one UTF-16 unit, three bytes. */\nconst PLACEHOLDER_UTF8_LENGTH = 3\n\nfunction styleAt(runs: readonly StyleRun[], index: number): CharacterStyleOverride | undefined {\n return runs.find((run) => index >= run.start && index < run.start + run.length)?.style\n}\n\n/** Style runs of `text[start, end)` in the slice's own indices. */\nfunction sliceStyleRuns(runs: readonly StyleRun[], start: number, end: number): StyleRun[] {\n const sliced: StyleRun[] = []\n for (const run of runs) {\n const from = Math.max(start, run.start)\n const to = Math.min(end, run.start + run.length)\n if (to > from) sliced.push({ start: from - start, length: to - from, style: run.style })\n }\n return sliced\n}\n\n/** Line heights by paragraph index, `lead` places before the text: each run's, the text's elsewhere. */\nfunction lineHeightRuns(node: ParagraphNode, lead: number): LineHeightRun[] {\n // A percent line height follows the font size of the characters it spaces.\n const own = (fontSize = node.fontSize) => lineHeightPixels(node.lineHeight, fontSize) || null\n const runs: LineHeightRun[] = []\n const add = (start: number, end: number, lineHeight: number | null) => {\n const last = runs.at(-1)\n // Runs at one line height measure as one, whatever else they style.\n if (last?.end === start && last.lineHeight === lineHeight) last.end = end\n else runs.push({ start, end, lineHeight })\n }\n let position = 0\n for (const run of node.styleRuns) {\n if (position < run.start) add(position + lead, run.start + lead, own())\n const runSize = run.style.fontSize ?? node.fontSize\n const lineHeight =\n run.style.lineHeight !== undefined\n ? lineHeightPixels(run.style.lineHeight, runSize) || null\n : own(runSize)\n add(run.start + lead, run.start + run.length + lead, lineHeight)\n position = run.start + run.length\n }\n if (position < node.text.length) add(position + lead, node.text.length + lead, own())\n return runs\n}\n\n/**\n * What placing a paragraph's lines as Figma does needs: its line heights, and its lines laid\n * out one by one from `node`'s text, the first after its indent and the last truncated as the\n * paragraph is.\n */\nfunction paragraphLines(\n r: TextRenderer,\n node: ParagraphNode,\n color: Float32Array | undefined,\n options: ParagraphBuildOptions,\n firstLineIndent = 0\n): TextLayoutBlockLines | undefined {\n // Lines are cut by character index, which the text's case must keep.\n if (shownText(node).length !== node.text.length) return undefined\n const lead = firstLineIndent > 0 ? 1 : 0\n const ellipsis = buildTruncateOpts(node).ellipsis\n // A justified line is stretched only with text after it: lines are laid out with the rest\n // of the paragraph and cut, as truncated last lines are.\n const justified = node.textAlignHorizontal === 'JUSTIFIED'\n const lineTruncation = (lines: number, truncated: boolean) => {\n if (truncated) return { maxLines: lines, ellipsis }\n return justified ? { maxLines: lines } : {}\n }\n return {\n heights: lineHeightRuns(node, lead),\n // A trimmed edge is laid out by where it stands in the paragraph.\n build:\n node.leadingTrim === 'CAP_HEIGHT'\n ? undefined\n : (start, end, lines, truncated) => {\n const from = Math.max(0, start - lead)\n const to = justified ? node.text.length : end - lead\n const line: ParagraphNode = {\n ...node,\n text: node.text.slice(from, to),\n styleRuns: sliceStyleRuns(node.styleRuns, from, to)\n }\n return buildSkParagraph(r, line, color, options, {\n firstLineIndent: start === 0 ? firstLineIndent : 0,\n truncation: lineTruncation(lines, truncated)\n })\n }\n }\n}\n\n/** Whether the text lays out paragraph by paragraph rather than as one native paragraph. */\nfunction needsParagraphLayout(node: ParagraphNode): boolean {\n return (\n hasTextList(node) ||\n node.paragraphSpacing !== 0 ||\n node.paragraphIndent !== 0 ||\n node.textParagraphs.some(hasParagraphSpacing)\n )\n}\n\nfunction layoutForNode(layout: TextLayout, node: ParagraphNode): void {\n if (node.textAutoResize === 'WIDTH_AND_HEIGHT') {\n layout.layout(1e6)\n layout.layout(Math.max(node.width || 1, Math.ceil(layout.getLongestLine())))\n } else {\n layout.layout(resolveParagraphLayoutWidth(node))\n }\n}\n\ninterface ListStyle {\n em: number\n family: string\n style: string\n /** The name of the first character's face, which its markers are drawn in. */\n faceName: string | null\n /** The list's first character's style, which its markers take. */\n override: CharacterStyleOverride | undefined\n}\n\nfunction listStyle(node: ParagraphNode, firstCharacter: number): ListStyle {\n const override = styleAt(node.styleRuns, firstCharacter)\n return {\n em: override?.fontSize ?? (node.fontSize || DEFAULT_FONT_SIZE),\n family: override?.fontFamily ?? (node.fontFamily || DEFAULT_FONT_FAMILY),\n style: textFontFace(node, override).style,\n faceName: rangeFontStyle(node, override ?? {}),\n override\n }\n}\n\n/** A marker in its list's style, without the text's decoration and with figures of one width. */\nfunction markerNode(node: ParagraphNode, item: TextListItem, style: ListStyle): ParagraphNode {\n const override = style.override\n const features = override?.fontFeatures ?? node.fontFeatures\n return {\n ...node,\n text: item.marker,\n fontSize: style.em,\n fontFamily: style.family,\n fontWeight: override?.fontWeight ?? node.fontWeight,\n italic: override?.italic ?? node.italic,\n fontStyle: style.faceName,\n letterSpacing: override?.letterSpacing ?? node.letterSpacing,\n lineHeight: override?.lineHeight !== undefined ? override.lineHeight : node.lineHeight,\n fontVariations: override?.fontVariations ?? node.fontVariations,\n opticalSizeFromFontSize: override?.opticalSizeFromFontSize ?? node.opticalSizeFromFontSize,\n fontFeatures:\n item.listType === 'ORDERED' ? [...features, { tag: 'TNUM', enabled: true }] : features,\n textLanguage: override?.textLanguage !== undefined ? override.textLanguage : node.textLanguage,\n styleRuns: override?.fills\n ? [{ start: 0, length: item.marker.length, style: { fills: override.fills } }]\n : [],\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDirection: 'LTR',\n textAlignHorizontal: 'LEFT',\n textAutoResize: 'WIDTH_AND_HEIGHT',\n textTruncation: 'DISABLED',\n maxLines: null\n }\n}\n\n/**\n * Text with lists, paragraph spacing, or a first-line indent, laid out one paragraph per\n * native paragraph: Skia has no hanging indent, so each list item lays out at the width its\n * indent leaves, beside a marker of its own.\n */\nfunction buildBlocks(\n r: TextRenderer,\n node: ParagraphNode,\n color: Float32Array | undefined,\n options: ParagraphBuildOptions\n): TextLayout {\n const shown = shownText(node)\n const sources = textParagraphRanges(node.text)\n const shownRanges = textParagraphRanges(shown)\n const items = new Map(\n textListItems(node.text, node.textParagraphs).map((item) => [item.paragraph, item])\n )\n const digits = topLevelNumberDigits([...items.values()])\n const rtl = resolveNodeTextDirection(node) === 'RTL'\n const truncation = buildTruncateOpts(node)\n const maxLines = truncation.maxLines\n // Each paragraph starts one byte, its newline, after the one before it ends.\n const utf8Starts: number[] = []\n let utf8Offset = 0\n for (const range of shownRanges) {\n utf8Starts.push(utf8Offset)\n utf8Offset += utf8Length(shown.slice(range.start, range.end)) + 1\n }\n\n const blocks: TextLayoutBlock[] = []\n try {\n for (const [index, { start, end }] of sources.entries()) {\n blocks.push(buildBlock(index, start, end))\n }\n } catch (error) {\n // Native paragraphs built before the failure are not garbage collected.\n for (const block of blocks) {\n block.paragraph.delete()\n block.marker?.paragraph.delete()\n }\n throw error\n }\n return new TextLayout(r.ck, blocks, maxLines)\n\n function buildBlock(index: number, start: number, end: number): TextLayoutBlock {\n const shownRange: TextParagraphRange = shownRanges[index]\n const item = items.get(index)\n const paragraphStyle = paragraphStyleAt(node.textParagraphs, index)\n const empty = end === start\n const blockNode: ParagraphNode = {\n ...node,\n text: empty ? ' ' : node.text.slice(start, end),\n styleRuns: empty\n ? sliceStyleRuns(node.styleRuns, start, start + 1)\n : sliceStyleRuns(node.styleRuns, start, end)\n }\n const paragraphIndent = paragraphSpacingAt(node, index, 'paragraphIndent')\n const firstLineIndent =\n paragraphStyle.listType === 'NONE' && paragraphIndent > 0 ? paragraphIndent : 0\n const blockOptions = (lines?: number): ParagraphBlockOptions => ({\n firstLineIndent,\n truncation: lines === undefined ? {} : { maxLines: lines, ellipsis: truncation.ellipsis },\n edges: { first: index === 0, last: index === sources.length - 1 }\n })\n const betweenItems =\n index > 0 &&\n paragraphStyleAt(node.textParagraphs, index - 1).listType !== 'NONE' &&\n paragraphStyle.listType !== 'NONE'\n const list = item ? listStyle(node, sources[item.groupStart].start) : null\n const marker = item && list ? buildMarker(r, node, item, list, color, options) : null\n let paragraph: Paragraph\n try {\n paragraph = buildSkParagraph(r, blockNode, color, options, blockOptions(maxLines))\n } catch (error) {\n marker?.paragraph.delete()\n throw error\n }\n return {\n paragraph,\n rebuild:\n maxLines === undefined\n ? undefined\n : (lines) => buildSkParagraph(r, blockNode, color, options, blockOptions(lines)),\n start: shownRange.start,\n utf8Start: utf8Starts[index],\n length: shownRange.end - shownRange.start,\n lead: firstLineIndent > 0 ? 1 : 0,\n utf8Lead: firstLineIndent > 0 ? PLACEHOLDER_UTF8_LENGTH : 0,\n leadWidth: firstLineIndent,\n empty,\n inset: item && list ? listInset(node, item, list, digits) : 0,\n rtl,\n // The space after a paragraph is its own: the paragraph before sets the space before.\n spaceBefore:\n index === 0\n ? 0\n : paragraphSpacingAt(node, index - 1, betweenItems ? 'listSpacing' : 'paragraphSpacing'),\n marker,\n lines: paragraphLines(r, blockNode, color, options, firstLineIndent),\n x: 0,\n y: 0,\n visible: true\n }\n }\n}\n\n/**\n * How far a list item's text stands from the start edge: its level's indent, widened for\n * ordered items by the digits past the first of the largest top-level number. A hanging list\n * moves the items back by one level, so markers stand outside the text box.\n */\nfunction listInset(\n node: ParagraphNode,\n item: TextListItem,\n list: ListStyle,\n digits: number\n): number {\n const unit = list.em * LIST_INDENT_EMS\n let inset = item.level * unit\n if (item.listType === 'ORDERED' && digits > 1) {\n const digit = glyphAdvanceSync(list.family, list.style, LIST_DIGIT_GLYPH_ID, list.em)\n inset += (digits - 1) * (digit ?? list.em * FALLBACK_DIGIT_EMS)\n }\n return node.hangingList ? inset - unit : inset\n}\n\nfunction buildMarker(\n r: TextRenderer,\n node: ParagraphNode,\n item: TextListItem,\n list: ListStyle,\n color: Float32Array | undefined,\n options: ParagraphBuildOptions\n): TextLayoutMarker {\n const paragraph = buildSkParagraph(r, markerNode(node, item, list), color, options)\n paragraph.layout(1e6)\n return {\n paragraph,\n kind: item.listType === 'ORDERED' ? 'number' : 'bullet',\n em: list.em,\n face: { family: list.family, style: list.style },\n x: 0,\n y: 0,\n lineNumber: 0\n }\n}\n\nfunction createTextLayout(\n r: TextRenderer,\n node: ParagraphNode,\n color: Float32Array | undefined,\n options: ParagraphBuildOptions\n): TextLayout {\n return needsParagraphLayout(node)\n ? buildBlocks(r, node, color, options)\n : TextLayout.ofParagraph(\n r.ck,\n buildSkParagraph(r, node, color, options),\n shownText(node).length,\n paragraphLines(r, node, color, options)\n )\n}\n\n/** How many laid-out line boxes fit the fixed height, preserving the first line. */\nfunction linesWithinHeight(layout: TextLayout, height: number): number {\n const lines = layout.getLineMetrics()\n const firstOverflow = lines.findIndex((line) => line.baseline + line.descent > height)\n return Math.max(1, firstOverflow === -1 ? lines.length : firstOverflow)\n}\n\n/** Lay a text node out as the renderer draws it, at its own width. */\nexport function buildParagraph(\n r: TextRenderer,\n node: ParagraphNode,\n color?: Float32Array,\n options: ParagraphBuildOptions = {}\n): TextLayout {\n const layout = createTextLayout(r, node, color, options)\n const heightTruncation =\n node.textTruncation === 'ENDING' &&\n node.height > 0 &&\n (node.maxLines == null || node.maxLines <= 0)\n let fittingLines: number | undefined\n try {\n layoutForNode(layout, node)\n if (heightTruncation) fittingLines = linesWithinHeight(layout, node.height)\n } catch (error) {\n layout.delete()\n throw error\n }\n if (fittingLines !== undefined && fittingLines < layout.getLineMetrics().length) {\n layout.delete()\n return buildParagraph(r, { ...node, maxLines: fittingLines }, color, options)\n }\n return layout\n}\n"],"mappings":";;;;;;;;;;;;AAoCA,MAAM,kBAAkB;;;;;AAKxB,MAAM,sBAAsB;;AAE5B,MAAM,qBAAqB;;AAE3B,MAAM,0BAA0B;AAEhC,SAAS,QAAQ,MAA2B,OAAmD;CAC7F,OAAO,KAAK,MAAM,QAAQ,SAAS,IAAI,SAAS,QAAQ,IAAI,QAAQ,IAAI,MAAM,CAAC,EAAE;AACnF;;AAGA,SAAS,eAAe,MAA2B,OAAe,KAAyB;CACzF,MAAM,SAAqB,CAAC;CAC5B,KAAK,MAAM,OAAO,MAAM;EACtB,MAAM,OAAO,KAAK,IAAI,OAAO,IAAI,KAAK;EACtC,MAAM,KAAK,KAAK,IAAI,KAAK,IAAI,QAAQ,IAAI,MAAM;EAC/C,IAAI,KAAK,MAAM,OAAO,KAAK;GAAE,OAAO,OAAO;GAAO,QAAQ,KAAK;GAAM,OAAO,IAAI;EAAM,CAAC;CACzF;CACA,OAAO;AACT;;AAGA,SAAS,eAAe,MAAqB,MAA+B;CAE1E,MAAM,OAAO,WAAW,KAAK,aAAa,iBAAiB,KAAK,YAAY,QAAQ,KAAK;CACzF,MAAM,OAAw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I,IAC5B,YAAY,GAAG,MAAM,OAAO,OAAO,IACnC,WAAW,YACT,EAAE,IACF,iBAAiB,GAAG,MAAM,OAAO,OAAO,GACxC,UAAU,IAAI,CAAC,CAAC,QAChB,eAAe,GAAG,MAAM,OAAO,OAAO,CACxC;AACN;;AAGA,SAAS,kBAAkB,QAAoB,QAAwB;CACrE,MAAM,QAAQ,OAAO,eAAe;CACpC,MAAM,gBAAgB,MAAM,WAAW,SAAS,KAAK,WAAW,KAAK,UAAU,MAAM;CACrF,OAAO,KAAK,IAAI,GAAG,kBAAkB,KAAK,MAAM,SAAS,aAAa;AACxE;;AAGA,SAAgB,eACd,GACA,MACA,OACA,UAAiC,CAAC,GACtB;CACZ,MAAM,SAAS,iBAAiB,GAAG,MAAM,OAAO,OAAO;CACvD,MAAM,mBACJ,KAAK,mBAAmB,YACxB,KAAK,SAAS,MACb,KAAK,YAAY,QAAQ,KAAK,YAAY;CAC7C,IAAI;CACJ,IAAI;EACF,cAAc,QAAQ,IAAI;EAC1B,IAAI,kBAAkB,eAAe,kBAAkB,QAAQ,KAAK,MAAM;CAC5E,SAAS,OAAO;EACd,OAAO,OAAO;EACd,MAAM;CACR;CACA,IAAI,iBAAiB,KAAA,KAAa,eAAe,OAAO,eAAe,CAAC,CAAC,QAAQ;EAC/E,OAAO,OAAO;EACd,OAAO,eAAe,GAAG;GAAE,GAAG;GAAM,UAAU;EAAa,GAAG,OAAO,OAAO;CAC9E;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"build.js","names":[],"sources":["../../../../src/canvas/text/layout/build.ts"],"sourcesContent":["import type { Paragraph } from 'canvaskit-wasm'\n\nimport type { CharacterStyleOverride, StyleRun, TextLength } from '@pairdraw/scene-graph'\nimport { rangeFontStyle } from '@pairdraw/scene-graph/shared-styles'\nimport {\n hasParagraphSpacing,\n hasTextList,\n paragraphSpacingAt,\n paragraphStyleAt,\n textListItems,\n textParagraphRanges,\n lineHeightPixels,\n lineStepPixels,\n topLevelNumberDigits,\n type TextListItem,\n type TextParagraphRange\n} from '@pairdraw/scene-graph/text'\nimport { resolveNodeTextDirection } from '@pairdraw/scene-graph/text/direction'\n\nimport { TextLayout, type TextLayoutBlock, type TextLayoutMarker } from '#core/canvas/text/layout'\nimport type { LineHeightRun, TextLayoutBlockLines } from '#core/canvas/text/layout/lines'\nimport type { ParagraphBuildOptions } from '#core/canvas/text/paint'\nimport {\n buildSkParagraph,\n buildTruncateOpts,\n resolveParagraphLayoutWidth,\n type ParagraphBlockOptions\n} from '#core/canvas/text/paragraph'\nimport type { ParagraphNode } from '#core/canvas/text/paragraph/inputs'\nimport type { TextRenderer } from '#core/canvas/text/renderer'\nimport { utf8Length } from '#core/canvas/text/utf8'\nimport { DEFAULT_FONT_FAMILY, DEFAULT_FONT_SIZE } from '#core/constants'\nimport { autoWidthWrapWidth } from '#core/layout/text-measurement'\nimport { shownText } from '#core/text/case'\nimport { glyphAdvanceSync } from '#core/text/font/glyphs'\nimport { textFontFace } from '#core/text/requirements/collect'\n\n/** A list item's indent per level, in ems of the list's first character. */\nconst LIST_INDENT_EMS = 1.5\n/**\n * Figma widens ordered lists by the advance of glyph 48 per extra digit: the character code of\n * \"0\" read as a glyph ID. Measured in live Figma for Inter, Roboto, DM Sans, and others.\n */\nconst LIST_DIGIT_GLYPH_ID = 48\n/** A digit's width, in ems, for a font whose glyphs cannot be read. */\nconst FALLBACK_DIGIT_EMS = 0.6\n/** The placeholder a first-line indent puts before the text takes one UTF-16 unit, three bytes. */\nconst PLACEHOLDER_UTF8_LENGTH = 3\n\nfunction styleAt(runs: readonly StyleRun[], index: number): CharacterStyleOverride | undefined {\n return runs.find((run) => index >= run.start && index < run.start + run.length)?.style\n}\n\n/** Style runs of `text[start, end)` in the slice's own indices. */\nfunction sliceStyleRuns(runs: readonly StyleRun[], start: number, end: number): StyleRun[] {\n const sliced: StyleRun[] = []\n for (const run of runs) {\n const from = Math.max(start, run.start)\n const to = Math.min(end, run.start + run.length)\n if (to > from) sliced.push({ start: from - start, length: to - from, style: run.style })\n }\n return sliced\n}\n\n/** Line heights by paragraph index, `lead` places before the text: each run's, the text's elsewhere. */\nfunction lineHeightRuns(node: ParagraphNode, lead: number): LineHeightRun[] {\n // A line height of zero lays lines out as auto; a percent one under half a pixel steps them\n // by none, as Figma does.\n const step = (lineHeight: TextLength | null, fontSize: number) =>\n lineHeightPixels(lineHeight, fontSize) ? lineStepPixels(lineHeight, fontSize) : null\n // A percent line height follows the font size of the characters it spaces.\n const own = (fontSize = node.fontSize) => step(node.lineHeight, fontSize)\n const runs: LineHeightRun[] = []\n const add = (start: number, end: number, lineHeight: number | null) => {\n const last = runs.at(-1)\n // Runs at one line height measure as one, whatever else they style.\n if (last?.end === start && last.lineHeight === lineHeight) last.end = end\n else runs.push({ start, end, lineHeight })\n }\n let position = 0\n for (const run of node.styleRuns) {\n if (position < run.start) add(position + lead, run.start + lead, own())\n const runSize = run.style.fontSize ?? node.fontSize\n const lineHeight =\n run.style.lineHeight !== undefined ? step(run.style.lineHeight, runSize) : own(runSize)\n add(run.start + lead, run.start + run.length + lead, lineHeight)\n position = run.start + run.length\n }\n if (position < node.text.length) add(position + lead, node.text.length + lead, own())\n return runs\n}\n\n/**\n * What placing a paragraph's lines as Figma does needs: its line heights, and its lines laid\n * out one by one from `node`'s text, the first after its indent and the last truncated as the\n * paragraph is.\n */\nfunction paragraphLines(\n r: TextRenderer,\n node: ParagraphNode,\n color: Float32Array | undefined,\n options: ParagraphBuildOptions,\n firstLineIndent = 0\n): TextLayoutBlockLines | undefined {\n // Lines are cut by character index, which the text's case must keep.\n if (shownText(node).length !== node.text.length) return undefined\n const lead = firstLineIndent > 0 ? 1 : 0\n const ellipsis = buildTruncateOpts(node).ellipsis\n // A justified line is stretched only with text after it: lines are laid out with the rest\n // of the paragraph and cut, as truncated last lines are.\n const justified = node.textAlignHorizontal === 'JUSTIFIED'\n const lineTruncation = (lines: number, truncated: boolean) => {\n if (truncated) return { maxLines: lines, ellipsis }\n return justified ? { maxLines: lines } : {}\n }\n return {\n heights: lineHeightRuns(node, lead),\n // A trimmed edge is laid out by where it stands in the paragraph.\n build:\n node.leadingTrim === 'CAP_HEIGHT'\n ? undefined\n : (start, end, lines, truncated) => {\n const from = Math.max(0, start - lead)\n const to = justified ? node.text.length : end - lead\n const line: ParagraphNode = {\n ...node,\n text: node.text.slice(from, to),\n styleRuns: sliceStyleRuns(node.styleRuns, from, to)\n }\n return buildSkParagraph(r, line, color, options, {\n firstLineIndent: start === 0 ? firstLineIndent : 0,\n truncation: lineTruncation(lines, truncated)\n })\n }\n }\n}\n\n/** Whether the text lays out paragraph by paragraph rather than as one native paragraph. */\nfunction needsParagraphLayout(node: ParagraphNode): boolean {\n return (\n hasTextList(node) ||\n node.paragraphSpacing !== 0 ||\n node.paragraphIndent !== 0 ||\n node.textParagraphs.some(hasParagraphSpacing)\n )\n}\n\nfunction layoutForNode(layout: TextLayout, node: ParagraphNode): void {\n if (node.textAutoResize !== 'WIDTH_AND_HEIGHT') {\n layout.layout(resolveParagraphLayoutWidth(node))\n return\n }\n const wrapWidth = resolveParagraphLayoutWidth(node)\n if (truncatesAtMaxWidth(node)) {\n layout.layout(Math.min(node.width || wrapWidth, wrapWidth))\n return\n }\n layout.layout(wrapWidth)\n const widestLine = Math.ceil(layout.getLongestLine())\n const width = Math.min(wrapWidth, Math.max(node.width || 1, widestLine))\n if (width !== wrapWidth) layout.layout(width)\n}\n\nfunction truncatesAtMaxWidth(node: ParagraphNode): boolean {\n return node.textTruncation === 'ENDING' && autoWidthWrapWidth(node) !== undefined\n}\n\ninterface ListStyle {\n em: number\n family: string\n style: string\n /** The name of the first character's face, which its markers are drawn in. */\n faceName: string | null\n /** The list's first character's style, which its markers take. */\n override: CharacterStyleOverride | undefined\n}\n\nfunction listStyle(node: ParagraphNode, firstCharacter: number): ListStyle {\n const override = styleAt(node.styleRuns, firstCharacter)\n return {\n em: override?.fontSize ?? (node.fontSize || DEFAULT_FONT_SIZE),\n family: override?.fontFamily ?? (node.fontFamily || DEFAULT_FONT_FAMILY),\n style: textFontFace(node, override).style,\n faceName: rangeFontStyle(node, override ?? {}),\n override\n }\n}\n\n/** A marker in its list's style, without the text's decoration and with figures of one width. */\nfunction markerNode(node: ParagraphNode, item: TextListItem, style: ListStyle): ParagraphNode {\n const override = style.override\n const features = override?.fontFeatures ?? node.fontFeatures\n return {\n ...node,\n text: item.marker,\n fontSize: style.em,\n fontFamily: style.family,\n fontWeight: override?.fontWeight ?? node.fontWeight,\n italic: override?.italic ?? node.italic,\n fontStyle: style.faceName,\n letterSpacing: override?.letterSpacing ?? node.letterSpacing,\n lineHeight: override?.lineHeight !== undefined ? override.lineHeight : node.lineHeight,\n fontVariations: override?.fontVariations ?? node.fontVariations,\n opticalSizeFromFontSize: override?.opticalSizeFromFontSize ?? node.opticalSizeFromFontSize,\n fontFeatures:\n item.listType === 'ORDERED' ? [...features, { tag: 'TNUM', enabled: true }] : features,\n textLanguage: override?.textLanguage !== undefined ? override.textLanguage : node.textLanguage,\n styleRuns: override?.fills\n ? [{ start: 0, length: item.marker.length, style: { fills: override.fills } }]\n : [],\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDirection: 'LTR',\n textAlignHorizontal: 'LEFT',\n textAutoResize: 'WIDTH_AND_HEIGHT',\n textTruncation: 'DISABLED',\n maxLines: null\n }\n}\n\n/**\n * Text with lists, paragraph spacing, or a first-line indent, laid out one paragraph per\n * native paragraph: Skia has no hanging indent, so each list item lays out at the width its\n * indent leaves, beside a marker of its own.\n */\nfunction buildBlocks(\n r: TextRenderer,\n node: ParagraphNode,\n color: Float32Array | undefined,\n options: ParagraphBuildOptions\n): TextLayout {\n const shown = shownText(node)\n const sources = textParagraphRanges(node.text)\n const shownRanges = textParagraphRanges(shown)\n const items = new Map(\n textListItems(node.text, node.textParagraphs).map((item) => [item.paragraph, item])\n )\n const digits = topLevelNumberDigits([...items.values()])\n const rtl = resolveNodeTextDirection(node) === 'RTL'\n const truncation = buildTruncateOpts(node)\n const maxLines = truncation.maxLines\n // Each paragraph starts one byte, its newline, after the one before it ends.\n const utf8Starts: number[] = []\n let utf8Offset = 0\n for (const range of shownRanges) {\n utf8Starts.push(utf8Offset)\n utf8Offset += utf8Length(shown.slice(range.start, range.end)) + 1\n }\n\n const blocks: TextLayoutBlock[] = []\n try {\n for (const [index, { start, end }] of sources.entries()) {\n blocks.push(buildBlock(index, start, end))\n }\n } catch (error) {\n // Native paragraphs built before the failure are not garbage collected.\n for (const block of blocks) {\n block.paragraph.delete()\n block.marker?.paragraph.delete()\n }\n throw error\n }\n return new TextLayout(r.ck, blocks, maxLines)\n\n function buildBlock(index: number, start: number, end: number): TextLayoutBlock {\n const shownRange: TextParagraphRange = shownRanges[index]\n const item = items.get(index)\n const paragraphStyle = paragraphStyleAt(node.textParagraphs, index)\n const empty = end === start\n const blockNode: ParagraphNode = {\n ...node,\n text: empty ? ' ' : node.text.slice(start, end),\n styleRuns: empty\n ? sliceStyleRuns(node.styleRuns, start, start + 1)\n : sliceStyleRuns(node.styleRuns, start, end)\n }\n const paragraphIndent = paragraphSpacingAt(node, index, 'paragraphIndent')\n const firstLineIndent =\n paragraphStyle.listType === 'NONE' && paragraphIndent > 0 ? paragraphIndent : 0\n const blockOptions = (lines?: number): ParagraphBlockOptions => ({\n firstLineIndent,\n truncation: lines === undefined ? {} : { maxLines: lines, ellipsis: truncation.ellipsis },\n edges: { first: index === 0, last: index === sources.length - 1 }\n })\n const betweenItems =\n index > 0 &&\n paragraphStyleAt(node.textParagraphs, index - 1).listType !== 'NONE' &&\n paragraphStyle.listType !== 'NONE'\n const list = item ? listStyle(node, sources[item.groupStart].start) : null\n const marker = item && list ? buildMarker(r, node, item, list, color, options) : null\n let paragraph: Paragraph\n try {\n paragraph = buildSkParagraph(r, blockNode, color, options, blockOptions(maxLines))\n } catch (error) {\n marker?.paragraph.delete()\n throw error\n }\n return {\n paragraph,\n rebuild:\n maxLines === undefined\n ? undefined\n : (lines) => buildSkParagraph(r, blockNode, color, options, blockOptions(lines)),\n start: shownRange.start,\n utf8Start: utf8Starts[index],\n length: shownRange.end - shownRange.start,\n lead: firstLineIndent > 0 ? 1 : 0,\n utf8Lead: firstLineIndent > 0 ? PLACEHOLDER_UTF8_LENGTH : 0,\n leadWidth: firstLineIndent,\n empty,\n inset: item && list ? listInset(node, item, list, digits) : 0,\n rtl,\n // The space after a paragraph is its own: the paragraph before sets the space before.\n spaceBefore:\n index === 0\n ? 0\n : paragraphSpacingAt(node, index - 1, betweenItems ? 'listSpacing' : 'paragraphSpacing'),\n marker,\n lines: paragraphLines(r, blockNode, color, options, firstLineIndent),\n x: 0,\n y: 0,\n visible: true\n }\n }\n}\n\n/**\n * How far a list item's text stands from the start edge: its level's indent, widened for\n * ordered items by the digits past the first of the largest top-level number. A hanging list\n * moves the items back by one level, so markers stand outside the text box.\n */\nfunction listInset(\n node: ParagraphNode,\n item: TextListItem,\n list: ListStyle,\n digits: number\n): number {\n const unit = list.em * LIST_INDENT_EMS\n let inset = item.level * unit\n if (item.listType === 'ORDERED' && digits > 1) {\n const digit = glyphAdvanceSync(list.family, list.style, LIST_DIGIT_GLYPH_ID, list.em)\n inset += (digits - 1) * (digit ?? list.em * FALLBACK_DIGIT_EMS)\n }\n return node.hangingList ? inset - unit : inset\n}\n\nfunction buildMarker(\n r: TextRenderer,\n node: ParagraphNode,\n item: TextListItem,\n list: ListStyle,\n color: Float32Array | undefined,\n options: ParagraphBuildOptions\n): TextLayoutMarker {\n const paragraph = buildSkParagraph(r, markerNode(node, item, list), color, options)\n paragraph.layout(1e6)\n return {\n paragraph,\n kind: item.listType === 'ORDERED' ? 'number' : 'bullet',\n em: list.em,\n face: { family: list.family, style: list.style },\n x: 0,\n y: 0,\n lineNumber: 0\n }\n}\n\nfunction createTextLayout(\n r: TextRenderer,\n node: ParagraphNode,\n color: Float32Array | undefined,\n options: ParagraphBuildOptions\n): TextLayout {\n if (needsParagraphLayout(node)) return buildBlocks(r, node, color, options)\n const truncation = buildTruncateOpts(node)\n return TextLayout.ofParagraph(\n r.ck,\n buildSkParagraph(r, node, color, options, truncation.ellipsis ? { truncation } : undefined),\n shownText(node).length,\n paragraphLines(r, node, color, options)\n )\n}\n\n/** How many laid-out line boxes fit the fixed height, preserving the first line. */\nfunction linesWithinHeight(layout: TextLayout, height: number): number {\n const lines = layout.getLineMetrics()\n const firstOverflow = lines.findIndex((line) => line.baseline + line.descent > height)\n return Math.max(1, firstOverflow === -1 ? lines.length : firstOverflow)\n}\n\n/** Lay a text node out as the renderer draws it, at its own width. */\nexport function buildParagraph(\n r: TextRenderer,\n node: ParagraphNode,\n color?: Float32Array,\n options: ParagraphBuildOptions = {}\n): TextLayout {\n const layout = createTextLayout(r, node, color, options)\n // A box set to truncate clips to the lines its height holds, which is the auto-resize mode a\n // panel offers; an imported text may instead truncate only where `textTruncation` says so.\n const heightTruncation =\n (node.textTruncation === 'ENDING' || node.textAutoResize === 'TRUNCATE') &&\n node.height > 0 &&\n (node.maxLines == null || node.maxLines <= 0)\n let fittingLines: number | undefined\n try {\n layoutForNode(layout, node)\n if (heightTruncation) fittingLines = linesWithinHeight(layout, node.height)\n } catch (error) {\n layout.delete()\n throw error\n }\n if (fittingLines !== undefined && fittingLines < layout.getLineMetrics().length) {\n layout.delete()\n return buildParagraph(r, { ...node, maxLines: fittingLines }, color, options)\n }\n return layout\n}\n"],"mappings":";;;;;;;;;;;;;AAsCA,MAAM,kBAAkB;;;;;AAKxB,MAAM,sBAAsB;;AAE5B,MAAM,qBAAqB;;AAE3B,MAAM,0BAA0B;AAEhC,SAAS,QAAQ,MAA2B,OAAmD;CAC7F,OAAO,KAAK,MAAM,QAAQ,SAAS,IAAI,SAAS,QAAQ,IAAI,QAAQ,IAAI,MAAM,CAAC,EAAE;AACnF;;AAGA,SAAS,eAAe,MAA2B,OAAe,KAAyB;CACzF,MAAM,SAAqB,CAAC;CAC5B,KAAK,MAAM,OAAO,MAAM;EACtB,MAAM,OAAO,KAAK,IAAI,OAAO,IAAI,KAAK;EACtC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a,eAAe,eAAe;;;;;UAoDnC;;;;;;EAgBR,kBAAkB;UA0CV;;EAKR,cAAc;EAMd,KAAK,QAAQ,QAAQ,WAAW;;UAaxB;EAcR;EAIA"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/canvas/text/layout/index.ts"],"mappings":";;;;UAoBiB;EACf,WAAW;EACX;;EAEA;;EAEA;IAAQ;IAAgB;;;EAExB;EACA;EACA;;;UAIe;EACf,WAAW;;EAEX,WAAW,qBAAqB;;EAEhC;EACA;;EAEA;;EAEA;EACA;EACA;;EAEA;;EAEA;EACA;;EAEA;EACA,QAAQ;;EAER,QAAQ;EACR;EACA;;EAEA;;UAGe;EACf;EACA;EACA;;;;;;;;cASW;mBAsCQ;WACR,QAAQ;;mBAEA;UAxCX;UACA;UACA;mBACS;;UAET;;SAGD,YACL,IAAI,WACJ,WAAW,WACX,gBACA,QAAQ,uBACP;EAwBgB,YAAA,IAAI,WACZ,QAAQ,mBAEA;;EAAA;;mBAIF;UAET;EAIR,OAAO;UAmCC;;;;;UAYA;;UAWA;;UAKA;UAQA;UAIA;UAsBA;UAIA;EAgDR;EAMA;EASA;EAIA,kBAAkB;EAIlB,iBAAiB,qBAAqB;;UAK9B;EASR,gBAAgB;EAehB,6BAA6B,WAAW,YAAY;EAsBpD,iBACE,eACA,aACA,aAAa,iBACb,YAAY,iBACX;;;;;EA4BH,aAAa,eAAe,eAAe;;;;;UAoDnC;;;;;;EAgBR,kBAAkB;UA0CV;;EAKR,cAAc;EAMd,KAAK,QAAQ,QAAQ,WAAW;;UAaxB;EAcR;EAIA"}
@@ -141,10 +141,14 @@ var TextLayout = class TextLayout {
141
141
  const metrics = block.paragraph.getLineMetrics();
142
142
  const boxes = this.placements.get(block)?.boxes;
143
143
  const blockEnd = block.start + block.length;
144
+ let previousEnd = block.start;
144
145
  for (const [lineIndex, line] of metrics.entries()) {
145
146
  const endsAtNewline = lineIndex === metrics.length - 1 && blockIndex < visible.length - 1;
146
147
  const indent = lineIndex === 0 ? block.leadWidth : 0;
147
148
  const box = boxes?.[lineIndex];
149
+ const startIndex = Math.max(previousEnd, this.toTextIndex(block, line.startIndex));
150
+ const endIncludingNewline = endsAtNewline ? blockEnd + 1 : this.toTextIndex(block, line.endIncludingNewline);
151
+ previousEnd = endIncludingNewline;
148
152
  this.lines.push({
149
153
  ...line,
150
154
  ...box && {
@@ -152,10 +156,10 @@ var TextLayout = class TextLayout {
152
156
  descent: box.height - box.ascent,
153
157
  height: box.height
154
158
  },
155
- startIndex: this.toTextIndex(block, line.startIndex),
156
- endIndex: this.toTextIndex(block, line.endIndex),
157
- endExcludingWhitespaces: this.toTextIndex(block, line.endExcludingWhitespaces),
158
- endIncludingNewline: endsAtNewline ? blockEnd + 1 : this.toTextIndex(block, line.endIncludingNewline),
159
+ startIndex,
160
+ endIndex: Math.max(startIndex, this.toTextIndex(block, line.endIndex)),
161
+ endExcludingWhitespaces: Math.max(startIndex, this.toTextIndex(block, line.endExcludingWhitespaces)),
162
+ endIncludingNewline,
159
163
  isHardBreak: endsAtNewline || line.isHardBreak,
160
164
  width: block.empty ? 0 : line.width - indent,
161
165
  left: line.left + block.x + (block.rtl ? 0 : indent),
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../../src/canvas/text/layout/index.ts"],"sourcesContent":["import type {\n Canvas,\n CanvasKit,\n LineMetrics,\n Paragraph,\n PositionWithAffinity,\n RectHeightStyle,\n RectWidthStyle,\n RectWithDirection,\n ShapedLine\n} from 'canvaskit-wasm'\n\nimport {\n placeLines,\n shapedLinesByLine,\n type BlockPlacement,\n type TextLayoutBlockLines\n} from '#core/canvas/text/layout/lines'\n\n/** A list item's number or bullet, laid out on its own. */\nexport interface TextLayoutMarker {\n paragraph: Paragraph\n kind: 'bullet' | 'number'\n /** Font size of the list's first character, which sets the marker's distance from the text. */\n em: number\n /** The face the marker is set in, for its glyph outlines. */\n face: { family: string; style: string }\n /** Where the marker is drawn and the line of the item it marks, set by layout. */\n x: number\n y: number\n lineNumber: number\n}\n\n/** One paragraph of the text, or the whole text when it needs no paragraph layout of its own. */\nexport interface TextLayoutBlock {\n paragraph: Paragraph\n /** Rebuilds the paragraph to show at most `maxLines` lines, when the text is truncated. */\n rebuild?: (maxLines: number) => Paragraph\n /** The first character the block holds, as an index into the text and in UTF-8 bytes. */\n start: number\n utf8Start: number\n /** Characters the block holds, not counting the newline that ends it. */\n length: number\n /** Indices before the text, in UTF-16 and UTF-8, and its width: a first-line indent. */\n lead: number\n utf8Lead: number\n leadWidth: number\n /** Laid out from a space, standing for a paragraph with no characters. */\n empty: boolean\n /** Distance of the text from the start edge: a list item's indent. */\n inset: number\n rtl: boolean\n /** Space above the block, from the paragraph before it. */\n spaceBefore: number\n marker: TextLayoutMarker | null\n /** What placing its lines as Figma does needs; without it they stack as the paragraph's. */\n lines?: TextLayoutBlockLines\n x: number\n y: number\n /** Whether the block is shown, as truncation hides blocks past its last line. */\n visible: boolean\n}\n\nexport interface TextCaretBox {\n x: number\n top: number\n bottom: number\n}\n\n/**\n * A laid-out text node: one native paragraph per block, stacked with paragraph and list\n * spacing, each indented by its list level and preceded by its marker. It answers the\n * `Paragraph` queries the renderer, measurement, and the text editor ask, in indices of the\n * whole text and coordinates of the whole layout.\n */\nexport class TextLayout {\n private lines: LineMetrics[] = []\n private lineOffsets: number[] = []\n private truncated = false\n private readonly placements = new Map<TextLayoutBlock, BlockPlacement>()\n /** The text's height when layout placed its lines itself. */\n private placedHeight: number | null = null\n\n /** Text laid out as one native paragraph of `length` characters, not yet laid out. */\n static ofParagraph(\n ck: CanvasKit,\n paragraph: Paragraph,\n length: number,\n lines?: TextLayoutBlockLines\n ): TextLayout {\n return new TextLayout(ck, [\n {\n paragraph,\n start: 0,\n utf8Start: 0,\n length,\n lead: 0,\n utf8Lead: 0,\n leadWidth: 0,\n empty: false,\n inset: 0,\n rtl: false,\n spaceBefore: 0,\n marker: null,\n lines,\n x: 0,\n y: 0,\n visible: true\n }\n ])\n }\n\n constructor(\n private readonly ck: CanvasKit,\n readonly blocks: TextLayoutBlock[],\n /** Lines the text may show in all, when it is truncated across blocks. */\n private readonly maxLines?: number\n ) {}\n\n /** The line cap a block's paragraph was rebuilt with, when it differs from `maxLines`. */\n private readonly caps = new Map<TextLayoutBlock, number>()\n\n private visibleBlocks(): TextLayoutBlock[] {\n return this.blocks.filter((block) => block.visible)\n }\n\n layout(width: number): void {\n let y = 0\n let lines = 0\n this.truncated = false\n this.clearPlacements()\n for (const [index, block] of this.blocks.entries()) {\n const remaining = this.maxLines === undefined ? Infinity : this.maxLines - lines\n block.visible = remaining > 0\n if (!block.visible) {\n this.truncated = true\n continue\n }\n block.paragraph.layout(Math.max(1, width - block.inset))\n // A block capped for a narrower layout gets its lines back when there is room for them.\n const cap = this.caps.get(block) ?? this.maxLines ?? Infinity\n const overflows = block.paragraph.getLineMetrics().length > remaining\n const clipped = cap < remaining && block.paragraph.didExceedMaxLines()\n if ((overflows || clipped) && block.rebuild) {\n block.paragraph.delete()\n block.paragraph = block.rebuild(remaining)\n this.caps.set(block, remaining)\n block.paragraph.layout(Math.max(1, width - block.inset))\n }\n if (block.paragraph.didExceedMaxLines()) this.truncated = true\n if (index > 0) y += block.spaceBefore\n block.x = block.rtl ? 0 : block.inset\n block.y = y\n y += block.paragraph.getHeight()\n lines += block.paragraph.getLineMetrics().length\n }\n this.placeLines(width)\n for (const block of this.visibleBlocks()) this.placeMarker(block)\n this.collectLines()\n }\n\n private clearPlacements(): void {\n for (const placement of this.placements.values()) {\n for (const piece of placement.pieces ?? []) piece.paragraph.delete()\n }\n this.placements.clear()\n this.placedHeight = null\n }\n\n /**\n * Places lines as Figma does when they differ in height, keeping the paragraph's placement\n * otherwise (`placeLines`).\n */\n private placeLines(width: number): void {\n const placed = placeLines(this.ck, this.visibleBlocks(), width)\n if (!placed) return\n for (const [block, { y, ...placement }] of placed.blocks) {\n block.y = y\n this.placements.set(block, placement)\n }\n this.placedHeight = placed.height\n }\n\n /** The block's line `index` stands this far below where its paragraph has it. */\n private lineOffset(block: TextLayoutBlock, index: number): number {\n return this.placements.get(block)?.offsets[index] ?? 0\n }\n\n /** How far a point `y` of the block's paragraph moves, by the line it falls on. */\n private offsetAt(block: TextLayoutBlock, y: number): number {\n const placement = this.placements.get(block)\n if (!placement) return 0\n const lines = block.paragraph.getLineMetrics()\n const index = lines.findIndex((line) => y < line.baseline + line.descent)\n return placement.offsets[index === -1 ? lines.length - 1 : index] ?? 0\n }\n\n private blockHeight(block: TextLayoutBlock): number {\n return this.placements.get(block)?.height ?? block.paragraph.getHeight()\n }\n\n private placeMarker(block: TextLayoutBlock): void {\n const marker = block.marker\n const first = block.paragraph.getLineMetrics().at(0)\n if (!marker || !first) return\n const markerLine = marker.paragraph.getLineMetrics().at(0)\n const width = marker.paragraph.getLongestLine()\n // A bullet centres on the middle of the indent; a number ends a third of an em before the\n // text, so numbers of any width line up on their periods.\n if (block.rtl) {\n const start = block.x + first.left + first.width\n marker.x =\n marker.kind === 'bullet' ? start + marker.em * 0.75 - width / 2 : start + marker.em / 3\n } else {\n const start = block.x + first.left\n marker.x =\n marker.kind === 'bullet'\n ? start - marker.em * 0.75 - width / 2\n : start - marker.em / 3 - width\n }\n marker.y = block.y + first.baseline - (markerLine?.baseline ?? 0)\n }\n\n private toTextIndex(block: TextLayoutBlock, index: number): number {\n return block.start + Math.max(0, Math.min(block.length, index - block.lead))\n }\n\n private collectLines(): void {\n this.lines = []\n this.lineOffsets = []\n const visible = this.visibleBlocks()\n for (const [blockIndex, block] of visible.entries()) {\n this.lineOffsets.push(this.lines.length)\n if (block.marker) block.marker.lineNumber = this.lines.length\n const metrics = block.paragraph.getLineMetrics()\n const boxes = this.placements.get(block)?.boxes\n const blockEnd = block.start + block.length\n for (const [lineIndex, line] of metrics.entries()) {\n const lastOfBlock = lineIndex === metrics.length - 1\n const endsAtNewline = lastOfBlock && blockIndex < visible.length - 1\n // A first-line indent is room before the text, not part of the line.\n const indent = lineIndex === 0 ? block.leadWidth : 0\n const box = boxes?.[lineIndex]\n this.lines.push({\n ...line,\n ...(box && {\n ascent: box.ascent,\n descent: box.height - box.ascent,\n height: box.height\n }),\n startIndex: this.toTextIndex(block, line.startIndex),\n endIndex: this.toTextIndex(block, line.endIndex),\n endExcludingWhitespaces: this.toTextIndex(block, line.endExcludingWhitespaces),\n endIncludingNewline: endsAtNewline\n ? blockEnd + 1\n : this.toTextIndex(block, line.endIncludingNewline),\n isHardBreak: endsAtNewline || line.isHardBreak,\n width: block.empty ? 0 : line.width - indent,\n left: line.left + block.x + (block.rtl ? 0 : indent),\n baseline: line.baseline + block.y + this.lineOffset(block, lineIndex),\n lineNumber: this.lines.length\n })\n }\n }\n }\n\n getHeight(): number {\n const last = this.visibleBlocks().at(-1)\n if (this.placedHeight !== null) return this.placedHeight\n return last ? last.y + last.paragraph.getHeight() : 0\n }\n\n getLongestLine(): number {\n let longest = 0\n for (const block of this.visibleBlocks()) {\n if (block.empty) continue\n longest = Math.max(longest, block.inset + block.paragraph.getLongestLine())\n }\n return longest\n }\n\n didExceedMaxLines(): boolean {\n return this.truncated\n }\n\n getLineMetrics(): LineMetrics[] {\n return this.lines\n }\n\n getLineMetricsAt(lineNumber: number): LineMetrics | null {\n return this.lines[lineNumber] ?? null\n }\n\n /** The block holding text index `index`; the newline ending a block belongs to it. */\n private blockAt(index: number): { block: TextLayoutBlock; order: number } | null {\n const visible = this.visibleBlocks()\n for (const [order, block] of visible.entries()) {\n if (index <= block.start + block.length) return { block, order }\n }\n const last = visible.at(-1)\n return last ? { block: last, order: visible.length - 1 } : null\n }\n\n getLineNumberAt(index: number): number {\n const found = this.blockAt(index)\n if (!found) return -1\n const { block, order } = found\n const local = block.empty\n ? 0\n : block.paragraph.getLineNumberAt(index - block.start + block.lead)\n const isLast = order === this.lineOffsets.length - 1\n if (local < 0) {\n if (isLast) return local\n return this.lineOffsets[order] + block.paragraph.getLineMetrics().length - 1\n }\n return this.lineOffsets[order] + local\n }\n\n getGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity {\n const visible = this.visibleBlocks()\n let block = visible.at(-1)\n for (const [index, candidate] of visible.entries()) {\n const next = visible.at(index + 1)\n const bottom = candidate.y + this.blockHeight(candidate)\n if (!next || y < bottom + next.spaceBefore / 2) {\n block = candidate\n break\n }\n }\n if (!block) return { pos: 0, affinity: this.ck.Affinity.Downstream }\n const local = block.paragraph.getGlyphPositionAtCoordinate(\n x - block.x,\n this.paragraphY(block, y - block.y)\n )\n return {\n pos: block.empty ? block.start : this.toTextIndex(block, local.pos),\n affinity: local.affinity\n }\n }\n\n getRectsForRange(\n start: number,\n end: number,\n heightStyle: RectHeightStyle,\n widthStyle: RectWidthStyle\n ): RectWithDirection[] {\n const rects: RectWithDirection[] = []\n for (const block of this.visibleBlocks()) {\n if (block.empty) continue\n const from = Math.max(start, block.start)\n const to = Math.min(end, block.start + block.length)\n if (to <= from) continue\n const local = block.paragraph.getRectsForRange(\n from - block.start + block.lead,\n to - block.start + block.lead,\n heightStyle,\n widthStyle\n )\n for (const { rect, dir } of local) {\n const y = block.y + this.offsetAt(block, (rect[1] + rect[3]) / 2)\n rects.push({\n rect: Float32Array.of(rect[0] + block.x, rect[1] + y, rect[2] + block.x, rect[3] + y),\n dir\n })\n }\n }\n return rects\n }\n\n /**\n * Where the caret stands before text index `index`: at the start edge of the character\n * there, or after the last character of its paragraph.\n */\n getCaretRect(index: number, rtl: boolean): TextCaretBox | null {\n const found = this.blockAt(index)\n if (!found) return null\n const { block } = found\n const local = index - block.start\n const first = block.paragraph.getLineMetrics().at(0)\n if (block.empty || block.length === 0) {\n if (!first) return null\n const top = block.y + first.baseline - first.ascent\n // The caret stands where typing starts: after a first-line indent.\n return {\n x: block.x + first.left + (rtl ? first.width - block.leadWidth : block.leadWidth),\n top,\n bottom: top + first.height\n }\n }\n const after = this.caretAfterLineBreak(block, local)\n if (after) return after\n let lo = local\n let hi = local + 1\n let useRight = false\n if (local <= 0) {\n lo = 0\n hi = 1\n useRight = rtl\n } else if (local >= block.length) {\n lo = block.length - 1\n hi = block.length\n useRight = !rtl\n }\n // The box of the whole character beside the caret: half an emoji or a surrogate pair has none.\n const cluster = block.paragraph.getGlyphInfoAt(lo + block.lead)?.graphemeClusterTextRange\n const rects = block.paragraph.getRectsForRange(\n cluster?.start ?? lo + block.lead,\n cluster?.end ?? hi + block.lead,\n this.ck.RectHeightStyle.Max,\n this.ck.RectWidthStyle.Tight\n )\n const rect = rects.at(0)?.rect\n if (!rect) return null\n const y = block.y + this.offsetAt(block, (rect[1] + rect[3]) / 2)\n return {\n x: block.x + (useRight ? rect[2] : rect[0]),\n top: y + rect[1],\n bottom: y + rect[3]\n }\n }\n\n /**\n * The caret after a line break that ends the paragraph: at the start of the empty line Skia\n * lays out below it, where typing goes, not after the break on the line above.\n */\n private caretAfterLineBreak(block: TextLayoutBlock, local: number): TextCaretBox | null {\n if (local < block.length) return null\n const lines = block.paragraph.getLineMetrics()\n const last = lines.at(-1)\n const previous = lines.at(-2)\n if (!last || !previous?.isHardBreak || last.endIndex > previous.endIncludingNewline) return null\n const lineTop = last.baseline - last.ascent\n const y = block.y + this.offsetAt(block, lineTop + last.height / 2)\n return { x: block.x + last.left, top: y + lineTop, bottom: y + lineTop + last.height }\n }\n\n /**\n * Shaped lines of the text in whole-text coordinates, one per line; run offsets are UTF-8\n * byte offsets into the whole text, as CanvasKit gives them. An empty line, which shaping\n * leaves out, has no runs and starts where the line before it ends.\n */\n getShapedLines(): ShapedLine[] {\n const shaped: ShapedLine[] = []\n for (const block of this.visibleBlocks()) {\n const metrics = block.paragraph.getLineMetrics()\n for (const [lineIndex, line] of shapedLinesByLine(block.paragraph).entries()) {\n const y = block.y + this.lineOffset(block, lineIndex)\n if (!line) {\n const { baseline, ascent, descent } = metrics[lineIndex]\n const previous = lineIndex > 0 ? shaped.at(-1) : undefined\n const start = previous?.textRange.last ?? block.utf8Start\n shaped.push({\n textRange: { first: start, last: start },\n top: baseline - ascent + y,\n bottom: baseline + descent + y,\n baseline: baseline + y,\n runs: []\n })\n continue\n }\n shaped.push({\n textRange: {\n first: this.toUtf8(block, line.textRange.first),\n last: this.toUtf8(block, line.textRange.last)\n },\n top: line.top + y,\n bottom: line.bottom + y,\n baseline: line.baseline + y,\n runs: block.empty\n ? []\n : line.runs.map((run) => ({\n ...run,\n positions: run.positions.map(\n (value, index) => value + (index % 2 === 0 ? block.x : y)\n ),\n offsets: run.offsets.map((offset) => this.toUtf8(block, offset))\n }))\n })\n }\n }\n return shaped\n }\n\n private toUtf8(block: TextLayoutBlock, offset: number): number {\n return block.empty ? block.utf8Start : block.utf8Start + Math.max(0, offset - block.utf8Lead)\n }\n\n /** Markers of the visible list items, where layout placed them. */\n getMarkers(): TextLayoutMarker[] {\n const markers: TextLayoutMarker[] = []\n for (const block of this.visibleBlocks()) if (block.marker) markers.push(block.marker)\n return markers\n }\n\n draw(canvas: Canvas, x: number, y: number): void {\n for (const block of this.visibleBlocks()) {\n const pieces = this.placements.get(block)?.pieces\n if (!pieces) canvas.drawParagraph(block.paragraph, x + block.x, y + block.y)\n for (const piece of pieces ?? []) {\n canvas.drawParagraph(piece.paragraph, x + block.x + piece.x, y + block.y + piece.y)\n }\n const marker = block.marker\n if (marker) canvas.drawParagraph(marker.paragraph, x + marker.x, y + marker.y)\n }\n }\n\n /** Where in the block's paragraph a point `y` below the block's top falls, by its line. */\n private paragraphY(block: TextLayoutBlock, y: number): number {\n const placement = this.placements.get(block)\n if (!placement) return y\n const lines = block.paragraph.getLineMetrics()\n // A point belongs to the line whose box it is in, or the nearest after the one above it.\n const index = lines.findIndex((line, lineIndex) => {\n const box = placement.boxes[lineIndex]\n const baseline = line.baseline + placement.offsets[lineIndex]\n return y < baseline - box.ascent + box.height\n })\n const line = lines[index === -1 ? lines.length - 1 : index]\n return line.baseline\n }\n\n isDeleted(): boolean {\n return this.blocks.every((block) => block.paragraph.isDeleted())\n }\n\n delete(): void {\n this.clearPlacements()\n for (const block of this.blocks) {\n block.paragraph.delete()\n block.marker?.parag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index.ts"],"sourcesContent":["import type {\n Canvas,\n CanvasKit,\n LineMetrics,\n Paragraph,\n PositionWithAffinity,\n RectHeightStyle,\n RectWidthStyle,\n RectWithDirection,\n ShapedLine\n} from 'canvaskit-wasm'\n\nimport {\n placeLines,\n shapedLinesByLine,\n type BlockPlacement,\n type TextLayoutBlockLines\n} from '#core/canvas/text/layout/lines'\n\n/** A list item's number or bullet, laid out on its own. */\nexport interface TextLayoutMarker {\n paragraph: Paragraph\n kind: 'bullet' | 'number'\n /** Font size of the list's first character, which sets the marker's distance from the text. */\n em: number\n /** The face the marker is set in, for its glyph outlines. */\n face: { family: string; style: string }\n /** Where the marker is drawn and the line of the item it marks, set by layout. */\n x: number\n y: number\n lineNumber: number\n}\n\n/** One paragraph of the text, or the whole text when it needs no paragraph layout of its own. */\nexport interface TextLayoutBlock {\n paragraph: Paragraph\n /** Rebuilds the paragraph to show at most `maxLines` lines, when the text is truncated. */\n rebuild?: (maxLines: number) => Paragraph\n /** The first character the block holds, as an index into the text and in UTF-8 bytes. */\n start: number\n utf8Start: number\n /** Characters the block holds, not counting the newline that ends it. */\n length: number\n /** Indices before the text, in UTF-16 and UTF-8, and its width: a first-line indent. */\n lead: number\n utf8Lead: number\n leadWidth: number\n /** Laid out from a space, standing for a paragraph with no characters. */\n empty: boolean\n /** Distance of the text from the start edge: a list item's indent. */\n inset: number\n rtl: boolean\n /** Space above the block, from the paragraph before it. */\n spaceBefore: number\n marker: TextLayoutMarker | null\n /** What placing its lines as Figma does needs; without it they stack as the paragraph's. */\n lines?: TextLayoutBlockLines\n x: number\n y: number\n /** Whether the block is shown, as truncation hides blocks past its last line. */\n visible: boolean\n}\n\nexport interface TextCaretBox {\n x: number\n top: number\n bottom: number\n}\n\n/**\n * A laid-out text node: one native paragraph per block, stacked with paragraph and list\n * spacing, each indented by its list level and preceded by its marker. It answers the\n * `Paragraph` queries the renderer, measurement, and the text editor ask, in indices of the\n * whole text and coordinates of the whole layout.\n */\nexport class TextLayout {\n private lines: LineMetrics[] = []\n private lineOffsets: number[] = []\n private truncated = false\n private readonly placements = new Map<TextLayoutBlock, BlockPlacement>()\n /** The text's height when layout placed its lines itself. */\n private placedHeight: number | null = null\n\n /** Text laid out as one native paragraph of `length` characters, not yet laid out. */\n static ofParagraph(\n ck: CanvasKit,\n paragraph: Paragraph,\n length: number,\n lines?: TextLayoutBlockLines\n ): TextLayout {\n return new TextLayout(ck, [\n {\n paragraph,\n start: 0,\n utf8Start: 0,\n length,\n lead: 0,\n utf8Lead: 0,\n leadWidth: 0,\n empty: false,\n inset: 0,\n rtl: false,\n spaceBefore: 0,\n marker: null,\n lines,\n x: 0,\n y: 0,\n visible: true\n }\n ])\n }\n\n constructor(\n private readonly ck: CanvasKit,\n readonly blocks: TextLayoutBlock[],\n /** Lines the text may show in all, when it is truncated across blocks. */\n private readonly maxLines?: number\n ) {}\n\n /** The line cap a block's paragraph was rebuilt with, when it differs from `maxLines`. */\n private readonly caps = new Map<TextLayoutBlock, number>()\n\n private visibleBlocks(): TextLayoutBlock[] {\n return this.blocks.filter((block) => block.visible)\n }\n\n layout(width: number): void {\n let y = 0\n let lines = 0\n this.truncated = false\n this.clearPlacements()\n for (const [index, block] of this.blocks.entries()) {\n const remaining = this.maxLines === undefined ? Infinity : this.maxLines - lines\n block.visible = remaining > 0\n if (!block.visible) {\n this.truncated = true\n continue\n }\n block.paragraph.layout(Math.max(1, width - block.inset))\n // A block capped for a narrower layout gets its lines back when there is room for them.\n const cap = this.caps.get(block) ?? this.maxLines ?? Infinity\n const overflows = block.paragraph.getLineMetrics().length > remaining\n const clipped = cap < remaining && block.paragraph.didExceedMaxLines()\n if ((overflows || clipped) && block.rebuild) {\n block.paragraph.delete()\n block.paragraph = block.rebuild(remaining)\n this.caps.set(block, remaining)\n block.paragraph.layout(Math.max(1, width - block.inset))\n }\n if (block.paragraph.didExceedMaxLines()) this.truncated = true\n if (index > 0) y += block.spaceBefore\n block.x = block.rtl ? 0 : block.inset\n block.y = y\n y += block.paragraph.getHeight()\n lines += block.paragraph.getLineMetrics().length\n }\n this.placeLines(width)\n for (const block of this.visibleBlocks()) this.placeMarker(block)\n this.collectLines()\n }\n\n private clearPlacements(): void {\n for (const placement of this.placements.values()) {\n for (const piece of placement.pieces ?? []) piece.paragraph.delete()\n }\n this.placements.clear()\n this.placedHeight = null\n }\n\n /**\n * Places lines as Figma does when they differ in height, keeping the paragraph's placement\n * otherwise (`placeLines`).\n */\n private placeLines(width: number): void {\n const placed = placeLines(this.ck, this.visibleBlocks(), width)\n if (!placed) return\n for (const [block, { y, ...placement }] of placed.blocks) {\n block.y = y\n this.placements.set(block, placement)\n }\n this.placedHeight = placed.height\n }\n\n /** The block's line `index` stands this far below where its paragraph has it. */\n private lineOffset(block: TextLayoutBlock, index: number): number {\n return this.placements.get(block)?.offsets[index] ?? 0\n }\n\n /** How far a point `y` of the block's paragraph moves, by the line it falls on. */\n private offsetAt(block: TextLayoutBlock, y: number): number {\n const placement = this.placements.get(block)\n if (!placement) return 0\n const lines = block.paragraph.getLineMetrics()\n const index = lines.findIndex((line) => y < line.baseline + line.descent)\n return placement.offsets[index === -1 ? lines.length - 1 : index] ?? 0\n }\n\n private blockHeight(block: TextLayoutBlock): number {\n return this.placements.get(block)?.height ?? block.paragraph.getHeight()\n }\n\n private placeMarker(block: TextLayoutBlock): void {\n const marker = block.marker\n const first = block.paragraph.getLineMetrics().at(0)\n if (!marker || !first) return\n const markerLine = marker.paragraph.getLineMetrics().at(0)\n const width = marker.paragraph.getLongestLine()\n // A bullet centres on the middle of the indent; a number ends a third of an em before the\n // text, so numbers of any width line up on their periods.\n if (block.rtl) {\n const start = block.x + first.left + first.width\n marker.x =\n marker.kind === 'bullet' ? start + marker.em * 0.75 - width / 2 : start + marker.em / 3\n } else {\n const start = block.x + first.left\n marker.x =\n marker.kind === 'bullet'\n ? start - marker.em * 0.75 - width / 2\n : start - marker.em / 3 - width\n }\n marker.y = block.y + first.baseline - (markerLine?.baseline ?? 0)\n }\n\n private toTextIndex(block: TextLayoutBlock, index: number): number {\n return block.start + Math.max(0, Math.min(block.length, index - block.lead))\n }\n\n private collectLines(): void {\n this.lines = []\n this.lineOffsets = []\n const visible = this.visibleBlocks()\n for (const [blockIndex, block] of visible.entries()) {\n this.lineOffsets.push(this.lines.length)\n if (block.marker) block.marker.lineNumber = this.lines.length\n const metrics = block.paragraph.getLineMetrics()\n const boxes = this.placements.get(block)?.boxes\n const blockEnd = block.start + block.length\n // Skia starts the empty line after a closing line break at that break; a line starts where\n // the one before it ends, its line break included.\n let previousEnd = block.start\n for (const [lineIndex, line] of metrics.entries()) {\n const lastOfBlock = lineIndex === metrics.length - 1\n const endsAtNewline = lastOfBlock && blockIndex < visible.length - 1\n // A first-line indent is room before the text, not part of the line.\n const indent = lineIndex === 0 ? block.leadWidth : 0\n const box = boxes?.[lineIndex]\n const startIndex = Math.max(previousEnd, this.toTextIndex(block, line.startIndex))\n const endIncludingNewline = endsAtNewline\n ? blockEnd + 1\n : this.toTextIndex(block, line.endIncludingNewline)\n previousEnd = endIncludingNewline\n this.lines.push({\n ...line,\n ...(box && {\n ascent: box.ascent,\n descent: box.height - box.ascent,\n height: box.height\n }),\n startIndex,\n endIndex: Math.max(startIndex, this.toTextIndex(block, line.endIndex)),\n endExcludingWhitespaces: Math.max(\n startIndex,\n this.toTextIndex(block, line.endExcludingWhitespaces)\n ),\n endIncludingNewline,\n isHardBreak: endsAtNewline || line.isHardBreak,\n width: block.empty ? 0 : line.width - indent,\n left: line.left + block.x + (block.rtl ? 0 : indent),\n baseline: line.baseline + block.y + this.lineOffset(block, lineIndex),\n lineNumber: this.lines.length\n })\n }\n }\n }\n\n getHeight(): number {\n const last = this.visibleBlocks().at(-1)\n if (this.placedHeight !== null) return this.placedHeight\n return last ? last.y + last.paragraph.getHeight() : 0\n }\n\n getLongestLine(): number {\n let longest = 0\n for (const block of this.visibleBlocks()) {\n if (block.empty) continue\n longest = Math.max(longest, block.inset + block.paragraph.getLongestLine())\n }\n return longest\n }\n\n didExceedMaxLines(): boolean {\n return this.truncated\n }\n\n getLineMetrics(): LineMetrics[] {\n return this.lines\n }\n\n getLineMetricsAt(lineNumber: number): LineMetrics | null {\n return this.lines[lineNumber] ?? null\n }\n\n /** The block holding text index `index`; the newline ending a block belongs to it. */\n private blockAt(index: number): { block: TextLayoutBlock; order: number } | null {\n const visible = this.visibleBlocks()\n for (const [order, block] of visible.entries()) {\n if (index <= block.start + block.length) return { block, order }\n }\n const last = visible.at(-1)\n return last ? { block: last, order: visible.length - 1 } : null\n }\n\n getLineNumberAt(index: number): number {\n const found = this.blockAt(index)\n if (!found) return -1\n const { block, order } = found\n const local = block.empty\n ? 0\n : block.paragraph.getLineNumberAt(index - block.start + block.lead)\n const isLast = order === this.lineOffsets.length - 1\n if (local < 0) {\n if (isLast) return local\n return this.lineOffsets[order] + block.paragraph.getLineMetrics().length - 1\n }\n return this.lineOffsets[order] + local\n }\n\n getGlyphPositionAtCoordinate(x: number, y: number): PositionWithAffinity {\n const visible = this.visibleBlocks()\n let block = visible.at(-1)\n for (const [index, candidate] of visible.entries()) {\n const next = visible.at(index + 1)\n const bottom = candidate.y + this.blockHeight(candidate)\n if (!next || y < bottom + next.spaceBefore / 2) {\n block = candidate\n break\n }\n }\n if (!block) return { pos: 0, affinity: this.ck.Affinity.Downstream }\n const local = block.paragraph.getGlyphPositionAtCoordinate(\n x - block.x,\n this.paragraphY(block, y - block.y)\n )\n return {\n pos: block.empty ? block.start : this.toTextIndex(block, local.pos),\n affinity: local.affinity\n }\n }\n\n getRectsForRange(\n start: number,\n end: number,\n heightStyle: RectHeightStyle,\n widthStyle: RectWidthStyle\n ): RectWithDirection[] {\n const rects: RectWithDirection[] = []\n for (const block of this.visibleBlocks()) {\n if (block.empty) continue\n const from = Math.max(start, block.start)\n const to = Math.min(end, block.start + block.length)\n if (to <= from) continue\n const local = block.paragraph.getRectsForRange(\n from - block.start + block.lead,\n to - block.start + block.lead,\n heightStyle,\n widthStyle\n )\n for (const { rect, dir } of local) {\n const y = block.y + this.offsetAt(block, (rect[1] + rect[3]) / 2)\n rects.push({\n rect: Float32Array.of(rect[0] + block.x, rect[1] + y, rect[2] + block.x, rect[3] + y),\n dir\n })\n }\n }\n return rects\n }\n\n /**\n * Where the caret stands before text index `index`: at the start edge of the character\n * there, or after the last character of its paragraph.\n */\n getCaretRect(index: number, rtl: boolean): TextCaretBox | null {\n const found = this.blockAt(index)\n if (!found) return null\n const { block } = found\n const local = index - block.start\n const first = block.paragraph.getLineMetrics().at(0)\n if (block.empty || block.length === 0) {\n if (!first) return null\n const top = block.y + first.baseline - first.ascent\n // The caret stands where typing starts: after a first-line indent.\n return {\n x: block.x + first.left + (rtl ? first.width - block.leadWidth : block.leadWidth),\n top,\n bottom: top + first.height\n }\n }\n const after = this.caretAfterLineBreak(block, local)\n if (after) return after\n let lo = local\n let hi = local + 1\n let useRight = false\n if (local <= 0) {\n lo = 0\n hi = 1\n useRight = rtl\n } else if (local >= block.length) {\n lo = block.length - 1\n hi = block.length\n useRight = !rtl\n }\n // The box of the whole character beside the caret: half an emoji or a surrogate pair has none.\n const cluster = block.paragraph.getGlyphInfoAt(lo + block.lead)?.graphemeClusterTextRange\n const rects = block.paragraph.getRectsForRange(\n cluster?.start ?? lo + block.lead,\n cluster?.end ?? hi + block.lead,\n this.ck.RectHeightStyle.Max,\n this.ck.RectWidthStyle.Tight\n )\n const rect = rects.at(0)?.rect\n if (!rect) return null\n const y = block.y + this.offsetAt(block, (rect[1] + rect[3]) / 2)\n return {\n x: block.x + (useRight ? rect[2] : rect[0]),\n top: y + rect[1],\n bottom: y + rect[3]\n }\n }\n\n /**\n * The caret after a line break that ends the paragraph: at the start of the empty line Skia\n * lays out below it, where typing goes, not after the break on the line above.\n */\n private caretAfterLineBreak(block: TextLayoutBlock, local: number): TextCaretBox | null {\n if (local < block.length) return null\n const lines = block.paragraph.getLineMetrics()\n const last = lines.at(-1)\n const previous = lines.at(-2)\n if (!last || !previous?.isHardBreak || last.endIndex > previous.endIncludingNewline) return null\n const lineTop = last.baseline - last.ascent\n const y = block.y + this.offsetAt(block, lineTop + last.height / 2)\n return { x: block.x + last.left, top: y + lineTop, bottom: y + lineTop + last.height }\n }\n\n /**\n * Shaped lines of the text in whole-text coordinates, one per line; run offsets are UTF-8\n * byte offsets into the whole text, as CanvasKit gives them. An empty line, which shaping\n * leaves out, has no runs and starts where the line before it ends.\n */\n getShapedLines(): ShapedLine[] {\n const shaped: ShapedLine[] = []\n for (const block of this.visibleBlocks()) {\n const metrics = block.paragraph.getLineMetrics()\n for (const [lineIndex, line] of shapedLinesByLine(block.paragraph).entries()) {\n const y = block.y + this.lineOffset(block, lineIndex)\n if (!line) {\n const { baseline, ascent, descent } = metrics[lineIndex]\n const previous = lineIndex > 0 ? shaped.at(-1) : undefined\n const start = previous?.textRange.last ?? block.utf8Start\n shaped.push({\n textRange: { first: start, last: start },\n top: baseline - ascent + y,\n bottom: baseline + descent + y,\n baseline: baseline + y,\n runs: []\n })\n continue\n }\n shaped.push({\n textRange: {\n first: this.toUtf8(block, line.textRange.first),\n last: this.toUtf8(block, line.textRange.last)\n },\n top: line.top + y,\n bottom: line.bottom + y,\n baseline: line.baseline + y,\n runs: block.empty\n ? []\n : line.runs.map((run) => ({\n ...run,\n positions: run.positions.map(\n (value, index) => value + (index % 2 === 0 ? block.x : y)\n ),\n offsets: run.offsets.map((offset) => this.toUtf8(block, offset))\n }))\n })\n }\n }\n return shaped\n }\n\n private toUtf8(block: TextLayoutBlock, offset: number): number {\n return block.empty ? block.utf8Start : block.utf8Start + Math.max(0, offset - block.utf8Lead)\n }\n\n /** Markers of the visible list items, where layout placed them. */\n getMarkers(): TextLayoutMarker[] {\n const markers: TextLayoutMarker[] = []\n for (const block of this.visibleBlocks()) if (block.marker) markers.push(block.marker)\n return markers\n }\n\n draw(canvas: Canvas, x: number, y: number): void {\n for (const block of this.visibleBlocks()) {\n const pieces = this.placements.get(block)?.pieces\n if (!pieces) canvas.drawParagraph(block.paragraph, x + block.x, y + block.y)\n for (const piece of pieces ?? []) {\n canvas.drawParagraph(piece.paragraph, x + block.x + piece.x, y + block.y + piece.y)\n }\n const marker = block.marker\n if (marker) canvas.drawParagraph(marker.paragraph, x + marker.x, y + marker.y)\n }\n }\n\n /** Where in the block's paragraph a point `y` below the block's top falls, by its line. */\n private paragraphY(block: TextLayoutBlock, y: number): number {\n const placement = this.placements.get(block)\n if (!placement) return y\n const lines = block.paragraph.getLineMetrics()\n // A point belongs to the line whose box it is in, or the nearest after the one above it.\n const index = lines.findIndex((line, lineIndex) => {\n const box = placement.boxes[lineIndex]\n const baseline = line.baseline + placement.offsets[lineIndex]\n return y < baseline - box.ascent + box.height\n })\n const line = lines[index === -1 ? lines.length - 1 : index]\n return line.baseline\n }\n\n isDeleted(): boolean {\n return this.blocks.every((block) => block.paragraph.isDeleted())\n }\n\n delete(): void {\n this.clearPlacements()\n for (const block of this.blocks) {\n block.paragraph.delete()\n block.marker?.paragraph.delete()\n }\n }\n}\n"],"mappings":";;;;;;;;AA2EA,IAAa,aAAb,MAAa,WAAW;CAsCH;CACR;CAEQ;CAxCnB,QAA+B,CAAC;CAChC,cAAgC,CAAC;CACjC,YAAoB;CACpB,6BAA8B,IAAI,IAAqC;;CAEvE,eAAsC;;CAGtC,OAAO,YACL,IACA,WACA,QACA,OACY;EACZ,OAAO,IAAI,WAAW,IAAI,CACxB;GACE;GACA,OAAO;GACP,WAAW;GACX;GACA,MAAM;GACN,UAAU;GACV,WAAW;GACX,OAAO;GACP,OAAO;GACP,KAAK;GACL,aAAa;GACb,QAAQ;GACR;GACA,GAAG;GACH,GAAG;GACH,SAAS;EACX,CACF,CAAC;CACH;CAEA,YACE,IACA,QAEA,UACA;EAJiB,KAAA,KAAA;EACR,KAAA,SAAA;EAEQ,KAAA,WAAA;CAChB;;CAGH,uBAAwB,IAAI,IAA6B;CAEzD,gBAA2C;EACzC,OAAO,KAAK,OAAO,QAAQ,UAAU,MAAM,OAAO;CACpD;CAEA,OAAO,OAAqB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I,QAAQ,OAAO,cAAc,OAAO,WAAW,IAAI,OAAO,GAAG,IAAI,OAAO,CAAC;EAC/E;CACF;;CAGA,WAAmB,OAAwB,GAAmB;EAC5D,MAAM,YAAY,KAAK,WAAW,IAAI,KAAK;EAC3C,IAAI,CAAC,WAAW,OAAO;EACvB,MAAM,QAAQ,MAAM,UAAU,eAAe;EAE7C,MAAM,QAAQ,MAAM,WAAW,MAAM,cAAc;GACjD,MAAM,MAAM,UAAU,MAAM;GAE5B,OAAO,IADU,KAAK,WAAW,UAAU,QAAQ,aAC7B,IAAI,SAAS,IAAI;EACzC,CAAC;EAED,OADa,MAAM,UAAU,KAAK,MAAM,SAAS,IAAI,MAC1C,CAAC;CACd;CAEA,YAAqB;EACnB,OAAO,KAAK,OAAO,OAAO,UAAU,MAAM,UAAU,UAAU,CAAC;CACjE;CAEA,SAAe;EACb,KAAK,gBAAgB;EACrB,KAAK,MAAM,SAAS,KAAK,QAAQ;GAC/B,MAAM,UAAU,OAAO;GACvB,MAAM,QAAQ,UAAU,OAAO;EACjC;CACF;AACF"}
@@ -33,7 +33,7 @@ function figmaLineBox(ck, paragraph, line, runs, lines = paragraph.getLineMetric
33
33
  for (const { rect } of rects) {
34
34
  const runNatural = metric(rect[3] - rect[1]);
35
35
  if (runNatural <= 0) continue;
36
- height = Math.max(height, Math.round(run.lineHeight ?? runNatural));
36
+ height = Math.max(height, run.lineHeight ?? Math.round(runNatural));
37
37
  if (runNatural > natural) {
38
38
  natural = runNatural;
39
39
  ascent = metric(lineAt(lines, (rect[1] + rect[3]) / 2, line).baseline - rect[1]);
@@ -165,13 +165,15 @@ function placeLines(ck, blocks, width) {
165
165
  const boxes = lineBoxes(ck, blocks, metrics);
166
166
  if (!boxes) return null;
167
167
  const all = boxes.flat();
168
- if (allSame(all.map((box) => box.height)) && allSame(all.map((box) => box.ascent))) return null;
168
+ const height = all[0].height;
169
+ if (allSame(all.map((box) => box.height)) && allSame(all.map((box) => box.ascent)) && allSame([height, Math.round(height)])) return null;
169
170
  const first = all[0];
170
171
  const last = all[all.length - 1];
172
+ const start = Math.round(first.ascent);
171
173
  let below = 0;
172
174
  const baselines = blocks.map((block, index) => boxes[index].map((box, line) => {
173
175
  if (index > 0 || line > 0) below += box.height + (line === 0 ? block.spaceBefore : 0);
174
- return first.ascent + below;
176
+ return first.ascent + Math.round(first.ascent + below) - start;
175
177
  }));
176
178
  const placed = /* @__PURE__ */ new Map();
177
179
  for (const [index, block] of blocks.entries()) {
@@ -1 +1 @@
1
- {"version":3,"file":"lines.js","names":[],"sources":["../../../../src/canvas/text/layout/lines.ts"],"sourcesContent":["import type { CanvasKit, LineMetrics, Paragraph, ShapedLine } from 'canvaskit-wasm'\n\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\n/** A stretch of a paragraph's characters set at one line height, `null` for auto. */\nexport interface LineHeightRun {\n start: number\n end: number\n lineHeight: number | null\n}\n\n/** A block's line heights, and how to lay one of its lines out on its own. */\nexport interface TextLayoutBlockLines {\n /** Line heights by paragraph index, lead included. */\n heights: LineHeightRun[]\n /**\n * The paragraph's characters from `start` as a paragraph of their own, holding its `lines`\n * lines up to `end`, and ending in the ellipsis when `truncated`; absent when lines cannot\n * be drawn apart from the others.\n */\n build?: (start: number, end: number, lines: number, truncated: boolean) => Paragraph\n}\n\n/** What placing a text layout block's lines reads of it. */\ninterface LineBlock {\n paragraph: Paragraph\n lines?: TextLayoutBlockLines\n lead: number\n length: number\n inset: number\n spaceBefore: number\n y: number\n}\n\n/** Lines laid out as a paragraph of their own, and where its top left goes in its block. */\nexport interface LinePiece {\n paragraph: Paragraph\n x: number\n y: number\n}\n\n/** Where a block's lines go when they do not stack as its paragraph has them. */\nexport interface BlockPlacement {\n height: number\n /** How far each line stands below where the paragraph has it. */\n offsets: number[]\n boxes: LineBox[]\n /** Paragraphs of lines that move together, drawn in place of the block's when lines move apart. */\n pieces: LinePiece[] | null\n}\n\n/** A line as Figma sets it: its height, and how far its baseline stands below its top. */\nexport interface LineBox {\n height: number\n ascent: number\n}\n\n/** The difference below which two line positions count as the same. */\nconst LINE_EPSILON = 0.01\n/**\n * Steps font metrics are measured in. Rects come in float32, whose error at a line far down a\n * text reaches the sixth digit, so lines in the same font would measure apart.\n */\nconst METRIC_STEPS = 1e4\n\nfunction metric(value: number): number {\n return Math.round(value * METRIC_STEPS) / METRIC_STEPS\n}\n\n/**\n * A line's box as Figma sets it. The line is as tall as the tallest line height on it, auto\n * standing for a font's own height rounded to a whole pixel, and its baseline sits where its\n * tallest font, centred in that height, puts it. Fonts' heights are the shaped runs' own, so a\n * fallback font counts with its metrics. Returns `null` for a line with nothing to measure.\n */\n/** The line a point `y` of the paragraph falls on, or `fallback` past them all. */\nfunction lineAt(lines: readonly LineMetrics[], y: number, fallback: LineMetrics): LineMetrics {\n return lines.find((line) => y < line.baseline + line.descent) ?? fallback\n}\n\nexport function figmaLineBox(\n ck: CanvasKit,\n paragraph: Paragraph,\n line: LineMetrics,\n runs: readonly LineHeightRun[],\n lines: readonly LineMetrics[] = paragraph.getLineMetrics()\n): LineBox | null {\n // An empty line is as tall as the newline that makes it.\n const start = line.startIndex\n const end = Math.max(line.endIndex, start + 1)\n let height = 0\n let natural = 0\n let ascent = 0\n for (const run of runs) {\n const from = Math.max(start, run.start)\n const to = Math.min(end, run.end)\n if (to <= from) continue\n const rects = paragraph.getRectsForRange(\n from,\n to,\n ck.RectHeightStyle.Tight,\n ck.RectWidthStyle.Tight\n )\n for (const { rect } of rects) {\n const runNatural = metric(rect[3] - rect[1])\n // A first-line indent is a placeholder with no height.\n if (runNatural <= 0) continue\n height = Math.max(height, Math.round(run.lineHeight ?? runNatural))\n if (runNatural > natural) {\n natural = runNatural\n // The newline that makes an empty line stands on the line above, so its box is\n // measured from the baseline of the line it stands on.\n ascent = metric(lineAt(lines, (rect[1] + rect[3]) / 2, line).baseline - rect[1])\n }\n }\n }\n if (natural === 0) return null\n return { height, ascent: (height - natural) / 2 + ascent }\n}\n\n/** Whether all `values` are the same, to within the precision lines are placed with. */\nexport function allSame(values: readonly number[]): boolean {\n const first = values.at(0)\n return first === undefined || values.every((value) => Math.abs(value - first) < LINE_EPSILON)\n}\n\n/** Each block's lines as Figma sets them, or `null` when one cannot be measured. */\nfunction lineBoxes(\n ck: CanvasKit,\n blocks: readonly LineBlock[],\n metrics: readonly LineMetrics[][]\n): LineBox[][] | null {\n const boxes: LineBox[][] = []\n for (const [index, block] of blocks.entries()) {\n const heights = block.lines?.heights\n if (!heights) return null\n const blockBoxes: LineBox[] = []\n for (const line of metrics[index]) {\n const box = figmaLineBox(ck, block.paragraph, line, heights, metrics[index])\n if (!box) return null\n blockBoxes.push(box)\n }\n boxes.push(blockBoxes)\n }\n return boxes\n}\n\n/**\n * A paragraph's shaped lines by line number. Shaping leaves empty lines out, so each shaped\n * line goes to the line whose baseline is nearest its own.\n */\nexport function shapedLinesByLine(paragraph: Paragraph): Array<ShapedLine | undefined> {\n const lines = paragraph.getLineMetrics()\n const byLine: Array<ShapedLine | undefined> = Array.from({ length: lines.length })\n for (const shaped of paragraph.getShapedLines()) {\n let nearest = 0\n for (const [index, line] of lines.entries()) {\n const distance = Math.abs(line.baseline - shaped.baseline)\n if (distance < Math.abs(lines[nearest].baseline - shaped.baseline)) nearest = index\n }\n byLine[nearest] = shaped\n }\n return byLine\n}\n\n/** Where a shaped line's first glyph stands, if it has one. */\nfunction firstGlyph(line: ShapedLine | undefined): [number, number] | null {\n const positions = line?.runs.find((run) => run.glyphs.length > 0)?.positions\n return positions ? [positions[0], positions[1]] : null\n}\n\n/** How far glyphs a piece draws must move to land where the block's lines have them. */\nfunction pieceShift(\n shaped: ReadonlyArray<ShapedLine | undefined>,\n own: ReadonlyArray<ShapedLine | undefined>\n): (Vector & { agrees: number }) | null {\n let shift: Vector | null = null\n // Paragraphs snap each line to whole-pixel baselines their own way, so lines of one piece\n // may need different shifts; the piece holds the lines that agree with its first.\n for (const [index, line] of own.entries()) {\n const glyph = firstGlyph(shaped[index])\n const ownGlyph = firstGlyph(line)\n if (!glyph || !ownGlyph) continue\n const x = glyph[0] - ownGlyph[0]\n const y = glyph[1] - ownGlyph[1]\n if (!shift) shift = { x, y }\n else if (!allSame([shift.x, x]) || !allSame([shift.y, y])) return { ...shift, agrees: index }\n }\n return shift && { ...shift, agrees: own.length }\n}\n\n/**\n * The block's lines as paragraphs of their own, one for each run of lines that move by the\n * same offset, or one per line when not `grouped`, placed so their glyphs land where the\n * block's paragraph has them, moved by that offset. `null` when lines cannot be laid out\n * apart from the others.\n */\nfunction buildPieces(\n block: LineBlock,\n width: number,\n offsets: readonly number[],\n grouped = true\n): LinePiece[] | null {\n const build = block.lines?.build\n if (!build) return null\n const lines = block.paragraph.getLineMetrics()\n const shaped = shapedLinesByLine(block.paragraph)\n const truncated = block.paragraph.didExceedMaxLines()\n const textEnd = block.lead + block.length\n const pieces: LinePiece[] = []\n let from = 0\n while (from < lines.length) {\n let to = from + 1\n if (grouped) while (to < lines.length && allSame([offsets[from], offsets[to]])) to++\n const start = lines[from].startIndex\n const end = to === lines.length ? textEnd : lines[to - 1].endIndex\n // Empty lines draw nothing.\n if (end <= start) {\n from = to\n continue\n }\n const count = to - from\n const paragraph = build(start, end, count, to === lines.length && truncated)\n paragraph.layout(Math.max(1, width - block.inset))\n const own = paragraph.getLineMetrics().length === count ? shapedLinesByLine(paragraph) : null\n const shift = own && pieceShift(shaped.slice(from, to), own)\n if (!shift || shift.agrees < count) {\n paragraph.delete()\n for (const piece of pieces) piece.paragraph.delete()\n // Lines that lay out or snap apart are drawn one by one.\n return grouped ? buildPieces(block, width, offsets, false) : null\n }\n pieces.push({ paragraph, x: shift.x, y: shift.y + offsets[from] })\n from = to\n }\n return pieces\n}\n\n/** Where `placeLines` puts each block, and the text's height. */\nexport interface PlacedLines<Block> {\n blocks: Map<Block, BlockPlacement & { y: number }>\n height: number\n}\n\n/**\n * Lines of laid-out blocks placed as Figma places them when they differ in height: each\n * line is as tall as its tallest line height, and each baseline stands that far, plus the\n * paragraph's spacing, below the one before, where a paragraph would stack the lines' boxes.\n * `null` keeps the paragraphs' placement: for lines alike, where it is the same, and for\n * lines that cannot be measured or drawn apart.\n */\nexport function placeLines<Block extends LineBlock>(\n ck: CanvasKit,\n blocks: readonly Block[],\n width: number\n): PlacedLines<Block> | null {\n const metrics = blocks.map((block) => block.paragraph.getLineMetrics())\n // A single line has none to be spaced from.\n if (metrics.flat().length < 2) return null\n const boxes = lineBoxes(ck, blocks, metrics)\n if (!boxes) return null\n const all = boxes.flat()\n if (allSame(all.map((box) => box.height)) && allSame(all.map((box) => box.ascent))) return null\n\n // Distances from the first baseline add up whole-pixel line heights, so they stay exact.\n const first = all[0]\n const last = all[all.length - 1]\n let below = 0\n const baselines = blocks.map((block, index) =>\n boxes[index].map((box, line) => {\n if (index > 0 || line > 0) below += box.height + (line === 0 ? block.spaceBefore : 0)\n return first.ascent + below\n })\n )\n const placed = new Map<Block, BlockPlacement & { y: number }>()\n for (const [index, block] of blocks.entries()) {\n const lines = metrics[index]\n const blockBoxes = boxes[index]\n const blockBaselines = baselines[index]\n const end = blockBoxes.length - 1\n const y = blockBaselines[0] - lines[0].baseline\n const offsets = lines.map((line, lineIndex) => blockBaselines[lineIndex] - y - line.baseline)\n const apart = !allSame(offsets)\n const pieces = apart ? buildPieces(block, width, offsets) : null\n placed.set(block, {\n y,\n height: blockBaselines[end] - blockBoxes[end].ascent + blockBoxes[end].height - y,\n offsets,\n boxes: blockBoxes,\n pieces\n })\n // Lines that cannot be drawn apart keep the paragraph's placement, and so does the text.\n if (apart && !pieces) {\n for (const placement of placed.values()) {\n for (const piece of placement.pieces ?? []) piece.paragraph.delete()\n }\n return null\n }\n }\n return { blocks: placed, height: first.ascent - last.ascent + below + last.height }\n}\n"],"mappings":";;AA0DA,MAAM,eAAe;;;;;AAKrB,MAAM,eAAe;AAErB,SAAS,OAAO,OAAuB;CACrC,OAAO,KAAK,MAAM,QAAQ,YAAY,IAAI;AAC5C;;;;;;;;AASA,SAAS,OAAO,OAA+B,G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A,QAAQ,eAAe,OAAO,WAAW,IAAI,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS;GAChF;GACA,OAAO;GACP;EACF,CAAC;EAED,IAAI,SAAS,CAAC,QAAQ;GACpB,KAAK,MAAM,aAAa,OAAO,OAAO,GACpC,KAAK,MAAM,SAAS,UAAU,UAAU,CAAC,GAAG,MAAM,UAAU,OAAO;GAErE,OAAO;EACT;CACF;CACA,OAAO;EAAE,QAAQ;EAAQ,QAAQ,MAAM,SAAS,KAAK,SAAS,QAAQ,KAAK;CAAO;AACpF"}
1
+ {"version":3,"file":"lines.js","names":[],"sources":["../../../../src/canvas/text/layout/lines.ts"],"sourcesContent":["import type { CanvasKit, LineMetrics, Paragraph, ShapedLine } from 'canvaskit-wasm'\n\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\n/** A stretch of a paragraph's characters set at one line height, `null` for auto. */\nexport interface LineHeightRun {\n start: number\n end: number\n lineHeight: number | null\n}\n\n/** A block's line heights, and how to lay one of its lines out on its own. */\nexport interface TextLayoutBlockLines {\n /** Line heights by paragraph index, lead included. */\n heights: LineHeightRun[]\n /**\n * The paragraph's characters from `start` as a paragraph of their own, holding its `lines`\n * lines up to `end`, and ending in the ellipsis when `truncated`; absent when lines cannot\n * be drawn apart from the others.\n */\n build?: (start: number, end: number, lines: number, truncated: boolean) => Paragraph\n}\n\n/** What placing a text layout block's lines reads of it. */\ninterface LineBlock {\n paragraph: Paragraph\n lines?: TextLayoutBlockLines\n lead: number\n length: number\n inset: number\n spaceBefore: number\n y: number\n}\n\n/** Lines laid out as a paragraph of their own, and where its top left goes in its block. */\nexport interface LinePiece {\n paragraph: Paragraph\n x: number\n y: number\n}\n\n/** Where a block's lines go when they do not stack as its paragraph has them. */\nexport interface BlockPlacement {\n height: number\n /** How far each line stands below where the paragraph has it. */\n offsets: number[]\n boxes: LineBox[]\n /** Paragraphs of lines that move together, drawn in place of the block's when lines move apart. */\n pieces: LinePiece[] | null\n}\n\n/** A line as Figma sets it: its height, and how far its baseline stands below its top. */\nexport interface LineBox {\n height: number\n ascent: number\n}\n\n/** The difference below which two line positions count as the same. */\nconst LINE_EPSILON = 0.01\n/**\n * Steps font metrics are measured in. Rects come in float32, whose error at a line far down a\n * text reaches the sixth digit, so lines in the same font would measure apart.\n */\nconst METRIC_STEPS = 1e4\n\nfunction metric(value: number): number {\n return Math.round(value * METRIC_STEPS) / METRIC_STEPS\n}\n\n/**\n * A line's box as Figma sets it. The line is as tall as the tallest line height on it, auto\n * standing for a font's own height rounded to a whole pixel, and its baseline sits where its\n * tallest font, centred in that height, puts it. Fonts' heights are the shaped runs' own, so a\n * fallback font counts with its metrics. Returns `null` for a line with nothing to measure.\n */\n/** The line a point `y` of the paragraph falls on, or `fallback` past them all. */\nfunction lineAt(lines: readonly LineMetrics[], y: number, fallback: LineMetrics): LineMetrics {\n return lines.find((line) => y < line.baseline + line.descent) ?? fallback\n}\n\nexport function figmaLineBox(\n ck: CanvasKit,\n paragraph: Paragraph,\n line: LineMetrics,\n runs: readonly LineHeightRun[],\n lines: readonly LineMetrics[] = paragraph.getLineMetrics()\n): LineBox | null {\n // An empty line is as tall as the newline that makes it.\n const start = line.startIndex\n const end = Math.max(line.endIndex, start + 1)\n let height = 0\n let natural = 0\n let ascent = 0\n for (const run of runs) {\n const from = Math.max(start, run.start)\n const to = Math.min(end, run.end)\n if (to <= from) continue\n const rects = paragraph.getRectsForRange(\n from,\n to,\n ck.RectHeightStyle.Tight,\n ck.RectWidthStyle.Tight\n )\n for (const { rect } of rects) {\n const runNatural = metric(rect[3] - rect[1])\n // A first-line indent is a placeholder with no height.\n if (runNatural <= 0) continue\n height = Math.max(height, run.lineHeight ?? Math.round(runNatural))\n if (runNatural > natural) {\n natural = runNatural\n // The newline that makes an empty line stands on the line above, so its box is\n // measured from the baseline of the line it stands on.\n ascent = metric(lineAt(lines, (rect[1] + rect[3]) / 2, line).baseline - rect[1])\n }\n }\n }\n if (natural === 0) return null\n return { height, ascent: (height - natural) / 2 + ascent }\n}\n\n/** Whether all `values` are the same, to within the precision lines are placed with. */\nexport function allSame(values: readonly number[]): boolean {\n const first = values.at(0)\n return first === undefined || values.every((value) => Math.abs(value - first) < LINE_EPSILON)\n}\n\n/** Each block's lines as Figma sets them, or `null` when one cannot be measured. */\nfunction lineBoxes(\n ck: CanvasKit,\n blocks: readonly LineBlock[],\n metrics: readonly LineMetrics[][]\n): LineBox[][] | null {\n const boxes: LineBox[][] = []\n for (const [index, block] of blocks.entries()) {\n const heights = block.lines?.heights\n if (!heights) return null\n const blockBoxes: LineBox[] = []\n for (const line of metrics[index]) {\n const box = figmaLineBox(ck, block.paragraph, line, heights, metrics[index])\n if (!box) return null\n blockBoxes.push(box)\n }\n boxes.push(blockBoxes)\n }\n return boxes\n}\n\n/**\n * A paragraph's shaped lines by line number. Shaping leaves empty lines out, so each shaped\n * line goes to the line whose baseline is nearest its own.\n */\nexport function shapedLinesByLine(paragraph: Paragraph): Array<ShapedLine | undefined> {\n const lines = paragraph.getLineMetrics()\n const byLine: Array<ShapedLine | undefined> = Array.from({ length: lines.length })\n for (const shaped of paragraph.getShapedLines()) {\n let nearest = 0\n for (const [index, line] of lines.entries()) {\n const distance = Math.abs(line.baseline - shaped.baseline)\n if (distance < Math.abs(lines[nearest].baseline - shaped.baseline)) nearest = index\n }\n byLine[nearest] = shaped\n }\n return byLine\n}\n\n/** Where a shaped line's first glyph stands, if it has one. */\nfunction firstGlyph(line: ShapedLine | undefined): [number, number] | null {\n const positions = line?.runs.find((run) => run.glyphs.length > 0)?.positions\n return positions ? [positions[0], positions[1]] : null\n}\n\n/** How far glyphs a piece draws must move to land where the block's lines have them. */\nfunction pieceShift(\n shaped: ReadonlyArray<ShapedLine | undefined>,\n own: ReadonlyArray<ShapedLine | undefined>\n): (Vector & { agrees: number }) | null {\n let shift: Vector | null = null\n // Paragraphs snap each line to whole-pixel baselines their own way, so lines of one piece\n // may need different shifts; the piece holds the lines that agree with its first.\n for (const [index, line] of own.entries()) {\n const glyph = firstGlyph(shaped[index])\n const ownGlyph = firstGlyph(line)\n if (!glyph || !ownGlyph) continue\n const x = glyph[0] - ownGlyph[0]\n const y = glyph[1] - ownGlyph[1]\n if (!shift) shift = { x, y }\n else if (!allSame([shift.x, x]) || !allSame([shift.y, y])) return { ...shift, agrees: index }\n }\n return shift && { ...shift, agrees: own.length }\n}\n\n/**\n * The block's lines as paragraphs of their own, one for each run of lines that move by the\n * same offset, or one per line when not `grouped`, placed so their glyphs land where the\n * block's paragraph has them, moved by that offset. `null` when lines cannot be laid out\n * apart from the others.\n */\nfunction buildPieces(\n block: LineBlock,\n width: number,\n offsets: readonly number[],\n grouped = true\n): LinePiece[] | null {\n const build = block.lines?.build\n if (!build) return null\n const lines = block.paragraph.getLineMetrics()\n const shaped = shapedLinesByLine(block.paragraph)\n const truncated = block.paragraph.didExceedMaxLines()\n const textEnd = block.lead + block.length\n const pieces: LinePiece[] = []\n let from = 0\n while (from < lines.length) {\n let to = from + 1\n if (grouped) while (to < lines.length && allSame([offsets[from], offsets[to]])) to++\n const start = lines[from].startIndex\n const end = to === lines.length ? textEnd : lines[to - 1].endIndex\n // Empty lines draw nothing.\n if (end <= start) {\n from = to\n continue\n }\n const count = to - from\n const paragraph = build(start, end, count, to === lines.length && truncated)\n paragraph.layout(Math.max(1, width - block.inset))\n const own = paragraph.getLineMetrics().length === count ? shapedLinesByLine(paragraph) : null\n const shift = own && pieceShift(shaped.slice(from, to), own)\n if (!shift || shift.agrees < count) {\n paragraph.delete()\n for (const piece of pieces) piece.paragraph.delete()\n // Lines that lay out or snap apart are drawn one by one.\n return grouped ? buildPieces(block, width, offsets, false) : null\n }\n pieces.push({ paragraph, x: shift.x, y: shift.y + offsets[from] })\n from = to\n }\n return pieces\n}\n\n/** Where `placeLines` puts each block, and the text's height. */\nexport interface PlacedLines<Block> {\n blocks: Map<Block, BlockPlacement & { y: number }>\n height: number\n}\n\n/**\n * Lines of laid-out blocks placed as Figma places them when they differ in height: each\n * line is as tall as its tallest line height, and each baseline stands that far, plus the\n * paragraph's spacing, below the one before, where a paragraph would stack the lines' boxes.\n * `null` keeps the paragraphs' placement: for lines alike, where it is the same, and for\n * lines that cannot be measured or drawn apart.\n */\nexport function placeLines<Block extends LineBlock>(\n ck: CanvasKit,\n blocks: readonly Block[],\n width: number\n): PlacedLines<Block> | null {\n const metrics = blocks.map((block) => block.paragraph.getLineMetrics())\n // A single line has none to be spaced from.\n if (metrics.flat().length < 2) return null\n const boxes = lineBoxes(ck, blocks, metrics)\n if (!boxes) return null\n const all = boxes.flat()\n // A paragraph steps lines by whole pixels, so lines alike at a whole-pixel height already\n // stand where Figma puts them.\n const height = all[0].height\n const alike = allSame(all.map((box) => box.height)) && allSame(all.map((box) => box.ascent))\n if (alike && allSame([height, Math.round(height)])) return null\n\n // Figma steps lines by their exact heights and puts each baseline on a whole pixel, so a\n // baseline stands the whole pixels between those below the first (Figma desktop 126).\n const first = all[0]\n const last = all[all.length - 1]\n const start = Math.round(first.ascent)\n let below = 0\n const baselines = blocks.map((block, index) =>\n boxes[index].map((box, line) => {\n if (index > 0 || line > 0) below += box.height + (line === 0 ? block.spaceBefore : 0)\n return first.ascent + Math.round(first.ascent + below) - start\n })\n )\n const placed = new Map<Block, BlockPlacement & { y: number }>()\n for (const [index, block] of blocks.entries()) {\n const lines = metrics[index]\n const blockBoxes = boxes[index]\n const blockBaselines = baselines[index]\n const end = blockBoxes.length - 1\n const y = blockBaselines[0] - lines[0].baseline\n const offsets = lines.map((line, lineIndex) => blockBaselines[lineIndex] - y - line.baseline)\n const apart = !allSame(offsets)\n const pieces = apart ? buildPieces(block, width, offsets) : null\n placed.set(block, {\n y,\n height: blockBaselines[end] - blockBoxes[end].ascent + blockBoxes[end].height - y,\n offsets,\n boxes: blockBoxes,\n pieces\n })\n // Lines that cannot be drawn apart keep the paragraph's placement, and so does the text.\n if (apart && !pieces) {\n for (const placement of placed.values()) {\n for (const piece of placement.pieces ?? []) piece.paragraph.delete()\n }\n return null\n }\n }\n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,OAAO,QAAQ,GAAG;EAC7C,MAAM,QAAQ,QAAQ;EACtB,MAAM,aAAa,MAAM;EACzB,MAAM,iBAAiB,UAAU;EACjC,MAAM,MAAM,WAAW,SAAS;EAChC,MAAM,IAAI,eAAe,KAAK,MAAM,EAAE,CAAC;EACvC,MAAM,UAAU,MAAM,KAAK,MAAM,cAAc,eAAe,aAAa,IAAI,KAAK,QAAQ;EAC5F,MAAM,QAAQ,CAAC,QAAQ,OAAO;EAC9B,MAAM,SAAS,QAAQ,YAAY,OAAO,OAAO,OAAO,IAAI;EAC5D,OAAO,IAAI,OAAO;GAChB;GACA,QAAQ,eAAe,OAAO,WAAW,IAAI,CAAC,SAAS,WAAW,IAAI,CAAC,SAAS;GAChF;GACA,OAAO;GACP;EACF,CAAC;EAED,IAAI,SAAS,CAAC,QAAQ;GACpB,KAAK,MAAM,aAAa,OAAO,OAAO,GACpC,KAAK,MAAM,SAAS,UAAU,UAAU,CAAC,GAAG,MAAM,UAAU,OAAO;GAErE,OAAO;EACT;CACF;CACA,OAAO;EAAE,QAAQ;EAAQ,QAAQ,MAAM,SAAS,KAAK,SAAS,QAAQ,KAAK;CAAO;AACpF"}
@@ -5,6 +5,11 @@ import { CanvasKit, Paragraph, TextFontFeatures, TextFontVariations } from "canv
5
5
  import { SceneNode } from "@pairdraw/scene-graph";
6
6
  //#region src/canvas/text/paragraph/index.d.ts
7
7
  declare function resolveParagraphLayoutWidth(node: ParagraphNode, maxWidth?: number): number;
8
+ /**
9
+ * The lines a truncating box shows: what `maxLines` allows, else as many as its height holds, as
10
+ * Figma keeps the last and ends it with an ellipsis. A text box set to truncate truncates even
11
+ * where nothing turned on `textTruncation`, which is how the auto-resize mode is chosen.
12
+ */
8
13
  declare function buildTruncateOpts(node: ParagraphNode): {
9
14
  maxLines?: number;
10
15
  ellipsis?: string;
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"mappings":";;;;;;iBAqCgB,4BAA4B,MAAM,eAAe;iBAMjD,kBAAkB,MAAM;EAAkB;EAAmB;;;iBA4B7D,mBACd,YAAY,yCACZ,WAAU,qCACT;iBAUa,iBACd,UAAU,wCACT;iBAQa,wBAAwB,GACtC;EAAM;IAAsB,YAAY;;GACxC,aAAa,2BACZ;;UAKc;EACf;EACA;;;iBAsCc,cACd,IAAI,WACJ,OAAO,yCACP,WAAW,eACV;;UAiHc;;EAEf;;EAEA;IAAe;IAAmB;;EAClC,QAAQ;;;;;;iBAYM,iBACd,GAAG,cACH,MAAM,eACN,QAAQ,gBACN,aAAqB,oBAAmB,uBAC1C,QAAO,wBACN"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../../src/canvas/text/paragraph/index.ts"],"mappings":";;;;;;iBAuCgB,4BAA4B,MAAM,eAAe;;;;;;iBAajD,kBAAkB,MAAM;EAAkB;EAAmB;;;iBA4B7D,mBACd,YAAY,yCACZ,WAAU,qCACT;iBAUa,iBACd,UAAU,wCACT;iBAQa,wBAAwB,GACtC;EAAM;IAAsB,YAAY;;GACxC,aAAa,2BACZ;;UAKc;EACf;EACA;;;iBAsCc,cACd,IAAI,WACJ,OAAO,yCACP,WAAW,eACV;;UAiHc;;EAEf;;EAEA;IAAe;IAAmB;;EAClC,QAAQ;;;;;;iBAYM,iBACd,GAAG,cACH,MAAM,eACN,QAAQ,gBACN,aAAqB,oBAAmB,uBAC1C,QAAO,wBACN"}
@@ -1,9 +1,11 @@
1
1
  import "../../../constants.js";
2
+ import { makeParagraphBuilder } from "../../../text/font/collection.js";
2
3
  import { shownTextSlice } from "../../../text/case.js";
3
4
  import { fontManager } from "../../../text/font/manager.js";
4
- import { laidOutText } from "../keycap.js";
5
5
  import { drawnFontVariations, loadedFace, resolveParagraphFontFamilies } from "../font-families.js";
6
+ import { laidOutText } from "../keycap.js";
6
7
  import { pushParagraphStyle } from "../paint.js";
8
+ import { autoWidthWrapWidth } from "../../../layout/text-measurement.js";
7
9
  import "../../../text/ellipsis.js";
8
10
  import { lineHeightPixels, textLengthPixels } from "@pairdraw/scene-graph/text";
9
11
  import { faceStyleKey } from "@pairdraw/scene-graph/font-style";
@@ -13,14 +15,21 @@ import { resolveNodeTextDirection } from "@pairdraw/scene-graph/text/direction";
13
15
  //#region src/canvas/text/paragraph/index.ts
14
16
  function resolveParagraphLayoutWidth(node, maxWidth) {
15
17
  if (maxWidth !== void 0) return maxWidth;
16
- if (node.textAutoResize === "WIDTH_AND_HEIGHT") return 1e6;
18
+ if (node.textAutoResize === "WIDTH_AND_HEIGHT") return autoWidthWrapWidth(node) ?? 1e6;
17
19
  return node.width || 1e6;
18
20
  }
21
+ /**
22
+ * The lines a truncating box shows: what `maxLines` allows, else as many as its height holds, as
23
+ * Figma keeps the last and ends it with an ellipsis. A text box set to truncate truncates even
24
+ * where nothing turned on `textTruncation`, which is how the auto-resize mode is chosen.
25
+ */
19
26
  function buildTruncateOpts(node) {
20
- if (node.textTruncation !== "ENDING") return {};
21
- const opts = { ellipsis: "…" };
22
- if (node.maxLines != null && node.maxLines > 0) opts.maxLines = node.maxLines;
23
- return opts;
27
+ if (node.textTruncation !== "ENDING" && node.textAutoResize !== "TRUNCATE") return {};
28
+ if (node.maxLines == null || node.maxLines <= 0) return node.textAutoResize === "TRUNCATE" ? {} : { ellipsis: "…" };
29
+ return {
30
+ maxLines: node.maxLines,
31
+ ellipsis: "…"
32
+ };
24
33
  }
25
34
  function getParagraphTextAlign(ck, node) {
26
35
  const direction = resolveNodeTextDirection(node);
@@ -189,7 +198,7 @@ function buildSkParagraph(r, node, color, { halfLeading = false, foregroundPaint
189
198
  textStyle: baseTextStyle
190
199
  });
191
200
  if (!r.fontProvider) throw new Error("Font provider not initialized");
192
- const builder = ck.ParagraphBuilder.MakeFromFontProvider(paraStyle, r.fontProvider);
201
+ const builder = makeParagraphBuilder(ck, paraStyle, r.fontProvider);
193
202
  let background;
194
203
  try {
195
204
  let paintStyle;