@open-pencil/scene-graph 0.17.0-beta.2 → 0.17.0-beta.4

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 (244) hide show
  1. package/dist/asset-keys.d.ts +11 -1
  2. package/dist/asset-keys.d.ts.map +1 -1
  3. package/dist/asset-keys.js +16 -1
  4. package/dist/asset-keys.js.map +1 -1
  5. package/dist/checkpoint.d.ts +3 -3
  6. package/dist/checkpoint.d.ts.map +1 -1
  7. package/dist/checkpoint.js +53 -23
  8. package/dist/checkpoint.js.map +1 -1
  9. package/dist/components/index.d.ts +2 -2
  10. package/dist/components/index.js +2 -2
  11. package/dist/components/properties.d.ts +6 -1
  12. package/dist/components/properties.d.ts.map +1 -1
  13. package/dist/components/properties.js +9 -1
  14. package/dist/components/properties.js.map +1 -1
  15. package/dist/constants.d.ts +6 -1
  16. package/dist/constants.d.ts.map +1 -1
  17. package/dist/constants.js +17 -1
  18. package/dist/constants.js.map +1 -1
  19. package/dist/constraints.d.ts +25 -0
  20. package/dist/constraints.d.ts.map +1 -0
  21. package/dist/constraints.js +51 -0
  22. package/dist/constraints.js.map +1 -0
  23. package/dist/coordinate.d.ts +64 -1
  24. package/dist/coordinate.d.ts.map +1 -1
  25. package/dist/coordinate.js +217 -1
  26. package/dist/coordinate.js.map +1 -1
  27. package/dist/copy.d.ts.map +1 -1
  28. package/dist/copy.js +8 -1
  29. package/dist/copy.js.map +1 -1
  30. package/dist/css/index.d.ts +3 -2
  31. package/dist/css/index.js +3 -2
  32. package/dist/css/text.d.ts +28 -1
  33. package/dist/css/text.d.ts.map +1 -1
  34. package/dist/css/text.js +84 -17
  35. package/dist/css/text.js.map +1 -1
  36. package/dist/css/transform.d.ts +34 -0
  37. package/dist/css/transform.d.ts.map +1 -0
  38. package/dist/css/transform.js +320 -0
  39. package/dist/css/transform.js.map +1 -0
  40. package/dist/css/values.d.ts.map +1 -1
  41. package/dist/css/values.js +11 -1
  42. package/dist/css/values.js.map +1 -1
  43. package/dist/figjam/palette.d.ts +1 -1
  44. package/dist/figjam/palette.js +1 -1
  45. package/dist/figjam/palette.js.map +1 -1
  46. package/dist/geometry.d.ts +8 -1
  47. package/dist/geometry.d.ts.map +1 -1
  48. package/dist/geometry.js +19 -8
  49. package/dist/geometry.js.map +1 -1
  50. package/dist/graph.d.ts +48 -12
  51. package/dist/graph.d.ts.map +1 -1
  52. package/dist/graph.js +110 -24
  53. package/dist/graph.js.map +1 -1
  54. package/dist/group-bounds.d.ts +14 -4
  55. package/dist/group-bounds.d.ts.map +1 -1
  56. package/dist/group-bounds.js +76 -11
  57. package/dist/group-bounds.js.map +1 -1
  58. package/dist/hit-test.d.ts +5 -0
  59. package/dist/hit-test.d.ts.map +1 -1
  60. package/dist/hit-test.js +18 -12
  61. package/dist/hit-test.js.map +1 -1
  62. package/dist/images.d.ts +27 -3
  63. package/dist/images.d.ts.map +1 -1
  64. package/dist/images.js +57 -3
  65. package/dist/images.js.map +1 -1
  66. package/dist/index.d.ts +2 -2
  67. package/dist/instances/index.d.ts.map +1 -1
  68. package/dist/instances/index.js +3 -0
  69. package/dist/instances/index.js.map +1 -1
  70. package/dist/instances/placement.js +55 -12
  71. package/dist/instances/placement.js.map +1 -1
  72. package/dist/instances/swap.js +3 -0
  73. package/dist/instances/swap.js.map +1 -1
  74. package/dist/instances/sync.js +34 -13
  75. package/dist/instances/sync.js.map +1 -1
  76. package/dist/node-defaults.d.ts.map +1 -1
  77. package/dist/node-defaults.js +1 -0
  78. package/dist/node-defaults.js.map +1 -1
  79. package/dist/order-keys.d.ts +3 -1
  80. package/dist/order-keys.d.ts.map +1 -1
  81. package/dist/order-keys.js +6 -1
  82. package/dist/order-keys.js.map +1 -1
  83. package/dist/plugin-data/fields.d.ts +2 -0
  84. package/dist/plugin-data/fields.d.ts.map +1 -1
  85. package/dist/plugin-data/fields.js +2 -0
  86. package/dist/plugin-data/fields.js.map +1 -1
  87. package/dist/resize.d.ts +22 -11
  88. package/dist/resize.d.ts.map +1 -1
  89. package/dist/resize.js +227 -93
  90. package/dist/resize.js.map +1 -1
  91. package/dist/scaling/index.d.ts +3 -2
  92. package/dist/scaling/index.js +3 -2
  93. package/dist/scaling/node.d.ts.map +1 -1
  94. package/dist/scaling/node.js +5 -1
  95. package/dist/scaling/node.js.map +1 -1
  96. package/dist/scaling/snapshot.d.ts +25 -0
  97. package/dist/scaling/snapshot.d.ts.map +1 -0
  98. package/dist/scaling/snapshot.js +39 -0
  99. package/dist/scaling/snapshot.js.map +1 -0
  100. package/dist/scaling/tree.d.ts +24 -2
  101. package/dist/scaling/tree.d.ts.map +1 -1
  102. package/dist/scaling/tree.js +37 -14
  103. package/dist/scaling/tree.js.map +1 -1
  104. package/dist/shaders/model.d.ts.map +1 -1
  105. package/dist/shaders/model.js +2 -1
  106. package/dist/shaders/model.js.map +1 -1
  107. package/dist/shared-styles.d.ts +3 -1
  108. package/dist/shared-styles.d.ts.map +1 -1
  109. package/dist/shared-styles.js +7 -1
  110. package/dist/shared-styles.js.map +1 -1
  111. package/dist/slots/authoring.d.ts +3 -2
  112. package/dist/slots/authoring.d.ts.map +1 -1
  113. package/dist/slots/authoring.js +5 -3
  114. package/dist/slots/authoring.js.map +1 -1
  115. package/dist/slots/content.d.ts.map +1 -1
  116. package/dist/slots/content.js +4 -1
  117. package/dist/slots/content.js.map +1 -1
  118. package/dist/text/direction.d.ts +3 -1
  119. package/dist/text/direction.d.ts.map +1 -1
  120. package/dist/text/direction.js +5 -1
  121. package/dist/text/direction.js.map +1 -1
  122. package/dist/transfer/apply.d.ts.map +1 -1
  123. package/dist/transfer/apply.js +1 -6
  124. package/dist/transfer/apply.js.map +1 -1
  125. package/dist/transfer/copied.d.ts +35 -3
  126. package/dist/transfer/copied.d.ts.map +1 -1
  127. package/dist/transfer/copied.js +44 -13
  128. package/dist/transfer/copied.js.map +1 -1
  129. package/dist/transfer/dependencies.d.ts +38 -0
  130. package/dist/transfer/dependencies.d.ts.map +1 -0
  131. package/dist/transfer/dependencies.js +100 -0
  132. package/dist/transfer/dependencies.js.map +1 -0
  133. package/dist/transfer/history.js +0 -1
  134. package/dist/transfer/history.js.map +1 -1
  135. package/dist/transfer/index.d.ts +5 -3
  136. package/dist/transfer/index.js +5 -3
  137. package/dist/transfer/nodes.d.ts.map +1 -1
  138. package/dist/transfer/nodes.js +7 -14
  139. package/dist/transfer/nodes.js.map +1 -1
  140. package/dist/transfer/plan.d.ts +0 -1
  141. package/dist/transfer/plan.js +3 -5
  142. package/dist/transfer/plan.js.map +1 -1
  143. package/dist/transfer/remove.js +5 -2
  144. package/dist/transfer/remove.js.map +1 -1
  145. package/dist/transfer/resources.d.ts +21 -0
  146. package/dist/transfer/resources.d.ts.map +1 -0
  147. package/dist/transfer/resources.js +38 -0
  148. package/dist/transfer/resources.js.map +1 -0
  149. package/dist/transfer/variables.d.ts +8 -1
  150. package/dist/transfer/variables.d.ts.map +1 -1
  151. package/dist/transfer/variables.js +24 -1
  152. package/dist/transfer/variables.js.map +1 -1
  153. package/dist/types.d.ts +47 -2
  154. package/dist/types.d.ts.map +1 -1
  155. package/dist/types.js.map +1 -1
  156. package/dist/undo.d.ts +28 -3
  157. package/dist/undo.d.ts.map +1 -1
  158. package/dist/undo.js +24 -7
  159. package/dist/undo.js.map +1 -1
  160. package/dist/variables/bindings.d.ts +17 -14
  161. package/dist/variables/bindings.d.ts.map +1 -1
  162. package/dist/variables/bindings.js +30 -72
  163. package/dist/variables/bindings.js.map +1 -1
  164. package/dist/variables/fields.d.ts +1 -1
  165. package/dist/variables/fields.js +1 -1
  166. package/dist/variables/fields.js.map +1 -1
  167. package/dist/variables/formula/check.d.ts +1 -1
  168. package/dist/variables/formula/index.d.ts +2 -2
  169. package/dist/variables/formula/index.js +1 -1
  170. package/dist/variables/formula/index.js.map +1 -1
  171. package/dist/variables/formula/print.d.ts +1 -1
  172. package/dist/variables/formula/signatures.js +1 -1
  173. package/dist/variables/index.d.ts +6 -6
  174. package/dist/variables/index.d.ts.map +1 -1
  175. package/dist/variables/index.js +40 -24
  176. package/dist/variables/index.js.map +1 -1
  177. package/dist/variables/paints.d.ts +57 -0
  178. package/dist/variables/paints.d.ts.map +1 -0
  179. package/dist/variables/paints.js +231 -0
  180. package/dist/variables/paints.js.map +1 -0
  181. package/dist/variables/resolution.d.ts +14 -11
  182. package/dist/variables/resolution.d.ts.map +1 -1
  183. package/dist/variables/resolution.js +36 -17
  184. package/dist/variables/resolution.js.map +1 -1
  185. package/dist/variables/subtree.js +17 -0
  186. package/dist/variables/subtree.js.map +1 -0
  187. package/dist/vector-network.d.ts.map +1 -1
  188. package/dist/vector-network.js +2 -8
  189. package/dist/vector-network.js.map +1 -1
  190. package/package.json +8 -1
  191. package/src/asset-keys.ts +20 -0
  192. package/src/checkpoint.ts +87 -32
  193. package/src/components/properties.ts +9 -0
  194. package/src/constants.ts +17 -0
  195. package/src/constraints.ts +60 -0
  196. package/src/coordinate.ts +220 -0
  197. package/src/copy.ts +9 -4
  198. package/src/css/index.ts +17 -1
  199. package/src/css/text.ts +85 -17
  200. package/src/css/transform.ts +266 -0
  201. package/src/css/values.ts +8 -0
  202. package/src/figjam/palette.ts +1 -1
  203. package/src/geometry.ts +20 -9
  204. package/src/graph.ts +128 -42
  205. package/src/group-bounds.ts +84 -17
  206. package/src/hit-test.ts +30 -14
  207. package/src/images.ts +71 -3
  208. package/src/instances/index.ts +4 -0
  209. package/src/instances/placement.ts +63 -10
  210. package/src/instances/swap.ts +5 -0
  211. package/src/instances/sync.ts +48 -21
  212. package/src/node-defaults.ts +1 -0
  213. package/src/order-keys.ts +6 -0
  214. package/src/plugin-data/fields.ts +6 -0
  215. package/src/resize.ts +267 -119
  216. package/src/scaling/index.ts +9 -1
  217. package/src/scaling/node.ts +9 -1
  218. package/src/scaling/snapshot.ts +51 -0
  219. package/src/scaling/tree.ts +63 -19
  220. package/src/shaders/model.ts +2 -3
  221. package/src/shared-styles.ts +8 -0
  222. package/src/slots/authoring.ts +5 -3
  223. package/src/slots/content.ts +4 -1
  224. package/src/text/direction.ts +5 -0
  225. package/src/transfer/apply.ts +1 -13
  226. package/src/transfer/copied.ts +83 -15
  227. package/src/transfer/dependencies.ts +126 -0
  228. package/src/transfer/history.ts +0 -6
  229. package/src/transfer/index.ts +20 -2
  230. package/src/transfer/nodes.ts +10 -26
  231. package/src/transfer/plan.ts +3 -11
  232. package/src/transfer/remove.ts +5 -2
  233. package/src/transfer/resources.ts +54 -0
  234. package/src/transfer/variables.ts +34 -0
  235. package/src/types.ts +55 -1
  236. package/src/undo.ts +48 -10
  237. package/src/variables/bindings.ts +44 -91
  238. package/src/variables/fields.ts +1 -1
  239. package/src/variables/formula/index.ts +3 -1
  240. package/src/variables/index.ts +56 -38
  241. package/src/variables/paints.ts +296 -0
  242. package/src/variables/resolution.ts +39 -28
  243. package/src/variables/subtree.ts +15 -0
  244. package/src/vector-network.ts +4 -2
