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

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 (390) hide show
  1. package/dist/arrow-caps.d.ts.map +1 -1
  2. package/dist/arrow-caps.js +2 -5
  3. package/dist/arrow-caps.js.map +1 -1
  4. package/dist/asset-keys.d.ts +11 -1
  5. package/dist/asset-keys.d.ts.map +1 -1
  6. package/dist/asset-keys.js +16 -1
  7. package/dist/asset-keys.js.map +1 -1
  8. package/dist/behaviours/index.d.ts +2 -2
  9. package/dist/behaviours/index.js +2 -2
  10. package/dist/behaviours/kinds.d.ts +11 -5
  11. package/dist/behaviours/kinds.d.ts.map +1 -1
  12. package/dist/behaviours/kinds.js +76 -75
  13. package/dist/behaviours/kinds.js.map +1 -1
  14. package/dist/behaviours/layers.d.ts.map +1 -1
  15. package/dist/behaviours/layers.js +3 -2
  16. package/dist/behaviours/layers.js.map +1 -1
  17. package/dist/behaviours/model.d.ts +7 -4
  18. package/dist/behaviours/model.d.ts.map +1 -1
  19. package/dist/behaviours/model.js +16 -9
  20. package/dist/behaviours/model.js.map +1 -1
  21. package/dist/behaviours/schema.d.ts +118 -4
  22. package/dist/behaviours/schema.d.ts.map +1 -1
  23. package/dist/behaviours/schema.js +18 -3
  24. package/dist/behaviours/schema.js.map +1 -1
  25. package/dist/behaviours/spec.d.ts.map +1 -1
  26. package/dist/behaviours/spec.js +3 -2
  27. package/dist/behaviours/spec.js.map +1 -1
  28. package/dist/bindings.js +9 -1
  29. package/dist/bindings.js.map +1 -1
  30. package/dist/checkpoint.d.ts +31 -2
  31. package/dist/checkpoint.d.ts.map +1 -1
  32. package/dist/checkpoint.js +211 -10
  33. package/dist/checkpoint.js.map +1 -1
  34. package/dist/components/index.d.ts +3 -3
  35. package/dist/components/index.js +3 -3
  36. package/dist/components/properties.d.ts +18 -1
  37. package/dist/components/properties.d.ts.map +1 -1
  38. package/dist/components/properties.js +66 -3
  39. package/dist/components/properties.js.map +1 -1
  40. package/dist/components/variants.d.ts +16 -10
  41. package/dist/components/variants.d.ts.map +1 -1
  42. package/dist/components/variants.js +39 -13
  43. package/dist/components/variants.js.map +1 -1
  44. package/dist/connectors/hit.d.ts.map +1 -1
  45. package/dist/connectors/hit.js +1 -7
  46. package/dist/connectors/hit.js.map +1 -1
  47. package/dist/connectors/pieces.d.ts.map +1 -1
  48. package/dist/connectors/pieces.js +2 -5
  49. package/dist/connectors/pieces.js.map +1 -1
  50. package/dist/constants.d.ts +6 -1
  51. package/dist/constants.d.ts.map +1 -1
  52. package/dist/constants.js +17 -1
  53. package/dist/constants.js.map +1 -1
  54. package/dist/constraints.d.ts +25 -0
  55. package/dist/constraints.d.ts.map +1 -0
  56. package/dist/constraints.js +51 -0
  57. package/dist/constraints.js.map +1 -0
  58. package/dist/coordinate.d.ts +64 -1
  59. package/dist/coordinate.d.ts.map +1 -1
  60. package/dist/coordinate.js +217 -1
  61. package/dist/coordinate.js.map +1 -1
  62. package/dist/copy.d.ts.map +1 -1
  63. package/dist/copy.js +17 -16
  64. package/dist/copy.js.map +1 -1
  65. package/dist/css/blend.d.ts +11 -0
  66. package/dist/css/blend.d.ts.map +1 -0
  67. package/dist/css/blend.js +30 -0
  68. package/dist/css/blend.js.map +1 -0
  69. package/dist/css/index.d.ts +4 -2
  70. package/dist/css/index.js +4 -2
  71. package/dist/css/text.d.ts +28 -1
  72. package/dist/css/text.d.ts.map +1 -1
  73. package/dist/css/text.js +84 -17
  74. package/dist/css/text.js.map +1 -1
  75. package/dist/css/transform.d.ts +34 -0
  76. package/dist/css/transform.d.ts.map +1 -0
  77. package/dist/css/transform.js +320 -0
  78. package/dist/css/transform.js.map +1 -0
  79. package/dist/css/values.d.ts.map +1 -1
  80. package/dist/css/values.js +11 -1
  81. package/dist/css/values.js.map +1 -1
  82. package/dist/cubic.d.ts +7 -0
  83. package/dist/cubic.d.ts.map +1 -0
  84. package/dist/cubic.js +17 -0
  85. package/dist/cubic.js.map +1 -0
  86. package/dist/export-format.d.ts +14 -1
  87. package/dist/export-format.d.ts.map +1 -1
  88. package/dist/export-format.js +26 -1
  89. package/dist/export-format.js.map +1 -1
  90. package/dist/fields/text.d.ts +2 -2
  91. package/dist/fields/text.d.ts.map +1 -1
  92. package/dist/fields/text.js +2 -1
  93. package/dist/fields/text.js.map +1 -1
  94. package/dist/figjam/index.d.ts +2 -2
  95. package/dist/figjam/index.js +2 -2
  96. package/dist/figjam/palette.d.ts +13 -2
  97. package/dist/figjam/palette.d.ts.map +1 -1
  98. package/dist/figjam/palette.js +30 -2
  99. package/dist/figjam/palette.js.map +1 -1
  100. package/dist/generated/index.d.ts +2 -2
  101. package/dist/generated/index.js +2 -2
  102. package/dist/generated/shape-with-text.d.ts +7 -2
  103. package/dist/generated/shape-with-text.d.ts.map +1 -1
  104. package/dist/generated/shape-with-text.js +20 -3
  105. package/dist/generated/shape-with-text.js.map +1 -1
  106. package/dist/geometry.d.ts +37 -46
  107. package/dist/geometry.d.ts.map +1 -1
  108. package/dist/geometry.js +80 -137
  109. package/dist/geometry.js.map +1 -1
  110. package/dist/graph.d.ts +49 -12
  111. package/dist/graph.d.ts.map +1 -1
  112. package/dist/graph.js +125 -27
  113. package/dist/graph.js.map +1 -1
  114. package/dist/group-bounds.d.ts +14 -4
  115. package/dist/group-bounds.d.ts.map +1 -1
  116. package/dist/group-bounds.js +76 -11
  117. package/dist/group-bounds.js.map +1 -1
  118. package/dist/guides.d.ts +3 -1
  119. package/dist/guides.d.ts.map +1 -1
  120. package/dist/guides.js +5 -1
  121. package/dist/guides.js.map +1 -1
  122. package/dist/hit-test.d.ts +5 -0
  123. package/dist/hit-test.d.ts.map +1 -1
  124. package/dist/hit-test.js +57 -38
  125. package/dist/hit-test.js.map +1 -1
  126. package/dist/images.d.ts +27 -3
  127. package/dist/images.d.ts.map +1 -1
  128. package/dist/images.js +57 -3
  129. package/dist/images.js.map +1 -1
  130. package/dist/index.d.ts +2 -2
  131. package/dist/instances/fields.d.ts +2 -2
  132. package/dist/instances/fields.d.ts.map +1 -1
  133. package/dist/instances/fields.js +8 -0
  134. package/dist/instances/fields.js.map +1 -1
  135. package/dist/instances/index.d.ts +1 -3
  136. package/dist/instances/index.d.ts.map +1 -1
  137. package/dist/instances/index.js +39 -30
  138. package/dist/instances/index.js.map +1 -1
  139. package/dist/instances/kept-overrides.js +204 -0
  140. package/dist/instances/kept-overrides.js.map +1 -0
  141. package/dist/instances/main-component.d.ts +3 -1
  142. package/dist/instances/main-component.d.ts.map +1 -1
  143. package/dist/instances/main-component.js +10 -2
  144. package/dist/instances/main-component.js.map +1 -1
  145. package/dist/instances/overrides.d.ts +4 -1
  146. package/dist/instances/overrides.d.ts.map +1 -1
  147. package/dist/instances/overrides.js +18 -2
  148. package/dist/instances/overrides.js.map +1 -1
  149. package/dist/instances/placement.js +55 -12
  150. package/dist/instances/placement.js.map +1 -1
  151. package/dist/instances/swap.js +291 -0
  152. package/dist/instances/swap.js.map +1 -0
  153. package/dist/instances/sync.js +112 -39
  154. package/dist/instances/sync.js.map +1 -1
  155. package/dist/node-defaults.d.ts.map +1 -1
  156. package/dist/node-defaults.js +2 -1
  157. package/dist/node-defaults.js.map +1 -1
  158. package/dist/order-keys.d.ts +3 -1
  159. package/dist/order-keys.d.ts.map +1 -1
  160. package/dist/order-keys.js +6 -1
  161. package/dist/order-keys.js.map +1 -1
  162. package/dist/outline/flatten.d.ts +15 -0
  163. package/dist/outline/flatten.d.ts.map +1 -0
  164. package/dist/outline/flatten.js +189 -0
  165. package/dist/outline/flatten.js.map +1 -0
  166. package/dist/outline/heads.js +34 -0
  167. package/dist/outline/heads.js.map +1 -0
  168. package/dist/outline/hit.d.ts +21 -0
  169. package/dist/outline/hit.d.ts.map +1 -0
  170. package/dist/outline/hit.js +276 -0
  171. package/dist/outline/hit.js.map +1 -0
  172. package/dist/outline/index.d.ts +5 -0
  173. package/dist/outline/index.js +5 -0
  174. package/dist/outline/point.d.ts +16 -0
  175. package/dist/outline/point.d.ts.map +1 -0
  176. package/dist/outline/point.js +42 -0
  177. package/dist/outline/point.js.map +1 -0
  178. package/dist/outline/shapes.d.ts +35 -0
  179. package/dist/outline/shapes.d.ts.map +1 -0
  180. package/dist/outline/shapes.js +181 -0
  181. package/dist/outline/shapes.js.map +1 -0
  182. package/dist/plugin-data/fields.d.ts +4 -1
  183. package/dist/plugin-data/fields.d.ts.map +1 -1
  184. package/dist/plugin-data/fields.js +21 -4
  185. package/dist/plugin-data/fields.js.map +1 -1
  186. package/dist/resize.d.ts +22 -11
  187. package/dist/resize.d.ts.map +1 -1
  188. package/dist/resize.js +227 -93
  189. package/dist/resize.js.map +1 -1
  190. package/dist/scaling/index.d.ts +3 -2
  191. package/dist/scaling/index.js +3 -2
  192. package/dist/scaling/node.d.ts.map +1 -1
  193. package/dist/scaling/node.js +5 -1
  194. package/dist/scaling/node.js.map +1 -1
  195. package/dist/scaling/snapshot.d.ts +25 -0
  196. package/dist/scaling/snapshot.d.ts.map +1 -0
  197. package/dist/scaling/snapshot.js +39 -0
  198. package/dist/scaling/snapshot.js.map +1 -0
  199. package/dist/scaling/tree.d.ts +24 -2
  200. package/dist/scaling/tree.d.ts.map +1 -1
  201. package/dist/scaling/tree.js +38 -15
  202. package/dist/scaling/tree.js.map +1 -1
  203. package/dist/shaders/model.d.ts.map +1 -1
  204. package/dist/shaders/model.js +2 -1
  205. package/dist/shaders/model.js.map +1 -1
  206. package/dist/shared-styles.d.ts +16 -1
  207. package/dist/shared-styles.d.ts.map +1 -1
  208. package/dist/shared-styles.js +69 -2
  209. package/dist/shared-styles.js.map +1 -1
  210. package/dist/slots/authoring.d.ts +3 -2
  211. package/dist/slots/authoring.d.ts.map +1 -1
  212. package/dist/slots/authoring.js +5 -3
  213. package/dist/slots/authoring.js.map +1 -1
  214. package/dist/slots/content.d.ts.map +1 -1
  215. package/dist/slots/content.js +6 -1
  216. package/dist/slots/content.js.map +1 -1
  217. package/dist/slots/frames.d.ts +2 -0
  218. package/dist/slots/frames.d.ts.map +1 -1
  219. package/dist/slots/frames.js +7 -2
  220. package/dist/slots/frames.js.map +1 -1
  221. package/dist/text/direction.d.ts +3 -1
  222. package/dist/text/direction.d.ts.map +1 -1
  223. package/dist/text/direction.js +5 -1
  224. package/dist/text/direction.js.map +1 -1
  225. package/dist/text/index.d.ts +2 -2
  226. package/dist/text/index.js +3 -3
  227. package/dist/text/lengths.d.ts +6 -1
  228. package/dist/text/lengths.d.ts.map +1 -1
  229. package/dist/text/lengths.js +10 -1
  230. package/dist/text/lengths.js.map +1 -1
  231. package/dist/text/overflow.d.ts +2 -2
  232. package/dist/text/overflow.js.map +1 -1
  233. package/dist/text/picture.d.ts +1 -2
  234. package/dist/text/picture.d.ts.map +1 -1
  235. package/dist/text/picture.js +1 -4
  236. package/dist/text/picture.js.map +1 -1
  237. package/dist/transfer/apply.d.ts.map +1 -1
  238. package/dist/transfer/apply.js +1 -6
  239. package/dist/transfer/apply.js.map +1 -1
  240. package/dist/transfer/copied.d.ts +35 -3
  241. package/dist/transfer/copied.d.ts.map +1 -1
  242. package/dist/transfer/copied.js +44 -13
  243. package/dist/transfer/copied.js.map +1 -1
  244. package/dist/transfer/dependencies.d.ts +38 -0
  245. package/dist/transfer/dependencies.d.ts.map +1 -0
  246. package/dist/transfer/dependencies.js +100 -0
  247. package/dist/transfer/dependencies.js.map +1 -0
  248. package/dist/transfer/history.js +0 -1
  249. package/dist/transfer/history.js.map +1 -1
  250. package/dist/transfer/index.d.ts +5 -3
  251. package/dist/transfer/index.js +5 -3
  252. package/dist/transfer/nodes.d.ts.map +1 -1
  253. package/dist/transfer/nodes.js +16 -19
  254. package/dist/transfer/nodes.js.map +1 -1
  255. package/dist/transfer/plan.d.ts +0 -1
  256. package/dist/transfer/plan.js +3 -5
  257. package/dist/transfer/plan.js.map +1 -1
  258. package/dist/transfer/remove.js +5 -2
  259. package/dist/transfer/remove.js.map +1 -1
  260. package/dist/transfer/resources.d.ts +21 -0
  261. package/dist/transfer/resources.d.ts.map +1 -0
  262. package/dist/transfer/resources.js +38 -0
  263. package/dist/transfer/resources.js.map +1 -0
  264. package/dist/transfer/variables.d.ts +8 -1
  265. package/dist/transfer/variables.d.ts.map +1 -1
  266. package/dist/transfer/variables.js +24 -1
  267. package/dist/transfer/variables.js.map +1 -1
  268. package/dist/types.d.ts +73 -2
  269. package/dist/types.d.ts.map +1 -1
  270. package/dist/types.js.map +1 -1
  271. package/dist/undo.d.ts +28 -3
  272. package/dist/undo.d.ts.map +1 -1
  273. package/dist/undo.js +24 -7
  274. package/dist/undo.js.map +1 -1
  275. package/dist/variables/bindings.d.ts +37 -11
  276. package/dist/variables/bindings.d.ts.map +1 -1
  277. package/dist/variables/bindings.js +122 -74
  278. package/dist/variables/bindings.js.map +1 -1
  279. package/dist/variables/fields.d.ts +19 -1
  280. package/dist/variables/fields.d.ts.map +1 -1
  281. package/dist/variables/fields.js +36 -1
  282. package/dist/variables/fields.js.map +1 -1
  283. package/dist/variables/formula/check.d.ts +1 -1
  284. package/dist/variables/formula/index.d.ts +2 -2
  285. package/dist/variables/formula/index.js +1 -1
  286. package/dist/variables/formula/index.js.map +1 -1
  287. package/dist/variables/formula/print.d.ts +1 -1
  288. package/dist/variables/formula/signatures.js +1 -1
  289. package/dist/variables/index.d.ts +7 -7
  290. package/dist/variables/index.d.ts.map +1 -1
  291. package/dist/variables/index.js +57 -26
  292. package/dist/variables/index.js.map +1 -1
  293. package/dist/variables/paints.d.ts +57 -0
  294. package/dist/variables/paints.d.ts.map +1 -0
  295. package/dist/variables/paints.js +231 -0
  296. package/dist/variables/paints.js.map +1 -0
  297. package/dist/variables/resolution.d.ts +14 -11
  298. package/dist/variables/resolution.d.ts.map +1 -1
  299. package/dist/variables/resolution.js +36 -17
  300. package/dist/variables/resolution.js.map +1 -1
  301. package/dist/variables/subtree.js +17 -0
  302. package/dist/variables/subtree.js.map +1 -0
  303. package/dist/vector-network.d.ts.map +1 -1
  304. package/dist/vector-network.js +2 -8
  305. package/dist/vector-network.js.map +1 -1
  306. package/package.json +14 -1
  307. package/src/arrow-caps.ts +2 -5
  308. package/src/asset-keys.ts +20 -0
  309. package/src/behaviours/kinds.ts +51 -34
  310. package/src/behaviours/layers.ts +4 -2
  311. package/src/behaviours/model.ts +22 -11
  312. package/src/behaviours/schema.ts +20 -4
  313. package/src/behaviours/spec.ts +8 -2
  314. package/src/bindings.ts +11 -2
  315. package/src/checkpoint.ts +319 -17
  316. package/src/components/properties.ts +101 -2
  317. package/src/components/variants.ts +51 -30
  318. package/src/connectors/hit.ts +1 -12
  319. package/src/connectors/pieces.ts +2 -5
  320. package/src/constants.ts +17 -0
  321. package/src/constraints.ts +60 -0
  322. package/src/coordinate.ts +220 -0
  323. package/src/copy.ts +18 -19
  324. package/src/css/blend.ts +27 -0
  325. package/src/css/index.ts +18 -1
  326. package/src/css/text.ts +85 -17
  327. package/src/css/transform.ts +266 -0
  328. package/src/css/values.ts +8 -0
  329. package/src/cubic.ts +14 -0
  330. package/src/export-format.ts +29 -0
  331. package/src/fields/text.ts +3 -1
  332. package/src/figjam/palette.ts +29 -1
  333. package/src/generated/shape-with-text.ts +28 -2
  334. package/src/geometry.ts +97 -206
  335. package/src/graph.ts +155 -45
  336. package/src/group-bounds.ts +84 -17
  337. package/src/guides.ts +5 -0
  338. package/src/hit-test.ts +93 -64
  339. package/src/images.ts +71 -3
  340. package/src/instances/fields.ts +8 -0
  341. package/src/instances/index.ts +62 -31
  342. package/src/instances/kept-overrides.ts +280 -0
  343. package/src/instances/main-component.ts +12 -0
  344. package/src/instances/overrides.ts +27 -1
  345. package/src/instances/placement.ts +63 -10
  346. package/src/instances/swap.ts +456 -0
  347. package/src/instances/sync.ts +176 -50
  348. package/src/node-defaults.ts +3 -1
  349. package/src/order-keys.ts +6 -0
  350. package/src/outline/flatten.ts +190 -0
  351. package/src/outline/heads.ts +52 -0
  352. package/src/outline/hit.ts +369 -0
  353. package/src/outline/index.ts +4 -0
  354. package/src/outline/point.ts +59 -0
  355. package/src/outline/shapes.ts +207 -0
  356. package/src/plugin-data/fields.ts +21 -2
  357. package/src/resize.ts +267 -119
  358. package/src/scaling/index.ts +9 -1
  359. package/src/scaling/node.ts +9 -1
  360. package/src/scaling/snapshot.ts +51 -0
  361. package/src/scaling/tree.ts +63 -19
  362. package/src/shaders/model.ts +2 -3
  363. package/src/shared-styles.ts +90 -1
  364. package/src/slots/authoring.ts +5 -3
  365. package/src/slots/content.ts +6 -1
  366. package/src/slots/frames.ts +9 -7
  367. package/src/text/direction.ts +5 -0
  368. package/src/text/lengths.ts +10 -0
  369. package/src/text/overflow.ts +2 -2
  370. package/src/text/picture.ts +0 -4
  371. package/src/transfer/apply.ts +1 -13
  372. package/src/transfer/copied.ts +83 -15
  373. package/src/transfer/dependencies.ts +126 -0
  374. package/src/transfer/history.ts +0 -6
  375. package/src/transfer/index.ts +20 -2
  376. package/src/transfer/nodes.ts +17 -31
  377. package/src/transfer/plan.ts +3 -11
  378. package/src/transfer/remove.ts +5 -2
  379. package/src/transfer/resources.ts +54 -0
  380. package/src/transfer/variables.ts +34 -0
  381. package/src/types.ts +83 -1
  382. package/src/undo.ts +48 -10
  383. package/src/variables/bindings.ts +152 -88
  384. package/src/variables/fields.ts +46 -1
  385. package/src/variables/formula/index.ts +3 -1
  386. package/src/variables/index.ts +90 -39
  387. package/src/variables/paints.ts +296 -0
  388. package/src/variables/resolution.ts +39 -28
  389. package/src/variables/subtree.ts +15 -0
  390. package/src/vector-network.ts +4 -2
