@open-pencil/scene-graph 0.17.0 → 0.18.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (423) hide show
  1. package/dist/behaviours/index.d.ts +3 -2
  2. package/dist/behaviours/index.js +2 -1
  3. package/dist/behaviours/kinds.d.ts.map +1 -1
  4. package/dist/behaviours/kinds.js +15 -8
  5. package/dist/behaviours/kinds.js.map +1 -1
  6. package/dist/behaviours/model.d.ts +2 -2
  7. package/dist/behaviours/model.d.ts.map +1 -1
  8. package/dist/behaviours/model.js.map +1 -1
  9. package/dist/behaviours/schema.d.ts +136 -1
  10. package/dist/behaviours/schema.d.ts.map +1 -1
  11. package/dist/behaviours/schema.js +17 -2
  12. package/dist/behaviours/schema.js.map +1 -1
  13. package/dist/behaviours/spec.d.ts.map +1 -1
  14. package/dist/behaviours/spec.js +4 -0
  15. package/dist/behaviours/spec.js.map +1 -1
  16. package/dist/behaviours/transition.d.ts +23 -0
  17. package/dist/behaviours/transition.d.ts.map +1 -0
  18. package/dist/behaviours/transition.js +36 -0
  19. package/dist/behaviours/transition.js.map +1 -0
  20. package/dist/checkpoint.d.ts.map +1 -1
  21. package/dist/checkpoint.js +2 -0
  22. package/dist/checkpoint.js.map +1 -1
  23. package/dist/color/index.d.ts +12 -9
  24. package/dist/color/index.d.ts.map +1 -1
  25. package/dist/color/index.js +15 -25
  26. package/dist/color/index.js.map +1 -1
  27. package/dist/color/management.d.ts +51 -23
  28. package/dist/color/management.d.ts.map +1 -1
  29. package/dist/color/management.js +154 -149
  30. package/dist/color/management.js.map +1 -1
  31. package/dist/color/okhcl.d.ts +28 -10
  32. package/dist/color/okhcl.d.ts.map +1 -1
  33. package/dist/color/okhcl.js +56 -40
  34. package/dist/color/okhcl.js.map +1 -1
  35. package/dist/color/schema.d.ts +6 -1
  36. package/dist/color/schema.d.ts.map +1 -1
  37. package/dist/color/schema.js +10 -1
  38. package/dist/color/schema.js.map +1 -1
  39. package/dist/constraints.d.ts.map +1 -1
  40. package/dist/constraints.js +2 -1
  41. package/dist/constraints.js.map +1 -1
  42. package/dist/copy.d.ts +7 -1
  43. package/dist/copy.d.ts.map +1 -1
  44. package/dist/copy.js +22 -1
  45. package/dist/copy.js.map +1 -1
  46. package/dist/corners.d.ts +3 -1
  47. package/dist/corners.d.ts.map +1 -1
  48. package/dist/corners.js +3 -1
  49. package/dist/corners.js.map +1 -1
  50. package/dist/css/grid.js +1 -1
  51. package/dist/css/index.d.ts +2 -1
  52. package/dist/css/index.js +3 -2
  53. package/dist/css/motion.d.ts +12 -0
  54. package/dist/css/motion.d.ts.map +1 -0
  55. package/dist/css/motion.js +60 -0
  56. package/dist/css/motion.js.map +1 -0
  57. package/dist/css/shadows.d.ts +4 -3
  58. package/dist/css/shadows.d.ts.map +1 -1
  59. package/dist/css/shadows.js +7 -6
  60. package/dist/css/shadows.js.map +1 -1
  61. package/dist/css/values.d.ts +3 -2
  62. package/dist/css/values.d.ts.map +1 -1
  63. package/dist/css/values.js +4 -4
  64. package/dist/css/values.js.map +1 -1
  65. package/dist/fields/index.d.ts +2 -2
  66. package/dist/fields/index.js +2 -2
  67. package/dist/fields/layout.d.ts +3 -1
  68. package/dist/fields/layout.d.ts.map +1 -1
  69. package/dist/fields/layout.js +9 -1
  70. package/dist/fields/layout.js.map +1 -1
  71. package/dist/figjam/palette.js +1 -1
  72. package/dist/font-style.d.ts.map +1 -1
  73. package/dist/font-style.js +7 -3
  74. package/dist/font-style.js.map +1 -1
  75. package/dist/generated/index.d.ts +6 -2
  76. package/dist/generated/index.d.ts.map +1 -1
  77. package/dist/generated/index.js +14 -4
  78. package/dist/generated/index.js.map +1 -1
  79. package/dist/geometry.d.ts +6 -1
  80. package/dist/geometry.d.ts.map +1 -1
  81. package/dist/geometry.js +10 -2
  82. package/dist/geometry.js.map +1 -1
  83. package/dist/graph.d.ts +29 -4
  84. package/dist/graph.d.ts.map +1 -1
  85. package/dist/graph.js +59 -9
  86. package/dist/graph.js.map +1 -1
  87. package/dist/group-bounds.d.ts +5 -2
  88. package/dist/group-bounds.d.ts.map +1 -1
  89. package/dist/group-bounds.js +38 -8
  90. package/dist/group-bounds.js.map +1 -1
  91. package/dist/hit-test.d.ts.map +1 -1
  92. package/dist/hit-test.js +19 -8
  93. package/dist/hit-test.js.map +1 -1
  94. package/dist/index.d.ts +2 -2
  95. package/dist/index.js +2 -2
  96. package/dist/instances/content-size.js +1 -1
  97. package/dist/instances/fields.d.ts +2 -2
  98. package/dist/instances/fields.d.ts.map +1 -1
  99. package/dist/instances/fields.js +2 -0
  100. package/dist/instances/fields.js.map +1 -1
  101. package/dist/instances/index.d.ts.map +1 -1
  102. package/dist/instances/index.js +50 -11
  103. package/dist/instances/index.js.map +1 -1
  104. package/dist/instances/sync.js +67 -7
  105. package/dist/instances/sync.js.map +1 -1
  106. package/dist/layout/flow.d.ts +16 -0
  107. package/dist/layout/flow.d.ts.map +1 -0
  108. package/dist/layout/flow.js +34 -0
  109. package/dist/layout/flow.js.map +1 -0
  110. package/dist/layout/index.d.ts +4 -3
  111. package/dist/layout/index.js +4 -3
  112. package/dist/layout/keywords.d.ts.map +1 -1
  113. package/dist/layout/keywords.js +7 -1
  114. package/dist/layout/keywords.js.map +1 -1
  115. package/dist/layout/sizing.d.ts +9 -1
  116. package/dist/layout/sizing.d.ts.map +1 -1
  117. package/dist/layout/sizing.js +17 -1
  118. package/dist/layout/sizing.js.map +1 -1
  119. package/dist/layout/spacing.d.ts +7 -1
  120. package/dist/layout/spacing.d.ts.map +1 -1
  121. package/dist/layout/spacing.js +10 -1
  122. package/dist/layout/spacing.js.map +1 -1
  123. package/dist/mesh/geometry.d.ts +83 -0
  124. package/dist/mesh/geometry.d.ts.map +1 -0
  125. package/dist/mesh/geometry.js +441 -0
  126. package/dist/mesh/geometry.js.map +1 -0
  127. package/dist/mesh/index.d.ts +4 -0
  128. package/dist/mesh/index.js +4 -0
  129. package/dist/mesh/model.d.ts +28 -0
  130. package/dist/mesh/model.d.ts.map +1 -0
  131. package/dist/mesh/model.js +40 -0
  132. package/dist/mesh/model.js.map +1 -0
  133. package/dist/mesh/schema.d.ts +191 -0
  134. package/dist/mesh/schema.d.ts.map +1 -0
  135. package/dist/mesh/schema.js +56 -0
  136. package/dist/mesh/schema.js.map +1 -0
  137. package/dist/mutation-impact.d.ts +2 -0
  138. package/dist/mutation-impact.d.ts.map +1 -1
  139. package/dist/mutation-impact.js +18 -7
  140. package/dist/mutation-impact.js.map +1 -1
  141. package/dist/node-defaults.d.ts +3 -1
  142. package/dist/node-defaults.d.ts.map +1 -1
  143. package/dist/node-defaults.js +22 -6
  144. package/dist/node-defaults.js.map +1 -1
  145. package/dist/paints/index.d.ts +5 -3
  146. package/dist/paints/index.js +5 -3
  147. package/dist/paints/pattern.d.ts +5 -1
  148. package/dist/paints/pattern.d.ts.map +1 -1
  149. package/dist/paints/pattern.js +33 -1
  150. package/dist/paints/pattern.js.map +1 -1
  151. package/dist/paints/shows.d.ts +4 -1
  152. package/dist/paints/shows.d.ts.map +1 -1
  153. package/dist/paints/shows.js +8 -1
  154. package/dist/paints/shows.js.map +1 -1
  155. package/dist/paints/solid.d.ts +11 -0
  156. package/dist/paints/solid.d.ts.map +1 -0
  157. package/dist/paints/solid.js +18 -0
  158. package/dist/paints/solid.js.map +1 -0
  159. package/dist/paints/stills.d.ts +74 -0
  160. package/dist/paints/stills.d.ts.map +1 -0
  161. package/dist/paints/stills.js +113 -0
  162. package/dist/paints/stills.js.map +1 -0
  163. package/dist/plugin-data/field.d.ts.map +1 -1
  164. package/dist/plugin-data/field.js +2 -0
  165. package/dist/plugin-data/field.js.map +1 -1
  166. package/dist/plugin-data/fields.d.ts +67 -0
  167. package/dist/plugin-data/fields.d.ts.map +1 -1
  168. package/dist/plugin-data/fields.js +12 -7
  169. package/dist/plugin-data/fields.js.map +1 -1
  170. package/dist/resize.d.ts +10 -3
  171. package/dist/resize.d.ts.map +1 -1
  172. package/dist/resize.js +34 -3
  173. package/dist/resize.js.map +1 -1
  174. package/dist/scaling/index.d.ts +2 -2
  175. package/dist/scaling/index.js +2 -2
  176. package/dist/scaling/node.d.ts +2 -1
  177. package/dist/scaling/node.d.ts.map +1 -1
  178. package/dist/scaling/node.js +27 -7
  179. package/dist/scaling/node.js.map +1 -1
  180. package/dist/shaders/index.d.ts +2 -3
  181. package/dist/shaders/index.js +2 -3
  182. package/dist/shaders/model.d.ts +3 -11
  183. package/dist/shaders/model.d.ts.map +1 -1
  184. package/dist/shaders/model.js +13 -36
  185. package/dist/shaders/model.js.map +1 -1
  186. package/dist/shaders/schema.d.ts +1 -1
  187. package/dist/shaders/schema.js +1 -1
  188. package/dist/shaders/schema.js.map +1 -1
  189. package/dist/shape-with-text/document.js +276 -0
  190. package/dist/shape-with-text/document.js.map +1 -0
  191. package/dist/shape-with-text/geometry.d.ts +13 -1
  192. package/dist/shape-with-text/geometry.d.ts.map +1 -1
  193. package/dist/shape-with-text/geometry.js +103 -41
  194. package/dist/shape-with-text/geometry.js.map +1 -1
  195. package/dist/shape-with-text/index.d.ts +2 -2
  196. package/dist/shape-with-text/index.js +2 -2
  197. package/dist/shared-style-index.d.ts +21 -0
  198. package/dist/shared-style-index.d.ts.map +1 -0
  199. package/dist/shared-style-index.js +72 -0
  200. package/dist/shared-style-index.js.map +1 -0
  201. package/dist/shared-styles.d.ts +3 -3
  202. package/dist/shared-styles.d.ts.map +1 -1
  203. package/dist/shared-styles.js +16 -7
  204. package/dist/shared-styles.js.map +1 -1
  205. package/dist/slides/drop.d.ts +32 -0
  206. package/dist/slides/drop.d.ts.map +1 -0
  207. package/dist/slides/drop.js +81 -0
  208. package/dist/slides/drop.js.map +1 -0
  209. package/dist/slides/index.d.ts +56 -0
  210. package/dist/slides/index.d.ts.map +1 -0
  211. package/dist/slides/index.js +134 -0
  212. package/dist/slides/index.js.map +1 -0
  213. package/dist/slides/motion.d.ts +55 -0
  214. package/dist/slides/motion.d.ts.map +1 -0
  215. package/dist/slides/motion.js +142 -0
  216. package/dist/slides/motion.js.map +1 -0
  217. package/dist/slides/playback.d.ts +59 -0
  218. package/dist/slides/playback.d.ts.map +1 -0
  219. package/dist/slides/playback.js +188 -0
  220. package/dist/slides/playback.js.map +1 -0
  221. package/dist/slides/types.d.ts +62 -0
  222. package/dist/slides/types.d.ts.map +1 -0
  223. package/dist/slides/types.js +39 -0
  224. package/dist/slides/types.js.map +1 -0
  225. package/dist/statuses/workflow.js +1 -1
  226. package/dist/text/direction.d.ts +6 -3
  227. package/dist/text/direction.d.ts.map +1 -1
  228. package/dist/text/direction.js +12 -12
  229. package/dist/text/direction.js.map +1 -1
  230. package/dist/text/index.d.ts +2 -1
  231. package/dist/text/index.js +3 -2
  232. package/dist/text/name.d.ts +22 -0
  233. package/dist/text/name.d.ts.map +1 -0
  234. package/dist/text/name.js +38 -0
  235. package/dist/text/name.js.map +1 -0
  236. package/dist/text/references.d.ts.map +1 -1
  237. package/dist/text/references.js +1 -2
  238. package/dist/text/references.js.map +1 -1
  239. package/dist/thumbnail.d.ts +23 -0
  240. package/dist/thumbnail.d.ts.map +1 -0
  241. package/dist/thumbnail.js +47 -0
  242. package/dist/thumbnail.js.map +1 -0
  243. package/dist/transfer/apply.d.ts.map +1 -1
  244. package/dist/transfer/apply.js +14 -3
  245. package/dist/transfer/apply.js.map +1 -1
  246. package/dist/transfer/copied.d.ts +6 -1
  247. package/dist/transfer/copied.d.ts.map +1 -1
  248. package/dist/transfer/copied.js +2 -2
  249. package/dist/transfer/copied.js.map +1 -1
  250. package/dist/transfer/dependencies.d.ts +4 -1
  251. package/dist/transfer/dependencies.d.ts.map +1 -1
  252. package/dist/transfer/dependencies.js +10 -1
  253. package/dist/transfer/dependencies.js.map +1 -1
  254. package/dist/transfer/history.js +2 -0
  255. package/dist/transfer/history.js.map +1 -1
  256. package/dist/transfer/identity.js +18 -3
  257. package/dist/transfer/identity.js.map +1 -1
  258. package/dist/transfer/index.d.ts +2 -1
  259. package/dist/transfer/index.js +4 -3
  260. package/dist/transfer/library.d.ts +45 -0
  261. package/dist/transfer/library.d.ts.map +1 -0
  262. package/dist/transfer/library.js +102 -0
  263. package/dist/transfer/library.js.map +1 -0
  264. package/dist/transfer/nodes.d.ts.map +1 -1
  265. package/dist/transfer/nodes.js +9 -0
  266. package/dist/transfer/nodes.js.map +1 -1
  267. package/dist/transfer/plan.d.ts +9 -0
  268. package/dist/transfer/plan.d.ts.map +1 -1
  269. package/dist/transfer/plan.js +51 -6
  270. package/dist/transfer/plan.js.map +1 -1
  271. package/dist/transfer/remove.js +7 -1
  272. package/dist/transfer/remove.js.map +1 -1
  273. package/dist/transfer/validation.js +8 -4
  274. package/dist/transfer/validation.js.map +1 -1
  275. package/dist/transfer/variables.d.ts.map +1 -1
  276. package/dist/transfer/variables.js +2 -1
  277. package/dist/transfer/variables.js.map +1 -1
  278. package/dist/types.d.ts +90 -12
  279. package/dist/types.d.ts.map +1 -1
  280. package/dist/types.js +33 -1
  281. package/dist/types.js.map +1 -1
  282. package/dist/variables/bindings.d.ts +11 -6
  283. package/dist/variables/bindings.d.ts.map +1 -1
  284. package/dist/variables/bindings.js +162 -38
  285. package/dist/variables/bindings.js.map +1 -1
  286. package/dist/variables/easing.d.ts +48 -0
  287. package/dist/variables/easing.d.ts.map +1 -0
  288. package/dist/variables/easing.js +321 -0
  289. package/dist/variables/easing.js.map +1 -0
  290. package/dist/variables/formula/index.d.ts +4 -2
  291. package/dist/variables/formula/index.d.ts.map +1 -1
  292. package/dist/variables/formula/index.js +26 -9
  293. package/dist/variables/formula/index.js.map +1 -1
  294. package/dist/variables/formula/parse.js +1 -1
  295. package/dist/variables/formula/schema.js +1 -1
  296. package/dist/variables/formula/signatures.d.ts +2 -2
  297. package/dist/variables/formula/signatures.d.ts.map +1 -1
  298. package/dist/variables/formula/signatures.js.map +1 -1
  299. package/dist/variables/formula/tree.d.ts +2 -2
  300. package/dist/variables/formula/tree.d.ts.map +1 -1
  301. package/dist/variables/formula/tree.js.map +1 -1
  302. package/dist/variables/index.d.ts +22 -5
  303. package/dist/variables/index.d.ts.map +1 -1
  304. package/dist/variables/index.js +67 -17
  305. package/dist/variables/index.js.map +1 -1
  306. package/dist/variables/lookup.js +1 -1
  307. package/dist/variables/lookup.js.map +1 -1
  308. package/dist/variables/motion.d.ts +46 -0
  309. package/dist/variables/motion.d.ts.map +1 -0
  310. package/dist/variables/motion.js +107 -0
  311. package/dist/variables/motion.js.map +1 -0
  312. package/dist/variables/paints.d.ts +10 -2
  313. package/dist/variables/paints.d.ts.map +1 -1
  314. package/dist/variables/paints.js +24 -10
  315. package/dist/variables/paints.js.map +1 -1
  316. package/dist/variables/resolution.d.ts.map +1 -1
  317. package/dist/variables/resolution.js +10 -9
  318. package/dist/variables/resolution.js.map +1 -1
  319. package/dist/variables/schema.d.ts +59 -1
  320. package/dist/variables/schema.d.ts.map +1 -1
  321. package/dist/variables/schema.js +36 -1
  322. package/dist/variables/schema.js.map +1 -1
  323. package/dist/variables/style-bindings.d.ts +23 -0
  324. package/dist/variables/style-bindings.d.ts.map +1 -0
  325. package/dist/variables/style-bindings.js +83 -0
  326. package/dist/variables/style-bindings.js.map +1 -0
  327. package/package.json +21 -2
  328. package/src/behaviours/index.ts +1 -0
  329. package/src/behaviours/kinds.ts +5 -1
  330. package/src/behaviours/model.ts +2 -2
  331. package/src/behaviours/schema.ts +19 -2
  332. package/src/behaviours/spec.ts +5 -0
  333. package/src/behaviours/transition.ts +46 -0
  334. package/src/checkpoint.ts +2 -0
  335. package/src/color/index.ts +15 -24
  336. package/src/color/management.ts +144 -168
  337. package/src/color/okhcl.ts +62 -43
  338. package/src/color/schema.ts +13 -0
  339. package/src/constraints.ts +2 -1
  340. package/src/copy.ts +29 -0
  341. package/src/corners.ts +3 -0
  342. package/src/css/index.ts +1 -0
  343. package/src/css/motion.ts +51 -0
  344. package/src/css/shadows.ts +7 -6
  345. package/src/css/values.ts +7 -3
  346. package/src/fields/layout.ts +9 -0
  347. package/src/font-style.ts +8 -3
  348. package/src/generated/index.ts +15 -3
  349. package/src/geometry.ts +13 -1
  350. package/src/graph.ts +72 -9
  351. package/src/group-bounds.ts +54 -13
  352. package/src/hit-test.ts +13 -8
  353. package/src/instances/fields.ts +2 -0
  354. package/src/instances/index.ts +71 -12
  355. package/src/instances/sync.ts +93 -11
  356. package/src/layout/flow.ts +34 -0
  357. package/src/layout/index.ts +1 -0
  358. package/src/layout/keywords.ts +7 -1
  359. package/src/layout/sizing.ts +30 -0
  360. package/src/layout/spacing.ts +12 -0
  361. package/src/mesh/geometry.ts +433 -0
  362. package/src/mesh/index.ts +3 -0
  363. package/src/mesh/model.ts +50 -0
  364. package/src/mesh/schema.ts +81 -0
  365. package/src/mutation-impact.ts +23 -7
  366. package/src/node-defaults.ts +22 -5
  367. package/src/paints/index.ts +2 -0
  368. package/src/paints/pattern.ts +55 -0
  369. package/src/paints/shows.ts +9 -0
  370. package/src/paints/solid.ts +10 -0
  371. package/src/paints/stills.ts +182 -0
  372. package/src/plugin-data/field.ts +3 -0
  373. package/src/plugin-data/fields.ts +15 -2
  374. package/src/resize.ts +32 -20
  375. package/src/scaling/index.ts +1 -1
  376. package/src/scaling/node.ts +43 -6
  377. package/src/shaders/index.ts +0 -1
  378. package/src/shaders/model.ts +19 -49
  379. package/src/shaders/schema.ts +1 -1
  380. package/src/shape-with-text/document.ts +175 -0
  381. package/src/shape-with-text/geometry.ts +99 -27
  382. package/src/shared-style-index.ts +106 -0
  383. package/src/shared-styles.ts +21 -14
  384. package/src/slides/drop.ts +94 -0
  385. package/src/slides/index.ts +125 -0
  386. package/src/slides/motion.ts +169 -0
  387. package/src/slides/playback.ts +200 -0
  388. package/src/slides/types.ts +94 -0
  389. package/src/text/direction.ts +13 -23
  390. package/src/text/index.ts +1 -0
  391. package/src/text/name.ts +39 -0
  392. package/src/text/references.ts +3 -3
  393. package/src/thumbnail.ts +52 -0
  394. package/src/transfer/apply.ts +16 -3
  395. package/src/transfer/copied.ts +7 -2
  396. package/src/transfer/dependencies.ts +10 -1
  397. package/src/transfer/history.ts +2 -0
  398. package/src/transfer/identity.ts +34 -2
  399. package/src/transfer/index.ts +6 -0
  400. package/src/transfer/library.ts +153 -0
  401. package/src/transfer/nodes.ts +20 -0
  402. package/src/transfer/plan.ts +96 -10
  403. package/src/transfer/remove.ts +6 -2
  404. package/src/transfer/validation.ts +15 -7
  405. package/src/transfer/variables.ts +8 -2
  406. package/src/types.ts +114 -10
  407. package/src/variables/bindings.ts +260 -36
  408. package/src/variables/easing.ts +282 -0
  409. package/src/variables/formula/index.ts +33 -14
  410. package/src/variables/formula/signatures.ts +6 -2
  411. package/src/variables/formula/tree.ts +3 -3
  412. package/src/variables/index.ts +90 -37
  413. package/src/variables/lookup.ts +1 -1
  414. package/src/variables/motion.ts +151 -0
  415. package/src/variables/paints.ts +29 -7
  416. package/src/variables/resolution.ts +11 -5
  417. package/src/variables/schema.ts +41 -0
  418. package/src/variables/style-bindings.ts +137 -0
  419. package/dist/shaders/still.d.ts +0 -18
  420. package/dist/shaders/still.d.ts.map +0 -1
  421. package/dist/shaders/still.js +0 -36
  422. package/dist/shaders/still.js.map +0 -1
  423. package/src/shaders/still.ts +0 -41