@@ -1 +1 @@
1
- {"version":3,"file":"apply.js","names":[],"sources":["../../src/transfer/apply.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph } from '../graph'\nimport { variableIdentityReferences } from './identity'\nimport type { prepareGraphTransfer } from './plan'\nimport { validateTransferReferences } from './validation'\nimport { prepareVariableTransfer } from './variables'\n\nexport type GraphTransferPlan = ReturnType<typeof prepareGraphTransfer>\n\nfunction validate(target: SceneGraph, plan: GraphTransferPlan): void {\n validateTransferReferences(target, plan)\n const reserved = new Set([\n ...target.nodes.keys(),\n ...target.variables.keys(),\n ...target.variableCollections.keys()\n ])\n const claim = (id: string): void => {\n if (reserved.has(id)) throw new Error(`Transfer identity collision ${id}`)\n reserved.add(id)\n }\n prepareVariableTransfer(\n plan.variables,\n plan.collections,\n variableIdentityReferences(plan.variables, plan.collections)\n )\n for (const [id, mode] of plan.activeModes) {\n if (\n !plan.collections\n .find((collection) => collection.id === id)\n ?.modes.some((entry) => entry.modeId === mode)\n )\n throw new Error(`Invalid transferred active mode ${id}:${mode}`)\n }\n for (const collection of plan.collections) claim(collection.id)\n for (const variable of plan.variables) claim(variable.id)\n const parents = new Set(target.nodes.keys())\n for (const node of plan.nodes) {\n claim(node.id)\n if ('id' in node.props || 'parentId' in node.props || 'childIds' in node.props)\n throw new Error('Transfer props cannot override hierarchy identity')\n if (!parents.has(node.parentId)) throw new Error(`Missing transfer parent ${node.parentId}`)\n parents.add(node.id)\n }\n for (const id of [...plan.rootIds, ...plan.dependencyPageIds]) {\n if (!plan.nodes.some((node) => node.id === id)) throw new Error(`Missing transfer root ${id}`)\n }\n for (const node of plan.nodes) {\n if (node.props.componentId && !parents.has(node.props.componentId))\n throw new Error(`Missing transfer component ${node.props.componentId}`)\n }\n for (const [hash, bytes] of plan.images) {\n const existing = target.images.get(hash)\n if (existing && !isEqual(existing, bytes)) throw new Error(`Transfer image collision ${hash}`)\n }\n}\n\n/** Revalidate at insertion time. Event-delivery failures after commit are not rollback failures. */\nexport function applyGraphTransfer(target: SceneGraph, input: GraphTransferPlan): void {\n const plan = structuredClone(input)\n validate(target, plan)\n const imageIds = [...plan.images.keys()].filter((hash) => !target.images.has(hash))\n target.withBufferedEvents(() => {\n try {\n for (const collection of plan.collections) target.addCollection(collection)\n for (const variable of plan.variables) target.addVariable(variable)\n for (const [id, mode] of plan.activeModes) target.activeMode.set(id, mode)\n for (const [hash, bytes] of plan.images)\n if (!target.images.has(hash)) target.images.set(hash, bytes)\n for (const node of plan.nodes)\n target.createNodeWithId(node.id, node.type, node.parentId, { ...node.props, childIds: [] })\n } catch (error) {\n for (const node of plan.nodes.toReversed())\n if (target.getNode(node.id)) target.deleteNode(node.id)\n for (const variable of plan.variables) target.variables.delete(variable.id)\n for (const collection of plan.collections) {\n target.variableCollections.delete(collection.id)\n target.activeMode.delete(collection.id)\n }\n for (const hash of imageIds) target.images.delete(hash)\n throw error\n }\n })\n}\n"],"mappings":";;;;;AAUA,SAAS,SAAS,QAAoB,MAA+B;CACnE,2BAA2B,QAAQ,IAAI;CACvC,MAAM,2BAAW,IA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xC;GACA,KAAK,MAAM,QAAQ,UAAU,OAAO,OAAO,OAAO,IAAI;GACtD,MAAM;EACR;CACF,CAAC;AACH"}
1
+ {"version":3,"file":"apply.js","names":[],"sources":["../../src/transfer/apply.ts"],"sourcesContent":["import { isEqual } from 'es-toolkit/predicate'\n\nimport type { SceneGraph } from '../graph'\nimport { variableIdentityReferences } from './identity'\nimport type { prepareGraphTransfer } from './plan'\nimport { validateTransferReferences } from './validation'\nimport { prepareVariableTransfer } from './variables'\n\nexport type GraphTransferPlan = ReturnType<typeof prepareGraphTransfer>\n\nfunction validate(target: SceneGraph, plan: GraphTransferPlan): void {\n validateTransferReferences(target, plan)\n const reserved = new Set([\n ...target.nodes.keys(),\n ...target.variables.keys(),\n ...target.variableCollections.keys()\n ])\n const claim = (id: string): void => {\n if (reserved.has(id)) throw new Error(`Transfer identity collision ${id}`)\n reserved.add(id)\n }\n prepareVariableTransfer(\n plan.variables,\n plan.collections,\n variableIdentityReferences(plan.variables, plan.collections)\n )\n for (const collection of plan.collections) claim(collection.id)\n for (const variable of plan.variables) claim(variable.id)\n const parents = new Set(target.nodes.keys())\n for (const node of plan.nodes) {\n claim(node.id)\n if ('id' in node.props || 'parentId' in node.props || 'childIds' in node.props)\n throw new Error('Transfer props cannot override hierarchy identity')\n if (!parents.has(node.parentId)) throw new Error(`Missing transfer parent ${node.parentId}`)\n parents.add(node.id)\n }\n for (const id of [...plan.rootIds, ...plan.dependencyPageIds]) {\n if (!plan.nodes.some((node) => node.id === id)) throw new Error(`Missing transfer root ${id}`)\n }\n for (const node of plan.nodes) {\n if (node.props.componentId && !parents.has(node.props.componentId))\n throw new Error(`Missing transfer component ${node.props.componentId}`)\n }\n for (const [hash, bytes] of plan.images) {\n const existing = target.images.get(hash)\n if (existing && !isEqual(existing, bytes)) throw new Error(`Transfer image collision ${hash}`)\n }\n}\n\n/** Revalidate at insertion time. Event-delivery failures after commit are not rollback failures. */\nexport function applyGraphTransfer(target: SceneGraph, input: GraphTransferPlan): void {\n const plan = structuredClone(input)\n validate(target, plan)\n const imageIds = [...plan.images.keys()].filter((hash) => !target.images.has(hash))\n target.withBufferedEvents(() => {\n try {\n for (const collection of plan.collections) target.addCollection(collection)\n for (const variable of plan.variables) target.addVariable(variable)\n for (const [hash, bytes] of plan.images)\n if (!target.images.has(hash)) target.images.set(hash, bytes)\n for (const node of plan.nodes)\n target.createNodeWithId(node.id, node.type, node.parentId, { ...node.props, childIds: [] })\n } catch (error) {\n for (const node of plan.nodes.toReversed())\n if (target.getNode(node.id)) target.deleteNode(node.id)\n for (const variable of plan.variables) target.variables.delete(variable.id)\n for (const collection of plan.collections) target.variableCollections.delete(collection.id)\n for (const hash of imageIds) target.images.delete(hash)\n throw error\n }\n })\n}\n"],"mappings":";;;;;AAUA,SAAS,SAAS,QAAoB,MAA+B;CACnE,2BAA2B,QAAQ,IAAI;CACvC,MAAM,2BAAW,IAAI,IAAI;EACvB,GAAG,OAAO,MAAM,KAAK;EACrB,GAAG,OAAO,UAAU,KAAK;EACzB,GAAG,OAAO,oBAAoB,KAAK;CACrC,CAAC;CACD,MAAM,SAAS,OAAqB;EAClC,IAAI,SAAS,IAAI,EAAE,GAAG,MAAM,IAAI,MAAM,+BAA+B,IAAI;EACzE,SAAS,IAAI,EAAE;CACjB;CACA,wBACE,KAAK,WACL,KAAK,aACL,2BAA2B,KAAK,WAAW,KAAK,WAAW,CAC7D;CACA,KAAK,MAAM,cAAc,KAAK,aAAa,MAAM,WAAW,EAAE;CAC9D,KAAK,MAAM,YAAY,KAAK,WAAW,MAAM,SAAS,EAAE;CACxD,MAAM,UAAU,IAAI,IAAI,OAAO,MAAM,KAAK,CAAC;CAC3C,KAAK,MAAM,QAAQ,KAAK,OAAO;EAC7B,MAAM,KAAK,EAAE;EACb,IAAI,QAAQ,KAAK,SAAS,cAAc,KAAK,SAAS,cAAc,KAAK,OACvE,MAAM,IAAI,MAAM,mDAAmD;EACrE,IAAI,CAAC,QAAQ,IAAI,KAAK,QAAQ,GAA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,QAAQ,KAAK,MAAM,WAAW,GACvC,IAAI,OAAO,QAAQ,KAAK,EAAE,GAAG,OAAO,WAAW,KAAK,EAAE;GACxD,KAAK,MAAM,YAAY,KAAK,WAAW,OAAO,UAAU,OAAO,SAAS,EAAE;GAC1E,KAAK,MAAM,cAAc,KAAK,aAAa,OAAO,oBAAoB,OAAO,WAAW,EAAE;GAC1F,KAAK,MAAM,QAAQ,UAAU,OAAO,OAAO,OAAO,IAAI;GACtD,MAAM;EACR;CACF,CAAC;AACH"}
@@ -1,14 +1,46 @@
1
1
  import { SceneGraph } from "../graph.js";
2
+ import { SceneNode } from "../types.js";
2
3
  //#region src/transfer/copied.d.ts
4
+ /** How a layer's references to other layers are resolved anew. */
5
+ interface ReferenceResolvers {
6
+ /** The component a reference names now; `previous` is the one the layer named, if any. */
7
+ component: (id: string, previous: string | null) => string;
8
+ /** The layer an override names now; `component` is the one its instance now draws. */
9
+ layer: (id: string, component: string | null) => string;
10
+ /** The layer a connector's end follows now. */
11
+ endpoint: (id: string) => string;
12
+ /**
13
+ * The layer a text link names now. Without it links keep naming their layers, as Figma's
14
+ * duplicate and paste do (desktop 126); copies into another document, which lacks those
15
+ * layers, pass it.
16
+ */
17
+ link?: (id: string) => string;
18
+ variable: (id: string) => string;
19
+ }
20
+ /** Copies placed in another document, whose text links must follow the copy. */
21
+ interface CopiedReferenceOptions {
22
+ followTextLinks?: boolean;
23
+ }
24
+ /** The instance-swap properties `nodes` define, whose values name components. */
25
+ declare function instanceSwapPropertyIds(nodes: Iterable<SceneNode>): Set<string>;
26
+ /**
27
+ * `node`'s references to other layers, resolved anew: its main component, the layers its
28
+ * overrides change and the components they swap in, the components its instance-swap properties
29
+ * default to or are set to, and the layers its connector ends follow. `previous` is the layer
30
+ * whose references these replace, so a resolver can keep what it already pointed at. Only the
31
+ * fields whose references change are returned: every write is an update collaboration sends.
32
+ */
33
+ declare function resolvedReferences(node: SceneNode, previous: SceneNode, resolve: ReferenceResolvers, swapProperties: ReadonlySet<string>): Partial<SceneNode>;
3
34
  /**
4
35
  * Points copied layers at one another, as `prepareNodeTransfer` does for a paste: an instance's
5
36
  * main component, the layers its overrides change and the components they swap in, the
6
37
  * components an instance-swap property defaults to or is set to, and the layers a connector's
7
38
  * ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design
8
39
  * JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and
9
- * so do variable IDs, since the copies keep their source's variables.
40
+ * so do variable IDs, since the copies keep their source's variables. Text links follow the copy
41
+ * only with `followTextLinks`.
10
42
  */
11
- declare function remapCopiedReferences(graph: SceneGraph, mappedIds: ReadonlyMap<string, string>): void;
43
+ declare function remapCopiedReferences(graph: SceneGraph, mappedIds: ReadonlyMap<string, string>, options?: CopiedReferenceOptions): void;
12
44
  //#endregion
13
- export { remapCopiedReferences };
45
+ export { CopiedReferenceOptions, ReferenceResolvers, instanceSwapPropertyIds, remapCopiedReferences, resolvedReferences };
14
46
  //# sourceMappingURL=copied.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"copied.d.ts","names":[],"sources":["../../src/transfer/copied.ts"],"mappings":";;;;;;;;;;iBAuDgB,sBACd,OAAO,YACP,WAAW"}
