@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,7 @@
1
+ /**
2
+ * @file render/index.ts
3
+ * @description React 19 static rendering utilities.
4
+ *
5
+ * @module @frontmcp/ui/render
6
+ */
7
+ export { renderToString, renderToStringSync, isReactAvailable } from './prerender';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ /**
3
+ * @file render/index.ts
4
+ * @description React 19 static rendering utilities.
5
+ *
6
+ * @module @frontmcp/ui/render
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.isReactAvailable = exports.renderToStringSync = exports.renderToString = void 0;
10
+ var prerender_1 = require("./prerender");
11
+ Object.defineProperty(exports, "renderToString", { enumerable: true, get: function () { return prerender_1.renderToString; } });
12
+ Object.defineProperty(exports, "renderToStringSync", { enumerable: true, get: function () { return prerender_1.renderToStringSync; } });
13
+ Object.defineProperty(exports, "isReactAvailable", { enumerable: true, get: function () { return prerender_1.isReactAvailable; } });
14
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/render/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,yCAAmF;AAA1E,2GAAA,cAAc,OAAA;AAAE,+GAAA,kBAAkB,OAAA;AAAE,6GAAA,gBAAgB,OAAA","sourcesContent":["/**\n * @file render/index.ts\n * @description React 19 static rendering utilities.\n *\n * @module @frontmcp/ui/render\n */\n\nexport { renderToString, renderToStringSync, isReactAvailable } from './prerender';\n"]}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * @file prerender.ts
3
+ * @description React 19 static rendering utilities.
4
+ *
5
+ * Provides both async (prerender) and sync (renderToStaticMarkup) methods
6
+ * for converting React elements to HTML strings.
7
+ *
8
+ * @example Async rendering (recommended)
9
+ * ```typescript
10
+ * import { renderToString } from '@frontmcp/ui/render';
11
+ * import { Card } from '@frontmcp/ui/components';
12
+ *
13
+ * const html = await renderToString(<Card title="Hello">Content</Card>);
14
+ * ```
15
+ *
16
+ * @example Sync rendering (backwards compatible)
17
+ * ```typescript
18
+ * import { renderToStringSync } from '@frontmcp/ui/render';
19
+ *
20
+ * const html = renderToStringSync(<Card title="Hello">Content</Card>);
21
+ * ```
22
+ *
23
+ * @module @frontmcp/ui/render
24
+ */
25
+ import type { ReactElement } from 'react';
26
+ /**
27
+ * Render a React element to static HTML string using React 19's prerender API.
28
+ *
29
+ * This is the recommended async method that:
30
+ * - Waits for all Suspense boundaries to resolve
31
+ * - Uses React 19's streaming prerender API
32
+ * - Returns clean static HTML without hydration markers
33
+ *
34
+ * @param element - The React element to render
35
+ * @returns Promise resolving to HTML string
36
+ */
37
+ export declare function renderToString(element: ReactElement): Promise<string>;
38
+ /**
39
+ * Render a React element to static HTML string synchronously.
40
+ *
41
+ * This is the sync method for backwards compatibility that:
42
+ * - Does NOT wait for Suspense boundaries
43
+ * - Uses React's renderToStaticMarkup
44
+ * - Returns clean static HTML without hydration markers
45
+ *
46
+ * @param element - The React element to render
47
+ * @returns HTML string
48
+ */
49
+ export declare function renderToStringSync(element: ReactElement): string;
50
+ /**
51
+ * Check if React and react-dom are available.
52
+ * Useful for conditional rendering in environments where React may not be installed.
53
+ *
54
+ * @returns true if React and react-dom are available
55
+ */
56
+ export declare function isReactAvailable(): boolean;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+ /**
3
+ * @file prerender.ts
4
+ * @description React 19 static rendering utilities.
5
+ *
6
+ * Provides both async (prerender) and sync (renderToStaticMarkup) methods
7
+ * for converting React elements to HTML strings.
8
+ *
9
+ * @example Async rendering (recommended)
10
+ * ```typescript
11
+ * import { renderToString } from '@frontmcp/ui/render';
12
+ * import { Card } from '@frontmcp/ui/components';
13
+ *
14
+ * const html = await renderToString(<Card title="Hello">Content</Card>);
15
+ * ```
16
+ *
17
+ * @example Sync rendering (backwards compatible)
18
+ * ```typescript
19
+ * import { renderToStringSync } from '@frontmcp/ui/render';
20
+ *
21
+ * const html = renderToStringSync(<Card title="Hello">Content</Card>);
22
+ * ```
23
+ *
24
+ * @module @frontmcp/ui/render
25
+ */
26
+ Object.defineProperty(exports, "__esModule", { value: true });
27
+ exports.renderToString = renderToString;
28
+ exports.renderToStringSync = renderToStringSync;
29
+ exports.isReactAvailable = isReactAvailable;
30
+ /**
31
+ * Render a React element to static HTML string using React 19's prerender API.
32
+ *
33
+ * This is the recommended async method that:
34
+ * - Waits for all Suspense boundaries to resolve
35
+ * - Uses React 19's streaming prerender API
36
+ * - Returns clean static HTML without hydration markers
37
+ *
38
+ * @param element - The React element to render
39
+ * @returns Promise resolving to HTML string
40
+ */
41
+ async function renderToString(element) {
42
+ // Dynamically import to avoid issues when react-dom is not installed
43
+ const { prerender } = await import('react-dom/static');
44
+ const { prelude } = await prerender(element);
45
+ // Convert ReadableStream to string
46
+ const reader = prelude.getReader();
47
+ const chunks = [];
48
+ while (true) {
49
+ const { done, value } = await reader.read();
50
+ if (done)
51
+ break;
52
+ if (value)
53
+ chunks.push(value);
54
+ }
55
+ // Concatenate all chunks and decode
56
+ const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);
57
+ const combined = new Uint8Array(totalLength);
58
+ let offset = 0;
59
+ for (const chunk of chunks) {
60
+ combined.set(chunk, offset);
61
+ offset += chunk.length;
62
+ }
63
+ return new TextDecoder().decode(combined);
64
+ }
65
+ /**
66
+ * Render a React element to static HTML string synchronously.
67
+ *
68
+ * This is the sync method for backwards compatibility that:
69
+ * - Does NOT wait for Suspense boundaries
70
+ * - Uses React's renderToStaticMarkup
71
+ * - Returns clean static HTML without hydration markers
72
+ *
73
+ * @param element - The React element to render
74
+ * @returns HTML string
75
+ */
76
+ function renderToStringSync(element) {
77
+ // Use dynamic require to handle optional react-dom dependency
78
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
79
+ const ReactDOMServer = require('react-dom/server');
80
+ return ReactDOMServer.renderToStaticMarkup(element);
81
+ }
82
+ /**
83
+ * Check if React and react-dom are available.
84
+ * Useful for conditional rendering in environments where React may not be installed.
85
+ *
86
+ * @returns true if React and react-dom are available
87
+ */
88
+ function isReactAvailable() {
89
+ try {
90
+ require('react');
91
+ require('react-dom/server');
92
+ return true;
93
+ }
94
+ catch {
95
+ return false;
96
+ }
97
+ }
98
+ //# sourceMappingURL=prerender.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"prerender.js","sourceRoot":"","sources":["../../../src/render/prerender.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;;AAgBH,wCA0BC;AAaD,gDAKC;AAQD,4CAQC;AAvED;;;;;;;;;;GAUG;AACI,KAAK,UAAU,cAAc,CAAC,OAAqB;IACxD,qEAAqE;IACrE,MAAM,EAAE,SAAS,EAAE,GAAG,MAAM,MAAM,CAAC,kBAAkB,CAAC,CAAC;IAEvD,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,SAAS,CAAC,OAAO,CAAC,CAAC;IAE7C,mCAAmC;IACnC,MAAM,MAAM,GAAG,OAAO,CAAC,SAAS,EAAE,CAAC;IACnC,MAAM,MAAM,GAAiB,EAAE,CAAC;IAEhC,OAAO,IAAI,EAAE,CAAC;QACZ,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,GAAG,MAAM,MAAM,CAAC,IAAI,EAAE,CAAC;QAC5C,IAAI,IAAI;YAAE,MAAM;QAChB,IAAI,KAAK;YAAE,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;IAChC,CAAC;IAED,oCAAoC;IACpC,MAAM,WAAW,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,CAAC,GAAG,GAAG,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;IACzE,MAAM,QAAQ,GAAG,IAAI,UAAU,CAAC,WAAW,CAAC,CAAC;IAC7C,IAAI,MAAM,GAAG,CAAC,CAAC;IACf,KAAK,MAAM,KAAK,IAAI,MAAM,EAAE,CAAC;QAC3B,QAAQ,CAAC,GAAG,CAAC,KAAK,EAAE,MAAM,CAAC,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC;IACzB,CAAC;IAED,OAAO,IAAI,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;AAC5C,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAgB,kBAAkB,CAAC,OAAqB;IACtD,8DAA8D;IAC9D,iEAAiE;IACjE,MAAM,cAAc,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAAC;IACnD,OAAO,cAAc,CAAC,oBAAoB,CAAC,OAAO,CAAC,CAAC;AACtD,CAAC;AAED;;;;;GAKG;AACH,SAAgB,gBAAgB;IAC9B,IAAI,CAAC;QACH,OAAO,CAAC,OAAO,CAAC,CAAC;QACjB,OAAO,CAAC,kBAAkB,CAAC,CAAC;QAC5B,OAAO,IAAI,CAAC;IACd,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,KAAK,CAAC;IACf,CAAC;AACH,CAAC","sourcesContent":["/**\n * @file prerender.ts\n * @description React 19 static rendering utilities.\n *\n * Provides both async (prerender) and sync (renderToStaticMarkup) methods\n * for converting React elements to HTML strings.\n *\n * @example Async rendering (recommended)\n * ```typescript\n * import { renderToString } from '@frontmcp/ui/render';\n * import { Card } from '@frontmcp/ui/components';\n *\n * const html = await renderToString(<Card title=\"Hello\">Content</Card>);\n * ```\n *\n * @example Sync rendering (backwards compatible)\n * ```typescript\n * import { renderToStringSync } from '@frontmcp/ui/render';\n *\n * const html = renderToStringSync(<Card title=\"Hello\">Content</Card>);\n * ```\n *\n * @module @frontmcp/ui/render\n */\n\n/// <reference path=\"./react-dom-static.d.ts\" />\nimport type { ReactElement } from 'react';\n\n/**\n * Render a React element to static HTML string using React 19's prerender API.\n *\n * This is the recommended async method that:\n * - Waits for all Suspense boundaries to resolve\n * - Uses React 19's streaming prerender API\n * - Returns clean static HTML without hydration markers\n *\n * @param element - The React element to render\n * @returns Promise resolving to HTML string\n */\nexport async function renderToString(element: ReactElement): Promise<string> {\n // Dynamically import to avoid issues when react-dom is not installed\n const { prerender } = await import('react-dom/static');\n\n const { prelude } = await prerender(element);\n\n // Convert ReadableStream to string\n const reader = prelude.getReader();\n const chunks: Uint8Array[] = [];\n\n while (true) {\n const { done, value } = await reader.read();\n if (done) break;\n if (value) chunks.push(value);\n }\n\n // Concatenate all chunks and decode\n const totalLength = chunks.reduce((acc, chunk) => acc + chunk.length, 0);\n const combined = new Uint8Array(totalLength);\n let offset = 0;\n for (const chunk of chunks) {\n combined.set(chunk, offset);\n offset += chunk.length;\n }\n\n return new TextDecoder().decode(combined);\n}\n\n/**\n * Render a React element to static HTML string synchronously.\n *\n * This is the sync method for backwards compatibility that:\n * - Does NOT wait for Suspense boundaries\n * - Uses React's renderToStaticMarkup\n * - Returns clean static HTML without hydration markers\n *\n * @param element - The React element to render\n * @returns HTML string\n */\nexport function renderToStringSync(element: ReactElement): string {\n // Use dynamic require to handle optional react-dom dependency\n // eslint-disable-next-line @typescript-eslint/no-require-imports\n const ReactDOMServer = require('react-dom/server');\n return ReactDOMServer.renderToStaticMarkup(element);\n}\n\n/**\n * Check if React and react-dom are available.\n * Useful for conditional rendering in environments where React may not be installed.\n *\n * @returns true if React and react-dom are available\n */\nexport function isReactAvailable(): boolean {\n try {\n require('react');\n require('react-dom/server');\n return true;\n } catch {\n return false;\n }\n}\n"]}
@@ -0,0 +1,144 @@
1
+ /**
2
+ * LRU Cache for Renderer Transpilation Results
3
+ *
4
+ * Provides fast, memory-bounded caching for transpiled templates.
5
+ * Uses content-addressable keys (hash of source) for deduplication.
6
+ */
7
+ import type { TranspileResult } from './types';
8
+ /**
9
+ * Options for the transpile cache.
10
+ */
11
+ export interface TranspileCacheOptions {
12
+ /** Maximum number of entries (default: 500) */
13
+ maxSize?: number;
14
+ /** TTL in milliseconds, 0 = infinite (default: 0 for transpile cache) */
15
+ ttl?: number;
16
+ }
17
+ /**
18
+ * LRU Cache for transpiled template results.
19
+ *
20
+ * Features:
21
+ * - Content-addressable keys via hash
22
+ * - LRU eviction when max size reached
23
+ * - Optional TTL for time-based expiration
24
+ * - Access statistics
25
+ *
26
+ * @example
27
+ * ```typescript
28
+ * const cache = new TranspileCache({ maxSize: 500 });
29
+ *
30
+ * // Store a transpiled result
31
+ * const hash = cache.set(sourceCode, transpileResult);
32
+ *
33
+ * // Retrieve it later
34
+ * const result = cache.get(sourceCode);
35
+ * if (result) {
36
+ * console.log('Cache hit!', result.code);
37
+ * }
38
+ * ```
39
+ */
40
+ export declare class TranspileCache {
41
+ private cache;
42
+ private readonly maxSize;
43
+ private readonly ttl;
44
+ /** Cache statistics */
45
+ private stats;
46
+ constructor(options?: TranspileCacheOptions);
47
+ /**
48
+ * Get a cached transpile result by source content.
49
+ *
50
+ * @param source - Source code to look up
51
+ * @returns Cached result or undefined if not found/expired
52
+ */
53
+ get(source: string): TranspileResult | undefined;
54
+ /**
55
+ * Get a cached transpile result by hash key.
56
+ *
57
+ * @param key - Hash key
58
+ * @returns Cached result or undefined if not found/expired
59
+ */
60
+ getByKey(key: string): TranspileResult | undefined;
61
+ /**
62
+ * Store a transpile result.
63
+ *
64
+ * @param source - Source code (used to generate key)
65
+ * @param value - Transpile result to cache
66
+ * @returns The hash key used for storage
67
+ */
68
+ set(source: string, value: TranspileResult): string;
69
+ /**
70
+ * Store a transpile result by hash key.
71
+ *
72
+ * @param key - Hash key
73
+ * @param value - Transpile result to cache
74
+ */
75
+ setByKey(key: string, value: TranspileResult): void;
76
+ /**
77
+ * Check if a source is cached.
78
+ *
79
+ * @param source - Source code to check
80
+ * @returns True if cached and not expired
81
+ */
82
+ has(source: string): boolean;
83
+ /**
84
+ * Check if a key is cached.
85
+ *
86
+ * @param key - Hash key to check
87
+ * @returns True if cached and not expired
88
+ */
89
+ hasByKey(key: string): boolean;
90
+ /**
91
+ * Delete a cached entry by source.
92
+ *
93
+ * @param source - Source code to delete
94
+ * @returns True if entry was deleted
95
+ */
96
+ delete(source: string): boolean;
97
+ /**
98
+ * Clear all cached entries.
99
+ */
100
+ clear(): void;
101
+ /**
102
+ * Get current cache size.
103
+ */
104
+ get size(): number;
105
+ /**
106
+ * Get cache statistics.
107
+ */
108
+ getStats(): {
109
+ hits: number;
110
+ misses: number;
111
+ evictions: number;
112
+ size: number;
113
+ hitRate: number;
114
+ };
115
+ }
116
+ /**
117
+ * Global transpile cache instance.
118
+ * Shared across all renderers for deduplication.
119
+ */
120
+ export declare const transpileCache: TranspileCache;
121
+ /**
122
+ * Render cache for full HTML output.
123
+ * Uses shorter TTL since outputs depend on input/output data.
124
+ */
125
+ export declare const renderCache: TranspileCache;
126
+ /**
127
+ * Simple LRU cache for storing any type of values.
128
+ * Used for caching compiled components (React/MDX).
129
+ */
130
+ export declare class ComponentCache<T = unknown> {
131
+ private cache;
132
+ private readonly maxSize;
133
+ constructor(maxSize?: number);
134
+ get(key: string): T | undefined;
135
+ set(key: string, value: T): void;
136
+ has(key: string): boolean;
137
+ delete(key: string): boolean;
138
+ clear(): void;
139
+ get size(): number;
140
+ }
141
+ /**
142
+ * Global component cache for storing compiled React/MDX components.
143
+ */
144
+ export declare const componentCache: ComponentCache<unknown>;
@@ -0,0 +1,240 @@
1
+ "use strict";
2
+ /**
3
+ * LRU Cache for Renderer Transpilation Results
4
+ *
5
+ * Provides fast, memory-bounded caching for transpiled templates.
6
+ * Uses content-addressable keys (hash of source) for deduplication.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.componentCache = exports.ComponentCache = exports.renderCache = exports.transpileCache = exports.TranspileCache = void 0;
10
+ const hash_1 = require("./utils/hash");
11
+ /**
12
+ * LRU Cache for transpiled template results.
13
+ *
14
+ * Features:
15
+ * - Content-addressable keys via hash
16
+ * - LRU eviction when max size reached
17
+ * - Optional TTL for time-based expiration
18
+ * - Access statistics
19
+ *
20
+ * @example
21
+ * ```typescript
22
+ * const cache = new TranspileCache({ maxSize: 500 });
23
+ *
24
+ * // Store a transpiled result
25
+ * const hash = cache.set(sourceCode, transpileResult);
26
+ *
27
+ * // Retrieve it later
28
+ * const result = cache.get(sourceCode);
29
+ * if (result) {
30
+ * console.log('Cache hit!', result.code);
31
+ * }
32
+ * ```
33
+ */
34
+ class TranspileCache {
35
+ cache = new Map();
36
+ maxSize;
37
+ ttl;
38
+ /** Cache statistics */
39
+ stats = {
40
+ hits: 0,
41
+ misses: 0,
42
+ evictions: 0,
43
+ };
44
+ constructor(options = {}) {
45
+ this.maxSize = options.maxSize ?? 500;
46
+ this.ttl = options.ttl ?? 0; // 0 = infinite TTL
47
+ }
48
+ /**
49
+ * Get a cached transpile result by source content.
50
+ *
51
+ * @param source - Source code to look up
52
+ * @returns Cached result or undefined if not found/expired
53
+ */
54
+ get(source) {
55
+ const key = (0, hash_1.hashString)(source);
56
+ return this.getByKey(key);
57
+ }
58
+ /**
59
+ * Get a cached transpile result by hash key.
60
+ *
61
+ * @param key - Hash key
62
+ * @returns Cached result or undefined if not found/expired
63
+ */
64
+ getByKey(key) {
65
+ const entry = this.cache.get(key);
66
+ if (!entry) {
67
+ this.stats.misses++;
68
+ return undefined;
69
+ }
70
+ // Check TTL expiration
71
+ if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {
72
+ this.cache.delete(key);
73
+ this.stats.misses++;
74
+ return undefined;
75
+ }
76
+ // Move to end for LRU (delete and re-add)
77
+ this.cache.delete(key);
78
+ entry.accessCount++;
79
+ this.cache.set(key, entry);
80
+ this.stats.hits++;
81
+ return entry.value;
82
+ }
83
+ /**
84
+ * Store a transpile result.
85
+ *
86
+ * @param source - Source code (used to generate key)
87
+ * @param value - Transpile result to cache
88
+ * @returns The hash key used for storage
89
+ */
90
+ set(source, value) {
91
+ const key = (0, hash_1.hashString)(source);
92
+ this.setByKey(key, value);
93
+ return key;
94
+ }
95
+ /**
96
+ * Store a transpile result by hash key.
97
+ *
98
+ * @param key - Hash key
99
+ * @param value - Transpile result to cache
100
+ */
101
+ setByKey(key, value) {
102
+ // Enforce size limit with LRU eviction
103
+ if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
104
+ // Remove oldest entry (first in Map iteration order)
105
+ const oldestKey = this.cache.keys().next().value;
106
+ if (oldestKey) {
107
+ this.cache.delete(oldestKey);
108
+ this.stats.evictions++;
109
+ }
110
+ }
111
+ this.cache.set(key, {
112
+ value,
113
+ timestamp: Date.now(),
114
+ accessCount: 1,
115
+ });
116
+ }
117
+ /**
118
+ * Check if a source is cached.
119
+ *
120
+ * @param source - Source code to check
121
+ * @returns True if cached and not expired
122
+ */
123
+ has(source) {
124
+ const key = (0, hash_1.hashString)(source);
125
+ return this.hasByKey(key);
126
+ }
127
+ /**
128
+ * Check if a key is cached.
129
+ *
130
+ * @param key - Hash key to check
131
+ * @returns True if cached and not expired
132
+ */
133
+ hasByKey(key) {
134
+ const entry = this.cache.get(key);
135
+ if (!entry)
136
+ return false;
137
+ // Check TTL
138
+ if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {
139
+ this.cache.delete(key);
140
+ return false;
141
+ }
142
+ return true;
143
+ }
144
+ /**
145
+ * Delete a cached entry by source.
146
+ *
147
+ * @param source - Source code to delete
148
+ * @returns True if entry was deleted
149
+ */
150
+ delete(source) {
151
+ const key = (0, hash_1.hashString)(source);
152
+ return this.cache.delete(key);
153
+ }
154
+ /**
155
+ * Clear all cached entries.
156
+ */
157
+ clear() {
158
+ this.cache.clear();
159
+ this.stats = { hits: 0, misses: 0, evictions: 0 };
160
+ }
161
+ /**
162
+ * Get current cache size.
163
+ */
164
+ get size() {
165
+ return this.cache.size;
166
+ }
167
+ /**
168
+ * Get cache statistics.
169
+ */
170
+ getStats() {
171
+ const total = this.stats.hits + this.stats.misses;
172
+ return {
173
+ ...this.stats,
174
+ size: this.cache.size,
175
+ hitRate: total > 0 ? this.stats.hits / total : 0,
176
+ };
177
+ }
178
+ }
179
+ exports.TranspileCache = TranspileCache;
180
+ /**
181
+ * Global transpile cache instance.
182
+ * Shared across all renderers for deduplication.
183
+ */
184
+ exports.transpileCache = new TranspileCache({ maxSize: 500 });
185
+ /**
186
+ * Render cache for full HTML output.
187
+ * Uses shorter TTL since outputs depend on input/output data.
188
+ */
189
+ exports.renderCache = new TranspileCache({
190
+ maxSize: 1000,
191
+ ttl: 5 * 60 * 1000, // 5 minutes
192
+ });
193
+ /**
194
+ * Simple LRU cache for storing any type of values.
195
+ * Used for caching compiled components (React/MDX).
196
+ */
197
+ class ComponentCache {
198
+ cache = new Map();
199
+ maxSize;
200
+ constructor(maxSize = 200) {
201
+ this.maxSize = maxSize;
202
+ }
203
+ get(key) {
204
+ const entry = this.cache.get(key);
205
+ if (!entry)
206
+ return undefined;
207
+ // Move to end for LRU
208
+ this.cache.delete(key);
209
+ this.cache.set(key, entry);
210
+ return entry.value;
211
+ }
212
+ set(key, value) {
213
+ // Enforce size limit with LRU eviction
214
+ if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
215
+ const oldestKey = this.cache.keys().next().value;
216
+ if (oldestKey) {
217
+ this.cache.delete(oldestKey);
218
+ }
219
+ }
220
+ this.cache.set(key, { value, timestamp: Date.now() });
221
+ }
222
+ has(key) {
223
+ return this.cache.has(key);
224
+ }
225
+ delete(key) {
226
+ return this.cache.delete(key);
227
+ }
228
+ clear() {
229
+ this.cache.clear();
230
+ }
231
+ get size() {
232
+ return this.cache.size;
233
+ }
234
+ }
235
+ exports.ComponentCache = ComponentCache;
236
+ /**
237
+ * Global component cache for storing compiled React/MDX components.
238
+ */
239
+ exports.componentCache = new ComponentCache();
240
+ //# sourceMappingURL=cache.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cache.js","sourceRoot":"","sources":["../../../src/renderers/cache.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;AAEH,uCAA0C;AAyB1C;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAa,cAAc;IACjB,KAAK,GAAG,IAAI,GAAG,EAAuC,CAAC;IAC9C,OAAO,CAAS;IAChB,GAAG,CAAS;IAE7B,uBAAuB;IACf,KAAK,GAAG;QACd,IAAI,EAAE,CAAC;QACP,MAAM,EAAE,CAAC;QACT,SAAS,EAAE,CAAC;KACb,CAAC;IAEF,YAAY,UAAiC,EAAE;QAC7C,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,IAAI,GAAG,CAAC;QACtC,IAAI,CAAC,GAAG,GAAG,OAAO,CAAC,GAAG,IAAI,CAAC,CAAC,CAAC,mBAAmB;IAClD,CAAC;IAED;;;;;OAKG;IACH,GAAG,CAAC,MAAc;QAChB,MAAM,GAAG,GAAG,IAAA,iBAAU,EAAC,MAAM,CAAC,CAAC;QAC/B,OAAO,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC;IAED;;;;;OAKG;IACH,QAAQ,CAAC,GAAW;QAClB,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QAElC,IAAI,CAAC,KAAK,EAAE,CAAC;YACX,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;YACpB,OAAO,SAAS,CAAC;QACnB,CAAC;QAED,uBAAuB;QACvB,IAAI,IAAI,CAAC,GAAG,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,CAAC,SAAS,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;YAC5D,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;YACvB,IAAI,CAAC,KAA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AAK,CAAC;YACjD,IAAI,SAAS,EAAE,CAAC;gBACd,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;YAC/B,CAAC;QACH,CAAC;QAED,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC;IACxD,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;IAC7B,CAAC;IAED,MAAM,CAAC,GAAW;QAChB,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAChC,CAAC;IAED,KAAK;QACH,IAAI,CAAC,KAAK,CAAC,KAAK,EAAE,CAAC;IACrB,CAAC;IAED,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC;IACzB,CAAC;CACF;AA7CD,wCA6CC;AAED;;GAEG;AACU,QAAA,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC","sourcesContent":["/**\n * LRU Cache for Renderer Transpilation Results\n *\n * Provides fast, memory-bounded caching for transpiled templates.\n * Uses content-addressable keys (hash of source) for deduplication.\n */\n\nimport { hashString } from './utils/hash';\nimport type { TranspileResult } from './types';\n\n/**\n * Cache entry with metadata.\n */\ninterface CacheEntry<T> {\n /** Cached value */\n value: T;\n /** Timestamp when entry was created */\n timestamp: number;\n /** Number of times this entry was accessed */\n accessCount: number;\n}\n\n/**\n * Options for the transpile cache.\n */\nexport interface TranspileCacheOptions {\n /** Maximum number of entries (default: 500) */\n maxSize?: number;\n /** TTL in milliseconds, 0 = infinite (default: 0 for transpile cache) */\n ttl?: number;\n}\n\n/**\n * LRU Cache for transpiled template results.\n *\n * Features:\n * - Content-addressable keys via hash\n * - LRU eviction when max size reached\n * - Optional TTL for time-based expiration\n * - Access statistics\n *\n * @example\n * ```typescript\n * const cache = new TranspileCache({ maxSize: 500 });\n *\n * // Store a transpiled result\n * const hash = cache.set(sourceCode, transpileResult);\n *\n * // Retrieve it later\n * const result = cache.get(sourceCode);\n * if (result) {\n * console.log('Cache hit!', result.code);\n * }\n * ```\n */\nexport class TranspileCache {\n private cache = new Map<string, CacheEntry<TranspileResult>>();\n private readonly maxSize: number;\n private readonly ttl: number;\n\n /** Cache statistics */\n private stats = {\n hits: 0,\n misses: 0,\n evictions: 0,\n };\n\n constructor(options: TranspileCacheOptions = {}) {\n this.maxSize = options.maxSize ?? 500;\n this.ttl = options.ttl ?? 0; // 0 = infinite TTL\n }\n\n /**\n * Get a cached transpile result by source content.\n *\n * @param source - Source code to look up\n * @returns Cached result or undefined if not found/expired\n */\n get(source: string): TranspileResult | undefined {\n const key = hashString(source);\n return this.getByKey(key);\n }\n\n /**\n * Get a cached transpile result by hash key.\n *\n * @param key - Hash key\n * @returns Cached result or undefined if not found/expired\n */\n getByKey(key: string): TranspileResult | undefined {\n const entry = this.cache.get(key);\n\n if (!entry) {\n this.stats.misses++;\n return undefined;\n }\n\n // Check TTL expiration\n if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {\n this.cache.delete(key);\n this.stats.misses++;\n return undefined;\n }\n\n // Move to end for LRU (delete and re-add)\n this.cache.delete(key);\n entry.accessCount++;\n this.cache.set(key, entry);\n\n this.stats.hits++;\n return entry.value;\n }\n\n /**\n * Store a transpile result.\n *\n * @param source - Source code (used to generate key)\n * @param value - Transpile result to cache\n * @returns The hash key used for storage\n */\n set(source: string, value: TranspileResult): string {\n const key = hashString(source);\n this.setByKey(key, value);\n return key;\n }\n\n /**\n * Store a transpile result by hash key.\n *\n * @param key - Hash key\n * @param value - Transpile result to cache\n */\n setByKey(key: string, value: TranspileResult): void {\n // Enforce size limit with LRU eviction\n if (this.cache.size >= this.maxSize && !this.cache.has(key)) {\n // Remove oldest entry (first in Map iteration order)\n const oldestKey = this.cache.keys().next().value;\n if (oldestKey) {\n this.cache.delete(oldestKey);\n this.stats.evictions++;\n }\n }\n\n this.cache.set(key, {\n value,\n timestamp: Date.now(),\n accessCount: 1,\n });\n }\n\n /**\n * Check if a source is cached.\n *\n * @param source - Source code to check\n * @returns True if cached and not expired\n */\n has(source: string): boolean {\n const key = hashString(source);\n return this.hasByKey(key);\n }\n\n /**\n * Check if a key is cached.\n *\n * @param key - Hash key to check\n * @returns True if cached and not expired\n */\n hasByKey(key: string): boolean {\n const entry = this.cache.get(key);\n if (!entry) return false;\n\n // Check TTL\n if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {\n this.cache.delete(key);\n return false;\n }\n\n return true;\n }\n\n /**\n * Delete a cached entry by source.\n *\n * @param source - Source code to delete\n * @returns True if entry was deleted\n */\n delete(source: string): boolean {\n const key = hashString(source);\n return this.cache.delete(key);\n }\n\n /**\n * Clear all cached entries.\n */\n clear(): void {\n this.cache.clear();\n this.stats = { hits: 0, misses: 0, evictions: 0 };\n }\n\n /**\n * Get current cache size.\n */\n get size(): number {\n return this.cache.size;\n }\n\n /**\n * Get cache statistics.\n */\n getStats(): { hits: number; misses: number; evictions: number; size: number; hitRate: number } {\n const total = this.stats.hits + this.stats.misses;\n return {\n ...this.stats,\n size: this.cache.size,\n hitRate: total > 0 ? this.stats.hits / total : 0,\n };\n }\n}\n\n/**\n * Global transpile cache instance.\n * Shared across all renderers for deduplication.\n */\nexport const transpileCache = new TranspileCache({ maxSize: 500 });\n\n/**\n * Render cache for full HTML output.\n * Uses shorter TTL since outputs depend on input/output data.\n */\nexport const renderCache = new TranspileCache({\n maxSize: 1000,\n ttl: 5 * 60 * 1000, // 5 minutes\n});\n\n/**\n * Simple LRU cache for storing any type of values.\n * Used for caching compiled components (React/MDX).\n */\nexport class ComponentCache<T = unknown> {\n private cache = new Map<string, { value: T; timestamp: number }>();\n private readonly maxSize: number;\n\n constructor(maxSize = 200) {\n this.maxSize = maxSize;\n }\n\n get(key: string): T | undefined {\n const entry = this.cache.get(key);\n if (!entry) return undefined;\n\n // Move to end for LRU\n this.cache.delete(key);\n this.cache.set(key, entry);\n return entry.value;\n }\n\n set(key: string, value: T): void {\n // Enforce size limit with LRU eviction\n if (this.cache.size >= this.maxSize && !this.cache.has(key)) {\n const oldestKey = this.cache.keys().next().value;\n if (oldestKey) {\n this.cache.delete(oldestKey);\n }\n }\n\n this.cache.set(key, { value, timestamp: Date.now() });\n }\n\n has(key: string): boolean {\n return this.cache.has(key);\n }\n\n delete(key: string): boolean {\n return this.cache.delete(key);\n }\n\n clear(): void {\n this.cache.clear();\n }\n\n get size(): number {\n return this.cache.size;\n }\n}\n\n/**\n * Global component cache for storing compiled React/MDX components.\n */\nexport const componentCache = new ComponentCache();\n"]}