@moondraft/import 0.0.0-stage → 0.2.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 (337) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/LICENSE +34 -0
  3. package/README.md +36 -2
  4. package/SOURCE.md +394 -0
  5. package/dist/adapter/convert.d.ts +144 -0
  6. package/dist/adapter/convert.js +2811 -0
  7. package/dist/adapter/figma-descriptions.d.ts +7 -0
  8. package/dist/adapter/figma-descriptions.js +34 -0
  9. package/dist/adapter/figma-grids.d.ts +12 -0
  10. package/dist/adapter/figma-grids.js +175 -0
  11. package/dist/adapter/figma-handoff.d.ts +12 -0
  12. package/dist/adapter/figma-handoff.js +167 -0
  13. package/dist/adapter/figma-hyperlinks.d.ts +13 -0
  14. package/dist/adapter/figma-hyperlinks.js +77 -0
  15. package/dist/adapter/figma.d.ts +12 -0
  16. package/dist/adapter/figma.js +40 -0
  17. package/dist/adapter/file-components.d.ts +20 -0
  18. package/dist/adapter/file-components.js +352 -0
  19. package/dist/adapter/file-resources.d.ts +29 -0
  20. package/dist/adapter/file-resources.js +851 -0
  21. package/dist/adapter/image-crop.d.ts +18 -0
  22. package/dist/adapter/image-crop.js +30 -0
  23. package/dist/adapter/index.d.ts +6 -0
  24. package/dist/adapter/index.js +9 -0
  25. package/dist/adapter/link.d.ts +49 -0
  26. package/dist/adapter/link.js +892 -0
  27. package/dist/adapter/payload.d.ts +31 -0
  28. package/dist/adapter/payload.js +78 -0
  29. package/dist/adapter/shapes.d.ts +31 -0
  30. package/dist/adapter/shapes.js +75 -0
  31. package/dist/adapter/variables.d.ts +45 -0
  32. package/dist/adapter/variables.js +106 -0
  33. package/dist/figma-file.d.ts +38 -0
  34. package/dist/figma-file.js +97 -0
  35. package/dist/figma-worker.d.ts +11 -0
  36. package/dist/figma-worker.js +12 -0
  37. package/dist/figma.d.ts +26 -0
  38. package/dist/figma.js +230 -0
  39. package/dist/index.d.ts +29 -0
  40. package/dist/index.js +50 -0
  41. package/dist/report.d.ts +42 -0
  42. package/dist/report.js +142 -0
  43. package/dist/serialize.d.ts +7 -0
  44. package/dist/serialize.js +79 -0
  45. package/dist/svg.d.ts +33 -0
  46. package/dist/svg.js +44 -0
  47. package/dist/syntax.d.ts +8 -0
  48. package/dist/syntax.js +19 -0
  49. package/dist/taco/figma-import/clipboard.d.ts +25 -0
  50. package/dist/taco/figma-import/clipboard.js +87 -0
  51. package/dist/taco/figma-import/clipboardSize.d.ts +31 -0
  52. package/dist/taco/figma-import/clipboardSize.js +107 -0
  53. package/dist/taco/figma-import/container/compression.d.ts +9 -0
  54. package/dist/taco/figma-import/container/compression.js +174 -0
  55. package/dist/taco/figma-import/container/error.d.ts +15 -0
  56. package/dist/taco/figma-import/container/error.js +19 -0
  57. package/dist/taco/figma-import/container/kiwiContainer.d.ts +41 -0
  58. package/dist/taco/figma-import/container/kiwiContainer.js +61 -0
  59. package/dist/taco/figma-import/container/limits.d.ts +22 -0
  60. package/dist/taco/figma-import/container/limits.js +22 -0
  61. package/dist/taco/figma-import/container/zip.d.ts +14 -0
  62. package/dist/taco/figma-import/container/zip.js +154 -0
  63. package/dist/taco/figma-import/figFile.d.ts +34 -0
  64. package/dist/taco/figma-import/figFile.js +91 -0
  65. package/dist/taco/figma-import/figFileDocument.d.ts +25 -0
  66. package/dist/taco/figma-import/figFileDocument.js +100 -0
  67. package/dist/taco/figma-import/import/blobs.d.ts +10 -0
  68. package/dist/taco/figma-import/import/blobs.js +23 -0
  69. package/dist/taco/figma-import/import/carry.d.ts +24 -0
  70. package/dist/taco/figma-import/import/carry.js +66 -0
  71. package/dist/taco/figma-import/import/componentProps.d.ts +90 -0
  72. package/dist/taco/figma-import/import/componentProps.js +329 -0
  73. package/dist/taco/figma-import/import/componentSets.d.ts +85 -0
  74. package/dist/taco/figma-import/import/componentSets.js +647 -0
  75. package/dist/taco/figma-import/import/converters/effects.d.ts +31 -0
  76. package/dist/taco/figma-import/import/converters/effects.js +127 -0
  77. package/dist/taco/figma-import/import/converters/ellipse.d.ts +7 -0
  78. package/dist/taco/figma-import/import/converters/ellipse.js +54 -0
  79. package/dist/taco/figma-import/import/converters/exportSettings.d.ts +4 -0
  80. package/dist/taco/figma-import/import/converters/exportSettings.js +49 -0
  81. package/dist/taco/figma-import/import/converters/frame.d.ts +21 -0
  82. package/dist/taco/figma-import/import/converters/frame.js +63 -0
  83. package/dist/taco/figma-import/import/converters/gradient.d.ts +74 -0
  84. package/dist/taco/figma-import/import/converters/gradient.js +108 -0
  85. package/dist/taco/figma-import/import/converters/group.d.ts +19 -0
  86. package/dist/taco/figma-import/import/converters/group.js +30 -0
  87. package/dist/taco/figma-import/import/converters/image.d.ts +13 -0
  88. package/dist/taco/figma-import/import/converters/image.js +94 -0
  89. package/dist/taco/figma-import/import/converters/layout.d.ts +33 -0
  90. package/dist/taco/figma-import/import/converters/layout.js +187 -0
  91. package/dist/taco/figma-import/import/converters/line.d.ts +11 -0
  92. package/dist/taco/figma-import/import/converters/line.js +40 -0
  93. package/dist/taco/figma-import/import/converters/rectangle.d.ts +3 -0
  94. package/dist/taco/figma-import/import/converters/rectangle.js +11 -0
  95. package/dist/taco/figma-import/import/converters/section.d.ts +8 -0
  96. package/dist/taco/figma-import/import/converters/section.js +29 -0
  97. package/dist/taco/figma-import/import/converters/shared.d.ts +71 -0
  98. package/dist/taco/figma-import/import/converters/shared.js +372 -0
  99. package/dist/taco/figma-import/import/converters/text.d.ts +54 -0
  100. package/dist/taco/figma-import/import/converters/text.js +707 -0
  101. package/dist/taco/figma-import/import/converters/vector.d.ts +105 -0
  102. package/dist/taco/figma-import/import/converters/vector.js +609 -0
  103. package/dist/taco/figma-import/import/converters/vectorNetwork.d.ts +114 -0
  104. package/dist/taco/figma-import/import/converters/vectorNetwork.js +503 -0
  105. package/dist/taco/figma-import/import/fields.d.ts +15 -0
  106. package/dist/taco/figma-import/import/fields.js +29 -0
  107. package/dist/taco/figma-import/import/instances.d.ts +184 -0
  108. package/dist/taco/figma-import/import/instances.js +1530 -0
  109. package/dist/taco/figma-import/import/nestingCycles.d.ts +86 -0
  110. package/dist/taco/figma-import/import/nestingCycles.js +488 -0
  111. package/dist/taco/figma-import/import/slots.d.ts +56 -0
  112. package/dist/taco/figma-import/import/slots.js +96 -0
  113. package/dist/taco/figma-import/import/styles.d.ts +48 -0
  114. package/dist/taco/figma-import/import/styles.js +48 -0
  115. package/dist/taco/figma-import/import/tree.d.ts +66 -0
  116. package/dist/taco/figma-import/import/tree.js +194 -0
  117. package/dist/taco/figma-import/import/types.d.ts +232 -0
  118. package/dist/taco/figma-import/import/types.js +33 -0
  119. package/dist/taco/figma-import/import/variables.d.ts +137 -0
  120. package/dist/taco/figma-import/import/variables.js +769 -0
  121. package/dist/taco/figma-import/import/variantTrees.d.ts +20 -0
  122. package/dist/taco/figma-import/import/variantTrees.js +520 -0
  123. package/dist/taco/figma-import/import/walk.d.ts +207 -0
  124. package/dist/taco/figma-import/import/walk.js +1464 -0
  125. package/dist/taco/figma-import/index.d.ts +22 -0
  126. package/dist/taco/figma-import/index.js +13 -0
  127. package/dist/taco/figma-import/kiwi/byteReader.d.ts +37 -0
  128. package/dist/taco/figma-import/kiwi/byteReader.js +151 -0
  129. package/dist/taco/figma-import/kiwi/error.d.ts +14 -0
  130. package/dist/taco/figma-import/kiwi/error.js +29 -0
  131. package/dist/taco/figma-import/kiwi/limits.d.ts +18 -0
  132. package/dist/taco/figma-import/kiwi/limits.js +18 -0
  133. package/dist/taco/figma-import/kiwi/message.d.ts +12 -0
  134. package/dist/taco/figma-import/kiwi/message.js +147 -0
  135. package/dist/taco/figma-import/kiwi/schema.d.ts +42 -0
  136. package/dist/taco/figma-import/kiwi/schema.js +206 -0
  137. package/dist/taco/figma-import/kiwi/types.d.ts +46 -0
  138. package/dist/taco/figma-import/kiwi/types.js +18 -0
  139. package/dist/taco/model/agent-hidden-fields.d.ts +20 -0
  140. package/dist/taco/model/agent-hidden-fields.js +29 -0
  141. package/dist/taco/model/asset-users.d.ts +23 -0
  142. package/dist/taco/model/asset-users.js +128 -0
  143. package/dist/taco/model/auto-layout-lines.d.ts +32 -0
  144. package/dist/taco/model/auto-layout-lines.js +70 -0
  145. package/dist/taco/model/codec.d.ts +444 -0
  146. package/dist/taco/model/codec.js +5665 -0
  147. package/dist/taco/model/color.d.ts +11 -0
  148. package/dist/taco/model/color.js +61 -0
  149. package/dist/taco/model/comment-operations.d.ts +102 -0
  150. package/dist/taco/model/comment-operations.js +227 -0
  151. package/dist/taco/model/component-evaluation.d.ts +96 -0
  152. package/dist/taco/model/component-evaluation.js +555 -0
  153. package/dist/taco/model/component-expressions.d.ts +242 -0
  154. package/dist/taco/model/component-expressions.js +1082 -0
  155. package/dist/taco/model/component-properties.d.ts +111 -0
  156. package/dist/taco/model/component-properties.js +339 -0
  157. package/dist/taco/model/component-samples.d.ts +83 -0
  158. package/dist/taco/model/component-samples.js +290 -0
  159. package/dist/taco/model/component-validity.d.ts +85 -0
  160. package/dist/taco/model/component-validity.js +397 -0
  161. package/dist/taco/model/components.d.ts +155 -0
  162. package/dist/taco/model/components.js +505 -0
  163. package/dist/taco/model/connector-ends.d.ts +20 -0
  164. package/dist/taco/model/connector-ends.js +188 -0
  165. package/dist/taco/model/connector-geometry.d.ts +74 -0
  166. package/dist/taco/model/connector-geometry.js +293 -0
  167. package/dist/taco/model/corner-radii.d.ts +26 -0
  168. package/dist/taco/model/corner-radii.js +47 -0
  169. package/dist/taco/model/derivations.d.ts +81 -0
  170. package/dist/taco/model/derivations.js +151 -0
  171. package/dist/taco/model/export-settings.d.ts +53 -0
  172. package/dist/taco/model/export-settings.js +156 -0
  173. package/dist/taco/model/expressions/ast.d.ts +153 -0
  174. package/dist/taco/model/expressions/ast.js +6 -0
  175. package/dist/taco/model/expressions/cache.d.ts +23 -0
  176. package/dist/taco/model/expressions/cache.js +43 -0
  177. package/dist/taco/model/expressions/check.d.ts +72 -0
  178. package/dist/taco/model/expressions/check.js +517 -0
  179. package/dist/taco/model/expressions/completion.d.ts +61 -0
  180. package/dist/taco/model/expressions/completion.js +421 -0
  181. package/dist/taco/model/expressions/evaluate.d.ts +32 -0
  182. package/dist/taco/model/expressions/evaluate.js +519 -0
  183. package/dist/taco/model/expressions/forms.d.ts +84 -0
  184. package/dist/taco/model/expressions/forms.js +200 -0
  185. package/dist/taco/model/expressions/index.d.ts +14 -0
  186. package/dist/taco/model/expressions/index.js +17 -0
  187. package/dist/taco/model/expressions/lexer.d.ts +42 -0
  188. package/dist/taco/model/expressions/lexer.js +213 -0
  189. package/dist/taco/model/expressions/library.d.ts +33 -0
  190. package/dist/taco/model/expressions/library.js +117 -0
  191. package/dist/taco/model/expressions/names.d.ts +43 -0
  192. package/dist/taco/model/expressions/names.js +99 -0
  193. package/dist/taco/model/expressions/parser.d.ts +15 -0
  194. package/dist/taco/model/expressions/parser.js +438 -0
  195. package/dist/taco/model/expressions/rename.d.ts +34 -0
  196. package/dist/taco/model/expressions/rename.js +46 -0
  197. package/dist/taco/model/expressions/source.d.ts +15 -0
  198. package/dist/taco/model/expressions/source.js +161 -0
  199. package/dist/taco/model/expressions/types.d.ts +119 -0
  200. package/dist/taco/model/expressions/types.js +102 -0
  201. package/dist/taco/model/expressions/values.d.ts +97 -0
  202. package/dist/taco/model/expressions/values.js +160 -0
  203. package/dist/taco/model/geometry-limits.d.ts +16 -0
  204. package/dist/taco/model/geometry-limits.js +67 -0
  205. package/dist/taco/model/geometry.d.ts +47 -0
  206. package/dist/taco/model/geometry.js +193 -0
  207. package/dist/taco/model/group-bounds.d.ts +38 -0
  208. package/dist/taco/model/group-bounds.js +144 -0
  209. package/dist/taco/model/id-table.d.ts +37 -0
  210. package/dist/taco/model/id-table.js +80 -0
  211. package/dist/taco/model/index.d.ts +25 -0
  212. package/dist/taco/model/index.js +27 -0
  213. package/dist/taco/model/instance-resolver.d.ts +376 -0
  214. package/dist/taco/model/instance-resolver.js +1778 -0
  215. package/dist/taco/model/layer-syntax.d.ts +340 -0
  216. package/dist/taco/model/layer-syntax.js +3506 -0
  217. package/dist/taco/model/layout/constraints.d.ts +84 -0
  218. package/dist/taco/model/layout/constraints.js +445 -0
  219. package/dist/taco/model/layout/frame-layout.d.ts +46 -0
  220. package/dist/taco/model/layout/frame-layout.js +618 -0
  221. package/dist/taco/model/layout/node-sizing.d.ts +163 -0
  222. package/dist/taco/model/layout/node-sizing.js +486 -0
  223. package/dist/taco/model/legacy-connector-caps.d.ts +15 -0
  224. package/dist/taco/model/legacy-connector-caps.js +70 -0
  225. package/dist/taco/model/linear-call.d.ts +48 -0
  226. package/dist/taco/model/linear-call.js +58 -0
  227. package/dist/taco/model/new-nodes.d.ts +145 -0
  228. package/dist/taco/model/new-nodes.js +277 -0
  229. package/dist/taco/model/node-builder.d.ts +449 -0
  230. package/dist/taco/model/node-builder.js +2294 -0
  231. package/dist/taco/model/node-table-watch.d.ts +36 -0
  232. package/dist/taco/model/node-table-watch.js +63 -0
  233. package/dist/taco/model/node-transform.d.ts +39 -0
  234. package/dist/taco/model/node-transform.js +79 -0
  235. package/dist/taco/model/node-users-index.d.ts +10 -0
  236. package/dist/taco/model/node-users-index.js +82 -0
  237. package/dist/taco/model/operation-references.d.ts +80 -0
  238. package/dist/taco/model/operation-references.js +399 -0
  239. package/dist/taco/model/operations.d.ts +610 -0
  240. package/dist/taco/model/operations.js +2882 -0
  241. package/dist/taco/model/overlay-table.d.ts +71 -0
  242. package/dist/taco/model/overlay-table.js +171 -0
  243. package/dist/taco/model/override-remap.d.ts +69 -0
  244. package/dist/taco/model/override-remap.js +230 -0
  245. package/dist/taco/model/parent-table.d.ts +53 -0
  246. package/dist/taco/model/parent-table.js +193 -0
  247. package/dist/taco/model/problem-collector.d.ts +27 -0
  248. package/dist/taco/model/problem-collector.js +101 -0
  249. package/dist/taco/model/sha256.d.ts +10 -0
  250. package/dist/taco/model/sha256.js +79 -0
  251. package/dist/taco/model/shape-geometry.d.ts +96 -0
  252. package/dist/taco/model/shape-geometry.js +368 -0
  253. package/dist/taco/model/shared-node-table.d.ts +97 -0
  254. package/dist/taco/model/shared-node-table.js +546 -0
  255. package/dist/taco/model/slots.d.ts +113 -0
  256. package/dist/taco/model/slots.js +281 -0
  257. package/dist/taco/model/stroke-settings.d.ts +37 -0
  258. package/dist/taco/model/stroke-settings.js +90 -0
  259. package/dist/taco/model/svg-path-import.d.ts +89 -0
  260. package/dist/taco/model/svg-path-import.js +219 -0
  261. package/dist/taco/model/text-measurement.d.ts +142 -0
  262. package/dist/taco/model/text-measurement.js +846 -0
  263. package/dist/taco/model/text-reads.d.ts +66 -0
  264. package/dist/taco/model/text-reads.js +128 -0
  265. package/dist/taco/model/text-sizer.d.ts +358 -0
  266. package/dist/taco/model/text-sizer.js +996 -0
  267. package/dist/taco/model/theme-users.d.ts +59 -0
  268. package/dist/taco/model/theme-users.js +312 -0
  269. package/dist/taco/model/thumbnail.d.ts +15 -0
  270. package/dist/taco/model/thumbnail.js +34 -0
  271. package/dist/taco/model/types.d.ts +2369 -0
  272. package/dist/taco/model/types.js +366 -0
  273. package/dist/taco/model/unknown-property.d.ts +5 -0
  274. package/dist/taco/model/unknown-property.js +7 -0
  275. package/dist/taco/model/validated-documents.d.ts +22 -0
  276. package/dist/taco/model/validated-documents.js +22 -0
  277. package/dist/taco/model/variable-modes.d.ts +61 -0
  278. package/dist/taco/model/variable-modes.js +438 -0
  279. package/dist/taco/model/variable-references.d.ts +54 -0
  280. package/dist/taco/model/variable-references.js +183 -0
  281. package/dist/taco/model/variables.d.ts +24 -0
  282. package/dist/taco/model/variables.js +151 -0
  283. package/dist/taco/model/vector-network.d.ts +34 -0
  284. package/dist/taco/model/vector-network.js +411 -0
  285. package/dist/taco/svg-import/import-svg.d.ts +36 -0
  286. package/dist/taco/svg-import/import-svg.js +729 -0
  287. package/dist/taco/svg-import/index.d.ts +3 -0
  288. package/dist/taco/svg-import/index.js +3 -0
  289. package/dist/taco/svg-import/limits/limits.d.ts +79 -0
  290. package/dist/taco/svg-import/limits/limits.js +160 -0
  291. package/dist/taco/svg-import/paint/gradients.d.ts +64 -0
  292. package/dist/taco/svg-import/paint/gradients.js +429 -0
  293. package/dist/taco/svg-import/paint/paint.d.ts +32 -0
  294. package/dist/taco/svg-import/paint/paint.js +162 -0
  295. package/dist/taco/svg-import/paths/paths.d.ts +58 -0
  296. package/dist/taco/svg-import/paths/paths.js +205 -0
  297. package/dist/taco/svg-import/public-types.d.ts +279 -0
  298. package/dist/taco/svg-import/public-types.js +56 -0
  299. package/dist/taco/svg-import/report/report.d.ts +44 -0
  300. package/dist/taco/svg-import/report/report.js +79 -0
  301. package/dist/taco/svg-import/reuse/reuse.d.ts +99 -0
  302. package/dist/taco/svg-import/reuse/reuse.js +840 -0
  303. package/dist/taco/svg-import/shapes/shapes.d.ts +35 -0
  304. package/dist/taco/svg-import/shapes/shapes.js +386 -0
  305. package/dist/taco/svg-import/structure/effects.d.ts +26 -0
  306. package/dist/taco/svg-import/structure/effects.js +618 -0
  307. package/dist/taco/svg-import/structure/image.d.ts +24 -0
  308. package/dist/taco/svg-import/structure/image.js +495 -0
  309. package/dist/taco/svg-import/structure/walk.d.ts +85 -0
  310. package/dist/taco/svg-import/structure/walk.js +544 -0
  311. package/dist/taco/svg-import/style/color.d.ts +40 -0
  312. package/dist/taco/svg-import/style/color.js +275 -0
  313. package/dist/taco/svg-import/style/computed.d.ts +214 -0
  314. package/dist/taco/svg-import/style/computed.js +1534 -0
  315. package/dist/taco/svg-import/style/css.d.ts +127 -0
  316. package/dist/taco/svg-import/style/css.js +541 -0
  317. package/dist/taco/svg-import/style/media.d.ts +25 -0
  318. package/dist/taco/svg-import/style/media.js +307 -0
  319. package/dist/taco/svg-import/style/properties.d.ts +43 -0
  320. package/dist/taco/svg-import/style/properties.js +135 -0
  321. package/dist/taco/svg-import/style/selector-reach.d.ts +30 -0
  322. package/dist/taco/svg-import/style/selector-reach.js +169 -0
  323. package/dist/taco/svg-import/style/selector-validity.d.ts +14 -0
  324. package/dist/taco/svg-import/style/selector-validity.js +307 -0
  325. package/dist/taco/svg-import/text/text.d.ts +29 -0
  326. package/dist/taco/svg-import/text/text.js +545 -0
  327. package/dist/taco/svg-import/transform/matrix.d.ts +111 -0
  328. package/dist/taco/svg-import/transform/matrix.js +229 -0
  329. package/dist/taco/svg-import/tree/element-data.d.ts +52 -0
  330. package/dist/taco/svg-import/tree/element-data.js +155 -0
  331. package/dist/taco/svg-import/tree/elements.d.ts +36 -0
  332. package/dist/taco/svg-import/tree/elements.js +121 -0
  333. package/dist/taco/svg-import/units/length.d.ts +43 -0
  334. package/dist/taco/svg-import/units/length.js +125 -0
  335. package/dist/taco/svg-import/units/viewbox.d.ts +35 -0
  336. package/dist/taco/svg-import/units/viewbox.js +77 -0
  337. package/package.json +55 -4
