@pairdraw/scene-graph 0.19.2 → 0.21.0

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 (285) hide show
  1. package/dist/color/index.d.ts +28 -7
  2. package/dist/color/index.d.ts.map +1 -1
  3. package/dist/color/index.js +40 -15
  4. package/dist/color/index.js.map +1 -1
  5. package/dist/color/management.d.ts +19 -6
  6. package/dist/color/management.d.ts.map +1 -1
  7. package/dist/color/management.js +56 -1
  8. package/dist/color/management.js.map +1 -1
  9. package/dist/color/profile.d.ts +32 -0
  10. package/dist/color/profile.d.ts.map +1 -0
  11. package/dist/color/profile.js +140 -0
  12. package/dist/color/profile.js.map +1 -0
  13. package/dist/comments/index.d.ts +2 -2
  14. package/dist/comments/index.js +2 -2
  15. package/dist/comments/merge.d.ts.map +1 -1
  16. package/dist/comments/merge.js +1 -0
  17. package/dist/comments/merge.js.map +1 -1
  18. package/dist/comments/schema.d.ts +3 -1
  19. package/dist/comments/schema.d.ts.map +1 -1
  20. package/dist/comments/schema.js +19 -2
  21. package/dist/comments/schema.js.map +1 -1
  22. package/dist/comments/threads.d.ts +3 -1
  23. package/dist/comments/threads.d.ts.map +1 -1
  24. package/dist/comments/threads.js +2 -1
  25. package/dist/comments/threads.js.map +1 -1
  26. package/dist/components/index.d.ts +2 -2
  27. package/dist/components/index.js +2 -2
  28. package/dist/components/properties.d.ts.map +1 -1
  29. package/dist/components/properties.js +7 -7
  30. package/dist/components/properties.js.map +1 -1
  31. package/dist/components/variants.d.ts +12 -1
  32. package/dist/components/variants.d.ts.map +1 -1
  33. package/dist/components/variants.js +30 -1
  34. package/dist/components/variants.js.map +1 -1
  35. package/dist/constants.d.ts +25 -1
  36. package/dist/constants.d.ts.map +1 -1
  37. package/dist/constants.js +94 -1
  38. package/dist/constants.js.map +1 -1
  39. package/dist/copy.d.ts.map +1 -1
  40. package/dist/copy.js +17 -1
  41. package/dist/copy.js.map +1 -1
  42. package/dist/css/index.d.ts +2 -2
  43. package/dist/css/index.js +2 -2
  44. package/dist/css/shadows.d.ts +2 -2
  45. package/dist/css/shadows.d.ts.map +1 -1
  46. package/dist/css/shadows.js +4 -4
  47. package/dist/css/shadows.js.map +1 -1
  48. package/dist/css/text.d.ts +17 -1
  49. package/dist/css/text.d.ts.map +1 -1
  50. package/dist/css/text.js +62 -1
  51. package/dist/css/text.js.map +1 -1
  52. package/dist/css/values.d.ts +7 -2
  53. package/dist/css/values.d.ts.map +1 -1
  54. package/dist/css/values.js +8 -4
  55. package/dist/css/values.js.map +1 -1
  56. package/dist/design-memory/index.d.ts +3 -0
  57. package/dist/design-memory/index.js +3 -0
  58. package/dist/design-memory/model.d.ts +33 -0
  59. package/dist/design-memory/model.d.ts.map +1 -0
  60. package/dist/design-memory/model.js +142 -0
  61. package/dist/design-memory/model.js.map +1 -0
  62. package/dist/design-memory/schema.d.ts +76 -0
  63. package/dist/design-memory/schema.d.ts.map +1 -0
  64. package/dist/design-memory/schema.js +72 -0
  65. package/dist/design-memory/schema.js.map +1 -0
  66. package/dist/effects.d.ts +7 -4
  67. package/dist/effects.d.ts.map +1 -1
  68. package/dist/effects.js +9 -4
  69. package/dist/effects.js.map +1 -1
  70. package/dist/empty-values.js +102 -0
  71. package/dist/empty-values.js.map +1 -0
  72. package/dist/fields/components.d.ts +9 -0
  73. package/dist/fields/components.d.ts.map +1 -0
  74. package/dist/fields/components.js +24 -0
  75. package/dist/fields/components.js.map +1 -0
  76. package/dist/fields/index.d.ts +3 -2
  77. package/dist/fields/index.js +3 -2
  78. package/dist/fields/layout.d.ts +3 -1
  79. package/dist/fields/layout.d.ts.map +1 -1
  80. package/dist/fields/layout.js +10 -1
  81. package/dist/fields/layout.js.map +1 -1
  82. package/dist/graph.d.ts +12 -1
  83. package/dist/graph.d.ts.map +1 -1
  84. package/dist/graph.js +39 -7
  85. package/dist/graph.js.map +1 -1
  86. package/dist/grid-values.d.ts +10 -0
  87. package/dist/grid-values.d.ts.map +1 -0
  88. package/dist/grid-values.js +53 -0
  89. package/dist/grid-values.js.map +1 -0
  90. package/dist/hit-test/drop.d.ts +20 -0
  91. package/dist/hit-test/drop.d.ts.map +1 -0
  92. package/dist/hit-test/drop.js +54 -0
  93. package/dist/hit-test/drop.js.map +1 -0
  94. package/dist/hit-test/geometry.js +86 -0
  95. package/dist/hit-test/geometry.js.map +1 -0
  96. package/dist/hit-test/masks.d.ts +14 -0
  97. package/dist/hit-test/masks.d.ts.map +1 -0
  98. package/dist/hit-test/masks.js +41 -0
  99. package/dist/hit-test/masks.js.map +1 -0
  100. package/dist/hit-test/paint.d.ts +6 -0
  101. package/dist/hit-test/paint.d.ts.map +1 -0
  102. package/dist/hit-test/paint.js +19 -0
  103. package/dist/hit-test/paint.js.map +1 -0
  104. package/dist/hit-test.d.ts +4 -15
  105. package/dist/hit-test.d.ts.map +1 -1
  106. package/dist/hit-test.js +5 -173
  107. package/dist/hit-test.js.map +1 -1
  108. package/dist/images.d.ts +3 -2
  109. package/dist/images.d.ts.map +1 -1
  110. package/dist/images.js +18 -2
  111. package/dist/images.js.map +1 -1
  112. package/dist/index.d.ts +2 -2
  113. package/dist/instances/copies.js +2 -1
  114. package/dist/instances/copies.js.map +1 -1
  115. package/dist/instances/fields.d.ts.map +1 -1
  116. package/dist/instances/fields.js +2 -0
  117. package/dist/instances/fields.js.map +1 -1
  118. package/dist/instances/index.d.ts +2 -1
  119. package/dist/instances/index.d.ts.map +1 -1
  120. package/dist/instances/index.js +13 -12
  121. package/dist/instances/index.js.map +1 -1
  122. package/dist/instances/overrides.d.ts +15 -1
  123. package/dist/instances/overrides.d.ts.map +1 -1
  124. package/dist/instances/overrides.js +37 -1
  125. package/dist/instances/overrides.js.map +1 -1
  126. package/dist/instances/source-walk.d.ts +12 -0
  127. package/dist/instances/source-walk.d.ts.map +1 -0
  128. package/dist/instances/swap-overrides.js +3 -3
  129. package/dist/instances/swap-overrides.js.map +1 -1
  130. package/dist/instances/sync.js +9 -7
  131. package/dist/instances/sync.js.map +1 -1
  132. package/dist/node-defaults.d.ts.map +1 -1
  133. package/dist/node-defaults.js +43 -38
  134. package/dist/node-defaults.js.map +1 -1
  135. package/dist/plugin-data/fields.d.ts +90 -0
  136. package/dist/plugin-data/fields.d.ts.map +1 -1
  137. package/dist/plugin-data/fields.js +33 -24
  138. package/dist/plugin-data/fields.js.map +1 -1
  139. package/dist/plugin-data/index.d.ts +2 -2
  140. package/dist/plugin-data/index.js +2 -2
  141. package/dist/plugin-data/schema.d.ts +6 -1
  142. package/dist/plugin-data/schema.d.ts.map +1 -1
  143. package/dist/plugin-data/schema.js +24 -1
  144. package/dist/plugin-data/schema.js.map +1 -1
  145. package/dist/preview.d.ts.map +1 -1
  146. package/dist/preview.js +2 -0
  147. package/dist/preview.js.map +1 -1
  148. package/dist/scaling/node.d.ts.map +1 -1
  149. package/dist/scaling/node.js +5 -1
  150. package/dist/scaling/node.js.map +1 -1
  151. package/dist/shaders/animation.d.ts +21 -0
  152. package/dist/shaders/animation.d.ts.map +1 -0
  153. package/dist/shaders/animation.js +25 -0
  154. package/dist/shaders/animation.js.map +1 -0
  155. package/dist/shaders/index.d.ts +2 -1
  156. package/dist/shaders/index.js +2 -1
  157. package/dist/slots/content.d.ts.map +1 -1
  158. package/dist/slots/content.js +4 -4
  159. package/dist/slots/content.js.map +1 -1
  160. package/dist/statuses/index.d.ts +2 -2
  161. package/dist/statuses/index.js +2 -2
  162. package/dist/statuses/workflow.d.ts +3 -1
  163. package/dist/statuses/workflow.d.ts.map +1 -1
  164. package/dist/statuses/workflow.js +6 -2
  165. package/dist/statuses/workflow.js.map +1 -1
  166. package/dist/token-sources/document.d.ts +26 -0
  167. package/dist/token-sources/document.d.ts.map +1 -0
  168. package/dist/token-sources/document.js +80 -0
  169. package/dist/token-sources/document.js.map +1 -0
  170. package/dist/token-sources/index.d.ts +3 -0
  171. package/dist/token-sources/index.js +3 -0
  172. package/dist/token-sources/schema.d.ts +43 -0
  173. package/dist/token-sources/schema.d.ts.map +1 -0
  174. package/dist/token-sources/schema.js +50 -0
  175. package/dist/token-sources/schema.js.map +1 -0
  176. package/dist/transfer/variables.d.ts.map +1 -1
  177. package/dist/transfer/variables.js +1 -1
  178. package/dist/transfer/variables.js.map +1 -1
  179. package/dist/types.d.ts +135 -15
  180. package/dist/types.d.ts.map +1 -1
  181. package/dist/types.js.map +1 -1
  182. package/dist/variables/bindings.d.ts +6 -5
  183. package/dist/variables/bindings.d.ts.map +1 -1
  184. package/dist/variables/bindings.js +24 -16
  185. package/dist/variables/bindings.js.map +1 -1
  186. package/dist/variables/formula/index.d.ts.map +1 -1
  187. package/dist/variables/formula/index.js +12 -6
  188. package/dist/variables/formula/index.js.map +1 -1
  189. package/dist/variables/index.d.ts +14 -1
  190. package/dist/variables/index.d.ts.map +1 -1
  191. package/dist/variables/index.js +38 -10
  192. package/dist/variables/index.js.map +1 -1
  193. package/dist/variables/paints.d.ts +9 -8
  194. package/dist/variables/paints.d.ts.map +1 -1
  195. package/dist/variables/paints.js +35 -26
  196. package/dist/variables/paints.js.map +1 -1
  197. package/dist/variables/resolver.d.ts +45 -0
  198. package/dist/variables/resolver.d.ts.map +1 -0
  199. package/dist/variables/resolver.js +106 -0
  200. package/dist/variables/resolver.js.map +1 -0
  201. package/dist/variations/copy.d.ts +16 -0
  202. package/dist/variations/copy.d.ts.map +1 -0
  203. package/dist/variations/copy.js +78 -0
  204. package/dist/variations/copy.js.map +1 -0
  205. package/dist/variations/index.d.ts +6 -0
  206. package/dist/variations/index.js +6 -0
  207. package/dist/variations/match.d.ts +23 -0
  208. package/dist/variations/match.d.ts.map +1 -0
  209. package/dist/variations/match.js +80 -0
  210. package/dist/variations/match.js.map +1 -0
  211. package/dist/variations/model.d.ts +39 -0
  212. package/dist/variations/model.d.ts.map +1 -0
  213. package/dist/variations/model.js +90 -0
  214. package/dist/variations/model.js.map +1 -0
  215. package/dist/variations/pick.d.ts +43 -0
  216. package/dist/variations/pick.d.ts.map +1 -0
  217. package/dist/variations/pick.js +211 -0
  218. package/dist/variations/pick.js.map +1 -0
  219. package/dist/variations/schema.d.ts +27 -0
  220. package/dist/variations/schema.d.ts.map +1 -0
  221. package/dist/variations/schema.js +27 -0
  222. package/dist/variations/schema.js.map +1 -0
  223. package/package.json +21 -1
  224. package/src/color/index.ts +43 -9
  225. package/src/color/management.ts +54 -1
  226. package/src/color/profile.ts +131 -0
  227. package/src/comments/merge.ts +3 -0
  228. package/src/comments/schema.ts +32 -2
  229. package/src/comments/threads.ts +5 -2
  230. package/src/components/properties.ts +13 -7
  231. package/src/components/variants.ts +39 -0
  232. package/src/constants.ts +75 -0
  233. package/src/copy.ts +20 -1
  234. package/src/css/index.ts +7 -1
  235. package/src/css/shadows.ts +8 -5
  236. package/src/css/text.ts +62 -0
  237. package/src/css/values.ts +12 -5
  238. package/src/design-memory/index.ts +2 -0
  239. package/src/design-memory/model.ts +143 -0
  240. package/src/design-memory/schema.ts +84 -0
  241. package/src/effects.ts +16 -7
  242. package/src/empty-values.ts +117 -0
  243. package/src/fields/components.ts +21 -0
  244. package/src/fields/index.ts +1 -0
  245. package/src/fields/layout.ts +10 -0
  246. package/src/graph.ts +50 -6
  247. package/src/grid-values.ts +47 -0
  248. package/src/hit-test/drop.ts +90 -0
  249. package/src/hit-test/geometry.ts +131 -0
  250. package/src/hit-test/masks.ts +57 -0
  251. package/src/hit-test/paint.ts +24 -0
  252. package/src/hit-test.ts +8 -277
  253. package/src/images.ts +27 -3
  254. package/src/instances/copies.ts +2 -1
  255. package/src/instances/fields.ts +2 -0
  256. package/src/instances/index.ts +20 -11
  257. package/src/instances/overrides.ts +49 -0
  258. package/src/instances/swap-overrides.ts +3 -2
  259. package/src/instances/sync.ts +11 -7
  260. package/src/node-defaults.ts +51 -41
  261. package/src/plugin-data/fields.ts +34 -32
  262. package/src/plugin-data/index.ts +1 -0
  263. package/src/plugin-data/schema.ts +30 -0
  264. package/src/preview.ts +2 -0
  265. package/src/scaling/node.ts +7 -2
  266. package/src/shaders/animation.ts +39 -0
  267. package/src/shaders/index.ts +1 -0
  268. package/src/slots/content.ts +8 -4
  269. package/src/statuses/workflow.ts +6 -4
  270. package/src/token-sources/document.ts +104 -0
  271. package/src/token-sources/index.ts +2 -0
  272. package/src/token-sources/schema.ts +59 -0
  273. package/src/transfer/variables.ts +2 -1
  274. package/src/types.ts +145 -14
  275. package/src/variables/bindings.ts +35 -18
  276. package/src/variables/formula/index.ts +19 -18
  277. package/src/variables/index.ts +49 -10
  278. package/src/variables/paints.ts +64 -29
  279. package/src/variables/resolver.ts +178 -0
  280. package/src/variations/copy.ts +89 -0
  281. package/src/variations/index.ts +5 -0
  282. package/src/variations/match.ts +100 -0
  283. package/src/variations/model.ts +132 -0
  284. package/src/variations/pick.ts +293 -0
  285. package/src/variations/schema.ts +29 -0
