@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 +1 @@
1
- {"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { createInstanceOverrideState } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\n/** A caller's list, or a fresh empty one: a list default belongs to the one layer it was made for. */\nfunction ownList<T>(given: T[] | undefined): T[] {\n return given ?? []\n}\n\n/** A caller's record, or a fresh empty one, for the same reason. */\nfunction ownRecord<V>(given: Record<string, V> | undefined): Record<string, V> {\n return given ?? {}\n}\n\n/** A new layer's fills: black on text, none elsewhere. */\nfunction defaultFills(type: NodeType): SceneNode['fills'] {\n return type === 'TEXT' ? [{ type: 'SOLID', color: BLACK, opacity: 1, visible: true }] : []\n}\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n // A literal ending in a spread is built one field at a time, and V8 keeps an object given this\n // many fields that way in dictionary mode, about 3 KB more per layer; a spread copy of a\n // finished literal keeps fast fields, in JavaScriptCore as well.\n // Imports supply most lists and records, so a default is made only where the caller gives none.\n const defaults = {\n id: generateId(),\n type,\n name: type.charAt(0) + type.slice(1).toLowerCase(),\n parentId: null,\n childIds: ownList(overrides.childIds),\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: overrides.source ?? createDefaultSourceMetadata(),\n derivedLayout: null,\n fills: overrides.fills ?? defaultFills(type),\n strokes: ownList(overrides.strokes),\n effects: ownList(overrides.effects),\n layoutGrids: ownList(overrides.layoutGrids),\n guides: ownList(overrides.guides),\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: ownList(overrides.fillGeometry),\n strokeGeometry: ownList(overrides.strokeGeometry),\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: ownList(overrides.textDecorationFills),\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: ownList(overrides.textParagraphs),\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: ownList(overrides.styleRuns),\n fontVariations: ownList(overrides.fontVariations),\n opticalSizeFromFontSize: true,\n fontFeatures: ownList(overrides.fontFeatures),\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: ownList(overrides.dashPattern),\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: ownList(overrides.connectorControlPoints),\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: ownList(overrides.gridTemplateColumns),\n gridTemplateRows: ownList(overrides.gridTemplateRows),\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n // Figma's: the golden-ratio star, whose inner points line up with its outer ones.\n starInnerRadius: (3 - Math.sqrt(5)) / 2,\n shapeWithTextType: 'SQUARE',\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: overrides.instanceOverrides ?? createInstanceOverrideState(),\n componentPropertyDefinitions: ownList(overrides.componentPropertyDefinitions),\n componentPropertyReferences: ownList(overrides.componentPropertyReferences),\n componentPropertyAssignments: ownRecord(overrides.componentPropertyAssignments),\n componentPropertyValues: ownRecord(overrides.componentPropertyValues),\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n libraryLayerId: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: ownList(overrides.symbolLinks),\n variantPropSpecs: ownList(overrides.variantPropSpecs),\n boundVariables: ownRecord(overrides.boundVariables),\n variableBindingScales: ownRecord(overrides.variableBindingScales),\n variableAssignmentScales: ownRecord(overrides.variableAssignmentScales),\n componentScale: 1,\n variableModes: ownRecord(overrides.variableModes),\n exportSettings: ownList(overrides.exportSettings),\n status: null,\n pluginData: ownList(overrides.pluginData),\n pluginRelaunchData: ownList(overrides.pluginRelaunchData),\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined\n } satisfies CompleteNodeFields\n return { ...defaults, ...overrides }\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/** The kinds that hold layers of their own on the canvas: what a shadow or a clip encloses. */\nexport const LAYER_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\nexport function isLayerContainer(node: Pick<SceneNode, 'type'>): boolean {\n return LAYER_CONTAINER_TYPES.has(node.type)\n}\n\n/** The kinds that clip their children when their clip content is on. */\nexport const CLIPPING_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n\n/**\n * Whether a layer clips its children: a frame, component, component set or instance with clip\n * content on. A section or group has no such setting in Figma and never clips, whatever an import\n * left in `clipsContent` (Figma desktop, live).\n */\nexport function clipsChildren(node: Pick<SceneNode, 'type' | 'clipsContent'>): boolean {\n return node.clipsContent && CLIPPING_TYPES.has(node.type)\n}\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE'\n])\n"],"mappings":";;;;AAUA,SAAgB,8BAA8C;CAC5D,OAAO;EACL,QAAQ;EACR,IAAI;EACJ,UAAU;EACV,cAAc,CAAC;EACf,KAAK;GACH,SAAS;GACT,cAAc;GACd,eAAe,CAAC;GAChB,QAAQ;GACR,iBAAiB,CAAC;GAClB,0BAA0B,CAAC;GAC3B,mBAAmB,CAAC;GACpB,gCAAgC;GAChC,oBAAoB;EACtB;CACF;AACF;;AAUA,SAAgB,mBAAmB,MAA0C;CAC3E,IAAI,SAAS,UAAU,SAAS,UAAU,OAAO;CACjD,OAAO,SAAS,SAAS,YAAY;AACvC;;;;;AAMA,SAAgB,kBACd,MACwD;CACxD,MAAM,QAAQ,KAAK,QAAQ,GAAG,CAAC;CAC/B,OAAO;EAAE,QAAQ,OAAO,UAAU,KAAK;EAAc,OAAO,OAAO,SAAS,KAAK;CAAY;AAC/F;;AAGA,SAAS,QAAW,OAA6B;CAC/C,OAAO,SAAS,CAAC;AACnB;;AAGA,SAAS,UAAa,OAAyD;CAC7E,OAAO,SAAS,CAAC;AACnB;;AAGA,SAAS,aAAa,MAAoC;CACxD,OAAO,SAAS,SAAS,CAAC;EAAE,MAAM;EAAS,OAAO;EAAO,SAAS;EAAG,SAAS;CAAK,CAAC,IAAI,C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b,qBAAqB;EACrB,kBAAkB;EAClB,eAAe;EACf,gBAAgB;EAChB,eAAe;EACf,qBAAqB;EACrB,mBAAmB;EACnB,mBAAmB;EACnB,aAAa,QAAQ,UAAU,WAAW;EAC1C,kBAAkB,QAAQ,UAAU,gBAAgB;EACpD,gBAAgB,UAAU,UAAU,cAAc;EAClD,uBAAuB,UAAU,UAAU,qBAAqB;EAChE,0BAA0B,UAAU,UAAU,wBAAwB;EACtE,gBAAgB;EAChB,eAAe,UAAU,UAAU,aAAa;EAChD,gBAAgB,QAAQ,UAAU,cAAc;EAChD,QAAQ;EACR,YAAY,QAAQ,UAAU,UAAU;EACxC,oBAAoB,QAAQ,UAAU,kBAAkB;EACxD,cAAc;EACd,OAAO;EACP,OAAO;EACP,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,cAAc;EACd,aAAa;EACb,kBAAkB,KAAA;EAEE,GAAG;CAAU;AACrC;;AAGA,MAAa,yCAAgD,IAAI,IAAc,CAC7E,SACA,mBACF,CAAC;;AAGD,MAAa,oCAA2C,IAAI,IAAc;CACxE;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAa,wCAA+C,IAAI,IAAc;CAC5E;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,iBAAiB,MAAwC;CACvE,OAAO,sBAAsB,IAAI,KAAK,IAAI;AAC5C;;AAGA,MAAa,iCAAwC,IAAI,IAAc;CACrE;CACA;CACA;CACA;AACF,CAAC;;;;;;AAOD,SAAgB,cAAc,MAAyD;CACrF,OAAO,KAAK,gBAAgB,eAAe,IAAI,KAAK,IAAI;AAC1D;AAEA,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
1
+ {"version":3,"file":"node-defaults.js","names":[],"sources":["../src/node-defaults.ts"],"sourcesContent":["import {\n BLACK,\n DEFAULT_FONT_FAMILY,\n DEFAULT_STROKE_MITER_LIMIT,\n DEFAULT_STROKE_WEIGHT\n} from './constants'\nimport { createInstanceOverrideState } from './instances/overrides'\nimport { NO_LETTER_SPACING } from './text/lengths'\nimport type { NodeType, SceneNode, SourceMetadata } from './types'\n\n/** The name a layer of `type` starts with: its type in words, as Figma names a new layer. */\nexport function defaultNodeName(type: NodeType): string {\n const words = type.toLowerCase().replaceAll('_', ' ')\n return words.charAt(0).toUpperCase() + words.slice(1)\n}\n\nexport function createDefaultSourceMetadata(): SourceMetadata {\n return {\n format: null,\n id: null,\n orderKey: null,\n editedFields: [],\n fig: {\n rawSize: null,\n rawTransform: null,\n rawNodeFields: {},\n layout: null,\n symbolOverrides: [],\n componentPropAssignments: [],\n hiddenSlotAssignments: [],\n derivedSymbolData: [],\n derivedSymbolDataLayoutVersion: null,\n uniformScaleFactor: null\n }\n }\n}\n\n/**\n * Every SceneNode field. Nodes start with all of them, so setting any field later keeps the\n * shape every node shares; a key added after creation turns a JavaScriptCore object into a\n * slower, larger dictionary.\n */\ntype CompleteNodeFields = SceneNode & Record<keyof SceneNode, unknown>\n\n/** Where Figma aligns a new node's strokes: centered on lines and vectors, outside text, else inside. */\nexport function defaultStrokeAlign(type: NodeType): SceneNode['strokeAlign'] {\n if (type === 'LINE' || type === 'VECTOR') return 'CENTER'\n return type === 'TEXT' ? 'OUTSIDE' : 'INSIDE'\n}\n\n/**\n * Weight and alignment a stroke added to `node` takes: its first stroke's, or what the node keeps\n * with none. Adding a stroke from the panel and from the plugin API both go through here.\n */\nexport function newStrokeGeometry(\n node: Pick<SceneNode, 'strokes' | 'strokeWeight' | 'strokeAlign'>\n): Pick<SceneNode['strokes'][number], 'weight' | 'align'> {\n const first = node.strokes.at(0)\n return { weight: first?.weight ?? node.strokeWeight, align: first?.align ?? node.strokeAlign }\n}\n\n/** A caller's list, or a fresh empty one: a list default belongs to the one layer it was made for. */\nfunction ownList<T>(given: T[] | undefined): T[] {\n return given ?? []\n}\n\n/** A caller's record, or a fresh empty one, for the same reason. */\nfunction ownRecord<V>(given: Record<string, V> | undefined): Record<string, V> {\n return given ?? {}\n}\n\n/** A new layer's fills: black on text, none elsewhere. */\nfunction defaultFills(type: NodeType): SceneNode['fills'] {\n return type === 'TEXT' ? [{ type: 'SOLID', color: BLACK, opacity: 1, visible: true }] : []\n}\n\nexport function createDefaultNode(\n generateId: () => string,\n type: NodeType,\n overrides: Partial<SceneNode> = {}\n): SceneNode {\n // A literal ending in a spread is built one field at a time, and V8 keeps an object given this\n // many fields that way in dictionary mode, about 3 KB more per layer; a spread copy of a\n // finished literal keeps fast fields, in JavaScriptCore as well.\n // Imports supply most lists and records, so a default is made only where the caller gives none.\n const defaults = {\n id: generateId(),\n type,\n name: defaultNodeName(type),\n parentId: null,\n childIds: ownList(overrides.childIds),\n x: 0,\n y: 0,\n width: 100,\n height: 100,\n rotation: 0,\n source: overrides.source ?? createDefaultSourceMetadata(),\n derivedLayout: null,\n fills: overrides.fills ?? defaultFills(type),\n strokes: ownList(overrides.strokes),\n effects: ownList(overrides.effects),\n layoutGrids: ownList(overrides.layoutGrids),\n guides: ownList(overrides.guides),\n fillStyleId: null,\n strokeStyleId: null,\n textStyleId: null,\n effectStyleId: null,\n gridStyleId: null,\n sharedStyleType: null,\n opacity: 1,\n cornerRadius: 0,\n topLeftRadius: 0,\n topRightRadius: 0,\n bottomRightRadius: 0,\n bottomLeftRadius: 0,\n independentCorners: false,\n cornerSmoothing: 0,\n visible: true,\n locked: false,\n clipsContent: false,\n text: '',\n fontSize: 14,\n fontFamily: DEFAULT_FONT_FAMILY,\n fontWeight: 400,\n italic: false,\n fontStyle: null,\n textAlignHorizontal: 'LEFT',\n textDirection: 'AUTO',\n textLanguage: null,\n leadingTrim: 'NONE',\n lineHeight: null,\n letterSpacing: NO_LETTER_SPACING,\n layoutMode: 'NONE',\n layoutDirection: 'AUTO',\n layoutWrap: 'NO_WRAP',\n primaryAxisAlign: 'MIN',\n counterAxisAlign: 'MIN',\n primaryAxisSizing: 'FIXED',\n counterAxisSizing: 'FIXED',\n itemSpacing: 0,\n counterAxisSpacing: 0,\n paddingTop: 0,\n paddingRight: 0,\n paddingBottom: 0,\n paddingLeft: 0,\n blendMode: 'PASS_THROUGH',\n layoutPositioning: 'AUTO',\n layoutGrow: 0,\n layoutAlignSelf: 'AUTO',\n vectorNetwork: null,\n handleMirroring: 'NONE',\n fillGeometry: ownList(overrides.fillGeometry),\n strokeGeometry: ownList(overrides.strokeGeometry),\n arcData: null,\n textAlignVertical: 'TOP',\n textAutoResize: 'NONE',\n textCase: 'ORIGINAL',\n textDecoration: 'NONE',\n textDecorationStyle: 'SOLID',\n textDecorationThickness: null,\n textDecorationFills: ownList(overrides.textDecorationFills),\n textDecorationSkipInk: true,\n textUnderlineOffset: null,\n maxLines: null,\n textParagraphs: ownList(overrides.textParagraphs),\n listSpacing: 0,\n paragraphSpacing: 0,\n paragraphIndent: 0,\n hangingList: false,\n styleRuns: ownList(overrides.styleRuns),\n fontVariations: ownList(overrides.fontVariations),\n opticalSizeFromFontSize: true,\n fontFeatures: ownList(overrides.fontFeatures),\n horizontalConstraint: 'MIN',\n verticalConstraint: 'MIN',\n strokeCap: 'NONE',\n strokeJoin: 'MITER',\n dashPattern: ownList(overrides.dashPattern),\n borderTopWeight: 0,\n borderRightWeight: 0,\n borderBottomWeight: 0,\n borderLeftWeight: 0,\n independentStrokeWeights: false,\n strokeWeight: DEFAULT_STROKE_WEIGHT,\n strokeAlign: defaultStrokeAlign(type),\n strokeMiterLimit: DEFAULT_STROKE_MITER_LIMIT,\n minWidth: null,\n maxWidth: null,\n minHeight: null,\n maxHeight: null,\n targetAspectRatio: null,\n connectorStart: null,\n connectorEnd: null,\n connectorLineType: 'ELBOWED',\n connectorStartCap: 'ROUND',\n connectorEndCap: 'ARROW_LINES',\n connectorControlPoints: ownList(overrides.connectorControlPoints),\n connectorCurveHandles: null,\n connectorLabelPosition: null,\n isMask: false,\n maskType: 'ALPHA',\n maskIsOutline: false,\n gridTemplateColumns: ownList(overrides.gridTemplateColumns),\n gridTemplateRows: ownList(overrides.gridTemplateRows),\n gridColumnGap: 0,\n gridRowGap: 0,\n gridPosition: null,\n counterAxisAlignContent: 'AUTO',\n itemReverseZIndex: false,\n strokesIncludedInLayout: false,\n expanded: true,\n textTruncation: 'DISABLED',\n autoRename: true,\n pointCount: 5,\n // Figma's: the golden-ratio star, whose inner points line up with its outer ones.\n starInnerRadius: (3 - Math.sqrt(5)) / 2,\n shapeWithTextType: 'SQUARE',\n slide: null,\n animation: null,\n shapeUserHeight: 0,\n shapeTruncates: false,\n componentId: null,\n instanceOverrides: overrides.instanceOverrides ?? createInstanceOverrideState(),\n componentPropertyDefinitions: ownList(overrides.componentPropertyDefinitions),\n componentPropertyReferences: ownList(overrides.componentPropertyReferences),\n componentPropertyAssignments: ownRecord(overrides.componentPropertyAssignments),\n componentPropertyValues: ownRecord(overrides.componentPropertyValues),\n componentKey: null,\n sourceLibraryKey: null,\n publishId: null,\n overrideKey: null,\n sharedSymbolVersion: null,\n publishedVersion: null,\n librarySource: null,\n libraryLayerId: null,\n isPublishable: false,\n isSymbolPublishable: false,\n isExposedInstance: false,\n symbolDescription: '',\n symbolLinks: ownList(overrides.symbolLinks),\n variantPropSpecs: ownList(overrides.variantPropSpecs),\n boundVariables: ownRecord(overrides.boundVariables),\n variableBindingScales: ownRecord(overrides.variableBindingScales),\n variableAssignmentScales: ownRecord(overrides.variableAssignmentScales),\n componentScale: 1,\n variableModes: ownRecord(overrides.variableModes),\n exportSettings: ownList(overrides.exportSettings),\n status: null,\n pluginData: ownList(overrides.pluginData),\n pluginRelaunchData: ownList(overrides.pluginRelaunchData),\n internalOnly: false,\n flipX: false,\n flipY: false,\n textPicture: null,\n derivedTextGlyphs: null,\n derivedTextHeight: null,\n textPathData: null,\n textPathBox: null,\n booleanOperation: undefined\n } satisfies CompleteNodeFields\n return { ...defaults, ...overrides }\n}\n\n/** Containers whose bounds follow their children and that set no coordinate space, as in Figma. */\nexport const FITTED_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'GROUP',\n 'BOOLEAN_OPERATION'\n])\n\n/** Layers whose stroke can take a weight per side, as Figma's `strokeTopWeight` and its siblings. */\nexport const SIDE_STROKE_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'RECTANGLE',\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'SLIDE'\n])\n\n/** The kinds that hold layers of their own on the canvas: what a shadow or a clip encloses. */\nexport const LAYER_CONTAINER_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'GROUP',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'SLIDE',\n 'SLIDE_ROW',\n 'SLIDE_GRID'\n])\n\nexport function isLayerContainer(node: Pick<SceneNode, 'type'>): boolean {\n return LAYER_CONTAINER_TYPES.has(node.type)\n}\n\n/** The kinds that clip their children when their clip content is on. */\nexport const CLIPPING_TYPES: ReadonlySet<NodeType> = new Set<NodeType>([\n 'FRAME',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'SLIDE'\n])\n\n/**\n * Whether a layer clips its children: a frame, component, component set or instance with clip\n * content on. A section or group has no such setting in Figma and never clips, whatever an import\n * left in `clipsContent` (Figma desktop, live).\n */\nexport function clipsChildren(node: Pick<SceneNode, 'type' | 'clipsContent'>): boolean {\n return node.clipsContent && CLIPPING_TYPES.has(node.type)\n}\n\nexport const CONTAINER_TYPES = new Set<NodeType>([\n 'CANVAS',\n 'FRAME',\n 'GROUP',\n 'BOOLEAN_OPERATION',\n 'SECTION',\n 'COMPONENT',\n 'COMPONENT_SET',\n 'INSTANCE',\n 'SLIDE',\n 'SLIDE_ROW',\n 'SLIDE_GRID'\n])\n"],"mappings":";;;;;AAWA,SAAgB,gBAAgB,MAAwB;CACtD,MAAM,QAAQ,KAAK,YAAY,CAAC,CAAC,WAAW,KAAK,GAAG;CACpD,OAAO,MAAM,OAAO,CAAC,CAAC,CAAC,YAAY,IAAI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c;EACd,OAAO;EACP,OAAO;EACP,aAAa;EACb,mBAAmB;EACnB,mBAAmB;EACnB,cAAc;EACd,aAAa;EACb,kBAAkB,KAAA;EAEE,GAAG;CAAU;AACrC;;AAGA,MAAa,yCAAgD,IAAI,IAAc,CAC7E,SACA,mBACF,CAAC;;AAGD,MAAa,oCAA2C,IAAI,IAAc;CACxE;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;AAGD,MAAa,wCAA+C,IAAI,IAAc;CAC5E;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,SAAgB,iBAAiB,MAAwC;CACvE,OAAO,sBAAsB,IAAI,KAAK,IAAI;AAC5C;;AAGA,MAAa,iCAAwC,IAAI,IAAc;CACrE;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;AAOD,SAAgB,cAAc,MAAyD;CACrF,OAAO,KAAK,gBAAgB,eAAe,IAAI,KAAK,IAAI;AAC1D;AAEA,MAAa,kCAAkB,IAAI,IAAc;CAC/C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC"}
@@ -1,4 +1,6 @@
1
- import { PatternTileLayout, patternTileLayout } from "./pattern.js";
1
+ import { PatternTileLayout, createPatternSourceLookup, patternSourceIds, patternTileLayout, resolvedPatternSourceIds } from "./pattern.js";
2
2
  import { fillSchema, gradientStopSchema, paintTransformSchema } from "./schema.js";