@@ -1 +1 @@
1
- {"version":3,"file":"arrow-caps.d.ts","names":[],"sources":["../src/arrow-caps.ts"],"mappings":";;;KAGY;UAOK;EACf;EACA;;EAEA;EACA,KAAK;;UAGU;EACf,MAAM;EACN,IAAI;;iBAmCU,WAAW,0BAA0B,OAAO;;;;;;iBAS5C,iBACd,UAAU,UACV,cAAc,WACd,UAAU;;;;;;;iBA6CI,sBACd,SAAS,eACT,aAAa,YACZ;;;;;iBA4Ba,uBACd,WACA,WACA,eACA,kBACE,QAAQ,QAAQ;;iBAaJ,mBACd,WACA,WACA,eACA,kBACE,WAAW;;;;;iBAmBC,kBACd,WACA,WACA,eACA,kBACE,QAAQ,QAAQ,QAAQ;;iBAeZ,iBACd,WACA,WACA,eACA,kBACE,QAAQ,QAAQ,QAAQ;;iBAYZ,gBAAgB;;iBAShB,gBAAgB,SAAS,eAAe,aAAa;;;;;iBAUrD,gBACd,SAAS,eACT,aAAa,WACb,iBACC;;;;;;;iBAmGa,eACd,eACA,gBACA,gBACA,KAAK,uBAEL;EACG,OAAO;EAAQ,KAAK"}
1
+ {"version":3,"file":"arrow-caps.d.ts","names":[],"sources":["../src/arrow-caps.ts"],"mappings":";;;KAIY;UAOK;EACf;EACA;;EAEA;EACA,KAAK;;UAGU;EACf,MAAM;EACN,IAAI;;iBAmCU,WAAW,0BAA0B,OAAO;;;;;;iBAS5C,iBACd,UAAU,UACV,cAAc,WACd,UAAU;;;;;;;iBA6CI,sBACd,SAAS,eACT,aAAa,YACZ;;;;;iBA4Ba,uBACd,WACA,WACA,eACA,kBACE,QAAQ,QAAQ;;iBAaJ,mBACd,WACA,WACA,eACA,kBACE,WAAW;;;;;iBAmBC,kBACd,WACA,WACA,eACA,kBACE,QAAQ,QAAQ,QAAQ;;iBAeZ,iBACd,WACA,WACA,eACA,kBACE,QAAQ,QAAQ,QAAQ;;iBAYZ,gBAAgB;;iBAShB,gBAAgB,SAAS,eAAe,aAAa;;;;;iBAUrD,gBACd,SAAS,eACT,aAAa,WACb,iBACC;;;;;;;iBA+Fa,eACd,eACA,gBACA,gBACA,KAAK,uBAEL;EACG,OAAO;EAAQ,KAAK"}
@@ -1,3 +1,4 @@
1
+ import { cubicPoint } from "./cubic.js";
1
2
  //#region src/arrow-caps.ts
