@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,37 +1,27 @@
1
1
  export * from './contrast'
2
2
  export * from './management'
3
3
  export { normalizeColor } from './normalize'
4
+ export { colorProfileSchema, EXPORT_COLOR_PROFILE_NAMES, exportColorProfileSchema } from './schema'
4
5
  export * from './okhcl'
5
6
 
6
- import { parse, formatHex, formatHex8, formatRgb, converter, differenceEuclidean } from 'culori'
7
+ import { formatHex, formatHex8, formatRgb, differenceEuclidean } from 'culori'
7
8
 
8
- import { BLACK } from '../constants'
9
9
  import type { Color } from '../primitives'
10
-
11
- const toRGB = converter('rgb')
12
-
13
- /** A CSS color, or null when `input` is not one. */
14
- export function tryParseColor(input: string): Color | null {
15
- const parsed = parse(input)
16
- if (!parsed) return null
17
- const rgb = toRGB(parsed)
18
- return {
19
- r: rgb.r,
20
- g: rgb.g,
21
- b: rgb.b,
22
- a: parsed.alpha ?? 1
23
- }
24
- }
25
-
26
- /** A CSS color, or black when `input` is not one. */
27
- export function parseColor(input: string): Color {
28
- return tryParseColor(input) ?? { ...BLACK }
29
- }
10
+ import type { ColorProfile } from '../types'
11
+ import { convertColor, parseColor } from './management'
30
12
 
31
13
  export function colorToHex(color: Color): string {
32
14
  return formatHex({ mode: 'rgb', r: color.r, g: color.g, b: color.b }).toUpperCase()
33
15
  }
34
16
 
