@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,290 @@
1
+ import { deserializeDocument } from "./codec.js";
2
+ import { CURRENT_DOCUMENT_SCHEMA_VERSION, codeStyleId, componentId, documentId, nodeId, pageId, textStyleId, variableCollectionId, variableId, variableModeId, } from "./types.js";
3
+ /**
4
+ * The IDs the component sample documents use, so tests can refer to them by
5
+ * name. Layer paths for overrides are built from the node IDs, for example
6
+ * `layerPathKey([componentSampleIds.cardButton, componentSampleIds.buttonLabel])`.
7
+ * @since 0.23.0
8
+ */
9
+ export const componentSampleIds = {
10
+ document: documentId("component-samples"),
11
+ page: pageId("page-one"),
12
+ pageRoot: nodeId("root-one"),
13
+ textStyle: textStyleId("body"),
14
+ /** A "Button" component: a horizontal auto layout root that hugs a label and an icon. */
15
+ button: componentId("button"),
16
+ buttonRoot: nodeId("button-root"),
17
+ buttonLabel: nodeId("button-label"),
18
+ buttonIcon: nodeId("button-icon"),
19
+ /** A "Card" component: a vertical auto layout root with a title and a nested Button instance. */
20
+ card: componentId("card"),
21
+ cardRoot: nodeId("card-root"),
22
+ cardTitle: nodeId("card-title"),
23
+ cardButton: nodeId("card-button"),
24
+ /** An "Icon button" component: a fixed-size root with only an icon. */
25
+ iconButton: componentId("icon-button"),
26
+ iconButtonRoot: nodeId("icon-button-root"),
27
+ iconButtonIcon: nodeId("icon-button-icon"),
28
+ /** Instances on the page. */
29
+ buttonInstance: nodeId("button-1"),
30
+ secondButtonInstance: nodeId("button-2"),
31
+ cardInstance: nodeId("card-1"),
32
+ /** Variables of the variable-bound sample. */
33
+ colors: variableCollectionId("colors"),
34
+ lightMode: variableModeId("light"),
35
+ primary: variableId("primary"),
36
+ danger: variableId("danger"),
37
+ };
38
+ const ids = componentSampleIds;
39
+ const framed = (id, name, frame) => ({
40
+ id,
41
+ name,
42
+ visible: true,
43
+ locked: false,
44
+ opacity: 1,
45
+ frame,
46
+ rotation: 0,
47
+ });
48
+ const text = (id, name, characters, frame) => ({
49
+ ...framed(id, name, frame),
50
+ type: "text",
51
+ paragraphs: [{ runs: [{ text: characters }] }],
52
+ verticalAlign: "top",
53
+ overflow: "visible",
54
+ autoResize: "width-and-height",
55
+ wrap: "none",
56
+ });
57
+ const rectangle = (id, name, frame, color) => ({
58
+ ...framed(id, name, frame),
59
+ type: "shape",
60
+ shape: "rectangle",
61
+ style: { fills: [{ kind: "solid", color }], cornerRadius: 4 },
62
+ });
63
+ const hugRoot = (id, name, kind, children, size, fill) => ({
64
+ ...framed(id, name, { x: 0, y: 0, ...size }),
65
+ type: "frame",
66
+ children,
67
+ layout: {
68
+ kind,
69
+ widthSizing: "hug",
70
+ heightSizing: "hug",
71
+ gap: 8,
72
+ padding: { top: 8, right: 12, bottom: 8, left: 12 },
73
+ align: "center",
74
+ justify: "start",
75
+ },
76
+ style: { fills: [{ kind: "solid", color: fill }], cornerRadius: 6 },
77
+ clipContent: false,
78
+ });
79
+ const instance = (id, name, of, frame, overrides) => ({
80
+ ...framed(id, name, frame),
81
+ type: "instance",
82
+ componentId: of,
83
+ ...(overrides === undefined ? {} : { overrides }),
84
+ });
85
+ const buttonComponent = {
86
+ id: ids.button,
87
+ key: "6f1d2b8e-7c1a-4e4f-9c1d-0b7a2f3e4d51",
88
+ name: "Button",
89
+ description: "A label with an icon",
90
+ rootId: ids.buttonRoot,
91
+ };
92
+ const buttonNodes = () => ({
93
+ [ids.buttonRoot]: hugRoot(ids.buttonRoot, "Button", "horizontal", [ids.buttonLabel, ids.buttonIcon], { width: 96, height: 40 }, "#0d9488"),
94
+ [ids.buttonLabel]: text(ids.buttonLabel, "Label", "Button", { x: 12, y: 8, width: 48, height: 24 }),
95
+ [ids.buttonIcon]: rectangle(ids.buttonIcon, "Icon", { x: 68, y: 12, width: 16, height: 16 }, "#ffffff"),
96
+ });
97
+ const cardComponent = {
98
+ id: ids.card,
99
+ key: "2a9c4e7b-3d5f-4a1b-8e6c-9f0d1a2b3c44",
100
+ name: "Card",
101
+ rootId: ids.cardRoot,
102
+ };
103
+ const cardNodes = () => ({
104
+ [ids.cardRoot]: hugRoot(ids.cardRoot, "Card", "vertical", [ids.cardTitle, ids.cardButton], { width: 200, height: 96 }, "#ffffff"),
105
+ [ids.cardTitle]: text(ids.cardTitle, "Title", "Card title", { x: 12, y: 8, width: 176, height: 24 }),
106
+ [ids.cardButton]: instance(ids.cardButton, "Button", ids.button, { x: 12, y: 40, width: 96, height: 40 }),
107
+ });
108
+ const iconButtonComponent = {
109
+ id: ids.iconButton,
110
+ key: "c3b2a1d0-5e6f-4789-a0b1-c2d3e4f5a677",
111
+ name: "Icon button",
112
+ rootId: ids.iconButtonRoot,
113
+ };
114
+ const iconButtonNodes = () => ({
115
+ [ids.iconButtonRoot]: {
116
+ ...hugRoot(ids.iconButtonRoot, "Icon button", "horizontal", [ids.iconButtonIcon], { width: 40, height: 40 }, "#0d9488"),
117
+ layout: {
118
+ kind: "horizontal",
119
+ widthSizing: "fixed",
120
+ heightSizing: "fixed",
121
+ gap: 0,
122
+ padding: { top: 12, right: 12, bottom: 12, left: 12 },
123
+ align: "center",
124
+ justify: "center",
125
+ },
126
+ },
127
+ [ids.iconButtonIcon]: rectangle(ids.iconButtonIcon, "Icon", { x: 12, y: 12, width: 16, height: 16 }, "#ffffff"),
128
+ });
129
+ const pageRoot = (children) => ({
130
+ ...framed(ids.pageRoot, "Page 1", { x: 0, y: 0, width: 800, height: 600 }),
131
+ type: "frame",
132
+ children,
133
+ layout: { kind: "absolute" },
134
+ });
135
+ const baseDocument = (nodes, components, theme) => deserializeDocument({
136
+ schemaVersion: CURRENT_DOCUMENT_SCHEMA_VERSION,
137
+ commentThreads: [],
138
+ id: ids.document,
139
+ title: "Component samples",
140
+ pageOrder: [ids.page],
141
+ pages: { [ids.page]: { id: ids.page, name: "Page 1", rootId: ids.pageRoot } },
142
+ nodes,
143
+ assets: {},
144
+ theme: {
145
+ defaultTextStyleId: ids.textStyle,
146
+ defaultCodeStyleId: codeStyleId("code"),
147
+ colors: {},
148
+ nodeStyles: {},
149
+ textStyles: {
150
+ [ids.textStyle]: {
151
+ name: "Body",
152
+ fontFamily: "Inter",
153
+ fontSize: 16,
154
+ fontWeight: 500,
155
+ lineHeight: 1.5,
156
+ color: "#111111",
157
+ },
158
+ },
159
+ codeStyles: {
160
+ code: {
161
+ name: "Code",
162
+ fontFamily: "JetBrains Mono",
163
+ fontSize: 14,
164
+ lineHeight: 1.4,
165
+ background: "#111111",
166
+ foreground: "#f5f5f5",
167
+ syntax: {},
168
+ },
169
+ },
170
+ ...theme,
171
+ },
172
+ components,
173
+ });
174
+ /**
175
+ * One Button component and one instance of it on the page, with no
176
+ * overrides. The instance is at the component's natural size.
177
+ * @since 0.23.0
178
+ */
179
+ export function plainInstanceSample() {
180
+ return baseDocument({
181
+ [ids.pageRoot]: pageRoot([ids.buttonInstance]),
182
+ ...buttonNodes(),
183
+ [ids.buttonInstance]: instance(ids.buttonInstance, "Button", ids.button, { x: 40, y: 40, width: 96, height: 40 }),
184
+ }, { [ids.button]: buttonComponent });
185
+ }
186
+ /**
187
+ * A Card component whose tree holds an instance of Button, and one Card
188
+ * instance on the page. The nesting graph has the edge Card → Button.
189
+ * @since 0.23.0
190
+ */
191
+ export function nestedInstanceSample() {
192
+ return baseDocument({
193
+ [ids.pageRoot]: pageRoot([ids.cardInstance]),
194
+ ...buttonNodes(),
195
+ ...cardNodes(),
196
+ [ids.cardInstance]: instance(ids.cardInstance, "Card", ids.card, { x: 40, y: 40, width: 200, height: 96 }),
197
+ }, { [ids.button]: buttonComponent, [ids.card]: cardComponent });
198
+ }
199
+ /**
200
+ * Two Button instances with text overrides: `button-1` changes the label's
201
+ * characters only, and `button-2` stores styled paragraphs because part of
202
+ * its label is bold. Both keep the component's font.
203
+ * @since 0.23.0
204
+ */
205
+ export function textOverrideSample() {
206
+ return baseDocument({
207
+ [ids.pageRoot]: pageRoot([ids.buttonInstance, ids.secondButtonInstance]),
208
+ ...buttonNodes(),
209
+ [ids.buttonInstance]: instance(ids.buttonInstance, "Buy button", ids.button, { x: 40, y: 40, width: 108, height: 40 }, { [ids.buttonLabel]: { characters: "Buy now" } }),
210
+ [ids.secondButtonInstance]: instance(ids.secondButtonInstance, "Styled button", ids.button, { x: 40, y: 100, width: 120, height: 40 }, {
211
+ [ids.buttonLabel]: {
212
+ paragraphs: [{
213
+ runs: [
214
+ { text: "Save " },
215
+ { text: "20%", overrides: { fontWeight: 700 } },
216
+ ],
217
+ }],
218
+ },
219
+ }),
220
+ }, { [ids.button]: buttonComponent });
221
+ }
222
+ /**
223
+ * The Button label's colour is bound to the `primary` variable in the
224
+ * component. The instance rebinds it to `danger` for the label, and for the
225
+ * root it overrides the fills with a plain colour while removing the
226
+ * component's `fillColor` binding, so the plain override cannot be repainted
227
+ * by the variable.
228
+ * @since 0.23.0
229
+ */
230
+ export function variableBoundOverrideSample() {
231
+ const button = buttonNodes();
232
+ const label = button[ids.buttonLabel];
233
+ const root = button[ids.buttonRoot];
234
+ return baseDocument({
235
+ [ids.pageRoot]: pageRoot([ids.buttonInstance]),
236
+ ...button,
237
+ [ids.buttonLabel]: { ...label, variableBindings: { textColor: ids.primary } },
238
+ [ids.buttonRoot]: { ...root, variableBindings: { fillColor: ids.primary } },
239
+ [ids.buttonInstance]: instance(ids.buttonInstance, "Danger button", ids.button, { x: 40, y: 40, width: 96, height: 40 }, {
240
+ [ids.buttonLabel]: { variableBindings: { textColor: ids.danger } },
241
+ [ids.buttonRoot]: {
242
+ fills: [{ kind: "solid", color: "#fee2e2" }],
243
+ variableBindings: { fillColor: null },
244
+ },
245
+ }),
246
+ }, { [ids.button]: buttonComponent }, {
247
+ variableCollections: {
248
+ [ids.colors]: {
249
+ name: "Colors",
250
+ defaultModeId: ids.lightMode,
251
+ modeOrder: [ids.lightMode],
252
+ modes: { [ids.lightMode]: { name: "Light" } },
253
+ variables: {
254
+ [ids.primary]: { name: "primary", type: "color", values: { [ids.lightMode]: "#0d9488" } },
255
+ [ids.danger]: { name: "danger", type: "color", values: { [ids.lightMode]: "#dc2626" } },
256
+ },
257
+ },
258
+ },
259
+ });
260
+ }
261
+ /**
262
+ * The nested sample plus an Icon button component. The Card instance swaps
263
+ * its nested Button to Icon button, and keeps a characters override under
264
+ * the old label's path, which Icon button does not have: the entry is
265
+ * allowed and has no effect.
266
+ * @since 0.23.0
267
+ */
268
+ export function swappedNestedInstanceSample() {
269
+ return baseDocument({
270
+ [ids.pageRoot]: pageRoot([ids.cardInstance]),
271
+ ...buttonNodes(),
272
+ ...cardNodes(),
273
+ ...iconButtonNodes(),
274
+ [ids.cardInstance]: instance(ids.cardInstance, "Card", ids.card, { x: 40, y: 40, width: 200, height: 96 }, {
275
+ [ids.cardButton]: { componentId: ids.iconButton },
276
+ [`${ids.cardButton};${ids.buttonLabel}`]: { characters: "Gone" },
277
+ }),
278
+ }, { [ids.button]: buttonComponent, [ids.card]: cardComponent, [ids.iconButton]: iconButtonComponent });
279
+ }
280
+ /**
281
+ * Every component sample by name, for tests that run over all of them.
282
+ * @since 0.23.0
283
+ */
284
+ export const componentSampleDocuments = {
285
+ plain: plainInstanceSample,
286
+ nested: nestedInstanceSample,
287
+ textOverride: textOverrideSample,
288
+ variableBoundOverride: variableBoundOverrideSample,
289
+ swappedNested: swappedNestedInstanceSample,
290
+ };
@@ -0,0 +1,85 @@
1
+ import { type ExpressionCheckResult, type ExpressionEnvironment } from "./expressions/check.ts";
2
+ import type { ComponentDefinition, ComponentPropertyValue, ComponentPropertyValues } from "./types.ts";
3
+ /**
4
+ * The most steps one search for a valid combination may take (one step is
5
+ * one property given one value). Above it the search throws a `ModelError`
6
+ * naming the component: its validity expression is too costly to search.
7
+ * @since 0.35.0
8
+ */
9
+ export declare const VARIANT_SEARCH_STEP_LIMIT = 100000;
10
+ /**
11
+ * What these functions read of a component: its ID and name (for messages),
12
+ * its properties and its validity expression.
13
+ * @since 0.35.0
14
+ */
15
+ export type ValidityComponent = Pick<ComponentDefinition, "id" | "name" | "properties" | "validity">;
16
+ /**
17
+ * The checking environment of a component's validity expression: its enum
18
+ * and boolean properties by name, and nothing else (no other property, no
19
+ * variable, no `stored`).
20
+ * @since 0.35.0
21
+ */
22
+ export declare function componentValidityEnvironment(component: ValidityComponent): ExpressionEnvironment;
23
+ /**
24
+ * Checks `source` (the component's own validity expression by default) as a
25
+ * validity expression of `component`: it must parse, be a boolean, and read
26
+ * only the component's enum and boolean properties. Undefined when there is
27
+ * no expression to check.
28
+ * @since 0.35.0
29
+ */
30
+ export declare function checkComponentValidity(component: ValidityComponent, source?: string | undefined): ExpressionCheckResult | undefined;
31
+ /**
32
+ * True when `values` (an instance's values by property ID; a missing value
33
+ * or one that does not fit reads as the default) form a valid combination
34
+ * of `component`. Always true for a component without a validity
35
+ * expression. Only enum and boolean values matter.
36
+ * @since 0.35.0
37
+ */
38
+ export declare function isValidVariantCombination(component: ValidityComponent, values?: ComponentPropertyValues): boolean;
39
+ /**
40
+ * For each enum and boolean property of `component`, by property ID, the
41
+ * values to offer with the others as in `values`: an option is offered
42
+ * when at least one valid combination has it (choosing it may change other
43
+ * properties, see `nearestValidCombination`). Enum values are option IDs in
44
+ * option order; booleans are `false`, then `true`. Every value is offered
45
+ * without a validity expression. Throws a `ModelError` when the search
46
+ * passes `VARIANT_SEARCH_STEP_LIMIT` steps.
47
+ * @since 0.35.0
48
+ */
49
+ export declare function offeredVariantValues(component: ValidityComponent, values?: ComponentPropertyValues): Readonly<Record<string, readonly ComponentPropertyValue[]>>;
50
+ /** A valid combination `nearestValidCombination` found. */
51
+ export interface VariantCombinationChange {
52
+ /** Every enum and boolean property's value, by property ID. */
53
+ readonly values: Readonly<Record<string, ComponentPropertyValue>>;
54
+ /** The properties whose value differs from the one `values` gave before, in property order. */
55
+ readonly changed: readonly string[];
56
+ }
57
+ /**
58
+ * The valid combination nearest to `values` that keeps `propertyId` at
59
+ * `value` (or, with no property given, the valid combination nearest to
60
+ * `values`): the fewest other properties changed; among as near ones, the
61
+ * first in the search order, which takes the properties in the component's
62
+ * order and each one's values in option order (a boolean `false` before
63
+ * `true`), so an earlier property's earlier option wins. Undefined when no
64
+ * valid combination has that value. `values` itself when it is valid.
65
+ * Throws a `ModelError` when the search passes `VARIANT_SEARCH_STEP_LIMIT`
66
+ * steps, and when `propertyId` is not an enum or boolean property or
67
+ * `value` does not fit it.
68
+ * @since 0.35.0
69
+ */
70
+ export declare function nearestValidCombination(component: ValidityComponent, values?: ComponentPropertyValues, propertyId?: string, value?: ComponentPropertyValue): VariantCombinationChange | undefined;
71
+ /**
72
+ * Why `values` are not a valid combination of `component`, naming the valid
73
+ * combinations nearest to them (each keeps one property and changes as few
74
+ * others as it can); undefined when they are valid.
75
+ * @since 0.35.0
76
+ */
77
+ export declare function invalidCombinationProblem(component: ValidityComponent, values?: ComponentPropertyValues): string | undefined;
78
+ /**
79
+ * `values` with the enum and boolean values moved to the nearest valid
80
+ * combination when they are not one (see `nearestValidCombination`; no
81
+ * property is held), writing only the values that change. `values` itself
82
+ * when it is valid or none is near.
83
+ * @since 0.35.0
84
+ */
85
+ export declare function withValidVariantValues(component: ValidityComponent, values: ComponentPropertyValues): ComponentPropertyValues;