2
3
  /**
3
4
  * Arrow heads relative to stroke weight, from the stroke outlines Figma gives for them. The
@@ -226,11 +227,7 @@ function trimArrowShafts(network, fallbackCap, weight) {
226
227
  return trimmed;
227
228
  }
228
229
  function cubicAt([a, b, c, d], t) {
229
- const u = 1 - t;
230
- return {
231
- x: u * u * u * a.x + 3 * u * u * t * b.x + 3 * u * t * t * c.x + t * t * t * d.x,
232
- y: u * u * u * a.y + 3 * u * u * t * b.y + 3 * u * t * t * c.y + t * t * t * d.y
233
- };
230
+ return cubicPoint(a, b, c, d, t);
234
231
  }
235
232
  function lerp(a, b, t) {
236
233
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"arrow-caps.js","names":[],"sources":["../src/arrow-caps.ts"],"sourcesContent":["import type { Vector } from './primitives'\nimport type { Stroke, StrokeCap, VectorNetwork } from './types'\n\nexport type ArrowCapKind =\n | 'ARROW_LINES'\n | 'ARROW_EQUILATERAL'\n | 'TRIANGLE_FILLED'\n | 'DIAMOND_FILLED'\n | 'CIRCLE_FILLED'\n\nexport interface ArrowEndpoint {\n x: number\n y: number\n /** Direction the arrow points, in radians, away from the path. */\n angle: number\n cap: ArrowCapKind\n}\n\nexport interface ArrowWing {\n from: Vector\n to: Vector\n}\n\n/**\n * Arrow heads relative to stroke weight, from the stroke outlines Figma gives for them. The\n * triangle heads run 5 back from the end and spread to 5/√3 on either side: the equilateral\n * arrow comes to its point at the end, and the filled triangle has its base across it. The\n * diamond reaches 5/√3 from the end every way, and the circle has radius 8/3. A line arrow's\n * wings meet at the end and run 4.5 back at 45°, stroked at the line's weight with round ends.\n */\nconst TRIANGLE_HEAD_DEPTH = 5\nconst TRIANGLE_HEAD_HALF_WIDTH = 5 / Math.sqrt(3)\nconst CIRCLE_HEAD_RADIUS = 8 / 3\nconst WING_LENGTH = 4.5\nconst WING_SWEEP = Math.PI / 4\n/** How far a line stops short of its end under a triangle head: half a weight inside its base. */\nconst SHAFT_TRIM = TRIANGLE_HEAD_DEPTH - 0.5\n/**\n * The furthest any head reaches past its line's box. On a line shorter than its head, a triangle\n * reaches back from the end to its base corners, and a line arrow's wings their full length.\n */\nconst HEAD_REACH = Math.max(\n WING_LENGTH + 0.5,\n Math.hypot(TRIANGLE_HEAD_DEPTH, TRIANGLE_HEAD_HALF_WIDTH),\n CIRCLE_HEAD_RADIUS\n)\n\nconst ARROW_CAPS: ReadonlySet<string> = new Set<ArrowCapKind>([\n 'ARROW_LINES',\n 'ARROW_EQUILATERAL',\n 'TRIANGLE_FILLED',\n 'DIAMOND_FILLED',\n 'CIRCLE_FILLED'\n])\n\nexport function isArrowCap(cap: string | undefined): cap is ArrowCapKind {\n return cap !== undefined && ARROW_CAPS.has(cap)\n}\n\n/**\n * Worst-case reach of an arrow head past the path. Used to widen visual bounds and render\n * margins so heads are not cropped by caches, exports, or culling. Vertex-level caps in the\n * network count even when no stroke or node cap is an arrow.\n */\nexport function arrowCapOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null\n): number {\n const networkHasArrow = network?.vertices.some((vertex) => isArrowCap(vertex.strokeCap)) ?? false\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n if (networkHasArrow || isArrowCap(stroke.cap ?? fallbackCap)) {\n overflow = Math.max(overflow, HEAD_REACH * stroke.weight)\n }\n }\n return overflow\n}\n\n/** An open path end that carries a head: its segment and which end of it, and its cap. */\ninterface OpenArrowEnd {\n segment: number\n side: 'start' | 'end'\n cap: ArrowCapKind\n}\n\n/** The open ends of `network` that carry a head: vertices used by exactly one segment. */\nfunction openArrowEnds(network: VectorNetwork, fallbackCap: StrokeCap): OpenArrowEnd[] {\n const degrees = Array.from({ length: network.vertices.length }, () => 0)\n for (const segment of network.segments) {\n degrees[segment.start]++\n degrees[segment.end]++\n }\n const ends: OpenArrowEnd[] = []\n network.segments.forEach((segment, index) => {\n for (const side of ['start', 'end'] as const) {\n const vertex = network.vertices[segment[side]]\n if (degrees[segment[side]] !== 1) continue\n const cap = (vertex.strokeCap as StrokeCap | undefined) ?? fallbackCap\n if (isArrowCap(cap)) ends.push({ segment: index, side, cap })\n }\n })\n return ends\n}\n\n/**\n * Finds the open path ends that should carry an arrow head: vertices used by\n * exactly one segment, with a per-vertex cap override falling back to the\n * stroke cap. The returned angle points away from the path, following the\n * terminal bezier tangent when the segment is curved.\n */\nexport function collectArrowEndpoints(\n network: VectorNetwork,\n fallbackCap: StrokeCap\n): ArrowEndpoint[] {\n const endpoints: ArrowEndpoint[] = []\n for (const { segment: index, side, cap } of openArrowEnds(network, fallbackCap)) {\n const segment = network.segments[index]\n const vertex = network.vertices[segment[side]]\n const tangent = side === 'start' ? segment.tangentStart : segment.tangentEnd\n let controlX: number\n let controlY: number\n if (Math.abs(tangent.x) > 0.001 || Math.abs(tangent.y) > 0.001) {\n controlX = vertex.x + tangent.x\n controlY = vertex.y + tangent.y\n } else {\n const other = network.vertices[side === 'start' ? segment.end : segment.start]\n controlX = other.x\n controlY = other.y\n }\n const dx = vertex.x - controlX\n const dy = vertex.y - controlY\n if (dx === 0 && dy === 0) continue\n endpoints.push({ x: vertex.x, y: vertex.y, angle: Math.atan2(dy, dx), cap })\n }\n return endpoints\n}\n\n/**\n * Points of a filled equilateral arrow head: tip first, then the two base corners. The tip sits\n * exactly on the endpoint and the head sweeps back along the path.\n */\nexport function equilateralArrowPoints(\n x: number,\n y: number,\n angle: number,\n weight: number\n): [Vector, Vector, Vector] {\n const { dir, perp } = headAxes(angle)\n const half = TRIANGLE_HEAD_HALF_WIDTH * weight\n const baseX = x - TRIANGLE_HEAD_DEPTH * weight * dir.x\n const baseY = y - TRIANGLE_HEAD_DEPTH * weight * dir.y\n return [\n { x, y },\n { x: baseX - half * perp.x, y: baseY - half * perp.y },\n { x: baseX + half * perp.x, y: baseY + half * perp.y }\n ]\n}\n\n/** The two wings of an open (lines-style) arrow head, each from the tip to its end. */\nexport function arrowLinesSegments(\n x: number,\n y: number,\n angle: number,\n weight: number\n): [ArrowWing, ArrowWing] {\n const wingLength = WING_LENGTH * weight\n const tip = { x, y }\n const makeWing = (wingAngle: number): ArrowWing => ({\n from: tip,\n to: { x: x + wingLength * Math.cos(wingAngle), y: y + wingLength * Math.sin(wingAngle) }\n })\n return [makeWing(angle + Math.PI - WING_SWEEP), makeWing(angle + Math.PI + WING_SWEEP)]\n}\n\nfunction headAxes(angle: number) {\n const dir = { x: Math.cos(angle), y: Math.sin(angle) }\n return { dir, perp: { x: -dir.y, y: dir.x } }\n}\n\n/**\n * Points of a filled triangle head: its base across the end, narrowing back along the path to\n * the shaft's width, in drawing order.\n */\nexport function triangleCapPoints(\n x: number,\n y: number,\n angle: number,\n weight: number\n): [Vector, Vector, Vector, Vector] {\n const { dir, perp } = headAxes(angle)\n const back = {\n x: x - TRIANGLE_HEAD_DEPTH * weight * dir.x,\n y: y - TRIANGLE_HEAD_DEPTH * weight * dir.y\n }\n const at = (point: Vector, side: number) => ({\n x: point.x + side * perp.x,\n y: point.y + side * perp.y\n })\n const half = TRIANGLE_HEAD_HALF_WIDTH * weight\n return [at(back, weight / 2), at({ x, y }, half), at({ x, y }, -half), at(back, -weight / 2)]\n}\n\n/** Points of a filled diamond head centred on the end, in drawing order. */\nexport function diamondCapPoints(\n x: number,\n y: number,\n angle: number,\n weight: number\n): [Vector, Vector, Vector, Vector] {\n const { dir, perp } = headAxes(angle)\n const reach = TRIANGLE_HEAD_HALF_WIDTH * weight\n return [\n { x: x + reach * dir.x, y: y + reach * dir.y },\n { x: x + reach * perp.x, y: y + reach * perp.y },\n { x: x - reach * dir.x, y: y - reach * dir.y },\n { x: x - reach * perp.x, y: y - reach * perp.y }\n ]\n}\n\n/** Radius of a filled circle head, centred on the end. */\nexport function circleCapRadius(weight: number): number {\n return CIRCLE_HEAD_RADIUS * weight\n}\n\nfunction trimsShaft(cap: StrokeCap | undefined): boolean {\n return cap === 'TRIANGLE_FILLED' || cap === 'ARROW_EQUILATERAL'\n}\n\n/** Whether any open end of `network` carries a head the line stops short of. */\nexport function hasTrimmedShaft(network: VectorNetwork, fallbackCap: StrokeCap): boolean {\n return network.vertices.some((vertex) =>\n trimsShaft((vertex.strokeCap as StrokeCap | undefined) ?? fallbackCap)\n )\n}\n\n/**\n * The network with its line pulled back from each open end that carries a triangle or\n * equilateral head, as Figma draws it, so the line's own cap stays inside the head.\n */\nexport function trimArrowShafts(\n network: VectorNetwork,\n fallbackCap: StrokeCap,\n weight: number\n): VectorNetwork {\n const trimmed = structuredClone(network)\n // By segment and side, not position: an open path's two ends may meet at one point.\n for (const { segment, side, cap } of openArrowEnds(network, fallbackCap)) {\n if (!trimsShaft(cap)) continue\n trimSegmentEnd(trimmed, trimmed.segments[segment], side === 'end', SHAFT_TRIM * weight)\n }\n return trimmed\n}\n\ntype Cubic = [Vector, Vector, Vector, Vector]\n\nfunction cubicAt([a, b, c, d]: Cubic, t: number): Vector {\n const u = 1 - t\n return {\n x: u * u * u * a.x + 3 * u * u * t * b.x + 3 * u * t * t * c.x + t * t * t * d.x,\n y: u * u * u * a.y + 3 * u * u * t * b.y + 3 * u * t * t * c.y + t * t * t * d.y\n }\n}\n\nfunction lerp(a: Vector, b: Vector, t: number): Vector {\n return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t }\n}\n\n/** The part of a cubic from its start to `t`, by de Casteljau. */\nfunction cubicHead([a, b, c, d]: Cubic, t: number): Cubic {\n const ab = lerp(a, b, t)\n const bc = lerp(b, c, t)\n const cd = lerp(c, d, t)\n const abc = lerp(ab, bc, t)\n const bcd = lerp(bc, cd, t)\n return [a, ab, abc, lerp(abc, bcd, t)]\n}\n\n/**\n * Pulls one end of `segment` back along it until it lies `distance` from where it was, keeping\n * the rest of the curve where it is.\n */\nfunction trimSegmentEnd(\n network: VectorNetwork,\n segment: VectorNetwork['segments'][number],\n atEnd: boolean,\n distance: number\n) {\n const start = network.vertices[segment.start]\n const end = network.vertices[segment.end]\n // Oriented so the trimmed end comes last.\n const from = atEnd ? start : end\n const to = atEnd ? end : start\n const out = atEnd ? segment.tangentStart : segment.tangentEnd\n const back = atEnd ? segment.tangentEnd : segment.tangentStart\n const cubic: Cubic = [\n { x: from.x, y: from.y },\n { x: from.x + out.x, y: from.y + out.y },\n { x: to.x + back.x, y: to.y + back.y },\n { x: to.x, y: to.y }\n ]\n const length = Math.hypot(to.x - from.x, to.y - from.y)\n if (length <= distance) return\n const index = atEnd ? segment.end : segment.start\n const isStraight = out.x === 0 && out.y === 0 && back.x === 0 && back.y === 0\n if (isStraight) {\n // A straight segment stays straight, so the corner before it keeps its radius.\n const keep = (length - distance) / length\n const vertex = network.vertices[index]\n network.vertices[index] = {\n ...vertex,\n x: from.x + (to.x - from.x) * keep,\n y: from.y + (to.y - from.y) * keep\n }\n return\n }\n let low = 0\n let high = 1\n for (let step = 0; step < 40; step++) {\n const t = (low + high) / 2\n const point = cubicAt(cubic, t)\n if (Math.hypot(point.x - to.x, point.y - to.y) > distance) low = t\n else high = t\n }\n const [, c1, c2, tip] = cubicHead(cubic, low)\n network.vertices[index] = { ...network.vertices[index], x: tip.x, y: tip.y }\n const kept = { x: c1.x - from.x, y: c1.y - from.y }\n const trimmedBack = { x: c2.x - tip.x, y: c2.y - tip.y }\n if (atEnd) {\n segment.tangentStart = kept\n segment.tangentEnd = trimmedBack\n } else {\n segment.tangentEnd = kept\n segment.tangentStart = trimmedBack\n }\n}\n\n/**\n * Where Figma strokes a LINE running from its origin to (`width`, `height`): a full weight to one\n * side, toward its local negative y, whatever the stroke's alignment. Under a cap both ends come in\n * by half a weight, so the cap or head ends where the line does; an equilateral arrow already\n * comes to its point at the end, so it stays there.\n */\nexport function lineStrokeEnds(\n width: number,\n height: number,\n weight: number,\n cap: StrokeCap | undefined,\n // Flatten insets a full half weight even past the middle, reversing a short line (live-measured).\n insetPastMiddle = false\n): { start: Vector; end: Vector } {\n const length = Math.hypot(width, height)\n if (length === 0) return { start: { x: 0, y: 0 }, end: { x: 0, y: 0 } }\n const ux = width / length\n const uy = height / length\n const inset =\n cap === undefined || cap === 'NONE' || cap === 'ARROW_EQUILATERAL'\n ? 0\n : (insetPastMiddle ? weight : Math.min(weight, length)) / 2\n const offset = { x: (uy * weight) / 2, y: (-ux * weight) / 2 }\n return {\n start: { x: ux * inset + offset.x,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KAAK,IAAI,QAAQ,MAAM,KAAK;CAC9D,MAAM,SAAS;EAAE,GAAI,KAAK,SAAU;EAAG,GAAI,CAAC,KAAK,SAAU;CAAE;CAC7D,OAAO;EACL,OAAO;GAAE,GAAG,KAAK,QAAQ,OAAO;GAAG,GAAG,KAAK,QAAQ,OAAO;EAAE;EAC5D,KAAK;GAAE,GAAG,QAAQ,KAAK,QAAQ,OAAO;GAAG,GAAG,SAAS,KAAK,QAAQ,OAAO;EAAE;CAC7E;AACF"}
1
+ {"version":3,"file":"arrow-caps.js","names":[],"sources":["../src/arrow-caps.ts"],"sourcesContent":["import { cubicPoint } from './cubic'\nimport type { Vector } from './primitives'\nimport type { Stroke, StrokeCap, VectorNetwork } from './types'\n\nexport type ArrowCapKind =\n | 'ARROW_LINES'\n | 'ARROW_EQUILATERAL'\n | 'TRIANGLE_FILLED'\n | 'DIAMOND_FILLED'\n | 'CIRCLE_FILLED'\n\nexport interface ArrowEndpoint {\n x: number\n y: number\n /** Direction the arrow points, in radians, away from the path. */\n angle: number\n cap: ArrowCapKind\n}\n\nexport interface ArrowWing {\n from: Vector\n to: Vector\n}\n\n/**\n * Arrow heads relative to stroke weight, from the stroke outlines Figma gives for them. The\n * triangle heads run 5 back from the end and spread to 5/√3 on either side: the equilateral\n * arrow comes to its point at the end, and the filled triangle has its base across it. The\n * diamond reaches 5/√3 from the end every way, and the circle has radius 8/3. A line arrow's\n * wings meet at the end and run 4.5 back at 45°, stroked at the line's weight with round ends.\n */\nconst TRIANGLE_HEAD_DEPTH = 5\nconst TRIANGLE_HEAD_HALF_WIDTH = 5 / Math.sqrt(3)\nconst CIRCLE_HEAD_RADIUS = 8 / 3\nconst WING_LENGTH = 4.5\nconst WING_SWEEP = Math.PI / 4\n/** How far a line stops short of its end under a triangle head: half a weight inside its base. */\nconst SHAFT_TRIM = TRIANGLE_HEAD_DEPTH - 0.5\n/**\n * The furthest any head reaches past its line's box. On a line shorter than its head, a triangle\n * reaches back from the end to its base corners, and a line arrow's wings their full length.\n */\nconst HEAD_REACH = Math.max(\n WING_LENGTH + 0.5,\n Math.hypot(TRIANGLE_HEAD_DEPTH, TRIANGLE_HEAD_HALF_WIDTH),\n CIRCLE_HEAD_RADIUS\n)\n\nconst ARROW_CAPS: ReadonlySet<string> = new Set<ArrowCapKind>([\n 'ARROW_LINES',\n 'ARROW_EQUILATERAL',\n 'TRIANGLE_FILLED',\n 'DIAMOND_FILLED',\n 'CIRCLE_FILLED'\n])\n\nexport function isArrowCap(cap: string | undefined): cap is ArrowCapKind {\n return cap !== undefined && ARROW_CAPS.has(cap)\n}\n\n/**\n * Worst-case reach of an arrow head past the path. Used to widen visual bounds and render\n * margins so heads are not cropped by caches, exports, or culling. Vertex-level caps in the\n * network count even when no stroke or node cap is an arrow.\n */\nexport function arrowCapOverflow(\n strokes?: Stroke[],\n fallbackCap?: StrokeCap,\n network?: VectorNetwork | null\n): number {\n const networkHasArrow = network?.vertices.some((vertex) => isArrowCap(vertex.strokeCap)) ?? false\n let overflow = 0\n for (const stroke of strokes ?? []) {\n if (!stroke.visible) continue\n if (networkHasArrow || isArrowCap(stroke.cap ?? fallbackCap)) {\n overflow = Math.max(overflow, HEAD_REACH * stroke.weight)\n }\n }\n return overflow\n}\n\n/** An open path end that carries a head: its segment and which end of it, and its cap. */\ninterface OpenArrowEnd {\n segment: number\n side: 'start' | 'end'\n cap: ArrowCapKind\n}\n\n/** The open ends of `network` that carry a head: vertices used by exactly one segment. */\nfunction openArrowEnds(network: VectorNetwork, fallbackCap: StrokeCap): OpenArrowEnd[] {\n const degrees = Array.from({ length: network.vertices.length }, () => 0)\n for (const segment of network.segments) {\n degrees[segment.start]++\n degrees[segment.end]++\n }\n const ends: OpenArrowEnd[] = []\n network.segments.forEach((segment, index) => {\n for (const side of ['start', 'end'] as const) {\n const vertex = network.vertices[segment[side]]\n if (degrees[segment[side]] !== 1) continue\n const cap = (vertex.strokeCap as StrokeCap | undefined) ?? fallbackCap\n if (isArrowCap(cap)) ends.push({ segment: index, side, cap })\n }\n })\n return ends\n}\n\n/**\n * Finds the open path ends that should carry an arrow head: vertices used by\n * exactly one segment, with a per-vertex cap override falling back to the\n * stroke cap. The returned angle points away from the path, following the\n * terminal bezier tangent when the segment is curved.\n */\nexport function collectArrowEndpoints(\n network: VectorNetwork,\n fallbackCap: StrokeCap\n): ArrowEndpoint[] {\n const endpoints: ArrowEndpoint[] = []\n for (const { segment: index, side, cap } of openArrowEnds(network, fallbackCap)) {\n const segment = network.segments[index]\n const vertex = network.vertices[segment[side]]\n const tangent = side === 'start' ? segment.tangentStart : segment.tangentEnd\n let controlX: number\n let controlY: number\n if (Math.abs(tangent.x) > 0.001 || Math.abs(tangent.y) > 0.001) {\n controlX = vertex.x + tangent.x\n controlY = vertex.y + tangent.y\n } else {\n const other = network.vertices[side === 'start' ? segment.end : segment.start]\n controlX = other.x\n controlY = other.y\n }\n const dx = vertex.x - controlX\n const dy = vertex.y - controlY\n if (dx === 0 && dy === 0) continue\n endpoints.push({ x: vertex.x, y: vertex.y, angle: Math.atan2(dy, dx), cap })\n }\n return endpoints\n}\n\n/**\n * Points of a filled equilateral arrow head: tip first, then the two base corners. The tip sits\n * exactly on the endpoint and the head sweeps back along the path.\n */\nexport function equilateralArrowPoints(\n x: number,\n y: number,\n angle: number,\n weight: number\n): [Vector, Vector, Vector] {\n const { dir, perp } = headAxes(angle)\n const half = TRIANGLE_HEAD_HALF_WIDTH * weight\n const baseX = x - TRIANGLE_HEAD_DEPTH * weight * dir.x\n const baseY = y - TRIANGLE_HEAD_DEPTH * weight * dir.y\n return [\n { x, y },\n { x: baseX - half * perp.x, y: baseY - half * perp.y },\n { x: baseX + half * perp.x, y: baseY + half * perp.y }\n ]\n}\n\n/** The two wings of an open (lines-style) arrow head, each from the tip to its end. */\nexport function arrowLinesSegments(\n x: number,\n y: number,\n angle: number,\n weight: number\n): [ArrowWing, ArrowWing] {\n const wingLength = WING_LENGTH * weight\n const tip = { x, y }\n const makeWing = (wingAngle: number): ArrowWing => ({\n from: tip,\n to: { x: x + wingLength * Math.cos(wingAngle), y: y + wingLength * Math.sin(wingAngle) }\n })\n return [makeWing(angle + Math.PI - WING_SWEEP), makeWing(angle + Math.PI + WING_SWEEP)]\n}\n\nfunction headAxes(angle: number) {\n const dir = { x: Math.cos(angle), y: Math.sin(angle) }\n return { dir, perp: { x: -dir.y, y: dir.x } }\n}\n\n/**\n * Points of a filled triangle head: its base across the end, narrowing back along the path to\n * the shaft's width, in drawing order.\n */\nexport function triangleCapPoints(\n x: number,\n y: number,\n angle: number,\n weight: number\n): [Vector, Vector, Vector, Vector] {\n const { dir, perp } = headAxes(angle)\n const back = {\n x: x - TRIANGLE_HEAD_DEPTH * weight * dir.x,\n y: y - TRIANGLE_HEAD_DEPTH * weight * dir.y\n }\n const at = (point: Vector, side: number) => ({\n x: point.x + side * perp.x,\n y: point.y + side * perp.y\n })\n const half = TRIANGLE_HEAD_HALF_WIDTH * weight\n return [at(back, weight / 2), at({ x, y }, half), at({ x, y }, -half), at(back, -weight / 2)]\n}\n\n/** Points of a filled diamond head centred on the end, in drawing order. */\nexport function diamondCapPoints(\n x: number,\n y: number,\n angle: number,\n weight: number\n): [Vector, Vector, Vector, Vector] {\n const { dir, perp } = headAxes(angle)\n const reach = TRIANGLE_HEAD_HALF_WIDTH * weight\n return [\n { x: x + reach * dir.x, y: y + reach * dir.y },\n { x: x + reach * perp.x, y: y + reach * perp.y },\n { x: x - reach * dir.x, y: y - reach * dir.y },\n { x: x - reach * perp.x, y: y - reach * perp.y }\n ]\n}\n\n/** Radius of a filled circle head, centred on the end. */\nexport function circleCapRadius(weight: number): number {\n return CIRCLE_HEAD_RADIUS * weight\n}\n\nfunction trimsShaft(cap: StrokeCap | undefined): boolean {\n return cap === 'TRIANGLE_FILLED' || cap === 'ARROW_EQUILATERAL'\n}\n\n/** Whether any open end of `network` carries a head the line stops short of. */\nexport function hasTrimmedShaft(network: VectorNetwork, fallbackCap: StrokeCap): boolean {\n return network.vertices.some((vertex) =>\n trimsShaft((vertex.strokeCap as StrokeCap | undefined) ?? fallbackCap)\n )\n}\n\n/**\n * The network with its line pulled back from each open end that carries a triangle or\n * equilateral head, as Figma draws it, so the line's own cap stays inside the head.\n */\nexport function trimArrowShafts(\n network: VectorNetwork,\n fallbackCap: StrokeCap,\n weight: number\n): VectorNetwork {\n const trimmed = structuredClone(network)\n // By segment and side, not position: an open path's two ends may meet at one point.\n for (const { segment, side, cap } of openArrowEnds(network, fallbackCap)) {\n if (!trimsShaft(cap)) continue\n trimSegmentEnd(trimmed, trimmed.segments[segment], side === 'end', SHAFT_TRIM * weight)\n }\n return trimmed\n}\n\ntype Cubic = [Vector, Vector, Vector, Vector]\n\nfunction cubicAt([a, b, c, d]: Cubic, t: number): Vector {\n return cubicPoint(a, b, c, d, t)\n}\n\nfunction lerp(a: Vector, b: Vector, t: number): Vector {\n return { x: a.x + (b.x - a.x) * t, y: a.y + (b.y - a.y) * t }\n}\n\n/** The part of a cubic from its start to `t`, by de Casteljau. */\nfunction cubicHead([a, b, c, d]: Cubic, t: number): Cubic {\n const ab = lerp(a, b, t)\n const bc = lerp(b, c, t)\n const cd = lerp(c, d, t)\n const abc = lerp(ab, bc, t)\n const bcd = lerp(bc, cd, t)\n return [a, ab, abc, lerp(abc, bcd, t)]\n}\n\n/**\n * Pulls one end of `segment` back along it until it lies `distance` from where it was, keeping\n * the rest of the curve where it is.\n */\nfunction trimSegmentEnd(\n network: VectorNetwork,\n segment: VectorNetwork['segments'][number],\n atEnd: boolean,\n distance: number\n) {\n const start = network.vertices[segment.start]\n const end = network.vertices[segment.end]\n // Oriented so the trimmed end comes last.\n const from = atEnd ? start : end\n const to = atEnd ? end : start\n const out = atEnd ? segment.tangentStart : segment.tangentEnd\n const back = atEnd ? segment.tangentEnd : segment.tangentStart\n const cubic: Cubic = [\n { x: from.x, y: from.y },\n { x: from.x + out.x, y: from.y + out.y },\n { x: to.x + back.x, y: to.y + back.y },\n { x: to.x, y: to.y }\n ]\n const length = Math.hypot(to.x - from.x, to.y - from.y)\n if (length <= distance) return\n const index = atEnd ? segment.end : segment.start\n const isStraight = out.x === 0 && out.y === 0 && back.x === 0 && back.y === 0\n if (isStraight) {\n // A straight segment stays straight, so the corner before it keeps its radius.\n const keep = (length - distance) / length\n const vertex = network.vertices[index]\n network.vertices[index] = {\n ...vertex,\n x: from.x + (to.x - from.x) * keep,\n y: from.y + (to.y - from.y) * keep\n }\n return\n }\n let low = 0\n let high = 1\n for (let step = 0; step < 40; step++) {\n const t = (low + high) / 2\n const point = cubicAt(cubic, t)\n if (Math.hypot(point.x - to.x, point.y - to.y) > distance) low = t\n else high = t\n }\n const [, c1, c2, tip] = cubicHead(cubic, low)\n network.vertices[index] = { ...network.vertices[index], x: tip.x, y: tip.y }\n const kept = { x: c1.x - from.x, y: c1.y - from.y }\n const trimmedBack = { x: c2.x - tip.x, y: c2.y - tip.y }\n if (atEnd) {\n segment.tangentStart = kept\n segment.tangentEnd = trimmedBack\n } else {\n segment.tangentEnd = kept\n segment.tangentStart = trimmedBack\n }\n}\n\n/**\n * Where Figma strokes a LINE running from its origin to (`width`, `height`): a full weight to one\n * side, toward its local negative y, whatever the stroke's alignment. Under a cap both ends come in\n * by half a weight, so the cap or head ends where the line does; an equilateral arrow already\n * comes to its point at the end, so it stays there.\n */\nexport function lineStrokeEnds(\n width: number,\n height: number,\n weight: number,\n cap: StrokeCap | undefined,\n // Flatten insets a full half weight even past the middle, reversing a short line (live-measured).\n insetPastMiddle = false\n): { start: Vector; end: Vector } {\n const length = Math.hypot(width, height)\n if (length === 0) return { start: { x: 0, y: 0 }, end: { x: 0, y: 0 } }\n const ux = width / length\n const uy = height / length\n const inset =\n cap === undefined || cap === 'NONE' || cap === 'ARROW_EQUILATERAL'\n ? 0\n : (insetPastMiddle ? weight : Math.min(weight, length)) / 2\n const offset = { x: (uy * weight) / 2, y: (-ux * weight) / 2 }\n return {\n start: { x: ux * inset + offset.x, y: uy * inset + offset.y },\n end: { x: width - ux * inset + offset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E;AACF"}
@@ -1,3 +1,4 @@
1
+ import { SceneNode, Variable, VariableCollection } from "./types.js";
1
2
  //#region src/asset-keys.d.ts
2
3
  /**
3
4
  * A key shaped as Figma's asset keys, 40 hex digits, derived from `seed` so the same seed always
@@ -12,6 +13,15 @@ declare function derivedAssetKey(seed: string): string;
12
13
  * across an edit would bring the old value back.
13
14
  */
14
15
  declare function derivedAssetVersion(content: string): string;
16
+ /** A collection's asset key: its library key, or else one derived from its ID. */
17
+ declare function collectionAssetKey(collection: Pick<VariableCollection, 'id' | 'key'>): string;
18
+ /** A variable's asset key: its library key, or else one derived from its ID. */
19
+ declare function variableAssetKey(variable: Pick<Variable, 'id' | 'key'>): string;
20
+ /**
21
+ * A shared style's asset key: its library key, or else one derived from its ID, which layers name
22
+ * it by but which can hold characters a key cannot (`S:…,`).
23
+ */
24
+ declare function styleAssetKey(style: Pick<SceneNode, 'id' | 'componentKey' | 'source'>): string;
15
25
  //#endregion
16
- export { derivedAssetKey, derivedAssetVersion };
26
+ export { collectionAssetKey, derivedAssetKey, derivedAssetVersion, styleAssetKey, variableAssetKey };
17
27
  //# sourceMappingURL=asset-keys.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"asset-keys.d.ts","names":[],"sources":["../src/asset-keys.ts"],"mappings":";;;;;;iBAQgB,gBAAgB;;;;;;;iBAahB,oBAAoB"}
1
+ {"version":3,"file":"asset-keys.d.ts","names":[],"sources":["../src/asset-keys.ts"],"mappings":";;;;;;;iBAUgB,gBAAgB;;;;;;;iBAahB,oBAAoB;;iBAMpB,mBAAmB,YAAY,KAAK;;iBAKpC,iBAAiB,UAAU,KAAK;;;;;iBAQhC,cAAc,OAAO,KAAK"}
@@ -21,7 +21,22 @@ function derivedAssetVersion(content) {
21
21
  const view = new DataView(sha1(utf8ToBytes(content)).buffer);
22
22
  return `${view.getUint32(0) & MAX_GUID_PART}:${view.getUint32(4) & MAX_GUID_PART}`;
23
23
  }
24
+ /** A collection's asset key: its library key, or else one derived from its ID. */
25
+ function collectionAssetKey(collection) {
26
+ return collection.key ?? derivedAssetKey(`collection:${collection.id}`);
27
+ }
28
+ /** A variable's asset key: its library key, or else one derived from its ID. */
29
+ function variableAssetKey(variable) {
30
+ return variable.key ?? derivedAssetKey(`variable:${variable.id}`);
31
+ }
32
+ /**
33
+ * A shared style's asset key: its library key, or else one derived from its ID, which layers name
34
+ * it by but which can hold characters a key cannot (`S:…,`).
35
+ */
36
+ function styleAssetKey(style) {
37
+ return style.componentKey ?? derivedAssetKey(`style:${style.source.id ?? style.id}`);
38
+ }
24
39
  //#endregion
25
- export { derivedAssetKey, derivedAssetVersion };
40
+ export { collectionAssetKey, derivedAssetKey, derivedAssetVersion, styleAssetKey, variableAssetKey };
26
41
 
27
42
  //# sourceMappingURL=asset-keys.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"asset-keys.js","names":[],"sources":["../src/asset-keys.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'\n\n/**\n * A key shaped as Figma's asset keys, 40 hex digits, derived from `seed` so the same seed always\n * gives the same key. The Figma clipboard names variables and collections by key; one made in\n * OpenPencil has none, so copying it gives it this one, and copying it again gives the same.\n */\nexport function derivedAssetKey(seed: string): string {\n return bytesToHex(sha1(utf8ToBytes(seed)))\n}\n\n/** Largest part of a Figma GUID, which Figma reads as a signed 32-bit integer. */\nconst MAX_GUID_PART = 0x7fffffff\n\n/**\n * A version shaped as Figma's asset versions, `session:local`, derived from `content` so that\n * copying an unchanged asset again gives the same version and copying a changed one gives another.\n * Figma keeps the first value it pasted for a key and version, so a version that stayed the same\n * across an edit would bring the old value back.\n */\nexport function derivedAssetVersion(content: string): string {\n const view = new DataView(sha1(utf8ToBytes(content)).buffer)\n return `${view.getUint32(0) & MAX_GUID_PART}:${view.getUint32(4) & MAX_GUID_PART}`\n}\n"],"mappings":";;;;;;;;AAQA,SAAgB,gBAAgB,MAAsB;CACpD,OAAO,WAAW,KAAK,YAAY,IAAI,CAAC,CAAC;AAC3C;;AAGA,MAAM,gBAAgB;;;;;;;AAQtB,SAAgB,oBAAoB,SAAyB;CAC3D,MAAM,OAAO,IAAI,SAAS,KAAK,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM;CAC3D,OAAO,GAAG,KAAK,UAAU,CAAC,IAAI,cAAc,GAAG,KAAK,UAAU,CAAC,IAAI;AACrE"}
1
+ {"version":3,"file":"asset-keys.js","names":[],"sources":["../src/asset-keys.ts"],"sourcesContent":["import { sha1 } from '@noble/hashes/legacy.js'\nimport { bytesToHex, utf8ToBytes } from '@noble/hashes/utils.js'\n\nimport type { SceneNode, Variable, VariableCollection } from './types'\n\n/**\n * A key shaped as Figma's asset keys, 40 hex digits, derived from `seed` so the same seed always\n * gives the same key. The Figma clipboard names variables and collections by key; one made in\n * OpenPencil has none, so copying it gives it this one, and copying it again gives the same.\n */\nexport function derivedAssetKey(seed: string): string {\n return bytesToHex(sha1(utf8ToBytes(seed)))\n}\n\n/** Largest part of a Figma GUID, which Figma reads as a signed 32-bit integer. */\nconst MAX_GUID_PART = 0x7fffffff\n\n/**\n * A version shaped as Figma's asset versions, `session:local`, derived from `content` so that\n * copying an unchanged asset again gives the same version and copying a changed one gives another.\n * Figma keeps the first value it pasted for a key and version, so a version that stayed the same\n * across an edit would bring the old value back.\n */\nexport function derivedAssetVersion(content: string): string {\n const view = new DataView(sha1(utf8ToBytes(content)).buffer)\n return `${view.getUint32(0) & MAX_GUID_PART}:${view.getUint32(4) & MAX_GUID_PART}`\n}\n\n/** A collection's asset key: its library key, or else one derived from its ID. */\nexport function collectionAssetKey(collection: Pick<VariableCollection, 'id' | 'key'>): string {\n return collection.key ?? derivedAssetKey(`collection:${collection.id}`)\n}\n\n/** A variable's asset key: its library key, or else one derived from its ID. */\nexport function variableAssetKey(variable: Pick<Variable, 'id' | 'key'>): string {\n return variable.key ?? derivedAssetKey(`variable:${variable.id}`)\n}\n\n/**\n * A shared style's asset key: its library key, or else one derived from its ID, which layers name\n * it by but which can hold characters a key cannot (`S:…,`).\n */\nexport function styleAssetKey(style: Pick<SceneNode, 'id' | 'componentKey' | 'source'>): string {\n return style.componentKey ?? derivedAssetKey(`style:${style.source.id ?? style.id}`)\n}\n"],"mappings":";;;;;;;;AAUA,SAAgB,gBAAgB,MAAsB;CACpD,OAAO,WAAW,KAAK,YAAY,IAAI,CAAC,CAAC;AAC3C;;AAGA,MAAM,gBAAgB;;;;;;;AAQtB,SAAgB,oBAAoB,SAAyB;CAC3D,MAAM,OAAO,IAAI,SAAS,KAAK,YAAY,OAAO,CAAC,CAAC,CAAC,MAAM;CAC3D,OAAO,GAAG,KAAK,UAAU,CAAC,IAAI,cAAc,GAAG,KAAK,UAAU,CAAC,IAAI;AACrE;;AAGA,SAAgB,mBAAmB,YAA4D;CAC7F,OAAO,WAAW,OAAO,gBAAgB,cAAc,WAAW,IAAI;AACxE;;AAGA,SAAgB,iBAAiB,UAAgD;CAC/E,OAAO,SAAS,OAAO,gBAAgB,YAAY,SAAS,IAAI;AAClE;;;;;AAMA,SAAgB,cAAc,OAAkE;CAC9F,OAAO,MAAM,gBAAgB,gBAAgB,SAAS,MAAM,OAAO,MAAM,MAAM,IAAI;AACrF"}
@@ -1,6 +1,6 @@
1
- import { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, BehaviourContract, BehaviourKind, BehaviourPartContract, BehaviourValueContract, BehaviourValueType, INTERACTION_STATES, InteractionState, behaviourContract } from "./kinds.js";
1
+ import { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, BehaviourContract, BehaviourKind, BehaviourPartContract, BehaviourValueContract, BehaviourValueType, INTERACTION_STATES, InteractionState, behaviourContract, hasInvalidState, interactionStatesOf } from "./kinds.js";
2
2
  import { findLayerByPath, hasBehaviour, layerPath } from "./layers.js";
3
3
  import { Behaviour, BehaviourBooleanBinding, BehaviourInteractionStates, BehaviourNumberSettings, BehaviourSpec, behaviourSchema, behaviourSpecSchema, interactionStateValues, isNumberRange } from "./schema.js";
4
4
  import { DEFAULT_NUMBER_SETTINGS, behaviourOwner, behaviourProperties, booleanBinding, emptyBehaviour, guessInteractionStates, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, textBinding, withBehaviour } from "./model.js";
5
5
  import { behaviourFromSpec, behaviourToSpec, guessOnOff } from "./spec.js";
6
- export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, Behaviour, BehaviourBooleanBinding, BehaviourContract, BehaviourInteractionStates, BehaviourKind, BehaviourNumberSettings, BehaviourPartContract, BehaviourSpec, BehaviourValueContract, BehaviourValueType, DEFAULT_NUMBER_SETTINGS, INTERACTION_STATES, InteractionState, behaviourContract, behaviourFromSpec, behaviourOwner, behaviourProperties, behaviourSchema, behaviourSpecSchema, behaviourToSpec, booleanBinding, emptyBehaviour, findLayerByPath, guessInteractionStates, guessOnOff, hasBehaviour, interactionStateValues, isNumberRange, layerPath, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, textBinding, withBehaviour };
6
+ export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, Behaviour, BehaviourBooleanBinding, BehaviourContract, BehaviourInteractionStates, BehaviourKind, BehaviourNumberSettings, BehaviourPartContract, BehaviourSpec, BehaviourValueContract, BehaviourValueType, DEFAULT_NUMBER_SETTINGS, INTERACTION_STATES, InteractionState, behaviourContract, behaviourFromSpec, behaviourOwner, behaviourProperties, behaviourSchema, behaviourSpecSchema, behaviourToSpec, booleanBinding, emptyBehaviour, findLayerByPath, guessInteractionStates, guessOnOff, hasBehaviour, hasInvalidState, interactionStateValues, interactionStatesOf, isNumberRange, layerPath, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, textBinding, withBehaviour };
@@ -1,6 +1,6 @@
1
- import { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, INTERACTION_STATES, behaviourContract } from "./kinds.js";
1
+ import { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, INTERACTION_STATES, behaviourContract, hasInvalidState, interactionStatesOf } from "./kinds.js";
2
2
  import { behaviourSchema, behaviourSpecSchema, interactionStateValues, isNumberRange } from "./schema.js";
