@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,111 @@
1
+ import { COMPUTABLE_FIELDS, type ComponentDefinition, type ComponentId, type ComponentPropertyDefinition, type ComponentPropertyValue, type ComputableField, type NodeExpressions, type SceneNode, type VariableProperty, type ValuedComponentPropertyDefinition } from "./types.ts";
2
+ /** A computable field other than `propertyValues.<id>`. @since 0.24.0 */
3
+ export type NamedComputableField = (typeof COMPUTABLE_FIELDS)[number];
4
+ /** The prefix of the computed field that holds a nested instance's property value. @since 0.24.0 */
5
+ export declare const PROPERTY_VALUE_FIELD_PREFIX = "propertyValues.";
6
+ /**
7
+ * True when `name` can be written bare in an expression as a property or an
8
+ * enum option name: a Unicode identifier (`ID_Start` or `_`, then
9
+ * `ID_Continue`, without U+200C or U+200D) that is not a keyword of the
10
+ * language. Since 0.34.0 a name need not be one: any other name is written
11
+ * in backticks (`formatExpressionName`), and `expressionNameProblem` says
12
+ * which names cannot be used at all.
13
+ * @since 0.24.0
14
+ */
15
+ export declare function isExpressionIdentifier(name: string): boolean;
16
+ /**
17
+ * The named fields a node of this type can compute, in `COMPUTABLE_FIELDS`
18
+ * order. An instance node can also compute `propertyValues.<property id>`
19
+ * for any property of its component.
20
+ * @since 0.24.0
21
+ */
22
+ export declare function computableFieldsOf(node: SceneNode): readonly NamedComputableField[];
23
+ /**
24
+ * The property ID in a `propertyValues.<property id>` field, or undefined
25
+ * for any other field.
26
+ * @since 0.24.0
27
+ */
28
+ export declare function propertyValueFieldId(field: string): string | undefined;
29
+ /**
30
+ * True when `field` can hold an expression on this node. It checks the name
31
+ * only: a `propertyValues.<id>` field naming a property the nested component
32
+ * does not have is allowed and has no effect.
33
+ * @since 0.24.0
34
+ */
35
+ export declare function isComputableField(node: SceneNode, field: string): field is ComputableField;
36
+ /**
37
+ * The variable binding properties that set the same value as a computed
38
+ * field. A field holds a binding or an expression, never both: saving an
39
+ * expression removes these bindings.
40
+ * @since 0.24.0
41
+ */
42
+ export declare const COMPUTABLE_FIELD_VARIABLE_PROPERTIES: Readonly<Record<NamedComputableField, readonly VariableProperty[]>>;
43
+ /**
44
+ * The variable binding properties that clash with a computed field; empty
45
+ * for `propertyValues.<id>`.
46
+ * @since 0.24.0
47
+ */
48
+ export declare function variablePropertiesOfField(field: string): readonly VariableProperty[];
49
+ /**
50
+ * The property with this ID, or undefined.
51
+ * @since 0.24.0
52
+ */
53
+ export declare function findComponentProperty(component: ComponentDefinition, propertyId: string): ComponentPropertyDefinition | undefined;
54
+ /**
55
+ * The property with this name, or undefined.
56
+ * @since 0.24.0
57
+ */
58
+ export declare function findComponentPropertyByName(component: ComponentDefinition, name: string): ComponentPropertyDefinition | undefined;
59
+ /**
60
+ * True when `value` fits the property's kind: a boolean for a boolean, a
61
+ * finite number for a number, a string for text and colour, an existing
62
+ * option ID for an enum, and a non-empty string for an instance swap.
63
+ * @since 0.24.0
64
+ */
65
+ export declare function propertyValueFits(property: ComponentPropertyDefinition, value: ComponentPropertyValue): boolean;
66
+ /**
67
+ * The value a property takes: the given value when it fits the property's
68
+ * kind, else the default.
69
+ * @since 0.24.0
70
+ */
71
+ export declare function effectivePropertyValue(property: ValuedComponentPropertyDefinition, value: ComponentPropertyValue | undefined): ComponentPropertyValue;
72
+ /**
73
+ * Property values carried from one component to another, as a swap does
74
+ * (design 8.9): a value is kept when the new component has a property with
75
+ * the same name and kind; an enum value only when the new property has an
76
+ * option with the same name, and then as that option's ID. Values that do
77
+ * not fit, or name a property the old component does not have, are dropped.
78
+ * An instance swap value goes through `mapComponent`, for a paste that maps
79
+ * component IDs. When `to` has a validity expression and the values carried
80
+ * are not a valid combination of it, its enum and boolean values move to the
81
+ * nearest valid one (`withValidVariantValues`). Undefined when nothing is
82
+ * left.
83
+ * @since 0.26.0
84
+ */
85
+ export declare function carryPropertyValues(from: ComponentDefinition | undefined, to: ComponentDefinition, values: Readonly<Record<string, ComponentPropertyValue>> | undefined, mapComponent?: (id: ComponentId) => ComponentId): Record<string, ComponentPropertyValue> | undefined;
86
+ /**
87
+ * Expressions carried from one component's instance to another's, as
88
+ * property values are: a `propertyValues.<id>` field is renamed to the new
89
+ * component's property with the same name and kind, and dropped when there is
90
+ * none or the old component lacks the ID. Other fields stay. Undefined when
91
+ * nothing is left.
92
+ * @since 0.26.0
93
+ */
94
+ export declare function carryPropertyExpressions(from: ComponentDefinition | undefined, to: ComponentDefinition, expressions: NodeExpressions | undefined): NodeExpressions | undefined;
95
+ /**
96
+ * The node without the variable bindings that clash with its expressions: a
97
+ * field holds a binding or an expression, never both, and the expression
98
+ * wins. The same node when nothing clashes.
99
+ * @since 0.26.0
100
+ */
101
+ export declare function withoutClashingBindings<T extends SceneNode>(node: T): T;
102
+ /**
103
+ * False for a layout field the frame's current layout kind does not use:
104
+ * `gap` on a grid or absolute frame, `columnGap` on a stack, any layout
105
+ * field on an absolute frame. True for every other field. A frame can keep
106
+ * an expression on any layout field (see `computableFieldsOf`), so it stays
107
+ * valid when the layout kind changes; the resolver applies, and the editor
108
+ * offers, only the fields in use.
109
+ * @since 0.24.0
110
+ */
111
+ export declare function isLayoutFieldInUse(node: SceneNode, field: string): boolean;
@@ -0,0 +1,339 @@
1
+ // Component properties and computed fields (docs/components/design.md 8.2,
2
+ // 8.3 and 8.7): which layer fields can hold an expression, which variable
3
+ // bindings they share a field with, and how property values are read.
4
+ // Validation lives in codec.ts; the checking and evaluation environments in
5
+ // component-expressions.ts.
6
+ import { withValidVariantValues } from "./component-validity.js";
7
+ import { isBareExpressionName } from "./expressions/names.js";
8
+ import { COMPUTABLE_FIELDS, isValuedComponentProperty, } from "./types.js";
9
+ import { putEntry } from "./id-table.js";
10
+ /** The prefix of the computed field that holds a nested instance's property value. @since 0.24.0 */
11
+ export const PROPERTY_VALUE_FIELD_PREFIX = "propertyValues.";
12
+ /**
13
+ * True when `name` can be written bare in an expression as a property or an
14
+ * enum option name: a Unicode identifier (`ID_Start` or `_`, then
15
+ * `ID_Continue`, without U+200C or U+200D) that is not a keyword of the
16
+ * language. Since 0.34.0 a name need not be one: any other name is written
17
+ * in backticks (`formatExpressionName`), and `expressionNameProblem` says
18
+ * which names cannot be used at all.
19
+ * @since 0.24.0
20
+ */
21
+ export function isExpressionIdentifier(name) {
22
+ return isBareExpressionName(name);
23
+ }
24
+ const SIZE_FIELDS = ["width", "height", "minWidth", "maxWidth", "minHeight", "maxHeight"];
25
+ const PAINT_FIELDS = ["fills", "strokes", "effects"];
26
+ const CORNER_FIELDS = ["cornerRadius", "cornerRadii", "cornerSmoothing"];
27
+ const LAYOUT_FIELDS = ["gap", "wrapGap", "columnGap", "rowGap", "padding", "direction", "align", "justify", "wrap"];
28
+ const TEXT_FIELDS = [
29
+ "characters",
30
+ "fontFamily",
31
+ "fontSize",
32
+ "fontWeight",
33
+ "lineHeight",
34
+ "letterSpacing",
35
+ "textColor",
36
+ "textStyle",
37
+ ];
38
+ /**
39
+ * The named fields a node of this type can compute, in `COMPUTABLE_FIELDS`
40
+ * order. An instance node can also compute `propertyValues.<property id>`
41
+ * for any property of its component.
42
+ * @since 0.24.0
43
+ */
44
+ export function computableFieldsOf(node) {
45
+ const fields = new Set(["visible", "opacity"]);
46
+ const add = (list) => list.forEach((field) => fields.add(field));
47
+ if ("frame" in node)
48
+ add(["x", "y", "rotation", "resizing.width", "resizing.height"]);
49
+ if ("transform" in node)
50
+ add(["transform"]);
51
+ if (node.type !== "group")
52
+ add(["constraints.horizontal", "constraints.vertical"]);
53
+ if (node.type === "frame")
54
+ add(["constraintSize", "clipContent", "layout.widthSizing", "layout.heightSizing"]);
55
+ if (node.type === "text")
56
+ add(["paragraphSpacing", "lineHeightMultiplier"]);
57
+ if (node.type === "shape" && (node.shape === "path" || node.shape === "line"))
58
+ add(["startCap", "endCap"]);
59
+ switch (node.type) {
60
+ case "frame":
61
+ add(PAINT_FIELDS);
62
+ add(CORNER_FIELDS);
63
+ add(SIZE_FIELDS);
64
+ add(LAYOUT_FIELDS);
65
+ break;
66
+ case "shape":
67
+ if (node.shape === "path") {
68
+ add(PAINT_FIELDS);
69
+ }
70
+ else if (node.shape === "line") {
71
+ add(["strokes", "effects", "width", "minWidth", "maxWidth"]);
72
+ }
73
+ else {
74
+ add(PAINT_FIELDS);
75
+ add(SIZE_FIELDS);
76
+ if (node.shape === "rectangle")
77
+ add(CORNER_FIELDS);
78
+ }
79
+ break;
80
+ case "text":
81
+ add(SIZE_FIELDS);
82
+ add(TEXT_FIELDS);
83
+ break;
84
+ case "code":
85
+ case "image":
86
+ case "video":
87
+ add(SIZE_FIELDS);
88
+ break;
89
+ case "instance":
90
+ add(SIZE_FIELDS);
91
+ add(["componentId"]);
92
+ break;
93
+ case "group":
94
+ add(["width", "height"]);
95
+ break;
96
+ case "connector":
97
+ break;
98
+ }
99
+ return COMPUTABLE_FIELDS.filter((field) => fields.has(field));
100
+ }
101
+ /**
102
+ * The property ID in a `propertyValues.<property id>` field, or undefined
103
+ * for any other field.
104
+ * @since 0.24.0
105
+ */
106
+ export function propertyValueFieldId(field) {
107
+ if (!field.startsWith(PROPERTY_VALUE_FIELD_PREFIX))
108
+ return undefined;
109
+ const id = field.slice(PROPERTY_VALUE_FIELD_PREFIX.length);
110
+ return id.length > 0 ? id : undefined;
111
+ }
112
+ /**
113
+ * True when `field` can hold an expression on this node. It checks the name
114
+ * only: a `propertyValues.<id>` field naming a property the nested component
115
+ * does not have is allowed and has no effect.
116
+ * @since 0.24.0
117
+ */
118
+ export function isComputableField(node, field) {
119
+ if (propertyValueFieldId(field) !== undefined)
120
+ return node.type === "instance";
121
+ return computableFieldsOf(node).includes(field);
122
+ }
123
+ /**
124
+ * The variable binding properties that set the same value as a computed
125
+ * field. A field holds a binding or an expression, never both: saving an
126
+ * expression removes these bindings.
127
+ * @since 0.24.0
128
+ */
129
+ export const COMPUTABLE_FIELD_VARIABLE_PROPERTIES = {
130
+ "x": [],
131
+ "y": [],
132
+ "rotation": [],
133
+ "transform": [],
134
+ "clipContent": [],
135
+ "paragraphSpacing": [],
136
+ "lineHeightMultiplier": ["lineHeight"],
137
+ "constraintSize": [],
138
+ "resizing.width": [],
139
+ "resizing.height": [],
140
+ "layout.widthSizing": [],
141
+ "layout.heightSizing": [],
142
+ "constraints.horizontal": [],
143
+ "constraints.vertical": [],
144
+ "startCap": [],
145
+ "endCap": [],
146
+ visible: ["visibility"],
147
+ opacity: ["opacity"],
148
+ fills: ["fillColor"],
149
+ strokes: ["strokeColor", "strokeWidth"],
150
+ effects: [],
151
+ cornerRadius: ["cornerRadius"],
152
+ cornerRadii: ["cornerRadius"],
153
+ cornerSmoothing: [],
154
+ width: ["width"],
155
+ height: ["height"],
156
+ minWidth: [],
157
+ maxWidth: [],
158
+ minHeight: [],
159
+ maxHeight: [],
160
+ gap: ["gap"],
161
+ wrapGap: ["wrapGap"],
162
+ columnGap: ["columnGap"],
163
+ rowGap: ["rowGap"],
164
+ padding: ["paddingTop", "paddingRight", "paddingBottom", "paddingLeft"],
165
+ direction: [],
166
+ align: [],
167
+ justify: [],
168
+ wrap: [],
169
+ characters: [],
170
+ fontFamily: ["fontFamily"],
171
+ fontSize: ["fontSize"],
172
+ fontWeight: ["fontWeight"],
173
+ lineHeight: ["lineHeight"],
174
+ letterSpacing: ["letterSpacing"],
175
+ textColor: ["textColor"],
176
+ textStyle: ["fontFamily", "fontSize", "fontWeight", "lineHeight", "letterSpacing"],
177
+ componentId: [],
178
+ };
179
+ /**
180
+ * The variable binding properties that clash with a computed field; empty
181
+ * for `propertyValues.<id>`.
182
+ * @since 0.24.0
183
+ */
184
+ export function variablePropertiesOfField(field) {
185
+ return COMPUTABLE_FIELD_VARIABLE_PROPERTIES[field] ?? [];
186
+ }
187
+ /**
188
+ * The property with this ID, or undefined.
189
+ * @since 0.24.0
190
+ */
191
+ export function findComponentProperty(component, propertyId) {
192
+ return component.properties?.find((property) => property.id === propertyId);
193
+ }
194
+ /**
195
+ * The property with this name, or undefined.
196
+ * @since 0.24.0
197
+ */
198
+ export function findComponentPropertyByName(component, name) {
199
+ return component.properties?.find((property) => property.name === name);
200
+ }
201
+ /**
202
+ * True when `value` fits the property's kind: a boolean for a boolean, a
203
+ * finite number for a number, a string for text and colour, an existing
204
+ * option ID for an enum, and a non-empty string for an instance swap.
205
+ * @since 0.24.0
206
+ */
207
+ export function propertyValueFits(property, value) {
208
+ switch (property.kind) {
209
+ case "boolean":
210
+ return typeof value === "boolean";
211
+ case "number":
212
+ return typeof value === "number" && Number.isFinite(value);
213
+ case "text":
214
+ case "color":
215
+ return typeof value === "string";
216
+ case "enum":
217
+ return typeof value === "string" && property.options.some((option) => option.id === value);
218
+ case "instance":
219
+ return typeof value === "string" && value.length > 0;
220
+ case "slot":
221
+ return false;
222
+ }
223
+ }
224
+ /**
225
+ * The value a property takes: the given value when it fits the property's
226
+ * kind, else the default.
227
+ * @since 0.24.0
228
+ */
229
+ export function effectivePropertyValue(property, value) {
230
+ return value !== undefined && propertyValueFits(property, value) ? value : property.defaultValue;
231
+ }
232
+ /**
233
+ * Property values carried from one component to another, as a swap does
234
+ * (design 8.9): a value is kept when the new component has a property with
235
+ * the same name and kind; an enum value only when the new property has an
236
+ * option with the same name, and then as that option's ID. Values that do
237
+ * not fit, or name a property the old component does not have, are dropped.
238
+ * An instance swap value goes through `mapComponent`, for a paste that maps
239
+ * component IDs. When `to` has a validity expression and the values carried
240
+ * are not a valid combination of it, its enum and boolean values move to the
241
+ * nearest valid one (`withValidVariantValues`). Undefined when nothing is
242
+ * left.
243
+ * @since 0.26.0
244
+ */
245
+ export function carryPropertyValues(from, to, values, mapComponent = (id) => id) {
246
+ if (from === undefined || values === undefined)
247
+ return undefined;
248
+ const carried = {};
249
+ for (const [propertyId, value] of Object.entries(values)) {
250
+ const old = findComponentProperty(from, propertyId);
251
+ if (old === undefined || !propertyValueFits(old, value))
252
+ continue;
253
+ const next = findComponentPropertyByName(to, old.name);
254
+ if (next === undefined || next.kind !== old.kind)
255
+ continue;
256
+ if (old.kind === "enum" && next.kind === "enum") {
257
+ const optionName = old.options.find((option) => option.id === value)?.name;
258
+ const option = next.options.find((candidate) => candidate.name === optionName);
259
+ if (option !== undefined)
260
+ putEntry(carried, next.id, option.id);
261
+ continue;
262
+ }
263
+ const mapped = next.kind === "instance" && typeof value === "string" ? mapComponent(value) : value;
264
+ if (propertyValueFits(next, mapped))
265
+ putEntry(carried, next.id, mapped);
266
+ }
267
+ const valid = withValidVariantValues(to, carried);
268
+ return Object.keys(valid).length === 0 ? undefined : valid;
269
+ }
270
+ /**
271
+ * Expressions carried from one component's instance to another's, as
272
+ * property values are: a `propertyValues.<id>` field is renamed to the new
273
+ * component's property with the same name and kind, and dropped when there is
274
+ * none or the old component lacks the ID. Other fields stay. Undefined when
275
+ * nothing is left.
276
+ * @since 0.26.0
277
+ */
278
+ export function carryPropertyExpressions(from, to, expressions) {
279
+ if (expressions === undefined)
280
+ return undefined;
281
+ const carried = {};
282
+ for (const [field, source] of Object.entries(expressions)) {
283
+ if (source === undefined)
284
+ continue;
285
+ const propertyId = propertyValueFieldId(field);
286
+ if (propertyId === undefined) {
287
+ putEntry(carried, field, source);
288
+ continue;
289
+ }
290
+ const old = from === undefined ? undefined : findComponentProperty(from, propertyId);
291
+ const next = old === undefined ? undefined : findComponentPropertyByName(to, old.name);
292
+ if (next !== undefined && next.kind === old.kind)
293
+ putEntry(carried, `${PROPERTY_VALUE_FIELD_PREFIX}${next.id}`, source);
294
+ }
295
+ return Object.keys(carried).length === 0 ? undefined : carried;
296
+ }
297
+ /**
298
+ * The node without the variable bindings that clash with its expressions: a
299
+ * field holds a binding or an expression, never both, and the expression
300
+ * wins. The same node when nothing clashes.
301
+ * @since 0.26.0
302
+ */
303
+ export function withoutClashingBindings(node) {
304
+ const bindings = node.variableBindings;
305
+ if (bindings === undefined || node.expressions === undefined)
306
+ return node;
307
+ const clashing = new Set(Object.keys(node.expressions).flatMap((field) => variablePropertiesOfField(field)));
308
+ const kept = Object.entries(bindings).filter(([property]) => !clashing.has(property));
309
+ if (kept.length === Object.keys(bindings).length)
310
+ return node;
311
+ const { variableBindings: _bindings, ...rest } = node;
312
+ return (kept.length === 0 ? rest : { ...rest, variableBindings: Object.fromEntries(kept) });
313
+ }
314
+ const STACK_LAYOUT_FIELDS = ["gap", "wrapGap", "padding", "direction", "align", "justify", "wrap"];
315
+ const GRID_LAYOUT_FIELDS = ["columnGap", "rowGap", "padding"];
316
+ /**
317
+ * False for a layout field the frame's current layout kind does not use:
318
+ * `gap` on a grid or absolute frame, `columnGap` on a stack, any layout
319
+ * field on an absolute frame. True for every other field. A frame can keep
320
+ * an expression on any layout field (see `computableFieldsOf`), so it stays
321
+ * valid when the layout kind changes; the resolver applies, and the editor
322
+ * offers, only the fields in use.
323
+ * @since 0.24.0
324
+ */
325
+ export function isLayoutFieldInUse(node, field) {
326
+ if (!LAYOUT_FIELDS.includes(field))
327
+ return true;
328
+ if (node.type !== "frame")
329
+ return false;
330
+ switch (node.layout.kind) {
331
+ case "horizontal":
332
+ case "vertical":
333
+ return STACK_LAYOUT_FIELDS.includes(field);
334
+ case "grid":
335
+ return GRID_LAYOUT_FIELDS.includes(field);
336
+ case "absolute":
337
+ return false;
338
+ }
339
+ }
@@ -0,0 +1,83 @@
1
+ import { type DesignDocument } from "./types.ts";
2
+ /**
3
+ * The IDs the component sample documents use, so tests can refer to them by
4
+ * name. Layer paths for overrides are built from the node IDs, for example
5
+ * `layerPathKey([componentSampleIds.cardButton, componentSampleIds.buttonLabel])`.
6
+ * @since 0.23.0
7
+ */
8
+ export declare const componentSampleIds: {
9
+ readonly document: import("./types.ts").DocumentId;
10
+ readonly page: import("./types.ts").PageId;
11
+ readonly pageRoot: import("./types.ts").NodeId;
12
+ readonly textStyle: import("./types.ts").TextStyleId;
13
+ /** A "Button" component: a horizontal auto layout root that hugs a label and an icon. */
14
+ readonly button: import("./types.ts").ComponentId;
15
+ readonly buttonRoot: import("./types.ts").NodeId;
16
+ readonly buttonLabel: import("./types.ts").NodeId;
17
+ readonly buttonIcon: import("./types.ts").NodeId;
18
+ /** A "Card" component: a vertical auto layout root with a title and a nested Button instance. */
19
+ readonly card: import("./types.ts").ComponentId;
20
+ readonly cardRoot: import("./types.ts").NodeId;
21
+ readonly cardTitle: import("./types.ts").NodeId;
22
+ readonly cardButton: import("./types.ts").NodeId;
23
+ /** An "Icon button" component: a fixed-size root with only an icon. */
24
+ readonly iconButton: import("./types.ts").ComponentId;
25
+ readonly iconButtonRoot: import("./types.ts").NodeId;
26
+ readonly iconButtonIcon: import("./types.ts").NodeId;
27
+ /** Instances on the page. */
28
+ readonly buttonInstance: import("./types.ts").NodeId;
29
+ readonly secondButtonInstance: import("./types.ts").NodeId;
30
+ readonly cardInstance: import("./types.ts").NodeId;
31
+ /** Variables of the variable-bound sample. */
32
+ readonly colors: import("./types.ts").VariableCollectionId;
33
+ readonly lightMode: import("./types.ts").VariableModeId;
34
+ readonly primary: import("./types.ts").VariableId;
35
+ readonly danger: import("./types.ts").VariableId;
36
+ };
37
+ /**
38
+ * One Button component and one instance of it on the page, with no
39
+ * overrides. The instance is at the component's natural size.
40
+ * @since 0.23.0
41
+ */
42
+ export declare function plainInstanceSample(): DesignDocument;
43
+ /**
44
+ * A Card component whose tree holds an instance of Button, and one Card
45
+ * instance on the page. The nesting graph has the edge Card → Button.
46
+ * @since 0.23.0
47
+ */
48
+ export declare function nestedInstanceSample(): DesignDocument;
49
+ /**
50
+ * Two Button instances with text overrides: `button-1` changes the label's
51
+ * characters only, and `button-2` stores styled paragraphs because part of
52
+ * its label is bold. Both keep the component's font.
53
+ * @since 0.23.0
54
+ */
55
+ export declare function textOverrideSample(): DesignDocument;
56
+ /**
57
+ * The Button label's colour is bound to the `primary` variable in the
58
+ * component. The instance rebinds it to `danger` for the label, and for the
59
+ * root it overrides the fills with a plain colour while removing the
60
+ * component's `fillColor` binding, so the plain override cannot be repainted
61
+ * by the variable.
62
+ * @since 0.23.0
63
+ */
64
+ export declare function variableBoundOverrideSample(): DesignDocument;
65
+ /**
66
+ * The nested sample plus an Icon button component. The Card instance swaps
67
+ * its nested Button to Icon button, and keeps a characters override under
68
+ * the old label's path, which Icon button does not have: the entry is
69
+ * allowed and has no effect.
70
+ * @since 0.23.0
71
+ */
72
+ export declare function swappedNestedInstanceSample(): DesignDocument;
73
+ /**
74
+ * Every component sample by name, for tests that run over all of them.
75
+ * @since 0.23.0
76
+ */
77
+ export declare const componentSampleDocuments: {
78
+ readonly plain: typeof plainInstanceSample;
79
+ readonly nested: typeof nestedInstanceSample;
80
+ readonly textOverride: typeof textOverrideSample;
81
+ readonly variableBoundOverride: typeof variableBoundOverrideSample;
82
+ readonly swappedNested: typeof swappedNestedInstanceSample;
83
+ };