1
+ {"version":3,"file":"copied.d.ts","names":[],"sources":["../../src/transfer/copied.ts"],"mappings":";;;;UASiB;;EAEf,YAAY,YAAY;;EAExB,QAAQ,YAAY;;EAEpB,WAAW;;;;;;EAMX,QAAQ;EACR,WAAW;;;UAII;EACf;;;iBAUc,wBAAwB,OAAO,SAAS,aAAa;;;;;;;;iBAWrD,mBACd,MAAM,WACN,UAAU,WACV,SAAS,oBACT,gBAAgB,sBACf,QAAQ;;;;;;;;;;iBA8DK,sBACd,OAAO,YACP,WAAW,6BACX,UAAS"}
@@ -1,32 +1,55 @@
1
1
  import { remapInstanceOverrideState } from "../instances/overrides.js";
2
+ import { remapStyleRunReferences } from "../text/references.js";
2
3
  import { componentPropertyDefinitions } from "../components/properties.js";
3
4
  import { isEqual, mapValues } from "es-toolkit";
4
5
  //#region src/transfer/copied.ts
5
6
  function swapPropertyIds(definitions) {
6
7
  return definitions.filter((definition) => definition.type === "INSTANCE_SWAP").map((definition) => definition.id);
7
8
  }
8
- function remappedReferences(node, mapped, swapProperties) {
9
+ /** The instance-swap properties `nodes` define, whose values name components. */
10
+ function instanceSwapPropertyIds(nodes) {
11
+ return new Set([...nodes].flatMap((node) => swapPropertyIds(node.componentPropertyDefinitions)));
12
+ }
13
+ /**
14
+ * `node`'s references to other layers, resolved anew: its main component, the layers its
15
+ * overrides change and the components they swap in, the components its instance-swap properties
16
+ * default to or are set to, and the layers its connector ends follow. `previous` is the layer
17
+ * whose references these replace, so a resolver can keep what it already pointed at. Only the
18
+ * fields whose references change are returned: every write is an update collaboration sends.
19
+ */
20
+ function resolvedReferences(node, previous, resolve, swapProperties) {
9
21
  const changes = {};
10
- if (node.componentId && mapped(node.componentId) !== node.componentId) changes.componentId = mapped(node.componentId);
22
+ const componentId = node.componentId ? resolve.component(node.componentId, previous.componentId) : null;
23
+ if (componentId !== node.componentId) changes.componentId = componentId;
11
24
  const overrides = remapInstanceOverrideState(node.instanceOverrides, {
12
- node: mapped,
13
- variable: (id) => id
25
+ node: (id) => resolve.layer(id, componentId),
26
+ variable: resolve.variable
14
27
  });
15
28
  if (!isEqual(overrides, node.instanceOverrides)) changes.instanceOverrides = overrides;
29
+ const previousDefaults = new Map(previous.componentPropertyDefinitions.map((definition) => [definition.id, definition.defaultValue]));
16
30
  const definitions = node.componentPropertyDefinitions.map((definition) => definition.type === "INSTANCE_SWAP" && definition.defaultValue ? {
17
31
  ...definition,
18
- defaultValue: mapped(definition.defaultValue)
32
+ defaultValue: resolve.component(definition.defaultValue, previousDefaults.get(definition.id) ?? null)
19
33
  } : definition);
20
34
  if (!isEqual(definitions, node.componentPropertyDefinitions)) changes.componentPropertyDefinitions = definitions;
21
- const assignments = mapValues(node.componentPropertyAssignments, (value, id) => swapProperties.has(id) ? mapped(value) : value);
35
+ const assignments = mapValues(node.componentPropertyAssignments, (value, id) => swapProperties.has(id) ? resolve.component(value, previous.componentPropertyAssignments[id] ?? null) : value);
22
36
  if (!isEqual(assignments, node.componentPropertyAssignments)) changes.componentPropertyAssignments = assignments;
23
37
  for (const field of ["connectorStart", "connectorEnd"]) {
24
38
  const endpoint = node[field];
25
- if (endpoint?.nodeId && mapped(endpoint.nodeId) !== endpoint.nodeId) changes[field] = {
39
+ const nodeId = endpoint?.nodeId ? resolve.endpoint(endpoint.nodeId) : null;
40
+ if (endpoint && nodeId && nodeId !== endpoint.nodeId) changes[field] = {
26
41
  ...endpoint,
27
- nodeId: mapped(endpoint.nodeId)
42
+ nodeId
28
43
  };
29
44
  }
45
+ if (resolve.link) {
46
+ const styleRuns = remapStyleRunReferences(node.styleRuns, {
47
+ variable: (id) => id,
48
+ style: (id) => id,
49
+ node: resolve.link
50
+ });
51
+ if (!isEqual(styleRuns, node.styleRuns)) changes.styleRuns = styleRuns;
52
+ }
30
53
  return changes;
31
54
  }
32
55
  /**
@@ -35,18 +58,26 @@ function remappedReferences(node, mapped, swapProperties) {
35
58
  * components an instance-swap property defaults to or is set to, and the layers a connector's
36
59
  * ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design
37
60
  * JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and
38
- * so do variable IDs, since the copies keep their source's variables.
61
+ * so do variable IDs, since the copies keep their source's variables. Text links follow the copy
62
+ * only with `followTextLinks`.
39
63
  */
40
- function remapCopiedReferences(graph, mappedIds) {
64
+ function remapCopiedReferences(graph, mappedIds, options = {}) {
41
65
  const mapped = (id) => mappedIds.get(id) ?? id;
66
+ const resolve = {
67
+ component: mapped,
68
+ layer: mapped,
69
+ endpoint: mapped,
70
+ link: options.followTextLinks ? mapped : void 0,
71
+ variable: (id) => id
72
+ };
42
73
  const copies = [...mappedIds.values()].flatMap((id) => graph.getNode(id) ?? []);
43
- const copiedSwaps = copies.flatMap((node) => swapPropertyIds(node.componentPropertyDefinitions));
74
+ const copiedSwaps = instanceSwapPropertyIds(copies);
44
75
  for (const node of copies) {
45
- const changes = remappedReferences(node, mapped, /* @__PURE__ */ new Set([...copiedSwaps, ...swapPropertyIds(componentPropertyDefinitions(graph, node))]));
76
+ const changes = resolvedReferences(node, node, resolve, /* @__PURE__ */ new Set([...copiedSwaps, ...swapPropertyIds(componentPropertyDefinitions(graph, node))]));
46
77
  if (Object.keys(changes).length > 0) graph.updateNode(node.id, changes);
47
78
  }
48
79
  }
49
80
  //#endregion
50
- export { remapCopiedReferences };
81
+ export { instanceSwapPropertyIds, remapCopiedReferences, resolvedReferences };
51
82
 
52
83
  //# sourceMappingURL=copied.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"copied.js","names":[],"sources":["../../src/transfer/copied.ts"],"sourcesContent":["import { isEqual, mapValues } from 'es-toolkit'\n\nimport { componentPropertyDefinitions } from '../components/properties'\nimport type { SceneGraph } from '../graph'\nimport { remapInstanceOverrideState } from '../instances/overrides'\nimport type { ComponentPropertyDefinition, SceneNode } from '../types'\n\nfunction swapPropertyIds(definitions: readonly ComponentPropertyDefinition[]): string[] {\n return definitions\n .filter((definition) => definition.type === 'INSTANCE_SWAP')\n .map((definition) => definition.id)\n}\n\nfunction remappedReferences(\n node: SceneNode,\n mapped: (id: string) => string,\n swapProperties: ReadonlySet<string>\n): Partial<SceneNode> {\n const changes: Partial<SceneNode> = {}\n if (node.componentId && mapped(node.componentId) !== node.componentId)\n changes.componentId = mapped(node.componentId)\n // Only what a mapping changes: every write is an update collaboration sends.\n const overrides = remapInstanceOverrideState(node.instanceOverrides, {\n node: mapped,\n variable: (id) => id\n })\n if (!isEqual(overrides, node.instanceOverrides)) changes.instanceOverrides = overrides\n const definitions = node.componentPropertyDefinitions.map((definition) =>\n definition.type === 'INSTANCE_SWAP' && definition.defaultValue\n ? { ...definition, defaultValue: mapped(definition.defaultValue) }\n : definition\n )\n if (!isEqual(definitions, node.componentPropertyDefinitions))\n changes.componentPropertyDefinitions = definitions\n const assignments = mapValues(node.componentPropertyAssignments, (value, id) =>\n swapProperties.has(id) ? mapped(value) : value\n )\n if (!isEqual(assignments, node.componentPropertyAssignments))\n changes.componentPropertyAssignments = assignments\n for (const field of ['connectorStart', 'connectorEnd'] as const) {\n const endpoint = node[field]\n if (endpoint?.nodeId && mapped(endpoint.nodeId) !== endpoint.nodeId)\n changes[field] = { ...endpoint, nodeId: mapped(endpoint.nodeId) }\n }\n return changes\n}\n\n/**\n * Points copied layers at one another, as `prepareNodeTransfer` does for a paste: an instance's\n * main component, the layers its overrides change and the components they swap in, the\n * components an instance-swap property defaults to or is set to, and the layers a connector's\n * ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design\n * JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and\n * so do variable IDs, since the copies keep their source's variables.\n */\nexport function remapCopiedReferences(\n graph: SceneGraph,\n mappedIds: ReadonlyMap<string, string>\n): void {\n const mapped = (id: string) => mappedIds.get(id) ?? id\n const copies = [...mappedIds.values()].flatMap((id) => graph.getNode(id) ?? [])\n const copiedSwaps = copies.flatMap((node) => swapPropertyIds(node.componentPropertyDefinitions))\n for (const node of copies) {\n // An instance's swap property may be defined on a component the copy leaves behind.\n const swapProperties = new Set([\n ...copiedSwaps,\n ...swapPropertyIds(componentPropertyDefinitions(graph, node))\n ])\n const changes = remappedReferences(node, mapped, swapProperties)\n if (Object.keys(changes).length > 0) graph.updateNode(node.id, changes)\n }\n}\n"],"mappings":";;;;AAOA,SAAS,gBAAgB,aAA+D;CACtF,OAAO,YACJ,QAAQ,eAAe,WAAW,SAAS,eAAe,CAAC,CAC3D,KAAK,eAAe,WAAW,EAAE;AACtC;AAEA,SAAS,mBACP,MACA,QACA,gBACoB;CACpB,MAAM,UAA8B,CAAC;CACrC,IAAI,KAAK,eAAe,OAAO,KAAK,WAAW,MAAM,KAAK,aACxD,QAAQ,cAAc,OAAO,KAAK,WAAW;CAE/C,MAAM,YAAY,2BAA2B,KAAK,mBAAmB;EACnE,MAAM;EACN,WAAW,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],"sources":["../../src/transfer/copied.ts"],"sourcesContent":["import { isEqual, mapValues } from 'es-toolkit'\n\nimport { componentPropertyDefinitions } from '../components/properties'\nimport type { SceneGraph } from '../graph'\nimport { remapInstanceOverrideState } from '../instances/overrides'\nimport { remapStyleRunReferences } from '../text/references'\nimport type { ComponentPropertyDefinition, SceneNode } from '../types'\n\n/** How a layer's references to other layers are resolved anew. */\nexport interface ReferenceResolvers {\n /** The component a reference names now; `previous` is the one the layer named, if any. */\n component: (id: string, previous: string | null) => string\n /** The layer an override names now; `component` is the one its instance now draws. */\n layer: (id: string, component: string | null) => string\n /** The layer a connector's end follows now. */\n endpoint: (id: string) => string\n /**\n * The layer a text link names now. Without it links keep naming their layers, as Figma's\n * duplicate and paste do (desktop 126); copies into another document, which lacks those\n * layers, pass it.\n */\n link?: (id: string) => string\n variable: (id: string) => string\n}\n\n/** Copies placed in another document, whose text links must follow the copy. */\nexport interface CopiedReferenceOptions {\n followTextLinks?: boolean\n}\n\nfunction swapPropertyIds(definitions: readonly ComponentPropertyDefinition[]): string[] {\n return definitions\n .filter((definition) => definition.type === 'INSTANCE_SWAP')\n .map((definition) => definition.id)\n}\n\n/** The instance-swap properties `nodes` define, whose values name components. */\nexport function instanceSwapPropertyIds(nodes: Iterable<SceneNode>): Set<string> {\n return new Set([...nodes].flatMap((node) => swapPropertyIds(node.componentPropertyDefinitions)))\n}\n\n/**\n * `node`'s references to other layers, resolved anew: its main component, the layers its\n * overrides change and the components they swap in, the components its instance-swap properties\n * default to or are set to, and the layers its connector ends follow. `previous` is the layer\n * whose references these replace, so a resolver can keep what it already pointed at. Only the\n * fields whose references change are returned: every write is an update collaboration sends.\n */\nexport function resolvedReferences(\n node: SceneNode,\n previous: SceneNode,\n resolve: ReferenceResolvers,\n swapProperties: ReadonlySet<string>\n): Partial<SceneNode> {\n const changes: Partial<SceneNode> = {}\n const componentId = node.componentId\n ? resolve.component(node.componentId, previous.componentId)\n : null\n if (componentId !== node.componentId) changes.componentId = componentId\n const overrides = remapInstanceOverrideState(node.instanceOverrides, {\n node: (id) => resolve.layer(id, componentId),\n variable: resolve.variable\n })\n if (!isEqual(overrides, node.instanceOverrides)) changes.instanceOverrides = overrides\n const previousDefaults = new Map(\n previous.componentPropertyDefinitions.map((definition) => [\n definition.id,\n definition.defaultValue\n ])\n )\n const definitions = node.componentPropertyDefinitions.map((definition) =>\n definition.type === 'INSTANCE_SWAP' && definition.defaultValue\n ? {\n ...definition,\n defaultValue: resolve.component(\n definition.defaultValue,\n previousDefaults.get(definition.id) ?? null\n )\n }\n : definition\n )\n if (!isEqual(definitions, node.componentPropertyDefinitions))\n changes.componentPropertyDefinitions = definitions\n const assignments = mapValues(node.componentPropertyAssignments, (value, id) =>\n swapProperties.has(id)\n ? resolve.component(value, previous.componentPropertyAssignments[id] ?? null)\n : value\n )\n if (!isEqual(assignments, node.componentPropertyAssignments))\n changes.componentPropertyAssignments = assignments\n for (const field of ['connectorStart', 'connectorEnd'] as const) {\n const endpoint = node[field]\n const nodeId = endpoint?.nodeId ? resolve.endpoint(endpoint.nodeId) : null\n if (endpoint && nodeId && nodeId !== endpoint.nodeId) changes[field] = { ...endpoint, nodeId }\n }\n if (resolve.link) {\n const styleRuns = remapStyleRunReferences(node.styleRuns, {\n variable: (id) => id,\n style: (id) => id,\n node: resolve.link\n })\n if (!isEqual(styleRuns, node.styleRuns)) changes.styleRuns = styleRuns\n }\n return changes\n}\n\n/**\n * Points copied layers at one another, as `prepareNodeTransfer` does for a paste: an instance's\n * main component, the layers its overrides change and the components they swap in, the\n * components an instance-swap property defaults to or is set to, and the layers a connector's\n * ends follow. `mappedIds` maps each copied layer to its copy, such as a library copy or a design\n * JSX render folded into the layers it replaces; a reference outside the copy stays as it is, and\n * so do variable IDs, since the copies keep their source's variables. Text links follow the copy\n * only with `followTextLinks`.\n */\nexport function remapCopiedReferences(\n graph: SceneGraph,\n mappedIds: ReadonlyMap<string, string>,\n options: CopiedReferenceOptions = {}\n): void {\n const mapped = (id: string) => mappedIds.get(id) ?? id\n const resolve: ReferenceResolvers = {\n component: mapped,\n layer: mapped,\n endpoint: mapped,\n link: options.followTextLinks ? mapped : undefined,\n variable: (id) => id\n }\n const copies = [...mappedIds.values()].flatMap((id) => graph.getNode(id) ?? [])\n const copiedSwaps = instanceSwapPropertyIds(copies)\n for (const node of copies) {\n // An instance's swap property may be defined on a component the copy leaves behind.\n const swapProperties = new Set([\n ...copiedSwaps,\n ...swapPropertyIds(componentPropertyDefinitions(graph, node))\n ])\n const changes = resolvedReferences(node, node, resolve, swapProperties)\n if (Object.keys(changes).length > 0) graph.updateNode(node.id, changes)\n }\n}\n"],"mappings":";;;;;AA8BA,SAAS,gBAAgB,aAA+D;CACtF,OAAO,YACJ,QAAQ,eAAe,WAAW,SAAS,eAAe,CAAC,CAC3D,KAAK,eAAe,WAAW,EAAE;AACtC;;AAGA,SAAgB,wBAAwB,OAAyC;CAC/E,OAAO,IAAI,IAAI,CAAC,GAAG,KAAK,CAAC,CAAC,SAAS,SAAS,gBAAgB,KAAK,4BAA4B,CAAC,CAAC;AACjG;;;;;;;;AASA,SAAgB,mBACd,MACA,UACA,SACA,gBACoB;CACpB,MAAM,UAA8B,CAAC;CACrC,MAAM,cAAc,KAAK,cACrB,QAAQ,UAAU,KAAK,aAAa,SAAS,WAAW,IACxD;CACJ,IAAI,gBAAgB,KAAK,aAAa,QAAQ,cAAc;CAC5D,MAAM,YAAY,2BAA2B,KAAK,mBAAmB;EACnE,OAAO,OAAO,QAAQ,MAAM,IAAI,WAAW;EAC3C,UAAU,QAAQ;CACpB,CAAC;CACD,IAAI,CAAC,QAAQ,WAAW,KAAK,iBAAiB,GAAG,QAAQ,oBAAoB;CAC7E,MAAM,mBAAmB,IAAI,IAC3B,SAAS,6BAA6B,KAAK,eAAe,CACxD,WAAW,IACX,WAAW,YACb,CAAC,CACH;CACA,MAAM,cAAc,KAAK,6BAA6B,KAAK,eACzD,WAAW,SAAS,mBAAmB,WAAW,eAC9C;EACE,GAAG;EAC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,IAJ7B,IAAI,CAC7B,GAAG,aACH,GAAG,gBAAgB,6BAA6B,OAAO,IAAI,CAAC,CAC9D,CACqE,CAAC;EACtE,IAAI,OAAO,KAAK,OAAO,CAAC,CAAC,SAAS,GAAG,MAAM,WAAW,KAAK,IAAI,OAAO;CACxE;AACF"}
@@ -0,0 +1,38 @@
1
+ import { SceneGraph } from "../graph.js";
2
+ import { SceneNode } from "../types.js";
3
+ //#region src/transfer/dependencies.d.ts
4
+ /** What layers need from their document to draw the same in another one. */
5
+ interface LayerDependencies {
6
+ /** The variables the layers and their styles bind, and every variable those alias. */
7
+ variables: Set<string>;
8
+ /**
9
+ * The collections of those variables, those the layers set a mode of, and those a kept
10
+ * expression names a mode of.
11
+ */
12
+ collections: Set<string>;
13
+ /** The shared styles the layers use, as the style layers that define them. */
14
+ styles: SceneNode[];
15
+ /** The images the layers and their styles paint with. */
16
+ images: Set<string>;
17
+ }
18
+ /** The variables a layer names: its own bindings, its characters', and its overrides'. */
19
+ declare function layerVariableIds(node: SceneNode): string[];
20
+ /**
21
+ * The images a layer paints with: its fills, strokes, vector regions, text decorations, and
22
+ * characters.
23
+ */
24
+ declare function layerImageHashes(node: SceneNode): string[];
25
+ /**
26
+ * The variables, collections, styles, and images `layers` depend on, as a copy into another
27
+ * document must carry them: a style brings what it binds and paints with in turn, and a variable
28
+ * brings the variables it aliases.
29
+ */
30
+ declare function layerDependencies(graph: SceneGraph, layers: Iterable<SceneNode>): LayerDependencies;
31
+ /**
32
+ * These variables and every variable they alias, at any depth, with their collections and the
33
+ * collections a kept expression names a mode of.
34
+ */
35
+ declare function variableDependencies(graph: SceneGraph, ids: Iterable<string>): Pick<LayerDependencies, 'variables' | 'collections'>;
36
+ //#endregion
37
+ export { LayerDependencies, layerDependencies, layerImageHashes, layerVariableIds, variableDependencies };
38
+ //# sourceMappingURL=dependencies.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.d.ts","names":[],"sources":["../../src/transfer/dependencies.ts"],"mappings":";;;;UAUiB;;EAEf,WAAW;;;;;EAKX,aAAa;;EAEb,QAAQ;;EAER,QAAQ;;;iBAIM,iBAAiB,MAAM;;;;;iBAgBvB,iBAAiB,MAAM;;;;;;iBAkBvB,kBACd,OAAO,YACP,QAAQ,SAAS,aAChB;;;;;iBA8Ba,qBACd,OAAO,YACP,KAAK,mBACJ,KAAK"}
@@ -0,0 +1,100 @@
1
+ import { overriddenBindingField } from "../instances/overrides.js";
2
+ import { isUnsupportedVariableValue, variableValueReferences } from "../variables/value.js";
3
+ import { styleRunReferences } from "../text/references.js";
4
+ import { referencedStyleIds, sharedStyleLayers } from "../shared-styles.js";
5
+ import { regionFills } from "../vector-network.js";
6
+ import { imagePaintHashes } from "../images.js";
7
+ //#region src/transfer/dependencies.ts
8
+ /** The variables a layer names: its own bindings, its characters', and its overrides'. */
9
+ function layerVariableIds(node) {
10
+ const { self, descendants } = node.instanceOverrides;
11
+ const overridden = [...self, ...[...descendants.values()].flatMap((fields) => [...fields])];
12
+ return [
13
+ ...Object.values(node.boundVariables),
14
+ ...styleRunReferences(node.styleRuns).variables,
15
+ ...overridden.flatMap(([field, value]) => typeof value === "string" && overriddenBindingField(field) !== null ? [value] : [])
16
+ ];
17
+ }
18
+ /**
19
+ * The images a layer paints with: its fills, strokes, vector regions, text decorations, and
20
+ * characters.
21
+ */
22
+ function layerImageHashes(node) {
23
+ return imagePaintHashes([
24
+ ...node.fills,
25
+ ...node.strokes,
26
+ ...regionFills(node.vectorNetwork),
27
+ ...node.textDecorationFills,
28
+ ...node.styleRuns.flatMap((run) => [...run.style.fills ?? [], ...run.style.textDecorationFills ?? []])
29
+ ]);
30
+ }
31
+ /**
32
+ * The variables, collections, styles, and images `layers` depend on, as a copy into another
33
+ * document must carry them: a style brings what it binds and paints with in turn, and a variable
34
+ * brings the variables it aliases.
35
+ */
36
+ function layerDependencies(graph, layers) {
37
+ const collections = /* @__PURE__ */ new Set();
38
+ const images = /* @__PURE__ */ new Set();
39
+ const styles = /* @__PURE__ */ new Map();
40
+ const pending = [];
41
+ let styleLayers;
42
+ const styleLayer = (id) => (styleLayers ??= sharedStyleLayers(graph)).get(id);
43
+ const visit = (node) => {
44
+ for (const hash of layerImageHashes(node)) images.add(hash);
45
+ pending.push(...layerVariableIds(node));
46
+ for (const id of Object.keys(node.variableModes)) if (graph.variableCollections.has(id)) collections.add(id);
47
+ for (const id of referencedStyleIds(node)) {
48
+ const style = styles.has(id) ? void 0 : styleLayer(id);
49
+ if (!style) continue;
50
+ styles.set(id, style);
51
+ visit(style);
52
+ }
53
+ };
54
+ for (const node of layers) visit(node);
55
+ const resolved = variableDependencies(graph, pending);
56
+ for (const id of resolved.collections) collections.add(id);
57
+ return {
58
+ variables: resolved.variables,
59
+ collections,
60
+ styles: [...styles.values()],
61
+ images
62
+ };
63
+ }
64
+ /**
65
+ * These variables and every variable they alias, at any depth, with their collections and the
66
+ * collections a kept expression names a mode of.
67
+ */
68
+ function variableDependencies(graph, ids) {
69
+ const pending = [...ids];
70
+ const variables = /* @__PURE__ */ new Set();
71
+ const collections = /* @__PURE__ */ new Set();
72
+ let modeCollections;
73
+ const collectionOfMode = (modeId) => {
74
+ modeCollections ??= new Map([...graph.variableCollections.values()].flatMap((collection) => collection.modes.map((mode) => [mode.modeId, collection.id])));
75
+ return modeCollections.get(modeId);
76
+ };
77
+ for (let id = pending.pop(); id !== void 0; id = pending.pop()) {
78
+ if (variables.has(id)) continue;
79
+ const variable = graph.variables.get(id);
80
+ if (!variable) continue;
81
+ variables.add(id);
82
+ collections.add(variable.collectionId);
83
+ for (const value of Object.values(variable.valuesByMode)) {
84
+ pending.push(...variableValueReferences(value));
85
+ if (!isUnsupportedVariableValue(value)) continue;
86
+ for (const modeId of value.modes) {
87
+ const collection = collectionOfMode(modeId);
88
+ if (collection) collections.add(collection);
89
+ }
90
+ }
91
+ }
92
+ return {
93
+ variables,
94
+ collections
95
+ };
96
+ }
97
+ //#endregion
98
+ export { layerDependencies, layerImageHashes, layerVariableIds, variableDependencies };
99
+
100
+ //# sourceMappingURL=dependencies.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dependencies.js","names":[],"sources":["../../src/transfer/dependencies.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { imagePaintHashes } from '../images'\nimport { overriddenBindingField } from '../instances/overrides'\nimport { referencedStyleIds, sharedStyleLayers } from '../shared-styles'\nimport { styleRunReferences } from '../text/references'\nimport type { SceneNode } from '../types'\nimport { isUnsupportedVariableValue, variableValueReferences } from '../variables/value'\nimport { regionFills } from '../vector-network'\n\n/** What layers need from their document to draw the same in another one. */\nexport interface LayerDependencies {\n /** The variables the layers and their styles bind, and every variable those alias. */\n variables: Set<string>\n /**\n * The collections of those variables, those the layers set a mode of, and those a kept\n * expression names a mode of.\n */\n collections: Set<string>\n /** The shared styles the layers use, as the style layers that define them. */\n styles: SceneNode[]\n /** The images the layers and their styles paint with. */\n images: Set<string>\n}\n\n/** The variables a layer names: its own bindings, its characters', and its overrides'. */\nexport function layerVariableIds(node: SceneNode): string[] {\n const { self, descendants } = node.instanceOverrides\n const overridden = [...self, ...[...descendants.values()].flatMap((fields) => [...fields])]\n return [\n ...Object.values(node.boundVariables),\n ...styleRunReferences(node.styleRuns).variables,\n ...overridden.flatMap(([field, value]) =>\n typeof value === 'string' && overriddenBindingField(field) !== null ? [value] : []\n )\n ]\n}\n\n/**\n * The images a layer paints with: its fills, strokes, vector regions, text decorations, and\n * characters.\n */\nexport function layerImageHashes(node: SceneNode): string[] {\n return imagePaintHashes([\n ...node.fills,\n ...node.strokes,\n ...regionFills(node.vectorNetwork),\n ...node.textDecorationFills,\n ...node.styleRuns.flatMap((run) => [\n ...(run.style.fills ?? []),\n ...(run.style.textDecorationFills ?? [])\n ])\n ])\n}\n\n/**\n * The variables, collections, styles, and images `layers` depend on, as a copy into another\n * document must carry them: a style brings what it binds and paints with in turn, and a variable\n * brings the variables it aliases.\n */\nexport function layerDependencies(\n graph: SceneGraph,\n layers: Iterable<SceneNode>\n): LayerDependencies {\n const collections = new Set<string>()\n const images = new Set<string>()\n const styles = new Map<string, SceneNode>()\n const pending: string[] = []\n let styleLayers: Map<string, SceneNode> | undefined\n const styleLayer = (id: string): SceneNode | undefined =>\n (styleLayers ??= sharedStyleLayers(graph)).get(id)\n const visit = (node: SceneNode): void => {\n for (const hash of layerImageHashes(node)) images.add(hash)\n pending.push(...layerVariableIds(node))\n for (const id of Object.keys(node.variableModes))\n if (graph.variableCollections.has(id)) collections.add(id)\n for (const id of referencedStyleIds(node)) {\n const style = styles.has(id) ? undefined : styleLayer(id)\n if (!style) continue\n styles.set(id, style)\n visit(style)\n }\n }\n for (const node of layers) visit(node)\n const resolved = variableDependencies(graph, pending)\n for (const id of resolved.collections) collections.add(id)\n return { variables: resolved.variables, collections, styles: [...styles.values()], images }\n}\n\n/**\n * These variables and every variable they alias, at any depth, with their collections and the\n * collections a kept expression names a mode of.\n */\nexport function variableDependencies(\n graph: SceneGraph,\n ids: Iterable<string>\n): Pick<LayerDependencies, 'variables' | 'collections'> {\n const pending = [...ids]\n const variables = new Set<string>()\n const collections = new Set<string>()\n let modeCollections: Map<string, string> | undefined\n const collectionOfMode = (modeId: string): string | undefined => {\n modeCollections ??= new Map(\n [...graph.variableCollections.values()].flatMap((collection) =>\n collection.modes.map((mode) => [mode.modeId, collection.id] as const)\n )\n )\n return modeCollections.get(modeId)\n }\n for (let id = pending.pop(); id !== undefined; id = pending.pop()) {\n if (variables.has(id)) continue\n const variable = graph.variables.get(id)\n if (!variable) continue\n variables.add(id)\n collections.add(variable.collectionId)\n for (const value of Object.values(variable.valuesByMode)) {\n pending.push(...variableValueReferences(value))\n // A kept expression can name a mode of a collection none of its aliases reach.\n if (!isUnsupportedVariableValue(value)) continue\n for (const modeId of value.modes) {\n const collection = collectionOfMode(modeId)\n if (collection) collections.add(collection)\n }\n }\n }\n return { variables, collections }\n}\n"],"mappings":";;;;;;;;AAyBA,SAAgB,iBAAiB,MAA2B;CAC1D,MAAM,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AAW;CAAY;AAClC"}
@@ -22,7 +22,6 @@ function captureTransferredState(graph, original) {
22
22
  }),
23
23
  variables: original.variables.map((variable) => structuredClone(requireValue(graph.variables.get(variable.id), "variable", variable.id))),
24
24
  collections: original.collections.map((collection) => structuredClone(requireValue(graph.variableCollections.get(collection.id), "collection", collection.id))),
25
- activeModes: new Map(original.collections.map((collection) => [collection.id, requireValue(graph.activeMode.get(collection.id), "active mode", collection.id)])),
26
25
  images: new Map([...original.images.keys()].map((hash) => [hash, requireValue(graph.images.get(hash), "image", hash).slice()]))
27
26
  };
28
27
  }
