@open-pencil/scene-graph 0.17.0 → 0.18.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (986) hide show
  1. package/dist/arrow-caps.d.ts +14 -17
  2. package/dist/arrow-caps.d.ts.map +1 -1
  3. package/dist/arrow-caps.js +1 -2
  4. package/dist/asset-keys.d.ts +5 -8
  5. package/dist/asset-keys.d.ts.map +1 -1
  6. package/dist/asset-keys.js +2 -3
  7. package/dist/behaviours/index.d.ts +6 -4
  8. package/dist/behaviours/index.js +6 -4
  9. package/dist/behaviours/kinds.d.ts +38 -15
  10. package/dist/behaviours/kinds.d.ts.map +1 -1
  11. package/dist/behaviours/kinds.js +134 -12
  12. package/dist/behaviours/kinds.js.map +1 -1
  13. package/dist/behaviours/layers.d.ts +3 -6
  14. package/dist/behaviours/layers.d.ts.map +1 -1
  15. package/dist/behaviours/layers.js +1 -2
  16. package/dist/behaviours/listing.d.ts +58 -0
  17. package/dist/behaviours/listing.d.ts.map +1 -0
  18. package/dist/behaviours/listing.js +98 -0
  19. package/dist/behaviours/listing.js.map +1 -0
  20. package/dist/behaviours/model.d.ts +19 -16
  21. package/dist/behaviours/model.d.ts.map +1 -1
  22. package/dist/behaviours/model.js +14 -6
  23. package/dist/behaviours/model.js.map +1 -1
  24. package/dist/behaviours/schema.d.ts +150 -17
  25. package/dist/behaviours/schema.d.ts.map +1 -1
  26. package/dist/behaviours/schema.js +19 -5
  27. package/dist/behaviours/schema.js.map +1 -1
  28. package/dist/behaviours/spec.d.ts +3 -6
  29. package/dist/behaviours/spec.d.ts.map +1 -1
  30. package/dist/behaviours/spec.js +7 -4
  31. package/dist/behaviours/spec.js.map +1 -1
  32. package/dist/behaviours/transition.d.ts +20 -0
  33. package/dist/behaviours/transition.d.ts.map +1 -0
  34. package/dist/behaviours/transition.js +35 -0
  35. package/dist/behaviours/transition.js.map +1 -0
  36. package/dist/bindings.js +2 -3
  37. package/dist/blur.d.ts +35 -0
  38. package/dist/blur.d.ts.map +1 -0
  39. package/dist/blur.js +69 -0
  40. package/dist/blur.js.map +1 -0
  41. package/dist/buffered-events.d.ts +3 -6
  42. package/dist/buffered-events.d.ts.map +1 -1
  43. package/dist/buffered-events.js +1 -2
  44. package/dist/buffered-events.js.map +1 -1
  45. package/dist/checkpoint.d.ts +3 -6
  46. package/dist/checkpoint.d.ts.map +1 -1
  47. package/dist/checkpoint.js +4 -3
  48. package/dist/checkpoint.js.map +1 -1
  49. package/dist/clipping.d.ts +4 -7
  50. package/dist/clipping.d.ts.map +1 -1
  51. package/dist/clipping.js +4 -16
  52. package/dist/clipping.js.map +1 -1
  53. package/dist/color/contrast.d.ts +4 -7
  54. package/dist/color/contrast.d.ts.map +1 -1
  55. package/dist/color/contrast.js +2 -3
  56. package/dist/color/index.d.ts +21 -20
  57. package/dist/color/index.d.ts.map +1 -1
  58. package/dist/color/index.js +16 -27
  59. package/dist/color/index.js.map +1 -1
  60. package/dist/color/management.d.ts +50 -25
  61. package/dist/color/management.d.ts.map +1 -1
  62. package/dist/color/management.js +155 -151
  63. package/dist/color/management.js.map +1 -1
  64. package/dist/color/normalize.d.ts +1 -4
  65. package/dist/color/normalize.d.ts.map +1 -1
  66. package/dist/color/normalize.js +1 -2
  67. package/dist/color/okhcl.d.ts +36 -21
  68. package/dist/color/okhcl.d.ts.map +1 -1
  69. package/dist/color/okhcl.js +57 -42
  70. package/dist/color/okhcl.js.map +1 -1
  71. package/dist/color/schema.d.ts +6 -4
  72. package/dist/color/schema.d.ts.map +1 -1
  73. package/dist/color/schema.js +12 -4
  74. package/dist/color/schema.js.map +1 -1
  75. package/dist/comments/document.d.ts +3 -6
  76. package/dist/comments/document.d.ts.map +1 -1
  77. package/dist/comments/document.js +1 -2
  78. package/dist/comments/index.js +2 -2
  79. package/dist/comments/list.d.ts +5 -8
  80. package/dist/comments/list.d.ts.map +1 -1
  81. package/dist/comments/list.js +1 -2
  82. package/dist/comments/merge.d.ts +2 -5
  83. package/dist/comments/merge.d.ts.map +1 -1
  84. package/dist/comments/merge.js +1 -2
  85. package/dist/comments/schema.d.ts +2 -5
  86. package/dist/comments/schema.d.ts.map +1 -1
  87. package/dist/comments/schema.js +1 -2
  88. package/dist/comments/threads.d.ts +16 -19
  89. package/dist/comments/threads.d.ts.map +1 -1
  90. package/dist/comments/threads.js +8 -3
  91. package/dist/comments/threads.js.map +1 -1
  92. package/dist/components/exposure.d.ts +4 -7
  93. package/dist/components/exposure.d.ts.map +1 -1
  94. package/dist/components/exposure.js +1 -2
  95. package/dist/components/properties.d.ts +13 -16
  96. package/dist/components/properties.d.ts.map +1 -1
  97. package/dist/components/properties.js +3 -4
  98. package/dist/components/variants.d.ts +5 -8
  99. package/dist/components/variants.d.ts.map +1 -1
  100. package/dist/components/variants.js +1 -2
  101. package/dist/connectors/controls.d.ts +6 -9
  102. package/dist/connectors/controls.d.ts.map +1 -1
  103. package/dist/connectors/controls.js +2 -3
  104. package/dist/connectors/create.d.ts +3 -6
  105. package/dist/connectors/create.d.ts.map +1 -1
  106. package/dist/connectors/create.js +2 -3
  107. package/dist/connectors/elbow.js +0 -1
  108. package/dist/connectors/gaps.d.ts +1 -4
  109. package/dist/connectors/gaps.d.ts.map +1 -1
  110. package/dist/connectors/gaps.js +1 -2
  111. package/dist/connectors/hit.d.ts +1 -4
  112. package/dist/connectors/hit.d.ts.map +1 -1
  113. package/dist/connectors/hit.js +3 -4
  114. package/dist/connectors/index.d.ts +3 -3
  115. package/dist/connectors/index.js +6 -6
  116. package/dist/connectors/label.d.ts +4 -7
  117. package/dist/connectors/label.d.ts.map +1 -1
  118. package/dist/connectors/label.js +1 -2
  119. package/dist/connectors/layout.d.ts +8 -10
  120. package/dist/connectors/layout.d.ts.map +1 -1
  121. package/dist/connectors/layout.js +12 -10
  122. package/dist/connectors/layout.js.map +1 -1
  123. package/dist/connectors/pieces.d.ts +2 -5
  124. package/dist/connectors/pieces.d.ts.map +1 -1
  125. package/dist/connectors/pieces.js +3 -4
  126. package/dist/connectors/pieces.js.map +1 -1
  127. package/dist/connectors/route.d.ts +2 -5
  128. package/dist/connectors/route.d.ts.map +1 -1
  129. package/dist/connectors/route.js +4 -5
  130. package/dist/connectors/sides.d.ts +3 -6
  131. package/dist/connectors/sides.d.ts.map +1 -1
  132. package/dist/connectors/sides.js +2 -3
  133. package/dist/connectors/sublayers.d.ts +21 -24
  134. package/dist/connectors/sublayers.d.ts.map +1 -1
  135. package/dist/connectors/sublayers.js +3 -3
  136. package/dist/connectors/sublayers.js.map +1 -1
  137. package/dist/constants.d.ts +13 -16
  138. package/dist/constants.d.ts.map +1 -1
  139. package/dist/constants.js +1 -2
  140. package/dist/constraints.d.ts +6 -8
  141. package/dist/constraints.d.ts.map +1 -1
  142. package/dist/constraints.js +3 -3
  143. package/dist/constraints.js.map +1 -1
  144. package/dist/coordinate.d.ts +27 -29
  145. package/dist/coordinate.d.ts.map +1 -1
  146. package/dist/coordinate.js +19 -38
  147. package/dist/coordinate.js.map +1 -1
  148. package/dist/copy.d.ts +36 -24
  149. package/dist/copy.d.ts.map +1 -1
  150. package/dist/copy.js +33 -4
  151. package/dist/copy.js.map +1 -1
  152. package/dist/corners.d.ts +9 -9
  153. package/dist/corners.d.ts.map +1 -1
  154. package/dist/corners.js +4 -3
  155. package/dist/corners.js.map +1 -1
  156. package/dist/css/blend.d.ts +1 -4
  157. package/dist/css/blend.d.ts.map +1 -1
  158. package/dist/css/blend.js +1 -2
  159. package/dist/css/grid.d.ts +1 -4
  160. package/dist/css/grid.d.ts.map +1 -1
  161. package/dist/css/grid.js +3 -4
  162. package/dist/css/index.d.ts +2 -1
  163. package/dist/css/index.js +3 -2
  164. package/dist/css/layout.d.ts +7 -10
  165. package/dist/css/layout.d.ts.map +1 -1
  166. package/dist/css/layout.js +2 -3
  167. package/dist/css/motion.d.ts +9 -0
  168. package/dist/css/motion.d.ts.map +1 -0
  169. package/dist/css/motion.js +59 -0
  170. package/dist/css/motion.js.map +1 -0
  171. package/dist/css/shadows.d.ts +4 -6
  172. package/dist/css/shadows.d.ts.map +1 -1
  173. package/dist/css/shadows.js +9 -9
  174. package/dist/css/shadows.js.map +1 -1
  175. package/dist/css/text.d.ts +8 -11
  176. package/dist/css/text.d.ts.map +1 -1
  177. package/dist/css/text.js +1 -2
  178. package/dist/css/transform.d.ts +6 -9
  179. package/dist/css/transform.d.ts.map +1 -1
  180. package/dist/css/transform.js +2 -3
  181. package/dist/css/values.d.ts +11 -13
  182. package/dist/css/values.d.ts.map +1 -1
  183. package/dist/css/values.js +5 -6
  184. package/dist/css/values.js.map +1 -1
  185. package/dist/cubic.d.ts +11 -5
  186. package/dist/cubic.d.ts.map +1 -1
  187. package/dist/cubic.js +71 -3
  188. package/dist/cubic.js.map +1 -1
  189. package/dist/events.js +1 -2
  190. package/dist/export-format.d.ts +5 -8
  191. package/dist/export-format.d.ts.map +1 -1
  192. package/dist/export-format.js +4 -3
  193. package/dist/export-format.js.map +1 -1
  194. package/dist/export-scale.d.ts +4 -7
  195. package/dist/export-scale.d.ts.map +1 -1
  196. package/dist/export-scale.js +1 -2
  197. package/dist/fields/appearance.d.ts +3 -6
  198. package/dist/fields/appearance.d.ts.map +1 -1
  199. package/dist/fields/appearance.js +1 -2
  200. package/dist/fields/geometry.d.ts +2 -5
  201. package/dist/fields/geometry.d.ts.map +1 -1
  202. package/dist/fields/geometry.js +1 -2
  203. package/dist/fields/index.d.ts +2 -2
  204. package/dist/fields/index.js +3 -3
  205. package/dist/fields/layout.d.ts +5 -6
  206. package/dist/fields/layout.d.ts.map +1 -1
  207. package/dist/fields/layout.js +10 -3
  208. package/dist/fields/layout.js.map +1 -1
  209. package/dist/fields/text.d.ts +5 -8
  210. package/dist/fields/text.d.ts.map +1 -1
  211. package/dist/fields/text.js +1 -2
  212. package/dist/fig-compression.d.ts +3 -6
  213. package/dist/fig-compression.d.ts.map +1 -1
  214. package/dist/fig-compression.js +1 -2
  215. package/dist/figjam/index.js +1 -1
  216. package/dist/figjam/palette.d.ts +21 -23
  217. package/dist/figjam/palette.d.ts.map +1 -1
  218. package/dist/figjam/palette.js +3 -4
  219. package/dist/figjam/text.d.ts +10 -13
  220. package/dist/figjam/text.d.ts.map +1 -1
  221. package/dist/figjam/text.js +1 -2
  222. package/dist/font-style.d.ts +18 -18
  223. package/dist/font-style.d.ts.map +1 -1
  224. package/dist/font-style.js +12 -8
  225. package/dist/font-style.js.map +1 -1
  226. package/dist/generated/index.d.ts +35 -15
  227. package/dist/generated/index.d.ts.map +1 -1
  228. package/dist/generated/index.js +50 -12
  229. package/dist/generated/index.js.map +1 -1
  230. package/dist/generated/kind.d.ts +17 -6
  231. package/dist/generated/kind.d.ts.map +1 -1
  232. package/dist/generated/shape-with-text.d.ts +10 -13
  233. package/dist/generated/shape-with-text.d.ts.map +1 -1
  234. package/dist/generated/shape-with-text.js +3 -3
  235. package/dist/generated/shape-with-text.js.map +1 -1
  236. package/dist/generated/spec.d.ts +45 -0
  237. package/dist/generated/spec.d.ts.map +1 -0
  238. package/dist/generated/spec.js +281 -0
  239. package/dist/generated/spec.js.map +1 -0
  240. package/dist/generated/sticky.d.ts +23 -26
  241. package/dist/generated/sticky.d.ts.map +1 -1
  242. package/dist/generated/sticky.js +4 -4
  243. package/dist/generated/sticky.js.map +1 -1
  244. package/dist/geometry.d.ts +47 -68
  245. package/dist/geometry.d.ts.map +1 -1
  246. package/dist/geometry.js +53 -77
  247. package/dist/geometry.js.map +1 -1
  248. package/dist/gradient.d.ts +15 -18
  249. package/dist/gradient.d.ts.map +1 -1
  250. package/dist/gradient.js +1 -2
  251. package/dist/graph.d.ts +33 -11
  252. package/dist/graph.d.ts.map +1 -1
  253. package/dist/graph.js +85 -28
  254. package/dist/graph.js.map +1 -1
  255. package/dist/group-bounds.d.ts +15 -14
  256. package/dist/group-bounds.d.ts.map +1 -1
  257. package/dist/group-bounds.js +41 -12
  258. package/dist/group-bounds.js.map +1 -1
  259. package/dist/guides.d.ts +5 -8
  260. package/dist/guides.d.ts.map +1 -1
  261. package/dist/guides.js +2 -3
  262. package/dist/hit-test.d.ts +20 -12
  263. package/dist/hit-test.d.ts.map +1 -1
  264. package/dist/hit-test.js +69 -38
  265. package/dist/hit-test.js.map +1 -1
  266. package/dist/icons/fit.d.ts +2 -4
  267. package/dist/icons/fit.d.ts.map +1 -1
  268. package/dist/icons/fit.js +1 -2
  269. package/dist/icons/glyph.d.ts +3 -5
  270. package/dist/icons/glyph.d.ts.map +1 -1
  271. package/dist/icons/glyph.js +3 -4
  272. package/dist/icons/index.d.ts +1 -1
  273. package/dist/icons/index.js +2 -2
  274. package/dist/icons/model.d.ts +8 -11
  275. package/dist/icons/model.d.ts.map +1 -1
  276. package/dist/icons/model.js +1 -2
  277. package/dist/icons/schema.d.ts +8 -11
  278. package/dist/icons/schema.d.ts.map +1 -1
  279. package/dist/icons/schema.js +1 -2
  280. package/dist/ids.d.ts +2 -5
  281. package/dist/ids.d.ts.map +1 -1
  282. package/dist/ids.js +3 -4
  283. package/dist/images.d.ts +20 -21
  284. package/dist/images.d.ts.map +1 -1
  285. package/dist/images.js +7 -6
  286. package/dist/images.js.map +1 -1
  287. package/dist/index.d.ts +2 -2
  288. package/dist/index.js +3 -3
  289. package/dist/instances/assignments.js +1 -2
  290. package/dist/instances/content-marks.js +98 -0
  291. package/dist/instances/content-marks.js.map +1 -0
  292. package/dist/instances/content-size.js +2 -3
  293. package/dist/instances/copies.js +2 -3
  294. package/dist/instances/cycles.d.ts +3 -6
  295. package/dist/instances/cycles.d.ts.map +1 -1
  296. package/dist/instances/cycles.js +1 -2
  297. package/dist/instances/deleted.d.ts +23 -0
  298. package/dist/instances/deleted.d.ts.map +1 -0
  299. package/dist/instances/deleted.js +82 -0
  300. package/dist/instances/deleted.js.map +1 -0
  301. package/dist/instances/fields.d.ts +5 -8
  302. package/dist/instances/fields.d.ts.map +1 -1
  303. package/dist/instances/fields.js +11 -7
  304. package/dist/instances/fields.js.map +1 -1
  305. package/dist/instances/index.d.ts +21 -20
  306. package/dist/instances/index.d.ts.map +1 -1
  307. package/dist/instances/index.js +116 -20
  308. package/dist/instances/index.js.map +1 -1
  309. package/dist/instances/kept-overrides.js +4 -5
  310. package/dist/instances/lookup.d.ts +17 -0
  311. package/dist/instances/lookup.d.ts.map +1 -0
  312. package/dist/instances/lookup.js +48 -0
  313. package/dist/instances/lookup.js.map +1 -0
  314. package/dist/instances/main-component.d.ts +2 -5
  315. package/dist/instances/main-component.d.ts.map +1 -1
  316. package/dist/instances/main-component.js +1 -2
  317. package/dist/instances/matching.js +1 -2
  318. package/dist/instances/overrides.d.ts +23 -26
  319. package/dist/instances/overrides.d.ts.map +1 -1
  320. package/dist/instances/overrides.js +1 -2
  321. package/dist/instances/placement.js +3 -4
  322. package/dist/instances/protection.js +3 -4
  323. package/dist/instances/source-walk.js +1 -2
  324. package/dist/instances/swap.js +7 -8
  325. package/dist/instances/sync.js +91 -18
  326. package/dist/instances/sync.js.map +1 -1
  327. package/dist/instances/vector-geometry.js +2 -3
  328. package/dist/layout/aspect-ratio.d.ts +7 -9
  329. package/dist/layout/aspect-ratio.d.ts.map +1 -1
  330. package/dist/layout/aspect-ratio.js +1 -2
  331. package/dist/layout/flow.d.ts +13 -0
  332. package/dist/layout/flow.d.ts.map +1 -0
  333. package/dist/layout/flow.js +35 -0
  334. package/dist/layout/flow.js.map +1 -0
  335. package/dist/layout/guides.d.ts +13 -16
  336. package/dist/layout/guides.d.ts.map +1 -1
  337. package/dist/layout/guides.js +4 -5
  338. package/dist/layout/guides.js.map +1 -1
  339. package/dist/layout/index.d.ts +6 -4
  340. package/dist/layout/index.js +7 -5
  341. package/dist/layout/keywords.d.ts +7 -9
  342. package/dist/layout/keywords.d.ts.map +1 -1
  343. package/dist/layout/keywords.js +8 -3
  344. package/dist/layout/keywords.js.map +1 -1
  345. package/dist/layout/limits.d.ts +13 -16
  346. package/dist/layout/limits.d.ts.map +1 -1
  347. package/dist/layout/limits.js +1 -2
  348. package/dist/layout/sizing.d.ts +18 -12
  349. package/dist/layout/sizing.d.ts.map +1 -1
  350. package/dist/layout/sizing.js +18 -3
  351. package/dist/layout/sizing.js.map +1 -1
  352. package/dist/layout/spacing.d.ts +7 -4
  353. package/dist/layout/spacing.d.ts.map +1 -1
  354. package/dist/layout/spacing.js +11 -3
  355. package/dist/layout/spacing.js.map +1 -1
  356. package/dist/layout/stacking.d.ts +8 -0
  357. package/dist/layout/stacking.d.ts.map +1 -0
  358. package/dist/layout/stacking.js +12 -0
  359. package/dist/layout/stacking.js.map +1 -0
  360. package/dist/layout/strokes.d.ts +1 -4
  361. package/dist/layout/strokes.d.ts.map +1 -1
  362. package/dist/layout/strokes.js +1 -2
  363. package/dist/layout/writes.js +1 -2
  364. package/dist/layout/writes.js.map +1 -1
  365. package/dist/masks.d.ts +4 -7
  366. package/dist/masks.d.ts.map +1 -1
  367. package/dist/masks.js +1 -2
  368. package/dist/matrix.d.ts +3 -4
  369. package/dist/matrix.d.ts.map +1 -1
  370. package/dist/matrix.js +11 -3
  371. package/dist/matrix.js.map +1 -1
  372. package/dist/mesh/geometry.d.ts +80 -0
  373. package/dist/mesh/geometry.d.ts.map +1 -0
  374. package/dist/mesh/geometry.js +430 -0
  375. package/dist/mesh/geometry.js.map +1 -0
  376. package/dist/mesh/index.d.ts +4 -0
  377. package/dist/mesh/index.js +4 -0
  378. package/dist/mesh/model.d.ts +25 -0
  379. package/dist/mesh/model.d.ts.map +1 -0
  380. package/dist/mesh/model.js +39 -0
  381. package/dist/mesh/model.js.map +1 -0
  382. package/dist/mesh/schema.d.ts +188 -0
  383. package/dist/mesh/schema.d.ts.map +1 -0
  384. package/dist/mesh/schema.js +55 -0
  385. package/dist/mesh/schema.js.map +1 -0
  386. package/dist/motion/apply.d.ts +42 -0
  387. package/dist/motion/apply.d.ts.map +1 -0
  388. package/dist/motion/apply.js +98 -0
  389. package/dist/motion/apply.js.map +1 -0
  390. package/dist/motion/edit.d.ts +53 -0
  391. package/dist/motion/edit.d.ts.map +1 -0
  392. package/dist/motion/edit.js +125 -0
  393. package/dist/motion/edit.js.map +1 -0
  394. package/dist/motion/effects.js +86 -0
  395. package/dist/motion/effects.js.map +1 -0
  396. package/dist/motion/evaluate.d.ts +33 -0
  397. package/dist/motion/evaluate.d.ts.map +1 -0
  398. package/dist/motion/evaluate.js +160 -0
  399. package/dist/motion/evaluate.js.map +1 -0
  400. package/dist/motion/fields.d.ts +69 -0
  401. package/dist/motion/fields.d.ts.map +1 -0
  402. package/dist/motion/fields.js +132 -0
  403. package/dist/motion/fields.js.map +1 -0
  404. package/dist/motion/index.d.ts +16 -0
  405. package/dist/motion/index.js +15 -0
  406. package/dist/motion/keyable.d.ts +32 -0
  407. package/dist/motion/keyable.d.ts.map +1 -0
  408. package/dist/motion/keyable.js +120 -0
  409. package/dist/motion/keyable.js.map +1 -0
  410. package/dist/motion/outline.d.ts +35 -0
  411. package/dist/motion/outline.d.ts.map +1 -0
  412. package/dist/motion/outline.js +59 -0
  413. package/dist/motion/outline.js.map +1 -0
  414. package/dist/motion/presets/index.d.ts +20 -0
  415. package/dist/motion/presets/index.d.ts.map +1 -0
  416. package/dist/motion/presets/index.js +166 -0
  417. package/dist/motion/presets/index.js.map +1 -0
  418. package/dist/motion/presets/settings.d.ts +43 -0
  419. package/dist/motion/presets/settings.d.ts.map +1 -0
  420. package/dist/motion/presets/settings.js +254 -0
  421. package/dist/motion/presets/settings.js.map +1 -0
  422. package/dist/motion/presets/stagger.d.ts +69 -0
  423. package/dist/motion/presets/stagger.d.ts.map +1 -0
  424. package/dist/motion/presets/stagger.js +185 -0
  425. package/dist/motion/presets/stagger.js.map +1 -0
  426. package/dist/motion/schema.d.ts +185 -0
  427. package/dist/motion/schema.d.ts.map +1 -0
  428. package/dist/motion/schema.js +62 -0
  429. package/dist/motion/schema.js.map +1 -0
  430. package/dist/motion/segment.d.ts +25 -0
  431. package/dist/motion/segment.d.ts.map +1 -0
  432. package/dist/motion/segment.js +73 -0
  433. package/dist/motion/segment.js.map +1 -0
  434. package/dist/motion/spec.d.ts +26 -0
  435. package/dist/motion/spec.d.ts.map +1 -0
  436. package/dist/motion/spec.js +175 -0
  437. package/dist/motion/spec.js.map +1 -0
  438. package/dist/motion/timeline.d.ts +16 -0
  439. package/dist/motion/timeline.d.ts.map +1 -0
  440. package/dist/motion/timeline.js +53 -0
  441. package/dist/motion/timeline.js.map +1 -0
  442. package/dist/motion/types.d.ts +49 -0
  443. package/dist/motion/types.d.ts.map +1 -0
  444. package/dist/motion/variables.d.ts +9 -0
  445. package/dist/motion/variables.d.ts.map +1 -0
  446. package/dist/motion/variables.js +25 -0
  447. package/dist/motion/variables.js.map +1 -0
  448. package/dist/mutation-impact.d.ts +9 -10
  449. package/dist/mutation-impact.d.ts.map +1 -1
  450. package/dist/mutation-impact.js +19 -9
  451. package/dist/mutation-impact.js.map +1 -1
  452. package/dist/node-defaults.d.ts +15 -14
  453. package/dist/node-defaults.d.ts.map +1 -1
  454. package/dist/node-defaults.js +153 -55
  455. package/dist/node-defaults.js.map +1 -1
  456. package/dist/order-keys.d.ts +8 -9
  457. package/dist/order-keys.d.ts.map +1 -1
  458. package/dist/order-keys.js +10 -2
  459. package/dist/order-keys.js.map +1 -1
  460. package/dist/outline/flatten.d.ts +3 -6
  461. package/dist/outline/flatten.d.ts.map +1 -1
  462. package/dist/outline/flatten.js +3 -4
  463. package/dist/outline/heads.js +1 -2
  464. package/dist/outline/hit.d.ts +2 -5
  465. package/dist/outline/hit.d.ts.map +1 -1
  466. package/dist/outline/hit.js +5 -6
  467. package/dist/outline/index.js +3 -3
  468. package/dist/outline/point.d.ts +4 -7
  469. package/dist/outline/point.d.ts.map +1 -1
  470. package/dist/outline/point.js +2 -3
  471. package/dist/outline/shapes.d.ts +4 -7
  472. package/dist/outline/shapes.d.ts.map +1 -1
  473. package/dist/outline/shapes.js +2 -3
  474. package/dist/paints/index.d.ts +5 -3
  475. package/dist/paints/index.js +5 -3
  476. package/dist/paints/pattern.d.ts +6 -5
  477. package/dist/paints/pattern.d.ts.map +1 -1
  478. package/dist/paints/pattern.js +34 -3
  479. package/dist/paints/pattern.js.map +1 -1
  480. package/dist/paints/schema.d.ts +4 -7
  481. package/dist/paints/schema.d.ts.map +1 -1
  482. package/dist/paints/schema.js +3 -4
  483. package/dist/paints/shows.d.ts +4 -4
  484. package/dist/paints/shows.d.ts.map +1 -1
  485. package/dist/paints/shows.js +9 -3
  486. package/dist/paints/shows.js.map +1 -1
  487. package/dist/paints/solid.d.ts +8 -0
  488. package/dist/paints/solid.d.ts.map +1 -0
  489. package/dist/paints/solid.js +17 -0
  490. package/dist/paints/solid.js.map +1 -0
  491. package/dist/paints/stills.d.ts +74 -0
  492. package/dist/paints/stills.d.ts.map +1 -0
  493. package/dist/paints/stills.js +117 -0
  494. package/dist/paints/stills.js.map +1 -0
  495. package/dist/parse-path.d.ts +12 -9
  496. package/dist/parse-path.d.ts.map +1 -1
  497. package/dist/parse-path.js +13 -3
  498. package/dist/parse-path.js.map +1 -1
  499. package/dist/paths/arc.d.ts +6 -9
  500. package/dist/paths/arc.d.ts.map +1 -1
  501. package/dist/paths/arc.js +1 -2
  502. package/dist/paths/index.d.ts +1 -1
  503. package/dist/paths/index.js +1 -1
  504. package/dist/paths/network.d.ts +13 -16
  505. package/dist/paths/network.d.ts.map +1 -1
  506. package/dist/paths/network.js +1 -2
  507. package/dist/paths/sink.d.ts +5 -8
  508. package/dist/paths/sink.d.ts.map +1 -1
  509. package/dist/paths/sink.js +1 -2
  510. package/dist/paths/smooth-corners.d.ts +3 -6
  511. package/dist/paths/smooth-corners.d.ts.map +1 -1
  512. package/dist/paths/smooth-corners.js +1 -2
  513. package/dist/plugin-data/field.d.ts +15 -18
  514. package/dist/plugin-data/field.d.ts.map +1 -1
  515. package/dist/plugin-data/field.js +3 -2
  516. package/dist/plugin-data/field.js.map +1 -1
  517. package/dist/plugin-data/fields.d.ts +104 -11
  518. package/dist/plugin-data/fields.d.ts.map +1 -1
  519. package/dist/plugin-data/fields.js +43 -13
  520. package/dist/plugin-data/fields.js.map +1 -1
  521. package/dist/plugin-data/index.d.ts +2 -2
  522. package/dist/plugin-data/index.js +2 -2
  523. package/dist/polygon.d.ts +8 -8
  524. package/dist/polygon.d.ts.map +1 -1
  525. package/dist/polygon.js +7 -7
  526. package/dist/polygon.js.map +1 -1
  527. package/dist/preview.d.ts +3 -5
  528. package/dist/preview.d.ts.map +1 -1
  529. package/dist/preview.js +2 -3
  530. package/dist/primitives/index.d.ts +7 -9
  531. package/dist/primitives/index.d.ts.map +1 -1
  532. package/dist/primitives/index.js +1 -2
  533. package/dist/primitives/schema.d.ts +3 -6
  534. package/dist/primitives/schema.d.ts.map +1 -1
  535. package/dist/primitives/schema.js +1 -2
  536. package/dist/resize.d.ts +19 -14
  537. package/dist/resize.d.ts.map +1 -1
  538. package/dist/resize.js +38 -8
  539. package/dist/resize.js.map +1 -1
  540. package/dist/scaling/index.d.ts +2 -2
  541. package/dist/scaling/index.js +2 -2
  542. package/dist/scaling/node.d.ts +2 -4
  543. package/dist/scaling/node.d.ts.map +1 -1
  544. package/dist/scaling/node.js +30 -11
  545. package/dist/scaling/node.js.map +1 -1
  546. package/dist/scaling/snapshot.d.ts +5 -8
  547. package/dist/scaling/snapshot.d.ts.map +1 -1
  548. package/dist/scaling/snapshot.js +1 -2
  549. package/dist/scaling/tree.d.ts +6 -9
  550. package/dist/scaling/tree.d.ts.map +1 -1
  551. package/dist/scaling/tree.js +2 -3
  552. package/dist/shaders/index.d.ts +2 -3
  553. package/dist/shaders/index.js +2 -3
  554. package/dist/shaders/model.d.ts +54 -21
  555. package/dist/shaders/model.d.ts.map +1 -1
  556. package/dist/shaders/model.js +103 -35
  557. package/dist/shaders/model.js.map +1 -1
  558. package/dist/shaders/schema.d.ts +16 -9
  559. package/dist/shaders/schema.d.ts.map +1 -1
  560. package/dist/shaders/schema.js +12 -3
  561. package/dist/shaders/schema.js.map +1 -1
  562. package/dist/shape-with-text/document.js +264 -0
  563. package/dist/shape-with-text/document.js.map +1 -0
  564. package/dist/shape-with-text/fit.d.ts +6 -9
  565. package/dist/shape-with-text/fit.d.ts.map +1 -1
  566. package/dist/shape-with-text/fit.js +1 -2
  567. package/dist/shape-with-text/geometry.d.ts +16 -7
  568. package/dist/shape-with-text/geometry.d.ts.map +1 -1
  569. package/dist/shape-with-text/geometry.js +105 -46
  570. package/dist/shape-with-text/geometry.js.map +1 -1
  571. package/dist/shape-with-text/index.d.ts +2 -2
  572. package/dist/shape-with-text/index.js +3 -3
  573. package/dist/shape-with-text/kinds.d.ts +4 -7
  574. package/dist/shape-with-text/kinds.d.ts.map +1 -1
  575. package/dist/shape-with-text/kinds.js +1 -2
  576. package/dist/shared-style-index.d.ts +19 -0
  577. package/dist/shared-style-index.d.ts.map +1 -0
  578. package/dist/shared-style-index.js +71 -0
  579. package/dist/shared-style-index.js.map +1 -0
  580. package/dist/shared-styles.d.ts +18 -20
  581. package/dist/shared-styles.d.ts.map +1 -1
  582. package/dist/shared-styles.js +20 -12
  583. package/dist/shared-styles.js.map +1 -1
  584. package/dist/slides/drop.d.ts +29 -0
  585. package/dist/slides/drop.d.ts.map +1 -0
  586. package/dist/slides/drop.js +80 -0
  587. package/dist/slides/drop.js.map +1 -0
  588. package/dist/slides/index.d.ts +56 -0
  589. package/dist/slides/index.d.ts.map +1 -0
  590. package/dist/slides/index.js +137 -0
  591. package/dist/slides/index.js.map +1 -0
  592. package/dist/slides/motion.d.ts +71 -0
  593. package/dist/slides/motion.d.ts.map +1 -0
  594. package/dist/slides/motion.js +167 -0
  595. package/dist/slides/motion.js.map +1 -0
  596. package/dist/slides/playback.d.ts +62 -0
  597. package/dist/slides/playback.d.ts.map +1 -0
  598. package/dist/slides/playback.js +220 -0
  599. package/dist/slides/playback.js.map +1 -0
  600. package/dist/slides/types.d.ts +59 -0
  601. package/dist/slides/types.d.ts.map +1 -0
  602. package/dist/slides/types.js +38 -0
  603. package/dist/slides/types.js.map +1 -0
  604. package/dist/slots/authoring.d.ts +6 -9
  605. package/dist/slots/authoring.d.ts.map +1 -1
  606. package/dist/slots/authoring.js +2 -3
  607. package/dist/slots/content.d.ts +5 -8
  608. package/dist/slots/content.d.ts.map +1 -1
  609. package/dist/slots/content.js +4 -5
  610. package/dist/slots/frames.d.ts +7 -9
  611. package/dist/slots/frames.d.ts.map +1 -1
  612. package/dist/slots/frames.js +3 -4
  613. package/dist/slots/frames.js.map +1 -1
  614. package/dist/slots/index.js +1 -1
  615. package/dist/slots/limits.d.ts +4 -7
  616. package/dist/slots/limits.d.ts.map +1 -1
  617. package/dist/slots/limits.js +1 -2
  618. package/dist/snap.d.ts +4 -7
  619. package/dist/snap.d.ts.map +1 -1
  620. package/dist/snap.js +7 -8
  621. package/dist/source-metadata.d.ts +1 -4
  622. package/dist/source-metadata.d.ts.map +1 -1
  623. package/dist/source-metadata.js +1 -2
  624. package/dist/specs/index.d.ts +3 -0
  625. package/dist/specs/index.js +3 -0
  626. package/dist/specs/model.d.ts +20 -0
  627. package/dist/specs/model.d.ts.map +1 -0
  628. package/dist/specs/model.js +32 -0
  629. package/dist/specs/model.js.map +1 -0
  630. package/dist/specs/schema.d.ts +24 -0
  631. package/dist/specs/schema.d.ts.map +1 -0
  632. package/dist/specs/schema.js +32 -0
  633. package/dist/specs/schema.js.map +1 -0
  634. package/dist/statuses/impact.d.ts +2 -5
  635. package/dist/statuses/impact.d.ts.map +1 -1
  636. package/dist/statuses/impact.js +2 -3
  637. package/dist/statuses/index.d.ts +1 -1
  638. package/dist/statuses/index.js +2 -2
  639. package/dist/statuses/node.d.ts +4 -7
  640. package/dist/statuses/node.d.ts.map +1 -1
  641. package/dist/statuses/node.js +1 -2
  642. package/dist/statuses/schema.d.ts +7 -9
  643. package/dist/statuses/schema.d.ts.map +1 -1
  644. package/dist/statuses/schema.js +1 -2
  645. package/dist/statuses/workflow.d.ts +9 -12
  646. package/dist/statuses/workflow.d.ts.map +1 -1
  647. package/dist/statuses/workflow.js +2 -3
  648. package/dist/strokes.d.ts +8 -10
  649. package/dist/strokes.d.ts.map +1 -1
  650. package/dist/strokes.js +2 -3
  651. package/dist/text/auto-resize.d.ts +4 -6
  652. package/dist/text/auto-resize.d.ts.map +1 -1
  653. package/dist/text/auto-resize.js +1 -2
  654. package/dist/text/direction.d.ts +10 -10
  655. package/dist/text/direction.d.ts.map +1 -1
  656. package/dist/text/direction.js +13 -14
  657. package/dist/text/direction.js.map +1 -1
  658. package/dist/text/index.d.ts +3 -2
  659. package/dist/text/index.js +6 -5
  660. package/dist/text/lengths.d.ts +9 -12
  661. package/dist/text/lengths.d.ts.map +1 -1
  662. package/dist/text/lengths.js +1 -2
  663. package/dist/text/lists.d.ts +17 -13
  664. package/dist/text/lists.d.ts.map +1 -1
  665. package/dist/text/lists.js +15 -4
  666. package/dist/text/lists.js.map +1 -1
  667. package/dist/text/name.d.ts +19 -0
  668. package/dist/text/name.d.ts.map +1 -0
  669. package/dist/text/name.js +37 -0
  670. package/dist/text/name.js.map +1 -0
  671. package/dist/text/overflow.d.ts +5 -7
  672. package/dist/text/overflow.d.ts.map +1 -1
  673. package/dist/text/overflow.js +1 -2
  674. package/dist/text/paragraphs.d.ts +20 -23
  675. package/dist/text/paragraphs.d.ts.map +1 -1
  676. package/dist/text/paragraphs.js +8 -5
  677. package/dist/text/paragraphs.js.map +1 -1
  678. package/dist/text/path.js +1 -2
  679. package/dist/text/picture.d.ts +3 -6
  680. package/dist/text/picture.d.ts.map +1 -1
  681. package/dist/text/picture.js +2 -3
  682. package/dist/text/references.d.ts +3 -6
  683. package/dist/text/references.d.ts.map +1 -1
  684. package/dist/text/references.js +2 -4
  685. package/dist/text/references.js.map +1 -1
  686. package/dist/text/runs.d.ts +6 -9
  687. package/dist/text/runs.d.ts.map +1 -1
  688. package/dist/text/runs.js +1 -2
  689. package/dist/text/schema.d.ts +1 -4
  690. package/dist/text/schema.d.ts.map +1 -1
  691. package/dist/text/schema.js +1 -2
  692. package/dist/thumbnail.d.ts +20 -0
  693. package/dist/thumbnail.d.ts.map +1 -0
  694. package/dist/thumbnail.js +46 -0
  695. package/dist/thumbnail.js.map +1 -0
  696. package/dist/transfer/apply.d.ts +2 -5
  697. package/dist/transfer/apply.d.ts.map +1 -1
  698. package/dist/transfer/apply.js +16 -6
  699. package/dist/transfer/apply.js.map +1 -1
  700. package/dist/transfer/copied.d.ts +11 -9
  701. package/dist/transfer/copied.d.ts.map +1 -1
  702. package/dist/transfer/copied.js +5 -6
  703. package/dist/transfer/copied.js.map +1 -1
  704. package/dist/transfer/dependencies.d.ts +10 -10
  705. package/dist/transfer/dependencies.d.ts.map +1 -1
  706. package/dist/transfer/dependencies.js +21 -10
  707. package/dist/transfer/dependencies.js.map +1 -1
  708. package/dist/transfer/history.d.ts +1 -4
  709. package/dist/transfer/history.d.ts.map +1 -1
  710. package/dist/transfer/history.js +3 -2
  711. package/dist/transfer/history.js.map +1 -1
  712. package/dist/transfer/identity.js +19 -5
  713. package/dist/transfer/identity.js.map +1 -1
  714. package/dist/transfer/index.d.ts +5 -4
  715. package/dist/transfer/index.js +6 -5
  716. package/dist/transfer/library.d.ts +43 -0
  717. package/dist/transfer/library.d.ts.map +1 -0
  718. package/dist/transfer/library.js +122 -0
  719. package/dist/transfer/library.js.map +1 -0
  720. package/dist/transfer/nodes.d.ts +2 -5
  721. package/dist/transfer/nodes.d.ts.map +1 -1
  722. package/dist/transfer/nodes.js +15 -4
  723. package/dist/transfer/nodes.js.map +1 -1
  724. package/dist/transfer/plan.d.ts +11 -5
  725. package/dist/transfer/plan.d.ts.map +1 -1
  726. package/dist/transfer/plan.js +52 -8
  727. package/dist/transfer/plan.js.map +1 -1
  728. package/dist/transfer/references.js +1 -2
  729. package/dist/transfer/remove.d.ts +1 -4
  730. package/dist/transfer/remove.d.ts.map +1 -1
  731. package/dist/transfer/remove.js +8 -3
  732. package/dist/transfer/remove.js.map +1 -1
  733. package/dist/transfer/resources.d.ts +2 -5
  734. package/dist/transfer/resources.d.ts.map +1 -1
  735. package/dist/transfer/resources.js +3 -4
  736. package/dist/transfer/validation.js +9 -6
  737. package/dist/transfer/validation.js.map +1 -1
  738. package/dist/transfer/variables.d.ts +3 -6
  739. package/dist/transfer/variables.d.ts.map +1 -1
  740. package/dist/transfer/variables.js +4 -4
  741. package/dist/transfer/variables.js.map +1 -1
  742. package/dist/types.d.ts +261 -134
  743. package/dist/types.d.ts.map +1 -1
  744. package/dist/types.js +47 -3
  745. package/dist/types.js.map +1 -1
  746. package/dist/undo.d.ts +5 -8
  747. package/dist/undo.d.ts.map +1 -1
  748. package/dist/undo.js +9 -3
  749. package/dist/undo.js.map +1 -1
  750. package/dist/variables/bindings.d.ts +29 -25
  751. package/dist/variables/bindings.d.ts.map +1 -1
  752. package/dist/variables/bindings.js +184 -55
  753. package/dist/variables/bindings.js.map +1 -1
  754. package/dist/variables/corners.d.ts +1 -4
  755. package/dist/variables/corners.d.ts.map +1 -1
  756. package/dist/variables/corners.js +1 -2
  757. package/dist/variables/easing.d.ts +53 -0
  758. package/dist/variables/easing.d.ts.map +1 -0
  759. package/dist/variables/easing.js +321 -0
  760. package/dist/variables/easing.js.map +1 -0
  761. package/dist/variables/fields.d.ts +21 -14
  762. package/dist/variables/fields.d.ts.map +1 -1
  763. package/dist/variables/fields.js +24 -6
  764. package/dist/variables/fields.js.map +1 -1
  765. package/dist/variables/formula/check.d.ts +2 -5
  766. package/dist/variables/formula/check.d.ts.map +1 -1
  767. package/dist/variables/formula/check.js +2 -3
  768. package/dist/variables/formula/evaluate.d.ts +1 -4
  769. package/dist/variables/formula/evaluate.d.ts.map +1 -1
  770. package/dist/variables/formula/evaluate.js +3 -4
  771. package/dist/variables/formula/index.d.ts +8 -8
  772. package/dist/variables/formula/index.d.ts.map +1 -1
  773. package/dist/variables/formula/index.js +29 -13
  774. package/dist/variables/formula/index.js.map +1 -1
  775. package/dist/variables/formula/parse.js +5 -6
  776. package/dist/variables/formula/print.d.ts +2 -5
  777. package/dist/variables/formula/print.d.ts.map +1 -1
  778. package/dist/variables/formula/print.js +4 -5
  779. package/dist/variables/formula/schema.d.ts +2 -5
  780. package/dist/variables/formula/schema.d.ts.map +1 -1
  781. package/dist/variables/formula/schema.js +6 -7
  782. package/dist/variables/formula/signatures.d.ts +4 -7
  783. package/dist/variables/formula/signatures.d.ts.map +1 -1
  784. package/dist/variables/formula/signatures.js +1 -2
  785. package/dist/variables/formula/signatures.js.map +1 -1
  786. package/dist/variables/formula/tokens.d.ts +5 -8
  787. package/dist/variables/formula/tokens.d.ts.map +1 -1
  788. package/dist/variables/formula/tokens.js +1 -2
  789. package/dist/variables/formula/tree.d.ts +8 -11
  790. package/dist/variables/formula/tree.d.ts.map +1 -1
  791. package/dist/variables/formula/tree.js +1 -2
  792. package/dist/variables/formula/tree.js.map +1 -1
  793. package/dist/variables/index.d.ts +42 -27
  794. package/dist/variables/index.d.ts.map +1 -1
  795. package/dist/variables/index.js +78 -29
  796. package/dist/variables/index.js.map +1 -1
  797. package/dist/variables/lookup.d.ts +11 -7
  798. package/dist/variables/lookup.d.ts.map +1 -1
  799. package/dist/variables/lookup.js +25 -4
  800. package/dist/variables/lookup.js.map +1 -1
  801. package/dist/variables/motion.d.ts +43 -0
  802. package/dist/variables/motion.d.ts.map +1 -0
  803. package/dist/variables/motion.js +106 -0
  804. package/dist/variables/motion.js.map +1 -0
  805. package/dist/variables/paints.d.ts +25 -19
  806. package/dist/variables/paints.d.ts.map +1 -1
  807. package/dist/variables/paints.js +28 -15
  808. package/dist/variables/paints.js.map +1 -1
  809. package/dist/variables/resolution.d.ts +22 -19
  810. package/dist/variables/resolution.d.ts.map +1 -1
  811. package/dist/variables/resolution.js +23 -14
  812. package/dist/variables/resolution.js.map +1 -1
  813. package/dist/variables/schema.d.ts +62 -7
  814. package/dist/variables/schema.d.ts.map +1 -1
  815. package/dist/variables/schema.js +39 -5
  816. package/dist/variables/schema.js.map +1 -1
  817. package/dist/variables/style-bindings.d.ts +21 -0
  818. package/dist/variables/style-bindings.d.ts.map +1 -0
  819. package/dist/variables/style-bindings.js +82 -0
  820. package/dist/variables/style-bindings.js.map +1 -0
  821. package/dist/variables/subtree.js +1 -2
  822. package/dist/variables/text.d.ts +2 -5
  823. package/dist/variables/text.d.ts.map +1 -1
  824. package/dist/variables/text.js +3 -4
  825. package/dist/variables/token.d.ts +5 -8
  826. package/dist/variables/token.d.ts.map +1 -1
  827. package/dist/variables/token.js +1 -2
  828. package/dist/variables/units.js +3 -5
  829. package/dist/variables/units.js.map +1 -1
  830. package/dist/variables/value.d.ts +4 -7
  831. package/dist/variables/value.d.ts.map +1 -1
  832. package/dist/variables/value.js +4 -5
  833. package/dist/variant-name.d.ts +2 -5
  834. package/dist/variant-name.d.ts.map +1 -1
  835. package/dist/variant-name.js +1 -2
  836. package/dist/variant-properties.d.ts +4 -7
  837. package/dist/variant-properties.d.ts.map +1 -1
  838. package/dist/variant-properties.js +2 -3
  839. package/dist/vector-network.d.ts +17 -20
  840. package/dist/vector-network.d.ts.map +1 -1
  841. package/dist/vector-network.js +4 -5
  842. package/package.json +42 -5
  843. package/src/behaviours/index.ts +2 -0
  844. package/src/behaviours/kinds.ts +108 -2
  845. package/src/behaviours/listing.ts +142 -0
  846. package/src/behaviours/model.ts +23 -2
  847. package/src/behaviours/schema.ts +19 -2
  848. package/src/behaviours/spec.ts +5 -0
  849. package/src/behaviours/transition.ts +46 -0
  850. package/src/blur.ts +88 -0
  851. package/src/checkpoint.ts +2 -0
  852. package/src/clipping.ts +3 -4
  853. package/src/color/index.ts +15 -24
  854. package/src/color/management.ts +144 -168
  855. package/src/color/okhcl.ts +62 -43
  856. package/src/color/schema.ts +13 -0
  857. package/src/comments/threads.ts +8 -1
  858. package/src/connectors/layout.ts +10 -3
  859. package/src/connectors/sublayers.ts +2 -1
  860. package/src/constraints.ts +2 -1
  861. package/src/coordinate.ts +17 -25
  862. package/src/copy.ts +38 -0
  863. package/src/corners.ts +3 -0
  864. package/src/css/index.ts +1 -0
  865. package/src/css/motion.ts +51 -0
  866. package/src/css/shadows.ts +7 -6
  867. package/src/css/values.ts +7 -3
  868. package/src/cubic.ts +57 -1
  869. package/src/export-format.ts +11 -1
  870. package/src/fields/layout.ts +9 -0
  871. package/src/font-style.ts +20 -7
  872. package/src/generated/index.ts +58 -9
  873. package/src/generated/kind.ts +16 -2
  874. package/src/generated/shape-with-text.ts +1 -0
  875. package/src/generated/spec.ts +243 -0
  876. package/src/generated/sticky.ts +2 -1
  877. package/src/geometry.ts +52 -89
  878. package/src/graph.ts +93 -15
  879. package/src/group-bounds.ts +54 -13
  880. package/src/hit-test.ts +78 -33
  881. package/src/images.ts +4 -1
  882. package/src/instances/content-marks.ts +124 -0
  883. package/src/instances/deleted.ts +115 -0
  884. package/src/instances/fields.ts +9 -3
  885. package/src/instances/index.ts +165 -17
  886. package/src/instances/lookup.ts +61 -0
  887. package/src/instances/sync.ts +108 -11
  888. package/src/layout/flow.ts +36 -0
  889. package/src/layout/index.ts +2 -0
  890. package/src/layout/keywords.ts +7 -1
  891. package/src/layout/sizing.ts +30 -0
  892. package/src/layout/spacing.ts +12 -0
  893. package/src/layout/stacking.ts +14 -0
  894. package/src/matrix.ts +11 -1
  895. package/src/mesh/geometry.ts +422 -0
  896. package/src/mesh/index.ts +3 -0
  897. package/src/mesh/model.ts +50 -0
  898. package/src/mesh/schema.ts +81 -0
  899. package/src/motion/apply.ts +156 -0
  900. package/src/motion/edit.ts +148 -0
  901. package/src/motion/effects.ts +166 -0
  902. package/src/motion/evaluate.ts +181 -0
  903. package/src/motion/fields.ts +136 -0
  904. package/src/motion/index.ts +13 -0
  905. package/src/motion/keyable.ts +141 -0
  906. package/src/motion/outline.ts +72 -0
  907. package/src/motion/presets/index.ts +257 -0
  908. package/src/motion/presets/settings.ts +221 -0
  909. package/src/motion/presets/stagger.ts +242 -0
  910. package/src/motion/schema.ts +66 -0
  911. package/src/motion/segment.ts +83 -0
  912. package/src/motion/spec.ts +225 -0
  913. package/src/motion/timeline.ts +48 -0
  914. package/src/motion/types.ts +45 -0
  915. package/src/motion/variables.ts +33 -0
  916. package/src/mutation-impact.ts +23 -7
  917. package/src/node-defaults.ts +152 -53
  918. package/src/order-keys.ts +16 -2
  919. package/src/paints/index.ts +2 -0
  920. package/src/paints/pattern.ts +55 -0
  921. package/src/paints/shows.ts +9 -0
  922. package/src/paints/solid.ts +10 -0
  923. package/src/paints/stills.ts +186 -0
  924. package/src/parse-path.ts +15 -0
  925. package/src/plugin-data/field.ts +3 -0
  926. package/src/plugin-data/fields.ts +54 -4
  927. package/src/polygon.ts +6 -4
  928. package/src/resize.ts +32 -20
  929. package/src/scaling/index.ts +1 -1
  930. package/src/scaling/node.ts +43 -6
  931. package/src/shaders/index.ts +0 -1
  932. package/src/shaders/model.ts +133 -45
  933. package/src/shaders/schema.ts +13 -1
  934. package/src/shape-with-text/document.ts +170 -0
  935. package/src/shape-with-text/geometry.ts +98 -29
  936. package/src/shared-style-index.ts +106 -0
  937. package/src/shared-styles.ts +21 -14
  938. package/src/slides/drop.ts +94 -0
  939. package/src/slides/index.ts +133 -0
  940. package/src/slides/motion.ts +203 -0
  941. package/src/slides/playback.ts +242 -0
  942. package/src/slides/types.ts +94 -0
  943. package/src/slots/frames.ts +2 -3
  944. package/src/specs/index.ts +2 -0
  945. package/src/specs/model.ts +40 -0
  946. package/src/specs/schema.ts +43 -0
  947. package/src/text/direction.ts +13 -23
  948. package/src/text/index.ts +1 -0
  949. package/src/text/lists.ts +20 -7
  950. package/src/text/name.ts +39 -0
  951. package/src/text/paragraphs.ts +10 -3
  952. package/src/text/references.ts +3 -3
  953. package/src/thumbnail.ts +52 -0
  954. package/src/transfer/apply.ts +16 -3
  955. package/src/transfer/copied.ts +7 -2
  956. package/src/transfer/dependencies.ts +27 -12
  957. package/src/transfer/history.ts +2 -0
  958. package/src/transfer/identity.ts +34 -2
  959. package/src/transfer/index.ts +6 -0
  960. package/src/transfer/library.ts +177 -0
  961. package/src/transfer/nodes.ts +28 -0
  962. package/src/transfer/plan.ts +96 -10
  963. package/src/transfer/remove.ts +6 -2
  964. package/src/transfer/validation.ts +15 -7
  965. package/src/transfer/variables.ts +8 -2
  966. package/src/types.ts +182 -15
  967. package/src/undo.ts +10 -1
  968. package/src/variables/bindings.ts +292 -51
  969. package/src/variables/easing.ts +281 -0
  970. package/src/variables/fields.ts +30 -3
  971. package/src/variables/formula/index.ts +33 -14
  972. package/src/variables/formula/signatures.ts +6 -2
  973. package/src/variables/formula/tree.ts +3 -3
  974. package/src/variables/index.ts +90 -37
  975. package/src/variables/lookup.ts +25 -2
  976. package/src/variables/motion.ts +151 -0
  977. package/src/variables/paints.ts +29 -7
  978. package/src/variables/resolution.ts +26 -6
  979. package/src/variables/schema.ts +41 -0
  980. package/src/variables/style-bindings.ts +137 -0
  981. package/src/variables/units.ts +2 -3
  982. package/dist/shaders/still.d.ts +0 -18
  983. package/dist/shaders/still.d.ts.map +0 -1
  984. package/dist/shaders/still.js +0 -36
  985. package/dist/shaders/still.js.map +0 -1
  986. package/src/shaders/still.ts +0 -41
