@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
@@ -0,0 +1,36 @@
1
+ import { easingPreset } from "../variables/easing.js";
2
+ import { mapMotionVariables, motionVariableIds, resolveMotion } from "../variables/motion.js";
3
+ //#region src/behaviours/transition.ts
4
+ /** The transition a behaviour starts with when one is added: Figma's Smart animate default. */
5
+ function defaultTransition() {
6
+ return {
7
+ duration: .3,
8
+ easing: easingPreset("OUT_CUBIC")
9
+ };
10
+ }
11
+ /**
12
+ * The transition `node` plays, an instance of the behaviour's component: each variable read in the
13
+ * modes the node is in, and the behaviour's own value where the variable is gone or gives nothing.
14
+ */
15
+ function resolveTransition(graph, behaviour, nodeId) {
16
+ return behaviour.transition && resolveMotion(graph, behaviour.transition, nodeId);
17
+ }
18
+ /** The variables a behaviour's transition follows. */
19
+ function transitionVariableIds(behaviour) {
20
+ return behaviour.transition ? motionVariableIds(behaviour.transition) : [];
21
+ }
22
+ /**
23
+ * The behaviour with its transition following other variables, as a copy into another document
24
+ * or a file's own IDs name them; a variable `map` gives nothing for is let go, keeping the value.
25
+ */
26
+ function mapTransitionVariables(behaviour, map) {
27
+ if (!behaviour.transition) return behaviour;
28
+ return {
29
+ ...behaviour,
30
+ transition: mapMotionVariables(behaviour.transition, map)
31
+ };
32
+ }
33
+ //#endregion
34
+ export { defaultTransition, mapTransitionVariables, resolveTransition, transitionVariableIds };
35
+
36
+ //# sourceMappingURL=transition.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transition.js","names":[],"sources":["../../src/behaviours/transition.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { easingPreset } from '../variables/easing'\nimport {\n mapMotionVariables,\n motionVariableIds,\n resolveMotion,\n type ResolvedMotion\n} from '../variables/motion'\nimport type { Behaviour, BehaviourTransition } from './schema'\n\n/** What a control's state change plays: a duration in seconds and an easing. */\nexport type ResolvedTransition = ResolvedMotion\n\n/** The transition a behaviour starts with when one is added: Figma's Smart animate default. */\nexport function defaultTransition(): BehaviourTransition {\n return { duration: 0.3, easing: easingPreset('OUT_CUBIC') }\n}\n\n/**\n * The transition `node` plays, an instance of the behaviour's component: each variable read in the\n * modes the node is in, and the behaviour's own value where the variable is gone or gives nothing.\n */\nexport function resolveTransition(\n graph: SceneGraph,\n behaviour: Behaviour,\n nodeId: string\n): ResolvedTransition | undefined {\n return behaviour.transition && resolveMotion(graph, behaviour.transition, nodeId)\n}\n\n/** The variables a behaviour's transition follows. */\nexport function transitionVariableIds(behaviour: Behaviour): string[] {\n return behaviour.transition ? motionVariableIds(behaviour.transition) : []\n}\n\n/**\n * The behaviour with its transition following other variables, as a copy into another document\n * or a file's own IDs name them; a variable `map` gives nothing for is let go, keeping the value.\n */\nexport function mapTransitionVariables(\n behaviour: Behaviour,\n map: (variableId: string) => string | undefined\n): Behaviour {\n if (!behaviour.transition) return behaviour\n return { ...behaviour, transition: mapMotionVariables(behaviour.transition, map) }\n}\n"],"mappings":";;;;AAcA,SAAgB,oBAAyC;CACvD,OAAO;EAAE,UAAU;EAAK,QAAQ,aAAa,WAAW;CAAE;AAC5D;;;;;AAMA,SAAgB,kBACd,OACA,WACA,QACgC;CAChC,OAAO,UAAU,cAAc,cAAc,OAAO,UAAU,YAAY,MAAM;AAClF;;AAGA,SAAgB,sBAAsB,WAAgC;CACpE,OAAO,UAAU,aAAa,kBAAkB,UAAU,UAAU,IAAI,CAAC;AAC3E;;;;;AAMA,SAAgB,uBACd,WACA,KACW;CACX,IAAI,CAAC,UAAU,YAAY,OAAO;CAClC,OAAO;EAAE,GAAG;EAAW,YAAY,mBAAmB,UAAU,YAAY,GAAG;CAAE;AACnF"}
@@ -1 +1 @@
1
- {"version":3,"file":"checkpoint.d.ts","names":[],"sources":["../src/checkpoint.ts"],"mappings":";;;;iBA+BgB,uBAAuB,OAAO;;;;;;;;;;;;UAqJ7B;;WAEN,OAAO,oBAAoB;;WAE3B,UAAU;;WAEV,WAAW,oBAAoB;WAC/B,qBAAqB,oBAAoB;;EAElD;;EAEA;;EAEA;;;;;;;;;iBAUc,yBAAyB,OAAO,aAAa"}
1
+ {"version":3,"file":"checkpoint.d.ts","names":[],"sources":["../src/checkpoint.ts"],"mappings":";;;;iBA+BgB,uBAAuB,OAAO;;;;;;;;;;;;UAsJ7B;;WAEN,OAAO,oBAAoB;;WAE3B,UAAU;;WAEV,WAAW,oBAAoB;WAC/B,qBAAqB,oBAAoB;;EAElD;;EAEA;;EAEA;;;;;;;;;iBAUc,yBAAyB,OAAO,aAAa"}
@@ -56,6 +56,7 @@ function captureGraphCheckpoint(graph) {
56
56
  graph.figSchemaDeflated = structuredClone(snapshot.figSchemaDeflated);
57
57
  graph.documentColorSpace = snapshot.documentColorSpace;
58
58
  graph.clearAbsPosCache();
59
+ graph.sharedStyleIndex.invalidate();
59
60
  for (const [id, node] of failedNodes) if (!graph.nodes.has(id)) graph.emitter.emit("node:deleted", id, node.parentId);
60
61
  for (const [id, node] of graph.nodes) if (failedNodes.has(id)) graph.emitter.emit("node:updated", id, node);
61
62
  else graph.emitter.emit("node:created", node);
@@ -244,6 +245,7 @@ function captureTouchedCheckpoint(graph) {
244
245
  graph.figSchemaDeflated = figSchemaDeflated;
245
246
  graph.documentColorSpace = documentColorSpace;
246
247
  graph.clearAbsPosCache();
248
+ graph.sharedStyleIndex.invalidate();
247
249
  const touched = /* @__PURE__ */ new Set([
248
250
  ...nodes.keys(),
249
251
  ...created,
@@ -1 +1 @@
1
- {"version":3,"file":"checkpoint.js","names":[],"sources":["../src/checkpoint.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport type { SceneGraph } from './graph'\nimport { createSceneMutationImpact, recordSceneMutations } from './mutation-impact'\nimport type { SceneNode, Variable, VariableCollection } from './types'\n\nconst NODE_COUNT_ERROR = 'Atomic tools must not create or remove nodes or variables'\nconst NODE_IDENTITY_ERROR = 'Atomic tools must not change node hierarchy or identity'\nconst VARIABLE_IDENTITY_ERROR = 'Atomic tools must not change variable identity'\nconst DOCUMENT_ERROR = 'Atomic tools must not change collections, assets or document metadata'\n\n/** Throws when an edit replaced a variable or changed its identity, collection, or type. */\nfunction assertVariableIdentity(\n graph: SceneGraph,\n saved: ReadonlyMap<string, Variable>,\n refs: ReadonlyMap<string, Variable>\n): void {\n for (const [id, before] of saved) {\n const after = graph.variables.get(id)\n if (\n !after ||\n after !== refs.get(id) ||\n before.id !== after.id ||\n before.collectionId !== after.collectionId ||\n before.type !== after.type\n )\n throw new Error(VARIABLE_IDENTITY_ERROR)\n }\n}\n\n/** Capture rollback state without changing graph or surviving object identities. */\nexport function captureGraphCheckpoint(graph: SceneGraph) {\n const nodeRefs = new Map(graph.nodes)\n const variableRefs = new Map(graph.variables)\n const collectionRefs = new Map(graph.variableCollections)\n const snapshot = structuredClone({\n nodes: graph.nodes,\n variables: graph.variables,\n variableCollections: graph.variableCollections,\n instanceIndex: graph.instanceIndex,\n enabledLibraries: graph.enabledLibraries,\n rootId: graph.rootId,\n figKiwiVersion: graph.figKiwiVersion,\n figSchemaDeflated: graph.figSchemaDeflated,\n documentColorSpace: graph.documentColorSpace\n })\n // Atomic property tools cannot edit assets. Retain existing buffers, not copies of every bitmap.\n const images = new Map(graph.images)\n\n function assertPropertiesOnly() {\n if (\n snapshot.nodes.size !== graph.nodes.size ||\n snapshot.variables.size !== graph.variables.size\n )\n throw new Error(NODE_COUNT_ERROR)\n for (const [id, before] of snapshot.nodes) {\n const after = graph.nodes.get(id)\n if (\n !after ||\n after !== nodeRefs.get(id) ||\n before.id !== after.id ||\n before.type !== after.type ||\n before.parentId !== after.parentId ||\n before.componentId !== after.componentId ||\n !isEqual(before.childIds, after.childIds)\n ) {\n throw new Error(NODE_IDENTITY_ERROR)\n }\n }\n assertVariableIdentity(graph, snapshot.variables, variableRefs)\n assertDocumentUnchanged()\n }\n\n function assertDocumentUnchanged() {\n if (\n !isEqual(snapshot.variableCollections, graph.variableCollections) ||\n !isEqual(snapshot.instanceIndex, graph.instanceIndex) ||\n !isEqual(snapshot.enabledLibraries, graph.enabledLibraries) ||\n images.size !== graph.images.size ||\n [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) ||\n graph.rootId !== snapshot.rootId ||\n graph.documentColorSpace !== snapshot.documentColorSpace ||\n graph.figKiwiVersion !== snapshot.figKiwiVersion ||\n !isEqual(graph.figSchemaDeflated, snapshot.figSchemaDeflated)\n ) {\n throw new Error(DOCUMENT_ERROR)\n }\n }\n\n function restore() {\n const failedNodes = new Map(graph.nodes)\n restoreObjects(graph.nodes, snapshot.nodes, nodeRefs)\n restoreObjects(graph.variables, snapshot.variables, variableRefs)\n restoreObjects(graph.variableCollections, snapshot.variableCollections, collectionRefs)\n restoreMap(graph.instanceIndex, structuredClone(snapshot.instanceIndex))\n restoreMap(graph.enabledLibraries, structuredClone(snapshot.enabledLibraries))\n restoreMap(graph.images, images)\n graph.connectorIds.clear()\n for (const node of graph.nodes.values())\n if (node.type === 'CONNECTOR') graph.connectorIds.add(node.id)\n graph.rootId = snapshot.rootId\n graph.figKiwiVersion = snapshot.figKiwiVersion\n graph.figSchemaDeflated = structuredClone(snapshot.figSchemaDeflated)\n graph.documentColorSpace = snapshot.documentColorSpace\n graph.clearAbsPosCache()\n // Notify consumers only after the complete hierarchy and indexes have been restored.\n for (const [id, node] of failedNodes) {\n if (!graph.nodes.has(id)) graph.emitter.emit('node:deleted', id, node.parentId)\n }\n for (const [id, node] of graph.nodes) {\n if (failedNodes.has(id)) graph.emitter.emit('node:updated', id, node)\n else graph.emitter.emit('node:created', node)\n }\n }\n\n return { nodes: snapshot.nodes, variables: snapshot.variables, assertPropertiesOnly, restore }\n}\n\nfunction restoreObjects<T extends object>(\n target: Map<string, T>,\n snapshot: Map<string, T>,\n refs: Map<string, T>\n) {\n target.clear()\n for (const [id, saved] of snapshot) {\n const original = refs.get(id)\n if (!original) throw new Error(`Missing checkpoint reference: ${id}`)\n for (const key of Object.keys(original) as (keyof T)[]) {\n if (!(key in saved)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(saved))\n target.set(id, original)\n }\n}\n\n/** Copies `id`'s record the first time it is reported: `null` for one about to be added. */\nfunction copyRecord<T>(copies: Map<string, T | null>, live: ReadonlyMap<string, T>, id: string) {\n if (!copies.has(id)) copies.set(id, structuredClone(live.get(id) ?? null))\n}\n\n/** Whether `target` holds exactly the objects `refs` held, in any order. */\nfunction sameEntries<T>(target: ReadonlyMap<string, T>, refs: ReadonlyMap<string, T>): boolean {\n if (target.size !== refs.size) return false\n for (const [id, ref] of refs) if (target.get(id) !== ref) return false\n return true\n}\n\n/**\n * Puts back the records `refs` held, in their order, with the copied ones rewritten in place to\n * their copies, as views may hold them.\n */\nfunction restoreCopied<T extends object>(\n target: Map<string, T>,\n copies: ReadonlyMap<string, T | null>,\n refs: ReadonlyMap<string, T>\n) {\n target.clear()\n for (const [id, original] of refs) {\n const saved = copies.get(id)\n if (saved) {\n for (const key of Object.keys(original) as (keyof T)[]) {\n if (!(key in saved)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(saved))\n }\n target.set(id, original)\n }\n}\n\nfunction restoreMap<K, V>(target: Map<K, V>, saved: Map<K, V>) {\n target.clear()\n for (const [key, value] of saved) target.set(key, value)\n}\n\n/**\n * Rollback state for an edit that may only change properties, which costs what the edit touches\n * rather than a copy of the document: a node is copied the first time the graph reports it about\n * to change (`SceneGraph.observeNodeChanges`), together with its ancestors below the page, which\n * keep instance override maps the graph writes into in place.\n */\nexport interface TouchedCheckpoint {\n /** Copies of the reported nodes and their ancestors below the page, as they were before. */\n readonly nodes: ReadonlyMap<string, SceneNode>\n /** Nodes the graph reported changing or creating. */\n readonly reported: ReadonlySet<string>\n /** Copies of the variables reported changing (`SceneGraph.willChangeVariable`), as they were. */\n readonly variables: ReadonlyMap<string, Variable | null>\n readonly variableCollections: ReadonlyMap<string, VariableCollection | null>\n /** Throws unless the edit only changed properties of existing nodes and variables. */\n assertPropertiesOnly(): void\n /** Stops observing and puts back everything the edit changed, keeping object identities. */\n restore(): void\n /** Stops observing the graph. */\n stop(): void\n}\n\n/**\n * Starts observing `graph` for an edit that may only change properties. Node identities are\n * kept as pointers, so replacing, adding, or removing a node anywhere is found; a node's fields\n * are compared and restored only where the graph reported it, so code that writes into a node\n * directly calls `SceneGraph.willChangeNode` first, and a node event without such a report fails\n * the edit.\n */\nexport function captureTouchedCheckpoint(graph: SceneGraph): TouchedCheckpoint {\n const nodeRefs = new Map(graph.nodes)\n const variableRefs = new Map(graph.variables)\n const collectionRefs = new Map(graph.variableCollections)\n const saved = structuredClone({\n enabledLibraries: graph.enabledLibraries\n })\n // Instances follow their nodes' components, which a property edit cannot change, so the sets\n // are kept rather than their ids copied deeply.\n const instanceIndex = new Map(\n [...graph.instanceIndex].map(([id, instances]) => [id, new Set(instances)])\n )\n const variables = new Map<string, Variable | null>()\n const variableCollections = new Map<string, VariableCollection | null>()\n // Property edits cannot edit assets. Retain existing buffers, not copies of every bitmap.\n const images = new Map(graph.images)\n const { rootId, figKiwiVersion, figSchemaDeflated, documentColorSpace } = graph\n const nodes = new Map<string, SceneNode>()\n const reported = new Set<string>()\n const created = new Set<string>()\n const impact = createSceneMutationImpact()\n\n /** Copies a node as the edit found it: the original object, should the edit have replaced it. */\n function copy(node: SceneNode) {\n nodes.set(node.id, structuredClone(nodeRefs.get(node.id) ?? node))\n }\n\n const skipped = (node: SceneNode) => nodes.has(node.id) || created.has(node.id)\n\n /**\n * Copies `node` and each ancestor not copied yet, up to but excluding its page. An ancestor\n * copied already had its own ancestors copied with it, so the walk stops there.\n */\n function copyLineage(node: SceneNode) {\n if (skipped(node)) return\n copy(node)\n if (!node.parentId) return\n graph.closest(node.parentId, (ancestor) => {\n if (ancestor.type === 'CANVAS' || ancestor.id === rootId || skipped(ancestor)) return true\n copy(ancestor)\n return false\n })\n }\n\n const unobserve = graph.observeNodeChanges({\n created: (node) => {\n created.add(node.id)\n reported.add(node.id)\n },\n before: (node) => {\n reported.add(node.id)\n copyLineage(node)\n },\n beforeRecord: (kind, id) => {\n if (kind === 'variable') copyRecord(variables, graph.variables, id)\n else copyRecord(variableCollections, graph.variableCollections, id)\n }\n })\n const unbindEvents = recordSceneMutations(graph, impact)\n let observing = true\n\n function stop() {\n if (!observing) return\n observing = false\n unobserve()\n unbindEvents()\n }\n\n function assertNodes() {\n if (\n created.size > 0 ||\n impact.deletedNodeIds.size > 0 ||\n graph.nodes.size !== nodeRefs.size ||\n graph.variables.size !== variableRefs.size\n )\n throw new Error(NODE_COUNT_ERROR)\n for (const [id, node] of graph.nodes) {\n const original = nodeRefs.get(id)\n if (!original) throw new Error(NODE_COUNT_ERROR)\n if (original !== node) throw new Error(NODE_IDENTITY_ERROR)\n }\n for (const [id, before] of nodes) {\n const after = graph.nodes.get(id)\n if (\n !after ||\n before.id !== after.id ||\n before.type !== after.type ||\n before.parentId !== after.parentId ||\n before.componentId !== after.componentId ||\n !isEqual(before.childIds, after.childIds)\n )\n throw new Error(NODE_IDENTITY_ERROR)\n }\n for (const id of [\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ]) {\n if (!nodes.has(id) && !created.has(id)) {\n throw new Error(\n `Atomic tools must report layer changes to the scene graph (SceneGraph.willChangeNode): ${id}`\n )\n }\n }\n }\n\n function assertPropertiesOnly() {\n assertNodes()\n if (!sameEntries(graph.variables, variableRefs)) throw new Error(VARIABLE_IDENTITY_ERROR)\n for (const [id, before] of variables) {\n const after = graph.variables.get(id)\n if (\n !before ||\n !after ||\n before.id !== after.id ||\n before.collectionId !== after.collectionId ||\n before.type !== after.type\n )\n throw new Error(VARIABLE_IDENTITY_ERROR)\n }\n if (\n !sameEntries(graph.variableCollections, collectionRefs) ||\n [...variableCollections].some(\n ([id, before]) => !isEqual(before, graph.variableCollections.get(id) ?? null)\n ) ||\n !isEqual(instanceIndex, graph.instanceIndex) ||\n !isEqual(saved.enabledLibraries, graph.enabledLibraries) ||\n images.size !== graph.images.size ||\n [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) ||\n graph.rootId !== rootId ||\n graph.documentColorSpace !== documentColorSpace ||\n graph.figKiwiVersion !== figKiwiVersion ||\n // Every writer assigns a new schema rather than writing into it.\n graph.figSchemaDeflated !== figSchemaDeflated\n )\n throw new Error(DOCUMENT_ERROR)\n }\n\n /** Puts the node map back as it was, in its order, if the edit changed its entries. */\n function restoreNodeMap(): { removed: Map<string, SceneNode>; readded: Set<string> } {\n const removed = new Map<string, SceneNode>()\n const readded = new Set<string>()\n let changed = graph.nodes.size !== nodeRefs.size\n if (!changed) {\n // In lockstep, so a node removed and set again, which moves to the end, is put back too.\n const live = graph.nodes.entries()\n for (const [id, node] of nodeRefs) {\n const next = live.next()\n if (next.done || next.value[0] !== id || next.value[1] !== node) {\n changed = true\n break\n }\n }\n }\n if (!changed) return { removed, readded }\n const failed = new Map(graph.nodes)\n graph.nodes.clear()\n for (const [id, node] of nodeRefs) {\n graph.nodes.set(id, node)\n if (!failed.has(id)) readded.add(id)\n }\n for (const [id, node] of failed) if (!nodeRefs.has(id)) removed.set(id, node)\n return { removed, readded }\n }\n\n function restore() {\n stop()\n const { removed, readded } = restoreNodeMap()\n for (const [id, copy] of nodes) {\n const original = nodeRefs.get(id)\n if (!original) continue\n for (const key of Object.keys(original)) {\n if (!Object.hasOwn(copy, key)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(copy))\n }\n restoreCopied(graph.variables, variables, variableRefs)\n restoreCopied(graph.variableCollections, variableCollections, collectionRefs)\n restoreMap(\n graph.instanceIndex,\n new Map([...instanceIndex].map(([id, instances]) => [id, new Set(instances)]))\n )\n restoreMap(graph.enabledLibraries, structuredClone(saved.enabledLibraries))\n restoreMap(graph.images, images)\n graph.rootId = rootId\n graph.figKiwiVersion = figKiwiVersion\n graph.figSchemaDeflated = figSchemaDeflated\n graph.documentColorSpace = documentColorSpace\n graph.clearAbsPosCache()\n const touched = new Set([\n ...nodes.keys(),\n ...created,\n ...readded,\n ...removed.keys(),\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ])\n for (const id of touched) {\n if (graph.nodes.get(id)?.type === 'CONNECTOR') graph.connectorIds.add(id)\n else graph.connectorIds.delete(id)\n }\n // Notify consumers only after the complete hierarchy and indexes have been restored.\n for (const [id, node] of removed) graph.emitter.emit('node:deleted', id, node.parentId)\n for (const id of touched) {\n const node = graph.nodes.get(id)\n if (!node) continue\n if (readded.has(id)) graph.emitter.emit('node:created', node)\n else graph.emitter.emit('node:updated', id, node)\n }\n }\n\n return {\n nodes,\n reported,\n variables,\n variableCollections,\n assertPropertiesOnly,\n restore,\n stop\n }\n}\n"],"mappings":";;;AAMA,MAAM,mBAAmB;AACzB,MAAM,sBAAsB;AAC5B,MAAM,0BAA0B;AAChC,MAAM,iBAAiB;;AAGvB,SAAS,uBACP,OACA,OACA,MACM;CACN,KAAK,MAAM,CAAC,IAAI,WAAW,OAAO;EAChC,MAAM,QAAQ,MAAM,UA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;GACV,GAAG,OAAO;GACV,GAAG,OAAO;EACZ,CAAC;EACD,KAAK,MAAM,MAAM,SACf,IAAI,MAAM,MAAM,IAAI,EAAE,CAAC,EAAE,SAAS,aAAa,MAAM,aAAa,IAAI,EAAE;OACnE,MAAM,aAAa,OAAO,EAAE;EAGnC,KAAK,MAAM,CAAC,IAAI,SAAS,SAAS,MAAM,QAAQ,KAAK,gBAAgB,IAAI,KAAK,QAAQ;EACtF,KAAK,MAAM,MAAM,SAAS;GACxB,MAAM,OAAO,MAAM,MAAM,IAAI,EAAE;GAC/B,IAAI,CAAC,MAAM;GACX,IAAI,QAAQ,IAAI,EAAE,GAAG,MAAM,QAAQ,KAAK,gBAAgB,IAAI;QACvD,MAAM,QAAQ,KAAK,gBAAgB,IAAI,IAAI;EAClD;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
1
+ {"version":3,"file":"checkpoint.js","names":[],"sources":["../src/checkpoint.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit'\n\nimport type { SceneGraph } from './graph'\nimport { createSceneMutationImpact, recordSceneMutations } from './mutation-impact'\nimport type { SceneNode, Variable, VariableCollection } from './types'\n\nconst NODE_COUNT_ERROR = 'Atomic tools must not create or remove nodes or variables'\nconst NODE_IDENTITY_ERROR = 'Atomic tools must not change node hierarchy or identity'\nconst VARIABLE_IDENTITY_ERROR = 'Atomic tools must not change variable identity'\nconst DOCUMENT_ERROR = 'Atomic tools must not change collections, assets or document metadata'\n\n/** Throws when an edit replaced a variable or changed its identity, collection, or type. */\nfunction assertVariableIdentity(\n graph: SceneGraph,\n saved: ReadonlyMap<string, Variable>,\n refs: ReadonlyMap<string, Variable>\n): void {\n for (const [id, before] of saved) {\n const after = graph.variables.get(id)\n if (\n !after ||\n after !== refs.get(id) ||\n before.id !== after.id ||\n before.collectionId !== after.collectionId ||\n before.type !== after.type\n )\n throw new Error(VARIABLE_IDENTITY_ERROR)\n }\n}\n\n/** Capture rollback state without changing graph or surviving object identities. */\nexport function captureGraphCheckpoint(graph: SceneGraph) {\n const nodeRefs = new Map(graph.nodes)\n const variableRefs = new Map(graph.variables)\n const collectionRefs = new Map(graph.variableCollections)\n const snapshot = structuredClone({\n nodes: graph.nodes,\n variables: graph.variables,\n variableCollections: graph.variableCollections,\n instanceIndex: graph.instanceIndex,\n enabledLibraries: graph.enabledLibraries,\n rootId: graph.rootId,\n figKiwiVersion: graph.figKiwiVersion,\n figSchemaDeflated: graph.figSchemaDeflated,\n documentColorSpace: graph.documentColorSpace\n })\n // Atomic property tools cannot edit assets. Retain existing buffers, not copies of every bitmap.\n const images = new Map(graph.images)\n\n function assertPropertiesOnly() {\n if (\n snapshot.nodes.size !== graph.nodes.size ||\n snapshot.variables.size !== graph.variables.size\n )\n throw new Error(NODE_COUNT_ERROR)\n for (const [id, before] of snapshot.nodes) {\n const after = graph.nodes.get(id)\n if (\n !after ||\n after !== nodeRefs.get(id) ||\n before.id !== after.id ||\n before.type !== after.type ||\n before.parentId !== after.parentId ||\n before.componentId !== after.componentId ||\n !isEqual(before.childIds, after.childIds)\n ) {\n throw new Error(NODE_IDENTITY_ERROR)\n }\n }\n assertVariableIdentity(graph, snapshot.variables, variableRefs)\n assertDocumentUnchanged()\n }\n\n function assertDocumentUnchanged() {\n if (\n !isEqual(snapshot.variableCollections, graph.variableCollections) ||\n !isEqual(snapshot.instanceIndex, graph.instanceIndex) ||\n !isEqual(snapshot.enabledLibraries, graph.enabledLibraries) ||\n images.size !== graph.images.size ||\n [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) ||\n graph.rootId !== snapshot.rootId ||\n graph.documentColorSpace !== snapshot.documentColorSpace ||\n graph.figKiwiVersion !== snapshot.figKiwiVersion ||\n !isEqual(graph.figSchemaDeflated, snapshot.figSchemaDeflated)\n ) {\n throw new Error(DOCUMENT_ERROR)\n }\n }\n\n function restore() {\n const failedNodes = new Map(graph.nodes)\n restoreObjects(graph.nodes, snapshot.nodes, nodeRefs)\n restoreObjects(graph.variables, snapshot.variables, variableRefs)\n restoreObjects(graph.variableCollections, snapshot.variableCollections, collectionRefs)\n restoreMap(graph.instanceIndex, structuredClone(snapshot.instanceIndex))\n restoreMap(graph.enabledLibraries, structuredClone(snapshot.enabledLibraries))\n restoreMap(graph.images, images)\n graph.connectorIds.clear()\n for (const node of graph.nodes.values())\n if (node.type === 'CONNECTOR') graph.connectorIds.add(node.id)\n graph.rootId = snapshot.rootId\n graph.figKiwiVersion = snapshot.figKiwiVersion\n graph.figSchemaDeflated = structuredClone(snapshot.figSchemaDeflated)\n graph.documentColorSpace = snapshot.documentColorSpace\n graph.clearAbsPosCache()\n graph.sharedStyleIndex.invalidate()\n // Notify consumers only after the complete hierarchy and indexes have been restored.\n for (const [id, node] of failedNodes) {\n if (!graph.nodes.has(id)) graph.emitter.emit('node:deleted', id, node.parentId)\n }\n for (const [id, node] of graph.nodes) {\n if (failedNodes.has(id)) graph.emitter.emit('node:updated', id, node)\n else graph.emitter.emit('node:created', node)\n }\n }\n\n return { nodes: snapshot.nodes, variables: snapshot.variables, assertPropertiesOnly, restore }\n}\n\nfunction restoreObjects<T extends object>(\n target: Map<string, T>,\n snapshot: Map<string, T>,\n refs: Map<string, T>\n) {\n target.clear()\n for (const [id, saved] of snapshot) {\n const original = refs.get(id)\n if (!original) throw new Error(`Missing checkpoint reference: ${id}`)\n for (const key of Object.keys(original) as (keyof T)[]) {\n if (!(key in saved)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(saved))\n target.set(id, original)\n }\n}\n\n/** Copies `id`'s record the first time it is reported: `null` for one about to be added. */\nfunction copyRecord<T>(copies: Map<string, T | null>, live: ReadonlyMap<string, T>, id: string) {\n if (!copies.has(id)) copies.set(id, structuredClone(live.get(id) ?? null))\n}\n\n/** Whether `target` holds exactly the objects `refs` held, in any order. */\nfunction sameEntries<T>(target: ReadonlyMap<string, T>, refs: ReadonlyMap<string, T>): boolean {\n if (target.size !== refs.size) return false\n for (const [id, ref] of refs) if (target.get(id) !== ref) return false\n return true\n}\n\n/**\n * Puts back the records `refs` held, in their order, with the copied ones rewritten in place to\n * their copies, as views may hold them.\n */\nfunction restoreCopied<T extends object>(\n target: Map<string, T>,\n copies: ReadonlyMap<string, T | null>,\n refs: ReadonlyMap<string, T>\n) {\n target.clear()\n for (const [id, original] of refs) {\n const saved = copies.get(id)\n if (saved) {\n for (const key of Object.keys(original) as (keyof T)[]) {\n if (!(key in saved)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(saved))\n }\n target.set(id, original)\n }\n}\n\nfunction restoreMap<K, V>(target: Map<K, V>, saved: Map<K, V>) {\n target.clear()\n for (const [key, value] of saved) target.set(key, value)\n}\n\n/**\n * Rollback state for an edit that may only change properties, which costs what the edit touches\n * rather than a copy of the document: a node is copied the first time the graph reports it about\n * to change (`SceneGraph.observeNodeChanges`), together with its ancestors below the page, which\n * keep instance override maps the graph writes into in place.\n */\nexport interface TouchedCheckpoint {\n /** Copies of the reported nodes and their ancestors below the page, as they were before. */\n readonly nodes: ReadonlyMap<string, SceneNode>\n /** Nodes the graph reported changing or creating. */\n readonly reported: ReadonlySet<string>\n /** Copies of the variables reported changing (`SceneGraph.willChangeVariable`), as they were. */\n readonly variables: ReadonlyMap<string, Variable | null>\n readonly variableCollections: ReadonlyMap<string, VariableCollection | null>\n /** Throws unless the edit only changed properties of existing nodes and variables. */\n assertPropertiesOnly(): void\n /** Stops observing and puts back everything the edit changed, keeping object identities. */\n restore(): void\n /** Stops observing the graph. */\n stop(): void\n}\n\n/**\n * Starts observing `graph` for an edit that may only change properties. Node identities are\n * kept as pointers, so replacing, adding, or removing a node anywhere is found; a node's fields\n * are compared and restored only where the graph reported it, so code that writes into a node\n * directly calls `SceneGraph.willChangeNode` first, and a node event without such a report fails\n * the edit.\n */\nexport function captureTouchedCheckpoint(graph: SceneGraph): TouchedCheckpoint {\n const nodeRefs = new Map(graph.nodes)\n const variableRefs = new Map(graph.variables)\n const collectionRefs = new Map(graph.variableCollections)\n const saved = structuredClone({\n enabledLibraries: graph.enabledLibraries\n })\n // Instances follow their nodes' components, which a property edit cannot change, so the sets\n // are kept rather than their ids copied deeply.\n const instanceIndex = new Map(\n [...graph.instanceIndex].map(([id, instances]) => [id, new Set(instances)])\n )\n const variables = new Map<string, Variable | null>()\n const variableCollections = new Map<string, VariableCollection | null>()\n // Property edits cannot edit assets. Retain existing buffers, not copies of every bitmap.\n const images = new Map(graph.images)\n const { rootId, figKiwiVersion, figSchemaDeflated, documentColorSpace } = graph\n const nodes = new Map<string, SceneNode>()\n const reported = new Set<string>()\n const created = new Set<string>()\n const impact = createSceneMutationImpact()\n\n /** Copies a node as the edit found it: the original object, should the edit have replaced it. */\n function copy(node: SceneNode) {\n nodes.set(node.id, structuredClone(nodeRefs.get(node.id) ?? node))\n }\n\n const skipped = (node: SceneNode) => nodes.has(node.id) || created.has(node.id)\n\n /**\n * Copies `node` and each ancestor not copied yet, up to but excluding its page. An ancestor\n * copied already had its own ancestors copied with it, so the walk stops there.\n */\n function copyLineage(node: SceneNode) {\n if (skipped(node)) return\n copy(node)\n if (!node.parentId) return\n graph.closest(node.parentId, (ancestor) => {\n if (ancestor.type === 'CANVAS' || ancestor.id === rootId || skipped(ancestor)) return true\n copy(ancestor)\n return false\n })\n }\n\n const unobserve = graph.observeNodeChanges({\n created: (node) => {\n created.add(node.id)\n reported.add(node.id)\n },\n before: (node) => {\n reported.add(node.id)\n copyLineage(node)\n },\n beforeRecord: (kind, id) => {\n if (kind === 'variable') copyRecord(variables, graph.variables, id)\n else copyRecord(variableCollections, graph.variableCollections, id)\n }\n })\n const unbindEvents = recordSceneMutations(graph, impact)\n let observing = true\n\n function stop() {\n if (!observing) return\n observing = false\n unobserve()\n unbindEvents()\n }\n\n function assertNodes() {\n if (\n created.size > 0 ||\n impact.deletedNodeIds.size > 0 ||\n graph.nodes.size !== nodeRefs.size ||\n graph.variables.size !== variableRefs.size\n )\n throw new Error(NODE_COUNT_ERROR)\n for (const [id, node] of graph.nodes) {\n const original = nodeRefs.get(id)\n if (!original) throw new Error(NODE_COUNT_ERROR)\n if (original !== node) throw new Error(NODE_IDENTITY_ERROR)\n }\n for (const [id, before] of nodes) {\n const after = graph.nodes.get(id)\n if (\n !after ||\n before.id !== after.id ||\n before.type !== after.type ||\n before.parentId !== after.parentId ||\n before.componentId !== after.componentId ||\n !isEqual(before.childIds, after.childIds)\n )\n throw new Error(NODE_IDENTITY_ERROR)\n }\n for (const id of [\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ]) {\n if (!nodes.has(id) && !created.has(id)) {\n throw new Error(\n `Atomic tools must report layer changes to the scene graph (SceneGraph.willChangeNode): ${id}`\n )\n }\n }\n }\n\n function assertPropertiesOnly() {\n assertNodes()\n if (!sameEntries(graph.variables, variableRefs)) throw new Error(VARIABLE_IDENTITY_ERROR)\n for (const [id, before] of variables) {\n const after = graph.variables.get(id)\n if (\n !before ||\n !after ||\n before.id !== after.id ||\n before.collectionId !== after.collectionId ||\n before.type !== after.type\n )\n throw new Error(VARIABLE_IDENTITY_ERROR)\n }\n if (\n !sameEntries(graph.variableCollections, collectionRefs) ||\n [...variableCollections].some(\n ([id, before]) => !isEqual(before, graph.variableCollections.get(id) ?? null)\n ) ||\n !isEqual(instanceIndex, graph.instanceIndex) ||\n !isEqual(saved.enabledLibraries, graph.enabledLibraries) ||\n images.size !== graph.images.size ||\n [...images].some(([id, bytes]) => graph.images.get(id) !== bytes) ||\n graph.rootId !== rootId ||\n graph.documentColorSpace !== documentColorSpace ||\n graph.figKiwiVersion !== figKiwiVersion ||\n // Every writer assigns a new schema rather than writing into it.\n graph.figSchemaDeflated !== figSchemaDeflated\n )\n throw new Error(DOCUMENT_ERROR)\n }\n\n /** Puts the node map back as it was, in its order, if the edit changed its entries. */\n function restoreNodeMap(): { removed: Map<string, SceneNode>; readded: Set<string> } {\n const removed = new Map<string, SceneNode>()\n const readded = new Set<string>()\n let changed = graph.nodes.size !== nodeRefs.size\n if (!changed) {\n // In lockstep, so a node removed and set again, which moves to the end, is put back too.\n const live = graph.nodes.entries()\n for (const [id, node] of nodeRefs) {\n const next = live.next()\n if (next.done || next.value[0] !== id || next.value[1] !== node) {\n changed = true\n break\n }\n }\n }\n if (!changed) return { removed, readded }\n const failed = new Map(graph.nodes)\n graph.nodes.clear()\n for (const [id, node] of nodeRefs) {\n graph.nodes.set(id, node)\n if (!failed.has(id)) readded.add(id)\n }\n for (const [id, node] of failed) if (!nodeRefs.has(id)) removed.set(id, node)\n return { removed, readded }\n }\n\n function restore() {\n stop()\n const { removed, readded } = restoreNodeMap()\n for (const [id, copy] of nodes) {\n const original = nodeRefs.get(id)\n if (!original) continue\n for (const key of Object.keys(original)) {\n if (!Object.hasOwn(copy, key)) Reflect.deleteProperty(original, key)\n }\n Object.assign(original, structuredClone(copy))\n }\n restoreCopied(graph.variables, variables, variableRefs)\n restoreCopied(graph.variableCollections, variableCollections, collectionRefs)\n restoreMap(\n graph.instanceIndex,\n new Map([...instanceIndex].map(([id, instances]) => [id, new Set(instances)]))\n )\n restoreMap(graph.enabledLibraries, structuredClone(saved.enabledLibraries))\n restoreMap(graph.images, images)\n graph.rootId = rootId\n graph.figKiwiVersion = figKiwiVersion\n graph.figSchemaDeflated = figSchemaDeflated\n graph.documentColorSpace = documentColorSpace\n graph.clearAbsPosCache()\n graph.sharedStyleIndex.invalidate()\n const touched = new Set([\n ...nodes.keys(),\n ...created,\n ...readded,\n ...removed.keys(),\n ...impact.changedNodeIds,\n ...impact.previousParentIds,\n ...impact.currentParentIds\n ])\n for (const id of touched) {\n if (graph.nodes.get(id)?.type === 'CONNECTOR') graph.connectorIds.add(id)\n else graph.connectorIds.delete(id)\n }\n // Notify consumers only after the complete hierarchy and indexes have been restored.\n for (const [id, node] of removed) graph.emitter.emit('node:deleted', id, node.parentId)\n for (const id of touched) {\n const node = graph.nodes.get(id)\n if (!node) continue\n if (readded.has(id)) graph.emitter.emit('node:created', node)\n else graph.emitter.emit('node:updated', id, node)\n }\n }\n\n return {\n nodes,\n reported,\n variables,\n variableCollections,\n assertPropertiesOnly,\n restore,\n stop\n }\n}\n"],"mappings":";;;AAMA,MAAM,mBAAmB;AACzB,MAAM,sBAAsB;AAC5B,MAAM,0BAA0B;AAChC,MAAM,iBAAiB;;AAGvB,SAAS,uBACP,OACA,OACA,MACM;CACN,KAAK,MAAM,CAAC,IAAI,WAAW,OAAO;EAChC,MAAM,QAAQ,MAAM,UAAU,IAAI,EAAE;EACpC,IACE,CAAC,SACD,UAAU,KAAK,IAAI,EAAE,KACrB,OAAO,OAAO,MAAM,MACpB,OAAO,iBAAiB,MAAM,gBAC9B,OAAO,SAAS,MAAM,MAEtB,MAAM,IAAI,MAAM,uBAAuB;CAC3C;AACF;;AAGA,SAAgB,uBAAuB,OAAmB;CACxD,MAAM,WAAW,IAAI,IAAI,MAAM,KAAK;CACpC,MAAM,eAAe,IAAI,IAAI,MAAM,SAAS;CAC5C,MAAM,iBAAiB,IAAI,IAAI,MAAM,mBAAmB;CACxD,MAAM,WAAW,gBAAgB;EAC/B,OAAO,MAAM;EACb,WAAW,MAAM;EACjB,qBAAqB,MAAM;EAC3B,eAAe,MAAM;EACrB,kBAAkB,MAAM;EACxB,QAAQ,MAAM;EACd,gBAAgB,MAAM;EACtB,mBAAmB,MAAM;EACzB,oBAAoB,MAAM;CAC5B,CAAC;CAED,MAAM,SAAS,IAAI,IAAI,MAAM,MAAM;CAEnC,SAAS,uBAAuB;EAC9B,IACE,SAAS,MAAM,SAAS,MAAM,MAAM,QACpC,SAAS,UAAU,SAAS,MAAM,UAAU,MAE5C,MAAM,IAAI,MAAM,gBAAgB;EAClC,KAAK,MAAM,CAAC,IAAI,WAAW,SAAS,OAAO;GACzC,MAAM,QAAQ,MAAM,MAAM,IAAI,EAAE;GAChC,IACE,CAAC,SACD,UAAU,SAAS,IAAI,EAAE,KACzB,OAAO,OAAO,MAAM,MACpB,OAAO,SAAS,MAAM,QACtB,OAAO,aAAa,MAAM,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C/E;EACA,WAAW,MAAM,kBAAkB,gBAAgB,MAAM,gBAAgB,CAAC;EAC1E,WAAW,MAAM,QAAQ,MAAM;EAC/B,MAAM,SAAS;EACf,MAAM,iBAAiB;EACvB,MAAM,oBAAoB;EAC1B,MAAM,qBAAqB;EAC3B,MAAM,iBAAiB;EACvB,MAAM,iBAAiB,WAAW;EAClC,MAAM,0BAAU,IAAI,IAAI;GACtB,GAAG,MAAM,KAAK;GACd,GAAG;GACH,GAAG;GACH,GAAG,QAAQ,KAAK;GAChB,GAAG,OAAO;GACV,GAAG,OAAO;GACV,GAAG,OAAO;EACZ,CAAC;EACD,KAAK,MAAM,MAAM,SACf,IAAI,MAAM,MAAM,IAAI,EAAE,CAAC,EAAE,SAAS,aAAa,MAAM,aAAa,IAAI,EAAE;OACnE,MAAM,aAAa,OAAO,EAAE;EAGnC,KAAK,MAAM,CAAC,IAAI,SAAS,SAAS,MAAM,QAAQ,KAAK,gBAAgB,IAAI,KAAK,QAAQ;EACtF,KAAK,MAAM,MAAM,SAAS;GACxB,MAAM,OAAO,MAAM,MAAM,IAAI,EAAE;GAC/B,IAAI,CAAC,MAAM;GACX,IAAI,QAAQ,IAAI,EAAE,GAAG,MAAM,QAAQ,KAAK,gBAAgB,IAAI;QACvD,MAAM,QAAQ,KAAK,gBAAgB,IAAI,IAAI;EAClD;CACF;CAEA,OAAO;EACL;EACA;EACA;EACA;EACA;EACA;EACA;CACF;AACF"}
@@ -1,15 +1,17 @@
1
1
  import { Color } from "../primitives/index.js";
2
+ import { ColorProfile } from "../types.js";
2
3
  import { compositeOver, contrastRatio, darkenForContrast, readableForeground } from "./contrast.js";
3
- import { OkHCLColor, OkHCLColorSpace, OkHCLPayload, clearNodeFillOkHCL, clearNodeStrokeOkHCL, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, okhclToRGBA, parseOkHCLPayload, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL } from "./okhcl.js";
4
- import { ColorIntentSpace, ColorPreviewOptions, RenderColorSpace, ResolvedRenderColor, colorToDisplayCSS, getDefaultRenderColorSpace, parseDisplayableColor, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview } from "./management.js";
4
+ import { GamutHandling, colorToProfileCSS, convertColor, fitIntoProfile, fitsGamut, linearSRGBMatrix, parseColor, parseDisplayableColor, toExtendedSRGB, tryParseColor } from "./management.js";
5
5
  import { normalizeColor } from "./normalize.js";
6
- import { colorSchema } from "./schema.js";
6
+ import { EXPORT_COLOR_PROFILE_NAMES, colorProfileSchema, colorSchema, exportColorProfileSchema } from "./schema.js";
7
+ import { OkHCLColor, OkHCLPayload, clearNodeFillOkHCL, clearNodeStrokeOkHCL, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, okhclInProfile, okhclToRGBA, paintOkHCL, parseOkHCLPayload, rememberPaintOkHCL, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL } from "./okhcl.js";
7
8
  //#region src/color/index.d.ts
8
- /** A CSS color, or null when `input` is not one. */
9
- declare function tryParseColor(input: string): Color | null;
10
- /** A CSS color, or black when `input` is not one. */
11
- declare function parseColor(input: string): Color;
12
9
  declare function colorToHex(color: Color): string;
10
+ /**
11
+ * `color`, whose components are in `profile`, as the sRGB hex code tools display: hex holds sRGB
12
+ * only, so a color outside it is brought inside by reducing chroma, not clipped.
13
+ */
14
+ declare function colorToSRGBHex(color: Color, profile: ColorProfile): string;
13
15
  declare function colorToHex8(color: Color, alpha?: number): string;
14
16
  declare function colorToHexRaw(color: Color): string;
15
17
  declare function colorToRgba255(color: Color): {
@@ -21,7 +23,8 @@ declare function colorToRgba255(color: Color): {
21
23
  declare function colorToCSS(color: Color): string;
22
24
  declare function colorToCSSCompact(color: Color): string;
23
25
  declare function rgba255ToColor(r: number, g: number, b: number, a?: number): Color;
24
- declare function colorToFill(color: string | Color): {
26
+ /** A solid paint of `color`, a CSS color read into `profile` or components already in it. */
27
+ declare function colorToFill(color: string | Color, profile?: ColorProfile): {
25
28
  type: "SOLID";
26
29
  color: {
27
30
  r: number;
@@ -34,5 +37,5 @@ declare function colorToFill(color: string | Color): {
34
37
  };
35
38
  declare function colorDistance(c1: Color, c2: Color): number;
36
39
  //#endregion
37
- export { ColorIntentSpace, ColorPreviewOptions, OkHCLColor, OkHCLColorSpace, OkHCLPayload, RenderColorSpace, ResolvedRenderColor, clearNodeFillOkHCL, clearNodeStrokeOkHCL, colorDistance, colorSchema, colorToCSS, colorToCSSCompact, colorToDisplayCSS, colorToFill, colorToHex, colorToHex8, colorToHexRaw, colorToRgba255, compositeOver, contrastRatio, darkenForContrast, getDefaultRenderColorSpace, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, normalizeColor, okhclToRGBA, parseColor, parseDisplayableColor, parseOkHCLPayload, readableForeground, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview, rgba255ToColor, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL, tryParseColor };
40
+ export { EXPORT_COLOR_PROFILE_NAMES, GamutHandling, OkHCLColor, OkHCLPayload, clearNodeFillOkHCL, clearNodeStrokeOkHCL, colorDistance, colorProfileSchema, colorSchema, colorToCSS, colorToCSSCompact, colorToFill, colorToHex, colorToHex8, colorToHexRaw, colorToProfileCSS, colorToRgba255, colorToSRGBHex, compositeOver, contrastRatio, convertColor, darkenForContrast, exportColorProfileSchema, fitIntoProfile, fitsGamut, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, linearSRGBMatrix, normalizeColor, okhclInProfile, okhclToRGBA, paintOkHCL, parseColor, parseDisplayableColor, parseOkHCLPayload, readableForeground, rememberPaintOkHCL, rgba255ToColor, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL, toExtendedSRGB, tryParseColor };
38
41
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/color/index.ts"],"mappings":";;;;;;;;iBAagB,cAAc,gBAAgB;;iBAa9B,WAAW,gBAAgB;iBAI3B,WAAW,OAAO;iBAIlB,YAAY,OAAO,OAAO;iBAM1B,cAAc,OAAO;iBAIrB,eAAe,OAAO;;;;;;iBAStB,WAAW,OAAO;iBAIlB,kBAAkB,OAAO;iBAOzB,eAAe,WAAW,WAAW,WAAW,aAAQ;iBAIxD,YAAY,gBAAgB;;;;;;;;;;;iBAY5B,cAAc,IAAI,OAAO,IAAI"}
1
+ {"version":3,"file":"index.d.ts","names":[],"sources":["../../src/color/index.ts"],"mappings":";;;;;;;;iBAYgB,WAAW,OAAO;;;;;iBAQlB,eAAe,OAAO,OAAO,SAAS;iBAItC,YAAY,OAAO,OAAO;iBAM1B,cAAc,OAAO;iBAIrB,eAAe,OAAO;;;;;;iBAStB,WAAW,OAAO;iBAIlB,kBAAkB,OAAO;iBAOzB,eAAe,WAAW,WAAW,WAAW,aAAQ;;iBAKxD,YAAY,gBAAgB,OAAO,UAAS;;;;;;;;;;;iBAY5C,cAAc,IAAI,OAAO,IAAI"}
@@ -1,28 +1,10 @@
1
- import { BLACK } from "../constants.js";
2
- import { colorSchema } from "./schema.js";
1
+ import { EXPORT_COLOR_PROFILE_NAMES, colorProfileSchema, colorSchema, exportColorProfileSchema } from "./schema.js";
3
2
  import { compositeOver, contrastRatio, darkenForContrast, readableForeground } from "./contrast.js";
4
3
  import { normalizeColor } from "./normalize.js";
5
- import { clearNodeFillOkHCL, clearNodeStrokeOkHCL, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, okhclToRGBA, parseOkHCLPayload, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL } from "./okhcl.js";
6
- import { colorToDisplayCSS, getDefaultRenderColorSpace, parseDisplayableColor, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview } from "./management.js";
7
- import { converter, differenceEuclidean, formatHex, formatHex8, formatRgb, parse } from "culori";
4
+ import { colorToProfileCSS, convertColor, fitIntoProfile, fitsGamut, linearSRGBMatrix, parseColor, parseDisplayableColor, toExtendedSRGB, tryParseColor } from "./management.js";
5
+ import { clearNodeFillOkHCL, clearNodeStrokeOkHCL, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, okhclInProfile, okhclToRGBA, paintOkHCL, parseOkHCLPayload, rememberPaintOkHCL, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL } from "./okhcl.js";
6
+ import { differenceEuclidean, formatHex, formatHex8, formatRgb } from "culori";
8
7
  //#region src/color/index.ts
9
- const toRGB = converter("rgb");
10
- /** A CSS color, or null when `input` is not one. */
11
- function tryParseColor(input) {
12
- const parsed = parse(input);
13
- if (!parsed) return null;
14
- const rgb = toRGB(parsed);
15
- return {
16
- r: rgb.r,
17
- g: rgb.g,
18
- b: rgb.b,
19
- a: parsed.alpha ?? 1
20
- };
21
- }
22
- /** A CSS color, or black when `input` is not one. */
23
- function parseColor(input) {
24
- return tryParseColor(input) ?? { ...BLACK };
25
- }
26
8
  function colorToHex(color) {
27
9
  return formatHex({
28
10
  mode: "rgb",
@@ -31,6 +13,13 @@ function colorToHex(color) {
31
13
  b: color.b
32
14
  }).toUpperCase();
33
15
  }
16
+ /**
17
+ * `color`, whose components are in `profile`, as the sRGB hex code tools display: hex holds sRGB
18
+ * only, so a color outside it is brought inside by reducing chroma, not clipped.
19
+ */
20
+ function colorToSRGBHex(color, profile) {
21
+ return colorToHex(convertColor(color, profile, "srgb", "map"));
22
+ }
34
23
  function colorToHex8(color, alpha) {
35
24
  const a = alpha ?? color.a;
36
25
  if (a >= 1) return colorToHex(color);
@@ -76,8 +65,9 @@ function rgba255ToColor(r, g, b, a = 1) {
76
65
  a
77
66
  };
78
67
  }
79
- function colorToFill(color) {
80
- const rgba = typeof color === "string" ? parseColor(color) : color;
68
+ /** A solid paint of `color`, a CSS color read into `profile` or components already in it. */
69
+ function colorToFill(color, profile = "srgb") {
70
+ const rgba = typeof color === "string" ? parseColor(color, profile) : color;
81
71
  return {
82
72
  type: "SOLID",
83
73
  color: {
@@ -105,6 +95,6 @@ function colorDistance(c1, c2) {
105
95
  }) * 255;
106
96
  }
107
97
  //#endregion
108
- export { clearNodeFillOkHCL, clearNodeStrokeOkHCL, colorDistance, colorSchema, colorToCSS, colorToCSSCompact, colorToDisplayCSS, colorToFill, colorToHex, colorToHex8, colorToHexRaw, colorToRgba255, compositeOver, contrastRatio, darkenForContrast, getDefaultRenderColorSpace, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, normalizeColor, okhclToRGBA, parseColor, parseDisplayableColor, parseOkHCLPayload, readableForeground, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview, rgba255ToColor, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL, tryParseColor };
98
+ export { EXPORT_COLOR_PROFILE_NAMES, clearNodeFillOkHCL, clearNodeStrokeOkHCL, colorDistance, colorProfileSchema, colorSchema, colorToCSS, colorToCSSCompact, colorToFill, colorToHex, colorToHex8, colorToHexRaw, colorToProfileCSS, colorToRgba255, colorToSRGBHex, compositeOver, contrastRatio, convertColor, darkenForContrast, exportColorProfileSchema, fitIntoProfile, fitsGamut, getFillOkHCL, getNodeOkHCLPayloads, getStrokeOkHCL, linearSRGBMatrix, normalizeColor, okhclInProfile, okhclToRGBA, paintOkHCL, parseColor, parseDisplayableColor, parseOkHCLPayload, readableForeground, rememberPaintOkHCL, rgba255ToColor, rgbaToOkHCL, serializeOkHCLPayload, setNodeFillOkHCL, setNodeStrokeOkHCL, toExtendedSRGB, tryParseColor };
109
99
 
110
100
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../../src/color/index.ts"],"sourcesContent":["export * from './contrast'\nexport * from './management'\nexport { normalizeColor } from './normalize'\nexport * from './okhcl'\n\nimport { parse, formatHex, formatHex8, formatRgb, converter, differenceEuclidean } from 'culori'\n\nimport { BLACK } from '../constants'\nimport type { Color } from '../primitives'\n\nconst toRGB = converter('rgb')\n\n/** A CSS color, or null when `input` is not one. */\nexport function tryParseColor(input: string): Color | null {\n const parsed = parse(input)\n if (!parsed) return null\n const rgb = toRGB(parsed)\n return {\n r: rgb.r,\n g: rgb.g,\n b: rgb.b,\n a: parsed.alpha ?? 1\n }\n}\n\n/** A CSS color, or black when `input` is not one. */\nexport function parseColor(input: string): Color {\n return tryParseColor(input) ?? { ...BLACK }\n}\n\nexport function colorToHex(color: Color): string {\n return formatHex({ mode: 'rgb', r: color.r, g: color.g, b: color.b }).toUpperCase()\n}\n\nexport function colorToHex8(color: Color, alpha?: number): string {\n const a = alpha ?? color.a\n if (a >= 1) return colorToHex(color)\n return formatHex8({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: a }).toUpperCase()\n}\n\nexport function colorToHexRaw(color: Color): string {\n return colorToHex(color).slice(1)\n}\n\nexport function colorToRgba255(color: Color) {\n return {\n r: Math.round(color.r * 255),\n g: Math.round(color.g * 255),\n b: Math.round(color.b * 255),\n a: color.a\n }\n}\n\nexport function colorToCSS(color: Color): string {\n return formatRgb({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n}\n\nexport function colorToCSSCompact(color: Color): string {\n const { r, g, b } = colorToRgba255(color)\n const a = Number(color.a.toFixed(3))\n if (a >= 1) return `rgb(${r},${g},${b})`\n return `rgba(${r},${g},${b},${a})`\n}\n\nexport function rgba255ToColor(r: number, g: number, b: number, a = 1): Color {\n return { r: r / 255, g: g / 255, b: b / 255, a }\n}\n\nexport function colorToFill(color: string | Color) {\n const rgba = typeof color === 'string' ? parseColor(color) : color\n return {\n type: 'SOLID' as const,\n color: { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a },\n opacity: rgba.a,\n visible: true\n }\n}\n\nconst euclideanRGB255 = differenceEuclidean('rgb')\n\nexport function colorDistance(c1: Color, c2: Color): number {\n return (\n euclideanRGB255(\n { mode: 'rgb', r: c1.r, g: c1.g, b: c1.b },\n { mode: 'rgb', r: c2.r, g: c2.g, b: c2.b }\n ) * 255\n )\n}\nexport * from './schema'\n"],"mappings":";;;;;;;;AAUA,MAAM,QAAQ,UAAU,KAAK;;AAG7B,SAAgB,cAAc,OAA6B;CACzD,MAAM,SAAS,MAAM,KAAK;CAC1B,IAAI,CAAC,QAAQ,OAAO;CACpB,MAAM,MAAM,MAAM,MAAM;CACxB,OAAO;EACL,GAAG,IAAI;EACP,GAAG,IAAI;EACP,GAAG,IAAI;EACP,GAAG,OAAO,SAAS;CACrB;AACF;;AAGA,SAAgB,WAAW,OAAsB;CAC/C,OAAO,cAAc,KAAK,KAAK,EAAE,GAAG,MAAM;AAC5C;AAEA,SAAgB,WAAW,OAAsB;CAC/C,OAAO,UAAU;EAAE,MAAM;EAAO,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,GAAG,MAAM;CAAE,CAAC,CAAC,CAAC,YAAY;AACpF;AAEA,SAAgB,YAAY,OAAc,OAAwB;CAChE,MAAM,IAAI,SAAS,MAAM;CACzB,IAAI,KAAK,GAAG,OAAO,WAAW,KAAK;CACnC,OAAO,WAAW;EAAE,MAAM;EAAO,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,OAAO;CAAE,CAAC,CAAC,CAAC,YAAY;AAC/F;AAEA,SAAgB,cAAc,OAAsB;CAClD,OAAO,WAAW,KAAK,CAAC,CAAC,MAAM,CAAC;AAClC;AAEA,SAAgB,eAAe,OAAc;CAC3C,OAAO;EACL,GAAG,KAAK,MAAM,MAAM,IAAI,GAAG;EAC3B,GAAG,KAAK,MAAM,MAAM,IAAI,GAAG;EAC3B,GAAG,KAAK,MAAM,MAAM,IAAI,GAAG;EAC3B,GAAG,MAAM;CACX;AACF;AAEA,SAAgB,WAAW,OAAsB;CAC/C,OAAO,UAAU;EAAE,MAAM;EAAO,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,GAAG,MAAM;EAAG,OAAO,MAAM;CAAE,CAAC;AACtF;AAEA,SAAgB,kBAAkB,OAAsB;CACtD,MAAM,EAAE,GAAG,GAAG,MAAM,eAAe,KAAK;CACxC,MAAM,IAAI,OAAO,MAAM,EAAE,QAAQ,CAAC,CAAC;CACnC,IAAI,KAAK,GAAG,OAAO,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE;CACtC,OAAO,QAAQ,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AAClC;AAEA,SAAgB,eAAe,GAAW,GAAW,GAAW,IAAI,GAAU;CAC5E,OAAO;EAAE,GAAG,IAAI;EAAK,GAAG,IAAI;EAAK,GAAG,IAAI;EAAK;CAAE;AACjD;AAEA,SAAgB,YAAY,OAAuB;CACjD,MAAM,OAAO,OAAO,UAAU,WAAW,WAAW,KAAK,IAAI;CAC7D,OAAO;EACL,MAAM;EACN,OAAO;GAAE,GAAG,KAAK;GAAG,GAAG,KAAK;GAAG,GAAG,KAAK;GAAG,GAAG,KAAK;EAAE;EACpD,SAAS,KAAK;EACd,SAAS;CACX;AACF;AAEA,MAAM,kBAAkB,oBAAoB,KAAK;AAEjD,SAAgB,cAAc,IAAW,IAAmB;CAC1D,OACE,gBACE;EAAE,MAAM;EAAO,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,GAAG,GAAG;CAAE,GACzC;EAAE,MAAM;EAAO,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,GAAG,GAAG;CAAE,CAC3C,IAAI;AAER"}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../../src/color/index.ts"],"sourcesContent":["export * from './contrast'\nexport * from './management'\nexport { normalizeColor } from './normalize'\nexport { colorProfileSchema, EXPORT_COLOR_PROFILE_NAMES, exportColorProfileSchema } from './schema'\nexport * from './okhcl'\n\nimport { formatHex, formatHex8, formatRgb, differenceEuclidean } from 'culori'\n\nimport type { Color } from '../primitives'\nimport type { ColorProfile } from '../types'\nimport { convertColor, parseColor } from './management'\n\nexport function colorToHex(color: Color): string {\n return formatHex({ mode: 'rgb', r: color.r, g: color.g, b: color.b }).toUpperCase()\n}\n\n/**\n * `color`, whose components are in `profile`, as the sRGB hex code tools display: hex holds sRGB\n * only, so a color outside it is brought inside by reducing chroma, not clipped.\n */\nexport function colorToSRGBHex(color: Color, profile: ColorProfile): string {\n return colorToHex(convertColor(color, profile, 'srgb', 'map'))\n}\n\nexport function colorToHex8(color: Color, alpha?: number): string {\n const a = alpha ?? color.a\n if (a >= 1) return colorToHex(color)\n return formatHex8({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: a }).toUpperCase()\n}\n\nexport function colorToHexRaw(color: Color): string {\n return colorToHex(color).slice(1)\n}\n\nexport function colorToRgba255(color: Color) {\n return {\n r: Math.round(color.r * 255),\n g: Math.round(color.g * 255),\n b: Math.round(color.b * 255),\n a: color.a\n }\n}\n\nexport function colorToCSS(color: Color): string {\n return formatRgb({ mode: 'rgb', r: color.r, g: color.g, b: color.b, alpha: color.a })\n}\n\nexport function colorToCSSCompact(color: Color): string {\n const { r, g, b } = colorToRgba255(color)\n const a = Number(color.a.toFixed(3))\n if (a >= 1) return `rgb(${r},${g},${b})`\n return `rgba(${r},${g},${b},${a})`\n}\n\nexport function rgba255ToColor(r: number, g: number, b: number, a = 1): Color {\n return { r: r / 255, g: g / 255, b: b / 255, a }\n}\n\n/** A solid paint of `color`, a CSS color read into `profile` or components already in it. */\nexport function colorToFill(color: string | Color, profile: ColorProfile = 'srgb') {\n const rgba = typeof color === 'string' ? parseColor(color, profile) : color\n return {\n type: 'SOLID' as const,\n color: { r: rgba.r, g: rgba.g, b: rgba.b, a: rgba.a },\n opacity: rgba.a,\n visible: true\n }\n}\n\nconst euclideanRGB255 = differenceEuclidean('rgb')\n\nexport function colorDistance(c1: Color, c2: Color): number {\n return (\n euclideanRGB255(\n { mode: 'rgb', r: c1.r, g: c1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,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE;AAClC;AAEA,SAAgB,eAAe,GAAW,GAAW,GAAW,IAAI,GAAU;CAC5E,OAAO;EAAE,GAAG,IAAI;EAAK,GAAG,IAAI;EAAK,GAAG,IAAI;EAAK;CAAE;AACjD;;AAGA,SAAgB,YAAY,OAAuB,UAAwB,QAAQ;CACjF,MAAM,OAAO,OAAO,UAAU,WAAW,WAAW,OAAO,OAAO,IAAI;CACtE,OAAO;EACL,MAAM;EACN,OAAO;GAAE,GAAG,KAAK;GAAG,GAAG,KAAK;GAAG,GAAG,KAAK;GAAG,GAAG,KAAK;EAAE;EACpD,SAAS,KAAK;EACd,SAAS;CACX;AACF;AAEA,MAAM,kBAAkB,oBAAoB,KAAK;AAEjD,SAAgB,cAAc,IAAW,IAAmB;CAC1D,OACE,gBACE;EAAE,MAAM;EAAO,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,GAAG,GAAG;CAAE,GACzC;EAAE,MAAM;EAAO,GAAG,GAAG;EAAG,GAAG,GAAG;EAAG,GAAG,GAAG;CAAE,CAC3C,IAAI;AAER"}
@@ -1,32 +1,60 @@
1
- import { Color } from "../primitives/index.js";
2
- import { DocumentColorSpace, Fill, SceneNode, Stroke } from "../types.js";
3
- import { OkHCLColor } from "./okhcl.js";
1
+ import { Color as Color$1 } from "../primitives/index.js";
2
+ import { ColorProfile } from "../types.js";
3
+ import { Color } from "culori";
4
4
  //#region src/color/management.d.ts
5
- type RenderColorSpace = 'srgb' | 'display-p3';
6
- type ColorIntentSpace = 'oklch' | 'srgb';
7
- interface ColorPreviewOptions {
8
- colorSpace?: RenderColorSpace;
9
- documentColorSpace?: DocumentColorSpace;
10
- }
11
- interface ResolvedRenderColor {
12
- color: Color;
13
- cssColor: string;
14
- sourceSpace: ColorIntentSpace;
15
- targetSpace: RenderColorSpace;
5
+ /** Whether `color`'s components fit 0 to 1, give or take round-off. */
6
+ declare function fitsGamut(color: Pick<Color$1, 'r' | 'g' | 'b'>): boolean;
7
+ /**
8
+ * `color`, a culori color in any space, as components in `profile`, brought inside it the way CSS
9
+ * maps out-of-gamut colors, by reducing chroma in OKLCH so lightness and hue hold, and whether it
10
+ * had to be. A color inside already keeps its components, as mapping it would shift them by float
11
+ * noise; one on the gamut's edge, as every saturated primary is, counts as inside despite
12
+ * round-off. A missing (`none`) component reads as zero.
13
+ */
14
+ declare function fitIntoProfile(color: Color, profile: ColorProfile): {
15
+ color: Color$1;
16
16
  clipped: boolean;
17
- }
18
- declare function resolveOkHCLForPreview(color: OkHCLColor, options?: ColorPreviewOptions): ResolvedRenderColor;
17
+ };
18
+ /**
19
+ * What to do with a color the target profile cannot show: `extend` keeps its components past 0
20
+ * and 1, for a renderer such as Skia that takes extended sRGB; `map` brings it inside by reducing
21
+ * chroma in OKLCH, as CSS maps out-of-gamut colors, keeping its lightness and hue.
22
+ */
23
+ type GamutHandling = 'extend' | 'map';
24
+ /** `color`, whose components are in `from`, as the components in `to` that show the same color. */
25
+ declare function convertColor(color: Color$1, from: ColorProfile, to: ColorProfile, gamut?: GamutHandling): Color$1;
26
+ /**
27
+ * `color`, whose components are in `profile`, as the sRGB components of the same color: past 0 and
28
+ * 1 where it lies outside sRGB. Skia takes colors this way and converts them into the space of
29
+ * whatever it draws on, so a wide-gamut color reaches it whole.
30
+ */
31
+ declare function toExtendedSRGB(color: Color$1, profile: ColorProfile): Color$1;
32
+ /**
33
+ * `color`, whose components are in `from`, as CSS showing it in `to`: `color(display-p3 …)` for
34
+ * Display P3, `rgb()` for sRGB, where a color outside sRGB clips per channel as a canvas clips it.
35
+ */
36
+ declare function colorToProfileCSS(color: Color$1, from: ColorProfile, to: ColorProfile): string;
37
+ /**
38
+ * The 3×3 matrix, row by row, taking linear components in `profile` to linear sRGB ones: its
39
+ * columns are the profile's primaries in linear sRGB.
40
+ */
41
+ declare function linearSRGBMatrix(profile: ColorProfile): number[];
19
42
  /**
20
43
  * A CSS color in any space, mapped into sRGB the way CSS maps out-of-gamut colors: by reducing
21
44
  * chroma in OKLCH, so a Display P3 red becomes the nearest sRGB red, not a clipped one. A missing
22
45
  * (`none`) component reads as zero. Null when `input` is not a color.
23
46
  */
24
- declare function parseDisplayableColor(input: string): Color | null;
25
- declare function resolveRGBAForPreview(color: Color, options?: ColorPreviewOptions): ResolvedRenderColor;
26
- declare function resolveNodeFillColor(fill: Fill, fillIndex: number, node: SceneNode, options?: ColorPreviewOptions): ResolvedRenderColor;
27
- declare function resolveNodeStrokeColor(stroke: Stroke, strokeIndex: number, node: SceneNode, options?: ColorPreviewOptions): ResolvedRenderColor;
28
- declare function colorToDisplayCSS(color: Color, options?: ColorPreviewOptions): string;
29
- declare function getDefaultRenderColorSpace(): RenderColorSpace;
47
+ declare function parseDisplayableColor(input: string): Color$1 | null;
48
+ /**
49
+ * A CSS color as components in `profile`, or null when `input` is not one. Hex and the other sRGB
50
+ * syntaxes give their numbers as they are, as Figma takes typed or imported hex as the document's
51
+ * own numbers in either profile. A color that names its space, such as `color(display-p3 …)` or
52
+ * `oklch()`, is converted into `profile`, and brought inside it by reducing chroma when the
53
+ * profile cannot show it.
54
+ */
55
+ declare function tryParseColor(input: string, profile?: ColorProfile): Color$1 | null;
56
+ /** A CSS color as components in `profile`, or black when `input` is not one. */
57
+ declare function parseColor(input: string, profile?: ColorProfile): Color$1;
30
58
  //#endregion
31
- export { ColorIntentSpace, ColorPreviewOptions, RenderColorSpace, ResolvedRenderColor, colorToDisplayCSS, getDefaultRenderColorSpace, parseDisplayableColor, resolveNodeFillColor, resolveNodeStrokeColor, resolveOkHCLForPreview, resolveRGBAForPreview };
59
+ export { GamutHandling, colorToProfileCSS, convertColor, fitIntoProfile, fitsGamut, linearSRGBMatrix, parseColor, parseDisplayableColor, toExtendedSRGB, tryParseColor };
32
60
  //# sourceMappingURL=management.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"management.d.ts","names":[],"sources":["../../src/color/management.ts"],"mappings":";;;;KAOY;KACA;UAEK;EACf,aAAa;EACb,qBAAqB;;UAGN;EACf,OAAO;EACP;EACA,aAAa;EACb,aAAa;EACb;;iBA0Ec,uBACd,OAAO,YACP,UAAU,sBACT;;;;;;iBA2Da,sBAAsB,gBAAgB;iBAStC,sBACd,OAAO,OACP,UAAU,sBACT;iBAaa,qBACd,MAAM,MACN,mBACA,MAAM,WACN,UAAU,sBACT;iBAMa,uBACd,QAAQ,QACR,qBACA,MAAM,WACN,UAAU,sBACT;iBAMa,kBAAkB,OAAO,OAAO,UAAU;iBAI1C,8BAA8B"}
1
+ {"version":3,"file":"management.d.ts","names":[],"sources":["../../src/color/management.ts"],"mappings":";;;;;iBAoBgB,UAAU,OAAO,KAAK;;;;;;;;iBAmBtB,eACd,OAAO,OACP,SAAS;EACN,OAAO;EAAO;;;;;;;KA8BP;;iBAGI,aACd,OAAO,SACP,MAAM,cACN,IAAI,cACJ,QAAO,gBACN;;;;;;iBAWa,eAAe,OAAO,SAAO,SAAS,eAAe;;;;;iBAkCrD,kBAAkB,OAAO,SAAO,MAAM,cAAc,IAAI;;;;;iBAYxD,iBAAiB,SAAS;;;;;;iBAkB1B,sBAAsB,gBAAgB;;;;;;;;iBAetC,cAAc,eAAe,UAAS,eAAwB;;iBAa9D,WAAW,eAAe,UAAS,eAAwB"}