@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
@@ -1 +1 @@
1
- {"version":3,"file":"serialization.js","names":[],"sources":["../../src/figma-api/serialization.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport { pluginChildren } from './accessors/sticky'\nimport { figmaFills, figmaStrokes } from './accessors/visual'\nimport type { NodeProxyHost } from './proxy'\n\nfunction resolveBindings(graph: SceneGraph, node: SceneNode): Record<string, unknown> | undefined {\n const keys = Object.keys(node.boundVariables)\n if (keys.length === 0) return undefined\n const result: Record<string, unknown> = {}\n for (const [field, varId] of Object.entries(node.boundVariables)) {\n const variable = graph.variables.get(varId)\n result[field] = {\n variableId: varId,\n variableName: variable?.name ?? varId,\n resolvedValue: variable ? graph.resolveVariable(varId) : undefined\n }\n }\n return result\n}\n\nfunction appendTextProps(obj: Record<string, unknown>, n: SceneNode): void {\n obj.fontFamily = n.fontFamily\n obj.fontSize = n.fontSize\n obj.fontWeight = n.fontWeight\n obj.italic = n.italic\n obj.textAlignHorizontal = n.textAlignHorizontal\n obj.textAlignVertical = n.textAlignVertical\n obj.textAutoResize = n.textAutoResize\n obj.textDirection = n.textDirection\n if (n.lineHeight != null) obj.lineHeight = n.lineHeight\n if (n.letterSpacing.value !== 0) obj.letterSpacing = n.letterSpacing\n if (n.textCase !== 'ORIGINAL') obj.textCase = n.textCase\n if (n.textDecoration !== 'NONE') obj.textDecoration = n.textDecoration\n if (n.maxLines != null) obj.maxLines = n.maxLines\n}\n\nexport function nodeProxyToJSON(\n graph: SceneGraph,\n api: NodeProxyHost,\n nodeId: string,\n maxDepth?: number,\n currentDepth = 0\n): Record<string, unknown> {\n const n = graph.getNode(nodeId)\n if (!n) return { id: nodeId, removed: true }\n\n const obj: Record<string, unknown> = {\n id: n.id,\n type: n.type,\n name: n.name,\n x: n.x,\n y: n.y,\n width: n.width,\n height: n.height\n }\n if (n.fills.length > 0) obj.fills = figmaFills(graph, n)\n if (n.strokes.length > 0) obj.strokes = figmaStrokes(graph, n)\n if (n.effects.length > 0) obj.effects = n.effects\n if (n.opacity !== 1) obj.opacity = n.opacity\n // The angle `set_rotation` writes, as the Figma API reports it. The scene stores the turn in\n // the opposite direction and keeps floating-point noise, so read it through the proxy.\n if (n.rotation !== 0) obj.rotation = api.wrapNode(nodeId).rotation\n if (n.cornerRadius > 0) obj.cornerRadius = n.cornerRadius\n if (!n.visible) obj.visible = false\n if (n.text) obj.characters = n.text\n if (n.type === 'TEXT') {\n appendTextProps(obj, n)\n }\n if (n.layoutMode !== 'NONE') {\n // An auto layout frame reports the insets and alignment a tool sets, so a caller can read back\n // what it wrote instead of measuring the result.\n const proxy = api.wrapNode(nodeId)\n obj.layoutMode = n.layoutMode\n obj.layoutDirection = n.layoutDirection\n obj.itemSpacing = n.itemSpacing\n obj.paddingTop = proxy.paddingTop\n obj.paddingRight = proxy.paddingRight\n obj.paddingBottom = proxy.paddingBottom\n obj.paddingLeft = proxy.paddingLeft\n obj.primaryAxisAlignItems = proxy.primaryAxisAlignItems\n obj.counterAxisAlignItems = proxy.counterAxisAlignItems\n obj.primaryAxisSizingMode = proxy.primaryAxisSizingMode\n obj.counterAxisSizingMode = proxy.counterAxisSizingMode\n }\n // Include variable bindings with resolved values\n const bindings = resolveBindings(graph, n)\n if (bindings) obj.boundVariables = bindings\n const children = pluginChildren(graph, nodeId)\n if (children.length > 0) {\n if (maxDepth !== undefined && currentDepth >= maxDepth) {\n obj.childCount = children.length\n } else {\n obj.children = children.map((child) =>\n api.wrapNode(child.id).toJSON(maxDepth, currentDepth + 1)\n )\n }\n }\n return obj\n}\n"],"mappings":";;;AAMA,SAAS,gBAAgB,OAAmB,MAAsD;CAEhG,IADa,OAAO,KAAK,KAAK,cACvB,CAAC,CAAC,WAAW,GAAG,OAAO,KAAA;CAC9B,MAAM,SAAkC,CAAC;CACzC,KAAK,MAAM,CAAC,OAAO,UAAU,OAAO,QAAQ,KAAK,cAAc,GAAG;EAChE,MAAM,WAAW,MAAM,UAAU,IAAI,KAAK;EAC1C,OAAO,SAAS;GACd,YAAY;GACZ,cAAc,UAAU,QAAQ;GAChC,eAAe,WAAW,MAAM,gBAAgB,KAAK,IAAI,KAAA;EAC3D;CACF;CACA,OAAO;AACT;AAEA,SAAS,gBAAgB,KAA8B,GAAoB;CACzE,IAAI,aAAa,EAAE;CACnB,IAAI,WAAW,EAAE;CACjB,IAAI,aAAa,EAAE;CACnB,IAAI,SAAS,EAAE;CACf,IAAI,sBAAsB,EAAE;CAC5B,IAAI,oBAAoB,EAAE;CAC1B,IAAI,iBAAiB,EAAE;CACvB,IAAI,gBAAgB,EAAE;CACtB,IAAI,EAAE,cAAc,MAAM,IAAI,aAAa,EAAE;CAC7C,IAAI,EAAE,cAAc,UAAU,GAAG,IAAI,gBAAgB,EAAE;CACvD,IAAI,EAAE,aAAa,YAAY,IAAI,WAAW,EAAE;CAChD,IAAI,EAAE,mBAAmB,QAAQ,IAAI,iBAAiB,EA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AgB,OAAO,CAAC;CACzC,IAAI,UAAU,IAAI,iBAAiB;CACnC,MAAM,WAAW,eAAe,OAAO,MAAM;CAC7C,IAAI,SAAS,SAAS,GAAG;EACvB,IAAI,aAAa,KAAA,KAAa,gBAAgB,UAC5C,IAAI,aAAa,SAAS;OAE1B,IAAI,WAAW,SAAS,KAAK,UAC3B,IAAI,SAAS,MAAM,EAAE,CAAC,CAAC,OAAO,UAAU,eAAe,CAAC,CAC1D;CAEJ;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"serialization.js","names":[],"sources":["../../src/figma-api/serialization.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\n\nimport { pluginChildren } from './accessors/sticky'\nimport { figmaFills, figmaStrokes } from './accessors/visual'\nimport type { NodeProxyHost } from './proxy'\n\nfunction resolveBindings(graph: SceneGraph, node: SceneNode): Record<string, unknown> | undefined {\n const keys = Object.keys(node.boundVariables)\n if (keys.length === 0) return undefined\n const result: Record<string, unknown> = {}\n for (const [field, varId] of Object.entries(node.boundVariables)) {\n const variable = graph.variables.get(varId)\n result[field] = {\n variableId: varId,\n variableName: variable?.name ?? varId,\n resolvedValue: variable ? graph.resolveVariable(varId) : undefined\n }\n }\n return result\n}\n\nfunction appendTextProps(obj: Record<string, unknown>, n: SceneNode): void {\n obj.fontFamily = n.fontFamily\n obj.fontSize = n.fontSize\n obj.fontWeight = n.fontWeight\n obj.italic = n.italic\n obj.textAlignHorizontal = n.textAlignHorizontal\n obj.textAlignVertical = n.textAlignVertical\n obj.textAutoResize = n.textAutoResize\n obj.textDirection = n.textDirection\n if (n.lineHeight != null) obj.lineHeight = n.lineHeight\n if (n.letterSpacing.value !== 0) obj.letterSpacing = n.letterSpacing\n if (n.textCase !== 'ORIGINAL') obj.textCase = n.textCase\n if (n.textDecoration !== 'NONE') obj.textDecoration = n.textDecoration\n if (n.maxLines != null) obj.maxLines = n.maxLines\n}\n\nexport function nodeProxyToJSON(\n graph: SceneGraph,\n api: NodeProxyHost,\n nodeId: string,\n maxDepth?: number,\n currentDepth = 0\n): Record<string, unknown> {\n const n = graph.getNode(nodeId)\n if (!n) return { id: nodeId, removed: true }\n\n const obj: Record<string, unknown> = {\n id: n.id,\n type: n.type,\n name: n.name,\n x: n.x,\n y: n.y,\n width: n.width,\n height: n.height\n }\n if (n.fills.length > 0) obj.fills = figmaFills(n)\n if (n.strokes.length > 0) obj.strokes = figmaStrokes(n)\n if (n.effects.length > 0) obj.effects = n.effects\n if (n.opacity !== 1) obj.opacity = n.opacity\n // The angle `set_rotation` writes, as the Figma API reports it. The scene stores the turn in\n // the opposite direction and keeps floating-point noise, so read it through the proxy.\n if (n.rotation !== 0) obj.rotation = api.wrapNode(nodeId).rotation\n if (n.cornerRadius > 0) obj.cornerRadius = n.cornerRadius\n if (!n.visible) obj.visible = false\n if (n.text) obj.characters = n.text\n if (n.type === 'TEXT') {\n appendTextProps(obj, n)\n }\n if (n.layoutMode !== 'NONE') {\n // An auto layout frame reports the insets and alignment a tool sets, so a caller can read back\n // what it wrote instead of measuring the result.\n const proxy = api.wrapNode(nodeId)\n obj.layoutMode = n.layoutMode\n obj.layoutDirection = n.layoutDirection\n obj.itemSpacing = n.itemSpacing\n obj.paddingTop = proxy.paddingTop\n obj.paddingRight = proxy.paddingRight\n obj.paddingBottom = proxy.paddingBottom\n obj.paddingLeft = proxy.paddingLeft\n obj.primaryAxisAlignItems = proxy.primaryAxisAlignItems\n obj.counterAxisAlignItems = proxy.counterAxisAlignItems\n obj.primaryAxisSizingMode = proxy.primaryAxisSizingMode\n obj.counterAxisSizingMode = proxy.counterAxisSizingMode\n }\n // Include variable bindings with resolved values\n const bindings = resolveBindings(graph, n)\n if (bindings) obj.boundVariables = bindings\n const children = pluginChildren(graph, nodeId)\n if (children.length > 0) {\n if (maxDepth !== undefined && currentDepth >= maxDepth) {\n obj.childCount = children.length\n } else {\n obj.children = children.map((child) =>\n api.wrapNode(child.id).toJSON(maxDepth, currentDepth + 1)\n )\n }\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AG,IAAI,QAAQ,WAAW,CAAC;CAChD,IAAI,EAAE,QAAQ,SAAS,GAAG,IAAI,UAAU,aAAa,CAAC;CACtD,IAAI,EAAE,QAAQ,SAAS,GAAG,IAAI,UAAU,EAAE;CAC1C,IAAI,EAAE,YAAY,GAAG,IAAI,UAAU,EAAE;CAGrC,IAAI,EAAE,aAAa,GAAG,IAAI,WAAW,IAAI,SAAS,MAAM,CAAC,CAAC;CAC1D,IAAI,EAAE,eAAe,GAAG,IAAI,eAAe,EAAE;CAC7C,IAAI,CAAC,EAAE,SAAS,IAAI,UAAU;CAC9B,IAAI,EAAE,MAAM,IAAI,aAAa,EAAE;CAC/B,IAAI,EAAE,SAAS,QACb,gBAAgB,KAAK,CAAC;CAExB,IAAI,EAAE,eAAe,QAAQ;EAG3B,MAAM,QAAQ,IAAI,SAAS,MAAM;EACjC,IAAI,aAAa,EAAE;EACnB,IAAI,kBAAkB,EAAE;EACxB,IAAI,cAAc,EAAE;EACpB,IAAI,aAAa,MAAM;EACvB,IAAI,eAAe,MAAM;EACzB,IAAI,gBAAgB,MAAM;EAC1B,IAAI,cAAc,MAAM;EACxB,IAAI,wBAAwB,MAAM;EAClC,IAAI,wBAAwB,MAAM;EAClC,IAAI,wBAAwB,MAAM;EAClC,IAAI,wBAAwB,MAAM;CACpC;CAEA,MAAM,WAAW,gBAAgB,OAAO,CAAC;CACzC,IAAI,UAAU,IAAI,iBAAiB;CACnC,MAAM,WAAW,eAAe,OAAO,MAAM;CAC7C,IAAI,SAAS,SAAS,GAAG;EACvB,IAAI,aAAa,KAAA,KAAa,gBAAgB,UAC5C,IAAI,aAAa,SAAS;OAE1B,IAAI,WAAW,SAAS,KAAK,UAC3B,IAAI,SAAS,MAAM,EAAE,CAAC,CAAC,OAAO,UAAU,eAAe,CAAC,CAC1D;CAEJ;CACA,OAAO;AACT"}
@@ -18,6 +18,12 @@ declare function assertSlotSettings(type: ComponentPropertyType, settings: Figma
18
18
  * of an instance refuses it, and a slot on either side becomes the instance's own content.
19
19
  */
20
20
  declare function prepareSlotMove(g: SceneGraph, parentId: string, childId: string, method: 'appendChild' | 'insertChild'): void;
21
+ /**
22
+ * Ready adding new layers under `parentId`, as a tool that builds layers in place does, by the
23
+ * rule appendChild follows: the locked part of an instance refuses them, since its layers come
24
+ * from the component, and a slot's content becomes the instance's own first.
25
+ */
26
+ declare function prepareSlotInsertion(g: SceneGraph, parentId: string, method: string): void;
21
27
  /**
22
28
  * Ready removing a layer the way Figma's remove() does: the locked part of an instance,
23
29
  * slot frames included, refuses it, and slot content becomes the instance's own first.
@@ -26,5 +32,5 @@ declare function prepareSlotRemoval(g: SceneGraph, nodeId: string): void;
26
32
  /** `ComponentNode.createSlot` and the `SlotNode` members Figma's plugin API defines. */
27
33
  declare function installSlotAccessors(prototype: object, internals: NodeProxyInternals): void;
28
34
  //#endregion
29
- export { FigmaSlotSettings, assertSlotSettings, figmaSlotSettings, installSlotAccessors, mergeSlotSettings, prepareSlotMove, prepareSlotRemoval };
35
+ export { FigmaSlotSettings, assertSlotSettings, figmaSlotSettings, installSlotAccessors, mergeSlotSettings, prepareSlotInsertion, prepareSlotMove, prepareSlotRemoval };
30
36
  //# sourceMappingURL=slots.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"slots.d.ts","names":[],"sources":["../../src/figma-api/slots.ts"],"mappings":";;;;UAqBiB;EACf;EACA;EACA;EACA;EACA;;;iBASc,kBACd,SAAS,0BACT,SAAS,oBACR;iBAca,kBAAkB,UAAU,eAAe;iBAQ3C,mBACd,MAAM,uBACN,UAAU;;;;;iBAUI,gBACd,GAAG,YACH,kBACA,iBACA;;;;;iBAiBc,mBAAmB,GAAG,YAAY;;iBAmBlC,qBAAqB,mBAAmB,WAAW"}
1
+ {"version":3,"file":"slots.d.ts","names":[],"sources":["../../src/figma-api/slots.ts"],"mappings":";;;;UAqBiB;EACf;EACA;EACA;EACA;EACA;;;iBASc,kBACd,SAAS,0BACT,SAAS,oBACR;iBAca,kBAAkB,UAAU,eAAe;iBAQ3C,mBACd,MAAM,uBACN,UAAU;;;;;iBAUI,gBACd,GAAG,YACH,kBACA,iBACA;;;;;;iBAac,qBAAqB,GAAG,YAAY,kBAAkB;;;;;iBAatD,mBAAmB,GAAG,YAAY;;iBAmBlC,qBAAqB,mBAAmB,WAAW"}
@@ -38,14 +38,22 @@ function assertSlotSettings(type, settings) {
38
38
  * of an instance refuses it, and a slot on either side becomes the instance's own content.
39
39
  */
40
40
  function prepareSlotMove(g, parentId, childId, method) {
41
- const target = slotScope(g, parentId);
42
- if (target.kind === "locked") throw new Error(`in ${method}: Cannot move node. New parent is an instance or is inside of an instance`);
43
41
  const sourceParentId = g.getNode(childId)?.parentId;
44
42
  const source = sourceParentId ? slotScope(g, sourceParentId) : void 0;
45
- if (target.kind === "slot") claimSlotContent(g, target);
43
+ prepareSlotInsertion(g, parentId, method);
46
44
  if (source?.kind === "slot") claimSlotContent(g, source);
47
45
  }
48
46
  /**
47
+ * Ready adding new layers under `parentId`, as a tool that builds layers in place does, by the
48
+ * rule appendChild follows: the locked part of an instance refuses them, since its layers come
49
+ * from the component, and a slot's content becomes the instance's own first.
50
+ */
51
+ function prepareSlotInsertion(g, parentId, method) {
52
+ const target = slotScope(g, parentId);
53
+ if (target.kind === "locked") throw new Error(`in ${method}: Cannot move node. New parent is an instance or is inside of an instance`);
54
+ if (target.kind === "slot") claimSlotContent(g, target);
55
+ }
56
+ /**
49
57
  * Ready removing a layer the way Figma's remove() does: the locked part of an instance,
50
58
  * slot frames included, refuses it, and slot content becomes the instance's own first.
51
59
  */
@@ -95,6 +103,6 @@ function installSlotAccessors(prototype, internals) {
95
103
  });
96
104
  }
97
105
  //#endregion
98
- export { assertSlotSettings, figmaSlotSettings, installSlotAccessors, mergeSlotSettings, prepareSlotMove, prepareSlotRemoval };
106
+ export { assertSlotSettings, figmaSlotSettings, installSlotAccessors, mergeSlotSettings, prepareSlotInsertion, prepareSlotMove, prepareSlotRemoval };
99
107
 
100
108
  //# sourceMappingURL=slots.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"slots.js","names":[],"sources":["../../src/figma-api/slots.ts"],"sourcesContent":["import type { ComponentPropertyType, SceneGraph, SlotSettings } from '@pairdraw/scene-graph'\nimport {\n createComponentPropertyId,\n componentPropertyDefinitions\n} from '@pairdraw/scene-graph/components'\nimport {\n DEFAULT_SLOT_SETTINGS,\n claimSlotContent,\n createSlotProperty,\n resetSlotContent,\n slotLimitViolations,\n slotPropertyId,\n slotScope,\n type SlotLimitViolation\n} from '@pairdraw/scene-graph/slots'\n\nimport type { NodeProxyInternals, ProxyThis } from './accessor-utils'\nimport { assertProxyEditable, graph, nodeId, raw } from './accessor-utils'\nimport type { NodeProxyHost } from './proxy'\n\n/** Figma's slot limits, where an unset count reads as null. */\nexport interface FigmaSlotSettings {\n stretchChildOnInsert?: boolean\n displayEmptyByDefault?: boolean\n minChildren?: number | null\n maxChildren?: number | null\n allowPreferredValuesOnly?: boolean\n}\n\n/** A count after a Figma change: null clears it, undefined keeps the current one. */\nfunction count(change: number | null | undefined, current: number | undefined) {\n return change === null ? undefined : (change ?? current)\n}\n\n/** Apply Figma slot settings to a definition's own. */\nexport function mergeSlotSettings(\n current: SlotSettings | undefined,\n changes: FigmaSlotSettings\n): SlotSettings {\n const base = { ...DEFAULT_SLOT_SETTINGS, ...current }\n const next: SlotSettings = {\n stretchChildOnInsert: changes.stretchChildOnInsert ?? base.stretchChildOnInsert,\n displayEmptyByDefault: changes.displayEmptyByDefault ?? base.displayEmptyByDefault,\n allowPreferredValuesOnly: changes.allowPreferredValuesOnly ?? base.allowPreferredValuesOnly\n }\n const minChildren = count(changes.minChildren, base.minChildren)\n const maxChildren = count(changes.maxChildren, base.maxChildren)\n if (minChildren !== undefined) next.minChildren = minChildren\n if (maxChildren !== undefined) next.maxChildren = maxChildren\n return next\n}\n\nexport function figmaSlotSettings(settings: SlotSettings): FigmaSlotSettings {\n return {\n ...settings,\n minChildren: settings.minChildren ?? null,\n maxChildren: settings.maxChildren ?? null\n }\n}\n\nexport function assertSlotSettings(\n type: ComponentPropertyType,\n settings: FigmaSlotSettings | undefined\n): void {\n if (settings && type !== 'SLOT')\n throw new Error(\"slotSettings is only supported for 'SLOT' properties\")\n}\n\n/**\n * Ready a move of `childId` into `parentId` the way Figma's appendChild does: the locked part\n * of an instance refuses it, and a slot on either side becomes the instance's own content.\n */\nexport function prepareSlotMove(\n g: SceneGraph,\n parentId: string,\n childId: string,\n method: 'appendChild' | 'insertChild'\n): void {\n const target = slotScope(g, parentId)\n if (target.kind === 'locked')\n throw new Error(\n `in ${method}: Cannot move node. New parent is an instance or is inside of an instance`\n )\n const sourceParentId = g.getNode(childId)?.parentId\n const source = sourceParentId ? slotScope(g, sourceParentId) : undefined\n if (target.kind === 'slot') claimSlotContent(g, target)\n if (source?.kind === 'slot') claimSlotContent(g, source)\n}\n\n/**\n * Ready removing a layer the way Figma's remove() does: the locked part of an instance,\n * slot frames included, refuses it, and slot content becomes the instance's own first.\n */\nexport function prepareSlotRemoval(g: SceneGraph, nodeId: string): void {\n const parentId = g.getNode(nodeId)?.parentId\n if (!parentId) return\n const scope = slotScope(g, parentId)\n if (scope.kind === 'locked') throw new Error('in remove: Removing this node is not allowed')\n if (scope.kind === 'slot') claimSlotContent(g, scope)\n}\n\nfunction host(target: ProxyThis, internals: NodeProxyInternals): NodeProxyHost {\n return target[internals.api] as NodeProxyHost\n}\n\n/** The instance slot a proxy is, if it is the frame of one. */\nfunction instanceSlot(target: ProxyThis, internals: NodeProxyInternals) {\n const scope = slotScope(graph(target, internals), nodeId(target, internals))\n return scope.kind === 'slot' && scope.frame.id === nodeId(target, internals) ? scope : undefined\n}\n\n/** `ComponentNode.createSlot` and the `SlotNode` members Figma's plugin API defines. */\nexport function installSlotAccessors(prototype: object, internals: NodeProxyInternals): void {\n Object.defineProperties(prototype, {\n createSlot: {\n // Figma appends a 100×100 frame named Slot, Slot 2, … and a SLOT property of that name.\n value(this: ProxyThis) {\n const component = raw(this, internals)\n if (component.type !== 'COMPONENT')\n throw new Error('createSlot() can only be called on components')\n assertProxyEditable(this, internals)\n const g = graph(this, internals)\n const frame = g.createNode('FRAME', component.id, { name: 'Slot' })\n const definition = createSlotProperty(g, frame.id, createComponentPropertyId())\n if (!definition) throw new Error('Failed to create slot')\n g.updateNode(frame.id, { name: definition.name })\n return host(this, internals).wrapNode(frame.id)\n }\n },\n resetSlot: {\n value(this: ProxyThis) {\n if (!slotPropertyId(raw(this, internals)))\n throw new Error('resetSlot() can only be called on slots')\n assertProxyEditable(this, internals)\n const scope = instanceSlot(this, internals)\n if (scope) resetSlotContent(graph(this, internals), scope)\n }\n },\n limitViolations: {\n // Figma measures limits only where an instance shows the slot; a main component's slot\n // reports none.\n get(this: ProxyThis): SlotLimitViolation[] {\n const scope = instanceSlot(this, internals)\n if (!scope) return []\n const g = graph(this, internals)\n const definition = componentPropertyDefinitions(g, scope.instance).find(\n (item) => item.id === scope.propertyId\n )\n if (!definition) return []\n return slotLimitViolations(g, definition, g.getChildren(scope.frame.id))\n }\n }\n })\n}\n"],"mappings":";;;;;AA8BA,SAAS,MAAM,QAAmC,SAA6B;CAC7E,OAAO,WAAW,OAAO,KAAA,IAAa,UAAU;AAClD;;AAGA,SAAgB,kBACd,SACA,SACc;CACd,MAAM,OAAO;EAAE,GAAG;EAAuB,GAAG;CAAQ;CACpD,MAAM,OAAqB;EACzB,sBAAsB,QAAQ,wBAAwB,KAAK;EAC3D,uBAAuB,QAAQ,yBAAyB,KAAK;EAC7D,0BAA0B,QAAQ,4BAA4B,KAAK;CACrE;CACA,MAAM,cAAc,MAAM,QAAQ,aAAa,KAAK,WAAW;CAC/D,MAAM,cAAc,MAAM,QAAQ,aAAa,KAAK,WAAW;CAC/D,IAAI,gBAAgB,KAAA,GAAW,KAAK,cAAc;CAClD,IAAI,gBAAgB,KAAA,GAAW,KAAK,cAAc;CAClD,OAAO;AACT;AAEA,SAAgB,kBAAkB,UAA2C;CAC3E,OAAO;EACL,GAAG;EACH,aA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AAoB,MAAM,SAAS;GACnC,MAAM,IAAI,MAAM,MAAM,SAAS;GAC/B,MAAM,QAAQ,EAAE,WAAW,SAAS,UAAU,IAAI,EAAE,MAAM,OAAO,CAAC;GAClE,MAAM,aAAa,mBAAmB,GAAG,MAAM,IAAI,0BAA0B,CAAC;GAC9E,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,uBAAuB;GACxD,EAAE,WAAW,MAAM,IAAI,EAAE,MAAM,WAAW,KAAK,CAAC;GAChD,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE;EAChD,EACF;EACA,WAAW,EACT,QAAuB;GACrB,IAAI,CAAC,eAAe,IAAI,MAAM,SAAS,CAAC,GACtC,MAAM,IAAI,MAAM,yCAAyC;GAC3D,oBAAoB,MAAM,SAAS;GACnC,MAAM,QAAQ,aAAa,MAAM,SAAS;GAC1C,IAAI,OAAO,iBAAiB,MAAM,MAAM,SAAS,GAAG,KAAK;EAC3D,EACF;EACA,iBAAiB,EAGf,MAA2C;GACzC,MAAM,QAAQ,aAAa,MAAM,SAAS;GAC1C,IAAI,CAAC,OAAO,OAAO,CAAC;GACpB,MAAM,IAAI,MAAM,MAAM,SAAS;GAC/B,MAAM,aAAa,6BAA6B,GAAG,MAAM,QAAQ,CAAC,CAAC,MAChE,SAAS,KAAK,OAAO,MAAM,UAC9B;GACA,IAAI,CAAC,YAAY,OAAO,CAAC;GACzB,OAAO,oBAAoB,GAAG,YAAY,EAAE,YAAY,MAAM,MAAM,EAAE,CAAC;EACzE,EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"slots.js","names":[],"sources":["../../src/figma-api/slots.ts"],"sourcesContent":["import type { ComponentPropertyType, SceneGraph, SlotSettings } from '@pairdraw/scene-graph'\nimport {\n createComponentPropertyId,\n componentPropertyDefinitions\n} from '@pairdraw/scene-graph/components'\nimport {\n DEFAULT_SLOT_SETTINGS,\n claimSlotContent,\n createSlotProperty,\n resetSlotContent,\n slotLimitViolations,\n slotPropertyId,\n slotScope,\n type SlotLimitViolation\n} from '@pairdraw/scene-graph/slots'\n\nimport type { NodeProxyInternals, ProxyThis } from './accessor-utils'\nimport { assertProxyEditable, graph, nodeId, raw } from './accessor-utils'\nimport type { NodeProxyHost } from './proxy'\n\n/** Figma's slot limits, where an unset count reads as null. */\nexport interface FigmaSlotSettings {\n stretchChildOnInsert?: boolean\n displayEmptyByDefault?: boolean\n minChildren?: number | null\n maxChildren?: number | null\n allowPreferredValuesOnly?: boolean\n}\n\n/** A count after a Figma change: null clears it, undefined keeps the current one. */\nfunction count(change: number | null | undefined, current: number | undefined) {\n return change === null ? undefined : (change ?? current)\n}\n\n/** Apply Figma slot settings to a definition's own. */\nexport function mergeSlotSettings(\n current: SlotSettings | undefined,\n changes: FigmaSlotSettings\n): SlotSettings {\n const base = { ...DEFAULT_SLOT_SETTINGS, ...current }\n const next: SlotSettings = {\n stretchChildOnInsert: changes.stretchChildOnInsert ?? base.stretchChildOnInsert,\n displayEmptyByDefault: changes.displayEmptyByDefault ?? base.displayEmptyByDefault,\n allowPreferredValuesOnly: changes.allowPreferredValuesOnly ?? base.allowPreferredValuesOnly\n }\n const minChildren = count(changes.minChildren, base.minChildren)\n const maxChildren = count(changes.maxChildren, base.maxChildren)\n if (minChildren !== undefined) next.minChildren = minChildren\n if (maxChildren !== undefined) next.maxChildren = maxChildren\n return next\n}\n\nexport function figmaSlotSettings(settings: SlotSettings): FigmaSlotSettings {\n return {\n ...settings,\n minChildren: settings.minChildren ?? null,\n maxChildren: settings.maxChildren ?? null\n }\n}\n\nexport function assertSlotSettings(\n type: ComponentPropertyType,\n settings: FigmaSlotSettings | undefined\n): void {\n if (settings && type !== 'SLOT')\n throw new Error(\"slotSettings is only supported for 'SLOT' properties\")\n}\n\n/**\n * Ready a move of `childId` into `parentId` the way Figma's appendChild does: the locked part\n * of an instance refuses it, and a slot on either side becomes the instance's own content.\n */\nexport function prepareSlotMove(\n g: SceneGraph,\n parentId: string,\n childId: string,\n method: 'appendChild' | 'insertChild'\n): void {\n const sourceParentId = g.getNode(childId)?.parentId\n const source = sourceParentId ? slotScope(g, sourceParentId) : undefined\n prepareSlotInsertion(g, parentId, method)\n if (source?.kind === 'slot') claimSlotContent(g, source)\n}\n\n/**\n * Ready adding new layers under `parentId`, as a tool that builds layers in place does, by the\n * rule appendChild follows: the locked part of an instance refuses them, since its layers come\n * from the component, and a slot's content becomes the instance's own first.\n */\nexport function prepareSlotInsertion(g: SceneGraph, parentId: string, method: string): void {\n const target = slotScope(g, parentId)\n if (target.kind === 'locked')\n throw new Error(\n `in ${method}: Cannot move node. New parent is an instance or is inside of an instance`\n )\n if (target.kind === 'slot') claimSlotContent(g, target)\n}\n\n/**\n * Ready removing a layer the way Figma's remove() does: the locked part of an instance,\n * slot frames included, refuses it, and slot content becomes the instance's own first.\n */\nexport function prepareSlotRemoval(g: SceneGraph, nodeId: string): void {\n const parentId = g.getNode(nodeId)?.parentId\n if (!parentId) return\n const scope = slotScope(g, parentId)\n if (scope.kind === 'locked') throw new Error('in remove: Removing this node is not allowed')\n if (scope.kind === 'slot') claimSlotContent(g, scope)\n}\n\nfunction host(target: ProxyThis, internals: NodeProxyInternals): NodeProxyHost {\n return target[internals.api] as NodeProxyHost\n}\n\n/** The instance slot a proxy is, if it is the frame of one. */\nfunction instanceSlot(target: ProxyThis, internals: NodeProxyInternals) {\n const scope = slotScope(graph(target, internals), nodeId(target, internals))\n return scope.kind === 'slot' && scope.frame.id === nodeId(target, internals) ? scope : undefined\n}\n\n/** `ComponentNode.createSlot` and the `SlotNode` members Figma's plugin API defines. */\nexport function installSlotAccessors(prototype: object, internals: NodeProxyInternals): void {\n Object.defineProperties(prototype, {\n createSlot: {\n // Figma appends a 100×100 frame named Slot, Slot 2, … and a SLOT property of that name.\n value(this: ProxyThis) {\n const component = raw(this, internals)\n if (component.type !== 'COMPONENT')\n throw new Error('createSlot() can only be called on components')\n assertProxyEditable(this, internals)\n const g = graph(this, internals)\n const frame = g.createNode('FRAME', component.id, { name: 'Slot' })\n const definition = createSlotProperty(g, frame.id, createComponentPropertyId())\n if (!definition) throw new Error('Failed to create slot')\n g.updateNode(frame.id, { name: definition.name })\n return host(this, internals).wrapNode(frame.id)\n }\n },\n resetSlot: {\n value(this: ProxyThis) {\n if (!slotPropertyId(raw(this, internals)))\n throw new Error('resetSlot() can only be called on slots')\n assertProxyEditable(this, internals)\n const scope = instanceSlot(this, internals)\n if (scope) resetSlotContent(graph(this, internals), scope)\n }\n },\n limitViolations: {\n // Figma measures limits only where an instance shows the slot; a main component's slot\n // reports none.\n get(this: ProxyThis): SlotLimitViolation[] {\n const scope = instanceSlot(this, internals)\n if (!scope) return []\n const g = graph(this, internals)\n const definition = componentPropertyDefinitions(g, scope.instance).find(\n (item) => item.id === scope.propertyId\n )\n if (!definition) return []\n return slotLimitViolations(g, definition, g.getChildren(scope.frame.id))\n }\n }\n })\n}\n"],"mappings":";;;;;AA8BA,SAAS,MAAM,QAAmC,SAA6B;CAC7E,OAAO,WAAW,OAAO,KAAA,IAAa,UAAU;AAClD;;AAGA,SAAgB,kBACd,SACA,SACc;CACd,MAAM,OAAO;EAAE,GAAG;EAAuB,GAAG;CAAQ;CACpD,MAAM,OAAqB;EACzB,sBAAsB,QAAQ,wBAAwB,KAAK;EAC3D,uBAAuB,QAAQ,yBAAyB,KAAK;EAC7D,0BAA0B,QAAQ,4BAA4B,KAAK;CACrE;CACA,MAAM,cAAc,MAAM,QAAQ,aAAa,KAAK,WAAW;CAC/D,MAAM,cAAc,MAAM,QAAQ,aAAa,KAAK,WAAW;CAC/D,IAAI,gBAAgB,KAAA,GAAW,KAAK,cAAc;CAClD,IAAI,gBAAgB,KAAA,GAAW,KAAK,cAAc;CAClD,OAAO;AACT;AAEA,SAAgB,kBAAkB,UAA2C;CAC3E,OAAO;EACL,GAAG;EACH,aAAa,SAAS,eAAe;EACrC,aAAa,SAAS,eAAe;CACvC;AACF;AAEA,SAAgB,mBACd,MACA,UACM;CACN,IAAI,YAAY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AAM,SAAS;GACnC,MAAM,IAAI,MAAM,MAAM,SAAS;GAC/B,MAAM,QAAQ,EAAE,WAAW,SAAS,UAAU,IAAI,EAAE,MAAM,OAAO,CAAC;GAClE,MAAM,aAAa,mBAAmB,GAAG,MAAM,IAAI,0BAA0B,CAAC;GAC9E,IAAI,CAAC,YAAY,MAAM,IAAI,MAAM,uBAAuB;GACxD,EAAE,WAAW,MAAM,IAAI,EAAE,MAAM,WAAW,KAAK,CAAC;GAChD,OAAO,KAAK,MAAM,SAAS,CAAC,CAAC,SAAS,MAAM,EAAE;EAChD,EACF;EACA,WAAW,EACT,QAAuB;GACrB,IAAI,CAAC,eAAe,IAAI,MAAM,SAAS,CAAC,GACtC,MAAM,IAAI,MAAM,yCAAyC;GAC3D,oBAAoB,MAAM,SAAS;GACnC,MAAM,QAAQ,aAAa,MAAM,SAAS;GAC1C,IAAI,OAAO,iBAAiB,MAAM,MAAM,SAAS,GAAG,KAAK;EAC3D,EACF;EACA,iBAAiB,EAGf,MAA2C;GACzC,MAAM,QAAQ,aAAa,MAAM,SAAS;GAC1C,IAAI,CAAC,OAAO,OAAO,CAAC;GACpB,MAAM,IAAI,MAAM,MAAM,SAAS;GAC/B,MAAM,aAAa,6BAA6B,GAAG,MAAM,QAAQ,CAAC,CAAC,MAChE,SAAS,KAAK,OAAO,MAAM,UAC9B;GACA,IAAI,CAAC,YAAY,OAAO,CAAC;GACzB,OAAO,oBAAoB,GAAG,YAAY,EAAE,YAAY,MAAM,MAAM,EAAE,CAAC;EACzE,EACF;CACF,CAAC;AACH"}
@@ -2,12 +2,15 @@ import { SceneGraph, SceneNode, Stroke } from "@pairdraw/scene-graph";
2
2
  //#region src/figma-api/strokes.d.ts
3
3
  /**
4
4
  * Sets the weight of all of a node's strokes and the weight it keeps with none, as Figma's
5
- * node-level `strokeWeight` does; see `SceneNode.strokeWeight`.
5
+ * node-level `strokeWeight` does; the graph gives the strokes the layer's value
6
+ * (`strokeLineChanges`).
6
7
  */
7
8
  declare function setStrokeWeight(graph: SceneGraph, node: SceneNode, weight: number): void;
8
9
  /** Sets the alignment of all of a node's strokes and the one it keeps with none. */
9
10
  declare function setStrokeAlign(graph: SceneGraph, node: SceneNode, align: Stroke['align']): void;
11
+ /** Dashes the layer and every stroke on it. */
12
+ declare function setDashPattern(graph: SceneGraph, node: SceneNode, pattern: readonly number[]): void;
10
13
  declare function setIndependentStrokeWeight(graph: SceneGraph, nodeId: string, field: 'borderTopWeight' | 'borderRightWeight' | 'borderBottomWeight' | 'borderLeftWeight', value: number): void;
11
14
  //#endregion
12
- export { setIndependentStrokeWeight, setStrokeAlign, setStrokeWeight };
15
+ export { setDashPattern, setIndependentStrokeWeight, setStrokeAlign, setStrokeWeight };
13
16
  //# sourceMappingURL=strokes.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"strokes.d.ts","names":[],"sources":["../../src/figma-api/strokes.ts"],"mappings":";;;;;;iBAQgB,gBAAgB,OAAO,YAAY,MAAM,WAAW;;iBASpD,eAAe,OAAO,YAAY,MAAM,WAAW,OAAO;iBAQ1D,2BACd,OAAO,YACP,gBACA,4FACA"}
1
+ {"version":3,"file":"strokes.d.ts","names":[],"sources":["../../src/figma-api/strokes.ts"],"mappings":";;;;;;;iBAQgB,gBAAgB,OAAO,YAAY,MAAM,WAAW;;iBAMpD,eAAe,OAAO,YAAY,MAAM,WAAW,OAAO;;iBAM1D,eACd,OAAO,YACP,MAAM,WACN;iBAMc,2BACd,OAAO,YACP,gBACA,4FACA"}
@@ -1,30 +1,23 @@
1
- import { copyStroke } from "@pairdraw/scene-graph/copy";
2
1
  import { recordInstanceOverride } from "@pairdraw/scene-graph/instances";
3
2
  //#region src/figma-api/strokes.ts
4
3
  /**
5
4
  * Sets the weight of all of a node's strokes and the weight it keeps with none, as Figma's
6
- * node-level `strokeWeight` does; see `SceneNode.strokeWeight`.
5
+ * node-level `strokeWeight` does; the graph gives the strokes the layer's value
6
+ * (`strokeLineChanges`).
7
7
  */
8
8
  function setStrokeWeight(graph, node, weight) {
9
- graph.updateNode(node.id, {
10
- strokeWeight: weight,
11
- strokes: node.strokes.map((stroke) => ({
12
- ...copyStroke(stroke),
13
- weight
14
- }))
15
- });
16
- recordInstanceOverride(graph, node.id, ["strokes", "strokeWeight"]);
9
+ graph.updateNode(node.id, { strokeWeight: weight });
10
+ recordInstanceOverride(graph, node.id, ["strokeWeight"]);
17
11
  }
18
12
  /** Sets the alignment of all of a node's strokes and the one it keeps with none. */
19
13
  function setStrokeAlign(graph, node, align) {
20
- graph.updateNode(node.id, {
21
- strokeAlign: align,
22
- strokes: node.strokes.map((stroke) => ({
23
- ...copyStroke(stroke),
24
- align
25
- }))
26
- });
27
- recordInstanceOverride(graph, node.id, ["strokes", "strokeAlign"]);
14
+ graph.updateNode(node.id, { strokeAlign: align });
15
+ recordInstanceOverride(graph, node.id, ["strokeAlign"]);
16
+ }
17
+ /** Dashes the layer and every stroke on it. */
18
+ function setDashPattern(graph, node, pattern) {
19
+ graph.updateNode(node.id, { dashPattern: [...pattern] });
20
+ recordInstanceOverride(graph, node.id, ["dashPattern"]);
28
21
  }
29
22
  function setIndependentStrokeWeight(graph, nodeId, field, value) {
30
23
  graph.updateNode(nodeId, {
@@ -34,6 +27,6 @@ function setIndependentStrokeWeight(graph, nodeId, field, value) {
34
27
  recordInstanceOverride(graph, nodeId, [field, "independentStrokeWeights"]);
35
28
  }
36
29
  //#endregion
37
- export { setIndependentStrokeWeight, setStrokeAlign, setStrokeWeight };
30
+ export { setDashPattern, setIndependentStrokeWeight, setStrokeAlign, setStrokeWeight };
38
31
 
39
32
  //# sourceMappingURL=strokes.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"strokes.js","names":[],"sources":["../../src/figma-api/strokes.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, Stroke } from '@pairdraw/scene-graph'\nimport { copyStroke } from '@pairdraw/scene-graph/copy'\nimport { recordInstanceOverride } from '@pairdraw/scene-graph/instances'\n\n/**\n * Sets the weight of all of a node's strokes and the weight it keeps with none, as Figma's\n * node-level `strokeWeight` does; see `SceneNode.strokeWeight`.\n */\nexport function setStrokeWeight(graph: SceneGraph, node: SceneNode, weight: number): void {\n graph.updateNode(node.id, {\n strokeWeight: weight,\n strokes: node.strokes.map((stroke) => ({ ...copyStroke(stroke), weight }))\n })\n recordInstanceOverride(graph, node.id, ['strokes', 'strokeWeight'])\n}\n\n/** Sets the alignment of all of a node's strokes and the one it keeps with none. */\nexport function setStrokeAlign(graph: SceneGraph, node: SceneNode, align: Stroke['align']): void {\n graph.updateNode(node.id, {\n strokeAlign: align,\n strokes: node.strokes.map((stroke) => ({ ...copyStroke(stroke), align }))\n })\n recordInstanceOverride(graph, node.id, ['strokes', 'strokeAlign'])\n}\n\nexport function setIndependentStrokeWeight(\n graph: SceneGraph,\n nodeId: string,\n field: 'borderTopWeight' | 'borderRightWeight' | 'borderBottomWeight' | 'borderLeftWeight',\n value: number\n): void {\n graph.updateNode(nodeId, {\n [field]: value,\n independentStrokeWeights: true\n })\n recordInstanceOverride(graph, nodeId, [field, 'independentStrokeWeights'])\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,gBAAgB,OAAmB,MAAiB,QAAsB;CACxF,MAAM,WAAW,KAAK,IAAI;EACxB,cAAc;EACd,SAAS,KAAK,QAAQ,KAAK,YAAY;GAAE,GAAG,WAAW,MAAM;GAAG;EAAO,EAAE;CAC3E,CAAC;CACD,uBAAuB,OAAO,KAAK,IAAI,CAAC,WAAW,cAAc,CAAC;AACpE;;AAGA,SAAgB,eAAe,OAAmB,MAAiB,OAA8B;CAC/F,MAAM,WAAW,KAAK,IAAI;EACxB,aAAa;EACb,SAAS,KAAK,QAAQ,KAAK,YAAY;GAAE,GAAG,WAAW,MAAM;GAAG;EAAM,EAAE;CAC1E,CAAC;CACD,uBAAuB,OAAO,KAAK,IAAI,CAAC,WAAW,aAAa,CAAC;AACnE;AAEA,SAAgB,2BACd,OACA,QACA,OACA,OACM;CACN,MAAM,WAAW,QAAQ;GACtB,QAAQ;EACT,0BAA0B;CAC5B,CAAC;CACD,uBAAuB,OAAO,QAAQ,CAAC,OAAO,0BAA0B,CAAC;AAC3E"}
1
+ {"version":3,"file":"strokes.js","names":[],"sources":["../../src/figma-api/strokes.ts"],"sourcesContent":["import type { SceneGraph, SceneNode, Stroke } from '@pairdraw/scene-graph'\nimport { recordInstanceOverride } from '@pairdraw/scene-graph/instances'\n\n/**\n * Sets the weight of all of a node's strokes and the weight it keeps with none, as Figma's\n * node-level `strokeWeight` does; the graph gives the strokes the layer's value\n * (`strokeLineChanges`).\n */\nexport function setStrokeWeight(graph: SceneGraph, node: SceneNode, weight: number): void {\n graph.updateNode(node.id, { strokeWeight: weight })\n recordInstanceOverride(graph, node.id, ['strokeWeight'])\n}\n\n/** Sets the alignment of all of a node's strokes and the one it keeps with none. */\nexport function setStrokeAlign(graph: SceneGraph, node: SceneNode, align: Stroke['align']): void {\n graph.updateNode(node.id, { strokeAlign: align })\n recordInstanceOverride(graph, node.id, ['strokeAlign'])\n}\n\n/** Dashes the layer and every stroke on it. */\nexport function setDashPattern(\n graph: SceneGraph,\n node: SceneNode,\n pattern: readonly number[]\n): void {\n graph.updateNode(node.id, { dashPattern: [...pattern] })\n recordInstanceOverride(graph, node.id, ['dashPattern'])\n}\n\nexport function setIndependentStrokeWeight(\n graph: SceneGraph,\n nodeId: string,\n field: 'borderTopWeight' | 'borderRightWeight' | 'borderBottomWeight' | 'borderLeftWeight',\n value: number\n): void {\n graph.updateNode(nodeId, {\n [field]: value,\n independentStrokeWeights: true\n })\n recordInstanceOverride(graph, nodeId, [field, 'independentStrokeWeights'])\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,gBAAgB,OAAmB,MAAiB,QAAsB;CACxF,MAAM,WAAW,KAAK,IAAI,EAAE,cAAc,OAAO,CAAC;CAClD,uBAAuB,OAAO,KAAK,IAAI,CAAC,cAAc,CAAC;AACzD;;AAGA,SAAgB,eAAe,OAAmB,MAAiB,OAA8B;CAC/F,MAAM,WAAW,KAAK,IAAI,EAAE,aAAa,MAAM,CAAC;CAChD,uBAAuB,OAAO,KAAK,IAAI,CAAC,aAAa,CAAC;AACxD;;AAGA,SAAgB,eACd,OACA,MACA,SACM;CACN,MAAM,WAAW,KAAK,IAAI,EAAE,aAAa,CAAC,GAAG,OAAO,EAAE,CAAC;CACvD,uBAAuB,OAAO,KAAK,IAAI,CAAC,aAAa,CAAC;AACxD;AAEA,SAAgB,2BACd,OACA,QACA,OACA,OACM;CACN,MAAM,WAAW,QAAQ;GACtB,QAAQ;EACT,0BAA0B;CAC5B,CAAC;CACD,uBAAuB,OAAO,QAAQ,CAAC,OAAO,0BAA0B,CAAC;AAC3E"}
@@ -4,8 +4,8 @@ import { variableAlias } from "../variables/values.js";
4
4
  import { getStyleAt } from "../../text/style-runs.js";
5
5
  import { getStyledTextSegments } from "./style.js";
6
6
  import { copyFills } from "@pairdraw/scene-graph/copy";
7
- import { TEXT_BINDABLE_FIELDS } from "@pairdraw/scene-graph";
8
7
  import { SCALED_RUN_BINDING_FIELDS, boundNumberValue, variableBindingOwner } from "@pairdraw/scene-graph/variables";
8
+ import { TEXT_BINDABLE_FIELDS } from "@pairdraw/scene-graph";
9
9
  import { SHARED_TEXT_STYLE_FIELDS, getSharedStyles } from "@pairdraw/scene-graph/shared-styles";
10
10
  import { mapValues, omit, pick } from "es-toolkit/object";
11
11
  //#region src/figma-api/text/bindings.ts
@@ -1,3 +1,4 @@
1
+ import { InsertStyleSource } from "../../text/style-runs.js";
1
2
  import { SceneGraph, SceneNode, StyleRun, TextLength, TextParagraphSpacingField, TextParagraphStyle } from "@pairdraw/scene-graph";
2
3
  //#region src/figma-api/text/index.d.ts
3
4
  /** Figma's plugin API line height: automatic, or a size in pixels or percent of the font size. */
@@ -19,8 +20,6 @@ interface FigmaLetterSpacing {
19
20
  declare function lineHeightValue(value: unknown): TextLength | null;
20
21
  /** Accepts Figma's object, in its unit, or a bare number of pixels as earlier scripts wrote it. */
21
22
  declare function letterSpacingValue(value: unknown): TextLength;
22
- /** Which neighbour inserted characters copy their style from, as Figma's `insertCharacters` takes it. */
23
- type InsertStyleSource = 'BEFORE' | 'AFTER';
24
23
  /**
25
24
  * A text's style runs once its characters are replaced. Figma resets the styles applied to
26
25
  * character ranges, so the whole text keeps the style of its first character.
@@ -41,5 +40,5 @@ declare function getParagraphSpacing(node: SceneNode, field: TextParagraphSpacin
41
40
  /** Text replaced whole takes the first paragraph's list style throughout, as in Figma. */
42
41
  declare function paragraphStylesForCharacters(node: SceneNode, text: string): TextParagraphStyle[];
43
42
  //#endregion
44
- export { FigmaLetterSpacing, FigmaLineHeight, InsertStyleSource, deleteCharacters, getParagraphSpacing, getRangeIndentation, getRangeListOptions, getRangeParagraphSpacing, insertCharacters, letterSpacingValue, lineHeightValue, paragraphStylesForCharacters, setRangeIndentation, setRangeListOptions, setRangeParagraphSpacing, spacingProblem, styleRunsForCharacters };
43
+ export { FigmaLetterSpacing, FigmaLineHeight, type InsertStyleSource, deleteCharacters, getParagraphSpacing, getRangeIndentation, getRangeListOptions, getRangeParagraphSpacing, insertCharacters, letterSpacingValue, lineHeightValue, paragraphStylesForCharacters, setRangeIndentation, setRangeListOptions, setRangeParagraphSpacing, spacingProblem, styleRunsForCharacters };
45
44
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/figma-api/text/index.ts"],"mappings":";;;KAkCY;EAAoB;;EAAmB;EAA4B;;;UAE9D;EACf;EACA;;;;;;iBAwBc,gBAAgB,iBAAiB;;iBAkBjC,mBAAmB,iBAAiB;;KAgBxC;;;;;iBAmBI,uBAAuB,MAAM,WAAW,qBAAqB;iBAM7D,iBACd,OAAO,YACP,MAAM,WACN,eACA,oBACA,WAAU;iBAkDI,iBACd,OAAO,YACP,MAAM,WACN,eACA;iBAuCc,oBACd,MAAM,WACN,eACA,aACA,gBACC;iBAOa,oBACd,OAAO,YACP,MAAM,WACN,eACA,aACA,SAAS;iBAaK,oBACd,MAAM,WACN,eACA,aACA;iBAiBc,oBACd,OAAO,YACP,MAAM,WACN,eACA,aACA;;iBAoBc,eAAe;iBAIf,yBACd,MAAM,WACN,OAAO,2BACP,eACA,aACA;iBAMc,yBACd,OAAO,YACP,MAAM,WACN,OAAO,2BACP,eACA,aACA;;iBAcc,oBACd,MAAM,WACN,OAAO,2BACP;;iBAMc,6BAA6B,MAAM,WAAW,eAAe"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../../src/figma-api/text/index.ts"],"mappings":";;;;KAwCY;EAAoB;;EAAmB;EAA4B;;;UAE9D;EACf;EACA;;;;;;iBAwBc,gBAAgB,iBAAiB;;iBAkBjC,mBAAmB,iBAAiB;;;;;iBAuBpC,uBAAuB,MAAM,WAAW,qBAAqB;iBAM7D,iBACd,OAAO,YACP,MAAM,WACN,eACA,oBACA,WAAU;iBAkDI,iBACd,OAAO,YACP,MAAM,WACN,eACA;iBAuCc,oBACd,MAAM,WACN,eACA,aACA,gBACC;iBAOa,oBACd,OAAO,YACP,MAAM,WACN,eACA,aACA,SAAS;iBAaK,oBACd,MAAM,WACN,eACA,aACA;iBAiBc,oBACd,OAAO,YACP,MAAM,WACN,eACA,aACA;;iBAoBc,eAAe;iBAIf,yBACd,MAAM,WACN,OAAO,2BACP,eACA,aACA;iBAMc,yBACd,OAAO,YACP,MAAM,WACN,OAAO,2BACP,eACA,aACA;;iBAcc,oBACd,MAAM,WACN,OAAO,2BACP;;iBAMc,6BAA6B,MAAM,WAAW,eAAe"}
@@ -1,4 +1,4 @@
1
- import { adjustRunsForDelete, getStyleAt, insertRunsWithStyle } from "../../text/style-runs.js";
1
+ import { adjustRunsForDelete, getStyleAt, insertRunsWithStyle, insertedStyleAt } from "../../text/style-runs.js";
2
2
  import { invalid, received } from "../accessors/text/messages.js";
3
3
  import { assertTextRange } from "./style.js";
4
4
  import { assertTextFontsLoaded } from "../fonts/loaded.js";
@@ -48,16 +48,6 @@ function letterSpacingValue(value) {
48
48
  }
49
49
  const INSERT_STYLE_SOURCES = /* @__PURE__ */ new Set(["BEFORE", "AFTER"]);
50
50
  /**
51
- * The style inserted characters take, as Figma gives it: the preceding character's for `BEFORE`
52
- * and the following one's for `AFTER`, or the closest character's at either end of the text.
53
- */
54
- function insertedStyle(node, start, useStyle) {
55
- if (node.text.length === 0) return {};
56
- const preferred = useStyle === "BEFORE" ? start - 1 : start;
57
- const index = Math.min(Math.max(preferred, 0), node.text.length - 1);
58
- return getStyleAt(node.styleRuns, index);
59
- }
60
- /**
61
51
  * A text's style runs once its characters are replaced. Figma resets the styles applied to
62
52
  * character ranges, so the whole text keeps the style of its first character.
63
53
  */
@@ -76,7 +66,7 @@ function insertCharacters(graph, node, start, characters, useStyle = "BEFORE") {
76
66
  assertTextFontsLoaded("insertCharacters", node);
77
67
  const text = node.text.slice(0, start) + characters + node.text.slice(start);
78
68
  const textParagraphs = paragraphStylesAfterEdit(node.textParagraphs, node.text, start, start, characters);
79
- const styleRuns = insertRunsWithStyle(node.styleRuns, start, characters.length, insertedStyle(node, start, useStyle));
69
+ const styleRuns = insertRunsWithStyle(node.styleRuns, start, characters.length, insertedStyleAt(node.styleRuns, node.text.length, start, useStyle));
80
70
  graph.updateNode(node.id, {
81
71
  text,
82
72
  textParagraphs,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../../src/figma-api/text/index.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\nimport { upperFirst } from 'es-toolkit/string'\n\nimport type {\n SceneGraph,\n SceneNode,\n StyleRun,\n TextLength,\n TextParagraphSpacingField,\n TextParagraphStyle\n} from '@pairdraw/scene-graph'\nimport { recordInstanceOverride } from '@pairdraw/scene-graph/instances'\nimport {\n MAX_LIST_INDENTATION,\n paragraphIndexAt,\n paragraphStyleAt,\n paragraphStylesAfterEdit,\n paragraphStylesInRange,\n pixelLength,\n sharedParagraphSpacing,\n textParagraphRanges,\n trimParagraphStyles,\n withIndentation,\n withListType,\n withParagraphSpacing\n} from '@pairdraw/scene-graph/text'\n\nimport { invalid, received } from '#core/figma-api/accessors/text/messages'\nimport { assertTextFontsLoaded } from '#core/figma-api/fonts/loaded'\nimport { adjustRunsForDelete, getStyleAt, insertRunsWithStyle } from '#core/text/style-runs'\n\nimport { assertTextRange } from './style'\n\n/** Figma's plugin API line height: automatic, or a size in pixels or percent of the font size. */\nexport type FigmaLineHeight = { unit: 'AUTO' } | { unit: 'PIXELS' | 'PERCENT'; value: number }\n/** Figma's plugin API letter spacing, in pixels or percent of the font size. */\nexport interface FigmaLetterSpacing {\n unit: 'PIXELS' | 'PERCENT'\n value: number\n}\n\n/** Figma's complaint about a length's `.value`, or null when it is a number. */\nfunction amountProblem(amount: unknown): string | null {\n if (amount === undefined) return 'Required value missing at .value'\n // NaN is a number to typeof, but not to Figma's check.\n return typeof amount === 'number' && !Number.isNaN(amount)\n ? null\n : `Expected number, received ${received(amount)} at .value`\n}\n\n/** A length object a script passes to `method`, checked as Figma checks it. */\nfunction lengthObject(method: string, property: string, value: unknown) {\n if (typeof value !== 'object' || value === null) {\n throw invalid(method, `Expected object, received ${received(value)}`, property)\n }\n return value as { unit?: unknown; value?: unknown }\n}\n\n/**\n * Accepts Figma's object, kept in its unit so a percent follows the font size as in Figma, or a\n * bare number of pixels or `null` for automatic, as earlier Pairdraw scripts wrote it.\n */\nexport function lineHeightValue(value: unknown): TextLength | null {\n if (value === null) return null\n if (typeof value === 'number') return pixelLength(value)\n const length = lengthObject('set_lineHeight', 'lineHeight', value)\n if (length.unit === 'AUTO') return null\n if (length.unit !== 'PIXELS' && length.unit !== 'PERCENT') {\n throw invalid(\n 'set_lineHeight',\n 'Expected .unit to be one of the following: PIXELS, PERCENT, AUTO',\n 'lineHeight'\n )\n }\n const problem = amountProblem(length.value)\n if (problem) throw invalid('set_lineHeight', problem, 'lineHeight')\n return { unit: length.unit, value: length.value as number }\n}\n\n/** Accepts Figma's object, in its unit, or a bare number of pixels as earlier scripts wrote it. */\nexport function letterSpacingValue(value: unknown): TextLength {\n if (typeof value === 'number') return pixelLength(value)\n const length = lengthObject('set_letterSpacing', 'letterSpacing', value)\n const unitKnown = length.unit === 'PIXELS' || length.unit === 'PERCENT'\n // Figma lists every problem, the value's before the unit's.\n const problems = compact([\n amountProblem(length.value),\n unitKnown ? null : 'Invalid option: expected one of \"PIXELS\"|\"PERCENT\" at .unit'\n ])\n if (problems.length > 0) {\n throw invalid('set_letterSpacing', problems.join('\\n'), 'letterSpacing')\n }\n return { unit: length.unit as TextLength['unit'], value: length.value as number }\n}\n\n/** Which neighbour inserted characters copy their style from, as Figma's `insertCharacters` takes it. */\nexport type InsertStyleSource = 'BEFORE' | 'AFTER'\n\nconst INSERT_STYLE_SOURCES: ReadonlySet<string> = new Set(['BEFORE', 'AFTER'])\n\n/**\n * The style inserted characters take, as Figma gives it: the preceding character's for `BEFORE`\n * and the following one's for `AFTER`, or the closest character's at either end of the text.\n */\nfunction insertedStyle(node: SceneNode, start: number, useStyle: InsertStyleSource) {\n if (node.text.length === 0) return {}\n const preferred = useStyle === 'BEFORE' ? start - 1 : start\n const index = Math.min(Math.max(preferred, 0), node.text.length - 1)\n return getStyleAt(node.styleRuns, index)\n}\n\n/**\n * A text's style runs once its characters are replaced. Figma resets the styles applied to\n * character ranges, so the whole text keeps the style of its first character.\n */\nexport function styleRunsForCharacters(node: SceneNode, characters: string): StyleRun[] {\n const first = node.text.length > 0 ? getStyleAt(node.styleRuns, 0) : {}\n if (characters.length === 0 || Object.keys(first).length === 0) return []\n return [{ start: 0, length: characters.length, style: { ...first } }]\n}\n\nexport function insertCharacters(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n characters: string,\n useStyle: InsertStyleSource = 'BEFORE'\n): void {\n // Scripts are not type-checked, so the value is checked as Figma checks it.\n if (!INSERT_STYLE_SOURCES.has(useStyle)) {\n throw invalid(\n 'insertCharacters',\n 'Invalid option: expected one of \"BEFORE\"|\"AFTER\"',\n 'useStyle'\n )\n }\n assertEditPosition('insertCharacters', node, 'start', start)\n assertTextFontsLoaded('insertCharacters', node)\n const text = node.text.slice(0, start) + characters + node.text.slice(start)\n const textParagraphs = paragraphStylesAfterEdit(\n node.textParagraphs,\n node.text,\n start,\n start,\n characters\n )\n const styleRuns = insertRunsWithStyle(\n node.styleRuns,\n start,\n characters.length,\n insertedStyle(node, start, useStyle)\n )\n graph.updateNode(node.id, { text, textParagraphs, styleRuns })\n recordInstanceOverride(graph, node.id, ['text', 'textParagraphs', 'styleRuns'])\n}\n\n/**\n * A position an edit can use: an integer from 0 through the text length, the end included,\n * refused with Figma's messages.\n */\nfunction assertEditPosition(\n method: 'insertCharacters' | 'deleteCharacters',\n node: SceneNode,\n name: string,\n value: number\n) {\n if (!Number.isInteger(value)) throw invalid(method, 'Expected int, received number', name)\n if (value < 0) throw invalid(method, 'Too small: expected number to be >=0', name)\n if (value > node.text.length) {\n const verb = method === 'insertCharacters' ? 'insert' : 'delete'\n throw new Error(\n `in ${method}: Cannot ${verb} characters at index greater than the length of the text`\n )\n }\n}\n\nexport function deleteCharacters(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n end: number\n): void {\n assertEditPosition('deleteCharacters', node, 'start', start)\n assertEditPosition('deleteCharacters', node, 'end', end)\n if (end < start) {\n throw new Error('in deleteCharacters: deleteCharacters must have (start <= end)')\n }\n assertTextFontsLoaded('deleteCharacters', node)\n const text = node.text.slice(0, start) + node.text.slice(end)\n const textParagraphs = paragraphStylesAfterEdit(node.textParagraphs, node.text, start, end, '')\n const styleRuns = adjustRunsForDelete(node.styleRuns, start, end - start)\n graph.updateNode(node.id, { text, textParagraphs, styleRuns })\n recordInstanceOverride(graph, node.id, ['text', 'textParagraphs', 'styleRuns'])\n}\n\ntype ListType = TextListOptions['type']\nconst LIST_TYPES: ReadonlySet<string> = new Set<ListType>(['NONE', 'ORDERED', 'UNORDERED'])\n\n/** The styles of the paragraphs a range touches: a newline belongs to the paragraph it ends. */\nfunction rangeParagraphStyles(node: SceneNode, start: number, end: number): TextParagraphStyle[] {\n const first = paragraphIndexAt(node.text, start)\n const last = paragraphIndexAt(node.text, end - 1)\n return Array.from({ length: last - first + 1 }, (_, index) =>\n paragraphStyleAt(node.textParagraphs, first + index)\n )\n}\n\nfunction updateParagraphs(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n end: number,\n change: (style: TextParagraphStyle) => TextParagraphStyle\n): void {\n const textParagraphs = paragraphStylesInRange(node.textParagraphs, node.text, start, end, change)\n graph.updateNode(node.id, { textParagraphs })\n recordInstanceOverride(graph, node.id, ['textParagraphs'])\n}\n\nexport function getRangeListOptions(\n node: SceneNode,\n start: number,\n end: number,\n mixed: symbol\n): TextListOptions | symbol {\n assertTextRange('getRangeListOptions', node, start, end)\n const types = new Set(rangeParagraphStyles(node, start, end).map((style) => style.listType))\n const [type] = types\n return types.size === 1 ? { type } : mixed\n}\n\nexport function setRangeListOptions(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n end: number,\n options: TextListOptions\n): void {\n if (!LIST_TYPES.has(options.type)) {\n throw new Error(\n `in setRangeListOptions: Property \"options\" failed validation: Invalid enum value. ` +\n `Expected 'NONE' | 'ORDERED' | 'UNORDERED', received '${String(options.type)}' at .type`\n )\n }\n assertTextRange('setRangeListOptions', node, start, end)\n assertTextFontsLoaded('setRangeListOptions', node)\n updateParagraphs(graph, node, start, end, (style) => withListType(style, options.type))\n}\n\nexport function getRangeIndentation(\n node: SceneNode,\n start: number,\n end: number,\n mixed: symbol\n): number | symbol {\n assertTextRange('getRangeIndentation', node, start, end)\n const levels = new Set(rangeParagraphStyles(node, start, end).map((style) => style.indentation))\n const [level] = levels\n return levels.size === 1 ? level : mixed\n}\n\n/** What Figma reports about an indentation it rejects, or `null`. */\nfunction indentationProblem(level: number): string | null {\n if (!Number.isInteger(level)) return 'Expected integer, received float'\n if (level < 0) return 'Number must be greater than or equal to 0'\n if (level > MAX_LIST_INDENTATION)\n return `Number must be less than or equal to ${MAX_LIST_INDENTATION}`\n return null\n}\n\nexport function setRangeIndentation(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n end: number,\n level: number\n): void {\n const invalid = indentationProblem(level)\n if (invalid) {\n throw new Error(`in setRangeIndentation: Property \"indentation\" failed validation: ${invalid}`)\n }\n assertTextRange('setRangeIndentation', node, start, end)\n assertTextFontsLoaded('setRangeIndentation', node)\n updateParagraphs(graph, node, start, end, (style) => withIndentation(style, level))\n}\n\n/**\n * The paragraphs a spacing range reaches. Unlike list options, Figma counts the paragraph at the\n * range's end position too, so a range ending where a paragraph starts reaches it.\n */\nfunction spacingParagraphs(node: SceneNode, start: number, end: number): [number, number] {\n return [paragraphIndexAt(node.text, start), paragraphIndexAt(node.text, end)]\n}\n\n/** What Figma reports about a spacing it rejects, or `null`. */\nexport function spacingProblem(value: number): string | null {\n return value >= 0 ? null : 'Number must be greater than or equal to 0'\n}\n\nexport function getRangeParagraphSpacing(\n node: SceneNode,\n field: TextParagraphSpacingField,\n start: number,\n end: number,\n mixed: symbol\n): number | symbol {\n assertTextRange(`getRange${upperFirst(field)}`, node, start, end)\n return sharedParagraphSpacing(node, field, ...spacingParagraphs(node, start, end)) ?? mixed\n}\n\nexport function setRangeParagraphSpacing(\n graph: SceneGraph,\n node: SceneNode,\n field: TextParagraphSpacingField,\n start: number,\n end: number,\n value: number\n): void {\n const method = `setRange${upperFirst(field)}`\n const invalid = spacingProblem(value)\n if (invalid) throw new Error(`in ${method}: Property \"value\" failed validation: ${invalid}`)\n assertTextRange(method, node, start, end)\n assertTextFontsLoaded(method, node)\n // Ranges change the paragraphs of their characters; one more reaches the end position's.\n updateParagraphs(graph, node, start, end + 1, (style) =>\n withParagraphSpacing(style, field, value)\n )\n}\n\n/** A text's spacing: one value when every paragraph has it, `mixed` otherwise. */\nexport function getParagraphSpacing(\n node: SceneNode,\n field: TextParagraphSpacingField,\n mixed: symbol\n): number | symbol {\n return sharedParagraphSpacing(node, field) ?? mixed\n}\n\n/** Text replaced whole takes the first paragraph's list style throughout, as in Figma. */\nexport function paragraphStylesForCharacters(node: SceneNode, text: string): TextParagraphStyle[] {\n if (node.textParagraphs.length === 0) return []\n const first = paragraphStyleAt(node.textParagraphs, 0)\n const count = textParagraphRanges(text).length\n return trimParagraphStyles(\n Array.from({ length: count }, () => first),\n count\n )\n}\n"],"mappings":";;;;;;;;;;AA0CA,SAAS,cAAc,QAAgC;CACrD,IAAI,WAAW,KAAA,GAAW,OAAO;CAEjC,OAAO,OAAO,WAAW,YAAY,CAAC,OAAO,MAAM,MAAM,IACrD,OACA,6BAA6B,SAAS,MAAM,EAAE;AACpD;;AAGA,SAAS,aAAa,QAAgB,UAAkB,OAAgB;CACtE,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,MAAM,QAAQ,QAAQ,6BAA6B,SAAS,KAAK,KAAK,QAAQ;CAEhF,OAAO;AACT;;;;;AAMA,SAAgB,gBAAgB,OAAmC;CACjE,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,OAAO,UAAU,UAAU,OAAO,YAAY,KAAK;CACvD,MAAM,SAAS,aAAa,kBAAkB,cAAc,KAAK;CACjE,IAAI,OAAO,SAAS,QAAQ,OAAO;CACnC,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,WAC9C,MAAM,QACJ,kBACA,oEACA,YACF;CAEF,MAAM,UAAU,cAAc,OAAO,KAAK;CAC1C,IAAI,SAAS,MAAM,QAAQ,kBAAkB,SAAS,YAAY;CAClE,OAAO;EAAE,MAAM,OAAO;EAAM,OAAO,OAAO;CAAgB;AAC5D;;AAGA,SAAgB,mBAAmB,OAA4B;CAC7D,IAAI,OAAO,UAAU,UAAU,OAAO,YAAY,KAAK;CACvD,MAAM,SAAS,aAAa,qBAAqB,iBAAiB,KAAK;CACvE,MAAM,YAAY,OAAO,SAAS,YAAY,OAAO,SAAS;CAE9D,MAAM,WAAW,QAAQ,CACvB,cAAc,OAAO,KAAK,GAC1B,YAAY,OAAO,iEACrB,CAAC;CACD,IAAI,SAAS,SAAS,GACpB,MAAM,QAAQ,qBA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M,KAAK,EAAE,QAAQ,MAAM,SAAS,KAAK,GACzC,KACF;AACF"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../../src/figma-api/text/index.ts"],"sourcesContent":["import { compact } from 'es-toolkit/array'\nimport { upperFirst } from 'es-toolkit/string'\n\nimport type {\n SceneGraph,\n SceneNode,\n StyleRun,\n TextLength,\n TextParagraphSpacingField,\n TextParagraphStyle\n} from '@pairdraw/scene-graph'\nimport { recordInstanceOverride } from '@pairdraw/scene-graph/instances'\nimport {\n MAX_LIST_INDENTATION,\n paragraphIndexAt,\n paragraphStyleAt,\n paragraphStylesAfterEdit,\n paragraphStylesInRange,\n pixelLength,\n sharedParagraphSpacing,\n textParagraphRanges,\n trimParagraphStyles,\n withIndentation,\n withListType,\n withParagraphSpacing\n} from '@pairdraw/scene-graph/text'\n\nimport { invalid, received } from '#core/figma-api/accessors/text/messages'\nimport { assertTextFontsLoaded } from '#core/figma-api/fonts/loaded'\nimport {\n adjustRunsForDelete,\n getStyleAt,\n insertedStyleAt,\n insertRunsWithStyle,\n type InsertStyleSource\n} from '#core/text/style-runs'\n\nimport { assertTextRange } from './style'\n\n/** Figma's plugin API line height: automatic, or a size in pixels or percent of the font size. */\nexport type FigmaLineHeight = { unit: 'AUTO' } | { unit: 'PIXELS' | 'PERCENT'; value: number }\n/** Figma's plugin API letter spacing, in pixels or percent of the font size. */\nexport interface FigmaLetterSpacing {\n unit: 'PIXELS' | 'PERCENT'\n value: number\n}\n\n/** Figma's complaint about a length's `.value`, or null when it is a number. */\nfunction amountProblem(amount: unknown): string | null {\n if (amount === undefined) return 'Required value missing at .value'\n // NaN is a number to typeof, but not to Figma's check.\n return typeof amount === 'number' && !Number.isNaN(amount)\n ? null\n : `Expected number, received ${received(amount)} at .value`\n}\n\n/** A length object a script passes to `method`, checked as Figma checks it. */\nfunction lengthObject(method: string, property: string, value: unknown) {\n if (typeof value !== 'object' || value === null) {\n throw invalid(method, `Expected object, received ${received(value)}`, property)\n }\n return value as { unit?: unknown; value?: unknown }\n}\n\n/**\n * Accepts Figma's object, kept in its unit so a percent follows the font size as in Figma, or a\n * bare number of pixels or `null` for automatic, as earlier Pairdraw scripts wrote it.\n */\nexport function lineHeightValue(value: unknown): TextLength | null {\n if (value === null) return null\n if (typeof value === 'number') return pixelLength(value)\n const length = lengthObject('set_lineHeight', 'lineHeight', value)\n if (length.unit === 'AUTO') return null\n if (length.unit !== 'PIXELS' && length.unit !== 'PERCENT') {\n throw invalid(\n 'set_lineHeight',\n 'Expected .unit to be one of the following: PIXELS, PERCENT, AUTO',\n 'lineHeight'\n )\n }\n const problem = amountProblem(length.value)\n if (problem) throw invalid('set_lineHeight', problem, 'lineHeight')\n return { unit: length.unit, value: length.value as number }\n}\n\n/** Accepts Figma's object, in its unit, or a bare number of pixels as earlier scripts wrote it. */\nexport function letterSpacingValue(value: unknown): TextLength {\n if (typeof value === 'number') return pixelLength(value)\n const length = lengthObject('set_letterSpacing', 'letterSpacing', value)\n const unitKnown = length.unit === 'PIXELS' || length.unit === 'PERCENT'\n // Figma lists every problem, the value's before the unit's.\n const problems = compact([\n amountProblem(length.value),\n unitKnown ? null : 'Invalid option: expected one of \"PIXELS\"|\"PERCENT\" at .unit'\n ])\n if (problems.length > 0) {\n throw invalid('set_letterSpacing', problems.join('\\n'), 'letterSpacing')\n }\n return { unit: length.unit as TextLength['unit'], value: length.value as number }\n}\n\nexport type { InsertStyleSource }\n\nconst INSERT_STYLE_SOURCES: ReadonlySet<string> = new Set(['BEFORE', 'AFTER'])\n\n/**\n * A text's style runs once its characters are replaced. Figma resets the styles applied to\n * character ranges, so the whole text keeps the style of its first character.\n */\nexport function styleRunsForCharacters(node: SceneNode, characters: string): StyleRun[] {\n const first = node.text.length > 0 ? getStyleAt(node.styleRuns, 0) : {}\n if (characters.length === 0 || Object.keys(first).length === 0) return []\n return [{ start: 0, length: characters.length, style: { ...first } }]\n}\n\nexport function insertCharacters(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n characters: string,\n useStyle: InsertStyleSource = 'BEFORE'\n): void {\n // Scripts are not type-checked, so the value is checked as Figma checks it.\n if (!INSERT_STYLE_SOURCES.has(useStyle)) {\n throw invalid(\n 'insertCharacters',\n 'Invalid option: expected one of \"BEFORE\"|\"AFTER\"',\n 'useStyle'\n )\n }\n assertEditPosition('insertCharacters', node, 'start', start)\n assertTextFontsLoaded('insertCharacters', node)\n const text = node.text.slice(0, start) + characters + node.text.slice(start)\n const textParagraphs = paragraphStylesAfterEdit(\n node.textParagraphs,\n node.text,\n start,\n start,\n characters\n )\n const styleRuns = insertRunsWithStyle(\n node.styleRuns,\n start,\n characters.length,\n insertedStyleAt(node.styleRuns, node.text.length, start, useStyle)\n )\n graph.updateNode(node.id, { text, textParagraphs, styleRuns })\n recordInstanceOverride(graph, node.id, ['text', 'textParagraphs', 'styleRuns'])\n}\n\n/**\n * A position an edit can use: an integer from 0 through the text length, the end included,\n * refused with Figma's messages.\n */\nfunction assertEditPosition(\n method: 'insertCharacters' | 'deleteCharacters',\n node: SceneNode,\n name: string,\n value: number\n) {\n if (!Number.isInteger(value)) throw invalid(method, 'Expected int, received number', name)\n if (value < 0) throw invalid(method, 'Too small: expected number to be >=0', name)\n if (value > node.text.length) {\n const verb = method === 'insertCharacters' ? 'insert' : 'delete'\n throw new Error(\n `in ${method}: Cannot ${verb} characters at index greater than the length of the text`\n )\n }\n}\n\nexport function deleteCharacters(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n end: number\n): void {\n assertEditPosition('deleteCharacters', node, 'start', start)\n assertEditPosition('deleteCharacters', node, 'end', end)\n if (end < start) {\n throw new Error('in deleteCharacters: deleteCharacters must have (start <= end)')\n }\n assertTextFontsLoaded('deleteCharacters', node)\n const text = node.text.slice(0, start) + node.text.slice(end)\n const textParagraphs = paragraphStylesAfterEdit(node.textParagraphs, node.text, start, end, '')\n const styleRuns = adjustRunsForDelete(node.styleRuns, start, end - start)\n graph.updateNode(node.id, { text, textParagraphs, styleRuns })\n recordInstanceOverride(graph, node.id, ['text', 'textParagraphs', 'styleRuns'])\n}\n\ntype ListType = TextListOptions['type']\nconst LIST_TYPES: ReadonlySet<string> = new Set<ListType>(['NONE', 'ORDERED', 'UNORDERED'])\n\n/** The styles of the paragraphs a range touches: a newline belongs to the paragraph it ends. */\nfunction rangeParagraphStyles(node: SceneNode, start: number, end: number): TextParagraphStyle[] {\n const first = paragraphIndexAt(node.text, start)\n const last = paragraphIndexAt(node.text, end - 1)\n return Array.from({ length: last - first + 1 }, (_, index) =>\n paragraphStyleAt(node.textParagraphs, first + index)\n )\n}\n\nfunction updateParagraphs(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n end: number,\n change: (style: TextParagraphStyle) => TextParagraphStyle\n): void {\n const textParagraphs = paragraphStylesInRange(node.textParagraphs, node.text, start, end, change)\n graph.updateNode(node.id, { textParagraphs })\n recordInstanceOverride(graph, node.id, ['textParagraphs'])\n}\n\nexport function getRangeListOptions(\n node: SceneNode,\n start: number,\n end: number,\n mixed: symbol\n): TextListOptions | symbol {\n assertTextRange('getRangeListOptions', node, start, end)\n const types = new Set(rangeParagraphStyles(node, start, end).map((style) => style.listType))\n const [type] = types\n return types.size === 1 ? { type } : mixed\n}\n\nexport function setRangeListOptions(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n end: number,\n options: TextListOptions\n): void {\n if (!LIST_TYPES.has(options.type)) {\n throw new Error(\n `in setRangeListOptions: Property \"options\" failed validation: Invalid enum value. ` +\n `Expected 'NONE' | 'ORDERED' | 'UNORDERED', received '${String(options.type)}' at .type`\n )\n }\n assertTextRange('setRangeListOptions', node, start, end)\n assertTextFontsLoaded('setRangeListOptions', node)\n updateParagraphs(graph, node, start, end, (style) => withListType(style, options.type))\n}\n\nexport function getRangeIndentation(\n node: SceneNode,\n start: number,\n end: number,\n mixed: symbol\n): number | symbol {\n assertTextRange('getRangeIndentation', node, start, end)\n const levels = new Set(rangeParagraphStyles(node, start, end).map((style) => style.indentation))\n const [level] = levels\n return levels.size === 1 ? level : mixed\n}\n\n/** What Figma reports about an indentation it rejects, or `null`. */\nfunction indentationProblem(level: number): string | null {\n if (!Number.isInteger(level)) return 'Expected integer, received float'\n if (level < 0) return 'Number must be greater than or equal to 0'\n if (level > MAX_LIST_INDENTATION)\n return `Number must be less than or equal to ${MAX_LIST_INDENTATION}`\n return null\n}\n\nexport function setRangeIndentation(\n graph: SceneGraph,\n node: SceneNode,\n start: number,\n end: number,\n level: number\n): void {\n const invalid = indentationProblem(level)\n if (invalid) {\n throw new Error(`in setRangeIndentation: Property \"indentation\" failed validation: ${invalid}`)\n }\n assertTextRange('setRangeIndentation', node, start, end)\n assertTextFontsLoaded('setRangeIndentation', node)\n updateParagraphs(graph, node, start, end, (style) => withIndentation(style, level))\n}\n\n/**\n * The paragraphs a spacing range reaches. Unlike list options, Figma counts the paragraph at the\n * range's end position too, so a range ending where a paragraph starts reaches it.\n */\nfunction spacingParagraphs(node: SceneNode, start: number, end: number): [number, number] {\n return [paragraphIndexAt(node.text, start), paragraphIndexAt(node.text, end)]\n}\n\n/** What Figma reports about a spacing it rejects, or `null`. */\nexport function spacingProblem(value: number): string | null {\n return value >= 0 ? null : 'Number must be greater than or equal to 0'\n}\n\nexport function getRangeParagraphSpacing(\n node: SceneNode,\n field: TextParagraphSpacingField,\n start: number,\n end: number,\n mixed: symbol\n): number | symbol {\n assertTextRange(`getRange${upperFirst(field)}`, node, start, end)\n return sharedParagraphSpacing(node, field, ...spacingParagraphs(node, start, end)) ?? mixed\n}\n\nexport function setRangeParagraphSpacing(\n graph: SceneGraph,\n node: SceneNode,\n field: TextParagraphSpacingField,\n start: number,\n end: number,\n value: number\n): void {\n const method = `setRange${upperFirst(field)}`\n const invalid = spacingProblem(value)\n if (invalid) throw new Error(`in ${method}: Property \"value\" failed validation: ${invalid}`)\n assertTextRange(method, node, start, end)\n assertTextFontsLoaded(method, node)\n // Ranges change the paragraphs of their characters; one more reaches the end position's.\n updateParagraphs(graph, node, start, end + 1, (style) =>\n withParagraphSpacing(style, field, value)\n )\n}\n\n/** A text's spacing: one value when every paragraph has it, `mixed` otherwise. */\nexport function getParagraphSpacing(\n node: SceneNode,\n field: TextParagraphSpacingField,\n mixed: symbol\n): number | symbol {\n return sharedParagraphSpacing(node, field) ?? mixed\n}\n\n/** Text replaced whole takes the first paragraph's list style throughout, as in Figma. */\nexport function paragraphStylesForCharacters(node: SceneNode, text: string): TextParagraphStyle[] {\n if (node.textParagraphs.length === 0) return []\n const first = paragraphStyleAt(node.textParagraphs, 0)\n const count = textParagraphRanges(text).length\n return trimParagraphStyles(\n Array.from({ length: count }, () => first),\n count\n )\n}\n"],"mappings":";;;;;;;;;;AAgDA,SAAS,cAAc,QAAgC;CACrD,IAAI,WAAW,KAAA,GAAW,OAAO;CAEjC,OAAO,OAAO,WAAW,YAAY,CAAC,OAAO,MAAM,MAAM,IACrD,OACA,6BAA6B,SAAS,MAAM,EAAE;AACpD;;AAGA,SAAS,aAAa,QAAgB,UAAkB,OAAgB;CACtE,IAAI,OAAO,UAAU,YAAY,UAAU,MACzC,MAAM,QAAQ,QAAQ,6BAA6B,SAAS,KAAK,KAAK,QAAQ;CAEhF,OAAO;AACT;;;;;AAMA,SAAgB,gBAAgB,OAAmC;CACjE,IAAI,UAAU,MAAM,OAAO;CAC3B,IAAI,OAAO,UAAU,UAAU,OAAO,YAAY,KAAK;CACvD,MAAM,SAAS,aAAa,kBAAkB,cAAc,KAAK;CACjE,IAAI,OAAO,SAAS,QAAQ,OAAO;CACnC,IAAI,OAAO,SAAS,YAAY,OAAO,SAAS,WAC9C,MAAM,QACJ,kBACA,oEACA,YACF;CAEF,MAAM,UAAU,cAAc,OAAO,KAAK;CAC1C,IAAI,SAAS,MAAM,QAAQ,kBAAkB,SAAS,YAAY;CAClE,OAAO;EAAE,MAAM,OAAO;EAAM,OAAO,OAAO;CAAgB;AAC5D;;AAGA,SAAgB,mBAAmB,OAA4B;CAC7D,IAAI,OAAO,UAAU,UAAU,OAAO,YAAY,KAAK;CAC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,QAAQ,MAAM,SAAS,KAAK,GACzC,KACF;AACF"}
@@ -1,7 +1,7 @@
1
1
  import { reconcileVariableLayouts } from "../../layout/variables.js";
2
2
  import { variableAlias } from "./values.js";
3
- import { TEXT_BINDABLE_FIELDS } from "@pairdraw/scene-graph";
4
3
  import { independentCornerChanges, paintBindingTarget } from "@pairdraw/scene-graph/variables";
4
+ import { TEXT_BINDABLE_FIELDS } from "@pairdraw/scene-graph";
5
5
  import { uniq } from "es-toolkit/array";
6
6
  import { isEmptyObject } from "es-toolkit/predicate";
7
7
  import { recordInstanceOverride } from "@pairdraw/scene-graph/instances";
@@ -1 +1 @@
1
- {"version":3,"file":"variable.d.ts","names":[],"sources":["../../../src/figma-api/variables/variable.ts"],"mappings":";;;;KAmBY,qBACR,QAAQ;;iBAsBI,mBACd,OAAO,YACP,gBACA,cACA,sBACA;;iBAWc,mBACd,OAAO,YACP,UAAU,UACV,gBACA,OAAO;;cAQI;;WACF;WACA;EAGG,YAAA,OAAO,YAAY;MAW3B;MAIA,KAAK;MAML;MAIA,YAAY;MAIZ;MAIA,qBAAqB;MAIrB;MAIA;MAIA,gBAAgB;MAIhB,gBAAgB,eAAe;MAU/B,UAAU;;MAKV,OAAO,QAAQ;MAUf,cAAc,QAAQ,OAAO;EAIjC,sBAAsB,UAAU,oBAAoB;EAKpD,yBAAyB,UAAU;;EAOnC,gBAAgB,gBAAgB,UAAU;;EAO1C,mBAAmB;aAAqB;;IACtC,OAAO;IACP,cAAc;;EAchB;EAIA;;;;;;;;;cAYW;;WACF;WACA;WACA;EAGG,YAAA,OAAO,YAAY;MAW3B;MAIA,KAAK;MAIL;MAIA,SAAS;IAAQ;IAAgB;;MAIjC;MAIA;MAIA;;EAKJ,QAAQ;EAMR,WAAW,gBAAgB;;EAQ3B,WAAW;EAQX;EAIA;;;;MA3C6B;MAAc"}
1
+ {"version":3,"file":"variable.d.ts","names":[],"sources":["../../../src/figma-api/variables/variable.ts"],"mappings":";;;;KAmBY,qBACR,QAAQ;;iBAsBI,mBACd,OAAO,YACP,gBACA,cACA,sBACA;;iBAWc,mBACd,OAAO,YACP,UAAU,UACV,gBACA,OAAO;;cAQI;;WACF;WACA;EAGG,YAAA,OAAO,YAAY;MAW3B;MAIA,KAAK;MAML;MAIA,YAAY;MAIZ;MAIA,qBAAqB;MAIrB;MAIA;MAIA,gBAAgB;MAIhB,gBAAgB,eAAe;MAU/B,UAAU;;MAKV,OAAO,QAAQ;MAUf,cAAc,QAAQ,OAAO;EAIjC,sBAAsB,UAAU,oBAAoB;EAKpD,yBAAyB,UAAU;;EAOnC,gBAAgB,gBAAgB,UAAU;;EAO1C,mBAAmB;aAAqB;;IACtC,OAAO;IACP,cAAc;;EAchB;EAIA;;;;;;;;;cAYW;;WACF;WACA;WACA;EAGG,YAAA,OAAO,YAAY;MAW3B;MAIA,KAAK;MAIL;MAIA,SAAS;IAAQ;IAAgB;;MAKjC;MAIA;MAIA;;EAKJ,QAAQ;EAMR,WAAW,gBAAgB;;EAQ3B,WAAW;EAQX;EAIA;;;;MA5C6B;MAAc"}
@@ -1,7 +1,7 @@
1
1
  import { reconcileVariableLayouts } from "../../layout/variables.js";
2
2
  import { figmaVariableValue, storedVariableValue } from "./values.js";
3
+ import { modesInListedOrder, updateTokenExpression } from "@pairdraw/scene-graph/variables";
3
4
  import { VARIABLE_SCOPES } from "@pairdraw/scene-graph";
4
- import { updateTokenExpression } from "@pairdraw/scene-graph/variables";
5
5
  import { uniq } from "es-toolkit/array";
6
6
  //#region src/figma-api/variables/variable.ts
7
7
  /** The plugin API lists no font variation or transform scope, so those stay unread. */
@@ -162,7 +162,7 @@ var FigmaVariableCollection = class {
162
162
  return false;
163
163
  }
164
164
  get modes() {
165
- return this.#collection.modes.map(({ modeId, name }) => ({
165
+ return modesInListedOrder(this.#collection).map(({ modeId, name }) => ({
166
166
  modeId,
167
167
  name
168
168
  }));
@@ -1 +1 @@
1
- {"version":3,"file":"variable.js","names":["#graph","#variable","#collection"],"sources":["../../../src/figma-api/variables/variable.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\n\nimport {\n VARIABLE_SCOPES,\n type CodeSyntaxPlatform,\n type SceneGraph,\n type Variable,\n type VariableCollection,\n type VariableScope,\n type VariableType,\n type VariableValue\n} from '@pairdraw/scene-graph'\nimport { updateTokenExpression } from '@pairdraw/scene-graph/variables'\n\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport { figmaVariableValue, storedVariableValue, type FigmaVariableValue } from './values'\n\n/** Scopes as Figma's plugin API names them; the file calls a stroke colour scope `STROKE`. */\nexport type FigmaVariableScope =\n | Exclude<VariableScope, 'STROKE' | 'FONT_VARIATIONS' | 'TRANSFORM'>\n | 'STROKE_COLOR'\n\n/** The plugin API lists no font variation or transform scope, so those stay unread. */\nfunction figmaScope(scope: VariableScope): FigmaVariableScope[] {\n if (scope === 'STROKE') return ['STROKE_COLOR']\n if (scope === 'FONT_VARIATIONS' || scope === 'TRANSFORM') return []\n return [scope]\n}\n\nfunction documentScope(scope: FigmaVariableScope): VariableScope {\n if (scope === 'STROKE_COLOR') return 'STROKE'\n if (!(VARIABLE_SCOPES as readonly string[]).includes(scope)) {\n throw new Error(`in set_scopes: Pairdraw does not support the ${scope as string} scope`)\n }\n return scope\n}\n\n/** Figma refuses empty names and names with `.`, `{` or `}`, which its references reserve. */\nconst RESERVED_NAME_CHARACTERS = /[.{}]/\n\n/** Figma's checks for a variable name: not empty, not reserved, not taken in the collection. */\nexport function assertVariableName(\n graph: SceneGraph,\n method: string,\n name: string,\n collectionId: string,\n self?: string\n): void {\n if (name === '') throw new Error(`in ${method}: name cannot be empty`)\n if (RESERVED_NAME_CHARACTERS.test(name)) throw new Error(`in ${method}: invalid variable name`)\n const taken = graph.variableCollections\n .get(collectionId)\n ?.variableIds.some((id) => id !== self && graph.variables.get(id)?.name === name)\n if (taken) throw new Error(`in ${method}: duplicate variable name`)\n}\n\n/** Stores one mode's value and shows it on the layers that use the variable. */\nexport function writeVariableValue(\n graph: SceneGraph,\n variable: Variable,\n modeId: string,\n value: VariableValue\n): void {\n variable.valuesByMode[modeId] = structuredClone(value)\n updateTokenExpression(variable, modeId, value)\n reconcileVariableLayouts(graph, { variables: [variable.id] })\n}\n\n/** A variable as Figma's plugin API hands it out, reading and writing the document's. */\nexport class FigmaVariable {\n readonly id: string\n readonly remote = false\n readonly #graph: SceneGraph\n\n constructor(graph: SceneGraph, id: string) {\n this.#graph = graph\n this.id = id\n }\n\n get #variable(): Variable {\n const variable = this.#graph.variables.get(this.id)\n if (!variable) throw new Error(`Variable ${this.id} has been removed`)\n return variable\n }\n\n get name(): string {\n return this.#variable.name\n }\n\n set name(name: string) {\n const variable = this.#variable\n assertVariableName(this.#graph, 'set_name', name, variable.collectionId, variable.id)\n variable.name = name\n }\n\n get description(): string {\n return this.#variable.description\n }\n\n set description(description: string) {\n this.#variable.description = description\n }\n\n get hiddenFromPublishing(): boolean {\n return this.#variable.hiddenFromPublishing\n }\n\n set hiddenFromPublishing(hidden: boolean) {\n this.#variable.hiddenFromPublishing = hidden\n }\n\n get variableCollectionId(): string {\n return this.#variable.collectionId\n }\n\n get key(): string {\n return this.#variable.key ?? ''\n }\n\n get resolvedType(): VariableType {\n return this.#variable.type\n }\n\n get valuesByMode(): Record<string, FigmaVariableValue> {\n const variable = this.#variable\n return Object.fromEntries(\n Object.keys(variable.valuesByMode).map((modeId) => [\n modeId,\n figmaVariableValue(this.#graph, variable, modeId)\n ])\n )\n }\n\n get scopes(): FigmaVariableScope[] {\n return (this.#variable.scopes ?? ['ALL_SCOPES']).flatMap(figmaScope)\n }\n\n /** Scopes the plugin API cannot name stay, as the script never saw them. */\n set scopes(scopes: FigmaVariableScope[]) {\n const variable = this.#variable\n if (scopes.includes('ALL_SCOPES')) {\n delete variable.scopes\n return\n }\n const unnamed = (variable.scopes ?? []).filter((scope) => figmaScope(scope).length === 0)\n variable.scopes = uniq([...scopes.map(documentScope), ...unnamed])\n }\n\n get codeSyntax(): Partial<Record<CodeSyntaxPlatform, string>> {\n return { ...this.#variable.codeSyntax }\n }\n\n setVariableCodeSyntax(platform: CodeSyntaxPlatform, value: string): void {\n const variable = this.#variable\n variable.codeSyntax = { ...variable.codeSyntax, [platform]: value }\n }\n\n removeVariableCodeSyntax(platform: CodeSyntaxPlatform): void {\n const variable = this.#variable\n const { [platform]: _removed, ...rest } = variable.codeSyntax ?? {}\n variable.codeSyntax = rest\n }\n\n /** Sets one mode's value; a reference that would make the variable read itself is ignored. */\n setValueForMode(modeId: string, newValue: FigmaVariableValue): void {\n const variable = this.#variable\n const value = storedVariableValue(this.#graph, variable, modeId, newValue)\n if (value !== null) writeVariableValue(this.#graph, variable, modeId, value)\n }\n\n /** The value the variable gives `consumer`, in the modes that layer resolves. */\n resolveForConsumer(consumer: { readonly id: string }): {\n value: FigmaVariableValue\n resolvedType: VariableType\n } {\n const variable = this.#variable\n const value = this.#graph.resolveVariableForNode(consumer.id, variable.id)\n if (value !== undefined) {\n return {\n value: typeof value === 'object' ? { ...value } : value,\n resolvedType: variable.type\n }\n }\n const modeId = this.#graph.getNodeVariableModeId(consumer.id, variable.collectionId)\n return { value: figmaVariableValue(this.#graph, variable, modeId), resolvedType: variable.type }\n }\n\n remove(): void {\n this.#graph.removeVariable(this.#variable.id)\n }\n\n toJSON() {\n return {\n id: this.id,\n name: this.name,\n resolvedType: this.resolvedType,\n variableCollectionId: this.variableCollectionId,\n valuesByMode: this.valuesByMode\n }\n }\n}\n\n/** A variable collection as Figma's plugin API hands it out. */\nexport class FigmaVariableCollection {\n readonly id: string\n readonly remote = false\n readonly isExtension = false\n readonly #graph: SceneGraph\n\n constructor(graph: SceneGraph, id: string) {\n this.#graph = graph\n this.id = id\n }\n\n get #collection(): VariableCollection {\n const collection = this.#graph.variableCollections.get(this.id)\n if (!collection) throw new Error(`Variable collection ${this.id} has been removed`)\n return collection\n }\n\n get name(): string {\n return this.#collection.name\n }\n\n set name(name: string) {\n this.#collection.name = name\n }\n\n get hiddenFromPublishing(): boolean {\n return false\n }\n\n get modes(): Array<{ modeId: string; name: string }> {\n return this.#collection.modes.map(({ modeId, name }) => ({ modeId, name }))\n }\n\n get defaultModeId(): string {\n return this.#collection.defaultModeId\n }\n\n get variableIds(): string[] {\n return [...this.#collection.variableIds]\n }\n\n get key(): string {\n return this.#collection.key ?? ''\n }\n\n /** Adds a mode that starts with every variable's default-mode value, as Figma does. */\n addMode(name: string): string {\n const modeId = this.#graph.createMode(this.#collection.id, name)\n if (modeId === undefined) throw new Error('in addMode: Could not find variable collection')\n return modeId\n }\n\n renameMode(modeId: string, newName: string): void {\n const collection = this.#collection\n if (!collection.modes.some((mode) => mode.modeId === modeId))\n throw new Error('in renameMode: Could not find mode')\n this.#graph.renameMode(collection.id, modeId, newName)\n }\n\n /** Removes a mode; removing the default makes the next mode the default, as in Figma. */\n removeMode(modeId: string): void {\n const collection = this.#collection\n if (!collection.modes.some((mode) => mode.modeId === modeId))\n throw new Error('in removeMode: Could not find mode')\n this.#graph.removeMode(collection.id, modeId)\n reconcileVariableLayouts(this.#graph, { variables: collection.variableIds })\n }\n\n remove(): void {\n this.#graph.removeCollection(this.#collection.id)\n }\n\n toJSON() {\n return {\n id: this.id,\n name: this.name,\n modes: this.modes,\n defaultModeId: this.defaultModeId,\n variableIds: this.variableIds\n }\n }\n}\n"],"mappings":";;;;;;;AAwBA,SAAS,WAAW,OAA4C;CAC9D,IAAI,UAAU,UAAU,OAAO,CAAC,cAAc;CAC9C,IAAI,UAAU,qBAAqB,UAAU,aAAa,OAAO,CAAC;CAClE,OAAO,CAAC,KAAK;AACf;AAEA,SAAS,cAAc,OAA0C;CAC/D,IAAI,UAAU,gBAAgB,OAAO;CACrC,IAAI,CAAE,gBAAsC,SAAS,KAAK,GACxD,MAAM,IAAI,MAAM,gDAAgD,MAAgB,OAAO;CAEzF,OAAO;AACT;;AAGA,MAAM,2BAA2B;;AAGjC,SAAgB,mBACd,OACA,QACA,MACA,cACA,MACM;CACN,IAAI,SAAS,IAAI,MAAM,IAAI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ACjC;;CAGA,QAAQ,MAAsB;EAC5B,MAAM,SAAS,KAAKF,OAAO,WAAW,KAAKE,YAAY,IAAI,IAAI;EAC/D,IAAI,WAAW,KAAA,GAAW,MAAM,IAAI,MAAM,gDAAgD;EAC1F,OAAO;CACT;CAEA,WAAW,QAAgB,SAAuB;EAChD,MAAM,aAAa,KAAKA;EACxB,IAAI,CAAC,WAAW,MAAM,MAAM,SAAS,KAAK,WAAW,MAAM,GACzD,MAAM,IAAI,MAAM,oCAAoC;EACtD,KAAKF,OAAO,WAAW,WAAW,IAAI,QAAQ,OAAO;CACvD;;CAGA,WAAW,QAAsB;EAC/B,MAAM,aAAa,KAAKE;EACxB,IAAI,CAAC,WAAW,MAAM,MAAM,SAAS,KAAK,WAAW,MAAM,GACzD,MAAM,IAAI,MAAM,oCAAoC;EACtD,KAAKF,OAAO,WAAW,WAAW,IAAI,MAAM;EAC5C,yBAAyB,KAAKA,QAAQ,EAAE,WAAW,WAAW,YAAY,CAAC;CAC7E;CAEA,SAAe;EACb,KAAKA,OAAO,iBAAiB,KAAKE,YAAY,EAAE;CAClD;CAEA,SAAS;EACP,OAAO;GACL,IAAI,KAAK;GACT,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,eAAe,KAAK;GACpB,aAAa,KAAK;EACpB;CACF;AACF"}
1
+ {"version":3,"file":"variable.js","names":["#graph","#variable","#collection"],"sources":["../../../src/figma-api/variables/variable.ts"],"sourcesContent":["import { uniq } from 'es-toolkit/array'\n\nimport {\n VARIABLE_SCOPES,\n type CodeSyntaxPlatform,\n type SceneGraph,\n type Variable,\n type VariableCollection,\n type VariableScope,\n type VariableType,\n type VariableValue\n} from '@pairdraw/scene-graph'\nimport { modesInListedOrder, updateTokenExpression } from '@pairdraw/scene-graph/variables'\n\nimport { reconcileVariableLayouts } from '#core/layout/variables'\n\nimport { figmaVariableValue, storedVariableValue, type FigmaVariableValue } from './values'\n\n/** Scopes as Figma's plugin API names them; the file calls a stroke colour scope `STROKE`. */\nexport type FigmaVariableScope =\n | Exclude<VariableScope, 'STROKE' | 'FONT_VARIATIONS' | 'TRANSFORM'>\n | 'STROKE_COLOR'\n\n/** The plugin API lists no font variation or transform scope, so those stay unread. */\nfunction figmaScope(scope: VariableScope): FigmaVariableScope[] {\n if (scope === 'STROKE') return ['STROKE_COLOR']\n if (scope === 'FONT_VARIATIONS' || scope === 'TRANSFORM') return []\n return [scope]\n}\n\nfunction documentScope(scope: FigmaVariableScope): VariableScope {\n if (scope === 'STROKE_COLOR') return 'STROKE'\n if (!(VARIABLE_SCOPES as readonly string[]).includes(scope)) {\n throw new Error(`in set_scopes: Pairdraw does not support the ${scope as string} scope`)\n }\n return scope\n}\n\n/** Figma refuses empty names and names with `.`, `{` or `}`, which its references reserve. */\nconst RESERVED_NAME_CHARACTERS = /[.{}]/\n\n/** Figma's checks for a variable name: not empty, not reserved, not taken in the collection. */\nexport function assertVariableName(\n graph: SceneGraph,\n method: string,\n name: string,\n collectionId: string,\n self?: string\n): void {\n if (name === '') throw new Error(`in ${method}: name cannot be empty`)\n if (RESERVED_NAME_CHARACTERS.test(name)) throw new Error(`in ${method}: invalid variable name`)\n const taken = graph.variableCollections\n .get(collectionId)\n ?.variableIds.some((id) => id !== self && graph.variables.get(id)?.name === name)\n if (taken) throw new Error(`in ${method}: duplicate variable name`)\n}\n\n/** Stores one mode's value and shows it on the layers that use the variable. */\nexport function writeVariableValue(\n graph: SceneGraph,\n variable: Variable,\n modeId: string,\n value: VariableValue\n): void {\n variable.valuesByMode[modeId] = structuredClone(value)\n updateTokenExpression(variable, modeId, value)\n reconcileVariableLayouts(graph, { variables: [variable.id] })\n}\n\n/** A variable as Figma's plugin API hands it out, reading and writing the document's. */\nexport class FigmaVariable {\n readonly id: string\n readonly remote = false\n readonly #graph: SceneGraph\n\n constructor(graph: SceneGraph, id: string) {\n this.#graph = graph\n this.id = id\n }\n\n get #variable(): Variable {\n const variable = this.#graph.variables.get(this.id)\n if (!variable) throw new Error(`Variable ${this.id} has been removed`)\n return variable\n }\n\n get name(): string {\n return this.#variable.name\n }\n\n set name(name: string) {\n const variable = this.#variable\n assertVariableName(this.#graph, 'set_name', name, variable.collectionId, variable.id)\n variable.name = name\n }\n\n get description(): string {\n return this.#variable.description\n }\n\n set description(description: string) {\n this.#variable.description = description\n }\n\n get hiddenFromPublishing(): boolean {\n return this.#variable.hiddenFromPublishing\n }\n\n set hiddenFromPublishing(hidden: boolean) {\n this.#variable.hiddenFromPublishing = hidden\n }\n\n get variableCollectionId(): string {\n return this.#variable.collectionId\n }\n\n get key(): string {\n return this.#variable.key ?? ''\n }\n\n get resolvedType(): VariableType {\n return this.#variable.type\n }\n\n get valuesByMode(): Record<string, FigmaVariableValue> {\n const variable = this.#variable\n return Object.fromEntries(\n Object.keys(variable.valuesByMode).map((modeId) => [\n modeId,\n figmaVariableValue(this.#graph, variable, modeId)\n ])\n )\n }\n\n get scopes(): FigmaVariableScope[] {\n return (this.#variable.scopes ?? ['ALL_SCOPES']).flatMap(figmaScope)\n }\n\n /** Scopes the plugin API cannot name stay, as the script never saw them. */\n set scopes(scopes: FigmaVariableScope[]) {\n const variable = this.#variable\n if (scopes.includes('ALL_SCOPES')) {\n delete variable.scopes\n return\n }\n const unnamed = (variable.scopes ?? []).filter((scope) => figmaScope(scope).length === 0)\n variable.scopes = uniq([...scopes.map(documentScope), ...unnamed])\n }\n\n get codeSyntax(): Partial<Record<CodeSyntaxPlatform, string>> {\n return { ...this.#variable.codeSyntax }\n }\n\n setVariableCodeSyntax(platform: CodeSyntaxPlatform, value: string): void {\n const variable = this.#variable\n variable.codeSyntax = { ...variable.codeSyntax, [platform]: value }\n }\n\n removeVariableCodeSyntax(platform: CodeSyntaxPlatform): void {\n const variable = this.#variable\n const { [platform]: _removed, ...rest } = variable.codeSyntax ?? {}\n variable.codeSyntax = rest\n }\n\n /** Sets one mode's value; a reference that would make the variable read itself is ignored. */\n setValueForMode(modeId: string, newValue: FigmaVariableValue): void {\n const variable = this.#variable\n const value = storedVariableValue(this.#graph, variable, modeId, newValue)\n if (value !== null) writeVariableValue(this.#graph, variable, modeId, value)\n }\n\n /** The value the variable gives `consumer`, in the modes that layer resolves. */\n resolveForConsumer(consumer: { readonly id: string }): {\n value: FigmaVariableValue\n resolvedType: VariableType\n } {\n const variable = this.#variable\n const value = this.#graph.resolveVariableForNode(consumer.id, variable.id)\n if (value !== undefined) {\n return {\n value: typeof value === 'object' ? { ...value } : value,\n resolvedType: variable.type\n }\n }\n const modeId = this.#graph.getNodeVariableModeId(consumer.id, variable.collectionId)\n return { value: figmaVariableValue(this.#graph, variable, modeId), resolvedType: variable.type }\n }\n\n remove(): void {\n this.#graph.removeVariable(this.#variable.id)\n }\n\n toJSON() {\n return {\n id: this.id,\n name: this.name,\n resolvedType: this.resolvedType,\n variableCollectionId: this.variableCollectionId,\n valuesByMode: this.valuesByMode\n }\n }\n}\n\n/** A variable collection as Figma's plugin API hands it out. */\nexport class FigmaVariableCollection {\n readonly id: string\n readonly remote = false\n readonly isExtension = false\n readonly #graph: SceneGraph\n\n constructor(graph: SceneGraph, id: string) {\n this.#graph = graph\n this.id = id\n }\n\n get #collection(): VariableCollection {\n const collection = this.#graph.variableCollections.get(this.id)\n if (!collection) throw new Error(`Variable collection ${this.id} has been removed`)\n return collection\n }\n\n get name(): string {\n return this.#collection.name\n }\n\n set name(name: string) {\n this.#collection.name = name\n }\n\n get hiddenFromPublishing(): boolean {\n return false\n }\n\n get modes(): Array<{ modeId: string; name: string }> {\n // Figma lists a collection's modes by sort position, not by their saved array order.\n return modesInListedOrder(this.#collection).map(({ modeId, name }) => ({ modeId, name }))\n }\n\n get defaultModeId(): string {\n return this.#collection.defaultModeId\n }\n\n get variableIds(): string[] {\n return [...this.#collection.variableIds]\n }\n\n get key(): string {\n return this.#collection.key ?? ''\n }\n\n /** Adds a mode that starts with every variable's default-mode value, as Figma does. */\n addMode(name: string): string {\n const modeId = this.#graph.createMode(this.#collection.id, name)\n if (modeId === undefined) throw new Error('in addMode: Could not find variable collection')\n return modeId\n }\n\n renameMode(modeId: string, newName: string): void {\n const collection = this.#collection\n if (!collection.modes.some((mode) => mode.modeId === modeId))\n throw new Error('in renameMode: Could not find mode')\n this.#graph.renameMode(collection.id, modeId, newName)\n }\n\n /** Removes a mode; removing the default makes the next mode the default, as in Figma. */\n removeMode(modeId: string): void {\n const collection = this.#collection\n if (!collection.modes.some((mode) => mode.modeId === modeId))\n throw new Error('in removeMode: Could not find mode')\n this.#graph.removeMode(collection.id, modeId)\n reconcileVariableLayouts(this.#graph, { variables: collection.variableIds })\n }\n\n remove(): void {\n this.#graph.removeCollection(this.#collection.id)\n }\n\n toJSON() {\n return {\n id: this.id,\n name: this.name,\n modes: this.modes,\n defaultModeId: this.defaultModeId,\n variableIds: this.variableIds\n }\n }\n}\n"],"mappings":";;;;;;;AAwBA,SAAS,WAAW,OAA4C;CAC9D,IAAI,UAAU,UAAU,OAAO,CAAC,cAAc;CAC9C,IAAI,UAAU,qBAAqB,UAAU,aAAa,OAAO,CAAC;CAClE,OAAO,CAAC,KAAK;AACf;AAEA,SAAS,cAAc,OAA0C;CAC/D,IAAI,UAAU,gBAAgB,OAAO;CACrC,IAAI,CAAE,gBAAsC,SAAS,KAAK,GACxD,MAAM,IAAI,MAAM,gDAAgD,MAAgB,OAAO;CAEzF,OAAO;AACT;;AAGA,MAAM,2BAA2B;;AAGjC,SAAgB,mBACd,OACA,QACA,MACA,cACA,MACM;CACN,IAAI,SAAS,IAAI,MAAM,IAAI,MAAM,MAAM,OAAO,uBAAuB;CACrE,IAAI,yBAAyB,KAAK,IAAI,GAAG,MAAM,IAAI,MAAM,MAAM,OAAO,wBAAwB;CAI9F,IAHc,MAAM,oBACjB,IAAI,YAAY,CAAC,EAChB,YAAY,MAAM,OAAO,OAAO,QAAQ,MAAM,UAAU,IAAI,EAAE,CAAC,EAAE,SAAS,IAAI,GACvE,MAAM,IAAI,MAAM,MAAM,OAAO,0BAA0B;AACpE;;AAGA,SAAgB,mBACd,OACA,UACA,Q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,oCAAoC;EACtD,KAAKF,OAAO,WAAW,WAAW,IAAI,QAAQ,OAAO;CACvD;;CAGA,WAAW,QAAsB;EAC/B,MAAM,aAAa,KAAKE;EACxB,IAAI,CAAC,WAAW,MAAM,MAAM,SAAS,KAAK,WAAW,MAAM,GACzD,MAAM,IAAI,MAAM,oCAAoC;EACtD,KAAKF,OAAO,WAAW,WAAW,IAAI,MAAM;EAC5C,yBAAyB,KAAKA,QAAQ,EAAE,WAAW,WAAW,YAAY,CAAC;CAC7E;CAEA,SAAe;EACb,KAAKA,OAAO,iBAAiB,KAAKE,YAAY,EAAE;CAClD;CAEA,SAAS;EACP,OAAO;GACL,IAAI,KAAK;GACT,MAAM,KAAK;GACX,OAAO,KAAK;GACZ,eAAe,KAAK;GACpB,aAAa,KAAK;EACpB;CACF;AACF"}
@@ -2,6 +2,11 @@ import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
2
2
  import { Mat3 } from "@pairdraw/scene-graph/matrix";
3
3
  import { Vector } from "@pairdraw/scene-graph/primitives";
4
4
  //#region src/geometry/figma.d.ts
5
+ /**
6
+ * A number as Figma's Design panel and size label show it: rounded to two decimals, so 33.333
7
+ * reads 33.33 and 0.126 reads 0.13. The layer keeps its exact value.
8
+ */
9
+ declare function panelNumber(value: number): number;
5
10
  /**
6
11
  * Figma's rotation of a transform: counterclockwise degrees in (-180, 180]. The plugin API and the
7
12
  * properties panel both report it; our nodes store a clockwise angle about their center.
@@ -22,5 +27,5 @@ declare function panelPositionChange(node: SceneNode, graph: Pick<SceneGraph, 'g
22
27
  */
23
28
  declare function panelRotationChange(node: SceneNode, graph: Pick<SceneGraph, 'getNode'>, degrees: number): Pick<SceneNode, 'rotation'>;
24
29
  //#endregion
25
- export { figmaRotation, panelPosition, panelPositionChange, panelRotation, panelRotationChange };
30
+ export { figmaRotation, panelNumber, panelPosition, panelPositionChange, panelRotation, panelRotationChange };
26
31
  //# sourceMappingURL=figma.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"figma.d.ts","names":[],"sources":["../../src/geometry/figma.ts"],"mappings":";;;;;;;;iBAUgB,cAAc,QAAQ;;;;;iBAoBtB,cAAc,MAAM,WAAW,OAAO,KAAK,yBAAyB;;iBAWpE,cAAc,MAAM,WAAW,OAAO,KAAK;;iBAM3C,oBACd,MAAM,WACN,OAAO,KAAK,wBACZ,iBACA,gBACC,KAAK;;;;;iBAgBQ,oBACd,MAAM,WACN,OAAO,KAAK,wBACZ,kBACC,KAAK"}
1
+ {"version":3,"file":"figma.d.ts","names":[],"sources":["../../src/geometry/figma.ts"],"mappings":";;;;;;;;iBAUgB,YAAY;;;;;iBASZ,cAAc,QAAQ;;;;;iBAoBtB,cAAc,MAAM,WAAW,OAAO,KAAK,yBAAyB;;iBAWpE,cAAc,MAAM,WAAW,OAAO,KAAK;;iBAM3C,oBACd,MAAM,WACN,OAAO,KAAK,wBACZ,iBACA,gBACC,KAAK;;;;;iBAgBQ,oBACd,MAAM,WACN,OAAO,KAAK,wBACZ,kBACC,KAAK"}
@@ -3,6 +3,13 @@ import Matrix from "@pairdraw/scene-graph/matrix";
3
3
  import { FITTED_CONTAINER_TYPES } from "@pairdraw/scene-graph/node-defaults";
4
4
  //#region src/geometry/figma.ts
5
5
  /**
6
+ * A number as Figma's Design panel and size label show it: rounded to two decimals, so 33.333
7
+ * reads 33.33 and 0.126 reads 0.13. The layer keeps its exact value.
8
+ */
9
+ function panelNumber(value) {
10
+ return Math.round(value * 100) / 100 + 0;
11
+ }
12
+ /**
6
13
  * Figma's rotation of a transform: counterclockwise degrees in (-180, 180]. The plugin API and the
7
14
  * properties panel both report it; our nodes store a clockwise angle about their center.
8
15
  */
@@ -72,6 +79,6 @@ function panelRotationChange(node, graph, degrees) {
72
79
  return { rotation: node.rotation + (mirrored ? turn : -turn) };
73
80
  }
74
81
  //#endregion
75
- export { figmaRotation, panelPosition, panelPositionChange, panelRotation, panelRotationChange };
82
+ export { figmaRotation, panelNumber, panelPosition, panelPositionChange, panelRotation, panelRotationChange };
76
83
 
77
84
  //# sourceMappingURL=figma.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"figma.js","names":[],"sources":["../../src/geometry/figma.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { getAxisAlignedWorldBounds, getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport Matrix, { type Mat3 } from '@pairdraw/scene-graph/matrix'\nimport { FITTED_CONTAINER_TYPES } from '@pairdraw/scene-graph/node-defaults'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\n/**\n * Figma's rotation of a transform: counterclockwise degrees in (-180, 180]. The plugin API and the\n * properties panel both report it; our nodes store a clockwise angle about their center.\n */\nexport function figmaRotation(matrix: Mat3): number {\n const degrees = (Math.atan2(-matrix[3], matrix[0]) * 180) / Math.PI\n // Figma reports the angle a script set, not its floating-point round trip.\n const rounded = Math.round(degrees * 1e6) / 1e6\n return Math.abs(degrees - rounded) < 1e-9 ? rounded + 0 : degrees\n}\n\n/** The nearest ancestor that sets a coordinate space: groups and booleans set none. */\nfunction containerOf(node: SceneNode, graph: Pick<SceneGraph, 'getNode'>): SceneNode | undefined {\n let parent = node.parentId ? graph.getNode(node.parentId) : undefined\n while (parent && FITTED_CONTAINER_TYPES.has(parent.type)) {\n parent = parent.parentId ? graph.getNode(parent.parentId) : undefined\n }\n return parent\n}\n\n/**\n * X and Y as Figma's properties panel shows them: the top-left of the node's box on the canvas,\n * measured from its container's box, so a turned node reads where it starts on screen.\n */\nexport function panelPosition(node: SceneNode, graph: Pick<SceneGraph, 'getNode'>): Vector {\n const bounds = getAxisAlignedWorldBounds(node, graph)\n const container = containerOf(node, graph)\n const origin =\n container && container.type !== 'CANVAS'\n ? getAxisAlignedWorldBounds(container, graph)\n : { x: 0, y: 0 }\n return { x: bounds.x - origin.x, y: bounds.y - origin.y }\n}\n\n/** Rotation as Figma's properties panel shows it: on the canvas, counterclockwise, -180 as 180. */\nexport function panelRotation(node: SceneNode, graph: Pick<SceneGraph, 'getNode'>): number {\n const degrees = figmaRotation(getWorldMatrix(node, graph))\n return degrees === -180 ? 180 : degrees\n}\n\n/** The move that makes the panel show `value` for `axis`, as typing it in Figma's panel does. */\nexport function panelPositionChange(\n node: SceneNode,\n graph: Pick<SceneGraph, 'getNode'>,\n axis: 'x' | 'y',\n value: number\n): Pick<SceneNode, 'x' | 'y'> {\n const delta = value - panelPosition(node, graph)[axis]\n // The canvas move, in the axes of the node's parent.\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const parentWorld =\n parent && parent.type !== 'CANVAS' ? getWorldMatrix(parent, graph) : Matrix.identity()\n const linear = [parentWorld[0], parentWorld[1], 0, parentWorld[3], parentWorld[4], 0, 0, 0, 1]\n const toParent = Matrix.invert(linear) ?? Matrix.identity()\n const [dx, dy] = Matrix.mapPoints(toParent, axis === 'x' ? [delta, 0] : [0, delta])\n return { x: node.x + dx, y: node.y + dy }\n}\n\n/**\n * The turn that makes the panel show `degrees`: about the node's center, as Figma's panel turns\n * it. A flip on the node or its ancestors reverses which way the stored angle goes.\n */\nexport function panelRotationChange(\n node: SceneNode,\n graph: Pick<SceneGraph, 'getNode'>,\n degrees: number\n): Pick<SceneNode, 'rotation'> {\n const world = getWorldMatrix(node, graph)\n const mirrored = world[0] * world[4] - world[1] * world[3] < 0\n // The shortest way round, so the stored angle stays within a turn.\n const turn = ((((degrees - panelRotation(node, graph) + 180) % 360) + 360) % 360) - 180\n return { rotation: node.rotation + (mirrored ? turn : -turn) }\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,cAAc,QAAsB;CAClD,MAAM,UAAW,KAAK,MAAM,CAAC,OAAO,IAAI,OAAO,EAAE,IAAI,MAAO,KAAK;CAEjE,MAAM,UAAU,KAAK,MAAM,UAAU,GAAG,IAAI;CAC5C,OAAO,KAAK,IAAI,UAAU,OAAO,IAAI,OAAO,UAAU,IAAI;AAC5D;;AAGA,SAAS,YAAY,MAAiB,OAA2D;CAC/F,IAAI,SAAS,K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,MAAM,QAAQ,eAAe,MAAM,KAAK;CACxC,MAAM,WAAW,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK;CAE7D,MAAM,SAAW,UAAU,cAAc,MAAM,KAAK,IAAI,OAAO,MAAO,OAAO,MAAO;CACpF,OAAO,EAAE,UAAU,KAAK,YAAY,WAAW,OAAO,CAAC,MAAM;AAC/D"}
1
+ {"version":3,"file":"figma.js","names":[],"sources":["../../src/geometry/figma.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport { getAxisAlignedWorldBounds, getWorldMatrix } from '@pairdraw/scene-graph/coordinate'\nimport Matrix, { type Mat3 } from '@pairdraw/scene-graph/matrix'\nimport { FITTED_CONTAINER_TYPES } from '@pairdraw/scene-graph/node-defaults'\nimport type { Vector } from '@pairdraw/scene-graph/primitives'\n\n/**\n * A number as Figma's Design panel and size label show it: rounded to two decimals, so 33.333\n * reads 33.33 and 0.126 reads 0.13. The layer keeps its exact value.\n */\nexport function panelNumber(value: number): number {\n // A small negative value rounds to -0, which reads as 0.\n return Math.round(value * 100) / 100 + 0\n}\n\n/**\n * Figma's rotation of a transform: counterclockwise degrees in (-180, 180]. The plugin API and the\n * properties panel both report it; our nodes store a clockwise angle about their center.\n */\nexport function figmaRotation(matrix: Mat3): number {\n const degrees = (Math.atan2(-matrix[3], matrix[0]) * 180) / Math.PI\n // Figma reports the angle a script set, not its floating-point round trip.\n const rounded = Math.round(degrees * 1e6) / 1e6\n return Math.abs(degrees - rounded) < 1e-9 ? rounded + 0 : degrees\n}\n\n/** The nearest ancestor that sets a coordinate space: groups and booleans set none. */\nfunction containerOf(node: SceneNode, graph: Pick<SceneGraph, 'getNode'>): SceneNode | undefined {\n let parent = node.parentId ? graph.getNode(node.parentId) : undefined\n while (parent && FITTED_CONTAINER_TYPES.has(parent.type)) {\n parent = parent.parentId ? graph.getNode(parent.parentId) : undefined\n }\n return parent\n}\n\n/**\n * X and Y as Figma's properties panel shows them: the top-left of the node's box on the canvas,\n * measured from its container's box, so a turned node reads where it starts on screen.\n */\nexport function panelPosition(node: SceneNode, graph: Pick<SceneGraph, 'getNode'>): Vector {\n const bounds = getAxisAlignedWorldBounds(node, graph)\n const container = containerOf(node, graph)\n const origin =\n container && container.type !== 'CANVAS'\n ? getAxisAlignedWorldBounds(container, graph)\n : { x: 0, y: 0 }\n return { x: bounds.x - origin.x, y: bounds.y - origin.y }\n}\n\n/** Rotation as Figma's properties panel shows it: on the canvas, counterclockwise, -180 as 180. */\nexport function panelRotation(node: SceneNode, graph: Pick<SceneGraph, 'getNode'>): number {\n const degrees = figmaRotation(getWorldMatrix(node, graph))\n return degrees === -180 ? 180 : degrees\n}\n\n/** The move that makes the panel show `value` for `axis`, as typing it in Figma's panel does. */\nexport function panelPositionChange(\n node: SceneNode,\n graph: Pick<SceneGraph, 'getNode'>,\n axis: 'x' | 'y',\n value: number\n): Pick<SceneNode, 'x' | 'y'> {\n const delta = value - panelPosition(node, graph)[axis]\n // The canvas move, in the axes of the node's parent.\n const parent = node.parentId ? graph.getNode(node.parentId) : undefined\n const parentWorld =\n parent && parent.type !== 'CANVAS' ? getWorldMatrix(parent, graph) : Matrix.identity()\n const linear = [parentWorld[0], parentWorld[1], 0, parentWorld[3], parentWorld[4], 0, 0, 0, 1]\n const toParent = Matrix.invert(linear) ?? Matrix.identity()\n const [dx, dy] = Matrix.mapPoints(toParent, axis === 'x' ? [delta, 0] : [0, delta])\n return { x: node.x + dx, y: node.y + dy }\n}\n\n/**\n * The turn that makes the panel show `degrees`: about the node's center, as Figma's panel turns\n * it. A flip on the node or its ancestors reverses which way the stored angle goes.\n */\nexport function panelRotationChange(\n node: SceneNode,\n graph: Pick<SceneGraph, 'getNode'>,\n degrees: number\n): Pick<SceneNode, 'rotation'> {\n const world = getWorldMatrix(node, graph)\n const mirrored = world[0] * world[4] - world[1] * world[3] < 0\n // The shortest way round, so the stored angle stays within a turn.\n const turn = ((((degrees - panelRotation(node, graph) + 180) %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