3
- import { paintShows } from "./shows.js";
4
- export { PatternTileLayout, fillSchema, gradientStopSchema, paintShows, paintTransformSchema, patternTileLayout };
3
+ import { isDrawnPaint, isFigmaShaderPaint, paintShows } from "./shows.js";
4
+ import { solidPaintColor } from "./solid.js";
5
+ import { StillFrame, StillFrameEncoding, StillPaint, createStillPaint, isStillFrameCurrent, readStillPaints, renameStillPaintImage, stillContentKey, stillFrameEncoding, stillFramePixels, stillPaintOf, withStillPaints } from "./stills.js";
6
+ export { PatternTileLayout, StillFrame, StillFrameEncoding, StillPaint, createPatternSourceLookup, createStillPaint, fillSchema, gradientStopSchema, isDrawnPaint, isFigmaShaderPaint, isStillFrameCurrent, paintShows, paintTransformSchema, patternSourceIds, patternTileLayout, readStillPaints, renameStillPaintImage, resolvedPatternSourceIds, solidPaintColor, stillContentKey, stillFrameEncoding, stillFramePixels, stillPaintOf, withStillPaints };
@@ -1,4 +1,6 @@
1
- import { paintShows } from "./shows.js";
2
- import { patternTileLayout } from "./pattern.js";
1
+ import { isDrawnPaint, isFigmaShaderPaint, paintShows } from "./shows.js";
2
+ import { solidPaintColor } from "./solid.js";
3
+ import { createStillPaint, isStillFrameCurrent, readStillPaints, renameStillPaintImage, stillContentKey, stillFrameEncoding, stillFramePixels, stillPaintOf, withStillPaints } from "./stills.js";
4
+ import { createPatternSourceLookup, patternSourceIds, patternTileLayout, resolvedPatternSourceIds } from "./pattern.js";
3
5
  import { fillSchema, gradientStopSchema, paintTransformSchema } from "./schema.js";