@@ -1,14 +1,9 @@
1
- import { TRANSPARENT } from "../constants.js";
2
- import { readAllPluginData, withAllPluginData } from "../plugin-data/field.js";
3
1
  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";
2
+ import { createStillPaint, isStillFrameCurrent, readStillPaints, stillContentKey, stillPaintOf, withStillPaints } from "../paints/stills.js";
8
3
  //#region src/shaders/model.ts
9
4
  /** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */
10
5
  function readShaderPaints(node) {
11
- return readAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.shader);
6
+ return readStillPaints(node, OPEN_PENCIL_PLUGIN_DATA.shader);
12
7
  }
13
8
  /**
14
9
  * The shader a fill or stroke of `node` draws: an image paint whose image is a shader's frame.
@@ -16,8 +11,7 @@ function readShaderPaints(node) {
16
11
  * image it holds.
17
12
  */
18
13
  function shaderOfPaint(node, paint) {
19
- if (paint.type !== "IMAGE" || !paint.imageHash) return null;
20
- return readShaderPaints(node).find((shader) => shader.image === paint.imageHash) ?? null;
14
+ return stillPaintOf(node, paint, OPEN_PENCIL_PLUGIN_DATA.shader);
21
15
  }
22
16
  /** Whether any paint of `node` draws a shader. */