@@ -1 +1 @@
1
- {"version":3,"file":"merge.js","names":[],"sources":["../../src/comments/merge.ts"],"sourcesContent":["import type { CommentReply, CommentThread } from '../types'\nimport { byCreatedAt } from './threads'\n\nfunction mergeReplies(first: CommentReply[], second: CommentReply[]): CommentReply[] {\n const byId = new Map<string, CommentReply>()\n for (const reply of [...first, ...second]) {\n const existing = byId.get(reply.id)\n // A deletion is never undone by an older copy of the same reply.\n byId.set(\n reply.id,\n existing ? { ...existing, ...reply, deleted: existing.deleted || reply.deleted } : reply\n )\n }\n return [...byId.values()].sort(byCreatedAt)\n}\n\n/**\n * Two copies of a document's comments become one. Nothing is lost: threads and replies are\n * joined by id, and for a thread both copies changed, the newer edit wins while replies from\n * both are kept. Deleted threads and replies stay deleted.\n */\nexport function mergeCommentThreads(\n local: readonly CommentThread[],\n remote: readonly CommentThread[]\n): CommentThread[] {\n const byId = new Map<string, CommentThread>()\n for (const thread of remote) byId.set(thread.id, thread)\n for (const thread of local) {\n const other = byId.get(thread.id)\n if (!other) {\n byId.set(thread.id, thread)\n continue\n }\n const newer = thread.updatedAt >= other.updatedAt ? thread : other\n byId.set(thread.id, {\n ...newer,\n deleted: thread.deleted || other.deleted,\n replies: mergeReplies(other.replies, thread.replies)\n })\n }\n return [...byId.values()].sort(byCreatedAt)\n}\n\n/**\n * Whether `local` holds anything `remote` lacks: a thread or reply it does not have, a newer edit,\n * or a deletion. Merging is then needed; otherwise `remote` already says everything.\n */\nexport function hasNewerComments(\n local: readonly CommentThread[],\n remote: readonly CommentThread[]\n): boolean {\n const remoteById = new Map(remote.map((thread) => [thread.id, thread]))\n return local.some((thread) => {\n const other = remoteById.get(thread.id)\n if (!other) return true\n if (thread.updatedAt > other.updatedAt || (thread.deleted && !other.deleted)) return true\n const replies = new Map(other.replies.map((entry) => [entry.id, entry]))\n return thread.replies.some((entry) => {\n const known = replies.get(entry.id)\n return !known || (!!entry.deleted && !known.deleted)\n })\n })\n}\n"],"mappings":";;AAGA,SAAS,aAAa,OAAuB,QAAwC;CACnF,MAAM,uBAAO,IAAI,IAA0B;CAC3C,KAAK,MAAM,SAAS,CAAC,GAAG,OAAO,GAAG,MAAM,GAAG;EACzC,MAAM,WAAW,KAAK,IAAI,MAAM,EAAE;EAElC,KAAK,IACH,MAAM,IACN,WAAW;GAAE,GAAG;GAAU,GAAG;GAAO,SAAS,SAAS,WAAW,MAAM;EAAQ,IAAI,KACrF;CACF;CACA,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW;AAC5C;;;;;;AAOA,SAAgB,oBACd,OACA,QACiB;CACjB,MAAM,uBAAO,IAAI,IAA2B;CAC5C,KAAK,MAAM,UAAU,QAAQ,KAAK,IAAI,OAAO,IAAI,MAAM;CACvD,KAAK,MAAM,UAAU,OAAO;EAC1B,MAAM,QAAQ,KAAK,IAAI,OAAO,EAAE;EAChC,IAAI,CAAC,OAAO;GACV,KAAK,IAAI,OAAO,IAAI,MAAM;GAC1B;EACF;EACA,MAAM,QAAQ,OAAO,aAAa,MAAM,YAAY,SAAS;EAC7D,KAAK,IAAI,OAAO,IAAI;GAClB,GAAG;GACH,SAAS,OAAO,WAAW,MAAM;GACjC,SAAS,aAAa,MAAM,SAAS,OAAO,OAAO;EACrD,CAAC;CACH;CACA,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW;AAC5C;;;;;AAMA,SAAgB,iBACd,OACA,QACS;CACT,MAAM,aAAa,IAAI,IAAI,OAAO,KAAK,WAAW,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC;CACtE,OAAO,MAAM,MAAM,WAAW;EAC5B,MAAM,QAAQ,WAAW,IAAI,OAAO,EAAE;EACtC,IAAI,CAAC,OAAO,OAAO;EACnB,IAAI,OAAO,YAAY,MAAM,aAAc,OAAO,WAAW,CAAC,MAAM,SAAU,OAAO;EACrF,MAAM,UAAU,IAAI,IAAI,MAAM,QAAQ,KAAK,UAAU,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;EACvE,OAAO,OAAO,QAAQ,MAAM,UAAU;GACpC,MAAM,QAAQ,QAAQ,IAAI,MAAM,EAAE;GAClC,OAAO,CAAC,SAAU,CAAC,CAAC,MAAM,WAAW,CAAC,MAAM;EAC9C,CAAC;CACH,CAAC;AACH"}
1
+ {"version":3,"file":"merge.js","names":[],"sources":["../../src/comments/merge.ts"],"sourcesContent":["import type { CommentReply, CommentThread } from '../types'\nimport { byCreatedAt } from './threads'\n\nfunction mergeReplies(first: CommentReply[], second: CommentReply[]): CommentReply[] {\n const byId = new Map<string, CommentReply>()\n for (const reply of [...first, ...second]) {\n const existing = byId.get(reply.id)\n // A deletion is never undone by an older copy of the same reply.\n byId.set(\n reply.id,\n existing ? { ...existing, ...reply, deleted: existing.deleted || reply.deleted } : reply\n )\n }\n return [...byId.values()].sort(byCreatedAt)\n}\n\n/**\n * Two copies of a document's comments become one. Nothing is lost: threads and replies are\n * joined by id, and for a thread both copies changed, the newer edit wins while replies from\n * both are kept. Deleted threads and replies stay deleted.\n */\nexport function mergeCommentThreads(\n local: readonly CommentThread[],\n remote: readonly CommentThread[]\n): CommentThread[] {\n const byId = new Map<string, CommentThread>()\n for (const thread of remote) byId.set(thread.id, thread)\n for (const thread of local) {\n const other = byId.get(thread.id)\n if (!other) {\n byId.set(thread.id, thread)\n continue\n }\n const newer = thread.updatedAt >= other.updatedAt ? thread : other\n byId.set(thread.id, {\n ...newer,\n // A region is only ever set together with its thread, so a copy that lacks one — written by\n // an older build or read before the person drew — does not erase it.\n region: newer.region ?? thread.region ?? other.region,\n deleted: thread.deleted || other.deleted,\n replies: mergeReplies(other.replies, thread.replies)\n })\n }\n return [...byId.values()].sort(byCreatedAt)\n}\n\n/**\n * Whether `local` holds anything `remote` lacks: a thread or reply it does not have, a newer edit,\n * or a deletion. Merging is then needed; otherwise `remote` already says everything.\n */\nexport function hasNewerComments(\n local: readonly CommentThread[],\n remote: readonly CommentThread[]\n): boolean {\n const remoteById = new Map(remote.map((thread) => [thread.id, thread]))\n return local.some((thread) => {\n const other = remoteById.get(thread.id)\n if (!other) return true\n if (thread.updatedAt > other.updatedAt || (thread.deleted && !other.deleted)) return true\n const replies = new Map(other.replies.map((entry) => [entry.id, entry]))\n return thread.replies.some((entry) => {\n const known = replies.get(entry.id)\n return !known || (!!entry.deleted && !known.deleted)\n })\n })\n}\n"],"mappings":";;AAGA,SAAS,aAAa,OAAuB,QAAwC;CACnF,MAAM,uBAAO,IAAI,IAA0B;CAC3C,KAAK,MAAM,SAAS,CAAC,GAAG,OAAO,GAAG,MAAM,GAAG;EACzC,MAAM,WAAW,KAAK,IAAI,MAAM,EAAE;EAElC,KAAK,IACH,MAAM,IACN,WAAW;GAAE,GAAG;GAAU,GAAG;GAAO,SAAS,SAAS,WAAW,MAAM;EAAQ,IAAI,KACrF;CACF;CACA,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW;AAC5C;;;;;;AAOA,SAAgB,oBACd,OACA,QACiB;CACjB,MAAM,uBAAO,IAAI,IAA2B;CAC5C,KAAK,MAAM,UAAU,QAAQ,KAAK,IAAI,OAAO,IAAI,MAAM;CACvD,KAAK,MAAM,UAAU,OAAO;EAC1B,MAAM,QAAQ,KAAK,IAAI,OAAO,EAAE;EAChC,IAAI,CAAC,OAAO;GACV,KAAK,IAAI,OAAO,IAAI,MAAM;GAC1B;EACF;EACA,MAAM,QAAQ,OAAO,aAAa,MAAM,YAAY,SAAS;EAC7D,KAAK,IAAI,OAAO,IAAI;GAClB,GAAG;GAGH,QAAQ,MAAM,UAAU,OAAO,UAAU,MAAM;GAC/C,SAAS,OAAO,WAAW,MAAM;GACjC,SAAS,aAAa,MAAM,SAAS,OAAO,OAAO;EACrD,CAAC;CACH;CACA,OAAO,CAAC,GAAG,KAAK,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW;AAC5C;;;;;AAMA,SAAgB,iBACd,OACA,QACS;CACT,MAAM,aAAa,IAAI,IAAI,OAAO,KAAK,WAAW,CAAC,OAAO,IAAI,MAAM,CAAC,CAAC;CACtE,OAAO,MAAM,MAAM,WAAW;EAC5B,MAAM,QAAQ,WAAW,IAAI,OAAO,EAAE;EACtC,IAAI,CAAC,OAAO,OAAO;EACnB,IAAI,OAAO,YAAY,MAAM,aAAc,OAAO,WAAW,CAAC,MAAM,SAAU,OAAO;EACrF,MAAM,UAAU,IAAI,IAAI,MAAM,QAAQ,KAAK,UAAU,CAAC,MAAM,IAAI,KAAK,CAAC,CAAC;EACvE,OAAO,OAAO,QAAQ,MAAM,UAAU;GACpC,MAAM,QAAQ,QAAQ,IAAI,MAAM,EAAE;GAClC,OAAO,CAAC,SAAU,CAAC,CAAC,MAAM,WAAW,CAAC,MAAM;EAC9C,CAAC;CACH,CAAC;AACH"}
@@ -1,8 +1,10 @@
1
1
  import { CommentThread } from "../types.js";
2
2
  import * as v from "valibot";
3
3
  //#region src/comments/schema.d.ts
4
+ /** Points one thread's region may carry; a file asking for more is not a stroke a person drew. */
5
+ declare const MAX_COMMENT_REGION_POINTS = 512;
4
6
  /** A list of comment threads as files and rooms hold them; threads that cannot be read are left out. */
5
7
  declare const commentThreadsSchema: v.GenericSchema<unknown, CommentThread[]>;
6
8
  //#endregion
7
- export { commentThreadsSchema };
9
+ export { MAX_COMMENT_REGION_POINTS, commentThreadsSchema };
8
10
  //# sourceMappingURL=schema.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/comments/schema.ts"],"mappings":";;;;cAwCa,sBAAsB,EAAE,uBAAuB"}
1
+ {"version":3,"file":"schema.d.ts","names":[],"sources":["../../src/comments/schema.ts"],"mappings":";;;;cAuBa;;cAuCA,sBAAsB,EAAE,uBAAuB"}
@@ -18,6 +18,21 @@ const commentReplySchema = v.object({
18
18
  id: v.string(),
19
19
  ...commentEntry
20
20
  });
21
+ /** Points one thread's region may carry; a file asking for more is not a stroke a person drew. */
22
+ const MAX_COMMENT_REGION_POINTS = 512;
23
+ const finiteSchema = v.pipe(v.number(), v.finite());
24
+ const commentPointSchema = v.tuple([finiteSchema, finiteSchema]);
25
+ /** The stroke a person circled with: its points and width, and the box they span. */
26
+ const commentRegionSchema = v.object({
27
+ points: v.pipe(v.array(commentPointSchema), v.minLength(2), v.maxLength(512)),
28
+ width: v.pipe(finiteSchema, v.minValue(0)),
29
+ bounds: v.object({
30
+ minX: finiteSchema,
31
+ minY: finiteSchema,
32
+ maxX: finiteSchema,
33
+ maxY: finiteSchema
34
+ })
35
+ });
21
36
  const commentThreadSchema = v.object({
22
37
  id: v.string(),
23
38
  pageId: v.string(),
@@ -39,12 +54,14 @@ const commentThreadsSchema = v.pipe(v.array(v.unknown()), v.transform((items) =>
39
54
  const parsed = v.safeParse(commentThreadSchema, item);
40
55
  if (!parsed.success) return [];
41
56
  const thread = parsed.output;
57
+ const region = v.safeParse(commentRegionSchema, item.region);
42
58
  return [{
43
59
  ...thread,
44
- updatedAt: thread.updatedAt || thread.createdAt
60
+ updatedAt: thread.updatedAt || thread.createdAt,
61
+ ...region.success ? { region: region.output } : {}
45
62
  }];
46
63
  })));
47
64
  //#endregion
48
- export { commentThreadsSchema };
65
+ export { MAX_COMMENT_REGION_POINTS, commentThreadsSchema };
49
66
 