4
- export { fillSchema, gradientStopSchema, paintShows, paintTransformSchema, patternTileLayout };
6
+ export { createPatternSourceLookup, createStillPaint, fillSchema, gradientStopSchema, isDrawnPaint, isFigmaShaderPaint, isStillFrameCurrent, paintShows, paintTransformSchema, patternSourceIds, patternTileLayout, readStillPaints, renameStillPaintImage, resolvedPatternSourceIds, solidPaintColor, stillContentKey, stillFrameEncoding, stillFramePixels, stillPaintOf, withStillPaints };
@@ -1,4 +1,5 @@
1
1
  import { Rect, Vector } from "../primitives/index.js";
2
+ import { SceneGraph } from "../graph.js";
2
3
  import { Fill, SceneNode } from "../types.js";
3
4
  //#region src/paints/pattern.d.ts
4
5
  /** Where a pattern's source repeats in one tile: the tile, the source's scale, and its copies. */
@@ -8,6 +9,9 @@ interface PatternTileLayout {
8
9
  positions: Vector[];
9
10
  }
10
11
  declare function patternTileLayout(source: Pick<SceneNode, 'width' | 'height'>, fill: Fill): PatternTileLayout;
12
+ declare function patternSourceIds(node: SceneNode): string[];
13
+ declare function createPatternSourceLookup(graph: SceneGraph): (sourceId: string) => SceneNode | null;
14
+ declare function resolvedPatternSourceIds(node: SceneNode, findSource: (sourceId: string) => SceneNode | null): string[];
11
15
  //#endregion
12
- export { PatternTileLayout, patternTileLayout };
16
+ export { PatternTileLayout, createPatternSourceLookup, patternSourceIds, patternTileLayout, resolvedPatternSourceIds };
13
17
  //# sourceMappingURL=pattern.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pattern.d.ts","names":[],"sources":["../../src/paints/pattern.ts"],"mappings":";;;;UAIiB;EACf,MAAM;EACN;EACA,WAAW;;iBAcG,kBACd,QAAQ,KAAK,gCACb,MAAM,OACL"}
1
+ {"version":3,"file":"pattern.d.ts","names":[],"sources":["../../src/paints/pattern.ts"],"mappings":";;;;;UAKiB;EACf,MAAM;EACN;EACA,WAAW;;iBAcG,kBACd,QAAQ,KAAK,gCACb,MAAM,OACL;iBA8Ba,iBAAiB,MAAM;iBAyBvB,0BACd,OAAO,cACL,qBAAqB;iBAYT,yBACd,MAAM,WACN,aAAa,qBAAqB"}
@@ -41,7 +41,39 @@ function patternTileLayout(source, fill) {
41
41
  positions
42
42
  };
43
43
  }
44
+ function addPatternSourceIds(paints, ids) {
45
+ for (const paint of paints) if (paint.type === "PATTERN" && paint.sourceNodeId) ids.push(paint.sourceNodeId);
46
+ }
47
+ function patternSourceIds(node) {
48
+ const ids = [];
49
+ addPatternSourceIds(node.fills, ids);
50
+ addPatternSourceIds(node.strokes, ids);
51
+ addPatternSourceIds(node.textDecorationFills, ids);
52
+ for (const region of node.vectorNetwork?.regions ?? []) addPatternSourceIds(region.fills ?? [], ids);
53
+ for (const run of node.styleRuns) {
54
+ addPatternSourceIds(run.style.fills ?? [], ids);
55
+ addPatternSourceIds(run.style.textDecorationFills ?? [], ids);
56
+ }
57
+ return ids;
58
+ }
59
+ function indexBySourceId(graph) {
60
+ const index = /* @__PURE__ */ new Map();
61
+ for (const node of graph.getAllNodes()) if (node.source.id && !index.has(node.source.id)) index.set(node.source.id, node);
62
+ return index;
63
+ }
64
+ function createPatternSourceLookup(graph) {
65
+ let bySourceId = null;
66
+ return (sourceId) => {
67
+ const direct = graph.getNode(sourceId);
68
+ if (direct) return direct;
69
+ bySourceId ??= indexBySourceId(graph);
70
+ return bySourceId.get(sourceId) ?? null;
71
+ };
72
+ }
73
+ function resolvedPatternSourceIds(node, findSource) {
74
+ return patternSourceIds(node).flatMap((sourceId) => findSource(sourceId)?.id ?? []);
75
+ }
44
76
  //#endregion
45
- export { patternTileLayout };
77
+ export { createPatternSourceLookup, patternSourceIds, patternTileLayout, resolvedPatternSourceIds };
46
78
 
47
79
  //# sourceMappingURL=pattern.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"pattern.js","names":[],"sources":["../../src/paints/pattern.ts"],"sourcesContent":["import type { Rect, Vector } from '../primitives'\nimport type { Fill, SceneNode } from '../types'\n\n/** Where a pattern's source repeats in one tile: the tile, the source's scale, and its copies. */\nexport interface PatternTileLayout {\n rect: Rect\n scale: number\n positions: Vector[]\n}\n\nfunction patternAlignmentOffset(\n alignment: Fill['horizontalAlignment'],\n gap: number,\n sourceSize: number,\n axis: 'x' | 'y'\n): number {\n if (alignment === 'CENTER') return axis === 'x' ? -gap / 2 : -sourceSize / 2\n if (alignment === 'END') return -gap\n return 0\n}\n\nexport function patternTileLayout(\n source: Pick<SceneNode, 'width' | 'height'>,\n fill: Fill\n): PatternTileLayout {\n const scale = fill.scale && fill.scale > 0 ? fill.scale : 1\n const spacing = fill.patternSpacing ?? { x: 0, y: 0 }\n const scaledWidth = source.width * scale\n const scaledHeight = source.height * scale\n const gapX = scaledWidth * spacing.x\n const gapY = scaledHeight * spacing.y\n const width = scaledWidth + gapX\n const height = scaledHeight + gapY\n const x = patternAlignmentOffset(fill.horizontalAlignment, gapX, scaledWidth, 'x')\n const y = patternAlignmentOffset(fill.verticalAlignment, gapY, scaledHeight, 'y')\n const positions = [{ x, y }]\n\n if (fill.patternTileType === 'HORIZONTAL_HEXAGONAL') {\n positions.push({ x: x + width / 2, y: y + height / 2 })\n } else if (fill.patternTileType === 'VERTICAL_HEXAGONAL') {\n positions.push({ x: x + width / 2, y: y - height / 2 })\n }\n\n return { rect: { x: 0, y: 0, width, height }, scale, positions }\n}\n"],"mappings":";AAUA,SAAS,uBACP,WACA,KACA,YACA,MACQ;CACR,IAAI,cAAc,UAAU,OAAO,SAAS,MAAM,CAAC,MAAM,IAAI,CAAC,aAAa;CAC3E,IAAI,cAAc,OAAO,OAAO,CAAC;CACjC,OAAO;AACT;AAEA,SAAgB,kBACd,QACA,MACmB;CACnB,MAAM,QAAQ,KAAK,SAAS,KAAK,QAAQ,IAAI,KAAK,QAAQ;CAC1D,MAAM,UAAU,KAAK,kBAAkB;EAAE,GAAG;EAAG,GAAG;CAAE;CACpD,MAAM,cAAc,OAAO,QAAQ;CACnC,MAAM,eAAe,OAAO,SAAS;CACrC,MAAM,OAAO,cAAc,QAAQ;CACnC,MAAM,OAAO,eAAe,QAAQ;CACpC,MAAM,QAAQ,cAAc;CAC5B,MAAM,SAAS,eAAe;CAC9B,MAAM,IAAI,uBAAuB,KAAK,qBAAqB,MAAM,aAAa,GAAG;CACjF,MAAM,IAAI,uBAAuB,KAAK,mBAAmB,MAAM,cAAc,GAAG;CAChF,MAAM,YAAY,CAAC;EAAE;EAAG;CAAE,CAAC;CAE3B,IAAI,KAAK,oBAAoB,wBAC3B,UAAU,KAAK;EAAE,GAAG,IAAI,QAAQ;EAAG,GAAG,IAAI,SAAS;CAAE,CAAC;MACjD,IAAI,KAAK,oBAAoB,sBAClC,UAAU,KAAK;EAAE,GAAG,IAAI,QAAQ;EAAG,GAAG,IAAI,SAAS;CAAE,CAAC;CAGxD,OAAO;EAAE,MAAM;GAAE,GAAG;GAAG,GAAG;GAAG;GAAO;EAAO;EAAG;EAAO;CAAU;AACjE"}