@@ -1 +1 @@
1
- {"version":3,"file":"history.js","names":[],"sources":["../../src/transfer/history.ts"],"sourcesContent":["import { cloneNodeProps } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport type { GraphTransferPlan } from './apply'\n\n/** Capture post-placement state for redo; this does not authorize deleting shared resources. */\nexport function captureTransferredState(\n graph: SceneGraph,\n original: GraphTransferPlan\n): GraphTransferPlan {\n const requireValue = <T>(value: T | undefined, kind: string, id: string): T => {\n if (value === undefined) throw new Error(`Missing transferred ${kind} ${id}`)\n return value\n }\n return {\n nodeIds: new Map(original.nodeIds),\n rootIds: [...original.rootIds],\n dependencyPageIds: [...original.dependencyPageIds],\n nodes: original.nodes.map((entry) => {\n const node = requireValue(graph.getNode(entry.id), 'node', entry.id)\n if (!node.parentId) throw new Error(`Missing transferred parent ${entry.id}`)\n return {\n id: node.id,\n type: node.type,\n parentId: node.parentId,\n props: cloneNodeProps(node, null)\n }\n }),\n variables: original.variables.map((variable) =>\n structuredClone(requireValue(graph.variables.get(variable.id), 'variable', variable.id))\n ),\n collections: original.collections.map((collection) =>\n structuredClone(\n requireValue(graph.variableCollections.get(collection.id), 'collection', collection.id)\n )\n ),\n activeModes: new Map(\n original.collections.map((collection) => [\n collection.id,\n requireValue(graph.activeMode.get(collection.id), 'active mode', collection.id)\n ])\n ),\n images: new Map(\n [...original.images.keys()].map((hash) => [\n hash,\n requireValue(graph.images.get(hash), 'image', hash).slice()\n ])\n )\n }\n}\n"],"mappings":";;;AAKA,SAAgB,wBACd,OACA,UACmB;CACnB,MAAM,gBAAmB,OAAsB,MAAc,OAAkB;EAC7E,IAAI,UAAU,KAAA,GAAW,MAAM,IAAI,MAAM,uBAAuB,KAAK,GAAG,IAAI;EAC5E,OAAO;CACT;CACA,OAAO;EACL,SAAS,IAAI,IAAI,SAAS,OAAO;EACjC,SAAS,CAAC,GAAG,SAAS,OAAO;EAC7B,mBAAmB,CAAC,GAAG,SAAS,iBAAiB;EACjD,OAAO,SAAS,MAAM,KAAK,UAAU;GACnC,MAAM,OAAO,aAAa,MAAM,QAAQ,MAAM,EAAE,GAAG,QAAQ,MAAM,EAAE;GACnE,IAAI,CAAC,KAAK,UAAU,MAAM,IAAI,MAAM,8BAA8B,MAAM,IAAI;GAC5E,OAAO;IACL,IAAI,KAAK;IACT,MAAM,KAAK;IACX,UAAU,KAAK;IACf,OAAO,eAAe,MAAM,IAAI;GAClC;EACF,CAAC;EACD,WAAW,SAAS,UAAU,KAAK,aACjC,gBAAgB,aAAa,MAAM,UAAU,IAAI,SAAS,EAAE,GAAG,YAAY,SAAS,EAAE,CAAC,CACzF;EACA,aAAa,SAAS,YAAY,KAAK,eACrC,gBACE,aAAa,MAAM,oBAAoB,IAAI,WAAW,EAAE,GAAG,cAAc,WAAW,EAAE,CACxF,CACF;EACA,aAAa,IAAI,IACf,SAAS,YAAY,KAAK,eAAe,CACvC,WAAW,IACX,aAAa,MAAM,WAAW,IAAI,WAAW,EAAE,GAAG,eAAe,WAAW,EAAE,CAChF,CAAC,CACH;EACA,QAAQ,IAAI,IACV,CAAC,GAAG,SAAS,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CACxC,MACA,aAAa,MAAM,OAAO,IAAI,IAAI,GAAG,SAAS,IAAI,CAAC,CAAC,MAAM,CAC5D,CAAC,CACH;CACF;AACF"}
1
+ {"version":3,"file":"history.js","names":[],"sources":["../../src/transfer/history.ts"],"sourcesContent":["import { cloneNodeProps } from '../copy'\nimport type { SceneGraph } from '../graph'\nimport type { GraphTransferPlan } from './apply'\n\n/** Capture post-placement state for redo; this does not authorize deleting shared resources. */\nexport function captureTransferredState(\n graph: SceneGraph,\n original: GraphTransferPlan\n): GraphTransferPlan {\n const requireValue = <T>(value: T | undefined, kind: string, id: string): T => {\n if (value === undefined) throw new Error(`Missing transferred ${kind} ${id}`)\n return value\n }\n return {\n nodeIds: new Map(original.nodeIds),\n rootIds: [...original.rootIds],\n dependencyPageIds: [...original.dependencyPageIds],\n nodes: original.nodes.map((entry) => {\n const node = requireValue(graph.getNode(entry.id), 'node', entry.id)\n if (!node.parentId) throw new Error(`Missing transferred parent ${entry.id}`)\n return {\n id: node.id,\n type: node.type,\n parentId: node.parentId,\n props: cloneNodeProps(node, null)\n }\n }),\n variables: original.variables.map((variable) =>\n structuredClone(requireValue(graph.variables.get(variable.id), 'variable', variable.id))\n ),\n collections: original.collections.map((collection) =>\n structuredClone(\n requireValue(graph.variableCollections.get(collection.id), 'collection', collection.id)\n )\n ),\n images: new Map(\n [...original.images.keys()].map((hash) => [\n hash,\n requireValue(graph.images.get(hash), 'image', hash).slice()\n ])\n )\n }\n}\n"],"mappings":";;;AAKA,SAAgB,wBACd,OACA,UACmB;CACnB,MAAM,gBAAmB,OAAsB,MAAc,OAAkB;EAC7E,IAAI,UAAU,KAAA,GAAW,MAAM,IAAI,MAAM,uBAAuB,KAAK,GAAG,IAAI;EAC5E,OAAO;CACT;CACA,OAAO;EACL,SAAS,IAAI,IAAI,SAAS,OAAO;EACjC,SAAS,CAAC,GAAG,SAAS,OAAO;EAC7B,mBAAmB,CAAC,GAAG,SAAS,iBAAiB;EACjD,OAAO,SAAS,MAAM,KAAK,UAAU;GACnC,MAAM,OAAO,aAAa,MAAM,QAAQ,MAAM,EAAE,GAAG,QAAQ,MAAM,EAAE;GACnE,IAAI,CAAC,KAAK,UAAU,MAAM,IAAI,MAAM,8BAA8B,MAAM,IAAI;GAC5E,OAAO;IACL,IAAI,KAAK;IACT,MAAM,KAAK;IACX,UAAU,KAAK;IACf,OAAO,eAAe,MAAM,IAAI;GAClC;EACF,CAAC;EACD,WAAW,SAAS,UAAU,KAAK,aACjC,gBAAgB,aAAa,MAAM,UAAU,IAAI,SAAS,EAAE,GAAG,YAAY,SAAS,EAAE,CAAC,CACzF;EACA,aAAa,SAAS,YAAY,KAAK,eACrC,gBACE,aAAa,MAAM,oBAAoB,IAAI,WAAW,EAAE,GAAG,cAAc,WAAW,EAAE,CACxF,CACF;EACA,QAAQ,IAAI,IACV,CAAC,GAAG,SAAS,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,SAAS,CACxC,MACA,aAAa,MAAM,OAAO,IAAI,IAAI,GAAG,SAAS,IAAI,CAAC,CAAC,MAAM,CAC5D,CAAC,CACH;CACF;AACF"}
@@ -2,7 +2,9 @@ import { GraphTransferInput, prepareGraphTransfer } from "./plan.js";
2
2
  import { GraphTransferPlan, applyGraphTransfer } from "./apply.js";
