@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":"index.js","names":["#fetch","#onPageChange","#onViewportChange","#onSelectionChange","#pageChange","images.createImage","images.imageByHash","images.fetchImage"],"sources":["../../src/figma-api/index.ts"],"sourcesContent":["import { fromUint8Array, isValid, toUint8Array } from 'js-base64'\n\nimport type { SceneGraph, SceneNode as CoreSceneNode, NodeType } from '@pairdraw/scene-graph'\nimport { createConnector, freeEndpoint } from '@pairdraw/scene-graph/connectors'\nimport { computeBounds } from '@pairdraw/scene-graph/geometry'\nimport type { GroupFitOptions } from '@pairdraw/scene-graph/group-bounds'\nimport type { Rect, Vector } from '@pairdraw/scene-graph/primitives'\n\nimport type { SkiaRenderer } from '#core/canvas'\nimport { groupFitOptions } from '#core/canvas/boolean'\nimport { IS_BROWSER, type InterfaceTheme } from '#core/constants'\nimport { newLayerDefaults } from '#core/editor/shapes/defaults'\nimport { booleanOperationPaints, createBooleanOperation } from '#core/editor/structure/boolean'\nimport { wrapNodes } from '#core/editor/structure/container-wrap'\nimport { ungroupNode } from '#core/editor/structure/group/ungroup'\nimport { setDefaultPageBackground } from '#core/figma-api/page-backgrounds'\nimport { defaultIcons, type IconProvider } from '#core/icons'\nimport type { RasterCodec } from '#core/io/formats/raster'\nimport { createSVGNodes } from '#core/io/formats/svg'\nimport { textAutoResizeChanges } from '#core/layout/text-auto-resize'\nimport { fontManager } from '#core/text/font/manager'\n\nimport { componentFromNode } from './components'\nimport { flattenSceneNodes } from './flatten'\nimport { loadFigmaFont } from './fonts/load'\nimport type { FigmaFontNameInput } from './fonts/names'\nimport { variationAxisTags } from './fonts/variations'\nimport * as images from './images'\nimport type {\n FigmaBooleanOperationNode,\n FigmaComponentNode,\n FigmaComponentSetNode,\n FigmaConnectorNode,\n FigmaEllipseNode,\n FigmaFrameNode,\n FigmaGroupNode,\n FigmaLineNode,\n FigmaPolygonNode,\n FigmaRectangleNode,\n FigmaSectionNode,\n FigmaShapeWithTextNode,\n FigmaStarNode,\n FigmaTextNode,\n FigmaVectorNode\n} from './node-types'\nimport { startPendingLayout } from './pending-layout'\nimport { FigmaNodeProxy, INTERNAL_ID, MIXED, type FigmaFont, type NodeProxyHost } from './proxy'\nimport { newShapeWithText } from './shape-with-text'\nimport type { ExportImageOptions } from './types'\nimport { figmaUtil } from './util'\nimport { FigmaVariablesAPI } from './variables'\nimport { combineComponentsAsVariants } from './variants'\n\nconst noop = () => undefined\n\n/** A view of the document: its centre point and its zoom. */\nexport interface FigmaViewport {\n center: Vector\n zoom: number\n}\n\n/** What a host passes to `FigmaAPI` beyond the document. */\nexport interface FigmaAPIOptions {\n /** Fetches the HTTP(S) URLs `figma.createImageAsync` loads; the global `fetch` by default. */\n fetch?: images.ImageFetch\n /**\n * Runs when a script puts the API on another page, so a host can show that page too. The host\n * owns which page is on screen, and a plugin that switches page expects to see it switched.\n */\n onPageChange?: (pageId: string) => void | Promise<void>\n /**\n * Runs when a script moves the viewport, so a host can show the same view. A host owns the\n * viewport on screen, and a plugin that pans or zooms expects to see the result.\n */\n onViewportChange?: (viewport: FigmaViewport) => void\n /**\n * The page the host already shows. Seeded here rather than assigned after construction, so a\n * plain tool call does not ask the host to switch to the page it is already on.\n */\n pageId?: string\n /**\n * The view the host already shows, seeded for the same reason: a tool that only reads or draws\n * must not move the viewport of whoever is looking at the document.\n */\n viewport?: FigmaViewport\n /**\n * Runs when a script sets the page selection, so a host can select those layers too. The host\n * owns which layers are selected on screen, and a plugin that selects expects to see them selected.\n */\n onSelectionChange?: (ids: readonly string[], pageId: string) => void\n /**\n * The selection the host already shows, seeded for the same reason as the page and the viewport:\n * a tool that only reads must not reselect what is already selected.\n */\n selection?: readonly string[]\n}\n\nexport { FigmaNodeProxy } from './proxy'\nexport { getPageBackgrounds, setPageBackgrounds } from './page-backgrounds'\nexport { flushPendingLayout } from './pending-layout'\nexport type { FigmaEffect } from './effects'\nexport type { ExportImageOptions } from './types'\nexport {\n ImageTooLargeError,\n MAX_IMAGE_FETCH_BYTES,\n readBoundedImage,\n type ImageFetch\n} from './images'\nexport {\n FigmaVariable,\n FigmaVariableCollection,\n FigmaVariablesAPI,\n type FigmaComposedColor,\n type FigmaVariableAlias,\n type FigmaVariableValue\n} from './variables'\nexport type {\n FigmaBooleanOperationNode,\n FigmaComponentNode,\n FigmaComponentSetNode,\n FigmaConnectorNode,\n FigmaEllipseNode,\n FigmaFrameNode,\n FigmaGroupNode,\n FigmaInstanceNode,\n FigmaLineNode,\n FigmaPolygonNode,\n FigmaRectangleNode,\n FigmaSectionNode,\n FigmaShapeWithTextNode,\n FigmaSlotNode,\n FigmaStarNode,\n FigmaTextNode,\n FigmaVectorNode\n} from './node-types'\nexport type { FigmaFont, FigmaFontName } from './proxy'\nexport type { FigmaFontNameInput } from './fonts/names'\nexport type { FigmaVariationSettings } from './fonts/variations'\n\n// TODO(figma-api): Implement the full official PluginAPI interface once our compatibility\n// layer covers all required node-specific return types and unsupported APIs are modeled explicitly.\nexport class FigmaAPI implements NodeProxyHost {\n readonly graph: SceneGraph\n private _currentPageId: string\n private _selection: FigmaNodeProxy[] = []\n private _nodeCache = new Map<string, FigmaNodeProxy>()\n private _pageProxies = new WeakSet<FigmaNodeProxy>()\n private _renderer: SkiaRenderer | null = null\n /** The interface theme new sections take their fill from, as in Figma. */\n theme: InterfaceTheme = 'light'\n\n readonly mixed = MIXED\n /** Figma's color and Markdown helpers, as `figma.util`. */\n readonly util: UtilAPI = figmaUtil\n /** The document's variables and collections, as Figma's `figma.variables`. */\n readonly variables: FigmaVariablesAPI\n\n /** How `createImageAsync` fetches HTTP(S) URLs; a host passes one that gets past CORS. */\n readonly #fetch: images.ImageFetch\n readonly #onPageChange: ((pageId: string) => void | Promise<void>) | undefined\n readonly #onViewportChange: ((viewport: FigmaViewport) => void) | undefined\n readonly #onSelectionChange: ((ids: readonly string[], pageId: string) => void) | undefined\n /** The last host page switch, so `setCurrentPageAsync` can wait for it. */\n #pageChange: Promise<void> = Promise.resolve()\n\n constructor(graph: SceneGraph, options: FigmaAPIOptions = {}) {\n this.graph = graph\n this.#fetch = options.fetch ?? ((input, init) => fetch(input, init))\n this.#onPageChange = options.onPageChange\n this.#onViewportChange = options.onViewportChange\n this.#onSelectionChange = options.onSelectionChange\n this.variables = new FigmaVariablesAPI(graph)\n startPendingLayout(graph)\n this._currentPageId = pageIdToStart(graph, options.pageId)\n if (options.viewport) {\n this._viewport = {\n x: options.viewport.center.x,\n y: options.viewport.center.y,\n zoom: options.viewport.zoom\n }\n }\n // Seeded here, not assigned through the setter, so a tool that only reads does not ask the\n // host to select the layers it is already showing.\n this._selection = (options.selection ?? []).flatMap((id) =>\n this.graph.getNode(id) ? [this.wrapNode(id)] : []\n )\n }\n\n setRenderer(renderer: SkiaRenderer | null): void {\n this._renderer = renderer\n }\n\n get groupFitOptions(): GroupFitOptions {\n return groupFitOptions(this._renderer, this.graph)\n }\n\n get currentPageId(): string {\n return this._currentPageId\n }\n\n wrapNode(id: string): FigmaNodeProxy {\n let proxy = this._nodeCache.get(id)\n if (!proxy) {\n proxy = new FigmaNodeProxy(id, this.graph, this)\n this._nodeCache.set(id, proxy)\n }\n return proxy\n }\n\n private _ensurePageProxy(\n proxy: FigmaNodeProxy\n ): FigmaNodeProxy & { selection: FigmaNodeProxy[] } {\n if (!this._pageProxies.has(proxy)) {\n Object.defineProperty(proxy, 'selection', {\n get: () => this._selection,\n set: (nodes: FigmaNodeProxy[]) => {\n const next = nodes.map((node) => node[INTERNAL_ID])\n const current = this._selection.map((node) => node[INTERNAL_ID])\n this._selection = nodes\n if (next.length === current.length && next.every((id, index) => id === current[index]))\n return\n this.#onSelectionChange?.(next, this._currentPageId)\n },\n enumerable: true,\n configurable: true\n })\n this._pageProxies.add(proxy)\n }\n return proxy as FigmaNodeProxy & { selection: FigmaNodeProxy[] }\n }\n\n get root(): FigmaNodeProxy {\n return this.wrapNode(this.graph.rootId)\n }\n\n get currentPage(): FigmaNodeProxy & { selection: FigmaNodeProxy[] } {\n return this._ensurePageProxy(this.wrapNode(this._currentPageId))\n }\n\n set currentPage(page: FigmaNodeProxy) {\n const pageId = page[INTERNAL_ID]\n if (pageId === this._currentPageId) return\n this._currentPageId = pageId\n this.#pageChange = Promise.resolve(this.#onPageChange?.(pageId))\n }\n\n getNodeById(id: string): FigmaNodeProxy | null {\n const node = this.graph.getNode(id)\n return node ? this.wrapNode(id) : null\n }\n\n /** The async lookup that Figma requires in dynamic-page mode; same result as getNodeById. */\n async getNodeByIdAsync(id: string): Promise<FigmaNodeProxy | null> {\n return this.getNodeById(id)\n }\n\n /**\n * The page switch Figma requires in dynamic-page mode, which sets `currentPage`. As in Figma, a\n * missing node throws at once and a node that is no page rejects.\n */\n setCurrentPageAsync(page: FigmaNodeProxy): Promise<void>\n setCurrentPageAsync(page: PageNode): Promise<void>\n // Scripts are not type-checked, so the call checks for a missing node as Figma does.\n setCurrentPageAsync(page: PageNode | FigmaNodeProxy | null | undefined): Promise<void> {\n if (page == null) throw new Error(`in setCurrentPageAsync: Expected node, got ${String(page)}`)\n if (this._rawNode(page).type !== 'CANVAS') {\n return Promise.reject(new Error('figma.setCurrentPageAsync expects a PageNode'))\n }\n this._currentPageId = this._nodeId(page)\n this.#pageChange = Promise.resolve(this.#onPageChange?.(this._currentPageId))\n return this.#pageChange\n }\n\n // --- Node Creation ---\n\n /** New layers start as the editor's tools make them, which is how Figma's plugin API makes them. */\n private _createNode(type: NodeType): FigmaNodeProxy {\n const defaults = newLayerDefaults(type, this.theme)\n // Figma's plugin API makes a line with no height, a 496 px section, and a hugging frame.\n if (type === 'LINE') defaults.height = 0\n if (type === 'SECTION') Object.assign(defaults, { width: 496, height: 496 })\n if (type === 'FRAME' || type === 'COMPONENT') defaults.primaryAxisSizing = 'HUG'\n const node = this.graph.createNode(type, this._currentPageId, defaults)\n return this.wrapNode(node.id)\n }\n\n createFrame(): FigmaFrameNode {\n return this._createNode('FRAME') as FigmaFrameNode\n }\n\n createRectangle(): FigmaRectangleNode {\n return this._createNode('RECTANGLE') as FigmaRectangleNode\n }\n\n createEllipse(): FigmaEllipseNode {\n return this._createNode('ELLIPSE') as FigmaEllipseNode\n }\n\n createText(): FigmaTextNode {\n const text = this._createNode('TEXT') as FigmaTextNode\n // Figma's plugin text starts empty at 12px and sizes itself to its content: no width, one\n // line tall.\n const node = this.graph.getNode(text.id)\n const defaults = { fontSize: 12, textAutoResize: 'WIDTH_AND_HEIGHT' as const, width: 0 }\n this.graph.updateNode(text.id, { ...defaults, ...textAutoResizeChanges(node, defaults) })\n return text\n }\n\n createLine(): FigmaLineNode {\n return this._createNode('LINE') as FigmaLineNode\n }\n\n createPolygon(): FigmaPolygonNode {\n return this._createNode('POLYGON') as FigmaPolygonNode\n }\n\n createStar(): FigmaStarNode {\n return this._createNode('STAR') as FigmaStarNode\n }\n\n createShapeWithText(): FigmaShapeWithTextNode {\n return this.wrapNode(newShapeWithText(this).id) as FigmaShapeWithTextNode\n }\n\n createVector(): FigmaVectorNode {\n return this._createNode('VECTOR') as FigmaVectorNode\n }\n\n /** The layers Figma makes from SVG markup, on the current page at its origin. */\n // eslint-disable-next-line pairdraw/no-mixed-case-acronym-identifiers -- Figma Plugin API name.\n createNodeFromSvg(svg: string): FigmaFrameNode {\n const node = createSVGNodes(this.graph, this._currentPageId, svg, { keepEmpty: true })\n if (!node) throw new Error('in createNodeFromSvg: Failed to convert SVG file')\n return this.wrapNode(node.id) as FigmaFrameNode\n }\n\n /**\n * A connector as Figma's plugin API makes one: \"Connector line\", free from the page origin to\n * 200 px right of it, with no start cap and an arrow at the end.\n */\n createConnector(): FigmaConnectorNode {\n const node = createConnector(this.graph, this._currentPageId, {\n start: freeEndpoint(0, 0),\n end: freeEndpoint(200, 0),\n startCap: 'NONE',\n endCap: 'ARROW_LINES'\n })\n return this.wrapNode(node.id) as FigmaConnectorNode\n }\n\n createComponent(): FigmaComponentNode {\n return this._createNode('COMPONENT') as FigmaComponentNode\n }\n\n createSection(): FigmaSectionNode {\n return this._createNode('SECTION') as FigmaSectionNode\n }\n\n createPage(): FigmaNodeProxy {\n const page = this.graph.addPage('Page')\n setDefaultPageBackground(this.graph, page, this.theme)\n return this.wrapNode(page.id)\n }\n\n // --- Grouping ---\n\n private _nodeId(node: BaseNode | FigmaNodeProxy): string {\n return (node as BaseNode & { [INTERNAL_ID]: string })[INTERNAL_ID]\n }\n\n private _rawNode(node: BaseNode | FigmaNodeProxy): CoreSceneNode {\n const id = this._nodeId(node)\n const raw = this.graph.getNode(id)\n if (!raw) throw new Error(`Node ${id} not found`)\n return raw\n }\n\n group(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaGroupNode\n group(nodes: ReadonlyArray<BaseNode>, parent: BaseNode & ChildrenMixin, index?: number): GroupNode\n group(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaGroupNode {\n const parentId = this._nodeId(parent)\n const members = nodes.map((node) => this._rawNode(node))\n const groupNode = wrapNodes(this.graph, 'GROUP', members, parentId, index)\n return this.wrapNode(groupNode.id) as FigmaGroupNode\n }\n\n ungroup(node: FigmaNodeProxy): FigmaNodeProxy[]\n ungroup(node: SceneNode & ChildrenMixin): Array<SceneNode>\n ungroup(node: (SceneNode & ChildrenMixin) | FigmaNodeProxy): Array<SceneNode> | FigmaNodeProxy[] {\n const children = ungroupNode(this.graph, this._nodeId(node)) ?? []\n return children.map((id) => this.wrapNode(id))\n }\n\n createComponentFromNode(node: FigmaNodeProxy): FigmaNodeProxy {\n const raw = this.graph.getNode(node[INTERNAL_ID])\n if (!raw) throw new Error('Node not found')\n return this.wrapNode(componentFromNode(this.graph, raw, raw.parentId ?? this._currentPageId).id)\n }\n\n combineAsVariants(\n nodes: ReadonlyArray<FigmaComponentNode>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaComponentSetNode\n combineAsVariants(\n nodes: ReadonlyArray<ComponentNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): ComponentSetNode\n combineAsVariants(\n nodes: ReadonlyArray<ComponentNode | FigmaComponentNode>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaComponentSetNode {\n const componentSet = combineComponentsAsVariants(\n this.graph,\n nodes.map((node) => this._nodeId(node)),\n this._nodeId(parent),\n index\n )\n return this.wrapNode(componentSet.id) as FigmaComponentSetNode\n }\n\n // --- Boolean Operations ---\n\n private _booleanOperation(\n operation: 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'EXCLUDE',\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n if (nodes.length < 2) throw new Error('Need at least 2 nodes for boolean operation')\n const parentId = this._nodeId(parent)\n const members = nodes.map((node) => this._rawNode(node))\n const { node: group } = createBooleanOperation(\n this.graph,\n members,\n parentId,\n operation,\n index,\n booleanOperationPaints(operation, members, 'script'),\n this.groupFitOptions\n )\n return this.wrapNode(group.id) as FigmaBooleanOperationNode\n }\n\n union(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode\n union(\n nodes: ReadonlyArray<BaseNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): BooleanOperationNode\n union(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n return this._booleanOperation('UNION', nodes, parent, index)\n }\n\n subtract(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode\n subtract(\n nodes: ReadonlyArray<BaseNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): BooleanOperationNode\n subtract(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n return this._booleanOperation('SUBTRACT', nodes, parent, index)\n }\n\n intersect(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode\n intersect(\n nodes: ReadonlyArray<BaseNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): BooleanOperationNode\n intersect(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n return this._booleanOperation('INTERSECT', nodes, parent, index)\n }\n\n exclude(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode\n exclude(\n nodes: ReadonlyArray<BaseNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): BooleanOperationNode\n exclude(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n return this._booleanOperation('EXCLUDE', nodes, parent, index)\n }\n\n // --- Flatten ---\n\n flatten(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent?: FigmaNodeProxy,\n index?: number\n ): FigmaVectorNode\n flatten(\n nodes: ReadonlyArray<BaseNode>,\n parent?: BaseNode & ChildrenMixin,\n index?: number\n ): VectorNode\n flatten(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent?: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaVectorNode {\n if (nodes.length === 0) throw new Error('Need at least 1 node to flatten')\n const parentId = this._nodeId(parent ?? this.currentPage)\n const sourceNodes: CoreSceneNode[] = []\n for (const node of nodes) {\n const raw = this.graph.getNode(this._nodeId(node))\n if (!raw) throw new Error('Node not found')\n sourceNodes.push(raw)\n }\n const vector = flattenSceneNodes(this.graph, this._renderer, sourceNodes, parentId)\n if (index != null) this.graph.insertChildAt(vector.id, parentId, index)\n for (const node of nodes) {\n this.graph.deleteNode(this._nodeId(node))\n }\n return this.wrapNode(vector.id) as FigmaVectorNode\n }\n\n // --- Viewport ---\n\n private _viewport = { x: 0, y: 0, zoom: 1 }\n\n get viewport(): FigmaViewport & {\n scrollAndZoomIntoView: (nodes: readonly { absoluteBoundingBox: Rect }[]) => void\n } {\n return {\n center: { x: this._viewport.x, y: this._viewport.y },\n zoom: this._viewport.zoom,\n scrollAndZoomIntoView: (nodes) => {\n const b = computeBounds(nodes.map((n) => n.absoluteBoundingBox))\n if (b.width === 0 && b.height === 0 && nodes.length === 0) return\n\n const padding = 80\n const contentW = b.width + padding * 2\n const contentH = b.height + padding * 2\n const viewW = IS_BROWSER ? window.innerWidth : 1280\n const viewH = IS_BROWSER ? window.innerHeight : 720\n const zoom = Math.min(viewW / contentW, viewH / contentH, 1)\n // A script scrolling to its own result must not move the view someone else is looking at:\n // only `viewport` and a page switch do that.\n this._viewport = { x: b.x + b.width / 2, y: b.y + b.height / 2, zoom }\n }\n }\n }\n\n set viewport(v: FigmaViewport) {\n this._showViewport({ x: v.center.x, y: v.center.y, zoom: v.zoom })\n }\n\n /**\n * Moves the viewport and puts the host on the same view. A tool that scrolls nodes into view\n * does not call this: only a viewport a writer asks for moves the view of whoever is looking.\n */\n private _showViewport(next: { x: number; y: number; zoom: number }): void {\n const current = this._viewport\n this._viewport = next\n if (current.x === next.x && current.y === next.y && current.zoom === next.zoom) return\n this.#onViewportChange?.({ center: { x: next.x, y: next.y }, zoom: next.zoom })\n }\n\n createImage(data: Uint8Array): Image {\n return images.createImage(this.graph, data)\n }\n\n getImageByHash(hash: string): Image | null {\n return images.imageByHash(this.graph, hash)\n }\n\n /** Fetches the image at `src` through the host's `fetch` and stores it as `createImage` does. */\n createImageAsync(src: string): Promise<Image> {\n return images.fetchImage(this.graph, src, this.#fetch)\n }\n\n // --- Stubs ---\n\n /** Loads the font so text measures and draws with it from then on; rejects as Figma does. */\n async loadFontAsync(fontName: FigmaFontNameInput): Promise<void> {\n await loadFigmaFont(fontName)\n }\n\n /**\n * The axis tags a variable family takes in `variationSettings`, or `null` for a static family.\n * Figma answers for any family it lists; Pairdraw reads the axes from a file the family has\n * loaded, so a family has to be loaded first.\n */\n getFontFamilyVariationAxes(family: string): string[] | null {\n const variation = fontManager.familyVariation(family)\n if (variation === undefined) {\n throw new Error(\n `in getFontFamilyVariationAxes: Font family \"${family}\" is not available. Load it with figma.loadFontAsync({ family: \"${family}\" }) first.`\n )\n }\n return variation ? variationAxisTags(variation.axes) : null\n }\n\n async listAvailableFontsAsync(): Promise<FigmaFont[]> {\n // Default: pure browser / test contexts have no enumeration surface.\n // Desktop hosts override this to return system + bundled fonts.\n return []\n }\n\n base64Encode(data: Uint8Array): string {\n return fromUint8Array(data)\n }\n\n base64Decode(data: string): Uint8Array {\n if (!isValid(data)) throw new TypeError('Invalid Base64 string')\n return toUint8Array(data)\n }\n\n notify(message: string): { cancel: () => void } {\n if (typeof console !== 'undefined') console.warn(`[figma.notify] ${message}`)\n return { cancel: noop }\n }\n\n /**\n * A script is one call rather than a plugin with a lifetime, so nothing closes; the message is\n * shown as Figma shows it, through `notify`.\n */\n closePlugin(message?: string): void {\n if (message) this.notify(message)\n }\n\n /** Every page is already in memory. */\n async loadAllPagesAsync(): Promise<void> {\n return undefined\n }\n\n commitUndo(): void {\n return undefined\n }\n\n triggerUndo(): void {\n return undefined\n }\n\n exportImage?: (nodeIds: string[], options: ExportImageOptions) => Promise<Uint8Array | null>\n /** Where icon tools search and fetch icons; hosts may pass a self-hosted or bundled set. */\n icons: IconProvider = defaultIcons\n rasterCodec?: RasterCodec\n /** The document as it was before the current AI run first edited `pageId`, or null if unedited. */\n changeBaseline?: (pageId: string) => SceneGraph | null\n}\n\n/** The page an API starts on: the one the host shows, else the document's first page. */\nfunction pageIdToStart(graph: SceneGraph, pageId?: string): string {\n const pages = graph.getPages()\n return pageId ?? (pages.length > 0 ? pages[0].id : graph.rootId)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,MAAM,aAAa,KAAA;AAwFnB,IAAa,WAAb,MAA+C;CAC7C;CACA;CACA,aAAuC,CAAC;CACxC,6BAAqB,IAAI,IAA4B;CACrD,+BAAuB,IAAI,QAAwB;CACnD,YAAyC;;CAEzC,QAAwB;CAExB,QAAiB;;CAEjB,OAAyB;;CAEzB;;CAGA;CACA;CACA;CACA;;CAEA,cAA6B,QAAQ,QAAQ;CAE7C,YAAY,OAAmB,UAA2B,CAAC,GAAG;EAC5D,KAAK,QAAQ;EACb,KAAKA,SAAS,QAAQ,WAAW,OAAO,SAAS,MAAM,OAAO,IAAI;EAClE,KAAKC,gBAAgB,QAAQ;EAC7B,KAAKC,oBAAoB,QAAQ;EACjC,KAAKC,qBAAqB,QAAQ;EAClC,KAAK,YAAY,IAAI,kBAAkB,KAAK;EAC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+CAA+C,OAAO,kEAAkE,OAAO,YACjI;EAEF,OAAO,YAAY,kBAAkB,UAAU,IAAI,IAAI;CACzD;CAEA,MAAM,0BAAgD;EAGpD,OAAO,CAAC;CACV;CAEA,aAAa,MAA0B;EACrC,OAAO,eAAe,IAAI;CAC5B;CAEA,aAAa,MAA0B;EACrC,IAAI,CAAC,QAAQ,IAAI,GAAG,MAAM,IAAI,UAAU,uBAAuB;EAC/D,OAAO,aAAa,IAAI;CAC1B;CAEA,OAAO,SAAyC;EAC9C,IAAI,OAAO,YAAY,aAAa,QAAQ,KAAK,kBAAkB,SAAS;EAC5E,OAAO,EAAE,QAAQ,KAAK;CACxB;;;;;CAMA,YAAY,SAAwB;EAClC,IAAI,SAAS,KAAK,OAAO,OAAO;CAClC;;CAGA,MAAM,oBAAmC,CAEzC;CAEA,aAAmB,CAEnB;CAEA,cAAoB,CAEpB;CAEA;;CAEA,QAAsB;CACtB;;CAEA;AACF;;AAGA,SAAS,cAAc,OAAmB,QAAyB;CACjE,MAAM,QAAQ,MAAM,SAAS;CAC7B,OAAO,WAAW,MAAM,SAAS,IAAI,MAAM,EAAE,CAAC,KAAK,MAAM;AAC3D"}
1
+ {"version":3,"file":"index.js","names":["#fetch","#onPageChange","#onViewportChange","#onSelectionChange","#pageSwitch","#pageChange","images.createImage","images.imageByHash","images.fetchImage"],"sources":["../../src/figma-api/index.ts"],"sourcesContent":["import { fromUint8Array, isValid, toUint8Array } from 'js-base64'\n\nimport type { SceneGraph, SceneNode as CoreSceneNode, NodeType } from '@pairdraw/scene-graph'\nimport { createConnector, freeEndpoint } from '@pairdraw/scene-graph/connectors'\nimport { computeBounds } from '@pairdraw/scene-graph/geometry'\nimport type { GroupFitOptions } from '@pairdraw/scene-graph/group-bounds'\nimport type { Rect, Vector } from '@pairdraw/scene-graph/primitives'\n\nimport type { SkiaRenderer } from '#core/canvas'\nimport { groupFitOptions } from '#core/canvas/boolean'\nimport { IS_BROWSER, type InterfaceTheme } from '#core/constants'\nimport { newLayerDefaults } from '#core/editor/shapes/defaults'\nimport { booleanOperationPaints, createBooleanOperation } from '#core/editor/structure/boolean'\nimport { wrapNodes } from '#core/editor/structure/container-wrap'\nimport { ungroupNode } from '#core/editor/structure/group/ungroup'\nimport { setDefaultPageBackground } from '#core/figma-api/page-backgrounds'\nimport { defaultIcons, type IconProvider } from '#core/icons'\nimport type { RasterCodec } from '#core/io/formats/raster'\nimport { createSVGNodes } from '#core/io/formats/svg'\nimport { textAutoResizeChanges } from '#core/layout/text-auto-resize'\nimport { fontManager } from '#core/text/font/manager'\n\nimport { componentFromNode } from './components'\nimport { flattenSceneNodes } from './flatten'\nimport { listFigmaFonts } from './fonts/list'\nimport { loadFigmaFont } from './fonts/load'\nimport type { FigmaFontNameInput } from './fonts/names'\nimport { variationAxisTags } from './fonts/variations'\nimport * as images from './images'\nimport type {\n FigmaBooleanOperationNode,\n FigmaComponentNode,\n FigmaComponentSetNode,\n FigmaConnectorNode,\n FigmaEllipseNode,\n FigmaFrameNode,\n FigmaGroupNode,\n FigmaLineNode,\n FigmaPolygonNode,\n FigmaRectangleNode,\n FigmaSectionNode,\n FigmaShapeWithTextNode,\n FigmaStarNode,\n FigmaTextNode,\n FigmaVectorNode\n} from './node-types'\nimport { startPendingLayout } from './pending-layout'\nimport { flushPendingComponentSync, startPendingComponentSync } from './pending-sync'\nimport {\n FigmaNodeProxy,\n INTERNAL_ID,\n loadPage,\n MIXED,\n pageOfNode,\n setPageHost,\n type FigmaFont,\n type NodeProxyHost\n} from './proxy'\nimport { newShapeWithText } from './shape-with-text'\nimport type { ExportImageOptions } from './types'\nimport { figmaUtil } from './util'\nimport { FigmaVariablesAPI } from './variables'\nimport { combineComponentsAsVariants } from './variants'\n\nconst noop = () => undefined\n\n/** A view of the document: its centre point and its zoom. */\nexport interface FigmaViewport {\n center: Vector\n zoom: number\n}\n\n/** What a host passes to `FigmaAPI` beyond the document. */\nexport interface FigmaAPIOptions {\n /** Fetches the HTTP(S) URLs `figma.createImageAsync` loads; the global `fetch` by default. */\n fetch?: images.ImageFetch\n /**\n * Loads a page's layers, for a host that loads pages as they are visited, as the editor does a\n * file it opens: `page.loadAsync`, `figma.loadAllPagesAsync`, and `setCurrentPageAsync` call\n * it, as they load pages in Figma's dynamic-page mode. Without one every page is in memory.\n */\n loadPage?: (pageId: string) => Promise<void>\n /** The page holding a layer not loaded yet, which `getNodeByIdAsync` loads to find it. */\n pageOfNode?: (nodeId: string) => Promise<string | null>\n /**\n * Runs when a script puts the API on another page, so a host can show that page too. The host\n * owns which page is on screen, and a plugin that switches page expects to see it switched.\n */\n onPageChange?: (pageId: string) => void | Promise<void>\n /**\n * Runs when a script moves the viewport, so a host can show the same view. A host owns the\n * viewport on screen, and a plugin that pans or zooms expects to see the result.\n */\n onViewportChange?: (viewport: FigmaViewport) => void\n /**\n * The page the host already shows. Seeded here rather than assigned after construction, so a\n * plain tool call does not ask the host to switch to the page it is already on.\n */\n pageId?: string\n /**\n * The view the host already shows, seeded for the same reason: a tool that only reads or draws\n * must not move the viewport of whoever is looking at the document.\n */\n viewport?: FigmaViewport\n /**\n * Runs when a script sets the page selection, so a host can select those layers too. The host\n * owns which layers are selected on screen, and a plugin that selects expects to see them selected.\n */\n onSelectionChange?: (ids: readonly string[], pageId: string) => void\n /**\n * The selection the host already shows, seeded for the same reason as the page and the viewport:\n * a tool that only reads must not reselect what is already selected.\n */\n selection?: readonly string[]\n /**\n * Brings instances in line with the component edits made so far, for a host that syncs them\n * after edits itself, as the editor does; reading a layer calls it first. Without one the API\n * records edits and syncs their instances itself.\n */\n flushComponentSync?: () => void\n}\n\nexport { FigmaNodeProxy } from './proxy'\nexport { getPageBackgrounds, setPageBackgrounds } from './page-backgrounds'\nexport { flushPendingLayout } from './pending-layout'\nexport { flushPendingComponentSync } from './pending-sync'\nexport type { FigmaEffect } from './effects'\nexport type { ExportImageOptions } from './types'\nexport {\n ImageTooLargeError,\n MAX_IMAGE_FETCH_BYTES,\n readBoundedImage,\n type ImageFetch\n} from './images'\nexport {\n FigmaVariable,\n FigmaVariableCollection,\n FigmaVariablesAPI,\n type FigmaComposedColor,\n type FigmaVariableAlias,\n type FigmaVariableValue\n} from './variables'\nexport type {\n FigmaBooleanOperationNode,\n FigmaComponentNode,\n FigmaComponentSetNode,\n FigmaConnectorNode,\n FigmaEllipseNode,\n FigmaFrameNode,\n FigmaGroupNode,\n FigmaInstanceNode,\n FigmaLineNode,\n FigmaPolygonNode,\n FigmaRectangleNode,\n FigmaSectionNode,\n FigmaShapeWithTextNode,\n FigmaSlotNode,\n FigmaStarNode,\n FigmaTextNode,\n FigmaVectorNode\n} from './node-types'\nexport type { FigmaFont, FigmaFontName } from './proxy'\nexport type { FigmaFontNameInput } from './fonts/names'\nexport type { FigmaVariationSettings } from './fonts/variations'\n\n// TODO(figma-api): Implement the full official PluginAPI interface once our compatibility\n// layer covers all required node-specific return types and unsupported APIs are modeled explicitly.\n/** What a plugin keeps in `figma.clientStorage`: JSON values, copied in and out. */\nconst clientStorageValues = new Map<string, unknown>()\n\nconst clientStorage: ClientStorageAPI = {\n async getAsync(key: string): Promise<unknown> {\n const value = clientStorageValues.get(key)\n return value === undefined ? undefined : structuredClone(value)\n },\n async setAsync(key: string, value: unknown): Promise<void> {\n clientStorageValues.set(key, structuredClone(value))\n },\n async deleteAsync(key: string): Promise<void> {\n clientStorageValues.delete(key)\n },\n async keysAsync(): Promise<string[]> {\n return [...clientStorageValues.keys()]\n }\n}\n\nexport class FigmaAPI implements NodeProxyHost {\n readonly graph: SceneGraph\n private _currentPageId: string\n private _selection: FigmaNodeProxy[] = []\n private _nodeCache = new Map<string, FigmaNodeProxy>()\n private _pageProxies = new WeakSet<FigmaNodeProxy>()\n private _renderer: SkiaRenderer | null = null\n /** The interface theme new sections take their fill from, as in Figma. */\n theme: InterfaceTheme = 'light'\n\n readonly mixed = MIXED\n /** Figma's color and Markdown helpers, as `figma.util`. */\n readonly util: UtilAPI = figmaUtil\n /** The document's variables and collections, as Figma's `figma.variables`. */\n readonly variables: FigmaVariablesAPI\n /** Values a plugin keeps for its next run, as Figma's `figma.clientStorage`. */\n readonly clientStorage: ClientStorageAPI = clientStorage\n\n /** How `createImageAsync` fetches HTTP(S) URLs; a host passes one that gets past CORS. */\n readonly #fetch: images.ImageFetch\n readonly #onPageChange: ((pageId: string) => void | Promise<void>) | undefined\n readonly #onViewportChange: ((viewport: FigmaViewport) => void) | undefined\n readonly #onSelectionChange: ((ids: readonly string[], pageId: string) => void) | undefined\n /** The last host page switch, so `setCurrentPageAsync` can wait for it. */\n #pageChange: Promise<void> = Promise.resolve()\n /** Counts page switches, so a switch whose page loads after a later one does not undo it. */\n #pageSwitch = 0\n\n constructor(graph: SceneGraph, options: FigmaAPIOptions = {}) {\n this.graph = graph\n this.#fetch = options.fetch ?? ((input, init) => fetch(input, init))\n if (options.loadPage)\n setPageHost(this, { load: options.loadPage, pageOfNode: options.pageOfNode })\n this.#onPageChange = options.onPageChange\n this.#onViewportChange = options.onViewportChange\n this.#onSelectionChange = options.onSelectionChange\n this.variables = new FigmaVariablesAPI(graph)\n startPendingLayout(graph)\n startPendingComponentSync(graph, options.flushComponentSync)\n this._currentPageId = pageIdToStart(graph, options.pageId)\n if (options.viewport) {\n this._viewport = {\n x: options.viewport.center.x,\n y: options.viewport.center.y,\n zoom: options.viewport.zoom\n }\n }\n // Seeded here, not assigned through the setter, so a tool that only reads does not ask the\n // host to select the layers it is already showing.\n this._selection = (options.selection ?? []).flatMap((id) =>\n this.graph.getNode(id) ? [this.wrapNode(id)] : []\n )\n }\n\n setRenderer(renderer: SkiaRenderer | null): void {\n this._renderer = renderer\n }\n\n get groupFitOptions(): GroupFitOptions {\n return groupFitOptions(this._renderer, this.graph)\n }\n\n get currentPageId(): string {\n return this._currentPageId\n }\n\n wrapNode(id: string): FigmaNodeProxy {\n let proxy = this._nodeCache.get(id)\n if (!proxy) {\n proxy = new FigmaNodeProxy(id, this.graph, this)\n this._nodeCache.set(id, proxy)\n }\n return proxy\n }\n\n private _ensurePageProxy(\n proxy: FigmaNodeProxy\n ): FigmaNodeProxy & { selection: FigmaNodeProxy[] } {\n if (!this._pageProxies.has(proxy)) {\n Object.defineProperty(proxy, 'selection', {\n get: () => this._selection,\n set: (nodes: FigmaNodeProxy[]) => {\n const next = nodes.map((node) => node[INTERNAL_ID])\n const current = this._selection.map((node) => node[INTERNAL_ID])\n this._selection = nodes\n if (next.length === current.length && next.every((id, index) => id === current[index]))\n return\n this.#onSelectionChange?.(next, this._currentPageId)\n },\n enumerable: true,\n configurable: true\n })\n this._pageProxies.add(proxy)\n }\n return proxy as FigmaNodeProxy & { selection: FigmaNodeProxy[] }\n }\n\n get root(): FigmaNodeProxy {\n return this.wrapNode(this.graph.rootId)\n }\n\n get currentPage(): FigmaNodeProxy & { selection: FigmaNodeProxy[] } {\n return this._ensurePageProxy(this.wrapNode(this._currentPageId))\n }\n\n set currentPage(page: FigmaNodeProxy) {\n const pageId = page[INTERNAL_ID]\n this.#pageSwitch++\n if (pageId === this._currentPageId) return\n this._currentPageId = pageId\n this.#pageChange = Promise.resolve(this.#onPageChange?.(pageId))\n }\n\n getNodeById(id: string): FigmaNodeProxy | null {\n flushPendingComponentSync(this.graph)\n const node = this.graph.getNode(id)\n return node ? this.wrapNode(id) : null\n }\n\n /** As in Figma's dynamic-page mode, a layer on a page not loaded yet loads that page. */\n async getNodeByIdAsync(id: string): Promise<FigmaNodeProxy | null> {\n const node = this.getNodeById(id)\n // A page asked for by id is its own holder, and one whose layers are not in yet loads first.\n const unloadedPage = node?.type === 'CANVAS' && this.graph.getChildren(id).length === 0\n if (node && !unloadedPage) return node\n const pageId = node\n ? id\n : ((await pageOfNode(this, id)) ??\n (this.graph.getPages().some((page) => page.id === id) ? id : null))\n if (!pageId) return null\n await loadPage(this, pageId)\n return this.getNodeById(id) ?? node\n }\n\n /**\n * The page switch Figma requires in dynamic-page mode, which sets `currentPage`. As in Figma, a\n * missing node throws at once and a node that is no page rejects.\n */\n setCurrentPageAsync(page: FigmaNodeProxy): Promise<void>\n setCurrentPageAsync(page: PageNode): Promise<void>\n // Scripts are not type-checked, so the call checks for a missing node as Figma does.\n setCurrentPageAsync(page: PageNode | FigmaNodeProxy | null | undefined): Promise<void> {\n if (page == null) throw new Error(`in setCurrentPageAsync: Expected node, got ${String(page)}`)\n if (this._rawNode(page).type !== 'CANVAS') {\n return Promise.reject(new Error('figma.setCurrentPageAsync expects a PageNode'))\n }\n const pageId = this._nodeId(page)\n const pageSwitch = ++this.#pageSwitch\n return loadPage(this, pageId).then(() => {\n if (pageSwitch !== this.#pageSwitch) return undefined\n if (this.graph.getNode(pageId)?.type !== 'CANVAS')\n throw new Error('in setCurrentPageAsync: The page was removed while it loaded')\n this._currentPageId = pageId\n this.#pageChange = Promise.resolve(this.#onPageChange?.(pageId))\n return this.#pageChange\n })\n }\n\n // --- Node Creation ---\n\n /** New layers start as the editor's tools make them, which is how Figma's plugin API makes them. */\n private _createNode(type: NodeType): FigmaNodeProxy {\n const defaults = newLayerDefaults(type, this.theme)\n // Figma's plugin API makes a line with no height, a 496 px section, and a hugging frame.\n if (type === 'LINE') defaults.height = 0\n if (type === 'SECTION') Object.assign(defaults, { width: 496, height: 496 })\n if (type === 'FRAME' || type === 'COMPONENT') defaults.primaryAxisSizing = 'HUG'\n const node = this.graph.createNode(type, this._currentPageId, defaults)\n return this.wrapNode(node.id)\n }\n\n createFrame(): FigmaFrameNode {\n return this._createNode('FRAME') as FigmaFrameNode\n }\n\n createRectangle(): FigmaRectangleNode {\n return this._createNode('RECTANGLE') as FigmaRectangleNode\n }\n\n createEllipse(): FigmaEllipseNode {\n return this._createNode('ELLIPSE') as FigmaEllipseNode\n }\n\n createText(): FigmaTextNode {\n const text = this._createNode('TEXT') as FigmaTextNode\n // Figma's plugin text starts empty at 12px and sizes itself to its content: no width, one\n // line tall.\n const node = this.graph.getNode(text.id)\n const defaults = { fontSize: 12, textAutoResize: 'WIDTH_AND_HEIGHT' as const, width: 0 }\n this.graph.updateNode(text.id, { ...defaults, ...textAutoResizeChanges(node, defaults) })\n return text\n }\n\n createLine(): FigmaLineNode {\n return this._createNode('LINE') as FigmaLineNode\n }\n\n createPolygon(): FigmaPolygonNode {\n return this._createNode('POLYGON') as FigmaPolygonNode\n }\n\n createStar(): FigmaStarNode {\n return this._createNode('STAR') as FigmaStarNode\n }\n\n createShapeWithText(): FigmaShapeWithTextNode {\n return this.wrapNode(newShapeWithText(this).id) as FigmaShapeWithTextNode\n }\n\n createVector(): FigmaVectorNode {\n return this._createNode('VECTOR') as FigmaVectorNode\n }\n\n /** The layers Figma makes from SVG markup, on the current page at its origin. */\n // eslint-disable-next-line pairdraw/no-mixed-case-acronym-identifiers -- Figma Plugin API name.\n createNodeFromSvg(svg: string): FigmaFrameNode {\n const node = createSVGNodes(this.graph, this._currentPageId, svg, { keepEmpty: true })\n if (!node) throw new Error('in createNodeFromSvg: Failed to convert SVG file')\n return this.wrapNode(node.id) as FigmaFrameNode\n }\n\n /**\n * A connector as Figma's plugin API makes one: \"Connector line\", free from the page origin to\n * 200 px right of it, with no start cap and an arrow at the end.\n */\n createConnector(): FigmaConnectorNode {\n const node = createConnector(this.graph, this._currentPageId, {\n start: freeEndpoint(0, 0),\n end: freeEndpoint(200, 0),\n startCap: 'NONE',\n endCap: 'ARROW_LINES'\n })\n return this.wrapNode(node.id) as FigmaConnectorNode\n }\n\n createComponent(): FigmaComponentNode {\n return this._createNode('COMPONENT') as FigmaComponentNode\n }\n\n createSection(): FigmaSectionNode {\n return this._createNode('SECTION') as FigmaSectionNode\n }\n\n createPage(): FigmaNodeProxy {\n const page = this.graph.addPage('Page')\n setDefaultPageBackground(this.graph, page, this.theme)\n return this.wrapNode(page.id)\n }\n\n // --- Grouping ---\n\n private _nodeId(node: BaseNode | FigmaNodeProxy): string {\n return (node as BaseNode & { [INTERNAL_ID]: string })[INTERNAL_ID]\n }\n\n private _rawNode(node: BaseNode | FigmaNodeProxy): CoreSceneNode {\n const id = this._nodeId(node)\n const raw = this.graph.getNode(id)\n if (!raw) throw new Error(`Node ${id} not found`)\n return raw\n }\n\n group(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaGroupNode\n group(nodes: ReadonlyArray<BaseNode>, parent: BaseNode & ChildrenMixin, index?: number): GroupNode\n group(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaGroupNode {\n const parentId = this._nodeId(parent)\n const members = nodes.map((node) => this._rawNode(node))\n const groupNode = wrapNodes(this.graph, 'GROUP', members, parentId, index)\n return this.wrapNode(groupNode.id) as FigmaGroupNode\n }\n\n ungroup(node: FigmaNodeProxy): FigmaNodeProxy[]\n ungroup(node: SceneNode & ChildrenMixin): Array<SceneNode>\n ungroup(node: (SceneNode & ChildrenMixin) | FigmaNodeProxy): Array<SceneNode> | FigmaNodeProxy[] {\n const children = ungroupNode(this.graph, this._nodeId(node)) ?? []\n return children.map((id) => this.wrapNode(id))\n }\n\n createComponentFromNode(node: FigmaNodeProxy): FigmaNodeProxy {\n const raw = this.graph.getNode(node[INTERNAL_ID])\n if (!raw) throw new Error('Node not found')\n return this.wrapNode(componentFromNode(this.graph, raw, raw.parentId ?? this._currentPageId).id)\n }\n\n combineAsVariants(\n nodes: ReadonlyArray<FigmaComponentNode>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaComponentSetNode\n combineAsVariants(\n nodes: ReadonlyArray<ComponentNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): ComponentSetNode\n combineAsVariants(\n nodes: ReadonlyArray<ComponentNode | FigmaComponentNode>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaComponentSetNode {\n const componentSet = combineComponentsAsVariants(\n this.graph,\n nodes.map((node) => this._nodeId(node)),\n this._nodeId(parent),\n index\n )\n return this.wrapNode(componentSet.id) as FigmaComponentSetNode\n }\n\n // --- Boolean Operations ---\n\n private _booleanOperation(\n operation: 'UNION' | 'SUBTRACT' | 'INTERSECT' | 'EXCLUDE',\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n if (nodes.length < 2) throw new Error('Need at least 2 nodes for boolean operation')\n const parentId = this._nodeId(parent)\n const members = nodes.map((node) => this._rawNode(node))\n const { node: group } = createBooleanOperation(\n this.graph,\n members,\n parentId,\n operation,\n index,\n booleanOperationPaints(operation, members, 'script'),\n this.groupFitOptions\n )\n return this.wrapNode(group.id) as FigmaBooleanOperationNode\n }\n\n union(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode\n union(\n nodes: ReadonlyArray<BaseNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): BooleanOperationNode\n union(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n return this._booleanOperation('UNION', nodes, parent, index)\n }\n\n subtract(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode\n subtract(\n nodes: ReadonlyArray<BaseNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): BooleanOperationNode\n subtract(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n return this._booleanOperation('SUBTRACT', nodes, parent, index)\n }\n\n intersect(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode\n intersect(\n nodes: ReadonlyArray<BaseNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): BooleanOperationNode\n intersect(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n return this._booleanOperation('INTERSECT', nodes, parent, index)\n }\n\n exclude(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent: FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode\n exclude(\n nodes: ReadonlyArray<BaseNode>,\n parent: BaseNode & ChildrenMixin,\n index?: number\n ): BooleanOperationNode\n exclude(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaBooleanOperationNode {\n return this._booleanOperation('EXCLUDE', nodes, parent, index)\n }\n\n // --- Flatten ---\n\n flatten(\n nodes: ReadonlyArray<FigmaNodeProxy>,\n parent?: FigmaNodeProxy,\n index?: number\n ): FigmaVectorNode\n flatten(\n nodes: ReadonlyArray<BaseNode>,\n parent?: BaseNode & ChildrenMixin,\n index?: number\n ): VectorNode\n flatten(\n nodes: ReadonlyArray<BaseNode | FigmaNodeProxy>,\n parent?: (BaseNode & ChildrenMixin) | FigmaNodeProxy,\n index?: number\n ): FigmaVectorNode {\n if (nodes.length === 0) throw new Error('Need at least 1 node to flatten')\n const parentId = this._nodeId(parent ?? this.currentPage)\n const sourceNodes: CoreSceneNode[] = []\n for (const node of nodes) {\n const raw = this.graph.getNode(this._nodeId(node))\n if (!raw) throw new Error('Node not found')\n sourceNodes.push(raw)\n }\n const vector = flattenSceneNodes(this.graph, this._renderer, sourceNodes, parentId)\n if (index != null) this.graph.insertChildAt(vector.id, parentId, index)\n for (const node of nodes) {\n this.graph.deleteNode(this._nodeId(node))\n }\n return this.wrapNode(vector.id) as FigmaVectorNode\n }\n\n // --- Viewport ---\n\n private _viewport = { x: 0, y: 0, zoom: 1 }\n\n get viewport(): FigmaViewport & {\n scrollAndZoomIntoView: (nodes: readonly { absoluteBoundingBox: Rect }[]) => void\n } {\n return {\n center: { x: this._viewport.x, y: this._viewport.y },\n zoom: this._viewport.zoom,\n scrollAndZoomIntoView: (nodes) => {\n const b = computeBounds(nodes.map((n) => n.absoluteBoundingBox))\n if (b.width === 0 && b.height === 0 && nodes.length === 0) return\n\n const padding = 80\n const contentW = b.width + padding * 2\n const contentH = b.height + padding * 2\n const viewW = IS_BROWSER ? window.innerWidth : 1280\n const viewH = IS_BROWSER ? window.innerHeight : 720\n const zoom = Math.min(viewW / contentW, viewH / contentH, 1)\n // A script scrolling to its own result must not move the view someone else is looking at:\n // only `viewport` and a page switch do that.\n this._viewport = { x: b.x + b.width / 2, y: b.y + b.height / 2, zoom }\n }\n }\n }\n\n set viewport(v: FigmaViewport) {\n this._showViewport({ x: v.center.x, y: v.center.y, zoom: v.zoom })\n }\n\n /**\n * Moves the viewport and puts the host on the same view. A tool that scrolls nodes into view\n * does not call this: only a viewport a writer asks for moves the view of whoever is looking.\n */\n private _showViewport(next: { x: number; y: number; zoom: number }): void {\n const current = this._viewport\n this._viewport = next\n if (current.x === next.x && current.y === next.y && current.zoom === next.zoom) return\n this.#onViewportChange?.({ center: { x: next.x, y: next.y }, zoom: next.zoom })\n }\n\n createImage(data: Uint8Array): Image {\n return images.createImage(this.graph, data)\n }\n\n getImageByHash(hash: string): Image | null {\n return images.imageByHash(this.graph, hash)\n }\n\n /** Fetches the image at `src` through the host's `fetch` and stores it as `createImage` does. */\n createImageAsync(src: string): Promise<Image> {\n return images.fetchImage(this.graph, src, this.#fetch)\n }\n\n // --- Stubs ---\n\n /** Loads the font so text measures and draws with it from then on; rejects as Figma does. */\n async loadFontAsync(fontName: FigmaFontNameInput): Promise<void> {\n await loadFigmaFont(fontName)\n }\n\n /**\n * The axis tags a variable family takes in `variationSettings`, or `null` for a static family.\n * Figma answers for any family it lists; Pairdraw reads the axes from a file the family has\n * loaded, so a family has to be loaded first.\n */\n getFontFamilyVariationAxes(family: string): string[] | null {\n const variation = fontManager.familyVariation(family)\n if (variation === undefined) {\n throw new Error(\n `in getFontFamilyVariationAxes: Font family \"${family}\" is not available. Load it with figma.loadFontAsync({ family: \"${family}\" }) first.`\n )\n }\n return variation ? variationAxisTags(variation.axes) : null\n }\n\n /** Every face a script can set, by family; see {@link listFigmaFonts}. */\n listAvailableFontsAsync(): Promise<FigmaFont[]> {\n return listFigmaFonts()\n }\n\n base64Encode(data: Uint8Array): string {\n return fromUint8Array(data)\n }\n\n base64Decode(data: string): Uint8Array {\n if (!isValid(data)) throw new TypeError('Invalid Base64 string')\n return toUint8Array(data)\n }\n\n notify(message: string): { cancel: () => void } {\n if (typeof console !== 'undefined') console.warn(`[figma.notify] ${message}`)\n return { cancel: noop }\n }\n\n /**\n * A script is one call rather than a plugin with a lifetime, so nothing closes; the message is\n * shown as Figma shows it, through `notify`.\n */\n closePlugin(message?: string): void {\n if (message) this.notify(message)\n }\n\n /** Loads every page's layers, one after another, for a host that loads them as visited. */\n async loadAllPagesAsync(): Promise<void> {\n for (const page of this.graph.getPages()) await loadPage(this, page.id)\n }\n\n commitUndo(): void {\n return undefined\n }\n\n triggerUndo(): void {\n return undefined\n }\n\n exportImage?: (nodeIds: string[], options: ExportImageOptions) => Promise<Uint8Array | null>\n /** Where icon tools search and fetch icons; hosts may pass a self-hosted or bundled set. */\n icons: IconProvider = defaultIcons\n rasterCodec?: RasterCodec\n /** The document as it was before the current AI run first edited `pageId`, or null if unedited. */\n changeBaseline?: (pageId: string) => SceneGraph | null\n}\n\n/** The page an API starts on: the one the host shows, else the document's first page. */\nfunction pageIdToStart(graph: SceneGraph, pageId?: string): string {\n const pages = graph.getPages()\n return pageId ?? (pages.length > 0 ? pages[0].id : graph.rootId)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,MAAM,aAAa,KAAA;;AAwGnB,MAAM,sCAAsB,IAAI,IAAqB;AAErD,MAAM,gBAAkC;CACtC,MAAM,SAAS,KAA+B;EAC5C,MAAM,QAAQ,oBAAoB,IAAI,GAAG;EACzC,OAAO,UAAU,KAA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AmB,KAAK,OAAO,IAAI;CAC5C;;CAGA,iBAAiB,KAA6B;EAC5C,OAAOC,WAAkB,KAAK,OAAO,KAAK,KAAKR,MAAM;CACvD;;CAKA,MAAM,cAAc,UAA6C;EAC/D,MAAM,cAAc,QAAQ;CAC9B;;;;;;CAOA,2BAA2B,QAAiC;EAC1D,MAAM,YAAY,YAAY,gBAAgB,MAAM;EACpD,IAAI,cAAc,KAAA,GAChB,MAAM,IAAI,MACR,+CAA+C,OAAO,kEAAkE,OAAO,YACjI;EAEF,OAAO,YAAY,kBAAkB,UAAU,IAAI,IAAI;CACzD;;CAGA,0BAAgD;EAC9C,OAAO,eAAe;CACxB;CAEA,aAAa,MAA0B;EACrC,OAAO,eAAe,IAAI;CAC5B;CAEA,aAAa,MAA0B;EACrC,IAAI,CAAC,QAAQ,IAAI,GAAG,MAAM,IAAI,UAAU,uBAAuB;EAC/D,OAAO,aAAa,IAAI;CAC1B;CAEA,OAAO,SAAyC;EAC9C,IAAI,OAAO,YAAY,aAAa,QAAQ,KAAK,kBAAkB,SAAS;EAC5E,OAAO,EAAE,QAAQ,KAAK;CACxB;;;;;CAMA,YAAY,SAAwB;EAClC,IAAI,SAAS,KAAK,OAAO,OAAO;CAClC;;CAGA,MAAM,oBAAmC;EACvC,KAAK,MAAM,QAAQ,KAAK,MAAM,SAAS,GAAG,MAAM,SAAS,MAAM,KAAK,EAAE;CACxE;CAEA,aAAmB,CAEnB;CAEA,cAAoB,CAEpB;CAEA;;CAEA,QAAsB;CACtB;;CAEA;AACF;;AAGA,SAAS,cAAc,OAAmB,QAAyB;CACjE,MAAM,QAAQ,MAAM,SAAS;CAC7B,OAAO,WAAW,MAAM,SAAS,IAAI,MAAM,EAAE,CAAC,KAAK,MAAM;AAC3D"}
@@ -12,7 +12,12 @@ interface FigmaInstanceOverride {
12
12
  * size but the instance's.
13
13
  */
14
14
  declare function instanceOverrides(graph: SceneGraph, root: SceneNode): FigmaInstanceOverride[];
15
+ /**
16
+ * Figma's `resetOverrides`: the instance and every instance inside it go back to their
17
+ * components, keeping the values their component properties set.
18
+ */
19
+ declare function resetInstanceOverrides(graph: SceneGraph, root: SceneNode): void;
15
20
  declare function installInstanceOverrideAccessors(prototype: object, internals: NodeProxyInternals): void;
16
21
  //#endregion
17
- export { FigmaInstanceOverride, installInstanceOverrideAccessors, instanceOverrides };
22
+ export { FigmaInstanceOverride, installInstanceOverrideAccessors, instanceOverrides, resetInstanceOverrides };
18
23
  //# sourceMappingURL=overrides.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"overrides.d.ts","names":[],"sources":["../../src/figma-api/overrides.ts"],"mappings":";;;;UAoBiB;EACf;EACA;;;;;;;iBA8Kc,kBAAkB,OAAO,YAAY,MAAM,YAAY;iBA6DvD,iCACd,mBACA,WAAW"}
1
+ {"version":3,"file":"overrides.d.ts","names":[],"sources":["../../src/figma-api/overrides.ts"],"mappings":";;;;UAoBiB;EACf;EACA;;;;;;;iBA8Kc,kBAAkB,OAAO,YAAY,MAAM,YAAY;;;;;iBAgCvD,uBAAuB,OAAO,YAAY,MAAM;iBA6BhD,iCACd,mBACA,WAAW"}
@@ -2,8 +2,8 @@ import { assertProxyEditable, graph, raw } from "./accessor-utils.js";
2
2
  import { flushPendingLayout } from "./pending-layout.js";
3
3
  import { omit, uniq } from "es-toolkit";
4
4
  import { isEqual as isEqual$1 } from "es-toolkit/predicate";
5
- import { overriddenVariableModeCollection } from "@pairdraw/scene-graph/instances/overrides";
6
5
  import { findInstanceAncestor, isReplacedLayer } from "@pairdraw/scene-graph/instances";
6
+ import { overriddenVariableModeCollection } from "@pairdraw/scene-graph/instances/overrides";
7
7
  //#region src/figma-api/overrides.ts
8
8
  /**
9
9
  * The fields Figma desktop 126 lists for an override of each of ours. Unlisted fields are ones
@@ -229,6 +229,6 @@ function installInstanceOverrideAccessors(prototype, internals) {
229
229
  });
230
230
  }
231
231
  //#endregion
232
- export { installInstanceOverrideAccessors, instanceOverrides };
232
+ export { installInstanceOverrideAccessors, instanceOverrides, resetInstanceOverrides };
233
233
 
234
234
  //# sourceMappingURL=overrides.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"overrides.js","names":["isEqual"],"sources":["../../src/figma-api/overrides.ts"],"sourcesContent":["import { omit, uniq } from 'es-toolkit'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport type {\n ComponentPropertyReferenceField,\n SceneGraph,\n SceneNode,\n Stroke\n} from '@pairdraw/scene-graph'\nimport { findInstanceAncestor, isReplacedLayer } from '@pairdraw/scene-graph/instances'\nimport {\n overriddenVariableModeCollection,\n type InstanceOverrideState\n} from '@pairdraw/scene-graph/instances/overrides'\n\nimport type { NodeProxyInternals, ProxyThis } from './accessor-utils'\nimport { assertProxyEditable, graph, raw } from './accessor-utils'\nimport { flushPendingLayout } from './pending-layout'\n\n/** One layer of an instance and the fields an edit changed on it, as Figma's `overrides`. */\nexport interface FigmaInstanceOverride {\n id: string\n overriddenFields: string[]\n}\n\n/**\n * The fields Figma desktop 126 lists for an override of each of ours. Unlisted fields are ones\n * Figma does not report: a layer's own size, size limits, clipping, the layout mode, a swap.\n * Figma spells the top stroke weight `stokeTopWeight`.\n */\nconst FIGMA_OVERRIDE_FIELDS: Readonly<Partial<Record<string, readonly string[]>>> = {\n // Figma keeps a size as one field, so a changed width or height lists both.\n width: ['height', 'width'],\n height: ['height', 'width'],\n name: ['name'],\n visible: ['visible'],\n locked: ['locked'],\n text: ['characters', 'styledTextSegments'],\n styleRuns: ['styledTextSegments'],\n textParagraphs: ['styledTextSegments'],\n listSpacing: ['styledTextSegments'],\n fontSize: ['fontSize'],\n fontFamily: ['fontName'],\n fontWeight: ['fontName'],\n italic: ['fontName'],\n fontStyle: ['fontName'],\n letterSpacing: ['letterSpacing'],\n lineHeight: ['lineHeight'],\n textCase: ['textCase'],\n textDecoration: ['textDecoration'],\n textDecorationStyle: ['textDecorationStyle'],\n textDecorationThickness: ['textDecorationThickness'],\n textUnderlineOffset: ['textDecorationOffset'],\n textDecorationFills: ['textDecorationColor'],\n textDecorationSkipInk: ['textDecorationSkipInk'],\n textAlignHorizontal: ['textAlignHorizontal'],\n textAlignVertical: ['textAlignVertical'],\n textAutoResize: ['textAutoResize'],\n textTruncation: ['textTruncation'],\n maxLines: ['maxLines'],\n leadingTrim: ['leadingTrim'],\n paragraphSpacing: ['paragraphSpacing'],\n paragraphIndent: ['paragraphIndent'],\n hangingList: ['hangingList'],\n fills: ['fills'],\n strokes: ['strokes'],\n effects: ['effects'],\n opacity: ['opacity'],\n blendMode: ['blendMode'],\n cornerRadius: [\n 'bottomLeftRadius',\n 'bottomRightRadius',\n 'cornerRadius',\n 'topLeftRadius',\n 'topRightRadius'\n ],\n topLeftRadius: ['topLeftRadius'],\n topRightRadius: ['topRightRadius'],\n bottomRightRadius: ['bottomRightRadius'],\n bottomLeftRadius: ['bottomLeftRadius'],\n cornerSmoothing: ['cornerSmoothing'],\n strokeWeight: [\n 'strokeBottomWeight',\n 'strokeLeftWeight',\n 'strokeRightWeight',\n 'stokeTopWeight',\n 'strokeWeight'\n ],\n borderTopWeight: ['stokeTopWeight'],\n borderRightWeight: ['strokeRightWeight'],\n borderBottomWeight: ['strokeBottomWeight'],\n borderLeftWeight: ['strokeLeftWeight'],\n strokeAlign: ['strokeAlign'],\n strokeCap: ['strokeCap'],\n strokeJoin: ['strokeJoin'],\n strokeMiterLimit: ['strokeMiterLimit'],\n dashPattern: ['dashPattern'],\n layoutWrap: ['layoutWrap'],\n primaryAxisAlign: ['primaryAxisAlignItems'],\n counterAxisAlign: ['counterAxisAlignItems'],\n primaryAxisSizing: ['primaryAxisSizingMode'],\n counterAxisSizing: ['counterAxisSizingMode'],\n itemSpacing: ['itemSpacing'],\n counterAxisSpacing: ['counterAxisSpacing'],\n paddingTop: ['paddingTop'],\n paddingRight: ['paddingRight'],\n paddingBottom: ['paddingBottom'],\n paddingLeft: ['paddingLeft'],\n gridColumnGap: ['gridColumnGap'],\n gridRowGap: ['gridRowGap'],\n itemReverseZIndex: ['itemReverseZIndex'],\n layoutGrids: ['layoutGrids'],\n layoutGrow: ['layoutGrow'],\n layoutAlignSelf: ['layoutAlign'],\n boundVariables: ['boundVariables'],\n variableModes: ['explicitVariableModes'],\n fillStyleId: ['fillStyleId'],\n strokeStyleId: ['strokeStyleId'],\n textStyleId: ['textStyleId'],\n effectStyleId: ['effectStyleId'],\n gridStyleId: ['gridStyleId']\n}\n\n/** Fields a component property sets on a layer, which Figma reports as the property's, not an override. */\nconst PROPERTY_FIELDS: Record<ComponentPropertyReferenceField, readonly string[]> = {\n TEXT: ['text', 'styleRuns', 'textParagraphs'],\n VISIBLE: ['visible'],\n INSTANCE_SWAP: ['componentId', 'name'],\n SLOT_CONTENT: []\n}\n\nfunction propertyFields(node: SceneNode): Set<string> {\n return new Set(node.componentPropertyReferences.flatMap(({ field }) => PROPERTY_FIELDS[field]))\n}\n\n/** Figma sorts the names as spelled right, so its misspelled top weight sorts as `strokeTop…`. */\nconst sortKey = (name: string) => (name === 'stokeTopWeight' ? 'strokeTopWeight' : name)\n\nfunction figmaFields(fields: Iterable<string>, skipped: Set<string>): string[] {\n const names = new Set<string>()\n for (const field of fields) {\n if (skipped.has(field)) continue\n for (const name of FIGMA_OVERRIDE_FIELDS[field] ?? []) names.add(name)\n }\n return [...names].sort((a, b) => sortKey(a).localeCompare(sortKey(b)))\n}\n\n/**\n * The layer of the component a node copies, which its overrides are measured against. A nested\n * instance links to the component's instance it copies, until a swap points it at a component;\n * the enclosing instance then keeps the layer it copied.\n */\nfunction componentLayer(graph: SceneGraph, node: SceneNode, owner: SceneNode | undefined) {\n const linked = node.componentId ? graph.getNode(node.componentId) : undefined\n if (node.type !== 'INSTANCE' || linked?.type === 'INSTANCE') return linked\n const source = owner?.instanceOverrides.descendants.get(node.id)?.get('sourceComponentId')\n return typeof source === 'string' ? graph.getNode(source) : undefined\n}\n\n/** Figma keeps stroke weight and alignment on the layer, so a paint differs by its colour alone. */\nconst paints = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => omit(stroke, ['weight', 'align']))\n\nfunction differs(node: SceneNode, source: SceneNode | undefined, field: string): boolean {\n if (!source) return true\n if (field === 'strokes') return !isEqual(paints(node.strokes), paints(source.strokes))\n return !isEqual(Reflect.get(node, field), Reflect.get(source, field))\n}\n\n/**\n * The fields recorded as edited on a node that still differ from its component layer: an edit\n * kept in the nearest instance above it, and one kept on the node itself if it is an instance.\n * Figma lists a field as overridden only while it differs.\n */\nfunction editedFields(graph: SceneGraph, node: SceneNode, root: SceneNode): string[] {\n const owner =\n node.id === root.id || !node.parentId ? undefined : findInstanceAncestor(graph, node.parentId)\n const source =\n node.id === root.id ? graph.getNode(root.componentId ?? '') : componentLayer(graph, node, owner)\n const fields = [\n ...(node.type === 'INSTANCE' ? node.instanceOverrides.self.keys() : []),\n ...(owner?.instanceOverrides.descendants.get(node.id)?.keys() ?? [])\n ].map((field) =>\n // A mode set for one collection is an override of the layer's modes, as Figma lists it.\n overriddenVariableModeCollection(field) === null ? field : 'variableModes'\n )\n // The instance's own size counts once it differs, as a layer that grows it makes it.\n if (node.id === root.id) fields.push('width', 'height')\n return uniq(fields).filter((field) => differs(node, source, field))\n}\n\n/**\n * Figma's `overrides`: each layer of the instance, itself first and then in layer order, with\n * the fields edited on it, including those inside nested instances. Figma lists no layer's own\n * size but the instance's.\n */\nexport function instanceOverrides(graph: SceneGraph, root: SceneNode): FigmaInstanceOverride[] {\n const result: FigmaInstanceOverride[] = []\n const visit = (node: SceneNode) => {\n const skipped = propertyFields(node)\n if (node.id !== root.id) skipped.add('width').add('height')\n const overriddenFields = figmaFields(editedFields(graph, node, root), skipped)\n if (overriddenFields.length > 0) result.push({ id: node.id, overriddenFields })\n for (const child of graph.getChildren(node.id)) visit(child)\n }\n visit(root)\n return result\n}\n\n/** Clears an override state but what component properties set, which Figma keeps on reset. */\nfunction withoutEdits(graph: SceneGraph, state: InstanceOverrideState): InstanceOverrideState {\n const keep = (nodeId: string, fields: Map<string, unknown>) => {\n const node = graph.getNode(nodeId)\n const driven = node ? propertyFields(node) : new Set<string>()\n return new Map([...fields].filter(([field]) => driven.has(field)))\n }\n const descendants = new Map(\n [...state.descendants]\n .map(([nodeId, fields]) => [nodeId, keep(nodeId, fields)] as const)\n .filter(([, fields]) => fields.size > 0)\n )\n return { self: new Map(), descendants }\n}\n\n/**\n * Figma's `resetOverrides`: the instance and every instance inside it go back to their\n * components, keeping the values their component properties set.\n */\nfunction resetInstanceOverrides(graph: SceneGraph, root: SceneNode): void {\n // A layer put in place of a component's layer goes, and the sync brings that layer back.\n const replaced: string[] = []\n const collect = (node: SceneNode) => {\n for (const child of graph.getChildren(node.id)) {\n if (isReplacedLayer(graph, child)) replaced.push(child.id)\n else collect(child)\n }\n }\n collect(root)\n for (const id of replaced) graph.deleteNode(id)\n const visit = (node: SceneNode) => {\n if (node.type === 'INSTANCE')\n graph.updateNode(node.id, { instanceOverrides: withoutEdits(graph, node.instanceOverrides) })\n for (const child of graph.getChildren(node.id)) visit(child)\n }\n visit(root)\n // The outermost instance passes its component's content down to the ones inside it.\n let outermost = root\n for (\n let parent = root.parentId ? findInstanceAncestor(graph, root.parentId) : undefined;\n parent;\n ) {\n outermost = parent\n parent = parent.parentId ? findInstanceAncestor(graph, parent.parentId) : undefined\n }\n graph.syncInstance(outermost.id)\n}\n\nexport function installInstanceOverrideAccessors(\n prototype: object,\n internals: NodeProxyInternals\n): void {\n Object.defineProperties(prototype, {\n overrides: {\n get(this: ProxyThis): FigmaInstanceOverride[] | undefined {\n const node = raw(this, internals)\n if (node.type !== 'INSTANCE') return undefined\n // Figma lists the size its layout gives the instance.\n flushPendingLayout(graph(this, internals))\n return instanceOverrides(graph(this, internals), node)\n }\n },\n resetOverrides: {\n value(this: ProxyThis) {\n const node = raw(this, internals)\n if (node.type !== 'INSTANCE')\n throw new TypeError('resetOverrides() can only be called on instances')\n assertProxyEditable(this, internals)\n resetInstanceOverrides(graph(this, internals), node)\n }\n }\n })\n}\n"],"mappings":";;;;;;;;;;;;AA8BA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AM,SAAS;GACnC,uBAAuB,MAAM,MAAM,SAAS,GAAG,IAAI;EACrD,EACF;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"overrides.js","names":["isEqual"],"sources":["../../src/figma-api/overrides.ts"],"sourcesContent":["import { omit, uniq } from 'es-toolkit'\nimport { isEqual } from 'es-toolkit/predicate'\n\nimport type {\n ComponentPropertyReferenceField,\n SceneGraph,\n SceneNode,\n Stroke\n} from '@pairdraw/scene-graph'\nimport { findInstanceAncestor, isReplacedLayer } from '@pairdraw/scene-graph/instances'\nimport {\n overriddenVariableModeCollection,\n type InstanceOverrideState\n} from '@pairdraw/scene-graph/instances/overrides'\n\nimport type { NodeProxyInternals, ProxyThis } from './accessor-utils'\nimport { assertProxyEditable, graph, raw } from './accessor-utils'\nimport { flushPendingLayout } from './pending-layout'\n\n/** One layer of an instance and the fields an edit changed on it, as Figma's `overrides`. */\nexport interface FigmaInstanceOverride {\n id: string\n overriddenFields: string[]\n}\n\n/**\n * The fields Figma desktop 126 lists for an override of each of ours. Unlisted fields are ones\n * Figma does not report: a layer's own size, size limits, clipping, the layout mode, a swap.\n * Figma spells the top stroke weight `stokeTopWeight`.\n */\nconst FIGMA_OVERRIDE_FIELDS: Readonly<Partial<Record<string, readonly string[]>>> = {\n // Figma keeps a size as one field, so a changed width or height lists both.\n width: ['height', 'width'],\n height: ['height', 'width'],\n name: ['name'],\n visible: ['visible'],\n locked: ['locked'],\n text: ['characters', 'styledTextSegments'],\n styleRuns: ['styledTextSegments'],\n textParagraphs: ['styledTextSegments'],\n listSpacing: ['styledTextSegments'],\n fontSize: ['fontSize'],\n fontFamily: ['fontName'],\n fontWeight: ['fontName'],\n italic: ['fontName'],\n fontStyle: ['fontName'],\n letterSpacing: ['letterSpacing'],\n lineHeight: ['lineHeight'],\n textCase: ['textCase'],\n textDecoration: ['textDecoration'],\n textDecorationStyle: ['textDecorationStyle'],\n textDecorationThickness: ['textDecorationThickness'],\n textUnderlineOffset: ['textDecorationOffset'],\n textDecorationFills: ['textDecorationColor'],\n textDecorationSkipInk: ['textDecorationSkipInk'],\n textAlignHorizontal: ['textAlignHorizontal'],\n textAlignVertical: ['textAlignVertical'],\n textAutoResize: ['textAutoResize'],\n textTruncation: ['textTruncation'],\n maxLines: ['maxLines'],\n leadingTrim: ['leadingTrim'],\n paragraphSpacing: ['paragraphSpacing'],\n paragraphIndent: ['paragraphIndent'],\n hangingList: ['hangingList'],\n fills: ['fills'],\n strokes: ['strokes'],\n effects: ['effects'],\n opacity: ['opacity'],\n blendMode: ['blendMode'],\n cornerRadius: [\n 'bottomLeftRadius',\n 'bottomRightRadius',\n 'cornerRadius',\n 'topLeftRadius',\n 'topRightRadius'\n ],\n topLeftRadius: ['topLeftRadius'],\n topRightRadius: ['topRightRadius'],\n bottomRightRadius: ['bottomRightRadius'],\n bottomLeftRadius: ['bottomLeftRadius'],\n cornerSmoothing: ['cornerSmoothing'],\n strokeWeight: [\n 'strokeBottomWeight',\n 'strokeLeftWeight',\n 'strokeRightWeight',\n 'stokeTopWeight',\n 'strokeWeight'\n ],\n borderTopWeight: ['stokeTopWeight'],\n borderRightWeight: ['strokeRightWeight'],\n borderBottomWeight: ['strokeBottomWeight'],\n borderLeftWeight: ['strokeLeftWeight'],\n strokeAlign: ['strokeAlign'],\n strokeCap: ['strokeCap'],\n strokeJoin: ['strokeJoin'],\n strokeMiterLimit: ['strokeMiterLimit'],\n dashPattern: ['dashPattern'],\n layoutWrap: ['layoutWrap'],\n primaryAxisAlign: ['primaryAxisAlignItems'],\n counterAxisAlign: ['counterAxisAlignItems'],\n primaryAxisSizing: ['primaryAxisSizingMode'],\n counterAxisSizing: ['counterAxisSizingMode'],\n itemSpacing: ['itemSpacing'],\n counterAxisSpacing: ['counterAxisSpacing'],\n paddingTop: ['paddingTop'],\n paddingRight: ['paddingRight'],\n paddingBottom: ['paddingBottom'],\n paddingLeft: ['paddingLeft'],\n gridColumnGap: ['gridColumnGap'],\n gridRowGap: ['gridRowGap'],\n itemReverseZIndex: ['itemReverseZIndex'],\n layoutGrids: ['layoutGrids'],\n layoutGrow: ['layoutGrow'],\n layoutAlignSelf: ['layoutAlign'],\n boundVariables: ['boundVariables'],\n variableModes: ['explicitVariableModes'],\n fillStyleId: ['fillStyleId'],\n strokeStyleId: ['strokeStyleId'],\n textStyleId: ['textStyleId'],\n effectStyleId: ['effectStyleId'],\n gridStyleId: ['gridStyleId']\n}\n\n/** Fields a component property sets on a layer, which Figma reports as the property's, not an override. */\nconst PROPERTY_FIELDS: Record<ComponentPropertyReferenceField, readonly string[]> = {\n TEXT: ['text', 'styleRuns', 'textParagraphs'],\n VISIBLE: ['visible'],\n INSTANCE_SWAP: ['componentId', 'name'],\n SLOT_CONTENT: []\n}\n\nfunction propertyFields(node: SceneNode): Set<string> {\n return new Set(node.componentPropertyReferences.flatMap(({ field }) => PROPERTY_FIELDS[field]))\n}\n\n/** Figma sorts the names as spelled right, so its misspelled top weight sorts as `strokeTop…`. */\nconst sortKey = (name: string) => (name === 'stokeTopWeight' ? 'strokeTopWeight' : name)\n\nfunction figmaFields(fields: Iterable<string>, skipped: Set<string>): string[] {\n const names = new Set<string>()\n for (const field of fields) {\n if (skipped.has(field)) continue\n for (const name of FIGMA_OVERRIDE_FIELDS[field] ?? []) names.add(name)\n }\n return [...names].sort((a, b) => sortKey(a).localeCompare(sortKey(b)))\n}\n\n/**\n * The layer of the component a node copies, which its overrides are measured against. A nested\n * instance links to the component's instance it copies, until a swap points it at a component;\n * the enclosing instance then keeps the layer it copied.\n */\nfunction componentLayer(graph: SceneGraph, node: SceneNode, owner: SceneNode | undefined) {\n const linked = node.componentId ? graph.getNode(node.componentId) : undefined\n if (node.type !== 'INSTANCE' || linked?.type === 'INSTANCE') return linked\n const source = owner?.instanceOverrides.descendants.get(node.id)?.get('sourceComponentId')\n return typeof source === 'string' ? graph.getNode(source) : undefined\n}\n\n/** Figma keeps stroke weight and alignment on the layer, so a paint differs by its colour alone. */\nconst paints = (strokes: readonly Stroke[]) =>\n strokes.map((stroke) => omit(stroke, ['weight', 'align']))\n\nfunction differs(node: SceneNode, source: SceneNode | undefined, field: string): boolean {\n if (!source) return true\n if (field === 'strokes') return !isEqual(paints(node.strokes), paints(source.strokes))\n return !isEqual(Reflect.get(node, field), Reflect.get(source, field))\n}\n\n/**\n * The fields recorded as edited on a node that still differ from its component layer: an edit\n * kept in the nearest instance above it, and one kept on the node itself if it is an instance.\n * Figma lists a field as overridden only while it differs.\n */\nfunction editedFields(graph: SceneGraph, node: SceneNode, root: SceneNode): string[] {\n const owner =\n node.id === root.id || !node.parentId ? undefined : findInstanceAncestor(graph, node.parentId)\n const source =\n node.id === root.id ? graph.getNode(root.componentId ?? '') : componentLayer(graph, node, owner)\n const fields = [\n ...(node.type === 'INSTANCE' ? node.instanceOverrides.self.keys() : []),\n ...(owner?.instanceOverrides.descendants.get(node.id)?.keys() ?? [])\n ].map((field) =>\n // A mode set for one collection is an override of the layer's modes, as Figma lists it.\n overriddenVariableModeCollection(field) === null ? field : 'variableModes'\n )\n // The instance's own size counts once it differs, as a layer that grows it makes it.\n if (node.id === root.id) fields.push('width', 'height')\n return uniq(fields).filter((field) => differs(node, source, field))\n}\n\n/**\n * Figma's `overrides`: each layer of the instance, itself first and then in layer order, with\n * the fields edited on it, including those inside nested instances. Figma lists no layer's own\n * size but the instance's.\n */\nexport function instanceOverrides(graph: SceneGraph, root: SceneNode): FigmaInstanceOverride[] {\n const result: FigmaInstanceOverride[] = []\n const visit = (node: SceneNode) => {\n const skipped = propertyFields(node)\n if (node.id !== root.id) skipped.add('width').add('height')\n const overriddenFields = figmaFields(editedFields(graph, node, root), skipped)\n if (overriddenFields.length > 0) result.push({ id: node.id, overriddenFields })\n for (const child of graph.getChildren(node.id)) visit(child)\n }\n visit(root)\n return result\n}\n\n/** Clears an override state but what component properties set, which Figma keeps on reset. */\nfunction withoutEdits(graph: SceneGraph, state: InstanceOverrideState): InstanceOverrideState {\n const keep = (nodeId: string, fields: Map<string, unknown>) => {\n const node = graph.getNode(nodeId)\n const driven = node ? propertyFields(node) : new Set<string>()\n return new Map([...fields].filter(([field]) => driven.has(field)))\n }\n const descendants = new Map(\n [...state.descendants]\n .map(([nodeId, fields]) => [nodeId, keep(nodeId, fields)] as const)\n .filter(([, fields]) => fields.size > 0)\n )\n return { self: new Map(), descendants }\n}\n\n/**\n * Figma's `resetOverrides`: the instance and every instance inside it go back to their\n * components, keeping the values their component properties set.\n */\nexport function resetInstanceOverrides(graph: SceneGraph, root: SceneNode): void {\n // A layer put in place of a component's layer goes, and the sync brings that layer back.\n const replaced: string[] = []\n const collect = (node: SceneNode) => {\n for (const child of graph.getChildren(node.id)) {\n if (isReplacedLayer(graph, child)) replaced.push(child.id)\n else collect(child)\n }\n }\n collect(root)\n for (const id of replaced) graph.deleteNode(id)\n const visit = (node: SceneNode) => {\n if (node.type === 'INSTANCE')\n graph.updateNode(node.id, { instanceOverrides: withoutEdits(graph, node.instanceOverrides) })\n for (const child of graph.getChildren(node.id)) visit(child)\n }\n visit(root)\n // The outermost instance passes its component's content down to the ones inside it.\n let outermost = root\n for (\n let parent = root.parentId ? findInstanceAncestor(graph, root.parentId) : undefined;\n parent;\n ) {\n outermost = parent\n parent = parent.parentId ? findInstanceAncestor(graph, parent.parentId) : undefined\n }\n graph.syncInstance(outermost.id)\n}\n\nexport function installInstanceOverrideAccessors(\n prototype: object,\n internals: NodeProxyInternals\n): void {\n Object.defineProperties(prototype, {\n overrides: {\n get(this: ProxyThis): FigmaInstanceOverride[] | undefined {\n const node = raw(this, internals)\n if (node.type !== 'INSTANCE') return undefined\n // Figma lists the size its layout gives the instance.\n flushPendingLayout(graph(this, internals))\n return instanceOverrides(graph(this, internals), node)\n }\n },\n resetOverrides: {\n value(this: ProxyThis) {\n const node = raw(this, internals)\n if (node.type !== 'INSTANCE')\n throw new TypeError('resetOverrides() can only be called on instances')\n assertProxyEditable(this, internals)\n resetInstanceOverrides(graph(this, internals), node)\n }\n }\n })\n}\n"],"mappings":";;;;;;;;;;;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BAAoB,MAAM,SAAS;GACnC,uBAAuB,MAAM,MAAM,SAAS,GAAG,IAAI;EACrD,EACF;CACF,CAAC;AACH"}
@@ -1,4 +1,4 @@
1
- import { SceneGraph } from "@pairdraw/scene-graph";
1
+ import { SceneGraph, SceneNode } from "@pairdraw/scene-graph";
2
2
  //#region src/figma-api/pending-layout.d.ts
3
3
  /**
4
4
  * Records the graph's edits so that reading geometry lays out what they touched first, as Figma
@@ -9,6 +9,16 @@ import { SceneGraph } from "@pairdraw/scene-graph";
9
9
  declare function startPendingLayout(graph: SceneGraph): void;
10
10
  /** Lays out the edits recorded since the last geometry read. */
11
11
  declare function flushPendingLayout(graph: SceneGraph): void;
12
+ /**
13
+ * Lays out the recorded edits before a script moves or sizes `node`, when that layout could change
14
+ * where it lands, as Figma lays out a script's edits while it runs: the layer follows its frame's
15
+ * size, or a resize places its children from its own size. A layer pinned left and top, or one
16
+ * an auto layout places, lands the same either way, so its edits wait for the next read: a script
17
+ * that builds many layers lays out once rather than once per layer.
18
+ */
19
+ declare function flushPendingLayoutBefore(graph: SceneGraph, node: SceneNode, { placesChildren }?: {
20
+ placesChildren?: boolean;
21
+ }): void;
12
22
  //#endregion
13
- export { flushPendingLayout, startPendingLayout };
23
+ export { flushPendingLayout, flushPendingLayoutBefore, startPendingLayout };
14
24
  //# sourceMappingURL=pending-layout.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pending-layout.d.ts","names":[],"sources":["../../src/figma-api/pending-layout.ts"],"mappings":";;;;;;;;iBAgCgB,mBAAmB,OAAO;;iBAS1B,mBAAmB,OAAO"}
1
+ {"version":3,"file":"pending-layout.d.ts","names":[],"sources":["../../src/figma-api/pending-layout.ts"],"mappings":";;;;;;;;iBAkCgB,mBAAmB,OAAO;;iBAS1B,mBAAmB,OAAO;;;;;;;;iBAoD1B,yBACd,OAAO,YACP,MAAM,aACJ;EAA4B"}
@@ -1,4 +1,5 @@
1
1
  import { createLayoutRunner } from "../layout/mutations.js";
2
+ import { flushPendingComponentSync } from "./pending-sync.js";
2
3
  import { createSceneMutationImpact, recordSceneMutations } from "@pairdraw/scene-graph/mutation-impact";
3
4
  //#region src/figma-api/pending-layout.ts
4
5
  const pendingByGraph = /* @__PURE__ */ new WeakMap();
@@ -25,6 +26,7 @@ function startPendingLayout(graph) {
25
26
  }
26
27
  /** Lays out the edits recorded since the last geometry read. */
27
28
  function flushPendingLayout(graph) {
29
+ flushPendingComponentSync(graph);
28
30
  const pending = pendingByGraph.get(graph);
29
31
  if (!pending || pending.flushing || pending.impact.changedNodeIds.size === 0) return;
30
32
  const impact = structuredClone(pending.impact);
@@ -39,7 +41,45 @@ function flushPendingLayout(graph) {
39
41
  pending.flushing = false;
40
42
  }
41
43
  }
44
+ /** Whether a frame resizing would move or stretch the layer: a constraint other than left or top. */
45
+ function followsFrameSize(node) {
46
+ return node.horizontalConstraint !== "MIN" || node.verticalConstraint !== "MIN";
47
+ }
48
+ /** The layer and the layers above it, up to but not including its page. */
49
+ function layoutChain(graph, id) {
50
+ const chain = [];
51
+ for (let node = graph.getNode(id); node && node.type !== "CANVAS";) {
52
+ chain.push(node.id);
53
+ node = node.parentId ? graph.getNode(node.parentId) : void 0;
54
+ }
55
+ return chain;
56
+ }
57
+ /**
58
+ * Whether laying out the recorded edits could reach the layer: an edit sits in the same frame as
59
+ * the layer, at any depth, since a layer that grows makes every Hug frame around it grow. Edits
60
+ * in another top-level frame share only the page with it, and leave it where it is.
61
+ */
62
+ function editsReach(graph, impact, node) {
63
+ const above = new Set(layoutChain(graph, node.id));
64
+ return [
65
+ ...impact.changedNodeIds,
66
+ ...impact.currentParentIds,
67
+ ...impact.previousParentIds
68
+ ].some((id) => layoutChain(graph, id).some((current) => above.has(current)));
69
+ }
70
+ /**
71
+ * Lays out the recorded edits before a script moves or sizes `node`, when that layout could change
72
+ * where it lands, as Figma lays out a script's edits while it runs: the layer follows its frame's
73
+ * size, or a resize places its children from its own size. A layer pinned left and top, or one
74
+ * an auto layout places, lands the same either way, so its edits wait for the next read: a script
75
+ * that builds many layers lays out once rather than once per layer.
76
+ */
77
+ function flushPendingLayoutBefore(graph, node, { placesChildren = false } = {}) {
78
+ const pending = pendingByGraph.get(graph);
79
+ if (!pending || pending.flushing || pending.impact.changedNodeIds.size === 0) return;
80
+ if ((followsFrameSize(node) || placesChildren && graph.getChildren(node.id).some(followsFrameSize)) && editsReach(graph, pending.impact, node)) flushPendingLayout(graph);
81
+ }
42
82
  //#endregion
43
- export { flushPendingLayout, startPendingLayout };
83
+ export { flushPendingLayout, flushPendingLayoutBefore, startPendingLayout };
44
84
 
45
85
  //# sourceMappingURL=pending-layout.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pending-layout.js","names":[],"sources":["../../src/figma-api/pending-layout.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\nimport {\n createSceneMutationImpact,\n recordSceneMutations,\n type SceneMutationImpact\n} from '@pairdraw/scene-graph/mutation-impact'\n\nimport { createLayoutRunner } from '#core/layout/mutations'\n\ninterface PendingLayout {\n impact: SceneMutationImpact\n flushing: boolean\n}\n\nconst pendingByGraph = new WeakMap<SceneGraph, PendingLayout>()\n\nfunction clearImpact(impact: SceneMutationImpact): void {\n for (const ids of Object.values(impact)) ids.clear()\n}\n\nfunction mergeImpact(into: SceneMutationImpact, from: SceneMutationImpact): void {\n for (const key of Object.keys(into) as (keyof SceneMutationImpact)[]) {\n for (const id of from[key]) into[key].add(id)\n }\n}\n\n/**\n * Records the graph's edits so that reading geometry lays out what they touched first, as Figma\n * does: a script that fills a child and then reads its width sees the filled width. A graph has\n * one recorder for its lifetime, kept across APIs: a script that failed before its tool laid\n * out its edits leaves them for the next read to lay out.\n */\nexport function startPendingLayout(graph: SceneGraph): void {\n if (pendingByGraph.has(graph)) return\n const pending: PendingLayout = { impact: createSceneMutationImpact(), flushing: false }\n pendingByGraph.set(graph, pending)\n // Layout's own writes are its result, not new edits.\n recordSceneMutations(graph, pending.impact, () => !pending.flushing && !graph.isApplyingLayout)\n}\n\n/** Lays out the edits recorded since the last geometry read. */\nexport function flushPendingLayout(graph: SceneGraph): void {\n const pending = pendingByGraph.get(graph)\n if (!pending || pending.flushing || pending.impact.changedNodeIds.size === 0) return\n const impact = structuredClone(pending.impact)\n clearImpact(pending.impact)\n pending.flushing = true\n try {\n createLayoutRunner(() => graph).runLayoutForImpact(impact)\n } catch (error) {\n // The edits are still unlaid out, so the next read tries again.\n mergeImpact(pending.impact, impact)\n throw error\n } finally {\n pending.flushing = false\n }\n}\n"],"mappings":";;;AAcA,MAAM,iCAAiB,IAAI,QAAmC;AAE9D,SAAS,YAAY,QAAmC;CACtD,KAAK,MAAM,OAAO,OAAO,OAAO,MAAM,GAAG,IAAI,MAAM;AACrD;AAEA,SAAS,YAAY,MAA2B,MAAiC;CAC/E,KAAK,MAAM,OAAO,OAAO,KAAK,IAAI,GAChC,KAAK,MAAM,MAAM,KAAK,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE;AAEhD;;;;;;;AAQA,SAAgB,mBAAmB,OAAyB;CAC1D,IAAI,eAAe,IAAI,KAAK,GAAG;CAC/B,MAAM,UAAyB;EAAE,QAAQ,0BAA0B;EAAG,UAAU;CAAM;CACtF,eAAe,IAAI,OAAO,OAAO;CAEjC,qBAAqB,OAAO,QAAQ,cAAc,CAAC,QAAQ,YAAY,CAAC,MAAM,gBAAgB;AAChG;;AAGA,SAAgB,mBAAmB,OAAyB;CAC1D,MAAM,UAAU,eAAe,IAAI,KAAK;CACxC,IAAI,CAAC,WAAW,QAAQ,YAAY,QAAQ,OAAO,eAAe,SAAS,GAAG;CAC9E,MAAM,SAAS,gBAAgB,QAAQ,MAAM;CAC7C,YAAY,QAAQ,MAAM;CAC1B,QAAQ,WAAW;CACnB,IAAI;EACF,yBAAyB,KAAK,CAAC,CAAC,mBAAmB,MAAM;CAC3D,SAAS,OAAO;EAEd,YAAY,QAAQ,QAAQ,MAAM;EAClC,MAAM;CACR,UAAU;EACR,QAAQ,WAAW;CACrB;AACF"}
1
+ {"version":3,"file":"pending-layout.js","names":[],"sources":["../../src/figma-api/pending-layout.ts"],"sourcesContent":["import type { SceneGraph, SceneNode } from '@pairdraw/scene-graph'\nimport {\n createSceneMutationImpact,\n recordSceneMutations,\n type SceneMutationImpact\n} from '@pairdraw/scene-graph/mutation-impact'\n\nimport { createLayoutRunner } from '#core/layout/mutations'\n\nimport { flushPendingComponentSync } from './pending-sync'\n\ninterface PendingLayout {\n impact: SceneMutationImpact\n flushing: boolean\n}\n\nconst pendingByGraph = new WeakMap<SceneGraph, PendingLayout>()\n\nfunction clearImpact(impact: SceneMutationImpact): void {\n for (const ids of Object.values(impact)) ids.clear()\n}\n\nfunction mergeImpact(into: SceneMutationImpact, from: SceneMutationImpact): void {\n for (const key of Object.keys(into) as (keyof SceneMutationImpact)[]) {\n for (const id of from[key]) into[key].add(id)\n }\n}\n\n/**\n * Records the graph's edits so that reading geometry lays out what they touched first, as Figma\n * does: a script that fills a child and then reads its width sees the filled width. A graph has\n * one recorder for its lifetime, kept across APIs: a script that failed before its tool laid\n * out its edits leaves them for the next read to lay out.\n */\nexport function startPendingLayout(graph: SceneGraph): void {\n if (pendingByGraph.has(graph)) return\n const pending: PendingLayout = { impact: createSceneMutationImpact(), flushing: false }\n pendingByGraph.set(graph, pending)\n // Layout's own writes are its result, not new edits.\n recordSceneMutations(graph, pending.impact, () => !pending.flushing && !graph.isApplyingLayout)\n}\n\n/** Lays out the edits recorded since the last geometry read. */\nexport function flushPendingLayout(graph: SceneGraph): void {\n // Instances lay out what their components hold now.\n flushPendingComponentSync(graph)\n const pending = pendingByGraph.get(graph)\n if (!pending || pending.flushing || pending.impact.changedNodeIds.size === 0) return\n const impact = structuredClone(pending.impact)\n clearImpact(pending.impact)\n pending.flushing = true\n try {\n createLayoutRunner(() => graph).runLayoutForImpact(impact)\n } catch (error) {\n // The edits are still unlaid out, so the next read tries again.\n mergeImpact(pending.impact, impact)\n throw error\n } finally {\n pending.flushing = false\n }\n}\n\n/** Whether a frame resizing would move or stretch the layer: a constraint other than left or top. */\nfunction followsFrameSize(node: SceneNode): boolean {\n return node.horizontalConstraint !== 'MIN' || node.verticalConstraint !== 'MIN'\n}\n\n/** The layer and the layers above it, up to but not including its page. */\nfunction layoutChain(graph: SceneGraph, id: string): string[] {\n const chain: string[] = []\n for (let node = graph.getNode(id); node && node.type !== 'CANVAS';) {\n chain.push(node.id)\n node = node.parentId ? graph.getNode(node.parentId) : undefined\n }\n return chain\n}\n\n/**\n * Whether laying out the recorded edits could reach the layer: an edit sits in the same frame as\n * the layer, at any depth, since a layer that grows makes every Hug frame around it grow. Edits\n * in another top-level frame share only the page with it, and leave it where it is.\n */\nfunction editsReach(graph: SceneGraph, impact: SceneMutationImpact, node: SceneNode): boolean {\n const above = new Set(layoutChain(graph, node.id))\n const edited = [...impact.changedNodeIds, ...impact.currentParentIds, ...impact.previousParentIds]\n return edited.some((id) => layoutChain(graph, id).some((current) => above.has(current)))\n}\n\n/**\n * Lays out the recorded edits before a script moves or sizes `node`, when that layout could change\n * where it lands, as Figma lays out a script's edits while it runs: the layer follows its frame's\n * size, or a resize places its children from its own size. A layer pinned left and top, or one\n * an auto layout places, lands the same either way, so its edits wait for the next read: a script\n * that builds many layers lays out once rather than once per layer.\n */\nexport function flushPendingLayoutBefore(\n graph: SceneGraph,\n node: SceneNode,\n { placesChildren = false }: { placesChildren?: boolean } = {}\n): void {\n const pending = pendingByGraph.get(graph)\n if (!pending || pending.flushing || pending.impact.changedNodeIds.size === 0) return\n const depends =\n followsFrameSize(node) || (placesChildren && graph.getChildren(node.id).some(followsFrameSize))\n if (depends && editsReach(graph, pending.impact, node)) flushPendingLayout(graph)\n}\n"],"mappings":";;;;AAgBA,MAAM,iCAAiB,IAAI,QAAmC;AAE9D,SAAS,YAAY,QAAmC;CACtD,KAAK,MAAM,OAAO,OAAO,OAAO,MAAM,GAAG,IAAI,MAAM;AACrD;AAEA,SAAS,YAAY,MAA2B,MAAiC;CAC/E,KAAK,MAAM,OA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AO;EAAkB,GAAG,OAAO;CACpE,CAAC,CAAC,MAAM,OAAO,YAAY,OAAO,EAAE,CAAC,CAAC,MAAM,YAAY,MAAM,IAAI,OAAO,CAAC,CAAC;AACzF;;;;;;;;AASA,SAAgB,yBACd,OACA,MACA,EAAE,iBAAiB,UAAwC,CAAC,GACtD;CACN,MAAM,UAAU,eAAe,IAAI,KAAK;CACxC,IAAI,CAAC,WAAW,QAAQ,YAAY,QAAQ,OAAO,eAAe,SAAS,GAAG;CAG9E,KADE,iBAAiB,IAAI,KAAM,kBAAkB,MAAM,YAAY,KAAK,EAAE,CAAC,CAAC,KAAK,gBAAgB,MAChF,WAAW,OAAO,QAAQ,QAAQ,IAAI,GAAG,mBAAmB,KAAK;AAClF"}
@@ -0,0 +1,19 @@
1
+ import { SceneGraph } from "@pairdraw/scene-graph";
2
+ //#region src/figma-api/pending-sync.d.ts
3
+ /**
4
+ * Makes reading a layer bring instances in line with the component edits made before it, as Figma
5
+ * does at once: a script that recolors a component and then reads an instance sees the new color.
6
+ * A host that already syncs instances after edits, such as the editor, passes its own `flush`,
7
+ * which also lays out and redraws what it synced. Without one the graph records its edits itself,
8
+ * for its lifetime, as `startPendingLayout` does.
9
+ */
10
+ declare function startPendingComponentSync(graph: SceneGraph, flush?: () => void): void;
11
+ /**
12
+ * Syncs the instances of the components edited since, before a read; given the layer about to be
13
+ * read or written, only when it is in an instance, as only those layers change. Edits inside a
14
+ * component then sync once, when an instance is next read, not once per edit.
15
+ */
16
+ declare function flushPendingComponentSync(graph: SceneGraph, layerId?: string): void;
17
+ //#endregion
18
+ export { flushPendingComponentSync, startPendingComponentSync };
19
+ //# sourceMappingURL=pending-sync.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending-sync.d.ts","names":[],"sources":["../../src/figma-api/pending-sync.ts"],"mappings":";;;;;;;;;iBAiBgB,0BAA0B,OAAO,YAAY;;;;;;iBAsC7C,0BAA0B,OAAO,YAAY"}
@@ -0,0 +1,52 @@
1
+ import { syncComponentsHolding } from "../editor/component-sync.js";
2
+ import { createSceneMutationImpact, recordSceneMutations } from "@pairdraw/scene-graph/mutation-impact";
3
+ //#region src/figma-api/pending-sync.ts
4
+ const syncByGraph = /* @__PURE__ */ new WeakMap();
5
+ /**
6
+ * Makes reading a layer bring instances in line with the component edits made before it, as Figma
7
+ * does at once: a script that recolors a component and then reads an instance sees the new color.
8
+ * A host that already syncs instances after edits, such as the editor, passes its own `flush`,
9
+ * which also lays out and redraws what it synced. Without one the graph records its edits itself,
10
+ * for its lifetime, as `startPendingLayout` does.
11
+ */
12
+ function startPendingComponentSync(graph, flush) {
13
+ if (flush) {
14
+ syncByGraph.set(graph, flush);
15
+ return;
16
+ }
17
+ if (syncByGraph.has(graph)) return;
18
+ const impact = createSceneMutationImpact();
19
+ let syncing = false;
20
+ recordSceneMutations(graph, impact, () => !syncing && !graph.isApplyingImportedState && !graph.isApplyingLayout);
21
+ syncByGraph.set(graph, () => {
22
+ if (syncing || impact.changedNodeIds.size === 0) return;
23
+ const changed = [...impact.changedNodeIds];
24
+ const leftParents = [...impact.previousParentIds];
25
+ for (const recorded of Object.values(impact)) recorded.clear();
26
+ syncing = true;
27
+ try {
28
+ syncComponentsHolding(graph, [...changed, ...leftParents]);
29
+ } catch (error) {
30
+ for (const id of changed) impact.changedNodeIds.add(id);
31
+ for (const id of leftParents) impact.previousParentIds.add(id);
32
+ throw error;
33
+ } finally {
34
+ syncing = false;
35
+ }
36
+ });
37
+ }
38
+ /**
39
+ * Syncs the instances of the components edited since, before a read; given the layer about to be
40
+ * read or written, only when it is in an instance, as only those layers change. Edits inside a
41
+ * component then sync once, when an instance is next read, not once per edit.
42
+ */
43
+ function flushPendingComponentSync(graph, layerId) {
44
+ const flush = syncByGraph.get(graph);
45
+ if (!flush) return;
46
+ if (layerId !== void 0 && !graph.closest(layerId, (node) => node.type === "INSTANCE")) return;
47
+ flush();
48
+ }
49
+ //#endregion
50
+ export { flushPendingComponentSync, startPendingComponentSync };
51
+
52
+ //# sourceMappingURL=pending-sync.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pending-sync.js","names":[],"sources":["../../src/figma-api/pending-sync.ts"],"sourcesContent":["import type { SceneGraph } from '@pairdraw/scene-graph'\nimport {\n createSceneMutationImpact,\n recordSceneMutations\n} from '@pairdraw/scene-graph/mutation-impact'\n\nimport { syncComponentsHolding } from '#core/editor/component-sync'\n\nconst syncByGraph = new WeakMap<SceneGraph, () => void>()\n\n/**\n * Makes reading a layer bring instances in line with the component edits made before it, as Figma\n * does at once: a script that recolors a component and then reads an instance sees the new color.\n * A host that already syncs instances after edits, such as the editor, passes its own `flush`,\n * which also lays out and redraws what it synced. Without one the graph records its edits itself,\n * for its lifetime, as `startPendingLayout` does.\n */\nexport function startPendingComponentSync(graph: SceneGraph, flush?: () => void): void {\n if (flush) {\n syncByGraph.set(graph, flush)\n return\n }\n if (syncByGraph.has(graph)) return\n const impact = createSceneMutationImpact()\n let syncing = false\n // Syncing writes the instances it updates, which are results, not edits; so do loading and layout.\n recordSceneMutations(\n graph,\n impact,\n () => !syncing && !graph.isApplyingImportedState && !graph.isApplyingLayout\n )\n syncByGraph.set(graph, () => {\n if (syncing || impact.changedNodeIds.size === 0) return\n const changed = [...impact.changedNodeIds]\n const leftParents = [...impact.previousParentIds]\n for (const recorded of Object.values(impact)) recorded.clear()\n syncing = true\n try {\n syncComponentsHolding(graph, [...changed, ...leftParents])\n } catch (error) {\n // The edits are still unsynced, so the next read tries again, as pending layout does.\n for (const id of changed) impact.changedNodeIds.add(id)\n for (const id of leftParents) impact.previousParentIds.add(id)\n throw error\n } finally {\n syncing = false\n }\n })\n}\n\n/**\n * Syncs the instances of the components edited since, before a read; given the layer about to be\n * read or written, only when it is in an instance, as only those layers change. Edits inside a\n * component then sync once, when an instance is next read, not once per edit.\n */\nexport function flushPendingComponentSync(graph: SceneGraph, layerId?: string): void {\n const flush = syncByGraph.get(graph)\n if (!flush) return\n if (layerId !== undefined && !graph.closest(layerId, (node) => node.type === 'INSTANCE')) return\n flush()\n}\n"],"mappings":";;;AAQA,MAAM,8BAAc,IAAI,QAAgC;;;;;;;;AASxD,SAAgB,0BAA0B,OAAmB,OAA0B;CACrF,IAAI,OAAO;EACT,YAAY,IAAI,OAAO,KAAK;EAC5B;CACF;CACA,IAAI,YAAY,IAAI,KAAK,GAAG;CAC5B,MAAM,SAAS,0BAA0B;CACzC,IAAI,UAAU;CAEd,qBACE,OACA,cACM,CAAC,WAAW,CAAC,MAAM,2BAA2B,CAAC,MAAM,gBAC7D;CACA,YAAY,IAAI,aAAa;EAC3B,IAAI,WAAW,OAAO,eAAe,SAAS,GAAG;EACjD,MAAM,UAAU,CAAC,GAAG,OAAO,cAAc;EACzC,MAAM,cAAc,CAAC,GAAG,OAAO,iBAAiB;EAChD,KAAK,MAAM,YAAY,OAAO,OAAO,MAAM,GAAG,SAAS,MAAM;EAC7D,UAAU;EACV,IAAI;GACF,sBAAsB,OAAO,CAAC,GAAG,SAAS,GAAG,WAAW,CAAC;EAC3D,SAAS,OAAO;GAEd,KAAK,MAAM,MAAM,SAAS,OAAO,eAAe,IAAI,EAAE;GACtD,KAAK,MAAM,MAAM,aAAa,OAAO,kBAAkB,IAAI,EAAE;GAC7D,MAAM;EACR,UAAU;GACR,UAAU;EACZ;CACF,CAAC;AACH;;;;;;AAOA,SAAgB,0BAA0B,OAAmB,SAAwB;CACnF,MAAM,QAAQ,YAAY,IAAI,KAAK;CACnC,IAAI,CAAC,OAAO;CACZ,IAAI,YAAY,KAAA,KAAa,CAAC,MAAM,QAAQ,UAAU,SAAS,KAAK,SAAS,UAAU,GAAG;CAC1F,MAAM;AACR"}
@@ -2,13 +2,15 @@ import { FigmaFont, FigmaFontName } from "./fonts/names.js";
2
2
  import { FigmaEffect } from "./effects.js";
3
3
  import { FigmaTransform } from "./types.js";
4
4
  import { FigmaPaint } from "./paints.js";
5
- import { FigmaLetterSpacing, FigmaLineHeight, InsertStyleSource } from "./text/index.js";
5
+ import { InsertStyleSource } from "../text/style-runs.js";
6
+ import { FigmaLetterSpacing, FigmaLineHeight } from "./text/index.js";
6
7
  import { TextRangeMethods } from "./accessors/text/ranges.js";
7
8
  import { VariableNodeMembers } from "./accessors/variables.js";
8
9
  import { FigmaVectorNetwork, FigmaVectorPath } from "./accessors/vector.js";
9
10
  import { FigmaDevStatusValue } from "./dev-status.js";
10
11
  import { FigmaInstanceOverride } from "./overrides.js";
11
12
  import { PluginDataMethods } from "./plugin-data.js";
13
+ import { FigmaReaction } from "./reactions.js";
12
14
  import { FigmaFrameNode, FigmaInstanceNode } from "./node-types.js";
13
15
  import { ArcData, HyperlinkTarget, LayoutGrid, LayoutMode, NodeType, SceneGraph, SceneNode } from "@pairdraw/scene-graph";
14
16
  import { ShapeWithTextType } from "@pairdraw/scene-graph/shape-with-text";
@@ -19,6 +21,15 @@ declare const MIXED: unique symbol;
19
21
  declare const INTERNAL_ID: unique symbol;
20
22
  declare const INTERNAL_GRAPH: unique symbol;
21
23
  declare const INTERNAL_API: unique symbol;
24
+ /** How a host loads pages as they are visited; see `FigmaAPIOptions`. */
25
+ interface PageHost {
26
+ load: (pageId: string) => Promise<void>;
27
+ pageOfNode?: (nodeId: string) => Promise<string | null>;
28
+ }
29
+ declare function setPageHost(api: NodeProxyHost, host: PageHost): void;
30
+ declare function loadPage(api: NodeProxyHost, pageId: string): Promise<void>;
31
+ /** The page holding a layer not loaded yet, which loading that page brings in. */
32
+ declare function pageOfNode(api: NodeProxyHost, nodeId: string): Promise<string | null>;
22
33
  interface NodeProxyHost {
23
34
  wrapNode(id: string): FigmaNodeProxy;
24
35
  readonly currentPageId: string;
@@ -115,6 +126,8 @@ declare class FigmaNodeProxy {
115
126
  readonly boundVariables: VariableNodeMembers['boundVariables'];
116
127
  setBoundVariable: VariableNodeMembers['setBoundVariable'];
117
128
  readonly overrides: FigmaInstanceOverride[] | undefined;
129
+ /** Prototype connections, in Figma's plugin shape; refused when the play cannot run them. */
130
+ reactions: readonly FigmaReaction[];
118
131
  /** A sticky note's body or a shape's label, a sticky's author line, and whether it is wide. */
119
132
  readonly text: FigmaNodeProxy | undefined;
120
133
  readonly authorName: string | undefined;
@@ -246,5 +259,5 @@ declare class FigmaNodeProxy {
246
259
  toString(): string;
247
260
  }
248
261
  //#endregion
249
- export { type FigmaFont, type FigmaFontName, FigmaNodeProxy, INTERNAL_API, INTERNAL_GRAPH, INTERNAL_ID, MIXED, NodeProxyHost };
262
+ export { type FigmaFont, type FigmaFontName, FigmaNodeProxy, INTERNAL_API, INTERNAL_GRAPH, INTERNAL_ID, MIXED, NodeProxyHost, PageHost, loadPage, pageOfNode, setPageHost };
250
263
  //# sourceMappingURL=proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"proxy.d.ts","names":[],"sources":["../../src/figma-api/proxy.ts"],"mappings":";;;;;;;;;;;;;;;;;cAuDM;cAIO;cACA;cACA;UAEI;EACf,SAAS,aAAa;WACb;;WAEA,iBAAiB;;cAgBf;GACV;GACA,iBAAiB;GACjB,eAAe;WAEC;;WAEA,MAAM;EACf;WACS;EACT;EACA;WACS;WACA;EACT;EACA,mBAAmB;EACnB,SAAS,eAAe;EACxB,2BAA2B,eAAe;EAC1C,UAAU;WACD,mBAAmB;WACnB,qBAAqB;WACrB,sBAAsB;EAE/B,gBAAgB;EAChB,kBAAkB;EAClB,kBAAkB;EAClB;EACA;EACA;EACA,WAAW;EACX;EACA;EACA,8BAA8B;EAC9B;EACA;EACA;EACA;EACA;EAEA,YAAY;EACZ,sBAAsB;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IAAe;IAAoB;;EACnC;EACA;EACA;EACA;WACS,mBAAmB;;EAE5B;EACA;EACA;EACA;EACA;EACA,SAAS,SAAS;EAClB,sBAAsB;EACtB,eAAe;EACf,wBAAwB,eAAe,uBAAuB;EAC9D,iBAAiB,sCAAsC;EACvD,eAAe;EACf,eAAe;E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P;MAIA,SAAS;MAOT;MAIA,SAAS;MAMT,wBAAwB;MAUxB,YAAY,gBAAgB;;EAM1B,yBAAyB,QAAQ;MAInC,iBAAiB;EAQrB,kBAAkB;;EAWlB,kBAAkB;;EAUlB,cAAc,WAAW;MAWrB,UAAU;MAMV,YAAY;EAMhB,YAAY,OAAO;;;;;UAiBX;EAaR,YAAY,eAAe,OAAO;EAclC,SAAS;EAgBT;EAWA,QAAQ,YAAY,MAAM,6BAA6B;EAIvD,QAAQ,WAAW,MAAM,6BAA6B;EAItD,UAAU,WAAW,MAAM,6BAA6B;EASxD,aAAa,YAAY,MAAM,6BAA6B;EAS5D,oBAAoB;IAAY;MAAqB;EAWrD,OAAO,mBAAmB,wBAAmB;EAU7C"}
1
+ {"version":3,"file":"proxy.d.ts","names":[],"sources":["../../src/figma-api/proxy.ts"],"mappings":";;;;;;;;;;;;;;;;;;;cA0DM;cAIO;cACA;cACA;;UAGI;EACf,OAAO,mBAAmB;EAC1B,cAAc,mBAAmB;;iBASnB,YAAY,KAAK,eAAe,MAAM;iBAItC,SAAS,KAAK,eAAe,iBAAiB;;iBAK9C,WAAW,KAAK,eAAe,iBAAiB;UAI/C;EACf,SAAS,aAAa;WACb;;WAEA,iBAAiB;;cAgBf;GACV;GACA,iBAAiB;GACjB,eAAe;WAEC;;WAEA,MAAM;EACf;WACS;EACT;EACA;WACS;WACA;EACT;EACA,mBAAmB;EACnB,SAAS,eAAe;EACxB,2BAA2B,eAAe;EAC1C,UAAU;WACD,mBAAmB;WACnB,qBAAqB;WACrB,sBAAsB;EAE/B,gBAAgB;EAChB,kBAAkB;EAClB,kBAAkB;EAClB;EACA;EACA;EACA,WAAW;EACX;EACA;EACA,8BAA8B;EAC9B;EACA;EACA;EACA;EACA;EAEA,YAAY;EACZ,sBAAsB;EACtB;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;IAAe;IAAoB;;EACnC;E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