@@ -1,8 +1,7 @@
1
- import { Color } from "../primitives/index.js";
2
1
  import { SceneGraph } from "../graph.js";
3
- import { SceneNode } from "../types.js";
2
+ import { Color } from "../primitives/index.js";
3
+ import { CharacterStyleOverride, Fill, SceneNode } from "../types.js";
4
4
  import { PaintBindingList } from "./fields.js";
5
- //#region src/variables/paints.d.ts
6
5
  /**
7
6
  * Figma keeps a bound paint's color and opacity as a cache of its variable: it draws and reads
8
7
  * what the paint holds, and writes the variable's color into it again only once the color the
@@ -12,26 +11,26 @@ import { PaintBindingList } from "./fields.js";
12
11
  * without an entry, such as one just restored, counts its paint's own color as the last one
13
12
  * applied, in the modes it has now.
14
13
  */
15
- interface AppliedColor {
14
+ export interface AppliedColor {
16
15
  readonly variableId: string;
17
16
  readonly color: Color;
18
17
  /** The mode set for the layer, or null, in each collection the variable resolves through. */
19
18
  readonly modes: Readonly<Record<string, string | null>>;
20
19
  }
21
20
  /** Whether a layer has a paint whose color is bound to a variable. */
22
- declare function hasBoundPaints(node: SceneNode): boolean;
21
+ export declare function hasBoundPaints(node: SceneNode): boolean;
23
22
  /**
24
23
  * A layer copied from another keeps the colors its bindings last applied there, so the copy's
25
24
  * paints, edits included, stay as they are until their variables' colors for it change.
26
25
  */
27
- declare function copyAppliedBoundPaints(source: SceneNode, copy: SceneNode): void;
26
+ export declare function copyAppliedBoundPaints(source: SceneNode, copy: SceneNode): void;
28
27
  /** The colors copied layers' bindings last applied, by layer id, as a copy captured them. */
29
- type AppliedBoundPaints = ReadonlyMap<string, ReadonlyMap<string, AppliedColor>>;
28
+ export type AppliedBoundPaints = ReadonlyMap<string, ReadonlyMap<string, AppliedColor>>;
30
29
  /**
31
30
  * The colors the bindings of the layers `nodeIds` names last applied, captured when they are
32
31
  * copied, so a paste counts what the copied paints were applied from, not what the source has now.
33
32
  */
34
- declare function captureAppliedBoundPaints(graph: SceneGraph, nodeIds: Iterable<string>): AppliedBoundPaints;
33
+ export declare function captureAppliedBoundPaints(graph: SceneGraph, nodeIds: Iterable<string>): AppliedBoundPaints;
35
34
  /**
36
35
  * Pasted layers keep their paints, edits included, as Figma's copies do. One copied in this
37
36
  * document takes the colors its source's bindings had last applied when it was copied, so a paste
@@ -39,42 +38,50 @@ declare function captureAppliedBoundPaints(graph: SceneGraph, nodeIds: Iterable<
39
38
  * its variables give it now as applied, as a loaded document does. `copies` maps each copied
40
39
  * layer's id to its copy's.
41
40
  */
42
- declare function keepPastedBoundPaints(graph: SceneGraph, copies: ReadonlyMap<string, string>, applied: AppliedBoundPaints): void;
41
+ export declare function keepPastedBoundPaints(graph: SceneGraph, copies: ReadonlyMap<string, string>, applied: AppliedBoundPaints): void;
42
+ /** The variable's RGB at full alpha in the paint, and its alpha as the paint's opacity. */
43
+ export declare function applyVariableColor(paint: Fill, color: Color): void;
43
44
  type PaintLists = Pick<Partial<SceneNode>, 'fills' | 'strokes'>;
44
45
  /**
45
46
  * Whether `node` is an instance, or a layer an instance copies from its component, with a paint
46
47
  * list neither it nor an instance around it overrides: such paints follow the component, and
47
48
  * refreshing them is no edit.
48
49
  */
49
- declare function copiesComponentPaints(graph: SceneGraph, node: SceneNode, list: PaintBindingList): boolean;
50
+ export declare function copiesComponentPaints(graph: SceneGraph, node: SceneNode, list: PaintBindingList): boolean;
51
+ /**
52
+ * A range's own fills with each bound one showing the colour its variable gives the text now, or
53
+ * null when every one does already. A range keeps no record of the colours it was last given, so
54
+ * an edit to a bound range paint lasts until the next refresh of the text's bindings.
55
+ */
56
+ export declare function refreshedRunFills(graph: SceneGraph, nodeId: string, style: CharacterStyleOverride): Fill[] | null;
50
57
  /**
51
58
  * Refreshes a layer's bound paints: each takes its variable's color for the layer, alpha as
52
59
  * opacity, once that color differs from the one last applied, discarding edits made since, as
53
60
  * Figma refreshes them when a variable's value or a layer's mode changes.
54
61
  */
55
- declare function refreshBoundPaints(graph: SceneGraph, node: SceneNode): void;
62
+ export declare function refreshBoundPaints(graph: SceneGraph, node: SceneNode): void;
56
63
  /** Gives one bound paint its variable's color for the layer, as binding it does in Figma. */
57
- declare function applyBoundPaintColor(graph: SceneGraph, node: SceneNode, field: string): void;
64
+ export declare function applyBoundPaintColor(graph: SceneGraph, node: SceneNode, field: string): void;
58
65
  /**
59
66
  * Gives every bound paint in this subtree its variable's color where it sits. A new instance
60
67
  * or a layer an instance sync adds is a copy, which shows its variables in its own context rather
61
68
  * than whatever its component's paints hold.
62
69
  */
63
- declare function applyBoundPaintColorsIn(graph: SceneGraph, rootId: string): void;
70
+ export declare function applyBoundPaintColorsIn(graph: SceneGraph, rootId: string): void;
64
71
  /** Refreshes the bound paints in this subtree whose variables now give their layers another color. */
65
- declare function refreshBoundPaintsIn(graph: SceneGraph, rootId: string): void;
72
+ export declare function refreshBoundPaintsIn(graph: SceneGraph, rootId: string): void;
66
73
  /**
67
74
  * Records, for the paint lists a write sets, the colors their variables give the layer now, so a
68
75
  * paint written with another color or opacity keeps it until that color changes.
69
76
  */
70
- declare function recordWrittenBoundPaints(graph: SceneGraph, node: SceneNode, written: PaintLists): void;
77
+ export declare function recordWrittenBoundPaints(graph: SceneGraph, node: SceneNode, written: PaintLists): void;
71
78
  /**
72
79
  * Refreshes the bound paints in a moved layer's subtree that resolve through a collection whose
73
80
  * mode set the move changed, as Figma does when a layer enters a frame or page that sets another
74
81
  * mode, or one where none was. A move between parents setting the same modes, or of layers that
75
82
  * bind no paint, costs no more than comparing those modes.
76
83
  */
77
- declare function refreshMovedBoundPaints(graph: SceneGraph, nodeId: string, previousParentId: string | null | undefined): void;
84
+ export declare function refreshMovedBoundPaints(graph: SceneGraph, nodeId: string, previousParentId: string | null | undefined): void;
78
85
  /**
79
86
  * A copy's bound paints are its own cache, as Figma keeps them per layer, so a component's edit
80
87
  * to its paint's color or opacity does not reach them. An instance sync writing a copy's paints
@@ -82,7 +89,6 @@ declare function refreshMovedBoundPaints(graph: SceneGraph, nodeId: string, prev
82
89
  * variable's color for the copy once that differs from the one last applied, or when it binds
83
90
  * anew. `updates` holds what the sync writes, whose paints this sets in place.
84
91
  */
85
- declare function keepCopyBoundPaints(graph: SceneGraph, target: SceneNode, updates: Partial<SceneNode>): void;
86
- //#endregion
87
- export { AppliedBoundPaints, AppliedColor, applyBoundPaintColor, applyBoundPaintColorsIn, captureAppliedBoundPaints, copiesComponentPaints, copyAppliedBoundPaints, hasBoundPaints, keepCopyBoundPaints, keepPastedBoundPaints, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints };
92
+ export declare function keepCopyBoundPaints(graph: SceneGraph, target: SceneNode, updates: Partial<SceneNode>): void;
93
+ export {};
88
94
  //# sourceMappingURL=paints.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"paints.d.ts","names":[],"sources":["../../src/variables/paints.ts"],"mappings":";;;;;;;;;;;;;;UAoBiB;WACN;WACA,OAAO;;WAEP,OAAO,SAAS;;;iBAyBX,eAAe,MAAM;;;;;iBAsDrB,uBAAuB,QAAQ,WAAW,MAAM;;KAMpD,qBAAqB,oBAAoB,oBAAoB;;;;;iBAMzD,0BACd,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{ paintBindingTarget } from "./fields.js";
2
- import { hasInstanceOverride } from "../instances/overrides.js";
1
+ import { isEqual } from "es-toolkit/predicate";
3
2
  import { copyFills, copyStrokes } from "../copy.js";
3
+ import { hasInstanceOverride } from "../instances/overrides.js";
4
+ import { solidPaintColor } from "../paints/solid.js";
5
+ import { paintBindingTarget } from "./fields.js";
4
6
  import { collectionsResolving, getNodeExplicitVariableModeId } from "./resolution.js";
5
7
  import { subtreeNodes } from "./subtree.js";
6
- import { isEqual } from "es-toolkit/predicate";
7
- //#region src/variables/paints.ts
8
+ // src/variables/paints.ts
8
9
  const appliedColors = /* @__PURE__ */ new WeakMap();
9
10
  const PAINT_LISTS = ["fills", "strokes"];
10
11
  /** The paints of `node` whose color is bound to a variable, each with a paint there to color. */
@@ -111,12 +112,8 @@ function recordApplied(node, bound, color, modes) {
111
112
  });