3
3
  import { removeGraphTransfer } from "./remove.js";
4
4
  import { captureTransferredState } from "./history.js";
5
- import { VariableTransferReferences, prepareVariableTransfer } from "./variables.js";
5
+ import { VariableTransferReferences, copyVariableTables, prepareVariableTransfer } from "./variables.js";
6
6
  import { NodeTransferReferences, prepareNodeTransfer } from "./nodes.js";
7
- import { remapCopiedReferences } from "./copied.js";
8
- export { type GraphTransferInput, type GraphTransferPlan, type NodeTransferReferences, type VariableTransferReferences, applyGraphTransfer, captureTransferredState, prepareGraphTransfer, prepareNodeTransfer, prepareVariableTransfer, remapCopiedReferences, removeGraphTransfer };
7
+ import { CopiedReferenceOptions, ReferenceResolvers, instanceSwapPropertyIds, remapCopiedReferences, resolvedReferences } from "./copied.js";
8
+ import { LayerDependencies, layerDependencies, layerImageHashes, layerVariableIds, variableDependencies } from "./dependencies.js";
9
+ import { ResourceReferences, remappedResourceReferences } from "./resources.js";
10
+ export { type CopiedReferenceOptions, type GraphTransferInput, type GraphTransferPlan, type LayerDependencies, type NodeTransferReferences, type ReferenceResolvers, type ResourceReferences, type VariableTransferReferences, applyGraphTransfer, captureTransferredState, copyVariableTables, instanceSwapPropertyIds, layerDependencies, layerImageHashes, layerVariableIds, prepareGraphTransfer, prepareNodeTransfer, prepareVariableTransfer, remapCopiedReferences, remappedResourceReferences, removeGraphTransfer, resolvedReferences, variableDependencies };
@@ -1,8 +1,10 @@
1
- import { remapCopiedReferences } from "./copied.js";
1
+ import { instanceSwapPropertyIds, remapCopiedReferences, resolvedReferences } from "./copied.js";
2
+ import { remappedResourceReferences } from "./resources.js";
2
3
  import { prepareNodeTransfer } from "./nodes.js";
