@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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shapes.js","names":[],"sources":["../../src/outline/shapes.ts"],"sourcesContent":["import { polygonOutline } from '../polygon'\nimport type { Vector } from '../primitives'\nimport type { SceneNode, WindingRule } from '../types'\nimport {\n arcPoints,\n blobContours,\n commandContours,\n loopPoints,\n segmentPoints,\n segmentRuns\n} from './flatten'\n\n/** Contours filled together under one winding rule. */\nexport interface OutlineArea {\n windingRule: WindingRule\n contours: Vector[][]\n}\n\n/**\n * A shape's geometry in its own coordinates, curves flattened: the areas its fills cover and the\n * lines its strokes follow, closed contours ending where they began.\n */\nexport interface ShapeOutline {\n areas: OutlineArea[]\n lines: Vector[][]\n /** Each line's own stroke weight, where sides differ, as a rectangle's independent borders. */\n lineWeights?: number[]\n /**\n * Strokes centre on the lines whatever their alignment, as on a network without regions that is\n * open or has no saved stroke geometry.\n */\n strokeCentered?: boolean\n /** For each line, whether its start and its end are open ends, where a stroke's cap is drawn. */\n lineEnds?: Array<[boolean, boolean]>\n /** The saved outline a stroke fills, for a shape whose stroke has no lines to follow. */\n strokeAreas?: OutlineArea[]\n}\n\nfunction closed(contour: Vector[]): Vector[] {\n const first = contour.at(0)\n const last = contour.at(-1)\n if (!first || !last || (first.x === last.x && first.y === last.y)) return contour\n return [...contour, first]\n}\n\nfunction fromContours(contours: Vector[][], windingRule: WindingRule = 'NONZERO'): ShapeOutline {\n return { areas: [{ windingRule, contours }], lines: contours.map(closed) }\n}\n\nfunction cornerRadii(node: SceneNode): [number, number, number, number] {\n const radii: [number, number, number, number] = node.independentCorners\n ? [node.topLeftRadius, node.topRightRadius, node.bottomRightRadius, node.bottomLeftRadius]\n : [node.cornerRadius, node.cornerRadius, node.cornerRadius, node.cornerRadius]\n const limit = Math.min(node.width, node.height) / 2\n return radii.map((radius) => Math.max(0, Math.min(radius, limit))) as typeof radii\n}\n\nfunction rectangleContour(node: SceneNode, tolerance: number): Vector[] {\n const { width: w, height: h } = node\n const [tl, tr, br, bl] = cornerRadii(node)\n const corner = (cx: number, cy: number, r: number, from: number): Vector[] =>\n r > 0 ? arcPoints(cx, cy, r, r, from, from + Math.PI / 2, tolerance) : [{ x: cx, y: cy }]\n return [\n ...corner(w - tr, tr, tr, -Math.PI / 2),\n ...corner(w - br, h - br, br, 0),\n ...corner(bl, h - bl, bl, Math.PI / 2),\n ...corner(tl, tl, tl, Math.PI)\n ]\n}\n\n/**\n * A rectangle's four sides with the weight each draws its border at: top, right, bottom, left.\n * Each side runs from the middle of one rounded corner to the middle of the next, as its border\n * is drawn round them.\n */\nfunction rectangleSides(\n node: SceneNode,\n tolerance: number\n): Pick<ShapeOutline, 'lines' | 'lineWeights'> {\n const { width: w, height: h } = node\n const [tl, tr, br, bl] = cornerRadii(node)\n const quarter = Math.PI / 4\n const arc = (cx: number, cy: number, r: number, from: number): Vector[] =>\n r > 0 ? arcPoints(cx, cy, r, r, from, from + quarter, tolerance) : [{ x: cx, y: cy }]\n return {\n lines: [\n [...arc(tl, tl, tl, 5 * quarter), ...arc(w - tr, tr, tr, -2 * quarter)],\n [...arc(w - tr, tr, tr, -quarter), ...arc(w - br, h - br, br, 0)],\n [...arc(w - br, h - br, br, quarter), ...arc(bl, h - bl, bl, 2 * quarter)],\n [...arc(bl, h - bl, bl, 3 * quarter), ...arc(tl, tl, tl, 4 * quarter)]\n ],\n lineWeights: [\n node.borderTopWeight,\n node.borderRightWeight,\n node.borderBottomWeight,\n node.borderLeftWeight\n ]\n }\n}\n\nconst FULL_TURN = Math.PI * 2\n\nfunction ellipseContours(node: SceneNode, tolerance: number): Vector[][] {\n const rx = node.width / 2\n const ry = node.height / 2\n const arc = node.arcData\n const start = arc?.startingAngle ?? 0\n const end = arc?.endingAngle ?? FULL_TURN\n const inner = arc?.innerRadius ?? 0\n const whole = Math.abs(end - start) >= FULL_TURN - 1e-6\n const outer = arcPoints(rx, ry, rx, ry, start, whole ? start + FULL_TURN : end, tolerance)\n if (inner <= 0) return [whole ? outer : [{ x: rx, y: ry }, ...outer]]\n const hole = arcPoints(\n rx,\n ry,\n rx * inner,\n ry * inner,\n whole ? start + FULL_TURN : end,\n start,\n tolerance\n )\n // A whole ring is two loops wound opposite ways; a part ring is one outline across its ends.\n return whole ? [outer, hole] : [[...outer, ...hole]]\n}\n\nfunction vectorOutline(node: SceneNode, tolerance: number): ShapeOutline | null {\n const network = node.vectorNetwork\n const geometry = node.fillGeometry.map((path) => ({\n windingRule: path.windingRule,\n contours: path.commandsBlob.length > 0 ? blobContours(path.commandsBlob, tolerance) : []\n }))\n if (!network) {\n if (geometry.length === 0 && node.strokeGeometry.length === 0) return null\n // Without a network the renderer fills the saved stroke geometry, or draws no stroke.\n const strokeAreas = node.strokeGeometry.map((path) => ({\n windingRule: path.windingRule,\n contours: path.commandsBlob.length > 0 ? blobContours(path.commandsBlob, tolerance) : []\n }))\n return { areas: geometry, lines: [], strokeAreas }\n }\n // A vertex on one segment only is an open end.\n const degree = new Map<number, number>()\n for (const segment of network.segments) {\n degree.set(segment.start, (degree.get(segment.start) ?? 0) + 1)\n degree.set(segment.end, (degree.get(segment.end) ?? 0) + 1)\n }\n const lines: Vector[][] = []\n const lineEnds: Array<[boolean, boolean]> = []\n for (const [index, segment] of network.segments.entries()) {\n const points = segmentPoints(network, index, tolerance)\n if (!points) continue\n lines.push(points)\n lineEnds.push([degree.get(segment.start) === 1, degree.get(segment.end) === 1])\n }\n // Without regions the stroke draws centred on each segment, unless a closed network carries\n // saved stroke geometry, which the renderer draws with its alignment.\n const open = lineEnds.some(([start, end]) => start || end)\n const strokeCentered = network.regions.length === 0 && (open || node.strokeGeometry.length === 0)\n if (geometry.length > 0) return { areas: geometry, lines, lineEnds, strokeCentered }\n const areas =\n network.regions.length > 0\n ? network.regions.map((region) => ({\n windingRule: region.windingRule,\n contours: region.loops.map((loop) => loopPoints(network, loop, tolerance))\n }))\n : // Without regions a fill closes each run of segments, as a path fill does.\n [{ windingRule: 'NONZERO' as const, contours: segmentRuns(network, tolerance) }]\n return { areas, lines, lineEnds, strokeCentered }\n}\n\n/**\n * The outline a click is tested against, in the node's own coordinates, with curves within\n * `tolerance` of the shape; null for layers tested by their box, such as text.\n */\nexport function shapeOutline(node: SceneNode, tolerance: number): ShapeOutline | null {\n switch (node.type) {\n case 'RECTANGLE':\n case 'ROUNDED_RECTANGLE': {\n const outline = fromContours([rectangleContour(node, tolerance)])\n return node.independentStrokeWeights\n ? { ...outline, ...rectangleSides(node, tolerance) }\n : outline\n }\n case 'ELLIPSE': {\n if (node.fillGeometry.length > 0) return vectorOutline(node, tolerance)\n return fromContours(ellipseContours(node, tolerance))\n }\n case 'POLYGON':\n case 'STAR':\n return fromContours(commandContours(polygonOutline(node), tolerance))\n case 'LINE':\n return {\n areas: [],\n lines: [\n [\n { x: 0, y: 0 },\n { x: node.width, y: node.height }\n ]\n ],\n lineEnds: [[true, true]]\n }\n case 'VECTOR':\n return vectorOutline(node, tolerance)\n default:\n return null\n }\n}\n"],"mappings":";;;AAsCA,SAAS,OAAO,SAA6B;CAC3C,MAAM,QAAQ,QAAQ,GAAG,CAAC;CAC1B,MAAM,OAAO,QAAQ,GAAG,EAAE;CAC1B,IAAI,CAAC,SAAS,CAAC,QAAS,MAAM,MAAM,KAAK,KAAK,MAAM,MAAM,KAAK,GAAI,OAAO;CAC1E,OAAO,CAAC,GAAG,SAAS,KAAK;AAC3B;AAEA,SAAS,aAAa,UAAsB,cAA2B,WAAyB;CAC9F,OAAO;EAAE,OAAO,CAAC;GAAE;GAAa;EAAS,CAAC;EAAG,OAAO,SAAS,IAAI,MAAM;CAAE;AAC3E;AAEA,SAAS,YAAY,MAAmD;CACtE,MAAM,QAA0C,KAAK,qBACjD;EAAC,KAAK;EAAe,KAAK;EAAgB,KAAK;EAAmB,KAAK;CAAgB,IACvF;EAAC,KAAK;EAAc,KAAK;EAAc,KAAK;EAAc,KAAK;CAAY;CAC/E,MAAM,QAAQ,KAAK,IAAI,KAAK,OAAO,KAAK,MAAM,IAAI;CAClD,OAAO,MAAM,KAAK,WAAW,KAAK,IAAI,GAAG,KAAK,IAAI,QAAQ,KAAK,CAAC,CAAC;AACnE;AAEA,SAAS,iBAAiB,MAAiB,WAA6B;CACtE,MAAM,EAAE,OAAO,GAAG,QAAQ,MAAM;CAChC,MAAM,CAAC,IAAI,IAAI,IAAI,MAAM,YAAY,IAAI;CACzC,MAAM,UAAU,IAAY,IAAY,GAAW,SACjD,IAAI,IAAI,UAAU,IAAI,IAAI,GAAG,GAAG,MAAM,OAAO,KAAK,KAAK,GA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GACtE,OAAO,aAAa,gBAAgB,MAAM,SAAS,CAAC;EAEtD,KAAK;EACL,KAAK,QACH,OAAO,aAAa,gBAAgB,eAAe,IAAI,GAAG,SAAS,CAAC;EACtE,KAAK,QACH,OAAO;GACL,OAAO,CAAC;GACR,OAAO,CACL,CACE;IAAE,GAAG;IAAG,GAAG;GAAE,GACb;IAAE,GAAG,KAAK;IAAO,GAAG,KAAK;GAAO,CAClC,CACF;GACA,UAAU,CAAC,CAAC,MAAM,IAAI,CAAC;EACzB;EACF,KAAK,UACH,OAAO,cAAc,MAAM,SAAS;EACtC,SACE,OAAO;CACX;AACF"}
@@ -33,6 +33,8 @@ declare const OPEN_PENCIL_PLUGIN_DATA: {
33
33
  textPathBox: PluginDataField<Rect>;
34
34
  /** The library asset a node was inserted from. */
35
35
  librarySource: PluginDataField<LibraryAssetSource>;
36
+ /** The library source layer a library definition's layer copies, on every definition layer. */
37
+ libraryLayer: PluginDataField<string>;
36
38
  /**
37
39
  * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the
38
40
  * root keeps it across a save as every layer keeps its GUID.
@@ -74,7 +76,7 @@ declare const OPEN_PENCIL_PLUGIN_DATA: {
74
76
  okhcl: PluginDataField<OkHCLPayload>;
75
77
  /** How a main component or component set behaves as a control in preview. */
76
78
  behaviour: PluginDataField<{
77
- kind: "button" | "textField" | "textarea" | "numberField" | "toggle" | "switch" | "checkbox" | "radio" | "radioGroup" | "toggleGroup" | "slider" | "progress" | "tabs" | "collapsible" | "accordion";
79
+ kind: "button" | "textField" | "textarea" | "numberField" | "toggle" | "switch" | "checkbox" | "radio" | "radioGroup" | "toggleGroup" | "slider" | "progress" | "tabs" | "tab" | "collapsible" | "accordion";
78
80
  booleans: {
79
81
  [x: string]: {
80
82
  propertyId: string;
@@ -104,6 +106,7 @@ declare const OPEN_PENCIL_PLUGIN_DATA: {
104
106
  pressed?: string | undefined;
105
107
  focus?: string | undefined;
106
108
  disabled?: string | undefined;
109
+ invalid?: string | undefined;
107
110
  propertyId: string;
108
111
  } | undefined;
109
112
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/plugin-data/fields.ts"],"mappings":";;;;;;;UAyGiB;EACf,OAAO;EACP,cAAc;IAAiB;IAAa;;;;;;;;cAuCjC;;iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBA0EG,kBAAkB,kBAAkB,oBAAoB"}
1
+ {"version":3,"file":"fields.d.ts","names":[],"sources":["../../src/plugin-data/fields.ts"],"mappings":";;;;;;;UAsHiB;EACf,OAAO;EACP,cAAc;IAAiB;IAAa;;;;;;;;cAuCjC;;iBAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;iBAgFG,kBAAkB,kBAAkB,oBAAoB"}
@@ -26,10 +26,25 @@ const boundVariablesSchema = v.pipe(v.custom((value) => typeof value === "object
26
26
  /** Every entry must be valid, or the whole value is ignored in favour of native settings. */
27
27
  const exportSettingsSchema = v.array(v.pipe(v.object({
28
28
  scale: v.pipe(v.number(), v.finite()),
29
- format: v.custom(isExportFormatId)
30
- }), v.transform(({ scale, format }) => ({
31
- scale: clampExportScale(scale),
32
- format
29
+ format: v.custom(isExportFormatId),
30
+ suffix: v.optional(v.string()),
31
+ size: v.optional(v.object({
32
+ type: v.picklist(["WIDTH", "HEIGHT"]),
33
+ value: v.pipe(v.number(), v.finite())
34
+ })),
35
+ contentsOnly: v.optional(v.boolean()),
36
+ useAbsoluteBounds: v.optional(v.boolean()),
37
+ colorProfile: v.optional(v.picklist([
38
+ "DOCUMENT",
39
+ "SRGB",
40
+ "DISPLAY_P3_V4"
41
+ ])),
42
+ svgOutlineText: v.optional(v.boolean()),
43
+ svgIdAttribute: v.optional(v.boolean()),
44
+ svgSimplifyStroke: v.optional(v.boolean())
45
+ }), v.transform((setting) => ({
46
+ ...setting,
47
+ scale: clampExportScale(setting.scale)
33
48
  }))));
34
49
  const librarySourceSchema = v.pipe(v.object({
35
50
  identity: v.object({
@@ -104,6 +119,8 @@ const OPEN_PENCIL_PLUGIN_DATA = {
104
119
  textPathBox: jsonPluginDataField("textPathBox", "format", textPathBoxSchema),
105
120
  /** The library asset a node was inserted from. */
106
121
  librarySource: jsonPluginDataField("librarySource", "bookkeeping", librarySourceSchema),
122
+ /** The library source layer a library definition's layer copies, on every definition layer. */
123
+ libraryLayer: jsonPluginDataField("libraryLayer", "bookkeeping", v.pipe(v.string(), v.nonEmpty(), v.maxLength(1024))),
107
124
  /**
108
125
  * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the
109
126
  * root keeps it across a save as every layer keeps its GUID.
@@ -1 +1 @@
1
- {"version":3,"file":"fields.js","names":[],"sources":["../../src/plugin-data/fields.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { behaviourSchema } from '../behaviours/schema'\nimport type { OkHCLPayload } from '../color/okhcl'\nimport { commentThreadsSchema } from '../comments/schema'\nimport { isExportFormatId, type ExportFormatId } from '../export-format'\nimport { clampExportScale } from '../export-scale'\nimport { FIG_COMPRESSIONS } from '../fig-compression'\nimport { iconSchema, iconTintSchema } from '../icons/schema'\nimport type { Rect } from '../primitives'\nimport { shaderPaintSchema } from '../shaders/schema'\nimport { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'\nimport {\n MODE_ATTRIBUTE_PATTERN,\n TOKEN_UNITS,\n type EnabledLibraryBinding,\n type ExportSetting,\n type LayoutDirection,\n type LibraryAssetSource,\n type PluginDataEntry,\n type SourceLibraryPublication,\n type TextDirection,\n type TokenUnit\n} from '../types'\nimport {\n jsonPluginDataField,\n textPluginDataField,\n withoutPluginData,\n type PluginDataKey\n} from './field'\n\nconst DIRECTIONS = ['AUTO', 'LTR', 'RTL'] as const satisfies readonly (\n | TextDirection\n | LayoutDirection\n)[]\n\nconst textPathBoxSchema: v.GenericSchema<unknown, Rect> = v.pipe(\n v.object({ x: v.number(), y: v.number(), width: v.number(), height: v.number() }),\n v.check(\n ({ x, y, width, height }) => Number.isFinite(x + y + width + height) && width > 0 && height > 0\n )\n)\n\n/** String-valued entries of a JSON object; other entries are dropped, not rejected. */\nconst boundVariablesSchema = v.pipe(\n v.custom<Record<string, unknown>>(\n (value) => typeof value === 'object' && value !== null && !Array.isArray(value)\n ),\n v.transform((value) =>\n Object.fromEntries(\n Object.entries(value).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n )\n )\n )\n)\n\n/** Every entry must be valid, or the whole value is ignored in favour of native settings. */\nconst exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(\n v.pipe(\n v.object({\n scale: v.pipe(v.number(), v.finite()),\n format: v.custom<ExportFormatId>(isExportFormatId)\n }),\n // Clamp at the file boundary: imported plugin data may carry a scale the UI never produces.\n v.transform(({ scale, format }) => ({ scale: clampExportScale(scale), format }))\n )\n)\n\nconst librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe(\n v.object({\n identity: v.object({ libraryId: v.string(), assetKey: v.string(), revisionId: v.string() }),\n sourceNodeId: v.optional(v.unknown()),\n readOnly: v.optional(v.unknown())\n }),\n v.transform(({ identity, sourceNodeId, readOnly }) => ({\n identity,\n sourceNodeId: typeof sourceNodeId === 'string' ? sourceNodeId : null,\n readOnly: readOnly === true\n }))\n)\n\nconst enabledLibrarySchema = v.object({\n libraryId: v.string(),\n revisionId: v.string(),\n enabled: v.optional(v.unknown())\n})\n\n/** Invalid entries are skipped one by one, so one bad binding keeps the others. */\nconst enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(enabledLibrarySchema, item)\n if (!parsed.success) return []\n const { libraryId, revisionId, enabled } = parsed.output\n return [{ libraryId, revisionId, enabled: enabled === true }]\n })\n )\n)\n\n// Shape only. Whether a string is valid CSS is checked where it is written into a stylesheet.\nconst cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1000))\n\n/** Token fields Figma has no slot for, with mode ids as the file spells them. */\nexport interface StoredToken {\n unit?: TokenUnit\n expressions?: Record<string, { css: string; resolved?: number }>\n}\n\nconst tokenSchema: v.GenericSchema<unknown, StoredToken> = v.object({\n unit: v.optional(v.picklist(TOKEN_UNITS)),\n expressions: v.optional(\n v.record(\n v.string(),\n v.object({ css: cssTextSchema, resolved: v.optional(v.pipe(v.number(), v.finite())) })\n )\n )\n})\n\nconst okhclSchema: v.GenericSchema<unknown, OkHCLPayload> = v.object({\n version: v.literal(1),\n kind: v.picklist(['fill', 'stroke']),\n index: v.number(),\n color: v.object({\n h: v.number(),\n c: v.number(),\n l: v.number(),\n a: v.fallback(v.optional(v.number()), undefined)\n })\n})\n\nconst sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> = v.object(\n {\n libraryId: v.string(),\n revisionId: v.string(),\n name: v.string(),\n catalogSource: v.optional(v.string())\n }\n)\n\n/**\n * Every plugin-data entry OpenPencil writes under {@link OPEN_PENCIL_PLUGIN_ID}: state Figma's\n * format has no field for. Add a key here, never as a string elsewhere, so reading and writing\n * it share one schema.\n */\nexport const OPEN_PENCIL_PLUGIN_DATA = {\n /** A text node's direction, on TEXT nodes. */\n textDirection: textPluginDataField('textDirection', 'format', DIRECTIONS),\n /** An auto-layout frame's direction. */\n layoutDirection: textPluginDataField('layoutDirection', 'format', DIRECTIONS),\n /** Marks a component set Figma would read as a plain frame. */\n nodeType: textPluginDataField('nodeType', 'format', ['COMPONENT_SET']),\n /** Variable bindings by field path, including those Figma cannot store natively. */\n boundVariables: jsonPluginDataField('boundVariables', 'format', boundVariablesSchema),\n exportSettings: jsonPluginDataField('exportSettings', 'format', exportSettingsSchema),\n /** The node-local rect a TEXT_PATH layout maps onto, which Kiwi has no field for. */\n textPathBox: jsonPluginDataField('textPathBox', 'format', textPathBoxSchema),\n /** The library asset a node was inserted from. */\n librarySource: jsonPluginDataField('librarySource', 'bookkeeping', librarySourceSchema),\n /**\n * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the\n * root keeps it across a save as every layer keeps its GUID.\n */\n documentId: jsonPluginDataField(\n 'documentId',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))\n ),\n /** Libraries enabled for the document, on the DOCUMENT node. */\n enabledLibraries: jsonPluginDataField('enabledLibraries', 'bookkeeping', enabledLibrariesSchema),\n /** The library this document publishes as, on the DOCUMENT node. */\n sourceLibraryPublication: jsonPluginDataField(\n 'sourceLibraryPublication',\n 'bookkeeping',\n sourceLibraryPublicationSchema\n ),\n /** Canvas comment threads, deleted ones included, on the DOCUMENT node. */\n comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),\n /** The statuses layers can be in, on the DOCUMENT node. */\n statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),\n /** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */\n figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),\n /** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */\n status: jsonPluginDataField('status', 'format', nodeStatusSchema),\n /** Unit and CSS expressions, on each VARIABLE. */\n token: jsonPluginDataField('token', 'format', tokenSchema),\n /** Mode conditions by mode id, on each VARIABLE_SET. */\n modeConditions: jsonPluginDataField(\n 'modeConditions',\n 'format',\n v.record(v.string(), cssTextSchema)\n ),\n /** The attribute that switches manual modes, on each VARIABLE_SET. */\n modeAttribute: jsonPluginDataField(\n 'modeAttribute',\n 'format',\n v.pipe(v.string(), v.trim(), v.maxLength(100), v.regex(MODE_ATTRIBUTE_PATTERN))\n ),\n /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */\n okhcl: jsonPluginDataField('okhcl', 'content', okhclSchema),\n /** How a main component or component set behaves as a control in preview. */\n behaviour: jsonPluginDataField('behaviour', 'content', behaviourSchema),\n /** The icon a frame draws, such as `lucide:home`, on the frame its paths are in. */\n icon: jsonPluginDataField('icon', 'content', iconSchema),\n /** Which of an icon path's paints its icon's color sets, on each path the source drew in it. */\n iconTint: jsonPluginDataField('iconTint', 'content', iconTintSchema),\n /** One entry per paint that draws a shader, matched to its image paint by the frame's hash. */\n shader: jsonPluginDataField('shader', 'content', shaderPaintSchema)\n} satisfies Record<string, PluginDataKey>\n\nconst NOT_CONTENT = Object.values(OPEN_PENCIL_PLUGIN_DATA).filter(\n (field) => field.role !== 'content'\n)\n\n/**\n * A node's plugin data that is part of its content, in a stable order: OpenPencil's content\n * fields and every other plugin's entries, which the node carries wherever it goes. Format\n * copies of node fields and bookkeeping are left out.\n */\nexport function contentPluginData(entries: readonly PluginDataEntry[]): PluginDataEntry[] {\n return withoutPluginData(entries, NOT_CONTENT).sort(\n (a, b) => a.pluginId.localeCompare(b.pluginId) || a.key.localeCompare(b.key)\n )\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,MAAM,aAAa;CAAC;CAAQ;CAAO;AAAK;AAKxC,MAAM,oBAAoD,EAAE,KAC1D,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,OAAO,EAAE,OAAO;CAAG,QAAQ,EAAE,OAAO;AAAE,CAAC,GAChF,EAAE,OACC,EAAE,GAAG,GAAG,OAAO,aAAa,OAAO,SAAS,IAAI,IAAI,QAAQ,MAAM,KAAK,QAAQ,KAAK,SAAS,CAChG,CACF;;AAGA,MAAM,uBAAuB,EAAE,KAC7B,EAAE,QACC,UAAU,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,CAChF,GACA,EAAE,WAAW,UACX,OAAO,YACL,OAAO,QAAQ,KAAK,CAAC,C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A,kBAAkB,oBAAoB,oBAAoB,eAAe,sBAAsB;;CAE/F,0BAA0B,oBACxB,4BACA,eACA,8BACF;;CAEA,UAAU,oBAAoB,YAAY,eAAe,oBAAoB;;CAE7E,UAAU,oBAAoB,YAAY,eAAe,oBAAoB;;CAE7E,gBAAgB,oBAAoB,kBAAkB,eAAe,gBAAgB;;CAErF,QAAQ,oBAAoB,UAAU,UAAU,gBAAgB;;CAEhE,OAAO,oBAAoB,SAAS,UAAU,WAAW;;CAEzD,gBAAgB,oBACd,kBACA,UACA,EAAE,OAAO,EAAE,OAAO,GAAG,aAAa,CACpC;;CAEA,eAAe,oBACb,iBACA,UACA,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,KAAK,GAAG,EAAE,UAAU,GAAG,GAAG,EAAE,MAAM,sBAAsB,CAAC,CAChF;;CAEA,OAAO,oBAAoB,SAAS,WAAW,WAAW;;CAE1D,WAAW,oBAAoB,aAAa,WAAW,eAAe;;CAEtE,MAAM,oBAAoB,QAAQ,WAAW,UAAU;;CAEvD,UAAU,oBAAoB,YAAY,WAAW,cAAc;;CAEnE,QAAQ,oBAAoB,UAAU,WAAW,iBAAiB;AACpE;AAEA,MAAM,cAAc,OAAO,OAAO,uBAAuB,CAAC,CAAC,QACxD,UAAU,MAAM,SAAS,SAC5B;;;;;;AAOA,SAAgB,kBAAkB,SAAwD;CACxF,OAAO,kBAAkB,SAAS,WAAW,CAAC,CAAC,MAC5C,GAAG,MAAM,EAAE,SAAS,cAAc,EAAE,QAAQ,KAAK,EAAE,IAAI,cAAc,EAAE,GAAG,CAC7E;AACF"}
1
+ {"version":3,"file":"fields.js","names":[],"sources":["../../src/plugin-data/fields.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport { behaviourSchema } from '../behaviours/schema'\nimport type { OkHCLPayload } from '../color/okhcl'\nimport { commentThreadsSchema } from '../comments/schema'\nimport { isExportFormatId, type ExportFormatId } from '../export-format'\nimport { clampExportScale } from '../export-scale'\nimport { FIG_COMPRESSIONS } from '../fig-compression'\nimport { iconSchema, iconTintSchema } from '../icons/schema'\nimport type { Rect } from '../primitives'\nimport { shaderPaintSchema } from '../shaders/schema'\nimport { nodeStatusSchema, statusWorkflowSchema } from '../statuses/schema'\nimport {\n MODE_ATTRIBUTE_PATTERN,\n TOKEN_UNITS,\n type EnabledLibraryBinding,\n type ExportSetting,\n type LayoutDirection,\n type LibraryAssetSource,\n type PluginDataEntry,\n type SourceLibraryPublication,\n type TextDirection,\n type TokenUnit\n} from '../types'\nimport {\n jsonPluginDataField,\n textPluginDataField,\n withoutPluginData,\n type PluginDataKey\n} from './field'\n\nconst DIRECTIONS = ['AUTO', 'LTR', 'RTL'] as const satisfies readonly (\n | TextDirection\n | LayoutDirection\n)[]\n\nconst textPathBoxSchema: v.GenericSchema<unknown, Rect> = v.pipe(\n v.object({ x: v.number(), y: v.number(), width: v.number(), height: v.number() }),\n v.check(\n ({ x, y, width, height }) => Number.isFinite(x + y + width + height) && width > 0 && height > 0\n )\n)\n\n/** String-valued entries of a JSON object; other entries are dropped, not rejected. */\nconst boundVariablesSchema = v.pipe(\n v.custom<Record<string, unknown>>(\n (value) => typeof value === 'object' && value !== null && !Array.isArray(value)\n ),\n v.transform((value) =>\n Object.fromEntries(\n Object.entries(value).filter(\n (entry): entry is [string, string] => typeof entry[1] === 'string'\n )\n )\n )\n)\n\n/** Every entry must be valid, or the whole value is ignored in favour of native settings. */\nconst exportSettingsSchema: v.GenericSchema<unknown, ExportSetting[]> = v.array(\n v.pipe(\n v.object({\n scale: v.pipe(v.number(), v.finite()),\n format: v.custom<ExportFormatId>(isExportFormatId),\n suffix: v.optional(v.string()),\n size: v.optional(\n v.object({\n type: v.picklist(['WIDTH', 'HEIGHT']),\n value: v.pipe(v.number(), v.finite())\n })\n ),\n contentsOnly: v.optional(v.boolean()),\n useAbsoluteBounds: v.optional(v.boolean()),\n colorProfile: v.optional(v.picklist(['DOCUMENT', 'SRGB', 'DISPLAY_P3_V4'])),\n svgOutlineText: v.optional(v.boolean()),\n svgIdAttribute: v.optional(v.boolean()),\n svgSimplifyStroke: v.optional(v.boolean())\n }),\n // Clamp at the file boundary: imported plugin data may carry a scale the UI never produces.\n v.transform((setting) => ({ ...setting, scale: clampExportScale(setting.scale) }))\n )\n)\n\nconst librarySourceSchema: v.GenericSchema<unknown, LibraryAssetSource> = v.pipe(\n v.object({\n identity: v.object({ libraryId: v.string(), assetKey: v.string(), revisionId: v.string() }),\n sourceNodeId: v.optional(v.unknown()),\n readOnly: v.optional(v.unknown())\n }),\n v.transform(({ identity, sourceNodeId, readOnly }) => ({\n identity,\n sourceNodeId: typeof sourceNodeId === 'string' ? sourceNodeId : null,\n readOnly: readOnly === true\n }))\n)\n\nconst enabledLibrarySchema = v.object({\n libraryId: v.string(),\n revisionId: v.string(),\n enabled: v.optional(v.unknown())\n})\n\n/** Invalid entries are skipped one by one, so one bad binding keeps the others. */\nconst enabledLibrariesSchema: v.GenericSchema<unknown, EnabledLibraryBinding[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(enabledLibrarySchema, item)\n if (!parsed.success) return []\n const { libraryId, revisionId, enabled } = parsed.output\n return [{ libraryId, revisionId, enabled: enabled === true }]\n })\n )\n)\n\n// Shape only. Whether a string is valid CSS is checked where it is written into a stylesheet.\nconst cssTextSchema = v.pipe(v.string(), v.trim(), v.nonEmpty(), v.maxLength(1000))\n\n/** Token fields Figma has no slot for, with mode ids as the file spells them. */\nexport interface StoredToken {\n unit?: TokenUnit\n expressions?: Record<string, { css: string; resolved?: number }>\n}\n\nconst tokenSchema: v.GenericSchema<unknown, StoredToken> = v.object({\n unit: v.optional(v.picklist(TOKEN_UNITS)),\n expressions: v.optional(\n v.record(\n v.string(),\n v.object({ css: cssTextSchema, resolved: v.optional(v.pipe(v.number(), v.finite())) })\n )\n )\n})\n\nconst okhclSchema: v.GenericSchema<unknown, OkHCLPayload> = v.object({\n version: v.literal(1),\n kind: v.picklist(['fill', 'stroke']),\n index: v.number(),\n color: v.object({\n h: v.number(),\n c: v.number(),\n l: v.number(),\n a: v.fallback(v.optional(v.number()), undefined)\n })\n})\n\nconst sourceLibraryPublicationSchema: v.GenericSchema<unknown, SourceLibraryPublication> = v.object(\n {\n libraryId: v.string(),\n revisionId: v.string(),\n name: v.string(),\n catalogSource: v.optional(v.string())\n }\n)\n\n/**\n * Every plugin-data entry OpenPencil writes under {@link OPEN_PENCIL_PLUGIN_ID}: state Figma's\n * format has no field for. Add a key here, never as a string elsewhere, so reading and writing\n * it share one schema.\n */\nexport const OPEN_PENCIL_PLUGIN_DATA = {\n /** A text node's direction, on TEXT nodes. */\n textDirection: textPluginDataField('textDirection', 'format', DIRECTIONS),\n /** An auto-layout frame's direction. */\n layoutDirection: textPluginDataField('layoutDirection', 'format', DIRECTIONS),\n /** Marks a component set Figma would read as a plain frame. */\n nodeType: textPluginDataField('nodeType', 'format', ['COMPONENT_SET']),\n /** Variable bindings by field path, including those Figma cannot store natively. */\n boundVariables: jsonPluginDataField('boundVariables', 'format', boundVariablesSchema),\n exportSettings: jsonPluginDataField('exportSettings', 'format', exportSettingsSchema),\n /** The node-local rect a TEXT_PATH layout maps onto, which Kiwi has no field for. */\n textPathBox: jsonPluginDataField('textPathBox', 'format', textPathBoxSchema),\n /** The library asset a node was inserted from. */\n librarySource: jsonPluginDataField('librarySource', 'bookkeeping', librarySourceSchema),\n /** The library source layer a library definition's layer copies, on every definition layer. */\n libraryLayer: jsonPluginDataField(\n 'libraryLayer',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(1024))\n ),\n /**\n * The document root's id, on the DOCUMENT node, whose own GUID is always Figma's `0:0`; the\n * root keeps it across a save as every layer keeps its GUID.\n */\n documentId: jsonPluginDataField(\n 'documentId',\n 'bookkeeping',\n v.pipe(v.string(), v.nonEmpty(), v.maxLength(64))\n ),\n /** Libraries enabled for the document, on the DOCUMENT node. */\n enabledLibraries: jsonPluginDataField('enabledLibraries', 'bookkeeping', enabledLibrariesSchema),\n /** The library this document publishes as, on the DOCUMENT node. */\n sourceLibraryPublication: jsonPluginDataField(\n 'sourceLibraryPublication',\n 'bookkeeping',\n sourceLibraryPublicationSchema\n ),\n /** Canvas comment threads, deleted ones included, on the DOCUMENT node. */\n comments: jsonPluginDataField('comments', 'bookkeeping', commentThreadsSchema),\n /** The statuses layers can be in, on the DOCUMENT node. */\n statuses: jsonPluginDataField('statuses', 'bookkeeping', statusWorkflowSchema),\n /** How tightly the document's `.fig` data is compressed, on the DOCUMENT node. */\n figCompression: textPluginDataField('figCompression', 'bookkeeping', FIG_COMPRESSIONS),\n /** A layer's status, any state of the workflow; Figma's `sectionStatusInfo` knows only two. */\n status: jsonPluginDataField('status', 'format', nodeStatusSchema),\n /** Unit and CSS expressions, on each VARIABLE. */\n token: jsonPluginDataField('token', 'format', tokenSchema),\n /** Mode conditions by mode id, on each VARIABLE_SET. */\n modeConditions: jsonPluginDataField(\n 'modeConditions',\n 'format',\n v.record(v.string(), cssTextSchema)\n ),\n /** The attribute that switches manual modes, on each VARIABLE_SET. */\n modeAttribute: jsonPluginDataField(\n 'modeAttribute',\n 'format',\n v.pipe(v.string(), v.trim(), v.maxLength(100), v.regex(MODE_ATTRIBUTE_PATTERN))\n ),\n /** One entry per paint picked in OkHCL, so the picker reopens on the same coordinates. */\n okhcl: jsonPluginDataField('okhcl', 'content', okhclSchema),\n /** How a main component or component set behaves as a control in preview. */\n behaviour: jsonPluginDataField('behaviour', 'content', behaviourSchema),\n /** The icon a frame draws, such as `lucide:home`, on the frame its paths are in. */\n icon: jsonPluginDataField('icon', 'content', iconSchema),\n /** Which of an icon path's paints its icon's color sets, on each path the source drew in it. */\n iconTint: jsonPluginDataField('iconTint', 'content', iconTintSchema),\n /** One entry per paint that draws a shader, matched to its image paint by the frame's hash. */\n shader: jsonPluginDataField('shader', 'content', shaderPaintSchema)\n} satisfies Record<string, PluginDataKey>\n\nconst NOT_CONTENT = Object.values(OPEN_PENCIL_PLUGIN_DATA).filter(\n (field) => field.role !== 'content'\n)\n\n/**\n * A node's plugin data that is part of its content, in a stable order: OpenPencil's content\n * fields and every other plugin's entries, which the node carries wherever it goes. Format\n * copies of node fields and bookkeeping are left out.\n */\nexport function contentPluginData(entries: readonly PluginDataEntry[]): PluginDataEntry[] {\n return withoutPluginData(entries, NOT_CONTENT).sort(\n (a, b) => a.pluginId.localeCompare(b.pluginId) || a.key.localeCompare(b.key)\n )\n}\n"],"mappings":";;;;;;;;;;;;AA+BA,MAAM,aAAa;CAAC;CAAQ;CAAO;AAAK;AAKxC,MAAM,oBAAoD,EAAE,KAC1D,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,OAAO,EAAE,OAAO;CAAG,QAAQ,EAAE,OAAO;AAAE,CAAC,GAChF,EAAE,OACC,EAAE,GAAG,GAAG,OAAO,aAAa,OAAO,SAAS,IAAI,IAAI,QAAQ,MAAM,KAAK,QAAQ,KAAK,SAAS,CAChG,CACF;;AAGA,MAAM,uBAAuB,EAAE,KAC7B,EAAE,QACC,UAAU,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,CAChF,GACA,EAAE,WAAW,UACX,OAAO,YACL,OAAO,QAAQ,KAAK,CAAC,CAAC,QACnB,UAAqC,OAAO,MAAM,OAAO,QAC5D,CACF,CACF,CACF;;AAGA,MAAM,uBAAkE,EAAE,MACxE,EAAE,KACA,EAAE,OAAO;CACP,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;CACpC,QAAQ,EAAE,OAAuB,gBAAgB;CACjD,QAAQ,EAAE,SAAS,EAAE,OAAO,CAAC;CAC7B,MAAM,EAAE,SACN,EAAE,OAAO;EACP,MAAM,EAAE,SAAS,CAAC,SAAS,QAAQ,CAAC;EACpC,OAAO,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;CACtC,CAAC,CACH;CACA,cAAc,E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ceneNode, VectorNetwork } from "./types.js";
7
7
  * geometry that must scale with the node, and textPathBox is the layout box the
8
8
  * glyphs were reflowed against.
9
9
  */
10
- type ResizeSnapshot = Pick<SceneNode, 'type' | 'x' | 'y' | 'width' | 'height' | 'vectorNetwork' | 'fillGeometry' | 'strokeGeometry' | 'derivedTextGlyphs' | 'strokes' | 'textPathData' | 'textPathBox'>;
10
+ type ResizeSnapshot = Pick<SceneNode, 'type' | 'x' | 'y' | 'width' | 'height' | 'flipX' | 'flipY' | 'vectorNetwork' | 'fillGeometry' | 'strokeGeometry' | 'derivedTextGlyphs' | 'strokes' | 'textPathData' | 'textPathBox'>;
11
11
  interface ResizeGraph {
12
+ readonly rootId: string;
12
13
  getNode(id: string): SceneNode | undefined;
13
14
  }
15
+ /** A child's box after its parent resizes, and the axes on which it turned over. */
16
+ type ConstrainedRect = Rect & {
17
+ flipsX?: boolean;
18
+ flipsY?: boolean;
19
+ };
14
20
  /** Keep a placed box's constrained edges or center when its content determines its size. */
15
21
  declare function resizedChildRect(placed: Rect, size: Pick<Rect, 'width' | 'height'>, horizontal: ConstraintType, vertical: ConstraintType): Rect;
16
- /** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */
17
- declare function constrainedChildRect(child: Rect, parentBefore: Pick<Rect, 'width' | 'height'>, parentAfter: Pick<Rect, 'width' | 'height'>, horizontal: ConstraintType, vertical: ConstraintType, aspectRatio?: number | null): Rect;
18
22
  /**
19
- * Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto
20
- * layout when its Hug frame grows (measured on desktop 126): Right and Left & right move or grow
21
- * it by the change in the parent's size rounded to whole pixels, Center by the change in its
22
- * rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not
23
- * rounded, so applying a run of changes one at a time lands where applying them at once does.
23
+ * A child's box after its parent resizes, by a handle, `resize()`, layout, or an instance taking
24
+ * another size than its component, keeping a locked aspect ratio as Figma does.
24
25
  */
25
- declare function layoutConstrainedChildRect(child: Rect, parentBefore: Pick<Rect, 'width' | 'height'>, parentAfter: Pick<Rect, 'width' | 'height'>, horizontal: ConstraintType, vertical: ConstraintType, aspectRatio?: number | null): Rect;
26
+ declare function constrainedChildRect(child: Rect, parentBefore: Pick<Rect, 'width' | 'height'>, parentAfter: Pick<Rect, 'width' | 'height'>, horizontal: ConstraintType, vertical: ConstraintType, aspectRatio?: number | null): ConstrainedRect;
26
27
  declare function scaledChildRect(child: Rect, parentBefore: Pick<Rect, 'width' | 'height'>, parentAfter: Pick<Rect, 'width' | 'height'>): Rect;
27
28
  declare function scaleVectorNetworkForResize(vectorNetwork: VectorNetwork | null, originalWidth: number, originalHeight: number, width: number, height: number): VectorNetwork | null;
28
29
  /** Snapshot one node's resize-relevant state (rect + geometry that must scale with it). */
@@ -35,7 +36,17 @@ declare function createResizeSnapshot(node: SceneNode): ResizeSnapshot;
35
36
  */
36
37
  declare function scaledGeometryChanges(orig: Pick<ResizeSnapshot, 'type' | 'vectorNetwork' | 'fillGeometry' | 'strokeGeometry' | 'derivedTextGlyphs' | 'strokes' | 'textPathData' | 'textPathBox'>, origWidth: number, origHeight: number, width: number, height: number): Partial<SceneNode>;
37
38
  declare function collectResizeDescendants(graph: ResizeGraph, rootId: string): Map<string, ResizeSnapshot> | null;
38
- declare function computeConstrainedResizeChanges(graph: ResizeGraph, rootId: string, rootBefore: Pick<Rect, 'width' | 'height'>, rootAfter: Pick<Rect, 'width' | 'height'>, originals: ReadonlyMap<string, ResizeSnapshot>): Map<string, Partial<SceneNode>>;
39
+ /**
40
+ * The flips a child takes when its constraints place it from `from`, written only where they
41
+ * differ from the ones it has now, so a drag that crosses back undoes its own turn.
42
+ */
43
+ declare function flipChanges(from: Pick<SceneNode, 'flipX' | 'flipY'>, current: Pick<SceneNode, 'flipX' | 'flipY'>, flipsX?: boolean, flipsY?: boolean): Partial<Pick<SceneNode, 'flipX' | 'flipY'>>;
44
+ type Size = Pick<Rect, 'width' | 'height'>;
45
+ /**
46
+ * Where the descendants of a layer go when it resizes from `rootBefore` to `rootAfter`, from the
47
+ * places `originals` recorded.
48
+ */
49
+ declare function computeConstrainedResizeChanges(graph: ResizeGraph, rootId: string, rootBefore: Size, rootAfter: Size, originals: ReadonlyMap<string, ResizeSnapshot>): Map<string, Partial<SceneNode>>;
39
50
  //#endregion
40
- export { ResizeSnapshot, collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges };
51
+ export { ConstrainedRect, ResizeSnapshot, collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, flipChanges, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges };
41
52
  //# sourceMappingURL=resize.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;KAkBY,iBAAiB,KAC3B;UAeQ;EACR,QAAQ,aAAa;;;iBA8CP,iBACd,QAAQ,MACR,MAAM,KAAK,2BACX,YAAY,gBACZ,UAAU,iBACT;;iBAyBa,qBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,8BACC;;;;;;;;iBAuCa,2BACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,8BACC;iBAgBa,gBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,4BACjB;iBAIa,4BACd,eAAe,sBACf,uBACA,wBACA,eACA,iBACC;;iBA8Ba,qBAAqB,MAAM,YAAY;;;;;;;iBAkDvC,sBACd,MAAM,KACJ,kJAUF,mBACA,oBACA,eACA,iBACC,QAAQ;iBAqDK,yBACd,OAAO,aACP,iBACC,YAAY;iBAoBC,gCACd,OAAO,aACP,gBACA,YAAY,KAAK,2BACjB,WAAW,KAAK,2BAChB,WAAW,oBAAoB,kBAC9B,YAAY,QAAQ"}
1
+ {"version":3,"file":"resize.d.ts","names":[],"sources":["../src/resize.ts"],"mappings":";;;;;;;;;KAuBY,iBAAiB,KAC3B;UAiBQ;WACC;EACT,QAAQ,aAAa;;;KAeX,kBAAkB;EAAS;EAAkB;;;iBAkDzC,iBACd,QAAQ,MACR,MAAM,KAAK,2BACX,YAAY,gBACZ,UAAU,iBACT;;;;;iBA4Ba,qBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,2BAClB,YAAY,gBACZ,UAAU,gBACV,8BACC;iBAca,gBACd,OAAO,MACP,cAAc,KAAK,2BACnB,aAAa,KAAK,4BACjB;iBASa,4BACd,eAAe,sBACf,uBACA,wBACA,eACA,iBACC;;iBA6Ba,qBAAqB,MAAM,YAAY;;;;;;;iBAoDvC,sBACd,MAAM,KACJ,kJAUF,mBACA,oBACA,eACA,iBACC,QAAQ;iBAsFK,yBACd,OAAO,aACP,iBACC,YAAY;;;;;iBAwBC,YACd,MAAM,KAAK,+BACX,SAAS,KAAK,+BACd,kBACA,mBACC,QAAQ,KAAK;KASX,OAAO,KAAK;;;;;iBAmJD,gCACd,OAAO,aACP,gBACA,YAAY,MACZ,WAAW,MACX,WAAW,oBAAoB,kBAC9B,YAAY,QAAQ"}
package/dist/resize.js CHANGED
@@ -1,33 +1,56 @@
1
+ import Matrix from "./matrix.js";
2
+ import { FITTED_CONTAINER_TYPES } from "./node-defaults.js";
3
+ import { getNodeLocalMatrix } from "./coordinate.js";
1
4
  import { cloneVectorNetwork, copyDerivedGlyphs, copyGeometryPaths, copyStroke, copyStrokes, scaleGeometryPaths } from "./copy.js";
5
+ import { CONSTRAINT_PARENT_TYPES } from "./constraints.js";
6
+ import { groupFitChanges } from "./group-bounds.js";
2
7
  import { enforcedAspectRatio } from "./layout/aspect-ratio.js";
3
8
  //#region src/resize.ts
4
- const CONSTRAINT_CONTAINER_TYPES = /* @__PURE__ */ new Set([
5
- "FRAME",
6
- "COMPONENT",
7
- "COMPONENT_SET",
8
- "INSTANCE",
9
- "GROUP",
10
- "BOOLEAN_OPERATION"
11
- ]);
9
+ /**
10
+ * Containers whose resize moves their children: the constraint parents, and groups and booleans,
11
+ * which scale theirs.
12
+ */
13
+ const CONSTRAINT_CONTAINER_TYPES = /* @__PURE__ */ new Set([...CONSTRAINT_PARENT_TYPES, ...FITTED_CONTAINER_TYPES]);
14
+ /**
15
+ * Where a constraint places a child on one axis when its parent goes from `parentBefore` to
16
+ * `parentAfter`, as Figma does (live-measured, #1060, #1816): Right and Left & right move or grow
17
+ * it by the change in the parent's size rounded to whole pixels, Center by the change in its
18
+ * rounded half, and Scale by the exact ratio. The child's own box is never rounded, so a resize
19
+ * to the same size changes nothing. Left & right that would leave no size keeps the axis as it
20
+ * was; past zero, the child turns over and its box runs back from the edge it was pinned to, as
21
+ * the layer is mirrored in Figma.
22
+ */
12
23
  function constrainedAxis(position, size, parentBefore, parentAfter, constraint) {
13
- const delta = parentAfter - parentBefore;
24
+ const delta = Math.round(parentAfter) - Math.round(parentBefore);
14
25
  if (constraint === "MAX") return {
15
26
  position: position + delta,
16
27
  size
17
28
  };
18
29
  if (constraint === "CENTER") return {
19
- position: position + delta / 2,
30
+ position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2),
20
31
  size
21
32
  };
22
- if (constraint === "STRETCH") return {
23
- position,
24
- size: Math.max(1, size + delta)
25
- };
33
+ if (constraint === "STRETCH") {
34
+ const stretched = size + delta;
35
+ if (stretched === 0) return {
36
+ position,
37
+ size
38
+ };
39
+ if (stretched > 0) return {
40
+ position,
41
+ size: stretched
42
+ };
43
+ return {
44
+ position: position + stretched,
45
+ size: -stretched,
46
+ flipped: true
47
+ };
48
+ }
26
49
  if (constraint === "SCALE" && parentBefore > 0) {
27
50
  const scale = parentAfter / parentBefore;
28
51
  return {
29
52
  position: position * scale,
30
- size: Math.max(1, size * scale)
53
+ size: size * scale
31
54
  };
32
55
  }
33
56
  return {
@@ -86,67 +109,33 @@ function keepLockedRatio(x, y, horizontal, vertical, aspectRatio) {
86
109
  y
87
110
  };
88
111
  }
89
- /** A child's box after its parent resizes, keeping a locked aspect ratio as Figma does. */
90
- function constrainedChildRect(child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) {
91
- let x = constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal);
92
- let y = constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical);
93
- ({x, y} = keepLockedRatio(x, y, horizontal, vertical, aspectRatio));
94
- return {
95
- x: Math.round(x.position),
96
- y: Math.round(y.position),
97
- width: Math.round(x.size),
98
- height: Math.round(y.size)
99
- };
100
- }
101
- function layoutConstrainedAxis(position, size, parentBefore, parentAfter, constraint) {
102
- const delta = Math.round(parentAfter) - Math.round(parentBefore);
103
- if (constraint === "MAX") return {
104
- position: position + delta,
105
- size
106
- };
107
- if (constraint === "CENTER") return {
108
- position: position + Math.round(parentAfter / 2) - Math.round(parentBefore / 2),
109
- size
110
- };
111
- if (constraint === "STRETCH") return {
112
- position,
113
- size: Math.abs(size + delta)
114
- };
115
- if (constraint === "SCALE" && parentBefore > 0) {
116
- const scale = parentAfter / parentBefore;
117
- return {
118
- position: Math.round(position * scale * 128) / 128,
119
- size: size * scale
120
- };
121
- }
122
- return {
123
- position,
124
- size
125
- };
126
- }
127
112
  /**
128
- * Where a child goes when layout resizes its parent, as Figma places a layer that ignores auto
129
- * layout when its Hug frame grows (measured on desktop 126): Right and Left & right move or grow
130
- * it by the change in the parent's size rounded to whole pixels, Center by the change in its
131
- * rounded half, and Scale by the exact ratio, its position to 1/128 of a pixel. Sizes are not
132
- * rounded, so applying a run of changes one at a time lands where applying them at once does.
113
+ * A child's box after its parent resizes, by a handle, `resize()`, layout, or an instance taking
114
+ * another size than its component, keeping a locked aspect ratio as Figma does.
133
115
  */
134
- function layoutConstrainedChildRect(child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) {
135
- const placed = keepLockedRatio(layoutConstrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal), layoutConstrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical), horizontal, vertical, aspectRatio);
136
- return {
137
- x: placed.x.position,
138
- y: placed.y.position,
139
- width: placed.x.size,
140
- height: placed.y.size
116
+ function constrainedChildRect(child, parentBefore, parentAfter, horizontal, vertical, aspectRatio = null) {
117
+ const { x, y } = keepLockedRatio(constrainedAxis(child.x, child.width, parentBefore.width, parentAfter.width, horizontal), constrainedAxis(child.y, child.height, parentBefore.height, parentAfter.height, vertical), horizontal, vertical, aspectRatio);
118
+ const rect = {
119
+ x: x.position,
120
+ y: y.position,
121
+ width: x.size,
122
+ height: y.size
141
123
  };
124
+ if (x.flipped) rect.flipsX = true;
125
+ if (y.flipped) rect.flipsY = true;
126
+ return rect;
142
127
  }
143
128
  function scaledChildRect(child, parentBefore, parentAfter) {
144
129
  return constrainedChildRect(child, parentBefore, parentAfter, "SCALE", "SCALE");
145
130
  }
131
+ /** How much a side grows; a flat side, as a straight line's, has nothing to scale along it. */
132
+ function sideScale(original, size) {
133
+ return original > 0 ? size / original : 1;
134
+ }
146
135
  function scaleVectorNetworkForResize(vectorNetwork, originalWidth, originalHeight, width, height) {
147
136
  if (!vectorNetwork || originalWidth <= 0 && originalHeight <= 0) return null;
148
- const scaleX = originalWidth > 0 ? width / originalWidth : 1;
149
- const scaleY = originalHeight > 0 ? height / originalHeight : 1;
137
+ const scaleX = sideScale(originalWidth, width);
138
+ const scaleY = sideScale(originalHeight, height);
150
139
  if (scaleX === 1 && scaleY === 1) return null;
151
140
  return {
152
141
  vertices: vectorNetwork.vertices.map((vertex) => ({
@@ -176,6 +165,8 @@ function createResizeSnapshot(node) {
176
165
  y: node.y,
177
166
  width: node.width,
178
167
  height: node.height,
168
+ flipX: node.flipX,
169
+ flipY: node.flipY,
179
170
  vectorNetwork: node.vectorNetwork ? cloneVectorNetwork(node.vectorNetwork) : null,
180
171
  fillGeometry: copyGeometryPaths(node.fillGeometry),
181
172
  strokeGeometry: copyGeometryPaths(node.strokeGeometry),
@@ -214,9 +205,9 @@ function scaleStrokes(strokes, sx, sy) {
214
205
  * OUTSIDE outlines look massively thick (DomeSticker resize bug).
215
206
  */
216
207
  function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
217
- if (origWidth <= 0 || origHeight <= 0) return {};
218
- const sx = width / origWidth;
219
- const sy = height / origHeight;
208
+ if (origWidth <= 0 && origHeight <= 0) return {};
209
+ const sx = sideScale(origWidth, width);
210
+ const sy = sideScale(origHeight, height);
220
211
  if (sx === 1 && sy === 1) return {};
221
212
  const changes = {};
222
213
  const resizedVN = scaleVectorNetworkForResize(orig.vectorNetwork, origWidth, origHeight, width, height);
@@ -238,6 +229,30 @@ function scaledGeometryChanges(orig, origWidth, origHeight, width, height) {
238
229
  if (orig.strokes.length > 0 && glyphs.length > 0 && pathText) changes.strokes = scaleStrokes(orig.strokes, sx, sy);
239
230
  return changes;
240
231
  }
232
+ /** Copies of the geometry a resize may change, as the snapshot held it before the resize. */
233
+ function snapshotGeometry(orig) {
234
+ return {
235
+ vectorNetwork: orig.vectorNetwork ? cloneVectorNetwork(orig.vectorNetwork) : null,
236
+ fillGeometry: copyGeometryPaths(orig.fillGeometry),
237
+ strokeGeometry: copyGeometryPaths(orig.strokeGeometry),
238
+ derivedTextGlyphs: copyDerivedGlyphs(orig.derivedTextGlyphs),
239
+ strokes: copyStrokes(orig.strokes),
240
+ textPathBox: orig.textPathBox ? { ...orig.textPathBox } : null
241
+ };
242
+ }
243
+ /** Whether a box of `size` scales the snapshot's geometry, a flat side left out. */
244
+ function scalesGeometry(orig, size) {
245
+ return sideScale(orig.width, size.width) !== 1 || sideScale(orig.height, size.height) !== 1;
246
+ }
247
+ /**
248
+ * A child's geometry for its constrained `box`, scaled from the snapshot. At a box that scales
249
+ * nothing, after an earlier frame of the same drag scaled it, the child takes its snapshot
250
+ * geometry again, as nothing else would undo that scaling.
251
+ */
252
+ function constrainedGeometryChanges(orig, current, box) {
253
+ if (scalesGeometry(orig, box)) return scaledGeometryChanges(orig, orig.width, orig.height, box.width, box.height);
254
+ return scalesGeometry(orig, current) ? snapshotGeometry(orig) : {};
255
+ }
241
256
  function collectResizeDescendants(graph, rootId) {
242
257
  const root = graph.getNode(rootId);
243
258
  if (!root || !CONSTRAINT_CONTAINER_TYPES.has(root.type)) return null;
@@ -255,33 +270,152 @@ function collectResizeDescendants(graph, rootId) {
255
270
  collect(rootId);
256
271
  return snapshots.size > 0 ? snapshots : null;
257
272
  }
258
- function computeConstrainedResizeChanges(graph, rootId, rootBefore, rootAfter, originals) {
259
- const changes = /* @__PURE__ */ new Map();
260
- const compute = (parentId, parentBefore, parentAfter) => {
261
- const parent = graph.getNode(parentId);
262
- if (!parent) return;
263
- const scalesChildren = parent.type === "GROUP" || parent.type === "BOOLEAN_OPERATION";
264
- for (const childId of parent.childIds) {
265
- const original = originals.get(childId);
266
- const child = graph.getNode(childId);
267
- if (!original || !child) continue;
268
- if (parent.layoutMode !== "NONE" && child.layoutPositioning !== "ABSOLUTE") {
269
- compute(childId, original, child);
270
- continue;
271
- }
272
- const rect = scalesChildren ? scaledChildRect(original, parentBefore, parentAfter) : constrainedChildRect(original, parentBefore, parentAfter, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child));
273
- const childChanges = {
274
- ...rect,
275
- ...scaledGeometryChanges(original, original.width, original.height, rect.width, rect.height)
273
+ /**
274
+ * The flips a child takes when its constraints place it from `from`, written only where they
275
+ * differ from the ones it has now, so a drag that crosses back undoes its own turn.
276
+ */
277
+ function flipChanges(from, current, flipsX = false, flipsY = false) {
278
+ const changes = {};
279
+ const flipX = from.flipX !== flipsX;
280
+ const flipY = from.flipY !== flipsY;
281
+ if (flipX !== current.flipX) changes.flipX = flipX;
282
+ if (flipY !== current.flipY) changes.flipY = flipY;
283
+ return changes;
284
+ }
285
+ /** The layer as the resize found it, or as the resize leaves it with its changes so far. */
286
+ function startOf(plan, id) {
287
+ const node = plan.graph.getNode(id);
288
+ const original = plan.originals.get(id);
289
+ return node && original ? {
290
+ ...node,
291
+ ...original
292
+ } : node;
293
+ }
294
+ function plannedOf(plan, id) {
295
+ const node = startOf(plan, id);
296
+ const changes = plan.changes.get(id);
297
+ return node && changes ? {
298
+ ...node,
299
+ ...changes
300
+ } : node;
301
+ }
302
+ function mergeChanges(plan, id, changes) {
303
+ plan.changes.set(id, {
304
+ ...plan.changes.get(id),
305
+ ...changes
306
+ });
307
+ }
308
+ /** Writes where a layer's constraints put it, then places its own children. */
309
+ function placeConstrained(plan, child, original, rect, toParent) {
310
+ const { flipsX, flipsY, ...box } = rect;
311
+ const position = toParent ? Matrix.mapPoint(toParent, box) : box;
312
+ plan.changes.set(child.id, {
313
+ ...box,
314
+ ...position,
315
+ ...flipChanges(original, child, flipsX, flipsY),
316
+ ...constrainedGeometryChanges(original, child, box)
317
+ });
318
+ placeChildren(plan, child.id, original, child.layoutMode === "NONE" ? box : child);
319
+ }
320
+ /**
321
+ * Places the layers in a group or boolean whose frame resized. The group owns no constraints: each
322
+ * layer in it keeps its place in the frame by its own, through nested groups, and the groups then
323
+ * fit around them, as in Figma (live, #1835). A layer is placed in the frame's space and written
324
+ * back in its group's.
325
+ */
326
+ function placeGroupedLayers(plan, group, toFrame, frameBefore, frameAfter) {
327
+ for (const childId of group.childIds) {
328
+ const child = plan.graph.getNode(childId);
329
+ const original = plan.originals.get(childId);
330
+ const start = startOf(plan, childId);
331
+ if (!child || !original || !start) continue;
332
+ if (FITTED_CONTAINER_TYPES.has(child.type)) {
333
+ placeGroupedLayers(plan, start, Matrix.multiply(toFrame, getNodeLocalMatrix(start)), frameBefore, frameAfter);
334
+ continue;
335
+ }
336
+ placeConstrained(plan, child, original, constrainedChildRect({
337
+ ...Matrix.mapPoint(toFrame, original),
338
+ width: original.width,
339
+ height: original.height
340
+ }, frameBefore, frameAfter, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child)), Matrix.invert(toFrame));
341
+ }
342
+ fitPlannedGroup(plan, group.id);
343
+ }
344
+ const PLACEMENT_KEYS = [
345
+ "x",
346
+ "y",
347
+ "width",
348
+ "height"
349
+ ];
350
+ /**
351
+ * Fits a group to its layers where the resize put them, when any of them moved: a boolean's box
352
+ * is its result's, which only the renderer measures, so one whose operands stay keeps its box. A
353
+ * drag places from the start each time, so the group's box is always written.
354
+ */
355
+ function fitPlannedGroup(plan, groupId) {
356
+ const group = plannedOf(plan, groupId);
357
+ if (!group) return;
358
+ const { x, y, width, height } = group;
359
+ mergeChanges(plan, groupId, {
360
+ x,
361
+ y,
362
+ width,
363
+ height
364
+ });
365
+ if (!group.childIds.some((id) => {
366
+ const start = startOf(plan, id);
367
+ const planned = plannedOf(plan, id);
368
+ return start && planned && PLACEMENT_KEYS.some((key) => start[key] !== planned[key]);
369
+ })) return;
370
+ const reader = {
371
+ rootId: plan.graph.rootId,
372
+ getNode: (id) => plannedOf(plan, id)
373
+ };
374
+ const children = group.childIds.flatMap((id) => reader.getNode(id) ?? []);
375
+ const fit = groupFitChanges(reader, group, children);
376
+ for (const [id, changes] of fit ?? []) mergeChanges(plan, id, changes);
377
+ }
378
+ /**
379
+ * Places the children of a layer that went from `parentBefore` to `parentAfter`: a frame's by their
380
+ * constraints, the layers in its groups and booleans by theirs, a group's or boolean's own scaled.
381
+ */
382
+ function placeChildren(plan, parentId, parentBefore, parentAfter) {
383
+ const parent = plan.graph.getNode(parentId);
384
+ if (!parent) return;
385
+ const scalesChildren = FITTED_CONTAINER_TYPES.has(parent.type);
386
+ for (const childId of parent.childIds) {
387
+ const original = plan.originals.get(childId);
388
+ const child = plan.graph.getNode(childId);
389
+ if (!original || !child) continue;
390
+ if (parent.layoutMode !== "NONE" && child.layoutPositioning !== "ABSOLUTE") {
391
+ placeChildren(plan, childId, original, child);
392
+ continue;
393
+ }
394
+ if (!scalesChildren && FITTED_CONTAINER_TYPES.has(child.type)) {
395
+ const start = {
396
+ ...child,
397
+ ...original
276
398
  };
277
- changes.set(childId, childChanges);
278
- compute(childId, original, child.layoutMode === "NONE" ? rect : child);
399
+ placeGroupedLayers(plan, start, getNodeLocalMatrix(start), parentBefore, parentAfter);
400
+ continue;
279
401
  }
402
+ placeConstrained(plan, child, original, scalesChildren ? scaledChildRect(original, parentBefore, parentAfter) : constrainedChildRect(original, parentBefore, parentAfter, child.horizontalConstraint, child.verticalConstraint, enforcedAspectRatio(child)), null);
403
+ }
404
+ }
405
+ /**
406
+ * Where the descendants of a layer go when it resizes from `rootBefore` to `rootAfter`, from the
407
+ * places `originals` recorded.
408
+ */
409
+ function computeConstrainedResizeChanges(graph, rootId, rootBefore, rootAfter, originals) {
410
+ const plan = {
411
+ graph,
412
+ originals,
413
+ changes: /* @__PURE__ */ new Map()
280
414
  };
281
- compute(rootId, rootBefore, rootAfter);
282
- return changes;
415
+ placeChildren(plan, rootId, rootBefore, rootAfter);
416
+ return plan.changes;
283
417
  }
284
418
  //#endregion
285
- export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, layoutConstrainedChildRect, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges };
419
+ export { collectResizeDescendants, computeConstrainedResizeChanges, constrainedChildRect, createResizeSnapshot, flipChanges, resizedChildRect, scaleVectorNetworkForResize, scaledChildRect, scaledGeometryChanges };
286
420
 
287
421
  //# sourceMappingURL=resize.js.map