23
17
  function hasShaderPaint(node) {
@@ -28,45 +22,28 @@ function hasShaderPaint(node) {
28
22
  * stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.
29
23
  */
30
24
  function withShaderPaints(node, paints, shaders = []) {
31
- const shown = new Set(imagePaintHashes(paints));
32
- const byImage = new Map(readShaderPaints(node).map((shader) => [shader.image, shader]));
33
- for (const shader of shaders) byImage.set(shader.image, shader);
34
- return withAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.shader, [...byImage.values()].filter((shader) => shown.has(shader.image)));
25
+ return withStillPaints(node, paints, OPEN_PENCIL_PLUGIN_DATA.shader, shaders);
35
26
  }
36
- /**
37
- * A new paint that draws `preset`, and the shader entry it shows. Its image names a frame not yet
38
- * rendered, unique to this paint, so no other paint's entry claims it until the frame is drawn.
39
- */
27
+ /** A new paint that draws `preset`, and the shader entry it shows (`createStillPaint`). */
40
28
  function createShaderPaint(preset) {
41
- const image = randomHex(20);
29
+ const { paint, image } = createStillPaint();
42
30
  return {
43
- paint: {
44
- type: "IMAGE",
45
- color: TRANSPARENT,
46
- opacity: 1,
47
- visible: true,
48
- imageHash: image,
49
- imageScaleMode: "FILL"
50
- },
31
+ paint,
51
32
  shader: {
52
33
  image,
53
34
  preset: structuredClone(preset)
54
35
  }
55
36
  };
56
37
  }
57
- /** A short key that tells one preset from another, which a rendered frame records. */
58
- function shaderPresetKey(preset) {
59
- return bytesToHex(sha1(utf8ToBytes(JSON.stringify(preset))));
60
- }
61
- /**
62
- * Whether a shader's frame was rendered for its preset at the size `node` has now, so undoing a
63
- * preset change after reopening the document does not keep a frame of the newer preset.
64
- */
38
+ /** Whether a shader's frame was rendered for its preset at the size `node` has now. */
65
39
  function isShaderFrameCurrent(shader, size) {
66
40
  const { frame } = shader;
67
- return frame !== void 0 && frame.preset === shaderPresetKey(shader.preset) && Math.round(frame.width) === Math.round(size.width) && Math.round(frame.height) === Math.round(size.height);
41
+ return isStillFrameCurrent(frame && {
42
+ ...frame,
43
+ key: frame.preset
44
+ }, stillContentKey(shader.preset), size);
68
45
  }
69
46
  //#endregion
70
- export { createShaderPaint, hasShaderPaint, isShaderFrameCurrent, readShaderPaints, shaderOfPaint, shaderPresetKey, withShaderPaints };
47
+ export { createShaderPaint, hasShaderPaint, isShaderFrameCurrent, readShaderPaints, shaderOfPaint, withShaderPaints };
71
48
 
72
49
  //# sourceMappingURL=model.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"model.js","names":[],"sources":["../../src/shaders/model.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 } from '../plugin-data/field'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { Fill, SceneNode } from '../types'\nimport type { ShaderPaint, ShaderPreset } from './schema'\n\n/** What shader paints read of a node. */\ntype ShaderNode = Pick<SceneNode, 'fills' | 'strokes' | 'pluginData'>\n\n/** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */\nexport function readShaderPaints(node: Pick<SceneNode, 'pluginData'>): ShaderPaint[] {\n return readAllPluginData(node.pluginData, OPEN_PENCIL_PLUGIN_DATA.shader)\n}\n\n/**\n * The shader a fill or stroke of `node` draws: an image paint whose image is a shader's frame.\n * Null for any other paint, including one whose image was replaced, which then draws as the\n * image it holds.\n */\nexport function shaderOfPaint(\n node: Pick<SceneNode, 'pluginData'>,\n paint: Fill\n): ShaderPaint | null {\n if (paint.type !== 'IMAGE' || !paint.imageHash) return null\n return readShaderPaints(node).find((shader) => shader.image === paint.imageHash) ?? null\n}\n\n/** Whether any paint of `node` draws a shader. */\nexport function hasShaderPaint(node: ShaderNode): boolean {\n return [...node.fills, ...node.strokes].some((paint) => shaderOfPaint(node, paint) !== null)\n}\n\n/**\n * The node's plugin data with `shaders` set by their image, keeping only shaders a fill or\n * stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.\n */\nexport function withShaderPaints(\n node: Pick<SceneNode, 'pluginData'>,\n paints: readonly Fill[],\n shaders: readonly ShaderPaint[] = []\n): SceneNode['pluginData'] {\n const shown = new Set(imagePaintHashes(paints))\n const byImage = new Map(readShaderPaints(node).map((shader) => [shader.image, shader]))\n for (const shader of shaders) byImage.set(shader.image, shader)\n return withAllPluginData(\n node.pluginData,\n OPEN_PENCIL_PLUGIN_DATA.shader,\n [...byImage.values()].filter((shader) => shown.has(shader.image))\n )\n}\n\n/**\n * A new paint that draws `preset`, and the shader entry it shows. Its image names a frame not yet\n * rendered, unique to this paint, so no other paint's entry claims it until the frame is drawn.\n */\nexport function createShaderPaint(preset: ShaderPreset): {\n paint: Fill\n shader: ShaderPaint\n} {\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 shader: { image, preset: structuredClone(preset) }\n }\n}\n\n/** A short key that tells one preset from another, which a rendered frame records. */\nexport function shaderPresetKey(preset: ShaderPreset): string {\n return bytesToHex(sha1(utf8ToBytes(JSON.stringify(preset))))\n}\n\n/**\n * Whether a shader's frame was rendered for its preset at the size `node` has now, so undoing a\n * preset change after reopening the document does not keep a frame of the newer preset.\n */\nexport function isShaderFrameCurrent(\n shader: ShaderPaint,\n size: { width: number; height: number }\n): boolean {\n const { frame } = shader\n return (\n frame !== undefined &&\n frame.preset === shaderPresetKey(shader.preset) &&\n Math.round(frame.width) === Math.round(size.width) &&\n Math.round(frame.height) === Math.round(size.height)\n )\n}\n"],"mappings":";;;;;;;;;AAgBA,SAAgB,iBAAiB,MAAoD;CACnF,OAAO,kBAAkB,KAAK,YAAY,wBAAwB,MAAM;AAC1E;;;;;;AAOA,SAAgB,cACd,MACA,OACoB;CACpB,IAAI,MAAM,SAAS,WAAW,CAAC,MAAM,WAAW,OAAO;CACvD,OAAO,iBAAiB,IAAI,CAAC,CAAC,MAAM,WAAW,OAAO,UAAU,MAAM,SAAS,KAAK;AACtF;;AAGA,SAAgB,eAAe,MAA2B;CACxD,OAAO,CAAC,GAAG,KAAK,OAAO,GAAG,KAAK,OAAO,CAAC,CAAC,MAAM,UAAU,cAAc,MAAM,KAAK,MAAM,IAAI;AAC7F;;;;;AAMA,SAAgB,iBACd,MACA,QACA,UAAkC,CAAC,GACV;CACzB,MAAM,QAAQ,IAAI,IAAI,iBAAiB,MAAM,CAAC;CAC9C,MAAM,UAAU,IAAI,IAAI,iBAAiB,IAAI,CAAC,CAAC,KAAK,WAAW,CAAC,OAAO,OAAO,MAAM,CAAC,CAAC;CACtF,KAAK,MAAM,UAAU,SAAS,QAAQ,IAAI,OAAO,OAAO,MAAM;CAC9D,OAAO,kBACL,KAAK,YACL,wBAAwB,QACxB,CAAC,GAAG,QAAQ,OAAO,CAAC,CAAC,CAAC,QAAQ,WAAW,MAAM,IAAI,OAAO,KAAK,CAAC,CAClE;AACF;;;;;AAMA,SAAgB,kBAAkB,QAGhC;CACA,MAAM,QAAQ,UAAU,EAAE;CAC1B,OAAO;EACL,OAAO;GACL,MAAM;GACN,OAAO;GACP,SAAS;GACT,SAAS;GACT,WAAW;GACX,gBAAgB;EAClB;EACA,QAAQ;GAAE;GAAO,QAAQ,gBAAgB,MAAM;EAAE;CACnD;AACF;;AAGA,SAAgB,gBAAgB,QAA8B;CAC5D,OAAO,WAAW,KAAK,YAAY,KAAK,UAAU,MAAM,CAAC,CAAC,CAAC;AAC7D;;;;;AAMA,SAAgB,qBACd,QACA,MACS;CACT,MAAM,EAAE,UAAU;CAClB,OACE,UAAU,KAAA,KACV,MAAM,WAAW,gBAAgB,OAAO,MAAM,KAC9C,KAAK,MAAM,MAAM,KAAK,MAAM,KAAK,MAAM,KAAK,KAAK,KACjD,KAAK,MAAM,MAAM,MAAM,MAAM,KAAK,MAAM,KAAK,MAAM;AAEvD"}
1
+ {"version":3,"file":"model.js","names":[],"sources":["../../src/shaders/model.ts"],"sourcesContent":["import {\n createStillPaint,\n isStillFrameCurrent,\n readStillPaints,\n stillContentKey,\n stillPaintOf,\n withStillPaints\n} from '../paints/stills'\nimport { OPEN_PENCIL_PLUGIN_DATA } from '../plugin-data/fields'\nimport type { Fill, SceneNode } from '../types'\nimport type { ShaderPaint, ShaderPreset } from './schema'\n\n/** What shader paints read of a node. */\ntype ShaderNode = Pick<SceneNode, 'fills' | 'strokes' | 'pluginData'>\n\n/** Every shader a node's fills and strokes draw, whether or not a paint still shows it. */\nexport function readShaderPaints(node: Pick<SceneNode, 'pluginData'>): ShaderPaint[] {\n return readStillPaints(node, OPEN_PENCIL_PLUGIN_DATA.shader)\n}\n\n/**\n * The shader a fill or stroke of `node` draws: an image paint whose image is a shader's frame.\n * Null for any other paint, including one whose image was replaced, which then draws as the\n * image it holds.\n */\nexport function shaderOfPaint(\n node: Pick<SceneNode, 'pluginData'>,\n paint: Fill\n): ShaderPaint | null {\n return stillPaintOf(node, paint, OPEN_PENCIL_PLUGIN_DATA.shader)\n}\n\n/** Whether any paint of `node` draws a shader. */\nexport function hasShaderPaint(node: ShaderNode): boolean {\n return [...node.fills, ...node.strokes].some((paint) => shaderOfPaint(node, paint) !== null)\n}\n\n/**\n * The node's plugin data with `shaders` set by their image, keeping only shaders a fill or\n * stroke of `paints` still shows, so removing or replacing a paint leaves no entry behind.\n */\nexport function withShaderPaints(\n node: Pick<SceneNode, 'pluginData'>,\n paints: readonly Fill[],\n shaders: readonly ShaderPaint[] = []\n): SceneNode['pluginData'] {\n return withStillPaints(node, paints, OPEN_PENCIL_PLUGIN_DATA.shader, shaders)\n}\n\n/** A new paint that draws `preset`, and the shader entry it shows (`createStillPaint`). */\nexport function createShaderPaint(preset: ShaderPreset): {\n paint: Fill\n shader: ShaderPaint\n} {\n const { paint, image } = createStillPaint()\n return { paint, shader: { image, preset: structuredClone(preset) } }\n}\n\n/** Whether a shader's frame was rendered for its preset at the size `node` has now. */\nexport function isShaderFrameCurrent(\n shader: ShaderPaint,\n size: { width: number; height: number }\n): boolean {\n const { frame } = shader\n return isStillFrameCurrent(\n frame && { ...frame, key: frame.preset },\n stillContentKey(shader.preset),\n size\n )\n}\n"],"mappings":";;;;AAgBA,SAAgB,iBAAiB,MAAoD;CACnF,OAAO,gBAAgB,MAAM,wBAAwB,MAAM;AAC7D;;;;;;AAOA,SAAgB,cACd,MACA,OACoB;CACpB,OAAO,aAAa,MAAM,OAAO,wBAAwB,MAAM;AACjE;;AAGA,SAAgB,eAAe,MAA2B;CACxD,OAAO,CAAC,GAAG,KAAK,OAAO,GAAG,KAAK,OAAO,CAAC,CAAC,MAAM,UAAU,cAAc,MAAM,KAAK,MAAM,IAAI;AAC7F;;;;;AAMA,SAAgB,iBACd,MACA,QACA,UAAkC,CAAC,GACV;CACzB,OAAO,gBAAgB,MAAM,QAAQ,wBAAwB,QAAQ,OAAO;AAC9E;;AAGA,SAAgB,kBAAkB,QAGhC;CACA,MAAM,EAAE,OAAO,UAAU,iBAAiB;CAC1C,OAAO;EAAE;EAAO,QAAQ;GAAE;GAAO,QAAQ,gBAAgB,MAAM;EAAE;CAAE;AACrE;;AAGA,SAAgB,qBACd,QACA,MACS;CACT,MAAM,EAAE,UAAU;CAClB,OAAO,oBACL,SAAS;EAAE,GAAG;EAAO,KAAK,MAAM;CAAO,GACvC,gBAAgB,OAAO,MAAM,GAC7B,IACF;AACF"}
@@ -31,7 +31,7 @@ declare const shaderPaintSchema: v.ObjectSchema<{
31
31
  readonly frame: v.OptionalSchema<v.ObjectSchema<{
32
32
  readonly width: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
33
33
  readonly height: v.SchemaWithPipe<readonly [v.NumberSchema<undefined>, v.FiniteAction<number, undefined>, v.MinValueAction<number, 0, undefined>]>;
34
- /** The preset's key (`shaderPresetKey`) when the frame was rendered. */
34
+ /** The preset's key (`stillContentKey`) when the frame was rendered. */
35
35
  readonly preset: v.SchemaWithPipe<readonly [v.StringSchema<undefined>, v.NonEmptyAction<string, undefined>]>;
36
36
  }, undefined>, undefined>;
37
37
  }, undefined>;
@@ -26,7 +26,7 @@ const shaderPaintSchema = v.object({
26
26
  frame: v.optional(v.object({
27
27
  width: v.pipe(v.number(), v.finite(), v.minValue(0)),
28
28
  height: v.pipe(v.number(), v.finite(), v.minValue(0)),
29
- /** The preset's key (`shaderPresetKey`) when the frame was rendered. */
29
+ /** The preset's key (`stillContentKey`) when the frame was rendered. */
30
30
  preset: v.pipe(v.string(), v.nonEmpty())
31
31
  }))
32
32
  });
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","names":[],"sources":["../../src/shaders/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\n/** One effect of a shader preset, as the `shaders` library names it, with the effects it holds. */\nexport interface ShaderComponent {\n type: string\n id?: string\n props?: Record<string, unknown>\n children?: ShaderComponent[]\n}\n\nconst shaderComponentSchema: v.GenericSchema<unknown, ShaderComponent> = v.object({\n type: v.pipe(v.string(), v.nonEmpty(), v.maxLength(100)),\n id: v.optional(v.string()),\n props: v.optional(v.record(v.string(), v.unknown())),\n children: v.optional(v.array(v.lazy(() => shaderComponentSchema)))\n})\n\n/**\n * A shader as the `shaders` library describes it and shaders.com exports it: a tree of effects,\n * drawn first to last.\n */\nexport const shaderPresetSchema = v.object({\n components: v.pipe(v.array(shaderComponentSchema), v.minLength(1)),\n structureVersion: v.optional(v.number())\n})\n\nexport type ShaderPreset = v.InferOutput<typeof shaderPresetSchema>\n\n/**\n * A paint that draws a shader. The paint itself is an image fill of the shader's still frame, so\n * every format and renderer that reads images shows it; this entry says which image it is, the\n * preset that draws it, and the layer size and preset the frame was rendered for, which is\n * missing until it is first rendered.\n */\nexport const shaderPaintSchema = v.object({\n image: v.pipe(v.string(), v.nonEmpty()),\n preset: shaderPresetSchema,\n frame: v.optional(\n v.object({\n width: v.pipe(v.number(), v.finite(), v.minValue(0)),\n height: v.pipe(v.number(), v.finite(), v.minValue(0)),\n /** The preset's key (`shaderPresetKey`) when the frame was rendered. */\n preset: v.pipe(v.string(), v.nonEmpty())\n })\n )\n})\n\nexport type ShaderPaint = v.InferOutput<typeof shaderPaintSchema>\n"],"mappings":";;AAUA,MAAM,wBAAmE,EAAE,OAAO;CAChF,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,GAAG,EAAE,UAAU,GAAG,CAAC;CACvD,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;CACzB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC;CACnD,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,qBAAqB,CAAC,CAAC;AACnE,CAAC;;;;;AAMD,MAAa,qBAAqB,EAAE,OAAO;CACzC,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,GAAG,EAAE,UAAU,CAAC,CAAC;CACjE,kBAAkB,EAAE,SAAS,EAAE,OAAO,CAAC;AACzC,CAAC;;;;;;;AAUD,MAAa,oBAAoB,EAAE,OAAO;CACxC,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;CACtC,QAAQ;CACR,OAAO,EAAE,SACP,EAAE,OAAO;EACP,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;EACnD,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;;EAEpD,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;CACzC,CAAC,CACH;AACF,CAAC"}
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../../src/shaders/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\n/** One effect of a shader preset, as the `shaders` library names it, with the effects it holds. */\nexport interface ShaderComponent {\n type: string\n id?: string\n props?: Record<string, unknown>\n children?: ShaderComponent[]\n}\n\nconst shaderComponentSchema: v.GenericSchema<unknown, ShaderComponent> = v.object({\n type: v.pipe(v.string(), v.nonEmpty(), v.maxLength(100)),\n id: v.optional(v.string()),\n props: v.optional(v.record(v.string(), v.unknown())),\n children: v.optional(v.array(v.lazy(() => shaderComponentSchema)))\n})\n\n/**\n * A shader as the `shaders` library describes it and shaders.com exports it: a tree of effects,\n * drawn first to last.\n */\nexport const shaderPresetSchema = v.object({\n components: v.pipe(v.array(shaderComponentSchema), v.minLength(1)),\n structureVersion: v.optional(v.number())\n})\n\nexport type ShaderPreset = v.InferOutput<typeof shaderPresetSchema>\n\n/**\n * A paint that draws a shader. The paint itself is an image fill of the shader's still frame, so\n * every format and renderer that reads images shows it; this entry says which image it is, the\n * preset that draws it, and the layer size and preset the frame was rendered for, which is\n * missing until it is first rendered.\n */\nexport const shaderPaintSchema = v.object({\n image: v.pipe(v.string(), v.nonEmpty()),\n preset: shaderPresetSchema,\n frame: v.optional(\n v.object({\n width: v.pipe(v.number(), v.finite(), v.minValue(0)),\n height: v.pipe(v.number(), v.finite(), v.minValue(0)),\n /** The preset's key (`stillContentKey`) when the frame was rendered. */\n preset: v.pipe(v.string(), v.nonEmpty())\n })\n )\n})\n\nexport type ShaderPaint = v.InferOutput<typeof shaderPaintSchema>\n"],"mappings":";;AAUA,MAAM,wBAAmE,EAAE,OAAO;CAChF,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,GAAG,EAAE,UAAU,GAAG,CAAC;CACvD,IAAI,EAAE,SAAS,EAAE,OAAO,CAAC;CACzB,OAAO,EAAE,SAAS,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,QAAQ,CAAC,CAAC;CACnD,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,WAAW,qBAAqB,CAAC,CAAC;AACnE,CAAC;;;;;AAMD,MAAa,qBAAqB,EAAE,OAAO;CACzC,YAAY,EAAE,KAAK,EAAE,MAAM,qBAAqB,GAAG,EAAE,UAAU,CAAC,CAAC;CACjE,kBAAkB,EAAE,SAAS,EAAE,OAAO,CAAC;AACzC,CAAC;;;;;;;AAUD,MAAa,oBAAoB,EAAE,OAAO;CACxC,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;CACtC,QAAQ;CACR,OAAO,EAAE,SACP,EAAE,OAAO;EACP,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;EACnD,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC,CAAC;;EAEpD,QAAQ,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,SAAS,CAAC;CACzC,CAAC,CACH;AACF,CAAC"}
@@ -0,0 +1,276 @@
1
+ import { pointAt, subPiece } from "../connectors/pieces.js";
2
+ //#region src/shape-with-text/document.ts
3
+ /**
4
+ * How far above the bottom a document's wave meets its left and right sides, and how far its
5
+ * crest rises, as FigJam draws it at every size. Below FigJam's least height the wave shrinks
6
+ * with the page.
7
+ */
8
+ const WAVE_LEFT = 16;
9
+ const WAVE_RIGHT = 15;
10
+ const WAVE_CREST = 31;
11
+ const LEAST_HEIGHT = 80;
12
+ /** Bezier handle length for a quarter circle. */
13
+ const KAPPA = .5522847498;
14
+ /** Steps that measure a stretch of curve, and halvings that find where a length ends. */
15
+ const LENGTH_STEPS = 32;
16
+ const SEARCH_STEPS = 30;
17
+ const UP = {
18
+ x: 0,
19
+ y: -1
20
+ };
21
+ function piece(from, c1, c2, to) {
22
+ return {
23
+ from,
24
+ to,
25
+ handleFrom: {
26
+ x: c1.x - from.x,
27
+ y: c1.y - from.y
28
+ },
29
+ handleTo: {
30
+ x: c2.x - to.x,
31
+ y: c2.y - to.y
32
+ }
33
+ };
34
+ }
35
+ function reversed(curve) {
36
+ return {
37
+ from: curve.to,
38
+ to: curve.from,
39
+ handleFrom: curve.handleTo,
40
+ handleTo: curve.handleFrom
41
+ };
42
+ }
43
+ /** The bottom wave, right to left: up from the right side to its crest, down to its trough, up to the left side. */
44
+ function wave(w, h) {
45
+ const scale = Math.min(1, h / LEAST_HEIGHT);
46
+ const left = {
47
+ x: 0,
48
+ y: h - WAVE_LEFT * scale
49
+ };
50
+ const trough = {
51
+ x: w * 13 / 48,
52
+ y: h
53
+ };
54
+ const crest = {
55
+ x: w * 17 / 24,
56
+ y: h - WAVE_CREST * scale
57
+ };
58
+ const right = {
59
+ x: w,
60
+ y: h - WAVE_RIGHT * scale
61
+ };
62
+ return [
63
+ piece(right, right, {
64
+ x: w * .854555,
65
+ y: crest.y
66
+ }, crest),
67
+ piece(crest, {
68
+ x: w * .5625,
69
+ y: crest.y
70
+ }, {
71
+ x: w * .413004,
72
+ y: h
73
+ }, trough),
74
+ piece(trough, {
75
+ x: w * 13 / 96,
76
+ y: h
77
+ }, left, left)
78
+ ];
79
+ }
80
+ function unit(v) {
81
+ const length = Math.hypot(v.x, v.y);
82
+ return length > 0 ? {
83
+ x: v.x / length,
84
+ y: v.y / length
85
+ } : {
86
+ x: 0,
87
+ y: 0
88
+ };
89
+ }
90
+ /** The direction a curve leaves its start in, past handles of no length. */
91
+ function leaving(curve) {
92
+ const { from, to, handleFrom, handleTo } = curve;
93
+ const c1 = {
94
+ x: from.x + handleFrom.x,
95
+ y: from.y + handleFrom.y
96
+ };
97
+ const c2 = {
98
+ x: to.x + handleTo.x,
99
+ y: to.y + handleTo.y
100
+ };
101
+ for (const point of [
102
+ c1,
103
+ c2,
104
+ to
105
+ ]) {
106
+ const direction = unit({
107
+ x: point.x - from.x,
108
+ y: point.y - from.y
109
+ });
110
+ if (direction.x !== 0 || direction.y !== 0) return direction;
111
+ }
112
+ return {
113
+ x: 0,
114
+ y: 0
115
+ };
116
+ }
117
+ /** The length of a curve from its start to `t`. */
118
+ function lengthTo(curve, t) {
119
+ let length = 0;
120
+ let last = curve.from;
121
+ for (let step = 1; step <= LENGTH_STEPS; step++) {
122
+ const point = pointAt(curve, t * step / LENGTH_STEPS);
123
+ length += Math.hypot(point.x - last.x, point.y - last.y);
124
+ last = point;
125
+ }
126
+ return length;
127
+ }
128
+ /** The parameter at `distance` along a curve from its start, by its length. */
129
+ function parameterAt(curve, distance) {
130
+ let low = 0;
131
+ let high = 1;
132
+ for (let step = 0; step < SEARCH_STEPS; step++) {
133
+ const middle = (low + high) / 2;
134
+ if (lengthTo(curve, middle) < distance) low = middle;
135
+ else high = middle;
136
+ }
137
+ return (low + high) / 2;
138
+ }
139
+ /**
140
+ * How far a corner of `radius` trims each side of a vertex whose sides leave it along `a` and
141
+ * `b`, and how long its handles are. FigJam fits a circle to a blunt corner; a sharp one it trims
142
+ * by the radius alone, with a quarter circle's handles.
143
+ */
144
+ function corner(a, b, radius) {
145
+ const angle = Math.acos(Math.max(-1, Math.min(1, a.x * b.x + a.y * b.y)));
146
+ if (angle <= Math.PI / 2) return {
147
+ trim: radius,
148
+ handle: radius * KAPPA
149
+ };
150
+ return {
151
+ trim: radius / Math.tan(angle / 2),
152
+ handle: 4 / 3 * Math.tan((Math.PI - angle) / 4) * radius
153
+ };
154
+ }
155
+ function curveTo(c1, c2, to) {
156
+ return {
157
+ type: "C",
158
+ x1: c1.x,
159
+ y1: c1.y,
160
+ x2: c2.x,
161
+ y2: c2.y,
162
+ x: to.x,
163
+ y: to.y
164
+ };
165
+ }
166
+ function pieceTo(curve) {
167
+ const { from, to, handleFrom, handleTo } = curve;
168
+ return curveTo({
169
+ x: from.x + handleFrom.x,
170
+ y: from.y + handleFrom.y
171
+ }, {
172
+ x: to.x + handleTo.x,
173
+ y: to.y + handleTo.y
174
+ }, to);
175
+ }
176
+ /**
177
+ * A single document as FigJam draws it: a page whose bottom is a wave of fixed height, every
178
+ * corner rounded to `radius`, those where the wave meets the sides included.
179
+ */
180
+ function documentOutline(w, h, radius) {
181
+ const [fromRight, middle, toLeft] = wave(w, h);
182
+ const r = Math.max(0, Math.min(radius, w / 2, h / 2));
183
+ const k = r * .4477152502;
184
+ const rightSide = fromRight.from;
185
+ const leftSide = toLeft.to;
186
+ const intoLeft = reversed(toLeft);
187
+ const right = corner(UP, leaving(fromRight), r);
188
+ const left = corner(UP, leaving(intoLeft), r);
189
+ const rightTrim = Math.min(right.trim, (rightSide.y - r) / 2);
190
+ const leftTrim = Math.min(left.trim, (leftSide.y - r) / 2);
191
+ const rightHandle = right.trim > 0 ? right.handle * rightTrim / right.trim : 0;
192
+ const leftHandle = left.trim > 0 ? left.handle * leftTrim / left.trim : 0;
193
+ const first = r > 0 ? subPiece(fromRight, parameterAt(fromRight, rightTrim), 1) : fromRight;
194
+ const last = r > 0 ? subPiece(toLeft, 0, 1 - parameterAt(intoLeft, leftTrim)) : toLeft;
195
+ const rightEnd = {
196
+ x: w,
197
+ y: rightSide.y - rightTrim
198
+ };
199
+ const leftEnd = {
200
+ x: 0,
201
+ y: leftSide.y - leftTrim
202
+ };
203
+ const commands = [
204
+ {
205
+ type: "M",
206
+ x: r,
207
+ y: 0
208
+ },
209
+ {
210
+ type: "L",
211
+ x: w - r,
212
+ y: 0
213
+ },
214
+ curveTo({
215
+ x: w - k,
216
+ y: 0
217
+ }, {
218
+ x: w,
219
+ y: k
220
+ }, {
221
+ x: w,
222
+ y: r
223
+ }),
224
+ {
225
+ type: "L",
226
+ x: rightEnd.x,
227
+ y: rightEnd.y
228
+ }
229
+ ];
230
+ if (r > 0) {
231
+ const back = unit({
232
+ x: -first.handleFrom.x,
233
+ y: -first.handleFrom.y
234
+ });
235
+ commands.push(curveTo({
236
+ x: w,
237
+ y: rightEnd.y + rightHandle
238
+ }, {
239
+ x: first.from.x + back.x * rightHandle,
240
+ y: first.from.y + back.y * rightHandle
241
+ }, first.from));
242
+ }
243
+ commands.push(pieceTo(first), pieceTo(middle), pieceTo(last));
244
+ if (r > 0) {
245
+ const on = unit({
246
+ x: -last.handleTo.x,
247
+ y: -last.handleTo.y
248
+ });
249
+ commands.push(curveTo({
250
+ x: last.to.x + on.x * leftHandle,
251
+ y: last.to.y + on.y * leftHandle
252
+ }, {
253
+ x: 0,
254
+ y: leftEnd.y + leftHandle
255
+ }, leftEnd));
256
+ }
257
+ commands.push({
258
+ type: "L",
259
+ x: 0,
260
+ y: r
261
+ }, curveTo({
262
+ x: 0,
263
+ y: k
264
+ }, {
265
+ x: k,
266
+ y: 0
267
+ }, {
268
+ x: r,
269
+ y: 0
270
+ }), { type: "Z" });
271
+ return commands;
272
+ }
273
+ //#endregion
274
+ export { documentOutline };
275
+
276
+ //# sourceMappingURL=document.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"document.js","names":[],"sources":["../../src/shape-with-text/document.ts"],"sourcesContent":["import { pointAt, subPiece, type ConnectorPiece } from '../connectors/pieces'\nimport type { PolygonOutlineCommand } from '../polygon'\nimport type { Vector } from '../primitives'\n\n/**\n * How far above the bottom a document's wave meets its left and right sides, and how far its\n * crest rises, as FigJam draws it at every size. Below FigJam's least height the wave shrinks\n * with the page.\n */\nconst WAVE_LEFT = 16\nconst WAVE_RIGHT = 15\nconst WAVE_CREST = 31\nconst LEAST_HEIGHT = 80\n/** Bezier handle length for a quarter circle. */\nconst KAPPA = 0.5522847498\n/** Steps that measure a stretch of curve, and halvings that find where a length ends. */\nconst LENGTH_STEPS = 32\nconst SEARCH_STEPS = 30\nconst UP: Vector = { x: 0, y: -1 }\n\nfunction piece(from: Vector, c1: Vector, c2: Vector, to: Vector): ConnectorPiece {\n return {\n from,\n to,\n handleFrom: { x: c1.x - from.x, y: c1.y - from.y },\n handleTo: { x: c2.x - to.x, y: c2.y - to.y }\n }\n}\n\nfunction reversed(curve: ConnectorPiece): ConnectorPiece {\n return { from: curve.to, to: curve.from, handleFrom: curve.handleTo, handleTo: curve.handleFrom }\n}\n\n/** The bottom wave, right to left: up from the right side to its crest, down to its trough, up to the left side. */\nfunction wave(w: number, h: number): ConnectorPiece[] {\n const scale = Math.min(1, h / LEAST_HEIGHT)\n const left = { x: 0, y: h - WAVE_LEFT * scale }\n const trough = { x: (w * 13) / 48, y: h }\n const crest = { x: (w * 17) / 24, y: h - WAVE_CREST * scale }\n const right = { x: w, y: h - WAVE_RIGHT * scale }\n return [\n piece(right, right, { x: w * 0.854555, y: crest.y }, crest),\n piece(crest, { x: w * 0.5625, y: crest.y }, { x: w * 0.413004, y: h }, trough),\n piece(trough, { x: (w * 13) / 96, y: h }, left, left)\n ]\n}\n\nfunction unit(v: Vector): Vector {\n const length = Math.hypot(v.x, v.y)\n return length > 0 ? { x: v.x / length, y: v.y / length } : { x: 0, y: 0 }\n}\n\n/** The direction a curve leaves its start in, past handles of no length. */\nfunction leaving(curve: ConnectorPiece): Vector {\n const { from, to, handleFrom, handleTo } = curve\n const c1 = { x: from.x + handleFrom.x, y: from.y + handleFrom.y }\n const c2 = { x: to.x + handleTo.x, y: to.y + handleTo.y }\n for (const point of [c1, c2, to]) {\n const direction = unit({ x: point.x - from.x, y: point.y - from.y })\n if (direction.x !== 0 || direction.y !== 0) return direction\n }\n return { x: 0, y: 0 }\n}\n\n/** The length of a curve from its start to `t`. */\nfunction lengthTo(curve: ConnectorPiece, t: number): number {\n let length = 0\n let last = curve.from\n for (let step = 1; step <= LENGTH_STEPS; step++) {\n const point = pointAt(curve, (t * step) / LENGTH_STEPS)\n length += Math.hypot(point.x - last.x, point.y - last.y)\n last = point\n }\n return length\n}\n\n/** The parameter at `distance` along a curve from its start, by its length. */\nfunction parameterAt(curve: ConnectorPiece, distance: number): number {\n let low = 0\n let high = 1\n for (let step = 0; step < SEARCH_STEPS; step++) {\n const middle = (low + high) / 2\n if (lengthTo(curve, middle) < distance) low = middle\n else high = middle\n }\n return (low + high) / 2\n}\n\n/**\n * How far a corner of `radius` trims each side of a vertex whose sides leave it along `a` and\n * `b`, and how long its handles are. FigJam fits a circle to a blunt corner; a sharp one it trims\n * by the radius alone, with a quarter circle's handles.\n */\nfunction corner(a: Vector, b: Vector, radius: number): { trim: number; handle: number } {\n const angle = Math.acos(Math.max(-1, Math.min(1, a.x * b.x + a.y * b.y)))\n if (angle <= Math.PI / 2) return { trim: radius, handle: radius * KAPPA }\n return {\n trim: radius / Math.tan(angle / 2),\n handle: (4 / 3) * Math.tan((Math.PI - angle) / 4) * radius\n }\n}\n\nfunction curveTo(c1: Vector, c2: Vector, to: Vector): PolygonOutlineCommand {\n return { type: 'C', x1: c1.x, y1: c1.y, x2: c2.x, y2: c2.y, x: to.x, y: to.y }\n}\n\nfunction pieceTo(curve: ConnectorPiece): PolygonOutlineCommand {\n const { from, to, handleFrom, handleTo } = curve\n return curveTo(\n { x: from.x + handleFrom.x, y: from.y + handleFrom.y },\n { x: to.x + handleTo.x, y: to.y + handleTo.y },\n to\n )\n}\n\n/**\n * A single document as FigJam draws it: a page whose bottom is a wave of fixed height, every\n * corner rounded to `radius`, those where the wave meets the sides included.\n */\nexport function documentOutline(w: number, h: number, radius: number): PolygonOutlineCommand[] {\n const [fromRight, middle, toLeft] = wave(w, h)\n const r = Math.max(0, Math.min(radius, w / 2, h / 2))\n const k = r * (1 - KAPPA)\n const rightSide = fromRight.from\n const leftSide = toLeft.to\n const intoLeft = reversed(toLeft)\n\n // Each bottom corner trims the side and the wave by the same length, the side no further than\n // its top corner.\n const right = corner(UP, leaving(fromRight), r)\n const left = corner(UP, leaving(intoLeft), r)\n const rightTrim = Math.min(right.trim, (rightSide.y - r) / 2)\n const leftTrim = Math.min(left.trim, (leftSide.y - r) / 2)\n // A corner trimmed short of its radius shortens its handles with it.\n const rightHandle = right.trim > 0 ? (right.handle * rightTrim) / right.trim : 0\n const leftHandle = left.trim > 0 ? (left.handle * leftTrim) / left.trim : 0\n const first = r > 0 ? subPiece(fromRight, parameterAt(fromRight, rightTrim), 1) : fromRight\n const last = r > 0 ? subPiece(toLeft, 0, 1 - parameterAt(intoLeft, leftTrim)) : toLeft\n const rightEnd = { x: w, y: rightSide.y - rightTrim }\n const leftEnd = { x: 0, y: leftSide.y - leftTrim }\n\n const commands: PolygonOutlineCommand[] = [\n { type: 'M', x: r, y: 0 },\n { type: 'L', x: w - r, y: 0 },\n curveTo({ x: w - k, y: 0 }, { x: w, y: k }, { x: w, y: r }),\n { type: 'L', x: rightEnd.x, y: rightEnd.y }\n ]\n if (r > 0) {\n const back = unit({ x: -first.handleFrom.x, y: -first.handleFrom.y })\n commands.push(\n curveTo(\n { x: w, y: rightEnd.y + rightHandle },\n { x: first.from.x + back.x * rightHandle, y: first.from.y + back.y * rightHandle },\n first.from\n )\n )\n }\n commands.push(pieceTo(first), pieceTo(middle), pieceTo(last))\n if (r > 0) {\n const on = unit({ x: -last.handleTo.x, y: -last.handleTo.y })\n commands.push(\n curveTo(\n { x: last.to.x + on.x * leftHandle, y: last.to.y + on.y * leftHandle },\n { x: 0, y: leftEnd.y + leftHandle },\n leftEnd\n )\n )\n }\n commands.push(\n { type: 'L', x: 0, y: r },\n curveTo({ x: 0, y: k }, { x: k, y: 0 }, { x: r, y: 0 }),\n { type: 'Z' }\n )\n return commands\n}\n"],"mappings":";;;;;;;AASA,MAAM,YAAY;AAClB,MAAM,aAAa;AACnB,MAAM,aAAa;AACnB,MAAM,eAAe;;AAErB,MAAM,QAAQ;;AAEd,MAAM,eAAe;AACrB,MAAM,eAAe;AACrB,MAAM,KAAa;CAAE,GAAG;CAAG,GAAG;AAAG;AAEjC,SAAS,MAAM,MAAc,IAAY,IAAY,IAA4B;CAC/E,OAAO;EACL;EACA;EACA,YAAY;GAAE,GAAG,GAAG,IAAI,K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EAAK,GAAG;EAAG,GAAG;CAAE,GACxB,QAAQ;EAAE,GAAG;EAAG,GAAG;CAAE,GAAG;EAAE,GAAG;EAAG,GAAG;CAAE,GAAG;EAAE,GAAG;EAAG,GAAG;CAAE,CAAC,GACtD,EAAE,MAAM,IAAI,CACd;CACA,OAAO;AACT"}
@@ -1,4 +1,5 @@
1
1
  import { ShapeWithTextType } from "./kinds.js";
2
+ import { SceneNode } from "../types.js";
2
3
  import { PolygonOutlineCommand } from "../polygon.js";
3
4
  //#region src/shape-with-text/geometry.d.ts
4
5
  interface ShapeWithTextGeometry {
@@ -7,6 +8,11 @@ interface ShapeWithTextGeometry {
7
8
  /** Inner lines that are stroked only, such as a database's front rim. */
8
9
  details: PolygonOutlineCommand[];
9
10
  }
11
+ /**
12
+ * The band FigJam cuts out of a shape's fill along its outline and inner lines when no stroke
13
+ * draws them, so a database still shows its rim: half of it insets the outline.
14
+ */
15
+ declare const SHAPE_WITH_TEXT_LINE_GAP = 3;
10
16
  /** How far a parallelogram's sides lean: FigJam leans them with the height, not the width. */
11
17
  declare function parallelogramSlant(w: number, h: number): number;
12
18
  /**
@@ -15,6 +21,12 @@ declare function parallelogramSlant(w: number, h: number): number;
15
21
  * curves, such as a rounded rectangle, keep their own shape.
16
22
  */
17
23
  declare function shapeWithTextGeometry(type: ShapeWithTextType, width: number, height: number, cornerRadius?: number): ShapeWithTextGeometry;
24
+ /**
25
+ * Whether the shape's fill has its outline and inner lines cut out of it, as FigJam draws a shape
26
+ * with inner lines, such as a database, when no stroke draws them: it has inner lines and no
27
+ * visible stroke.
28
+ */
29
+ declare function shapeWithTextCutsFill(node: Pick<SceneNode, 'type' | 'shapeWithTextType' | 'width' | 'height' | 'strokes'>): boolean;
18
30
  //#endregion
19
- export { ShapeWithTextGeometry, parallelogramSlant, shapeWithTextGeometry };
31
+ export { SHAPE_WITH_TEXT_LINE_GAP, ShapeWithTextGeometry, parallelogramSlant, shapeWithTextCutsFill, shapeWithTextGeometry };
20
32
  //# sourceMappingURL=geometry.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"geometry.d.ts","names":[],"sources":["../../src/shape-with-text/geometry.ts"],"mappings":";;;UAIiB;;EAEf,SAAS;;EAET,SAAS;;;iBAqIK,mBAAmB,WAAW;;;;;;iBAwV9B,sBACd,MAAM,mBACN,eACA,gBACA,wBACC"}
1
+ {"version":3,"file":"geometry.d.ts","names":[],"sources":["../../src/shape-with-text/geometry.ts"],"mappings":";;;;UAOiB;;EAEf,SAAS;;EAET,SAAS;;;;;;cAUE;;iBAyIG,mBAAmB,WAAW;;;;;;iBAmY9B,sBACd,MAAM,mBACN,eACA,gBACA,wBACC;;;;;;iBAYa,sBACd,MAAM,KAAK"}
@@ -1,7 +1,21 @@
1
+ import { drawsStroke } from "../geometry.js";
1
2
  import { databaseCap } from "./fit.js";
3
+ import { documentOutline } from "./document.js";
2
4
  //#region src/shape-with-text/geometry.ts
3
5
  /** Bezier handle length for a quarter ellipse. */
4
6
  const KAPPA = .5522847498;
7
+ /**
8
+ * The band FigJam cuts out of a shape's fill along its outline and inner lines when no stroke
9
+ * draws them, so a database still shows its rim: half of it insets the outline.
10
+ */
11
+ const SHAPE_WITH_TEXT_LINE_GAP = 3;
12
+ /** A folder's tab: its height, and how far its base reaches past the middle of the box. */
13
+ const FOLDER_TAB_HEIGHT = 44;
14
+ const FOLDER_TAB_OVERHANG = 13;
15
+ /** How far the tab's sides lean in over its full height. */
16
+ const FOLDER_TAB_SLANT = 18;
17
+ /** How far a multiple document's front page sits right of and below its back page. */
18
+ const DOCUMENT_OFFSET = 16;
5
19
  function polygon(points) {
6
20
  const commands = points.map(([x, y], index) => ({
7
21
  type: index === 0 ? "M" : "L",
@@ -306,16 +320,30 @@ const BUILDERS = {
306
320
  }]
307
321
  };
308
322
  },
309
- ENG_FOLDER: (w, h) => {
310
- const tab = Math.min(h * .18, w * .2);
311
- return plain(polygon([
312
- [0, 0],
313
- [w * .4, 0],
314
- [w * .4 + tab, tab],
315
- [w, tab],
316
- [w, h],
317
- [0, h]
318
- ]));
323
+ ENG_FOLDER: (w, h, _min, radius) => {
324
+ const tab = Math.min(FOLDER_TAB_HEIGHT, h);
325
+ const base = Math.min(w / 2 + FOLDER_TAB_OVERHANG, w);
326
+ const slant = Math.min(FOLDER_TAB_SLANT * tab / FOLDER_TAB_HEIGHT, base / 2);
327
+ return {
328
+ outline: roundedPolygon([
329
+ [0, h],
330
+ [0, tab],
331
+ [slant, 0],
332
+ [base - slant, 0],
333
+ [base, tab],
334
+ [w, tab],
335
+ [w, h]
336
+ ], [
337
+ radius,
338
+ 0,
339
+ radius,
340
+ radius,
341
+ 0,
342
+ radius,
343
+ radius
344
+ ]),
345
+ details: line([0, tab], [base, tab])
346
+ };
319
347
  },
320
348
  TRAPEZOID: (w, h) => {
321
349
  const s = Math.min(w * .2, h);
@@ -350,35 +378,43 @@ const BUILDERS = {
350
378
  curve(w * .25, h * .9, 0, h * .75, 0, h * .45),
351
379
  { type: "Z" }
352
380
  ]),
353
- DOCUMENT_SINGLE: (w, h) => plain(documentPage(0, 0, w, h)),
354
- DOCUMENT_MULTIPLE: (w, h, min) => {
355
- const o = min * .06;
381
+ DOCUMENT_SINGLE: (w, h, _min, radius) => plain(documentOutline(w, h, radius)),
382
+ DOCUMENT_MULTIPLE: (w, h, _min, radius) => {
383
+ const o = Math.min(DOCUMENT_OFFSET, w / 4, h / 4);
384
+ const wave = documentPage(o, o, w - o, h - o).filter((command) => command.type === "C");
385
+ const base = wave.at(-1)?.y ?? h;
386
+ const join = Math.min(h - 2 * o, base);
387
+ const outline = roundedPolygon([
388
+ [0, 0],
389
+ [w - o, 0],
390
+ [w - o, o],
391
+ [w, o],
392
+ [w, base],
393
+ [o, base],
394
+ [o, join],
395
+ [0, join - o / 4]
396
+ ], [
397
+ radius,
398
+ radius,
399
+ 0,
400
+ radius,
401
+ 0,
402
+ 0,
403
+ 0,
404
+ radius
405
+ ]);
406
+ const bottom = outline.findIndex((command) => command.type === "L" && command.x === o && command.y === base);
356
407
  return {
357
- outline: documentPage(0, o * 2, w - o * 2, h - o * 2),
358
- details: [
359
- ...line([o, o * 2], [o, o]),
360
- {
361
- type: "L",
362
- x: w - o,
363
- y: o
364
- },
365
- {
366
- type: "L",
367
- x: w - o,
368
- y: h - o * 2
369
- },
370
- ...line([o * 2, o], [o * 2, 0]),
371
- {
372
- type: "L",
373
- x: w,
374
- y: 0
375
- },
376
- {
377
- type: "L",
378
- x: w,
379
- y: h - o * 3
380
- }
381
- ]
408
+ outline: [
409
+ ...outline.slice(0, bottom),
410
+ ...wave,
411
+ ...outline.slice(bottom + 1)
412
+ ],
413
+ details: [...line([w - o, o], [o, o]), {
414
+ type: "L",
415
+ x: o,
416
+ y: join
417
+ }]
382
418
  };
383
419
  },
384
420
  MANUAL_INPUT: (w, h) => plain(polygon([
@@ -498,8 +534,25 @@ function roundCorners(commands, radius) {
498
534
  const points = [];
499
535
  for (const command of commands) if (command.type !== "Z") points.push([command.x, command.y]);
500
536
  if (points.length < 3) return commands;
537
+ return roundedPolygon(points, points.map(() => radius));
538
+ }
539
+ /**
540
+ * The closed polygon through `points` with the corner at each rounded to its own radius in
541
+ * `radii`, shortened where an edge is too short for it; a corner with radius 0 stays sharp.
542
+ */
543
+ function roundedPolygon(points, radii) {
501
544
  const rounded = [];
502
545
  points.forEach((vertex, index) => {
546
+ const radius = radii[index] ?? 0;
547
+ const type = index === 0 ? "M" : "L";
548
+ if (radius <= 0) {
549
+ rounded.push({
550
+ type,
551
+ x: vertex[0],
552
+ y: vertex[1]
553
+ });
554
+ return;
555
+ }
503
556
  const before = points[(index + points.length - 1) % points.length];
504
557
  const after = points[(index + 1) % points.length];
505
558
  const toward = (to) => {
@@ -510,7 +563,7 @@ function roundCorners(commands, radius) {
510
563
  const [inX, inY] = toward(before);
511
564
  const [outX, outY] = toward(after);
512
565
  rounded.push({
513
- type: index === 0 ? "M" : "L",
566
+ type,
514
567
  x: inX,
515
568
  y: inY
516
569
  });
@@ -527,13 +580,22 @@ function roundCorners(commands, radius) {
527
580
  function shapeWithTextGeometry(type, width, height, cornerRadius = 0) {
528
581
  const w = Math.max(0, width);
529
582
  const h = Math.max(0, height);
530
- const geometry = BUILDERS[type](w, h, Math.min(w, h));
583
+ const geometry = BUILDERS[type](w, h, Math.min(w, h), cornerRadius);
531
584
  return {
532
585
  ...geometry,
533
586
  outline: roundCorners(geometry.outline, cornerRadius)
534
587
  };
535
588
  }
589
+ /**
590
+ * Whether the shape's fill has its outline and inner lines cut out of it, as FigJam draws a shape
591
+ * with inner lines, such as a database, when no stroke draws them: it has inner lines and no
592
+ * visible stroke.
593
+ */
594
+ function shapeWithTextCutsFill(node) {
595
+ if (node.strokes.some((stroke) => stroke.opacity > 0 && drawsStroke(node, stroke))) return false;
596
+ return shapeWithTextGeometry(node.shapeWithTextType, node.width, node.height).details.length > 0;
597
+ }
536
598
  //#endregion
537
- export { parallelogramSlant, shapeWithTextGeometry };
599
+ export { SHAPE_WITH_TEXT_LINE_GAP, parallelogramSlant, shapeWithTextCutsFill, shapeWithTextGeometry };
538
600
 
539
601
  //# sourceMappingURL=geometry.js.map