@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
@@ -1,5 +1,13 @@
1
+ import { omitBy } from 'es-toolkit/object'
2
+ import { isEmptyObject } from 'es-toolkit/predicate'
3
+
1
4
  import type { NodeCloneMode } from '../copy'
2
5
  import type { SceneGraph } from '../graph'
6
+ import {
7
+ collectResizeDescendants,
8
+ computeConstrainedResizeChanges,
9
+ sharedResizeSnapshot
10
+ } from '../resize'
3
11
  import {
4
12
  detachOwnedSlotContent,
5
13
  restoreOwnedSlotContent,
@@ -34,7 +42,8 @@ import {
34
42
  copyProp,
35
43
  sourceInTargetCoordinates,
36
44
  syncChildren,
37
- updateSyncedProps
45
+ updateSyncedProps,
46
+ withSyncedStyleBindings
38
47
  } from './sync'
39
48
 
40
49
  export { canCreateInstance, createsComponentCycle, cycleSafeParent } from './cycles'
@@ -72,12 +81,60 @@ export function createInstance(
72
81
  const instance = graph.createNode('INSTANCE', parentId, { ...props, ...overrides, componentId })
73
82
 
74
83
  cloneChildrenWithMapping(graph, component.id, instance.id)
84
+ // The copies arrive at the component's size; an instance created at another one places them by
85
+ // their constraints, as resizing it afterwards does.
86
+ placeCopiedChildrenForSize(graph, component, instance)
75
87
  // A copy shows its bound paints in its own context, not as its component's paints hold them.
76
88
  applyBoundPaintColorsIn(graph, instance.id)
77
89
 
78
90
  return instance
79
91
  }
80
92
 
93
+ /**
94
+ * Places a new instance's copies as its own size asks, from the size the component gave them.
95
+ * Cloning writes them at the component's size, in the instance's coordinates, so an instance
96
+ * created straight at another size would otherwise keep every layer at the component's size and
97
+ * place, while resizing it to the same size scales them; Figma scales a copy's `scale` layers
98
+ * however it reaches that size.
99
+ */
100
+ function placeCopiedChildrenForSize(
101
+ graph: SceneGraph,
102
+ component: SceneNode,
103
+ instance: SceneNode
104
+ ): void {
105
+ if (instance.childIds.length === 0) return
106
+ // The component's size in the copies' coordinates, which a scaled instance holds apart.
107
+ const from = sourceInTargetCoordinates(component, instance.componentScale)
108
+ if (from.width === instance.width && from.height === instance.height) return
109
+ // The copies are new and every pass writes new geometry, so the snapshots need no copies of it.
110
+ const originals = collectResizeDescendants(graph, instance.id, sharedResizeSnapshot)
111
+ if (!originals) return
112
+ // An auto layout frame places its own constrained layers for the size it has, which a pass
113
+ // only gives it as it writes; each pass starts from the snapshots, so the placement repeats
114
+ // until no such frame changes size, one level deeper each time.
115
+ for (let pass = 0; pass <= originals.size; pass++) {
116
+ const changes = computeConstrainedResizeChanges(graph, instance.id, from, instance, originals)
117
+ const resizesLayout = [...changes].some(([id, change]) => resizesLayoutFrame(graph, id, change))
118
+ for (const [id, change] of changes) writeChanged(graph, id, change)
119
+ if (!resizesLayout) return
120
+ }
121
+ }
122
+
123
+ /** Writes only what differs: the plan places every layer, most of them where they already are. */
124
+ function writeChanged(graph: SceneGraph, id: string, change: Partial<SceneNode>): void {
125
+ const node = graph.nodes.get(id)
126
+ if (!node) return
127
+ const changed = omitBy(change, (value, key) => node[key] === value)
128
+ if (!isEmptyObject(changed)) graph.updateNode(id, changed)
129
+ }
130
+
131
+ function resizesLayoutFrame(graph: SceneGraph, id: string, change: Partial<SceneNode>): boolean {
132
+ const node = graph.nodes.get(id)
133
+ if (!node || node.layoutMode === 'NONE') return false
134
+ const { width = node.width, height = node.height } = change
135
+ return width !== node.width || height !== node.height
136
+ }
137
+
81
138
  export function populateInstanceChildren(
82
139
  graph: SceneGraph,
83
140
  instanceId: string,
@@ -234,17 +291,19 @@ function syncInstancesOf(
234
291
  if (syncing.has(componentId)) return
235
292
  syncing.add(componentId)
236
293
  try {
237
- groupCopyRemovals(graph, (removals) => {
238
- for (const instance of instances) {
239
- const source = sourceInTargetCoordinates(component, instance.componentScale)
240
- const { updates, kept } = ownSyncedProps(graph, instance, source)
241
- // An instance that hugs its layers sizes to what it shows, not to the component.
242
- keepOwnContentSize(graph, updates, instance, source)
243
- updateSyncedProps(graph, instance, updates, kept)
244
- const context = createInstanceSyncContext(instance.id, instance.instanceOverrides)
245
- syncChildren(graph, component.id, instance.id, instance.instanceOverrides, context)
246
- removeLeftoverCopies(graph, context, removals)
247
- }
294
+ withSyncedStyleBindings(graph, () => {
295
+ groupCopyRemovals(graph, (removals) => {
296
+ for (const instance of instances) {
297
+ const source = sourceInTargetCoordinates(component, instance.componentScale)
298
+ const { updates, kept } = ownSyncedProps(graph, instance, source)
299
+ // An instance that hugs its layers sizes to what it shows, not to the component.
300
+ keepOwnContentSize(graph, updates, instance, source)
301
+ updateSyncedProps(graph, instance, updates, kept)
302
+ const context = createInstanceSyncContext(instance.id, instance.instanceOverrides)
303
+ syncChildren(graph, component.id, instance.id, instance.instanceOverrides, context)
304
+ removeLeftoverCopies(graph, context, removals)
305
+ }
306
+ })
248
307
  })
249
308
  } finally {
250
309
  syncing.delete(componentId)
@@ -16,13 +16,22 @@ import {
16
16
  withStrokeLines
17
17
  } from '../strokes'
18
18
  import type { SceneNode } from '../types'
19
- import { resolvedNumericBindings } from '../variables/bindings'
20
- import { isNumericVariableBindingField } from '../variables/fields'
19
+ import {
20
+ resolvedNumericBindings,
21
+ resolvedRunBindings,
22
+ resolvesToNumber,
23
+ resolvedValueBindings
24
+ } from '../variables/bindings'
21
25
  import {
22
26
  applyBoundPaintColorsIn,
23
27
  copyAppliedBoundPaints,
24
28
  keepCopyBoundPaints
25
29
  } from '../variables/paints'
30
+ import {
31
+ createStyleBindingLookup,
32
+ effectiveBoundVariables,
33
+ type TextStyleLookup
34
+ } from '../variables/style-bindings'
26
35
  import { scaleVariableBindingUnits } from '../variables/units'
27
36
  import { applyEnclosingAssignments, assignedFieldValues, propertyDrivenFields } from './assignments'
28
37
  import { keepOwnContentSize, remeasureChangedText, type SyncedPlacement } from './content-size'
@@ -157,6 +166,7 @@ export function updateSyncedProps(
157
166
  kept: (field: string) => boolean = () => false
158
167
  ): void {
159
168
  resolveBoundNumbersInPlace(graph, target, updates, kept)
169
+ resolveBoundValuesInPlace(graph, target, updates, kept)
160
170
  if (updates.fills || updates.strokes || updates.boundVariables) {
161
171
  applySyncedModes(graph, target, updates)
162
172
  keepCopyBoundPaints(graph, target, updates)
@@ -225,21 +235,93 @@ function resolveBoundNumbersInPlace(
225
235
  updates: Partial<SceneNode>,
226
236
  kept: (field: string) => boolean
227
237
  ): void {
228
- const bound = updates.boundVariables ?? target.boundVariables
229
- // The fields the sync writes, and the ones it binds anew, which keep an equal value only in
230
- // the component's mode.
231
- const rebound = updates.boundVariables
232
- ? Object.keys(bound).filter((field) => bound[field] !== target.boundVariables[field])
233
- : []
234
- const synced = uniq([...Object.keys(updates), ...rebound]).filter(
235
- (field) => isNumericVariableBindingField(field) && bound[field] && !kept(field)
238
+ const own = updates.boundVariables ?? target.boundVariables
239
+ // The fields the sync writes, and the ones whose binding it changes, which keep an equal value
240
+ // only in the component's mode.
241
+ const rebound = updates.boundVariables ? changedBindings(target.boundVariables, own) : []
242
+ const styles = styleBindingsOf(graph)
243
+ const textStyleId = updates.textStyleId === undefined ? target.textStyleId : updates.textStyleId
244
+ const bound = effectiveBoundVariables(
245
+ { type: target.type, textStyleId, boundVariables: own },
246
+ styles
236
247
  )
248
+ const restyled = textStyleId !== target.textStyleId ? Object.keys(bound) : []
249
+ const synced = uniq([...Object.keys(updates), ...rebound, ...restyled]).filter(
250
+ (field) => resolvesToNumber(field) && bound[field] && !kept(field)
251
+ )
252
+ resolveSyncedRunsInPlace(graph, target, updates, styles)
237
253
  if (synced.length === 0) return
238
254
  applySyncedModes(graph, target, updates)
239
- const resolved = resolvedNumericBindings(graph, { ...target, ...updates })
255
+ const resolved = resolvedNumericBindings(graph, { ...target, ...updates }, styles)
240
256
  Object.assign(updates, pick(resolved, synced as (keyof SceneNode)[]))
241
257
  }
242
258
 
259
+ /**
260
+ * Bound text and visibility the sync writes, or whose binding it changes, take the value they
261
+ * resolve to where the copy sits, as bound numbers do, rather than the one the component holds
262
+ * in its own mode.
263
+ */
264
+ function resolveBoundValuesInPlace(
265
+ graph: SceneGraph,
266
+ target: SceneNode,
267
+ updates: Partial<SceneNode>,
268
+ kept: (field: string) => boolean
269
+ ): void {
270
+ const bound = updates.boundVariables ?? target.boundVariables
271
+ const rebound = updates.boundVariables ? changedBindings(target.boundVariables, bound) : []
272
+ const synced = (['text', 'visible'] as const).filter(
273
+ (field) =>
274
+ (updates[field] !== undefined || rebound.includes(field)) && bound[field] && !kept(field)
275
+ )
276
+ if (synced.length === 0) return
277
+ applySyncedModes(graph, target, updates)
278
+ const resolved = resolvedValueBindings(graph, { ...target, ...updates })
279
+ Object.assign(updates, pick(resolved, synced))
280
+ }
281
+
282
+ function changedBindings(before: Record<string, string>, after: Record<string, string>): string[] {
283
+ return uniq([...Object.keys(before), ...Object.keys(after)]).filter(
284
+ (field) => before[field] !== after[field]
285
+ )
286
+ }
287
+
288
+ function resolveSyncedRunsInPlace(
289
+ graph: SceneGraph,
290
+ target: SceneNode,
291
+ updates: Partial<SceneNode>,
292
+ styles: TextStyleLookup
293
+ ): void {
294
+ if (!updates.styleRuns) {
295
+ return
296
+ }
297
+ applySyncedModes(graph, target, updates)
298
+ const copy = {
299
+ id: target.id,
300
+ styleRuns: updates.styleRuns,
301
+ componentScale: updates.componentScale ?? target.componentScale
302
+ }
303
+ Object.assign(updates, resolvedRunBindings(graph, copy, styles))
304
+ }
305
+
306
+ const styleBindingsDuringSync = new WeakMap<SceneGraph, TextStyleLookup>()
307
+
308
+ export function withSyncedStyleBindings(graph: SceneGraph, sync: () => void): void {
309
+ if (styleBindingsDuringSync.has(graph)) {
310
+ sync()
311
+ return
312
+ }
313
+ styleBindingsDuringSync.set(graph, createStyleBindingLookup(graph))
314
+ try {
315
+ sync()
316
+ } finally {
317
+ styleBindingsDuringSync.delete(graph)
318
+ }
319
+ }
320
+
321
+ function styleBindingsOf(graph: SceneGraph): TextStyleLookup {
322
+ return styleBindingsDuringSync.get(graph) ?? createStyleBindingLookup(graph)
323
+ }
324
+
243
325
  /** The modes the copy takes in this sync decide what its bindings resolve to. */
244
326
  function applySyncedModes(graph: SceneGraph, target: SceneNode, updates: Partial<SceneNode>): void {
245
327
  if (updates.variableModes && !isEqual(updates.variableModes, target.variableModes))
@@ -0,0 +1,34 @@
1
+ import { geometryBlobBounds } from '../geometry'
2
+ import type { SceneGraph } from '../graph'
3
+ import type { SceneNode } from '../types'
4
+
5
+ function hasFiniteSavedFill(node: SceneNode): boolean {
6
+ const box = geometryBlobBounds(node.fillGeometry)
7
+ return box !== null && [box.x, box.y, box.width, box.height].every(Number.isFinite)
8
+ }
9
+
10
+ /**
11
+ * Whether `node` is a boolean with no operands and so no box: Figma keeps one whose operands are
12
+ * all removed as a layer of no size, and neither a group's box nor an auto layout flow counts it.
13
+ * One read from a file with a finite saved fill and a size to match still has its box.
14
+ */
15
+ export function isEmptyBoolean(node: SceneNode): boolean {
16
+ return (
17
+ node.type === 'BOOLEAN_OPERATION' &&
18
+ node.childIds.length === 0 &&
19
+ !((node.width > 0 || node.height > 0) && hasFiniteSavedFill(node))
20
+ )
21
+ }
22
+
23
+ /** Whether auto layout places `child` in its flow: shown, not placed absolutely, and not an empty boolean. */
24
+ export function inLayoutFlow(child: SceneNode): boolean {
25
+ return child.visible && child.layoutPositioning !== 'ABSOLUTE' && !isEmptyBoolean(child)
26
+ }
27
+
28
+ /** The children an auto layout frame places in its flow, in order. */
29
+ export function flowChildren(graph: SceneGraph, frame: SceneNode): SceneNode[] {
30
+ return frame.childIds.flatMap((id) => {
31
+ const child = graph.getNode(id)
32
+ return child && inLayoutFlow(child) ? [child] : []
33
+ })
34
+ }
@@ -1,4 +1,5 @@
1
1
  export * from './aspect-ratio'
2
+ export * from './flow'
2
3
  export * from './guides'
3
4
  export * from './keywords'
4
5
  export * from './limits'
@@ -16,12 +16,18 @@ const DIRECTIONS = new Map<string, AutoLayoutDirection>([
16
16
  ['vertical', 'VERTICAL']
17
17
  ])
18
18
 
19
+ /**
20
+ * `flow-start` and `flow-end` are what `flex-start` and `flex-end` compute to, as CSS Box
21
+ * Alignment now defines them and the HTML engine reports them.
22
+ */
19
23
  const POSITIONS = new Map<string, 'MIN' | 'CENTER' | 'MAX'>([
20
24
  ['start', 'MIN'],
21
25
  ['flex-start', 'MIN'],
26
+ ['flow-start', 'MIN'],
22
27
  ['center', 'CENTER'],
23
28
  ['end', 'MAX'],
24
- ['flex-end', 'MAX']
29
+ ['flex-end', 'MAX'],
30
+ ['flow-end', 'MAX']
25
31
  ])
26
32
 
27
33
  function keyword(value: string | undefined): string | undefined {
@@ -1,5 +1,6 @@
1
1
  import type { SceneGraph } from '../graph'
2
2
  import type { LayoutSizing, SceneNode, TextAutoResize } from '../types'
3
+ import { flowChildren } from './flow'
3
4
 
4
5
  /**
5
6
  * How a node sizes along one screen axis, as Figma's `layoutSizingHorizontal` and
@@ -192,3 +193,32 @@ export function autoLayoutSizingFields(
192
193
  counterAxisSizing: horizontal ? height : width
193
194
  }
194
195
  }
196
+
197
+ /**
198
+ * The axes a frame hugs but keeps its size on, as Figma keeps them. With nothing in its flow,
199
+ * no visible layer that is not placed absolutely, it keeps every axis it hugs: a new frame keeps
200
+ * the size it was made at, and one that loses its last layer keeps the size it hugged to. On the
201
+ * counter axis it also keeps its size when every child in its flow fills that axis and none has
202
+ * content of its own to hug.
203
+ */
204
+ export function heldHugAxes(graph: SceneGraph, frame: SceneNode): ('width' | 'height')[] {
205
+ if (frame.layoutMode !== 'HORIZONTAL' && frame.layoutMode !== 'VERTICAL') return []
206
+ const [primary, counter] =
207
+ frame.layoutMode === 'HORIZONTAL'
208
+ ? (['width', 'height'] as const)
209
+ : (['height', 'width'] as const)
210
+ const hugged = [
211
+ ...(frame.primaryAxisSizing === 'HUG' ? [primary] : []),
212
+ ...(frame.counterAxisSizing === 'HUG' ? [counter] : [])
213
+ ]
214
+ const flow = flowChildren(graph, frame)
215
+ if (flow.length === 0) return hugged
216
+ const filled = flow.every(
217
+ (child) =>
218
+ child.layoutMode === 'NONE' &&
219
+ child.type !== 'TEXT' &&
220
+ (child.layoutAlignSelf === 'STRETCH' ||
221
+ (child.layoutAlignSelf === 'AUTO' && frame.counterAxisAlign === 'STRETCH'))
222
+ )
223
+ return filled && frame.counterAxisSizing === 'HUG' ? [counter] : []
224
+ }
@@ -1,3 +1,4 @@
1
+ import { isGeneratedFrame } from '../generated'
1
2
  import type { SceneNode } from '../types'
2
3
 
3
4
  /**
@@ -9,3 +10,14 @@ export function counterAxisSpacingOf(
9
10
  ): number {
10
11
  return node.counterAxisSpacing ?? node.itemSpacing
11
12
  }
13
+
14
+ /**
15
+ * The space an auto layout keeps between its items along its axis. Space between takes the place
16
+ * of the gap, as in Figma. A generated frame keeps it as the least space between its sublayers,
17
+ * as a sticky note keeps its author clear of a long body.
18
+ */
19
+ export function primaryAxisSpacingOf(
20
+ node: Pick<SceneNode, 'type' | 'primaryAxisAlign' | 'itemSpacing'>
21
+ ): number {
22
+ return node.primaryAxisAlign === 'SPACE_BETWEEN' && !isGeneratedFrame(node) ? 0 : node.itemSpacing
23
+ }