3
3
  import { DEFAULT_NUMBER_SETTINGS, behaviourOwner, behaviourProperties, booleanBinding, emptyBehaviour, guessInteractionStates, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, textBinding, withBehaviour } from "./model.js";
4
4
  import { findLayerByPath, hasBehaviour, layerPath } from "./layers.js";
5
5
  import { behaviourFromSpec, behaviourToSpec, guessOnOff } from "./spec.js";
6
- export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, DEFAULT_NUMBER_SETTINGS, INTERACTION_STATES, behaviourContract, behaviourFromSpec, behaviourOwner, behaviourProperties, behaviourSchema, behaviourSpecSchema, behaviourToSpec, booleanBinding, emptyBehaviour, findLayerByPath, guessInteractionStates, guessOnOff, hasBehaviour, interactionStateValues, isNumberRange, layerPath, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, textBinding, withBehaviour };
6
+ export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, DEFAULT_NUMBER_SETTINGS, INTERACTION_STATES, behaviourContract, behaviourFromSpec, behaviourOwner, behaviourProperties, behaviourSchema, behaviourSpecSchema, behaviourToSpec, booleanBinding, emptyBehaviour, findLayerByPath, guessInteractionStates, guessOnOff, hasBehaviour, hasInvalidState, interactionStateValues, interactionStatesOf, isNumberRange, layerPath, missingBindings, numberSettings, partBinding, readBehaviour, renameBehaviourProperties, textBinding, withBehaviour };
@@ -1,12 +1,13 @@
1
1
  //#region src/behaviours/kinds.d.ts