1
+ {"version":3,"file":"pattern.js","names":[],"sources":["../../src/paints/pattern.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { Rect, Vector } from '../primitives'\nimport type { Fill, SceneNode } from '../types'\n\n/** Where a pattern's source repeats in one tile: the tile, the source's scale, and its copies. */\nexport interface PatternTileLayout {\n rect: Rect\n scale: number\n positions: Vector[]\n}\n\nfunction patternAlignmentOffset(\n alignment: Fill['horizontalAlignment'],\n gap: number,\n sourceSize: number,\n axis: 'x' | 'y'\n): number {\n if (alignment === 'CENTER') return axis === 'x' ? -gap / 2 : -sourceSize / 2\n if (alignment === 'END') return -gap\n return 0\n}\n\nexport function patternTileLayout(\n source: Pick<SceneNode, 'width' | 'height'>,\n fill: Fill\n): PatternTileLayout {\n const scale = fill.scale && fill.scale > 0 ? fill.scale : 1\n const spacing = fill.patternSpacing ?? { x: 0, y: 0 }\n const scaledWidth = source.width * scale\n const scaledHeight = source.height * scale\n const gapX = scaledWidth * spacing.x\n const gapY = scaledHeight * spacing.y\n const width = scaledWidth + gapX\n const height = scaledHeight + gapY\n const x = patternAlignmentOffset(fill.horizontalAlignment, gapX, scaledWidth, 'x')\n const y = patternAlignmentOffset(fill.verticalAlignment, gapY, scaledHeight, 'y')\n const positions = [{ x, y }]\n\n if (fill.patternTileType === 'HORIZONTAL_HEXAGONAL') {\n positions.push({ x: x + width / 2, y: y + height / 2 })\n } else if (fill.patternTileType === 'VERTICAL_HEXAGONAL') {\n positions.push({ x: x + width / 2, y: y - height / 2 })\n }\n\n return { rect: { x: 0, y: 0, width, height }, scale, positions }\n}\n\nfunction addPatternSourceIds(paints: readonly Fill[], ids: string[]) {\n for (const paint of paints) {\n if (paint.type === 'PATTERN' && paint.sourceNodeId) {\n ids.push(paint.sourceNodeId)\n }\n }\n}\n\nexport function patternSourceIds(node: SceneNode): string[] {\n const ids: string[] = []\n addPatternSourceIds(node.fills, ids)\n addPatternSourceIds(node.strokes, ids)\n addPatternSourceIds(node.textDecorationFills, ids)\n for (const region of node.vectorNetwork?.regions ?? []) {\n addPatternSourceIds(region.fills ?? [], ids)\n }\n for (const run of node.styleRuns) {\n addPatternSourceIds(run.style.fills ?? [], ids)\n addPatternSourceIds(run.style.textDecorationFills ?? [], ids)\n }\n return ids\n}\n\nfunction indexBySourceId(graph: SceneGraph): Map<string, SceneNode> {\n const index = new Map<string, SceneNode>()\n for (const node of graph.getAllNodes()) {\n if (node.source.id && !index.has(node.source.id)) {\n index.set(node.source.id, node)\n }\n }\n return index\n}\n\nexport function createPatternSourceLookup(\n graph: SceneGraph\n): (sourceId: string) => SceneNode | null {\n let bySourceId: Map<string, SceneNode> | null = null\n return (sourceId) => {\n const direct = graph.getNode(sourceId)\n if (direct) {\n return direct\n }\n bySourceId ??= indexBySourceId(graph)\n return bySourceId.get(sourceId) ?? null\n }\n}\n\nexport function resolvedPatternSourceIds(\n node: SceneNode,\n findSource: (sourceId: string) => SceneNode | null\n): string[] {\n return patternSourceIds(node).flatMap((sourceId) => findSource(sourceId)?.id ?? [])\n}\n"],"mappings":";AAWA,SAAS,uBACP,WACA,KACA,YACA,MACQ;CACR,IAAI,cAAc,UAAU,OAAO,SAAS,MAAM,CAAC,MAAM,IAAI,CAAC,aAAa;CAC3E,IAAI,cAAc,OAAO,OAAO,CAAC;CACjC,OAAO;AACT;AAEA,SAAgB,kBACd,QACA,MACmB;CACnB,MAAM,QAAQ,KAAK,SAAS,KAAK,QAAQ,IAAI,KAAK,QAAQ;CAC1D,MAAM,UAAU,KAAK,kBAAkB;EAAE,GAAG;EAAG,GAAG;CAAE;CACpD,MAAM,cAAc,OAAO,QAAQ;CACnC,MAAM,eAAe,OAAO,SAAS;CACrC,MAAM,OAAO,cAAc,QAAQ;CACnC,MAAM,OAAO,eAAe,QAAQ;CACpC,MAAM,QAAQ,cAAc;CAC5B,MAAM,SAAS,eAAe;CAC9B,MAAM,IAAI,uBAAuB,KAAK,qBAAqB,MAAM,aAAa,GAAG;CACjF,MAAM,IAAI,uBAAuB,KAAK,mBAAmB,MAAM,cAAc,GAAG;CAChF,MAAM,YAAY,CAAC;EAAE;EAAG;CAAE,CAAC;CAE3B,IAAI,KAAK,oBAAoB,wBAC3B,UAAU,KAAK;EAAE,GAAG,IAAI,Q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,YACU;CACV,OAAO,iBAAiB,IAAI,CAAC,CAAC,SAAS,aAAa,WAAW,QAAQ,CAAC,EAAE,MAAM,CAAC,CAAC;AACpF"}
@@ -6,6 +6,9 @@ import { Fill } from "../types.js";
6
6
  * render bounds, and does not click through it to its layer (Figma desktop, live).
7
7
  */
8
8
  declare function paintShows(paint: Fill): boolean;
9
+ /** A Figma shader paint, which OpenPencil cannot draw: Figma keeps the program outside the file. */
10
+ declare function isFigmaShaderPaint(paint: Fill): boolean;
11
+ declare function isDrawnPaint(paint: Fill): boolean;
9
12
  //#endregion
10
- export { paintShows };
13
+ export { isDrawnPaint, isFigmaShaderPaint, paintShows };
11
14
  //# sourceMappingURL=shows.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"shows.d.ts","names":[],"sources":["../../src/paints/shows.ts"],"mappings":";;;;;;;iBAOgB,WAAW,OAAO"}
1
+ {"version":3,"file":"shows.d.ts","names":[],"sources":["../../src/paints/shows.ts"],"mappings":";;;;;;;iBAOgB,WAAW,OAAO;;iBAQlB,mBAAmB,OAAO;iBAI1B,aAAa,OAAO"}
@@ -10,7 +10,14 @@ function paintShows(paint) {
10
10
  if (paint.type === "SOLID") return paint.color.a > 0;
11
11
  return true;
12
12
  }
13
+ /** A Figma shader paint, which OpenPencil cannot draw: Figma keeps the program outside the file. */
14
+ function isFigmaShaderPaint(paint) {
15
+ return paint.type === "CUSTOM";
16
+ }
17
+ function isDrawnPaint(paint) {
18
+ return paint.visible && !isFigmaShaderPaint(paint);
19
+ }
13
20
  //#endregion
14
- export { paintShows };
21
+ export { isDrawnPaint, isFigmaShaderPaint, paintShows };
15
22
 
16
23
  //# sourceMappingURL=shows.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"shows.js","names":[],"sources":["../../src/paints/shows.ts"],"sourcesContent":["import type { Fill } from '../types'\n\n/**\n * Whether a paint shows anything: visible, above 0% opacity, and not wholly transparent in its own\n * color or every gradient stop. Figma casts no shadow from a paint that does not, counts it in no\n * render bounds, and does not click through it to its layer (Figma desktop, live).\n */\nexport function paintShows(paint: Fill): boolean {\n if (!paint.visible || !(paint.opacity > 0)) return false\n if (paint.gradientStops) return paint.gradientStops.some((stop) => stop.color.a > 0)\n if (paint.type === 'SOLID') return paint.color.a > 0\n return true\n}\n"],"mappings":";;;;;;AAOA,SAAgB,WAAW,OAAsB;CAC/C,IAAI,CAAC,MAAM,WAAW,EAAE,MAAM,UAAU,IAAI,OAAO;CACnD,IAAI,MAAM,eAAe,OAAO,MAAM,cAAc,MAAM,SAAS,KAAK,MAAM,IAAI,CAAC;CACnF,IAAI,MAAM,SAAS,SAAS,OAAO,MAAM,MAAM,IAAI;CACnD,OAAO;AACT"}
