@moondraft/import 0.0.0-stage → 0.1.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 (323) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +169 -0
  5. package/dist/adapter/convert.d.ts +122 -0
  6. package/dist/adapter/convert.js +2302 -0
  7. package/dist/adapter/figma.d.ts +9 -0
  8. package/dist/adapter/figma.js +30 -0
  9. package/dist/adapter/file-components.d.ts +14 -0
  10. package/dist/adapter/file-components.js +262 -0
  11. package/dist/adapter/file-resources.d.ts +29 -0
  12. package/dist/adapter/file-resources.js +562 -0
  13. package/dist/adapter/index.d.ts +6 -0
  14. package/dist/adapter/index.js +9 -0
  15. package/dist/adapter/link.d.ts +45 -0
  16. package/dist/adapter/link.js +688 -0
  17. package/dist/adapter/payload.d.ts +31 -0
  18. package/dist/adapter/payload.js +78 -0
  19. package/dist/adapter/shapes.d.ts +31 -0
  20. package/dist/adapter/shapes.js +75 -0
  21. package/dist/adapter/variables.d.ts +44 -0
  22. package/dist/adapter/variables.js +103 -0
  23. package/dist/figma-file.d.ts +38 -0
  24. package/dist/figma-file.js +97 -0
  25. package/dist/figma-worker.d.ts +11 -0
  26. package/dist/figma-worker.js +12 -0
  27. package/dist/figma.d.ts +26 -0
  28. package/dist/figma.js +96 -0
  29. package/dist/index.d.ts +28 -0
  30. package/dist/index.js +49 -0
  31. package/dist/report.d.ts +15 -0
  32. package/dist/report.js +69 -0
  33. package/dist/svg.d.ts +33 -0
  34. package/dist/svg.js +44 -0
  35. package/dist/syntax.d.ts +8 -0
  36. package/dist/syntax.js +19 -0
  37. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  38. package/dist/taco/figma-import/clipboard.js +87 -0
  39. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  40. package/dist/taco/figma-import/clipboardSize.js +107 -0
  41. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  42. package/dist/taco/figma-import/container/compression.js +174 -0
  43. package/dist/taco/figma-import/container/error.d.ts +15 -0
  44. package/dist/taco/figma-import/container/error.js +19 -0
  45. package/dist/taco/figma-import/container/kiwiContainer.d.ts +38 -0
  46. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  47. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  48. package/dist/taco/figma-import/container/limits.js +22 -0
  49. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  50. package/dist/taco/figma-import/container/zip.js +154 -0
  51. package/dist/taco/figma-import/figFile.d.ts +34 -0
  52. package/dist/taco/figma-import/figFile.js +91 -0
  53. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  54. package/dist/taco/figma-import/figFileDocument.js +100 -0
  55. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  56. package/dist/taco/figma-import/import/blobs.js +23 -0
  57. package/dist/taco/figma-import/import/carry.d.ts +11 -0
  58. package/dist/taco/figma-import/import/carry.js +33 -0
  59. package/dist/taco/figma-import/import/componentProps.d.ts +84 -0
  60. package/dist/taco/figma-import/import/componentProps.js +313 -0
  61. package/dist/taco/figma-import/import/componentSets.d.ts +83 -0
  62. package/dist/taco/figma-import/import/componentSets.js +647 -0
  63. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  64. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  65. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  66. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  67. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  68. package/dist/taco/figma-import/import/converters/frame.js +55 -0
  69. package/dist/taco/figma-import/import/converters/gradient.d.ts +72 -0
  70. package/dist/taco/figma-import/import/converters/gradient.js +106 -0
  71. package/dist/taco/figma-import/import/converters/group.d.ts +21 -0
  72. package/dist/taco/figma-import/import/converters/group.js +39 -0
  73. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  74. package/dist/taco/figma-import/import/converters/image.js +83 -0
  75. package/dist/taco/figma-import/import/converters/layout.d.ts +34 -0
  76. package/dist/taco/figma-import/import/converters/layout.js +168 -0
  77. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  78. package/dist/taco/figma-import/import/converters/line.js +40 -0
  79. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  80. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  81. package/dist/taco/figma-import/import/converters/section.d.ts +9 -0
  82. package/dist/taco/figma-import/import/converters/section.js +35 -0
  83. package/dist/taco/figma-import/import/converters/shared.d.ts +68 -0
  84. package/dist/taco/figma-import/import/converters/shared.js +362 -0
  85. package/dist/taco/figma-import/import/converters/text.d.ts +41 -0
  86. package/dist/taco/figma-import/import/converters/text.js +576 -0
  87. package/dist/taco/figma-import/import/converters/vector.d.ts +84 -0
  88. package/dist/taco/figma-import/import/converters/vector.js +468 -0
  89. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +98 -0
  90. package/dist/taco/figma-import/import/converters/vectorNetwork.js +385 -0
  91. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  92. package/dist/taco/figma-import/import/fields.js +29 -0
  93. package/dist/taco/figma-import/import/instances.d.ts +163 -0
  94. package/dist/taco/figma-import/import/instances.js +1323 -0
  95. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  96. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  97. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  98. package/dist/taco/figma-import/import/slots.js +96 -0
  99. package/dist/taco/figma-import/import/styles.d.ts +46 -0
  100. package/dist/taco/figma-import/import/styles.js +42 -0
  101. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  102. package/dist/taco/figma-import/import/tree.js +194 -0
  103. package/dist/taco/figma-import/import/types.d.ts +232 -0
  104. package/dist/taco/figma-import/import/types.js +33 -0
  105. package/dist/taco/figma-import/import/variables.d.ts +136 -0
  106. package/dist/taco/figma-import/import/variables.js +762 -0
  107. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  108. package/dist/taco/figma-import/import/variantTrees.js +480 -0
  109. package/dist/taco/figma-import/import/walk.d.ts +159 -0
  110. package/dist/taco/figma-import/import/walk.js +1297 -0
  111. package/dist/taco/figma-import/index.d.ts +22 -0
  112. package/dist/taco/figma-import/index.js +13 -0
  113. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  114. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  115. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  116. package/dist/taco/figma-import/kiwi/error.js +29 -0
  117. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  118. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  119. package/dist/taco/figma-import/kiwi/message.d.ts +10 -0
  120. package/dist/taco/figma-import/kiwi/message.js +145 -0
  121. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  122. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  123. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  124. package/dist/taco/figma-import/kiwi/types.js +18 -0
  125. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  126. package/dist/taco/model/agent-hidden-fields.js +29 -0
  127. package/dist/taco/model/asset-users.d.ts +23 -0
  128. package/dist/taco/model/asset-users.js +128 -0
  129. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  130. package/dist/taco/model/auto-layout-lines.js +70 -0
  131. package/dist/taco/model/codec.d.ts +444 -0
  132. package/dist/taco/model/codec.js +5635 -0
  133. package/dist/taco/model/color.d.ts +11 -0
  134. package/dist/taco/model/color.js +61 -0
  135. package/dist/taco/model/comment-operations.d.ts +102 -0
  136. package/dist/taco/model/comment-operations.js +227 -0
  137. package/dist/taco/model/component-evaluation.d.ts +94 -0
  138. package/dist/taco/model/component-evaluation.js +548 -0
  139. package/dist/taco/model/component-expressions.d.ts +242 -0
  140. package/dist/taco/model/component-expressions.js +1082 -0
  141. package/dist/taco/model/component-properties.d.ts +111 -0
  142. package/dist/taco/model/component-properties.js +339 -0
  143. package/dist/taco/model/component-samples.d.ts +83 -0
  144. package/dist/taco/model/component-samples.js +290 -0
  145. package/dist/taco/model/component-validity.d.ts +85 -0
  146. package/dist/taco/model/component-validity.js +397 -0
  147. package/dist/taco/model/components.d.ts +155 -0
  148. package/dist/taco/model/components.js +505 -0
  149. package/dist/taco/model/connector-ends.d.ts +20 -0
  150. package/dist/taco/model/connector-ends.js +188 -0
  151. package/dist/taco/model/connector-geometry.d.ts +74 -0
  152. package/dist/taco/model/connector-geometry.js +293 -0
  153. package/dist/taco/model/corner-radii.d.ts +26 -0
  154. package/dist/taco/model/corner-radii.js +47 -0
  155. package/dist/taco/model/derivations.d.ts +81 -0
  156. package/dist/taco/model/derivations.js +151 -0
  157. package/dist/taco/model/export-settings.d.ts +53 -0
  158. package/dist/taco/model/export-settings.js +156 -0
  159. package/dist/taco/model/expressions/ast.d.ts +153 -0
  160. package/dist/taco/model/expressions/ast.js +6 -0
  161. package/dist/taco/model/expressions/cache.d.ts +23 -0
  162. package/dist/taco/model/expressions/cache.js +43 -0
  163. package/dist/taco/model/expressions/check.d.ts +72 -0
  164. package/dist/taco/model/expressions/check.js +517 -0
  165. package/dist/taco/model/expressions/completion.d.ts +61 -0
  166. package/dist/taco/model/expressions/completion.js +421 -0
  167. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  168. package/dist/taco/model/expressions/evaluate.js +519 -0
  169. package/dist/taco/model/expressions/forms.d.ts +84 -0
  170. package/dist/taco/model/expressions/forms.js +200 -0
  171. package/dist/taco/model/expressions/index.d.ts +14 -0
  172. package/dist/taco/model/expressions/index.js +17 -0
  173. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  174. package/dist/taco/model/expressions/lexer.js +213 -0
  175. package/dist/taco/model/expressions/library.d.ts +33 -0
  176. package/dist/taco/model/expressions/library.js +117 -0
  177. package/dist/taco/model/expressions/names.d.ts +43 -0
  178. package/dist/taco/model/expressions/names.js +99 -0
  179. package/dist/taco/model/expressions/parser.d.ts +15 -0
  180. package/dist/taco/model/expressions/parser.js +438 -0
  181. package/dist/taco/model/expressions/rename.d.ts +34 -0
  182. package/dist/taco/model/expressions/rename.js +46 -0
  183. package/dist/taco/model/expressions/source.d.ts +15 -0
  184. package/dist/taco/model/expressions/source.js +161 -0
  185. package/dist/taco/model/expressions/types.d.ts +119 -0
  186. package/dist/taco/model/expressions/types.js +102 -0
  187. package/dist/taco/model/expressions/values.d.ts +97 -0
  188. package/dist/taco/model/expressions/values.js +160 -0
  189. package/dist/taco/model/geometry-limits.d.ts +16 -0
  190. package/dist/taco/model/geometry-limits.js +67 -0
  191. package/dist/taco/model/geometry.d.ts +47 -0
  192. package/dist/taco/model/geometry.js +193 -0
  193. package/dist/taco/model/group-bounds.d.ts +38 -0
  194. package/dist/taco/model/group-bounds.js +144 -0
  195. package/dist/taco/model/id-table.d.ts +37 -0
  196. package/dist/taco/model/id-table.js +80 -0
  197. package/dist/taco/model/index.d.ts +25 -0
  198. package/dist/taco/model/index.js +27 -0
  199. package/dist/taco/model/instance-resolver.d.ts +372 -0
  200. package/dist/taco/model/instance-resolver.js +1748 -0
  201. package/dist/taco/model/layer-syntax.d.ts +340 -0
  202. package/dist/taco/model/layer-syntax.js +3506 -0
  203. package/dist/taco/model/layout/constraints.d.ts +84 -0
  204. package/dist/taco/model/layout/constraints.js +445 -0
  205. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  206. package/dist/taco/model/layout/frame-layout.js +618 -0
  207. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  208. package/dist/taco/model/layout/node-sizing.js +486 -0
  209. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  210. package/dist/taco/model/legacy-connector-caps.js +70 -0
  211. package/dist/taco/model/linear-call.d.ts +48 -0
  212. package/dist/taco/model/linear-call.js +58 -0
  213. package/dist/taco/model/new-nodes.d.ts +145 -0
  214. package/dist/taco/model/new-nodes.js +277 -0
  215. package/dist/taco/model/node-builder.d.ts +449 -0
  216. package/dist/taco/model/node-builder.js +2294 -0
  217. package/dist/taco/model/node-table-watch.d.ts +36 -0
  218. package/dist/taco/model/node-table-watch.js +63 -0
  219. package/dist/taco/model/node-transform.d.ts +39 -0
  220. package/dist/taco/model/node-transform.js +79 -0
  221. package/dist/taco/model/node-users-index.d.ts +10 -0
  222. package/dist/taco/model/node-users-index.js +82 -0
  223. package/dist/taco/model/operation-references.d.ts +80 -0
  224. package/dist/taco/model/operation-references.js +399 -0
  225. package/dist/taco/model/operations.d.ts +610 -0
  226. package/dist/taco/model/operations.js +2882 -0
  227. package/dist/taco/model/overlay-table.d.ts +71 -0
  228. package/dist/taco/model/overlay-table.js +171 -0
  229. package/dist/taco/model/override-remap.d.ts +69 -0
  230. package/dist/taco/model/override-remap.js +230 -0
  231. package/dist/taco/model/parent-table.d.ts +53 -0
  232. package/dist/taco/model/parent-table.js +193 -0
  233. package/dist/taco/model/problem-collector.d.ts +27 -0
  234. package/dist/taco/model/problem-collector.js +101 -0
  235. package/dist/taco/model/sha256.d.ts +10 -0
  236. package/dist/taco/model/sha256.js +74 -0
  237. package/dist/taco/model/shape-geometry.d.ts +96 -0
  238. package/dist/taco/model/shape-geometry.js +368 -0
  239. package/dist/taco/model/shared-node-table.d.ts +97 -0
  240. package/dist/taco/model/shared-node-table.js +546 -0
  241. package/dist/taco/model/slots.d.ts +113 -0
  242. package/dist/taco/model/slots.js +281 -0
  243. package/dist/taco/model/stroke-settings.d.ts +37 -0
  244. package/dist/taco/model/stroke-settings.js +90 -0
  245. package/dist/taco/model/svg-path-import.d.ts +89 -0
  246. package/dist/taco/model/svg-path-import.js +219 -0
  247. package/dist/taco/model/text-measurement.d.ts +142 -0
  248. package/dist/taco/model/text-measurement.js +846 -0
  249. package/dist/taco/model/text-reads.d.ts +66 -0
  250. package/dist/taco/model/text-reads.js +128 -0
  251. package/dist/taco/model/text-sizer.d.ts +358 -0
  252. package/dist/taco/model/text-sizer.js +996 -0
  253. package/dist/taco/model/theme-users.d.ts +59 -0
  254. package/dist/taco/model/theme-users.js +312 -0
  255. package/dist/taco/model/thumbnail.d.ts +15 -0
  256. package/dist/taco/model/thumbnail.js +34 -0
  257. package/dist/taco/model/types.d.ts +2347 -0
  258. package/dist/taco/model/types.js +366 -0
  259. package/dist/taco/model/unknown-property.d.ts +5 -0
  260. package/dist/taco/model/unknown-property.js +7 -0
  261. package/dist/taco/model/validated-documents.d.ts +22 -0
  262. package/dist/taco/model/validated-documents.js +22 -0
  263. package/dist/taco/model/variable-modes.d.ts +61 -0
  264. package/dist/taco/model/variable-modes.js +438 -0
  265. package/dist/taco/model/variable-references.d.ts +54 -0
  266. package/dist/taco/model/variable-references.js +183 -0
  267. package/dist/taco/model/variables.d.ts +24 -0
  268. package/dist/taco/model/variables.js +151 -0
  269. package/dist/taco/model/vector-network.d.ts +34 -0
  270. package/dist/taco/model/vector-network.js +411 -0
  271. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  272. package/dist/taco/svg-import/import-svg.js +729 -0
  273. package/dist/taco/svg-import/index.d.ts +3 -0
  274. package/dist/taco/svg-import/index.js +3 -0
  275. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  276. package/dist/taco/svg-import/limits/limits.js +160 -0
  277. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  278. package/dist/taco/svg-import/paint/gradients.js +429 -0
  279. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  280. package/dist/taco/svg-import/paint/paint.js +162 -0
  281. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  282. package/dist/taco/svg-import/paths/paths.js +205 -0
  283. package/dist/taco/svg-import/public-types.d.ts +279 -0
  284. package/dist/taco/svg-import/public-types.js +56 -0
  285. package/dist/taco/svg-import/report/report.d.ts +44 -0
  286. package/dist/taco/svg-import/report/report.js +79 -0
  287. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  288. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  289. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  290. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  291. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  292. package/dist/taco/svg-import/structure/effects.js +618 -0
  293. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  294. package/dist/taco/svg-import/structure/image.js +495 -0
  295. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  296. package/dist/taco/svg-import/structure/walk.js +544 -0
  297. package/dist/taco/svg-import/style/color.d.ts +40 -0
  298. package/dist/taco/svg-import/style/color.js +275 -0
  299. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  300. package/dist/taco/svg-import/style/computed.js +1534 -0
  301. package/dist/taco/svg-import/style/css.d.ts +127 -0
  302. package/dist/taco/svg-import/style/css.js +541 -0
  303. package/dist/taco/svg-import/style/media.d.ts +25 -0
  304. package/dist/taco/svg-import/style/media.js +307 -0
  305. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  306. package/dist/taco/svg-import/style/properties.js +135 -0
  307. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  308. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  309. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  310. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  311. package/dist/taco/svg-import/text/text.d.ts +29 -0
  312. package/dist/taco/svg-import/text/text.js +545 -0
  313. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  314. package/dist/taco/svg-import/transform/matrix.js +229 -0
  315. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  316. package/dist/taco/svg-import/tree/element-data.js +155 -0
  317. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  318. package/dist/taco/svg-import/tree/elements.js +121 -0
  319. package/dist/taco/svg-import/units/length.d.ts +43 -0
  320. package/dist/taco/svg-import/units/length.js +125 -0
  321. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  322. package/dist/taco/svg-import/units/viewbox.js +77 -0
  323. package/package.json +54 -4