2
2
  /** The controls a main component can behave as, in the order the picker lists them. */
3
- declare const BEHAVIOUR_KINDS: readonly ["button", "textField", "textarea", "numberField", "toggle", "switch", "checkbox", "radio", "radioGroup", "toggleGroup", "slider", "progress", "tabs", "collapsible", "accordion"];
3
+ declare const BEHAVIOUR_KINDS: readonly ["button", "textField", "textarea", "numberField", "toggle", "switch", "checkbox", "radio", "radioGroup", "toggleGroup", "slider", "progress", "tabs", "tab", "collapsible", "accordion"];
4
4
  type BehaviourKind = (typeof BEHAVIOUR_KINDS)[number];
5
5
  /**
6
6
  * The interaction states a control can show, each drawn as a value of one variant property:
7
- * at rest, under the pointer, while pressed, focused from the keyboard, and disabled.
7
+ * at rest, under the pointer, while pressed, focused from the keyboard, disabled, and invalid. Only
8
+ * a form control has an invalid state (`hasInvalidState`), shown while its value fails validation.
8
9
  */
9
- declare const INTERACTION_STATES: readonly ["rest", "hover", "pressed", "focus", "disabled"];
10
+ declare const INTERACTION_STATES: readonly ["rest", "hover", "pressed", "focus", "disabled", "invalid"];
10
11
  type InteractionState = (typeof INTERACTION_STATES)[number];
