@metamorph-labs/polymorph 1.0.18 → 1.0.19

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 (319) hide show
  1. package/CHANGELOG.md +242 -0
  2. package/dist/design/systems/desktop.json +1 -1
  3. package/dist/design/systems/dew.json +1 -1
  4. package/dist/design/systems/flint.json +1 -1
  5. package/dist/design/systems/glassmorphic.json +1 -1
  6. package/dist/design/systems/harbor.json +1 -1
  7. package/dist/design/systems/journal.json +1 -1
  8. package/dist/design/systems/pastel.json +1 -1
  9. package/dist/design/systems/pebble.json +1 -1
  10. package/dist/design/systems/plain.json +1 -1
  11. package/dist/design/systems/pop.json +1 -1
  12. package/dist/design/systems/press.json +1 -1
  13. package/dist/packages/angular-ui/src/ai/ArtifactPane.ts +15 -4
  14. package/dist/packages/angular-ui/src/ai/PromptInput.ts +3 -1
  15. package/dist/packages/angular-ui/src/archetypes/Dashboard.ts +38 -20
  16. package/dist/packages/angular-ui/src/archetypes/dashboard.states.ts +52 -0
  17. package/dist/packages/angular-ui/src/controls/ColorInput.ts +62 -34
  18. package/dist/packages/angular-ui/src/controls/Combobox.ts +28 -7
  19. package/dist/packages/angular-ui/src/controls/DatePicker.ts +12 -11
  20. package/dist/packages/angular-ui/src/controls/DateRangePicker.ts +22 -17
  21. package/dist/packages/angular-ui/src/controls/DateRangePickerRangeCalendar.ts +3 -2
  22. package/dist/packages/angular-ui/src/controls/FileUpload.ts +18 -12
  23. package/dist/packages/angular-ui/src/controls/FileUploadRow.ts +24 -4
  24. package/dist/packages/angular-ui/src/controls/MultiSelect.ts +49 -12
  25. package/dist/packages/angular-ui/src/controls/NumberInput.ts +27 -3
  26. package/dist/packages/angular-ui/src/controls/PhoneInput.ts +9 -5
  27. package/dist/packages/angular-ui/src/controls/Select.ts +36 -7
  28. package/dist/packages/angular-ui/src/controls/TagInput.ts +61 -7
  29. package/dist/packages/angular-ui/src/controls/TimeInput.ts +15 -1
  30. package/dist/packages/angular-ui/src/controls/select.states.ts +79 -58
  31. package/dist/packages/angular-ui/src/overlays/Command.ts +50 -13
  32. package/dist/packages/angular-ui/src/overlays/CommandPanel.ts +11 -7
  33. package/dist/packages/angular-ui/src/overlays/ToastViewport.ts +1 -1
  34. package/dist/packages/angular-ui/src/structure/CodeBlock.ts +18 -4
  35. package/dist/packages/angular-ui/src/structure/Stat.ts +295 -84
  36. package/dist/packages/angular-ui/src/structure/stat.states.ts +116 -0
  37. package/dist/packages/cli/src/agents.js +4 -3
  38. package/dist/packages/cli/src/apply.js +43 -18
  39. package/dist/packages/cli/src/check.js +4 -0
  40. package/dist/packages/cli/src/cli.js +6 -2
  41. package/dist/packages/cli/src/elements.js +12 -2
  42. package/dist/packages/cli/src/emit.js +43 -8
  43. package/dist/packages/cli/src/readings.js +29 -3
  44. package/dist/packages/cli/src/skills/bridge.js +1197 -0
  45. package/dist/packages/cli/src/skills/facts.js +190 -0
  46. package/dist/packages/cli/src/skills/native.js +1580 -0
  47. package/dist/packages/cli/src/skills/rules.js +199 -0
  48. package/dist/packages/cli/src/skills/runtime.js +1020 -0
  49. package/dist/packages/cli/src/skills/screen-charts.js +334 -0
  50. package/dist/packages/cli/src/skills/screen-chat.js +247 -0
  51. package/dist/packages/cli/src/skills/screen-code.js +565 -0
  52. package/dist/packages/cli/src/skills/screen-rich-text.js +305 -0
  53. package/dist/packages/cli/src/skills/screen.js +378 -0
  54. package/dist/packages/cli/src/skills/setup-packages.js +307 -0
  55. package/dist/packages/cli/src/skills/setup.js +125 -0
  56. package/dist/packages/cli/src/skills/theme-documents.js +351 -0
  57. package/dist/packages/cli/src/skills/theme.js +208 -0
  58. package/dist/packages/cli/src/skills.js +13 -794
  59. package/dist/packages/cli/src/theme.js +42 -1
  60. package/dist/packages/cli/src/tool-verbs.js +19 -4
  61. package/dist/packages/cli/src/verbs.js +28 -2
  62. package/dist/packages/elements-ui/dist/cdn/chunks/{AppShellUserCard-0eCCnnN_.js → AppShellUserCard-XT4br4fr.js} +1 -1
  63. package/dist/packages/elements-ui/dist/cdn/chunks/{AreaChart-DftfzLG0.js → AreaChart-CXNFfbJ8.js} +1 -1
  64. package/dist/packages/elements-ui/dist/cdn/chunks/ArtifactPane-Pr9_K2uM.js +1 -0
  65. package/dist/packages/elements-ui/dist/cdn/chunks/{Avatar-DcdMgxgY.js → Avatar-3WXoBPLv.js} +1 -1
  66. package/dist/packages/elements-ui/dist/cdn/chunks/{Avatar-DcuvZwe7.js → Avatar-BKqjM8qW.js} +1 -1
  67. package/dist/packages/elements-ui/dist/cdn/chunks/{AvatarButton-D5XKVduu.js → AvatarButton-BasMQCSM.js} +1 -1
  68. package/dist/packages/elements-ui/dist/cdn/chunks/{AvatarGroup-DgFwJUNO.js → AvatarGroup-COch2-O0.js} +1 -1
  69. package/dist/packages/elements-ui/dist/cdn/chunks/{BarChart-myuR0aHc.js → BarChart-ugae8zfr.js} +1 -1
  70. package/dist/packages/elements-ui/dist/cdn/chunks/{ChatMessage-CgQ1h_JP.js → ChatMessage-Bx4yrF2x.js} +1 -1
  71. package/dist/packages/elements-ui/dist/cdn/chunks/CodeBlock-B_e5ma3K.js +1 -0
  72. package/dist/packages/elements-ui/dist/cdn/chunks/CodeBlock-Fgtr48Vb.js +1 -0
  73. package/dist/packages/elements-ui/dist/cdn/chunks/ColorInput-CD7rsWRp.js +1 -0
  74. package/dist/packages/elements-ui/dist/cdn/chunks/Combobox-CUw7z6TS.js +1 -0
  75. package/dist/packages/elements-ui/dist/cdn/chunks/{Combobox-DB2FT7so.js → Combobox-hWIFU9X_.js} +1 -1
  76. package/dist/packages/elements-ui/dist/cdn/chunks/Command-BXgqRd3I.js +1 -0
  77. package/dist/packages/elements-ui/dist/cdn/chunks/{ConfirmDialog-BtQOAHY2.js → ConfirmDialog-CAaBRKxl.js} +1 -1
  78. package/dist/packages/elements-ui/dist/cdn/chunks/{Dashboard-ChMPH4_Q.js → Dashboard-DwNw5Wnd.js} +1 -1
  79. package/dist/packages/elements-ui/dist/cdn/chunks/DatePicker-DjqtswQR.js +1 -0
  80. package/dist/packages/elements-ui/dist/cdn/chunks/DateRangePicker-LsXFHOzm.js +1 -0
  81. package/dist/packages/elements-ui/dist/cdn/chunks/{DonutChart-BEK89BeL.js → DonutChart-DYXx6eTe.js} +1 -1
  82. package/dist/packages/elements-ui/dist/cdn/chunks/FileUpload-3gbZTSSx.js +1 -0
  83. package/dist/packages/elements-ui/dist/cdn/chunks/{FormField-PlLLDKqc.js → FormField-Bvw4cLBc.js} +1 -1
  84. package/dist/packages/elements-ui/dist/cdn/chunks/{FormField-C6L3vYp4.js → FormField-DzhcinED.js} +1 -1
  85. package/dist/packages/elements-ui/dist/cdn/chunks/{FunnelChart-DVQz_gad.js → FunnelChart-D24XhrGw.js} +1 -1
  86. package/dist/packages/elements-ui/dist/cdn/chunks/{Heading-fAcu6Vrw.js → Heading-Cvfyu8pc.js} +1 -1
  87. package/dist/packages/elements-ui/dist/cdn/chunks/{Heading-CgzEi9OQ.js → Heading-XDJzlwt9.js} +1 -1
  88. package/dist/packages/elements-ui/dist/cdn/chunks/{Heatmap-BRwR-n-V.js → Heatmap-BQoUS6gY.js} +1 -1
  89. package/dist/packages/elements-ui/dist/cdn/chunks/{Hero-CV2YWeb4.js → Hero-CXuuFceS.js} +1 -1
  90. package/dist/packages/elements-ui/dist/cdn/chunks/{Histogram-CCYwlinB.js → Histogram-DW_ZPHpR.js} +1 -1
  91. package/dist/packages/elements-ui/dist/cdn/chunks/{LineChart-BH6Pq1P1.js → LineChart-kf-zlNWe.js} +1 -1
  92. package/dist/packages/elements-ui/dist/cdn/chunks/{Markdown-DmZEch4i.js → Markdown-C3rjhIbt.js} +1 -1
  93. package/dist/packages/elements-ui/dist/cdn/chunks/ModeSwitch-DQ86CK9h.js +1 -0
  94. package/dist/packages/elements-ui/dist/cdn/chunks/MultiSelect-DbSx9QtV.js +1 -0
  95. package/dist/packages/elements-ui/dist/cdn/chunks/NumberInput-B4ZZOGLl.js +7 -0
  96. package/dist/packages/elements-ui/dist/cdn/chunks/PhoneInput-BsMfbNi6.js +210 -0
  97. package/dist/packages/elements-ui/dist/cdn/chunks/PromptInput-l_-zAXSZ.js +1 -0
  98. package/dist/packages/elements-ui/dist/cdn/chunks/{RadarChart-Coje7Sb0.js → RadarChart-CwJAWRki.js} +1 -1
  99. package/dist/packages/elements-ui/dist/cdn/chunks/{RichTextContent-CufjptHF.js → RichTextContent-D51UfuWk.js} +1 -1
  100. package/dist/packages/elements-ui/dist/cdn/chunks/{RichTextInput-Dz7yBFUA.js → RichTextInput-B32fN_p9.js} +3 -3
  101. package/dist/packages/elements-ui/dist/cdn/chunks/{ScatterChart-Do5tQTC5.js → ScatterChart-Mps7l5-i.js} +1 -1
  102. package/dist/packages/elements-ui/dist/cdn/chunks/Select-CpsRP0NR.js +1 -0
  103. package/dist/packages/elements-ui/dist/cdn/chunks/Stat-CXR6bP7X.js +1 -0
  104. package/dist/packages/elements-ui/dist/cdn/chunks/Stat-DGcx2ZZq.js +1 -0
  105. package/dist/packages/elements-ui/dist/cdn/chunks/TagInput-BhkLU4gE.js +1 -0
  106. package/dist/packages/elements-ui/dist/cdn/chunks/TimeInput-r2jNTOLN.js +1 -0
  107. package/dist/packages/elements-ui/dist/cdn/chunks/{Toast-CAYGbn7g.js → Toast-BTfcZn0I.js} +1 -1
  108. package/dist/packages/elements-ui/dist/cdn/chunks/{ToastViewport-CFslglYc.js → ToastViewport-BBQMRCQT.js} +1 -1
  109. package/dist/packages/elements-ui/dist/cdn/chunks/{ToolCall-DUCoKsoE.js → ToolCall-DNU5kk9_.js} +1 -1
  110. package/dist/packages/elements-ui/dist/cdn/chunks/{Treemap-Bh3ruYGJ.js → Treemap-BV8TlZHB.js} +1 -1
  111. package/dist/packages/elements-ui/dist/cdn/chunks/agent-DfOqpL9c.js +1 -0
  112. package/dist/packages/elements-ui/dist/cdn/chunks/api-DJBiUXxK.js +4 -0
  113. package/dist/packages/elements-ui/dist/cdn/chunks/avatar.module-D4YdFevY.js +1 -0
  114. package/dist/packages/elements-ui/dist/cdn/chunks/cap-DA71oFHt.js +1 -0
  115. package/dist/packages/elements-ui/dist/cdn/chunks/{cartesian-I5uPfyqv.js → cartesian-CEn2lJCc.js} +1 -1
  116. package/dist/packages/elements-ui/dist/cdn/chunks/{chart-annotations.module-xUExw4pu.js → chart-annotations.module-hA_KO_Pe.js} +1 -1
  117. package/dist/packages/elements-ui/dist/cdn/chunks/chart-brush.module-C_8txUW5.js +1 -0
  118. package/dist/packages/elements-ui/dist/cdn/chunks/chart-twin.module-BpfyTQ9R.js +1 -0
  119. package/dist/packages/elements-ui/dist/cdn/chunks/check-CHvc4yHL.js +1 -0
  120. package/dist/packages/elements-ui/dist/cdn/chunks/css-vars-DeZ4TCna.js +1 -0
  121. package/dist/packages/elements-ui/dist/cdn/chunks/draw-BiQ3Of6N.js +1 -0
  122. package/dist/packages/elements-ui/dist/cdn/chunks/drawing-nhJNBahV.js +1 -0
  123. package/dist/packages/elements-ui/dist/cdn/chunks/field-labels-Df5HuYC5.js +1 -0
  124. package/dist/packages/elements-ui/dist/cdn/chunks/frame-CtTY4oCn.js +1 -0
  125. package/dist/packages/elements-ui/dist/cdn/chunks/on-call-YKLF3-FH.js +1 -0
  126. package/dist/packages/elements-ui/dist/cdn/chunks/runtime-QRQ3CjZg.js +1 -0
  127. package/dist/packages/elements-ui/dist/cdn/chunks/series-uUg6_JtL.js +1 -0
  128. package/dist/packages/elements-ui/dist/cdn/chunks/src-XnWjGSDr.js +67 -0
  129. package/dist/packages/elements-ui/dist/cdn/chunks/toast-pwGvxH2T.js +1 -0
  130. package/dist/packages/elements-ui/dist/cdn/chunks/urls-Qks0KJ_p.js +6 -0
  131. package/dist/packages/elements-ui/dist/cdn/chunks/webmcp-Dro53ATH.js +1 -0
  132. package/dist/packages/elements-ui/dist/cdn/polymorph-all.js +52 -50
  133. package/dist/packages/elements-ui/dist/cdn/polymorph.css +1 -1
  134. package/dist/packages/elements-ui/dist/cdn/polymorph.js +1 -1
  135. package/dist/packages/elements-ui/dist/cdn/prepaint.js +1 -1
  136. package/dist/packages/elements-ui/dist/cdn/themes/desktop.css +5 -4
  137. package/dist/packages/elements-ui/dist/cdn/themes/dew.css +5 -4
  138. package/dist/packages/elements-ui/dist/cdn/themes/flint.css +5 -4
  139. package/dist/packages/elements-ui/dist/cdn/themes/glassmorphic.css +5 -4
  140. package/dist/packages/elements-ui/dist/cdn/themes/harbor.css +5 -4
  141. package/dist/packages/elements-ui/dist/cdn/themes/journal.css +5 -4
  142. package/dist/packages/elements-ui/dist/cdn/themes/pastel.css +5 -4
  143. package/dist/packages/elements-ui/dist/cdn/themes/pebble.css +5 -4
  144. package/dist/packages/elements-ui/dist/cdn/themes/plain.css +5 -4
  145. package/dist/packages/elements-ui/dist/cdn/themes/pop.css +5 -4
  146. package/dist/packages/elements-ui/dist/cdn/themes/press.css +5 -4
  147. package/dist/packages/elements-ui/dist/cdn/themes/terminal.css +5 -4
  148. package/dist/packages/elements-ui/src/ai/ArtifactPane.ts +2 -0
  149. package/dist/packages/elements-ui/src/archetypes/dashboard.states.ts +9 -0
  150. package/dist/packages/elements-ui/src/controls/ColorInput.ts +2 -0
  151. package/dist/packages/elements-ui/src/controls/NumberInput.ts +2 -0
  152. package/dist/packages/elements-ui/src/controls/TagInput.ts +4 -0
  153. package/dist/packages/elements-ui/src/controls/TimeInput.ts +2 -0
  154. package/dist/packages/elements-ui/src/controls/select.states.ts +10 -0
  155. package/dist/packages/elements-ui/src/overlays/Command.ts +2 -0
  156. package/dist/packages/elements-ui/src/structure/CodeBlock.ts +5 -2
  157. package/dist/packages/elements-ui/src/structure/Stat.ts +6 -0
  158. package/dist/packages/elements-ui/src/structure/stat.states.ts +33 -0
  159. package/dist/packages/mcp/src/propose.js +92 -15
  160. package/dist/packages/mcp/src/server.js +19 -8
  161. package/dist/packages/mcp/src/tools.js +80 -5
  162. package/dist/packages/mcp/src/write.js +95 -13
  163. package/dist/packages/react-ui/src/ai/ArtifactPane.tsx +5 -2
  164. package/dist/packages/react-ui/src/ai/PromptInput.tsx +5 -2
  165. package/dist/packages/react-ui/src/archetypes/dashboard.states.tsx +28 -0
  166. package/dist/packages/react-ui/src/controls/ColorInput.tsx +69 -13
  167. package/dist/packages/react-ui/src/controls/Combobox.tsx +13 -5
  168. package/dist/packages/react-ui/src/controls/DatePicker.tsx +3 -0
  169. package/dist/packages/react-ui/src/controls/DateRangePicker.tsx +22 -5
  170. package/dist/packages/react-ui/src/controls/FileUpload.tsx +2 -0
  171. package/dist/packages/react-ui/src/controls/MultiSelect.tsx +30 -6
  172. package/dist/packages/react-ui/src/controls/NumberInput.tsx +19 -1
  173. package/dist/packages/react-ui/src/controls/PhoneInput.tsx +3 -3
  174. package/dist/packages/react-ui/src/controls/Select.tsx +59 -23
  175. package/dist/packages/react-ui/src/controls/TagInput.tsx +43 -10
  176. package/dist/packages/react-ui/src/controls/TimeInput.tsx +10 -0
  177. package/dist/packages/react-ui/src/controls/date-segments.tsx +16 -0
  178. package/dist/packages/react-ui/src/controls/select.states.tsx +13 -0
  179. package/dist/packages/react-ui/src/overlays/Command.tsx +23 -2
  180. package/dist/packages/react-ui/src/overlays/Toaster.tsx +2 -2
  181. package/dist/packages/react-ui/src/structure/CodeBlock.tsx +7 -3
  182. package/dist/packages/react-ui/src/structure/Stat.tsx +90 -13
  183. package/dist/packages/react-ui/src/structure/stat.states.tsx +68 -0
  184. package/dist/packages/recipes/src/ai/artifact-pane.module.css +4 -4
  185. package/dist/packages/recipes/src/controls/rich-text-input.module.css +1 -1
  186. package/dist/packages/recipes/src/structure/avatar.module.css +3 -1
  187. package/dist/packages/recipes/src/structure/heading.module.css +5 -4
  188. package/dist/packages/recipes/src/structure/hero.module.css +3 -1
  189. package/dist/packages/recipes/src/structure/stat.module.css +7 -0
  190. package/dist/packages/registry/src/card.js +4 -3
  191. package/dist/packages/registry/src/frameworks.js +28 -1
  192. package/dist/packages/registry/src/runtime-card.js +300 -0
  193. package/dist/packages/registry/src/runtime-members.js +176 -0
  194. package/dist/packages/registry/src/screen-table.js +166 -0
  195. package/dist/packages/rules/package.js +1 -1
  196. package/dist/packages/solid-ui/src/ai/ArtifactPane.tsx +11 -3
  197. package/dist/packages/solid-ui/src/ai/PromptInput.tsx +3 -1
  198. package/dist/packages/solid-ui/src/archetypes/Dashboard.tsx +3 -0
  199. package/dist/packages/solid-ui/src/archetypes/dashboard.states.tsx +39 -0
  200. package/dist/packages/solid-ui/src/controls/ColorInput.tsx +38 -17
  201. package/dist/packages/solid-ui/src/controls/Combobox.tsx +27 -6
  202. package/dist/packages/solid-ui/src/controls/DatePicker.tsx +12 -11
  203. package/dist/packages/solid-ui/src/controls/DateRangePicker.tsx +21 -16
  204. package/dist/packages/solid-ui/src/controls/DateRangePickerRangeCalendar.tsx +3 -4
  205. package/dist/packages/solid-ui/src/controls/FileUpload.tsx +1 -0
  206. package/dist/packages/solid-ui/src/controls/FileUploadRow.tsx +6 -0
  207. package/dist/packages/solid-ui/src/controls/MultiSelect.tsx +51 -11
  208. package/dist/packages/solid-ui/src/controls/NumberInput.tsx +21 -2
  209. package/dist/packages/solid-ui/src/controls/PhoneInput.tsx +8 -4
  210. package/dist/packages/solid-ui/src/controls/Select.tsx +37 -6
  211. package/dist/packages/solid-ui/src/controls/TagInput.tsx +26 -5
  212. package/dist/packages/solid-ui/src/controls/TimeInput.tsx +10 -1
  213. package/dist/packages/solid-ui/src/controls/select.states.tsx +18 -0
  214. package/dist/packages/solid-ui/src/overlays/Command.tsx +15 -2
  215. package/dist/packages/solid-ui/src/overlays/CommandPanel.tsx +7 -7
  216. package/dist/packages/solid-ui/src/overlays/ToastViewport.tsx +1 -1
  217. package/dist/packages/solid-ui/src/structure/CodeBlock.tsx +9 -5
  218. package/dist/packages/solid-ui/src/structure/Stat.tsx +86 -25
  219. package/dist/packages/solid-ui/src/structure/stat.states.tsx +73 -0
  220. package/dist/packages/svelte-ui/src/ai/ArtifactPane.svelte +8 -2
  221. package/dist/packages/svelte-ui/src/ai/PromptInput.svelte +3 -1
  222. package/dist/packages/svelte-ui/src/archetypes/Dashboard.svelte +3 -0
  223. package/dist/packages/svelte-ui/src/archetypes/dashboard.states.svelte +2 -0
  224. package/dist/packages/svelte-ui/src/controls/ColorInput.svelte +29 -8
  225. package/dist/packages/svelte-ui/src/controls/Combobox.svelte +26 -5
  226. package/dist/packages/svelte-ui/src/controls/DatePicker.svelte +7 -5
  227. package/dist/packages/svelte-ui/src/controls/DateRangePicker.svelte +15 -9
  228. package/dist/packages/svelte-ui/src/controls/DateRangePickerRangeCalendar.svelte +3 -2
  229. package/dist/packages/svelte-ui/src/controls/FileUpload.svelte +1 -0
  230. package/dist/packages/svelte-ui/src/controls/FileUploadRow.svelte +8 -1
  231. package/dist/packages/svelte-ui/src/controls/MultiSelect.svelte +36 -10
  232. package/dist/packages/svelte-ui/src/controls/NumberInput.svelte +14 -1
  233. package/dist/packages/svelte-ui/src/controls/PhoneInput.svelte +3 -3
  234. package/dist/packages/svelte-ui/src/controls/Select.svelte +20 -6
  235. package/dist/packages/svelte-ui/src/controls/TagInput.svelte +21 -3
  236. package/dist/packages/svelte-ui/src/controls/TimeInput.svelte +11 -1
  237. package/dist/packages/svelte-ui/src/controls/select.states.svelte +26 -24
  238. package/dist/packages/svelte-ui/src/overlays/Command.svelte +13 -1
  239. package/dist/packages/svelte-ui/src/overlays/CommandPanel.svelte +11 -6
  240. package/dist/packages/svelte-ui/src/overlays/ToastViewport.svelte +1 -1
  241. package/dist/packages/svelte-ui/src/structure/CodeBlock.svelte +7 -2
  242. package/dist/packages/svelte-ui/src/structure/Stat.svelte +70 -17
  243. package/dist/packages/svelte-ui/src/structure/stat.states.svelte +27 -0
  244. package/dist/packages/theme/src/admit.js +6 -3
  245. package/dist/packages/theme/src/color/resolve.js +19 -2
  246. package/dist/packages/theme/src/derive.js +13 -6
  247. package/dist/packages/theme/src/emit.js +1 -1
  248. package/dist/packages/theme/src/runtime.js +58 -0
  249. package/dist/packages/theme/src/seeds.js +30 -4
  250. package/dist/packages/theme/src/systems.js +1 -1
  251. package/dist/packages/theme/src/tokens.js +15 -6
  252. package/dist/packages/vue-ui/src/ai/ArtifactPane.vue +11 -2
  253. package/dist/packages/vue-ui/src/ai/PromptInput.vue +3 -1
  254. package/dist/packages/vue-ui/src/archetypes/Dashboard.vue +3 -0
  255. package/dist/packages/vue-ui/src/archetypes/dashboard.states.ts +49 -0
  256. package/dist/packages/vue-ui/src/controls/ColorInput.vue +33 -12
  257. package/dist/packages/vue-ui/src/controls/Combobox.vue +26 -5
  258. package/dist/packages/vue-ui/src/controls/DatePicker.vue +12 -11
  259. package/dist/packages/vue-ui/src/controls/DateRangePicker.vue +20 -15
  260. package/dist/packages/vue-ui/src/controls/DateRangePickerRangeCalendar.vue +3 -4
  261. package/dist/packages/vue-ui/src/controls/FileUpload.vue +1 -0
  262. package/dist/packages/vue-ui/src/controls/FileUploadRow.vue +6 -0
  263. package/dist/packages/vue-ui/src/controls/MultiSelect.vue +37 -10
  264. package/dist/packages/vue-ui/src/controls/NumberInput.vue +17 -1
  265. package/dist/packages/vue-ui/src/controls/PhoneInput.vue +7 -3
  266. package/dist/packages/vue-ui/src/controls/Select.vue +22 -7
  267. package/dist/packages/vue-ui/src/controls/TagInput.vue +21 -3
  268. package/dist/packages/vue-ui/src/controls/TimeInput.vue +10 -1
  269. package/dist/packages/vue-ui/src/controls/select.states.ts +17 -0
  270. package/dist/packages/vue-ui/src/overlays/Command.vue +13 -1
  271. package/dist/packages/vue-ui/src/overlays/CommandPanel.vue +7 -7
  272. package/dist/packages/vue-ui/src/overlays/ToastViewport.vue +1 -1
  273. package/dist/packages/vue-ui/src/structure/CodeBlock.vue +7 -2
  274. package/dist/packages/vue-ui/src/structure/Stat.vue +71 -18
  275. package/dist/packages/vue-ui/src/structure/stat.states.ts +67 -0
  276. package/dist/platforms/android/ui/src/generated/kotlin/dev/polymorph/ui/Contracts.kt +144 -33
  277. package/dist/platforms/android/ui/src/generated/kotlin/dev/polymorph/ui/Members.kt +17 -7
  278. package/dist/platforms/ios/Sources/PolymorphUI/Generated/Contracts.swift +204 -31
  279. package/dist/registry/registry.json +371 -75
  280. package/dist/screen/assets/{screen-CuQbskb8.css → screen-B22PTPwF.css} +1 -1
  281. package/dist/screen/assets/screen-Cpbh7XMb.js +372 -0
  282. package/dist/screen/screen.html +3 -3
  283. package/package.json +1 -1
  284. package/dist/packages/elements-ui/dist/cdn/chunks/ArtifactPane-DsmRlr6d.js +0 -1
  285. package/dist/packages/elements-ui/dist/cdn/chunks/CodeBlock-BqP8HZKM.js +0 -1
  286. package/dist/packages/elements-ui/dist/cdn/chunks/CodeBlock-D8VARz0a.js +0 -1
  287. package/dist/packages/elements-ui/dist/cdn/chunks/ColorInput-BrzZOVeL.js +0 -1
  288. package/dist/packages/elements-ui/dist/cdn/chunks/Combobox-BiUq0h-w.js +0 -1
  289. package/dist/packages/elements-ui/dist/cdn/chunks/Command-hmxVRdFg.js +0 -1
  290. package/dist/packages/elements-ui/dist/cdn/chunks/DatePicker-C8prGbJ2.js +0 -1
  291. package/dist/packages/elements-ui/dist/cdn/chunks/DateRangePicker-CO1ioqwN.js +0 -1
  292. package/dist/packages/elements-ui/dist/cdn/chunks/FileUpload-HPQe-ttb.js +0 -1
  293. package/dist/packages/elements-ui/dist/cdn/chunks/ModeSwitch-CerqbGv3.js +0 -1
  294. package/dist/packages/elements-ui/dist/cdn/chunks/MultiSelect-CQq7jPgI.js +0 -1
  295. package/dist/packages/elements-ui/dist/cdn/chunks/NumberInput-Dre9GwBy.js +0 -7
  296. package/dist/packages/elements-ui/dist/cdn/chunks/PhoneInput-D6_J6Es_.js +0 -210
  297. package/dist/packages/elements-ui/dist/cdn/chunks/PromptInput-BXcsUQ5W.js +0 -1
  298. package/dist/packages/elements-ui/dist/cdn/chunks/Select-DxGQgv2q.js +0 -1
  299. package/dist/packages/elements-ui/dist/cdn/chunks/Stat-FsMUWigK.js +0 -1
  300. package/dist/packages/elements-ui/dist/cdn/chunks/Stat-WS8v6BQv.js +0 -1
  301. package/dist/packages/elements-ui/dist/cdn/chunks/TagInput-D-uIQEGS.js +0 -1
  302. package/dist/packages/elements-ui/dist/cdn/chunks/TimeInput-Dho571vA.js +0 -1
  303. package/dist/packages/elements-ui/dist/cdn/chunks/agent-DBDk4wLH.js +0 -1
  304. package/dist/packages/elements-ui/dist/cdn/chunks/api-B9sGZiYn.js +0 -4
  305. package/dist/packages/elements-ui/dist/cdn/chunks/avatar.module-CQwnWhWo.js +0 -1
  306. package/dist/packages/elements-ui/dist/cdn/chunks/cap-Ct4k7zNC.js +0 -1
  307. package/dist/packages/elements-ui/dist/cdn/chunks/chart-brush.module-DycBfben.js +0 -1
  308. package/dist/packages/elements-ui/dist/cdn/chunks/chart-twin.module-Cks7VwS5.js +0 -1
  309. package/dist/packages/elements-ui/dist/cdn/chunks/check-dOfCSYFA.js +0 -1
  310. package/dist/packages/elements-ui/dist/cdn/chunks/draw-DclRgiWM.js +0 -1
  311. package/dist/packages/elements-ui/dist/cdn/chunks/drawing-DjkZr0z8.js +0 -1
  312. package/dist/packages/elements-ui/dist/cdn/chunks/frame-BSvl4y47.js +0 -1
  313. package/dist/packages/elements-ui/dist/cdn/chunks/on-call-Jk1sYJc_.js +0 -1
  314. package/dist/packages/elements-ui/dist/cdn/chunks/receivers-BpRfF6dV.js +0 -4
  315. package/dist/packages/elements-ui/dist/cdn/chunks/series-C_1TNd2n.js +0 -1
  316. package/dist/packages/elements-ui/dist/cdn/chunks/src-Bub3C9YP.js +0 -67
  317. package/dist/packages/elements-ui/dist/cdn/chunks/toast-AarMGYJn.js +0 -1
  318. package/dist/packages/elements-ui/dist/cdn/chunks/webmcp-eEPzSqph.js +0 -1
  319. package/dist/screen/assets/screen-Clj2u6_s.js +0 -372