112
113
  }
113
114
  /** The variable's RGB at full alpha in the paint, and its alpha as the paint's opacity. */
114
- function applyColor(paint, color) {
115
- paint.color = {
116
- ...color,
117
- a: 1
118
- };
119
- paint.opacity = color.a;
115
+ function applyVariableColor(paint, color) {
116
+ Object.assign(paint, solidPaintColor(color));
120
117
  }
121
118
  /** Whether `paint` already shows `color` as a bound paint stores it. */
122
119
  function showsColor(paint, color) {
@@ -163,10 +160,10 @@ function refresh(graph, node, forced) {
163
160
  if (!forced(bound.field) && !stale || showsColor(paint, color)) continue;
164
161
  if (bound.list === "fills") {
165
162
  fills ??= copyFills(node.fills);
166
- applyColor(fills[bound.index], color);
163
+ applyVariableColor(fills[bound.index], color);
167
164
  } else {
168
165
  strokes ??= copyStrokes(node.strokes);
169
- applyColor(strokes[bound.index], color);
166
+ applyVariableColor(strokes[bound.index], color);
170
167
  }
171
168
  }
172
169
  const changes = {};
@@ -174,6 +171,23 @@ function refresh(graph, node, forced) {
174
171
  if (strokes) changes.strokes = strokes;
175
172
  if (fills || strokes) writePaints(graph, node, changes);
176
173
  }
174
+ /**
175
+ * A range's own fills with each bound one showing the colour its variable gives the text now, or
176
+ * null when every one does already. A range keeps no record of the colours it was last given, so
177
+ * an edit to a bound range paint lasts until the next refresh of the text's bindings.
178
+ */
179
+ function refreshedRunFills(graph, nodeId, style) {
180
+ let fills;
181
+ for (const [field, variableId] of Object.entries(style.boundVariables ?? {})) {
182
+ const target = paintBindingTarget(field);
183
+ const paint = target?.list === "fills" ? style.fills?.at(target.index) : void 0;
184
+ const color = paint && variableId && graph.resolveColorVariableForNode(nodeId, variableId);
185
+ if (!target || !paint || !color || showsColor(paint, color)) continue;
186
+ fills ??= copyFills(style.fills ?? []);
187
+ applyVariableColor(fills[target.index], color);
188
+ }
189
+ return fills ?? null;
190
+ }
177
191
  const NONE_FORCED = () => false;
178
192
  const ALL_FORCED = () => true;
179
193
  /**
@@ -271,12 +285,11 @@ function keepCopyBoundPaints(graph, target, updates) {
271
285
  const color = graph.resolveColorVariableForNode(target.id, variableId);
272
286
  if (!color) return;
273
287
  const modes = explicitModes(graph, target, variableId);
274
- if (!keeps || staleApplied(target, bound, own, color, modes)) applyColor(paint, color);
288
+ if (!keeps || staleApplied(target, bound, own, color, modes)) applyVariableColor(paint, color);
275
289
  recordApplied(target, bound, color, modes);
276
290
  });
277
291
  }
278
292
  }
279
- //#endregion
280
- export { applyBoundPaintColor, applyBoundPaintColorsIn, captureAppliedBoundPaints, copiesComponentPaints, copyAppliedBoundPaints, hasBoundPaints, keepCopyBoundPaints, keepPastedBoundPaints, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints };
293
+ export { applyBoundPaintColor, applyBoundPaintColorsIn, applyVariableColor, captureAppliedBoundPaints, copiesComponentPaints, copyAppliedBoundPaints, hasBoundPaints, keepCopyBoundPaints, keepPastedBoundPaints, recordWrittenBoundPaints, refreshBoundPaints, refreshBoundPaintsIn, refreshMovedBoundPaints, refreshedRunFills };
281
294
 
282
295
  //# sourceMappingURL=paints.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"paints.js","names":[],"sources":["../../src/variables/paints.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { copyFills, copyStrokes } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { hasInstanceOverride } from '../instances/overrides'\nimport type { Color } from '../primitives'\nimport type { Fill, SceneNode, Stroke } from '../types'\nimport { paintBindingTarget, type PaintBindingList } from './fields'\nimport { collectionsResolving, getNodeExplicitVariableModeId } from './resolution'\nimport { subtreeNodes } from './subtree'\n\n/**\n * Figma keeps a bound paint's color and opacity as a cache of its variable: it draws and reads\n * what the paint holds, and writes the variable's color into it again only once the color the\n * variable gives that layer changes, or the mode set for the layer changes, so an edit to the\n * paint sticks until then. The color each binding last gave its paint, and the modes set for the\n * layer then, live here, beside the graph and never saved, by layer and binding field. A layer\n * without an entry, such as one just restored, counts its paint's own color as the last one\n * applied, in the modes it has now.\n */\nexport interface AppliedColor {\n readonly variableId: string\n readonly color: Color\n /** The mode set for the layer, or null, in each collection the variable resolves through. */\n readonly modes: Readonly<Record<string, string | null>>\n}\n\nconst appliedColors = new WeakMap<SceneNode, Map<string, AppliedColor>>()\n\nconst PAINT_LISTS = ['fills', 'strokes'] as const\n\ninterface BoundPaint {\n readonly field: string\n readonly list: PaintBindingList\n readonly index: number\n readonly variableId: string\n}\n\n/** The paints of `node` whose color is bound to a variable, each with a paint there to color. */\nfunction boundPaints(node: SceneNode): BoundPaint[] {\n const paints: BoundPaint[] = []\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n const target = paintBindingTarget(field)\n if (target && node[target.list].at(target.index)) paints.push({ field, ...target, variableId })\n }\n return paints\n}\n\n/** Whether a layer has a paint whose color is bound to a variable. */\nexport function hasBoundPaints(node: SceneNode): boolean {\n for (const field in node.boundVariables) if (paintBindingTarget(field)) return true\n return false\n}\n\n/** A paint's color with its opacity as alpha, as a variable's color carries it. */\nfunction paintColor(paint: Fill): Color {\n return { r: paint.color.r, g: paint.color.g, b: paint.color.b, a: paint.opacity }\n}\n\n/** Saved colors are single precision, so a color read back from a file still matches its source. */\nconst COLOR_TOLERANCE = 1e-6\n\nfunction sameColor(a: Color, b: Color): boolean {\n return (\n Math.abs(a.r - b.r) <= COLOR_TOLERANCE &&\n Math.abs(a.g - b.g) <= COLOR_TOLERANCE &&\n Math.abs(a.b - b.b) <= COLOR_TOLERANCE &&\n Math.abs(a.a - b.a) <= COLOR_TOLERANCE\n )\n}\n\n/**\n * The modes set for a layer, or null, in the collections a variable resolves through. Figma\n * refreshes a bound paint whenever one of them changes, even to a mode giving the same color.\n */\nfunction explicitModes(\n graph: SceneGraph,\n node: SceneNode,\n variableId: string\n): Record<string, string | null> {\n const modes: Record<string, string | null> = {}\n for (const collectionId of collectionsResolving(graph, [variableId]))\n modes[collectionId] = getNodeExplicitVariableModeId(graph, node.id, collectionId)\n return modes\n}\n\n/** Whether the color a binding last applied is stale: another color, or set in other modes. */\nfunction staleApplied(\n node: SceneNode,\n bound: BoundPaint,\n paint: Fill,\n color: Color,\n modes: Readonly<Record<string, string | null>>\n): boolean {\n const entry = appliedColors.get(node)?.get(bound.field)\n if (entry?.variableId !== bound.variableId) return !sameColor(paintColor(paint), color)\n return !sameColor(entry.color, color) || !isEqual(entry.modes, modes)\n}\n\n/**\n * A layer copied from another keeps the colors its bindings last applied there, so the copy's\n * paints, edits included, stay as they are until their variables' colors for it change.\n */\nexport function copyAppliedBoundPaints(source: SceneNode, copy: SceneNode): void {\n const entries = appliedColors.get(source)\n if (entries) appliedColors.set(copy, new Map(entries))\n}\n\n/** The colors copied layers' bindings last applied, by layer id, as a copy captured them. */\nexport type AppliedBoundPaints = ReadonlyMap<string, ReadonlyMap<string, AppliedColor>>\n\n/**\n * The colors the bindings of the layers `nodeIds` names last applied, captured when they are\n * copied, so a paste counts what the copied paints were applied from, not what the source has now.\n */\nexport function captureAppliedBoundPaints(\n graph: SceneGraph,\n nodeIds: Iterable<string>\n): AppliedBoundPaints {\n const captured = new Map<string, ReadonlyMap<string, AppliedColor>>()\n for (const id of nodeIds) {\n const node = graph.nodes.get(id)\n const entries = node && appliedColors.get(node)\n if (entries) captured.set(id, new Map(entries))\n }\n return captured\n}\n\n/**\n * Pasted layers keep their paints, edits included, as Figma's copies do. One copied in this\n * document takes the colors its source's bindings had last applied when it was copied, so a paste\n * into another mode refreshes them as a move there would; one from elsewhere counts the colors\n * its variables give it now as applied, as a loaded document does. `copies` maps each copied\n * layer's id to its copy's.\n */\nexport function keepPastedBoundPaints(\n graph: SceneGraph,\n copies: ReadonlyMap<string, string>,\n applied: AppliedBoundPaints\n): void {\n for (const [sourceId, copyId] of copies) {\n const copy = graph.nodes.get(copyId)\n if (!copy || !hasBoundPaints(copy)) continue\n const entries = applied.get(sourceId)\n if (!entries) {\n recordWrittenBoundPaints(graph, copy, { fills: copy.fills, strokes: copy.strokes })\n continue\n }\n appliedColors.set(copy, new Map(entries))\n refresh(graph, copy, NONE_FORCED)\n }\n}\n\nfunction recordApplied(\n node: SceneNode,\n bound: BoundPaint,\n color: Color,\n modes: Readonly<Record<string, string | null>>\n): void {\n let entries = appliedColors.get(node)\n if (!entries) {\n entries = new Map()\n appliedColors.set(node, entries)\n }\n entries.set(bound.field, { variableId: bound.variableId, color: { ...color }, modes })\n}\n\n/** The variable's RGB at full alpha in the paint, and its alpha as the paint's opacity. */\nfunction applyColor(paint: Fill, color: Color): void {\n paint.color = { ...color, a: 1 }\n paint.opacity = color.a\n}\n\n/** Whether `paint` already shows `color` as a bound paint stores it. */\nfunction showsColor(paint: Fill, color: Color): boolean {\n return sameColor(paintColor(paint), color) && paint.color.a === 1\n}\n\ntype PaintLists = Pick<Partial<SceneNode>, 'fills' | 'strokes'>\n\n/**\n * Whether `node` is an instance, or a layer an instance copies from its component, with a paint\n * list neither it nor an instance around it overrides: such paints follow the component, and\n * refreshing them is no edit.\n */\nexport function copiesComponentPaints(\n graph: SceneGraph,\n node: SceneNode,\n list: PaintBindingList\n): boolean {\n const walk = { copied: false }\n const overriding = graph.closest(node.id, (current) => {\n if (current.type !== 'INSTANCE') return false\n walk.copied = true\n return hasInstanceOverride(current.instanceOverrides, current.id, node.id, list)\n })\n return walk.copied && !overriding\n}\n\n/**\n * Writes refreshed paints. A copy's paints that follow its component are derived values that a\n * save leaves to the component, not edits written over it.\n */\nfunction writePaints(graph: SceneGraph, node: SceneNode, changes: PaintLists): void {\n const derived = PAINT_LISTS.every(\n (list) => !changes[list] || copiesComponentPaints(graph, node, list)\n )\n const write = () => graph.updateNode(node.id, changes)\n if (derived) graph.applyComponentDerivedDuring(write)\n else write()\n}\n\n/**\n * Writes into each bound paint the color its variable gives the layer now, where that differs\n * from the color last applied, or wherever `forced` says, and records what each binding gives.\n */\nfunction refresh(graph: SceneGraph, node: SceneNode, forced: (field: string) => boolean): void {\n let fills: Fill[] | undefined\n let strokes: Stroke[] | undefined\n for (const bound of boundPaints(node)) {\n const color = graph.resolveColorVariableForNode(node.id, bound.variableId)\n const paint = node[bound.list].at(bound.index)\n if (!color || !paint) continue\n const modes = explicitModes(graph, node, bound.variableId)\n const stale = staleApplied(node, bound, paint, color, modes)\n recordApplied(node, bound, color, modes)\n if ((!forced(bound.field) && !stale) || showsColor(paint, color)) continue\n if (bound.list === 'fills') {\n fills ??= copyFills(node.fills)\n applyColor(fills[bound.index], color)\n } else {\n strokes ??= copyStrokes(node.strokes)\n applyColor(strokes[bound.index], color)\n }\n }\n const changes: PaintLists = {}\n if (fills) changes.fills = fills\n if (strokes) changes.strokes = strokes\n if (fills || strokes) writePaints(graph, node, changes)\n}\n\nconst NONE_FORCED = (): boolean => false\nconst ALL_FORCED = (): boolean => true\n\n/**\n * Refreshes a layer's bound paints: each takes its variable's color for the layer, alpha as\n * opacity, once that color differs from the one last applied, discarding edits made since, as\n * Figma refreshes them when a variable's value or a layer's mode changes.\n */\nexport function refreshBoundPaints(graph: SceneGraph, node: SceneNode): void {\n if (hasBoundPaints(node)) refresh(graph, node, NONE_FORCED)\n}\n\n/** Gives one bound paint its variable's color for the layer, as binding it does in Figma. */\nexport function applyBoundPaintColor(graph: SceneGraph, node: SceneNode, field: string): void {\n if (paintBindingTarget(field)) refresh(graph, node, (bound) => bound === field)\n}\n\n/**\n * Gives every bound paint in this subtree its variable's color where it sits. A new instance\n * or a layer an instance sync adds is a copy, which shows its variables in its own context rather\n * than whatever its component's paints hold.\n */\nexport function applyBoundPaintColorsIn(graph: SceneGraph, rootId: string): void {\n for (const node of subtreeNodes(graph, [rootId]))\n if (hasBoundPaints(node)) refresh(graph, node, ALL_FORCED)\n}\n\n/** Refreshes the bound paints in this subtree whose variables now give their layers another color. */\nexport function refreshBoundPaintsIn(graph: SceneGraph, rootId: string): void {\n for (const node of subtreeNodes(graph, [rootId])) refreshBoundPaints(graph, node)\n}\n\n/**\n * Records, for the paint lists a write sets, the colors their variables give the layer now, so a\n * paint written with another color or opacity keeps it until that color changes.\n */\nexport function recordWrittenBoundPaints(\n graph: SceneGraph,\n node: SceneNode,\n written: PaintLists\n): void {\n for (const bound of boundPaints(node)) {\n if (!written[bound.list]) continue\n const color = graph.resolveColorVariableForNode(node.id, bound.variableId)\n if (color) recordApplied(node, bound, color, explicitModes(graph, node, bound.variableId))\n }\n}\n\n/**\n * Refreshes the bound paints in a moved layer's subtree that resolve through a collection whose\n * mode set the move changed, as Figma does when a layer enters a frame or page that sets another\n * mode, or one where none was. A move between parents setting the same modes, or of layers that\n * bind no paint, costs no more than comparing those modes.\n */\nexport function refreshMovedBoundPaints(\n graph: SceneGraph,\n nodeId: string,\n previousParentId: string | null | undefined\n): void {\n if (graph.isApplyingImportedState || graph.variableCollections.size === 0) return\n const parentId = graph.nodes.get(nodeId)?.parentId\n if (!parentId) return\n const previous = previousParentId && graph.nodes.has(previousParentId) ? previousParentId : null\n const changed = new Set(\n [...graph.variableCollections.keys()].filter(\n (id) =>\n !previous ||\n getNodeExplicitVariableModeId(graph, previous, id) !==\n getNodeExplicitVariableModeId(graph, parentId, id)\n )\n )\n if (changed.size === 0) return\n const reaches = new Map<string, boolean>()\n const reachesChanged = (variableId: string) => {\n let found = reaches.get(variableId)\n if (found === undefined) {\n found = [...collectionsResolving(graph, [variableId])].some((id) => changed.has(id))\n reaches.set(variableId, found)\n }\n return found\n }\n for (const node of subtreeNodes(graph, [nodeId])) {\n if (boundPaints(node).some((bound) => reachesChanged(bound.variableId)))\n refresh(graph, node, NONE_FORCED)\n }\n}\n\nfunction reboundPaint(\n target: SceneNode,\n bindings: Readonly<Record<string, string>>,\n list: PaintBindingList\n): boolean {\n return target[list].some((_, index) => {\n const field = `${list}/${index}/color`\n return field in bindings && bindings[field] !== target.boundVariables[field]\n })\n}\n\n/**\n * A copy's bound paints are its own cache, as Figma keeps them per layer, so a component's edit\n * to its paint's color or opacity does not reach them. An instance sync writing a copy's paints\n * keeps the color and opacity of each one still bound to the same variable, and gives it the\n * variable's color for the copy once that differs from the one last applied, or when it binds\n * anew. `updates` holds what the sync writes, whose paints this sets in place.\n */\nexport function keepCopyBoundPaints(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>\n): void {\n const bindings = updates.boundVariables ?? target.boundVariables\n for (const list of PAINT_LISTS) {\n // A paint the component binds anew keeps its own paint otherwise, but takes the new color.\n if (!updates[list] && reboundPaint(target, bindings, list))\n Object.assign(updates, {\n [list]: list === 'fills' ? copyFills(target.fills) : copyStrokes(target.strokes)\n })\n updates[list]?.forEach((paint, index) => {\n const field = `${list}/${index}/color`\n const variableId = bindings[field]\n if (!variableId) return\n const bound = { field, list, index, variableId }\n const own = target[list].at(index)\n const keeps = own !== undefined && target.boundVariables[field] === variableId\n if (keeps) {\n paint.color = { ...own.color }\n paint.opacity = own.opacity\n }\n const color = graph.resolveColorVariableForNode(target.id, variableId)\n if (!color) return\n const modes = explicitModes(graph, target, variableId)\n if (!keeps || staleApplied(target, bound, own, color, modes)) applyColor(paint, color)\n recordApplied(target, bound, color, modes)\n })\n }\n}\n"],"mappings":";;;;;;;AA2BA,MAAM,gCAAgB,IAAI,QAA8C;AAExE,MAAM,cAAc,CAAC,SAAS,SAAS;;AAUvC,SAA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MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM;GAC/B,MAAM,aAAa,SAAS;GAC5B,IAAI,CAAC,YAAY;GACjB,MAAM,QAAQ;IAAE;IAAO;IAAM;IAAO;GAAW;GAC/C,MAAM,MAAM,OAAO,KAAK,CAAC,GAAG,KAAK;GACjC,MAAM,QAAQ,QAAQ,KAAA,KAAa,OAAO,eAAe,WAAW;GACpE,IAAI,OAAO;IACT,MAAM,QAAQ,EAAE,GAAG,IAAI,MAAM;IAC7B,MAAM,UAAU,IAAI;GACtB;GACA,MAAM,QAAQ,MAAM,4BAA4B,OAAO,IAAI,UAAU;GACrE,IAAI,CAAC,OAAO;GACZ,MAAM,QAAQ,cAAc,OAAO,QAAQ,UAAU;GACrD,IAAI,CAAC,SAAS,aAAa,QAAQ,OAAO,KAAK,OAAO,KAAK,GAAG,WAAW,OAAO,KAAK;GACrF,cAAc,QAAQ,OAAO,OAAO,KAAK;EAC3C,CAAC;CACH;AACF"}
1
+ {"version":3,"file":"paints.js","names":[],"sources":["../../src/variables/paints.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport { copyFills, copyStrokes } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport { hasInstanceOverride } from '../instances/overrides'\nimport { solidPaintColor } from '../paints/solid'\nimport type { Color } from '../primitives'\nimport type { CharacterStyleOverride, Fill, SceneNode, Stroke } from '../types'\nimport { paintBindingTarget, type PaintBindingList } from './fields'\nimport { collectionsResolving, getNodeExplicitVariableModeId } from './resolution'\nimport { subtreeNodes } from './subtree'\n\n/**\n * Figma keeps a bound paint's color and opacity as a cache of its variable: it draws and reads\n * what the paint holds, and writes the variable's color into it again only once the color the\n * variable gives that layer changes, or the mode set for the layer changes, so an edit to the\n * paint sticks until then. The color each binding last gave its paint, and the modes set for the\n * layer then, live here, beside the graph and never saved, by layer and binding field. A layer\n * without an entry, such as one just restored, counts its paint's own color as the last one\n * applied, in the modes it has now.\n */\nexport interface AppliedColor {\n readonly variableId: string\n readonly color: Color\n /** The mode set for the layer, or null, in each collection the variable resolves through. */\n readonly modes: Readonly<Record<string, string | null>>\n}\n\nconst appliedColors = new WeakMap<SceneNode, Map<string, AppliedColor>>()\n\nconst PAINT_LISTS = ['fills', 'strokes'] as const\n\ninterface BoundPaint {\n readonly field: string\n readonly list: PaintBindingList\n readonly index: number\n readonly variableId: string\n}\n\n/** The paints of `node` whose color is bound to a variable, each with a paint there to color. */\nfunction boundPaints(node: SceneNode): BoundPaint[] {\n const paints: BoundPaint[] = []\n for (const [field, variableId] of Object.entries(node.boundVariables)) {\n const target = paintBindingTarget(field)\n if (target && node[target.list].at(target.index)) paints.push({ field, ...target, variableId })\n }\n return paints\n}\n\n/** Whether a layer has a paint whose color is bound to a variable. */\nexport function hasBoundPaints(node: SceneNode): boolean {\n for (const field in node.boundVariables) if (paintBindingTarget(field)) return true\n return false\n}\n\n/** A paint's color with its opacity as alpha, as a variable's color carries it. */\nfunction paintColor(paint: Fill): Color {\n return { r: paint.color.r, g: paint.color.g, b: paint.color.b, a: paint.opacity }\n}\n\n/** Saved colors are single precision, so a color read back from a file still matches its source. */\nconst COLOR_TOLERANCE = 1e-6\n\nfunction sameColor(a: Color, b: Color): boolean {\n return (\n Math.abs(a.r - b.r) <= COLOR_TOLERANCE &&\n Math.abs(a.g - b.g) <= COLOR_TOLERANCE &&\n Math.abs(a.b - b.b) <= COLOR_TOLERANCE &&\n Math.abs(a.a - b.a) <= COLOR_TOLERANCE\n )\n}\n\n/**\n * The modes set for a layer, or null, in the collections a variable resolves through. Figma\n * refreshes a bound paint whenever one of them changes, even to a mode giving the same color.\n */\nfunction explicitModes(\n graph: SceneGraph,\n node: SceneNode,\n variableId: string\n): Record<string, string | null> {\n const modes: Record<string, string | null> = {}\n for (const collectionId of collectionsResolving(graph, [variableId]))\n modes[collectionId] = getNodeExplicitVariableModeId(graph, node.id, collectionId)\n return modes\n}\n\n/** Whether the color a binding last applied is stale: another color, or set in other modes. */\nfunction staleApplied(\n node: SceneNode,\n bound: BoundPaint,\n paint: Fill,\n color: Color,\n modes: Readonly<Record<string, string | null>>\n): boolean {\n const entry = appliedColors.get(node)?.get(bound.field)\n if (entry?.variableId !== bound.variableId) return !sameColor(paintColor(paint), color)\n return !sameColor(entry.color, color) || !isEqual(entry.modes, modes)\n}\n\n/**\n * A layer copied from another keeps the colors its bindings last applied there, so the copy's\n * paints, edits included, stay as they are until their variables' colors for it change.\n */\nexport function copyAppliedBoundPaints(source: SceneNode, copy: SceneNode): void {\n const entries = appliedColors.get(source)\n if (entries) appliedColors.set(copy, new Map(entries))\n}\n\n/** The colors copied layers' bindings last applied, by layer id, as a copy captured them. */\nexport type AppliedBoundPaints = ReadonlyMap<string, ReadonlyMap<string, AppliedColor>>\n\n/**\n * The colors the bindings of the layers `nodeIds` names last applied, captured when they are\n * copied, so a paste counts what the copied paints were applied from, not what the source has now.\n */\nexport function captureAppliedBoundPaints(\n graph: SceneGraph,\n nodeIds: Iterable<string>\n): AppliedBoundPaints {\n const captured = new Map<string, ReadonlyMap<string, AppliedColor>>()\n for (const id of nodeIds) {\n const node = graph.nodes.get(id)\n const entries = node && appliedColors.get(node)\n if (entries) captured.set(id, new Map(entries))\n }\n return captured\n}\n\n/**\n * Pasted layers keep their paints, edits included, as Figma's copies do. One copied in this\n * document takes the colors its source's bindings had last applied when it was copied, so a paste\n * into another mode refreshes them as a move there would; one from elsewhere counts the colors\n * its variables give it now as applied, as a loaded document does. `copies` maps each copied\n * layer's id to its copy's.\n */\nexport function keepPastedBoundPaints(\n graph: SceneGraph,\n copies: ReadonlyMap<string, string>,\n applied: AppliedBoundPaints\n): void {\n for (const [sourceId, copyId] of copies) {\n const copy = graph.nodes.get(copyId)\n if (!copy || !hasBoundPaints(copy)) continue\n const entries = applied.get(sourceId)\n if (!entries) {\n recordWrittenBoundPaints(graph, copy, { fills: copy.fills, strokes: copy.strokes })\n continue\n }\n appliedColors.set(copy, new Map(entries))\n refresh(graph, copy, NONE_FORCED)\n }\n}\n\nfunction recordApplied(\n node: SceneNode,\n bound: BoundPaint,\n color: Color,\n modes: Readonly<Record<string, string | null>>\n): void {\n let entries = appliedColors.get(node)\n if (!entries) {\n entries = new Map()\n appliedColors.set(node, entries)\n }\n entries.set(bound.field, { variableId: bound.variableId, color: { ...color }, modes })\n}\n\n/** The variable's RGB at full alpha in the paint, and its alpha as the paint's opacity. */\nexport function applyVariableColor(paint: Fill, color: Color): void {\n Object.assign(paint, solidPaintColor(color))\n}\n\n/** Whether `paint` already shows `color` as a bound paint stores it. */\nfunction showsColor(paint: Fill, color: Color): boolean {\n return sameColor(paintColor(paint), color) && paint.color.a === 1\n}\n\ntype PaintLists = Pick<Partial<SceneNode>, 'fills' | 'strokes'>\n\n/**\n * Whether `node` is an instance, or a layer an instance copies from its component, with a paint\n * list neither it nor an instance around it overrides: such paints follow the component, and\n * refreshing them is no edit.\n */\nexport function copiesComponentPaints(\n graph: SceneGraph,\n node: SceneNode,\n list: PaintBindingList\n): boolean {\n const walk = { copied: false }\n const overriding = graph.closest(node.id, (current) => {\n if (current.type !== 'INSTANCE') return false\n walk.copied = true\n return hasInstanceOverride(current.instanceOverrides, current.id, node.id, list)\n })\n return walk.copied && !overriding\n}\n\n/**\n * Writes refreshed paints. A copy's paints that follow its component are derived values that a\n * save leaves to the component, not edits written over it.\n */\nfunction writePaints(graph: SceneGraph, node: SceneNode, changes: PaintLists): void {\n const derived = PAINT_LISTS.every(\n (list) => !changes[list] || copiesComponentPaints(graph, node, list)\n )\n const write = () => graph.updateNode(node.id, changes)\n if (derived) graph.applyComponentDerivedDuring(write)\n else write()\n}\n\n/**\n * Writes into each bound paint the color its variable gives the layer now, where that differs\n * from the color last applied, or wherever `forced` says, and records what each binding gives.\n */\nfunction refresh(graph: SceneGraph, node: SceneNode, forced: (field: string) => boolean): void {\n let fills: Fill[] | undefined\n let strokes: Stroke[] | undefined\n for (const bound of boundPaints(node)) {\n const color = graph.resolveColorVariableForNode(node.id, bound.variableId)\n const paint = node[bound.list].at(bound.index)\n if (!color || !paint) continue\n const modes = explicitModes(graph, node, bound.variableId)\n const stale = staleApplied(node, bound, paint, color, modes)\n recordApplied(node, bound, color, modes)\n if ((!forced(bound.field) && !stale) || showsColor(paint, color)) continue\n if (bound.list === 'fills') {\n fills ??= copyFills(node.fills)\n applyVariableColor(fills[bound.index], color)\n } else {\n strokes ??= copyStrokes(node.strokes)\n applyVariableColor(strokes[bound.index], color)\n }\n }\n const changes: PaintLists = {}\n if (fills) changes.fills = fills\n if (strokes) changes.strokes = strokes\n if (fills || strokes) writePaints(graph, node, changes)\n}\n\n/**\n * A range's own fills with each bound one showing the colour its variable gives the text now, or\n * null when every one does already. A range keeps no record of the colours it was last given, so\n * an edit to a bound range paint lasts until the next refresh of the text's bindings.\n */\nexport function refreshedRunFills(\n graph: SceneGraph,\n nodeId: string,\n style: CharacterStyleOverride\n): Fill[] | null {\n let fills: Fill[] | undefined\n for (const [field, variableId] of Object.entries(style.boundVariables ?? {})) {\n const target = paintBindingTarget(field)\n const paint = target?.list === 'fills' ? style.fills?.at(target.index) : undefined\n const color = paint && variableId && graph.resolveColorVariableForNode(nodeId, variableId)\n if (!target || !paint || !color || showsColor(paint, color)) continue\n fills ??= copyFills(style.fills ?? [])\n applyVariableColor(fills[target.index], color)\n }\n return fills ?? null\n}\n\nconst NONE_FORCED = (): boolean => false\nconst ALL_FORCED = (): boolean => true\n\n/**\n * Refreshes a layer's bound paints: each takes its variable's color for the layer, alpha as\n * opacity, once that color differs from the one last applied, discarding edits made since, as\n * Figma refreshes them when a variable's value or a layer's mode changes.\n */\nexport function refreshBoundPaints(graph: SceneGraph, node: SceneNode): void {\n if (hasBoundPaints(node)) refresh(graph, node, NONE_FORCED)\n}\n\n/** Gives one bound paint its variable's color for the layer, as binding it does in Figma. */\nexport function applyBoundPaintColor(graph: SceneGraph, node: SceneNode, field: string): void {\n if (paintBindingTarget(field)) refresh(graph, node, (bound) => bound === field)\n}\n\n/**\n * Gives every bound paint in this subtree its variable's color where it sits. A new instance\n * or a layer an instance sync adds is a copy, which shows its variables in its own context rather\n * than whatever its component's paints hold.\n */\nexport function applyBoundPaintColorsIn(graph: SceneGraph, rootId: string): void {\n for (const node of subtreeNodes(graph, [rootId]))\n if (hasBoundPaints(node)) refresh(graph, node, ALL_FORCED)\n}\n\n/** Refreshes the bound paints in this subtree whose variables now give their layers another color. */\nexport function refreshBoundPaintsIn(graph: SceneGraph, rootId: string): void {\n for (const node of subtreeNodes(graph, [rootId])) refreshBoundPaints(graph, node)\n}\n\n/**\n * Records, for the paint lists a write sets, the colors their variables give the layer now, so a\n * paint written with another color or opacity keeps it until that color changes.\n */\nexport function recordWrittenBoundPaints(\n graph: SceneGraph,\n node: SceneNode,\n written: PaintLists\n): void {\n for (const bound of boundPaints(node)) {\n if (!written[bound.list]) continue\n const color = graph.resolveColorVariableForNode(node.id, bound.variableId)\n if (color) recordApplied(node, bound, color, explicitModes(graph, node, bound.variableId))\n }\n}\n\n/**\n * Refreshes the bound paints in a moved layer's subtree that resolve through a collection whose\n * mode set the move changed, as Figma does when a layer enters a frame or page that sets another\n * mode, or one where none was. A move between parents setting the same modes, or of layers that\n * bind no paint, costs no more than comparing those modes.\n */\nexport function refreshMovedBoundPaints(\n graph: SceneGraph,\n nodeId: string,\n previousParentId: string | null | undefined\n): void {\n if (graph.isApplyingImportedState || graph.variableCollections.size === 0) return\n const parentId = graph.nodes.get(nodeId)?.parentId\n if (!parentId) return\n const previous = previousParentId && graph.nodes.has(previousParentId) ? previousParentId : null\n const changed = new Set(\n [...graph.variableCollections.keys()].filter(\n (id) =>\n !previous ||\n getNodeExplicitVariableModeId(graph, previous, id) !==\n getNodeExplicitVariableModeId(graph, parentId, id)\n )\n )\n if (changed.size === 0) return\n const reaches = new Map<string, boolean>()\n const reachesChanged = (variableId: string) => {\n let found = reaches.get(variableId)\n if (found === undefined) {\n found = [...collectionsResolving(graph, [variableId])].some((id) => changed.has(id))\n reaches.set(variableId, found)\n }\n return found\n }\n for (const node of subtreeNodes(graph, [nodeId])) {\n if (boundPaints(node).some((bound) => reachesChanged(bound.variableId)))\n refresh(graph, node, NONE_FORCED)\n }\n}\n\nfunction reboundPaint(\n target: SceneNode,\n bindings: Readonly<Record<string, string>>,\n list: PaintBindingList\n): boolean {\n return target[list].some((_, index) => {\n const field = `${list}/${index}/color`\n return field in bindings && bindings[field] !== target.boundVariables[field]\n })\n}\n\n/**\n * A copy's bound paints are its own cache, as Figma keeps them per layer, so a component's edit\n * to its paint's color or opacity does not reach them. An instance sync writing a copy's paints\n * keeps the color and opacity of each one still bound to the same variable, and gives it the\n * variable's color for the copy once that differs from the one last applied, or when it binds\n * anew. `updates` holds what the sync writes, whose paints this sets in place.\n */\nexport function keepCopyBoundPaints(\n graph: SceneGraph,\n target: SceneNode,\n updates: Partial<SceneNode>\n): void {\n const bindings = updates.boundVariables ?? target.boundVariables\n for (const list of PAINT_LISTS) {\n // A paint the component binds anew keeps its own paint otherwise, but takes the new color.\n if (!updates[list] && reboundPaint(target, bindings, list))\n Object.assign(updates, {\n [list]: list === 'fills' ? copyFills(target.fills) : copyStrokes(target.strokes)\n })\n updates[list]?.forEach((paint, index) => {\n const field = `${list}/${index}/color`\n const variableId = bindings[field]\n if (!variableId) return\n const bound = { field, list, index, variableId }\n const own = target[list].at(index)\n const keeps = own !== undefined && target.boundVariables[field] === variableId\n if (keeps) {\n paint.color = { ...own.color }\n paint.opacity = own.opacity\n }\n const color = graph.resolveColorVariableForNode(target.id, variableId)\n if (!color) return\n const modes = explicitModes(graph, target, variableId)\n if (!keeps || staleApplied(target, bound, own, color, modes)) applyVariableColor(paint, color)\n recordApplied(target, bound, color, modes)\n })\n }\n}\n"],"mappings":";;;;;;;;AA4BA,MAAM,gCAAgB,IAAI,QAA8C;AAExE,MAAM,cAAc,CAAC,SAAS,SAAS;;AAUvC,SAAS,YAAY,MAA+B;CAClD,MAAM,SAAuB,CAAC;CAC9B,KAAK,MAAM,CAAC,OAAO,eAAe,OAAO,QAAQ,KAAK,c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,SAAS,YAAY,SAAS,WAAW,OAAO,eAAe;CACxE,CAAC;AACH;;;;;;;;AASA,SAAgB,oBACd,OACA,QACA,SACM;CACN,MAAM,WAAW,QAAQ,kBAAkB,OAAO;CAClD,KAAK,MAAM,QAAQ,aAAa;EAE9B,IAAI,CAAC,QAAQ,SAAS,aAAa,QAAQ,UAAU,IAAI,GACvD,OAAO,OAAO,SAAS,GACpB,OAAO,SAAS,UAAU,UAAU,OAAO,KAAK,IAAI,YAAY,OAAO,OAAO,EACjF,CAAC;EACH,QAAQ,KAAK,EAAE,SAAS,OAAO,UAAU;GACvC,MAAM,QAAQ,GAAG,KAAK,GAAG,MAAM;GAC/B,MAAM,aAAa,SAAS;GAC5B,IAAI,CAAC,YAAY;GACjB,MAAM,QAAQ;IAAE;IAAO;IAAM;IAAO;GAAW;GAC/C,MAAM,MAAM,OAAO,KAAK,CAAC,GAAG,KAAK;GACjC,MAAM,QAAQ,QAAQ,KAAA,KAAa,OAAO,eAAe,WAAW;GACpE,IAAI,OAAO;IACT,MAAM,QAAQ,EAAE,GAAG,IAAI,MAAM;IAC7B,MAAM,UAAU,IAAI;GACtB;GACA,MAAM,QAAQ,MAAM,4BAA4B,OAAO,IAAI,UAAU;GACrE,IAAI,CAAC,OAAO;GACZ,MAAM,QAAQ,cAAc,OAAO,QAAQ,UAAU;GACrD,IAAI,CAAC,SAAS,aAAa,QAAQ,OAAO,KAAK,OAAO,KAAK,GAAG,mBAAmB,OAAO,KAAK;GAC7F,cAAc,QAAQ,OAAO,OAAO,KAAK;EAC3C,CAAC;CACH;AACF"}
@@ -1,22 +1,27 @@
1
- import { Color } from "../primitives/index.js";
2
1
  import { SceneGraph } from "../graph.js";
2
+ import { Color } from "../primitives/index.js";
3
3
  import { Variable, VariableLiteral, VariableValue } from "../types.js";
4
4
  import { VariableFormulaError } from "./formula/tree.js";
5
- //#region src/variables/resolution.d.ts
6
5
  /**
7
6
  * The mode a node is in for a collection: the nearest explicit mode on it or an ancestor (the page
8
7
  * included), else the collection's default, as Figma resolves it.
9
8
  */
10
- declare function getNodeVariableModeId(graph: SceneGraph, nodeId: string, collectionId: string): string;
9
+ export declare function getNodeVariableModeId(graph: SceneGraph, nodeId: string, collectionId: string): string;
10
+ /**
11
+ * Whether a mode set for a collection still picks one of its modes. A layer keeps a mode its
12
+ * collection removed, as Figma keeps it, and resolves as if none were set (live-verified); a
13
+ * collection the document does not hold, such as an unloaded library's, keeps every mode.
14
+ */
15
+ export declare function collectionHoldsMode(graph: SceneGraph, collectionId: string, modeId: string): boolean;
11
16
  /** The nearest mode set on a node or an ancestor for a collection, or null where none is. */
12
- declare function getNodeExplicitVariableModeId(graph: SceneGraph, nodeId: string, collectionId: string): string | null;
17
+ export declare function getNodeExplicitVariableModeId(graph: SceneGraph, nodeId: string, collectionId: string): string | null;
13
18
  /**
14
19
  * The collections whose modes decide what these variables resolve to: their own, and those of the
15
20
  * variables they alias, at any depth and in any mode.
16
21
  */
17
- declare function collectionsResolving(graph: SceneGraph, variableIds: Iterable<string>): Set<string>;
18
- declare function resolveVariable(graph: SceneGraph, variableId: string, modeId?: string, visited?: Set<string>): VariableLiteral | undefined;
19
- declare class VariableResolutionError extends VariableFormulaError {
22
+ export declare function collectionsResolving(graph: SceneGraph, variableIds: Iterable<string>): Set<string>;
23
+ export declare function resolveVariable(graph: SceneGraph, variableId: string, modeId?: string, visited?: Set<string>): VariableLiteral | undefined;
24
+ export declare class VariableResolutionError extends VariableFormulaError {
20
25
  readonly code: 'cycle' | 'depth' | 'missing-variable' | 'missing-value' | 'type' | 'non-finite';
21
26
  readonly variableId: string;
22
27
  name: string;
@@ -26,19 +31,17 @@ declare class VariableResolutionError extends VariableFormulaError {
26
31
  * Resolve a draft or saved definition with identical mode, dependency and error semantics. A
27
32
  * memo shares values between lookups in one mode context; without one, nothing is cached.
28
33
  */
29
- declare function resolveVariableInModes(graph: SceneGraph, variableId: string, modeFor: (collectionId: string) => string, visiting?: Set<string>, memo?: Map<string, VariableLiteral>, overrides?: ReadonlyMap<string, VariableValue>): VariableLiteral;
34
+ export declare function resolveVariableInModes(graph: SceneGraph, variableId: string, modeFor: (collectionId: string) => string, visiting?: Set<string>, memo?: Map<string, VariableLiteral>, overrides?: ReadonlyMap<string, VariableValue>): VariableLiteral;
30
35
  /** Shared mode fallback for canvas resolution and formula draft validation. */
31
- declare function variableValueInMode(graph: SceneGraph, variable: Variable, modeId: string): VariableValue | undefined;
32
- type NodeVariableResolver = (nodeId: string, variableId: string) => VariableLiteral | undefined;
36
+ export declare function variableValueInMode(graph: SceneGraph, variable: Variable, modeId: string): VariableValue | undefined;
37
+ export type NodeVariableResolver = (nodeId: string, variableId: string) => VariableLiteral | undefined;
33
38
  /** One read/reconcile operation only: equal mode contexts share results, edits start a new cache. */
34
- declare function createBatchVariableResolver(graph: SceneGraph): NodeVariableResolver;
35
- declare function resolveColorVariable(graph: SceneGraph, variableId: string): Color | undefined;
36
- declare function resolveNumberVariable(graph: SceneGraph, variableId: string): number | undefined;
37
- declare function resolveColorVariableForNode(graph: SceneGraph, nodeId: string, variableId: string): Color | undefined;
38
- declare function resolveNumberVariableForNode(graph: SceneGraph, nodeId: string, variableId: string): number | undefined;
39
+ export declare function createBatchVariableResolver(graph: SceneGraph): NodeVariableResolver;
40
+ export declare function resolveColorVariable(graph: SceneGraph, variableId: string): Color | undefined;
41
+ export declare function resolveNumberVariable(graph: SceneGraph, variableId: string): number | undefined;
42
+ export declare function resolveColorVariableForNode(graph: SceneGraph, nodeId: string, variableId: string): Color | undefined;
43
+ export declare function resolveNumberVariableForNode(graph: SceneGraph, nodeId: string, variableId: string): number | undefined;
39
44
  /** A variable's value in the mode a node is in, aliases followed. */
40
- declare function resolveVariableForNode(graph: SceneGraph, nodeId: string, variableId: string): VariableLiteral | undefined;
41
- declare function resolveStringVariableForNode(graph: SceneGraph, nodeId: string, variableId: string): string | undefined;
42
- //#endregion
43
- export { NodeVariableResolver, VariableResolutionError, collectionsResolving, createBatchVariableResolver, getNodeExplicitVariableModeId, getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, variableValueInMode };
45
+ export declare function resolveVariableForNode(graph: SceneGraph, nodeId: string, variableId: string): VariableLiteral | undefined;
46
+ export declare function resolveStringVariableForNode(graph: SceneGraph, nodeId: string, variableId: string): string | undefined;
44
47
  //# sourceMappingURL=resolution.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolution.d.ts","names":[],"sources":["../../src/variables/resolution.ts"],"mappings":";;;;;;;;;iBAgBgB,sBACd,OAAO,YACP,gBACA;;iBAQc,8BACd,OAAO,YACP,gBACA;;;;;iBAec,qBACd,OAAO,YACP,aAAa,mBACZ;iBAgBa,gBACd,OAAO,YACP,oBACA,iBACA,UAAU,cACT;cAaU,gCAAgC;WAGhC;WACA;EAHF;EAEE,YAAA,wFACA,oBACT;;;;;;iBAYY,uBACd,OAAO,YACP,oBACA,UAAU,iCACV,WAAQ,aACR,OAAO,YAAY,kBACnB,YAAY,oBAAoB,iBAC/B;;iBA2Ha,oBACd,OAAO,YACP,UAAU,UACV,iBACC;KAQS,wBACV,gBACA,uBACG;;iBAGW,4BAA4B,OAAO,aAAa;iBAqBhD,qBAAqB,OAAO,YAAY,qBAAqB;iBAM7D,sBAAsB,OAAO,YAAY;iBAKzC,4BACd,OAAO,YACP,gBACA,qBACC;iBAMa,6BACd,OAAO,YACP,gBACA;;iBAOc,uBACd,OAAO,YACP,gBACA,qBACC;iBAMa,6BACd,OAAO,YACP,gBACA"}
1
+ {"version":3,"file":"resolution.d.ts","names":[],"sources":["../../src/variables/resolution.ts"],"mappings":";;;;;;;;wBAgBgB,sBACd,OAAO,YACP,gBACA;;;;;;wBAYc,oBACd,OAAO,YACP,sBACA;;wBAOc,8BACd,OAAO,YACP,gBACA;;;;;wBAec,qBACd,OAAO,YACP,aAAa,mBACZ;wBAgBa,gBACd,OAAO,YACP,oBACA,iBACA,UAAU,cACT;qBAaU,gCAAgC;WAGhC;WACA;EAHF;EAEE,YAAA,wFACA,oBACT;;;;;;wBAmBY,uBACd,OAAO,YACP,oBACA,UAAU,iCACV,WAAQ,aACR,OAAO,YAAY,kBACnB,YAAY,oBAAoB,iBAC/B;;wBA0Ha,oBACd,OAAO,YACP,UAAU,UACV,iBACC;YAQS,wBACV,gBACA,uBACG;;wBAGW,4BAA4B,OAAO,aAAa;wBAqBhD,qBAAqB,OAAO,YAAY,qBAAqB;wBAM7D,sBAAsB,OAAO,YAAY;wBAKzC,4BACd,OAAO,YACP,gBACA,qBACC;wBAMa,6BACd,OAAO,YACP,gBACA;;wBAOc,uBACd,OAAO,YACP,gBACA,qBACC;wBAMa,6BACd,OAAO,YACP,gBACA"}
@@ -1,7 +1,7 @@
1
+ import { appendAll } from "@open-pencil/std/arrays";
1
2
  import { VariableFormulaError } from "./formula/tree.js";
2
3
  import { resolveVariableValue, variableValueReferences } from "./value.js";
3
- import { appendAll } from "@open-pencil/std/arrays";
4
- //#region src/variables/resolution.ts
4
+ // src/variables/resolution.ts
5
5
  function defaultModeId(graph, collectionId) {
6
6
  return graph.variableCollections.get(collectionId)?.defaultModeId ?? "";
7
7
  }
@@ -12,12 +12,21 @@ function defaultModeId(graph, collectionId) {
12
12
  function getNodeVariableModeId(graph, nodeId, collectionId) {
13
13
  return getNodeExplicitVariableModeId(graph, nodeId, collectionId) ?? defaultModeId(graph, collectionId);
14
14
  }
15
+ /**
16
+ * Whether a mode set for a collection still picks one of its modes. A layer keeps a mode its
17
+ * collection removed, as Figma keeps it, and resolves as if none were set (live-verified); a
18
+ * collection the document does not hold, such as an unloaded library's, keeps every mode.
19
+ */
20
+ function collectionHoldsMode(graph, collectionId, modeId) {
21
+ const collection = graph.variableCollections.get(collectionId);
22
+ return !collection || collection.modes.some((mode) => mode.modeId === modeId);
23
+ }
15
24
  /** The nearest mode set on a node or an ancestor for a collection, or null where none is. */
16
25
  function getNodeExplicitVariableModeId(graph, nodeId, collectionId) {
17
26
  let node = graph.nodes.get(nodeId);
18
27
  while (node) {
19
28
  const modeId = node.variableModes[collectionId];
20
- if (modeId) return modeId;
29
+ if (modeId && collectionHoldsMode(graph, collectionId, modeId)) return modeId;
21
30
  node = node.parentId ? graph.nodes.get(node.parentId) : void 0;
22
31
  }
23
32
  return null;
@@ -54,12 +63,14 @@ var VariableResolutionError = class extends VariableFormulaError {
54
63
  this.variableId = variableId;
55
64
  }
56
65
  };
57
- const RESULT_TYPES = {
58
- FLOAT: "number",
59
- BOOLEAN: "boolean",
60
- STRING: "string",
61
- COLOR: "object"
62
- };
66
+ /** Whether a resolved value is one a variable of this type gives. */
67
+ function fitsType(value, type) {
68
+ if (type === "COLOR") return typeof value === "object" && "r" in value;
69
+ if (type === "EASING") return typeof value === "object" && "easing" in value;
70
+ if (type === "BOOLEAN") return typeof value === "boolean";
71
+ if (type === "STRING") return typeof value === "string";
72
+ return typeof value === "number";
73
+ }
63
74
  /**
64
75
  * Resolve a draft or saved definition with identical mode, dependency and error semantics. A
65
76
  * memo shares values between lookups in one mode context; without one, nothing is cached.
@@ -81,7 +92,7 @@ function evaluateDefinition(graph, variable, value, modeFor, visiting, memo, ove
81
92
  visiting.add(variableId);
82
93
  try {
83
94
  const result = resolveVariableValue(value, (id) => resolveVariableInModes(graph, id, modeFor, visiting, memo, overrides));
84
- if (result === void 0 || typeof result !== RESULT_TYPES[variable.type]) throw new VariableResolutionError("type", variableId, `Wrong result type: ${variable.name}`);
95
+ if (result === void 0 || !fitsType(result, variable.type)) throw new VariableResolutionError("type", variableId, `Wrong result type: ${variable.name}`);
85
96
  if (typeof result === "number" && !Number.isFinite(result)) throw new VariableResolutionError("non-finite", variableId, `Non-finite value: ${variable.name}`);
86
97
  memo?.set(variableId, result);
87
98
  return result;
@@ -121,8 +132,7 @@ function resolveExpression(graph, variable, value, modeFor, visiting, memo) {
121
132
  }
122
133
  /** A resolved value the canvas can draw for a variable of this type, or nothing. */
123
134
  function drawable(value, type) {
124
- if (value === void 0 || typeof value !== RESULT_TYPES[type]) return void 0;
125
- if (typeof value === "object" && !("r" in value)) return void 0;
135
+ if (value === void 0 || !fitsType(value, type)) return void 0;
126
136
  return typeof value === "number" && !Number.isFinite(value) ? void 0 : value;
127
137
  }
128
138
  /** Shared mode fallback for canvas resolution and formula draft validation. */
@@ -172,7 +182,6 @@ function resolveStringVariableForNode(graph, nodeId, variableId) {
172
182
  const value = resolveVariableForNode(graph, nodeId, variableId);
173
183
  return typeof value === "string" ? value : void 0;
174
184
  }
175
- //#endregion
176
- export { VariableResolutionError, collectionsResolving, createBatchVariableResolver, getNodeExplicitVariableModeId, getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, variableValueInMode };
185
+ export { VariableResolutionError, collectionHoldsMode, collectionsResolving, createBatchVariableResolver, getNodeExplicitVariableModeId, getNodeVariableModeId, resolveColorVariable, resolveColorVariableForNode, resolveNumberVariable, resolveNumberVariableForNode, resolveStringVariableForNode, resolveVariable, resolveVariableForNode, resolveVariableInModes, variableValueInMode };
177
186
 
178
187
  //# sourceMappingURL=resolution.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"resolution.js","names":[],"sources":["../../src/variables/resolution.ts"],"sourcesContent":["import { appendAll } from '@open-pencil/std/arrays'\n\nimport type { SceneGraph } from '../graph'\nimport type { Color } from '../primitives'\nimport type { Variable, VariableLiteral, VariableValue } from '../types'\nimport { MAX_FORMULA_DEPTH, VariableFormulaError } from './formula/tree'\nimport { resolveVariableValue, variableValueReferences } from './value'\n\nfunction defaultModeId(graph: SceneGraph, collectionId: string): string {\n return graph.variableCollections.get(collectionId)?.defaultModeId ?? ''\n}\n\n/**\n * The mode a node is in for a collection: the nearest explicit mode on it or an ancestor (the page\n * included), else the collection's default, as Figma resolves it.\n */\nexport function getNodeVariableModeId(\n graph: SceneGraph,\n nodeId: string,\n collectionId: string\n): string {\n return (\n getNodeExplicitVariableModeId(graph, nodeId, collectionId) ?? defaultModeId(graph, collectionId)\n )\n}\n\n/** The nearest mode set on a node or an ancestor for a collection, or null where none is. */\nexport function getNodeExplicitVariableModeId(\n graph: SceneGraph,\n nodeId: string,\n collectionId: string\n): string | null {\n let node = graph.nodes.get(nodeId)\n while (node) {\n const modeId = node.variableModes[collectionId]\n if (modeId) return modeId\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return null\n}\n\n/**\n * The collections whose modes decide what these variables resolve to: their own, and those of the\n * variables they alias, at any depth and in any mode.\n */\nexport function collectionsResolving(\n graph: SceneGraph,\n variableIds: Iterable<string>\n): Set<string> {\n const pending = [...variableIds]\n const seen = new Set<string>()\n const collections = new Set<string>()\n for (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n if (seen.has(id)) continue\n seen.add(id)\n const variable = graph.variables.get(id)\n if (!variable) continue\n collections.add(variable.collectionId)\n for (const value of Object.values(variable.valuesByMode))\n appendAll(pending, variableValueReferences(value))\n }\n return collections\n}\n\nexport function resolveVariable(\n graph: SceneGraph,\n variableId: string,\n modeId?: string,\n visited?: Set<string>\n): VariableLiteral | undefined {\n const initial = graph.variables.get(variableId)\n return resolveInModes(\n graph,\n variableId,\n (collectionId) =>\n modeId && initial?.collectionId === collectionId\n ? modeId\n : defaultModeId(graph, collectionId),\n visited\n )\n}\n\nexport class VariableResolutionError extends VariableFormulaError {\n override name = 'VariableResolutionError'\n constructor(\n readonly code: 'cycle' | 'depth' | 'missing-variable' | 'missing-value' | 'type' | 'non-finite',\n readonly variableId: string,\n message: string\n ) {\n super(message)\n }\n}\n\nconst RESULT_TYPES = { FLOAT: 'number', BOOLEAN: 'boolean', STRING: 'string', COLOR: 'object' }\n\n/**\n * Resolve a draft or saved definition with identical mode, dependency and error semantics. A\n * memo shares values between lookups in one mode context; without one, nothing is cached.\n */\nexport function resolveVariableInModes(\n graph: SceneGraph,\n variableId: string,\n modeFor: (collectionId: string) => string,\n visiting = new Set<string>(),\n memo?: Map<string, VariableLiteral>,\n overrides?: ReadonlyMap<string, VariableValue>\n): VariableLiteral {\n const cached = memo?.get(variableId)\n if (cached !== undefined) return cached\n if (visiting.has(variableId))\n throw new VariableResolutionError('cycle', variableId, 'Circular variable reference')\n if (visiting.size >= MAX_FORMULA_DEPTH)\n throw new VariableResolutionError('depth', variableId, 'Too many linked variables')\n const variable = graph.variables.get(variableId)\n if (!variable)\n throw new VariableResolutionError(\n 'missing-variable',\n variableId,\n `Missing variable: ${variableId}`\n )\n const value =\n overrides?.get(variableId) ??\n variableValueInMode(graph, variable, modeFor(variable.collectionId))\n if (value === undefined)\n throw new VariableResolutionError(\n 'missing-value',\n variableId,\n `Missing value: ${variable.name}`\n )\n return evaluateDefinition(graph, variable, value, modeFor, visiting, memo, overrides)\n}\n\n/** Resolve one variable's definition in its mode context, its dependencies in theirs. */\nfunction evaluateDefinition(\n graph: SceneGraph,\n variable: Variable,\n value: VariableValue,\n modeFor: (collectionId: string) => string,\n visiting: Set<string>,\n memo?: Map<string, VariableLiteral>,\n overrides?: ReadonlyMap<string, VariableValue>\n): VariableLiteral {\n const variableId = variable.id\n visiting.add(variableId)\n try {\n const result = resolveVariableValue(value, (id) =>\n resolveVariableInModes(graph, id, modeFor, visiting, memo, overrides)\n )\n if (result === undefined || typeof result !== RESULT_TYPES[variable.type])\n throw new VariableResolutionError('type', variableId, `Wrong result type: ${variable.name}`)\n if (typeof result === 'number' && !Number.isFinite(result))\n throw new VariableResolutionError(\n 'non-finite',\n variableId,\n `Non-finite value: ${variable.name}`\n )\n // Failures can depend on the current path's depth. Only completed values are reusable.\n memo?.set(variableId, result)\n return result\n } finally {\n visiting.delete(variableId)\n }\n}\n\n/**\n * What the canvas draws for a variable, or nothing when it cannot be resolved. Literals and alias\n * chains, which most bindings are, resolve in a loop; an expression on the way takes the full\n * resolver, whose diagnostics the canvas does not need.\n */\nfunction resolveInModes(\n graph: SceneGraph,\n variableId: string,\n modeFor: (collectionId: string) => string,\n visiting?: Set<string>,\n memo?: Map<string, VariableLiteral>\n): VariableLiteral | undefined {\n const cached = memo?.get(variableId)\n if (cached !== undefined) return cached\n const initial = graph.variables.get(variableId)\n if (!initial) return undefined\n let id = variableId\n for (let depth = visiting?.size ?? 0; depth < MAX_FORMULA_DEPTH; depth++) {\n const variable = id === variableId ? initial : graph.variables.get(id)\n if (!variable || visiting?.has(id)) return undefined\n const value = variableValueInMode(graph, variable, modeFor(variable.collectionId))\n if (typeof value === 'object' && 'aliasId' in value) {\n id = value.aliasId\n continue\n }\n const result =\n typeof value === 'object' && 'expression' in value\n ? resolveExpression(graph, variable, value, modeFor, visiting, memo)\n : value\n return drawable(result, initial.type)\n }\n return undefined\n}\n\n/** A formula shares its dependencies' values for the length of one resolution. */\nfunction resolveExpression(\n graph: SceneGraph,\n variable: Variable,\n value: VariableValue,\n modeFor: (collectionId: string) => string,\n visiting?: Set<string>,\n memo?: Map<string, VariableLiteral>\n): VariableLiteral | undefined {\n try {\n return evaluateDefinition(\n graph,\n variable,\n value,\n modeFor,\n visiting ?? new Set(),\n memo ?? new Map()\n )\n } catch {\n return undefined\n }\n}\n\n/** A resolved value the canvas can draw for a variable of this type, or nothing. */\nfunction drawable(value: VariableValue | undefined, type: Variable['type']) {\n if (value === undefined || typeof value !== RESULT_TYPES[type]) return undefined\n if (typeof value === 'object' && !('r' in value)) return undefined\n return typeof value === 'number' && !Number.isFinite(value) ? undefined : value\n}\n\n/** Shared mode fallback for canvas resolution and formula draft validation. */\nexport function variableValueInMode(\n graph: SceneGraph,\n variable: Variable,\n modeId: string\n): VariableValue | undefined {\n const values = variable.valuesByMode\n if (Object.hasOwn(values, modeId)) return values[modeId]\n const defaultMode = graph.variableCollections.get(variable.collectionId)?.defaultModeId ?? ''\n if (Object.hasOwn(values, defaultMode)) return values[defaultMode]\n return Object.values(values).at(0)\n}\n\nexport type NodeVariableResolver = (\n nodeId: string,\n variableId: string\n) => VariableLiteral | undefined\n\n/** One read/reconcile operation only: equal mode contexts share results, edits start a new cache. */\nexport function createBatchVariableResolver(graph: SceneGraph): NodeVariableResolver {\n const collections = [...graph.variableCollections.keys()]\n const contexts = new Map<string, Map<string, VariableLiteral>>()\n return (nodeId, variableId) => {\n const modes = collections.map((id) => getNodeVariableModeId(graph, nodeId, id))\n const key = JSON.stringify(modes)\n let memo = contexts.get(key)\n if (!memo) {\n memo = new Map()\n contexts.set(key, memo)\n }\n return resolveInModes(\n graph,\n variableId,\n (id) => modes[collections.indexOf(id)] ?? '',\n undefined,\n memo\n )\n }\n}\n\nexport function resolveColorVariable(graph: SceneGraph, variableId: string): Color | undefined {\n const value = resolveVariable(graph, variableId)\n if (value && typeof value === 'object' && 'r' in value) return value\n return undefined\n}\n\nexport function resolveNumberVariable(graph: SceneGraph, variableId: string): number | undefined {\n const value = resolveVariable(graph, variableId)\n return typeof value === 'number' ? value : undefined\n}\n\nexport function resolveColorVariableForNode(\n graph: SceneGraph,\n nodeId: string,\n variableId: string\n): Color | undefined {\n const value = resolveVariableForNode(graph, nodeId, variableId)\n if (value && typeof value === 'object' && 'r' in value) return value\n return undefined\n}\n\nexport function resolveNumberVariableForNode(\n graph: SceneGraph,\n nodeId: string,\n variableId: string\n): number | undefined {\n const value = resolveVariableForNode(graph, nodeId, variableId)\n return typeof value === 'number' ? value : undefined\n}\n\n/** A variable's value in the mode a node is in, aliases followed. */\nexport function resolveVariableForNode(\n graph: SceneGraph,\n nodeId: string,\n variableId: string\n): VariableLiteral | undefined {\n return resolveInModes(graph, variableId, (collectionId) =>\n getNodeVariableModeId(graph, nodeId, collectionId)\n )\n}\n\nexport function resolveStringVariableForNode(\n graph: SceneGraph,\n nodeId: string,\n variableId: string\n): string | undefined {\n const value = resolveVariableForNode(graph, nodeId, variableId)\n return typeof value === 'string' ? value : undefined\n}\n"],"mappings":";;;;AAQA,SAAS,cAAc,OAAmB,cAA8B;CACtE,OAAO,MAAM,oBAAoB,IAAI,YAAY,CAAC,EAAE,iBAAiB;AACvE;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AAgB,6BACd,OACA,QACA,YACoB;CACpB,MAAM,QAAQ,uBAAuB,OAAO,QAAQ,UAAU;CAC9D,OAAO,OAAO,UAAU,WAAW,QAAQ,KAAA;AAC7C"}
1
+ {"version":3,"file":"resolution.js","names":[],"sources":["../../src/variables/resolution.ts"],"sourcesContent":["import { appendAll } from '@open-pencil/std/arrays'\n\nimport type { SceneGraph } from '../graph'\nimport type { Color } from '../primitives'\nimport type { Variable, VariableLiteral, VariableType, VariableValue } from '../types'\nimport { MAX_FORMULA_DEPTH, VariableFormulaError } from './formula/tree'\nimport { resolveVariableValue, variableValueReferences } from './value'\n\nfunction defaultModeId(graph: SceneGraph, collectionId: string): string {\n return graph.variableCollections.get(collectionId)?.defaultModeId ?? ''\n}\n\n/**\n * The mode a node is in for a collection: the nearest explicit mode on it or an ancestor (the page\n * included), else the collection's default, as Figma resolves it.\n */\nexport function getNodeVariableModeId(\n graph: SceneGraph,\n nodeId: string,\n collectionId: string\n): string {\n return (\n getNodeExplicitVariableModeId(graph, nodeId, collectionId) ?? defaultModeId(graph, collectionId)\n )\n}\n\n/**\n * Whether a mode set for a collection still picks one of its modes. A layer keeps a mode its\n * collection removed, as Figma keeps it, and resolves as if none were set (live-verified); a\n * collection the document does not hold, such as an unloaded library's, keeps every mode.\n */\nexport function collectionHoldsMode(\n graph: SceneGraph,\n collectionId: string,\n modeId: string\n): boolean {\n const collection = graph.variableCollections.get(collectionId)\n return !collection || collection.modes.some((mode) => mode.modeId === modeId)\n}\n\n/** The nearest mode set on a node or an ancestor for a collection, or null where none is. */\nexport function getNodeExplicitVariableModeId(\n graph: SceneGraph,\n nodeId: string,\n collectionId: string\n): string | null {\n let node = graph.nodes.get(nodeId)\n while (node) {\n const modeId = node.variableModes[collectionId]\n if (modeId && collectionHoldsMode(graph, collectionId, modeId)) return modeId\n node = node.parentId ? graph.nodes.get(node.parentId) : undefined\n }\n return null\n}\n\n/**\n * The collections whose modes decide what these variables resolve to: their own, and those of the\n * variables they alias, at any depth and in any mode.\n */\nexport function collectionsResolving(\n graph: SceneGraph,\n variableIds: Iterable<string>\n): Set<string> {\n const pending = [...variableIds]\n const seen = new Set<string>()\n const collections = new Set<string>()\n for (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n if (seen.has(id)) continue\n seen.add(id)\n const variable = graph.variables.get(id)\n if (!variable) continue\n collections.add(variable.collectionId)\n for (const value of Object.values(variable.valuesByMode))\n appendAll(pending, variableValueReferences(value))\n }\n return collections\n}\n\nexport function resolveVariable(\n graph: SceneGraph,\n variableId: string,\n modeId?: string,\n visited?: Set<string>\n): VariableLiteral | undefined {\n const initial = graph.variables.get(variableId)\n return resolveInModes(\n graph,\n variableId,\n (collectionId) =>\n modeId && initial?.collectionId === collectionId\n ? modeId\n : defaultModeId(graph, collectionId),\n visited\n )\n}\n\nexport class VariableResolutionError extends VariableFormulaError {\n override name = 'VariableResolutionError'\n constructor(\n readonly code: 'cycle' | 'depth' | 'missing-variable' | 'missing-value' | 'type' | 'non-finite',\n readonly variableId: string,\n message: string\n ) {\n super(message)\n }\n}\n\n/** Whether a resolved value is one a variable of this type gives. */\nfunction fitsType(value: VariableValue, type: VariableType): value is VariableLiteral {\n if (type === 'COLOR') return typeof value === 'object' && 'r' in value\n if (type === 'EASING') return typeof value === 'object' && 'easing' in value\n if (type === 'BOOLEAN') return typeof value === 'boolean'\n if (type === 'STRING') return typeof value === 'string'\n return typeof value === 'number'\n}\n\n/**\n * Resolve a draft or saved definition with identical mode, dependency and error semantics. A\n * memo shares values between lookups in one mode context; without one, nothing is cached.\n */\nexport function resolveVariableInModes(\n graph: SceneGraph,\n variableId: string,\n modeFor: (collectionId: string) => string,\n visiting = new Set<string>(),\n memo?: Map<string, VariableLiteral>,\n overrides?: ReadonlyMap<string, VariableValue>\n): VariableLiteral {\n const cached = memo?.get(variableId)\n if (cached !== undefined) return cached\n if (visiting.has(variableId))\n throw new VariableResolutionError('cycle', variableId, 'Circular variable reference')\n if (visiting.size >= MAX_FORMULA_DEPTH)\n throw new VariableResolutionError('depth', variableId, 'Too many linked variables')\n const variable = graph.variables.get(variableId)\n if (!variable)\n throw new VariableResolutionError(\n 'missing-variable',\n variableId,\n `Missing variable: ${variableId}`\n )\n const value =\n overrides?.get(variableId) ??\n variableValueInMode(graph, variable, modeFor(variable.collectionId))\n if (value === undefined)\n throw new VariableResolutionError(\n 'missing-value',\n variableId,\n `Missing value: ${variable.name}`\n )\n return evaluateDefinition(graph, variable, value, modeFor, visiting, memo, overrides)\n}\n\n/** Resolve one variable's definition in its mode context, its dependencies in theirs. */\nfunction evaluateDefinition(\n graph: SceneGraph,\n variable: Variable,\n value: VariableValue,\n modeFor: (collectionId: string) => string,\n visiting: Set<string>,\n memo?: Map<string, VariableLiteral>,\n overrides?: ReadonlyMap<string, VariableValue>\n): VariableLiteral {\n const variableId = variable.id\n visiting.add(variableId)\n try {\n const result = resolveVariableValue(value, (id) =>\n resolveVariableInModes(graph, id, modeFor, visiting, memo, overrides)\n )\n if (result === undefined || !fitsType(result, variable.type))\n throw new VariableResolutionError('type', variableId, `Wrong result type: ${variable.name}`)\n if (typeof result === 'number' && !Number.isFinite(result))\n throw new VariableResolutionError(\n 'non-finite',\n variableId,\n `Non-finite value: ${variable.name}`\n )\n // Failures can depend on the current path's depth. Only completed values are reusable.\n memo?.set(variableId, result)\n return result\n } finally {\n visiting.delete(variableId)\n }\n}\n\n/**\n * What the canvas draws for a variable, or nothing when it cannot be resolved. Literals and alias\n * chains, which most bindings are, resolve in a loop; an expression on the way takes the full\n * resolver, whose diagnostics the canvas does not need.\n */\nfunction resolveInModes(\n graph: SceneGraph,\n variableId: string,\n modeFor: (collectionId: string) => string,\n visiting?: Set<string>,\n memo?: Map<string, VariableLiteral>\n): VariableLiteral | undefined {\n const cached = memo?.get(variableId)\n if (cached !== undefined) return cached\n const initial = graph.variables.get(variableId)\n if (!initial) return undefined\n let id = variableId\n for (let depth = visiting?.size ?? 0; depth < MAX_FORMULA_DEPTH; depth++) {\n const variable = id === variableId ? initial : graph.variables.get(id)\n if (!variable || visiting?.has(id)) return undefined\n const value = variableValueInMode(graph, variable, modeFor(variable.collectionId))\n if (typeof value === 'object' && 'aliasId' in value) {\n id = value.aliasId\n continue\n }\n const result =\n typeof value === 'object' && 'expression' in value\n ? resolveExpression(graph, variable, value, modeFor, visiting, memo)\n : value\n return drawable(result, initial.type)\n }\n return undefined\n}\n\n/** A formula shares its dependencies' values for the length of one resolution. */\nfunction resolveExpression(\n graph: SceneGraph,\n variable: Variable,\n value: VariableValue,\n modeFor: (collectionId: string) => string,\n visiting?: Set<string>,\n memo?: Map<string, VariableLiteral>\n): VariableLiteral | undefined {\n try {\n return evaluateDefinition(\n graph,\n variable,\n value,\n modeFor,\n visiting ?? new Set(),\n memo ?? new Map()\n )\n } catch {\n return undefined\n }\n}\n\n/** A resolved value the canvas can draw for a variable of this type, or nothing. */\nfunction drawable(value: VariableValue | undefined, type: Variable['type']) {\n if (value === undefined || !fitsType(value, type)) return undefined\n return typeof value === 'number' && !Number.isFinite(value) ? undefined : value\n}\n\n/** Shared mode fallback for canvas resolution and formula draft validation. */\nexport function variableValueInMode(\n graph: SceneGraph,\n variable: Variable,\n modeId: string\n): VariableValue | undefined {\n const values = variable.valuesByMode\n if (Object.hasOwn(values, modeId)) return values[modeId]\n const defaultMode = graph.variableCollections.get(variable.collectionId)?.defaultModeId ?? ''\n if (Object.hasOwn(values, defaultMode)) return values[defaultMode]\n return Object.values(values).at(0)\n}\n\nexport type NodeVariableResolver = (\n nodeId: string,\n variableId: string\n) => VariableLiteral | undefined\n\n/** One read/reconcile operation only: equal mode contexts share results, edits start a new cache. */\nexport function createBatchVariableResolver(graph: SceneGraph): NodeVariableResolver {\n const collections = [...graph.variableCollections.keys()]\n const contexts = new Map<string, Map<string, VariableLiteral>>()\n return (nodeId, variableId) => {\n const modes = collections.map((id) => getNodeVariableModeId(graph, nodeId, id))\n const key = JSON.stringify(modes)\n let memo = contexts.get(key)\n if (!memo) {\n memo = new Map()\n contexts.set(key, memo)\n }\n return resolveInModes(\n graph,\n variableId,\n (id) => modes[collections.indexOf(id)] ?? '',\n undefined,\n memo\n )\n }\n}\n\nexport function resolveColorVariable(graph: SceneGraph, variableId: string): Color | undefined {\n const value = resolveVariable(graph, variableId)\n if (value && typeof value === 'object' && 'r' in value) return value\n return undefined\n}\n\nexport function resolveNumberVariable(graph: SceneGraph, variableId: string): number | undefined {\n const value = resolveVariable(graph, variableId)\n return typeof value === 'number' ? value : undefined\n}\n\nexport function resolveColorVariableForNode(\n graph: SceneGraph,\n nodeId: string,\n variableId: string\n): Color | undefined {\n const value = resolveVariableForNode(graph, nodeId, variableId)\n if (value && typeof value === 'object' && 'r' in value) return value\n return undefined\n}\n\nexport function resolveNumberVariableForNode(\n graph: SceneGraph,\n nodeId: string,\n variableId: string\n): number | undefined {\n const value = resolveVariableForNode(graph, nodeId, variableId)\n return typeof value === 'number' ? value : undefined\n}\n\n/** A variable's value in the mode a node is in, aliases followed. */\nexport function resolveVariableForNode(\n graph: SceneGraph,\n nodeId: string,\n variableId: string\n): VariableLiteral | undefined {\n return resolveInModes(graph, variableId, (collectionId) =>\n getNodeVariableModeId(graph, nodeId, collectionId)\n )\n}\n\nexport function resolveStringVariableForNode(\n graph: SceneGraph,\n nodeId: string,\n variableId: string\n): string | undefined {\n const value = resolveVariableForNode(graph, nodeId, variableId)\n return typeof value === 'string' ? value : undefined\n}\n"],"mappings":";;;;AAQA,SAAS,cAAc,OAAmB,cAA8B;CACtE,OAAO,MAAM,oBAAoB,IAAI,YAAY,CAAC,EAAE,iBAAiB;AACvE;;;;;AAMA,SAAgB,sBACd,OACA,QACA,cACQ;CACR,OACE,8BAA8B,OAAO,QAAQ,YAAY,KAAK,cAAc,OAAO,YAAY;AAEnG;;;;;;AAOA,SAAgB,oBACd,OACA,cACA,QACS;CACT,MAAM,aAAa,MAAM,oBAAoB,IAAI,YAAY;CAC7D,OAAO,CAAC,cAAc,WAAW,MAAM,MAAM,SAAS,KAAK,WAAW,MA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