50
67
  //# sourceMappingURL=schema.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"schema.js","names":[],"sources":["../../src/comments/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { CommentThread } from '../types'\n\n// Lenient on purpose: other tools may write comments, so missing fields get defaults and one\n// malformed thread is skipped instead of hiding every comment.\nconst commentAuthorColorSchema = v.fallback(\n v.optional(v.object({ r: v.number(), g: v.number(), b: v.number(), a: v.number() })),\n undefined\n)\n\n/** What a comment and each reply say, who wrote them and when, and whether they were deleted. */\nconst commentEntry = {\n author: v.fallback(v.string(), ''),\n authorColor: commentAuthorColorSchema,\n text: v.fallback(v.string(), ''),\n createdAt: v.fallback(v.string(), ''),\n deleted: v.optional(v.boolean())\n}\n\nconst commentReplySchema = v.object({ id: v.string(), ...commentEntry })\n\nconst commentThreadSchema = v.object({\n id: v.string(),\n pageId: v.string(),\n pageName: v.optional(v.string()),\n nodeId: v.optional(v.nullable(v.string())),\n nodeName: v.optional(v.nullable(v.string())),\n offsetX: v.optional(v.number()),\n offsetY: v.optional(v.number()),\n x: v.fallback(v.number(), 0),\n y: v.fallback(v.number(), 0),\n ...commentEntry,\n updatedAt: v.fallback(v.string(), ''),\n resolved: v.fallback(v.boolean(), false),\n resolvedAt: v.optional(v.nullable(v.string())),\n replies: v.fallback(v.array(commentReplySchema), [])\n})\n\n/** A list of comment threads as files and rooms hold them; threads that cannot be read are left out. */\nexport const commentThreadsSchema: v.GenericSchema<unknown, CommentThread[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(commentThreadSchema, item)\n if (!parsed.success) return []\n const thread = parsed.output\n return [{ ...thread, updatedAt: thread.updatedAt || thread.createdAt }]\n })\n )\n)\n"],"mappings":";;AAMA,MAAM,2BAA2B,EAAE,SACjC,EAAE,SAAS,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;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AAC,OAAO,SAAS,OAAO,CAAC;CAC7B,MAAM,SAAS,OAAO;CACtB,OAAO,CAAC;EAAE,GAAG;EAAQ,WAAW,OAAO,aAAa,OAAO;CAAU,CAAC;AACxE,CAAC,CACH,CACF"}
1
+ {"version":3,"file":"schema.js","names":[],"sources":["../../src/comments/schema.ts"],"sourcesContent":["import * as v from 'valibot'\n\nimport type { CommentRegion, CommentThread } from '../types'\n\n// Lenient on purpose: other tools may write comments, so missing fields get defaults and one\n// malformed thread is skipped instead of hiding every comment.\nconst commentAuthorColorSchema = v.fallback(\n v.optional(v.object({ r: v.number(), g: v.number(), b: v.number(), a: v.number() })),\n undefined\n)\n\n/** What a comment and each reply say, who wrote them and when, and whether they were deleted. */\nconst commentEntry = {\n author: v.fallback(v.string(), ''),\n authorColor: commentAuthorColorSchema,\n text: v.fallback(v.string(), ''),\n createdAt: v.fallback(v.string(), ''),\n deleted: v.optional(v.boolean())\n}\n\nconst commentReplySchema = v.object({ id: v.string(), ...commentEntry })\n\n/** Points one thread's region may carry; a file asking for more is not a stroke a person drew. */\nexport const MAX_COMMENT_REGION_POINTS = 512\n\nconst finiteSchema = v.pipe(v.number(), v.finite())\nconst commentPointSchema = v.tuple([finiteSchema, finiteSchema])\n\n/** The stroke a person circled with: its points and width, and the box they span. */\nconst commentRegionSchema: v.GenericSchema<unknown, CommentRegion> = v.object({\n points: v.pipe(\n v.array(commentPointSchema),\n v.minLength(2),\n v.maxLength(MAX_COMMENT_REGION_POINTS)\n ),\n width: v.pipe(finiteSchema, v.minValue(0)),\n bounds: v.object({\n minX: finiteSchema,\n minY: finiteSchema,\n maxX: finiteSchema,\n maxY: finiteSchema\n })\n})\n\nconst commentThreadSchema = v.object({\n id: v.string(),\n pageId: v.string(),\n pageName: v.optional(v.string()),\n nodeId: v.optional(v.nullable(v.string())),\n nodeName: v.optional(v.nullable(v.string())),\n offsetX: v.optional(v.number()),\n offsetY: v.optional(v.number()),\n x: v.fallback(v.number(), 0),\n y: v.fallback(v.number(), 0),\n ...commentEntry,\n updatedAt: v.fallback(v.string(), ''),\n resolved: v.fallback(v.boolean(), false),\n resolvedAt: v.optional(v.nullable(v.string())),\n replies: v.fallback(v.array(commentReplySchema), [])\n})\n\n/** A list of comment threads as files and rooms hold them; threads that cannot be read are left out. */\nexport const commentThreadsSchema: v.GenericSchema<unknown, CommentThread[]> = v.pipe(\n v.array(v.unknown()),\n v.transform((items) =>\n items.flatMap((item) => {\n const parsed = v.safeParse(commentThreadSchema, item)\n if (!parsed.success) return []\n const thread = parsed.output\n // A stroke that cannot be read is dropped; the note it was drawn around is still worth keeping.\n const region = v.safeParse(commentRegionSchema, (item as { region?: unknown }).region)\n return [\n {\n ...thread,\n updatedAt: thread.updatedAt || thread.createdAt,\n ...(region.success ? { region: region.output } : {})\n }\n ]\n })\n )\n)\n"],"mappings":";;AAMA,MAAM,2BAA2B,EAAE,SACjC,EAAE,SAAS,EAAE,OAAO;CAAE,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;CAAG,GAAG,EAAE,OAAO;AAAE,CAAC,CAAC,GACnF,KAAA,CACF;;AAGA,MAAM,eAAe;CACnB,QAAQ,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACjC,aAAa;CACb,MAAM,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CAC/B,WAAW,EAAE,SAAS,EAAE,OAAO,GAAG,EAAE;CACpC,SAAS,EAAE,SAAS,EAAE,QAAQ,CAAC;AACjC;AAEA,MAAM,qBAAqB,EAAE,OAAO;CAAE,IAAI,EAAE,OAAO;CAAG,GAAG;AAAa,CAAC;;AAGvE,MAAa,4BAA4B;AAEzC,MAAM,eAAe,EAAE,KAAK,EAAE,OAAO,GAAG,EAAE,OAAO,CAAC;AAClD,MAAM,qBAAqB,EAAE,MAAM,CAAC,cAAc,YAAY,CAAC;;AAG/D,MAAM,sBAA+D,EAAE,OAAO;CAC5E,QAAQ,EAAE,KACR,EAAE,MAA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AAU,EAAE,QAAQ,OAAO,OAAO,IAAI,CAAC;CACpD,CACF;AACF,CAAC,CACH,CACF"}
@@ -1,6 +1,6 @@
1
1
  import { Color, Vector } from "../primitives/index.js";
2
2
  import { SceneGraph } from "../graph.js";
3
- import { CommentReply, CommentThread, SceneNode } from "../types.js";
3
+ import { CommentRegion, CommentReply, CommentThread, SceneNode } from "../types.js";
4
4
  //#region src/comments/threads.d.ts
5
5
  /** Who writes a comment: their name and, in a collaboration room, their color. */