@@ -0,0 +1,1020 @@
1
+ import { DEFAULT_SYSTEM } from "../plan.js";
2
+ import { Facts, SkillFactError, all, commands, skill } from "./facts.js";
3
+ import { addressNeed, defaultMembers } from "../../../registry/src/runtime-members.js";
4
+ import { compactTable, expandTable } from "../../../registry/src/screen-table.js";
5
+ //#region ../cli/src/skills/runtime.ts
6
+ /**
7
+ * The skill for a screen a model writes while the product runs: the run-time card and the host's
8
+ * rules in the model's prompt, the check and the retry on the server, the React renderer and
9
+ * `<poly-screen>` on the page, the model's prose, what an action tells the host, an action with
10
+ * consequences, refusing addresses, and what a request costs. Each example in it was compiled
11
+ * against the sources or run against them, the no-build page against the built files.
12
+ */
13
+ /**
14
+ * The members the examples allow. None needs an address, so the examples draw the same with
15
+ * `addresses: 'refused'`; `runtimeSkill` throws when one does.
16
+ */
17
+ var EXAMPLE_MEMBERS = [
18
+ "Stack",
19
+ "Heading",
20
+ "Text",
21
+ "Button",
22
+ "FormField",
23
+ "NumberInput",
24
+ "Textarea"
25
+ ];
26
+ /**
27
+ * The members React draws by default that a host refusing addresses cannot draw, by the rule the
28
+ * card, the check and the walk read (`addressNeed` in `@polymorph/registry/runtime-members`), on
29
+ * the table `@polymorph/screen` ships, which is the registry's compacted and expanded.
30
+ */
31
+ function addressMembers(registry) {
32
+ const table = expandTable(compactTable(registry));
33
+ return defaultMembers(table).filter((name) => addressNeed(table, name) !== null);
34
+ }
35
+ /** The example answer: the document a model writes for a refund, from the members above only. */
36
+ var REFUND = `{
37
+ "spec": "polymorph-screen/1",
38
+ "name": "RefundRequest",
39
+ "purpose": "Asks the person how much of an order to refund, and why.",
40
+ "inputs": [{ "name": "order", "type": "string" }, { "name": "requestRefund", "type": "() => void" }],
41
+ "root": {
42
+ "component": "Stack",
43
+ "props": { "gap": 4 },
44
+ "children": [
45
+ { "component": "Heading", "children": ["Refund an order"] },
46
+ { "component": "Text", "props": { "tone": "secondary" }, "children": [{ "$": "order" }] },
47
+ {
48
+ "component": "FormField",
49
+ "props": { "label": "Amount" },
50
+ "children": [{ "component": "NumberInput", "props": { "name": "amount", "min": 0 } }]
51
+ },
52
+ {
53
+ "component": "FormField",
54
+ "props": { "label": "Reason" },
55
+ "children": [{ "component": "Textarea", "props": { "name": "reason" } }]
56
+ },
57
+ {
58
+ "component": "Button",
59
+ "props": { "label": "Request the refund", "variant": "solid", "tone": "accent", "onClick": { "$": "requestRefund" } }
60
+ }
61
+ ]
62
+ }
63
+ }`;
64
+ function runtimeSkill(registry, run) {
65
+ const f = new Facts(registry);
66
+ const card = (name) => f.x(name, "@polymorph/screen/card");
67
+ const react = (name) => f.x(name, "@polymorph/react/screen");
68
+ const elements = (name) => f.x(name, "@polymorph/elements-ui/screen");
69
+ const quoted = EXAMPLE_MEMBERS.map((name) => `'${name}'`).join(", ");
70
+ const check = f.x("checkScreen", "@polymorph/screen/check");
71
+ const answered = f.x("checkAnswer", "@polymorph/screen/check");
72
+ const partial = f.x("parsePartial", "@polymorph/screen/partial");
73
+ const addressed = addressMembers(registry);
74
+ const leaks = EXAMPLE_MEMBERS.filter((name) => addressed.includes(name));
75
+ if (leaks.length > 0) throw new SkillFactError(`the run-time examples allow ${leaks.join(", ")}, which a host refusing addresses cannot draw`);
76
+ const refused = addressed.map((name) => f.m(name));
77
+ const body = `
78
+ # Draw a screen a model writes while the product runs
79
+
80
+ A run-time screen is interface a model writes while the product runs. The model answers with a
81
+ \`polymorph-screen/1\` document in a fenced \`json\` block, sometimes with prose around it. The host
82
+ draws the document with the members, in the app's theme, while it streams in. When a member calls
83
+ one of the document's actions, such as a press or a submit, the host is told the action's name and
84
+ the form's values as data. Nothing is compiled.
85
+
86
+ The work is in two places, and both are given the same list of members:
87
+
88
+ - **The server that calls the model** builds the run-time card, sends it with the host's own
89
+ rules, checks each whole answer with ${answered} and asks once more when it has faults.
90
+ - **The page** draws the answer while it streams, with ${react("ScreenView")} or \`<poly-screen>\`.
91
+ The renderer applies the member list and the run-time rules itself, so the page treats the
92
+ document as untrusted whatever the server checked.
93
+
94
+ Polymorph gives the card, the check and the renderers. The host calls the model, keeps the
95
+ conversation and decides what each action means.
96
+
97
+ ## 1. Check that this is the right tool
98
+
99
+ | The screen | Use |
100
+ | --- | --- |
101
+ | Is part of the product: known when it is built, reviewed and kept | A spec that \`emit\` compiles, or code: the \`polymorph-screen\` skill |
102
+ | Depends on what the person asked: a form the agent needs filled before it acts, a summary of what it found, a choice between options it computed | This skill |
103
+ | Already exists, and an agent fills and presses in it | The \`polymorph-agent-bridge\` skill |
104
+ | Is drawn by SwiftUI or Compose | Nothing draws a document at run time on iOS or Android: the \`polymorph-native\` skill emits it |
105
+
106
+ A document computes nothing: it has no condition, no loop and no expression. A total, a filtered
107
+ list or whether to show a warning is computed by the host and passed as data, or the model is asked
108
+ for a new document.
109
+
110
+ ## 2. Install the renderer
111
+
112
+ | The app | Draws with | Builds the card and checks with |
113
+ | --- | --- | --- |
114
+ | React | ${react("ScreenView")} from \`@polymorph/react/screen\`, in \`@polymorph/react\` | ${card("runtimeCard")} from \`@polymorph/screen/card\`, ${check} from \`@polymorph/screen/check\` |
115
+ | Vue, Svelte, Solid, Angular, or elements with a bundler | \`<poly-screen>\`, defined by importing \`@polymorph/elements-ui/screen\` once | the same, given \`framework: 'elements'\` |
116
+ | A page with no build | \`<poly-screen>\`, defined by \`polymorph.js\` | \`${f.x("loadScreen", "packages/elements-ui/src/cdn/polymorph.ts").slice(1, -1)}()\` from \`polymorph.js\`, or the same on a server |
117
+
118
+ React is the only framework with a renderer of its own.
119
+ [references/elements.md](references/elements.md) has the \`<poly-screen>\` host for the others and
120
+ for a page with no build.
121
+
122
+ \`@polymorph/screen\` has no dependencies and runs in a server, a worker and a page. Add it where the
123
+ card is built or an answer checked, under the alias and at the version of the project's other
124
+ polymorph packages, so the card, the check and the renderer read one vocabulary:
125
+
126
+ \`\`\`json
127
+ { "dependencies": { "@polymorph/screen": "npm:@metamorph-labs/polymorph-screen@^<version>" } }
128
+ \`\`\`
129
+
130
+ ## 3. Choose the members a document may use
131
+
132
+ \`\`\`ts
133
+ // screen-members.ts: the members a document may use. The server and the page both import it.
134
+ export const MEMBERS = [${quoted}]
135
+ \`\`\`
136
+
137
+ The list is what the model may write. It goes to the card and the check (\`members\`) and to the
138
+ renderer (\`allow\` on ${react("ScreenView")}, \`members\` on \`<poly-screen>\`), so the model is never
139
+ shown a member the renderer refuses. The host's own code composes any member, in the list or not:
140
+ the ${f.m("ChatThread")} around the screen, the ${f.m("ConfirmDialog")} that confirms an action.
141
+
142
+ - A part comes with its member: ${f.m("Table")} allows ${f.part("Table", "Row")}.
143
+ - A shorter list gives a shorter card, fewer choices and a check that refuses the rest.
144
+ - With no list, every member the framework draws is allowed but ${f.m("ThirdParty")}, which holds
145
+ whatever the host puts in it, and, in React, ${f.m("Toast")}.
146
+
147
+ To refuse links and remote pictures, pass \`addresses: 'refused'\` beside the list: to the card and
148
+ the check, as \`addresses\` on ${react("ScreenView")}, and as the \`addresses\` attribute of
149
+ \`<poly-screen>\`. The card then lists no prop that takes an address, the check reports each one a
150
+ document writes, and the renderer passes none: ${f.m("Card")} and ${f.part("List", "Item")} are
151
+ drawn without their \`href\`. A member that cannot be drawn without an address is left out of the
152
+ card and refused: ${all(refused)}. The host's own data, bound whole, is passed as the host gave it.
153
+
154
+ ## 4. Build the system prompt: the card, then the host's rules
155
+
156
+ \`\`\`ts
157
+ // prompt.ts, on the server.
158
+ import { runtimeCard } from '@polymorph/screen/card'
159
+
160
+ import { MEMBERS } from './screen-members'
161
+
162
+ // The same release, framework and members give the same text, so it is built once.
163
+ export const CARD = runtimeCard({ members: MEMBERS })
164
+
165
+ // What only this host knows. A document's action is a name the host maps to its own handler,
166
+ // so the rules name each action the host handles and the fields it reads.
167
+ export const RULES = [
168
+ 'Actions this host handles:',
169
+ '- requestRefund, of type () => void, bound to the Button that asks for a refund. It reads the fields amount (a NumberInput) and reason (a Textarea).',
170
+ 'Any other action you declare is sent back to you as the next turn.',
171
+ 'Never say that a refund is made or approved. The host asks the person to confirm it, and tells you what happened.',
172
+ ].join('\\n')
173
+ \`\`\`
174
+
175
+ Send the card first and unchanged, then the rules, as the system prompt, and mark the end of the
176
+ two for the provider's prompt cache. The card says what the check and the renderer hold a document
177
+ to, so the host adds to it after it and never edits it. The card names no action: the model names
178
+ each callback input itself, so the rules declare the names the host handles. A cache holds the longest prefix that is
179
+ the same in every request, so what differs between requests, such as the host's data and the
180
+ person's words, goes after both, in the messages. A provider caches only above a minimum length,
181
+ which a card for a few members may not reach. The model needs no tool to write a lawful document.
182
+
183
+ For \`<poly-screen>\`, pass \`framework: 'elements'\` too. The card lists each allowed member with its
184
+ props, parts and lawful cells, the data types and icon roles they take, and the output contract:
185
+ one document in a fenced \`json\` block. The system card the \`card\` verb prints is for a coding
186
+ agent and never goes in a run-time prompt.
187
+
188
+ ## 5. Ask for a screen
189
+
190
+ The person's request is the message. When the screen should show the host's data, the message names
191
+ each key the host holds, with its type: a document binds a data input by the key's name.
192
+
193
+ \`\`\`ts
194
+ const message = [
195
+ 'I want a refund for order 1042.',
196
+ 'Data you can bind, by input name: order (string, the order number as the person reads it).',
197
+ ].join('\\n\\n')
198
+ \`\`\`
199
+
200
+ The model answers with prose, a document, or both:
201
+
202
+ \`\`\`json
203
+ ${REFUND}
204
+ \`\`\`
205
+
206
+ ## 6. On the server: call the model, check the whole answer, ask once more
207
+
208
+ \`\`\`ts
209
+ // ask.ts, on the server that calls the model.
210
+ import { checkAnswer } from '@polymorph/screen/check'
211
+
212
+ // Stand-in: your call to the model. It sends CARD and RULES as the system prompt and \`turns\` as
213
+ // the conversation, calls \`onText\` with the answer so far each time more arrives, and resolves
214
+ // with the whole answer. A Turn is { role: 'user' | 'assistant', content: string }.
215
+ import { askModel, type Turn } from './model'
216
+ import { MEMBERS } from './screen-members'
217
+
218
+ /** Answers the conversation, and asks once more, with the faults, when the answer is not lawful. */
219
+ export async function answer(turns: Turn[], onText: (text: string) => void): Promise<Turn[]> {
220
+ const first = await askModel(turns, onText)
221
+ const answered: Turn[] = [...turns, { role: 'assistant', content: first }]
222
+ const { ok, faults } = checkAnswer(first, { members: MEMBERS })
223
+ if (ok) return answered
224
+ const lines = faults.map((fault) => \`\${fault.path}: \${fault.message}\`)
225
+ const retry: Turn[] = [
226
+ ...answered,
227
+ { role: 'user', content: \`Your screen has these faults. Answer with the corrected document.\\n\${lines.join('\\n')}\` },
228
+ ]
229
+ // Once: a second answer is drawn as it is, and the renderer leaves out what it refuses.
230
+ return [...retry, { role: 'assistant', content: await askModel(retry, onText) }]
231
+ }
232
+ \`\`\`
233
+
234
+ - ${answered} takes the whole answer as text and the host's options, and returns \`ok\`, \`faults\`,
235
+ \`document\`, \`complete\` and \`prose\`. It reads the document as the renderer does
236
+ (${partial}): the first fence marked \`json\` or unmarked, or the first brace that opens an
237
+ object. An answer with neither is prose, which is lawful: \`document\` is \`undefined\`.
238
+ - An answer that ends before its document does, at a token limit or a dropped stream, is one fault
239
+ at \`$\`: \`the answer ends before its document does\`, in words that ask for the whole document
240
+ again. Call it once the answer has ended; while it streams, a document that has not closed is
241
+ normal.
242
+ - Each fault is \`{ path, message }\` in words a model corrects from
243
+ (\`\`no component called \`Modal\` — did you mean \`Dialog\`, …?\`\`). The check reads what the
244
+ renderer does not: variant and tone cells, icon roles and the usage rules. ${check} checks a
245
+ document object the host already holds.
246
+
247
+ ## 7. On the page: draw the prose and the screen while they stream
248
+
249
+ \`\`\`tsx
250
+ import { useState } from 'react'
251
+ import * as members from '@polymorph/react-ui'
252
+ import { parsePartial, ScreenView, type ScreenAction } from '@polymorph/react/screen'
253
+
254
+ import { MEMBERS } from './screen-members'
255
+ // Stand-in: posts the person's message, or an action, to your server, which adds it to the
256
+ // conversation and calls \`answer\` (step 6). It calls \`onText\` with the answer so far as it
257
+ // streams back, and resolves when the answer ends.
258
+ import { streamTurn } from './server'
259
+
260
+ const { PromptInput, Stack, StreamingText } = members
261
+
262
+ export function Assistant({ data }: { data: Record<string, unknown> }) {
263
+ const [answer, setAnswer] = useState('')
264
+ const [done, setDone] = useState(true)
265
+
266
+ const send = async (message: string) => {
267
+ setDone(false)
268
+ await streamTurn(message, setAnswer)
269
+ setDone(true)
270
+ }
271
+
272
+ const onAction = (action: ScreenAction) => {
273
+ void send(\`An action from the screen: \${JSON.stringify(action)}\`)
274
+ }
275
+
276
+ const { document, prose, fence } = parsePartial(answer)
277
+
278
+ return (
279
+ <Stack gap={4}>
280
+ {prose !== '' && <StreamingText streaming={!done && fence !== 'open'}>{prose}</StreamingText>}
281
+ {document !== undefined && (
282
+ <ScreenView
283
+ text={answer}
284
+ streaming={!done}
285
+ members={members}
286
+ allow={MEMBERS}
287
+ data={data}
288
+ onAction={onAction}
289
+ onFault={(fault) => console.warn(fault.path, fault.message)}
290
+ />
291
+ )}
292
+ <PromptInput label="Message" streaming={!done} onSubmit={(text) => void send(text)} />
293
+ </Stack>
294
+ )
295
+ }
296
+ \`\`\`
297
+
298
+ - ${react("ScreenView")} applies \`allow\` and the run-time rules as it draws: a member outside the
299
+ list, a prop the member lacks, a refused address and a value where a function goes are left out
300
+ and reported. Without \`allow\` it draws every member React draws but ${f.m("ThirdParty")} and
301
+ ${f.m("Toast")}, so the page gets the server's list.
302
+ - \`prose\` is the text outside the fenced block that holds the document, as the reader finds it:
303
+ the text before the block, and after it once the block closes. \`fence\` is \`open\` from the
304
+ block's first backtick to its closing line. ${f.m("StreamingText")} draws the prose as it is.
305
+ ${f.m("Markdown")} draws the links its text writes, so it is for a host that allows links.
306
+ - Draw ${react("ScreenView")} only when the answer holds a document. Given none, with \`streaming\`
307
+ off, it reports \`the document has no root element\` at \`$.root\`.
308
+ - \`streaming\` is on while the answer arrives and off when it ends, so an answer cut short reports
309
+ what it lacks. Left out, an answer that stops early never reports.
310
+ - An element is drawn once every prop it requires is written, and stays drawn, so a field keeps its
311
+ text and focus while the answer grows. A new answer replaces the screen from its first element.
312
+ [references/contract.md](references/contract.md) says what new \`data\` and a replaced document
313
+ keep.
314
+
315
+ ## 8. Handle each action
316
+
317
+ The person types 40 and a reason and presses the button. \`onAction\` is called with a
318
+ ${f.x("ScreenAction", "@polymorph/screen/walk")}:
319
+
320
+ \`\`\`json
321
+ { "name": "requestRefund", "args": [], "values": { "amount": 40, "reason": "It arrived broken." }, "changed": ["amount", "reason"] }
322
+ \`\`\`
323
+
324
+ | Field | What it is |
325
+ | --- | --- |
326
+ | \`name\` | the callback input the document bound, which the member called |
327
+ | \`args\` | what the member passed, as JSON. An event is dropped: a ${f.m("Button")}'s ${f.p("Button", "onClick")} gives \`[]\` |
328
+ | \`values\` | every control with a \`name\`, on screen or not: what the person chose, else the document's or host's value, else its default, else its type's empty value |
329
+ | \`changed\` | the names in \`values\` whose value the person chose |
330
+
331
+ - \`values\` is JSON. ${f.m("NumberInput")} gives a number, or \`null\` while empty. ${f.m("Input")}
332
+ gives text for every \`type\`, ${f.v("Input", "type", "number")} included.
333
+ - Map each name the rules declared to the host's own handler. Send any other action to the model as
334
+ the next turn, as step 7 does; the next answer is the next screen.
335
+ - An action is the document's word, not the person's: the model chose its \`name\`, and each value
336
+ is what a control holds. An action with consequences, such as a refund, a deletion or a message
337
+ sent, opens the host's own ${f.m("ConfirmDialog")}, written from the host's data, and the server
338
+ authorises and checks again before it acts, once for each idempotency key.
339
+ [references/contract.md](references/contract.md) has the pattern.
340
+ - An action does not prove that a person acted: ${f.m("Countdown")} calls
341
+ ${f.p("Countdown", "onEnd")} when its time is reached, and an agent on the page presses as a person
342
+ does, each with an empty \`changed\`. Bound how many model turns actions may start in a row, so a
343
+ screen that calls its own action as it is drawn cannot loop.
344
+ - A promise \`onAction\` returns is what a member that waits on its callback waits on: a
345
+ ${f.m("ConfirmDialog")} in the document stays open and busy until it settles. A ${f.m("Button")}
346
+ does not wait.
347
+
348
+ ## 9. Look at an answer while you build
349
+
350
+ Save an answer's document to a file, and draw it, validate it or read a member with the CLI:
351
+ [references/api.md](references/api.md) has the commands and what each does not apply.
352
+
353
+ ## What a document cannot do, and what stays the host's job
354
+
355
+ Nothing a document holds runs or is inserted as markup, a callback prop takes only a function the
356
+ screen makes, an address is relative, a fragment, or \`http:\`, \`https:\`, \`mailto:\` or \`tel:\`, and a
357
+ fault takes out only the element it is in. These stay the host's job:
358
+
359
+ - What an action means, and confirming one with consequences.
360
+ - The host's own data inside a bound value, addresses included: it is passed as the host gave it.
361
+ - Where an allowed link leads and where a picture loads from: an \`https:\` address can name any
362
+ site.
363
+ - Ids and names: a document can set an \`id\` and a control's \`name\`, so draw the screen outside the
364
+ host's own \`<form>\`.
365
+ - The words: a screen shows any text the model writes and asks for any field it names. Treat
366
+ \`values\` as input from the page.
367
+
368
+ [references/contract.md](references/contract.md) has each rule, every fault, the limits, and how a
369
+ run-time document differs from a spec \`emit\` compiles.
370
+
371
+ ## What a request costs
372
+
373
+ | Part | What it costs |
374
+ | --- | --- |
375
+ | The card | input on every request: measure it with the command below. After the first request a prompt cache holds it (step 4) |
376
+ | The host's rules | input on every request, held in the cache with the card |
377
+ | The conversation | input on every request: each earlier message and answer, documents included |
378
+ | The answer | output: the prose and the document the model writes |
379
+ | A retry | one more request: the same prefix, the conversation with the first answer and the fault list, and a second answer |
380
+ | An action | nothing, unless the host sends it to the model. One the host handles itself, such as \`requestRefund\`, costs no model call; telling the model the outcome is one request |
381
+
382
+ A request's price is these counts at the provider's rates for input, cached input and output; the
383
+ provider's response reports each count. The card's length depends on the release, the framework,
384
+ the members and \`--addresses\`. This prints the card for the list in step 3, the text
385
+ \`runtimeCard\` returns for the same options, and its length in characters on stderr; a provider's
386
+ tokenizer reads about four characters to a token:
387
+
388
+ ${commands(run, `card --runtime --framework react --members ${EXAMPLE_MEMBERS.join(",")}`)}
389
+
390
+ Its standard output is the whole card, so a server that runs no JavaScript writes it to a file
391
+ once for each release (\`> card.md\`) and sends that.
392
+
393
+ The page pays once, in what it loads:
394
+
395
+ - **React**: \`@polymorph/react/screen\` adds the renderer and the vocabulary table to the bundle.
396
+ \`import * as members\` adds every member; a map of the allowed ones (\`{ Stack, Heading, … }\`)
397
+ adds only those. The card and the validator come only where imported.
398
+ - **\`<poly-screen>\`**: the first to connect fetches the renderer and the vocabulary table, each
399
+ member's code loads when its element first renders, and the validator on the first check.
400
+ `;
401
+ return [
402
+ {
403
+ path: "polymorph-runtime-screen/SKILL.md",
404
+ contents: skill("polymorph-runtime-screen", "Let a product answer with real interface while it runs. A model writes a polymorph-screen/1 document, the server checks it with checkAnswer, the page draws it as it streams with ScreenView from @polymorph/react/screen or the <poly-screen> element from @polymorph/elements-ui/screen, and each press or submit becomes an action the product handles. Use when asked for generative UI, to render a model or agent response as components, to let an assistant show a form, a choice or a confirmation, or when code imports @polymorph/screen, runtimeCard, checkAnswer, parsePartial, ScreenView or loadScreen. Covers the members a model may use and refusing links and images, the card and the host’s rules in the system prompt, checking and asking again, drawing the prose and the screen while they stream, actions and values, confirming an action with consequences, and what a request costs.", body)
405
+ },
406
+ {
407
+ path: "polymorph-runtime-screen/references/elements.md",
408
+ contents: elementsReference(registry, elements)
409
+ },
410
+ {
411
+ path: "polymorph-runtime-screen/references/contract.md",
412
+ contents: contractReference(registry)
413
+ },
414
+ {
415
+ path: "polymorph-runtime-screen/references/api.md",
416
+ contents: apiReference(registry, run)
417
+ }
418
+ ];
419
+ }
420
+ /** The host for Vue, Svelte, Solid, Angular, elements with a bundler, and a page with no build. */
421
+ function elementsReference(registry, elements) {
422
+ const f = new Facts(registry);
423
+ const quoted = EXAMPLE_MEMBERS.map((name) => `'${name}'`).join(", ");
424
+ return `# Draw with \`<poly-screen>\`
425
+
426
+ \`<poly-screen>\` draws a document as \`poly-*\` elements, the elements that render each member, in
427
+ the light DOM. It draws no box of its own, so the screen lays out as content of the element's
428
+ parent. Vue, Svelte, Solid and Angular have no run-time renderer of their own, so an app in any of
429
+ them uses it, as a page with no build does. The elements read the theme the page carries, as every
430
+ member does.
431
+
432
+ Like \`ScreenView\`, it applies its \`members\` and the run-time rules as it draws, whatever the server
433
+ checked, and it draws only the document. Show the prose, \`parsePartial(text).prose\`, in an element
434
+ of the page's own, as text.
435
+
436
+ ## In an app with a bundler
437
+
438
+ 1. Add \`@polymorph/elements\` and \`@polymorph/elements-ui\` to \`package.json\` under the alias and
439
+ version the other polymorph packages use (\`npm:@metamorph-labs/polymorph-elements-ui@^<version>\`),
440
+ and \`@polymorph/screen\` on the server that builds the card. Run the project's install.
441
+ 2. Import \`@polymorph/elements-ui/screen\` once. It defines \`<poly-screen>\` and every \`poly-*\`
442
+ element; each member's code loads the first time one of its elements renders.
443
+ 3. Write \`<poly-screen></poly-screen>\` in the template, as any custom element. In Vue, make
444
+ \`compilerOptions.isCustomElement\` accept the \`poly-\` tags; in Angular, add
445
+ \`CUSTOM_ELEMENTS_SCHEMA\` to the component's \`schemas\`.
446
+ 4. Take the element through the framework's template ref, once it is mounted, and connect it:
447
+
448
+ \`\`\`ts
449
+ import type { PolymorphEvent } from '@polymorph/elements'
450
+ import { ACTION_EVENT, FAULT_EVENT, type PolyScreen, type ScreenAction } from '@polymorph/elements-ui/screen'
451
+
452
+ import { MEMBERS } from './screen-members'
453
+ // Stand-in: posts the message to your server, which calls \`answer\` (the skill's step 6) and
454
+ // streams the answer back. It calls \`onText\` with the answer so far, and resolves when it ends.
455
+ import { streamTurn } from './server'
456
+
457
+ /** Draws the model's answers in a \`<poly-screen>\` the page or a template wrote, and sends each action back. */
458
+ export function connectScreen(screen: PolyScreen, data: Record<string, unknown>) {
459
+ screen.members = MEMBERS
460
+ screen.data = data
461
+
462
+ const send = async (message: string) => {
463
+ screen.streaming = true
464
+ await streamTurn(message, (text) => {
465
+ screen.text = text
466
+ })
467
+ screen.streaming = false
468
+ }
469
+
470
+ screen.addEventListener(ACTION_EVENT, (event) => {
471
+ const action = (event as PolymorphEvent<ScreenAction>).detail
472
+ void send(\`An action from the screen: \${JSON.stringify(action)}\`)
473
+ })
474
+ screen.addEventListener(FAULT_EVENT, (event) => console.warn((event as CustomEvent).detail))
475
+ return send
476
+ }
477
+ \`\`\`
478
+
479
+ On the server, \`answer\` from the skill's step 6 builds the card and checks for the elements:
480
+
481
+ \`\`\`ts
482
+ const CARD = runtimeCard({ framework: 'elements', members: MEMBERS })
483
+ const { ok, faults } = checkAnswer(first, { framework: 'elements', members: MEMBERS })
484
+ \`\`\`
485
+
486
+ \`@polymorph/elements-ui/screen\` exports the same functions bound to the elements, for code in the
487
+ page: ${elements("drawScreen")} draws into a plain element, and ${elements("PolyScreen")},
488
+ ${elements("ACTION_EVENT")} and ${elements("FAULT_EVENT")} are the element's class and its events.
489
+
490
+ ## On a page with no build
491
+
492
+ A page with no build loads the elements from files the project copied into \`public/polymorph/\`
493
+ when it was set up (the \`polymorph-setup\` skill). The page links \`polymorph.css\` and its theme
494
+ sheet, then loads \`polymorph.js\` as a module script. \`polymorph.js\` defines \`<poly-screen>\`,
495
+ and the first one to connect fetches the renderer.
496
+
497
+ \`\`\`html
498
+ <poly-screen id="assistant" members="${EXAMPLE_MEMBERS.join(" ")}"></poly-screen>
499
+
500
+ <script type="module">
501
+ // Stand-in: posts the message to the page's server, which calls the model with the card for the
502
+ // elements and checks the answer. It calls \`onText\` with the answer so far, and resolves when it ends.
503
+ import { streamTurn } from './server.js'
504
+
505
+ const screen = document.querySelector('#assistant')
506
+ screen.data = { order: 'Order 1042' }
507
+
508
+ async function send(message) {
509
+ screen.streaming = true
510
+ await streamTurn(message, (text) => {
511
+ screen.text = text
512
+ })
513
+ screen.streaming = false
514
+ }
515
+
516
+ screen.addEventListener('poly-action', (event) => {
517
+ send(\`An action from the screen: \${JSON.stringify(event.detail)}\`)
518
+ })
519
+ screen.addEventListener('poly-fault', (event) => console.warn(event.detail))
520
+
521
+ send('I want a refund for order 1042.')
522
+ <\/script>
523
+ \`\`\`
524
+
525
+ The page builds the card, or checks a document, with ${f.x("loadScreen", "packages/elements-ui/src/cdn/polymorph.ts")}.
526
+ It fetches the validator and the card only when called, and its functions are bound to the
527
+ elements, so they take no \`framework\`:
528
+
529
+ \`\`\`html
530
+ <script type="module">
531
+ import { loadScreen } from './polymorph/polymorph.js'
532
+
533
+ const { runtimeCard, checkAnswer } = await loadScreen()
534
+ const card = runtimeCard({ members: [${quoted}] })
535
+ <\/script>
536
+ \`\`\`
537
+
538
+ ## What the element does
539
+
540
+ - It draws the first of these that holds a document: the \`spec\` property, the \`text\` property
541
+ (an answer so far), or a \`<script type="application/json">\` child, which a server that renders
542
+ the page writes and the element draws with no script on the page.
543
+ - \`streaming\` is the page's to set: on while an answer arrives, off when it ends, so an answer cut
544
+ short reports what it lacks. A page that never sets it gives each chunk of \`text\` as a new whole
545
+ document, whose faults are told again and whose unfinished elements are not drawn.
546
+ - \`members\` is an attribute (names separated by spaces, or a JSON array) and a property. A value
547
+ that is not a list of names allows no member, and is a fault at the path \`members\`.
548
+ - \`addresses="refused"\` (an attribute and a property) passes no address and draws no member that
549
+ needs one, as the skill's step 3 says. A change to \`members\` or \`addresses\` draws anew.
550
+ - \`poly-action\` carries \`{ name, args, values, changed }\`, as an action does in React. A listener
551
+ hands the member a promise with \`event.waitUntil(promise)\`, while the event is dispatched:
552
+ ${f.m("ConfirmDialog")} stays open and busy until it settles.
553
+ - \`poly-fault\` carries \`{ path, message, component? }\`, once for each fault. \`faults="inline"\`
554
+ draws each fault in its node's place, for a page under construction.
555
+ - \`values\`, \`changed\` and \`check()\` read the drawing. \`check()\` is a promise of what the check
556
+ says of the document it draws, with its members and addresses; for \`text\` once \`streaming\` is
557
+ off, it is \`checkAnswer\`'s, so an answer cut short is a fault.
558
+ - A property set before the element is defined is read when it is.
559
+ `;
560
+ }
561
+ /** The run-time contract: what a document does, what each fault means, and the limits. */
562
+ function contractReference(registry) {
563
+ const f = new Facts(registry);
564
+ const screen = (name) => f.x(name, "@polymorph/screen");
565
+ const check = f.x("checkScreen", "@polymorph/screen/check");
566
+ return `# The run-time contract
567
+
568
+ What a document does at run time is decided once, in the walk every renderer draws from, so a
569
+ document behaves the same in React and as elements.
570
+
571
+ ## An action with consequences
572
+
573
+ An action is a name and the form's values. The model chose the name, and each value is what a
574
+ control holds, so neither is the person's decision. A host that moves money, deletes or sends on an
575
+ action does four things:
576
+
577
+ 1. Maps the name to its own handler. The rules in its system prompt declare the names it handles.
578
+ 2. Reads \`values\` as input from the page: checks each value's type and range against its own data.
579
+ 3. Opens its own ${f.m("ConfirmDialog")}, outside the screen, controlled by
580
+ ${f.p("ConfirmDialog", "open")} and ${f.p("ConfirmDialog", "onOpenChange")}. Its words come from
581
+ the host's data and the values, never from the document. An agent on the page cannot confirm
582
+ it: the confirm is the person's.
583
+ 4. Sends the request to its server with an idempotency key made when the dialog opens. The server
584
+ authorises the person, reads the order from its own records, checks the amount again, and acts
585
+ at most once for each key, so a confirm pressed twice or a request sent again refunds once.
586
+
587
+ \`\`\`tsx
588
+ import { useState } from 'react'
589
+ import * as members from '@polymorph/react-ui'
590
+ import { ScreenView, type ScreenAction } from '@polymorph/react/screen'
591
+
592
+ import { MEMBERS } from './screen-members'
593
+ // Stand-in: your server's refund endpoint, which authorises, checks again and acts once for each
594
+ // key. It resolves with what the server did, in the host's words.
595
+ import { refund } from './refunds'
596
+
597
+ const { ConfirmDialog, Stack } = members
598
+
599
+ interface Order {
600
+ id: string
601
+ number: string
602
+ refundable: number
603
+ currency: string
604
+ }
605
+
606
+ interface Asked {
607
+ amount: number
608
+ reason: string
609
+ key: string
610
+ }
611
+
612
+ export function RefundScreen(props: {
613
+ answer: string
614
+ streaming: boolean
615
+ order: Order
616
+ send: (message: string) => void
617
+ }) {
618
+ const { answer, streaming, order, send } = props
619
+ const [asked, setAsked] = useState<Asked | null>(null)
620
+ const money = (amount: number) =>
621
+ new Intl.NumberFormat(undefined, { style: 'currency', currency: order.currency }).format(amount)
622
+
623
+ const onAction = (action: ScreenAction) => {
624
+ if (action.name !== 'requestRefund') {
625
+ send(\`An action from the screen: \${JSON.stringify(action)}\`)
626
+ return
627
+ }
628
+ const { amount, reason } = action.values
629
+ if (typeof amount !== 'number' || amount <= 0 || amount > order.refundable) {
630
+ send(\`The host refused the refund: the amount must be above 0 and at most \${order.refundable}.\`)
631
+ return
632
+ }
633
+ setAsked({ amount, reason: typeof reason === 'string' ? reason : '', key: crypto.randomUUID() })
634
+ }
635
+
636
+ return (
637
+ <Stack gap={4}>
638
+ <ScreenView
639
+ text={answer}
640
+ streaming={streaming}
641
+ members={members}
642
+ allow={MEMBERS}
643
+ data={{ order: order.number }}
644
+ onAction={onAction}
645
+ />
646
+ <ConfirmDialog
647
+ open={asked !== null}
648
+ onOpenChange={(open) => {
649
+ if (!open) setAsked(null)
650
+ }}
651
+ title={\`Refund order \${order.number}?\`}
652
+ description={asked === null ? '' : \`\${money(asked.amount)} goes back to the card that paid for this order.\`}
653
+ confirmLabel="Refund"
654
+ onConfirm={async () => {
655
+ if (asked === null) return
656
+ const outcome = await refund({ order: order.id, ...asked })
657
+ send(\`The host's refund: \${outcome}\`)
658
+ }}
659
+ />
660
+ </Stack>
661
+ )
662
+ }
663
+ \`\`\`
664
+
665
+ - The promise ${f.p("ConfirmDialog", "onConfirm")} returns keeps the confirm busy and the dialog
666
+ open until it settles. The dialog closes when it resolves, and stays open when it rejects.
667
+ - Sending the outcome to the model is a request; the model's next screen then reads what happened
668
+ from the host.
669
+
670
+ ## Data inputs
671
+
672
+ An input whose type is not a function is a data input, filled from the host's \`data\` by its name.
673
+ An input the host gives no value for is absent, never a placeholder: an optional prop bound to it
674
+ takes its default. A required prop bound to it is not passed, and once the document is whole it is
675
+ a fault (\`\` \`Select\` requires \`options\`, and the host's data holds nothing at \`choices\` \`\`). The
676
+ element is still drawn without it, so a screen keeps its shape while the host's data arrives.
677
+
678
+ A binding names a declared input, or a dotted path into one (\`order.number\`). Each name reads one
679
+ of the value's own properties, never one it inherits, so \`order.constructor\` reads nothing.
680
+
681
+ ## Callback inputs
682
+
683
+ An input whose type is a function is a callback input. What a member is handed for it is decided by
684
+ the prop, list item or structured object field the document binds it to:
685
+
686
+ | Bound where | It is |
687
+ | --- | --- |
688
+ | A callback that returns nothing receives it (${f.m("Button")}'s ${f.p("Button", "onClick")}, ${f.m("Pagination")}'s ${f.p("Pagination", "onPageChange")}) | an action: the host is told \`{ name, args, values, changed }\` |
689
+ | A callback that returns a value receives it (${f.m("DataTable")}'s ${f.p("DataTable", "getRowId")}) | a question the member asks while it draws. Where the prop may be left out, nothing is passed and the member answers as it does by default; where it is required, a stub answers by the return type (a key, \`false\`, \`0\`, an empty list). The host is never told |
690
+ | No callback receives it (${f.m("Button")}'s ${f.p("Button", "label")}, a child) | a fault, and nothing is passed |
691
+
692
+ A required callback the document leaves unbound gets the same stub, so a member that requires a
693
+ handler still draws.
694
+
695
+ ## What an action carries
696
+
697
+ \`args\` is what the member passed, reduced to JSON: text, numbers and booleans as themselves; \`NaN\`
698
+ and infinities as \`null\`; a date or a time as ISO 8601 text; a \`Set\` as a list, a \`Map\` as an
699
+ object; a file as \`{ size, name, type }\`. An event, a DOM node, an element and a function are
700
+ dropped at the end of the list and \`null\` before a kept argument, so each kept argument keeps its
701
+ position.
702
+
703
+ \`values\` holds every control that has a \`name\` and a controlled value (\`value\`, or a checkbox's
704
+ \`checked\`), whether or not it is on screen: a closed dialog's field, an unselected tab panel. A
705
+ control's value is, in order: what the person chose, until the document or the host gives it
706
+ another value; else the value the document or the host gives it; else its default; else the empty
707
+ value of its type: \`null\` where the type admits it, \`[]\` for a list, \`false\` for a checkbox or a
708
+ switch, \`""\` for text. A value is what the member reports: ${f.m("NumberInput")} a number,
709
+ ${f.m("Input")} text for every \`type\`.
710
+
711
+ - Two controls with one name are a fault, and \`values\` holds the last in document order.
712
+ - A control named \`__proto__\`, \`constructor\` or \`prototype\` is a fault and is left out.
713
+ - When a document binds a change event to an action (\`"onChange": { "$": "onEdit" }\`), the
714
+ screen holds the new value before it tells the host, so the action's \`values\` already has it.
715
+
716
+ ## Controls follow the reader
717
+
718
+ A value the person chose stands until the document or the host gives that prop a different value,
719
+ so a document replaced with the same value does not undo the person's typing. A document's value is
720
+ compared by content, the host's data by identity. A control the document gives no value keeps its
721
+ own state. A control that takes another name, or moves because an element is inserted before it, is
722
+ a new control.
723
+
724
+ ## Changing what is drawn
725
+
726
+ - **New data**: pass another \`data\` (\`screen.data\` on \`<poly-screen>\`). Only what is bound to a
727
+ value that changed is drawn again. In React, a new object that holds the same values draws nothing
728
+ again.
729
+ - **The same answer, growing**: each element stays drawn with its state, so a field the person is
730
+ typing in keeps its text and its focus.
731
+ - **A new answer**: a new document from its first character. The screen is empty until its root is
732
+ drawn, and the old screen's controls go with what was typed in them, which the action that led to
733
+ the answer already carried in \`values\`.
734
+ - **A document replaced whole**: pass it as \`document\` in React, \`spec\` on \`<poly-screen>\`. An
735
+ element at the same place with the same component, and for a named control the same name, keeps
736
+ its rendering and its state. A control that an inserted element moves to another place is drawn
737
+ as a new, empty control, and \`values\` no longer holds what was typed in it.
738
+
739
+ ## An element a required prop is missing from
740
+
741
+ Once the document is whole, an element whose required text or data (a label, an \`alt\`, options)
742
+ was never written, or was refused by another fault, is drawn as nothing, with a fault that names the
743
+ prop, and its controls hold no value. While the document streams it waits, with no fault.
744
+
745
+ - A required prop that takes any node is a slot (${f.m("FormPage")}'s ${f.p("FormPage", "actions")}).
746
+ An empty slot does not take out its element: the page is drawn with the slot empty.
747
+ - A member that reads one element it requires, as its child (${f.m("FormField")}'s control) or in a
748
+ prop that takes exactly one element (${f.m("SettingsRow")}'s ${f.p("SettingsRow", "control")}), is not
749
+ drawn without it; the element that holds it is.
750
+ - Still drawn: a required prop bound to data the host has not given yet, a refused address (a
751
+ ${f.m("Link")} without its \`href\` is not a link), and a required callback the document left
752
+ unbound.
753
+
754
+ ## Faults
755
+
756
+ Each fault is \`{ path, message, component? }\`, at the validator's paths (\`$.root.children[2]\`), told
757
+ once in a drawing when it first appears: to \`onFault\` in React, as \`poly-fault\` on
758
+ \`<poly-screen>\`. A drawing begins when the screen is made, when a stream begins, and when the host
759
+ gives a whole document that differs from the one drawn. While a document streams, nothing that has
760
+ not arrived is a fault.
761
+
762
+ | Fault | What it means for the host |
763
+ | --- | --- |
764
+ | \`no component called …\` | The vocabulary has no such member. The element is drawn as nothing. Ask again with the fault |
765
+ | \`… is not one of the members this host draws\` | A member outside the list. Drawn as nothing. Ask again, or widen the list and the card together |
766
+ | \`… has no prop …\` | The prop is not passed; the element is drawn without it |
767
+ | \`… takes a function\`, a callback input where no callback receives it | Not passed. If the prop was required text, the element is drawn as nothing |
768
+ | A function in the host's data bound by the document | Not passed. The document reached for something the host did not offer |
769
+ | \`… is not an address a screen may hold\` | The address is not passed. The element is drawn, inert |
770
+ | \`… is missing its required prop …\`, \`… is not drawn …\` | The element is drawn as nothing |
771
+ | A shared or inherited control name | \`values\` holds one control, or none |
772
+ | A member that threw as it rendered | Its node is drawn as nothing; the rest of the screen draws |
773
+ | Text that stops being JSON, at \`$\` | The answer broke off; the document holds what came before it |
774
+ | \`the answer ends before its document does\`, at \`$\` | ${f.x("checkAnswer", "@polymorph/screen/check")} only: the answer was cut off. Ask again with the fault |
775
+ | \`… takes an address, and this host takes none\` | Under \`addresses: 'refused'\`: not passed; the element is drawn without it |
776
+ | \`… requires an address at …\`, \`… draws the links and pictures its text writes\` | Under \`addresses: 'refused'\`: drawn as nothing |
777
+ | \`the document has no root element\`, at \`$.root\` | The answer ended with no document, or none that holds a root. Draw the renderer only for an answer that holds one |
778
+
779
+ A fault in the root element leaves nothing to draw. \`faults="inline"\` draws each fault in its
780
+ node's place, which helps while building a host.
781
+
782
+ ## Addresses
783
+
784
+ A string at a prop or object key that takes an address (\`avatar\`, \`href\`, \`nextHref\`,
785
+ \`previousHref\`, \`src\`, \`srcSet\`) is relative (\`/orders/1042\`, \`?page=2\`), a fragment
786
+ (\`#reason\`), or has the scheme \`http:\`, \`https:\`, \`mailto:\` or \`tel:\`. Any other scheme is a
787
+ fault and is not passed. An address with a control character anywhere is refused whole, and spaces
788
+ at either end are stripped before the scheme is read. Each address in a \`srcSet\` is held to the
789
+ same rule. The rule covers the document's values and a value a binding puts directly at an address;
790
+ it does not reach into an object the host binds whole.
791
+
792
+ With \`addresses: 'refused'\` (the skill's step 3), any value the document writes or binds at those
793
+ keys is a fault and is not passed, whatever its scheme, and the element is drawn without it. A
794
+ member that requires an address, in a prop or in a required field of the data type a prop takes,
795
+ and ${f.m("Markdown")}, which draws the links and pictures its text writes, are left out of the card
796
+ and drawn as nothing. A host that names one in its list is refused it all the same.
797
+
798
+ ## Limits
799
+
800
+ | Constant | Value | What is held to it |
801
+ | --- | --- | --- |
802
+ | ${f.x("MAX_DEPTH", "@polymorph/screen/partial")} | 128 | objects and lists nested in one another. Deeper text stops being read |
803
+ | ${screen("MAX_TYPE_LENGTH")} | 500 | characters of an input's type. A longer type is a fault, and the input has no value |
804
+ | ${screen("MAX_KEY_LENGTH")} | 100 | characters of a prop name or a field. A longer key is a fault, and what it holds is not read |
805
+ | ${screen("MAX_JSON_VALUES")} | 100,000 | values one action's \`args\` or one control's value reduces to. A cut is a fault |
806
+
807
+ No text and no value makes the reader, the check or the walk throw, and each takes time in
808
+ proportion to what it reads.
809
+
810
+ ## What is not checked
811
+
812
+ - The host's data inside a bound value: a list of the host's objects is passed as the host gave it.
813
+ - Where a link leads, and where a picture or a recording loads from.
814
+ - What ${f.m("Markdown")} draws from its text: links and pictures at \`http:\`, \`https:\`, \`mailto:\`
815
+ or no scheme. No other member draws Markdown, and a host that refuses addresses draws none.
816
+ - Ids and names, which can match the host's own. A control inside the host's \`<form>\` posts under
817
+ the document's name.
818
+ - Who called an action (the skill's step 8).
819
+ - What ${check} cannot see: it reads only the document, so what the walk refuses from the
820
+ host's data (an address, a function) is reported by the renderer, not the check.
821
+
822
+ ## A run-time document is not a spec to emit
823
+
824
+ The format and the validator are the same, so \`emit\` reads a document a model wrote. What happens
825
+ to it differs:
826
+
827
+ | | A spec \`emit\` compiles | A run-time document |
828
+ | --- | --- | --- |
829
+ | A data input | a prop the container passes | the host's \`data\` under its name, empty when absent |
830
+ | A callback input | a function the container passes | an action the host is told of |
831
+ | Members | every member the framework ships | the host's list |
832
+ | Checked by | \`validate\` | ${check}: the validator, then the run-time rules |
833
+ | Becomes | a source file, reviewed and built | a drawing in the person's page |
834
+ | Platforms | web, iOS and Android | web |
835
+ `;
836
+ }
837
+ /** Every export, prop, attribute and event, for a host that needs more than the procedure. */
838
+ function apiReference(registry, run) {
839
+ const f = new Facts(registry);
840
+ const walk = (name) => f.x(name, "@polymorph/screen/walk");
841
+ const react = (name) => f.x(name, "@polymorph/react/screen");
842
+ const elements = (name) => f.x(name, "@polymorph/elements-ui/screen");
843
+ return `# Reference: exports, props, attributes and events
844
+
845
+ ## \`@polymorph/screen\`
846
+
847
+ No framework, no DOM and no dependency: it runs in a page, a worker and a server. Each subpath loads
848
+ only what it needs.
849
+
850
+ | Import | Exports | Loads |
851
+ | --- | --- | --- |
852
+ | \`@polymorph/screen/partial\` | ${f.x("parsePartial", "@polymorph/screen/partial")}, ${f.x("MAX_DEPTH", "@polymorph/screen/partial")}, the type ${f.x("PartialDocument", "@polymorph/screen/partial")} | nothing else |
853
+ | \`@polymorph/screen/check\` | ${f.x("checkAnswer", "@polymorph/screen/check")}, ${f.x("checkScreen", "@polymorph/screen/check")} | the vocabulary table, the validator and the reader |
854
+ | \`@polymorph/screen/card\` | ${f.x("runtimeCard", "@polymorph/screen/card")}, ${f.x("outputContract", "@polymorph/screen/card")} | the table and the card |
855
+ | \`@polymorph/screen/walk\` | ${walk("createScreen")}, ${walk("materialize")}, the types ${walk("ScreenAction")}, ${walk("ScreenFault")}, ${walk("ScreenNode")}, ${walk("ScreenOptions")}, ${walk("ScreenUpdate")} | no table: a renderer hands it one |
856
+ | \`@polymorph/screen/vocabulary\` | ${f.x("VOCABULARY", "@polymorph/screen/vocabulary")}, the table generated from the release's registry | the table |
857
+ | \`@polymorph/screen\` | all of the above, the limits and the helpers the renderers share | everything |
858
+
859
+ \`checkAnswer(text, options)\`, \`checkScreen(document, options)\`, \`runtimeCard(options)\` and
860
+ \`outputContract(options)\` take:
861
+
862
+ | Option | What it is |
863
+ | --- | --- |
864
+ | \`framework\` | \`react\` (the default), \`vue\`, \`svelte\`, \`solid\`, \`angular\` or \`elements\`: the default members and which are absent |
865
+ | \`members\` | the names the host allows; the framework's default when absent |
866
+ | \`addresses\` | \`allowed\` (the default) or \`refused\`: no address passes, and no member that needs one |
867
+
868
+ \`checkScreen\` returns \`{ ok, faults }\`, each fault \`{ path, message }\`. \`checkAnswer\` returns
869
+ those and \`document\`, \`complete\` and \`prose\`, with an answer cut short as a fault at \`$\`.
870
+ \`outputContract\` is the card's last part alone.
871
+
872
+ \`parsePartial(text)\` returns:
873
+
874
+ | Field | What it is |
875
+ | --- | --- |
876
+ | \`document\` | the document so far; \`undefined\` before its first brace, and for an answer that is prose only |
877
+ | \`complete\` | whether the document's outermost brace has closed; \`false\` for an answer that is prose only |
878
+ | \`open\` | the path of the string still being written, or \`null\` |
879
+ | \`cut\` | the path of the innermost value the text ends inside, or \`null\` |
880
+ | \`error\` | \`{ at, message }\` where the text stops being JSON, or \`null\` |
881
+ | \`prose\` | the text outside the block that holds the document: before it, and after it once it closes; all the text when there is no document |
882
+ | \`fence\` | \`open\` from the block's first backtick until its closing line, then \`closed\`; \`null\` with no fence |
883
+
884
+ It reads the first fence marked \`json\`, or unmarked, and the first brace that opens an object when
885
+ the text has no fence. A name, a number, \`true\`, \`false\`, \`null\` and a binding are left out until
886
+ whole; a string a person reads is kept while it is written.
887
+
888
+ \`createScreen(options)\` is for a renderer of your own: \`document\`, \`vocabulary\`, \`framework\`,
889
+ \`members\`, \`data\`, \`fill\` (\`absent\` or \`sample\`), \`streaming\`, \`open\`, \`cut\`, \`onAction\` and
890
+ \`onFault\`. It returns a ${walk("Screen")}: \`root\`, \`faults\`, \`values\`, \`changed\`, \`fills\`,
891
+ \`streaming\`, \`update(change)\`, \`subscribe(listener)\` and \`fail(fault)\`.
892
+
893
+ ## The model's prose
894
+
895
+ \`parsePartial(answer).prose\` is the text around the document, for the page to draw as text beside
896
+ the screen. A fenced block in another language is prose, as the reader skips it. A last line that
897
+ may still become the document's fence (one to three backticks) is left out until it is whole. Draw
898
+ the prose with ${f.m("StreamingText")}, with ${f.p("StreamingText", "streaming")} on while \`fence\` is
899
+ not \`open\`. ${f.m("Markdown")} draws the links and pictures its text writes, so it is for a host
900
+ that allows them.
901
+
902
+ ## \`@polymorph/react/screen\`
903
+
904
+ A subpath of \`@polymorph/react\`; the foundation's root loads none of it. It exports
905
+ ${react("ScreenView")}, ${react("useScreen")} (the screen \`ScreenView\` draws, to read its
906
+ \`values\`, \`changed\`, \`faults\` and \`fills\`), ${react("ScreenDrawing")} (draws a \`Screen\`),
907
+ ${react("componentFor")} (the component a name resolves to among the members), \`parsePartial\`, and
908
+ the types \`ScreenAction\`, \`ScreenFault\`, ${react("ScreenViewProps")} and ${react("ScreenMembers")}.
909
+
910
+ | \`ScreenView\` prop | What it is |
911
+ | --- | --- |
912
+ | \`members\` | required: the components by member name. A part is read as \`members.Table.Row\` or \`members['Table.Row']\` |
913
+ | \`text\` | a model's answer so far |
914
+ | \`document\` | the document as an object, read when \`text\` is absent |
915
+ | \`cut\`, \`open\` | \`parsePartial\`'s, beside \`document\` |
916
+ | \`streaming\` | whether more is to come. With \`text\`, whether its document has not closed, unless given. Off while chunks still arrive, each chunk is a new whole document whose faults are told again |
917
+ | \`data\` | the host's data by input name |
918
+ | \`allow\` | the members a document may use. Read when the screen is made. Absent, every member React draws but \`ThirdParty\` and \`Toast\` |
919
+ | \`addresses\` | \`allowed\` (the default) or \`refused\`. Read when the screen is made |
920
+ | \`fill\` | \`absent\` (the default) or \`sample\`, which fills an input with no data from its type |
921
+ | \`onAction(action)\` | told each action; a promise it returns is what a member waits on |
922
+ | \`onFault(fault)\` | told each fault once |
923
+ | \`faults\` | \`hidden\` (the default) or \`inline\` |
924
+ | \`renderFault(fault, cause)\` | draws a fault in place when \`faults\` is \`inline\`. \`cause\` is \`unknown\`, \`refused\`, \`missing\`, \`threw\` or \`value\` |
925
+ | \`renderBinding(path, value)\` | draws a binding where something is drawn |
926
+ | \`decorate(drawn, node)\` | wraps the drawing of every node |
927
+ | \`fallback\` | what shows while a member that is not lazy suspends |
928
+
929
+ No handler runs while React renders, so a server render and strict mode's second render tell the
930
+ host nothing. Each node draws inside its own error boundary.
931
+
932
+ ### A host that parses the stream itself
933
+
934
+ A host that reads the answer itself, to log it or to show the prose before the fence, passes what
935
+ \`parsePartial\` returned. With \`cut\`, an element still being written waits as it does with
936
+ \`text\`; without it, every element that has arrived is drawn with the props it has so far.
937
+
938
+ \`\`\`tsx
939
+ import * as members from '@polymorph/react-ui'
940
+ import { parsePartial, ScreenView } from '@polymorph/react/screen'
941
+
942
+ import { MEMBERS } from './screen-members'
943
+
944
+ export function ParsedScreen({ answer, ended }: { answer: string; ended: boolean }) {
945
+ const read = parsePartial(answer)
946
+ return (
947
+ <ScreenView
948
+ document={read.document}
949
+ cut={read.cut}
950
+ open={read.open}
951
+ streaming={!ended && !read.complete}
952
+ members={members}
953
+ allow={MEMBERS}
954
+ />
955
+ )
956
+ }
957
+ \`\`\`
958
+
959
+ \`drawScreen\` takes the same four fields in its options and in \`update\`. \`<poly-screen>\` takes the
960
+ document as \`spec\` and nothing else, so it draws each element as it arrives with the props it has
961
+ so far.
962
+
963
+ ## \`@polymorph/elements-ui/screen\`
964
+
965
+ Importing it defines \`<poly-screen>\` and every element. It exports ${elements("drawScreen")},
966
+ \`checkAnswer\`, \`checkScreen\`, \`runtimeCard\`, \`outputContract\` and \`parsePartial\` bound to the elements,
967
+ ${elements("definePolyScreen")}, ${elements("PolyScreen")}, ${elements("SCREEN_TAG")},
968
+ ${elements("ACTION_EVENT")} (\`'poly-action'\`) and ${elements("FAULT_EVENT")} (\`'poly-fault'\`).
969
+
970
+ \`drawScreen(container, options)\` appends the drawing to a plain element. It takes \`document\`,
971
+ \`data\`, \`streaming\`, \`open\`, \`cut\`, \`members\`, \`addresses\`, \`faults\`, \`onAction\` and \`onFault\`, and no
972
+ \`text\`: a host that streams passes what \`parsePartial\` returned. It returns \`values\`, \`changed\`,
973
+ \`faults\`, \`update(change)\`, \`check()\` and \`dispose()\`.
974
+
975
+ ## \`<poly-screen>\`
976
+
977
+ | Attribute or property | What it is |
978
+ | --- | --- |
979
+ | \`spec\` (property) | the document |
980
+ | \`text\` (property) | a model's answer so far |
981
+ | \`data\` (property) | the host's data by input name |
982
+ | \`streaming\` (attribute and property) | more of the document is to come |
983
+ | \`members\` (attribute and property) | the members the host allows: names separated by spaces, or a JSON array |
984
+ | \`addresses\` (attribute and property) | \`allowed\` (the default) or \`refused\` |
985
+ | \`faults\` (attribute and property) | \`hidden\` (the default) or \`inline\` |
986
+ | \`values\`, \`changed\` (properties, read only) | each named control's value, and the names the person changed |
987
+ | \`check()\` (method) | a promise of what the check says of the document it draws; for \`text\` once \`streaming\` is off, of the answer |
988
+
989
+ | Event | \`detail\` |
990
+ | --- | --- |
991
+ | \`poly-action\` | \`{ name, args, values, changed }\`; \`event.waitUntil(promise)\` hands the member a promise |
992
+ | \`poly-fault\` | \`{ path, message, component? }\` |
993
+
994
+ Both bubble and are composed.
995
+
996
+ ## \`loadScreen()\`
997
+
998
+ \`polymorph.js\` and \`polymorph-all.js\` export ${f.x("loadScreen", "packages/elements-ui/src/cdn/polymorph.ts")}.
999
+ It resolves to \`drawScreen\`, \`parsePartial\`, \`checkAnswer\`, \`checkScreen\`, \`runtimeCard\` and
1000
+ \`outputContract\`, bound to the elements.
1001
+
1002
+ ## The tools while you build
1003
+
1004
+ Print the run-time card, or save an answer's document to a file to look at it:
1005
+
1006
+ ${commands(run, "card --runtime --framework react --members Stack,Card,Text,Button --addresses refused", `render answer.json --system ${DEFAULT_SYSTEM} --data data.json`, "validate answer.json --framework react", "component FormField --framework react")}
1007
+
1008
+ - \`card --runtime\` prints the card \`runtimeCard\` builds for the same \`--framework\` (\`react\` or
1009
+ \`elements\`), \`--members\` and \`--addresses\`, and its length in characters on stderr.
1010
+
1011
+ - \`render\` draws it with the React members, every member allowed, and reports layout faults.
1012
+ \`--data\` takes a JSON file of the host's data by input name. It does not apply the host's list
1013
+ or report a run-time fault, such as a refused address.
1014
+ - \`validate\` checks it as \`emit\` would: names, props, values, cells and usage rules. It does not
1015
+ apply the host's list or the run-time rules; only \`checkScreen\` does.
1016
+ - \`component\` prints what a member takes.
1017
+ `;
1018
+ }
1019
+ //#endregion
1020
+ export { runtimeSkill };