3
4
  import { removeGraphTransfer } from "./remove.js";
4
5
  import { captureTransferredState } from "./history.js";
5
- import { prepareVariableTransfer } from "./variables.js";
6
+ import { copyVariableTables, prepareVariableTransfer } from "./variables.js";
6
7
  import { applyGraphTransfer } from "./apply.js";
7
8
  import { prepareGraphTransfer } from "./plan.js";
8
- export { applyGraphTransfer, captureTransferredState, prepareGraphTransfer, prepareNodeTransfer, prepareVariableTransfer, remapCopiedReferences, removeGraphTransfer };
9
+ import { layerDependencies, layerImageHashes, layerVariableIds, variableDependencies } from "./dependencies.js";
10
+ export { applyGraphTransfer, captureTransferredState, copyVariableTables, instanceSwapPropertyIds, layerDependencies, layerImageHashes, layerVariableIds, prepareGraphTransfer, prepareNodeTransfer, prepareVariableTransfer, remapCopiedReferences, remappedResourceReferences, removeGraphTransfer, resolvedReferences, variableDependencies };
@@ -1 +1 @@
1
- {"version":3,"file":"nodes.d.ts","names":[],"sources":["../../src/transfer/nodes.ts"],"mappings":";;;UAsCiB,+BAA+B;EAC9C,OAAO;EACP,QAAQ;EACR,YAAY;EACZ,eAAe,oBAAoB;;;iBAIrB,oBACd,QAAQ,WACR,MAAM,yBACL,QAAQ"}
1
+ {"version":3,"file":"nodes.d.ts","names":[],"sources":["../../src/transfer/nodes.ts"],"mappings":";;;UAuCiB,+BAA+B;EAC9C,OAAO;EACP,QAAQ;EACR,YAAY;EACZ,eAAe,oBAAoB;;;iBAIrB,oBACd,QAAQ,WACR,MAAM,yBACL,QAAQ"}
@@ -1,8 +1,9 @@
1
1
  import { overriddenBindingField, remapInstanceOverrideState } from "../instances/overrides.js";
2
2
  import { cloneNodeProps } from "../copy.js";
3
- import { remapStyleRunReferences, styleRunReferences } from "../text/references.js";
3
+ import { styleRunReferences } from "../text/references.js";
4
4
  import { referencedStyleIds } from "../shared-styles.js";
5
5
  import { requireTransferReference } from "./references.js";
6
+ import { remappedResourceReferences } from "./resources.js";
6
7
  //#region src/transfer/nodes.ts
7
8
  function semanticTransferReferences(node) {
8
9
  const runs = styleRunReferences(node.styleRuns);
@@ -37,25 +38,17 @@ function prepareNodeTransfer(source, refs) {
37
38
  variable,
38
39
  collection: (id) => refs.collections.get(id)
39
40
  });
40
- result.boundVariables = Object.fromEntries(Object.entries(source.boundVariables).map(([field, id]) => [field, variable(id)]));
41
- result.variableModes = Object.fromEntries(Object.entries(source.variableModes).map(([collection, mode]) => [requireTransferReference(refs.collections, collection, "collection"), requireTransferReference(refs.modes, mode, "mode")]));
42
- for (const field of [
43
- "fillStyleId",
44
- "strokeStyleId",
45
- "textStyleId",
46
- "effectStyleId",
47
- "gridStyleId"
48
- ]) result[field] = source[field] ? style(source[field]) : null;
49
- if (result.styleRuns) result.styleRuns = remapStyleRunReferences(result.styleRuns, {
41
+ Object.assign(result, remappedResourceReferences(source, {
50
42
  variable,
43
+ collection: (id) => requireTransferReference(refs.collections, id, "collection"),
44
+ mode: (id) => requireTransferReference(refs.modes, id, "mode"),
51
45
  style,
52
- node: (id) => refs.nodes.get(id) ?? id
53
- });
46
+ layer: (id) => refs.nodes.get(id) ?? id
47
+ }));
54
48
  for (const field of ["connectorStart", "connectorEnd"]) {
55
49
  const endpoint = result[field];
56
50
  if (endpoint?.nodeId) endpoint.nodeId = refs.nodes.get(endpoint.nodeId) ?? endpoint.nodeId;
57
51
  }