6
6
  interface CommentAuthor {
@@ -41,6 +41,8 @@ declare function createCommentThread(graph: SceneGraph, options: {
41
41
  at: Vector;
42
42
  /** Pin it on this layer's top-level layer rather than on whatever is at `at`. */
43
43
  node?: SceneNode;
44
+ /** The area the person circled, when the comment was drawn rather than clicked. */
45
+ region?: CommentRegion | null;
44
46
  author: CommentAuthor;
45
47
  text: string;
46
48
  now: string;
@@ -1 +1 @@
1
- {"version":3,"file":"threads.d.ts","names":[],"sources":["../../src/comments/threads.ts"],"mappings":";;;;;UAMiB;EACf;EACA,QAAQ;;;iBAQM;;iBAKA,YAAY;EAAK;GAAqB;EAAK;;;iBAK3C,YAAY,QAAQ,gBAAgB;;iBAKpC,kBAAkB,QAAQ,eAAe;;iBAKzC,sBACd,kBAAkB,iBAClB,aACC;;;;;iBAoBa,cAAc,OAAO,YAAY,gBAAgB,IAAI,QAAQ,OAAO;;;;;;;;;iBAepE,gBAAgB,OAAO,YAAY,QAAQ,gBAAgB;;iBAQ3D,oBACd,OAAO,YACP;EACE;EACA,IAAI;;EAEJ,OAAO;EACP,QAAQ;EACR;EACA;IAED;iBAiBa,mBAAmB,QAAQ,eAAe,cAAc,cAAc;;iBAWtE,kBACd,kBAAkB,iBAClB,YACA,aACA,OAAO,QAAQ,kBAAkB,gBAChC;;iBAKa,qBAAqB,QAAQ,eAAe,OAAO,eAAe;iBAIlE,qBACd,QAAQ,eACR,mBACA,cACC;;iBAKa,oBAAoB,QAAQ,gBAAgB;iBAI5C,mBAAmB,QAAQ,eAAe,kBAAkB"}
1
+ {"version":3,"file":"threads.d.ts","names":[],"sources":["../../src/comments/threads.ts"],"mappings":";;;;;UAMiB;EACf;EACA,QAAQ;;;iBAQM;;iBAKA,YAAY;EAAK;GAAqB;EAAK;;;iBAK3C,YAAY,QAAQ,gBAAgB;;iBAKpC,kBAAkB,QAAQ,eAAe;;iBAKzC,sBACd,kBAAkB,iBAClB,aACC;;;;;iBAoBa,cAAc,OAAO,YAAY,gBAAgB,IAAI,QAAQ,OAAO;;;;;;;;;iBAepE,gBAAgB,OAAO,YAAY,QAAQ,gBAAgB;;iBAQ3D,oBACd,OAAO,YACP;EACE;EACA,IAAI;;EAEJ,OAAO;;EAEP,SAAS;EACT,QAAQ;EACR;EACA;IAED;iBAkBa,mBAAmB,QAAQ,eAAe,cAAc,cAAc;;iBAWtE,kBACd,kBAAkB,iBAClB,YACA,aACA,OAAO,QAAQ,kBAAkB,gBAChC;;iBAKa,qBAAqB,QAAQ,eAAe,OAAO,eAAe;iBAIlE,qBACd,QAAQ,eACR,mBACA,cACC;;iBAKa,oBAAoB,QAAQ,gBAAgB;iBAI5C,mBAAmB,QAAQ,eAAe,kBAAkB"}
@@ -63,7 +63,7 @@ function commentPosition(graph, thread) {
63
63
  }
64
64
  /** A new thread pinned at a canvas point of a page. */
65
65
  function createCommentThread(graph, options) {
66
- const { pageId, at, node, author, text, now } = options;
66
+ const { pageId, at, node, region, author, text, now } = options;
67
67
  return {
68
68
  id: newCommentId("c"),
69
69
  pageId,
@@ -75,6 +75,7 @@ function createCommentThread(graph, options) {
75
75
  createdAt: now,
76
76
  updatedAt: now,
77
77
  resolved: false,
78
+ ...region ? { region } : {},
78
79
  replies: []
79
80
  };
80
81
  }
@@ -1 +1 @@
1
- {"version":3,"file":"threads.js","names":[],"sources":["../../src/comments/threads.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { Color, Vector } from '../primitives'\nimport { randomHex } from '../random'\nimport type { CommentReply, CommentThread, SceneNode } from '../types'\n\n/** Who writes a comment: their name and, in a collaboration room, their color. */\nexport interface CommentAuthor {\n name: string\n color?: Color\n}\n\nfunction newCommentId(prefix: 'c' | 'r'): string {\n return `${prefix}_${randomHex(8)}`\n}\n\n/** When a comment is written or changed, as stored: an ISO timestamp. */\nexport function commentTimestamp(): string {\n return new Date().toISOString()\n}\n\n/** Oldest first, the order threads and replies are shown and numbered in. */\nexport function byCreatedAt(a: { createdAt: string }, b: { createdAt: string }): number {\n return a.createdAt.localeCompare(b.createdAt)\n}\n\n/** A thread's replies, without the deleted ones kept as tombstones. */\nexport function liveReplies(thread: CommentThread): CommentReply[] {\n return thread.replies.filter((entry) => !entry.deleted)\n}\n\n/** Whether `author` started the thread or replied to it, as Figma's \"Only your threads\" counts. */\nexport function takesPartInThread(thread: CommentThread, author: string): boolean {\n return thread.author === author || liveReplies(thread).some((entry) => entry.author === author)\n}\n\n/** The thread with `id`, unless it is missing or deleted. */\nexport function findLiveCommentThread(\n threads: readonly CommentThread[],\n id: string\n): CommentThread | undefined {\n return threads.find((thread) => thread.id === id && !thread.deleted)\n}\n\n/**\n * The layer a comment on `node` is kept on: its top-level layer, as Figma attaches comments, or\n * within a section the section's own child, as frames move about inside it.\n */\nfunction commentLayer(graph: SceneGraph, node: SceneNode, pageId: string): SceneNode {\n const isSection = (id: string | null) => !!id && graph.getNode(id)?.type === 'SECTION'\n return (\n graph.closest(node.id, (layer) => layer.parentId === pageId || isSection(layer.parentId)) ??\n node\n )\n}\n\n/**\n * Where a pin at a canvas point is kept: on the top-level layer under it, or on `node`'s when\n * given, so it follows that layer; on the canvas when nothing is there.\n */\nexport function commentAnchor(graph: SceneGraph, pageId: string, at: Vector, node?: SceneNode) {\n const target = node ?? graph.hitTest(at.x, at.y, pageId)\n const layer = target ? commentLayer(graph, target, pageId) : null\n const abs = layer ? graph.getAbsolutePosition(layer.id) : null\n return {\n nodeId: layer?.id ?? null,\n nodeName: layer?.name ?? null,\n offsetX: abs ? at.x - abs.x : 0,\n offsetY: abs ? at.y - abs.y : 0,\n x: at.x,\n y: at.y\n }\n}\n\n/** Where a thread's pin is now: on its layer while that layer exists, else where it was left. */\nexport function commentPosition(graph: SceneGraph, thread: CommentThread): Vector {\n const node = thread.nodeId ? graph.getNode(thread.nodeId) : undefined\n if (!node) return { x: thread.x, y: thread.y }\n const abs = graph.getAbsolutePosition(node.id)\n return { x: abs.x + (thread.offsetX ?? 0), y: abs.y + (thread.offsetY ?? 0) }\n}\n\n/** A new thread pinned at a canvas point of a page. */\nexport function createCommentThread(\n graph: SceneGraph,\n options: {\n pageId: string\n at: Vector\n /** Pin it on this layer's top-level layer rather than on whatever is at `at`. */\n node?: SceneNode\n author: CommentAuthor\n text: string\n now: string\n }\n): CommentThread {\n const { pageId, at, node, author, text, now } = options\n return {\n id: newCommentId('c'),\n pageId,\n pageName: graph.getNode(pageId)?.name,\n ...commentAnchor(graph, pageId, at, node),\n author: author.name,\n authorColor: author.color,\n text,\n createdAt: now,\n updatedAt: now,\n resolved: false,\n replies: []\n }\n}\n\nexport function createCommentReply(author: CommentAuthor, text: string, now: string): CommentReply {\n return {\n id: newCommentId('r'),\n author: author.name,\n authorColor: author.color,\n text,\n createdAt: now\n }\n}\n\n/** The threads with one changed and marked as edited at `now`, for merging with other copies. */\nexport function editCommentThread(\n threads: readonly CommentThread[],\n id: string,\n now: string,\n edit: (thread: CommentThread) => CommentThread\n): CommentThread[] {\n return threads.map((thread) => (thread.id === id ? { ...edit(thread), updatedAt: now } : thread))\n}\n\n/** A reply ends up in the thread and reopens it, as answering a resolved comment does. */\nexport function replyToCommentThread(thread: CommentThread, reply: CommentReply): CommentThread {\n return { ...thread, resolved: false, resolvedAt: null, replies: [...thread.replies, reply] }\n}\n\nexport function resolveCommentThread(\n thread: CommentThread,\n resolved: boolean,\n now: string\n): CommentThread {\n return { ...thread, resolved, resolvedAt: resolved ? now : null }\n}\n\n/** Deleted threads and replies stay as tombstones, so a stale copy cannot bring them back. */\nexport function deleteCommentThread(thread: CommentThread): CommentThread {\n return { ...thread, deleted: true }\n}\n\nexport function deleteCommentReply(thread: CommentThread, replyId: string): CommentThread {\n return {\n ...thread,\n replies: thread.replies.map((entry) =>\n entry.id === replyId ? { ...entry, deleted: true } : entry\n )\n }\n}\n"],"mappings":";;AAWA,SAAS,aAAa,QAA2B;CAC/C,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;AACjC;;AAGA,SAAgB,mBAA2B;CACzC,wBAAO,IAAI,KAAK,EAAA,CAAE,YAAY;AAChC;;AAGA,SAAgB,YAAY,GAA0B,GAAkC;CACtF,OAAO,EAAE,UAAU,cAAc,EAAE,SAAS;AAC9C;;AAGA,SAAgB,YAAY,QAAuC;CACjE,OAAO,OAAO,QAAQ,QAAQ,UAAU,CAAC,MAAM,OAAO;AACxD;;AAGA,SAAgB,kBAAkB,QAAuB,QAAyB;CAChF,OAAO,OAAO,WAAW,UAAU,YAAY,MAAM,CAAC,CAAC,MAAM,UAAU,MAAM,WAAW,MAAM;AAChG;;AAGA,SAAgB,sBACd,SACA,IAC2B;CAC3B,OAAO,QAAQ,MAAM,WAAW,OAAO,OAAO,MAAM,CAAC,OAAO,OAAO;AACrE;;;;;AAMA,SAAS,aAAa,OAAmB,MAAiB,QAA2B;CACnF,MAAM,aAAa,OAAsB,CAAC,CAAC,MAAM,MAAM,QAAQ,EAAE,CAAC,EAAE,SAAS;CAC7E,OACE,MAAM,QAAQ,KAAK,KAAK,UAAU,MAAM,aAAa,UAAU,UAAU,MAAM,QAAQ,CAAC,KACxF;AAEJ;;;;;AAMA,SAAgB,cAAc,OAAmB,QAAgB,IAAY,MAAkB;CAC7F,MAAM,SAAS,QAAQ,MAAM,QAAQ,GAAG,GAAG,GAAG,GAAG,MAAM;CACvD,MAAM,QAAQ,SAAS,aAAa,OAAO,QAAQ,MAAM,IAAI;CAC7D,MAAM,MAAM,QAAQ,MAAM,oBAAoB,MAAM,EAAE,IAAI;CAC1D,OAAO;EACL,QAAQ,OAAO,MAAM;EACrB,UAA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BACd,QACA,UACA,KACe;CACf,OAAO;EAAE,GAAG;EAAQ;EAAU,YAAY,WAAW,MAAM;CAAK;AAClE;;AAGA,SAAgB,oBAAoB,QAAsC;CACxE,OAAO;EAAE,GAAG;EAAQ,SAAS;CAAK;AACpC;AAEA,SAAgB,mBAAmB,QAAuB,SAAgC;CACxF,OAAO;EACL,GAAG;EACH,SAAS,OAAO,QAAQ,KAAK,UAC3B,MAAM,OAAO,UAAU;GAAE,GAAG;GAAO,SAAS;EAAK,IAAI,KACvD;CACF;AACF"}
1
+ {"version":3,"file":"threads.js","names":[],"sources":["../../src/comments/threads.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { Color, Vector } from '../primitives'\nimport { randomHex } from '../random'\nimport type { CommentRegion, CommentReply, CommentThread, SceneNode } from '../types'\n\n/** Who writes a comment: their name and, in a collaboration room, their color. */\nexport interface CommentAuthor {\n name: string\n color?: Color\n}\n\nfunction newCommentId(prefix: 'c' | 'r'): string {\n return `${prefix}_${randomHex(8)}`\n}\n\n/** When a comment is written or changed, as stored: an ISO timestamp. */\nexport function commentTimestamp(): string {\n return new Date().toISOString()\n}\n\n/** Oldest first, the order threads and replies are shown and numbered in. */\nexport function byCreatedAt(a: { createdAt: string }, b: { createdAt: string }): number {\n return a.createdAt.localeCompare(b.createdAt)\n}\n\n/** A thread's replies, without the deleted ones kept as tombstones. */\nexport function liveReplies(thread: CommentThread): CommentReply[] {\n return thread.replies.filter((entry) => !entry.deleted)\n}\n\n/** Whether `author` started the thread or replied to it, as Figma's \"Only your threads\" counts. */\nexport function takesPartInThread(thread: CommentThread, author: string): boolean {\n return thread.author === author || liveReplies(thread).some((entry) => entry.author === author)\n}\n\n/** The thread with `id`, unless it is missing or deleted. */\nexport function findLiveCommentThread(\n threads: readonly CommentThread[],\n id: string\n): CommentThread | undefined {\n return threads.find((thread) => thread.id === id && !thread.deleted)\n}\n\n/**\n * The layer a comment on `node` is kept on: its top-level layer, as Figma attaches comments, or\n * within a section the section's own child, as frames move about inside it.\n */\nfunction commentLayer(graph: SceneGraph, node: SceneNode, pageId: string): SceneNode {\n const isSection = (id: string | null) => !!id && graph.getNode(id)?.type === 'SECTION'\n return (\n graph.closest(node.id, (layer) => layer.parentId === pageId || isSection(layer.parentId)) ??\n node\n )\n}\n\n/**\n * Where a pin at a canvas point is kept: on the top-level layer under it, or on `node`'s when\n * given, so it follows that layer; on the canvas when nothing is there.\n */\nexport function commentAnchor(graph: SceneGraph, pageId: string, at: Vector, node?: SceneNode) {\n const target = node ?? graph.hitTest(at.x, at.y, pageId)\n const layer = target ? commentLayer(graph, target, pageId) : null\n const abs = layer ? graph.getAbsolutePosition(layer.id) : null\n return {\n nodeId: layer?.id ?? null,\n nodeName: layer?.name ?? null,\n offsetX: abs ? at.x - abs.x : 0,\n offsetY: abs ? at.y - abs.y : 0,\n x: at.x,\n y: at.y\n }\n}\n\n/** Where a thread's pin is now: on its layer while that layer exists, else where it was left. */\nexport function commentPosition(graph: SceneGraph, thread: CommentThread): Vector {\n const node = thread.nodeId ? graph.getNode(thread.nodeId) : undefined\n if (!node) return { x: thread.x, y: thread.y }\n const abs = graph.getAbsolutePosition(node.id)\n return { x: abs.x + (thread.offsetX ?? 0), y: abs.y + (thread.offsetY ?? 0) }\n}\n\n/** A new thread pinned at a canvas point of a page. */\nexport function createCommentThread(\n graph: SceneGraph,\n options: {\n pageId: string\n at: Vector\n /** Pin it on this layer's top-level layer rather than on whatever is at `at`. */\n node?: SceneNode\n /** The area the person circled, when the comment was drawn rather than clicked. */\n region?: CommentRegion | null\n author: CommentAuthor\n text: string\n now: string\n }\n): CommentThread {\n const { pageId, at, node, region, author, text, now } = options\n return {\n id: newCommentId('c'),\n pageId,\n pageName: graph.getNode(pageId)?.name,\n ...commentAnchor(graph, pageId, at, node),\n author: author.name,\n authorColor: author.color,\n text,\n createdAt: now,\n updatedAt: now,\n resolved: false,\n ...(region ? { region } : {}),\n replies: []\n }\n}\n\nexport function createCommentReply(author: CommentAuthor, text: string, now: string): CommentReply {\n return {\n id: newCommentId('r'),\n author: author.name,\n authorColor: author.color,\n text,\n createdAt: now\n }\n}\n\n/** The threads with one changed and marked as edited at `now`, for merging with other copies. */\nexport function editCommentThread(\n threads: readonly CommentThread[],\n id: string,\n now: string,\n edit: (thread: CommentThread) => CommentThread\n): CommentThread[] {\n return threads.map((thread) => (thread.id === id ? { ...edit(thread), updatedAt: now } : thread))\n}\n\n/** A reply ends up in the thread and reopens it, as answering a resolved comment does. */\nexport function replyToCommentThread(thread: CommentThread, reply: CommentReply): CommentThread {\n return { ...thread, resolved: false, resolvedAt: null, replies: [...thread.replies, reply] }\n}\n\nexport function resolveCommentThread(\n thread: CommentThread,\n resolved: boolean,\n now: string\n): CommentThread {\n return { ...thread, resolved, resolvedAt: resolved ? now : null }\n}\n\n/** Deleted threads and replies stay as tombstones, so a stale copy cannot bring them back. */\nexport function deleteCommentThread(thread: CommentThread): CommentThread {\n return { ...thread, deleted: true }\n}\n\nexport function deleteCommentReply(thread: CommentThread, replyId: string): CommentThread {\n return {\n ...thread,\n replies: thread.replies.map((entry) =>\n entry.id === replyId ? { ...entry, deleted: true } : entry\n )\n }\n}\n"],"mappings":";;AAWA,SAAS,aAAa,QAA2B;CAC/C,OAAO,GAAG,OAAO,GAAG,UAAU,CAAC;AACjC;;AAGA,SAAgB,mBAA2B;CACzC,wBAAO,IAAI,KAAK,EAAA,CAAE,YAAY;AAChC;;AAGA,SAAgB,YAAY,GAA0B,GAAkC;CACtF,OAAO,EAAE,UAAU,cAAc,EAAE,SAAS;AAC9C;;AAGA,SAAgB,YAAY,QAAuC;CACjE,OAAO,OAAO,QAAQ,QAAQ,UAAU,CAAC,MAAM,OAAO;AACxD;;AAGA,SAAgB,kBAAkB,QAAuB,QAAyB;CAChF,OAAO,OAAO,WAAW,UAAU,YAAY,MAAM,CAAC,CAAC,MAAM,UAAU,MAAM,WAAW,MAAM;AAChG;;AAGA,SAAgB,sBACd,SACA,IAC2B;CAC3B,OAAO,QAA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OAAO,QAAQ,IAAI,IAAI;EACxC,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB;EACA,WAAW;EACX,WAAW;EACX,UAAU;EACV,GAAI,SAAS,EAAE,OAAO,IAAI,CAAC;EAC3B,SAAS,CAAC;CACZ;AACF;AAEA,SAAgB,mBAAmB,QAAuB,MAAc,KAA2B;CACjG,OAAO;EACL,IAAI,aAAa,GAAG;EACpB,QAAQ,OAAO;EACf,aAAa,OAAO;EACpB;EACA,WAAW;CACb;AACF;;AAGA,SAAgB,kBACd,SACA,IACA,KACA,MACiB;CACjB,OAAO,QAAQ,KAAK,WAAY,OAAO,OAAO,KAAK;EAAE,GAAG,KAAK,MAAM;EAAG,WAAW;CAAI,IAAI,MAAO;AAClG;;AAGA,SAAgB,qBAAqB,QAAuB,OAAoC;CAC9F,OAAO;EAAE,GAAG;EAAQ,UAAU;EAAO,YAAY;EAAM,SAAS,CAAC,GAAG,OAAO,SAAS,KAAK;CAAE;AAC7F;AAEA,SAAgB,qBACd,QACA,UACA,KACe;CACf,OAAO;EAAE,GAAG;EAAQ;EAAU,YAAY,WAAW,MAAM;CAAK;AAClE;;AAGA,SAAgB,oBAAoB,QAAsC;CACxE,OAAO;EAAE,GAAG;EAAQ,SAAS;CAAK;AACpC;AAEA,SAAgB,mBAAmB,QAAuB,SAAgC;CACxF,OAAO;EACL,GAAG;EACH,SAAS,OAAO,QAAQ,KAAK,UAC3B,MAAM,OAAO,UAAU;GAAE,GAAG;GAAO,SAAS;EAAK,IAAI,KACvD;CACF;AACF"}
@@ -1,5 +1,5 @@
1
1
  import { ComponentPropertyTarget, applyComponentPropertyValue, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, propertyOwner, removeComponentProperty, resolveComponentPropertyValue } from "./properties.js";
2
2
  import { libraryDefinitionsPage } from "./library-page.js";
3
- import { compareCanvasPosition, defaultVariant, restingVariant, variantDefaultValue } from "./variants.js";
3
+ import { compareCanvasPosition, defaultVariant, restingVariant, variantDefaultValue, variantInstanceFor, variantSetsAround } from "./variants.js";
4
4
  import { InstanceExposureIssue, exposableInstances, exposedInstances, instanceExposureIssue } from "./exposure.js";
5
- export { ComponentPropertyTarget, type InstanceExposureIssue, applyComponentPropertyValue, compareCanvasPosition, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, defaultVariant, exposableInstances, exposedInstances, findComponentPropertyTarget, findComponentPropertyTargets, instanceExposureIssue, libraryDefinitionsPage, propertyOwner, removeComponentProperty, resolveComponentPropertyValue, restingVariant, variantDefaultValue };
5
+ export { ComponentPropertyTarget, type InstanceExposureIssue, applyComponentPropertyValue, compareCanvasPosition, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, defaultVariant, exposableInstances, exposedInstances, findComponentPropertyTarget, findComponentPropertyTargets, instanceExposureIssue, libraryDefinitionsPage, propertyOwner, removeComponentProperty, resolveComponentPropertyValue, restingVariant, variantDefaultValue, variantInstanceFor, variantSetsAround };
@@ -1,5 +1,5 @@
1
1
  import { applyComponentPropertyValue, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, findComponentPropertyTarget, findComponentPropertyTargets, propertyOwner, removeComponentProperty, resolveComponentPropertyValue } from "./properties.js";
2
2
  import { libraryDefinitionsPage } from "./library-page.js";
3
- import { compareCanvasPosition, defaultVariant, restingVariant, variantDefaultValue } from "./variants.js";
3
+ import { compareCanvasPosition, defaultVariant, restingVariant, variantDefaultValue, variantInstanceFor, variantSetsAround } from "./variants.js";
4
4
  import { exposableInstances, exposedInstances, instanceExposureIssue } from "./exposure.js";
5
- export { applyComponentPropertyValue, compareCanvasPosition, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, defaultVariant, exposableInstances, exposedInstances, findComponentPropertyTarget, findComponentPropertyTargets, instanceExposureIssue, libraryDefinitionsPage, propertyOwner, removeComponentProperty, resolveComponentPropertyValue, restingVariant, variantDefaultValue };
5
+ export { applyComponentPropertyValue, compareCanvasPosition, componentPropertyDefinitions, componentPropertyOwners, createComponentPropertyId, defaultVariant, exposableInstances, exposedInstances, findComponentPropertyTarget, findComponentPropertyTargets, instanceExposureIssue, libraryDefinitionsPage, propertyOwner, removeComponentProperty, resolveComponentPropertyValue, restingVariant, variantDefaultValue, variantInstanceFor, variantSetsAround };
@@ -1 +1 @@
1
- {"version":3,"file":"properties.d.ts","names":[],"sources":["../../src/components/properties.ts"],"mappings":";;;UAYiB;EACf,MAAM;EACN,OAAO;EACP,QAAQ;;;;;;iBAOM,cAAc,OAAO,YAAY,WAAW,YAAY;iBAKxD,wBAAwB,OAAO,YAAY,UAAU,YAAY;iBAQjE,6BACd,OAAO,YACP,UAAU,YACT;iBAUa,8BAA8B,OAAO,YAAY,gBAAgB;iBAkBjE,4BACd,OAAO,YACP,UAAU,WACV,qBACC;iBAIa,6BACd,OAAO,YACP,UAAU,WACV,qBACC;iBA4Ea,4BACd,OAAO,YACP,oBACA,YAAY,6BACZ,gBACC;iBAmEa,wBACd,OAAO,YACP,iBACA;;iBAwBc"}
1
+ {"version":3,"file":"properties.d.ts","names":[],"sources":["../../src/components/properties.ts"],"mappings":";;;UAYiB;EACf,MAAM;EACN,OAAO;EACP,QAAQ;;;;;;iBAOM,cAAc,OAAO,YAAY,WAAW,YAAY;iBAKxD,wBAAwB,OAAO,YAAY,UAAU,YAAY;iBAQjE,6BACd,OAAO,YACP,UAAU,YACT;iBAUa,8BAA8B,OAAO,YAAY,gBAAgB;iBAkBjE,4BACd,OAAO,YACP,UAAU,WACV,qBACC;iBAIa,6BACd,OAAO,YACP,UAAU,WACV,qBACC;iBAkFa,4BACd,OAAO,YACP,oBACA,YAAY,6BACZ,gBACC;iBAmEa,wBACd,OAAO,YACP,iBACA;;iBAwBc"}
@@ -1,4 +1,4 @@
1
- import { setInstanceOverride } from "../instances/overrides.js";
1
+ import { ownInstanceOverrides, setInstanceOverride } from "../instances/overrides.js";
2
2
  import { randomHex } from "../random.js";
3
3
  import { instanceMainComponent } from "../instances/main-component.js";
4
4
  import { walkInstanceSources } from "../instances/source-walk.js";
@@ -54,7 +54,7 @@ function applyTextProperty(graph, owner, targets, value) {
54
54
  for (const item of targets) {
55
55
  if (item.field !== "TEXT" || item.node.type !== "TEXT") continue;
56
56
  graph.updateNode(item.node.id, { text: value });
57
- if (findInstanceAncestor(graph, item.node.id)) setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, "text", value);
57
+ if (findInstanceAncestor(graph, item.node.id)) setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "text", value);
58
58
  }
59
59
  }
60
60
  function applyBooleanProperty(graph, owner, targets, value) {
@@ -62,17 +62,17 @@ function applyBooleanProperty(graph, owner, targets, value) {
62
62
  if (item.field !== "VISIBLE") continue;
63
63
  const instance = findInstanceAncestor(graph, item.node.id);
64
64
  graph.updateNode(item.node.id, { visible: value === "true" });
65
- if (instance) setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, "visible", value === "true");
65
+ if (instance) setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "visible", value === "true");
66
66
  }
67
67
  }