1
+ {"version":3,"file":"shows.js","names":[],"sources":["../../src/paints/shows.ts"],"sourcesContent":["import type { Fill } from '../types'\n\n/**\n * Whether a paint shows anything: visible, above 0% opacity, and not wholly transparent in its own\n * color or every gradient stop. Figma casts no shadow from a paint that does not, counts it in no\n * render bounds, and does not click through it to its layer (Figma desktop, live).\n */\nexport function paintShows(paint: Fill): boolean {\n if (!paint.visible || !(paint.opacity > 0)) return false\n if (paint.gradientStops) return paint.gradientStops.some((stop) => stop.color.a > 0)\n if (paint.type === 'SOLID') return paint.color.a > 0\n return true\n}\n\n/** A Figma shader paint, which OpenPencil cannot draw: Figma keeps the program outside the file. */\nexport function isFigmaShaderPaint(paint: Fill): boolean {\n return paint.type === 'CUSTOM'\n}\n\nexport function isDrawnPaint(paint: Fill): boolean {\n return paint.visible && !isFigmaShaderPaint(paint)\n}\n"],"mappings":";;;;;;AAOA,SAAgB,WAAW,OAAsB;CAC/C,IAAI,CAAC,MAAM,WAAW,EAAE,MAAM,UAAU,IAAI,OAAO;CACnD,IAAI,MAAM,eAAe,OAAO,MAAM,cAAc,MAAM,SAAS,KAAK,MAAM,IAAI,CAAC;CACnF,IAAI,MAAM,SAAS,SAAS,OAAO,MAAM,MAAM,IAAI;CACnD,OAAO;AACT;;AAGA,SAAgB,mBAAmB,OAAsB;CACvD,OAAO,MAAM,SAAS;AACxB;AAEA,SAAgB,aAAa,OAAsB;CACjD,OAAO,MAAM,WAAW,CAAC,mBAAmB,KAAK;AACnD"}
@@ -0,0 +1,11 @@
1
+ import { Color } from "../primitives/index.js";
2
+ import { Fill } from "../types.js";
3
+ //#region src/paints/solid.d.ts
4
+ /**
5
+ * A color as a solid paint holds it: its channels at full alpha, and its alpha as the paint's
6
+ * opacity, which shapes draw at alone and text draws at times its color's alpha.
7
+ */
8
+ declare function solidPaintColor(color: Color): Pick<Fill, 'color' | 'opacity'>;
9
+ //#endregion
10
+ export { solidPaintColor };
11
+ //# sourceMappingURL=solid.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solid.d.ts","names":[],"sources":["../../src/paints/solid.ts"],"mappings":";;;;;;;iBAOgB,gBAAgB,OAAO,QAAQ,KAAK"}
@@ -0,0 +1,18 @@
1
+ //#region src/paints/solid.ts
2
+ /**
3
+ * A color as a solid paint holds it: its channels at full alpha, and its alpha as the paint's
4
+ * opacity, which shapes draw at alone and text draws at times its color's alpha.
5
+ */
6
+ function solidPaintColor(color) {
7
+ return {
8
+ color: {
9
+ ...color,
10
+ a: 1
11
+ },
12
+ opacity: color.a
13
+ };
14
+ }
15
+ //#endregion
16
+ export { solidPaintColor };
17
+
18
+ //# sourceMappingURL=solid.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"solid.js","names":[],"sources":["../../src/paints/solid.ts"],"sourcesContent":["import type { Color } from '../primitives'\nimport type { Fill } from '../types'\n\n/**\n * A color as a solid paint holds it: its channels at full alpha, and its alpha as the paint's\n * opacity, which shapes draw at alone and text draws at times its color's alpha.\n */\nexport function solidPaintColor(color: Color): Pick<Fill, 'color' | 'opacity'> {\n return { color: { ...color, a: 1 }, opacity: color.a }\n}\n"],"mappings":";;;;;AAOA,SAAgB,gBAAgB,OAA+C;CAC7E,OAAO;EAAE,OAAO;GAAE,GAAG;GAAO,GAAG;EAAE;EAAG,SAAS,MAAM;CAAE;AACvD"}
@@ -0,0 +1,74 @@
1
+ import { Size } from "../primitives/index.js";
2
+ import { Fill, SceneNode } from "../types.js";
3
+ import { PluginDataField } from "../plugin-data/field.js";
4
+ //#region src/paints/stills.d.ts
5
+ /**
6
+ * Paints OpenPencil draws itself, such as shaders and mesh gradients, kept as an image fill of
7
+ * their still frame, so `.fig` files, the Figma clipboard, and every format that reads images
8
+ * show them. What draws the frame is plugin data on the layer, one entry per paint, matched to
9
+ * the paint by the frame's image hash. A paint whose image is replaced, as in Figma, then draws
10
+ * as the image it holds.
11
+ *
12
+ * Frames are drawn and stored the same way for every renderer that draws one: the editor's
13
+ * canvas and the tools that prebuild documents. Figma must be able to read them, which rules out
14
+ * WebP.
15
+ */
16
+ interface StillPaint {
17
+ /** The hash of the paint's image: the still frame. */
18
+ image: string;
19
+ }
20
+ /** Every entry a node keeps under `field`, whether or not a paint still shows it. */
21
+ declare function readStillPaints<T extends StillPaint>(node: Pick<SceneNode, 'pluginData'>, field: PluginDataField<T>): T[];
22
+ /**
23
+ * The entry under `field` that `paint` of `node` shows: an image paint whose image is that
24
+ * entry's frame. Null for any other paint, including one whose image was replaced.
25
+ */
26
+ declare function stillPaintOf<T extends StillPaint>(node: Pick<SceneNode, 'pluginData'>, paint: Fill, field: PluginDataField<T>): T | null;
27
+ /**
28
+ * The node's plugin data with `field`'s entries set by their image, keeping only entries a fill
29
+ * or stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.
30
+ */
31
+ declare function withStillPaints<T extends StillPaint>(node: Pick<SceneNode, 'pluginData'>, paints: readonly Fill[], field: PluginDataField<T>, entries?: readonly T[]): SceneNode['pluginData'];
32
+ /**
33
+ * A new image paint for a still frame not yet drawn. Its image is unique to this paint, so no
34
+ * other paint's entry claims it until the frame is drawn.
35
+ */
36
+ declare function createStillPaint(): {
37
+ paint: Fill;
38
+ image: string;
39
+ };
40
+ /** A short key that tells one drawn value from another, which a drawn frame records. */
41
+ declare function stillContentKey(value: unknown): string;
42
+ /** The layer size and content key a frame was drawn for. */
43
+ interface StillFrame {
44
+ width: number;
45
+ height: number;
46
+ key: string;
47
+ }
48
+ /**
49
+ * Whether a frame was drawn for the content `key` names at the layer's size now, so undoing a
50
+ * change after reopening the document does not keep a frame of the newer content.
51
+ */
52
+ declare function isStillFrameCurrent(frame: StillFrame | undefined, key: string, size: Size): boolean;
53
+ /**
54
+ * The stored value of OpenPencil plugin-data entry `key` with the still frame it names renamed by
55
+ * `rename`, so the paint is found under its image's new name; null when the entry names no still
56
+ * frame or its name stays.
57
+ */
58
+ declare function renameStillPaintImage(key: string, value: string, rename: (image: string) => string | null): string | null;
59
+ /** The pixels a frame for a layer of `size` is drawn at. */
60
+ declare function stillFramePixels(size: Size): Size;
61
+ interface StillFrameEncoding {
62
+ type: 'image/jpeg' | 'image/png';
63
+ /** For `canvas.toBlob` and `toDataURL`; PNG takes none. */
64
+ quality?: number;
65
+ }
66
+ /**
67
+ * The encoding a frame with these RGBA pixels is stored in: JPEG when every pixel is opaque, which
68
+ * is about 25 times smaller than PNG for a shader, and PNG when any pixel lets the layer behind
69
+ * show through, which JPEG cannot keep.
70
+ */
71
+ declare function stillFrameEncoding(rgba: ArrayLike<number>): StillFrameEncoding;
72
+ //#endregion
73
+ export { StillFrame, StillFrameEncoding, StillPaint, createStillPaint, isStillFrameCurrent, readStillPaints, renameStillPaintImage, stillContentKey, stillFrameEncoding, stillFramePixels, stillPaintOf, withStillPaints };
74
+ //# sourceMappingURL=stills.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stills.d.ts","names":[],"sources":["../../src/paints/stills.ts"],"mappings":";;;;;;;;;;;;;;;UAuBiB;;EAEf;;;iBAIc,gBAAgB,UAAU,YACxC,MAAM,KAAK,0BACX,OAAO,gBAAgB,KACtB;;;;;iBAQa,aAAa,UAAU,YACrC,MAAM,KAAK,0BACX,OAAO,MACP,OAAO,gBAAgB,KACtB;;;;;iBASa,gBAAgB,UAAU,YACxC,MAAM,KAAK,0BACX,iBAAiB,QACjB,OAAO,gBAAgB,IACvB,mBAAkB,MACjB;;;;;iBAea;EAAsB,OAAO;EAAM;;;iBAgBnC,gBAAgB;;UAKf;EACf;EACA;EACA;;;;;;iBAOc,oBACd,OAAO,wBACP,aACA,MAAM;;;;;;iBAkCQ,sBACd,aACA,eACA,SAAS;;iBAaK,iBAAiB,MAAM,OAAO;UAQ7B;EACf;;EAEA;;;;;;;iBAQc,mBAAmB,MAAM,oBAAoB"}
@@ -0,0 +1,113 @@
1
+ import { TRANSPARENT } from "../constants.js";
2
+ import { readAllPluginData, withAllPluginData } from "../plugin-data/field.js";
3
+ import { OPEN_PENCIL_PLUGIN_DATA } from "../plugin-data/fields.js";
4
+ import { imagePaintHashes } from "../images.js";
5
+ import { randomHex } from "@open-pencil/std/random";
6
+ import { sha1 } from "@noble/hashes/legacy.js";
7
+ import { bytesToHex, utf8ToBytes } from "@noble/hashes/utils.js";
8
+ //#region src/paints/stills.ts
9
+ /** Every entry a node keeps under `field`, whether or not a paint still shows it. */
10
+ function readStillPaints(node, field) {
11
+ return readAllPluginData(node.pluginData, field);
12
+ }
13
+ /**
14
+ * The entry under `field` that `paint` of `node` shows: an image paint whose image is that
15
+ * entry's frame. Null for any other paint, including one whose image was replaced.
16
+ */
17
+ function stillPaintOf(node, paint, field) {
18
+ if (paint.type !== "IMAGE" || !paint.imageHash) return null;
19
+ return readStillPaints(node, field).find((entry) => entry.image === paint.imageHash) ?? null;
20
+ }
21
+ /**
22
+ * The node's plugin data with `field`'s entries set by their image, keeping only entries a fill
23
+ * or stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.
24
+ */
25
+ function withStillPaints(node, paints, field, entries = []) {
26
+ const shown = new Set(imagePaintHashes(paints));
27
+ const byImage = new Map(readStillPaints(node, field).map((entry) => [entry.image, entry]));
28
+ for (const entry of entries) byImage.set(entry.image, entry);
29
+ return withAllPluginData(node.pluginData, field, [...byImage.values()].filter((entry) => shown.has(entry.image)));
30
+ }
31
+ /**
32
+ * A new image paint for a still frame not yet drawn. Its image is unique to this paint, so no
33
+ * other paint's entry claims it until the frame is drawn.
34
+ */
35
+ function createStillPaint() {
36
+ const image = randomHex(20);
37
+ return {
38
+ paint: {
39
+ type: "IMAGE",
40
+ color: TRANSPARENT,
41
+ opacity: 1,
42
+ visible: true,
43
+ imageHash: image,
44
+ imageScaleMode: "FILL"
45
+ },
46
+ image
47
+ };
48
+ }
49
+ /** A short key that tells one drawn value from another, which a drawn frame records. */
50
+ function stillContentKey(value) {
51
+ return bytesToHex(sha1(utf8ToBytes(JSON.stringify(value))));
52
+ }
53
+ /**
54
+ * Whether a frame was drawn for the content `key` names at the layer's size now, so undoing a
55
+ * change after reopening the document does not keep a frame of the newer content.
56
+ */
57
+ function isStillFrameCurrent(frame, key, size) {
58
+ return frame?.key === key && Math.round(frame.width) === Math.round(size.width) && Math.round(frame.height) === Math.round(size.height);
59
+ }
60
+ /** Renames the image a stored entry of `field` names, or says it names none. */
61
+ function stillPaintRenamer(field) {
62
+ return {
63
+ key: field.key,
64
+ rename(value, rename) {
65
+ const paint = field.decode(value);
66
+ const renamed = paint ? rename(paint.image) : null;
67
+ return paint && renamed && renamed !== paint.image ? field.encode({
68
+ ...paint,
69
+ image: renamed
70
+ }) : null;
71
+ }
72
+ };
73
+ }
74
+ /** The plugin-data fields whose entries name a paint's still frame: shaders and meshes. */
75
+ const STILL_PAINT_RENAMERS = [stillPaintRenamer(OPEN_PENCIL_PLUGIN_DATA.shader), stillPaintRenamer(OPEN_PENCIL_PLUGIN_DATA.mesh)];
76
+ /**
77
+ * The stored value of OpenPencil plugin-data entry `key` with the still frame it names renamed by
78
+ * `rename`, so the paint is found under its image's new name; null when the entry names no still
79
+ * frame or its name stays.
80
+ */
81
+ function renameStillPaintImage(key, value, rename) {
82
+ return STILL_PAINT_RENAMERS.find((renamer) => renamer.key === key)?.rename(value, rename) ?? null;
83
+ }
84
+ /** Frames are drawn at twice the layer's size, for sharp high-density displays. */
85
+ const FRAME_SCALE = 2;
86
+ /** The longest side a frame is drawn at, however large the layer. */
87
+ const MAX_FRAME_EDGE = 2048;
88
+ /** JPEG quality for opaque frames: no visible difference from PNG at a fraction of the size. */
89
+ const JPEG_QUALITY = .9;
90
+ /** The pixels a frame for a layer of `size` is drawn at. */
91
+ function stillFramePixels(size) {
92
+ const scale = Math.min(FRAME_SCALE, MAX_FRAME_EDGE / Math.max(size.width, size.height, 1));
93
+ return {
94
+ width: Math.max(1, Math.round(size.width * scale)),
95
+ height: Math.max(1, Math.round(size.height * scale))
96
+ };
97
+ }
98
+ /**
99
+ * The encoding a frame with these RGBA pixels is stored in: JPEG when every pixel is opaque, which
100
+ * is about 25 times smaller than PNG for a shader, and PNG when any pixel lets the layer behind
101
+ * show through, which JPEG cannot keep.
102
+ */
103
+ function stillFrameEncoding(rgba) {
104
+ for (let alpha = 3; alpha < rgba.length; alpha += 4) if (rgba[alpha] !== 255) return { type: "image/png" };
105
+ return {
106
+ type: "image/jpeg",
107
+ quality: JPEG_QUALITY
108
+ };
109
+ }
110
+ //#endregion
111
+ export { createStillPaint, isStillFrameCurrent, readStillPaints, renameStillPaintImage, stillContentKey, stillFrameEncoding, stillFramePixels, stillPaintOf, withStillPaints };
112
+
113
+ //# sourceMappingURL=stills.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stills.js","names":[],"sources":["../../src/paints/stills.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'\n\nimport { randomHex } from '@open-pencil/std/random'\n\nimport { TRANSPARENT } from '../constants'\nimport { imagePaintHashes } from '../images'\nimport { readAllPluginData, withAllPluginData, type PluginDataField } from '../plugin-data/field'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { Size } from '../primitives'\nimport type { Fill, SceneNode } from '../types'\n\n/**\n * Paints OpenPencil draws itself, such as shaders and mesh gradients, kept as an image fill of\n * their still frame, so `.fig` files, the Figma clipboard, and every format that reads images\n * show them. What draws the frame is plugin data on the layer, one entry per paint, matched to\n * the paint by the frame's image hash. A paint whose image is replaced, as in Figma, then draws\n * as the image it holds.\n *\n * Frames are drawn and stored the same way for every renderer that draws one: the editor's\n * canvas and the tools that prebuild documents. Figma must be able to read them, which rules out\n * WebP.\n */\nexport interface StillPaint {\n /** The hash of the paint's image: the still frame. */\n image: string\n}\n\n/** Every entry a node keeps under `field`, whether or not a paint still shows it. */\nexport function readStillPaints<T extends StillPaint>(\n node: Pick<SceneNode, 'pluginData'>,\n field: PluginDataField<T>\n): T[] {\n return readAllPluginData(node.pluginData, field)\n}\n\n/**\n * The entry under `field` that `paint` of `node` shows: an image paint whose image is that\n * entry's frame. Null for any other paint, including one whose image was replaced.\n */\nexport function stillPaintOf<T extends StillPaint>(\n node: Pick<SceneNode, 'pluginData'>,\n paint: Fill,\n field: PluginDataField<T>\n): T | null {\n if (paint.type !== 'IMAGE' || !paint.imageHash) return null\n return readStillPaints(node, field).find((entry) => entry.image === paint.imageHash) ?? null\n}\n\n/**\n * The node's plugin data with `field`'s entries set by their image, keeping only entries a fill\n * or stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.\n */\nexport function withStillPaints<T extends StillPaint>(\n node: Pick<SceneNode, 'pluginData'>,\n paints: readonly Fill[],\n field: PluginDataField<T>,\n entries: readonly T[] = []\n): SceneNode['pluginData'] {\n const shown = new Set(imagePaintHashes(paints))\n const byImage = new Map(readStillPaints(node, field).map((entry) => [entry.image, entry]))\n for (const entry of entries) byImage.set(entry.image, entry)\n return withAllPluginData(\n node.pluginData,\n field,\n [...byImage.values()].filter((entry) => shown.has(entry.image))\n )\n}\n\n/**\n * A new image paint for a still frame not yet drawn. Its image is unique to this paint, so no\n * other paint's entry claims it until the frame is drawn.\n */\nexport function createStillPaint(): { paint: Fill; image: string } {\n const image = randomHex(20)\n return {\n paint: {\n type: 'IMAGE',\n color: TRANSPARENT,\n opacity: 1,\n visible: true,\n imageHash: image,\n imageScaleMode: 'FILL'\n },\n image\n }\n}\n\n/** A short key that tells one drawn value from another, which a drawn frame records. */\nexport function stillContentKey(value: unknown): string {\n return bytesToHex(sha1(utf8ToBytes(JSON.stringify(value))))\n}\n\n/** The layer size and content key a frame was drawn for. */\nexport interface StillFrame {\n width: number\n height: number\n key: string\n}\n\n/**\n * Whether a frame was drawn for the content `key` names at the layer's size now, so undoing a\n * change after reopening the document does not keep a frame of the newer content.\n */\nexport function isStillFrameCurrent(\n frame: StillFrame | undefined,\n key: string,\n size: Size\n): boolean {\n return (\n frame?.key === key &&\n Math.round(frame.width) === Math.round(size.width) &&\n Math.round(frame.height) === Math.round(size.height)\n )\n}\n\n/** Renames the image a stored entry of `field` names, or says it names none. */\nfunction stillPaintRenamer<T extends StillPaint>(field: PluginDataField<T>) {\n return {\n key: field.key,\n rename(value: string, rename: (image: string) => string | null): string | null {\n const paint = field.decode(value)\n const renamed = paint ? rename(paint.image) : null\n return paint && renamed && renamed !== paint.image\n ? field.encode({ ...paint, image: renamed })\n : null\n }\n }\n}\n\n/** The plugin-data fields whose entries name a paint's still frame: shaders and meshes. */\nconst STILL_PAINT_RENAMERS = [\n stillPaintRenamer(OPEN_PENCIL_PLUGIN_DATA.shader),\n stillPaintRenamer(OPEN_PENCIL_PLUGIN_DATA.mesh)\n]\n\n/**\n * The stored value of OpenPencil plugin-data entry `key` with the still frame it names renamed by\n * `rename`, so the paint is found under its image's new name; null when the entry names no still\n * frame or its name stays.\n */\nexport function renameStillPaintImage(\n key: string,\n value: string,\n rename: (image: string) => string | null\n): string | null {\n return STILL_PAINT_RENAMERS.find((renamer) => renamer.key === key)?.rename(value, rename) ?? null\n}\n\n/** Frames are drawn at twice the layer's size, for sharp high-density displays. */\nconst FRAME_SCALE = 2\n/** The longest side a frame is drawn at, however large the layer. */\nconst MAX_FRAME_EDGE = 2048\n/** JPEG quality for opaque frames: no visible difference from PNG at a fraction of the size. */\nconst JPEG_QUALITY = 0.9\n\n/** The pixels a frame for a layer of `size` is drawn at. */\nexport function stillFramePixels(size: Size): Size {\n const scale = Math.min(FRAME_SCALE, MAX_FRAME_EDGE / Math.max(size.width, size.height, 1))\n return {\n width: Math.max(1, Math.round(size.width * scale)),\n height: Math.max(1, Math.round(size.height * scale))\n }\n}\n\nexport interface StillFrameEncoding {\n type: 'image/jpeg' | 'image/png'\n /** For `canvas.toBlob` and `toDataURL`; PNG takes none. */\n quality?: number\n}\n\n/**\n * The encoding a frame with these RGBA pixels is stored in: JPEG when every pixel is opaque, which\n * is about 25 times smaller than PNG for a shader, and PNG when any pixel lets the layer behind\n * show through, which JPEG cannot keep.\n */\nexport function stillFrameEncoding(rgba: ArrayLike<number>): StillFrameEncoding {\n for (let alpha = 3; alpha < rgba.length; alpha += 4) {\n if (rgba[alpha] !== 255) return { type: 'image/png' }\n }\n return { type: 'image/jpeg', quality: JPEG_QUALITY }\n}\n"],"mappings":";;;;;;;;;AA6BA,SAAgB,gBACd,MACA,OACK;CACL,OAAO,kBAAkB,KAAK,YAAY,KAAK;AACjD;;;;;AAMA,SAAgB,aACd,MACA,OACA,OACU;CACV,IAAI,MAAM,SAAS,WAAW,CAAC,MAAM,WAAW,OAAO;CACvD,OAAO,gBAAgB,MAAM,KAAK,CAAC,CAAC,MAAM,UAAU,MAAM,UAAU,MAAM,SAAS,KAAK;AAC1F;;;;;AAMA,SAAgB,gBACd,MACA,QACA,OACA,UAAwB,CAAC,GACA;CACzB,MAAM,QAAQ,IAAI,IAAI,iBAAiB,MAAM,CAAC;CAC9C,MAAM,UAAU,IAAI,IAAI,gBAAgB,MAAM,KAAK,CAAC,CAAC,KAAK,UAAU,CAAC,MAAM,OAAO,KAAK,CAAC,CAAC;CACzF,KAAK,MAAM,SAAS,SAAS,QAAQ,IAAI,MAAM,OAAO,KAAK;CAC3D,OAAO,kBACL,KAAK,YACL,OACA,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAC,CAAC,QAAQ,UAAU,MAAM,IAAI,MAAM,KAAK,CAAC,CAChE;AACF;;;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ACjD,QAAQ,KAAK,IAAI,GAAG,KAAK,MAAM,KAAK,SAAS,KAAK,CAAC;CACrD;AACF;;;;;;AAaA,SAAgB,mBAAmB,MAA6C;CAC9E,KAAK,IAAI,QAAQ,GAAG,QAAQ,KAAK,QAAQ,SAAS,GAChD,IAAI,KAAK,WAAW,KAAK,OAAO,EAAE,MAAM,YAAY;CAEtD,OAAO;EAAE,MAAM;EAAc,SAAS;CAAa;AACrD"}
@@ -1 +1 @@
1
- {"version":3,"file":"field.d.ts","names":[],"sources":["../../src/plugin-data/field.ts"],"mappings":";;;;cAKa;;;;;;;;;KAUD;;UAGK;WACN;WACA,MAAM;;;UAIA,gBAAgB,WAAW;;EAE1C,OAAO,mCAAmC;EAC1C,OAAO,OAAO;;;;;;iBAOA,oBAAoB,GAClC,aACA,MAAM,gBACN,QAAQ,EAAE,uBAAuB,KAChC,gBAAgB;;iBAcH,0BAA0B,kBACxC,aACA,MAAM,gBACN,iBAAiB,MAChB,gBAAgB;iBAaH,kBAAkB,OAAO,iBAAiB,OAAO;iBAIjD,cACd,kBAAkB,+BAClB,OAAO;iBAKO,eAAe,GAC7B,kBAAkB,+BAClB,OAAO,gBAAgB,KACtB;;iBAKa,kBAAkB,GAChC,kBAAkB,+BAClB,OAAO,gBAAgB,KACtB;iBAQa,gBAAgB,GAAG,OAAO,gBAAgB,IAAI,OAAO,IAAI;;iBAKzD,kBACd,kBAAkB,mBAClB,iBAAiB,kBAChB;;iBAKa,eAAe,GAC7B,kBAAkB,mBAClB,OAAO,gBAAgB,IACvB,OAAO,gBACN;;iBAKa,kBAAkB,GAChC,kBAAkB,mBAClB,OAAO,gBAAgB,IACvB,iBAAiB,MAChB"}
1
+ {"version":3,"file":"field.d.ts","names":[],"sources":["../../src/plugin-data/field.ts"],"mappings":";;;;cAKa;;;;;;;;;KAUD;;UAGK;WACN;WACA,MAAM;;;UAIA,gBAAgB,WAAW;;EAE1C,OAAO,mCAAmC;EAC1C,OAAO,OAAO;;;;;;iBAOA,oBAAoB,GAClC,aACA,MAAM,gBACN,QAAQ,EAAE,uBAAuB,KAChC,gBAAgB;;iBAgBH,0BAA0B,kBACxC,aACA,MAAM,gBACN,iBAAiB,MAChB,gBAAgB;iBAcH,kBAAkB,OAAO,iBAAiB,OAAO;iBAIjD,cACd,kBAAkB,+BAClB,OAAO;iBAKO,eAAe,GAC7B,kBAAkB,+BAClB,OAAO,gBAAgB,KACtB;;iBAKa,kBAAkB,GAChC,kBAAkB,+BAClB,OAAO,gBAAgB,KACtB;iBAQa,gBAAgB,GAAG,OAAO,gBAAgB,IAAI,OAAO,IAAI;;iBAKzD,kBACd,kBAAkB,mBAClB,iBAAiB,kBAChB;;iBAKa,eAAe,GAC7B,kBAAkB,mBAClB,OAAO,gBAAgB,IACvB,OAAO,gBACN;;iBAKa,kBAAkB,GAChC,kBAAkB,mBAClB,OAAO,gBAAgB,IACvB,iBAAiB,MAChB"}
@@ -12,6 +12,7 @@ function jsonPluginDataField(key, role, schema) {
12
12
  key,
13
13
  role,
14
14
  decode(value) {
15
+ if (value == null) return void 0;
15
16
  const parsed = v.safeParse(stored, value);
16
17
  return parsed.success ? parsed.output : void 0;
17
18
  },
@@ -25,6 +26,7 @@ function textPluginDataField(key, role, values) {
25
26
  key,
26
27
  role,
27
28
  decode(value) {
29
+ if (value == null) return void 0;
28
30
  const parsed = v.safeParse(schema, value);
29
31
  return parsed.success ? parsed.output : void 0;
30
32
  },
@@ -1 +1 @@
1
- {"version":3,"file":"field.js","names":[],"sources":["../../src/plugin-data/field.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { PluginDataEntry } from '../types'\n\n/** The plugin id OpenPencil keeps its own state under, on nodes and in `.fig` files. */\nexport const OPEN_PENCIL_PLUGIN_ID = 'open-pencil'\n\n/**\n * What a field holds:\n * - `content` belongs to the node like its fills do and exists only as plugin data, so it\n * travels with a component copied into a library or another document;\n * - `format` repeats a node or variable field for files that have no slot for it, where the\n * node field is what counts;\n * - `bookkeeping` records where a node or document came from and stays behind.\n */\nexport type PluginDataRole = 'content' | 'format' | 'bookkeeping'\n\n/** One OpenPencil plugin-data key. */\nexport interface PluginDataKey {\n readonly key: string\n readonly role: PluginDataRole\n}\n\n/** A plugin-data key and how its string value is read and written. */\nexport interface PluginDataField<T> extends PluginDataKey {\n /** The stored value, or `undefined` when it is missing or not a valid value. */\n decode(value: string | null | undefined): T | undefined\n encode(value: T): string\n}\n\n/**\n * A value stored as JSON. Invalid JSON and a wrong shape both read as missing: plugin data\n * comes from files anyone can edit, so a bad entry is ignored rather than thrown on.\n */\nexport function jsonPluginDataField<T>(\n key: string,\n role: PluginDataRole,\n schema: v.GenericSchema<unknown, T>\n): PluginDataField<T> {\n const stored = v.pipe(v.string(), v.parseJson(), schema)\n return {\n key,\n role,\n decode(value) {\n const parsed = v.safeParse(stored, value)\n return parsed.success ? parsed.output : undefined\n },\n encode: (value) => JSON.stringify(value)\n }\n}\n\n/** A value stored as one of a fixed set of plain strings. */\nexport function textPluginDataField<const T extends string>(\n key: string,\n role: PluginDataRole,\n values: readonly T[]\n): PluginDataField<T> {\n const schema = v.picklist(values)\n return {\n key,\n role,\n decode(value) {\n const parsed = v.safeParse(schema, value)\n return parsed.success ? parsed.output : undefined\n },\n encode: (value) => value\n }\n}\n\nexport function isPluginDataEntry(entry: PluginDataEntry, field: PluginDataKey): boolean {\n return entry.pluginId === OPEN_PENCIL_PLUGIN_ID && entry.key === field.key\n}\n\nexport function hasPluginData(\n entries: readonly PluginDataEntry[] | undefined,\n field: PluginDataKey\n): boolean {\n return entries?.some((entry) => isPluginDataEntry(entry, field)) ?? false\n}\n\nexport function readPluginData<T>(\n entries: readonly PluginDataEntry[] | undefined,\n field: PluginDataField<T>\n): T | undefined {\n return field.decode(entries?.find((entry) => isPluginDataEntry(entry, field))?.value)\n}\n\n/** Every valid value of a field kept as several entries under one key. */\nexport function readAllPluginData<T>(\n entries: readonly PluginDataEntry[] | undefined,\n field: PluginDataField<T>\n): T[] {\n return (entries ?? []).flatMap((entry) => {\n if (!isPluginDataEntry(entry, field)) return []\n const value = field.decode(entry.value)\n return value === undefined ? [] : [value]\n })\n}\n\nexport function pluginDataEntry<T>(field: PluginDataField<T>, value: T): PluginDataEntry {\n return { pluginId: OPEN_PENCIL_PLUGIN_ID, key: field.key, value: field.encode(value) }\n}\n\n/** Entries other than those of `fields`; other plugins' entries are always kept. */\nexport function withoutPluginData(\n entries: readonly PluginDataEntry[],\n fields: readonly PluginDataKey[]\n): PluginDataEntry[] {\n return entries.filter((entry) => !fields.some((field) => isPluginDataEntry(entry, field)))\n}\n\n/** Entries with `field` set to `value`, appended last; `undefined` removes the field. */\nexport function withPluginData<T>(\n entries: readonly PluginDataEntry[],\n field: PluginDataField<T>,\n value: T | undefined\n): PluginDataEntry[] {\n return withAllPluginData(entries, field, value === undefined ? [] : [value])\n}\n\n/** Entries with every entry of `field` replaced by one per value. */\nexport function withAllPluginData<T>(\n entries: readonly PluginDataEntry[],\n field: PluginDataField<T>,\n values: readonly T[]\n): PluginDataEntry[] {\n return [\n ...withoutPluginData(entries, [field]),\n ...values.map((value) => pluginDataEntry(field, value))\n ]\n}\n"],"mappings":";;;AAKA,MAAa,wBAAwB;;;;;AA6BrC,SAAgB,oBACd,KACA,MACA,QACoB;CACpB,MAAM,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,UAAU,GAAG,MAAM;CACvD,OAAO;EACL;EACA;EACA,OAAO,OAAO;GACZ,MAAM,SAAS,EAAE,UAAU,QAAQ,KAAK;GACxC,OAAO,OAAO,UAAU,OAAO,SAAS,KAAA;EAC1C;EACA,SAAS,UAAU,KAAK,UAAU,KAAK;CACzC;AACF;;AAGA,SAAgB,oBACd,KACA,MACA,QACoB;CACpB,MAAM,SAAS,EAAE,SAAS,MAAM;CAChC,OAAO;EACL;EACA;EACA,OAAO,OAAO;GACZ,MAAM,SAAS,EAAE,UAAU,QAAQ,KAAK;GACxC,OAAO,OAAO,UAAU,OAAO,SAAS,KAAA;EAC1C;EACA,SAAS,UAAU;CACrB;AACF;AAEA,SAAgB,kBAAkB,OAAwB,OAA+B;CACvF,OAAO,MAAM,aAAA,iBAAsC,MAAM,QAAQ,MAAM;AACzE;AAEA,SAAgB,cACd,SACA,OACS;CACT,OAAO,SAAS,MAAM,UAAU,kBAAkB,OAAO,KAAK,CAAC,KAAK;AACtE;AAEA,SAAgB,eACd,SACA,OACe;CACf,OAAO,MAAM,OAAO,SAAS,MAAM,UAAU,kBAAkB,OAAO,KAAK,CAAC,CAAC,EAAE,KAAK;AACtF;;AAGA,SAAgB,kBACd,SACA,OACK;CACL,QAAQ,WAAW,CAAC,EAAA,CAAG,SAAS,UAAU;EACxC,IAAI,CAAC,kBAAkB,OAAO,KAAK,GAAG,OAAO,CAAC;EAC9C,MAAM,QAAQ,MAAM,OAAO,MAAM,KAAK;EACtC,OAAO,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,KAAK;CAC1C,CAAC;AACH;AAEA,SAAgB,gBAAmB,OAA2B,OAA2B;CACvF,OAAO;EAAE,UAAU;EAAuB,KAAK,MAAM;EAAK,OAAO,MAAM,OAAO,KAAK;CAAE;AACvF;;AAGA,SAAgB,kBACd,SACA,QACmB;CACnB,OAAO,QAAQ,QAAQ,UAAU,CAAC,OAAO,MAAM,UAAU,kBAAkB,OAAO,KAAK,CAAC,CAAC;AAC3F;;AAGA,SAAgB,eACd,SACA,OACA,OACmB;CACnB,OAAO,kBAAkB,SAAS,OAAO,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,KAAK,CAAC;AAC7E;;AAGA,SAAgB,kBACd,SACA,OACA,QACmB;CACnB,OAAO,CACL,GAAG,kBAAkB,SAAS,CAAC,KAAK,CAAC,GACrC,GAAG,OAAO,KAAK,UAAU,gBAAgB,OAAO,KAAK,CAAC,CACxD;AACF"}
1
+ {"version":3,"file":"field.js","names":[],"sources":["../../src/plugin-data/field.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { PluginDataEntry } from '../types'\n\n/** The plugin id OpenPencil keeps its own state under, on nodes and in `.fig` files. */\nexport const OPEN_PENCIL_PLUGIN_ID = 'open-pencil'\n\n/**\n * What a field holds:\n * - `content` belongs to the node like its fills do and exists only as plugin data, so it\n * travels with a component copied into a library or another document;\n * - `format` repeats a node or variable field for files that have no slot for it, where the\n * node field is what counts;\n * - `bookkeeping` records where a node or document came from and stays behind.\n */\nexport type PluginDataRole = 'content' | 'format' | 'bookkeeping'\n\n/** One OpenPencil plugin-data key. */\nexport interface PluginDataKey {\n readonly key: string\n readonly role: PluginDataRole\n}\n\n/** A plugin-data key and how its string value is read and written. */\nexport interface PluginDataField<T> extends PluginDataKey {\n /** The stored value, or `undefined` when it is missing or not a valid value. */\n decode(value: string | null | undefined): T | undefined\n encode(value: T): string\n}\n\n/**\n * A value stored as JSON. Invalid JSON and a wrong shape both read as missing: plugin data\n * comes from files anyone can edit, so a bad entry is ignored rather than thrown on.\n */\nexport function jsonPluginDataField<T>(\n key: string,\n role: PluginDataRole,\n schema: v.GenericSchema<unknown, T>\n): PluginDataField<T> {\n const stored = v.pipe(v.string(), v.parseJson(), schema)\n return {\n key,\n role,\n decode(value) {\n // Most layers carry no entry at all; validating that absence builds an issue per read.\n if (value == null) return undefined\n const parsed = v.safeParse(stored, value)\n return parsed.success ? parsed.output : undefined\n },\n encode: (value) => JSON.stringify(value)\n }\n}\n\n/** A value stored as one of a fixed set of plain strings. */\nexport function textPluginDataField<const T extends string>(\n key: string,\n role: PluginDataRole,\n values: readonly T[]\n): PluginDataField<T> {\n const schema = v.picklist(values)\n return {\n key,\n role,\n decode(value) {\n if (value == null) return undefined\n const parsed = v.safeParse(schema, value)\n return parsed.success ? parsed.output : undefined\n },\n encode: (value) => value\n }\n}\n\nexport function isPluginDataEntry(entry: PluginDataEntry, field: PluginDataKey): boolean {\n return entry.pluginId === OPEN_PENCIL_PLUGIN_ID && entry.key === field.key\n}\n\nexport function hasPluginData(\n entries: readonly PluginDataEntry[] | undefined,\n field: PluginDataKey\n): boolean {\n return entries?.some((entry) => isPluginDataEntry(entry, field)) ?? false\n}\n\nexport function readPluginData<T>(\n entries: readonly PluginDataEntry[] | undefined,\n field: PluginDataField<T>\n): T | undefined {\n return field.decode(entries?.find((entry) => isPluginDataEntry(entry, field))?.value)\n}\n\n/** Every valid value of a field kept as several entries under one key. */\nexport function readAllPluginData<T>(\n entries: readonly PluginDataEntry[] | undefined,\n field: PluginDataField<T>\n): T[] {\n return (entries ?? []).flatMap((entry) => {\n if (!isPluginDataEntry(entry, field)) return []\n const value = field.decode(entry.value)\n return value === undefined ? [] : [value]\n })\n}\n\nexport function pluginDataEntry<T>(field: PluginDataField<T>, value: T): PluginDataEntry {\n return { pluginId: OPEN_PENCIL_PLUGIN_ID, key: field.key, value: field.encode(value) }\n}\n\n/** Entries other than those of `fields`; other plugins' entries are always kept. */\nexport function withoutPluginData(\n entries: readonly PluginDataEntry[],\n fields: readonly PluginDataKey[]\n): PluginDataEntry[] {\n return entries.filter((entry) => !fields.some((field) => isPluginDataEntry(entry, field)))\n}\n\n/** Entries with `field` set to `value`, appended last; `undefined` removes the field. */\nexport function withPluginData<T>(\n entries: readonly PluginDataEntry[],\n field: PluginDataField<T>,\n value: T | undefined\n): PluginDataEntry[] {\n return withAllPluginData(entries, field, value === undefined ? [] : [value])\n}\n\n/** Entries with every entry of `field` replaced by one per value. */\nexport function withAllPluginData<T>(\n entries: readonly PluginDataEntry[],\n field: PluginDataField<T>,\n values: readonly T[]\n): PluginDataEntry[] {\n return [\n ...withoutPluginData(entries, [field]),\n ...values.map((value) => pluginDataEntry(field, value))\n ]\n}\n"],"mappings":";;;AAKA,MAAa,wBAAwB;;;;;AA6BrC,SAAgB,oBACd,KACA,MACA,QACoB;CACpB,MAAM,SAAS,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,UAAU,GAAG,MAAM;CACvD,OAAO;EACL;EACA;EACA,OAAO,OAAO;GAEZ,IAAI,SAAS,MAAM,OAAO,KAAA;GAC1B,MAAM,SAAS,EAAE,U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AAO,kBAAkB,SAAS,OAAO,UAAU,KAAA,IAAY,CAAC,IAAI,CAAC,KAAK,CAAC;AAC7E;;AAGA,SAAgB,kBACd,SACA,OACA,QACmB;CACnB,OAAO,CACL,GAAG,kBAAkB,SAAS,CAAC,KAAK,CAAC,GACrC,GAAG,OAAO,KAAK,UAAU,gBAAgB,OAAO,KAAK,CAAC,CACxD;AACF"}
@@ -44,6 +44,11 @@ declare const OPEN_PENCIL_PLUGIN_DATA: {
44
44
  enabledLibraries: PluginDataField<EnabledLibraryBinding[]>;
45
45
  /** The library this document publishes as, on the DOCUMENT node. */
46
46
  sourceLibraryPublication: PluginDataField<SourceLibraryPublication>;
47
+ /**
48
+ * The layer chosen as the document's thumbnail, on the DOCUMENT node. Figma keeps its own
49
+ * choice outside the file, so a `.fig` carries only this one.
50
+ */
51
+ thumbnail: PluginDataField<string>;
47
52
  /** Canvas comment threads, deleted ones included, on the DOCUMENT node. */
48
53
  comments: PluginDataField<CommentThread[]>;
49
54
  /** The statuses layers can be in, on the DOCUMENT node. */
@@ -113,6 +118,27 @@ declare const OPEN_PENCIL_PLUGIN_DATA: {
113
118
  invalid?: string | undefined;
114
119
  propertyId: string;
115
120
  } | undefined;
121
+ transition?: {
122
+ duration: number;
123
+ easing: {
124
+ easing: "IN_CUBIC" | "OUT_CUBIC" | "INOUT_CUBIC" | "LINEAR" | "IN_BACK_CUBIC" | "OUT_BACK_CUBIC" | "INOUT_BACK_CUBIC" | "CUSTOM_CUBIC" | "SPRING" | "GENTLE_SPRING" | "CUSTOM_SPRING" | "SPRING_PRESET_ONE" | "SPRING_PRESET_TWO" | "SPRING_PRESET_THREE" | "HOLD" | "EASE_IN";
125
+ bezier?: {
126
+ x1: number;
127
+ y1: number;
128
+ x2: number;
129
+ y2: number;
130
+ } | undefined;
131
+ spring?: {
132
+ stiffness: number;
133
+ damping: number;
134
+ mass: number;
135
+ type?: "NORMALIZED" | "PHYSICAL" | undefined;
136
+ platform?: "ANDROID" | "IOS_WEB" | undefined;
137
+ } | undefined;
138
+ };
139
+ durationVariableId?: string | undefined;
140
+ easingVariableId?: string | undefined;
141
+ } | undefined;
116
142
  }>;
117
143
  /** The icon a frame draws, such as `lucide:home`, on the frame its paths are in. */
118
144
  icon: PluginDataField<{
@@ -137,6 +163,47 @@ declare const OPEN_PENCIL_PLUGIN_DATA: {
137
163
  preset: string;
138
164
  } | undefined;
139
165
  }>;
166
+ /** One entry per paint that draws a mesh gradient, matched to its image paint by the frame's hash. */
167
+ mesh: PluginDataField<{
168
+ image: string;
169
+ mesh: {
170
+ columns: number;
171
+ rows: number;
172
+ points: {
173
+ position: {
174
+ x: number;
175
+ y: number;
176
+ };
177
+ left?: {
178
+ x: number;
179
+ y: number;
180
+ } | undefined;
181
+ right?: {
182
+ x: number;
183
+ y: number;
184
+ } | undefined;
185
+ top?: {
186
+ x: number;
187
+ y: number;
188
+ } | undefined;
189
+ bottom?: {
190
+ x: number;
191
+ y: number;
192
+ } | undefined;
193
+ }[];
194
+ colors: {
195
+ r: number;
196
+ g: number;
197
+ b: number;
198
+ a: number;
199
+ }[];
200
+ };
201
+ frame?: {
202
+ width: number;
203
+ height: number;
204
+ key: string;
205
+ } | undefined;
206
+ }>;
140
207
  };
141
208
  /**
142
209
  * A node's plugin data that is part of its content, in a stable order: OpenPencil's content