@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,9 +1,10 @@
1
1
  import { cloneNodeProps } from '../copy'
2
2
  import { overriddenBindingField, remapInstanceOverrideState } from '../instances/overrides'
3
3
  import { referencedStyleIds } from '../shared-styles'
4
- import { remapStyleRunReferences, styleRunReferences } from '../text/references'
4
+ import { styleRunReferences } from '../text/references'
5
5
  import type { ComponentPropertyType, SceneNode } from '../types'
6
6
  import { requireTransferReference as required } from './references'
7
+ import { remappedResourceReferences } from './resources'
7
8
  import type { VariableTransferReferences } from './variables'
8
9
 
9
10
  export function semanticTransferReferences(node: SceneNode): string[] {
@@ -65,51 +66,36 @@ export function prepareNodeTransfer(
65
66
  result.componentId = source.componentId ? node(source.componentId) : null
66
67
  result.instanceOverrides = remapInstanceOverrideState(source.instanceOverrides, {
67
68
  node,
68
- variable
69
+ variable,
70
+ collection: (id) => refs.collections.get(id)
69
71
  })
70
- result.boundVariables = Object.fromEntries(
71
- Object.entries(source.boundVariables).map(([field, id]) => [field, variable(id)])
72
- )
73
- result.variableModes = Object.fromEntries(
74
- Object.entries(source.variableModes).map(([collection, mode]) => [
75
- required(refs.collections, collection, 'collection'),
76
- required(refs.modes, mode, 'mode')
77
- ])
78
- )
79
- for (const field of [
80
- 'fillStyleId',
81
- 'strokeStyleId',
82
- 'textStyleId',
83
- 'effectStyleId',
84
- 'gridStyleId'
85
- ] as const) {
86
- result[field] = source[field] ? style(source[field]) : null
87
- }
88
- if (result.styleRuns) {
89
- // A link to a layer the transfer leaves behind keeps naming it.
90
- result.styleRuns = remapStyleRunReferences(result.styleRuns, {
72
+ Object.assign(
73
+ result,
74
+ remappedResourceReferences(source, {
91
75
  variable,
76
+ collection: (id) => required(refs.collections, id, 'collection'),
77
+ mode: (id) => required(refs.modes, id, 'mode'),
92
78
  style,
93
- node: (id) => refs.nodes.get(id) ?? id
79
+ // A link to a layer the transfer leaves behind keeps naming it.
80
+ layer: (id) => refs.nodes.get(id) ?? id
94
81
  })
95
- }
82
+ )
96
83
  // A connector keeps the layers it was attached to when they are left behind; the end becomes
97
84
  // free where nothing by that ID exists, as a pasted Figma connector does.
98
85
  for (const field of ['connectorStart', 'connectorEnd'] as const) {
99
86
  const endpoint = result[field]
100
87
  if (endpoint?.nodeId) endpoint.nodeId = refs.nodes.get(endpoint.nodeId) ?? endpoint.nodeId
101
88
  }
102
- for (const region of result.vectorNetwork?.regions ?? [])
103
- if (region.fillStyleId) region.fillStyleId = style(region.fillStyleId)
104
89
  result.componentPropertyDefinitions = source.componentPropertyDefinitions.map((definition) => ({
105
90
  ...structuredClone(definition),
106
91
  id: property(definition.id),
107
92
  defaultValue: propertyValue(definition.id, definition.defaultValue)
108
93
  }))
109
- result.componentPropertyReferences = source.componentPropertyReferences.map((reference) => ({
110
- ...reference,
111
- propertyId: property(reference.propertyId)
112
- }))
94
+ // A reference to a property that neither the transfer nor its destination defines names nothing.
95
+ result.componentPropertyReferences = source.componentPropertyReferences.flatMap((reference) => {
96
+ const propertyId = refs.properties.get(reference.propertyId)
97
+ return propertyId ? [{ ...reference, propertyId }] : []
98
+ })
113
99
  result.componentPropertyAssignments = values(source.componentPropertyAssignments)
114
100
  // Variant values are keyed by display names, unlike definition-ID assignments.
115
101
  result.componentPropertyValues = { ...source.componentPropertyValues }
@@ -1,7 +1,7 @@
1
1
  import type { SceneGraph } from '../graph'
2
+ import { sharedStyleLayers } from '../shared-styles'
2
3
  import type { ComponentPropertyType, SceneNode } from '../types'
3
4
  import { prepareNodeTransfer } from './nodes'
4
- import { requireTransferReference } from './references'
5
5
  import { prepareVariableTransfer } from './variables'
6
6
 
7
7
  export interface GraphTransferInput {
@@ -73,14 +73,12 @@ export function prepareGraphTransfer(input: GraphTransferInput) {
73
73
  }
74
74
  // Layers name a style by the style's own ID, which a transferred style keeps unless the
75
75
  // target already holds another style by it: IDs read from Figma are only unique in one file.
76
- const targetStyleIds = new Set<string>()
77
- for (const node of target.getAllNodes())
78
- if (node.sharedStyleType !== null && node.source.id) targetStyleIds.add(node.source.id)
76
+ const targetStyles = sharedStyleLayers(target)
79
77
  const styles = new Map<string, string>()
80
78
  for (const node of ordered) {
81
79
  const id = node.source.id
82
80
  if (node.sharedStyleType === null || !id) continue
83
- styles.set(id, targetStyleIds.has(id) ? allocate() : id)
81
+ styles.set(id, targetStyles.has(id) ? allocate() : id)
84
82
  }
85
83
  const references = {
86
84
  nodes,
@@ -119,12 +117,6 @@ export function prepareGraphTransfer(input: GraphTransferInput) {
119
117
  props: withStyleId(node, prepareNodeTransfer(node, references), styles)
120
118
  })),
121
119
  ...resources,
122
- activeModes: new Map(
123
- [...source.activeMode].map(([collection, mode]) => [
124
- requireTransferReference(collections, collection, 'collection'),
125
- requireTransferReference(modes, mode, 'mode')
126
- ])
127
- ),
128
120
  images: new Map([...source.images].map(([hash, bytes]) => [hash, bytes.slice()]))
129
121
  }
130
122
  }
@@ -30,10 +30,13 @@ export function removeGraphTransfer(graph: SceneGraph, plan: GraphTransferPlan):
30
30
  }
31
31
  graph.withBufferedEvents(() => {
32
32
  for (const node of plan.nodes.toReversed()) graph.deleteNode(node.id)
33
- for (const id of variables) graph.variables.delete(id)
33
+ for (const id of variables) {
34
+ graph.willChangeVariable(id)
35
+ graph.variables.delete(id)
36
+ }
34
37
  for (const id of collections) {
38
+ graph.willChangeCollection(id)
35
39
  graph.variableCollections.delete(id)
36
- graph.activeMode.delete(id)
37
40
  }
38
41
  })
39
42
  }
