@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,1580 @@
1
+ import "../../../registry/src/platforms.js";
2
+ import { PUBLISHED_NAMES } from "../../../registry/src/install.js";
3
+ import { DEFAULT_SYSTEM } from "../plan.js";
4
+ import { Facts, SkillFactError, all, commands, either, skill } from "./facts.js";
5
+ //#region ../cli/src/skills/native.ts
6
+ /** Where the native names the texts cite are declared, below the repository root. */
7
+ var IOS_UI = "platforms/ios/Sources/PolymorphUI";
8
+ var IOS_CONTRACTS = "platforms/ios/Sources/PolymorphUI/Generated/Contracts.swift";
9
+ var IOS_TOKENS = "platforms/ios/Sources/PolymorphTokens";
10
+ var KOTLIN_UI = "platforms/android/ui/src/main/kotlin";
11
+ var KOTLIN_MEMBERS = "platforms/android/ui/src/generated/kotlin";
12
+ var KOTLIN_CONTRACTS = "platforms/android/ui/src/generated/kotlin/dev/polymorph/ui/Contracts.kt";
13
+ var KOTLIN_TOKENS = "platforms/android/tokens/src/main/kotlin";
14
+ var KOTLIN_CATALOGUE = "platforms/android/tokens/src/generated/kotlin";
15
+ var DART = "platforms/dart/lib";
16
+ /** The repository a native app depends on, by URL or through JitPack. */
17
+ var REPOSITORY = "https://github.com/metamorph-labs/polymorph";
18
+ /** `before`, `name` and `after` in code font, once `name` is declared at `from` (`Facts.x`). */
19
+ function x(f, name, from, before = "", after = "") {
20
+ f.x(name, from);
21
+ return `\`${before}${name}${after}\``;
22
+ }
23
+ /** A name both contracts declare, in code font, held to the Swift and the Kotlin file. */
24
+ function both(f, name) {
25
+ f.x(name, KOTLIN_CONTRACTS);
26
+ return x(f, name, IOS_CONTRACTS);
27
+ }
28
+ /** A slug as the native packages spell it: `deep-sea` is `deepSea`. */
29
+ var camel = (slug) => slug.replace(/-([a-z0-9])/g, (_, letter) => letter.toUpperCase());
30
+ /** What every native text reads from the registry. */
31
+ function nativeFacts(registry) {
32
+ const f = new Facts(registry);
33
+ const named = (system) => `${camel(system.name)}_${camel(system.defaultPalette)}`;
34
+ const pairings = registry.theme.systems.map(named);
35
+ const plain = registry.theme.systems.find((system) => system.name === DEFAULT_SYSTEM);
36
+ const pairing = `${camel(DEFAULT_SYSTEM)}_${camel(plain?.defaultPalette ?? "")}`;
37
+ if (!pairings.includes(pairing)) throw new SkillFactError(`no catalogue pairing ${pairing}`);
38
+ const tenant = registry.theme.systems.find((system) => system.kind === "tenant");
39
+ if (tenant === void 0) throw new SkillFactError("the catalogue has no system of kind tenant");
40
+ const grid = registry.components.filter((member) => member.grid !== null).filter((member) => ["variant", "tone"].every((p) => member.props.some((e) => e.name === p))).map((member) => member.name);
41
+ const adapted = registry.components.find((member) => member.platforms.ios.status === "adapted");
42
+ const absent = registry.components.find((member) => member.platforms.ios.status === "absent" && member.platforms.ios.substitute !== void 0 && member.platforms.ios.substitute !== "none");
43
+ if (adapted === void 0 || absent === void 0) throw new SkillFactError("the iOS map has no adapted member, or no absent one with a substitute");
44
+ const table = registry.components.find((member) => member.name === "Table");
45
+ const parts = table?.parts ?? [];
46
+ const carried = new Set((table?.props ?? []).filter((prop) => prop.name.includes(".")).map((prop) => prop.name.slice(0, prop.name.indexOf("."))));
47
+ const kept = parts.filter((part) => carried.has(part.name)).map((part) => part.name);
48
+ const lost = parts.filter((part) => !carried.has(part.name)).map((part) => part.name);
49
+ if (kept.length === 0 || lost.length === 0) throw new SkillFactError("Table carries every web part on a phone, or none");
50
+ const on = (name, platform, status) => {
51
+ const entry = registry.components.find((member) => member.name === name)?.platforms[platform];
52
+ if (entry?.status !== status) throw new SkillFactError(`${name} is not ${status} on ${platform}`);
53
+ return entry.as ?? "";
54
+ };
55
+ const renders = {
56
+ rangeIos: on("DateRangePicker", "ios", "adapted"),
57
+ tableIos: on("DataTable", "ios", "adapted"),
58
+ tableAndroid: on("DataTable", "android", "adapted")
59
+ };
60
+ on("DateRangePicker", "android", "native");
61
+ return {
62
+ f,
63
+ version: registry.version,
64
+ tag: `v${registry.version}`,
65
+ pairing,
66
+ pairings,
67
+ tenant: {
68
+ name: tenant.name,
69
+ pairing: named(tenant)
70
+ },
71
+ grid,
72
+ adapted: {
73
+ name: adapted.name,
74
+ as: adapted.platforms.ios.as ?? ""
75
+ },
76
+ absent: {
77
+ name: absent.name,
78
+ substitute: absent.platforms.ios.substitute
79
+ },
80
+ archetypes: f.tier("archetypes").filter((name) => name !== "AppShell"),
81
+ tableParts: {
82
+ kept: kept.map((part) => f.part("Table", part)),
83
+ lost: lost.map((part) => f.part("Table", part))
84
+ },
85
+ renders
86
+ };
87
+ }
88
+ /**
89
+ * The list screen both references work, as a spec for `platform`: what `validate` checks, and
90
+ * what the worked views are the hand-written form of.
91
+ */
92
+ function listSpec(platform) {
93
+ return `\`\`\`json
94
+ {
95
+ "spec": "polymorph-screen/1",
96
+ "name": "${platform === "ios" ? "OrdersView" : "OrdersScreen"}",
97
+ "purpose": "Every order, searchable and filtered by the day it was placed; a tap opens one.",
98
+ "platform": "${platform}",
99
+ "types": { "@polymorph/react-ui": ["DataTableColumn", "DateRange"], "./orders": ["Order"] },
100
+ "inputs": [
101
+ { "name": "orders", "type": "Order[]", "doc": "Already searched and filtered." },
102
+ { "name": "columns", "type": "DataTableColumn<Order>[]" },
103
+ { "name": "query", "type": "string" },
104
+ { "name": "placed", "type": "DateRange | null" },
105
+ { "name": "isFiltered", "type": "boolean" },
106
+ { "name": "getRowId", "type": "(order: Order) => string" },
107
+ { "name": "onOpenOrder", "type": "(order: Order) => void" },
108
+ { "name": "onQueryChange", "type": "(query: string) => void" },
109
+ { "name": "onPlacedChange", "type": "(placed: DateRange | null) => void" },
110
+ { "name": "onClearFilters", "type": "() => void" }
111
+ ],
112
+ "root": {
113
+ "component": "ListPage",
114
+ "props": {
115
+ "title": "Orders",
116
+ "emptyState": {
117
+ "$object": {
118
+ "title": "No orders match these filters",
119
+ "icon": "search",
120
+ "secondaryAction": {
121
+ "component": "Button",
122
+ "props": { "label": "Clear filters", "variant": "ghost", "tone": "neutral", "onClick": { "$": "onClearFilters" } }
123
+ }
124
+ }
125
+ },
126
+ "filters": {
127
+ "component": "FilterBar",
128
+ "props": {
129
+ "isFiltered": { "$": "isFiltered" },
130
+ "onClear": { "$": "onClearFilters" },
131
+ "search": {
132
+ "component": "SearchInput",
133
+ "props": { "aria-label": "Search orders", "size": "sm", "value": { "$": "query" }, "onChange": { "$": "onQueryChange" } }
134
+ }
135
+ },
136
+ "children": [
137
+ {
138
+ "component": "DateRangePicker",
139
+ "props": { "aria-label": "Placed between", "size": "sm", "value": { "$": "placed" }, "onChange": { "$": "onPlacedChange" } }
140
+ }
141
+ ]
142
+ }
143
+ },
144
+ "children": [
145
+ {
146
+ "component": "DataTable",
147
+ "props": {
148
+ "label": "Orders",
149
+ "columns": { "$": "columns" },
150
+ "data": { "$": "orders" },
151
+ "getRowId": { "$": "getRowId" },
152
+ "onRowClick": { "$": "onOpenOrder" },
153
+ "emptyState": { "$object": { "title": "No orders yet", "icon": "inbox" } }
154
+ }
155
+ }
156
+ ]
157
+ }
158
+ }
159
+ \`\`\``;
160
+ }
161
+ function nativeSkill(registry, run) {
162
+ const n = nativeFacts(registry);
163
+ const { f, tag } = n;
164
+ const body = `
165
+ # Build a SwiftUI or Compose screen with polymorph
166
+
167
+ Polymorph is a closed vocabulary of interface components, called members. On iOS they are SwiftUI
168
+ views and on Android Jetpack Compose composables, each drawn from the platform's own controls. A
169
+ member keeps its name with a \`PM\` prefix (${f.m("Button")} is ${x(f, "PMButton", IOS_UI)}), its
170
+ props and its events. The theme decides every colour, length, font and motion: one pairing, a
171
+ system worn with a palette, installed at the app's root. A screen composes members and binds data
172
+ and actions to them. It decides no style.
173
+
174
+ ## 1. Find the platform
175
+
176
+ | The repository has | The platform | Then read |
177
+ | --- | --- | --- |
178
+ | \`import PolymorphUI\`, or the PolymorphUI library in \`Package.swift\` or the Xcode project | \`ios\`, SwiftUI | [references/swiftui.md](references/swiftui.md) |
179
+ | \`import dev.polymorph.ui\`, or \`com.github.metamorph-labs.polymorph:ui\` or \`dev.polymorph:ui\` in a Gradle file | \`android\`, Compose | [references/compose.md](references/compose.md) |
180
+ | \`polymorph_tokens:\` in \`pubspec.yaml\` | Flutter or Dart: the tokens only | [references/flutter.md](references/flutter.md) |
181
+ | An Xcode project, a \`Package.swift\` or a Gradle build without these | Add the packages | step 2 |
182
+ | No Xcode project, no \`Package.swift\` and no Gradle build | Start the app | step 2 |
183
+
184
+ ## 2. Add the packages at a release
185
+
186
+ The packages are released at the git tag \`${tag}\`, and every line the references give names
187
+ that release. A newer release is the same lines with its version.
188
+
189
+ | Platform | What the app adds | The lines |
190
+ | --- | --- | --- |
191
+ | iOS 17 or macOS 14 and later | One Swift package by the repository's URL, \`${REPOSITORY}\`, with two libraries: PolymorphTokens, each catalogue pairing as a ${x(f, "PMTheme", IOS_TOKENS)}, and PolymorphUI, the members | [references/swiftui.md](references/swiftui.md) |
192
+ | Android | Two Gradle modules that JitPack builds from the tag, \`com.github.metamorph-labs.polymorph:tokens:${tag}\` and \`com.github.metamorph-labs.polymorph:ui:${tag}\`, or the same modules from a checkout of polymorph | [references/compose.md](references/compose.md) |
193
+ | Flutter or Dart | The tokens only: polymorph has no Flutter members | [references/flutter.md](references/flutter.md) |
194
+
195
+ An iOS app is an Xcode project and an Android app is a Gradle build, and the IDE writes each. When
196
+ the repository has neither, ask the person to create the app: in Xcode, File › New › Project ›
197
+ App, with the SwiftUI interface; in Android Studio, New Project › Empty Activity, which is
198
+ Compose. Then add the packages. Until the iOS app exists, its screens can live in a Swift
199
+ package's library target, which \`swift build\` compiles on a Mac and the app later adds as a
200
+ local package. [references/swiftui.md](references/swiftui.md) has that \`Package.swift\`.
201
+
202
+ ## 3. Read the vocabulary for the platform
203
+
204
+ The polymorph tools run from a shell with Node.js 24 or later. Every command starts with the same
205
+ words:
206
+
207
+ ${commands(run, "card --framework react --platform ios", "search date --framework react --platform android", "component DatePicker --framework react")}
208
+
209
+ \`card\` prints every member with its props, its variant and tone pairs and its parts, then the
210
+ icon roles and a Platforms section. \`--framework react\` names the whole vocabulary by its spec's
211
+ names. \`--platform\` (\`ios\` or \`android\`) leaves out the members absent there, says how an
212
+ adapted member renders, and lists each member's parts as that platform has them. \`search\` finds
213
+ members by what they do. \`component\` prints one member's props with their types and defaults,
214
+ its parts on the web, its states, and under "Where it renders" a line per platform. A
215
+ \`polymorph/system-card.md\` in the repository is the web card. An MCP server named \`polymorph\`
216
+ answers the same through \`get_system_card\` and \`search_components\`, given \`framework\` and
217
+ \`platform\`, and \`get_component\`.
218
+
219
+ A member's line under "Where it renders" says one of three things:
220
+
221
+ | The line says | What to do |
222
+ | --- | --- |
223
+ | native | Use the member as the card lists it. |
224
+ | adapted | Use it the same way. It renders as the line says, such as ${f.m(n.adapted.name)} on iOS: ${n.adapted.as}. The member chooses by the device, so the screen never branches on it. |
225
+ | absent | Use the substitute the line names, such as ${f.m(n.absent.substitute)} for ${f.m(n.absent.name)}. Where it names none, the screen goes without it, or the need goes in a ${f.m("Bespoke")} zone (step 6). |
226
+
227
+ Take a member's parts from the platform's card, not from \`component\`. A phone carries only the
228
+ parts its contract declares: on iOS and Android ${f.m("Table")} is composed of
229
+ ${all(n.tableParts.kept)}, and has no ${either(n.tableParts.lost)}.
230
+
231
+ The props are the web's. A hyphenated name is camelCased (\`aria-label\` is \`ariaLabel\`), a
232
+ callback is called without the web's DOM event, and ${all(n.grid.map((name) => f.m(name)))} take
233
+ \`variant\` and \`tone\` as one \`appearance\`, a lawful pair. Every Swift or Kotlin name is the
234
+ web's with \`PM\` in front: the member ${x(f, "PMBadge", IOS_UI)}, its props
235
+ ${both(f, "PMBadgeProps")}, the enum of a prop that takes one of a few words
236
+ ${both(f, "PMBadgeTone")}, the web's data types ${both(f, "PMDateRange")} and
237
+ ${both(f, "PMCalendarDate")}, and a member's props passed as a value, ${both(f, "PMEmptyStateProps")}.
238
+ The reference for the platform has the rule in full, where the generated \`Contracts.swift\` or
239
+ \`Contracts.kt\` that declares every name is, and the command that prints one declaration.
240
+
241
+ ## 4. Emit the screen from a spec
242
+
243
+ A native screen is a stateless view of two values: the model, which is the data it shows, and the
244
+ actions, which are the code the app supplies. The app owns the store that holds the model, the
245
+ router and every asynchronous task. Write the screen as a spec whose \`platform\` is \`ios\` or
246
+ \`android\` (step 6 has one), and emit the view from the repository's root:
247
+
248
+ ${commands(run, "emit screens/orders.json Sources/AppScreens/OrdersView.swift", "emit screens/orders.json app/src/main/kotlin/com/acme/orders/OrdersScreen.kt")}
249
+
250
+ \`emit\` checks the spec as \`validate\` does, writes nothing when it finds a fault, and prints
251
+ each fault at its path. The \`platform\` decides the file: \`.swift\` for \`ios\`, \`.kt\` for
252
+ \`android\`, and no \`--framework\`. It writes below the directory it runs in, which holds the
253
+ app's \`Package.swift\`, \`.xcodeproj\`, \`.xcworkspace\` or Gradle build and takes only that
254
+ platform's screens. A Kotlin file declares the package its directory names below \`kotlin/\`.
255
+ After a change to the spec, emit again: \`emit\` replaces its own file, hand edits included, and
256
+ refuses any other.
257
+
258
+ | Part | SwiftUI | Compose |
259
+ | --- | --- | --- |
260
+ | The model: \`loadStatus\` first, then each piece of data | \`struct <Name>Model\` | \`data class <Name>Model\`, with an empty \`companion object\` |
261
+ | The actions: one for each thing the app does | \`struct <Name>Actions\` of \`@MainActor\` closures | \`interface <Name>Actions\` of functions |
262
+ | The view | \`@MainActor struct <Name>View: View\` with \`let model\` and \`let actions\` | \`@Composable fun <Name>Screen(model, actions)\` |
263
+ | Actions that do nothing, until the store is wired | \`static let inert\` on the actions | \`object <Name>Inert : <Name>Actions\` |
264
+
265
+ A spec has no condition, loop or handler body, so a view that draws a part only when the model
266
+ says so, or a ${x(f, "PMBespoke", IOS_UI)} zone's drawing, is written by hand in the same shape.
267
+ Every view keeps five rules, which an emitted one keeps by construction:
268
+
269
+ 1. Its root is a page archetype: ${all(n.archetypes.map((name) => f.m(name)))}. It passes
270
+ \`model.loadStatus\`, a ${x(f, "PMLoadStatus", IOS_UI)}, to the archetype, which draws the four
271
+ states. The cases are \`.loading\`, \`.ready\`, \`.empty\` and \`.failed(message:)\` in Swift,
272
+ and the same words capitalised in Kotlin, such as \`PMLoadStatus.Failed(message)\`. \`loading\`
273
+ draws skeleton rows. \`failed\` draws a danger alert with the message, with "Try again" when the
274
+ archetype's \`onRetry\` is set. \`empty\` draws ${f.m("ListPage")}'s or ${f.m("SearchPage")}'s
275
+ ${f.p("ListPage", "emptyState")}, and draws as \`ready\` elsewhere. The header, and a
276
+ ${f.m("ListPage")}'s ${f.p("ListPage", "summary")} and ${f.p("ListPage", "filters")}, stay
277
+ drawn in every state.
278
+ 2. It holds no state: no \`@State\` or \`@Environment\`, no \`remember\` or \`mutableStateOf\`. A
279
+ member keeps its own state, such as a field's draft or an open sheet.
280
+ 3. It calls nothing asynchronous: no \`.task\` or \`Task { }\`, no \`LaunchedEffect(…)\`. The route
281
+ that shows the view starts the load.
282
+ 4. It navigates nowhere: no \`NavigationLink(…)\` and no \`navigate(…)\`. Opening something is an
283
+ action the app implements.
284
+ 5. It names no theme and no token.
285
+
286
+ The view hands what was tapped to an action, as in \`onRowClick: actions.onOpenOrder\`. The store
287
+ implements the action by changing the app's router. The router is the platform's own, written in
288
+ app code at the app's root: \`NavigationStack(path:) { … }\` with \`.navigationDestination(for:)\`
289
+ in SwiftUI, Navigation Compose's \`NavHost(…) { … }\` in Compose. ${f.m("AppShell")} is the app's
290
+ frame around that router, never a screen's root. On iOS it already draws its content inside a
291
+ navigation stack of its own, so the app adds its destinations to that content and nests no second
292
+ stack. In Compose the app's navigation host is its content. The system's back stays: the
293
+ navigation bar's back button and the edge swipe on iOS, the back gesture on Android. No member
294
+ hides it, and the app does not hide it either. ${f.m("DetailPage")}'s ${f.p("DetailPage", "onBack")}
295
+ is an action too, which the app implements by popping the same router.
296
+
297
+ The reference for the platform has two worked screens, a settings page and a list, in the shape
298
+ \`emit\` writes, and the store, the route and the root around the list.
299
+
300
+ ## 5. Install the theme at the root
301
+
302
+ | | SwiftUI | Compose |
303
+ | --- | --- | --- |
304
+ | Install the pairing | ${x(f, "pmTheme", IOS_UI, ".", `(.${n.pairing})`)} on the root view | ${x(f, "ProvidePMTheme", KOTLIN_UI, "", `(PMThemes.${n.pairing}) { … }`)}, which also gives Material 3 the pairing |
305
+ | Before the app installs one | \`PMTheme.default\`, which is \`.${n.pairing}\` | \`PMThemes.default\`, the same |
306
+ | Light and dark | Each colour resolves in the colour scheme it is drawn in. ${x(f, "preferredColorScheme", IOS_TOKENS, ".preferredColorScheme(theme.", ")")} draws the pairing in its own mode. | The system's mode. ${x(f, "preferredDark", KOTLIN_TOKENS, "dark = theme.")} draws the pairing in its own mode. |
307
+
308
+ The packages carry each system worn with its default palette, named \`<system>_<palette>\`:
309
+ ${n.pairings.map((name) => `\`.${name}\``).join(", ")}. \`PMTheme.named(system:palette:)\` and
310
+ \`PMThemes.named(system, palette)\` find one by its two names. The card's Theme section lists each
311
+ system with its kind. \`tenant\`, as on ${n.tenant.name}'s line, marks a system that takes a
312
+ designed system's axes with another brand's seeds. It says nothing about how an app gets it:
313
+ ${n.tenant.name} is \`.${n.tenant.pairing}\` like the rest. A system worn with another palette is
314
+ not in the packages. On iOS a theme outside the catalogue arrives as a token document that a server
315
+ admits ([references/swiftui.md](references/swiftui.md)). The Kotlin and Dart token packages read
316
+ no documents, so Android and Flutter wear catalogue pairings only.
317
+
318
+ A pairing names its font families and carries no font files: \`theme.fonts.body\`, \`.heading\`,
319
+ \`.display\` and \`.mono\`, each with its \`family\`. \`heading\` is the face of \`text.lg\` to
320
+ \`text.3xl\`, and in a system with no heading slot it is the body slot. Each is the web's family
321
+ without the web's "Variable" suffix, so read it from the pairing, not from the card. The app
322
+ bundles the files: on iOS it adds them to the app target and lists them under
323
+ \`<key>UIAppFonts</key>\` in its Info.plist, and on Android it provides
324
+ ${x(f, "LocalPMFontFamilies", KOTLIN_UI)}. Until it does, each type step uses the system font in
325
+ its slot's design.
326
+
327
+ The app sets the pairing, the mode, its fonts and its translations of the words the members write
328
+ by default, such as a dialog's "Close". It never overrides a member's colour, size or font, and
329
+ never installs a second pairing on part of a screen. ${f.m("DensityScope")} and
330
+ ${f.m("ToneScope")} re-assign density and the inverse tone for a subtree, as on the web: the
331
+ \`polymorph-rules\` skill has the exception ladder, which holds on every platform.
332
+
333
+ ## 6. Check your own work
334
+
335
+ \`check\` and \`validate\` lint web code and apply no rule to a \`.swift\` or \`.kt\` file. What
336
+ either prints about a native repository is not a result: a clean report says nothing about the
337
+ screen. \`check\` takes one directory, and \`validate\` takes files or a spec. Run these four
338
+ checks, in this order:
339
+
340
+ 1. Build. A member the package does not draw, an action the store does not implement, an argument
341
+ of the wrong type, and in Swift an argument out of the initialiser's order each fail to
342
+ compile. The reference for the platform has the command.
343
+ 2. Search the view files, not the store's or the route's, for what a screen may not write. The
344
+ reference for the platform has the search. Replace each hit as the table below says.
345
+ 3. Check the composition as a spec. \`emit\` checked the spec of an emitted view. For a view
346
+ written by hand, write its tree as a screen spec whose \`platform\` is \`ios\` or \`android\`, and
347
+ run \`${run} validate orders.json --framework react\`. \`validate\` takes no \`--platform\` flag:
348
+ the spec's own field carries the platform, and \`react\` is the one framework it accepts with a
349
+ native spec. It names a member the platform lacks with its substitute, a part the platform lacks
350
+ with the parts it has, a prop the member does not take, and a required prop left out.
351
+ 4. Run the app in the simulator or an emulator when the session can, in light and dark mode, at a
352
+ phone's width and at the largest text size.
353
+
354
+ | A hit | Write instead |
355
+ | --- | --- |
356
+ | A colour: \`Color(…)\`, \`.foregroundStyle(…)\`, \`MaterialTheme.colorScheme\` | A member's \`tone\` or \`variant\` |
357
+ | A layout container: \`VStack { }\`, \`HStack { }\`, \`Column { }\`, \`Row { }\` | ${all([
358
+ "Stack",
359
+ "Inline",
360
+ "Grid"
361
+ ].map((name) => f.m(name)))} |
362
+ | A length: \`.padding(…)\`, \`.frame(…)\`, \`16.dp\`, \`Modifier.size(…)\` | Their spacing steps: ${all(f.shared([
363
+ "Stack",
364
+ "Inline",
365
+ "Grid"
366
+ ], [
367
+ "gap",
368
+ "p",
369
+ "px",
370
+ "py"
371
+ ]))} |
372
+ | A font: \`.font(…)\`, \`fontSize = 20.sp\` | ${f.m("Heading")}'s ${f.p("Heading", "level")}, ${f.m("Text")}'s ${f.p("Text", "size")} and ${f.p("Text", "tone")} |
373
+ | A platform control: \`Button(…)\`, \`Toggle(…)\`, \`TextField(…)\`, \`Picker(…)\`, Material's \`Switch(…)\` | The member: ${x(f, "PMButton", IOS_UI)}, ${x(f, "PMSwitch", IOS_UI)}, ${x(f, "PMInput", IOS_UI)}, ${x(f, "PMSelect", IOS_UI)} |
374
+ | An icon: \`Image(systemName:)\`, \`Icon(Icons.…)\` | ${x(f, "PMIcon", IOS_UI)} with a role, or a member's \`icon\` |
375
+ | Motion: \`withAnimation\`, \`.animation(…)\`, \`animate…AsState\` | Nothing: members animate their own states |
376
+ | State, a task or navigation | The store and the route (step 4) |
377
+ | What no member draws | A ${x(f, "PMBespoke", IOS_UI)} zone with its \`reason\`, drawn from the theme's tokens (the reference has one) |
378
+
379
+ A spec, for \`emit\` or for check 3, spells each prop as the web does (\`aria-label\`, \`variant\` and
380
+ \`tone\`), writes a plain object such as an empty state as \`{ "$object": { … } }\`, and binds every
381
+ value the app supplies to an input. On a native archetype it may also bind \`onRetry\` to an action.
382
+ The \`polymorph-screen\` skill has the format. This is the list screen the references work, for iOS
383
+ (\`"platform": "android"\` and \`"name": "OrdersScreen"\` make it Android's):
384
+
385
+ ${listSpec("ios")}
386
+
387
+ ## 7. Let a member behave like the platform's own control
388
+
389
+ A native member behaves like the same control in any other app on its platform, and the app does
390
+ not work around it. Do not wrap a member in modifiers that change its size, its tap area, its
391
+ colours or its behaviour. Do not swap a member for a UIKit view or a Material component to make it
392
+ behave otherwise. Where a member differs from its web rendering, the difference is decided: on
393
+ iOS ${f.m("DatePicker")} is SwiftUI's own date picker, and UIKit sets its tap area. When a screen
394
+ seems to need a member to behave otherwise, tell the person which member and what the screen
395
+ needs. The change belongs in a polymorph release.
396
+
397
+ ## What you cannot do here
398
+
399
+ - Draw a native screen with the tools. \`render\` draws web specs in a browser.
400
+ - Change a member. \`add\` and \`update\` copy web members only. Never edit the package's copy
401
+ (\`.build/checkouts/polymorph\`, Xcode's package cache or Gradle's): a change to a member is a
402
+ polymorph release.
403
+ - Wear a theme outside the catalogue on Android or in Flutter.
404
+ `;
405
+ return [
406
+ {
407
+ path: "polymorph-native/SKILL.md",
408
+ contents: skill("polymorph-native", "Build or change a SwiftUI or Jetpack Compose screen with the polymorph design system's native members, or add them to a new or existing iOS or Android app. Use when Swift code imports PolymorphUI or PolymorphTokens, when Package.swift or an Xcode project names github.com/metamorph-labs/polymorph, when a Gradle build depends on com.github.metamorph-labs.polymorph (JitPack) or dev.polymorph and Kotlin imports dev.polymorph.ui, when pubspec.yaml names polymorph_tokens, or when asked to use polymorph on iOS, Android, SwiftUI, Compose or Flutter. Covers the Swift package and JitPack lines, the PM-prefixed names (PMButton, PMBadgeTone, PMDateRange) and where they are declared, the native screen contract (model, actions, a stateless view, four load states), emitting it from a spec, a list screen (ListPage, FilterBar, DataTable) with its store and navigation, installing a pairing with pmTheme or ProvidePMTheme and its fonts, the members and parts a platform adapts or lacks, and checking a screen no lint reads.", body)
409
+ },
410
+ {
411
+ path: "polymorph-native/references/swiftui.md",
412
+ contents: swiftReference(registry)
413
+ },
414
+ {
415
+ path: "polymorph-native/references/compose.md",
416
+ contents: composeReference(registry)
417
+ },
418
+ {
419
+ path: "polymorph-native/references/flutter.md",
420
+ contents: flutterReference(registry)
421
+ }
422
+ ];
423
+ }
424
+ /** SwiftUI: how a member is written, two worked screens, the app around them and other themes. */
425
+ function swiftReference(registry) {
426
+ const { f, pairing, version, renders } = nativeFacts(registry);
427
+ const engine = PUBLISHED_NAMES["@polymorph/engine"];
428
+ const range = registry.packages["@polymorph/engine"];
429
+ if (engine === void 0 || range === void 0) throw new SkillFactError("the registry has no published name or range for @polymorph/engine");
430
+ return `# SwiftUI: members, two worked screens and the app around them
431
+
432
+ ## Add the package
433
+
434
+ SwiftPM reads the package by the repository's URL, takes its version from the release tag, and
435
+ names it \`polymorph\`. A Swift package that holds an app's screens before the app exists is this
436
+ whole \`Package.swift\`, with its sources in \`Sources/AppScreens/\`:
437
+
438
+ \`\`\`swift
439
+ // swift-tools-version: 5.9
440
+ import PackageDescription
441
+
442
+ let package = Package(
443
+ name: "AppScreens",
444
+ platforms: [.iOS(.v17), .macOS(.v14)],
445
+ products: [.library(name: "AppScreens", targets: ["AppScreens"])],
446
+ dependencies: [
447
+ .package(url: "${REPOSITORY}", from: "${version}"),
448
+ ],
449
+ targets: [
450
+ .target(
451
+ name: "AppScreens",
452
+ dependencies: [
453
+ .product(name: "PolymorphTokens", package: "polymorph"),
454
+ .product(name: "PolymorphUI", package: "polymorph"),
455
+ ]
456
+ ),
457
+ ]
458
+ )
459
+ \`\`\`
460
+
461
+ The \`platforms\` line is required: the libraries need iOS 17 or macOS 14, and SwiftPM refuses a
462
+ target that supports less. \`swift build\` compiles the package for the Mac. An existing package
463
+ adds the \`.package\` line and the two products to its own manifest.
464
+
465
+ An Xcode project with no \`Package.swift\` adds the package in Xcode: File › Add Package
466
+ Dependencies…, the URL above, Up to Next Major Version from ${version}, and both libraries on the
467
+ app's target. A package of screens is added with Add Local… in the same dialog. Xcode writes the
468
+ project file, so ask the person to take this step rather than editing \`project.pbxproj\`.
469
+
470
+ ## How a member is written
471
+
472
+ A file imports PolymorphUI, and also PolymorphTokens where it names a
473
+ ${x(f, "PMTheme", IOS_TOKENS)}. A member is a view built from one value of its
474
+ props, \`PM<Member>(props: .init(…))\`. The initialiser takes the props as labelled arguments, in
475
+ the order it declares them: the order \`component\` lists the props in, with
476
+ \`appearance\` where \`tone\` would be, and \`loadStatus\` and \`onRetry\` first on a page
477
+ archetype. When the order is wrong, the compiler names the argument that must come first.
478
+
479
+ | On the web | In SwiftUI |
480
+ | --- | --- |
481
+ | A member, ${f.m("Button")} | \`PMButton(props: .init(label: "Save"))\`, whose props are ${x(f, "PMButtonProps", IOS_CONTRACTS)} |
482
+ | A part, ${f.part("SettingsRow", "Group")} | Nested in the member: \`PMSettingsRow.Group(props: .init(…))\`, whose props are ${x(f, "PMSettingsRowGroupProps", IOS_CONTRACTS)}, as \`PMTable.Row(props: .init(…))\` takes ${x(f, "PMTableRowProps", IOS_CONTRACTS)} |
483
+ | A string or a boolean | Itself: \`label: "Save"\`, \`disabled: true\` |
484
+ | A number | A Swift Double: \`lines: 2\`. A ${both(f, "PMCalendarDate")}'s \`year\`, \`month\` and \`day\` are Doubles too. |
485
+ | A prop that takes one of a few words | A case of the enum \`PM<Member><Prop>\`: \`tone: .accent\` is a ${both(f, "PMBadgeTone")}. A hyphenated word is camelCased: \`.codeBlock\`. |
486
+ | A size, an icon role, a spacing step, a sort direction | One enum every member shares: \`size: .sm\` is a ${x(f, "PMControlSize", IOS_UI)}, \`icon: .add\` a ${both(f, "PMIconRole")}, \`gap: .s5\` a ${both(f, "PMSpaceStep")}, \`.desc\` a ${both(f, "PMSortDirection")} |
487
+ | ${f.m("Grid")}'s \`columns={2}\` | \`columns: .columns2\` |
488
+ | ${f.m("Button")}'s ${f.v("Button", "variant", "outline")} with ${f.v("Button", "tone", "danger")} | \`appearance: .outlineDanger\`: ${x(f, "PMButtonAppearance", IOS_UI)} holds only the lawful pairs |
489
+ | A child, or a prop that holds an element (\`control\`, \`trigger\`, \`actions\`) | ${x(f, "PMContent", IOS_UI)}, SwiftUI's type-erased view: \`AnyView(…)\`, and several as \`AnyView(Group { … })\` |
490
+ | Words where an element goes, as ${f.m("Text")}'s children or a table cell's | SwiftUI's \`AnyView(Text("…"))\`, which takes the member's type step and colour. ${x(f, "PMText", IOS_UI)} is for words with a size or tone of their own. |
491
+ | A callback, \`onClick\` | A \`@MainActor\` closure without the DOM event: \`onClick: actions.onSave\`, \`onChange: { value in … }\` |
492
+ | A value the app controls that may be null, as ${f.m("Select")}'s ${f.p("Select", "value")} | \`T??\`, written \`.some(model.frequency)\`: given, \`nil\` included. Left out, the member holds the value itself. A value that cannot be null is passed as itself: \`value: model.query\`. |
493
+ | A data type, such as ${x(f, "SelectOption", "@polymorph/react-ui")} or ${x(f, "DateRange", "@polymorph/react-ui")} | \`PM\` and its name: \`.option(PMSelectOption(value: "now", label: "As they happen"))\`, \`PMDateRange(start:end:)\` of two \`PMCalendarDate(year:month:day:)\` |
494
+ | A member's props passed as a value, as ${f.m("ListPage")}'s ${f.p("ListPage", "emptyState")} | That member's props struct: \`PMEmptyStateProps(icon: .search, title: "No orders match")\` |
495
+
496
+ ## Where the declarations are
497
+
498
+ \`Generated/Contracts.swift\` in PolymorphUI declares every props struct with its initialiser,
499
+ every enum and every data type. \`PolymorphUI.swift\` beside it declares ${x(f, "PMLoadStatus", IOS_UI)},
500
+ ${x(f, "PMControlSize", IOS_UI)} and ${x(f, "PMContent", IOS_UI)}. A Swift package has them under
501
+ \`.build/checkouts/polymorph/platforms/ios/Sources/PolymorphUI/\` once it has resolved, and an
502
+ Xcode project under \`SourcePackages/checkouts/polymorph/\` in its DerivedData folder. Find the
503
+ file, then print a declaration whole, up to its closing brace:
504
+
505
+ \`\`\`sh
506
+ C=$(find . ~/Library/Developer/Xcode/DerivedData -path '*/checkouts/polymorph/platforms/ios/Sources/PolymorphUI/Generated/Contracts.swift' 2>/dev/null | head -n 1)
507
+ sed -n '/^public struct PMListPageProps/,/^}/p' "$C"
508
+ sed -n '/^public enum PMBadgeTone/,/^}/p' "$C"
509
+ \`\`\`
510
+
511
+ ## A worked screen: settings
512
+
513
+ This view compiles against the package at the release tag. It is the shape \`emit\` writes from a
514
+ spec, and the shape a view written by hand keeps.
515
+
516
+ \`\`\`swift
517
+ import PolymorphUI
518
+ import SwiftUI
519
+
520
+ /// What \`NotificationsView\` shows. \`loadStatus\` says which of the four load states it is in.
521
+ struct NotificationsModel {
522
+ var loadStatus: PMLoadStatus
523
+ /// Whether the morning digest is on.
524
+ var digest: Bool
525
+ var frequency: String?
526
+ var frequencyOptions: [PMSelectOptionEntry]
527
+ }
528
+
529
+ /// The code the app supplies to \`NotificationsView\`, one closure per action.
530
+ struct NotificationsActions {
531
+ let onDigestChange: @MainActor (Bool) -> Void
532
+ let onFrequencyChange: @MainActor (String?) -> Void
533
+ let onSignOut: @MainActor () -> Void
534
+ }
535
+
536
+ /// Which emails the person receives, and a way to sign out.
537
+ @MainActor
538
+ struct NotificationsView: View {
539
+ let model: NotificationsModel
540
+ let actions: NotificationsActions
541
+
542
+ var body: some View {
543
+ PMSettingsPage(
544
+ props: .init(
545
+ loadStatus: model.loadStatus,
546
+ children: AnyView(
547
+ Group {
548
+ PMSettingsRow.Group(
549
+ props: .init(
550
+ children: AnyView(
551
+ Group {
552
+ PMSettingsRow(
553
+ props: .init(
554
+ control: AnyView(
555
+ PMSwitch(
556
+ props: .init(
557
+ checked: model.digest,
558
+ onCheckedChange: actions.onDigestChange
559
+ )
560
+ )
561
+ ),
562
+ description: "One email with what changed overnight.",
563
+ label: "Morning digest"
564
+ )
565
+ )
566
+ PMSettingsRow(
567
+ props: .init(
568
+ control: AnyView(
569
+ PMSelect(
570
+ props: .init(
571
+ onChange: actions.onFrequencyChange,
572
+ options: model.frequencyOptions,
573
+ value: .some(model.frequency)
574
+ )
575
+ )
576
+ ),
577
+ label: "Alerts"
578
+ )
579
+ )
580
+ }
581
+ ),
582
+ title: "Email"
583
+ )
584
+ )
585
+ PMSettingsRow.Group(
586
+ props: .init(
587
+ children: AnyView(
588
+ PMSettingsRow(
589
+ props: .init(
590
+ control: AnyView(
591
+ PMButton(
592
+ props: .init(
593
+ label: "Sign out",
594
+ onClick: actions.onSignOut,
595
+ appearance: .outlineDanger
596
+ )
597
+ )
598
+ ),
599
+ label: "This device"
600
+ )
601
+ )
602
+ ),
603
+ title: "Account"
604
+ )
605
+ )
606
+ }
607
+ ),
608
+ title: "Notifications"
609
+ )
610
+ )
611
+ }
612
+ }
613
+
614
+ extension NotificationsActions {
615
+ /// Every action doing nothing, so the app compiles before it wires its store.
616
+ @MainActor static let inert: Self = Self(
617
+ onDigestChange: { _ in },
618
+ onFrequencyChange: { _ in },
619
+ onSignOut: {}
620
+ )
621
+ }
622
+ \`\`\`
623
+
624
+ ## A worked screen: a list
625
+
626
+ A records screen is a ${f.m("ListPage")}. Its ${f.p("ListPage", "filters")} hold a
627
+ ${f.m("FilterBar")} with the search field in ${f.p("FilterBar", "search")} and the other filters as
628
+ its children, and its body is a ${f.m("DataTable")}. On iOS ${f.m("DateRangePicker")} is
629
+ adapted: ${renders.rangeIos}. ${f.m("DataTable")} is adapted too: ${renders.tableIos}, a row's
630
+ cells stacked in the list. A tap on a row calls ${f.p("DataTable", "onRowClick")} with the row.
631
+ \`emit\` writes this view, apart from its comments, from the spec in the skill's step 6 with
632
+ \`onRetry\` bound as well.
633
+
634
+ \`\`\`swift
635
+ import PolymorphUI
636
+ import SwiftUI
637
+
638
+ /// What \`OrdersView\` shows. \`loadStatus\` says which of the four load states it is in.
639
+ struct OrdersModel {
640
+ var loadStatus: PMLoadStatus
641
+ /// Already searched and filtered.
642
+ var orders: [Order]
643
+ var columns: [PMDataTableColumn<Order>]
644
+ var query: String
645
+ var placed: PMDateRange?
646
+ var isFiltered: Bool
647
+ }
648
+
649
+ /// The code the app supplies to \`OrdersView\`, one closure per action.
650
+ struct OrdersActions {
651
+ let getRowId: @MainActor (Order) -> String
652
+ let onOpenOrder: @MainActor (Order) -> Void
653
+ let onQueryChange: @MainActor (String) -> Void
654
+ let onPlacedChange: @MainActor (PMDateRange?) -> Void
655
+ let onClearFilters: @MainActor () -> Void
656
+ let onRetry: @MainActor () -> Void
657
+ }
658
+
659
+ /// Every order, searchable and filtered by the day it was placed; a tap opens one.
660
+ @MainActor
661
+ struct OrdersView: View {
662
+ let model: OrdersModel
663
+ let actions: OrdersActions
664
+
665
+ var body: some View {
666
+ PMListPage(
667
+ props: .init(
668
+ loadStatus: model.loadStatus,
669
+ onRetry: actions.onRetry,
670
+ children: AnyView(
671
+ PMDataTable(
672
+ props: .init(
673
+ columns: model.columns,
674
+ data: model.orders,
675
+ emptyState: PMEmptyStateProps(icon: .inbox, title: "No orders yet"),
676
+ getRowId: actions.getRowId,
677
+ label: "Orders",
678
+ onRowClick: actions.onOpenOrder
679
+ )
680
+ )
681
+ ),
682
+ emptyState: PMEmptyStateProps(
683
+ icon: .search,
684
+ secondaryAction: AnyView(
685
+ PMButton(
686
+ props: .init(
687
+ label: "Clear filters",
688
+ onClick: actions.onClearFilters,
689
+ appearance: .ghostNeutral
690
+ )
691
+ )
692
+ ),
693
+ title: "No orders match these filters"
694
+ ),
695
+ filters: AnyView(
696
+ PMFilterBar(
697
+ props: .init(
698
+ children: AnyView(
699
+ PMDateRangePicker(
700
+ props: .init(
701
+ ariaLabel: "Placed between",
702
+ onChange: actions.onPlacedChange,
703
+ size: .sm,
704
+ value: .some(model.placed)
705
+ )
706
+ )
707
+ ),
708
+ isFiltered: model.isFiltered,
709
+ onClear: actions.onClearFilters,
710
+ search: AnyView(
711
+ PMSearchInput(
712
+ props: .init(
713
+ ariaLabel: "Search orders",
714
+ onChange: actions.onQueryChange,
715
+ size: .sm,
716
+ value: model.query
717
+ )
718
+ )
719
+ )
720
+ )
721
+ )
722
+ ),
723
+ title: "Orders"
724
+ )
725
+ )
726
+ }
727
+ }
728
+
729
+ extension OrdersActions {
730
+ /// Every action doing nothing, so the app compiles before it wires its store.
731
+ @MainActor static let inert: Self = Self(
732
+ getRowId: { _ in "" },
733
+ onOpenOrder: { _ in },
734
+ onQueryChange: { _ in },
735
+ onPlacedChange: { _ in },
736
+ onClearFilters: {},
737
+ onRetry: {}
738
+ )
739
+ }
740
+ \`\`\`
741
+
742
+ ## The app around it
743
+
744
+ The store holds the model and supplies the actions, the root's navigation stack reads the router,
745
+ and the root starts the load. These are the app's own code, so state, tasks and
746
+ navigation live here.
747
+
748
+ \`\`\`swift
749
+ import Foundation
750
+ import Observation
751
+ import PolymorphTokens
752
+ import PolymorphUI
753
+ import SwiftUI
754
+
755
+ /// One order as the list shows it. The store formats its words before they reach the view.
756
+ struct Order {
757
+ enum Status: String {
758
+ case open, shipped, cancelled
759
+ }
760
+
761
+ let id: String
762
+ let customer: String
763
+ let status: Status
764
+ /// The total as the person's locale writes it, such as "$1,204.00".
765
+ let total: String
766
+ let placedOn: PMCalendarDate
767
+ }
768
+
769
+ extension OrdersModel {
770
+ /// The columns. A column's \`value\` is its cell's text, and \`cell\` draws a member in its place.
771
+ static var columns: [PMDataTableColumn<Order>] {
772
+ [
773
+ PMDataTableColumn(key: "id", header: "Order", value: { $0.id }),
774
+ PMDataTableColumn(key: "customer", header: "Customer", value: { $0.customer }),
775
+ PMDataTableColumn(
776
+ key: "status", header: "Status", value: { $0.status.rawValue.capitalized },
777
+ cell: { order in
778
+ AnyView(
779
+ PMBadge(
780
+ props: .init(
781
+ children: order.status.rawValue.capitalized,
782
+ tone: order.status == .open ? .accent : .neutral, variant: .soft)))
783
+ }),
784
+ PMDataTableColumn(key: "total", header: "Total", value: { $0.total }, numeric: true),
785
+ ]
786
+ }
787
+ }
788
+
789
+ /// Where the app can go.
790
+ enum Route: Hashable {
791
+ case order(String)
792
+ }
793
+
794
+ /// The app's router: the path its root \`NavigationStack\` reads.
795
+ @MainActor @Observable
796
+ final class Router {
797
+ var path: [Route] = []
798
+ }
799
+
800
+ @MainActor @Observable
801
+ final class OrdersStore {
802
+ private(set) var model = OrdersModel(
803
+ loadStatus: .loading, orders: [], columns: OrdersModel.columns, query: "", placed: nil,
804
+ isFiltered: false)
805
+ private var all: [Order] = []
806
+
807
+ func actions(router: Router) -> OrdersActions {
808
+ OrdersActions(
809
+ getRowId: { $0.id },
810
+ onOpenOrder: { router.path.append(.order($0.id)) },
811
+ onQueryChange: { self.model.query = $0; self.refilter() },
812
+ onPlacedChange: { self.model.placed = $0; self.refilter() },
813
+ onClearFilters: { self.model.query = ""; self.model.placed = nil; self.refilter() },
814
+ onRetry: { Task { await self.load() } }
815
+ )
816
+ }
817
+
818
+ func load() async {
819
+ model.loadStatus = .loading
820
+ do {
821
+ all = try await fetchOrders()
822
+ refilter(settle: true)
823
+ } catch {
824
+ model.loadStatus = .failed(message: error.localizedDescription)
825
+ }
826
+ }
827
+
828
+ /// Keeps the orders the query and the dates allow. Once loaded, the status is \`.empty\` only
829
+ /// while a filter hides every order; with no orders at all it is \`.ready\`, and the table
830
+ /// draws its own empty state.
831
+ private func refilter(settle: Bool = false) {
832
+ let day = { (date: PMCalendarDate) in date.year * 10_000 + date.month * 100 + date.day }
833
+ let query = model.query
834
+ let placed = model.placed
835
+ model.isFiltered = !query.isEmpty || placed != nil
836
+ model.orders = all.filter { order in
837
+ (query.isEmpty || order.customer.localizedCaseInsensitiveContains(query))
838
+ && (placed.map { day($0.start) <= day(order.placedOn) && day(order.placedOn) <= day($0.end) }
839
+ ?? true)
840
+ }
841
+ if settle || model.loadStatus == .ready || model.loadStatus == .empty {
842
+ model.loadStatus = model.orders.isEmpty && model.isFiltered ? .empty : .ready
843
+ }
844
+ }
845
+
846
+ private func fetchOrders() async throws -> [Order] {
847
+ [
848
+ Order(
849
+ id: "1042", customer: "Dana Ruiz", status: .open,
850
+ total: Decimal(1204).formatted(.currency(code: "USD")),
851
+ placedOn: PMCalendarDate(year: 2026, month: 3, day: 18))
852
+ ]
853
+ }
854
+ }
855
+
856
+ struct RootView: View {
857
+ @State private var router = Router()
858
+ @State private var orders = OrdersStore()
859
+ let theme = PMTheme.${pairing}
860
+
861
+ var body: some View {
862
+ NavigationStack(path: $router.path) {
863
+ OrdersView(model: orders.model, actions: orders.actions(router: router))
864
+ .task { await orders.load() }
865
+ .navigationDestination(for: Route.self) { route in
866
+ switch route {
867
+ case .order(let id): Text(id) // the order's own route, whose root is a DetailPage
868
+ }
869
+ }
870
+ }
871
+ .pmTheme(theme)
872
+ .preferredColorScheme(theme.preferredColorScheme)
873
+ }
874
+ }
875
+ \`\`\`
876
+
877
+ An app framed by ${f.m("AppShell")} has no \`NavigationStack(path:) { … }\` of its own: the
878
+ shell draws its content in a navigation stack that takes no path, so the root adds
879
+ \`.navigationDestination(item:)\` to that content, bound to the order the router holds.
880
+
881
+ The store formats money and dates before they reach the model, with Foundation's formatters in the
882
+ person's locale: a column's \`value\`, a ${f.m("Badge")}'s words and a ${f.m("Stat")}'s value are
883
+ text. A column with \`numeric: true\` draws its figures as the system draws numbers, at the side of
884
+ the column it decides. A ${both(f, "PMCalendarDate")} holds Doubles, so the store converts it to
885
+ and from a Foundation date itself. A view under no \`.pmTheme(_:)\` draws under
886
+ \`PMTheme.default\`. The words the members write by default, such as a dialog's "Close" or a
887
+ page's "Try again", are looked up in the app's string catalog, so the app translates them there.
888
+
889
+ A pairing's fonts are drawn when they are installed: the app adds the font files to its target and
890
+ lists each under \`<key>UIAppFonts</key>\` in its Info.plist. The family a file declares must equal
891
+ the pairing's \`theme.fonts.body.family\` (and \`.heading\`, \`.display\`, \`.mono\`). Until then
892
+ each type step uses the system font in its slot's design.
893
+
894
+ ## What no member draws
895
+
896
+ A ${x(f, "PMBespoke", IOS_UI)} zone declares it, with the reason a reviewer reads. Inside, the view
897
+ reads the pairing from the environment and draws with its tokens, and keeps every accessibility
898
+ rule.
899
+
900
+ \`\`\`swift
901
+ import PolymorphUI
902
+ import SwiftUI
903
+
904
+ struct Flagged: View {
905
+ @Environment(\\.pmTheme) private var theme
906
+
907
+ var body: some View {
908
+ PMBespoke(
909
+ props: .init(
910
+ children: AnyView(
911
+ Circle().fill(theme.colors.accentBg.color)
912
+ .frame(width: theme.defaultDensity.space.s6, height: theme.defaultDensity.space.s6)
913
+ .accessibilityHidden(true)
914
+ ),
915
+ reason: "Unread marker: the vocabulary has no dot that is not a Badge."
916
+ )
917
+ )
918
+ }
919
+ }
920
+ \`\`\`
921
+
922
+ ## Check the view
923
+
924
+ Build: \`swift build\` in a Swift package, or
925
+ \`xcodebuild -scheme <App> -destination 'generic/platform=iOS Simulator' build\` in an Xcode
926
+ project. Then search each view's file, and not the store's or the route's, for what a screen may
927
+ not write, and replace each hit as the skill's table says:
928
+
929
+ \`\`\`sh
930
+ grep -nE 'Color[(.]|foregroundStyle|\\.background\\(|\\.font\\(|\\.padding\\(|\\.frame\\(|cornerRadius|withAnimation|\\.animation\\(|systemName|@State|@Environment|\\.task|Task \\{|NavigationLink|NavigationStack|navigationDestination|[HVZ]Stack|Spacer\\(|(^|[^A-Za-z])(Button|Toggle|TextField|Picker)\\(' OrdersView.swift
931
+ \`\`\`
932
+
933
+ \`AnyView(Text("…"))\` is lawful: it is words handed to a member.
934
+
935
+ ## A theme outside the catalogue
936
+
937
+ The device does not run the theme engine. A server admits the system and palette under the same
938
+ laws the catalogue meets, and sends the app a token document for iOS. The server, a Node project,
939
+ installs the engine under the name the code imports:
940
+
941
+ \`\`\`sh
942
+ npm install @polymorph/engine@npm:${engine}@${range}
943
+ \`\`\`
944
+
945
+ \`\`\`ts
946
+ import { admitTheme, emitTokenDocumentJSON } from '@polymorph/engine'
947
+
948
+ const admission = admitTheme({ system, palette })
949
+ if (!admission.lawful) throw new Error(admission.faults.map((fault) => fault.message).join('\\n'))
950
+ const body = emitTokenDocumentJSON(admission.resolved, { platform: 'ios' })
951
+ // admission.fonts lists the families the app bundles
952
+ \`\`\`
953
+
954
+ The app reads it into a pairing, and keeps the default while the document is unavailable:
955
+
956
+ \`\`\`swift
957
+ import Foundation
958
+ import PolymorphTokens
959
+
960
+ func documentTheme(_ data: Data) -> PMTheme {
961
+ do {
962
+ return try PMTheme(tokenDocument: data)
963
+ } catch {
964
+ return .default
965
+ }
966
+ }
967
+ \`\`\`
968
+
969
+ The initialiser throws a ${x(f, "PMTokenDocumentError", IOS_TOKENS)} that names the problem: a
970
+ document of another format or platform, a value missing or of the wrong kind at its path, or a hit
971
+ target under 44 points. ${x(f, "admitTheme", "@polymorph/engine")} and
972
+ ${x(f, "emitTokenDocumentJSON", "@polymorph/engine")} run in Node, on the server, not in the app.
973
+ `;
974
+ }
975
+ /** Compose: how a member is written, two worked screens, the app around them and what it provides. */
976
+ function composeReference(registry) {
977
+ const { f, pairing, tag, renders } = nativeFacts(registry);
978
+ const local = (name) => x(f, name, KOTLIN_UI);
979
+ for (const name of [
980
+ "PMIconRole",
981
+ "PMSpaceStep",
982
+ "PMSortDirection",
983
+ "PMGridColumns"
984
+ ]) f.x(name, KOTLIN_CONTRACTS);
985
+ f.x("PMButtonAppearance", KOTLIN_CONTRACTS);
986
+ f.x("PMSelectOptionEntry", KOTLIN_CONTRACTS);
987
+ return `# Compose: members, two worked screens and the app around them
988
+
989
+ ## Add the modules
990
+
991
+ JitPack builds the two Gradle modules from the release tag: \`tokens\`, plain Kotlin with each
992
+ catalogue pairing as a \`PMTheme\`, and \`ui\`, the members on Compose Multiplatform, published with
993
+ an Android library and a JVM variant:
994
+
995
+ \`\`\`kotlin
996
+ // settings.gradle.kts
997
+ dependencyResolutionManagement {
998
+ repositories {
999
+ google()
1000
+ mavenCentral()
1001
+ maven("https://jitpack.io")
1002
+ }
1003
+ }
1004
+
1005
+ // app/build.gradle.kts
1006
+ dependencies {
1007
+ implementation("com.github.metamorph-labs.polymorph:tokens:${tag}")
1008
+ implementation("com.github.metamorph-labs.polymorph:ui:${tag}")
1009
+ }
1010
+ \`\`\`
1011
+
1012
+ The app module compiles against API 37 (\`compileSdk = 37\`), because the Compose libraries \`ui\`
1013
+ brings require it. JitPack builds a tag the first time an app asks for it, which takes some
1014
+ minutes. A repository that holds a checkout of polymorph at the tag, or a git submodule of it,
1015
+ includes the build instead (the last section).
1016
+
1017
+ ## How a member is written
1018
+
1019
+ A file imports each name from \`dev.polymorph.ui\`, and pairings from \`dev.polymorph.tokens\`. A
1020
+ member is a composable that takes its props as named arguments, in any order. A required argument
1021
+ without a default, such as \`label\` on \`PMButton\`, must be given.
1022
+
1023
+ | On the web | In Compose |
1024
+ | --- | --- |
1025
+ | A member, ${f.m("Button")} | \`PMButton(label = "Save")\`, whose props are ${x(f, "PMButtonProps", KOTLIN_CONTRACTS)} |
1026
+ | A part, ${f.part("SettingsRow", "Group")} | ${x(f, "PMSettingsRowGroup", KOTLIN_MEMBERS)}: the member's name and the part's, joined, as ${x(f, "PMTableRow", KOTLIN_MEMBERS)} |
1027
+ | A string or a boolean | Itself: \`label = "Save"\`, \`disabled = true\` |
1028
+ | A number | A Kotlin Double: \`lines = 2.0\`. A ${both(f, "PMCalendarDate")}'s \`year\`, \`month\` and \`day\` are Doubles too. |
1029
+ | A prop that takes one of a few words | An entry of the enum \`PM<Member><Prop>\`, PascalCased: \`tone = PMBadgeTone.Accent\` |
1030
+ | A size, an icon role, a spacing step, a sort direction | One enum every member shares: \`size = PMControlSize.Sm\`, \`icon = PMIconRole.Add\`, \`gap = PMSpaceStep.S6\`, \`direction = PMSortDirection.Desc\` |
1031
+ | ${f.m("Grid")}'s \`columns={4}\` | \`columns = PMGridColumns.Columns4\` |
1032
+ | ${f.m("Button")}'s ${f.v("Button", "variant", "outline")} with ${f.v("Button", "tone", "danger")} | \`appearance = PMButtonAppearance.OutlineDanger\`, one of the lawful pairs |
1033
+ | A child | The trailing lambda: \`PMCard { … }\` |
1034
+ | A prop that holds an element (\`control\`, \`actions\`, \`search\`) | A \`@Composable\` lambda: \`control = { PMSwitch(…) }\` |
1035
+ | Words where an element goes, as ${f.m("Text")}'s children or a table cell's | Material's \`Text("…")\`, which takes the style the member provides. ${x(f, "PMText", KOTLIN_MEMBERS)} is for words with a size or tone of their own. |
1036
+ | A callback | A function without the DOM event. A required action binds as a reference, \`onClick = actions::onSignOut\`, and an optional one as itself, \`onRetry = actions.onRetry\` |
1037
+ | A value the app controls that may be null, as ${f.m("Select")}'s ${f.p("Select", "value")} | \`value = PMSome(model.frequency)\`: given, \`null\` included. Left out, the member holds the value itself. A value that cannot be null is passed as itself: \`value = model.query\`. |
1038
+ | A data type, such as ${x(f, "SelectOption", "@polymorph/react-ui")} or ${x(f, "DateRange", "@polymorph/react-ui")} | \`PM\` and its name: \`PMSelectOptionEntry.Option(PMSelectOption(value = "now", label = "As they happen"))\`, \`PMDateRange(start, end)\` of two \`PMCalendarDate(year = 2026.0, month = 3.0, day = 18.0)\` |
1039
+ | A member's props passed as a value, as ${f.m("ListPage")}'s ${f.p("ListPage", "emptyState")} | That member's props class: \`PMEmptyStateProps(title = "No orders match")\` |
1040
+
1041
+ ${x(f, "PMSome", KOTLIN_UI)} tells a value that is given as null from a value left out. A prop
1042
+ named \`as\` is written between backticks in Kotlin, because \`as\` is a keyword there.
1043
+
1044
+ ## Where the declarations are
1045
+
1046
+ \`Members.kt\` declares every member's and part's composable with its arguments, and
1047
+ \`Contracts.kt\` every props class, enum and data type, both in
1048
+ \`platforms/android/ui/src/generated/kotlin/dev/polymorph/ui/\`. \`PolymorphUI.kt\` in
1049
+ \`platforms/android/ui/src/main/kotlin/dev/polymorph/ui/\` declares ${local("PMLoadStatus")},
1050
+ ${local("PMSome")}, ${local("PMControlSize")} and ${local("PMContent")}, and the
1051
+ \`PolymorphUI*.kt\` files beside it the composition locals. An app on JitPack has the compiled
1052
+ modules only: an IDE opens a declaration, or the files are in the repository at the release tag,
1053
+ under \`${REPOSITORY}/tree/${tag}/platforms/android/ui/src\`. With a checkout beside the app, print
1054
+ a declaration whole:
1055
+
1056
+ \`\`\`sh
1057
+ K=../polymorph/platforms/android/ui/src/generated/kotlin/dev/polymorph/ui
1058
+ sed -n '/^fun PMListPage(/,/^)/p' "$K/Members.kt"
1059
+ sed -n '/^enum class PMBadgeTone(/,/^}/p' "$K/Contracts.kt"
1060
+ \`\`\`
1061
+
1062
+ ## A worked screen: settings
1063
+
1064
+ This file compiles against the package at the release tag. It is the shape \`emit\` writes from a
1065
+ spec, and the shape a screen written by hand keeps.
1066
+
1067
+ \`\`\`kotlin
1068
+ package com.example.app
1069
+
1070
+ import androidx.compose.runtime.Composable
1071
+ import dev.polymorph.ui.PMButton
1072
+ import dev.polymorph.ui.PMButtonAppearance
1073
+ import dev.polymorph.ui.PMLoadStatus
1074
+ import dev.polymorph.ui.PMSelect
1075
+ import dev.polymorph.ui.PMSelectOptionEntry
1076
+ import dev.polymorph.ui.PMSettingsPage
1077
+ import dev.polymorph.ui.PMSettingsRow
1078
+ import dev.polymorph.ui.PMSettingsRowGroup
1079
+ import dev.polymorph.ui.PMSome
1080
+ import dev.polymorph.ui.PMSwitch
1081
+
1082
+ /** What \`NotificationsScreen\` shows. \`loadStatus\` says which of the four load states it is in. */
1083
+ data class NotificationsModel(
1084
+ val loadStatus: PMLoadStatus,
1085
+ /** Whether the morning digest is on. */
1086
+ val digest: Boolean,
1087
+ val frequency: String?,
1088
+ val frequencyOptions: List<PMSelectOptionEntry>,
1089
+ ) {
1090
+ companion object
1091
+ }
1092
+
1093
+ /** The code the app supplies to \`NotificationsScreen\`, one function per action. */
1094
+ interface NotificationsActions {
1095
+ fun onDigestChange(next: Boolean)
1096
+ fun onFrequencyChange(value: String?)
1097
+ fun onSignOut()
1098
+ }
1099
+
1100
+ /** Which emails the person receives, and a way to sign out. */
1101
+ @Composable
1102
+ fun NotificationsScreen(model: NotificationsModel, actions: NotificationsActions) {
1103
+ PMSettingsPage(loadStatus = model.loadStatus, title = "Notifications") {
1104
+ PMSettingsRowGroup(title = "Email") {
1105
+ PMSettingsRow(
1106
+ control = {
1107
+ PMSwitch(checked = model.digest, onCheckedChange = actions::onDigestChange)
1108
+ },
1109
+ description = "One email with what changed overnight.",
1110
+ label = "Morning digest",
1111
+ )
1112
+ PMSettingsRow(
1113
+ control = {
1114
+ PMSelect(
1115
+ onChange = actions::onFrequencyChange,
1116
+ options = model.frequencyOptions,
1117
+ value = PMSome(model.frequency),
1118
+ )
1119
+ },
1120
+ label = "Alerts",
1121
+ )
1122
+ }
1123
+ PMSettingsRowGroup(title = "Account") {
1124
+ PMSettingsRow(
1125
+ control = {
1126
+ PMButton(
1127
+ label = "Sign out",
1128
+ onClick = actions::onSignOut,
1129
+ appearance = PMButtonAppearance.OutlineDanger,
1130
+ )
1131
+ },
1132
+ label = "This device",
1133
+ )
1134
+ }
1135
+ }
1136
+ }
1137
+
1138
+ /** Every action doing nothing, so the app compiles before it wires its store. */
1139
+ object NotificationsInert : NotificationsActions {
1140
+ override fun onDigestChange(next: Boolean) {}
1141
+ override fun onFrequencyChange(value: String?) {}
1142
+ override fun onSignOut() {}
1143
+ }
1144
+ \`\`\`
1145
+
1146
+ ## A worked screen: a list
1147
+
1148
+ A records screen is a ${f.m("ListPage")}. Its ${f.p("ListPage", "filters")} hold a
1149
+ ${f.m("FilterBar")} with the search field in ${f.p("FilterBar", "search")} and the other filters as
1150
+ its children, and its body is a ${f.m("DataTable")}. On Android ${f.m("DateRangePicker")} is
1151
+ Material's own date range picker. ${f.m("DataTable")} is adapted: ${renders.tableAndroid}, a row's
1152
+ cells stacked in the list. A tap on a row calls ${f.p("DataTable", "onRowClick")} with the row.
1153
+ \`emit\` writes this screen, apart from its comments and its package line, from the spec in the
1154
+ skill's step 6 made Android's, with \`onRetry\` bound as well.
1155
+
1156
+ \`\`\`kotlin
1157
+ package com.example.app
1158
+
1159
+ import androidx.compose.runtime.Composable
1160
+ import dev.polymorph.ui.PMButton
1161
+ import dev.polymorph.ui.PMButtonAppearance
1162
+ import dev.polymorph.ui.PMControlSize
1163
+ import dev.polymorph.ui.PMDataTable
1164
+ import dev.polymorph.ui.PMDataTableColumn
1165
+ import dev.polymorph.ui.PMDateRange
1166
+ import dev.polymorph.ui.PMDateRangePicker
1167
+ import dev.polymorph.ui.PMEmptyStateProps
1168
+ import dev.polymorph.ui.PMFilterBar
1169
+ import dev.polymorph.ui.PMIconRole
1170
+ import dev.polymorph.ui.PMListPage
1171
+ import dev.polymorph.ui.PMLoadStatus
1172
+ import dev.polymorph.ui.PMSearchInput
1173
+ import dev.polymorph.ui.PMSome
1174
+
1175
+ /** What \`OrdersScreen\` shows. \`loadStatus\` says which of the four load states it is in. */
1176
+ data class OrdersModel(
1177
+ val loadStatus: PMLoadStatus,
1178
+ /** Already searched and filtered. */
1179
+ val orders: List<Order>,
1180
+ val columns: List<PMDataTableColumn<Order>>,
1181
+ val query: String,
1182
+ val placed: PMDateRange?,
1183
+ val isFiltered: Boolean,
1184
+ ) {
1185
+ companion object
1186
+ }
1187
+
1188
+ /** The code the app supplies to \`OrdersScreen\`, one function per action. */
1189
+ interface OrdersActions {
1190
+ fun getRowId(order: Order): String
1191
+ fun onOpenOrder(order: Order)
1192
+ fun onQueryChange(query: String)
1193
+ fun onPlacedChange(placed: PMDateRange?)
1194
+ fun onClearFilters()
1195
+ fun onRetry()
1196
+ }
1197
+
1198
+ /** Every order, searchable and filtered by the day it was placed; a tap opens one. */
1199
+ @Composable
1200
+ fun OrdersScreen(model: OrdersModel, actions: OrdersActions) {
1201
+ PMListPage(
1202
+ loadStatus = model.loadStatus,
1203
+ onRetry = actions::onRetry,
1204
+ emptyState = PMEmptyStateProps(
1205
+ icon = PMIconRole.Search,
1206
+ secondaryAction = {
1207
+ PMButton(
1208
+ label = "Clear filters",
1209
+ onClick = actions::onClearFilters,
1210
+ appearance = PMButtonAppearance.GhostNeutral,
1211
+ )
1212
+ },
1213
+ title = "No orders match these filters",
1214
+ ),
1215
+ filters = {
1216
+ PMFilterBar(
1217
+ isFiltered = model.isFiltered,
1218
+ onClear = actions::onClearFilters,
1219
+ search = {
1220
+ PMSearchInput(
1221
+ ariaLabel = "Search orders",
1222
+ onChange = actions::onQueryChange,
1223
+ size = PMControlSize.Sm,
1224
+ value = model.query,
1225
+ )
1226
+ },
1227
+ ) {
1228
+ PMDateRangePicker(
1229
+ ariaLabel = "Placed between",
1230
+ onChange = actions::onPlacedChange,
1231
+ size = PMControlSize.Sm,
1232
+ value = PMSome(model.placed),
1233
+ )
1234
+ }
1235
+ },
1236
+ title = "Orders",
1237
+ ) {
1238
+ PMDataTable(
1239
+ columns = model.columns,
1240
+ data = model.orders,
1241
+ emptyState = PMEmptyStateProps(icon = PMIconRole.Inbox, title = "No orders yet"),
1242
+ getRowId = actions::getRowId,
1243
+ label = "Orders",
1244
+ onRowClick = actions::onOpenOrder,
1245
+ )
1246
+ }
1247
+ }
1248
+
1249
+ /** Every action doing nothing, so the app compiles before it wires its store. */
1250
+ object OrdersInert : OrdersActions {
1251
+ override fun getRowId(order: Order): String = ""
1252
+ override fun onOpenOrder(order: Order) {}
1253
+ override fun onQueryChange(query: String) {}
1254
+ override fun onPlacedChange(placed: PMDateRange?) {}
1255
+ override fun onClearFilters() {}
1256
+ override fun onRetry() {}
1257
+ }
1258
+ \`\`\`
1259
+
1260
+ ## The app around it
1261
+
1262
+ The store is an AndroidX ViewModel that holds the model, implements the actions and opens screens
1263
+ through the app's router. The route collects the model and starts the load, and the root provides
1264
+ the pairing. These are the app's own code, so coroutines, state and navigation live here.
1265
+
1266
+ \`\`\`kotlin
1267
+ package com.example.app
1268
+
1269
+ import androidx.compose.runtime.Composable
1270
+ import androidx.compose.runtime.LaunchedEffect
1271
+ import androidx.compose.runtime.collectAsState
1272
+ import androidx.compose.runtime.getValue
1273
+ import androidx.lifecycle.ViewModel
1274
+ import androidx.lifecycle.viewModelScope
1275
+ import dev.polymorph.tokens.PMThemes
1276
+ import dev.polymorph.ui.PMBadge
1277
+ import dev.polymorph.ui.PMBadgeTone
1278
+ import dev.polymorph.ui.PMBadgeVariant
1279
+ import dev.polymorph.ui.PMCalendarDate
1280
+ import dev.polymorph.ui.PMDataTableColumn
1281
+ import dev.polymorph.ui.PMDateRange
1282
+ import dev.polymorph.ui.PMLoadStatus
1283
+ import dev.polymorph.ui.ProvidePMTheme
1284
+ import java.text.NumberFormat
1285
+ import java.util.Currency
1286
+ import kotlinx.coroutines.CancellationException
1287
+ import kotlinx.coroutines.flow.MutableStateFlow
1288
+ import kotlinx.coroutines.flow.StateFlow
1289
+ import kotlinx.coroutines.flow.asStateFlow
1290
+ import kotlinx.coroutines.flow.update
1291
+ import kotlinx.coroutines.launch
1292
+
1293
+ /** One order as the list shows it. The store formats its words before they reach the screen. */
1294
+ data class Order(
1295
+ val id: String,
1296
+ val customer: String,
1297
+ val status: Status,
1298
+ /** The total as the person's locale writes it, such as "$1,204.00". */
1299
+ val total: String,
1300
+ val placedOn: PMCalendarDate,
1301
+ ) {
1302
+ enum class Status(val label: String) { Open("Open"), Shipped("Shipped"), Cancelled("Cancelled") }
1303
+ }
1304
+
1305
+ /** The columns. A column's \`value\` is its cell's text, and \`cell\` draws a member in its place. */
1306
+ val orderColumns: List<PMDataTableColumn<Order>> = listOf(
1307
+ PMDataTableColumn(key = "id", header = "Order", value = { it.id }),
1308
+ PMDataTableColumn(key = "customer", header = "Customer", value = { it.customer }),
1309
+ PMDataTableColumn(
1310
+ key = "status",
1311
+ header = "Status",
1312
+ value = { it.status.label },
1313
+ cell = { order ->
1314
+ PMBadge(
1315
+ children = order.status.label,
1316
+ tone = if (order.status == Order.Status.Open) PMBadgeTone.Accent else PMBadgeTone.Neutral,
1317
+ variant = PMBadgeVariant.Soft,
1318
+ )
1319
+ },
1320
+ ),
1321
+ PMDataTableColumn(key = "total", header = "Total", value = { it.total }, numeric = true),
1322
+ )
1323
+
1324
+ /** Where the app can go. */
1325
+ sealed interface Route {
1326
+ data class OrderDetail(val id: String) : Route
1327
+ }
1328
+
1329
+ /** The app's router: the back stack its root navigation reads. */
1330
+ class Router {
1331
+ private val stack = MutableStateFlow<List<Route>>(emptyList())
1332
+ val path: StateFlow<List<Route>> = stack.asStateFlow()
1333
+
1334
+ fun open(route: Route) = stack.update { it + route }
1335
+ }
1336
+
1337
+ class OrdersStore(private val router: Router) : ViewModel(), OrdersActions {
1338
+ private val state = MutableStateFlow(
1339
+ OrdersModel(PMLoadStatus.Loading, emptyList(), orderColumns, query = "", placed = null, isFiltered = false),
1340
+ )
1341
+ val model: StateFlow<OrdersModel> = state.asStateFlow()
1342
+ private var all: List<Order> = emptyList()
1343
+
1344
+ override fun getRowId(order: Order): String = order.id
1345
+ override fun onOpenOrder(order: Order) = router.open(Route.OrderDetail(order.id))
1346
+ override fun onQueryChange(query: String) = refilter { copy(query = query) }
1347
+ override fun onPlacedChange(placed: PMDateRange?) = refilter { copy(placed = placed) }
1348
+ override fun onClearFilters() = refilter { copy(query = "", placed = null) }
1349
+ override fun onRetry() {
1350
+ viewModelScope.launch { load() }
1351
+ }
1352
+
1353
+ suspend fun load() {
1354
+ state.update { it.copy(loadStatus = PMLoadStatus.Loading) }
1355
+ try {
1356
+ all = fetchOrders()
1357
+ refilter(settle = true)
1358
+ } catch (error: CancellationException) {
1359
+ throw error
1360
+ } catch (error: Exception) {
1361
+ state.update { it.copy(loadStatus = PMLoadStatus.Failed(error.message.orEmpty())) }
1362
+ }
1363
+ }
1364
+
1365
+ /**
1366
+ * Changes the model, then keeps the orders the query and the dates allow. Once loaded, the
1367
+ * status is \`Empty\` only while a filter hides every order; with no orders at all it is
1368
+ * \`Ready\`, and the table draws its own empty state.
1369
+ */
1370
+ private fun refilter(settle: Boolean = false, change: OrdersModel.() -> OrdersModel = { this }) =
1371
+ state.update { current ->
1372
+ val next = current.change()
1373
+ val day = { date: PMCalendarDate -> date.year * 10_000 + date.month * 100 + date.day }
1374
+ val orders = all.filter { order ->
1375
+ (next.query.isEmpty() || order.customer.contains(next.query, ignoreCase = true)) &&
1376
+ (next.placed?.let { day(order.placedOn) in day(it.start)..day(it.end) } ?: true)
1377
+ }
1378
+ val filtered = next.query.isNotEmpty() || next.placed != null
1379
+ val loaded = settle || next.loadStatus == PMLoadStatus.Ready || next.loadStatus == PMLoadStatus.Empty
1380
+ next.copy(
1381
+ orders = orders,
1382
+ isFiltered = filtered,
1383
+ loadStatus = when {
1384
+ !loaded -> next.loadStatus
1385
+ orders.isEmpty() && filtered -> PMLoadStatus.Empty
1386
+ else -> PMLoadStatus.Ready
1387
+ },
1388
+ )
1389
+ }
1390
+
1391
+ private suspend fun fetchOrders(): List<Order> = listOf(
1392
+ Order(
1393
+ id = "1042",
1394
+ customer = "Dana Ruiz",
1395
+ status = Order.Status.Open,
1396
+ total = NumberFormat.getCurrencyInstance().apply { currency = Currency.getInstance("USD") }.format(1204),
1397
+ placedOn = PMCalendarDate(year = 2026.0, month = 3.0, day = 18.0),
1398
+ ),
1399
+ )
1400
+ }
1401
+
1402
+ @Composable
1403
+ fun OrdersRoute(store: OrdersStore) {
1404
+ val model by store.model.collectAsState()
1405
+ LaunchedEffect(store) { store.load() }
1406
+ OrdersScreen(model = model, actions = store)
1407
+ }
1408
+
1409
+ @Composable
1410
+ fun App(store: OrdersStore) {
1411
+ val theme = PMThemes.${pairing}
1412
+ ProvidePMTheme(theme, dark = theme.preferredDark) {
1413
+ OrdersRoute(store)
1414
+ }
1415
+ }
1416
+ \`\`\`
1417
+
1418
+ The store needs \`androidx.lifecycle\` and \`kotlinx.coroutines\`. The router here is a back stack
1419
+ the root reads. An app on Navigation Compose keeps its navigation controller in the router instead:
1420
+ \`open\` calls \`navController.navigate(…)\`, and the root's \`NavHost(…) { … }\` draws each route inside
1421
+ ${local("ProvidePMTheme")}, where the system's back gesture pops it. The store formats money and
1422
+ dates before they reach the model, in the person's locale: a column's \`value\`, a
1423
+ ${f.m("Badge")}'s words and a ${f.m("Stat")}'s value are text. A column with \`numeric = true\` draws its figures as the system draws numbers, at the side of
1424
+ the column it decides. A ${both(f, "PMCalendarDate")} holds Doubles, so the store converts it to and from
1425
+ its own date type. ${local("ProvidePMTheme")} also gives Material 3 the pairing, so the app's own
1426
+ Material components match the members. A composable under none draws under
1427
+ ${x(f, "PMThemes", KOTLIN_CATALOGUE, "", ".default")} in the system's mode.
1428
+
1429
+ ## What the app provides
1430
+
1431
+ The members read these from the composition. Provide each that the screen's members need, at the
1432
+ root, with \`CompositionLocalProvider(…)\`:
1433
+
1434
+ | Composition local | What it is | Without it |
1435
+ | --- | --- | --- |
1436
+ | ${local("LocalPMStrings")} | The app's translations of the words the members write by default | English |
1437
+ | ${local("LocalPMFontFamilies")} | A function from each of the pairing's fonts, a ${x(f, "PMFont", KOTLIN_TOKENS)}, to a Compose font family built from the files the app bundles for its \`family\`, or null | The system font in the slot's design |
1438
+ | ${local("LocalPMImageLoader")} | A painter for a picture's URL, from the app's image loader | Each member draws its fallback |
1439
+ | ${local("LocalPMFilePicker")} | The platform's document picker, for file upload and attaching | A dropzone opens nothing, and a prompt has no attach button |
1440
+ | ${local("LocalPMImageEncoder")} | Writes an edited image as a file | The image editor's confirm hands nothing over |
1441
+ | ${local("LocalPMToday")} | The person's date, for calendars and relative times | The date in UTC |
1442
+
1443
+ A link opens through Compose's \`LocalUriHandler.current\`, or through a member's \`onNavigate\` when the
1444
+ app routes its own paths.
1445
+
1446
+ ## What no member draws
1447
+
1448
+ A ${x(f, "PMBespoke", IOS_UI)} zone declares it, with the reason a reviewer reads. Inside, the
1449
+ composable reads the pairing through \`PM.theme\` and draws with its tokens, and keeps every
1450
+ accessibility rule.
1451
+
1452
+ \`\`\`kotlin
1453
+ import androidx.compose.foundation.background
1454
+ import androidx.compose.foundation.layout.Box
1455
+ import androidx.compose.foundation.layout.size
1456
+ import androidx.compose.foundation.shape.CircleShape
1457
+ import androidx.compose.runtime.Composable
1458
+ import androidx.compose.ui.Modifier
1459
+ import androidx.compose.ui.semantics.clearAndSetSemantics
1460
+ import androidx.compose.ui.unit.dp
1461
+ import dev.polymorph.ui.PM
1462
+ import dev.polymorph.ui.PMBespoke
1463
+ import dev.polymorph.ui.color
1464
+
1465
+ @Composable
1466
+ fun Flagged() {
1467
+ val theme = PM.theme
1468
+ PMBespoke(reason = "Unread marker: the vocabulary has no dot that is not a Badge.") {
1469
+ Box(
1470
+ Modifier
1471
+ .size(theme.defaultDensity.space[6].dp)
1472
+ .background(theme.colors.accentBg.color, CircleShape)
1473
+ .clearAndSetSemantics {},
1474
+ )
1475
+ }
1476
+ }
1477
+ \`\`\`
1478
+
1479
+ \`.color\` resolves a colour role in the mode the members draw in. ${x(f, "PM", KOTLIN_UI, "", ".theme")}
1480
+ is the pairing the root provided.
1481
+
1482
+ ## Check the screen
1483
+
1484
+ Build: \`./gradlew :app:compileDebugKotlin\`. Then search each screen's file, and not the store's
1485
+ or the route's, for what a screen may not write, and replace each hit as the skill's table says:
1486
+
1487
+ \`\`\`sh
1488
+ grep -nE 'Color\\(|\\.dp([^A-Za-z]|$)|\\.sp([^A-Za-z]|$)|MaterialTheme|Modifier\\.|animate[A-Z]|remember|mutableStateOf|LaunchedEffect|navigate\\(|NavHost|Icons\\.|(^|[^A-Za-z])(Column|Row|Box|Spacer|Button|Switch|TextField|Icon)\\(' OrdersScreen.kt
1489
+ \`\`\`
1490
+
1491
+ Material's \`Text("…")\` inside a member is lawful: it is words handed to the member.
1492
+
1493
+ ## A checkout instead of JitPack
1494
+
1495
+ A repository that holds a checkout of polymorph at the release tag, or a git submodule of it,
1496
+ includes the Gradle build and depends on the modules by their own names:
1497
+
1498
+ \`\`\`kotlin
1499
+ // settings.gradle.kts
1500
+ includeBuild("../polymorph/platforms/android")
1501
+
1502
+ // app/build.gradle.kts
1503
+ dependencies {
1504
+ implementation("dev.polymorph:tokens")
1505
+ implementation("dev.polymorph:ui")
1506
+ }
1507
+ \`\`\`
1508
+
1509
+ The included build runs on the app's Gradle, which is 9.5 or a later 9.x release, and compiles the
1510
+ members. That compile runs out of memory at Gradle's default heap, so the app's
1511
+ \`gradle.properties\` sets \`org.gradle.jvmargs=-Xmx4g\` and \`kotlin.daemon.jvmargs=-Xmx4g\`.
1512
+ `;
1513
+ }
1514
+ /** Flutter and Dart: the token package, and how its values map to Flutter's types. */
1515
+ function flutterReference(registry) {
1516
+ const { f, pairing, tag } = nativeFacts(registry);
1517
+ const dart = (name) => x(f, name, DART);
1518
+ return `# Flutter and Dart: the tokens only
1519
+
1520
+ Polymorph has no Flutter members. The Dart package polymorph_tokens holds each catalogue pairing
1521
+ as a \`const PMTheme\` of plain Dart values, with no dependencies, Flutter included. A Flutter app
1522
+ reads the same decisions the native members read, and builds its own widgets from them: the
1523
+ colours in light and dark, the type steps, spacing, radii, shadows and motion. Nothing in polymorph
1524
+ checks those widgets. The members, the screen contract and the red rules do not reach Flutter, so
1525
+ the widgets keep the rule by hand: every colour, length, font and duration comes from the pairing.
1526
+
1527
+ ## Add the package
1528
+
1529
+ The package lives in a directory of the repository, so a Flutter app depends on it by git at the
1530
+ release tag:
1531
+
1532
+ \`\`\`yaml
1533
+ dependencies:
1534
+ polymorph_tokens:
1535
+ git:
1536
+ url: ${REPOSITORY}.git
1537
+ path: platforms/dart
1538
+ ref: ${tag}
1539
+ \`\`\`
1540
+
1541
+ An app that holds a checkout of polymorph, or a git submodule of it, depends on it by path
1542
+ instead: \`path: ../polymorph/platforms/dart\`.
1543
+
1544
+ ## Read a pairing
1545
+
1546
+ \`\`\`dart
1547
+ import 'package:polymorph_tokens/polymorph_tokens.dart';
1548
+
1549
+ const theme = PMThemes.${pairing};
1550
+ final density = theme.defaultDensity; // the density the system's axes select
1551
+ final accent = theme.colors.accentBg.resolve(isDark: false); // a PMRgba
1552
+ final gutter = density.space[4];
1553
+ final body = theme.text.md; // size, lineHeight, tracking, weight
1554
+ final duration = theme.defaultMotion.duration.control; // milliseconds
1555
+ \`\`\`
1556
+
1557
+ \`PMThemes.named(system, palette)\` finds a pairing by name, and \`PMThemes.catalogue\` lists them.
1558
+ A colour role resolves for a mode with \`resolve(isDark:)\`, so the app passes the platform's
1559
+ brightness.
1560
+
1561
+ ## Map a value to Flutter
1562
+
1563
+ | Value | In Flutter |
1564
+ | --- | --- |
1565
+ | A colour, ${dart("PMRgba")} | \`Color(rgba.argb)\` |
1566
+ | A length: \`space[4]\`, \`radius.control\`, \`controlHeight.md\` | The \`double\` itself, in logical pixels |
1567
+ | A type step's \`lineHeight\` | \`TextStyle.height\` |
1568
+ | A type step's \`tracking\`, in em | \`letterSpacing: tracking * size\` |
1569
+ | A duration, in milliseconds | \`Duration(milliseconds: …)\` |
1570
+ | ${dart("PMEasing")} | \`Cubic(x1, y1, x2, y2)\` |
1571
+ | ${dart("PMSpring")} | \`SpringDescription(mass: s.mass, stiffness: s.stiffness, damping: s.damping)\` |
1572
+
1573
+ The hit target, \`density.hitTarget\`, is 48 at every density, Flutter's minimum interactive size. A
1574
+ widget shorter than it keeps its drawn height and extends its tap area to it, as Material's
1575
+ \`MaterialTapTargetSize.padded\` does. The pairing names its font families and does not carry the
1576
+ files, so the app bundles the fonts it uses.
1577
+ `;
1578
+ }
1579
+ //#endregion
1580
+ export { nativeSkill };