11
12
  /**
12
13
  * How a behaviour value is held. A boolean is a variant or boolean property of the component,
@@ -31,7 +32,8 @@ interface BehaviourPartContract {
31
32
  required: boolean;
32
33
  /**
33
34
  * Whether the slot holds the control's items, each an instance with its own behaviour (a
34
- * radio, a toggle, a collapsible), which the control turns on and off.
35
+ * radio, a toggle, a collapsible, a tab), which the control turns on and off. A tab list's
36
+ * triggers may also be plain layers, which have no state of their own.
35
37
  */
36
38
  items?: boolean;
37
39
  /**
@@ -51,6 +53,10 @@ interface BehaviourContract {
51
53
  */
52
54
  declare const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContract>>;
53
55
  declare function behaviourContract(kind: BehaviourKind): BehaviourContract;
56
+ /** Whether a kind of control can be invalid: a form control, whose contract has `invalid`. */
57
+ declare function hasInvalidState(kind: BehaviourKind): boolean;
58
+ /** The interaction states a kind of control can show. */
59
+ declare function interactionStatesOf(kind: BehaviourKind): InteractionState[];
54
60
  //#endregion
55
- export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, BehaviourContract, BehaviourKind, BehaviourPartContract, BehaviourValueContract, BehaviourValueType, INTERACTION_STATES, InteractionState, behaviourContract };
61
+ export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, BehaviourContract, BehaviourKind, BehaviourPartContract, BehaviourValueContract, BehaviourValueType, INTERACTION_STATES, InteractionState, behaviourContract, hasInvalidState, interactionStatesOf };
56
62
  //# sourceMappingURL=kinds.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"kinds.d.ts","names":[],"sources":["../../src/behaviours/kinds.ts"],"mappings":";;cACa;KAkBD,wBAAwB;;;;;cAMvB;KAED,2BAA2B;;;;;;;KAQ3B;;UAGK;EACf;EACA,MAAM;;EAEN;;;;;;UAOe;EACf;EACA;;;;;EAKA;;;;;EAKA;;UAGe;EACf,QAAQ;EACR,OAAO;;;;;;;cAqBI,qBAAqB,SAAS,OAAO,eAAe;iBA+FjD,kBAAkB,MAAM,gBAAgB"}
1
+ {"version":3,"file":"kinds.d.ts","names":[],"sources":["../../src/behaviours/kinds.ts"],"mappings":";;cACa;KAmBD,wBAAwB;;;;;;cAOvB;KASD,2BAA2B;;;;;;;KAQ3B;;UAGK;EACf;EACA,MAAM;;EAEN;;;;;;UAOe;EACf;EACA;;;;;;EAMA;;;;;EAKA;;UAGe;EACf,QAAQ;EACR,OAAO;;;;;;;cA2BI,qBAAqB,SAAS,OAAO,eAAe;iBAsFjD,kBAAkB,MAAM,gBAAgB;;iBAKxC,gBAAgB,MAAM;;iBAKtB,oBAAoB,MAAM,gBAAgB"}
@@ -14,20 +14,34 @@ const BEHAVIOUR_KINDS = [
14
14
  "slider",
15
15
  "progress",
16
16
  "tabs",
17
+ "tab",
17
18
  "collapsible",
18
19
  "accordion"
19
20
  ];
20
21
  /**
21
22
  * The interaction states a control can show, each drawn as a value of one variant property:
22
- * at rest, under the pointer, while pressed, focused from the keyboard, and disabled.
23
+ * at rest, under the pointer, while pressed, focused from the keyboard, disabled, and invalid. Only
24
+ * a form control has an invalid state (`hasInvalidState`), shown while its value fails validation.
23
25
  */
24
26
  const INTERACTION_STATES = [
25
27
  "rest",
26
28
  "hover",
27
29
  "pressed",
28
30
  "focus",
29
- "disabled"
31
+ "disabled",
32
+ "invalid"
30
33
  ];
34
+ const DISABLED = {
35
+ id: "disabled",
36
+ type: "boolean",
37
+ required: false
38
+ };
39
+ /** Whether a form control's value fails validation, which code marks with `aria-invalid`. */
40
+ const INVALID = {
41
+ id: "invalid",
42
+ type: "boolean",
43
+ required: false
44
+ };
31
45
  /**
32
46
  * A text field or textarea: its text is a text property, and `filled`, when bound, draws the
33
47
  * empty field with its placeholder.
@@ -44,11 +58,8 @@ const TEXT_INPUT = {
44
58
  type: "boolean",
45
59
  required: false
46
60
  },
47
- {
48
- id: "disabled",
49
- type: "boolean",
50
- required: false
51
- }
61
+ DISABLED,
62
+ INVALID
52
63
  ],
53
64
  parts: []
54
65
  };
@@ -59,11 +70,7 @@ const TEXT_INPUT = {
59
70
  */
60
71
  const BEHAVIOUR_CONTRACTS = {
61
72
  button: {
62
- values: [{
63
- id: "disabled",
64
- type: "boolean",
65
- required: false
66
- }],
73
+ values: [DISABLED],
67
74
  parts: []
68
75
  },
69
76
  textField: TEXT_INPUT,
@@ -80,11 +87,8 @@ const BEHAVIOUR_CONTRACTS = {
80
87
  type: "text",
81
88
  required: true
82
89
  },
83
- {
84
- id: "disabled",
85
- type: "boolean",
86
- required: false
87
- }
90
+ DISABLED,
91
+ INVALID
88
92
  ],
89
93
  parts: [{
90
94
  id: "increment",
@@ -99,64 +103,56 @@ const BEHAVIOUR_CONTRACTS = {
99
103
  id: "value",
100
104
  type: "boolean",
101
105
  required: true
102
- }, {
103
- id: "disabled",
104
- type: "boolean",
105
- required: false
106
- }],
106
+ }, DISABLED],
107
107
  parts: []
108
108
  },
109
109
  switch: {
110
- values: [{
111
- id: "value",
112
- type: "boolean",
113
- required: true
114
- }, {
115
- id: "disabled",
116
- type: "boolean",
117
- required: false
118
- }],
110
+ values: [
111
+ {
112
+ id: "value",
113
+ type: "boolean",
114
+ required: true
115
+ },
116
+ DISABLED,
117
+ INVALID
118
+ ],
119
119
  parts: [{
120
120
  id: "thumb",
121
121
  required: false
122
122
  }]
123
123
  },
124
124
  checkbox: {
125
- values: [{
126
- id: "value",
127
- type: "boolean",
128
- required: true
129
- }, {
130
- id: "disabled",
131
- type: "boolean",
132
- required: false
133
- }],
125
+ values: [
126
+ {
127
+ id: "value",
128
+ type: "boolean",
129
+ required: true
130
+ },
131
+ DISABLED,
132
+ INVALID
133
+ ],
134
134
  parts: [{
135
135
  id: "indicator",
136
136
  required: false
137
137
  }]
138
138
  },
139
139
  radio: {
140
- values: [{
141
- id: "value",
142
- type: "boolean",
143
- required: true
144
- }, {
145
- id: "disabled",
146
- type: "boolean",
147
- required: false
148
- }],
140
+ values: [
141
+ {
142
+ id: "value",
143
+ type: "boolean",
144
+ required: true
145
+ },
146
+ DISABLED,
147
+ INVALID
148
+ ],
149
149
  parts: [{
150
150
  id: "indicator",
151
151
  required: false
152
152
  }]
153
153
  },