@@ -0,0 +1,54 @@
1
+ import { isEqual } from 'es-toolkit'
2
+
3
+ import { STYLE_LINK_FIELDS } from '../shared-styles'
4
+ import { remapStyleRunReferences } from '../text/references'
5
+ import type { SceneNode } from '../types'
6
+
7
+ /** How a layer's references to variables, collections, modes, and styles are renamed. */
8
+ export interface ResourceReferences {
9
+ variable: (id: string) => string
10
+ collection: (id: string) => string
11
+ mode: (id: string) => string
12
+ style: (id: string) => string
13
+ /** The layer a text link names; links keep naming theirs without it. */
14
+ layer?: (id: string) => string
15
+ }
16
+
17
+ /**
18
+ * `node`'s references to variables, collections, modes, and styles, renamed as a copy into
19
+ * another document renames them: its bindings, the modes it sets, the styles it and its text
20
+ * ranges and vector regions use. Only the fields that change are returned. Instance overrides
21
+ * name layers too, so their callers rename them with the layers.
22
+ */
23
+ export function remappedResourceReferences(
24
+ node: SceneNode,
25
+ references: ResourceReferences
26
+ ): Partial<SceneNode> {
27
+ const { variable, collection, mode, style, layer } = references
28
+ const remapped: Partial<SceneNode> = {
29
+ boundVariables: Object.fromEntries(
30
+ Object.entries(node.boundVariables).map(([field, id]) => [field, variable(id)])
31
+ ),
32
+ variableModes: Object.fromEntries(
33
+ Object.entries(node.variableModes).map(([id, modeId]) => [collection(id), mode(modeId)])
34
+ ),
35
+ styleRuns: remapStyleRunReferences(node.styleRuns, { variable, style, node: layer })
36
+ }
37
+ for (const field of STYLE_LINK_FIELDS) {
38
+ const id = node[field]
39
+ if (id) remapped[field] = style(id)
40
+ }
41
+ if (node.vectorNetwork?.regions.some((region) => region.fillStyleId)) {
42
+ remapped.vectorNetwork = {
43
+ ...node.vectorNetwork,
44
+ regions: node.vectorNetwork.regions.map((region) =>
45
+ region.fillStyleId ? { ...region, fillStyleId: style(region.fillStyleId) } : region
46
+ )
47
+ }
48
+ }
49
+ return Object.fromEntries(
50
+ Object.entries(remapped).filter(
51
+ ([field, value]) => !isEqual(value, node[field as keyof SceneNode])
52
+ )
53
+ )
54
+ }
@@ -1,3 +1,6 @@
1
+ import { uniq } from 'es-toolkit'
2
+
3
+ import type { SceneGraph } from '../graph'
1
4
  import type { Variable, VariableCollection, VariableValue } from '../types'