17
+ /**
18
+ * `color`, whose components are in `profile`, as the sRGB hex code tools display: hex holds sRGB
19
+ * only, so a color outside it is brought inside by reducing chroma, not clipped.
20
+ */
21
+ export function colorToSRGBHex(color: Color, profile: ColorProfile): string {
22
+ return colorToHex(convertColor(color, profile, 'srgb', 'map'))
23
+ }
24
+
35
25
  export function colorToHex8(color: Color, alpha?: number): string {
36
26
  const a = alpha ?? color.a
37
27
  if (a >= 1) return colorToHex(color)
@@ -66,8 +56,9 @@ export function rgba255ToColor(r: number, g: number, b: number, a = 1): Color {
66
56
  return { r: r / 255, g: g / 255, b: b / 255, a }
67
57
  }
68
58
 
69
- export function colorToFill(color: string | Color) {
70
- const rgba = typeof color === 'string' ? parseColor(color) : color
59
+ /** A solid paint of `color`, a CSS color read into `profile` or components already in it. */
60
+ export function colorToFill(color: string | Color, profile: ColorProfile = 'srgb') {
61
+ const rgba = typeof color === 'string' ? parseColor(color, profile) : color
71
62
  return {
72
63
  type: 'SOLID' as const,
73
64
  color: { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a },
@@ -1,154 +1,153 @@
1
- import { converter, formatCss, formatRgb, inGamut, parse, toGamut } from 'culori'
1
+ import { converter, formatCss, formatRgb, parse, toGamut, type Color as CuloriColor } from 'culori'
2
2
 
3
+ import { BLACK } from '../constants'
3
4
  import type { Color } from '../primitives'
4
- import type { DocumentColorSpace, Fill, SceneNode, Stroke } from '../types'
5
+ import type { ColorProfile } from '../types'
5
6
  import { normalizeColor } from './normalize'
6
- import { getFillOkHCL, getStrokeOkHCL, type OkHCLColor } from './okhcl'
7
-
8
- export type RenderColorSpace = 'srgb' | 'display-p3'
9
- export type ColorIntentSpace = 'oklch' | 'srgb'
10
-
11
- export interface ColorPreviewOptions {
12
- colorSpace?: RenderColorSpace
13
- documentColorSpace?: DocumentColorSpace
14
- }
15
-
16
- export interface ResolvedRenderColor {
17
- color: Color
18
- cssColor: string
19
- sourceSpace: ColorIntentSpace
20
- targetSpace: RenderColorSpace
21
- clipped: boolean
22
- }
23
-
24
- const DEFAULT_COLOR_SPACE: RenderColorSpace = 'srgb'
25
7
 
8
+ const toLinearSRGB = converter('lrgb')
26
9
  const toRGB = converter('rgb')
27
10
  const toP3 = converter('p3')
28
11
  const toDisplayableRGB = toGamut('rgb', 'oklch')
29
12
  const toDisplayableP3 = toGamut('p3', 'oklch')
30
- const isDisplayableRGB = inGamut('rgb')
31
- const isDisplayableP3 = inGamut('p3')
32
13
 
33
- function normalizeOkLCH(color: OkHCLColor) {
34
- const hue = color.h % 360
14
+ /**
15
+ * How far past 0 or 1 a component may land and still count as inside a gamut. Conversions round
16
+ * off: P3 red read through OKLCH comes back with a blue of -1e-15, which is the same color.
17
+ */
18
+ const GAMUT_TOLERANCE = 1e-6
19
+
20
+ /** Whether `color`'s components fit 0 to 1, give or take round-off. */
21
+ export function fitsGamut(color: Pick<Color, 'r' | 'g' | 'b'>): boolean {
22
+ return [color.r, color.g, color.b].every(
23
+ (channel) => channel >= -GAMUT_TOLERANCE && channel <= 1 + GAMUT_TOLERANCE
24
+ )
25
+ }
26
+
27
+ /** `color`, a culori color in any space, as components in `profile`, past 0 and 1 if need be. */
28
+ function exactlyInProfile(color: CuloriColor, profile: ColorProfile): Color {
29
+ const { r, g, b } = profile === 'display-p3' ? toP3(color) : toRGB(color)
30
+ return { r, g, b, a: color.alpha ?? 1 }
31
+ }
32
+
33
+ /**
34
+ * `color`, a culori color in any space, as components in `profile`, brought inside it the way CSS
35
+ * maps out-of-gamut colors, by reducing chroma in OKLCH so lightness and hue hold, and whether it
36
+ * had to be. A color inside already keeps its components, as mapping it would shift them by float
37
+ * noise; one on the gamut's edge, as every saturated primary is, counts as inside despite
38
+ * round-off. A missing (`none`) component reads as zero.
39
+ */
40
+ export function fitIntoProfile(
41
+ color: CuloriColor,
42
+ profile: ColorProfile
43
+ ): { color: Color; clipped: boolean } {
44
+ const exact = normalizeColor(exactlyInProfile(color, profile))
45
+ const clipped = !fitsGamut(exact)
46
+ const p3 = profile === 'display-p3'
47
+ const inside = clipped
48
+ ? normalizeColor(
49
+ exactlyInProfile(p3 ? toDisplayableP3(color) : toDisplayableRGB(color), profile)
50
+ )
51
+ : exact
52
+ const clamp = (channel: number) => Math.min(1, Math.max(0, channel))
35
53
  return {
36
- mode: 'oklch' as const,
37
- l: Math.max(0, Math.min(1, color.l)),
38
- c: Math.max(0, color.c),
39
- h: hue < 0 ? hue + 360 : hue,
40
- alpha: Math.max(0, Math.min(1, color.a ?? 1))
54
+ color: { r: clamp(inside.r), g: clamp(inside.g), b: clamp(inside.b), a: color.alpha ?? 1 },
55
+ clipped
41
56
  }
42
57
  }
43
58
 
59
+ function insideProfile(color: CuloriColor, profile: ColorProfile): Color {
60
+ return fitIntoProfile(color, profile).color
61
+ }
62
+
63
+ function culoriColor(color: Color, profile: ColorProfile): CuloriColor {
64
+ const mode = profile === 'display-p3' ? 'p3' : 'rgb'
65
+ return { mode, r: color.r, g: color.g, b: color.b, alpha: color.a }
66
+ }
67
+
44
68
  /**
45
- * Numbers are stored in the document's profile, so painting into a surface with a different
46
- * profile has to convert them. Same profile means no work, which is the common case.
69
+ * What to do with a color the target profile cannot show: `extend` keeps its components past 0
70
+ * and 1, for a renderer such as Skia that takes extended sRGB; `map` brings it inside by reducing
71
+ * chroma in OKLCH, as CSS maps out-of-gamut colors, keeping its lightness and hue.
47
72
  */
48
- function convertComponents(color: Color, from: RenderColorSpace, to: RenderColorSpace): Color {
73
+ export type GamutHandling = 'extend' | 'map'
74
+
75
+ /** `color`, whose components are in `from`, as the components in `to` that show the same color. */
76
+ export function convertColor(
77
+ color: Color,
78
+ from: ColorProfile,
79
+ to: ColorProfile,
80
+ gamut: GamutHandling = 'extend'
81
+ ): Color {
49
82
  if (from === to) return color
50
- const source =
51
- from === 'display-p3'
52
- ? { mode: 'p3' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }
53
- : { mode: 'rgb' as const, r: color.r, g: color.g, b: color.b, alpha: color.a }
54
- const converted = to === 'display-p3' ? toP3(source) : toRGB(source)
55
- return normalizeColor({
56
- r: converted.r,
57
- g: converted.g,
58
- b: converted.b,
59
- a: converted.alpha ?? color.a
60
- })
83
+ const source = culoriColor(color, from)
84
+ return gamut === 'extend' ? exactlyInProfile(source, to) : insideProfile(source, to)
61
85
  }
62
86
 
63
- function isOutsideGamut(color: Color, space: RenderColorSpace): boolean {
64
- if (space === 'display-p3') {
65
- return !isDisplayableP3({ mode: 'p3', r: color.r, g: color.g, b: color.b, alpha: color.a })
87
+ /**
88
+ * `color`, whose components are in `profile`, as the sRGB components of the same color: past 0 and
89
+ * 1 where it lies outside sRGB. Skia takes colors this way and converts them into the space of
90
+ * whatever it draws on, so a wide-gamut color reaches it whole.
91
+ */
92
+ export function toExtendedSRGB(color: Color, profile: ColorProfile): Color {
93
+ if (profile === 'srgb') return color
94
+ // Renderers call this for every paint they draw, so it skips culori's color objects: Display P3
95
+ // shares sRGB's transfer curve, leaving one matrix between the linear components.
96
+ // Indexed reads of a plain array: destructuring costs more than the conversion.
97
+ const m = P3_TO_LINEAR_SRGB
98
+ const r = decodeSRGB(color.r)
99
+ const g = decodeSRGB(color.g)
100
+ const b = decodeSRGB(color.b)
101
+ return {
102
+ r: encodeSRGB(m[0] * r + m[1] * g + m[2] * b),
103
+ g: encodeSRGB(m[3] * r + m[4] * g + m[5] * b),
104
+ b: encodeSRGB(m[6] * r + m[7] * g + m[8] * b),
105
+ a: color.a
66
106
  }
67
- return !isDisplayableRGB({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })
68
107
  }
69
108
 
70
- function resolveTargetSpace(options?: ColorPreviewOptions): RenderColorSpace {
71
- return options?.colorSpace ?? options?.documentColorSpace ?? DEFAULT_COLOR_SPACE
109
+ /** The sRGB transfer curve, mirrored below zero as extended sRGB and culori's `lrgb` take it. */
110
+ function decodeSRGB(channel: number): number {
111
+ const magnitude = Math.abs(channel)
112
+ if (magnitude <= 0.04045) return channel / 12.92
113
+ return (Math.sign(channel) || 1) * ((magnitude + 0.055) / 1.055) ** 2.4
72
114
  }
73
115
 
74
- function formatCSSForTarget(color: Color, targetSpace: RenderColorSpace): string {
75
- if (targetSpace === 'display-p3') {
76
- const p3 = toP3({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })
77
- return formatCss({
78
- mode: 'p3',
79
- r: p3.r,
80
- g: p3.g,
81
- b: p3.b,
82
- alpha: p3.alpha ?? color.a
83
- })
84
- }
85
-
86
- return formatRgb({
87
- mode: 'rgb',
88
- r: color.r,
89
- g: color.g,
90
- b: color.b,
91
- alpha: color.a
92
- })
116
+ function encodeSRGB(channel: number): number {
117
+ const magnitude = Math.abs(channel)
118
+ if (magnitude <= 0.0031308) return channel * 12.92
119
+ return (Math.sign(channel) || 1) * (1.055 * magnitude ** (1 / 2.4) - 0.055)
93
120
  }
94
121
 
95
- export function resolveOkHCLForPreview(
96
- color: OkHCLColor,
97
- options?: ColorPreviewOptions
98
- ): ResolvedRenderColor {
99
- const oklch = normalizeOkLCH(color)
100
- const targetSpace = resolveTargetSpace(options)
101
-
102
- if (targetSpace === 'display-p3') {
103
- const clipped = !isDisplayableP3(oklch)
104
- const p3 = toP3(toDisplayableP3(oklch))
105
- // P3 coordinates, because the caller asked for a P3 target.
106
- const resolved = normalizeColor({
107
- r: p3.r,
108
- g: p3.g,
109
- b: p3.b,
110
- a: p3.alpha ?? oklch.alpha
111
- })
112
-
113
- return {
114
- color: resolved,
115
- cssColor: formatCss({
116
- mode: 'p3',
117
- r: p3.r,
118
- g: p3.g,
119
- b: p3.b,
120
- alpha: p3.alpha ?? oklch.alpha
121
- }),
122
- sourceSpace: 'oklch',
123
- targetSpace,
124
- clipped
125
- }
122
+ /**
123
+ * `color`, whose components are in `from`, as CSS showing it in `to`: `color(display-p3 …)` for
124
+ * Display P3, `rgb()` for sRGB, where a color outside sRGB clips per channel as a canvas clips it.
125
+ */
126
+ export function colorToProfileCSS(color: Color, from: ColorProfile, to: ColorProfile): string {
127
+ const shown = convertColor(color, from, to)
128
+ if (to === 'display-p3') {
129
+ return formatCss({ mode: 'p3', r: shown.r, g: shown.g, b: shown.b, alpha: shown.a })
126
130
  }
131
+ return formatRgb({ mode: 'rgb', r: shown.r, g: shown.g, b: shown.b, alpha: shown.a })
132
+ }
127
133
 
128
- const clipped = !isDisplayableRGB(oklch)
129
- const rgb = toRGB(toDisplayableRGB(oklch))
130
- const resolved = normalizeColor({
131
- r: rgb.r,
132
- g: rgb.g,
133
- b: rgb.b,
134
- a: rgb.alpha ?? oklch.alpha
135
- })
136
-
137
- return {
138
- color: resolved,
139
- cssColor: formatRgb({
140
- mode: 'rgb',
141
- r: resolved.r,
142
- g: resolved.g,
143
- b: resolved.b,
144
- alpha: resolved.a
145
- }),
146
- sourceSpace: 'oklch',
147
- targetSpace,
148
- clipped
149
- }
134
+ /**
135
+ * The 3×3 matrix, row by row, taking linear components in `profile` to linear sRGB ones: its
136
+ * columns are the profile's primaries in linear sRGB.
137
+ */
138
+ export function linearSRGBMatrix(profile: ColorProfile): number[] {
139
+ const mode = profile === 'display-p3' ? 'p3' : 'rgb'
140
+ const columns = [
141
+ { r: 1, g: 0, b: 0 },
142
+ { r: 0, g: 1, b: 0 },
143
+ { r: 0, g: 0, b: 1 }
144
+ ].map((primary) => toLinearSRGB({ mode, ...primary }))
145
+ return (['r', 'g', 'b'] as const).flatMap((row) => columns.map((column) => column[row]))
150
146
  }
151
147
 
148
+ /** Display P3's matrix, made once: renderers convert every paint they draw through it. */
149
+ const P3_TO_LINEAR_SRGB = linearSRGBMatrix('display-p3')
150
+
152
151
  /**
153
152
  * A CSS color in any space, mapped into sRGB the way CSS maps out-of-gamut colors: by reducing
154
153
  * chroma in OKLCH, so a Display P3 red becomes the nearest sRGB red, not a clipped one. A missing
@@ -156,55 +155,32 @@ export function resolveOkHCLForPreview(
156
155
  */
157
156
  export function parseDisplayableColor(input: string): Color | null {
158
157
  const parsed = parse(input)
159
- if (!parsed) return null
160
- // Mapping through OKLCH shifts colors already in sRGB by float noise, so only map the rest.
161
- const rgb = isDisplayableRGB(parsed) ? toRGB(parsed) : toDisplayableRGB(parsed)
162
- // culori leaves a `none` channel out, which normalizing reads as zero.
163
- return normalizeColor({ r: rgb.r, g: rgb.g, b: rgb.b, a: parsed.alpha })
158
+ return parsed ? insideProfile(parsed, 'srgb') : null
164
159
  }
165
160
 
166
- export function resolveRGBAForPreview(
167
- color: Color,
168
- options?: ColorPreviewOptions
169
- ): ResolvedRenderColor {
170
- const documentColorSpace = options?.documentColorSpace ?? DEFAULT_COLOR_SPACE
171
- const targetSpace = options?.colorSpace ?? documentColorSpace
172
- const resolved = convertComponents(normalizeColor(color), documentColorSpace, targetSpace)
173
- return {
174
- color: resolved,
175
- cssColor: formatCSSForTarget(resolved, targetSpace),
176
- sourceSpace: 'srgb',
177
- targetSpace,
178
- clipped: targetSpace !== documentColorSpace && isOutsideGamut(resolved, targetSpace)
179
- }
180
- }
161
+ /** Syntaxes CSS reads as sRGB numbers: hex, `rgb()`, `hsl()`, `hwb()`, names, `color(srgb …)`. */
162
+ const SRGB_SYNTAX_MODES = new Set(['rgb', 'hsl', 'hwb'])
181
163
 
182
- export function resolveNodeFillColor(
183
- fill: Fill,
184
- fillIndex: number,
185
- node: SceneNode,
186
- options?: ColorPreviewOptions
187
- ): ResolvedRenderColor {
188
- const okhcl = getFillOkHCL(node, fillIndex)?.color
189
- if (okhcl) return resolveOkHCLForPreview(okhcl, options)
190
- return resolveRGBAForPreview(fill.color, options)
191
- }
192
-
193
- export function resolveNodeStrokeColor(
194
- stroke: Stroke,
195
- strokeIndex: number,
196
- node: SceneNode,
197
- options?: ColorPreviewOptions
198
- ): ResolvedRenderColor {
199
- const okhcl = getStrokeOkHCL(node, strokeIndex)?.color
200
- if (okhcl) return resolveOkHCLForPreview(okhcl, options)
201
- return resolveRGBAForPreview(stroke.color, options)
202
- }
203
-
204
- export function colorToDisplayCSS(color: Color, options?: ColorPreviewOptions): string {
205
- return resolveRGBAForPreview(color, options).cssColor
164
+ /**
165
+ * A CSS color as components in `profile`, or null when `input` is not one. Hex and the other sRGB
166
+ * syntaxes give their numbers as they are, as Figma takes typed or imported hex as the document's
167
+ * own numbers in either profile. A color that names its space, such as `color(display-p3 …)` or
168
+ * `oklch()`, is converted into `profile`, and brought inside it by reducing chroma when the
169
+ * profile cannot show it.
170
+ */
171
+ export function tryParseColor(input: string, profile: ColorProfile = 'srgb'): Color | null {
172
+ const parsed = parse(input)
173
+ if (!parsed) return null
174
+ // A component written past the float range, such as `1e999`, is no color.
175
+ if (Object.values(parsed).some((value) => typeof value === 'number' && !Number.isFinite(value)))
176
+ return null
177
+ const a = parsed.alpha ?? 1
178
+ // culori leaves a `none` channel out, which normalizing reads as zero.
179
+ if (SRGB_SYNTAX_MODES.has(parsed.mode)) return normalizeColor({ ...toRGB(parsed), a })
180
+ return insideProfile(parsed, profile)
206
181
  }
207
182
 
208
- export function getDefaultRenderColorSpace(): RenderColorSpace {
209
- return DEFAULT_COLOR_SPACE
183
+ /** A CSS color as components in `profile`, or black when `input` is not one. */
184
+ export function parseColor(input: string, profile: ColorProfile = 'srgb'): Color {
185
+ return tryParseColor(input, profile) ?? { ...BLACK }
210
186
  }
@@ -1,11 +1,11 @@
1
- import { converter, toGamut } from 'culori'
1
+ import { converter } from 'culori'
2
2
 
3
3
  import { copyFill, copyStroke } from '../copy'
4
4
  import { readAllPluginData, withAllPluginData } from '../plugin-data/field'
5
5
  import { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'
6
6
  import type { Color } from '../primitives'
7
- import type { PluginDataEntry, SceneNode } from '../types'
8
- import { normalizeColor } from './normalize'
7
+ import type { ColorProfile, PluginDataEntry, SceneNode } from '../types'
8
+ import { fitIntoProfile } from './management'
9
9
 
10
10
  export interface OkHCLColor {
11
11
  h: number
@@ -21,14 +21,7 @@ export interface OkHCLPayload {
21
21
  color: OkHCLColor
22
22
  }
23
23
 
24
- const toRGB = converter('rgb')
25
- const toP3 = converter('p3')
26
24
  const toOkHCL = converter('oklch')
27
- const toDisplayableRGB = toGamut('rgb', 'oklch')
28
- const toDisplayableP3 = toGamut('p3', 'oklch')
29
-
30
- /** Colour spaces a document's stored numbers can be in. */
31
- export type OkHCLColorSpace = 'srgb' | 'display-p3'
32
25
 
33
26
  function clampUnit(value: number): number {
34
27
  if (value < 0) return 0
@@ -50,38 +43,28 @@ function normalizeOkHCLColor(color: OkHCLColor): OkHCLColor {
50
43
  }
51
44
  }
52
45
 
53
- /** Coordinates in `colorSpace`, so callers can store colours in the document's profile. */
54
- export function okhclToRGBA(color: OkHCLColor, colorSpace: OkHCLColorSpace = 'srgb'): Color {
55
- const normalized = normalizeOkHCLColor(color)
56
- const oklch = {
57
- mode: 'oklch' as const,
58
- l: normalized.l,
59
- c: normalized.c,
60
- h: normalized.h,
61
- alpha: normalized.a
62
- }
63
- if (colorSpace === 'display-p3') {
64
- const p3 = toP3(toDisplayableP3(oklch))
65
- return normalizeColor({
66
- r: p3.r,
67
- g: p3.g,
68
- b: p3.b,
69
- a: p3.alpha ?? normalized.a
70
- })
71
- }
72
- const rgb = toRGB(toDisplayableRGB(oklch))
73
- return normalizeColor({
74
- r: rgb.r,
75
- g: rgb.g,
76
- b: rgb.b,
77
- a: rgb.alpha ?? normalized.a
78
- })
46
+ /**
47
+ * `color` as components in `profile`, and whether the profile could not show it: a color past the
48
+ * gamut is brought inside by reducing chroma, keeping lightness and hue, as {@link fitIntoProfile}
49
+ * brings any color inside.
50
+ */
51
+ export function okhclInProfile(
52
+ color: OkHCLColor,
53
+ profile: ColorProfile
54
+ ): { color: Color; clipped: boolean } {
55
+ const { l, c, h, a } = normalizeOkHCLColor(color)
56
+ return fitIntoProfile({ mode: 'oklch', l, c, h, alpha: a ?? 1 }, profile)
79
57
  }
80
58
 
81
- /** Reads `color` as coordinates in `colorSpace`, the inverse of {@link okhclToRGBA}. */
82
- export function rgbaToOkHCL(color: Color, colorSpace: OkHCLColorSpace = 'srgb'): OkHCLColor {
59
+ /** Coordinates in `profile`, so callers can store colours in the document's profile. */
60
+ export function okhclToRGBA(color: OkHCLColor, profile: ColorProfile = 'srgb'): Color {
61
+ return okhclInProfile(color, profile).color
62
+ }
63
+
64
+ /** Reads `color` as coordinates in `profile`, the inverse of {@link okhclToRGBA}. */
65
+ export function rgbaToOkHCL(color: Color, profile: ColorProfile = 'srgb'): OkHCLColor {
83
66
  const oklch = toOkHCL(
84
- colorSpace === 'display-p3'
67
+ profile === 'display-p3'
85
68
  ? { mode: 'p3', r: color.r, g: color.g, b: color.b, alpha: color.a }
86
69
  : { mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a }
87
70
  )
@@ -132,12 +115,12 @@ export function setNodeFillOkHCL(
132
115
  node: SceneNode,
133
116
  index: number,
134
117
  color: OkHCLColor,
135
- colorSpace: OkHCLColorSpace = 'srgb'
118
+ profile: ColorProfile = 'srgb'
136
119
  ): Partial<SceneNode> {
137
120
  const fills = node.fills.map(copyFill)
138
121
  if (index < 0 || index >= fills.length) throw new Error(`Fill ${index} not found`)
139
122
  const fill = fills[index]
140
- const rgba = okhclToRGBA(color, colorSpace)
123
+ const rgba = okhclToRGBA(color, profile)
141
124
  fills[index] = {
142
125
  ...fill,
143
126
  color: rgba,
@@ -154,12 +137,12 @@ export function setNodeStrokeOkHCL(
154
137
  node: SceneNode,
155
138
  index: number,
156
139
  color: OkHCLColor,
157
- colorSpace: OkHCLColorSpace = 'srgb'
140
+ profile: ColorProfile = 'srgb'
158
141
  ): Partial<SceneNode> {
159
142
  const strokes = node.strokes.map(copyStroke)
160
143
  if (index < 0 || index >= strokes.length) throw new Error(`Stroke ${index} not found`)
161
144
  const stroke = strokes[index]
162
- const rgba = okhclToRGBA(color, colorSpace)
145
+ const rgba = okhclToRGBA(color, profile)
163
146
  strokes[index] = {
164
147
  ...stroke,
165
148
  color: rgba,
@@ -199,3 +182,39 @@ export function getStrokeOkHCL(node: SceneNode, index: number): OkHCLPayload | n
199
182
  ) ?? null
200
183
  )
201
184
  }
185
+
186
+ /** Whether two colors differ by less than half a step of 8 bits in every component. */
187
+ function sameColor(left: Color, right: Color): boolean {
188
+ const step = 1 / 510
189
+ return (['r', 'g', 'b', 'a'] as const).every((key) => Math.abs(left[key] - right[key]) <= step)
190
+ }
191
+
192
+ /**
193
+ * The OkHCL color a paint was last edited in, while it still makes the paint's stored color. The
194
+ * stored color is what draws and what files keep; any other edit to it, such as a hex value, the
195
+ * eyedropper, a plugin, or a new color profile, leaves the OkHCL value describing an older color.
196
+ */
197
+ export function paintOkHCL(
198
+ node: SceneNode,
199
+ kind: 'fill' | 'stroke',
200
+ index: number,
201
+ profile: ColorProfile
202
+ ): OkHCLColor | null {
203
+ const payload = kind === 'fill' ? getFillOkHCL(node, index) : getStrokeOkHCL(node, index)
204
+ const paint = index < 0 ? undefined : (kind === 'fill' ? node.fills : node.strokes).at(index)
205
+ if (!payload || !paint) return null
206
+ return sameColor(okhclToRGBA(payload.color, profile), paint.color) ? payload.color : null
207
+ }
208
+
209
+ /**
210
+ * Keeps `color` as the OkHCL color a paint is edited in without changing the paint, for picking
211
+ * the OkHCL format: the paint keeps its exact stored color.
212
+ */
213
+ export function rememberPaintOkHCL(
214
+ node: SceneNode,
215
+ kind: 'fill' | 'stroke',
216
+ index: number,
217
+ color: OkHCLColor
218
+ ): Partial<SceneNode> {
219
+ return { pluginData: withOkHCLPayload(node, kind, index, color) }
220
+ }
@@ -1,6 +1,7 @@
1
1
  import * as v from 'valibot'
2
2
 
3
3
  import { finiteNumberSchema } from '../primitives/schema'
4
+ import type { ColorProfile, ExportColorProfile } from '../types'
4
5
 
5
6
  export const colorSchema = v.object({
6
7
  r: finiteNumberSchema,
@@ -8,3 +9,15 @@ export const colorSchema = v.object({
8
9
  b: finiteNumberSchema,
9
10
  a: finiteNumberSchema
10
11
  })
12
+
13
+ /** A document's color profile, as files, libraries, and collaboration record it. */
14
+ export const colorProfileSchema = v.picklist(['srgb', 'display-p3'] satisfies ColorProfile[])
15
+
16
+ /** The profiles an export can ask for, as Figma names them. */
17
+ export const EXPORT_COLOR_PROFILE_NAMES = [
18
+ 'DOCUMENT',
19
+ 'SRGB',
20
+ 'DISPLAY_P3_V4'
21
+ ] as const satisfies readonly ExportColorProfile[]
22
+
23
+ export const exportColorProfileSchema = v.picklist(EXPORT_COLOR_PROFILE_NAMES)
@@ -9,7 +9,8 @@ export const CONSTRAINT_PARENT_TYPES: ReadonlySet<SceneNode['type']> = new Set<S
9
9
  'FRAME',
10
10
  'COMPONENT',
11
11
  'COMPONENT_SET',
12
- 'INSTANCE'
12
+ 'INSTANCE',
13
+ 'SLIDE'
13
14
  ])
14
15
 
15
16
  /**
package/src/copy.ts CHANGED
@@ -11,6 +11,7 @@
11
11
  import { readGeometryBlob } from './geometry'
12
12
  import { cloneInstanceOverrideState } from './instances/overrides'
13
13
  import { createDefaultSourceMetadata } from './node-defaults'
14
+ import type { Color } from './primitives'
14
15
  import type {
15
16
  ArcData,
16
17
  ComponentPropertyDefinition,
@@ -39,6 +40,12 @@ export function copyFill<T extends Fill>(f: T): T {
39
40
  if (f.filters) copy.filters = { ...f.filters }
40
41
  if (f.patternSpacing) copy.patternSpacing = { ...f.patternSpacing }
41
42
  if (f.noiseSize) copy.noiseSize = { ...f.noiseSize }
43
+ if (f.customEffectAssetRef) {
44
+ copy.customEffectAssetRef = { ...f.customEffectAssetRef }
45
+ }
46
+ if (f.componentPropAssignments) {
47
+ copy.componentPropAssignments = structuredClone(f.componentPropAssignments)
48
+ }
42
49
  return copy
43
50
  }
44
51
 
@@ -115,6 +122,26 @@ export function copyEffects(effects: Effect[]): Effect[] {
115
122
  return effects.map(copyEffect)
116
123
  }
117
124
 
125
+ /**
126
+ * Copies of `effects` with every color they hold passed through `map`: each effect's own and a
127
+ * duotone noise's second color. `map` is told where each sits, `0` or `0.noise` for the first.
128
+ */
129
+ export function mapEffectColors(
130
+ effects: Effect[],
131
+ map: (color: Color, slot: string) => Color
132
+ ): Effect[] {
133
+ return copyEffects(effects).map((effect, index) => {
134
+ const next = { ...effect, color: map(effect.color, `${index}`) }
135
+ if (effect.noise?.secondaryColor) {
136
+ next.noise = {
137
+ ...effect.noise,
138
+ secondaryColor: map(effect.noise.secondaryColor, `${index}.noise`)
139
+ }
140
+ }
141
+ return next
142
+ })
143
+ }
144
+
118
145
  export function copyLayoutGrids(grids: LayoutGrid[]): LayoutGrid[] {
119
146
  return grids.map((grid) => ({ ...grid, color: grid.color ? { ...grid.color } : undefined }))
120
147
  }
@@ -344,6 +371,8 @@ export function cloneNodeProps(
344
371
  textPathBox: src.textPathBox ? { ...src.textPathBox } : null,
345
372
  gridPosition: src.gridPosition ? { ...src.gridPosition } : null,
346
373
  targetAspectRatio: src.targetAspectRatio ? { ...src.targetAspectRatio } : null,
374
+ slide: structuredClone(src.slide),
375
+ animation: structuredClone(src.animation),
347
376
  connectorStart: src.connectorStart ? copyConnectorEndpoint(src.connectorStart) : null,
348
377
  connectorEnd: src.connectorEnd ? copyConnectorEndpoint(src.connectorEnd) : null,
349
378
  connectorControlPoints: structuredClone(src.connectorControlPoints),