@open-pencil/scene-graph 0.17.0-beta.7 → 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 +3 -2
  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 +8 -18
  60. package/dist/css/shadows.js.map +1 -1
  61. package/dist/css/values.d.ts +6 -3
  62. package/dist/css/values.d.ts.map +1 -1
  63. package/dist/css/values.js +23 -5
  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 +91 -13
  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 +2 -0
  343. package/src/css/motion.ts +51 -0
  344. package/src/css/shadows.ts +8 -23
  345. package/src/css/values.ts +34 -4
  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 +115 -11
  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
package/src/corners.ts CHANGED
@@ -1,5 +1,8 @@
1
1
  import type { SceneNode } from './types'
2
2
 
3
+ /** The radius a pill takes: round at the ends at any size a layer reaches. */
4
+ export const PILL_RADIUS = 9999
5
+
3
6
  /** A rectangle's corner radii, clockwise from the top left. */
4
7
  export type CornerRadii = [
5
8
  topLeft: number,
package/src/css/index.ts CHANGED
@@ -8,6 +8,7 @@ export {
8
8
  parseCSSJustifyContent,
9
9
  type CSSAspectRatio
10
10
  } from './layout'
11
+ export { parseCSSEasing, parseCSSTime } from './motion'
11
12
  export { parseCSSShadows } from './shadows'
12
13
  export {
13
14
  CSS_GENERIC_FONT_FAMILIES,
@@ -34,5 +35,6 @@ export {
34
35
  parseCSSURLs,
35
36
  parsePaintFallback,
36
37
  parseFragmentReference,
38
+ splitCSSLayers,
37
39
  splitCSSValue
38
40
  } from './values'
@@ -0,0 +1,51 @@
1
+ import valueParser from 'postcss-value-parser'
2
+
3
+ import type { Easing } from '../types'
4
+ import { easingForBezier, easingPreset } from '../variables/easing'
5
+ import { dimension } from './values'
6
+
7
+ /** A CSS `<time>` in seconds: `250ms` or `0.25s`; a bare number is seconds. Null otherwise. */
8
+ export function parseCSSTime(value: string): number | null {
9
+ const parsed = dimension(value.trim())
10
+ if (!parsed) return null
11
+ if (parsed.unit === 'ms') return parsed.number / 1000
12
+ return parsed.unit === 's' || parsed.unit === '' ? parsed.number : null
13
+ }
14
+
15
+ /** The CSS keywords that name one of Figma's curves, and `step-end`, which holds. */
16
+ const KEYWORD_CURVES: Partial<Record<string, Easing['easing']>> = {
17
+ linear: 'LINEAR',
18
+ 'ease-in': 'EASE_IN',
19
+ 'ease-out': 'OUT_CUBIC',
20
+ 'ease-in-out': 'INOUT_CUBIC',
21
+ 'step-end': 'HOLD'
22
+ }
23
+
24
+ /**
25
+ * A CSS easing function as an easing: a keyword Figma has a preset for, `ease`, or
26
+ * `cubic-bezier(x1, y1, x2, y2)` with both x between 0 and 1. Null for anything else.
27
+ */
28
+ export function parseCSSEasing(value: string): Easing | null {
29
+ const nodes = valueParser(value.trim()).nodes.filter((node) => node.type !== 'space')
30
+ const [node] = nodes
31
+ if (nodes.length !== 1) return null
32
+ if (node.type === 'word') {
33
+ const keyword = node.value.toLowerCase()
34
+ if (keyword === 'ease')
35
+ return { easing: 'CUSTOM_CUBIC', bezier: { x1: 0.25, y1: 0.1, x2: 0.25, y2: 1 } }
36
+ const curve = KEYWORD_CURVES[keyword]
37
+ return curve ? easingPreset(curve) : null
38
+ }
39
+ if (node.type !== 'function' || node.value.toLowerCase() !== 'cubic-bezier') return null
40
+ // Exactly four numbers between commas: nothing else, such as a fifth argument or a function.
41
+ const parts = node.nodes.filter((part) => part.type !== 'space')
42
+ const separated = parts.every((part, index) =>
43
+ index % 2 === 0 ? part.type === 'word' : part.type === 'div' && part.value === ','
44
+ )
45
+ if (parts.length !== 7 || !separated) return null
46
+ const numbers = parts.filter((_, index) => index % 2 === 0).map((part) => dimension(part.value))
47
+ if (numbers.some((number) => number?.unit !== '')) return null
48
+ const [x1, y1, x2, y2] = numbers.map((number) => number?.number ?? 0)
49
+ if (x1 < 0 || x1 > 1 || x2 < 0 || x2 > 1) return null
50
+ return easingForBezier({ x1, y1, x2, y2 })
51
+ }
@@ -3,30 +3,14 @@ import valueParser, { type Node } from 'postcss-value-parser'
3
3
  import { tryParseColor } from '../color'
4
4
  import { BLACK } from '../constants'
5
5
  import type { Color } from '../primitives'
6
- import type { Effect } from '../types'
7
- import { parseCSSNumber } from './values'
8
-
9
- /** The layers of a shadow list, split at its top-level commas. */
10
- function layersOf(nodes: Node[]): Node[][] {
11
- const layers: Node[][] = []
12
- let current: Node[] = []
13
- for (const node of nodes) {
14
- if (node.type === 'div' && node.value === ',') {
15
- layers.push(current)
16
- current = []
17
- } else if (node.type !== 'space' && node.type !== 'comment') {
18
- current.push(node)
19
- }
20
- }
21
- layers.push(current)
22
- return layers
23
- }
6
+ import type { ColorProfile, Effect } from '../types'
7
+ import { cssLayerNodes, parseCSSNumber } from './values'
24
8
 
25
9
  /**
26
10
  * One layer: `inset`, two to four lengths, and a color in any order. Without a color it is
27
11
  * black, as `currentColor` usually is; a layer with anything else, such as `none`, is dropped.
28
12
  */
29
- function shadowOf(nodes: Node[]): Effect[] {
13
+ function shadowOf(nodes: Node[], profile: ColorProfile): Effect[] {
30
14
  let inset = false
31
15
  let color: Color | null = null
32
16
  const lengths: number[] = []
@@ -40,7 +24,7 @@ function shadowOf(nodes: Node[]): Effect[] {
40
24
  lengths.push(length)
41
25
  continue
42
26
  }
43
- const parsed = tryParseColor(valueParser.stringify(node))
27
+ const parsed = tryParseColor(valueParser.stringify(node), profile)
44
28
  if (!parsed || color) return []
45
29
  color = parsed
46
30
  }
@@ -60,9 +44,10 @@ function shadowOf(nodes: Node[]): Effect[] {
60
44
 
61
45
  /**
62
46
  * The shadows of a CSS `box-shadow` or `text-shadow` list, such as
63
- * `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`.
47
+ * `0 4px 8px rgb(0 0 0 / 0.2), inset 0 1px #fff`: drop shadows, and inner shadows for `inset`,
48
+ * their colors read into `profile`.
64
49
  */
65
- export function parseCSSShadows(value: string | undefined): Effect[] {
50
+ export function parseCSSShadows(value: string | undefined, profile: ColorProfile): Effect[] {
66
51
  if (!value) return []
67
- return layersOf(valueParser(value).nodes).flatMap(shadowOf)
52
+ return cssLayerNodes(valueParser(value).nodes).flatMap((layer) => shadowOf(layer, profile))
68
53
  }
package/src/css/values.ts CHANGED
@@ -1,9 +1,10 @@
1
1
  import { compact } from 'es-toolkit'
2
- import valueParser from 'postcss-value-parser'
2
+ import valueParser, { type Node } from 'postcss-value-parser'
3
3
  import { decode, parsePath } from 'ufo'
4
4
 
5
5
  import { tryParseColor } from '../color'
6
6
  import type { Color } from '../primitives'
7
+ import type { ColorProfile } from '../types'
7
8
 
8
9
  /** A CSS dimension's number and lowercase unit, or null. */
9
10
  export function dimension(value: string): { number: number; unit: string } | null {
@@ -37,13 +38,42 @@ export function parseCSSNumber(value: string | undefined): number | null {
37
38
  }
38
39
  }
39
40
 
40
- /** A CSS color that paints something; null for an invalid or fully transparent one. */
41
- export function parseCSSColor(value: string | undefined): Color | null {
41
+ /** A CSS color that paints something, as components in `profile`; null for an invalid or transparent one. */
42
+ export function parseCSSColor(
43
+ value: string | undefined,
44
+ profile: ColorProfile = 'srgb'
45
+ ): Color | null {
42
46
  if (!value) return null
43
- const color = tryParseColor(value.trim())
47
+ const color = tryParseColor(value.trim(), profile)
44
48
  return color && color.a > 0 ? color : null
45
49
  }
46
50
 
51
+ /**
52
+ * The layers of a comma-separated CSS list, such as `box-shadow` or `background-image`, split at
53
+ * its top-level commas, each without its spaces and comments.
54
+ */
55
+ export function cssLayerNodes(nodes: readonly Node[]): Node[][] {
56
+ const layers: Node[][] = []
57
+ let current: Node[] = []
58
+ for (const node of nodes) {
59
+ if (node.type === 'div' && node.value === ',') {
60
+ layers.push(current)
61
+ current = []
62
+ } else if (node.type !== 'space' && node.type !== 'comment') {
63
+ current.push(node)
64
+ }
65
+ }
66
+ layers.push(current)
67
+ return layers
68
+ }
69
+
70
+ /** The layers of a comma-separated CSS list as text, each its parts joined by single spaces. */
71
+ export function splitCSSLayers(value: string): string[] {
72
+ return cssLayerNodes(valueParser(value).nodes).map((layer) =>
73
+ layer.map((node) => valueParser.stringify(node)).join(' ')
74
+ )
75
+ }
76
+
47
77
  /** The space-separated parts of a CSS value, keeping functions such as `rgb(0, 0, 0)` whole. */
48
78
  export function splitCSSValue(value: string): string[] {
49
79
  return valueParser(value)
@@ -46,3 +46,12 @@ export const LAYOUT_AFFECTING_KEYS: ReadonlySet<string> = new Set([
46
46
  'gridPosition',
47
47
  ...SIZE_CONSTRAINT_FIELDS
48
48
  ])
49
+
50
+ /** Fields layout never reads, so an edit to these alone leaves every layer where it is. */
51
+ export const LAYOUT_NEUTRAL_FIELDS: ReadonlySet<string> = new Set([
52
+ 'name',
53
+ 'locked',
54
+ 'expanded',
55
+ 'exportSettings',
56
+ 'pluginData'
57
+ ] satisfies (keyof SceneNode)[])
package/src/font-style.ts CHANGED
@@ -100,9 +100,14 @@ export function normalizeFontFamily(family: string): string {
100
100
  return family.replace(/\s+(Variable|\d+(?:pt|px|em))$/i, '')
101
101
  }
102
102
 
103
+ /** The name of the standard weight nearest `weight`, from Thin at 100 to Black at 900. */
104
+ function weightName(weight: number): string {
105
+ const nearest = Math.min(900, Math.max(100, Math.round(weight / 100) * 100))
106
+ return FONT_WEIGHT_NAMES[nearest] ?? 'Regular'
107
+ }
108
+
103
109
  export function faceLoadKey(weight: number, italic = false): string {
104
- const rounded = Math.round(weight / 100) * 100
105
- const label = FONT_WEIGHT_NAMES[rounded] ?? 'Regular'
110
+ const label = weightName(weight)
106
111
  return italic ? `${label} Italic` : label
107
112
  }
108
113
 
@@ -111,7 +116,7 @@ export function faceLoadKey(weight: number, italic = false): string {
111
116
  * for the regular weight), for a face whose font has not said its own.
112
117
  */
113
118
  export function standardStyleName(weight: number, italic = false): string {
114
- const label = FONT_WEIGHT_NAMES[Math.round(weight / 100) * 100] ?? 'Regular'
119
+ const label = weightName(weight)
115
120
  if (!italic) return label
116
121
  return label === 'Regular' ? 'Italic' : `${label} Italic`
117
122
  }
@@ -61,14 +61,26 @@ export function withGeneratedFrameSize(
61
61
  return { ...kind.sized(changes, node), ...changes }
62
62
  }
63
63
 
64
- /** Whether a layer turns: any layer but a generated frame that stays upright. */
64
+ /** A deck's slides, and the rows and grid that lay them out: their size and place are the deck's. */
65
+ export const DECK_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([
66
+ 'SLIDE',
67
+ 'SLIDE_ROW',
68
+ 'SLIDE_GRID'
69
+ ])
70
+
71
+ /** Whether a layer is placed by its X and Y: any but a deck's slides, rows, and grid. */
72
+ export function layerMoves(node: Pick<SceneNode, 'type'>): boolean {
73
+ return !DECK_TYPES.has(node.type)
74
+ }
75
+
76
+ /** Whether a layer turns: any layer but a generated frame that stays upright, or a deck's slides. */
65
77
  export function layerRotates(node: Pick<SceneNode, 'type'>): boolean {
66
- return generatedFrameKind(node)?.rotates ?? true
78
+ return !DECK_TYPES.has(node.type) && (generatedFrameKind(node)?.rotates ?? true)
67
79
  }
68
80
 
69
81
  /** Whether a layer's resize handles and W and H fields resize it freely. */
70
82
  export function layerResizes(node: Pick<SceneNode, 'type'>): boolean {
71
- return generatedFrameKind(node)?.resizes ?? true
83
+ return !DECK_TYPES.has(node.type) && (generatedFrameKind(node)?.resizes ?? true)
72
84
  }
73
85
 
74
86
  export type { GeneratedFrameKind } from './kind'
package/src/geometry.ts CHANGED
@@ -216,7 +216,8 @@ const SIDE_STROKE_TYPES: ReadonlySet<string> = new Set<SceneNode['type']>([
216
216
  'COMPONENT',
217
217
  'INSTANCE',
218
218
  'SECTION',
219
- 'GROUP'
219
+ 'GROUP',
220
+ 'SLIDE'
220
221
  ])
221
222
 
222
223
  /**
@@ -227,6 +228,17 @@ export function drawsStrokeSides(node: StrokeSidesInput): boolean {
227
228
  return node.independentStrokeWeights === true && (!node.type || SIDE_STROKE_TYPES.has(node.type))
228
229
  }
229
230
 
231
+ /**
232
+ * Whether `stroke` draws anything on `node`. A zero weight draws nothing, as in Figma, unless the
233
+ * node strokes each side by its own weight.
234
+ */
235
+ export function drawsStroke(
236
+ node: StrokeSidesInput,
237
+ stroke: Pick<Stroke, 'visible' | 'weight'>
238
+ ): boolean {
239
+ return stroke.visible && (stroke.weight > 0 || drawsStrokeSides(node))
240
+ }
241
+
230
242
  /** The share of a stroke's weight that lies outside the shape it outlines. */
231
243
  export function strokeAlignShare(align: Stroke['align']): number {
232
244
  if (align === 'OUTSIDE') return 1
package/src/graph.ts CHANGED
@@ -15,7 +15,7 @@ import { cloneNodeProps, type NodeCloneMode } from './copy'
15
15
  import { bindNodeEvents } from './events'
16
16
  import { TRANSFORM_FIELDS } from './fields/geometry'
17
17
  import { LAYOUT_AFFECTING_KEYS } from './fields/layout'
18
- import { withGeneratedFrameSize } from './generated'
18
+ import { isGeneratedFrame, withGeneratedFrameSize } from './generated'
19
19
  import * as HitTest from './hit-test'
20
20
  import { generateId } from './ids'
21
21
  import * as Instances from './instances'
@@ -24,18 +24,21 @@ import Matrix from './matrix'
24
24
  import { CONTAINER_TYPES, createDefaultNode } from './node-defaults'
25
25
  import { updateNodePreview, type NodePreviewObserver } from './preview'
26
26
  import type { Color, Rect, Vector } from './primitives'
27
+ import { SharedStyleIndex } from './shared-style-index'
27
28
  import { markSourceFieldsEdited } from './source-metadata'
28
29
  import { strokeLineChanges } from './strokes'
30
+ import { newTextNameChanges, textNameChanges } from './text/name'
29
31
  import { textCacheInvalidationChanges } from './text/picture'
30
32
  import { remapCopiedReferences } from './transfer/copied'
31
33
  import type {
32
- DocumentColorSpace,
34
+ ColorProfile,
33
35
  DocumentKind,
34
36
  EnabledLibraryBinding,
35
37
  NodeChangeObserver,
36
38
  NodeType,
37
39
  SceneGraphEventHandlers,
38
40
  SceneNode,
41
+ SharedStyleType,
39
42
  Variable,
40
43
  VariableCollection,
41
44
  VariableType,
@@ -53,6 +56,7 @@ type GraphScope =
53
56
  | 'layout'
54
57
  | 'derivedLayout'
55
58
  | 'componentDerived'
59
+ | 'peerChanges'
56
60
 
57
61
  export class SceneGraph {
58
62
  nodes = new Map<string, SceneNode>()
@@ -63,7 +67,7 @@ export class SceneGraph {
63
67
  figKiwiVersion: number | null = null
64
68
  /** Deflated kiwi schema bytes from the original .fig file, preserved for roundtrip fidelity. */
65
69
  figSchemaDeflated: Uint8Array | null = null
66
- documentColorSpace: DocumentColorSpace = 'srgb'
70
+ documentColorSpace: ColorProfile = 'srgb'
67
71
  documentKind: DocumentKind = 'design'
68
72
  enabledLibraries = new Map<string, EnabledLibraryBinding>()
69
73
  readonly emitter = new BufferedSceneEmitter()
@@ -74,7 +78,8 @@ export class SceneGraph {
74
78
  importedState: 0,
75
79
  layout: 0,
76
80
  derivedLayout: 0,
77
- componentDerived: 0
81
+ componentDerived: 0,
82
+ peerChanges: 0
78
83
  }
79
84
  private previewObservers: NodePreviewObserver[] = []
80
85
  private readonly changeObservers = new Set<NodeChangeObserver>()
@@ -87,6 +92,7 @@ export class SceneGraph {
87
92
  instanceIndex = new Map<string, Set<string>>()
88
93
  /** Every connector in the graph, so routing need not scan every layer. */
89
94
  connectorIds = new Set<string>()
95
+ readonly sharedStyleIndex = new SharedStyleIndex(() => this.nodes)
90
96
 
91
97
  constructor(private readonly idGenerator: () => string = generateId) {
92
98
  const root = createDefaultNode(this.idGenerator, 'FRAME', {
@@ -164,6 +170,20 @@ export class SceneGraph {
164
170
  return this.outsideWrites > 0
165
171
  }
166
172
 
173
+ /**
174
+ * Runs `write`, a collaborator's change arriving, outside every edit in progress. The change
175
+ * already holds what the collaborator's edit derived from it, such as the layers its component's
176
+ * instances gained, so this graph must not derive them again under ids of its own.
177
+ */
178
+ applyPeerChangesDuring<T>(write: () => T): T {
179
+ return this.withScope('peerChanges', () => this.runOutsideEdits(write))
180
+ }
181
+
182
+ /** Whether a collaborator's change is being applied (`applyPeerChangesDuring`). */
183
+ get isApplyingPeerChanges(): boolean {
184
+ return this.scopeDepths.peerChanges > 0
185
+ }
186
+
167
187
  /**
168
188
  * Pauses the recorders open now, and only those, until the returned function resumes them: a
169
189
  * recorder that opens while an earlier pause is still pending, such as during a script's load
@@ -332,6 +352,16 @@ export class SceneGraph {
332
352
  return Variables.getVariablesByType(this, type)
333
353
  }
334
354
 
355
+ /** Every variable but the deleted ones, which only their bindings still reach. */
356
+ getLiveVariables(): Variable[] {
357
+ return Variables.liveVariables(this)
358
+ }
359
+
360
+ /** Every collection but the deleted ones. */
361
+ getLiveCollections(): VariableCollection[] {
362
+ return Variables.liveCollections(this)
363
+ }
364
+
335
365
  bindVariable(nodeId: string, field: string, variableId: string): void {
336
366
  Variables.bindVariable(this, nodeId, field, variableId)
337
367
  }
@@ -453,6 +483,7 @@ export class SceneGraph {
453
483
  node.parentId = parentId
454
484
  this.nodes.set(node.id, node)
455
485
  if (node.type === 'CONNECTOR') this.connectorIds.add(node.id)
486
+ this.sharedStyleIndex.added(node)
456
487
  for (const observer of this.changeObservers) observer.created(node)
457
488
  if (node.type === 'INSTANCE' && node.componentId) this.indexInstance(node.componentId, node.id)
458
489
  this.emitter.emit('node:created', node)
@@ -465,7 +496,11 @@ export class SceneGraph {
465
496
 
466
497
  createNode(type: NodeType, parentId: string, overrides: Partial<SceneNode> = {}): SceneNode {
467
498
  const node = createDefaultNode(() => this.generateEntityId(), type, overrides)
468
- Object.assign(node, strokeLineChanges(node, overrides))
499
+ Object.assign(
500
+ node,
501
+ strokeLineChanges(node, overrides),
502
+ this.textName(newTextNameChanges(node, overrides), parentId)
503
+ )
469
504
  const parent = this.nodes.get(parentId)
470
505
  this.willChangeNode(parent)
471
506
  parent?.childIds.push(node.id)
@@ -611,14 +646,39 @@ export class SceneGraph {
611
646
  this.applyNodeChanges(node, this.impliedChanges(node, omitBy(changes, isUndefined)))
612
647
  }
613
648
 
649
+ /** The node of the shared style with this ID, when the document holds one of `type`. */
650
+ getSharedStyleNode(styleId: string, type: SharedStyleType): SceneNode | undefined {
651
+ return this.sharedStyleIndex.styleNode(styleId, type)
652
+ }
653
+
654
+ private styleIndexWillChange(node: SceneNode, changes: Partial<SceneNode>): boolean {
655
+ return !this.isApplyingLayout && this.sharedStyleIndex.willChange(node, changes)
656
+ }
657
+
614
658
  /**
615
- * `changes` with what they also set: a size from outside layout on a generated frame, and
616
- * strokes and the layer's line fields kept in agreement (`strokeLineChanges`).
659
+ * `changes` with what they also set: a size from outside layout on a generated frame, strokes
660
+ * and the layer's line fields kept in agreement (`strokeLineChanges`), and the name of a text
661
+ * layer that follows its text (`textName`).
617
662
  */
618
663
  private impliedChanges(node: SceneNode, changes: Partial<SceneNode>): Partial<SceneNode> {
619
664
  const sized = this.isApplyingLayout ? changes : withGeneratedFrameSize(node, changes)
620
- const lines = strokeLineChanges(node, sized)
621
- return isEmptyObject(lines) ? sized : { ...sized, ...lines }
665
+ const implied = {
666
+ ...strokeLineChanges(node, sized),
667
+ ...this.textName(textNameChanges(node, sized), node.parentId)
668
+ }
669
+ return isEmptyObject(implied) ? sized : { ...sized, ...implied }
670
+ }
671
+
672
+ /**
673
+ * What a write sets on a text layer's name (`textNameChanges`, `newTextNameChanges`), except while a
674
+ * document loads with names of its own; in an instance, whose layers take their component's
675
+ * names, as Figma's do, even with their text overridden; and in a generated frame, such as a
676
+ * sticky note's body, which keeps its template's name while the frame is named by it.
677
+ */
678
+ private textName(named: Partial<SceneNode>, parentId: string | null): Partial<SceneNode> {
679
+ if (this.isApplyingImportedState || isEmptyObject(named)) return {}
680
+ const copied = (n: SceneNode) => n.type === 'INSTANCE' || isGeneratedFrame(n)
681
+ return parentId && this.closest(parentId, copied) ? {} : named
622
682
  }
623
683
 
624
684
  /** Replay captured properties without dropping explicit undefined values or absent keys. */
@@ -673,9 +733,11 @@ export class SceneGraph {
673
733
  changes,
674
734
  this.scopeDepths.sourceMetadata === 0 && !this.isApplyingDerivedLayout
675
735
  )
736
+ const restyled = this.styleIndexWillChange(node, changes)
676
737
  Object.assign(node, changes)
677
738
  this.followListBindings(node, changes)
678
739
  for (const key of absent) Reflect.deleteProperty(node, key)
740
+ this.sharedStyleIndex.didChange(node, restyled)
679
741
  this.publishNodeUpdate(id, changes)
680
742
  }
681
743
 
@@ -793,6 +855,7 @@ export class SceneGraph {
793
855
 
794
856
  if (node.type === 'INSTANCE' && node.componentId) this.unindexInstance(node.componentId, id)
795
857
  this.connectorIds.delete(id)
858
+ this.sharedStyleIndex.removed(node)
796
859
  this.nodes.delete(id)
797
860
  this.emitter.emit('node:deleted', id, node.parentId)
798
861
  }
@@ -1,5 +1,9 @@
1
+ import { isEqual } from 'es-toolkit'
2
+
1
3
  import { getAxisAlignedBoundsInParent, getNodeLocalMatrix } from './coordinate'
4
+ import { copyGeometryPaths } from './copy'
2
5
  import type { SceneGraph } from './graph'
6
+ import { isEmptyBoolean } from './layout/flow'
3
7
  import { isVisibleMask, maskRuns } from './masks'
4
8
  import Matrix from './matrix'
5
9
  import { FITTED_CONTAINER_TYPES } from './node-defaults'
@@ -12,9 +16,12 @@ import type { SceneNode } from './types'
12
16
  */
13
17
  export type GroupFitGraph = Pick<SceneGraph, 'getNode' | 'rootId'>
14
18
 
15
- /** Where a layer sits, with a connector's ends, since a free end is in the parent's axes too. */
19
+ /**
20
+ * Where a layer sits, with a connector's ends, since a free end is in the parent's axes too, and
21
+ * a boolean's saved geometry, which it drops when it loses its last operand.
22
+ */
16
23
  type Placement = Pick<SceneNode, 'x' | 'y' | 'width' | 'height'> &
17
- Partial<Pick<SceneNode, 'connectorStart' | 'connectorEnd'>>
24
+ Partial<Pick<SceneNode, 'connectorStart' | 'connectorEnd' | 'fillGeometry' | 'strokeGeometry'>>
18
25
 
19
26
  /** What `fitEnclosingGroups` changed, so a caller can undo and redo it. */
20
27
  export interface GroupFit {
@@ -34,6 +41,13 @@ export interface GroupFitOptions {
34
41
 
35
42
  function placement(node: SceneNode): Placement {
36
43
  const box = { x: node.x, y: node.y, width: node.width, height: node.height }
44
+ if (node.type === 'BOOLEAN_OPERATION') {
45
+ return {
46
+ ...box,
47
+ fillGeometry: copyGeometryPaths(node.fillGeometry),
48
+ strokeGeometry: copyGeometryPaths(node.strokeGeometry)
49
+ }
50
+ }
37
51
  if (node.type !== 'CONNECTOR') return box
38
52
  return {
39
53
  ...box,
@@ -72,18 +86,22 @@ function fittedAncestors(graph: SceneGraph, parentIds: Iterable<string>): SceneN
72
86
  }
73
87
 
74
88
  /**
75
- * The layers a group's box covers, bottom to top. Hidden layers do not count, as in Figma. A mask
76
- * hides the layers above it outside its shape, so they count only through the mask: the box is
77
- * the layers below it and the masks.
89
+ * The layers a group's box covers, bottom to top. Hidden layers do not count, as in Figma, nor do
90
+ * booleans with no operands unless they keep a finite saved fill and a box sized to it, since a
91
+ * group counts a layer by its box. A mask hides the layers above it outside its shape, so they
92
+ * count only through the mask: the box is the layers below it and the masks.
78
93
  */
79
94
  function groupBoundingLayers(children: readonly SceneNode[]): SceneNode[] {
80
95
  const shown = children.filter((child) => child.visible)
81
96
  const runs = maskRuns(shown, isVisibleMask)
82
- if (runs.length === 0) return shown
83
- return [
84
- ...shown.slice(0, runs[0].start),
85
- ...runs.flatMap((run) => shown.slice(run.start, run.maskedStart))
86
- ]
97
+ const covered =
98
+ runs.length === 0
99
+ ? shown
100
+ : [
101
+ ...shown.slice(0, runs[0].start),
102
+ ...runs.flatMap((run) => shown.slice(run.start, run.maskedStart))
103
+ ]
104
+ return covered.filter((layer) => !isEmptyBoolean(layer))
87
105
  }
88
106
 
89
107
  /**
@@ -203,14 +221,37 @@ function fitGroup(
203
221
  }
204
222
  }
205
223
 
206
- /** A group left without layers goes away; an empty boolean stays, as in Figma. */
207
- function removeEmptyGroup(graph: SceneGraph, group: SceneNode, fit: GroupFit) {
224
+ /**
225
+ * A group left without layers goes away. A boolean stays, as in Figma, as a layer of no size at its
226
+ * parent's origin, without the geometry its operands made.
227
+ */
228
+ function settleEmptyContainer(graph: SceneGraph, group: SceneNode, fit: GroupFit) {
229
+ if (group.type === 'BOOLEAN_OPERATION') {
230
+ collapseEmptyBoolean(graph, group, fit)
231
+ return
232
+ }
208
233
  if (group.type !== 'GROUP' || !group.parentId) return
209
234
  const index = graph.getNode(group.parentId)?.childIds.indexOf(group.id) ?? -1
210
235
  fit.removed.push({ node: structuredClone(group), index })
211
236
  graph.deleteNode(group.id)
212
237
  }
213
238
 
239
+ function collapseEmptyBoolean(graph: SceneGraph, boolean: SceneNode, fit: GroupFit) {
240
+ const before = placement(boolean)
241
+ const collapsed: Placement = {
242
+ x: 0,
243
+ y: 0,
244
+ width: 0,
245
+ height: 0,
246
+ fillGeometry: [],
247
+ strokeGeometry: []
248
+ }
249
+ if (isEqual(before, collapsed)) return
250
+ if (!fit.before.has(boolean.id)) fit.before.set(boolean.id, before)
251
+ graph.updateNode(boolean.id, collapsed)
252
+ fit.after.set(boolean.id, collapsed)
253
+ }
254
+
214
255
  /**
215
256
  * Refits the groups and booleans around these parents to their children, keeping every child where
216
257
  * it is on the canvas, and removes groups left empty, as Figma does after a layer inside one moves,
@@ -225,7 +266,7 @@ export function fitEnclosingGroups(
225
266
  const fit: GroupFit = { before: new Map(), after: new Map(), removed: [] }
226
267
  for (const group of fittedAncestors(graph, parentIds)) {
227
268
  const children = graph.getChildren(group.id)
228
- if (children.length === 0) removeEmptyGroup(graph, group, fit)
269
+ if (children.length === 0) settleEmptyContainer(graph, group, fit)
229
270
  else fitGroup(graph, group, children, fit, options)
230
271
  }
231
272
  return fit.before.size === 0 && fit.removed.length === 0 ? null : fit
package/src/hit-test.ts CHANGED
@@ -15,8 +15,13 @@ const CONTAINER_TYPES = new Set<NodeType>([
15
15
  'SECTION',
16
16
  'COMPONENT',
17
17
  'COMPONENT_SET',
18
- 'INSTANCE'
18
+ 'INSTANCE',
19
+ 'SLIDE',
20
+ 'SLIDE_ROW',
21
+ 'SLIDE_GRID'
19
22
  ])
23
+ /** What holds a deck's slides: never selected from the canvas, and no target of a drop. */
24
+ const SLIDE_HOLDER_TYPES = new Set<NodeType>(['SLIDE_ROW', 'SLIDE_GRID'])
20
25
  const OPAQUE_CONTAINER_TYPES = new Set<NodeType>(['COMPONENT', 'INSTANCE'])
21
26
 
22
27
  /** Whether a container's own paints show, so its empty area is drawn (`paintShows`). */
@@ -292,13 +297,13 @@ export function hitTestDeep(
292
297
 
293
298
  /**
294
299
  * A container a click looks into by itself, as in Figma: a top-level frame (on the page or in a
295
- * section) or a section that holds layers, and a component set. On a FigJam board frames stay
300
+ * section), section, or slide that holds layers, a component set, and what holds a deck's slides. On a FigJam board frames stay
296
301
  * closed (`framesOpen` false): a click inside one selects the frame.
297
302
  */
298
303
  function opensByItself(graph: SceneGraph, node: SceneNode, framesOpen = true): boolean {
299
- if (node.type === 'COMPONENT_SET') return true
304
+ if (node.type === 'COMPONENT_SET' || SLIDE_HOLDER_TYPES.has(node.type)) return true
300
305
  if (node.childIds.length === 0) return false
301
- if (node.type === 'SECTION') return true
306
+ if (node.type === 'SECTION' || node.type === 'SLIDE') return true
302
307
  return framesOpen && node.type === 'FRAME' && isTopLevel(graph, node)
303
308
  }
304
309
 
@@ -463,15 +468,15 @@ interface DropRules {
463
468
  passThrough: ReadonlySet<NodeType>
464
469
  }
465
470
 
466
- const LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE'])
467
- const COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE'])
471
+ const LAYER_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'COMPONENT', 'INSTANCE', 'SLIDE'])
472
+ const COMPONENT_TARGETS = new Set<NodeType>(['FRAME', 'SECTION', 'INSTANCE', 'SLIDE'])
468
473
 
469
474
  function dropRules(options: DropTargetOptions): DropRules {
470
475
  const { componentSetIds } = options
471
476
  if (!componentSetIds) {
472
477
  return {
473
478
  takes: (node) => LAYER_TARGETS.has(node.type),
474
- passThrough: new Set(['GROUP', 'COMPONENT_SET'])
479
+ passThrough: new Set([...SLIDE_HOLDER_TYPES, 'GROUP', 'COMPONENT_SET'])
475
480
  }
476
481
  }
477
482
  // Components never go into other components, and a set only takes back its own variants.
@@ -479,7 +484,7 @@ function dropRules(options: DropTargetOptions): DropRules {
479
484
  takes: (node) =>
480
485
  COMPONENT_TARGETS.has(node.type) ||
481
486
  (node.type === 'COMPONENT_SET' && componentSetIds.has(node.id)),
482
- passThrough: new Set(['GROUP'])
487
+ passThrough: new Set([...SLIDE_HOLDER_TYPES, 'GROUP'])
483
488
  }
484
489
  }
485
490
 
@@ -55,6 +55,8 @@ export const INSTANCE_FOLLOWED_FIELDS = [
55
55
  'pointCount',
56
56
  'starInnerRadius',
57
57
  'shapeWithTextType',
58
+ 'slide',
59
+ 'animation',
58
60
  'shapeUserHeight',
59
61
  'shapeTruncates'
60
62
  ] as const