68
68
  function applyInstanceSwapProperty(graph, owner, targets, target) {
69
69
  for (const item of targets) {
70
70
  if (item.field !== "INSTANCE_SWAP" || item.node.type !== "INSTANCE") continue;
71
71
  graph.swapInstanceComponent(item.node.id, target.id);
72
- setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, "name", target.name);
73
- setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, "componentId", target.id);
74
- setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, "sourceComponentId", item.source.id);
75
- graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides });
72
+ setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "name", target.name);
73
+ setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "componentId", target.id);
74
+ setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, "sourceComponentId", item.source.id);
75
+ graph.updateNode(owner.id, { instanceOverrides: ownInstanceOverrides(owner) });
76
76
  }
77
77
  }
78
78
  function applyComponentPropertyValue(graph, instanceId, definition, value) {
@@ -1 +1 @@
1
- {"version":3,"file":"properties.js","names":[],"sources":["../../src/components/properties.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor, recordAssignmentOverride } from '../instances'\nimport { instanceMainComponent } from '../instances/main-component'\nimport { setInstanceOverride } from '../instances/overrides'\nimport { walkInstanceSources } from '../instances/source-walk'\nimport { randomHex } from '../random'\nimport type {\n ComponentPropertyDefinition,\n ComponentPropertyReferenceField,\n SceneNode\n} from '../types'\n\nexport interface ComponentPropertyTarget {\n node: SceneNode\n field: ComponentPropertyReferenceField\n source: SceneNode\n}\n\n/**\n * The component that defines a main component's properties: its set when it is a variant,\n * since variants own no properties of their own (desktop 126), else the component itself.\n */\nexport function propertyOwner(graph: SceneGraph, component: SceneNode): SceneNode {\n const parent = component.parentId ? graph.getNode(component.parentId) : undefined\n return component.type === 'COMPONENT' && parent?.type === 'COMPONENT_SET' ? parent : component\n}\n\nexport function componentPropertyOwners(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n if (instance.type !== 'INSTANCE') return []\n const component = instanceMainComponent(graph, instance)\n if (!component) return []\n const parent = component.parentId ? graph.getNode(component.parentId) : null\n return parent?.type === 'COMPONENT_SET' ? [parent, component] : [component]\n}\n\nexport function componentPropertyDefinitions(\n graph: SceneGraph,\n instance: SceneNode\n): ComponentPropertyDefinition[] {\n const definitions = new Map<string, ComponentPropertyDefinition>()\n for (const owner of componentPropertyOwners(graph, instance)) {\n for (const definition of owner.componentPropertyDefinitions) {\n if (!definitions.has(definition.id)) definitions.set(definition.id, definition)\n }\n }\n return [...definitions.values()]\n}\n\nexport function resolveComponentPropertyValue(graph: SceneGraph, value: string): SceneNode | null {\n const direct = graph.getNode(value)\n if (direct?.type === 'COMPONENT') return direct\n if (direct?.type === 'COMPONENT_SET') {\n const componentId = direct.childIds.find((id) => graph.getNode(id)?.type === 'COMPONENT')\n return componentId ? (graph.getNode(componentId) ?? null) : null\n }\n for (const node of graph.getAllNodes()) {\n if (\n node.type === 'COMPONENT' &&\n (node.componentKey === value || node.sourceLibraryKey === value || node.source.id === value)\n ) {\n return node\n }\n }\n return null\n}\n\nexport function findComponentPropertyTarget(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): ComponentPropertyTarget | null {\n return findComponentPropertyTargets(graph, instance, propertyId)[0] ?? null\n}\n\nexport function findComponentPropertyTargets(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): ComponentPropertyTarget[] {\n const targets: ComponentPropertyTarget[] = []\n walkInstanceSources(\n graph,\n instance,\n (source, target) => {\n const reference = source.componentPropertyReferences.find(\n (candidate) => candidate.propertyId === propertyId\n )\n if (reference) targets.push({ node: target, field: reference.field, source })\n return true\n },\n true\n )\n return targets\n}\n\nfunction applyTextProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n value: string\n): void {\n for (const item of targets) {\n if (item.field !== 'TEXT' || item.node.type !== 'TEXT') continue\n graph.updateNode(item.node.id, { text: value })\n if (findInstanceAncestor(graph, item.node.id)) {\n setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, 'text', value)\n }\n }\n}\n\nfunction applyBooleanProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n value: string\n): void {\n for (const item of targets) {\n if (item.field !== 'VISIBLE') continue\n const instance = findInstanceAncestor(graph, item.node.id)\n graph.updateNode(item.node.id, { visible: value === 'true' })\n if (instance) {\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n item.node.id,\n 'visible',\n value === 'true'\n )\n }\n }\n}\n\nfunction applyInstanceSwapProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n target: SceneNode\n): void {\n for (const item of targets) {\n if (item.field !== 'INSTANCE_SWAP' || item.node.type !== 'INSTANCE') continue\n graph.swapInstanceComponent(item.node.id, target.id)\n setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, 'name', target.name)\n setInstanceOverride(owner.instanceOverrides, owner.id, item.node.id, 'componentId', target.id)\n setInstanceOverride(\n owner.instanceOverrides,\n owner.id,\n item.node.id,\n 'sourceComponentId',\n item.source.id\n )\n graph.updateNode(owner.id, { instanceOverrides: owner.instanceOverrides })\n }\n}\n\nexport function applyComponentPropertyValue(\n graph: SceneGraph,\n instanceId: string,\n definition: ComponentPropertyDefinition,\n value: string\n): SceneNode | null {\n const instance = graph.getNode(instanceId)\n if (instance?.type !== 'INSTANCE') return null\n if (definition.type === 'VARIANT') return null\n const targets = findComponentPropertyTargets(graph, instance, definition.id)\n const target =\n definition.type === 'INSTANCE_SWAP' ? resolveComponentPropertyValue(graph, value) : null\n if (definition.type === 'INSTANCE_SWAP' && !target) return null\n if (definition.type === 'TEXT') {\n applyTextProperty(graph, instance, targets, value)\n } else if (definition.type === 'BOOLEAN') {\n applyBooleanProperty(graph, instance, targets, value)\n } else if (target) {\n applyInstanceSwapProperty(graph, instance, targets, target)\n }\n const previous = instance.componentPropertyAssignments[definition.id]\n const assigned = definition.type === 'INSTANCE_SWAP' && target ? target.id : value\n graph.updateNode(instance.id, {\n componentPropertyAssignments: {\n ...instance.componentPropertyAssignments,\n [definition.id]: assigned\n }\n })\n // Assigning a nested instance's property is an edit of the instance above it, so it outranks\n // a text override at that same level. Reapplying the value a property already has (a variant\n // swap, a reload) is not an edit and records nothing.\n if (previous !== assigned) recordAssignmentOverride(graph, instance.id, definition.id, value)\n return definition.type === 'INSTANCE_SWAP' ? target : instance\n}\n\nfunction componentSubtree(graph: SceneGraph, componentId: string): SceneNode[] {\n const component = graph.getNode(componentId)\n if (!component) return []\n const nodes = [component]\n const visit = (node: SceneNode): void => {\n for (const child of graph.getChildren(node.id)) {\n nodes.push(child)\n visit(child)\n }\n }\n visit(component)\n return nodes\n}\n\nfunction componentInstances(graph: SceneGraph, componentId: string): SceneNode[] {\n return [...graph.getAllNodes()].filter(\n (node) => node.type === 'INSTANCE' && node.componentId === componentId\n )\n}\n\nfunction removePropertyFromNode(graph: SceneGraph, node: SceneNode, propertyId: string): void {\n if (node.componentPropertyReferences.some((reference) => reference.propertyId === propertyId)) {\n graph.updateNode(node.id, {\n componentPropertyReferences: node.componentPropertyReferences.filter(\n (reference) => reference.propertyId !== propertyId\n )\n })\n }\n if (node.type === 'INSTANCE' && propertyId in node.componentPropertyAssignments) {\n graph.updateNode(node.id, {\n componentPropertyAssignments: Object.fromEntries(\n Object.entries(node.componentPropertyAssignments).filter(([id]) => id !== propertyId)\n )\n })\n }\n}\n\nexport function removeComponentProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string\n): boolean {\n const owner = graph.getNode(ownerId)\n if (!owner || (owner.type !== 'COMPONENT' && owner.type !== 'COMPONENT_SET')) return false\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.filter(\n (definition) => definition.id !== propertyId\n )\n })\n const nodes = [\n ...componentSubtree(graph, owner.id),\n ...componentInstances(graph, owner.id),\n ...(owner.type === 'COMPONENT_SET'\n ? owner.childIds.flatMap((id) => [\n ...componentSubtree(graph, id),\n ...componentInstances(graph, id)\n ])\n : [])\n ]\n for (const node of nodes) removePropertyFromNode(graph, node, propertyId)\n return true\n}\n\n/** A new component property ID, in the `prop:` form the editor, plugin API, and design JSX share. */\nexport function createComponentPropertyId(): string {\n return `prop:${randomHex(8)}`\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAgB,cAAc,OAAmB,WAAiC;CAChF,MAAM,SAAS,UAAU,WAAW,MAAM,QAAQ,UAAU,QAAQ,IAAI,KAAA;CACxE,OAAO,UAAU,SAAS,eAAe,QAAQ,SAAS,kBAAkB,SAAS;AACvF;AAEA,SAAgB,wBAAwB,OAAmB,UAAkC;CAC3F,IAAI,SAAS,SAAS,YAAY,OAAO,CAAC;CAC1C,MAAM,YAAY,sBAAsB,OAAO,QAAQ;CACvD,IAAI,CAAC,WAAW,OAAO,C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U,eAAe,UAAU,GAC1F,MAAM,WAAW,KAAK,IAAI,EACxB,6BAA6B,KAAK,4BAA4B,QAC3D,cAAc,UAAU,eAAe,UAC1C,EACF,CAAC;CAEH,IAAI,KAAK,SAAS,cAAc,cAAc,KAAK,8BACjD,MAAM,WAAW,KAAK,IAAI,EACxB,8BAA8B,OAAO,YACnC,OAAO,QAAQ,KAAK,4BAA4B,CAAC,CAAC,QAAQ,CAAC,QAAQ,OAAO,UAAU,CACtF,EACF,CAAC;AAEL;AAEA,SAAgB,wBACd,OACA,SACA,YACS;CACT,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,IAAI,CAAC,SAAU,MAAM,SAAS,eAAe,MAAM,SAAS,iBAAkB,OAAO;CACrF,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,MAAM,6BAA6B,QAC9D,eAAe,WAAW,OAAO,UACpC,EACF,CAAC;CACD,MAAM,QAAQ;EACZ,GAAG,iBAAiB,OAAO,MAAM,EAAE;EACnC,GAAG,mBAAmB,OAAO,MAAM,EAAE;EACrC,GAAI,MAAM,SAAS,kBACf,MAAM,SAAS,SAAS,OAAO,CAC7B,GAAG,iBAAiB,OAAO,EAAE,GAC7B,GAAG,mBAAmB,OAAO,EAAE,CACjC,CAAC,IACD,CAAC;CACP;CACA,KAAK,MAAM,QAAQ,OAAO,uBAAuB,OAAO,MAAM,UAAU;CACxE,OAAO;AACT;;AAGA,SAAgB,4BAAoC;CAClD,OAAO,QAAQ,UAAU,CAAC;AAC5B"}
1
+ {"version":3,"file":"properties.js","names":[],"sources":["../../src/components/properties.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { findInstanceAncestor, recordAssignmentOverride } from '../instances'\nimport { instanceMainComponent } from '../instances/main-component'\nimport { ownInstanceOverrides, setInstanceOverride } from '../instances/overrides'\nimport { walkInstanceSources } from '../instances/source-walk'\nimport { randomHex } from '../random'\nimport type {\n ComponentPropertyDefinition,\n ComponentPropertyReferenceField,\n SceneNode\n} from '../types'\n\nexport interface ComponentPropertyTarget {\n node: SceneNode\n field: ComponentPropertyReferenceField\n source: SceneNode\n}\n\n/**\n * The component that defines a main component's properties: its set when it is a variant,\n * since variants own no properties of their own (desktop 126), else the component itself.\n */\nexport function propertyOwner(graph: SceneGraph, component: SceneNode): SceneNode {\n const parent = component.parentId ? graph.getNode(component.parentId) : undefined\n return component.type === 'COMPONENT' && parent?.type === 'COMPONENT_SET' ? parent : component\n}\n\nexport function componentPropertyOwners(graph: SceneGraph, instance: SceneNode): SceneNode[] {\n if (instance.type !== 'INSTANCE') return []\n const component = instanceMainComponent(graph, instance)\n if (!component) return []\n const parent = component.parentId ? graph.getNode(component.parentId) : null\n return parent?.type === 'COMPONENT_SET' ? [parent, component] : [component]\n}\n\nexport function componentPropertyDefinitions(\n graph: SceneGraph,\n instance: SceneNode\n): ComponentPropertyDefinition[] {\n const definitions = new Map<string, ComponentPropertyDefinition>()\n for (const owner of componentPropertyOwners(graph, instance)) {\n for (const definition of owner.componentPropertyDefinitions) {\n if (!definitions.has(definition.id)) definitions.set(definition.id, definition)\n }\n }\n return [...definitions.values()]\n}\n\nexport function resolveComponentPropertyValue(graph: SceneGraph, value: string): SceneNode | null {\n const direct = graph.getNode(value)\n if (direct?.type === 'COMPONENT') return direct\n if (direct?.type === 'COMPONENT_SET') {\n const componentId = direct.childIds.find((id) => graph.getNode(id)?.type === 'COMPONENT')\n return componentId ? (graph.getNode(componentId) ?? null) : null\n }\n for (const node of graph.getAllNodes()) {\n if (\n node.type === 'COMPONENT' &&\n (node.componentKey === value || node.sourceLibraryKey === value || node.source.id === value)\n ) {\n return node\n }\n }\n return null\n}\n\nexport function findComponentPropertyTarget(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): ComponentPropertyTarget | null {\n return findComponentPropertyTargets(graph, instance, propertyId)[0] ?? null\n}\n\nexport function findComponentPropertyTargets(\n graph: SceneGraph,\n instance: SceneNode,\n propertyId: string\n): ComponentPropertyTarget[] {\n const targets: ComponentPropertyTarget[] = []\n walkInstanceSources(\n graph,\n instance,\n (source, target) => {\n const reference = source.componentPropertyReferences.find(\n (candidate) => candidate.propertyId === propertyId\n )\n if (reference) targets.push({ node: target, field: reference.field, source })\n return true\n },\n true\n )\n return targets\n}\n\nfunction applyTextProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n value: string\n): void {\n for (const item of targets) {\n if (item.field !== 'TEXT' || item.node.type !== 'TEXT') continue\n graph.updateNode(item.node.id, { text: value })\n if (findInstanceAncestor(graph, item.node.id)) {\n setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, 'text', value)\n }\n }\n}\n\nfunction applyBooleanProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n value: string\n): void {\n for (const item of targets) {\n if (item.field !== 'VISIBLE') continue\n const instance = findInstanceAncestor(graph, item.node.id)\n graph.updateNode(item.node.id, { visible: value === 'true' })\n if (instance) {\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n item.node.id,\n 'visible',\n value === 'true'\n )\n }\n }\n}\n\nfunction applyInstanceSwapProperty(\n graph: SceneGraph,\n owner: SceneNode,\n targets: ComponentPropertyTarget[],\n target: SceneNode\n): void {\n for (const item of targets) {\n if (item.field !== 'INSTANCE_SWAP' || item.node.type !== 'INSTANCE') continue\n graph.swapInstanceComponent(item.node.id, target.id)\n setInstanceOverride(ownInstanceOverrides(owner), owner.id, item.node.id, 'name', target.name)\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n item.node.id,\n 'componentId',\n target.id\n )\n setInstanceOverride(\n ownInstanceOverrides(owner),\n owner.id,\n item.node.id,\n 'sourceComponentId',\n item.source.id\n )\n graph.updateNode(owner.id, { instanceOverrides: ownInstanceOverrides(owner) })\n }\n}\n\nexport function applyComponentPropertyValue(\n graph: SceneGraph,\n instanceId: string,\n definition: ComponentPropertyDefinition,\n value: string\n): SceneNode | null {\n const instance = graph.getNode(instanceId)\n if (instance?.type !== 'INSTANCE') return null\n if (definition.type === 'VARIANT') return null\n const targets = findComponentPropertyTargets(graph, instance, definition.id)\n const target =\n definition.type === 'INSTANCE_SWAP' ? resolveComponentPropertyValue(graph, value) : null\n if (definition.type === 'INSTANCE_SWAP' && !target) return null\n if (definition.type === 'TEXT') {\n applyTextProperty(graph, instance, targets, value)\n } else if (definition.type === 'BOOLEAN') {\n applyBooleanProperty(graph, instance, targets, value)\n } else if (target) {\n applyInstanceSwapProperty(graph, instance, targets, target)\n }\n const previous = instance.componentPropertyAssignments[definition.id]\n const assigned = definition.type === 'INSTANCE_SWAP' && target ? target.id : value\n graph.updateNode(instance.id, {\n componentPropertyAssignments: {\n ...instance.componentPropertyAssignments,\n [definition.id]: assigned\n }\n })\n // Assigning a nested instance's property is an edit of the instance above it, so it outranks\n // a text override at that same level. Reapplying the value a property already has (a variant\n // swap, a reload) is not an edit and records nothing.\n if (previous !== assigned) recordAssignmentOverride(graph, instance.id, definition.id, value)\n return definition.type === 'INSTANCE_SWAP' ? target : instance\n}\n\nfunction componentSubtree(graph: SceneGraph, componentId: string): SceneNode[] {\n const component = graph.getNode(componentId)\n if (!component) return []\n const nodes = [component]\n const visit = (node: SceneNode): void => {\n for (const child of graph.getChildren(node.id)) {\n nodes.push(child)\n visit(child)\n }\n }\n visit(component)\n return nodes\n}\n\nfunction componentInstances(graph: SceneGraph, componentId: string): SceneNode[] {\n return [...graph.getAllNodes()].filter(\n (node) => node.type === 'INSTANCE' && node.componentId === componentId\n )\n}\n\nfunction removePropertyFromNode(graph: SceneGraph, node: SceneNode, propertyId: string): void {\n if (node.componentPropertyReferences.some((reference) => reference.propertyId === propertyId)) {\n graph.updateNode(node.id, {\n componentPropertyReferences: node.componentPropertyReferences.filter(\n (reference) => reference.propertyId !== propertyId\n )\n })\n }\n if (node.type === 'INSTANCE' && propertyId in node.componentPropertyAssignments) {\n graph.updateNode(node.id, {\n componentPropertyAssignments: Object.fromEntries(\n Object.entries(node.componentPropertyAssignments).filter(([id]) => id !== propertyId)\n )\n })\n }\n}\n\nexport function removeComponentProperty(\n graph: SceneGraph,\n ownerId: string,\n propertyId: string\n): boolean {\n const owner = graph.getNode(ownerId)\n if (!owner || (owner.type !== 'COMPONENT' && owner.type !== 'COMPONENT_SET')) return false\n graph.updateNode(owner.id, {\n componentPropertyDefinitions: owner.componentPropertyDefinitions.filter(\n (definition) => definition.id !== propertyId\n )\n })\n const nodes = [\n ...componentSubtree(graph, owner.id),\n ...componentInstances(graph, owner.id),\n ...(owner.type === 'COMPONENT_SET'\n ? owner.childIds.flatMap((id) => [\n ...componentSubtree(graph, id),\n ...componentInstances(graph, id)\n ])\n : [])\n ]\n for (const node of nodes) removePropertyFromNode(graph, node, propertyId)\n return true\n}\n\n/** A new component property ID, in the `prop:` form the editor, plugin API, and design JSX share. */\nexport function createComponentPropertyId(): string {\n return `prop:${randomHex(8)}`\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAgB,cAAc,OAAmB,WAAiC;CAChF,MAAM,SAAS,UAAU,WAAW,MAAM,QAAQ,UAAU,QAAQ,IAAI,KAAA;CACxE,OAAO,UAAU,SAAS,eAAe,QAAQ,SAAS,kBAAkB,SAAS;AACvF;AAEA,SAAgB,wBAAwB,OAAmB,UAAkC;CAC3F,IAAI,SAAS,SAAS,YAAY,OAAO,CAAC;CAC1C,MAAM,YAAY,sBAAsB,OAAO,QAAQ;CACvD,IAAI,CAAC,WAAW,OAAO,CAAC;CACxB,MAAM,SAAS,UAAU,WAAW,MAAM,QAAQ,UAAU,QAAQ,IAAI;CACxE,OAAO,QAAQ,SAAS,kBAAkB,CAAC,QAAQ,SAAS,IAAI,CAAC,SAAS;AAC5E;AAEA,SAAgB,6BACd,OACA,UAC+B;CAC/B,MAAM,8BAAc,IAAI,IAAyC;CACjE,KAAK,MAAM,SAAS,wBAAwB,OAAO,QAAQ,GACzD,KAAK,MAAM,cAAc,MAAM,8BAC7B,IAAI,CAAC,YAAY,IAAI,WAAW,EAAE,G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EACF,CAAC;AAEL;AAEA,SAAgB,wBACd,OACA,SACA,YACS;CACT,MAAM,QAAQ,MAAM,QAAQ,OAAO;CACnC,IAAI,CAAC,SAAU,MAAM,SAAS,eAAe,MAAM,SAAS,iBAAkB,OAAO;CACrF,MAAM,WAAW,MAAM,IAAI,EACzB,8BAA8B,MAAM,6BAA6B,QAC9D,eAAe,WAAW,OAAO,UACpC,EACF,CAAC;CACD,MAAM,QAAQ;EACZ,GAAG,iBAAiB,OAAO,MAAM,EAAE;EACnC,GAAG,mBAAmB,OAAO,MAAM,EAAE;EACrC,GAAI,MAAM,SAAS,kBACf,MAAM,SAAS,SAAS,OAAO,CAC7B,GAAG,iBAAiB,OAAO,EAAE,GAC7B,GAAG,mBAAmB,OAAO,EAAE,CACjC,CAAC,IACD,CAAC;CACP;CACA,KAAK,MAAM,QAAQ,OAAO,uBAAuB,OAAO,MAAM,UAAU;CACxE,OAAO;AACT;;AAGA,SAAgB,4BAAoC;CAClD,OAAO,QAAQ,UAAU,CAAC;AAC5B"}
@@ -22,6 +22,17 @@ declare function variantDefaultValue(graph: SceneGraph, set: SceneNode, property
22
22
  * variant, else the default variant, as a document that leaves them out draws it.
23
23
  */
24
24
  declare function restingVariant(graph: SceneGraph, set: SceneNode): SceneNode | undefined;
25
+ /**
26
+ * The component sets whose variants a prototype's Change to on this layer may show, nearest
27
+ * first: the set of each variant, and of each instance of a variant, from the layer up.
28
+ */
29
+ declare function variantSetsAround(graph: SceneGraph, nodeId: string): SceneNode[];
30
+ /**
31
+ * The instance a Change to from this layer switches to another variant of `setId`: the layer
32
+ * itself or its nearest instance ancestor that shows a variant of that set. A main component has
33
+ * none, since it is the definition rather than a copy that changes.
34
+ */
35
+ declare function variantInstanceFor(graph: SceneGraph, nodeId: string, setId: string): SceneNode | undefined;
25
36
  //#endregion
26
- export { compareCanvasPosition, defaultVariant, restingVariant, variantDefaultValue };
37
+ export { compareCanvasPosition, defaultVariant, restingVariant, variantDefaultValue, variantInstanceFor, variantSetsAround };
27
38
  //# sourceMappingURL=variants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"variants.d.ts","names":[],"sources":["../../src/components/variants.ts"],"mappings":";;;;iBAIgB,sBAAsB,GAAG,WAAW,GAAG;;;;;iBAQvC,eAAe,OAAO,YAAY,KAAK,YAAY;;;;;iBAWnD,oBACd,OAAO,YACP,KAAK,WACL;EAAY;EAAc;EAAsB;;;;;;iBAUlC,eAAe,OAAO,YAAY,KAAK,YAAY"}
1
+ {"version":3,"file":"variants.d.ts","names":[],"sources":["../../src/components/variants.ts"],"mappings":";;;;iBAKgB,sBAAsB,GAAG,WAAW,GAAG;;;;;iBAQvC,eAAe,OAAO,YAAY,KAAK,YAAY;;;;;iBAWnD,oBACd,OAAO,YACP,KAAK,WACL;EAAY;EAAc;EAAsB;;;;;;iBAUlC,eAAe,OAAO,YAAY,KAAK,YAAY;;;;;iBA8BnD,kBAAkB,OAAO,YAAY,iBAAiB;;;;;;iBAetD,mBACd,OAAO,YACP,gBACA,gBACC"}
@@ -1,3 +1,4 @@
1
+ import { instanceMainComponent } from "../instances/main-component.js";
1
2
  //#region src/components/variants.ts
2
3
  /** Variants in reading order on the canvas: top to bottom, then left to right, then by name. */
3
4
  function compareCanvasPosition(a, b) {
@@ -26,7 +27,35 @@ function restingVariant(graph, set) {
26
27
  const values = set.componentPropertyDefinitions.filter((definition) => definition.type === "VARIANT").map((property) => [property.name, variantDefaultValue(graph, set, property)]);
27
28
  return graph.getChildren(set.id).find((child) => child.type === "COMPONENT" && values.every(([name, value]) => child.componentPropertyValues[name] === value)) ?? defaultVariant(graph, set);
28
29
  }
30
+ /** The component set a variant belongs to, or the set of the variant an instance shows. */
31
+ function variantSetOf(graph, node) {
32
+ const variant = node.type === "INSTANCE" ? instanceMainComponent(graph, node) : node;
33
+ if (variant?.type !== "COMPONENT" || !variant.parentId) return void 0;
34
+ const set = graph.getNode(variant.parentId);
35
+ return set?.type === "COMPONENT_SET" ? set : void 0;
36
+ }
37
+ /**
38
+ * The component sets whose variants a prototype's Change to on this layer may show, nearest
39
+ * first: the set of each variant, and of each instance of a variant, from the layer up.
40
+ */
41
+ function variantSetsAround(graph, nodeId) {
42
+ const sets = [];
43
+ graph.closest(nodeId, (node) => {
44
+ const set = variantSetOf(graph, node);
45
+ if (set && !sets.includes(set)) sets.push(set);
46
+ return false;
47
+ });
48
+ return sets;
49
+ }
50
+ /**
51
+ * The instance a Change to from this layer switches to another variant of `setId`: the layer
52
+ * itself or its nearest instance ancestor that shows a variant of that set. A main component has
53
+ * none, since it is the definition rather than a copy that changes.
54
+ */
55
+ function variantInstanceFor(graph, nodeId, setId) {
56
+ return graph.closest(nodeId, (node) => node.type === "INSTANCE" && variantSetOf(graph, node)?.id === setId);
57
+ }
29
58
  //#endregion
30
- export { compareCanvasPosition, defaultVariant, restingVariant, variantDefaultValue };
59
+ export { compareCanvasPosition, defaultVariant, restingVariant, variantDefaultValue, variantInstanceFor, variantSetsAround };
31
60
 
32
61
  //# sourceMappingURL=variants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"variants.js","names":[],"sources":["../../src/components/variants.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport type { SceneNode } from '../types'\n\n/** Variants in reading order on the canvas: top to bottom, then left to right, then by name. */\nexport function compareCanvasPosition(a: SceneNode, b: SceneNode): number {\n return a.y - b.y || a.x - b.x || a.name.localeCompare(b.name)\n}\n\n/**\n * A component set's default variant, the one an instance starts as: the variant in its\n * top-left corner, as Figma defines it.\n */\nexport function defaultVariant(graph: SceneGraph, set: SceneNode): SceneNode | undefined {\n return graph\n .getChildren(set.id)\n .filter((child) => child.type === 'COMPONENT')\n .sort(compareCanvasPosition)[0]\n}\n\n/**\n * The value a variant property starts at: its recorded default when that is one of its options,\n * or else the default variant's, since a document may leave the recorded default empty.\n */\nexport function variantDefaultValue(\n graph: SceneGraph,\n set: SceneNode,\n property: { name: string; defaultValue: string; variantOptions?: string[] }\n): string {\n if (property.variantOptions?.includes(property.defaultValue)) return property.defaultValue\n return defaultVariant(graph, set)?.componentPropertyValues[property.name] ?? property.defaultValue\n}\n\n/**\n * The variant with every property at its default value: the recorded defaults when they name a\n * variant, else the default variant, as a document that leaves them out draws it.\n */\nexport function restingVariant(graph: SceneGraph, set: SceneNode): SceneNode | undefined {\n const properties = set.componentPropertyDefinitions.filter(\n (definition) => definition.type === 'VARIANT'\n )\n const values = properties.map(\n (property) => [property.name, variantDefaultValue(graph, set, property)] as const\n )\n return (\n graph\n .getChildren(set.id)\n .find(\n (child) =>\n child.type === 'COMPONENT' &&\n values.every(([name, value]) => child.componentPropertyValues[name] === value)\n ) ?? defaultVariant(graph, set)\n )\n}\n"],"mappings":";;AAIA,SAAgB,sBAAsB,GAAc,GAAsB;CACxE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,cAAc,EAAE,IAAI;AAC9D;;;;;AAMA,SAAgB,eAAe,OAAmB,KAAuC;CACvF,OAAO,MACJ,YAAY,IAAI,EAAE,CAAC,CACnB,QAAQ,UAAU,MAAM,SAAS,WAAW,CAAC,CAC7C,KAAK,qBAAqB,CAAC,CAAC;AACjC;;;;;AAMA,SAAgB,oBACd,OACA,KACA,UACQ;CACR,IAAI,SAAS,gBAAgB,SAAS,SAAS,YAAY,GAAG,OAAO,SAAS;CAC9E,OAAO,eAAe,OAAO,GAAG,CAAC,EAAE,wBAAwB,SAAS,SAAS,SAAS;AACxF;;;;;AAMA,SAAgB,eAAe,OAAmB,KAAuC;CAIvF,MAAM,SAHa,IAAI,6BAA6B,QACjD,eAAe,WAAW,SAAS,SAEd,CAAC,CAAC,KACvB,aAAa,CAAC,SAAS,MAAM,oBAAoB,OAAO,KAAK,QAAQ,CAAC,CACzE;CACA,OACE,MACG,YAAY,IAAI,EAAE,CAAC,CACnB,MACE,UACC,MAAM,SAAS,eACf,OAAO,OAAO,CAAC,MAAM,WAAW,MAAM,wBAAwB,UAAU,KAAK,CACjF,KAAK,eAAe,OAAO,GAAG;AAEpC"}
1
+ {"version":3,"file":"variants.js","names":[],"sources":["../../src/components/variants.ts"],"sourcesContent":["import type { SceneGraph } from '../graph'\nimport { instanceMainComponent } from '../instances/main-component'\nimport type { SceneNode } from '../types'\n\n/** Variants in reading order on the canvas: top to bottom, then left to right, then by name. */\nexport function compareCanvasPosition(a: SceneNode, b: SceneNode): number {\n return a.y - b.y || a.x - b.x || a.name.localeCompare(b.name)\n}\n\n/**\n * A component set's default variant, the one an instance starts as: the variant in its\n * top-left corner, as Figma defines it.\n */\nexport function defaultVariant(graph: SceneGraph, set: SceneNode): SceneNode | undefined {\n return graph\n .getChildren(set.id)\n .filter((child) => child.type === 'COMPONENT')\n .sort(compareCanvasPosition)[0]\n}\n\n/**\n * The value a variant property starts at: its recorded default when that is one of its options,\n * or else the default variant's, since a document may leave the recorded default empty.\n */\nexport function variantDefaultValue(\n graph: SceneGraph,\n set: SceneNode,\n property: { name: string; defaultValue: string; variantOptions?: string[] }\n): string {\n if (property.variantOptions?.includes(property.defaultValue)) return property.defaultValue\n return defaultVariant(graph, set)?.componentPropertyValues[property.name] ?? property.defaultValue\n}\n\n/**\n * The variant with every property at its default value: the recorded defaults when they name a\n * variant, else the default variant, as a document that leaves them out draws it.\n */\nexport function restingVariant(graph: SceneGraph, set: SceneNode): SceneNode | undefined {\n const properties = set.componentPropertyDefinitions.filter(\n (definition) => definition.type === 'VARIANT'\n )\n const values = properties.map(\n (property) => [property.name, variantDefaultValue(graph, set, property)] as const\n )\n return (\n graph\n .getChildren(set.id)\n .find(\n (child) =>\n child.type === 'COMPONENT' &&\n values.every(([name, value]) => child.componentPropertyValues[name] === value)\n ) ?? defaultVariant(graph, set)\n )\n}\n\n/** The component set a variant belongs to, or the set of the variant an instance shows. */\nfunction variantSetOf(graph: SceneGraph, node: SceneNode): SceneNode | undefined {\n const variant = node.type === 'INSTANCE' ? instanceMainComponent(graph, node) : node\n if (variant?.type !== 'COMPONENT' || !variant.parentId) return undefined\n const set = graph.getNode(variant.parentId)\n return set?.type === 'COMPONENT_SET' ? set : undefined\n}\n\n/**\n * The component sets whose variants a prototype's Change to on this layer may show, nearest\n * first: the set of each variant, and of each instance of a variant, from the layer up.\n */\nexport function variantSetsAround(graph: SceneGraph, nodeId: string): SceneNode[] {\n const sets: SceneNode[] = []\n graph.closest(nodeId, (node) => {\n const set = variantSetOf(graph, node)\n if (set && !sets.includes(set)) sets.push(set)\n return false\n })\n return sets\n}\n\n/**\n * The instance a Change to from this layer switches to another variant of `setId`: the layer\n * itself or its nearest instance ancestor that shows a variant of that set. A main component has\n * none, since it is the definition rather than a copy that changes.\n */\nexport function variantInstanceFor(\n graph: SceneGraph,\n nodeId: string,\n setId: string\n): SceneNode | undefined {\n return graph.closest(\n nodeId,\n (node) => node.type === 'INSTANCE' && variantSetOf(graph, node)?.id === setId\n )\n}\n"],"mappings":";;;AAKA,SAAgB,sBAAsB,GAAc,GAAsB;CACxE,OAAO,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,cAAc,EAAE,IAAI;AAC9D;;;;;AAMA,SAAgB,eAAe,OAAmB,KAAuC;CACvF,OAAO,MACJ,YAAY,IAAI,EAAE,CAAC,CACnB,QAAQ,UAAU,MAAM,SAAS,WAAW,CAAC,CAC7C,KAAK,qBAAqB,CAAC,CAAC;AACjC;;;;;AAMA,SAAgB,oBACd,OACA,KACA,UACQ;CACR,IAAI,SAAS,gBAAgB,SAAS,SAAS,YAAY,GAAG,OAAO,SAAS;CAC9E,OAAO,eAAe,OAAO,GAAG,CAAC,EAAE,wBAAwB,SAAS,SAAS,SAAS;AACxF;;;;;AAMA,SAAgB,eAAe,OAAmB,KAAuC;CAIvF,MAAM,SAHa,IAAI,6BAA6B,QACjD,eAAe,WAAW,SAAS,SAEd,CAAC,CAAC,KACvB,aAAa,CAAC,SAAS,MAAM,oBAAoB,OAAO,KAAK,QAAQ,CAAC,CACzE;CACA,OACE,MACG,YAAY,IAAI,EAAE,CAAC,CACnB,MACE,UACC,MAAM,SAAS,eACf,OAAO,OAAO,CAAC,MAAM,WAAW,MAAM,wBAAwB,UAAU,KAAK,CACjF,KAAK,eAAe,OAAO,GAAG;AAEpC;;AAGA,SAAS,aAAa,OAAmB,MAAwC;CAC/E,MAAM,UAAU,KAAK,SAAS,aAAa,sBAAsB,OAAO,IAAI,IAAI;CAChF,IAAI,SAAS,SAAS,eAAe,CAAC,QAAQ,UAAU,OAAO,KAAA;CAC/D,MAAM,MAAM,MAAM,QAAQ,QAAQ,QAAQ;CAC1C,OAAO,KAAK,SAAS,kBAAkB,MAAM,KAAA;AAC/C;;;;;AAMA,SAAgB,kBAAkB,OAAmB,QAA6B;CAChF,MAAM,OAAoB,CAAC;CAC3B,MAAM,QAAQ,SAAS,SAAS;EAC9B,MAAM,MAAM,aAAa,OAAO,IAAI;EACpC,IAAI,OAAO,CAAC,KAAK,SAAS,GAAG,GAAG,KAAK,KAAK,GAAG;EAC7C,OAAO;CACT,CAAC;CACD,OAAO;AACT;;;;;;AAOA,SAAgB,mBACd,OACA,QACA,OACuB;CACvB,OAAO,MAAM,QACX,SACC,SAAS,KAAK,SAAS,cAAc,aAAa,OAAO,IAAI,CAAC,EAAE,OAAO,KAC1E;AACF"}
@@ -1,4 +1,5 @@
1
1
  import { Color } from "./primitives/index.js";
2
+ import { NoiseEffectParams, PrototypeEasingType, TextureEffectParams } from "./types.js";
2
3
  //#region src/constants.d.ts
3
4
  declare const BLACK: Color;
4
5
  declare const WHITE: Color;
@@ -11,6 +12,29 @@ declare const DEFAULT_STROKE_WEIGHT = 1;
11
12
  * instances of but never edits: a component library's definitions, and a `.pen` library's.
12
13
  */
13
14
  declare const LIBRARY_DEFINITIONS_PAGE_NAME = "Pairdraw library definitions";
15
+ /** The grain of a noise effect whose values are missing: none of the layer covered. */
16
+ declare const UNSET_NOISE: Readonly<NoiseEffectParams>;
17
+ /** A new noise effect's grain, as Figma's effects panel starts one: black at 25%, fully dense. */
18
+ declare const DEFAULT_NOISE: Readonly<NoiseEffectParams>;
19
+ /** The colour a new noise effect's grains start in. */
20
+ declare const DEFAULT_NOISE_COLOR: Readonly<Color>;
21
+ /** A new texture effect's grain, as Figma's effects panel starts one, with a radius of 4. */
22
+ declare const DEFAULT_TEXTURE: Readonly<TextureEffectParams>;
23
+ /** The grain of a texture effect whose values are missing; its radius of 0 moves nothing. */
24
+ declare const UNSET_TEXTURE: Readonly<TextureEffectParams>;
25
+ /** The ways a frame's content may scroll in play, as Figma's `overflowDirection` names them. */
26
+ declare const OVERFLOW_DIRECTIONS: readonly ["NONE", "HORIZONTAL", "VERTICAL", "BOTH"];
27
+ /** How a layer moves while its parent frame scrolls in play, in Figma's names. */
28
+ declare const SCROLL_BEHAVIORS: readonly ["SCROLLS", "FIXED", "STICKY_SCROLLS"];
29
+ /** The easings a prototype transition takes, Figma's presets, in the order its menu lists them. */
30
+ declare const PROTOTYPE_EASINGS: readonly ["EASE_OUT", "EASE_IN", "EASE_IN_AND_OUT", "LINEAR"];
31
+ /** The easing a transition without one plays with, Figma's default. */
32
+ declare const DEFAULT_PROTOTYPE_EASING: PrototypeEasingType;
33
+ /**
34
+ * Each easing as the control points of its cubic Bézier, `[x1, y1, x2, y2]`: what a `.fig` file
35
+ * stores as an action's `easingFunction` and CSS reads as `cubic-bezier()`.
36
+ */
37
+ declare const PROTOTYPE_EASING_CURVES: Readonly<Record<PrototypeEasingType, readonly [number, number, number, number]>>;
14
38
  //#endregion
15
- export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, LIBRARY_DEFINITIONS_PAGE_NAME, TRANSPARENT, WHITE };
39
+ export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_NOISE, DEFAULT_NOISE_COLOR, DEFAULT_PROTOTYPE_EASING, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, DEFAULT_TEXTURE, LIBRARY_DEFINITIONS_PAGE_NAME, OVERFLOW_DIRECTIONS, PROTOTYPE_EASINGS, PROTOTYPE_EASING_CURVES, SCROLL_BEHAVIORS, TRANSPARENT, UNSET_NOISE, UNSET_TEXTURE, WHITE };
16
40
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;cAEa,OAAO;cACP,OAAO;cACP,aAAa;cACb;cACA;cACA;;;;;cAKA"}
1
+ {"version":3,"file":"constants.d.ts","names":[],"sources":["../src/constants.ts"],"mappings":";;;cASa,OAAO;cACP,OAAO;cACP,aAAa;cACb;cACA;cACA;;;;;cAKA;;cAGA,aAAa,SAAS;;cAOtB,eAAe,SAAS;;cAOxB,qBAAqB,SAAS;;cAG9B,iBAAiB,SAAS;;cAM1B,eAAe,SAAS;;cAMxB;;cAQA;;cAOA;;cAQA,0BAA0B;;;;;cAM1B,yBAAyB,SACpC,OAAO"}
package/dist/constants.js CHANGED
@@ -25,7 +25,100 @@ const DEFAULT_STROKE_WEIGHT = 1;
25
25
  * instances of but never edits: a component library's definitions, and a `.pen` library's.
26
26
  */
27
27
  const LIBRARY_DEFINITIONS_PAGE_NAME = "Pairdraw library definitions";
28
+ /** The grain of a noise effect whose values are missing: none of the layer covered. */
29
+ const UNSET_NOISE = {
30
+ noiseType: "MONOTONE",
31
+ noiseSize: {
32
+ x: 1,
33
+ y: 1
34
+ },
35
+ density: 0
36
+ };
37
+ /** A new noise effect's grain, as Figma's effects panel starts one: black at 25%, fully dense. */
38
+ const DEFAULT_NOISE = {
39
+ noiseType: "MONOTONE",
40
+ noiseSize: {
41
+ x: .5,
42
+ y: .5
43
+ },
44
+ density: 1
45
+ };
46
+ /** The colour a new noise effect's grains start in. */
47
+ const DEFAULT_NOISE_COLOR = {
48
+ r: 0,
49
+ g: 0,
50
+ b: 0,
51
+ a: .25
52
+ };
53
+ /** A new texture effect's grain, as Figma's effects panel starts one, with a radius of 4. */
54
+ const DEFAULT_TEXTURE = {
55
+ noiseSize: {
56
+ x: 4,
57
+ y: 4
58
+ },
59
+ clipToShape: false
60
+ };
61
+ /** The grain of a texture effect whose values are missing; its radius of 0 moves nothing. */
62
+ const UNSET_TEXTURE = {
63
+ noiseSize: {
64
+ x: 1,
65
+ y: 1
66
+ },
67
+ clipToShape: true
68
+ };
69
+ /** The ways a frame's content may scroll in play, as Figma's `overflowDirection` names them. */
70
+ const OVERFLOW_DIRECTIONS = [
71
+ "NONE",
72
+ "HORIZONTAL",
73
+ "VERTICAL",
74
+ "BOTH"
75
+ ];
76
+ /** How a layer moves while its parent frame scrolls in play, in Figma's names. */
77
+ const SCROLL_BEHAVIORS = [
78
+ "SCROLLS",
79
+ "FIXED",
80
+ "STICKY_SCROLLS"
81
+ ];
82
+ /** The easings a prototype transition takes, Figma's presets, in the order its menu lists them. */
83
+ const PROTOTYPE_EASINGS = [
84
+ "EASE_OUT",
85
+ "EASE_IN",
86
+ "EASE_IN_AND_OUT",
87
+ "LINEAR"
88
+ ];
89
+ /** The easing a transition without one plays with, Figma's default. */
90
+ const DEFAULT_PROTOTYPE_EASING = "EASE_OUT";
91
+ /**
92
+ * Each easing as the control points of its cubic Bézier, `[x1, y1, x2, y2]`: what a `.fig` file
93
+ * stores as an action's `easingFunction` and CSS reads as `cubic-bezier()`.
94
+ */
95
+ const PROTOTYPE_EASING_CURVES = {
96
+ LINEAR: [
97
+ 0,
98
+ 0,
99
+ 1,
100
+ 1
101
+ ],
102
+ EASE_IN: [
103
+ .42,
104
+ 0,
105
+ 1,
106
+ 1
107
+ ],
108
+ EASE_OUT: [
109
+ 0,
110
+ 0,
111
+ .58,
112
+ 1
113
+ ],
114
+ EASE_IN_AND_OUT: [
115
+ .42,
116
+ 0,
117
+ .58,
118
+ 1
119
+ ]
120
+ };
28
121
  //#endregion
29
- export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, LIBRARY_DEFINITIONS_PAGE_NAME, TRANSPARENT, WHITE };
122
+ export { BLACK, DEFAULT_FONT_FAMILY, DEFAULT_NOISE, DEFAULT_NOISE_COLOR, DEFAULT_PROTOTYPE_EASING, DEFAULT_STROKE_MITER_LIMIT, DEFAULT_STROKE_WEIGHT, DEFAULT_TEXTURE, LIBRARY_DEFINITIONS_PAGE_NAME, OVERFLOW_DIRECTIONS, PROTOTYPE_EASINGS, PROTOTYPE_EASING_CURVES, SCROLL_BEHAVIORS, TRANSPARENT, UNSET_NOISE, UNSET_TEXTURE, WHITE };
30
123
 
31
124
  //# sourceMappingURL=constants.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { Color } from './primitives'\n\nexport const BLACK: Color = { r: 0, g: 0, b: 0, a: 1 }\nexport const WHITE: Color = { r: 1, g: 1, b: 1, a: 1 }\nexport const TRANSPARENT: Color = { r: 0, g: 0, b: 0, a: 0 }\nexport const DEFAULT_FONT_FAMILY = 'Inter'\nexport const DEFAULT_STROKE_MITER_LIMIT = 4\nexport const DEFAULT_STROKE_WEIGHT = 1\n/**\n * The hidden page a document keeps the components of libraries it uses on, which it shows\n * instances of but never edits: a component library's definitions, and a `.pen` library's.\n */\nexport const LIBRARY_DEFINITIONS_PAGE_NAME = 'Pairdraw library definitions'\n"],"mappings":";AAEA,MAAa,QAAe;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AACrD,MAAa,QAAe;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AACrD,MAAa,cAAqB;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AAC3D,MAAa,sBAAsB;AACnC,MAAa,6BAA6B;AAC1C,MAAa,wBAAwB;;;;;AAKrC,MAAa,gCAAgC"}
1
+ {"version":3,"file":"constants.js","names":[],"sources":["../src/constants.ts"],"sourcesContent":["import type { Color } from './primitives'\nimport type {\n NoiseEffectParams,\n OverflowDirection,\n PrototypeEasingType,\n ScrollBehavior,\n TextureEffectParams\n} from './types'\n\nexport const BLACK: Color = { r: 0, g: 0, b: 0, a: 1 }\nexport const WHITE: Color = { r: 1, g: 1, b: 1, a: 1 }\nexport const TRANSPARENT: Color = { r: 0, g: 0, b: 0, a: 0 }\nexport const DEFAULT_FONT_FAMILY = 'Inter'\nexport const DEFAULT_STROKE_MITER_LIMIT = 4\nexport const DEFAULT_STROKE_WEIGHT = 1\n/**\n * The hidden page a document keeps the components of libraries it uses on, which it shows\n * instances of but never edits: a component library's definitions, and a `.pen` library's.\n */\nexport const LIBRARY_DEFINITIONS_PAGE_NAME = 'Pairdraw library definitions'\n\n/** The grain of a noise effect whose values are missing: none of the layer covered. */\nexport const UNSET_NOISE: Readonly<NoiseEffectParams> = {\n noiseType: 'MONOTONE',\n noiseSize: { x: 1, y: 1 },\n density: 0\n}\n\n/** A new noise effect's grain, as Figma's effects panel starts one: black at 25%, fully dense. */\nexport const DEFAULT_NOISE: Readonly<NoiseEffectParams> = {\n noiseType: 'MONOTONE',\n noiseSize: { x: 0.5, y: 0.5 },\n density: 1\n}\n\n/** The colour a new noise effect's grains start in. */\nexport const DEFAULT_NOISE_COLOR: Readonly<Color> = { r: 0, g: 0, b: 0, a: 0.25 }\n\n/** A new texture effect's grain, as Figma's effects panel starts one, with a radius of 4. */\nexport const DEFAULT_TEXTURE: Readonly<TextureEffectParams> = {\n noiseSize: { x: 4, y: 4 },\n clipToShape: false\n}\n\n/** The grain of a texture effect whose values are missing; its radius of 0 moves nothing. */\nexport const UNSET_TEXTURE: Readonly<TextureEffectParams> = {\n noiseSize: { x: 1, y: 1 },\n clipToShape: true\n}\n\n/** The ways a frame's content may scroll in play, as Figma's `overflowDirection` names them. */\nexport const OVERFLOW_DIRECTIONS = [\n 'NONE',\n 'HORIZONTAL',\n 'VERTICAL',\n 'BOTH'\n] as const satisfies readonly OverflowDirection[]\n\n/** How a layer moves while its parent frame scrolls in play, in Figma's names. */\nexport const SCROLL_BEHAVIORS = [\n 'SCROLLS',\n 'FIXED',\n 'STICKY_SCROLLS'\n] as const satisfies readonly ScrollBehavior[]\n\n/** The easings a prototype transition takes, Figma's presets, in the order its menu lists them. */\nexport const PROTOTYPE_EASINGS = [\n 'EASE_OUT',\n 'EASE_IN',\n 'EASE_IN_AND_OUT',\n 'LINEAR'\n] as const satisfies readonly PrototypeEasingType[]\n\n/** The easing a transition without one plays with, Figma's default. */\nexport const DEFAULT_PROTOTYPE_EASING: PrototypeEasingType = 'EASE_OUT'\n\n/**\n * Each easing as the control points of its cubic Bézier, `[x1, y1, x2, y2]`: what a `.fig` file\n * stores as an action's `easingFunction` and CSS reads as `cubic-bezier()`.\n */\nexport const PROTOTYPE_EASING_CURVES: Readonly<\n Record<PrototypeEasingType, readonly [number, number, number, number]>\n> = {\n LINEAR: [0, 0, 1, 1],\n EASE_IN: [0.42, 0, 1, 1],\n EASE_OUT: [0, 0, 0.58, 1],\n EASE_IN_AND_OUT: [0.42, 0, 0.58, 1]\n}\n"],"mappings":";AASA,MAAa,QAAe;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AACrD,MAAa,QAAe;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AACrD,MAAa,cAAqB;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAE;AAC3D,MAAa,sBAAsB;AACnC,MAAa,6BAA6B;AAC1C,MAAa,wBAAwB;;;;;AAKrC,MAAa,gCAAgC;;AAG7C,MAAa,cAA2C;CACtD,WAAW;CACX,WAAW;EAAE,GAAG;EAAG,GAAG;CAAE;CACxB,SAAS;AACX;;AAGA,MAAa,gBAA6C;CACxD,WAAW;CACX,WAAW;EAAE,GAAG;EAAK,GAAG;CAAI;CAC5B,SAAS;AACX;;AAGA,MAAa,sBAAuC;CAAE,GAAG;CAAG,GAAG;CAAG,GAAG;CAAG,GAAG;AAAK;;AAGhF,MAAa,kBAAiD;CAC5D,WAAW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"file":"copy.d.ts","names":[],"sources":["../src/copy.ts"],"mappings":";;;iBAiCgB,SAAS,UAAU,MAAM,GAAG,IAAI;iBAgBhC,WAAW,GAAG,SAAS;iBAQvB,WAAW,GAAG,SAAS;iBA8BvB,aAAa,GAAG,WAAW;;iBA6B3B,eAAe,kBAAkB,QAAQ,GAAG,MAAM,IAAI;;iBAMtD,kBAAkB,cAAc;iBAKhC,UAAU,OAAO,SAAS;iBAI1B,YAAY,SAAS,WAAW;iBAIhC,YAAY,SAAS,WAAW;iBAIhC,gBAAgB,OAAO,eAAe;iBAItC,cAAc,MAAM,aAAa;iBAajC,kBAAkB,OAAO,iBAAiB;;;;;;;iBAU1C,sBACd,MAAM,YACN,aACA,aACA,aACA,aACA,aACA,cACC;iBAoBa,uBACd,OAAO,gBACP,aACA,aACA,aACA,aACA,aACA,cACC;;;;;iBAUa,mBAAmB,OAAO,gBAAgB,YAAY,aAAa;;iBAmCnE,kBAAkB,QAAQ,4BAA4B;iBAatD,sBAAsB,UAAU,oBAAoB;;;;;;;;KAiBxD;iBAUI,eACd,KAAK,WACL,4BACA,OAAM,gBACL,QAAQ"}
package/dist/copy.js CHANGED
@@ -36,9 +36,25 @@ function copyStroke(s) {
36
36
  return copy;
37
37
  }
38
38
  function copyEffect(e) {
39
- if (e.type === "SHADER") return structuredClone(e);
40
39
  const normalized = normalizeEffects([e])[0] ?? e;
41
40
  if (normalized.type === "SHADER") return structuredClone(normalized);
41
+ if (normalized.type === "NOISE") return {
42
+ ...normalized,
43
+ color: { ...normalized.color },
44
+ noise: {
45
+ ...normalized.noise,
46
+ noiseSize: { ...normalized.noise.noiseSize },
47
+ secondaryColor: normalized.noise.secondaryColor ? { ...normalized.noise.secondaryColor } : void 0
48
+ }
49
+ };
50
+ if (normalized.type === "TEXTURE") return {
51
+ ...normalized,
52
+ color: { ...normalized.color },
53
+ texture: {
54
+ ...normalized.texture,
55
+ noiseSize: { ...normalized.texture.noiseSize }
56
+ }
57
+ };
42
58
  return {
43
59
  ...normalized,
44
60
  color: { ...normalized.color },