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

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 (423) hide show
  1. package/dist/behaviours/index.d.ts +3 -2
  2. package/dist/behaviours/index.js +2 -1
  3. package/dist/behaviours/kinds.d.ts.map +1 -1
  4. package/dist/behaviours/kinds.js +15 -8
  5. package/dist/behaviours/kinds.js.map +1 -1
  6. package/dist/behaviours/model.d.ts +2 -2
  7. package/dist/behaviours/model.d.ts.map +1 -1
  8. package/dist/behaviours/model.js.map +1 -1
  9. package/dist/behaviours/schema.d.ts +136 -1
  10. package/dist/behaviours/schema.d.ts.map +1 -1
  11. package/dist/behaviours/schema.js +17 -2
  12. package/dist/behaviours/schema.js.map +1 -1
  13. package/dist/behaviours/spec.d.ts.map +1 -1
  14. package/dist/behaviours/spec.js +4 -0
  15. package/dist/behaviours/spec.js.map +1 -1
  16. package/dist/behaviours/transition.d.ts +23 -0
  17. package/dist/behaviours/transition.d.ts.map +1 -0
  18. package/dist/behaviours/transition.js +36 -0
  19. package/dist/behaviours/transition.js.map +1 -0
  20. package/dist/checkpoint.d.ts.map +1 -1
  21. package/dist/checkpoint.js +2 -0
  22. package/dist/checkpoint.js.map +1 -1
  23. package/dist/color/index.d.ts +12 -9
  24. package/dist/color/index.d.ts.map +1 -1
  25. package/dist/color/index.js +15 -25
  26. package/dist/color/index.js.map +1 -1
  27. package/dist/color/management.d.ts +51 -23
  28. package/dist/color/management.d.ts.map +1 -1
  29. package/dist/color/management.js +154 -149
  30. package/dist/color/management.js.map +1 -1
  31. package/dist/color/okhcl.d.ts +28 -10
  32. package/dist/color/okhcl.d.ts.map +1 -1
  33. package/dist/color/okhcl.js +56 -40
  34. package/dist/color/okhcl.js.map +1 -1
  35. package/dist/color/schema.d.ts +6 -1
  36. package/dist/color/schema.d.ts.map +1 -1
  37. package/dist/color/schema.js +10 -1
  38. package/dist/color/schema.js.map +1 -1
  39. package/dist/constraints.d.ts.map +1 -1
  40. package/dist/constraints.js +2 -1
  41. package/dist/constraints.js.map +1 -1
  42. package/dist/copy.d.ts +7 -1
  43. package/dist/copy.d.ts.map +1 -1
  44. package/dist/copy.js +22 -1
  45. package/dist/copy.js.map +1 -1
  46. package/dist/corners.d.ts +3 -1
  47. package/dist/corners.d.ts.map +1 -1
  48. package/dist/corners.js +3 -1
  49. package/dist/corners.js.map +1 -1
  50. package/dist/css/grid.js +1 -1
  51. package/dist/css/index.d.ts +2 -1
  52. package/dist/css/index.js +3 -2
  53. package/dist/css/motion.d.ts +12 -0
  54. package/dist/css/motion.d.ts.map +1 -0
  55. package/dist/css/motion.js +60 -0
  56. package/dist/css/motion.js.map +1 -0
  57. package/dist/css/shadows.d.ts +4 -3
  58. package/dist/css/shadows.d.ts.map +1 -1
  59. package/dist/css/shadows.js +7 -6
  60. package/dist/css/shadows.js.map +1 -1
  61. package/dist/css/values.d.ts +3 -2
  62. package/dist/css/values.d.ts.map +1 -1
  63. package/dist/css/values.js +4 -4
  64. package/dist/css/values.js.map +1 -1
  65. package/dist/fields/index.d.ts +2 -2
  66. package/dist/fields/index.js +2 -2
  67. package/dist/fields/layout.d.ts +3 -1
  68. package/dist/fields/layout.d.ts.map +1 -1
  69. package/dist/fields/layout.js +9 -1
  70. package/dist/fields/layout.js.map +1 -1
  71. package/dist/figjam/palette.js +1 -1
  72. package/dist/font-style.d.ts.map +1 -1
  73. package/dist/font-style.js +7 -3
  74. package/dist/font-style.js.map +1 -1
  75. package/dist/generated/index.d.ts +6 -2
  76. package/dist/generated/index.d.ts.map +1 -1
  77. package/dist/generated/index.js +14 -4
  78. package/dist/generated/index.js.map +1 -1
  79. package/dist/geometry.d.ts +6 -1
  80. package/dist/geometry.d.ts.map +1 -1
  81. package/dist/geometry.js +10 -2
  82. package/dist/geometry.js.map +1 -1
  83. package/dist/graph.d.ts +29 -4
  84. package/dist/graph.d.ts.map +1 -1
  85. package/dist/graph.js +59 -9
  86. package/dist/graph.js.map +1 -1
  87. package/dist/group-bounds.d.ts +5 -2
  88. package/dist/group-bounds.d.ts.map +1 -1
  89. package/dist/group-bounds.js +38 -8
  90. package/dist/group-bounds.js.map +1 -1
  91. package/dist/hit-test.d.ts.map +1 -1
  92. package/dist/hit-test.js +19 -8
  93. package/dist/hit-test.js.map +1 -1
  94. package/dist/index.d.ts +2 -2
  95. package/dist/index.js +2 -2
  96. package/dist/instances/content-size.js +1 -1
  97. package/dist/instances/fields.d.ts +2 -2
  98. package/dist/instances/fields.d.ts.map +1 -1
  99. package/dist/instances/fields.js +2 -0
  100. package/dist/instances/fields.js.map +1 -1
  101. package/dist/instances/index.d.ts.map +1 -1
  102. package/dist/instances/index.js +50 -11
  103. package/dist/instances/index.js.map +1 -1
  104. package/dist/instances/sync.js +67 -7
  105. package/dist/instances/sync.js.map +1 -1
  106. package/dist/layout/flow.d.ts +16 -0
  107. package/dist/layout/flow.d.ts.map +1 -0
  108. package/dist/layout/flow.js +34 -0
  109. package/dist/layout/flow.js.map +1 -0
  110. package/dist/layout/index.d.ts +4 -3
  111. package/dist/layout/index.js +4 -3
  112. package/dist/layout/keywords.d.ts.map +1 -1
  113. package/dist/layout/keywords.js +7 -1
  114. package/dist/layout/keywords.js.map +1 -1
  115. package/dist/layout/sizing.d.ts +9 -1
  116. package/dist/layout/sizing.d.ts.map +1 -1
  117. package/dist/layout/sizing.js +17 -1
  118. package/dist/layout/sizing.js.map +1 -1
  119. package/dist/layout/spacing.d.ts +7 -1
  120. package/dist/layout/spacing.d.ts.map +1 -1
  121. package/dist/layout/spacing.js +10 -1
  122. package/dist/layout/spacing.js.map +1 -1
  123. package/dist/mesh/geometry.d.ts +83 -0
  124. package/dist/mesh/geometry.d.ts.map +1 -0
  125. package/dist/mesh/geometry.js +441 -0
  126. package/dist/mesh/geometry.js.map +1 -0
  127. package/dist/mesh/index.d.ts +4 -0
  128. package/dist/mesh/index.js +4 -0
  129. package/dist/mesh/model.d.ts +28 -0
  130. package/dist/mesh/model.d.ts.map +1 -0
  131. package/dist/mesh/model.js +40 -0
  132. package/dist/mesh/model.js.map +1 -0
  133. package/dist/mesh/schema.d.ts +191 -0
  134. package/dist/mesh/schema.d.ts.map +1 -0
  135. package/dist/mesh/schema.js +56 -0
  136. package/dist/mesh/schema.js.map +1 -0
  137. package/dist/mutation-impact.d.ts +2 -0
  138. package/dist/mutation-impact.d.ts.map +1 -1
  139. package/dist/mutation-impact.js +18 -7
  140. package/dist/mutation-impact.js.map +1 -1
  141. package/dist/node-defaults.d.ts +3 -1
  142. package/dist/node-defaults.d.ts.map +1 -1
  143. package/dist/node-defaults.js +22 -6
  144. package/dist/node-defaults.js.map +1 -1
  145. package/dist/paints/index.d.ts +5 -3
  146. package/dist/paints/index.js +5 -3
  147. package/dist/paints/pattern.d.ts +5 -1
  148. package/dist/paints/pattern.d.ts.map +1 -1
  149. package/dist/paints/pattern.js +33 -1
  150. package/dist/paints/pattern.js.map +1 -1
  151. package/dist/paints/shows.d.ts +4 -1
  152. package/dist/paints/shows.d.ts.map +1 -1
  153. package/dist/paints/shows.js +8 -1
  154. package/dist/paints/shows.js.map +1 -1
  155. package/dist/paints/solid.d.ts +11 -0
  156. package/dist/paints/solid.d.ts.map +1 -0
  157. package/dist/paints/solid.js +18 -0
  158. package/dist/paints/solid.js.map +1 -0
  159. package/dist/paints/stills.d.ts +74 -0
  160. package/dist/paints/stills.d.ts.map +1 -0
  161. package/dist/paints/stills.js +113 -0
  162. package/dist/paints/stills.js.map +1 -0
  163. package/dist/plugin-data/field.d.ts.map +1 -1
  164. package/dist/plugin-data/field.js +2 -0
  165. package/dist/plugin-data/field.js.map +1 -1
  166. package/dist/plugin-data/fields.d.ts +67 -0
  167. package/dist/plugin-data/fields.d.ts.map +1 -1
  168. package/dist/plugin-data/fields.js +12 -7
  169. package/dist/plugin-data/fields.js.map +1 -1
  170. package/dist/resize.d.ts +10 -3
  171. package/dist/resize.d.ts.map +1 -1
  172. package/dist/resize.js +34 -3
  173. package/dist/resize.js.map +1 -1
  174. package/dist/scaling/index.d.ts +2 -2
  175. package/dist/scaling/index.js +2 -2
  176. package/dist/scaling/node.d.ts +2 -1
  177. package/dist/scaling/node.d.ts.map +1 -1
  178. package/dist/scaling/node.js +27 -7
  179. package/dist/scaling/node.js.map +1 -1
  180. package/dist/shaders/index.d.ts +2 -3
  181. package/dist/shaders/index.js +2 -3
  182. package/dist/shaders/model.d.ts +3 -11
  183. package/dist/shaders/model.d.ts.map +1 -1
  184. package/dist/shaders/model.js +13 -36
  185. package/dist/shaders/model.js.map +1 -1
  186. package/dist/shaders/schema.d.ts +1 -1
  187. package/dist/shaders/schema.js +1 -1
  188. package/dist/shaders/schema.js.map +1 -1
  189. package/dist/shape-with-text/document.js +276 -0
  190. package/dist/shape-with-text/document.js.map +1 -0
  191. package/dist/shape-with-text/geometry.d.ts +13 -1
  192. package/dist/shape-with-text/geometry.d.ts.map +1 -1
  193. package/dist/shape-with-text/geometry.js +103 -41
  194. package/dist/shape-with-text/geometry.js.map +1 -1
  195. package/dist/shape-with-text/index.d.ts +2 -2
  196. package/dist/shape-with-text/index.js +2 -2
  197. package/dist/shared-style-index.d.ts +21 -0
  198. package/dist/shared-style-index.d.ts.map +1 -0
  199. package/dist/shared-style-index.js +72 -0
  200. package/dist/shared-style-index.js.map +1 -0
  201. package/dist/shared-styles.d.ts +3 -3
  202. package/dist/shared-styles.d.ts.map +1 -1
  203. package/dist/shared-styles.js +16 -7
  204. package/dist/shared-styles.js.map +1 -1
  205. package/dist/slides/drop.d.ts +32 -0
  206. package/dist/slides/drop.d.ts.map +1 -0
  207. package/dist/slides/drop.js +81 -0
  208. package/dist/slides/drop.js.map +1 -0
  209. package/dist/slides/index.d.ts +56 -0
  210. package/dist/slides/index.d.ts.map +1 -0
  211. package/dist/slides/index.js +134 -0
  212. package/dist/slides/index.js.map +1 -0
  213. package/dist/slides/motion.d.ts +55 -0
  214. package/dist/slides/motion.d.ts.map +1 -0
  215. package/dist/slides/motion.js +142 -0
  216. package/dist/slides/motion.js.map +1 -0
  217. package/dist/slides/playback.d.ts +59 -0
  218. package/dist/slides/playback.d.ts.map +1 -0
  219. package/dist/slides/playback.js +188 -0
  220. package/dist/slides/playback.js.map +1 -0
  221. package/dist/slides/types.d.ts +62 -0
  222. package/dist/slides/types.d.ts.map +1 -0
  223. package/dist/slides/types.js +39 -0
  224. package/dist/slides/types.js.map +1 -0
  225. package/dist/statuses/workflow.js +1 -1
  226. package/dist/text/direction.d.ts +6 -3
  227. package/dist/text/direction.d.ts.map +1 -1
  228. package/dist/text/direction.js +12 -12
  229. package/dist/text/direction.js.map +1 -1
  230. package/dist/text/index.d.ts +2 -1
  231. package/dist/text/index.js +3 -2
  232. package/dist/text/name.d.ts +22 -0
  233. package/dist/text/name.d.ts.map +1 -0
  234. package/dist/text/name.js +38 -0
  235. package/dist/text/name.js.map +1 -0
  236. package/dist/text/references.d.ts.map +1 -1
  237. package/dist/text/references.js +1 -2
  238. package/dist/text/references.js.map +1 -1
  239. package/dist/thumbnail.d.ts +23 -0
  240. package/dist/thumbnail.d.ts.map +1 -0
  241. package/dist/thumbnail.js +47 -0
  242. package/dist/thumbnail.js.map +1 -0
  243. package/dist/transfer/apply.d.ts.map +1 -1
  244. package/dist/transfer/apply.js +14 -3
  245. package/dist/transfer/apply.js.map +1 -1
  246. package/dist/transfer/copied.d.ts +6 -1
  247. package/dist/transfer/copied.d.ts.map +1 -1
  248. package/dist/transfer/copied.js +2 -2
  249. package/dist/transfer/copied.js.map +1 -1
  250. package/dist/transfer/dependencies.d.ts +4 -1
  251. package/dist/transfer/dependencies.d.ts.map +1 -1
  252. package/dist/transfer/dependencies.js +10 -1
  253. package/dist/transfer/dependencies.js.map +1 -1
  254. package/dist/transfer/history.js +2 -0
  255. package/dist/transfer/history.js.map +1 -1
  256. package/dist/transfer/identity.js +18 -3
  257. package/dist/transfer/identity.js.map +1 -1
  258. package/dist/transfer/index.d.ts +2 -1
  259. package/dist/transfer/index.js +4 -3
  260. package/dist/transfer/library.d.ts +45 -0
  261. package/dist/transfer/library.d.ts.map +1 -0
  262. package/dist/transfer/library.js +102 -0
  263. package/dist/transfer/library.js.map +1 -0
  264. package/dist/transfer/nodes.d.ts.map +1 -1
  265. package/dist/transfer/nodes.js +9 -0
  266. package/dist/transfer/nodes.js.map +1 -1
  267. package/dist/transfer/plan.d.ts +9 -0
  268. package/dist/transfer/plan.d.ts.map +1 -1
  269. package/dist/transfer/plan.js +51 -6
  270. package/dist/transfer/plan.js.map +1 -1
  271. package/dist/transfer/remove.js +7 -1
  272. package/dist/transfer/remove.js.map +1 -1
  273. package/dist/transfer/validation.js +8 -4
  274. package/dist/transfer/validation.js.map +1 -1
  275. package/dist/transfer/variables.d.ts.map +1 -1
  276. package/dist/transfer/variables.js +2 -1
  277. package/dist/transfer/variables.js.map +1 -1
  278. package/dist/types.d.ts +90 -12
  279. package/dist/types.d.ts.map +1 -1
  280. package/dist/types.js +33 -1
  281. package/dist/types.js.map +1 -1
  282. package/dist/variables/bindings.d.ts +11 -6
  283. package/dist/variables/bindings.d.ts.map +1 -1
  284. package/dist/variables/bindings.js +162 -38
  285. package/dist/variables/bindings.js.map +1 -1
  286. package/dist/variables/easing.d.ts +48 -0
  287. package/dist/variables/easing.d.ts.map +1 -0
  288. package/dist/variables/easing.js +321 -0
  289. package/dist/variables/easing.js.map +1 -0
  290. package/dist/variables/formula/index.d.ts +4 -2
  291. package/dist/variables/formula/index.d.ts.map +1 -1
  292. package/dist/variables/formula/index.js +26 -9
  293. package/dist/variables/formula/index.js.map +1 -1
  294. package/dist/variables/formula/parse.js +1 -1
  295. package/dist/variables/formula/schema.js +1 -1
  296. package/dist/variables/formula/signatures.d.ts +2 -2
  297. package/dist/variables/formula/signatures.d.ts.map +1 -1
  298. package/dist/variables/formula/signatures.js.map +1 -1
  299. package/dist/variables/formula/tree.d.ts +2 -2
  300. package/dist/variables/formula/tree.d.ts.map +1 -1
  301. package/dist/variables/formula/tree.js.map +1 -1
  302. package/dist/variables/index.d.ts +22 -5
  303. package/dist/variables/index.d.ts.map +1 -1
  304. package/dist/variables/index.js +67 -17
  305. package/dist/variables/index.js.map +1 -1
  306. package/dist/variables/lookup.js +1 -1
  307. package/dist/variables/lookup.js.map +1 -1
  308. package/dist/variables/motion.d.ts +46 -0
  309. package/dist/variables/motion.d.ts.map +1 -0
  310. package/dist/variables/motion.js +107 -0
  311. package/dist/variables/motion.js.map +1 -0
  312. package/dist/variables/paints.d.ts +10 -2
  313. package/dist/variables/paints.d.ts.map +1 -1
  314. package/dist/variables/paints.js +24 -10
  315. package/dist/variables/paints.js.map +1 -1
  316. package/dist/variables/resolution.d.ts.map +1 -1
  317. package/dist/variables/resolution.js +10 -9
  318. package/dist/variables/resolution.js.map +1 -1
  319. package/dist/variables/schema.d.ts +59 -1
  320. package/dist/variables/schema.d.ts.map +1 -1
  321. package/dist/variables/schema.js +36 -1
  322. package/dist/variables/schema.js.map +1 -1
  323. package/dist/variables/style-bindings.d.ts +23 -0
  324. package/dist/variables/style-bindings.d.ts.map +1 -0
  325. package/dist/variables/style-bindings.js +83 -0
  326. package/dist/variables/style-bindings.js.map +1 -0
  327. package/package.json +21 -2
  328. package/src/behaviours/index.ts +1 -0
  329. package/src/behaviours/kinds.ts +5 -1
  330. package/src/behaviours/model.ts +2 -2
  331. package/src/behaviours/schema.ts +19 -2
  332. package/src/behaviours/spec.ts +5 -0
  333. package/src/behaviours/transition.ts +46 -0
  334. package/src/checkpoint.ts +2 -0
  335. package/src/color/index.ts +15 -24
  336. package/src/color/management.ts +144 -168
  337. package/src/color/okhcl.ts +62 -43
  338. package/src/color/schema.ts +13 -0
  339. package/src/constraints.ts +2 -1
  340. package/src/copy.ts +29 -0
  341. package/src/corners.ts +3 -0
  342. package/src/css/index.ts +1 -0
  343. package/src/css/motion.ts +51 -0
  344. package/src/css/shadows.ts +7 -6
  345. package/src/css/values.ts +7 -3
  346. package/src/fields/layout.ts +9 -0
  347. package/src/font-style.ts +8 -3
  348. package/src/generated/index.ts +15 -3
  349. package/src/geometry.ts +13 -1
  350. package/src/graph.ts +72 -9
  351. package/src/group-bounds.ts +54 -13
  352. package/src/hit-test.ts +13 -8
  353. package/src/instances/fields.ts +2 -0
  354. package/src/instances/index.ts +71 -12
  355. package/src/instances/sync.ts +93 -11
  356. package/src/layout/flow.ts +34 -0
  357. package/src/layout/index.ts +1 -0
  358. package/src/layout/keywords.ts +7 -1
  359. package/src/layout/sizing.ts +30 -0
  360. package/src/layout/spacing.ts +12 -0
  361. package/src/mesh/geometry.ts +433 -0
  362. package/src/mesh/index.ts +3 -0
  363. package/src/mesh/model.ts +50 -0
  364. package/src/mesh/schema.ts +81 -0
  365. package/src/mutation-impact.ts +23 -7
  366. package/src/node-defaults.ts +22 -5
  367. package/src/paints/index.ts +2 -0
  368. package/src/paints/pattern.ts +55 -0
  369. package/src/paints/shows.ts +9 -0
  370. package/src/paints/solid.ts +10 -0
  371. package/src/paints/stills.ts +182 -0
  372. package/src/plugin-data/field.ts +3 -0
  373. package/src/plugin-data/fields.ts +15 -2
  374. package/src/resize.ts +32 -20
  375. package/src/scaling/index.ts +1 -1
  376. package/src/scaling/node.ts +43 -6
  377. package/src/shaders/index.ts +0 -1
  378. package/src/shaders/model.ts +19 -49
  379. package/src/shaders/schema.ts +1 -1
  380. package/src/shape-with-text/document.ts +175 -0
  381. package/src/shape-with-text/geometry.ts +99 -27
  382. package/src/shared-style-index.ts +106 -0
  383. package/src/shared-styles.ts +21 -14
  384. package/src/slides/drop.ts +94 -0
  385. package/src/slides/index.ts +125 -0
  386. package/src/slides/motion.ts +169 -0
  387. package/src/slides/playback.ts +200 -0
  388. package/src/slides/types.ts +94 -0
  389. package/src/text/direction.ts +13 -23
  390. package/src/text/index.ts +1 -0
  391. package/src/text/name.ts +39 -0
  392. package/src/text/references.ts +3 -3
  393. package/src/thumbnail.ts +52 -0
  394. package/src/transfer/apply.ts +16 -3
  395. package/src/transfer/copied.ts +7 -2
  396. package/src/transfer/dependencies.ts +10 -1
  397. package/src/transfer/history.ts +2 -0
  398. package/src/transfer/identity.ts +34 -2
  399. package/src/transfer/index.ts +6 -0
  400. package/src/transfer/library.ts +153 -0
  401. package/src/transfer/nodes.ts +20 -0
  402. package/src/transfer/plan.ts +96 -10
  403. package/src/transfer/remove.ts +6 -2
  404. package/src/transfer/validation.ts +15 -7
  405. package/src/transfer/variables.ts +8 -2
  406. package/src/types.ts +114 -10
  407. package/src/variables/bindings.ts +260 -36
  408. package/src/variables/easing.ts +282 -0
  409. package/src/variables/formula/index.ts +33 -14
  410. package/src/variables/formula/signatures.ts +6 -2
  411. package/src/variables/formula/tree.ts +3 -3
  412. package/src/variables/index.ts +90 -37
  413. package/src/variables/lookup.ts +1 -1
  414. package/src/variables/motion.ts +151 -0
  415. package/src/variables/paints.ts +29 -7
  416. package/src/variables/resolution.ts +11 -5
  417. package/src/variables/schema.ts +41 -0
  418. package/src/variables/style-bindings.ts +137 -0
  419. package/dist/shaders/still.d.ts +0 -18
  420. package/dist/shaders/still.d.ts.map +0 -1
  421. package/dist/shaders/still.js +0 -36
  422. package/dist/shaders/still.js.map +0 -1
  423. package/src/shaders/still.ts +0 -41
