@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,11 +1,11 @@
1
- import { sha1 } from '@noble/hashes/legacy.js'
2
- import { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'
3
-
4
- import { randomHex } from '@open-pencil/std/random'
5
-
6
- import { TRANSPARENT } from '../constants'
7
- import { imagePaintHashes } from '../images'
8
- import { readAllPluginData, withAllPluginData } from '../plugin-data/field'
1
+ import {
2
+ createStillPaint,
3
+ isStillFrameCurrent,
4
+ readStillPaints,
5
+ stillContentKey,
6
+ stillPaintOf,
7
+ withStillPaints
8
+ } from '../paints/stills'
9
9
  import { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'
10
10
  import type { Fill, SceneNode } from '../types'
11
11
  import type { ShaderPaint, ShaderPreset } from './schema'
@@ -15,7 +15,7 @@ type ShaderNode = Pick<SceneNode, 'fills' | 'strokes' | 'pluginData'>
15
15
 
16
16
  /** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */
17
17
  export function readShaderPaints(node: Pick<SceneNode, 'pluginData'>): ShaderPaint[] {
18
- return readAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.shader)
18
+ return readStillPaints(node, OPEN_PENCIL_PLUGIN_DATA.shader)
19
19
  }
20
20
 
21
21
  /**
@@ -27,8 +27,7 @@ export function shaderOfPaint(
27
27
  node: Pick<SceneNode, 'pluginData'>,
28
28
  paint: Fill
29
29
  ): ShaderPaint | null {
30
- if (paint.type !== 'IMAGE' || !paint.imageHash) return null
31
- return readShaderPaints(node).find((shader) => shader.image === paint.imageHash) ?? null
30
+ return stillPaintOf(node, paint, OPEN_PENCIL_PLUGIN_DATA.shader)
32
31
  }
33
32
 
34
33
  /** Whether any paint of `node` draws a shader. */
@@ -45,56 +44,27 @@ export function withShaderPaints(
45
44
  paints: readonly Fill[],
46
45
  shaders: readonly ShaderPaint[] = []
47
46
  ): SceneNode['pluginData'] {
48
- const shown = new Set(imagePaintHashes(paints))
49
- const byImage = new Map(readShaderPaints(node).map((shader) => [shader.image, shader]))
50
- for (const shader of shaders) byImage.set(shader.image, shader)
51
- return withAllPluginData(
52
- node.pluginData,
53
- OPEN_PENCIL_PLUGIN_DATA.shader,
54
- [...byImage.values()].filter((shader) => shown.has(shader.image))
55
- )
47
+ return withStillPaints(node, paints, OPEN_PENCIL_PLUGIN_DATA.shader, shaders)
56
48
  }
57
49
 
58
- /**
59
- * A new paint that draws `preset`, and the shader entry it shows. Its image names a frame not yet
60
- * rendered, unique to this paint, so no other paint's entry claims it until the frame is drawn.
61
- */
50
+ /** A new paint that draws `preset`, and the shader entry it shows (`createStillPaint`). */
62
51
  export function createShaderPaint(preset: ShaderPreset): {
63
52
  paint: Fill
64
53
  shader: ShaderPaint
65
54
  } {
66
- const image = randomHex(20)
67
- return {
68
- paint: {
69
- type: 'IMAGE',
70
- color: TRANSPARENT,
71
- opacity: 1,
72
- visible: true,
73
- imageHash: image,
74
- imageScaleMode: 'FILL'
75
- },
76
- shader: { image, preset: structuredClone(preset) }
77
- }
55
+ const { paint, image } = createStillPaint()
56
+ return { paint, shader: { image, preset: structuredClone(preset) } }
78
57
  }
79
58
 
80
- /** A short key that tells one preset from another, which a rendered frame records. */
81
- export function shaderPresetKey(preset: ShaderPreset): string {
82
- return bytesToHex(sha1(utf8ToBytes(JSON.stringify(preset))))
83
- }
84
-
85
- /**
86
- * Whether a shader's frame was rendered for its preset at the size `node` has now, so undoing a
87
- * preset change after reopening the document does not keep a frame of the newer preset.
88
- */
59
+ /** Whether a shader's frame was rendered for its preset at the size `node` has now. */
89
60
  export function isShaderFrameCurrent(
90
61
  shader: ShaderPaint,
91
62
  size: { width: number; height: number }
92
63
  ): boolean {
93
64
  const { frame } = shader
94
- return (
95
- frame !== undefined &&
96
- frame.preset === shaderPresetKey(shader.preset) &&
97
- Math.round(frame.width) === Math.round(size.width) &&
98
- Math.round(frame.height) === Math.round(size.height)
65
+ return isStillFrameCurrent(
66
+ frame && { ...frame, key: frame.preset },
67
+ stillContentKey(shader.preset),
68
+ size
99
69
  )
100
70
  }
@@ -39,7 +39,7 @@ export const shaderPaintSchema = v.object({
39
39
  v.object({
40
40
  width: v.pipe(v.number(), v.finite(), v.minValue(0)),
41
41
  height: v.pipe(v.number(), v.finite(), v.minValue(0)),
42
- /** The preset's key (`shaderPresetKey`) when the frame was rendered. */
42
+ /** The preset's key (`stillContentKey`) when the frame was rendered. */
43
43
  preset: v.pipe(v.string(), v.nonEmpty())
44
44
  })
45
45
  )
@@ -0,0 +1,175 @@
1
+ import { pointAt, subPiece, type ConnectorPiece } from '../connectors/pieces'
2
+ import type { PolygonOutlineCommand } from '../polygon'
3
+ import type { Vector } from '../primitives'
4
+
5
+ /**
6
+ * How far above the bottom a document's wave meets its left and right sides, and how far its
7
+ * crest rises, as FigJam draws it at every size. Below FigJam's least height the wave shrinks
8
+ * with the page.
9
+ */
10
+ const WAVE_LEFT = 16
11
+ const WAVE_RIGHT = 15
12
+ const WAVE_CREST = 31
13
+ const LEAST_HEIGHT = 80
14
+ /** Bezier handle length for a quarter circle. */
15
+ const KAPPA = 0.5522847498
16
+ /** Steps that measure a stretch of curve, and halvings that find where a length ends. */
17
+ const LENGTH_STEPS = 32
18
+ const SEARCH_STEPS = 30
19
+ const UP: Vector = { x: 0, y: -1 }
20
+
21
+ function piece(from: Vector, c1: Vector, c2: Vector, to: Vector): ConnectorPiece {
22
+ return {
23
+ from,
24
+ to,
25
+ handleFrom: { x: c1.x - from.x, y: c1.y - from.y },
26
+ handleTo: { x: c2.x - to.x, y: c2.y - to.y }
27
+ }
28
+ }
29
+
30
+ function reversed(curve: ConnectorPiece): ConnectorPiece {
31
+ return { from: curve.to, to: curve.from, handleFrom: curve.handleTo, handleTo: curve.handleFrom }
32
+ }
33
+
34
+ /** The bottom wave, right to left: up from the right side to its crest, down to its trough, up to the left side. */
35
+ function wave(w: number, h: number): ConnectorPiece[] {
36
+ const scale = Math.min(1, h / LEAST_HEIGHT)
37
+ const left = { x: 0, y: h - WAVE_LEFT * scale }
38
+ const trough = { x: (w * 13) / 48, y: h }
39
+ const crest = { x: (w * 17) / 24, y: h - WAVE_CREST * scale }
40
+ const right = { x: w, y: h - WAVE_RIGHT * scale }
41
+ return [
42
+ piece(right, right, { x: w * 0.854555, y: crest.y }, crest),
43
+ piece(crest, { x: w * 0.5625, y: crest.y }, { x: w * 0.413004, y: h }, trough),
44
+ piece(trough, { x: (w * 13) / 96, y: h }, left, left)
45
+ ]
46
+ }
47
+
48
+ function unit(v: Vector): Vector {
49
+ const length = Math.hypot(v.x, v.y)
50
+ return length > 0 ? { x: v.x / length, y: v.y / length } : { x: 0, y: 0 }
51
+ }
52
+
53
+ /** The direction a curve leaves its start in, past handles of no length. */
54
+ function leaving(curve: ConnectorPiece): Vector {
55
+ const { from, to, handleFrom, handleTo } = curve
56
+ const c1 = { x: from.x + handleFrom.x, y: from.y + handleFrom.y }
57
+ const c2 = { x: to.x + handleTo.x, y: to.y + handleTo.y }
58
+ for (const point of [c1, c2, to]) {
59
+ const direction = unit({ x: point.x - from.x, y: point.y - from.y })
60
+ if (direction.x !== 0 || direction.y !== 0) return direction
61
+ }
62
+ return { x: 0, y: 0 }
63
+ }
64
+
65
+ /** The length of a curve from its start to `t`. */
66
+ function lengthTo(curve: ConnectorPiece, t: number): number {
67
+ let length = 0
68
+ let last = curve.from
69
+ for (let step = 1; step <= LENGTH_STEPS; step++) {
70
+ const point = pointAt(curve, (t * step) / LENGTH_STEPS)
71
+ length += Math.hypot(point.x - last.x, point.y - last.y)
72
+ last = point
73
+ }
74
+ return length
75
+ }
76
+
77
+ /** The parameter at `distance` along a curve from its start, by its length. */
78
+ function parameterAt(curve: ConnectorPiece, distance: number): number {
79
+ let low = 0
80
+ let high = 1
81
+ for (let step = 0; step < SEARCH_STEPS; step++) {
82
+ const middle = (low + high) / 2
83
+ if (lengthTo(curve, middle) < distance) low = middle
84
+ else high = middle
85
+ }
86
+ return (low + high) / 2
87
+ }
88
+
89
+ /**
90
+ * How far a corner of `radius` trims each side of a vertex whose sides leave it along `a` and
91
+ * `b`, and how long its handles are. FigJam fits a circle to a blunt corner; a sharp one it trims
92
+ * by the radius alone, with a quarter circle's handles.
93
+ */
94
+ function corner(a: Vector, b: Vector, radius: number): { trim: number; handle: number } {
95
+ const angle = Math.acos(Math.max(-1, Math.min(1, a.x * b.x + a.y * b.y)))
96
+ if (angle <= Math.PI / 2) return { trim: radius, handle: radius * KAPPA }
97
+ return {
98
+ trim: radius / Math.tan(angle / 2),
99
+ handle: (4 / 3) * Math.tan((Math.PI - angle) / 4) * radius
100
+ }
101
+ }
102
+
103
+ function curveTo(c1: Vector, c2: Vector, to: Vector): PolygonOutlineCommand {
104
+ return { type: 'C', x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: to.x, y: to.y }
105
+ }
106
+
107
+ function pieceTo(curve: ConnectorPiece): PolygonOutlineCommand {
108
+ const { from, to, handleFrom, handleTo } = curve
109
+ return curveTo(
110
+ { x: from.x + handleFrom.x, y: from.y + handleFrom.y },
111
+ { x: to.x + handleTo.x, y: to.y + handleTo.y },
112
+ to
113
+ )
114
+ }
115
+
116
+ /**
117
+ * A single document as FigJam draws it: a page whose bottom is a wave of fixed height, every
118
+ * corner rounded to `radius`, those where the wave meets the sides included.
119
+ */
120
+ export function documentOutline(w: number, h: number, radius: number): PolygonOutlineCommand[] {
121
+ const [fromRight, middle, toLeft] = wave(w, h)
122
+ const r = Math.max(0, Math.min(radius, w / 2, h / 2))
123
+ const k = r * (1 - KAPPA)
124
+ const rightSide = fromRight.from
125
+ const leftSide = toLeft.to
126
+ const intoLeft = reversed(toLeft)
127
+
128
+ // Each bottom corner trims the side and the wave by the same length, the side no further than
129
+ // its top corner.
130
+ const right = corner(UP, leaving(fromRight), r)
131
+ const left = corner(UP, leaving(intoLeft), r)
132
+ const rightTrim = Math.min(right.trim, (rightSide.y - r) / 2)
133
+ const leftTrim = Math.min(left.trim, (leftSide.y - r) / 2)
134
+ // A corner trimmed short of its radius shortens its handles with it.
135
+ const rightHandle = right.trim > 0 ? (right.handle * rightTrim) / right.trim : 0
136
+ const leftHandle = left.trim > 0 ? (left.handle * leftTrim) / left.trim : 0
137
+ const first = r > 0 ? subPiece(fromRight, parameterAt(fromRight, rightTrim), 1) : fromRight
138
+ const last = r > 0 ? subPiece(toLeft, 0, 1 - parameterAt(intoLeft, leftTrim)) : toLeft
139
+ const rightEnd = { x: w, y: rightSide.y - rightTrim }
140
+ const leftEnd = { x: 0, y: leftSide.y - leftTrim }
141
+
142
+ const commands: PolygonOutlineCommand[] = [
143
+ { type: 'M', x: r, y: 0 },
144
+ { type: 'L', x: w - r, y: 0 },
145
+ curveTo({ x: w - k, y: 0 }, { x: w, y: k }, { x: w, y: r }),
146
+ { type: 'L', x: rightEnd.x, y: rightEnd.y }
147
+ ]
148
+ if (r > 0) {
149
+ const back = unit({ x: -first.handleFrom.x, y: -first.handleFrom.y })
150
+ commands.push(
151
+ curveTo(
152
+ { x: w, y: rightEnd.y + rightHandle },
153
+ { x: first.from.x + back.x * rightHandle, y: first.from.y + back.y * rightHandle },
154
+ first.from
155
+ )
156
+ )
157
+ }
158
+ commands.push(pieceTo(first), pieceTo(middle), pieceTo(last))
159
+ if (r > 0) {
160
+ const on = unit({ x: -last.handleTo.x, y: -last.handleTo.y })
161
+ commands.push(
162
+ curveTo(
163
+ { x: last.to.x + on.x * leftHandle, y: last.to.y + on.y * leftHandle },
164
+ { x: 0, y: leftEnd.y + leftHandle },
165
+ leftEnd
166
+ )
167
+ )
168
+ }
169
+ commands.push(
170
+ { type: 'L', x: 0, y: r },
171
+ curveTo({ x: 0, y: k }, { x: k, y: 0 }, { x: r, y: 0 }),
172
+ { type: 'Z' }
173
+ )
174
+ return commands
175
+ }
@@ -1,4 +1,7 @@
1
+ import { drawsStroke } from '../geometry'
1
2
  import type { PolygonOutlineCommand } from '../polygon'
3
+ import type { SceneNode } from '../types'
4
+ import { documentOutline } from './document'
2
5
  import { databaseCap } from './fit'
3
6
  import type { ShapeWithTextType } from './kinds'
4
7
 
@@ -12,6 +15,20 @@ export interface ShapeWithTextGeometry {
12
15
  /** Bezier handle length for a quarter ellipse. */
13
16
  const KAPPA = 0.5522847498
14
17
 
18
+ /**
19
+ * The band FigJam cuts out of a shape's fill along its outline and inner lines when no stroke
20
+ * draws them, so a database still shows its rim: half of it insets the outline.
21
+ */
22
+ export const SHAPE_WITH_TEXT_LINE_GAP = 3
23
+
24
+ /** A folder's tab: its height, and how far its base reaches past the middle of the box. */
25
+ const FOLDER_TAB_HEIGHT = 44
26
+ const FOLDER_TAB_OVERHANG = 13
27
+ /** How far the tab's sides lean in over its full height. */
28
+ const FOLDER_TAB_SLANT = 18
29
+ /** How far a multiple document's front page sits right of and below its back page. */
30
+ const DOCUMENT_OFFSET = 16
31
+
15
32
  type Point = readonly [number, number]
16
33
 
17
34
  function polygon(points: Point[]): PolygonOutlineCommand[] {
@@ -136,7 +153,7 @@ const plain = (outline: PolygonOutlineCommand[]): ShapeWithTextGeometry => ({
136
153
  details: []
137
154
  })
138
155
 
139
- type Builder = (w: number, h: number, min: number) => ShapeWithTextGeometry
156
+ type Builder = (w: number, h: number, min: number, radius: number) => ShapeWithTextGeometry
140
157
 
141
158
  /** How far a parallelogram's sides lean: FigJam leans them with the height, not the width. */
142
159
  export function parallelogramSlant(w: number, h: number): number {
@@ -260,18 +277,27 @@ const BUILDERS: Record<ShapeWithTextType, Builder> = {
260
277
  details: [...line([w - f, 0], [w - f, f]), { type: 'L', x: w, y: f }]
261
278
  }
262
279
  },
263
- ENG_FOLDER: (w, h) => {
264
- const tab = Math.min(h * 0.18, w * 0.2)
265
- return plain(
266
- polygon([
267
- [0, 0],
268
- [w * 0.4, 0],
269
- [w * 0.4 + tab, tab],
270
- [w, tab],
271
- [w, h],
272
- [0, h]
273
- ])
274
- )
280
+ // A tab on the left of the box above a body; the line between them is the body's top edge.
281
+ // The corners where tab and body meet stay sharp.
282
+ ENG_FOLDER: (w, h, _min, radius) => {
283
+ const tab = Math.min(FOLDER_TAB_HEIGHT, h)
284
+ const base = Math.min(w / 2 + FOLDER_TAB_OVERHANG, w)
285
+ const slant = Math.min((FOLDER_TAB_SLANT * tab) / FOLDER_TAB_HEIGHT, base / 2)
286
+ return {
287
+ outline: roundedPolygon(
288
+ [
289
+ [0, h],
290
+ [0, tab],
291
+ [slant, 0],
292
+ [base - slant, 0],
293
+ [base, tab],
294
+ [w, tab],
295
+ [w, h]
296
+ ],
297
+ [radius, 0, radius, radius, 0, radius, radius]
298
+ ),
299
+ details: line([0, tab], [base, tab])
300
+ }
275
301
  },
276
302
  TRAPEZOID: (w, h) => {
277
303
  const s = Math.min(w * 0.2, h)
@@ -297,19 +323,36 @@ const BUILDERS: Record<ShapeWithTextType, Builder> = {
297
323
  curve(w * 0.25, h * 0.9, 0, h * 0.75, 0, h * 0.45),
298
324
  { type: 'Z' }
299
325
  ]),
300
- DOCUMENT_SINGLE: (w, h) => plain(documentPage(0, 0, w, h)),
301
- DOCUMENT_MULTIPLE: (w, h, min) => {
302
- const o = min * 0.06
326
+ DOCUMENT_SINGLE: (w, h, _min, radius) => plain(documentOutline(w, h, radius)),
327
+ // A back page with a front page over its lower right; the front page's top and left edges,
328
+ // where it lies over the back one, are the inner lines.
329
+ DOCUMENT_MULTIPLE: (w, h, _min, radius) => {
330
+ const o = Math.min(DOCUMENT_OFFSET, w / 4, h / 4)
331
+ const front = documentPage(o, o, w - o, h - o)
332
+ const wave = front.filter((command) => command.type === 'C')
333
+ const base = wave.at(-1)?.y ?? h
334
+ // The back page ends on the front page's left side, sloping down to it.
335
+ const join = Math.min(h - 2 * o, base)
336
+ const outline = roundedPolygon(
337
+ [
338
+ [0, 0],
339
+ [w - o, 0],
340
+ [w - o, o],
341
+ [w, o],
342
+ [w, base],
343
+ [o, base],
344
+ [o, join],
345
+ [0, join - o / 4]
346
+ ],
347
+ [radius, radius, 0, radius, 0, 0, 0, radius]
348
+ )
349
+ // The straight edge along the bottom becomes the front page's wave.
350
+ const bottom = outline.findIndex(
351
+ (command) => command.type === 'L' && command.x === o && command.y === base
352
+ )
303
353
  return {
304
- outline: documentPage(0, o * 2, w - o * 2, h - o * 2),
305
- details: [
306
- ...line([o, o * 2], [o, o]),
307
- { type: 'L', x: w - o, y: o },
308
- { type: 'L', x: w - o, y: h - o * 2 },
309
- ...line([o * 2, o], [o * 2, 0]),
310
- { type: 'L', x: w, y: 0 },
311
- { type: 'L', x: w, y: h - o * 3 }
312
- ]
354
+ outline: [...outline.slice(0, bottom), ...wave, ...outline.slice(bottom + 1)],
355
+ details: [...line([w - o, o], [o, o]), { type: 'L', x: o, y: join }]
313
356
  }
314
357
  },
315
358
  MANUAL_INPUT: (w, h) =>
@@ -451,8 +494,25 @@ function roundCorners(commands: PolygonOutlineCommand[], radius: number): Polygo
451
494
  const points: Point[] = []
452
495
  for (const command of commands) if (command.type !== 'Z') points.push([command.x, command.y])
453
496
  if (points.length < 3) return commands
497
+ return roundedPolygon(
498
+ points,
499
+ points.map(() => radius)
500
+ )
501
+ }
502
+
503
+ /**
504
+ * The closed polygon through `points` with the corner at each rounded to its own radius in
505
+ * `radii`, shortened where an edge is too short for it; a corner with radius 0 stays sharp.
506
+ */
507
+ function roundedPolygon(points: Point[], radii: number[]): PolygonOutlineCommand[] {
454
508
  const rounded: PolygonOutlineCommand[] = []
455
509
  points.forEach((vertex, index) => {
510
+ const radius = radii[index] ?? 0
511
+ const type = index === 0 ? 'M' : 'L'
512
+ if (radius <= 0) {
513
+ rounded.push({ type, x: vertex[0], y: vertex[1] })
514
+ return
515
+ }
456
516
  const before = points[(index + points.length - 1) % points.length]
457
517
  const after = points[(index + 1) % points.length]
458
518
  const toward = (to: Point): Point => {
@@ -462,7 +522,7 @@ function roundCorners(commands: PolygonOutlineCommand[], radius: number): Polygo
462
522
  }
463
523
  const [inX, inY] = toward(before)
464
524
  const [outX, outY] = toward(after)
465
- rounded.push({ type: index === 0 ? 'M' : 'L', x: inX, y: inY })
525
+ rounded.push({ type, x: inX, y: inY })
466
526
  rounded.push(
467
527
  curve(
468
528
  inX + (vertex[0] - inX) * KAPPA,
@@ -491,6 +551,18 @@ export function shapeWithTextGeometry(
491
551
  ): ShapeWithTextGeometry {
492
552
  const w = Math.max(0, width)
493
553
  const h = Math.max(0, height)
494
- const geometry = BUILDERS[type](w, h, Math.min(w, h))
554
+ const geometry = BUILDERS[type](w, h, Math.min(w, h), cornerRadius)
495
555
  return { ...geometry, outline: roundCorners(geometry.outline, cornerRadius) }
496
556
  }
557
+
558
+ /**
559
+ * Whether the shape's fill has its outline and inner lines cut out of it, as FigJam draws a shape
560
+ * with inner lines, such as a database, when no stroke draws them: it has inner lines and no
561
+ * visible stroke.
562
+ */
563
+ export function shapeWithTextCutsFill(
564
+ node: Pick<SceneNode, 'type' | 'shapeWithTextType' | 'width' | 'height' | 'strokes'>
565
+ ): boolean {
566
+ if (node.strokes.some((stroke) => stroke.opacity > 0 && drawsStroke(node, stroke))) return false
567
+ return shapeWithTextGeometry(node.shapeWithTextType, node.width, node.height).details.length > 0
568
+ }
@@ -0,0 +1,106 @@
1
+ import type { SceneNode, SharedStyleType } from './types'
2
+
3
+ type NodeMap = ReadonlyMap<string, SceneNode>
4
+
5
+ const INDEX_KEYS: ReadonlySet<string> = new Set(['source', 'sharedStyleType'])
6
+
7
+ function restyles(changes: Partial<SceneNode>): boolean {
8
+ for (const key of INDEX_KEYS) {
9
+ if (key in changes) {
10
+ return true
11
+ }
12
+ }
13
+ return false
14
+ }
15
+
16
+ function styleKey(node: SceneNode): string | null {
17
+ return node.sharedStyleType && node.source.id ? node.source.id : null
18
+ }
19
+
20
+ export class SharedStyleIndex {
21
+ private readonly nodeIdsByStyleId = new Map<string, Set<string>>()
22
+ private indexed: NodeMap | null = null
23
+
24
+ constructor(private readonly nodes: () => NodeMap) {}
25
+
26
+ styleNode(styleId: string, type: SharedStyleType): SceneNode | undefined {
27
+ if (!styleId) {
28
+ return undefined
29
+ }
30
+ const nodes = this.current()
31
+ for (const id of this.nodeIdsByStyleId.get(styleId) ?? []) {
32
+ const node = nodes.get(id)
33
+ if (node?.sharedStyleType === type && node.source.id === styleId) {
34
+ return node
35
+ }
36
+ }
37
+ return undefined
38
+ }
39
+
40
+ added(node: SceneNode): void {
41
+ if (this.indexed) {
42
+ this.add(node)
43
+ }
44
+ }
45
+
46
+ removed(node: SceneNode): void {
47
+ if (this.indexed) {
48
+ this.remove(node)
49
+ }
50
+ }
51
+
52
+ willChange(node: SceneNode, changes: Partial<SceneNode>): boolean {
53
+ const restyled = restyles(changes)
54
+ if (restyled) {
55
+ this.removed(node)
56
+ }
57
+ return restyled
58
+ }
59
+
60
+ didChange(node: SceneNode, restyled: boolean): void {
61
+ if (restyled) {
62
+ this.added(node)
63
+ }
64
+ }
65
+
66
+ invalidate(): void {
67
+ this.indexed = null
68
+ }
69
+
70
+ private current(): NodeMap {
71
+ const nodes = this.nodes()
72
+ if (this.indexed !== nodes) {
73
+ this.nodeIdsByStyleId.clear()
74
+ for (const node of nodes.values()) {
75
+ this.add(node)
76
+ }
77
+ this.indexed = nodes
78
+ }
79
+ return nodes
80
+ }
81
+
82
+ private add(node: SceneNode): void {
83
+ const key = styleKey(node)
84
+ if (!key) {
85
+ return
86
+ }
87
+ let ids = this.nodeIdsByStyleId.get(key)
88
+ if (!ids) {
89
+ ids = new Set()
90
+ this.nodeIdsByStyleId.set(key, ids)
91
+ }
92
+ ids.add(node.id)
93
+ }
94
+
95
+ private remove(node: SceneNode): void {
96
+ const key = styleKey(node)
97
+ const ids = key ? this.nodeIdsByStyleId.get(key) : undefined
98
+ if (!key || !ids) {
99
+ return
100
+ }
101
+ ids.delete(node.id)
102
+ if (ids.size === 0) {
103
+ this.nodeIdsByStyleId.delete(key)
104
+ }
105
+ }
106
+ }
@@ -6,6 +6,7 @@ import { BLACK } from './constants'
6
6
  import { copyEffects, copyFills, copyLayoutGrids } from './copy'
7
7
  import type { SceneGraph } from './graph'
8
8
  import { newStrokeGeometry } from './node-defaults'
9
+ import { scaledTextStyleLengths } from './scaling/node'
9
10
  import { STROKE_LINE_KEYS } from './strokes'
10
11
  import { styleRunReferences } from './text/references'
11
12
  import type {
@@ -157,19 +158,6 @@ export function styleDetachmentChanges(
157
158
  return next
158
159
  }
159
160
 
160
- /** The node of the shared style with `id`, when the document holds one of `type`. */
161
- export function findSharedStyle(
162
- graph: SceneGraph,
163
- id: string,
164
- type: SharedStyleType
165
- ): SceneNode | undefined {
166
- if (!id) return undefined
167
- for (const node of graph.getAllNodes()) {
168
- if (node.sharedStyleType === type && node.source.id === id) return node
169
- }
170
- return undefined
171
- }
172
-
173
161
  /** A new local style's ID, in the shape Figma gives one: `S:` and a 40-digit hex key. */
174
162
  export function newSharedStyleId(): string {
175
163
  return `S:${randomHex(20)},`
@@ -225,10 +213,29 @@ export function sharedStylePatch(
225
213
  else if (kind === 'stroke') patch.strokes = strokesFromStyle(target, style)
226
214
  else if (kind === 'effect') patch.effects = copyEffects(style.effects)
227
215
  else if (kind === 'grid') patch.layoutGrids = copyLayoutGrids(style.layoutGrids)
228
- else Object.assign(patch, structuredClone(pick(style, SHARED_STYLE_FIELDS.text)))
216
+ else {
217
+ const fields = structuredClone(pick(style, SHARED_STYLE_FIELDS.text))
218
+ Object.assign(patch, scaledTextStyleLengths(fields, target.componentScale))
219
+ // A text starting to use a text style lets go of its own bindings of the style's fields.
220
+ const dropped =
221
+ target.textStyleId === styleId
222
+ ? []
223
+ : Object.keys(target.boundVariables).filter(isTextStyleField)
224
+ if (dropped.length > 0) {
225
+ patch.boundVariables = omit(target.boundVariables, dropped)
226
+ patch.variableBindingScales = omit(target.variableBindingScales, dropped)
227
+ }
228
+ }
229
229
  return patch
230
230
  }
231
231
 
232
+ const TEXT_STYLE_FIELD_SET: ReadonlySet<string> = new Set(SHARED_STYLE_FIELDS.text)
233
+
234
+ /** Whether a text style sets `field`, so a text or range starting to use it lets its binding go. */
235
+ export function isTextStyleField(field: string): boolean {
236
+ return TEXT_STYLE_FIELD_SET.has(field)
237
+ }
238
+
232
239
  /** A layer leaving a shared style: it keeps the style's values, without the reference. */
233
240
  export function sharedStyleDetachPatch(kind: SharedStyleKind): Partial<SceneNode> {
234
241
  return { [STYLE_REF_KEYS[kind]]: null }