@frontmcp/ui 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (393) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +438 -0
  3. package/package.json +147 -0
  4. package/src/adapters/index.d.ts +10 -0
  5. package/src/adapters/index.js +18 -0
  6. package/src/adapters/index.js.map +1 -0
  7. package/src/adapters/platform-meta.d.ts +165 -0
  8. package/src/adapters/platform-meta.js +310 -0
  9. package/src/adapters/platform-meta.js.map +1 -0
  10. package/src/base-template/bridge.d.ts +89 -0
  11. package/src/base-template/bridge.js +452 -0
  12. package/src/base-template/bridge.js.map +1 -0
  13. package/src/base-template/default-base-template.d.ts +91 -0
  14. package/src/base-template/default-base-template.js +435 -0
  15. package/src/base-template/default-base-template.js.map +1 -0
  16. package/src/base-template/index.d.ts +14 -0
  17. package/src/base-template/index.js +30 -0
  18. package/src/base-template/index.js.map +1 -0
  19. package/src/base-template/polyfills.d.ts +30 -0
  20. package/src/base-template/polyfills.js +190 -0
  21. package/src/base-template/polyfills.js.map +1 -0
  22. package/src/base-template/theme-styles.d.ts +73 -0
  23. package/src/base-template/theme-styles.js +95 -0
  24. package/src/base-template/theme-styles.js.map +1 -0
  25. package/src/bridge/adapters/base-adapter.d.ts +103 -0
  26. package/src/bridge/adapters/base-adapter.js +314 -0
  27. package/src/bridge/adapters/base-adapter.js.map +1 -0
  28. package/src/bridge/adapters/claude.adapter.d.ts +66 -0
  29. package/src/bridge/adapters/claude.adapter.js +145 -0
  30. package/src/bridge/adapters/claude.adapter.js.map +1 -0
  31. package/src/bridge/adapters/ext-apps.adapter.d.ts +142 -0
  32. package/src/bridge/adapters/ext-apps.adapter.js +416 -0
  33. package/src/bridge/adapters/ext-apps.adapter.js.map +1 -0
  34. package/src/bridge/adapters/gemini.adapter.d.ts +63 -0
  35. package/src/bridge/adapters/gemini.adapter.js +160 -0
  36. package/src/bridge/adapters/gemini.adapter.js.map +1 -0
  37. package/src/bridge/adapters/generic.adapter.d.ts +55 -0
  38. package/src/bridge/adapters/generic.adapter.js +108 -0
  39. package/src/bridge/adapters/generic.adapter.js.map +1 -0
  40. package/src/bridge/adapters/index.d.ts +25 -0
  41. package/src/bridge/adapters/index.js +65 -0
  42. package/src/bridge/adapters/index.js.map +1 -0
  43. package/src/bridge/adapters/openai.adapter.d.ts +64 -0
  44. package/src/bridge/adapters/openai.adapter.js +194 -0
  45. package/src/bridge/adapters/openai.adapter.js.map +1 -0
  46. package/src/bridge/core/adapter-registry.d.ts +121 -0
  47. package/src/bridge/core/adapter-registry.js +271 -0
  48. package/src/bridge/core/adapter-registry.js.map +1 -0
  49. package/src/bridge/core/bridge-factory.d.ts +198 -0
  50. package/src/bridge/core/bridge-factory.js +428 -0
  51. package/src/bridge/core/bridge-factory.js.map +1 -0
  52. package/src/bridge/core/index.d.ts +9 -0
  53. package/src/bridge/core/index.js +22 -0
  54. package/src/bridge/core/index.js.map +1 -0
  55. package/src/bridge/index.d.ts +61 -0
  56. package/src/bridge/index.js +94 -0
  57. package/src/bridge/index.js.map +1 -0
  58. package/src/bridge/runtime/iife-generator.d.ts +61 -0
  59. package/src/bridge/runtime/iife-generator.js +940 -0
  60. package/src/bridge/runtime/iife-generator.js.map +1 -0
  61. package/src/bridge/runtime/index.d.ts +8 -0
  62. package/src/bridge/runtime/index.js +16 -0
  63. package/src/bridge/runtime/index.js.map +1 -0
  64. package/src/bridge/types.d.ts +385 -0
  65. package/src/bridge/types.js +11 -0
  66. package/src/bridge/types.js.map +1 -0
  67. package/src/build/cdn-resources.d.ts +140 -0
  68. package/src/build/cdn-resources.js +314 -0
  69. package/src/build/cdn-resources.js.map +1 -0
  70. package/src/build/index.d.ts +294 -0
  71. package/src/build/index.js +325 -0
  72. package/src/build/index.js.map +1 -0
  73. package/src/build/widget-manifest.d.ts +212 -0
  74. package/src/build/widget-manifest.js +652 -0
  75. package/src/build/widget-manifest.js.map +1 -0
  76. package/src/bundler/bundler.d.ts +110 -0
  77. package/src/bundler/bundler.js +432 -0
  78. package/src/bundler/bundler.js.map +1 -0
  79. package/src/bundler/cache.d.ts +172 -0
  80. package/src/bundler/cache.js +250 -0
  81. package/src/bundler/cache.js.map +1 -0
  82. package/src/bundler/index.d.ts +41 -0
  83. package/src/bundler/index.js +73 -0
  84. package/src/bundler/index.js.map +1 -0
  85. package/src/bundler/sandbox/enclave-adapter.d.ts +120 -0
  86. package/src/bundler/sandbox/enclave-adapter.js +339 -0
  87. package/src/bundler/sandbox/enclave-adapter.js.map +1 -0
  88. package/src/bundler/sandbox/executor.d.ts +13 -0
  89. package/src/bundler/sandbox/executor.js +22 -0
  90. package/src/bundler/sandbox/executor.js.map +1 -0
  91. package/src/bundler/sandbox/policy.d.ts +61 -0
  92. package/src/bundler/sandbox/policy.js +238 -0
  93. package/src/bundler/sandbox/policy.js.map +1 -0
  94. package/src/bundler/types.d.ts +347 -0
  95. package/src/bundler/types.js +132 -0
  96. package/src/bundler/types.js.map +1 -0
  97. package/src/components/alert.d.ts +71 -0
  98. package/src/components/alert.js +189 -0
  99. package/src/components/alert.js.map +1 -0
  100. package/src/components/alert.schema.d.ts +114 -0
  101. package/src/components/alert.schema.js +105 -0
  102. package/src/components/alert.schema.js.map +1 -0
  103. package/src/components/avatar.d.ts +76 -0
  104. package/src/components/avatar.js +176 -0
  105. package/src/components/avatar.js.map +1 -0
  106. package/src/components/avatar.schema.d.ts +169 -0
  107. package/src/components/avatar.schema.js +103 -0
  108. package/src/components/avatar.schema.js.map +1 -0
  109. package/src/components/badge.d.ts +70 -0
  110. package/src/components/badge.js +149 -0
  111. package/src/components/badge.js.map +1 -0
  112. package/src/components/badge.schema.d.ts +109 -0
  113. package/src/components/badge.schema.js +96 -0
  114. package/src/components/badge.schema.js.map +1 -0
  115. package/src/components/button.d.ts +111 -0
  116. package/src/components/button.js +336 -0
  117. package/src/components/button.js.map +1 -0
  118. package/src/components/button.schema.d.ts +148 -0
  119. package/src/components/button.schema.js +121 -0
  120. package/src/components/button.schema.js.map +1 -0
  121. package/src/components/card.d.ts +60 -0
  122. package/src/components/card.js +117 -0
  123. package/src/components/card.js.map +1 -0
  124. package/src/components/card.schema.d.ts +113 -0
  125. package/src/components/card.schema.js +98 -0
  126. package/src/components/card.schema.js.map +1 -0
  127. package/src/components/form.d.ts +239 -0
  128. package/src/components/form.js +420 -0
  129. package/src/components/form.js.map +1 -0
  130. package/src/components/form.schema.d.ts +441 -0
  131. package/src/components/form.schema.js +406 -0
  132. package/src/components/form.schema.js.map +1 -0
  133. package/src/components/index.d.ts +29 -0
  134. package/src/components/index.js +98 -0
  135. package/src/components/index.js.map +1 -0
  136. package/src/components/list.d.ts +127 -0
  137. package/src/components/list.js +279 -0
  138. package/src/components/list.js.map +1 -0
  139. package/src/components/list.schema.d.ts +134 -0
  140. package/src/components/list.schema.js +168 -0
  141. package/src/components/list.schema.js.map +1 -0
  142. package/src/components/modal.d.ts +111 -0
  143. package/src/components/modal.js +260 -0
  144. package/src/components/modal.js.map +1 -0
  145. package/src/components/modal.schema.d.ts +186 -0
  146. package/src/components/modal.schema.js +167 -0
  147. package/src/components/modal.schema.js.map +1 -0
  148. package/src/components/table.d.ts +105 -0
  149. package/src/components/table.js +283 -0
  150. package/src/components/table.js.map +1 -0
  151. package/src/components/table.schema.d.ts +159 -0
  152. package/src/components/table.schema.js +173 -0
  153. package/src/components/table.schema.js.map +1 -0
  154. package/src/handlebars/helpers.d.ts +348 -0
  155. package/src/handlebars/helpers.js +605 -0
  156. package/src/handlebars/helpers.js.map +1 -0
  157. package/src/handlebars/index.d.ts +193 -0
  158. package/src/handlebars/index.js +350 -0
  159. package/src/handlebars/index.js.map +1 -0
  160. package/src/index.d.ts +50 -0
  161. package/src/index.js +192 -0
  162. package/src/index.js.map +1 -0
  163. package/src/layouts/base.d.ts +88 -0
  164. package/src/layouts/base.js +227 -0
  165. package/src/layouts/base.js.map +1 -0
  166. package/src/layouts/index.d.ts +7 -0
  167. package/src/layouts/index.js +25 -0
  168. package/src/layouts/index.js.map +1 -0
  169. package/src/layouts/presets.d.ts +133 -0
  170. package/src/layouts/presets.js +277 -0
  171. package/src/layouts/presets.js.map +1 -0
  172. package/src/pages/consent.d.ts +116 -0
  173. package/src/pages/consent.js +218 -0
  174. package/src/pages/consent.js.map +1 -0
  175. package/src/pages/error.d.ts +100 -0
  176. package/src/pages/error.js +263 -0
  177. package/src/pages/error.js.map +1 -0
  178. package/src/pages/index.d.ts +8 -0
  179. package/src/pages/index.js +27 -0
  180. package/src/pages/index.js.map +1 -0
  181. package/src/react/Alert.d.ts +101 -0
  182. package/src/react/Alert.js +51 -0
  183. package/src/react/Alert.js.map +1 -0
  184. package/src/react/Badge.d.ts +100 -0
  185. package/src/react/Badge.js +55 -0
  186. package/src/react/Badge.js.map +1 -0
  187. package/src/react/Button.d.ts +108 -0
  188. package/src/react/Button.js +52 -0
  189. package/src/react/Button.js.map +1 -0
  190. package/src/react/Card.d.ts +103 -0
  191. package/src/react/Card.js +55 -0
  192. package/src/react/Card.js.map +1 -0
  193. package/src/react/hooks/context.d.ts +178 -0
  194. package/src/react/hooks/context.js +287 -0
  195. package/src/react/hooks/context.js.map +1 -0
  196. package/src/react/hooks/index.d.ts +41 -0
  197. package/src/react/hooks/index.js +61 -0
  198. package/src/react/hooks/index.js.map +1 -0
  199. package/src/react/hooks/tools.d.ts +283 -0
  200. package/src/react/hooks/tools.js +465 -0
  201. package/src/react/hooks/tools.js.map +1 -0
  202. package/src/react/index.d.ts +80 -0
  203. package/src/react/index.js +113 -0
  204. package/src/react/index.js.map +1 -0
  205. package/src/react/types.d.ts +105 -0
  206. package/src/react/types.js +12 -0
  207. package/src/react/types.js.map +1 -0
  208. package/src/react/utils.d.ts +42 -0
  209. package/src/react/utils.js +99 -0
  210. package/src/react/utils.js.map +1 -0
  211. package/src/registry/index.d.ts +45 -0
  212. package/src/registry/index.js +67 -0
  213. package/src/registry/index.js.map +1 -0
  214. package/src/registry/render-template.d.ts +86 -0
  215. package/src/registry/render-template.js +239 -0
  216. package/src/registry/render-template.js.map +1 -0
  217. package/src/registry/tool-ui.registry.d.ts +260 -0
  218. package/src/registry/tool-ui.registry.js +438 -0
  219. package/src/registry/tool-ui.registry.js.map +1 -0
  220. package/src/registry/uri-utils.d.ts +55 -0
  221. package/src/registry/uri-utils.js +97 -0
  222. package/src/registry/uri-utils.js.map +1 -0
  223. package/src/render/index.d.ts +7 -0
  224. package/src/render/index.js +14 -0
  225. package/src/render/index.js.map +1 -0
  226. package/src/render/prerender.d.ts +56 -0
  227. package/src/render/prerender.js +98 -0
  228. package/src/render/prerender.js.map +1 -0
  229. package/src/renderers/cache.d.ts +144 -0
  230. package/src/renderers/cache.js +240 -0
  231. package/src/renderers/cache.js.map +1 -0
  232. package/src/renderers/html.renderer.d.ts +122 -0
  233. package/src/renderers/html.renderer.js +204 -0
  234. package/src/renderers/html.renderer.js.map +1 -0
  235. package/src/renderers/index.d.ts +35 -0
  236. package/src/renderers/index.js +70 -0
  237. package/src/renderers/index.js.map +1 -0
  238. package/src/renderers/mdx.renderer.d.ts +119 -0
  239. package/src/renderers/mdx.renderer.js +305 -0
  240. package/src/renderers/mdx.renderer.js.map +1 -0
  241. package/src/renderers/react.renderer.d.ts +95 -0
  242. package/src/renderers/react.renderer.js +260 -0
  243. package/src/renderers/react.renderer.js.map +1 -0
  244. package/src/renderers/registry.d.ts +133 -0
  245. package/src/renderers/registry.js +232 -0
  246. package/src/renderers/registry.js.map +1 -0
  247. package/src/renderers/types.d.ts +341 -0
  248. package/src/renderers/types.js +9 -0
  249. package/src/renderers/types.js.map +1 -0
  250. package/src/renderers/utils/detect.d.ts +106 -0
  251. package/src/renderers/utils/detect.js +267 -0
  252. package/src/renderers/utils/detect.js.map +1 -0
  253. package/src/renderers/utils/hash.d.ts +39 -0
  254. package/src/renderers/utils/hash.js +75 -0
  255. package/src/renderers/utils/hash.js.map +1 -0
  256. package/src/renderers/utils/index.d.ts +8 -0
  257. package/src/renderers/utils/index.js +28 -0
  258. package/src/renderers/utils/index.js.map +1 -0
  259. package/src/renderers/utils/transpiler.d.ts +88 -0
  260. package/src/renderers/utils/transpiler.js +215 -0
  261. package/src/renderers/utils/transpiler.js.map +1 -0
  262. package/src/runtime/adapters/html.adapter.d.ts +58 -0
  263. package/src/runtime/adapters/html.adapter.js +131 -0
  264. package/src/runtime/adapters/html.adapter.js.map +1 -0
  265. package/src/runtime/adapters/index.d.ts +25 -0
  266. package/src/runtime/adapters/index.js +54 -0
  267. package/src/runtime/adapters/index.js.map +1 -0
  268. package/src/runtime/adapters/mdx.adapter.d.ts +72 -0
  269. package/src/runtime/adapters/mdx.adapter.js +241 -0
  270. package/src/runtime/adapters/mdx.adapter.js.map +1 -0
  271. package/src/runtime/adapters/react.adapter.d.ts +69 -0
  272. package/src/runtime/adapters/react.adapter.js +245 -0
  273. package/src/runtime/adapters/react.adapter.js.map +1 -0
  274. package/src/runtime/adapters/types.d.ts +94 -0
  275. package/src/runtime/adapters/types.js +11 -0
  276. package/src/runtime/adapters/types.js.map +1 -0
  277. package/src/runtime/csp.d.ts +37 -0
  278. package/src/runtime/csp.js +140 -0
  279. package/src/runtime/csp.js.map +1 -0
  280. package/src/runtime/index.d.ts +16 -0
  281. package/src/runtime/index.js +72 -0
  282. package/src/runtime/index.js.map +1 -0
  283. package/src/runtime/mcp-bridge.d.ts +100 -0
  284. package/src/runtime/mcp-bridge.js +581 -0
  285. package/src/runtime/mcp-bridge.js.map +1 -0
  286. package/src/runtime/renderer-runtime.d.ts +132 -0
  287. package/src/runtime/renderer-runtime.js +389 -0
  288. package/src/runtime/renderer-runtime.js.map +1 -0
  289. package/src/runtime/sanitizer.d.ts +171 -0
  290. package/src/runtime/sanitizer.js +318 -0
  291. package/src/runtime/sanitizer.js.map +1 -0
  292. package/src/runtime/types.d.ts +414 -0
  293. package/src/runtime/types.js +12 -0
  294. package/src/runtime/types.js.map +1 -0
  295. package/src/runtime/wrapper.d.ts +375 -0
  296. package/src/runtime/wrapper.js +1793 -0
  297. package/src/runtime/wrapper.js.map +1 -0
  298. package/src/styles/index.d.ts +7 -0
  299. package/src/styles/index.js +11 -0
  300. package/src/styles/index.js.map +1 -0
  301. package/src/styles/variants.d.ts +50 -0
  302. package/src/styles/variants.js +175 -0
  303. package/src/styles/variants.js.map +1 -0
  304. package/src/theme/cdn.d.ts +194 -0
  305. package/src/theme/cdn.js +375 -0
  306. package/src/theme/cdn.js.map +1 -0
  307. package/src/theme/index.d.ts +17 -0
  308. package/src/theme/index.js +57 -0
  309. package/src/theme/index.js.map +1 -0
  310. package/src/theme/platforms.d.ts +106 -0
  311. package/src/theme/platforms.js +161 -0
  312. package/src/theme/platforms.js.map +1 -0
  313. package/src/theme/presets/github-openai.d.ts +49 -0
  314. package/src/theme/presets/github-openai.js +189 -0
  315. package/src/theme/presets/github-openai.js.map +1 -0
  316. package/src/theme/presets/index.d.ts +10 -0
  317. package/src/theme/presets/index.js +17 -0
  318. package/src/theme/presets/index.js.map +1 -0
  319. package/src/theme/theme.d.ts +395 -0
  320. package/src/theme/theme.js +332 -0
  321. package/src/theme/theme.js.map +1 -0
  322. package/src/tool-template/builder.d.ts +212 -0
  323. package/src/tool-template/builder.js +397 -0
  324. package/src/tool-template/builder.js.map +1 -0
  325. package/src/tool-template/index.d.ts +15 -0
  326. package/src/tool-template/index.js +38 -0
  327. package/src/tool-template/index.js.map +1 -0
  328. package/src/types/index.d.ts +13 -0
  329. package/src/types/index.js +26 -0
  330. package/src/types/index.js.map +1 -0
  331. package/src/types/ui-config.d.ts +357 -0
  332. package/src/types/ui-config.js +12 -0
  333. package/src/types/ui-config.js.map +1 -0
  334. package/src/types/ui-runtime.d.ts +965 -0
  335. package/src/types/ui-runtime.js +117 -0
  336. package/src/types/ui-runtime.js.map +1 -0
  337. package/src/validation/error-box.d.ts +55 -0
  338. package/src/validation/error-box.js +75 -0
  339. package/src/validation/error-box.js.map +1 -0
  340. package/src/validation/index.d.ts +12 -0
  341. package/src/validation/index.js +21 -0
  342. package/src/validation/index.js.map +1 -0
  343. package/src/validation/wrapper.d.ts +96 -0
  344. package/src/validation/wrapper.js +117 -0
  345. package/src/validation/wrapper.js.map +1 -0
  346. package/src/web-components/core/attribute-parser.d.ts +85 -0
  347. package/src/web-components/core/attribute-parser.js +189 -0
  348. package/src/web-components/core/attribute-parser.js.map +1 -0
  349. package/src/web-components/core/base-element.d.ts +197 -0
  350. package/src/web-components/core/base-element.js +289 -0
  351. package/src/web-components/core/base-element.js.map +1 -0
  352. package/src/web-components/core/index.d.ts +8 -0
  353. package/src/web-components/core/index.js +18 -0
  354. package/src/web-components/core/index.js.map +1 -0
  355. package/src/web-components/elements/fmcp-alert.d.ts +45 -0
  356. package/src/web-components/elements/fmcp-alert.js +93 -0
  357. package/src/web-components/elements/fmcp-alert.js.map +1 -0
  358. package/src/web-components/elements/fmcp-badge.d.ts +46 -0
  359. package/src/web-components/elements/fmcp-badge.js +99 -0
  360. package/src/web-components/elements/fmcp-badge.js.map +1 -0
  361. package/src/web-components/elements/fmcp-button.d.ts +124 -0
  362. package/src/web-components/elements/fmcp-button.js +233 -0
  363. package/src/web-components/elements/fmcp-button.js.map +1 -0
  364. package/src/web-components/elements/fmcp-card.d.ts +52 -0
  365. package/src/web-components/elements/fmcp-card.js +115 -0
  366. package/src/web-components/elements/fmcp-card.js.map +1 -0
  367. package/src/web-components/elements/fmcp-input.d.ts +95 -0
  368. package/src/web-components/elements/fmcp-input.js +248 -0
  369. package/src/web-components/elements/fmcp-input.js.map +1 -0
  370. package/src/web-components/elements/fmcp-select.d.ts +99 -0
  371. package/src/web-components/elements/fmcp-select.js +243 -0
  372. package/src/web-components/elements/fmcp-select.js.map +1 -0
  373. package/src/web-components/elements/index.d.ts +12 -0
  374. package/src/web-components/elements/index.js +34 -0
  375. package/src/web-components/elements/index.js.map +1 -0
  376. package/src/web-components/index.d.ts +49 -0
  377. package/src/web-components/index.js +75 -0
  378. package/src/web-components/index.js.map +1 -0
  379. package/src/web-components/register.d.ts +56 -0
  380. package/src/web-components/register.js +80 -0
  381. package/src/web-components/register.js.map +1 -0
  382. package/src/web-components/types.d.ts +121 -0
  383. package/src/web-components/types.js +25 -0
  384. package/src/web-components/types.js.map +1 -0
  385. package/src/widgets/index.d.ts +7 -0
  386. package/src/widgets/index.js +24 -0
  387. package/src/widgets/index.js.map +1 -0
  388. package/src/widgets/progress.d.ts +132 -0
  389. package/src/widgets/progress.js +303 -0
  390. package/src/widgets/progress.js.map +1 -0
  391. package/src/widgets/resource.d.ts +162 -0
  392. package/src/widgets/resource.js +340 -0
  393. package/src/widgets/resource.js.map +1 -0