58
- for (const region of result.vectorNetwork?.regions ?? []) if (region.fillStyleId) region.fillStyleId = style(region.fillStyleId);
59
52
  result.componentPropertyDefinitions = source.componentPropertyDefinitions.map((definition) => ({
60
53
  ...structuredClone(definition),
61
54
  id: property(definition.id),
@@ -1 +1 @@
1
- {"version":3,"file":"nodes.js","names":["required"],"sources":["../../src/transfer/nodes.ts"],"sourcesContent":["import { cloneNodeProps } from '../copy'\nimport { overriddenBindingField, remapInstanceOverrideState } from '../instances/overrides'\nimport { referencedStyleIds } from '../shared-styles'\nimport { remapStyleRunReferences, styleRunReferences } from '../text/references'\nimport type { ComponentPropertyType, SceneNode } from '../types'\nimport { requireTransferReference as required } from './references'\nimport type { VariableTransferReferences } from './variables'\n\nexport function semanticTransferReferences(node: SceneNode): string[] {\n const runs = styleRunReferences(node.styleRuns)\n return [\n ...(node.componentId ? [node.componentId] : []),\n ...Object.values(node.boundVariables),\n ...runs.variables,\n ...referencedStyleIds(node),\n ...Object.entries(node.componentPropertyAssignments).flatMap(([id, value]) => [id, value]),\n ...node.componentPropertyReferences.map((reference) => reference.propertyId),\n ...node.componentPropertyDefinitions.flatMap((definition) => [\n definition.id,\n ...(definition.type === 'INSTANCE_SWAP' && definition.defaultValue\n ? [definition.defaultValue]\n : [])\n ]),\n ...node.instanceOverrides.descendants.keys(),\n ...[\n ...node.instanceOverrides.self,\n ...[...node.instanceOverrides.descendants.values()].flatMap((fields) => [...fields])\n ].flatMap(([field, value]) =>\n typeof value === 'string' &&\n (field === 'componentId' ||\n field === 'sourceComponentId' ||\n overriddenBindingField(field) !== null)\n ? [value]\n : []\n )\n ]\n}\n\nexport interface NodeTransferReferences extends VariableTransferReferences {\n nodes: ReadonlyMap<string, string>\n styles: ReadonlyMap<string, string>\n properties: ReadonlyMap<string, string>\n propertyTypes: ReadonlyMap<string, ComponentPropertyType>\n}\n\n/** Prepare runtime references without rewriting original format identities or ordinary text. */\nexport function prepareNodeTransfer(\n source: SceneNode,\n refs: NodeTransferReferences\n): Partial<SceneNode> {\n const node = (id: string) => required(refs.nodes, id, 'node')\n const variable = (id: string) => required(refs.variables, id, 'variable')\n const property = (id: string) => required(refs.properties, id, 'property')\n const style = (id: string) => required(refs.styles, id, 'style')\n const propertyValue = (id: string, value: string): string => {\n const type = refs.propertyTypes.get(id)\n if (!type) throw new Error(`Missing property transfer type: ${id}`)\n return type === 'INSTANCE_SWAP' && value ? node(value) : value\n }\n const values = (entries: Record<string, string>) =>\n Object.fromEntries(\n Object.entries(entries).map(([id, value]) => [property(id), propertyValue(id, value)])\n )\n const result = cloneNodeProps(source, null)\n result.componentId = source.componentId ? node(source.componentId) : null\n result.instanceOverrides = remapInstanceOverrideState(source.instanceOverrides, {\n node,\n variable,\n collection: (id) => refs.collections.get(id)\n })\n result.boundVariables = Object.fromEntries(\n Object.entries(source.boundVariables).map(([field, id]) => [field, variable(id)])\n )\n result.variableModes = Object.fromEntries(\n Object.entries(source.variableModes).map(([collection, mode]) => [\n required(refs.collections, collection, 'collection'),\n required(refs.modes, mode, 'mode')\n ])\n )\n for (const field of [\n 'fillStyleId',\n 'strokeStyleId',\n 'textStyleId',\n 'effectStyleId',\n 'gridStyleId'\n ] as const) {\n result[field] = source[field] ? style(source[field]) : null\n }\n if (result.styleRuns) {\n // A link to a layer the transfer leaves behind keeps naming it.\n result.styleRuns = remapStyleRunReferences(result.styleRuns, {\n variable,\n style,\n node: (id) => refs.nodes.get(id) ?? id\n })\n }\n // A connector keeps the layers it was attached to when they are left behind; the end becomes\n // free where nothing by that ID exists, as a pasted Figma connector does.\n for (const field of ['connectorStart', 'connectorEnd'] as const) {\n const endpoint = result[field]\n if (endpoint?.nodeId) endpoint.nodeId = refs.nodes.get(endpoint.nodeId) ?? endpoint.nodeId\n }\n for (const region of result.vectorNetwork?.regions ?? [])\n if (region.fillStyleId) region.fillStyleId = style(region.fillStyleId)\n result.componentPropertyDefinitions = source.componentPropertyDefinitions.map((definition) => ({\n ...structuredClone(definition),\n id: property(definition.id),\n defaultValue: propertyValue(definition.id, definition.defaultValue)\n }))\n // A reference to a property that neither the transfer nor its destination defines names nothing.\n result.componentPropertyReferences = source.componentPropertyReferences.flatMap((reference) => {\n const propertyId = refs.properties.get(reference.propertyId)\n return propertyId ? [{ ...reference, propertyId }] : []\n })\n result.componentPropertyAssignments = values(source.componentPropertyAssignments)\n // Variant values are keyed by display names, unlike definition-ID assignments.\n result.componentPropertyValues = { ...source.componentPropertyValues }\n return result\n}\n"],"mappings":";;;;;;AAQA,SAAgB,2BAA2B,MAA2B;CACpE,MAAM,OAAO,mBAAmB,KAAK,SAAS;CAC9C,OAAO;EACL,GAAI,KAAK,cAAc,CAAC,KAAK,WAAW,IAAI,CAAC;EAC7C,GAAG,OAAO,OAAO,KAAK,cAAc;EACpC,GAAG,KAAK;EACR,GAAG,mBAAmB,IAAI;EAC1B,GAAG,OAAO,QAAQ,KAAK,4BAA4B,CAAC,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC,IAAI,KAAK,CAAC;EACzF,GAAG,KAAK,4BAA4B,KAAK,cAAc,UAAU,UAAU;EAC3E,GAAG,KAAK,6BAA6B,SAAS,eAAe,CAC3D,WAAW,IACX,GAAI,WAAW,SAAS,mBAAmB,WAAW,eAClD,CAAC,WAAW,YAAY,IACxB,CAAC,CACP,CAAC;EACD,GAAG,KAAK,kBAAkB,YAAY,KAAK;EAC3C,GAAG,CACD,GAAG,KAAK,kBAAkB,MAC1B,GAAG,CAAC,GAAG,KAAK,kBAAkB,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,MAAM,CAAC,CACrF,CAAC,CAAC,SAAS,CAAC,OAAO,WACjB,OAAO,UAAU,aAChB,UAAU,iBACT,UAAU,uBACV,uBAAuB,KAAK,MAAM,QAChC,CAAC,KAAK,IACN,CAAC,CACP;CACF;AACF;;AAUA,SAAgB,oBACd,QACA,MACoB;CACpB,MAAM,QAAQ,OAAeA,yBAAS,KAAK,OAAO,IAAI,MAAM;CAC5D,MAAM,YAAY,OAAeA,yBAAS,KAAK,WAAW,IA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KAAK,MAAM,SAAS,CAAC,kBAAkB,cAAc,GAAY;EAC/D,MAAM,WAAW,OAAO;EACxB,IAAI,UAAU,QAAQ,SAAS,SAAS,KAAK,MAAM,IAAI,SAAS,MAAM,KAAK,SAAS;CACtF;CACA,KAAK,MAAM,UAAU,OAAO,eAAe,WAAW,CAAC,GACrD,IAAI,OAAO,aAAa,OAAO,cAAc,MAAM,OAAO,WAAW;CACvE,OAAO,+BAA+B,OAAO,6BAA6B,KAAK,gBAAgB;EAC7F,GAAG,gBAAgB,UAAU;EAC7B,IAAI,SAAS,WAAW,EAAE;EAC1B,cAAc,cAAc,WAAW,IAAI,WAAW,YAAY;CACpE,EAAE;CAEF,OAAO,8BAA8B,OAAO,4BAA4B,SAAS,cAAc;EAC7F,MAAM,aAAa,KAAK,WAAW,IAAI,UAAU,UAAU;EAC3D,OAAO,aAAa,CAAC;GAAE,GAAG;GAAW;EAAW,CAAC,IAAI,CAAC;CACxD,CAAC;CACD,OAAO,+BAA+B,OAAO,OAAO,4BAA4B;CAEhF,OAAO,0BAA0B,EAAE,GAAG,OAAO,wBAAwB;CACrE,OAAO;AACT"}
1
+ {"version":3,"file":"nodes.js","names":["required"],"sources":["../../src/transfer/nodes.ts"],"sourcesContent":["import { cloneNodeProps } from '../copy'\nimport { overriddenBindingField, remapInstanceOverrideState } from '../instances/overrides'\nimport { referencedStyleIds } from '../shared-styles'\nimport { styleRunReferences } from '../text/references'\nimport type { ComponentPropertyType, SceneNode } from '../types'\nimport { requireTransferReference as required } from './references'\nimport { remappedResourceReferences } from './resources'\nimport type { VariableTransferReferences } from './variables'\n\nexport function semanticTransferReferences(node: SceneNode): string[] {\n const runs = styleRunReferences(node.styleRuns)\n return [\n ...(node.componentId ? [node.componentId] : []),\n ...Object.values(node.boundVariables),\n ...runs.variables,\n ...referencedStyleIds(node),\n ...Object.entries(node.componentPropertyAssignments).flatMap(([id, value]) => [id, value]),\n ...node.componentPropertyReferences.map((reference) => reference.propertyId),\n ...node.componentPropertyDefinitions.flatMap((definition) => [\n definition.id,\n ...(definition.type === 'INSTANCE_SWAP' && definition.defaultValue\n ? [definition.defaultValue]\n : [])\n ]),\n ...node.instanceOverrides.descendants.keys(),\n ...[\n ...node.instanceOverrides.self,\n ...[...node.instanceOverrides.descendants.values()].flatMap((fields) => [...fields])\n ].flatMap(([field, value]) =>\n typeof value === 'string' &&\n (field === 'componentId' ||\n field === 'sourceComponentId' ||\n overriddenBindingField(field) !== null)\n ? [value]\n : []\n )\n ]\n}\n\nexport interface NodeTransferReferences extends VariableTransferReferences {\n nodes: ReadonlyMap<string, string>\n styles: ReadonlyMap<string, string>\n properties: ReadonlyMap<string, string>\n propertyTypes: ReadonlyMap<string, ComponentPropertyType>\n}\n\n/** Prepare runtime references without rewriting original format identities or ordinary text. */\nexport function prepareNodeTransfer(\n source: SceneNode,\n refs: NodeTransferReferences\n): Partial<SceneNode> {\n const node = (id: string) => required(refs.nodes, id, 'node')\n const variable = (id: string) => required(refs.variables, id, 'variable')\n const property = (id: string) => required(refs.properties, id, 'property')\n const style = (id: string) => required(refs.styles, id, 'style')\n const propertyValue = (id: string, value: string): string => {\n const type = refs.propertyTypes.get(id)\n if (!type) throw new Error(`Missing property transfer type: ${id}`)\n return type === 'INSTANCE_SWAP' && value ? node(value) : value\n }\n const values = (entries: Record<string, string>) =>\n Object.fromEntries(\n Object.entries(entries).map(([id, value]) => [property(id), propertyValue(id, value)])\n )\n const result = cloneNodeProps(source, null)\n result.componentId = source.componentId ? node(source.componentId) : null\n result.instanceOverrides = remapInstanceOverrideState(source.instanceOverrides, {\n node,\n variable,\n collection: (id) => refs.collections.get(id)\n })\n Object.assign(\n result,\n remappedResourceReferences(source, {\n variable,\n collection: (id) => required(refs.collections, id, 'collection'),\n mode: (id) => required(refs.modes, id, 'mode'),\n style,\n // A link to a layer the transfer leaves behind keeps naming it.\n layer: (id) => refs.nodes.get(id) ?? id\n })\n )\n // A connector keeps the layers it was attached to when they are left behind; the end becomes\n // free where nothing by that ID exists, as a pasted Figma connector does.\n for (const field of ['connectorStart', 'connectorEnd'] as const) {\n const endpoint = result[field]\n if (endpoint?.nodeId) endpoint.nodeId = refs.nodes.get(endpoint.nodeId) ?? endpoint.nodeId\n }\n result.componentPropertyDefinitions = source.componentPropertyDefinitions.map((definition) => ({\n ...structuredClone(definition),\n id: property(definition.id),\n defaultValue: propertyValue(definition.id, definition.defaultValue)\n }))\n // A reference to a property that neither the transfer nor its destination defines names nothing.\n result.componentPropertyReferences = source.componentPropertyReferences.flatMap((reference) => {\n const propertyId = refs.properties.get(reference.propertyId)\n return propertyId ? [{ ...reference, propertyId }] : []\n })\n result.componentPropertyAssignments = values(source.componentPropertyAssignments)\n // Variant values are keyed by display names, unlike definition-ID assignments.\n result.componentPropertyValues = { ...source.componentPropertyValues }\n return result\n}\n"],"mappings":";;;;;;;AASA,SAAgB,2BAA2B,MAA2B;CACpE,MAAM,OAAO,mBAAmB,KAAK,SAAS;CAC9C,OAAO;EACL,GAAI,KAAK,cAAc,CAAC,KAAK,WAAW,IAAI,CAAC;EAC7C,GAAG,OAAO,OAAO,KAAK,cAAc;EACpC,GAAG,KAAK;EACR,GAAG,mBAAmB,IAAI;EAC1B,GAAG,OAAO,QAAQ,KAAK,4BAA4B,CAAC,CAAC,SAAS,CAAC,IAAI,WAAW,CAAC,IAAI,KAAK,CAAC;EACzF,GAAG,KAAK,4BAA4B,KAAK,cAAc,UAAU,UAAU;EAC3E,GAAG,KAAK,6BAA6B,SAAS,eAAe,CAC3D,WAAW,IACX,GAAI,WAAW,SAAS,mBAAmB,WAAW,eAClD,CAAC,WAAW,YAAY,IACxB,CAAC,CACP,CAAC;EACD,GAAG,KAAK,kBAAkB,YAAY,KAAK;EAC3C,GAAG,CACD,GAAG,KAAK,kBAAkB,MAC1B,GAAG,CAAC,GAAG,KAAK,kBAAkB,YAAY,OAAO,CAAC,CAAC,CAAC,SAAS,WAAW,CAAC,GAAG,MAAM,CAAC,CACrF,CAAC,CAAC,SAAS,CAAC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,QAAQ,SAAS,SAAS,KAAK,MAAM,IAAI,SAAS,MAAM,KAAK,SAAS;CACtF;CACA,OAAO,+BAA+B,OAAO,6BAA6B,KAAK,gBAAgB;EAC7F,GAAG,gBAAgB,UAAU;EAC7B,IAAI,SAAS,WAAW,EAAE;EAC1B,cAAc,cAAc,WAAW,IAAI,WAAW,YAAY;CACpE,EAAE;CAEF,OAAO,8BAA8B,OAAO,4BAA4B,SAAS,cAAc;EAC7F,MAAM,aAAa,KAAK,WAAW,IAAI,UAAU,UAAU;EAC3D,OAAO,aAAa,CAAC;GAAE,GAAG;GAAW;EAAW,CAAC,IAAI,CAAC;CACxD,CAAC;CACD,OAAO,+BAA+B,OAAO,OAAO,4BAA4B;CAEhF,OAAO,0BAA0B,EAAE,GAAG,OAAO,wBAAwB;CACrE,OAAO;AACT"}
@@ -10,7 +10,6 @@ interface GraphTransferInput {
10
10
  }
11
11
  /** Preflight a self-contained fragment; allocation does not insert anything into the target. */
12
12
  declare function prepareGraphTransfer(input: GraphTransferInput): {
13
- activeModes: Map<string, string>;
14
13
  images: Map<string, Uint8Array<ArrayBuffer>>;
15
14
  variables: Variable[];
16
15
  collections: VariableCollection[];
@@ -1,4 +1,4 @@
1
- import { requireTransferReference } from "./references.js";
1
+ import { sharedStyleLayers } from "../shared-styles.js";
2
2
  import { prepareNodeTransfer } from "./nodes.js";
3
3
  import { prepareVariableTransfer } from "./variables.js";
4
4
  //#region src/transfer/plan.ts
@@ -55,13 +55,12 @@ function prepareGraphTransfer(input) {
55
55
  propertyTypes.set(definition.id, definition.type);
56
56
  if (!properties.has(definition.id)) properties.set(definition.id, allocate());
57
57
  }
58
- const targetStyleIds = /* @__PURE__ */ new Set();
59
- for (const node of target.getAllNodes()) if (node.sharedStyleType !== null && node.source.id) targetStyleIds.add(node.source.id);
58
+ const targetStyles = sharedStyleLayers(target);
60
59
  const styles = /* @__PURE__ */ new Map();
61
60
  for (const node of ordered) {
62
61
  const id = node.source.id;
63
62
  if (node.sharedStyleType === null || !id) continue;
64
- styles.set(id, targetStyleIds.has(id) ? allocate() : id);
63
+ styles.set(id, targetStyles.has(id) ? allocate() : id);
65
64
  }
66
65
  const references = {
67
66
  nodes,
@@ -96,7 +95,6 @@ function prepareGraphTransfer(input) {
96
95
  props: withStyleId(node, prepareNodeTransfer(node, references), styles)
97
96
  })),
98
97
  ...resources,
99
- activeModes: new Map([...source.activeMode].map(([collection, mode]) => [requireTransferReference(collections, collection, "collection"), requireTransferReference(modes, mode, "mode")])),
100
98
  images: new Map([...source.images].map(([hash, bytes]) => [hash, bytes.slice()]))
101
99
  };
102
100
  }
@@ -1 +1 @@
1
- {"version":3,"file":"plan.js","names":[],"sources":["../../src/transfer/plan.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { ComponentPropertyType, SceneNode } from '../types'\nimport { prepareNodeTransfer } from './nodes'\nimport { requireTransferReference } from './references'\nimport { prepareVariableTransfer } from './variables'\n\nexport interface GraphTransferInput {\n source: SceneGraph\n rootIds: readonly string[]\n dependencyPageIds: readonly string[]\n target: SceneGraph\n parentId: string\n}\n\n/** A transferred style's props under the ID the transfer gives it. */\nfunction withStyleId(\n node: SceneNode,\n props: Partial<SceneNode>,\n styles: ReadonlyMap<string, string>\n): Partial<SceneNode> {\n const id =\n node.sharedStyleType !== null && node.source.id ? styles.get(node.source.id) : undefined\n if (!id || id === node.source.id) return props\n return { ...props, source: { ...(props.source ?? node.source), id } }\n}\n\n/** Preflight a self-contained fragment; allocation does not insert anything into the target. */\nexport function prepareGraphTransfer(input: GraphTransferInput) {\n const { source, target, parentId } = input\n if (!target.getNode(parentId)) throw new Error(`Missing transfer parent ${parentId}`)\n const reserved = new Set([\n ...target.nodes.keys(),\n ...target.variables.keys(),\n ...target.variableCollections.keys()\n ])\n for (const collection of target.variableCollections.values())\n for (const mode of collection.modes) reserved.add(mode.modeId)\n let sequence = 0\n const namespace = crypto.randomUUID()\n const allocate = (): string => {\n let id = `${namespace}:${sequence++}`\n while (reserved.has(id)) id = `${namespace}:${sequence++}`\n reserved.add(id)\n return id\n }\n const ordered: SceneNode[] = []\n const seen = new Set<string>()\n const visit = (id: string): void => {\n if (seen.has(id)) throw new Error(`Repeated transfer node ${id}`)\n const node = source.getNode(id)\n if (!node) throw new Error(`Missing transfer source ${id}`)\n seen.add(id)\n ordered.push(node)\n for (const child of node.childIds) visit(child)\n }\n for (const id of [...input.dependencyPageIds, ...input.rootIds]) visit(id)\n const nodes = new Map(ordered.map((node) => [node.id, allocate()]))\n const variables = new Map([...source.variables.keys()].map((id) => [id, allocate()]))\n const collections = new Map([...source.variableCollections.keys()].map((id) => [id, allocate()]))\n const modes = new Map<string, string>()\n for (const collection of source.variableCollections.values()) {\n for (const mode of collection.modes)\n if (!modes.has(mode.modeId)) modes.set(mode.modeId, allocate())\n }\n const properties = new Map<string, string>()\n const propertyTypes = new Map<string, ComponentPropertyType>()\n for (const node of ordered)\n for (const definition of node.componentPropertyDefinitions) {\n if (propertyTypes.has(definition.id) && propertyTypes.get(definition.id) !== definition.type)\n throw new Error(`Conflicting property type ${definition.id}`)\n propertyTypes.set(definition.id, definition.type)\n if (!properties.has(definition.id)) properties.set(definition.id, allocate())\n }\n // Layers name a style by the style's own ID, which a transferred style keeps unless the\n // target already holds another style by it: IDs read from Figma are only unique in one file.\n const targetStyleIds = new Set<string>()\n for (const node of target.getAllNodes())\n if (node.sharedStyleType !== null && node.source.id) targetStyleIds.add(node.source.id)\n const styles = new Map<string, string>()\n for (const node of ordered) {\n const id = node.source.id\n if (node.sharedStyleType === null || !id) continue\n styles.set(id, targetStyleIds.has(id) ? allocate() : id)\n }\n const references = {\n nodes,\n variables,\n collections,\n modes,\n properties,\n propertyTypes,\n styles\n }\n const resources = prepareVariableTransfer(\n [...source.variables.values()],\n [...source.variableCollections.values()],\n references\n )\n const mapped = (id: string): string => {\n const value = nodes.get(id)\n if (!value) throw new Error(`Missing transfer node mapping ${id}`)\n return value\n }\n const roots = new Set(input.rootIds)\n const dependencies = new Set(input.dependencyPageIds)\n const destinationParent = (node: SceneNode): string => {\n if (roots.has(node.id)) return parentId\n if (dependencies.has(node.id)) return target.rootId\n return mapped(node.parentId ?? '')\n }\n return {\n nodeIds: nodes,\n rootIds: input.rootIds.map(mapped),\n dependencyPageIds: input.dependencyPageIds.map(mapped),\n nodes: ordered.map((node) => ({\n id: mapped(node.id),\n type: node.type,\n parentId: destinationParent(node),\n props: withStyleId(node, prepareNodeTransfer(node, references), styles)\n })),\n ...resources,\n activeModes: new Map(\n [...source.activeMode].map(([collection, mode]) => [\n requireTransferReference(collections, collection, 'collection'),\n requireTransferReference(modes, mode, 'mode')\n ])\n ),\n images: new Map([...source.images].map(([hash, bytes]) => [hash, bytes.slice()]))\n }\n}\n"],"mappings":";;;;;AAeA,SAAS,YACP,MACA,OACA,QACoB;CACpB,MAAM,KACJ,KAAK,oBAAoB,QAAQ,KAAK,OAAO,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,KAAA;CACjF,IAAI,CAAC,MAAM,OAAO,KAAK,OAAO,IAAI,OAAO;CACzC,OAAO;EAAE,GAAG;EAAO,QAAQ;GAAE,GAAI,MAAM,UAAU,KAAK;GAAS;EAAG;CAAE;AACtE;;AAGA,SAAgB,qBAAqB,OAA2B;CAC9D,MAAM,EAAE,QAAQ,QAAQ,aAAa;CACrC,IAAI,CAAC,OAAO,QAAQ,QAAQ,GAAG,MAAM,IAAI,MAAM,2BAA2B,UAAU;CACpF,MAAM,2BAAW,IAAI,IAAI;EACvB,GAAG,OAAO,MAAM,KAAK;EACrB,GAAG,OAAO,UAAU,KAAK;EACzB,GAAG,OAAO,oBAAoB,KAAK;CACrC,CAAC;CACD,KAAK,MAAM,cAAc,OAAO,oBAAoB,OAAO,GACzD,KAAK,MAAM,QAAQ,WAAW,OAAO,SAAS,IAAI,KAAK,MAAM;CAC/D,IAAI,WAAW;CACf,MAAM,YAAY,OAAO,WAAW;CACpC,MAAM,iBAAyB;EAC7B,IAAI,KAAK,GAAG,UAA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AI,MAAM;EACjC,mBAAmB,MAAM,kBAAkB,IAAI,MAAM;EACrD,OAAO,QAAQ,KAAK,UAAU;GAC5B,IAAI,OAAO,KAAK,EAAE;GAClB,MAAM,KAAK;GACX,UAAU,kBAAkB,IAAI;GAChC,OAAO,YAAY,MAAM,oBAAoB,MAAM,UAAU,GAAG,MAAM;EACxE,EAAE;EACF,GAAG;EACH,aAAa,IAAI,IACf,CAAC,GAAG,OAAO,UAAU,CAAC,CAAC,KAAK,CAAC,YAAY,UAAU,CACjD,yBAAyB,aAAa,YAAY,YAAY,GAC9D,yBAAyB,OAAO,MAAM,MAAM,CAC9C,CAAC,CACH;EACA,QAAQ,IAAI,IAAI,CAAC,GAAG,OAAO,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAAC,MAAM,MAAM,MAAM,CAAC,CAAC,CAAC;CAClF;AACF"}
1
+ {"version":3,"file":"plan.js","names":[],"sources":["../../src/transfer/plan.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { sharedStyleLayers } from '../shared-styles'\nimport type { ComponentPropertyType, SceneNode } from '../types'\nimport { prepareNodeTransfer } from './nodes'\nimport { prepareVariableTransfer } from './variables'\n\nexport interface GraphTransferInput {\n source: SceneGraph\n rootIds: readonly string[]\n dependencyPageIds: readonly string[]\n target: SceneGraph\n parentId: string\n}\n\n/** A transferred style's props under the ID the transfer gives it. */\nfunction withStyleId(\n node: SceneNode,\n props: Partial<SceneNode>,\n styles: ReadonlyMap<string, string>\n): Partial<SceneNode> {\n const id =\n node.sharedStyleType !== null && node.source.id ? styles.get(node.source.id) : undefined\n if (!id || id === node.source.id) return props\n return { ...props, source: { ...(props.source ?? node.source), id } }\n}\n\n/** Preflight a self-contained fragment; allocation does not insert anything into the target. */\nexport function prepareGraphTransfer(input: GraphTransferInput) {\n const { source, target, parentId } = input\n if (!target.getNode(parentId)) throw new Error(`Missing transfer parent ${parentId}`)\n const reserved = new Set([\n ...target.nodes.keys(),\n ...target.variables.keys(),\n ...target.variableCollections.keys()\n ])\n for (const collection of target.variableCollections.values())\n for (const mode of collection.modes) reserved.add(mode.modeId)\n let sequence = 0\n const namespace = crypto.randomUUID()\n const allocate = (): string => {\n let id = `${namespace}:${sequence++}`\n while (reserved.has(id)) id = `${namespace}:${sequence++}`\n reserved.add(id)\n return id\n }\n const ordered: SceneNode[] = []\n const seen = new Set<string>()\n const visit = (id: string): void => {\n if (seen.has(id)) throw new Error(`Repeated transfer node ${id}`)\n const node = source.getNode(id)\n if (!node) throw new Error(`Missing transfer source ${id}`)\n seen.add(id)\n ordered.push(node)\n for (const child of node.childIds) visit(child)\n }\n for (const id of [...input.dependencyPageIds, ...input.rootIds]) visit(id)\n const nodes = new Map(ordered.map((node) => [node.id, allocate()]))\n const variables = new Map([...source.variables.keys()].map((id) => [id, allocate()]))\n const collections = new Map([...source.variableCollections.keys()].map((id) => [id, allocate()]))\n const modes = new Map<string, string>()\n for (const collection of source.variableCollections.values()) {\n for (const mode of collection.modes)\n if (!modes.has(mode.modeId)) modes.set(mode.modeId, allocate())\n }\n const properties = new Map<string, string>()\n const propertyTypes = new Map<string, ComponentPropertyType>()\n for (const node of ordered)\n for (const definition of node.componentPropertyDefinitions) {\n if (propertyTypes.has(definition.id) && propertyTypes.get(definition.id) !== definition.type)\n throw new Error(`Conflicting property type ${definition.id}`)\n propertyTypes.set(definition.id, definition.type)\n if (!properties.has(definition.id)) properties.set(definition.id, allocate())\n }\n // Layers name a style by the style's own ID, which a transferred style keeps unless the\n // target already holds another style by it: IDs read from Figma are only unique in one file.\n const targetStyles = sharedStyleLayers(target)\n const styles = new Map<string, string>()\n for (const node of ordered) {\n const id = node.source.id\n if (node.sharedStyleType === null || !id) continue\n styles.set(id, targetStyles.has(id) ? allocate() : id)\n }\n const references = {\n nodes,\n variables,\n collections,\n modes,\n properties,\n propertyTypes,\n styles\n }\n const resources = prepareVariableTransfer(\n [...source.variables.values()],\n [...source.variableCollections.values()],\n references\n )\n const mapped = (id: string): string => {\n const value = nodes.get(id)\n if (!value) throw new Error(`Missing transfer node mapping ${id}`)\n return value\n }\n const roots = new Set(input.rootIds)\n const dependencies = new Set(input.dependencyPageIds)\n const destinationParent = (node: SceneNode): string => {\n if (roots.has(node.id)) return parentId\n if (dependencies.has(node.id)) return target.rootId\n return mapped(node.parentId ?? '')\n }\n return {\n nodeIds: nodes,\n rootIds: input.rootIds.map(mapped),\n dependencyPageIds: input.dependencyPageIds.map(mapped),\n nodes: ordered.map((node) => ({\n id: mapped(node.id),\n type: node.type,\n parentId: destinationParent(node),\n props: withStyleId(node, prepareNodeTransfer(node, references), styles)\n })),\n ...resources,\n images: new Map([...source.images].map(([hash, bytes]) => [hash, bytes.slice()]))\n }\n}\n"],"mappings":";;;;;AAeA,SAAS,YACP,MACA,OACA,QACoB;CACpB,MAAM,KACJ,KAAK,oBAAoB,QAAQ,KAAK,OAAO,KAAK,OAAO,IAAI,KAAK,OAAO,EAAE,IAAI,KAAA;CACjF,IAAI,CAAC,MAAM,OAAO,KAAK,OAAO,IAAI,OAAO;CACzC,OAAO;EAAE,GAAG;EAAO,QAAQ;GAAE,GAAI,MAAM,UAAU,KAAK;GAAS;EAAG;CAAE;AACtE;;AAGA,SAAgB,qBAAqB,OAA2B;CAC9D,MAAM,EAAE,QAAQ,QAAQ,aAAa;CACrC,IAAI,CAAC,OAAO,QAAQ,QAAQ,GAAG,MAAM,IAAI,MAAM,2BAA2B,UAAU;CACpF,MAAM,2BAAW,IAAI,IAAI;EACvB,GAAG,OAAO,MAAM,KAAK;EACrB,GAAG,OAAO,UAAU,KAAK;EACzB,GAAG,OAAO,oBAAoB,KAAK;CACrC,CAAC;CACD,KAAK,MAAM,cAAc,OAAO,oBAAoB,OAAO,GACzD,KAAK,MAAM,QAAQ,WAAW,OAAO,SAAS,IAAI,KAAK,MAAM;CAC/D,IAAI,WAAW;CACf,MAAM,YAAY,OAAO,WAAW;CACpC,MAAM,iBAAyB;EAC7B,IAAI,KAAK,GAAG,UAAU,GAAG;E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