@@ -0,0 +1,59 @@
1
+ import type { DesignDocument, DocumentTheme, NodeId, SceneNode } from "./types.ts";
2
+ /**
3
+ * Which nodes use each part of the theme, kept for each frozen document, so
4
+ * that a theme edit marks changed only the nodes that use what it changed
5
+ * instead of every node. A node uses:
6
+ *
7
+ * - `text:<id>`, `code:<id>`, `node:<id>`: a text, code or node style it
8
+ * names (in its paragraphs, its code style, its visual style or an
9
+ * instance override);
10
+ * - `text-default`, `code-default`: the default text or code style, for a
11
+ * run, text layer, text override or code layer that names none;
12
+ * - `var:<id>`: a variable it binds (or an instance override binds);
13
+ * - `mode:<collection id>`: a collection it chooses a mode of;
14
+ * - `var-name:<Collection/Name>`: a variable an expression or condition of
15
+ * it reads by name, `var("Collection/Name")`; which variable the name finds,
16
+ * and that variable's value and type, are what the layer reads;
17
+ * - `any`: every part, for a layer with an expression this module cannot
18
+ * read (one that does not parse).
19
+ *
20
+ * The variable names an expression reads are fixed by its source: `var(...)`
21
+ * takes a string literal, and nothing else an expression can write reads the
22
+ * theme (property names, `let` names, `stored` and the library's functions
23
+ * do not; `stored` reads the layer's own style, text styles and bindings,
24
+ * which the keys above name). No expression reads a collection's, mode's or
25
+ * style's name, the named colors or a mode by name, so a change of those
26
+ * alone marks only the layers that read a variable whose name changed.
27
+ *
28
+ * What a node uses depends on the node alone, so the index of a document made
29
+ * by an edit is the index of the document it was made from with the nodes the
30
+ * edit wrote read again, whatever the edit did to the theme.
31
+ *
32
+ * Internal to the model: not exported from the package index, except
33
+ * `nodesUsingThemeChange`.
34
+ */
35
+ type ThemeKey = string;
36
+ /** The parts of the theme `node` uses, sorted, or null when it uses none. */
37
+ export declare function themeKeysOfNode(node: SceneNode): readonly ThemeKey[] | null;
38
+ /**
39
+ * The parts of the theme that differ between `before` and `after` in a way a
40
+ * node that uses them can see, or "all" when the change is one this module
41
+ * cannot attribute (a theme field it does not know). A change of a style's or
42
+ * variable's name alone, or of the named colors, reaches only the layers
43
+ * whose expressions read a variable name that now finds another variable or
44
+ * none (`var-name:`), or that this module cannot read (`any`).
45
+ */
46
+ export declare function changedThemeKeys(before: DocumentTheme, after: DocumentTheme): ReadonlySet<ThemeKey> | "all";
47
+ /**
48
+ * The nodes of `document` that use a part of the theme that differs between
49
+ * `before` and `after` (`changedThemeKeys`): every node of `document` when
50
+ * the change cannot be attributed. A node that does not use any part that
51
+ * changed shows and checks the same with either theme.
52
+ */
53
+ export declare function nodesUsingThemeChange(document: DesignDocument, before: DocumentTheme, after: DocumentTheme): readonly NodeId[];
54
+ /**
55
+ * Keeps the index of `derived`, made by an edit of `base`, when `base` has
56
+ * one: so a run of edits keeps it, reading only the nodes each edit wrote.
57
+ */
58
+ export declare function keepThemeUsers(base: DesignDocument, derived: DesignDocument): void;
59
+ export {};
@@ -0,0 +1,312 @@
1
+ import { canonicalJson } from "./codec.js";
2
+ import { derivations, isFrozenNodeMap, MAX_DERIVATION_STEPS } from "./derivations.js";
3
+ import { variablesByExpressionName } from "./component-expressions.js";
4
+ import { parseExpression } from "./expressions/parser.js";
5
+ import { entryOf } from "./id-table.js";
6
+ import { NodeUsers, sameKeys } from "./node-users-index.js";
7
+ import { modelApplyStats } from "./operations.js";
8
+ import { tableKeys, tableValues } from "./shared-node-table.js";
9
+ /** Whether two parts of a theme hold the same JSON value; parts reused by an edit compare by identity. */
10
+ function same(left, right) {
11
+ return left === right || canonicalJson(left ?? null) === canonicalJson(right ?? null);
12
+ }
13
+ const ANY = "any";
14
+ const VARIABLE_NAME = "var-name:";
15
+ /** The variable names `expression` reads with `var(...)`: every node of the tree is visited, whatever its kind. */
16
+ function addVariableNames(value, names) {
17
+ if (Array.isArray(value)) {
18
+ for (const item of value)
19
+ addVariableNames(item, names);
20
+ return;
21
+ }
22
+ if (typeof value !== "object" || value === null)
23
+ return;
24
+ const node = value;
25
+ if (node.kind === "variable" && typeof node.name === "string")
26
+ names.add(node.name);
27
+ for (const [field, child] of Object.entries(node))
28
+ if (field !== "span" && typeof child === "object")
29
+ addVariableNames(child, names);
30
+ }
31
+ /** The keys of the variable names each expression source reads, or null for one that does not parse. */
32
+ const expressionKeysCache = new Map();
33
+ const EXPRESSION_CACHE_LIMIT = 50_000;
34
+ function expressionKeys(source) {
35
+ const cached = expressionKeysCache.get(source);
36
+ if (cached !== undefined || expressionKeysCache.has(source))
37
+ return cached ?? null;
38
+ const parsed = parseExpression(source);
39
+ let keys = null;
40
+ if (parsed.ok) {
41
+ const names = new Set();
42
+ addVariableNames(parsed.expression, names);
43
+ keys = [...names].map((name) => `${VARIABLE_NAME}${name}`);
44
+ }
45
+ if (expressionKeysCache.size >= EXPRESSION_CACHE_LIMIT)
46
+ expressionKeysCache.clear();
47
+ expressionKeysCache.set(source, keys);
48
+ return keys;
49
+ }
50
+ /** Adds the keys of the theme `source` reads, or `any` when it cannot be read. */
51
+ function addExpressionKeys(source, add) {
52
+ if (typeof source !== "string")
53
+ return;
54
+ const keys = expressionKeys(source);
55
+ if (keys === null)
56
+ add(ANY);
57
+ else
58
+ for (const key of keys)
59
+ add(key);
60
+ }
61
+ const TEXT_DEFAULT = "text-default";
62
+ const CODE_DEFAULT = "code-default";
63
+ function addParagraphKeys(paragraphs, add) {
64
+ if (paragraphs === undefined || paragraphs.length === 0) {
65
+ add(TEXT_DEFAULT);
66
+ return;
67
+ }
68
+ for (const paragraph of paragraphs) {
69
+ if (paragraph.runs.length === 0)
70
+ add(TEXT_DEFAULT);
71
+ for (const run of paragraph.runs)
72
+ add(run.styleId === undefined ? TEXT_DEFAULT : `text:${run.styleId}`);
73
+ const marker = paragraph.list?.marker;
74
+ if (marker?.styleId !== undefined)
75
+ add(`text:${marker.styleId}`);
76
+ }
77
+ }
78
+ function addBindingKeys(bindings, add) {
79
+ for (const id of Object.values(bindings ?? {}))
80
+ if (typeof id === "string")
81
+ add(`var:${id}`);
82
+ }
83
+ function addOverrideKeys(override, add) {
84
+ if (typeof override.styleId === "string")
85
+ add(`node:${override.styleId}`);
86
+ if (typeof override.textStyleId === "string")
87
+ add(`text:${override.textStyleId}`);
88
+ else if (override.textStyleId === null || override.textStyle !== undefined || override.characters !== undefined)
89
+ add(TEXT_DEFAULT);
90
+ if (override.paragraphs !== undefined)
91
+ addParagraphKeys(override.paragraphs, add);
92
+ addBindingKeys(override.variableBindings, add);
93
+ }
94
+ /** The parts of the theme `node` uses, sorted, or null when it uses none. */
95
+ export function themeKeysOfNode(node) {
96
+ const keys = new Set();
97
+ const add = (key) => {
98
+ keys.add(key);
99
+ };
100
+ const record = node;
101
+ for (const source of Object.values(node.expressions ?? {}))
102
+ addExpressionKeys(source, add);
103
+ if (node.condition !== undefined)
104
+ addExpressionKeys(node.condition, add);
105
+ if (record.style?.styleId !== undefined)
106
+ add(`node:${record.style.styleId}`);
107
+ if (node.type === "text" || record.paragraphs !== undefined)
108
+ addParagraphKeys(record.paragraphs, add);
109
+ if (node.type === "code")
110
+ add(record.codeStyleId === undefined ? CODE_DEFAULT : `code:${record.codeStyleId}`);
111
+ addBindingKeys(node.variableBindings, add);
112
+ for (const collectionId of Object.keys(node.variableModes ?? {}))
113
+ add(`mode:${collectionId}`);
114
+ if (node.type === "instance")
115
+ for (const override of Object.values(record.overrides ?? {}))
116
+ addOverrideKeys(override, add);
117
+ return keys.size === 0 ? null : [...keys].sort();
118
+ }
119
+ /** An entry without its name, which no node reads but an expression. */
120
+ function withoutName(entry) {
121
+ if (entry === undefined)
122
+ return undefined;
123
+ const { name: _name, ...rest } = entry;
124
+ return rest;
125
+ }
126
+ const THEME_FIELDS = new Set([
127
+ "defaultTextStyleId", "defaultCodeStyleId", "colors", "nodeStyles", "textStyles", "codeStyles", "variableCollections",
128
+ ]);
129
+ /**
130
+ * The parts of the theme that differ between `before` and `after` in a way a
131
+ * node that uses them can see, or "all" when the change is one this module
132
+ * cannot attribute (a theme field it does not know). A change of a style's or
133
+ * variable's name alone, or of the named colors, reaches only the layers
134
+ * whose expressions read a variable name that now finds another variable or
135
+ * none (`var-name:`), or that this module cannot read (`any`).
136
+ */
137
+ export function changedThemeKeys(before, after) {
138
+ const keys = new Set();
139
+ if (before === after)
140
+ return keys;
141
+ for (const field of new Set([...Object.keys(before), ...Object.keys(after)])) {
142
+ if (!THEME_FIELDS.has(field) && !same(before[field], after[field])) {
143
+ return "all";
144
+ }
145
+ }
146
+ if (same(before, after))
147
+ return keys;
148
+ keys.add(ANY);
149
+ const styles = (kind, left, right, defaults) => {
150
+ if (left === right)
151
+ return;
152
+ for (const id of new Set([...Object.keys(left), ...Object.keys(right)])) {
153
+ if (same(withoutName(entryOf(left, id)), withoutName(entryOf(right, id))))
154
+ continue;
155
+ keys.add(`${kind}:${id}`);
156
+ if (defaults !== undefined && (defaults[0] === id || defaults[1] === id))
157
+ keys.add(`${kind}-default`);
158
+ }
159
+ };
160
+ if (before.defaultTextStyleId !== after.defaultTextStyleId)
161
+ keys.add(TEXT_DEFAULT);
162
+ if (before.defaultCodeStyleId !== after.defaultCodeStyleId)
163
+ keys.add(CODE_DEFAULT);
164
+ styles("text", before.textStyles, after.textStyles, [before.defaultTextStyleId, after.defaultTextStyleId]);
165
+ styles("code", before.codeStyles, after.codeStyles, [before.defaultCodeStyleId, after.defaultCodeStyleId]);
166
+ styles("node", before.nodeStyles, after.nodeStyles);
167
+ const leftCollections = before.variableCollections ?? {};
168
+ const rightCollections = after.variableCollections ?? {};
169
+ if (leftCollections !== rightCollections) {
170
+ for (const id of new Set([...Object.keys(leftCollections), ...Object.keys(rightCollections)])) {
171
+ const left = entryOf(leftCollections, id);
172
+ const right = entryOf(rightCollections, id);
173
+ if (left === right)
174
+ continue;
175
+ const leftVariables = left?.variables ?? {};
176
+ const rightVariables = right?.variables ?? {};
177
+ const variableIds = new Set([...Object.keys(leftVariables), ...Object.keys(rightVariables)]);
178
+ const { name: _leftName, variables: _leftVariables, ...leftModes } = left ?? { name: "", variables: {} };
179
+ const { name: _rightName, variables: _rightVariables, ...rightModes } = right ?? { name: "", variables: {} };
180
+ if (left === undefined || right === undefined || !same(leftModes, rightModes)) {
181
+ // The modes changed: every variable of the collection resolves anew, and every choice of its modes is read again.
182
+ keys.add(`mode:${id}`);
183
+ for (const variableId of variableIds)
184
+ keys.add(`var:${variableId}`);
185
+ continue;
186
+ }
187
+ if (leftVariables === rightVariables)
188
+ continue;
189
+ for (const variableId of variableIds) {
190
+ if (!same(withoutName(entryOf(leftVariables, variableId)), withoutName(entryOf(rightVariables, variableId)))) {
191
+ keys.add(`var:${variableId}`);
192
+ }
193
+ }
194
+ }
195
+ addChangedVariableNames(before, after, keys);
196
+ }
197
+ return keys;
198
+ }
199
+ /**
200
+ * Adds `var-name:<name>` for each expression name of a variable that finds
201
+ * another variable, or none, after the change, or whose variable changed in
202
+ * `keys` (its value, type or modes).
203
+ */
204
+ function addChangedVariableNames(before, after, keys) {
205
+ const left = variablesByExpressionName(before);
206
+ const right = variablesByExpressionName(after);
207
+ for (const [name, found] of left) {
208
+ const other = right.get(name);
209
+ if (other === undefined || other.variableId !== found.variableId || other.collectionId !== found.collectionId ||
210
+ keys.has(`var:${found.variableId}`)) {
211
+ keys.add(`${VARIABLE_NAME}${name}`);
212
+ }
213
+ }
214
+ for (const name of right.keys())
215
+ if (!left.has(name))
216
+ keys.add(`${VARIABLE_NAME}${name}`);
217
+ }
218
+ /** The index of each frozen document. */
219
+ const indexes = new WeakMap();
220
+ function canKeep(document) {
221
+ return Object.isFrozen(document) && isFrozenNodeMap(document.nodes);
222
+ }
223
+ function wholeIndex(document) {
224
+ modelApplyStats.themeUsersWholeDocumentScans += 1;
225
+ const keysById = new Map();
226
+ for (const node of tableValues(document.nodes)) {
227
+ const keys = themeKeysOfNode(node);
228
+ if (keys !== null)
229
+ keysById.set(node.id, keys);
230
+ }
231
+ return new NodeUsers(undefined, keysById);
232
+ }
233
+ /** `users` with the nodes `ids` read again from `document`. */
234
+ function withNodes(users, document, ids) {
235
+ const changes = new Map();
236
+ for (const id of ids) {
237
+ if (changes.has(id))
238
+ continue;
239
+ const node = entryOf(document.nodes, id);
240
+ const keys = node === undefined ? null : themeKeysOfNode(node);
241
+ if (!sameKeys(keys, users.keysOf(id)))
242
+ changes.set(id, keys);
243
+ }
244
+ return users.with(changes);
245
+ }
246
+ /**
247
+ * The index of `document`: kept, or made from the index of the nearest
248
+ * document it was made from by edits (as far as `MAX_DERIVATION_STEPS`
249
+ * steps reach), or else read from every node of the earliest of them. Each
250
+ * document on the way keeps its own index. Only a frozen document keeps one.
251
+ */
252
+ function themeUsersOf(document) {
253
+ const kept = indexes.get(document);
254
+ if (kept !== undefined)
255
+ return kept;
256
+ if (!canKeep(document))
257
+ return wholeIndex(document);
258
+ const chain = [document];
259
+ let users;
260
+ for (let step = 0; step < MAX_DERIVATION_STEPS; step += 1) {
261
+ const base = derivations.get(chain[chain.length - 1])?.base.deref();
262
+ if (base === undefined || !canKeep(base))
263
+ break;
264
+ users = indexes.get(base);
265
+ if (users !== undefined)
266
+ break;
267
+ chain.push(base);
268
+ }
269
+ if (users === undefined) {
270
+ const earliest = chain.pop();
271
+ users = wholeIndex(earliest);
272
+ indexes.set(earliest, users);
273
+ }
274
+ for (let index = chain.length - 1; index >= 0; index -= 1) {
275
+ const derived = chain[index];
276
+ users = withNodes(users, derived, derivations.get(derived).changedNodeIds);
277
+ indexes.set(derived, users);
278
+ }
279
+ return users;
280
+ }
281
+ /**
282
+ * The nodes of `document` that use a part of the theme that differs between
283
+ * `before` and `after` (`changedThemeKeys`): every node of `document` when
284
+ * the change cannot be attributed. A node that does not use any part that
285
+ * changed shows and checks the same with either theme.
286
+ */
287
+ export function nodesUsingThemeChange(document, before, after) {
288
+ const keys = changedThemeKeys(before, after);
289
+ if (keys === "all")
290
+ return tableKeys(document.nodes);
291
+ if (keys.size === 0)
292
+ return [];
293
+ const users = themeUsersOf(document);
294
+ const ids = new Set();
295
+ for (const key of keys)
296
+ for (const id of users.usersOf(key))
297
+ ids.add(id);
298
+ return [...ids];
299
+ }
300
+ /**
301
+ * Keeps the index of `derived`, made by an edit of `base`, when `base` has
302
+ * one: so a run of edits keeps it, reading only the nodes each edit wrote.
303
+ */
304
+ export function keepThemeUsers(base, derived) {
305
+ const kept = indexes.get(base);
306
+ if (kept === undefined || !canKeep(derived) || indexes.has(derived))
307
+ return;
308
+ const derivation = derivations.get(derived);
309
+ if (derivation === undefined || derivation.base.deref() !== base)
310
+ return;
311
+ indexes.set(derived, withNodes(kept, derived, derivation.changedNodeIds));
312
+ }
@@ -0,0 +1,15 @@
1
+ import { type DesignDocument, type NodeId, type PageId } from "./types.ts";
2
+ /**
3
+ * Whether "Set as thumbnail" can take `nodeId`: a frame directly on a page,
4
+ * as in Figma. `document.set-thumbnail` refuses any other layer.
5
+ */
6
+ export declare function canBeThumbnail(document: DesignDocument, nodeId: NodeId): boolean;
7
+ /**
8
+ * The frame set as the file's thumbnail and its page, or null when none is
9
+ * set or the one set is no longer a top-level frame (removed, or moved into
10
+ * another layer); the file then has the default thumbnail.
11
+ */
12
+ export declare function thumbnailFrameOf(document: DesignDocument): {
13
+ readonly nodeId: NodeId;
14
+ readonly pageId: PageId;
15
+ } | null;
@@ -0,0 +1,34 @@
1
+ import { entryOf } from "./id-table.js";
2
+ import { isContainerNode } from "./types.js";
3
+ /** The page a top-level frame sits on, or null when `nodeId` is not a frame directly on a page. */
4
+ function pageOfTopLevelFrame(document, nodeId) {
5
+ const node = entryOf(document.nodes, nodeId);
6
+ if (node === undefined || node.type !== "frame")
7
+ return null;
8
+ for (const pageId of document.pageOrder) {
9
+ const page = entryOf(document.pages, pageId);
10
+ const root = page === undefined ? undefined : entryOf(document.nodes, page.rootId);
11
+ if (root !== undefined && isContainerNode(root) && root.children.includes(nodeId))
12
+ return pageId;
13
+ }
14
+ return null;
15
+ }
16
+ /**
17
+ * Whether "Set as thumbnail" can take `nodeId`: a frame directly on a page,
18
+ * as in Figma. `document.set-thumbnail` refuses any other layer.
19
+ */
20
+ export function canBeThumbnail(document, nodeId) {
21
+ return pageOfTopLevelFrame(document, nodeId) !== null;
22
+ }
23
+ /**
24
+ * The frame set as the file's thumbnail and its page, or null when none is
25
+ * set or the one set is no longer a top-level frame (removed, or moved into
26
+ * another layer); the file then has the default thumbnail.
27
+ */
28
+ export function thumbnailFrameOf(document) {
29
+ const nodeId = document.thumbnailNodeId;
30
+ if (nodeId === undefined)
31
+ return null;
32
+ const pageId = pageOfTopLevelFrame(document, nodeId);
33
+ return pageId === null ? null : { nodeId, pageId };
34
+ }