@@ -1,8 +1,14 @@
1
1
  import type { SceneGraph } from '../graph'
2
2
  import { sharedStyleLayers } from '../shared-styles'
3
- import type { ComponentPropertyType, SceneNode } from '../types'
3
+ import type { ComponentPropertyType, SceneNode, Variable, VariableCollection } from '../types'
4
+ import {
5
+ libraryModeOf,
6
+ matchLibraryResources,
7
+ withoutLibraryKey,
8
+ type LibraryReuse
9
+ } from './library'
4
10
  import { prepareNodeTransfer } from './nodes'
5
- import { prepareVariableTransfer } from './variables'
11
+ import { prepareVariableTransfer, type VariableTransferReferences } from './variables'
6
12
 
7
13
  export interface GraphTransferInput {
8
14
  source: SceneGraph
@@ -24,6 +30,60 @@ function withStyleId(
24
30
  return { ...props, source: { ...(props.source ?? node.source), id } }
25
31
  }
26
32
 
33
+ /**
34
+ * The variables and collections a transfer adds, given what the target holds of them: nothing
35
+ * for a copy it holds, and a variable new to a library collection it holds joins that one. A
36
+ * copy that cannot take the place of the target's becomes the target's own, without its key,
37
+ * and a library collection new to the target remembers each library mode, so that a later
38
+ * transfer of it pairs its modes exactly.
39
+ */
40
+ function libraryResources(
41
+ prepared: { variables: Variable[]; collections: VariableCollection[] },
42
+ sourceCollections: readonly VariableCollection[],
43
+ references: VariableTransferReferences,
44
+ reuse: LibraryReuse
45
+ ) {
46
+ const mapped = (id: string) => references.variables.get(id) ?? references.collections.get(id)
47
+ const local = new Set([...reuse.local].map(mapped))
48
+ const reused = {
49
+ collections: [...new Set(reuse.collections.values())],
50
+ variables: [...new Set(reuse.variables.values())],
51
+ styles: [...new Set(reuse.styles.values())]
52
+ }
53
+ const heldCollections = new Set(reused.collections)
54
+ const heldVariables = new Set(reused.variables)
55
+ const own = <T extends { id: string; key?: string; version?: string }>(item: T): T =>
56
+ local.has(item.id) ? withoutLibraryKey(item) : item
57
+ const libraryModes = new Map(
58
+ sourceCollections.flatMap((collection) =>
59
+ collection.key
60
+ ? collection.modes.map((mode) => [references.modes.get(mode.modeId), libraryModeOf(mode)])
61
+ : []
62
+ )
63
+ )
64
+ const collections = prepared.collections
65
+ .filter((collection) => !heldCollections.has(collection.id))
66
+ .map(own)
67
+ .map((collection) =>
68
+ collection.key
69
+ ? {
70
+ ...collection,
71
+ modes: collection.modes.map((mode) => ({
72
+ ...mode,
73
+ libraryModeId: libraryModes.get(mode.modeId)
74
+ }))
75
+ }
76
+ : collection
77
+ )
78
+ const variables = prepared.variables
79
+ .filter((variable) => !heldVariables.has(variable.id))
80
+ .map(own)
81
+ const joined = variables
82
+ .filter((variable) => heldCollections.has(variable.collectionId))
83
+ .map((variable) => ({ collectionId: variable.collectionId, variableId: variable.id }))
84
+ return { variables, collections, joined, reused }
85
+ }
86
+
27
87
  /** Preflight a self-contained fragment; allocation does not insert anything into the target. */
28
88
  export function prepareGraphTransfer(input: GraphTransferInput) {
29
89
  const { source, target, parentId } = input
@@ -43,6 +103,18 @@ export function prepareGraphTransfer(input: GraphTransferInput) {
43
103
  reserved.add(id)
44
104
  return id
45
105
  }
106
+ const targetStyles = sharedStyleLayers(target)
107
+ const reuse = matchLibraryResources(
108
+ target,
109
+ {
110
+ collections: source.variableCollections.values(),
111
+ variables: source.variables.values(),
112
+ styles: sharedStyleLayers(source).values()
113
+ },
114
+ targetStyles
115
+ )
116
+ const reusedStyle = (node: SceneNode) =>
117
+ node.sharedStyleType !== null && !!node.source.id && reuse.styles.has(node.source.id)
46
118
  const ordered: SceneNode[] = []
47
119
  const seen = new Set<string>()
48
120
  const visit = (id: string): void => {
@@ -50,17 +122,27 @@ export function prepareGraphTransfer(input: GraphTransferInput) {
50
122
  const node = source.getNode(id)
51
123
  if (!node) throw new Error(`Missing transfer source ${id}`)
52
124
  seen.add(id)
125
+ // Layers name the target's copy of a library style it already holds instead.
126
+ if (reusedStyle(node)) return
53
127
  ordered.push(node)
54
128
  for (const child of node.childIds) visit(child)
55
129
  }
56
130
  for (const id of [...input.dependencyPageIds, ...input.rootIds]) visit(id)
57
131
  const nodes = new Map(ordered.map((node) => [node.id, allocate()]))
58
- const variables = new Map([...source.variables.keys()].map((id) => [id, allocate()]))
59
- const collections = new Map([...source.variableCollections.keys()].map((id) => [id, allocate()]))
132
+ const variables = new Map(
133
+ [...source.variables.keys()].map((id) => [id, reuse.variables.get(id) ?? allocate()])
134
+ )
135
+ const collections = new Map(
136
+ [...source.variableCollections.keys()].map((id) => [
137
+ id,
138
+ reuse.collections.get(id) ?? allocate()
139
+ ])
140
+ )
60
141
  const modes = new Map<string, string>()
61
142
  for (const collection of source.variableCollections.values()) {
62
143
  for (const mode of collection.modes)
63
- if (!modes.has(mode.modeId)) modes.set(mode.modeId, allocate())
144
+ if (!modes.has(mode.modeId))
145
+ modes.set(mode.modeId, reuse.modes.get(mode.modeId) ?? allocate())
64
146
  }
65
147
  const properties = new Map<string, string>()
66
148
  const propertyTypes = new Map<string, ComponentPropertyType>()
@@ -73,8 +155,7 @@ export function prepareGraphTransfer(input: GraphTransferInput) {
73
155
  }
74
156
  // Layers name a style by the style's own ID, which a transferred style keeps unless the
75
157
  // target already holds another style by it: IDs read from Figma are only unique in one file.
76
- const targetStyles = sharedStyleLayers(target)
77
- const styles = new Map<string, string>()
158
+ const styles = new Map(reuse.styles)
78
159
  for (const node of ordered) {
79
160
  const id = node.source.id
80
161
  if (node.sharedStyleType === null || !id) continue
@@ -89,10 +170,15 @@ export function prepareGraphTransfer(input: GraphTransferInput) {
89
170
  propertyTypes,
90
171
  styles
91
172
  }
92
- const resources = prepareVariableTransfer(
93
- [...source.variables.values()],
173
+ const resources = libraryResources(
174
+ prepareVariableTransfer(
175
+ [...source.variables.values()],
176
+ [...source.variableCollections.values()],
177
+ references
178
+ ),
94
179
  [...source.variableCollections.values()],
95
- references
180
+ references,
181
+ reuse
96
182
  )
97
183
  const mapped = (id: string): string => {
98
184
  const value = nodes.get(id)
@@ -1,5 +1,5 @@
1
1
  import type { SceneGraph } from '../graph'
2
- import type { GraphTransferPlan } from './apply'
2
+ import { leaveHeldCollections, type GraphTransferPlan } from './apply'
3
3
  import { semanticTransferReferences } from './nodes'
4
4
 
5
5
  /** Refuse to remove transferred content that has acquired external dependents. */
@@ -25,11 +25,15 @@ export function removeGraphTransfer(graph: SceneGraph, plan: GraphTransferPlan):
25
25
  throw new Error(`Transferred content is referenced by ${node.id}`)
26
26
  }
27
27
  for (const variable of graph.variables.values()) {
28
- if (!variables.has(variable.id) && referencesOwned(variable.valuesByMode))
28
+ if (variables.has(variable.id)) continue
29
+ if (referencesOwned(variable.valuesByMode))
29
30
  throw new Error('Transferred variable has external aliases')
31
+ if (collections.has(variable.collectionId))
32
+ throw new Error('Transferred collection holds non-owned variables')
30
33
  }
31
34
  graph.withBufferedEvents(() => {
32
35
  for (const node of plan.nodes.toReversed()) graph.deleteNode(node.id)
36
+ leaveHeldCollections(graph, plan)
33
37
  for (const id of variables) {
34
38
  graph.willChangeVariable(id)
35
39
  graph.variables.delete(id)
@@ -1,8 +1,9 @@
1
1
  import type { SceneGraph } from '../graph'
2
2
  import { createDefaultNode } from '../node-defaults'
3
+ import { sharedStyleLayers } from '../shared-styles'
3
4
  import type { ComponentPropertyType } from '../types'
4
5
  import type { GraphTransferPlan } from './apply'
5
- import { variableIdentityReferences } from './identity'
6
+ import { heldTransferCollections, variableIdentityReferences } from './identity'
6
7
  import { prepareNodeTransfer } from './nodes'
7
8
 
8
9
  /** Revalidate mutable plan references without allocating or registering destination nodes. */
@@ -24,18 +25,25 @@ export function validateTransferReferences(target: SceneGraph, plan: GraphTransf
24
25
  properties.set(definition.id, definition.id)
25
26
  propertyTypes.set(definition.id, definition.type)
26
27
  }
27
- const collections = new Map(plan.collections.map((collection) => [collection.id, collection]))
28
- const styles = new Map(
29
- [...nodes.values()].flatMap((node) =>
30
- node.sharedStyleType !== null && node.source.id ? [[node.source.id, node.source.id]] : []
28
+ const planCollections = [...plan.collections, ...heldTransferCollections(target, plan)]
29
+ const collections = new Map(planCollections.map((collection) => [collection.id, collection]))
30
+ const heldStyles = sharedStyleLayers(target)
31
+ for (const id of plan.reused.styles)
32
+ if (!heldStyles.has(id)) throw new Error(`Missing reused transfer style ${id}`)
33
+ const styles = new Map([
34
+ ...plan.reused.styles.map((id) => [id, id] as const),
35
+ ...[...nodes.values()].flatMap((node) =>
36
+ node.sharedStyleType !== null && node.source.id
37
+ ? [[node.source.id, node.source.id] as const]
38
+ : []
31
39
  )
32
- )
40
+ ])
33
41
  const references = {
34
42
  nodes: identities,
35
43
  styles,
36
44
  properties,
37
45
  propertyTypes,
38
- ...variableIdentityReferences(plan.variables, plan.collections)
46
+ ...variableIdentityReferences(plan.variables, planCollections, plan.reused.variables)
39
47
  }
40
48
  for (const node of nodes.values()) {
41
49
  prepareNodeTransfer(node, references)
@@ -35,8 +35,14 @@ function assertResourceOwnership(
35
35
  }
36
36
  for (const variable of variables) {
37
37
  const collection = sets.get(variable.collectionId)
38
- if (!collection?.variableIds.includes(variable.id))
39
- throw new Error(`Missing collection membership for ${variable.id}`)
38
+ if (!collection) throw new Error(`Missing collection membership for ${variable.id}`)
39
+ // A collection lists only its live variables; a deleted one still transfers with its bindings.
40
+ if (collection.variableIds.includes(variable.id) === !!variable.deleted)
41
+ throw new Error(
42
+ variable.deleted
43
+ ? `Deleted variable ${variable.id} listed in ${collection.id}`
44
+ : `Missing collection membership for ${variable.id}`
45
+ )
40
46
  const modes = new Set(collection.modes.map((mode) => mode.modeId))
41
47
  for (const mode of Object.keys(variable.valuesByMode)) {
42
48
  if (!modes.has(mode)) throw new Error(`Unknown mode ${mode} for ${variable.id}`)
package/src/types.ts CHANGED
@@ -5,6 +5,7 @@ import type { CanvasGuide } from './guides'
5
5
  import type { InstanceOverrideState } from './instances/overrides'
6
6
  import type { Color, Matrix, Rect, Vector } from './primitives'
7
7
  import type { ShapeWithTextType } from './shape-with-text/kinds'
8
+ import type { LayerAnimation, SlideSettings } from './slides/types'
8
9
 
9
10
  export interface SceneGraphEvents {
10
11
  'node:created': (node: SceneNode) => void
@@ -58,10 +59,14 @@ export interface NodeChangeObserver {
58
59
  resume?: () => void
59
60
  }
60
61
 
61
- export type DocumentColorSpace = 'srgb' | 'display-p3'
62
+ /**
63
+ * A color profile: the one a document's colors are stored in, or the one they are shown or
64
+ * exported in. Figma files are sRGB or Display P3.
65
+ */
66
+ export type ColorProfile = 'srgb' | 'display-p3'
62
67
 
63
- /** What a document is for, as Figma keeps design files and FigJam boards apart. */
64
- export type DocumentKind = 'design' | 'board'
68
+ /** What a document is for, as Figma keeps design files, FigJam boards and Slides decks apart. */
69
+ export type DocumentKind = 'design' | 'board' | 'slides'
65
70
 
66
71
  export interface FigmaSourcePayload {
67
72
  rawSize: Vector | null
@@ -70,6 +75,11 @@ export interface FigmaSourcePayload {
70
75
  layout: FigmaLayoutMetadata | null
71
76
  symbolOverrides: unknown[]
72
77
  componentPropAssignments: unknown[]
78
+ /**
79
+ * An instance's saved assignments of slot content that no layer shows, as when its variant
80
+ * has no frame for the slot. Figma keeps them, and the content, for a variant that does.
81
+ */
82
+ hiddenSlotAssignments: unknown[]
73
83
  derivedSymbolData: unknown[]
74
84
  derivedSymbolDataLayoutVersion: number | null
75
85
  uniformScaleFactor: number | null
@@ -142,6 +152,14 @@ export type NodeType =
142
152
  | 'CONNECTOR'
143
153
  | 'SHAPE_WITH_TEXT'
144
154
  | 'STICKY'
155
+ | 'SLIDE'
156
+ | 'SLIDE_ROW'
157
+ | 'SLIDE_GRID'
158
+ /**
159
+ * A Figma shader's definition on the internal page, which a shader paint names: its library key,
160
+ * version and property definitions. OpenPencil keeps it for Figma and never draws it.
161
+ */
162
+ | 'CODE_COMPONENT'
145
163
 
146
164
  export type FillType =
147
165
  | 'SOLID'
@@ -186,6 +204,11 @@ export interface GradientStop {
186
204
 
187
205
  export type GradientTransform = Matrix
188
206
 
207
+ export interface LibraryAssetRef {
208
+ key: string
209
+ version?: string
210
+ }
211
+
189
212
  /** Figma's adjustments of an image paint, each from -1 to 1; 0 leaves the image as it is. */
190
213
  export interface ImageFilters {
191
214
  exposure?: number
@@ -227,6 +250,8 @@ export interface Fill {
227
250
  density?: number
228
251
  noiseSize?: Vector
229
252
  customEffectId?: string
253
+ customEffectAssetRef?: LibraryAssetRef
254
+ componentPropAssignments?: unknown[]
230
255
  }
231
256
 
232
257
  export type StrokeCap =
@@ -403,7 +428,11 @@ export interface ConnectorLabelPosition {
403
428
  offAxis: 'NONE' | 'ABOVE' | 'BELOW'
404
429
  }
405
430
  export type TextAlignVertical = 'TOP' | 'CENTER' | 'BOTTOM'
406
- export type TextCase = 'ORIGINAL' | 'UPPER' | 'LOWER' | 'TITLE'
431
+ /**
432
+ * How a text's letters are cased: as typed, re-cased, or drawn as small caps, which take the
433
+ * font's own small capitals for lower-case letters and, forced, for capitals too.
434
+ */
435
+ export type TextCase = 'ORIGINAL' | 'UPPER' | 'LOWER' | 'TITLE' | 'SMALL_CAPS' | 'SMALL_CAPS_FORCED'
407
436
  export type TextDecoration = 'NONE' | 'UNDERLINE' | 'STRIKETHROUGH'
408
437
  export type TextDecorationStyle = 'SOLID' | 'DOTTED' | 'WAVY'
409
438
  export type LeadingTrim = 'NONE' | 'CAP_HEIGHT'
@@ -456,8 +485,11 @@ export const TEXT_BINDABLE_FIELDS = [
456
485
 
457
486
  export type TextBindableField = (typeof TEXT_BINDABLE_FIELDS)[number]
458
487
 
459
- /** Variable IDs bound to text fields, by field. */
460
- export type TextBoundVariables = Partial<Record<TextBindableField, string>>
488
+ /**
489
+ * Variable IDs a range binds, by field: a `TextBindableField`, or the colour of one of the range's
490
+ * own fills, as `fills/0/color`, the way a layer names its paints' bindings.
491
+ */
492
+ export type TextBoundVariables = Record<string, string>
461
493
 
462
494
  /**
463
495
  * A line height or letter spacing as Figma keeps it: pixels, or a percent of the font size that
@@ -934,6 +966,10 @@ export interface SceneNode {
934
966
  starInnerRadius: number
935
967
  /** The FigJam kind a SHAPE_WITH_TEXT draws; its label is the node's own text. */
936
968
  shapeWithTextType: ShapeWithTextType
969
+ /** What a slide keeps besides its layers; null on other layers. */
970
+ slide: SlideSettings | null
971
+ /** How the layer comes onto or leaves the slide it is on while presenting; null for none. */
972
+ animation: LayerAnimation | null
937
973
  /** The height a shape with text was given; it grows past it to fit its label. 0 is unset. */
938
974
  shapeUserHeight: number
939
975
  /**
@@ -1045,7 +1081,62 @@ export interface ComponentPropertyDefinition {
1045
1081
  slotSettings?: SlotSettings
1046
1082
  }
1047
1083
 
1048
- export type VariableType = 'COLOR' | 'FLOAT' | 'STRING' | 'BOOLEAN'
1084
+ /** A TIMING variable holds a duration in seconds; an EASING one, an `Easing`. */
1085
+ export const VARIABLE_TYPES = ['COLOR', 'FLOAT', 'STRING', 'BOOLEAN', 'EASING', 'TIMING'] as const
1086
+ export type VariableType = (typeof VARIABLE_TYPES)[number]
1087
+
1088
+ /**
1089
+ * The curves and springs an easing can be, by the names `.fig` files give them. `CUSTOM_CUBIC`
1090
+ * and `CUSTOM_SPRING` hold the curve or spring they were given; the rest are presets, and
1091
+ * `HOLD` jumps to the end without easing.
1092
+ */
1093
+ export const EASING_CURVES = [
1094
+ 'IN_CUBIC',
1095
+ 'OUT_CUBIC',
1096
+ 'INOUT_CUBIC',
1097
+ 'LINEAR',
1098
+ 'IN_BACK_CUBIC',
1099
+ 'OUT_BACK_CUBIC',
1100
+ 'INOUT_BACK_CUBIC',
1101
+ 'CUSTOM_CUBIC',
1102
+ 'SPRING',
1103
+ 'GENTLE_SPRING',
1104
+ 'CUSTOM_SPRING',
1105
+ 'SPRING_PRESET_ONE',
1106
+ 'SPRING_PRESET_TWO',
1107
+ 'SPRING_PRESET_THREE',
1108
+ 'HOLD',
1109
+ 'EASE_IN'
1110
+ ] as const
1111
+ export type EasingCurve = (typeof EASING_CURVES)[number]
1112
+
1113
+ /** A CSS `cubic-bezier()`: the two control points between (0, 0) and (1, 1). */
1114
+ export interface CubicBezier {
1115
+ x1: number
1116
+ y1: number
1117
+ x2: number
1118
+ y2: number
1119
+ }
1120
+
1121
+ /**
1122
+ * A spring as its physics. `type` says how it is edited: by its bounce (`NORMALIZED`, the
1123
+ * default) or by these three numbers (`PHYSICAL`), whose meaning `platform` sets.
1124
+ */
1125
+ export interface Spring {
1126
+ stiffness: number
1127
+ damping: number
1128
+ mass: number
1129
+ type?: 'NORMALIZED' | 'PHYSICAL'
1130
+ platform?: 'IOS_WEB' | 'ANDROID'
1131
+ }
1132
+
1133
+ /** An EASING variable's value: a curve or spring, and the numbers it holds as a file saves them. */
1134
+ export interface Easing {
1135
+ easing: EasingCurve
1136
+ bezier?: CubicBezier
1137
+ spring?: Spring
1138
+ }
1139
+
1049
1140
  export interface VariableAlias {
1050
1141
  aliasId: string
1051
1142
  }
@@ -1057,7 +1148,10 @@ export interface VariableColorExpression {
1057
1148
  opacity: number | VariableAlias
1058
1149
  }
1059
1150
 
1060
- export type VariableLiteral = Color | number | string | boolean
1151
+ export type VariableLiteral = Color | number | string | boolean | Easing
1152
+ /** The types a formula computes with and gives; easings and timings are not among them. */
1153
+ export type VariableFormulaType = 'COLOR' | 'FLOAT' | 'STRING' | 'BOOLEAN'
1154
+ export type VariableFormulaLiteral = Color | number | string | boolean
1061
1155
  /** The arithmetic, comparison, logic and conversions a formula combines values with. */
1062
1156
  export const VARIABLE_FORMULA_OPERATORS = [
1063
1157
  'add',
@@ -1083,10 +1177,10 @@ export interface VariableFormulaOperation {
1083
1177
  operator: VariableFormulaOperator
1084
1178
  operands: VariableFormulaNode[]
1085
1179
  }
1086
- export type VariableFormulaNode = VariableLiteral | VariableAlias | VariableFormulaOperation
1180
+ export type VariableFormulaNode = VariableFormulaLiteral | VariableAlias | VariableFormulaOperation
1087
1181
  export interface VariableFormula {
1088
1182
  expression: 'FORMULA'
1089
- type: VariableType
1183
+ type: VariableFormulaType
1090
1184
  value: VariableFormulaNode
1091
1185
  }
1092
1186
  /**
@@ -1183,6 +1277,11 @@ export interface Variable {
1183
1277
  key?: string
1184
1278
  /** Published library version (from NodeChange.version). Used for assetRef resolution in colorVar. */
1185
1279
  version?: string
1280
+ /**
1281
+ * Deleted as Figma deletes a variable: gone from its collection's `variableIds` and from every
1282
+ * list of variables, while layers bound to it still resolve it and the file keeps it.
1283
+ */
1284
+ deleted?: true
1186
1285
  }
1187
1286
 
1188
1287
  /** Scalar numeric node fields accepted by numeric property controls; some may also be null. */
@@ -1232,6 +1331,11 @@ export interface VariableCollection {
1232
1331
  key?: string
1233
1332
  /** Published library version, which references by key carry with it. */
1234
1333
  version?: string
1334
+ /**
1335
+ * Deleted as Figma deletes a collection: gone from every list of collections, with its variables
1336
+ * deleted too, while layers bound to them still resolve them and the file keeps them.
1337
+ */
1338
+ deleted?: true
1235
1339
  }
1236
1340
 
1237
1341
  /** Whether a collection is a library's copy, which takes no variables or modes of the file's. */