2
5
  import { mapVariableValueReferences } from '../variables/value'
3
6
  import { requireTransferReference as mapped } from './references'
@@ -81,3 +84,34 @@ export function prepareVariableTransfer(
81
84
  }))
82
85
  }
83
86
  }
87
+
88
+ /**
89
+ * Copies the variables `ids` and the collections `collectionIds` into `target`, IDs kept. Each
90
+ * collection comes from the first of its `sources` that has it, and its variables with it; a
91
+ * variable it lacks there comes from the next. A collection keeps only the variables copied.
92
+ */
93
+ export function copyVariableTables(
94
+ target: SceneGraph,
95
+ ids: ReadonlySet<string>,
96
+ collectionIds: Iterable<string>,
97
+ sources: (collectionId: string) => readonly SceneGraph[]
98
+ ): void {
99
+ for (const collectionId of collectionIds) {
100
+ const graphs = sources(collectionId)
101
+ const first = <T>(read: (graph: SceneGraph) => T | undefined): T | undefined =>
102
+ graphs.map(read).find((found) => found !== undefined)
103
+ const collection = first((graph) => graph.variableCollections.get(collectionId))
104
+ if (!collection) continue
105
+ const members = uniq(
106
+ graphs.flatMap((graph) => graph.variableCollections.get(collectionId)?.variableIds ?? [])
107
+ ).filter((id) => ids.has(id))
108
+ target.variableCollections.set(collectionId, {
109
+ ...structuredClone(collection),
110
+ variableIds: members
111
+ })
112
+ for (const id of members) {
113
+ const variable = first((graph) => graph.variables.get(id))
114
+ if (variable) target.variables.set(id, structuredClone(variable))
115
+ }
116
+ }
117
+ }
package/src/types.ts CHANGED
@@ -34,12 +34,26 @@ export type SceneGraphEventHandlers = Partial<{
34
34
  ) => void
35
35
  }>
36
36
 
37
+ /** The document's records besides its nodes, which edits report changing as they do nodes. */
38
+ export type DocumentRecordKind = 'variable' | 'collection'
39
+
37
40
  /** Hears about nodes as an edit adds and changes them, synchronously and before each change. */
38
41
  export interface NodeChangeObserver {
39
42
  /** A node is about to change and is still as it was. */
40
43
  before: (node: SceneNode) => void
41
44
  /** A node was just added. */
42
45
  created: (node: SceneNode) => void
46
+ /**
47
+ * A variable or collection is about to change, be added, or be removed, and is still as it
48
+ * was: absent, for one about to be added.
49
+ */
50
+ beforeRecord?: (kind: DocumentRecordKind, id: string) => void
51
+ /**
52
+ * The edit being observed waits on something outside it (`SceneGraph.waitOutsideEdit`): until
53
+ * `resume`, nodes change for someone else's edit, not this one.
54
+ */
55
+ pause?: () => void
56
+ resume?: () => void
43
57
  }
44
58
 
45
59
  export type DocumentColorSpace = 'srgb' | 'display-p3'
@@ -243,8 +257,39 @@ export interface Stroke extends Fill {
243
257
  dashPattern?: number[]
244
258
  }
245
259
 