@@ -0,0 +1,122 @@
1
+ /**
2
+ * HTML Renderer
3
+ *
4
+ * Handles plain HTML templates:
5
+ * - Static HTML strings
6
+ * - Template builder functions: (ctx) => string
7
+ * - Handlebars-enhanced templates: HTML with {{variable}} syntax
8
+ *
9
+ * This is the default fallback renderer with the lowest priority.
10
+ */
11
+ import type { TemplateContext } from '../runtime/types';
12
+ import type { PlatformCapabilities } from '../theme';
13
+ import type { UIRenderer, TranspileResult, TranspileOptions, RenderOptions, RuntimeScripts } from './types';
14
+ /**
15
+ * Template builder function type.
16
+ */
17
+ type TemplateBuilderFn<In, Out> = (ctx: TemplateContext<In, Out>) => string;
18
+ /**
19
+ * Types this renderer can handle.
20
+ */
21
+ type HtmlTemplate<In = unknown, Out = unknown> = string | TemplateBuilderFn<In, Out>;
22
+ /**
23
+ * Check if a template contains Handlebars syntax.
24
+ * Non-async version for canHandle check.
25
+ */
26
+ declare function containsHandlebars(template: string): boolean;
27
+ /**
28
+ * HTML Renderer Implementation.
29
+ *
30
+ * Handles:
31
+ * - Static HTML strings (passed through directly)
32
+ * - Template builder functions that return HTML strings
33
+ * - Handlebars-enhanced templates (detected by {{...}} syntax)
34
+ *
35
+ * When Handlebars syntax is detected, the template is processed
36
+ * with the HandlebarsRenderer for variable interpolation, conditionals,
37
+ * and loops.
38
+ *
39
+ * @example Static HTML
40
+ * ```typescript
41
+ * const template = '<div class="card">Hello World</div>';
42
+ * await htmlRenderer.render(template, context);
43
+ * ```
44
+ *
45
+ * @example Template function
46
+ * ```typescript
47
+ * const template = (ctx) => `<div>${ctx.helpers.escapeHtml(ctx.output.name)}</div>`;
48
+ * await htmlRenderer.render(template, context);
49
+ * ```
50
+ *
51
+ * @example Handlebars template
52
+ * ```typescript
53
+ * const template = `
54
+ * <div class="card">
55
+ * <h2>{{escapeHtml output.title}}</h2>
56
+ * {{#if output.items}}
57
+ * <ul>
58
+ * {{#each output.items}}
59
+ * <li>{{this.name}}</li>
60
+ * {{/each}}
61
+ * </ul>
62
+ * {{/if}}
63
+ * </div>
64
+ * `;
65
+ * await htmlRenderer.render(template, context);
66
+ * ```
67
+ */
68
+ export declare class HtmlRenderer implements UIRenderer<HtmlTemplate> {
69
+ readonly type: "html";
70
+ readonly priority = 0;
71
+ /**
72
+ * Check if this renderer can handle the given template.
73
+ *
74
+ * Accepts:
75
+ * - Any string (assumed to be HTML, with or without Handlebars)
76
+ * - Functions that are template builders (not React components)
77
+ */
78
+ canHandle(template: unknown): template is HtmlTemplate;
79
+ /**
80
+ * Check if a template uses Handlebars syntax.
81
+ *
82
+ * @param template - Template string to check
83
+ * @returns true if template contains {{...}} syntax
84
+ */
85
+ usesHandlebars(template: string): boolean;
86
+ /**
87
+ * Transpile the template.
88
+ *
89
+ * For HTML templates, no transpilation is needed.
90
+ * This method returns a dummy result for consistency.
91
+ */
92
+ transpile(template: HtmlTemplate, _options?: TranspileOptions): Promise<TranspileResult>;
93
+ /**
94
+ * Render the template to HTML string.
95
+ *
96
+ * For static strings without Handlebars, returns the string directly.
97
+ * For strings with Handlebars syntax, processes with HandlebarsRenderer.
98
+ * For functions, calls the function with the context.
99
+ */
100
+ render<In, Out>(template: HtmlTemplate<In, Out>, context: TemplateContext<In, Out>, _options?: RenderOptions): Promise<string>;
101
+ /**
102
+ * Render Handlebars template with context.
103
+ */
104
+ private renderHandlebars;
105
+ /**
106
+ * Get runtime scripts for client-side functionality.
107
+ *
108
+ * HTML templates don't need additional runtime scripts.
109
+ */
110
+ getRuntimeScripts(_platform: PlatformCapabilities): RuntimeScripts;
111
+ }
112
+ /**
113
+ * Singleton instance of the HTML renderer.
114
+ */
115
+ export declare const htmlRenderer: HtmlRenderer;
116
+ /**
117
+ * Check if a template string contains Handlebars syntax.
118
+ *
119
+ * @param template - Template string
120
+ * @returns true if contains {{...}}
121
+ */
122
+ export { containsHandlebars };
@@ -0,0 +1,204 @@
1
+ "use strict";
2
+ /**
3
+ * HTML Renderer
4
+ *
5
+ * Handles plain HTML templates:
6
+ * - Static HTML strings
7
+ * - Template builder functions: (ctx) => string
8
+ * - Handlebars-enhanced templates: HTML with {{variable}} syntax
9
+ *
10
+ * This is the default fallback renderer with the lowest priority.
11
+ */
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ exports.htmlRenderer = exports.HtmlRenderer = void 0;
14
+ exports.containsHandlebars = containsHandlebars;
15
+ const detect_1 = require("./utils/detect");
16
+ const hash_1 = require("./utils/hash");
17
+ /**
18
+ * Lazy-loaded HandlebarsRenderer for Handlebars template support.
19
+ */
20
+ let handlebarsRenderer = null;
21
+ /**
22
+ * Load HandlebarsRenderer if available.
23
+ */
24
+ async function loadHandlebarsRenderer() {
25
+ if (handlebarsRenderer !== null) {
26
+ return handlebarsRenderer;
27
+ }
28
+ try {
29
+ // Dynamic import with explicit .js extension for ESM compatibility
30
+ const handlebarsModule = await import(/* webpackIgnore: true */ '../handlebars/index.js');
31
+ const { HandlebarsRenderer } = handlebarsModule;
32
+ const renderer = new HandlebarsRenderer();
33
+ handlebarsRenderer = {
34
+ render: (template, context) => renderer.render(template, {
35
+ input: (context.input ?? {}),
36
+ output: context.output,
37
+ structuredContent: context.structuredContent,
38
+ }),
39
+ containsHandlebars: (template) => HandlebarsRenderer.containsHandlebars(template),
40
+ };
41
+ return handlebarsRenderer;
42
+ }
43
+ catch {
44
+ // Handlebars not available, return null
45
+ return null;
46
+ }
47
+ }
48
+ /**
49
+ * Check if a template contains Handlebars syntax.
50
+ * Non-async version for canHandle check.
51
+ */
52
+ function containsHandlebars(template) {
53
+ // Match {{...}} but not {{! comments }}
54
+ return /\{\{(?!!)[\s\S]*?\}\}/.test(template);
55
+ }
56
+ /**
57
+ * HTML Renderer Implementation.
58
+ *
59
+ * Handles:
60
+ * - Static HTML strings (passed through directly)
61
+ * - Template builder functions that return HTML strings
62
+ * - Handlebars-enhanced templates (detected by {{...}} syntax)
63
+ *
64
+ * When Handlebars syntax is detected, the template is processed
65
+ * with the HandlebarsRenderer for variable interpolation, conditionals,
66
+ * and loops.
67
+ *
68
+ * @example Static HTML
69
+ * ```typescript
70
+ * const template = '<div class="card">Hello World</div>';
71
+ * await htmlRenderer.render(template, context);
72
+ * ```
73
+ *
74
+ * @example Template function
75
+ * ```typescript
76
+ * const template = (ctx) => `<div>${ctx.helpers.escapeHtml(ctx.output.name)}</div>`;
77
+ * await htmlRenderer.render(template, context);
78
+ * ```
79
+ *
80
+ * @example Handlebars template
81
+ * ```typescript
82
+ * const template = `
83
+ * <div class="card">
84
+ * <h2>{{escapeHtml output.title}}</h2>
85
+ * {{#if output.items}}
86
+ * <ul>
87
+ * {{#each output.items}}
88
+ * <li>{{this.name}}</li>
89
+ * {{/each}}
90
+ * </ul>
91
+ * {{/if}}
92
+ * </div>
93
+ * `;
94
+ * await htmlRenderer.render(template, context);
95
+ * ```
96
+ */
97
+ class HtmlRenderer {
98
+ type = 'html';
99
+ priority = 0; // Lowest priority - fallback renderer
100
+ /**
101
+ * Check if this renderer can handle the given template.
102
+ *
103
+ * Accepts:
104
+ * - Any string (assumed to be HTML, with or without Handlebars)
105
+ * - Functions that are template builders (not React components)
106
+ */
107
+ canHandle(template) {
108
+ // String templates
109
+ if (typeof template === 'string') {
110
+ return true;
111
+ }
112
+ // Template builder functions
113
+ if (typeof template === 'function') {
114
+ return (0, detect_1.isTemplateBuilderFunction)(template);
115
+ }
116
+ return false;
117
+ }
118
+ /**
119
+ * Check if a template uses Handlebars syntax.
120
+ *
121
+ * @param template - Template string to check
122
+ * @returns true if template contains {{...}} syntax
123
+ */
124
+ usesHandlebars(template) {
125
+ return containsHandlebars(template);
126
+ }
127
+ /**
128
+ * Transpile the template.
129
+ *
130
+ * For HTML templates, no transpilation is needed.
131
+ * This method returns a dummy result for consistency.
132
+ */
133
+ async transpile(template, _options) {
134
+ const source = typeof template === 'string' ? template : template.toString();
135
+ const hash = (0, hash_1.hashString)(source);
136
+ return {
137
+ code: '', // No transpiled code needed
138
+ hash,
139
+ cached: true, // Always "cached" since no work is done
140
+ };
141
+ }
142
+ /**
143
+ * Render the template to HTML string.
144
+ *
145
+ * For static strings without Handlebars, returns the string directly.
146
+ * For strings with Handlebars syntax, processes with HandlebarsRenderer.
147
+ * For functions, calls the function with the context.
148
+ */
149
+ async render(template, context, _options) {
150
+ // Static HTML string
151
+ if (typeof template === 'string') {
152
+ // Check for Handlebars syntax
153
+ if (containsHandlebars(template)) {
154
+ return this.renderHandlebars(template, context);
155
+ }
156
+ return template;
157
+ }
158
+ // Template builder function
159
+ if (typeof template === 'function') {
160
+ const result = template(context);
161
+ // Check if the function result contains Handlebars
162
+ if (typeof result === 'string' && containsHandlebars(result)) {
163
+ return this.renderHandlebars(result, context);
164
+ }
165
+ return result;
166
+ }
167
+ // Fallback (should never reach here due to canHandle check)
168
+ return String(template);
169
+ }
170
+ /**
171
+ * Render Handlebars template with context.
172
+ */
173
+ async renderHandlebars(template, context) {
174
+ const renderer = await loadHandlebarsRenderer();
175
+ if (!renderer) {
176
+ // Handlebars not available, return template as-is with a warning comment
177
+ console.warn('[@frontmcp/ui] Template contains Handlebars syntax but handlebars is not installed. ' +
178
+ 'Install it for template interpolation: npm install handlebars');
179
+ return template;
180
+ }
181
+ return renderer.render(template, {
182
+ input: context.input,
183
+ output: context.output,
184
+ structuredContent: context.structuredContent,
185
+ });
186
+ }
187
+ /**
188
+ * Get runtime scripts for client-side functionality.
189
+ *
190
+ * HTML templates don't need additional runtime scripts.
191
+ */
192
+ getRuntimeScripts(_platform) {
193
+ return {
194
+ headScripts: '',
195
+ isInline: false,
196
+ };
197
+ }
198
+ }
199
+ exports.HtmlRenderer = HtmlRenderer;
200
+ /**
201
+ * Singleton instance of the HTML renderer.
202
+ */
203
+ exports.htmlRenderer = new HtmlRenderer();
204
+ //# sourceMappingURL=html.renderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.renderer.js","sourceRoot":"","sources":["../../../src/renderers/html.renderer.ts"],"names":[],"mappings":"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","sourcesContent":["/**\n * HTML Renderer\n *\n * Handles plain HTML templates:\n * - Static HTML strings\n * - Template builder functions: (ctx) => string\n * - Handlebars-enhanced templates: HTML with {{variable}} syntax\n *\n * This is the default fallback renderer with the lowest priority.\n */\n\nimport type { TemplateContext } from '../runtime/types';\nimport type { PlatformCapabilities } from '../theme';\nimport type { UIRenderer, TranspileResult, TranspileOptions, RenderOptions, RuntimeScripts } from './types';\nimport { isTemplateBuilderFunction } from './utils/detect';\nimport { hashString } from './utils/hash';\n\n/**\n * Template builder function type.\n */\ntype TemplateBuilderFn<In, Out> = (ctx: TemplateContext<In, Out>) => string;\n\n/**\n * Types this renderer can handle.\n */\ntype HtmlTemplate<In = unknown, Out = unknown> = string | TemplateBuilderFn<In, Out>;\n\n/**\n * Lazy-loaded HandlebarsRenderer for Handlebars template support.\n */\nlet handlebarsRenderer: {\n render: (\n template: string,\n context: { input: unknown; output: unknown; structuredContent?: unknown },\n ) => Promise<string>;\n containsHandlebars: (template: string) => boolean;\n} | null = null;\n\n/**\n * Load HandlebarsRenderer if available.\n */\nasync function loadHandlebarsRenderer(): Promise<typeof handlebarsRenderer> {\n if (handlebarsRenderer !== null) {\n return handlebarsRenderer;\n }\n\n try {\n // Dynamic import with explicit .js extension for ESM compatibility\n const handlebarsModule = await import(/* webpackIgnore: true */ '../handlebars/index.js');\n const { HandlebarsRenderer } = handlebarsModule;\n const renderer = new HandlebarsRenderer();\n handlebarsRenderer = {\n render: (template: string, context: { input: unknown; output: unknown; structuredContent?: unknown }) =>\n renderer.render(template, {\n input: (context.input ?? {}) as Record<string, unknown>,\n output: context.output,\n structuredContent: context.structuredContent,\n }),\n containsHandlebars: (template: string) => HandlebarsRenderer.containsHandlebars(template),\n };\n return handlebarsRenderer;\n } catch {\n // Handlebars not available, return null\n return null;\n }\n}\n\n/**\n * Check if a template contains Handlebars syntax.\n * Non-async version for canHandle check.\n */\nfunction containsHandlebars(template: string): boolean {\n // Match {{...}} but not {{! comments }}\n return /\\{\\{(?!!)[\\s\\S]*?\\}\\}/.test(template);\n}\n\n/**\n * HTML Renderer Implementation.\n *\n * Handles:\n * - Static HTML strings (passed through directly)\n * - Template builder functions that return HTML strings\n * - Handlebars-enhanced templates (detected by {{...}} syntax)\n *\n * When Handlebars syntax is detected, the template is processed\n * with the HandlebarsRenderer for variable interpolation, conditionals,\n * and loops.\n *\n * @example Static HTML\n * ```typescript\n * const template = '<div class=\"card\">Hello World</div>';\n * await htmlRenderer.render(template, context);\n * ```\n *\n * @example Template function\n * ```typescript\n * const template = (ctx) => `<div>${ctx.helpers.escapeHtml(ctx.output.name)}</div>`;\n * await htmlRenderer.render(template, context);\n * ```\n *\n * @example Handlebars template\n * ```typescript\n * const template = `\n * <div class=\"card\">\n * <h2>{{escapeHtml output.title}}</h2>\n * {{#if output.items}}\n * <ul>\n * {{#each output.items}}\n * <li>{{this.name}}</li>\n * {{/each}}\n * </ul>\n * {{/if}}\n * </div>\n * `;\n * await htmlRenderer.render(template, context);\n * ```\n */\nexport class HtmlRenderer implements UIRenderer<HtmlTemplate> {\n readonly type = 'html' as const;\n readonly priority = 0; // Lowest priority - fallback renderer\n\n /**\n * Check if this renderer can handle the given template.\n *\n * Accepts:\n * - Any string (assumed to be HTML, with or without Handlebars)\n * - Functions that are template builders (not React components)\n */\n canHandle(template: unknown): template is HtmlTemplate {\n // String templates\n if (typeof template === 'string') {\n return true;\n }\n\n // Template builder functions\n if (typeof template === 'function') {\n return isTemplateBuilderFunction(template as Function);\n }\n\n return false;\n }\n\n /**\n * Check if a template uses Handlebars syntax.\n *\n * @param template - Template string to check\n * @returns true if template contains {{...}} syntax\n */\n usesHandlebars(template: string): boolean {\n return containsHandlebars(template);\n }\n\n /**\n * Transpile the template.\n *\n * For HTML templates, no transpilation is needed.\n * This method returns a dummy result for consistency.\n */\n async transpile(template: HtmlTemplate, _options?: TranspileOptions): Promise<TranspileResult> {\n const source = typeof template === 'string' ? template : template.toString();\n const hash = hashString(source);\n\n return {\n code: '', // No transpiled code needed\n hash,\n cached: true, // Always \"cached\" since no work is done\n };\n }\n\n /**\n * Render the template to HTML string.\n *\n * For static strings without Handlebars, returns the string directly.\n * For strings with Handlebars syntax, processes with HandlebarsRenderer.\n * For functions, calls the function with the context.\n */\n async render<In, Out>(\n template: HtmlTemplate<In, Out>,\n context: TemplateContext<In, Out>,\n _options?: RenderOptions,\n ): Promise<string> {\n // Static HTML string\n if (typeof template === 'string') {\n // Check for Handlebars syntax\n if (containsHandlebars(template)) {\n return this.renderHandlebars(template, context);\n }\n return template;\n }\n\n // Template builder function\n if (typeof template === 'function') {\n const result = template(context);\n // Check if the function result contains Handlebars\n if (typeof result === 'string' && containsHandlebars(result)) {\n return this.renderHandlebars(result, context);\n }\n return result;\n }\n\n // Fallback (should never reach here due to canHandle check)\n return String(template);\n }\n\n /**\n * Render Handlebars template with context.\n */\n private async renderHandlebars<In, Out>(template: string, context: TemplateContext<In, Out>): Promise<string> {\n const renderer = await loadHandlebarsRenderer();\n\n if (!renderer) {\n // Handlebars not available, return template as-is with a warning comment\n console.warn(\n '[@frontmcp/ui] Template contains Handlebars syntax but handlebars is not installed. ' +\n 'Install it for template interpolation: npm install handlebars',\n );\n return template;\n }\n\n return renderer.render(template, {\n input: context.input as Record<string, unknown>,\n output: context.output,\n structuredContent: context.structuredContent,\n });\n }\n\n /**\n * Get runtime scripts for client-side functionality.\n *\n * HTML templates don't need additional runtime scripts.\n */\n getRuntimeScripts(_platform: PlatformCapabilities): RuntimeScripts {\n return {\n headScripts: '',\n isInline: false,\n };\n }\n}\n\n/**\n * Singleton instance of the HTML renderer.\n */\nexport const htmlRenderer = new HtmlRenderer();\n\n/**\n * Check if a template string contains Handlebars syntax.\n *\n * @param template - Template string\n * @returns true if contains {{...}}\n */\nexport { containsHandlebars };\n"]}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Renderer Module
3
+ *
4
+ * Multi-framework rendering system for Tool UI templates.
5
+ * Supports HTML, React, and MDX templates with auto-detection.
6
+ *
7
+ * @module @frontmcp/ui
8
+ *
9
+ * @example Basic usage with auto-detection
10
+ * ```typescript
11
+ * import { rendererRegistry } from '@frontmcp/ui';
12
+ *
13
+ * // HTML template
14
+ * const htmlTemplate = (ctx) => `<div>${ctx.output.name}</div>`;
15
+ * const result = await rendererRegistry.render(htmlTemplate, context);
16
+ * ```
17
+ *
18
+ * @example Register React renderer
19
+ * ```typescript
20
+ * import { rendererRegistry, reactRenderer } from '@frontmcp/ui';
21
+ *
22
+ * rendererRegistry.register(reactRenderer);
23
+ *
24
+ * // Now React components are auto-detected
25
+ * const MyComponent = ({ output }) => <div>{output.name}</div>;
26
+ * const result = await rendererRegistry.render(MyComponent, context);
27
+ * ```
28
+ */
29
+ export type { RendererType, UIRenderer, ToolUIProps, HydratedToolUIProps, TranspileResult, TranspileOptions, RenderOptions, RuntimeScripts, RenderResult, RendererRegistryOptions, DetectionResult, ReactComponentType, WrapperContext, ExtendedToolUIConfig, } from './types';
30
+ export { TranspileCache, transpileCache, renderCache, type TranspileCacheOptions } from './cache';
31
+ export { RendererRegistry, rendererRegistry } from './registry';
32
+ export { HtmlRenderer, htmlRenderer } from './html.renderer';
33
+ export { ReactRenderer, reactRenderer, buildHydrationScript } from './react.renderer';
34
+ export { MdxRenderer, mdxRenderer, buildMdxHydrationScript } from './mdx.renderer';
35
+ export { isReactComponent, isTemplateBuilderFunction, containsJsx, containsMdxSyntax, isPlainHtml, detectTemplateType, hashString, hashCombined, isHash, transpileJsx, isSwcAvailable, executeTranspiledCode, transpileAndExecute, } from './utils';
@@ -0,0 +1,70 @@
1
+ "use strict";
2
+ /**
3
+ * Renderer Module
4
+ *
5
+ * Multi-framework rendering system for Tool UI templates.
6
+ * Supports HTML, React, and MDX templates with auto-detection.
7
+ *
8
+ * @module @frontmcp/ui
9
+ *
10
+ * @example Basic usage with auto-detection
11
+ * ```typescript
12
+ * import { rendererRegistry } from '@frontmcp/ui';
13
+ *
14
+ * // HTML template
15
+ * const htmlTemplate = (ctx) => `<div>${ctx.output.name}</div>`;
16
+ * const result = await rendererRegistry.render(htmlTemplate, context);
17
+ * ```
18
+ *
19
+ * @example Register React renderer
20
+ * ```typescript
21
+ * import { rendererRegistry, reactRenderer } from '@frontmcp/ui';
22
+ *
23
+ * rendererRegistry.register(reactRenderer);
24
+ *
25
+ * // Now React components are auto-detected
26
+ * const MyComponent = ({ output }) => <div>{output.name}</div>;
27
+ * const result = await rendererRegistry.render(MyComponent, context);
28
+ * ```
29
+ */
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.transpileAndExecute = exports.executeTranspiledCode = exports.isSwcAvailable = exports.transpileJsx = exports.isHash = exports.hashCombined = exports.hashString = exports.detectTemplateType = exports.isPlainHtml = exports.containsMdxSyntax = exports.containsJsx = exports.isTemplateBuilderFunction = exports.isReactComponent = exports.buildMdxHydrationScript = exports.mdxRenderer = exports.MdxRenderer = exports.buildHydrationScript = exports.reactRenderer = exports.ReactRenderer = exports.htmlRenderer = exports.HtmlRenderer = exports.rendererRegistry = exports.RendererRegistry = exports.renderCache = exports.transpileCache = exports.TranspileCache = void 0;
32
+ // Cache
33
+ var cache_1 = require("./cache");
34
+ Object.defineProperty(exports, "TranspileCache", { enumerable: true, get: function () { return cache_1.TranspileCache; } });
35
+ Object.defineProperty(exports, "transpileCache", { enumerable: true, get: function () { return cache_1.transpileCache; } });
36
+ Object.defineProperty(exports, "renderCache", { enumerable: true, get: function () { return cache_1.renderCache; } });
37
+ // Registry
38
+ var registry_1 = require("./registry");
39
+ Object.defineProperty(exports, "RendererRegistry", { enumerable: true, get: function () { return registry_1.RendererRegistry; } });
40
+ Object.defineProperty(exports, "rendererRegistry", { enumerable: true, get: function () { return registry_1.rendererRegistry; } });
41
+ // HTML Renderer (built-in)
42
+ var html_renderer_1 = require("./html.renderer");
43
+ Object.defineProperty(exports, "HtmlRenderer", { enumerable: true, get: function () { return html_renderer_1.HtmlRenderer; } });
44
+ Object.defineProperty(exports, "htmlRenderer", { enumerable: true, get: function () { return html_renderer_1.htmlRenderer; } });
45
+ // React Renderer
46
+ var react_renderer_1 = require("./react.renderer");
47
+ Object.defineProperty(exports, "ReactRenderer", { enumerable: true, get: function () { return react_renderer_1.ReactRenderer; } });
48
+ Object.defineProperty(exports, "reactRenderer", { enumerable: true, get: function () { return react_renderer_1.reactRenderer; } });
49
+ Object.defineProperty(exports, "buildHydrationScript", { enumerable: true, get: function () { return react_renderer_1.buildHydrationScript; } });
50
+ // MDX Renderer
51
+ var mdx_renderer_1 = require("./mdx.renderer");
52
+ Object.defineProperty(exports, "MdxRenderer", { enumerable: true, get: function () { return mdx_renderer_1.MdxRenderer; } });
53
+ Object.defineProperty(exports, "mdxRenderer", { enumerable: true, get: function () { return mdx_renderer_1.mdxRenderer; } });
54
+ Object.defineProperty(exports, "buildMdxHydrationScript", { enumerable: true, get: function () { return mdx_renderer_1.buildMdxHydrationScript; } });
55
+ // Utilities
56
+ var utils_1 = require("./utils");
57
+ Object.defineProperty(exports, "isReactComponent", { enumerable: true, get: function () { return utils_1.isReactComponent; } });
58
+ Object.defineProperty(exports, "isTemplateBuilderFunction", { enumerable: true, get: function () { return utils_1.isTemplateBuilderFunction; } });
59
+ Object.defineProperty(exports, "containsJsx", { enumerable: true, get: function () { return utils_1.containsJsx; } });
60
+ Object.defineProperty(exports, "containsMdxSyntax", { enumerable: true, get: function () { return utils_1.containsMdxSyntax; } });
61
+ Object.defineProperty(exports, "isPlainHtml", { enumerable: true, get: function () { return utils_1.isPlainHtml; } });
62
+ Object.defineProperty(exports, "detectTemplateType", { enumerable: true, get: function () { return utils_1.detectTemplateType; } });
63
+ Object.defineProperty(exports, "hashString", { enumerable: true, get: function () { return utils_1.hashString; } });
64
+ Object.defineProperty(exports, "hashCombined", { enumerable: true, get: function () { return utils_1.hashCombined; } });
65
+ Object.defineProperty(exports, "isHash", { enumerable: true, get: function () { return utils_1.isHash; } });
66
+ Object.defineProperty(exports, "transpileJsx", { enumerable: true, get: function () { return utils_1.transpileJsx; } });
67
+ Object.defineProperty(exports, "isSwcAvailable", { enumerable: true, get: function () { return utils_1.isSwcAvailable; } });
68
+ Object.defineProperty(exports, "executeTranspiledCode", { enumerable: true, get: function () { return utils_1.executeTranspiledCode; } });
69
+ Object.defineProperty(exports, "transpileAndExecute", { enumerable: true, get: function () { return utils_1.transpileAndExecute; } });
70
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/renderers/index.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;;;AAsBH,QAAQ;AACR,iCAAkG;AAAzF,uGAAA,cAAc,OAAA;AAAE,uGAAA,cAAc,OAAA;AAAE,oGAAA,WAAW,OAAA;AAEpD,WAAW;AACX,uCAAgE;AAAvD,4GAAA,gBAAgB,OAAA;AAAE,4GAAA,gBAAgB,OAAA;AAE3C,2BAA2B;AAC3B,iDAA6D;AAApD,6GAAA,YAAY,OAAA;AAAE,6GAAA,YAAY,OAAA;AAEnC,iBAAiB;AACjB,mDAAsF;AAA7E,+GAAA,aAAa,OAAA;AAAE,+GAAA,aAAa,OAAA;AAAE,sHAAA,oBAAoB,OAAA;AAE3D,eAAe;AACf,+CAAmF;AAA1E,2GAAA,WAAW,OAAA;AAAE,2GAAA,WAAW,OAAA;AAAE,uHAAA,uBAAuB,OAAA;AAE1D,YAAY;AACZ,iCAciB;AAbf,yGAAA,gBAAgB,OAAA;AAChB,kHAAA,yBAAyB,OAAA;AACzB,oGAAA,WAAW,OAAA;AACX,0GAAA,iBAAiB,OAAA;AACjB,oGAAA,WAAW,OAAA;AACX,2GAAA,kBAAkB,OAAA;AAClB,mGAAA,UAAU,OAAA;AACV,qGAAA,YAAY,OAAA;AACZ,+FAAA,MAAM,OAAA;AACN,qGAAA,YAAY,OAAA;AACZ,uGAAA,cAAc,OAAA;AACd,8GAAA,qBAAqB,OAAA;AACrB,4GAAA,mBAAmB,OAAA","sourcesContent":["/**\n * Renderer Module\n *\n * Multi-framework rendering system for Tool UI templates.\n * Supports HTML, React, and MDX templates with auto-detection.\n *\n * @module @frontmcp/ui\n *\n * @example Basic usage with auto-detection\n * ```typescript\n * import { rendererRegistry } from '@frontmcp/ui';\n *\n * // HTML template\n * const htmlTemplate = (ctx) => `<div>${ctx.output.name}</div>`;\n * const result = await rendererRegistry.render(htmlTemplate, context);\n * ```\n *\n * @example Register React renderer\n * ```typescript\n * import { rendererRegistry, reactRenderer } from '@frontmcp/ui';\n *\n * rendererRegistry.register(reactRenderer);\n *\n * // Now React components are auto-detected\n * const MyComponent = ({ output }) => <div>{output.name}</div>;\n * const result = await rendererRegistry.render(MyComponent, context);\n * ```\n */\n\n// Types\n// Note: TemplateBuilderFn and ToolUITemplate are exported from ../runtime/types\n// to avoid duplication with the main runtime exports\nexport type {\n RendererType,\n UIRenderer,\n ToolUIProps,\n HydratedToolUIProps,\n TranspileResult,\n TranspileOptions,\n RenderOptions,\n RuntimeScripts,\n RenderResult,\n RendererRegistryOptions,\n DetectionResult,\n ReactComponentType,\n WrapperContext,\n ExtendedToolUIConfig,\n} from './types';\n\n// Cache\nexport { TranspileCache, transpileCache, renderCache, type TranspileCacheOptions } from './cache';\n\n// Registry\nexport { RendererRegistry, rendererRegistry } from './registry';\n\n// HTML Renderer (built-in)\nexport { HtmlRenderer, htmlRenderer } from './html.renderer';\n\n// React Renderer\nexport { ReactRenderer, reactRenderer, buildHydrationScript } from './react.renderer';\n\n// MDX Renderer\nexport { MdxRenderer, mdxRenderer, buildMdxHydrationScript } from './mdx.renderer';\n\n// Utilities\nexport {\n isReactComponent,\n isTemplateBuilderFunction,\n containsJsx,\n containsMdxSyntax,\n isPlainHtml,\n detectTemplateType,\n hashString,\n hashCombined,\n isHash,\n transpileJsx,\n isSwcAvailable,\n executeTranspiledCode,\n transpileAndExecute,\n} from './utils';\n"]}
@@ -0,0 +1,119 @@
1
+ /**
2
+ * MDX Renderer
3
+ *
4
+ * Handles MDX templates - Markdown with embedded JSX components.
5
+ * Uses @mdx-js/mdx for compilation and react-dom/server for SSR.
6
+ *
7
+ * MDX allows mixing Markdown with React components:
8
+ * - Markdown headings, lists, code blocks
9
+ * - JSX component tags: `<Card />`
10
+ * - JS expressions: `{output.items.map(...)}`
11
+ * - Frontmatter for metadata
12
+ */
13
+ import type { TemplateContext } from '../runtime/types';
14
+ import type { PlatformCapabilities } from '../theme';
15
+ import type { UIRenderer, TranspileResult, TranspileOptions, RenderOptions, RuntimeScripts } from './types';
16
+ /**
17
+ * Types this renderer can handle - MDX strings.
18
+ */
19
+ type MdxTemplate = string;
20
+ /**
21
+ * MDX Renderer Implementation.
22
+ *
23
+ * Compiles MDX (Markdown + JSX) to React components using @mdx-js/mdx,
24
+ * then renders to HTML using react-dom/server.
25
+ *
26
+ * @example Basic MDX template
27
+ * ```typescript
28
+ * @Tool({
29
+ * ui: {
30
+ * template: `
31
+ * # User Profile
32
+ *
33
+ * <UserCard name={output.name} email={output.email} />
34
+ *
35
+ * ## Recent Activity
36
+ * {output.items.map(item => <ActivityItem key={item.id} {...item} />)}
37
+ * `,
38
+ * mdxComponents: { UserCard, ActivityItem }
39
+ * }
40
+ * })
41
+ * ```
42
+ *
43
+ * @example MDX with frontmatter
44
+ * ```typescript
45
+ * @Tool({
46
+ * ui: {
47
+ * template: `
48
+ * ---
49
+ * title: Dashboard
50
+ * ---
51
+ *
52
+ * # {frontmatter.title}
53
+ *
54
+ * <Dashboard data={output} />
55
+ * `
56
+ * }
57
+ * })
58
+ * ```
59
+ */
60
+ export declare class MdxRenderer implements UIRenderer<MdxTemplate> {
61
+ readonly type: "mdx";
62
+ readonly priority = 10;
63
+ /**
64
+ * Lazy-loaded modules.
65
+ */
66
+ private React;
67
+ private ReactDOMServer;
68
+ private jsxRuntime;
69
+ private mdxEvaluate;
70
+ /**
71
+ * Check if this renderer can handle the given template.
72
+ *
73
+ * Accepts strings containing MDX syntax (Markdown + JSX).
74
+ */
75
+ canHandle(template: unknown): template is MdxTemplate;
76
+ /**
77
+ * Transpile MDX to executable JavaScript.
78
+ *
79
+ * Uses @mdx-js/mdx to compile MDX source to a module.
80
+ * Note: For MDX, we use evaluate() which combines compile + run,
81
+ * so this method just returns the source hash for caching purposes.
82
+ */
83
+ transpile(template: MdxTemplate, _options?: TranspileOptions): Promise<TranspileResult>;
84
+ /**
85
+ * Render MDX template to HTML string.
86
+ *
87
+ * Uses @mdx-js/mdx's evaluate() for clean compilation + execution,
88
+ * then renders the resulting React component to HTML via SSR.
89
+ */
90
+ render<In, Out>(template: MdxTemplate, context: TemplateContext<In, Out>, options?: RenderOptions): Promise<string>;
91
+ /**
92
+ * Get runtime scripts for client-side functionality.
93
+ */
94
+ getRuntimeScripts(platform: PlatformCapabilities): RuntimeScripts;
95
+ /**
96
+ * Load React and ReactDOMServer modules.
97
+ */
98
+ private loadReact;
99
+ /**
100
+ * Load @mdx-js/mdx evaluate function.
101
+ *
102
+ * evaluate() is the cleanest way to run MDX - it combines
103
+ * compile and run in a single step, handling all the runtime
104
+ * injection automatically.
105
+ */
106
+ private loadMdx;
107
+ }
108
+ /**
109
+ * Singleton instance of the MDX renderer.
110
+ */
111
+ export declare const mdxRenderer: MdxRenderer;
112
+ /**
113
+ * Build MDX hydration script for client-side interactivity.
114
+ *
115
+ * Note: MDX hydration is more complex than React hydration
116
+ * because it needs the MDX runtime and component definitions.
117
+ */
118
+ export declare function buildMdxHydrationScript(): string;
119
+ export {};