@@ -0,0 +1,519 @@
1
+ // The evaluator (docs/components/design.md 8.4 "Defined results instead of
2
+ // runtime errors", 8.6). It runs a checked expression against the values of
3
+ // the component's properties, the document's variables and the stored base
4
+ // value, and always gives a value: division by zero gives 0, a result that is
5
+ // not finite becomes 0, amounts and colour channels are held in 0 to 1, and
6
+ // sizes, padding, radii, stroke widths and blurs inside a value stay at 0 or more,
7
+ // and text sizes and line heights at 1 px or more.
8
+ // Every part of the expression is visited at most once.
9
+ import { linearEndpoints } from "../linear-call.js";
10
+ import { EXPRESSION_LIBRARY, expressionSignatureAccepts } from "./library.js";
11
+ import { parseExpression } from "./parser.js";
12
+ import { expressionColorToHex, expressionValuesEqual, zeroExpressionValue } from "./values.js";
13
+ /**
14
+ * Evaluates an expression that has passed the check. It never throws for
15
+ * such an expression when the environment holds every property, variable
16
+ * and stored value the checking environment typed; a missing one is a
17
+ * programming error and throws, since a wrong value would be a silent
18
+ * failure.
19
+ */
20
+ export function evaluateExpression(expression, environment) {
21
+ return new Evaluator(environment).evaluate(expression);
22
+ }
23
+ /** 0 for a number that is not finite (from very large values or 0 / 0); negative zero is plain 0. */
24
+ export function finiteExpressionNumber(value) {
25
+ return Number.isFinite(value) ? value + 0 : 0;
26
+ }
27
+ /** A number held between 0 and 1: what amounts and colour channels become. */
28
+ export function clampExpressionAmount(value) {
29
+ return Math.min(1, Math.max(0, finiteExpressionNumber(value)));
30
+ }
31
+ function num(kind, value) {
32
+ return { kind, value: finiteExpressionNumber(value) };
33
+ }
34
+ function color(red, green, blue, alpha) {
35
+ return {
36
+ kind: "color",
37
+ value: {
38
+ red: clampExpressionAmount(red),
39
+ green: clampExpressionAmount(green),
40
+ blue: clampExpressionAmount(blue),
41
+ alpha: clampExpressionAmount(alpha),
42
+ },
43
+ };
44
+ }
45
+ // OKLCH, after Björn Ottosson's OKLab: equal steps in lightness look equally different.
46
+ function toLinear(channel) {
47
+ return channel <= 0.04045 ? channel / 12.92 : ((channel + 0.055) / 1.055) ** 2.4;
48
+ }
49
+ function fromLinear(channel) {
50
+ return channel <= 0.0031308 ? 12.92 * channel : 1.055 * channel ** (1 / 2.4) - 0.055;
51
+ }
52
+ function toOklab(c) {
53
+ const r = toLinear(c.red);
54
+ const g = toLinear(c.green);
55
+ const b = toLinear(c.blue);
56
+ const l = Math.cbrt(0.4122214708 * r + 0.5363325363 * g + 0.0514459929 * b);
57
+ const m = Math.cbrt(0.2119034982 * r + 0.6806995451 * g + 0.1073969566 * b);
58
+ const s = Math.cbrt(0.0883024619 * r + 0.2817188376 * g + 0.6299787005 * b);
59
+ return [
60
+ 0.2104542553 * l + 0.793617785 * m - 0.0040720468 * s,
61
+ 1.9779984951 * l - 2.428592205 * m + 0.4505937099 * s,
62
+ 0.0259040371 * l + 0.7827717662 * m - 0.808675766 * s,
63
+ ];
64
+ }
65
+ function fromOklab(L, a, b, alpha) {
66
+ const l = (L + 0.3963377774 * a + 0.2158037573 * b) ** 3;
67
+ const m = (L - 0.1055613458 * a - 0.0638541728 * b) ** 3;
68
+ const s = (L - 0.0894841775 * a - 1.291485548 * b) ** 3;
69
+ return color(fromLinear(4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s), fromLinear(-1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s), fromLinear(-0.0041960863 * l - 0.7034186147 * m + 1.707614701 * s), alpha);
70
+ }
71
+ /** The colour with its OKLCH lightness moved by `delta` (from -1 to 1), hue and chroma kept. */
72
+ function shiftLightness(c, delta) {
73
+ const [L, a, b] = toOklab(c);
74
+ const lightness = Math.min(1, Math.max(0, L + delta));
75
+ if (lightness <= 0)
76
+ return color(0, 0, 0, c.alpha);
77
+ if (lightness >= 1)
78
+ return color(1, 1, 1, c.alpha);
79
+ return fromOklab(lightness, a, b, c.alpha);
80
+ }
81
+ /** Rounds half away from zero. */
82
+ function roundHalfAway(x) {
83
+ return Math.sign(x) * Math.round(Math.abs(x));
84
+ }
85
+ /** Evenly spaced stops from the first colour to the last. */
86
+ function evenStops(colors) {
87
+ const last = Math.max(1, colors.length - 1);
88
+ return colors.map((c, i) => ({ offset: i / last, color: expressionColorToHex(c.value) }));
89
+ }
90
+ const numbers = (args, ...names) => names.map((n) => args.named.get(n));
91
+ const colors = (args, ...names) => names.map((n) => args.named.get(n).value);
92
+ const text = (args, name) => args.named.get(name).value;
93
+ const length = (args, name) => args.named.get(name).value;
94
+ /** A length the model keeps at 0 or more (sizes, padding, radii, widths, blurs), held there as the panel does. */
95
+ const extent = (args, name) => atLeastZero(length(args, name));
96
+ /** Held at 0 or more; negative zero is plain 0. */
97
+ function atLeastZero(value) {
98
+ return Math.max(0, value) + 0;
99
+ }
100
+ /** A text size or line height held at 1 px or more; the renderer rejects 0. */
101
+ function textExtent(value) {
102
+ return Math.max(1, value);
103
+ }
104
+ /** A font weight held in 1 to 1000, the model's range. */
105
+ function fontWeight(value) {
106
+ return Math.min(1000, Math.max(1, value));
107
+ }
108
+ function shadow(kind) {
109
+ return (args) => {
110
+ const [x, y, blur, spread] = numbers(args, "x", "y", "blur", "spread");
111
+ const [c] = colors(args, "color");
112
+ return {
113
+ kind: "effect",
114
+ value: { kind: "shadow", shadow: { kind, x: x.value, y: y.value, blur: atLeastZero(blur.value), spread: spread.value, color: expressionColorToHex(c) } },
115
+ };
116
+ };
117
+ }
118
+ function blur(kind) {
119
+ return (args) => ({ kind: "effect", value: { kind, radius: extent(args, "radius") } });
120
+ }
121
+ const IMPLEMENTATIONS = {
122
+ min: (args) => {
123
+ const all = [...numbers(args, "a", "b"), ...args.rest];
124
+ return num(all[0].kind, Math.min(...all.map((v) => v.value)));
125
+ },
126
+ max: (args) => {
127
+ const all = [...numbers(args, "a", "b"), ...args.rest];
128
+ return num(all[0].kind, Math.max(...all.map((v) => v.value)));
129
+ },
130
+ clamp: (args) => {
131
+ const [x, low, high] = numbers(args, "x", "low", "high");
132
+ return num(x.kind, Math.min(Math.max(x.value, low.value), Math.max(low.value, high.value)));
133
+ },
134
+ round: (args) => {
135
+ const [x] = numbers(args, "x");
136
+ return num(x.kind, roundHalfAway(x.value));
137
+ },
138
+ floor: (args) => {
139
+ const [x] = numbers(args, "x");
140
+ return num(x.kind, Math.floor(x.value));
141
+ },
142
+ ceil: (args) => {
143
+ const [x] = numbers(args, "x");
144
+ return num(x.kind, Math.ceil(x.value));
145
+ },
146
+ abs: (args) => {
147
+ const [x] = numbers(args, "x");
148
+ return num(x.kind, Math.abs(x.value));
149
+ },
150
+ mix: (args) => {
151
+ const [a, b] = colors(args, "a", "b");
152
+ const t = clampExpressionAmount(numbers(args, "t")[0].value);
153
+ const blend = (x, y) => x + (y - x) * t;
154
+ return color(blend(a.red, b.red), blend(a.green, b.green), blend(a.blue, b.blue), blend(a.alpha, b.alpha));
155
+ },
156
+ with_alpha: (args) => {
157
+ const [c] = colors(args, "color");
158
+ return color(c.red, c.green, c.blue, numbers(args, "alpha")[0].value);
159
+ },
160
+ lighten: (args) => shiftLightness(colors(args, "color")[0], clampExpressionAmount(numbers(args, "amount")[0].value / 100)),
161
+ darken: (args) => shiftLightness(colors(args, "color")[0], -clampExpressionAmount(numbers(args, "amount")[0].value / 100)),
162
+ rgb: (args) => {
163
+ const [r, g, b] = numbers(args, "red", "green", "blue");
164
+ return color(r.value / 255, g.value / 255, b.value / 255, 1);
165
+ },
166
+ rgba: (args) => {
167
+ const [r, g, b, a] = numbers(args, "red", "green", "blue", "alpha");
168
+ return color(r.value / 255, g.value / 255, b.value / 255, a.value);
169
+ },
170
+ text: (args) => {
171
+ const [value, decimals] = numbers(args, "value", "decimals");
172
+ if (decimals === undefined)
173
+ return { kind: "string", value: String(value.value) };
174
+ const places = Math.min(100, Math.max(0, roundHalfAway(decimals.value)));
175
+ return { kind: "string", value: value.value.toFixed(places) };
176
+ },
177
+ upper: (args) => ({ kind: "string", value: text(args, "value").toUpperCase() }),
178
+ lower: (args) => ({ kind: "string", value: text(args, "value").toLowerCase() }),
179
+ point: (args) => ({ kind: "point", x: length(args, "x"), y: length(args, "y") }),
180
+ size: (args) => ({ kind: "size", width: extent(args, "width"), height: extent(args, "height") }),
181
+ insets: (args) => {
182
+ const n = args.named;
183
+ if (n.has("all")) {
184
+ const all = extent(args, "all");
185
+ return { kind: "insets", value: { top: all, right: all, bottom: all, left: all } };
186
+ }
187
+ if (n.has("vertical")) {
188
+ const vertical = extent(args, "vertical");
189
+ const horizontal = extent(args, "horizontal");
190
+ return { kind: "insets", value: { top: vertical, right: horizontal, bottom: vertical, left: horizontal } };
191
+ }
192
+ return {
193
+ kind: "insets",
194
+ value: { top: extent(args, "top"), right: extent(args, "right"), bottom: extent(args, "bottom"), left: extent(args, "left") },
195
+ };
196
+ },
197
+ corners: (args) => {
198
+ if (args.named.has("all")) {
199
+ const all = extent(args, "all");
200
+ return { kind: "corners", value: { topLeft: all, topRight: all, bottomRight: all, bottomLeft: all } };
201
+ }
202
+ return {
203
+ kind: "corners",
204
+ value: {
205
+ topLeft: extent(args, "top_left"),
206
+ topRight: extent(args, "top_right"),
207
+ bottomRight: extent(args, "bottom_right"),
208
+ bottomLeft: extent(args, "bottom_left"),
209
+ },
210
+ };
211
+ },
212
+ image: (args) => ({ kind: "paint", value: { kind: "image", assetId: text(args, "asset"), fit: args.named.get("fit").option } }),
213
+ solid: (args) => ({
214
+ kind: "paint",
215
+ value: { kind: "solid", color: expressionColorToHex(colors(args, "color")[0]), opacity: clampExpressionAmount(numbers(args, "opacity")[0].value) },
216
+ }),
217
+ linear: (args, environment) => {
218
+ const box = environment.paintBox?.() ?? { width: 1, height: 1 };
219
+ return { kind: "paint", value: { kind: "linear-gradient", ...linearEndpoints(length(args, "angle"), box),
220
+ stops: evenStops([args.named.get("from"), args.named.get("to"), ...args.rest]) } };
221
+ },
222
+ radial: (args) => ({
223
+ kind: "paint",
224
+ value: { kind: "radial-gradient", stops: evenStops([args.named.get("from"), args.named.get("to"), ...args.rest]) },
225
+ }),
226
+ angular: (args) => ({
227
+ kind: "paint",
228
+ value: { kind: "angular-gradient", angle: length(args, "angle"), stops: evenStops([args.named.get("from"), args.named.get("to"), ...args.rest]) },
229
+ }),
230
+ stroke: (args) => ({
231
+ kind: "stroke",
232
+ value: {
233
+ paint: args.named.get("paint").value,
234
+ width: extent(args, "width"),
235
+ position: args.named.get("align").option,
236
+ },
237
+ }),
238
+ shadow: shadow("drop"),
239
+ inner_shadow: shadow("inner"),
240
+ layer_blur: blur("layer_blur"),
241
+ background_blur: blur("background_blur"),
242
+ text_style: (args) => ({
243
+ kind: "text_style",
244
+ value: {
245
+ fontFamily: text(args, "family"),
246
+ fontWeight: fontWeight(numbers(args, "weight")[0].value),
247
+ fontSize: textExtent(length(args, "size")),
248
+ lineHeightPixels: textExtent(length(args, "line_height")),
249
+ letterSpacing: length(args, "letter_spacing"),
250
+ },
251
+ }),
252
+ };
253
+ /** Default argument values, evaluated once from the source text the library stores. */
254
+ const DEFAULTS = new Map();
255
+ function defaultValue(source, type) {
256
+ let value = DEFAULTS.get(source);
257
+ if (value === undefined) {
258
+ const parsed = parseExpression(source);
259
+ value = parsed.ok ? new Evaluator(EMPTY_ENVIRONMENT).evaluate(parsed.expression) : zeroExpressionValue(type);
260
+ DEFAULTS.set(source, value);
261
+ }
262
+ return value;
263
+ }
264
+ const EMPTY_ENVIRONMENT = {
265
+ propertyValue: () => undefined,
266
+ variableValue: () => undefined,
267
+ };
268
+ function missing(what) {
269
+ throw new Error(`Cannot evaluate: ${what} has no value in this environment. Check the expression against the same environment first.`);
270
+ }
271
+ function patternMatches(pattern, subject) {
272
+ if (pattern.kind === "boolean")
273
+ return subject.kind === "boolean" && subject.value === pattern.value;
274
+ return subject.kind === "enum" && subject.option === pattern.name;
275
+ }
276
+ class Evaluator {
277
+ scopes = [];
278
+ environment;
279
+ constructor(environment) {
280
+ this.environment = environment;
281
+ }
282
+ evaluate(expression) {
283
+ switch (expression.kind) {
284
+ case "boolean":
285
+ return { kind: "boolean", value: expression.value };
286
+ case "number":
287
+ return num(expression.unit === "px" ? "length" : expression.unit === "%" ? "percent" : expression.unit === "deg" ? "angle" : "number", expression.value);
288
+ case "string":
289
+ return { kind: "string", value: expression.value };
290
+ case "color":
291
+ return { kind: "color", value: expression.value };
292
+ case "option":
293
+ return { kind: "enum", option: expression.name };
294
+ case "name": {
295
+ for (let i = this.scopes.length - 1; i >= 0; i -= 1) {
296
+ const local = this.scopes[i].get(expression.name);
297
+ if (local !== undefined)
298
+ return local;
299
+ }
300
+ return this.environment.propertyValue(expression.name) ?? missing(`the property \`${expression.name}\``);
301
+ }
302
+ case "stored":
303
+ return this.environment.stored ?? missing("`stored`");
304
+ case "variable":
305
+ return this.environment.variableValue(expression.name) ?? missing(`the variable \`${expression.name}\``);
306
+ case "call":
307
+ return this.call(expression.callee, expression.args);
308
+ case "list":
309
+ return { kind: "list", items: expression.items.map((item) => this.evaluate(item)) };
310
+ case "field":
311
+ return this.field(this.evaluate(expression.target), expression.name);
312
+ case "with": {
313
+ let value = this.evaluate(expression.target);
314
+ for (const update of expression.updates)
315
+ value = this.withField(value, update.name, this.evaluate(update.value));
316
+ return value;
317
+ }
318
+ case "unary": {
319
+ const operand = this.evaluate(expression.operand);
320
+ if (expression.operator === "not")
321
+ return { kind: "boolean", value: !operand.value };
322
+ const n = operand;
323
+ return num(n.kind, -n.value);
324
+ }
325
+ case "binary":
326
+ return this.binary(expression);
327
+ case "if":
328
+ return this.evaluate(expression.condition).value ? this.evaluate(expression.then) : this.evaluate(expression.else);
329
+ case "let": {
330
+ const value = this.evaluate(expression.value);
331
+ this.scopes.push(new Map([[expression.name, value]]));
332
+ try {
333
+ return this.evaluate(expression.body);
334
+ }
335
+ finally {
336
+ this.scopes.pop();
337
+ }
338
+ }
339
+ case "match": {
340
+ const subject = this.evaluate(expression.subject);
341
+ for (const arm of expression.arms) {
342
+ if (arm.patterns.some((pattern) => patternMatches(pattern, subject)))
343
+ return this.evaluate(arm.body);
344
+ }
345
+ if (expression.otherwise !== undefined)
346
+ return this.evaluate(expression.otherwise);
347
+ return missing(`the \`match\` arm for ${subject.kind === "enum" ? `.${subject.option}` : String(subject.value)}`);
348
+ }
349
+ }
350
+ }
351
+ binary(expression) {
352
+ const { operator } = expression;
353
+ if (operator === "and" || operator === "or") {
354
+ const left = this.evaluate(expression.left).value;
355
+ if (operator === "and" ? !left : left)
356
+ return { kind: "boolean", value: left };
357
+ return this.evaluate(expression.right);
358
+ }
359
+ const left = this.evaluate(expression.left);
360
+ const right = this.evaluate(expression.right);
361
+ switch (operator) {
362
+ case "==":
363
+ return { kind: "boolean", value: expressionValuesEqual(left, right) };
364
+ case "!=":
365
+ return { kind: "boolean", value: !expressionValuesEqual(left, right) };
366
+ case "++":
367
+ return { kind: "string", value: left.value + right.value };
368
+ }
369
+ const a = left;
370
+ const b = right;
371
+ switch (operator) {
372
+ case "<":
373
+ return { kind: "boolean", value: a.value < b.value };
374
+ case "<=":
375
+ return { kind: "boolean", value: a.value <= b.value };
376
+ case ">":
377
+ return { kind: "boolean", value: a.value > b.value };
378
+ case ">=":
379
+ return { kind: "boolean", value: a.value >= b.value };
380
+ case "+":
381
+ return num(a.kind, a.value + b.value);
382
+ case "-":
383
+ return num(a.kind, a.value - b.value);
384
+ case "*":
385
+ return num(a.kind === "number" ? b.kind : a.kind, a.value * b.value);
386
+ case "/": {
387
+ const kind = a.kind === b.kind ? "number" : a.kind;
388
+ return b.value === 0 ? num(kind, 0) : num(kind, a.value / b.value);
389
+ }
390
+ }
391
+ }
392
+ call(callee, args) {
393
+ const fn = EXPRESSION_LIBRARY[callee] ?? missing(`the function \`${callee}\``);
394
+ const positional = args.filter((a) => a.name === undefined);
395
+ const namedArgs = args.filter((a) => a.name !== undefined);
396
+ const names = new Set(namedArgs.map((a) => a.name));
397
+ // Overloads with one shape differ only by numeric type, and the values carry their own kind.
398
+ const signature = fn.overloads.find((o) => expressionSignatureAccepts(o, positional.length, names)) ?? missing(`a form of \`${callee}\` for these arguments`);
399
+ const named = new Map();
400
+ const rest = [];
401
+ for (const [i, arg] of positional.entries()) {
402
+ const parameter = signature.parameters[i];
403
+ if (parameter === undefined)
404
+ rest.push(this.evaluate(arg.value));
405
+ else
406
+ named.set(parameter.name, this.evaluate(arg.value));
407
+ }
408
+ for (const arg of namedArgs)
409
+ named.set(arg.name, this.evaluate(arg.value));
410
+ for (const parameter of signature.parameters) {
411
+ if (!named.has(parameter.name))
412
+ named.set(parameter.name, defaultValue(parameter.defaultSource ?? "", parameter.type));
413
+ }
414
+ return IMPLEMENTATIONS[callee]({ named, rest }, this.environment);
415
+ }
416
+ field(target, name) {
417
+ switch (target.kind) {
418
+ case "color":
419
+ return num("number", target.value[name]);
420
+ case "point":
421
+ return num("length", name === "x" ? target.x : target.y);
422
+ case "size":
423
+ return num("length", name === "width" ? target.width : target.height);
424
+ case "insets":
425
+ return num("length", target.value[name]);
426
+ case "corners":
427
+ return num("length", target.value[CORNER_FIELDS[name] ?? "topLeft"]);
428
+ case "paint":
429
+ return name === "visible" ? { kind: "boolean", value: target.value.visible ?? true } : num("number", target.value.opacity ?? 1);
430
+ case "stroke":
431
+ if (name === "paint")
432
+ return { kind: "paint", value: target.value.paint };
433
+ if (name === "width")
434
+ return num("length", target.value.width);
435
+ if (name === "join")
436
+ return { kind: "enum", option: target.value.join ?? "miter" };
437
+ if (name === "miter_angle")
438
+ return num("angle", target.value.miterAngle ?? 28.95502437185985);
439
+ if (name === "dash_cap")
440
+ return { kind: "enum", option: target.value.dashCap ?? "none" };
441
+ if (name === "dash")
442
+ return { kind: "list", items: (target.value.dash ?? []).map((value) => num("length", value)) };
443
+ if (name === "sides")
444
+ return { kind: "insets", value: target.value.sides ?? { top: target.value.width, right: target.value.width, bottom: target.value.width, left: target.value.width } };
445
+ return { kind: "enum", option: target.value.position ?? "center" };
446
+ case "text_style":
447
+ switch (name) {
448
+ case "family":
449
+ return { kind: "string", value: target.value.fontFamily };
450
+ case "weight":
451
+ return num("number", target.value.fontWeight);
452
+ case "size":
453
+ return num("length", target.value.fontSize);
454
+ case "line_height":
455
+ return num("length", target.value.lineHeightPixels);
456
+ default:
457
+ return num("length", target.value.letterSpacing);
458
+ }
459
+ default:
460
+ return missing(`the field \`${name}\` of a \`${target.kind}\``);
461
+ }
462
+ }
463
+ withField(target, name, value) {
464
+ const n = value.value;
465
+ switch (target.kind) {
466
+ case "color":
467
+ return { kind: "color", value: { ...target.value, [name]: clampExpressionAmount(n) } };
468
+ case "point":
469
+ return { ...target, [name]: n };
470
+ case "size":
471
+ return { ...target, [name]: atLeastZero(n) };
472
+ case "insets":
473
+ return { kind: "insets", value: { ...target.value, [name]: atLeastZero(n) } };
474
+ case "corners":
475
+ return { kind: "corners", value: { ...target.value, [CORNER_FIELDS[name] ?? "topLeft"]: atLeastZero(n) } };
476
+ case "paint":
477
+ return name === "visible"
478
+ ? { kind: "paint", value: { ...target.value, visible: value.value } }
479
+ : { kind: "paint", value: { ...target.value, opacity: clampExpressionAmount(n) } };
480
+ case "stroke":
481
+ if (name === "paint")
482
+ return { kind: "stroke", value: { ...target.value, paint: value.value } };
483
+ if (name === "width")
484
+ return { kind: "stroke", value: { ...target.value, width: atLeastZero(n) } };
485
+ if (name === "join")
486
+ return { kind: "stroke", value: { ...target.value, join: value.option } };
487
+ if (name === "miter_angle")
488
+ return { kind: "stroke", value: { ...target.value, miterAngle: Math.min(180, Math.max(Number.EPSILON, n)) } };
489
+ if (name === "dash_cap")
490
+ return { kind: "stroke", value: { ...target.value, dashCap: value.option } };
491
+ if (name === "dash" && value.kind === "list")
492
+ return { kind: "stroke", value: { ...target.value, dash: value.items.map((item) => atLeastZero(item.value)) } };
493
+ if (name === "sides" && value.kind === "insets")
494
+ return { kind: "stroke", value: { ...target.value, sides: value.value } };
495
+ return { kind: "stroke", value: { ...target.value, position: value.option } };
496
+ case "text_style":
497
+ switch (name) {
498
+ case "family":
499
+ return { kind: "text_style", value: { ...target.value, fontFamily: value.value } };
500
+ case "weight":
501
+ return { kind: "text_style", value: { ...target.value, fontWeight: fontWeight(n) } };
502
+ case "size":
503
+ return { kind: "text_style", value: { ...target.value, fontSize: textExtent(n) } };
504
+ case "line_height":
505
+ return { kind: "text_style", value: { ...target.value, lineHeightPixels: textExtent(n) } };
506
+ default:
507
+ return { kind: "text_style", value: { ...target.value, letterSpacing: n } };
508
+ }
509
+ default:
510
+ return missing(`the field \`${name}\` of a \`${target.kind}\``);
511
+ }
512
+ }
513
+ }
514
+ const CORNER_FIELDS = {
515
+ top_left: "topLeft",
516
+ top_right: "topRight",
517
+ bottom_right: "bottomRight",
518
+ bottom_left: "bottomLeft",
519
+ };
@@ -0,0 +1,84 @@
1
+ import type { Expression } from "./ast.ts";
2
+ import type { ExpressionEnvironment } from "./check.ts";
3
+ import type { ExpressionEnumType } from "./types.ts";
4
+ /** What a value table varies by: an enum property's options, or a boolean's on and off. */
5
+ export type ValueTableSubject = {
6
+ readonly kind: "enum";
7
+ readonly type: ExpressionEnumType;
8
+ } | {
9
+ readonly kind: "boolean";
10
+ };
11
+ /** One row of a value table. */
12
+ export interface ValueTableRow {
13
+ /** The option name, or `"true"` / `"false"` for a boolean. */
14
+ readonly key: string;
15
+ /** What the row shows: the option name, or "on" / "off". */
16
+ readonly label: string;
17
+ /** The row's constant as source text; absent when the `match` has no arm for it yet. */
18
+ readonly source?: string;
19
+ }
20
+ /** A value table read from source text: one row per option, in the property's option order. */
21
+ export interface ExpressionValueTable {
22
+ /** The property the table varies by. */
23
+ readonly property: string;
24
+ readonly subject: ValueTableSubject;
25
+ readonly rows: readonly ValueTableRow[];
26
+ }
27
+ /** The rows a value table over this subject has, without values. */
28
+ export declare function valueTableKeys(subject: ValueTableSubject): readonly {
29
+ readonly key: string;
30
+ readonly label: string;
31
+ }[];
32
+ /** The subject for a property, or undefined when a table cannot vary by it (it is not an enum or boolean). */
33
+ export declare function valueTableSubject(property: string, environment: ExpressionEnvironment): ValueTableSubject | undefined;
34
+ /** True when the expression reads nothing that changes with property values: no property, `stored`, `if`, `let` or `match`. */
35
+ export declare function isConstantExpression(expression: Expression): boolean;
36
+ /**
37
+ * Recognises a value table: a `match` on one enum or boolean property,
38
+ * one pattern per arm, no `else`, every arm a constant. Rows follow the
39
+ * property's option order ("on" before "off"); an option the `match` does
40
+ * not cover yet (added to the enum later) is a row without `source`.
41
+ * Returns undefined for anything else, which the editor shows as an
42
+ * expression.
43
+ */
44
+ export declare function readValueTable(source: string, environment: ExpressionEnvironment): ExpressionValueTable | undefined;
45
+ /**
46
+ * Writes a value table as a `match`, one arm per row in row order; rows
47
+ * without `source` are left out. It fits on one line when short enough,
48
+ * as in `match size { .small => 4px, .large => 8px }`, and otherwise puts
49
+ * each arm on its own line.
50
+ */
51
+ export declare function writeValueTable(table: Pick<ExpressionValueTable, "property" | "subject" | "rows">): string;
52
+ /** A new value table over the property with every row holding `rowSource`, the field's current value. */
53
+ export declare function startValueTable(property: string, subject: ValueTableSubject, rowSource: string): string;
54
+ /**
55
+ * Replaces one row's constant. A row that is already written is replaced
56
+ * in place, so the rest of the text (comments, line breaks) stays; a row
57
+ * the `match` does not cover yet is added by writing the table again.
58
+ * Throws when `source` is not a value table or `key` is not one of its
59
+ * rows: the caller only offers rows of a table it read.
60
+ */
61
+ export declare function setValueTableRow(source: string, environment: ExpressionEnvironment, key: string, rowSource: string): string;
62
+ /** A "Show when" condition in one of the forms of design 8.8. */
63
+ export type ShowWhenCondition =
64
+ /** `showIcon` (on) or `not showIcon` (off). */
65
+ {
66
+ readonly kind: "boolean";
67
+ readonly property: string;
68
+ readonly on: boolean;
69
+ }
70
+ /** `size == .large`, or `size == .small or size == .medium` for several options. */
71
+ | {
72
+ readonly kind: "enum";
73
+ readonly property: string;
74
+ readonly options: readonly string[];
75
+ };
76
+ /**
77
+ * Recognises a "Show when" condition: `showIcon`, `not showIcon`,
78
+ * `size == .large`, or `size == .a or size == .b ...` with one property,
79
+ * known options and no option twice. Options come back in the order
80
+ * written. Returns undefined for anything else.
81
+ */
82
+ export declare function readShowWhen(source: string, environment: ExpressionEnvironment): ShowWhenCondition | undefined;
83
+ /** Writes a "Show when" condition. Throws for an enum condition without options, which would never show the layer. */
84
+ export declare function writeShowWhen(condition: ShowWhenCondition): string;