154
154
  radioGroup: {
155
- values: [{
156
- id: "disabled",
157
- type: "boolean",
158
- required: false
159
- }],
155
+ values: [DISABLED, INVALID],
160
156
  parts: [{
161
157
  id: "items",
162
158
  required: true,
@@ -165,11 +161,7 @@ const BEHAVIOUR_CONTRACTS = {
165
161
  }]
166
162
  },
167
163
  toggleGroup: {
168
- values: [{
169
- id: "disabled",
170
- type: "boolean",
171
- required: false
172
- }],
164
+ values: [DISABLED],
173
165
  parts: [{
174
166
  id: "items",
175
167
  required: true,
@@ -182,11 +174,7 @@ const BEHAVIOUR_CONTRACTS = {
182
174
  id: "value",
183
175
  type: "number",
184
176
  required: false
185
- }, {
186
- id: "disabled",
187
- type: "boolean",
188
- required: false
189
- }],
177
+ }, DISABLED],
190
178
  parts: [
191
179
  {
192
180
  id: "track",
@@ -211,6 +199,7 @@ const BEHAVIOUR_CONTRACTS = {
211
199
  parts: [{
212
200
  id: "list",
213
201
  required: true,
202
+ items: true,
214
203
  children: "trigger"
215
204
  }, {
216
205
  id: "panels",
@@ -218,6 +207,18 @@ const BEHAVIOUR_CONTRACTS = {
218
207
  children: "content"
219
208
  }]
220
209
  },
210
+ tab: {
211
+ values: [{
212
+ id: "value",
213
+ type: "boolean",
214
+ required: true
215
+ }, {
216
+ id: "disabled",
217
+ type: "boolean",
218
+ required: false
219
+ }],
220
+ parts: []
221
+ },
221
222
  progress: {
222
223
  values: [{
223
224
  id: "value",
@@ -237,11 +238,7 @@ const BEHAVIOUR_CONTRACTS = {
237
238
  id: "open",
238
239
  type: "boolean",
239
240
  required: false
240
- }, {
241
- id: "disabled",
242
- type: "boolean",
243
- required: false
244
- }],
241
+ }, DISABLED],
245
242
  parts: [{
246
243
  id: "trigger",
247
244
  required: true
@@ -251,11 +248,7 @@ const BEHAVIOUR_CONTRACTS = {
251
248
  }]
252
249
  },
253
250
  accordion: {
254
- values: [{
255
- id: "disabled",
256
- type: "boolean",
257
- required: false
258
- }],
251
+ values: [DISABLED],
259
252
  parts: [{
260
253
  id: "items",
261
254
  required: true,
@@ -267,7 +260,15 @@ const BEHAVIOUR_CONTRACTS = {
267
260
  function behaviourContract(kind) {
268
261
  return BEHAVIOUR_CONTRACTS[kind];
269
262
  }
263
+ /** Whether a kind of control can be invalid: a form control, whose contract has `invalid`. */
264
+ function hasInvalidState(kind) {
265
+ return BEHAVIOUR_CONTRACTS[kind].values.some((value) => value.id === "invalid");
266
+ }
267
+ /** The interaction states a kind of control can show. */
268
+ function interactionStatesOf(kind) {
269
+ return INTERACTION_STATES.filter((state) => state !== "invalid" || hasInvalidState(kind));
270
+ }
270
271
  //#endregion
271
- export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, INTERACTION_STATES, behaviourContract };
272
+ export { BEHAVIOUR_CONTRACTS, BEHAVIOUR_KINDS, INTERACTION_STATES, behaviourContract, hasInvalidState, interactionStatesOf };
272
273
 
273
274
  //# sourceMappingURL=kinds.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kinds.js","names":[],"sources":["../../src/behaviours/kinds.ts"],"sourcesContent":["/** The controls a main component can behave as, in the order the picker lists them. */\nexport const BEHAVIOUR_KINDS = [\n 'button',\n 'textField',\n 'textarea',\n 'numberField',\n 'toggle',\n 'switch',\n 'checkbox',\n 'radio',\n 'radioGroup',\n 'toggleGroup',\n 'slider',\n 'progress',\n 'tabs',\n 'collapsible',\n 'accordion'\n] as const\n\nexport type BehaviourKind = (typeof BEHAVIOUR_KINDS)[number]\n\n/**\n * The interaction states a control can show, each drawn as a value of one variant property:\n * at rest, under the pointer, while pressed, focused from the keyboard, and disabled.\n */\nexport const INTERACTION_STATES = ['rest', 'hover', 'pressed', 'focus', 'disabled'] as const\n\nexport type InteractionState = (typeof INTERACTION_STATES)[number]\n\n/**\n * How a behaviour value is held. A boolean is a variant or boolean property of the component,\n * and text is a text property. Figma has no number property, so a number is the behaviour's\n * own (min, max, step, default); a choice is which item of a slot is active, the first by\n * default.\n */\nexport type BehaviourValueType = 'boolean' | 'text' | 'number' | 'choice'\n\n/** A value of the control: its state, which preview reads and changes. */\nexport interface BehaviourValueContract {\n id: string\n type: BehaviourValueType\n /** Whether a boolean or text value must be bound before the behaviour is complete. */\n required: boolean\n}\n\n/**\n * A Reka UI subcomponent of the control, which is a slot of the component: the behaviour binds\n * it to one of the component's slot properties, never to a layer found by name.\n */\nexport interface BehaviourPartContract {\n id: string\n required: boolean\n /**\n * Whether the slot holds the control's items, each an instance with its own behaviour (a\n * radio, a toggle, a collapsible), which the control turns on and off.\n */\n items?: boolean\n /**\n * The Reka UI part each child of the slot is, when the slot holds repeated parts: a tab list's\n * triggers, the tabs' content panels, or a group's items.\n */\n children?: string\n}\n\nexport interface BehaviourContract {\n values: BehaviourValueContract[]\n parts: BehaviourPartContract[]\n}\n\n/**\n * A text field or textarea: its text is a text property, and `filled`, when bound, draws the\n * empty field with its placeholder.\n */\nconst TEXT_INPUT: BehaviourContract = {\n values: [\n { id: 'value', type: 'text', required: true },\n { id: 'filled', type: 'boolean', required: false },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: []\n}\n\n/**\n * The behaviours OpenPencil knows, after Reka UI's primitives. Their states are drawn as the\n * component's variants and properties; their subcomponents (thumb, range, trigger, …) are the\n * component's slots, and the component itself is the control's root.\n */\nexport const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContract>> = {\n button: {\n values: [{ id: 'disabled', type: 'boolean', required: false }],\n parts: []\n },\n textField: TEXT_INPUT,\n textarea: TEXT_INPUT,\n numberField: {\n values: [\n { id: 'value', type: 'number', required: false },\n { id: 'text', type: 'text', required: true },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: [\n { id: 'increment', required: false },\n { id: 'decrement', required: false }\n ]\n },\n toggle: {\n values: [\n { id: 'value', type: 'boolean', required: true },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: []\n },\n switch: {\n values: [\n { id: 'value', type: 'boolean', required: true },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: [{ id: 'thumb', required: false }]\n },\n checkbox: {\n values: [\n { id: 'value', type: 'boolean', required: true },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: [{ id: 'indicator', required: false }]\n },\n radio: {\n values: [\n { id: 'value', type: 'boolean', required: true },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: [{ id: 'indicator', required: false }]\n },\n radioGroup: {\n values: [{ id: 'disabled', type: 'boolean', required: false }],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n },\n toggleGroup: {\n values: [{ id: 'disabled', type: 'boolean', required: false }],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n },\n slider: {\n values: [\n { id: 'value', type: 'number', required: false },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: [\n { id: 'track', required: true },\n { id: 'range', required: false },\n { id: 'thumb', required: true }\n ]\n },\n tabs: {\n values: [{ id: 'value', type: 'choice', required: false }],\n parts: [\n { id: 'list', required: true, children: 'trigger' },\n { id: 'panels', required: false, children: 'content' }\n ]\n },\n progress: {\n values: [{ id: 'value', type: 'number', required: false }],\n parts: [\n { id: 'track', required: true },\n { id: 'indicator', required: true }\n ]\n },\n collapsible: {\n values: [\n { id: 'open', type: 'boolean', required: false },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: [\n { id: 'trigger', required: true },\n { id: 'content', required: true }\n ]\n },\n accordion: {\n values: [{ id: 'disabled', type: 'boolean', required: false }],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n }\n}\n\nexport function behaviourContract(kind: BehaviourKind): BehaviourContract {\n return BEHAVIOUR_CONTRACTS[kind]\n}\n"],"mappings":";;AACA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;AAQA,MAAa,qBAAqB;CAAC;CAAQ;CAAS;CAAW;CAAS;AAAU;;;;;AAgDlF,MAAM,aAAgC;CACpC,QAAQ;EACN;GAAE,IAAI;GAAS,MAAM;GAAQ,UAAU;EAAK;EAC5C;GAAE,IAAI;GAAU,MAAM;GAAW,UAAU;EAAM;EACjD;GAAE,IAAI;GAAY,MAAM;GAAW,UAAU;EAAM;CACrD;CACA,OAAO,CAAC;AACV;;;;;;AAOA,MAAa,sBAA0E;CACrF,QAAQ;EACN,QAAQ,CAAC;GAAE,IAAI;GAAY,MAAM;GAAW,UAAU;EAAM,CAAC;EAC7D,OAAO,CAAC;CACV;CACA,WAAW;CACX,UAAU;CACV,aAAa;EACX,QAAQ;GACN;IAAE,IAAI;IAAS,MAAM;IAAU,UAAU;GAAM;GAC/C;IAAE,IAAI;IAAQ,MAAM;IAAQ,UAAU;GAAK;GAC3C;IAAE,IAAI;IAAY,MAAM;IAAW,UAAU;GAAM;EACrD;EACA,OAAO,CACL;GAAE,IAAI;GAAa,UAAU;EAAM,GACnC;GAAE,IAAI;GAAa,UAAU;EAAM,CACrC;CACF;CACA,QAAQ;EACN,QAAQ,CACN;GAAE,IAAI;GAAS,MAAM;GAAW,UAAU;EAAK,GAC/C;GAAE,IAAI;GAAY,MAAM;GAAW,UAAU;EAAM,CACrD;EACA,OAAO,C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,OAAO,CACL;GAAE,IAAI;GAAQ,UAAU;GAAM,UAAU;EAAU,GAClD;GAAE,IAAI;GAAU,UAAU;GAAO,UAAU;EAAU,CACvD;CACF;CACA,UAAU;EACR,QAAQ,CAAC;GAAE,IAAI;GAAS,MAAM;GAAU,UAAU;EAAM,CAAC;EACzD,OAAO,CACL;GAAE,IAAI;GAAS,UAAU;EAAK,GAC9B;GAAE,IAAI;GAAa,UAAU;EAAK,CACpC;CACF;CACA,aAAa;EACX,QAAQ,CACN;GAAE,IAAI;GAAQ,MAAM;GAAW,UAAU;EAAM,GAC/C;GAAE,IAAI;GAAY,MAAM;GAAW,UAAU;EAAM,CACrD;EACA,OAAO,CACL;GAAE,IAAI;GAAW,UAAU;EAAK,GAChC;GAAE,IAAI;GAAW,UAAU;EAAK,CAClC;CACF;CACA,WAAW;EACT,QAAQ,CAAC;GAAE,IAAI;GAAY,MAAM;GAAW,UAAU;EAAM,CAAC;EAC7D,OAAO,CAAC;GAAE,IAAI;GAAS,UAAU;GAAM,OAAO;GAAM,UAAU;EAAO,CAAC;CACxE;AACF;AAEA,SAAgB,kBAAkB,MAAwC;CACxE,OAAO,oBAAoB;AAC7B"}
1
+ {"version":3,"file":"kinds.js","names":[],"sources":["../../src/behaviours/kinds.ts"],"sourcesContent":["/** The controls a main component can behave as, in the order the picker lists them. */\nexport const BEHAVIOUR_KINDS = [\n 'button',\n 'textField',\n 'textarea',\n 'numberField',\n 'toggle',\n 'switch',\n 'checkbox',\n 'radio',\n 'radioGroup',\n 'toggleGroup',\n 'slider',\n 'progress',\n 'tabs',\n 'tab',\n 'collapsible',\n 'accordion'\n] as const\n\nexport type BehaviourKind = (typeof BEHAVIOUR_KINDS)[number]\n\n/**\n * The interaction states a control can show, each drawn as a value of one variant property:\n * at rest, under the pointer, while pressed, focused from the keyboard, disabled, and invalid. Only\n * a form control has an invalid state (`hasInvalidState`), shown while its value fails validation.\n */\nexport const INTERACTION_STATES = [\n 'rest',\n 'hover',\n 'pressed',\n 'focus',\n 'disabled',\n 'invalid'\n] as const\n\nexport type InteractionState = (typeof INTERACTION_STATES)[number]\n\n/**\n * How a behaviour value is held. A boolean is a variant or boolean property of the component,\n * and text is a text property. Figma has no number property, so a number is the behaviour's\n * own (min, max, step, default); a choice is which item of a slot is active, the first by\n * default.\n */\nexport type BehaviourValueType = 'boolean' | 'text' | 'number' | 'choice'\n\n/** A value of the control: its state, which preview reads and changes. */\nexport interface BehaviourValueContract {\n id: string\n type: BehaviourValueType\n /** Whether a boolean or text value must be bound before the behaviour is complete. */\n required: boolean\n}\n\n/**\n * A Reka UI subcomponent of the control, which is a slot of the component: the behaviour binds\n * it to one of the component's slot properties, never to a layer found by name.\n */\nexport interface BehaviourPartContract {\n id: string\n required: boolean\n /**\n * Whether the slot holds the control's items, each an instance with its own behaviour (a\n * radio, a toggle, a collapsible, a tab), which the control turns on and off. A tab list's\n * triggers may also be plain layers, which have no state of their own.\n */\n items?: boolean\n /**\n * The Reka UI part each child of the slot is, when the slot holds repeated parts: a tab list's\n * triggers, the tabs' content panels, or a group's items.\n */\n children?: string\n}\n\nexport interface BehaviourContract {\n values: BehaviourValueContract[]\n parts: BehaviourPartContract[]\n}\n\nconst DISABLED: BehaviourValueContract = { id: 'disabled', type: 'boolean', required: false }\n\n/** Whether a form control's value fails validation, which code marks with `aria-invalid`. */\nconst INVALID: BehaviourValueContract = { id: 'invalid', type: 'boolean', required: false }\n\n/**\n * A text field or textarea: its text is a text property, and `filled`, when bound, draws the\n * empty field with its placeholder.\n */\nconst TEXT_INPUT: BehaviourContract = {\n values: [\n { id: 'value', type: 'text', required: true },\n { id: 'filled', type: 'boolean', required: false },\n DISABLED,\n INVALID\n ],\n parts: []\n}\n\n/**\n * The behaviours OpenPencil knows, after Reka UI's primitives. Their states are drawn as the\n * component's variants and properties; their subcomponents (thumb, range, trigger, …) are the\n * component's slots, and the component itself is the control's root.\n */\nexport const BEHAVIOUR_CONTRACTS: Readonly<Record<BehaviourKind, BehaviourContract>> = {\n button: {\n values: [DISABLED],\n parts: []\n },\n textField: TEXT_INPUT,\n textarea: TEXT_INPUT,\n numberField: {\n values: [\n { id: 'value', type: 'number', required: false },\n { id: 'text', type: 'text', required: true },\n DISABLED,\n INVALID\n ],\n parts: [\n { id: 'increment', required: false },\n { id: 'decrement', required: false }\n ]\n },\n toggle: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED],\n parts: []\n },\n switch: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],\n parts: [{ id: 'thumb', required: false }]\n },\n checkbox: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],\n parts: [{ id: 'indicator', required: false }]\n },\n radio: {\n values: [{ id: 'value', type: 'boolean', required: true }, DISABLED, INVALID],\n parts: [{ id: 'indicator', required: false }]\n },\n radioGroup: {\n values: [DISABLED, INVALID],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n },\n toggleGroup: {\n values: [DISABLED],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n },\n slider: {\n values: [{ id: 'value', type: 'number', required: false }, DISABLED],\n parts: [\n { id: 'track', required: true },\n { id: 'range', required: false },\n { id: 'thumb', required: true }\n ]\n },\n tabs: {\n values: [{ id: 'value', type: 'choice', required: false }],\n parts: [\n { id: 'list', required: true, items: true, children: 'trigger' },\n { id: 'panels', required: false, children: 'content' }\n ]\n },\n // A tab list's trigger, after Reka's TabsTrigger: on while its tab is the chosen one.\n tab: {\n values: [\n { id: 'value', type: 'boolean', required: true },\n { id: 'disabled', type: 'boolean', required: false }\n ],\n parts: []\n },\n progress: {\n values: [{ id: 'value', type: 'number', required: false }],\n parts: [\n { id: 'track', required: true },\n { id: 'indicator', required: true }\n ]\n },\n collapsible: {\n values: [{ id: 'open', type: 'boolean', required: false }, DISABLED],\n parts: [\n { id: 'trigger', required: true },\n { id: 'content', required: true }\n ]\n },\n accordion: {\n values: [DISABLED],\n parts: [{ id: 'items', required: true, items: true, children: 'item' }]\n }\n}\n\nexport function behaviourContract(kind: BehaviourKind): BehaviourContract {\n return BEHAVIOUR_CONTRACTS[kind]\n}\n\n/** Whether a kind of control can be invalid: a form control, whose contract has `invalid`. */\nexport function hasInvalidState(kind: BehaviourKind): boolean {\n return BEHAVIOUR_CONTRACTS[kind].values.some((value) => value.id === 'invalid')\n}\n\n/** The interaction states a kind of control can show. */\nexport function interactionStatesOf(kind: BehaviourKind): InteractionState[] {\n return INTERACTION_STATES.filter((state) => state !== 'invalid' || hasInvalidState(kind))\n}\n"],"mappings":";;AACA,MAAa,kBAAkB;CAC7B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF;;;;;;AASA,MAAa,qBAAqB;CAChC;CACA;CACA;CACA;CACA;CACA;AACF;AA6CA,MAAM,WAAmC;CAAE,IAAI;CAAY,MAAM;CAAW,UAAU;AAAM;;AAG5F,MAAM,UAAkC;CAAE,IAAI;CAAW,MAAM;CAAW,UAAU;AAAM;;;;;AAM1F,MAAM,aAAgC;CACpC,QAAQ;EACN;GAAE,IAAI;GAAS,MAAM;GAAQ,UAAU;EAAK;EAC5C;GAAE,IAAI;GAAU,MAAM;GAAW,UAAU;EAAM;EACjD;EACA;CACF;CACA,OAAO,CAAC;AACV;;;;;;AAOA,MAAa,sBAA0E;CACrF,QAAQ;EACN,QAAQ,CAAC,QAAQ;EACjB,OAAO,CAAC;CACV;CACA,WAAW;CACX,UAAU;CACV,aAAa;EACX,QAAQ;GACN;IAAE,IAAI;IAAS,MAAM;IAAU,UAAU;GAAM;GAC/C;IAAE,IAAI;IAAQ,MAAM;IAAQ,UAAU;GAAK;GAC3C;GACA;EACF;EACA,OAAO,CACL;GAAE,IAAI;GAAa,UAAU;EAAM,GACnC;GAAE,IAAI;GAAa,UAAU;EAAM,CACrC;CACF;CACA,QAAQ;EACN,QAAQ,CAAC;GAAE,IAAI;GAAS,MAAM;GAAW,UAAU;EAAK,GAAG,QAAQ;EACnE,OAAO,CA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AY,MAAM;GAAW,UAAU;EAAM,CACrD;EACA,OAAO,CAAC;CACV;CACA,UAAU;EACR,QAAQ,CAAC;GAAE,IAAI;GAAS,MAAM;GAAU,UAAU;EAAM,CAAC;EACzD,OAAO,CACL;GAAE,IAAI;GAAS,UAAU;EAAK,GAC9B;GAAE,IAAI;GAAa,UAAU;EAAK,CACpC;CACF;CACA,aAAa;EACX,QAAQ,CAAC;GAAE,IAAI;GAAQ,MAAM;GAAW,UAAU;EAAM,GAAG,QAAQ;EACnE,OAAO,CACL;GAAE,IAAI;GAAW,UAAU;EAAK,GAChC;GAAE,IAAI;GAAW,UAAU;EAAK,CAClC;CACF;CACA,WAAW;EACT,QAAQ,CAAC,QAAQ;EACjB,OAAO,CAAC;GAAE,IAAI;GAAS,UAAU;GAAM,OAAO;GAAM,UAAU;EAAO,CAAC;CACxE;AACF;AAEA,SAAgB,kBAAkB,MAAwC;CACxE,OAAO,oBAAoB;AAC7B;;AAGA,SAAgB,gBAAgB,MAA8B;CAC5D,OAAO,oBAAoB,KAAK,CAAC,OAAO,MAAM,UAAU,MAAM,OAAO,SAAS;AAChF;;AAGA,SAAgB,oBAAoB,MAAyC;CAC3E,OAAO,mBAAmB,QAAQ,UAAU,UAAU,aAAa,gBAAgB,IAAI,CAAC;AAC1F"}
@@ -1 +1 @@
1
- {"version":3,"file":"layers.d.ts","names":[],"sources":["../../src/behaviours/layers.ts"],"mappings":";;;;iBAKgB,aAAa,OAAO,YAAY,MAAM;;;;;;iBAetC,UAAU,OAAO,YAAY,gBAAgB;;iBAgB7C,gBACd,OAAO,YACP,gBACA,eACC"}
1
+ {"version":3,"file":"layers.d.ts","names":[],"sources":["../../src/behaviours/layers.ts"],"mappings":";;;;iBAMgB,aAAa,OAAO,YAAY,MAAM;;;;;;iBAgBtC,UAAU,OAAO,YAAY,gBAAgB;;iBAgB7C,gBACd,OAAO,YACP,gBACA,eACC"}
@@ -1,9 +1,10 @@
1
+ import { instanceMainComponent } from "../instances/main-component.js";
1
2
  import { behaviourOwner, readBehaviour } from "./model.js";
2
3
  //#region src/behaviours/layers.ts
3
4
  /** Whether an instance's main component, or its set, has a behaviour. */
4
5
  function hasBehaviour(graph, node) {
5
- if (node.type !== "INSTANCE" || !node.componentId) return false;
6
- const component = graph.getNode(node.componentId);
6
+ if (node.type !== "INSTANCE") return false;
7
+ const component = instanceMainComponent(graph, node);
7
8
  const owner = component && behaviourOwner(graph, component);
8
9
  return !!owner && !!readBehaviour(owner);
9
10
  }
@@ -1 +1 @@
1
- {"version":3,"file":"layers.js","names":[],"sources":["../../src/behaviours/layers.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { SceneNode } from '../types'\nimport { behaviourOwner, readBehaviour } from './model'\n\n/** Whether an instance's main component, or its set, has a behaviour. */\nexport function hasBehaviour(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type !== 'INSTANCE' || !node.componentId) return false\n const component = graph.getNode(node.componentId)\n const owner = component && behaviourOwner(graph, component)\n return !!owner && !!readBehaviour(owner)\n}\n\n/** A name as a path segment: `/` separates segments and `#` the twin index, so both are escaped. */\nconst pathName = (name: string) => name.replace(/[%/#]/g, (char) => encodeURIComponent(char))\n\n/**\n * A layer's path below a root: the names of the layers down to it, with the position among\n * same-named siblings when names repeat. It stays the same when a variant switch rebuilds an\n * instance's layers, so it identifies controls and keeps their DOM in place.\n */\nexport function layerPath(graph: SceneGraph, rootId: string, nodeId: string): string {\n const segments: string[] = []\n // `closest` stops on a parent cycle in bad data, where a hand-written walk would not.\n graph.closest(nodeId, (node) => {\n if (node.id === rootId) return true\n const twins = node.parentId\n ? graph.getChildren(node.parentId).filter((child) => child.name === node.name)\n : []\n const index = twins.findIndex((child) => child.id === node.id)\n segments.unshift(twins.length > 1 ? `${pathName(node.name)}#${index}` : pathName(node.name))\n return false\n })\n return segments.join('/')\n}\n\n/** The layer at `path` below a root, the inverse of `layerPath`. */\nexport function findLayerByPath(\n graph: SceneGraph,\n rootId: string,\n path: string\n): SceneNode | undefined {\n let current = graph.getNode(rootId)\n for (const segment of path ? path.split('/') : []) {\n if (!current) return undefined\n const hash = segment.lastIndexOf('#')\n const name = hash === -1 ? segment : segment.slice(0, hash)\n const twins = graph.getChildren(current.id).filter((child) => pathName(child.name) === name)\n current = twins.at(hash === -1 ? 0 : Number(segment.slice(hash + 1)))\n }\n return current\n}\n"],"mappings":";;;AAKA,SAAgB,aAAa,OAAmB,MAA0B;CACxE,IAAI,KAAK,SAAS,cAAc,CAAC,KAAK,aAAa,OAAO;CAC1D,MAAM,YAAY,MAAM,QAAQ,KAAK,WAAW;CAChD,MAAM,QAAQ,aAAa,eAAe,OAAO,SAAS;CAC1D,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,cAAc,KAAK;AACzC;;AAGA,MAAM,YAAY,SAAiB,KAAK,QAAQ,WAAW,SAAS,mBAAmB,IAAI,CAAC;;;;;;AAO5F,SAAgB,UAAU,OAAmB,QAAgB,QAAwB;CACnF,MAAM,WAAqB,CAAC;CAE5B,MAAM,QAAQ,SAAS,SAAS;EAC9B,IAAI,KAAK,OAAO,QAAQ,OAAO;EAC/B,MAAM,QAAQ,KAAK,WACf,MAAM,YAAY,KAAK,QAAQ,CAAC,CAAC,QAAQ,UAAU,MAAM,SAAS,KAAK,IAAI,IAC3E,CAAC;EACL,MAAM,QAAQ,MAAM,WAAW,UAAU,MAAM,OAAO,KAAK,EAAE;EAC7D,SAAS,QAAQ,MAAM,SAAS,IAAI,GAAG,SAAS,KAAK,IAAI,EAAE,GAAG,UAAU,SAAS,KAAK,IAAI,CAAC;EAC3F,OAAO;CACT,CAAC;CACD,OAAO,SAAS,KAAK,GAAG;AAC1B;;AAGA,SAAgB,gBACd,OACA,QACA,MACuB;CACvB,IAAI,UAAU,MAAM,QAAQ,MAAM;CAClC,KAAK,MAAM,WAAW,OAAO,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG;EACjD,IAAI,CAAC,SAAS,OAAO,KAAA;EACrB,MAAM,OAAO,QAAQ,YAAY,GAAG;EACpC,MAAM,OAAO,SAAS,KAAK,UAAU,QAAQ,MAAM,GAAG,IAAI;EAE1D,UADc,MAAM,YAAY,QAAQ,EAAE,CAAC,CAAC,QAAQ,UAAU,SAAS,MAAM,IAAI,MAAM,IACzE,CAAC,CAAC,GAAG,SAAS,KAAK,IAAI,OAAO,QAAQ,MAAM,OAAO,CAAC,CAAC,CAAC;CACtE;CACA,OAAO;AACT"}
1
+ {"version":3,"file":"layers.js","names":[],"sources":["../../src/behaviours/layers.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { instanceMainComponent } from '../instances/main-component'\nimport type { SceneNode } from '../types'\nimport { behaviourOwner, readBehaviour } from './model'\n\n/** Whether an instance's main component, or its set, has a behaviour. */\nexport function hasBehaviour(graph: SceneGraph, node: SceneNode): boolean {\n if (node.type !== 'INSTANCE') return false\n // A copy of a nested instance names the instance it copies, so follow it to the component.\n const component = instanceMainComponent(graph, node)\n const owner = component && behaviourOwner(graph, component)\n return !!owner && !!readBehaviour(owner)\n}\n\n/** A name as a path segment: `/` separates segments and `#` the twin index, so both are escaped. */\nconst pathName = (name: string) => name.replace(/[%/#]/g, (char) => encodeURIComponent(char))\n\n/**\n * A layer's path below a root: the names of the layers down to it, with the position among\n * same-named siblings when names repeat. It stays the same when a variant switch rebuilds an\n * instance's layers, so it identifies controls and keeps their DOM in place.\n */\nexport function layerPath(graph: SceneGraph, rootId: string, nodeId: string): string {\n const segments: string[] = []\n // `closest` stops on a parent cycle in bad data, where a hand-written walk would not.\n graph.closest(nodeId, (node) => {\n if (node.id === rootId) return true\n const twins = node.parentId\n ? graph.getChildren(node.parentId).filter((child) => child.name === node.name)\n : []\n const index = twins.findIndex((child) => child.id === node.id)\n segments.unshift(twins.length > 1 ? `${pathName(node.name)}#${index}` : pathName(node.name))\n return false\n })\n return segments.join('/')\n}\n\n/** The layer at `path` below a root, the inverse of `layerPath`. */\nexport function findLayerByPath(\n graph: SceneGraph,\n rootId: string,\n path: string\n): SceneNode | undefined {\n let current = graph.getNode(rootId)\n for (const segment of path ? path.split('/') : []) {\n if (!current) return undefined\n const hash = segment.lastIndexOf('#')\n const name = hash === -1 ? segment : segment.slice(0, hash)\n const twins = graph.getChildren(current.id).filter((child) => pathName(child.name) === name)\n current = twins.at(hash === -1 ? 0 : Number(segment.slice(hash + 1)))\n }\n return current\n}\n"],"mappings":";;;;AAMA,SAAgB,aAAa,OAAmB,MAA0B;CACxE,IAAI,KAAK,SAAS,YAAY,OAAO;CAErC,MAAM,YAAY,sBAAsB,OAAO,IAAI;CACnD,MAAM,QAAQ,aAAa,eAAe,OAAO,SAAS;CAC1D,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,cAAc,KAAK;AACzC;;AAGA,MAAM,YAAY,SAAiB,KAAK,QAAQ,WAAW,SAAS,mBAAmB,IAAI,CAAC;;;;;;AAO5F,SAAgB,UAAU,OAAmB,QAAgB,QAAwB;CACnF,MAAM,WAAqB,CAAC;CAE5B,MAAM,QAAQ,SAAS,SAAS;EAC9B,IAAI,KAAK,OAAO,QAAQ,OAAO;EAC/B,MAAM,QAAQ,KAAK,WACf,MAAM,YAAY,KAAK,QAAQ,CAAC,CAAC,QAAQ,UAAU,MAAM,SAAS,KAAK,IAAI,IAC3E,CAAC;EACL,MAAM,QAAQ,MAAM,WAAW,UAAU,MAAM,OAAO,KAAK,EAAE;EAC7D,SAAS,QAAQ,MAAM,SAAS,IAAI,GAAG,SAAS,KAAK,IAAI,EAAE,GAAG,UAAU,SAAS,KAAK,IAAI,CAAC;EAC3F,OAAO;CACT,CAAC;CACD,OAAO,SAAS,KAAK,GAAG;AAC1B;;AAGA,SAAgB,gBACd,OACA,QACA,MACuB;CACvB,IAAI,UAAU,MAAM,QAAQ,MAAM;CAClC,KAAK,MAAM,WAAW,OAAO,KAAK,MAAM,GAAG,IAAI,CAAC,GAAG;EACjD,IAAI,CAAC,SAAS,OAAO,KAAA;EACrB,MAAM,OAAO,QAAQ,YAAY,GAAG;EACpC,MAAM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