260
+ /**
261
+ * A Glass effect's lens, in Figma's plugin terms: how far in from the edge it bends what is
262
+ * behind the layer (`depth`, 1 to 100 px) and how strongly (`refraction`, 0 to 1), the light it
263
+ * catches (`lightAngle` in degrees, 0 lighting the top edge, and `lightIntensity`, 0 to 1), and how
264
+ * far the colours split (`dispersion`, 0 to 1). The effect's `radius` frosts the glass.
265
+ */
266
+ export interface GlassEffectParams {
267
+ refraction: number
268
+ depth: number
269
+ lightAngle: number
270
+ lightIntensity: number
271
+ dispersion: number
272
+ }
273
+
274
+ /**
275
+ * A progressive blur's ramp, in Figma's plugin terms: the blur grows from `startRadius` at
276
+ * `startOffset` to the effect's `radius` at `endOffset`, both points fractions of the layer's
277
+ * size, and holds each end's radius beyond it.
278
+ */
279
+ export interface ProgressiveBlur {
280
+ startRadius: number
281
+ startOffset: Vector
282
+ endOffset: Vector
283
+ }
284
+
246
285
  export interface Effect {
247
- type: 'DROP_SHADOW' | 'INNER_SHADOW' | 'LAYER_BLUR' | 'BACKGROUND_BLUR' | 'FOREGROUND_BLUR'
286
+ type:
287
+ | 'DROP_SHADOW'
288
+ | 'INNER_SHADOW'
289
+ | 'LAYER_BLUR'
290
+ | 'BACKGROUND_BLUR'
291
+ | 'FOREGROUND_BLUR'
292
+ | 'GLASS'
248
293
  color: Color
249
294
  offset: Vector
250
295
  radius: number
@@ -252,6 +297,10 @@ export interface Effect {
252
297
  visible: boolean
253
298
  blendMode?: BlendMode
254
299
  showShadowBehindNode?: boolean
300
+ /** Set on a `GLASS` effect, and only there. */
301
+ glass?: GlassEffectParams
302
+ /** Set on a layer or background blur that is progressive, and only there. */
303
+ progressive?: ProgressiveBlur
255
304
  }
256
305
 
257
306
  export type ConstraintType = 'MIN' | 'CENTER' | 'MAX' | 'STRETCH' | 'SCALE'
@@ -443,9 +492,37 @@ export interface PluginDataEntry {
443
492
  value: string
444
493
  }
445
494
 
495
+ /** A fixed width or height in pixels an export is scaled to, instead of a multiplier. */
496
+ export interface ExportSize {
497
+ type: 'WIDTH' | 'HEIGHT'
498
+ value: number
499
+ }
500
+
501
+ /** The colour profile an export is written in; the document's own unless set. */
502
+ export type ExportColorProfile = 'DOCUMENT' | 'SRGB' | 'DISPLAY_P3_V4'
503
+
504
+ /**
505
+ * One export a layer keeps. The options past `scale` and `format` are Figma's and read as Figma's
506
+ * defaults when left out.
507
+ */
446
508
  export interface ExportSetting {
447
509
  scale: number
448
510
  format: ExportFormatId
511
+ /** Appended to the file name. */
512
+ suffix?: string
513
+ /** A size that replaces `scale`. */
514
+ size?: ExportSize
515
+ /** Only the layer, without what overlaps it (default true). */
516
+ contentsOnly?: boolean
517
+ /** The layer's box rather than everything it draws, for text (default false). */
518
+ useAbsoluteBounds?: boolean
519
+ colorProfile?: ExportColorProfile
520
+ /** SVG: text as outlines rather than `<text>` (default true). */
521
+ svgOutlineText?: boolean
522
+ /** SVG: every layer's name as its element's `id` (default false). */
523
+ svgIdAttribute?: boolean
524
+ /** SVG: strokes as strokes where possible rather than masked outlines (default true). */
525
+ svgSimplifyStroke?: boolean
449
526
  }
450
527
 
451
528
  export interface PluginRelaunchDataEntry {
@@ -822,6 +899,11 @@ export interface SceneNode {
822
899
  sharedSymbolVersion: string | null
823
900
  publishedVersion: string | null
824
901
  librarySource: LibraryAssetSource | null
902
+ /**
903
+ * The layer of a library's source document that a library definition's layer copies, which pairs
904
+ * it with the same layer in the library's next revision whatever that layer is called by then.
905
+ */
906
+ libraryLayerId: string | null
825
907
  isPublishable: boolean
826
908
  isSymbolPublishable: boolean
827
909
  /**
package/src/undo.ts CHANGED
@@ -5,10 +5,29 @@ export interface UndoEntry {
5
5
  coalesceKey?: string
6
6
  }
7
7
 
8
+ /**
9
+ * Why committed history changed: a new step, a change joining the newest step, undo, redo, or
10
+ * clearing it.
11
+ */
12
+ export type HistoryChange = 'record' | 'join' | 'undo' | 'redo' | 'clear'
13
+
8
14
  export interface UndoManagerOptions {
9
15
  limit?: number
10
- /** Called after recording, undoing, redoing, or clearing committed history. */
11
- onChange?: () => void
16
+ /**
17
+ * Called after recording, joining, undoing, redoing, or clearing committed history, with which,
18
+ * and with the step recorded or joined for `'record'` and `'join'`.
19
+ */
20
+ onChange?: (change: HistoryChange, step?: UndoEntry) => void
21
+ /**
22
+ * Called when an edit ends without a step, its changes undone or amounting to nothing: a batch
23
+ * rolled back, or an edit reported with `discardEdit`. History is unchanged, so `onChange` is not.
24
+ */
25
+ onDiscard?: () => void
26
+ /**
27
+ * Runs an undo or a redo, which the editor runs outside edits in progress
28
+ * (`SceneGraph.runOutsideEdits`), so an agent's edit open meanwhile does not record it.
29
+ */
30
+ runReplay?: (replay: () => void) => void
12
31
  }
13
32
 
14
33
  interface UndoBatch {
@@ -28,11 +47,15 @@ export class UndoManager {
28
47
  private openEdits = 0
29
48
  private readonly settlers = new Set<() => void>()
30
49
  private readonly limit: number
31
- private readonly onChange: (() => void) | undefined
50
+ private readonly onChange: ((change: HistoryChange, step?: UndoEntry) => void) | undefined
51
+ private readonly onDiscard: (() => void) | undefined
52
+ private readonly runReplay: (replay: () => void) => void
32
53
 
33
54
  constructor(options: UndoManagerOptions = {}) {
34
55
  this.limit = options.limit ?? DEFAULT_HISTORY_LIMIT
35
56
  this.onChange = options.onChange
57
+ this.onDiscard = options.onDiscard
58
+ this.runReplay = options.runReplay ?? ((replay) => replay())
36
59
  }
37
60
 
38
61
  apply(entry: UndoEntry): void {
@@ -86,7 +109,7 @@ export class UndoManager {
86
109
  if (!entry) return null
87
110
  this.replay(() => entry.inverse())
88
111
  this.redoStack.push(entry)
89
- this.onChange?.()
112
+ this.onChange?.('undo')
90
113
  return entry.label
91
114
  }
92
115
 
@@ -96,7 +119,7 @@ export class UndoManager {
96
119
  if (!entry) return null
97
120
  this.replay(() => entry.forward())
98
121
  this.undoStack.push(entry)
99
- this.onChange?.()
122
+ this.onChange?.('redo')
100
123
  return entry.label
101
124
  }
102
125
 
@@ -127,9 +150,23 @@ export class UndoManager {
127
150
  }
128
151
 
129
152
  rollbackBatch(): void {
130
- const batch = this.batches.pop()
153
+ const batch = this.batches.at(-1)
131
154
  if (!batch) return
132
- for (const entry of batch.entries.toReversed()) entry.inverse()
155
+ // Still open while it rolls back, so what the rollback changes belongs to the batch.
156
+ try {
157
+ for (const entry of batch.entries.toReversed()) entry.inverse()
158
+ } finally {
159
+ this.batches.pop()
160
+ }
161
+ this.onDiscard?.()
162
+ }
163
+
164
+ /**
165
+ * Reports an edit that ended without a step, rolled back or changing nothing, as a rolled-back
166
+ * batch does. Called once the edit has closed, so `isRecording` tells whether another is open.
167
+ */
168
+ discardEdit(): void {
169
+ this.onDiscard?.()
133
170
  }
134
171
 
135
172
  /** Abandon provisional history without replaying it or changing committed undo/redo entries. */
@@ -141,7 +178,7 @@ export class UndoManager {
141
178
  this.undoStack = []
142
179
  this.redoStack = []
143
180
  this.discardBatches()
144
- this.onChange?.()
181
+ this.onChange?.('clear')
145
182
  }
146
183
 
147
184
  /** Whether undo or redo is replaying a step, whose changes are history rather than new edits. */
@@ -170,13 +207,14 @@ export class UndoManager {
170
207
  entry.inverse()
171
208
  inverse()
172
209
  }
210
+ this.onChange?.('join', last)
173
211
  return true
174
212
  }
175
213
 
176
214
  private replay(step: () => void) {
177
215
  this.replaying++
178
216
  try {
179
- step()
217
+ this.runReplay(step)
180
218
  } finally {
181
219
  this.replaying--
182
220
  }
@@ -274,7 +312,7 @@ export class UndoManager {
274
312
  }
275
313
  this.redoStack = []
276
314
  this.trimUndoStack()
277
- this.onChange?.()
315
+ this.onChange?.('record', this.undoStack.at(-1))
278
316
  }
279
317
 
280
318
  private trimUndoStack(): void {