@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,85 @@
1
+ /**
2
+ * @file attribute-parser.ts
3
+ * @description Attribute parsing utilities for FrontMCP Web Components.
4
+ *
5
+ * Converts HTML attributes to typed options for component rendering.
6
+ * Handles boolean attributes, HTMX attributes, and kebab-to-camel case conversion.
7
+ *
8
+ * @example Attribute parsing
9
+ * ```typescript
10
+ * // variant="primary" -> { variant: 'primary' }
11
+ * // disabled -> { disabled: true }
12
+ * // disabled="false" -> { disabled: false }
13
+ * // hx-get="/api" -> { htmx: { get: '/api' } }
14
+ * ```
15
+ *
16
+ * @module @frontmcp/ui/web-components/core/attribute-parser
17
+ */
18
+ import type { ZodSchema } from 'zod';
19
+ /**
20
+ * Result of parsing an attribute value
21
+ */
22
+ export interface ParsedAttribute {
23
+ /** The option key (camelCase) */
24
+ key: string | null;
25
+ /** The parsed value */
26
+ value: unknown;
27
+ /** Whether this is a nested htmx option */
28
+ isHtmx?: boolean;
29
+ /** Whether this is a data attribute */
30
+ isData?: boolean;
31
+ }
32
+ /**
33
+ * Parse an HTML attribute into a typed option value.
34
+ *
35
+ * Attribute naming conventions:
36
+ * - Simple: `variant="primary"` -> `{ variant: 'primary' }`
37
+ * - Boolean: `disabled` -> `{ disabled: true }`
38
+ * - Boolean false: `disabled="false"` -> `{ disabled: false }`
39
+ * - HTMX: `hx-get="/api"` -> `{ htmx: { get: '/api' } }`
40
+ * - Data: `data-foo="bar"` -> `{ data: { foo: 'bar' } }`
41
+ *
42
+ * @param attrName - The attribute name (kebab-case)
43
+ * @param value - The attribute value (null for boolean attributes)
44
+ * @returns Parsed attribute with key and typed value
45
+ */
46
+ export declare function parseAttributeValue(attrName: string, value: string | null): ParsedAttribute;
47
+ /**
48
+ * Convert kebab-case to camelCase.
49
+ *
50
+ * @param str - Kebab-case string
51
+ * @returns camelCase string
52
+ *
53
+ * @example
54
+ * kebabToCamel('full-width') // 'fullWidth'
55
+ * kebabToCamel('icon-before') // 'iconBefore'
56
+ */
57
+ export declare function kebabToCamel(str: string): string;
58
+ /**
59
+ * Convert camelCase to kebab-case.
60
+ *
61
+ * @param str - camelCase string
62
+ * @returns kebab-case string
63
+ *
64
+ * @example
65
+ * camelToKebab('fullWidth') // 'full-width'
66
+ * camelToKebab('iconBefore') // 'icon-before'
67
+ */
68
+ export declare function camelToKebab(str: string): string;
69
+ /**
70
+ * Extract observable attribute names from a Zod schema.
71
+ *
72
+ * @param schema - Zod schema to extract keys from
73
+ * @returns Array of kebab-case attribute names
74
+ */
75
+ export declare function getObservedAttributesFromSchema<T>(schema: ZodSchema<T>): string[];
76
+ /**
77
+ * Merge a parsed attribute into an options object.
78
+ *
79
+ * Handles nested objects for htmx and data attributes.
80
+ *
81
+ * @param options - Current options object
82
+ * @param parsed - Parsed attribute result
83
+ * @returns Updated options object
84
+ */
85
+ export declare function mergeAttributeIntoOptions<T>(options: Partial<T>, parsed: ParsedAttribute): Partial<T>;
@@ -0,0 +1,189 @@
1
+ "use strict";
2
+ /**
3
+ * @file attribute-parser.ts
4
+ * @description Attribute parsing utilities for FrontMCP Web Components.
5
+ *
6
+ * Converts HTML attributes to typed options for component rendering.
7
+ * Handles boolean attributes, HTMX attributes, and kebab-to-camel case conversion.
8
+ *
9
+ * @example Attribute parsing
10
+ * ```typescript
11
+ * // variant="primary" -> { variant: 'primary' }
12
+ * // disabled -> { disabled: true }
13
+ * // disabled="false" -> { disabled: false }
14
+ * // hx-get="/api" -> { htmx: { get: '/api' } }
15
+ * ```
16
+ *
17
+ * @module @frontmcp/ui/web-components/core/attribute-parser
18
+ */
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.parseAttributeValue = parseAttributeValue;
21
+ exports.kebabToCamel = kebabToCamel;
22
+ exports.camelToKebab = camelToKebab;
23
+ exports.getObservedAttributesFromSchema = getObservedAttributesFromSchema;
24
+ exports.mergeAttributeIntoOptions = mergeAttributeIntoOptions;
25
+ /**
26
+ * Parse an HTML attribute into a typed option value.
27
+ *
28
+ * Attribute naming conventions:
29
+ * - Simple: `variant="primary"` -> `{ variant: 'primary' }`
30
+ * - Boolean: `disabled` -> `{ disabled: true }`
31
+ * - Boolean false: `disabled="false"` -> `{ disabled: false }`
32
+ * - HTMX: `hx-get="/api"` -> `{ htmx: { get: '/api' } }`
33
+ * - Data: `data-foo="bar"` -> `{ data: { foo: 'bar' } }`
34
+ *
35
+ * @param attrName - The attribute name (kebab-case)
36
+ * @param value - The attribute value (null for boolean attributes)
37
+ * @returns Parsed attribute with key and typed value
38
+ */
39
+ function parseAttributeValue(attrName, value) {
40
+ // Skip internal fmcp attributes
41
+ if (attrName.startsWith('data-fmcp-')) {
42
+ return { key: null, value: undefined };
43
+ }
44
+ // Handle HTMX attributes (hx-* -> htmx.*)
45
+ if (attrName.startsWith('hx-')) {
46
+ const htmxKey = attrName.slice(3); // Remove 'hx-'
47
+ return {
48
+ key: htmxKey,
49
+ value: value ?? '',
50
+ isHtmx: true,
51
+ };
52
+ }
53
+ // Handle data attributes (data-* -> data.*)
54
+ if (attrName.startsWith('data-')) {
55
+ const dataKey = attrName.slice(5); // Remove 'data-'
56
+ return {
57
+ key: dataKey,
58
+ value: value ?? '',
59
+ isData: true,
60
+ };
61
+ }
62
+ // Convert kebab-case to camelCase
63
+ const camelName = kebabToCamel(attrName);
64
+ // Handle boolean attributes (presence = true)
65
+ if (value === null || value === '') {
66
+ return { key: camelName, value: true };
67
+ }
68
+ // Handle explicit boolean strings
69
+ if (value === 'true') {
70
+ return { key: camelName, value: true };
71
+ }
72
+ if (value === 'false') {
73
+ return { key: camelName, value: false };
74
+ }
75
+ // Handle numeric values
76
+ const numValue = Number(value);
77
+ if (!isNaN(numValue) && value.trim() !== '') {
78
+ return { key: camelName, value: numValue };
79
+ }
80
+ // Handle JSON values (for complex objects)
81
+ if (value.startsWith('{') || value.startsWith('[')) {
82
+ try {
83
+ return { key: camelName, value: JSON.parse(value) };
84
+ }
85
+ catch {
86
+ // Not valid JSON, treat as string
87
+ }
88
+ }
89
+ // Default: string value
90
+ return { key: camelName, value };
91
+ }
92
+ /**
93
+ * Convert kebab-case to camelCase.
94
+ *
95
+ * @param str - Kebab-case string
96
+ * @returns camelCase string
97
+ *
98
+ * @example
99
+ * kebabToCamel('full-width') // 'fullWidth'
100
+ * kebabToCamel('icon-before') // 'iconBefore'
101
+ */
102
+ function kebabToCamel(str) {
103
+ return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());
104
+ }
105
+ /**
106
+ * Convert camelCase to kebab-case.
107
+ *
108
+ * @param str - camelCase string
109
+ * @returns kebab-case string
110
+ *
111
+ * @example
112
+ * camelToKebab('fullWidth') // 'full-width'
113
+ * camelToKebab('iconBefore') // 'icon-before'
114
+ */
115
+ function camelToKebab(str) {
116
+ return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);
117
+ }
118
+ /**
119
+ * Extract observable attribute names from a Zod schema.
120
+ *
121
+ * @param schema - Zod schema to extract keys from
122
+ * @returns Array of kebab-case attribute names
123
+ */
124
+ function getObservedAttributesFromSchema(schema) {
125
+ const attributes = [];
126
+ // Extract keys from schema shape (Zod object schemas have a shape property)
127
+ const schemaAny = schema;
128
+ if (schemaAny.shape) {
129
+ for (const key of Object.keys(schemaAny.shape)) {
130
+ // Convert camelCase keys to kebab-case attributes
131
+ attributes.push(camelToKebab(key));
132
+ }
133
+ }
134
+ // Always include common attributes
135
+ const commonAttrs = ['class', 'id', 'style'];
136
+ attributes.push(...commonAttrs);
137
+ // Include HTMX attributes
138
+ const htmxAttrs = [
139
+ 'hx-get',
140
+ 'hx-post',
141
+ 'hx-put',
142
+ 'hx-delete',
143
+ 'hx-patch',
144
+ 'hx-target',
145
+ 'hx-swap',
146
+ 'hx-trigger',
147
+ 'hx-confirm',
148
+ 'hx-indicator',
149
+ 'hx-push-url',
150
+ 'hx-select',
151
+ 'hx-vals',
152
+ ];
153
+ attributes.push(...htmxAttrs);
154
+ // Deduplicate
155
+ return [...new Set(attributes)];
156
+ }
157
+ /**
158
+ * Merge a parsed attribute into an options object.
159
+ *
160
+ * Handles nested objects for htmx and data attributes.
161
+ *
162
+ * @param options - Current options object
163
+ * @param parsed - Parsed attribute result
164
+ * @returns Updated options object
165
+ */
166
+ function mergeAttributeIntoOptions(options, parsed) {
167
+ if (parsed.key === null || parsed.value === undefined) {
168
+ return options;
169
+ }
170
+ const result = { ...options };
171
+ if (parsed.isHtmx) {
172
+ // Merge into htmx nested object
173
+ const htmx = result['htmx'] ?? {};
174
+ htmx[parsed.key] = parsed.value;
175
+ result['htmx'] = htmx;
176
+ }
177
+ else if (parsed.isData) {
178
+ // Merge into data nested object
179
+ const data = result['data'] ?? {};
180
+ data[parsed.key] = String(parsed.value);
181
+ result['data'] = data;
182
+ }
183
+ else {
184
+ // Direct assignment
185
+ result[parsed.key] = parsed.value;
186
+ }
187
+ return result;
188
+ }
189
+ //# sourceMappingURL=attribute-parser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"attribute-parser.js","sourceRoot":"","sources":["../../../../src/web-components/core/attribute-parser.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;GAgBG;;AAgCH,kDA2DC;AAYD,oCAEC;AAYD,oCAEC;AAQD,0EAoCC;AAWD,8DAuBC;AAnLD;;;;;;;;;;;;;GAaG;AACH,SAAgB,mBAAmB,CAAC,QAAgB,EAAE,KAAoB;IACxE,gCAAgC;IAChC,IAAI,QAAQ,CAAC,UAAU,CAAC,YAAY,CAA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AAC,GAAG,MAAM,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;QACxC,MAAM,CAAC,MAAM,CAAC,GAAG,IAAI,CAAC;IACxB,CAAC;SAAM,CAAC;QACN,oBAAoB;QACpB,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC;IACpC,CAAC;IAED,OAAO,MAAoB,CAAC;AAC9B,CAAC","sourcesContent":["/**\n * @file attribute-parser.ts\n * @description Attribute parsing utilities for FrontMCP Web Components.\n *\n * Converts HTML attributes to typed options for component rendering.\n * Handles boolean attributes, HTMX attributes, and kebab-to-camel case conversion.\n *\n * @example Attribute parsing\n * ```typescript\n * // variant=\"primary\" -> { variant: 'primary' }\n * // disabled -> { disabled: true }\n * // disabled=\"false\" -> { disabled: false }\n * // hx-get=\"/api\" -> { htmx: { get: '/api' } }\n * ```\n *\n * @module @frontmcp/ui/web-components/core/attribute-parser\n */\n\nimport type { ZodSchema } from 'zod';\n\n/**\n * Result of parsing an attribute value\n */\nexport interface ParsedAttribute {\n /** The option key (camelCase) */\n key: string | null;\n /** The parsed value */\n value: unknown;\n /** Whether this is a nested htmx option */\n isHtmx?: boolean;\n /** Whether this is a data attribute */\n isData?: boolean;\n}\n\n/**\n * Parse an HTML attribute into a typed option value.\n *\n * Attribute naming conventions:\n * - Simple: `variant=\"primary\"` -> `{ variant: 'primary' }`\n * - Boolean: `disabled` -> `{ disabled: true }`\n * - Boolean false: `disabled=\"false\"` -> `{ disabled: false }`\n * - HTMX: `hx-get=\"/api\"` -> `{ htmx: { get: '/api' } }`\n * - Data: `data-foo=\"bar\"` -> `{ data: { foo: 'bar' } }`\n *\n * @param attrName - The attribute name (kebab-case)\n * @param value - The attribute value (null for boolean attributes)\n * @returns Parsed attribute with key and typed value\n */\nexport function parseAttributeValue(attrName: string, value: string | null): ParsedAttribute {\n // Skip internal fmcp attributes\n if (attrName.startsWith('data-fmcp-')) {\n return { key: null, value: undefined };\n }\n\n // Handle HTMX attributes (hx-* -> htmx.*)\n if (attrName.startsWith('hx-')) {\n const htmxKey = attrName.slice(3); // Remove 'hx-'\n return {\n key: htmxKey,\n value: value ?? '',\n isHtmx: true,\n };\n }\n\n // Handle data attributes (data-* -> data.*)\n if (attrName.startsWith('data-')) {\n const dataKey = attrName.slice(5); // Remove 'data-'\n return {\n key: dataKey,\n value: value ?? '',\n isData: true,\n };\n }\n\n // Convert kebab-case to camelCase\n const camelName = kebabToCamel(attrName);\n\n // Handle boolean attributes (presence = true)\n if (value === null || value === '') {\n return { key: camelName, value: true };\n }\n\n // Handle explicit boolean strings\n if (value === 'true') {\n return { key: camelName, value: true };\n }\n if (value === 'false') {\n return { key: camelName, value: false };\n }\n\n // Handle numeric values\n const numValue = Number(value);\n if (!isNaN(numValue) && value.trim() !== '') {\n return { key: camelName, value: numValue };\n }\n\n // Handle JSON values (for complex objects)\n if (value.startsWith('{') || value.startsWith('[')) {\n try {\n return { key: camelName, value: JSON.parse(value) };\n } catch {\n // Not valid JSON, treat as string\n }\n }\n\n // Default: string value\n return { key: camelName, value };\n}\n\n/**\n * Convert kebab-case to camelCase.\n *\n * @param str - Kebab-case string\n * @returns camelCase string\n *\n * @example\n * kebabToCamel('full-width') // 'fullWidth'\n * kebabToCamel('icon-before') // 'iconBefore'\n */\nexport function kebabToCamel(str: string): string {\n return str.replace(/-([a-z])/g, (_, letter) => letter.toUpperCase());\n}\n\n/**\n * Convert camelCase to kebab-case.\n *\n * @param str - camelCase string\n * @returns kebab-case string\n *\n * @example\n * camelToKebab('fullWidth') // 'full-width'\n * camelToKebab('iconBefore') // 'icon-before'\n */\nexport function camelToKebab(str: string): string {\n return str.replace(/[A-Z]/g, (letter) => `-${letter.toLowerCase()}`);\n}\n\n/**\n * Extract observable attribute names from a Zod schema.\n *\n * @param schema - Zod schema to extract keys from\n * @returns Array of kebab-case attribute names\n */\nexport function getObservedAttributesFromSchema<T>(schema: ZodSchema<T>): string[] {\n const attributes: string[] = [];\n\n // Extract keys from schema shape (Zod object schemas have a shape property)\n const schemaAny = schema as { shape?: Record<string, unknown> };\n if (schemaAny.shape) {\n for (const key of Object.keys(schemaAny.shape)) {\n // Convert camelCase keys to kebab-case attributes\n attributes.push(camelToKebab(key));\n }\n }\n\n // Always include common attributes\n const commonAttrs = ['class', 'id', 'style'];\n attributes.push(...commonAttrs);\n\n // Include HTMX attributes\n const htmxAttrs = [\n 'hx-get',\n 'hx-post',\n 'hx-put',\n 'hx-delete',\n 'hx-patch',\n 'hx-target',\n 'hx-swap',\n 'hx-trigger',\n 'hx-confirm',\n 'hx-indicator',\n 'hx-push-url',\n 'hx-select',\n 'hx-vals',\n ];\n attributes.push(...htmxAttrs);\n\n // Deduplicate\n return [...new Set(attributes)];\n}\n\n/**\n * Merge a parsed attribute into an options object.\n *\n * Handles nested objects for htmx and data attributes.\n *\n * @param options - Current options object\n * @param parsed - Parsed attribute result\n * @returns Updated options object\n */\nexport function mergeAttributeIntoOptions<T>(options: Partial<T>, parsed: ParsedAttribute): Partial<T> {\n if (parsed.key === null || parsed.value === undefined) {\n return options;\n }\n\n const result = { ...options } as Record<string, unknown>;\n\n if (parsed.isHtmx) {\n // Merge into htmx nested object\n const htmx = (result['htmx'] as Record<string, unknown>) ?? {};\n htmx[parsed.key] = parsed.value;\n result['htmx'] = htmx;\n } else if (parsed.isData) {\n // Merge into data nested object\n const data = (result['data'] as Record<string, string>) ?? {};\n data[parsed.key] = String(parsed.value);\n result['data'] = data;\n } else {\n // Direct assignment\n result[parsed.key] = parsed.value;\n }\n\n return result as Partial<T>;\n}\n"]}
@@ -0,0 +1,197 @@
1
+ /**
2
+ * @file base-element.ts
3
+ * @description Base class for all FrontMCP Web Components.
4
+ *
5
+ * Provides a foundation for creating Custom Elements with:
6
+ * - Zod schema validation
7
+ * - Attribute-to-option mapping
8
+ * - Property setters for React/Vue compatibility
9
+ * - Batched rendering via queueMicrotask
10
+ * - Light DOM (no Shadow DOM) for Tailwind compatibility
11
+ *
12
+ * @example Creating a custom element
13
+ * ```typescript
14
+ * import { FmcpElement } from '@frontmcp/ui/web-components';
15
+ * import { ButtonOptionsSchema, type ButtonOptions } from '@frontmcp/ui/components';
16
+ * import { button } from '@frontmcp/ui/components';
17
+ *
18
+ * class FmcpButton extends FmcpElement<ButtonOptions> {
19
+ * protected readonly config = {
20
+ * name: 'button',
21
+ * schema: ButtonOptionsSchema,
22
+ * defaults: { variant: 'primary', size: 'md' },
23
+ * };
24
+ *
25
+ * static get observedAttributes() {
26
+ * return getObservedAttributesFromSchema(ButtonOptionsSchema);
27
+ * }
28
+ *
29
+ * protected renderHtml(options: ButtonOptions, content: string): string {
30
+ * return button(content, options);
31
+ * }
32
+ * }
33
+ *
34
+ * customElements.define('fmcp-button', FmcpButton);
35
+ * ```
36
+ *
37
+ * @module @frontmcp/ui/web-components/core/base-element
38
+ */
39
+ import type { ZodSchema } from 'zod';
40
+ declare const HTMLElementBase: {
41
+ new (): HTMLElement;
42
+ prototype: HTMLElement;
43
+ };
44
+ /**
45
+ * Configuration for FmcpElement subclasses
46
+ */
47
+ export interface FmcpElementConfig<TOptions> {
48
+ /** Component name (used in error messages) */
49
+ name: string;
50
+ /** Zod schema for validation */
51
+ schema: ZodSchema<TOptions>;
52
+ /** Default option values */
53
+ defaults?: Partial<TOptions>;
54
+ }
55
+ /**
56
+ * Custom event detail for fmcp:render event
57
+ */
58
+ export interface FmcpRenderEventDetail<TOptions = unknown> {
59
+ options: TOptions;
60
+ }
61
+ /**
62
+ * Base class for all FrontMCP Web Components.
63
+ *
64
+ * Key features:
65
+ * - **Light DOM**: Renders directly to innerHTML (no Shadow DOM)
66
+ * - **Attribute Parsing**: Converts HTML attributes to typed options
67
+ * - **Property Setters**: React/Vue can set properties directly
68
+ * - **Zod Validation**: Invalid options render error box
69
+ * - **Batched Rendering**: Multiple changes batch via queueMicrotask
70
+ * - **HTMX Support**: hx-* attributes pass through to inner elements
71
+ *
72
+ * @typeParam TOptions - The component's options type (from Zod schema)
73
+ *
74
+ * @example Usage in HTML
75
+ * ```html
76
+ * <fmcp-button variant="primary" disabled>
77
+ * Click Me
78
+ * </fmcp-button>
79
+ * ```
80
+ *
81
+ * @example Usage in React
82
+ * ```tsx
83
+ * <fmcp-button
84
+ * variant="primary"
85
+ * onClick={handleClick}
86
+ * >
87
+ * Click Me
88
+ * </fmcp-button>
89
+ * ```
90
+ */
91
+ export declare abstract class FmcpElement<TOptions> extends HTMLElementBase {
92
+ /**
93
+ * Configuration provided by subclass.
94
+ * Must include component name, Zod schema, and optional defaults.
95
+ */
96
+ protected abstract readonly config: FmcpElementConfig<TOptions>;
97
+ /** Internal options state */
98
+ protected _options: Partial<TOptions>;
99
+ /** Content passed as children (captured on connect) */
100
+ protected _content: string;
101
+ /** Whether component has been connected to DOM */
102
+ private _connected;
103
+ /** Whether a render is pending (for batching) */
104
+ private _pendingRender;
105
+ /** Whether initial render has completed */
106
+ private _initialRenderComplete;
107
+ /**
108
+ * Called when element is added to DOM.
109
+ * Captures content, parses attributes, and renders.
110
+ *
111
+ * Supports SSR hydration via `data-ssr` attribute:
112
+ * - If `data-ssr` is present, content was pre-rendered by server
113
+ * - Web component adopts existing content without re-rendering
114
+ * - This enables progressive enhancement for LLM platforms
115
+ */
116
+ connectedCallback(): void;
117
+ /**
118
+ * Called when element is removed from DOM.
119
+ */
120
+ disconnectedCallback(): void;
121
+ /**
122
+ * Called when an observed attribute changes.
123
+ * Updates options and schedules re-render.
124
+ */
125
+ attributeChangedCallback(name: string, oldValue: string | null, newValue: string | null): void;
126
+ /**
127
+ * Set all options at once (React pattern).
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const el = document.querySelector('fmcp-button');
132
+ * el.options = { variant: 'danger', size: 'lg' };
133
+ * ```
134
+ */
135
+ set options(value: Partial<TOptions>);
136
+ /**
137
+ * Get current options.
138
+ */
139
+ get options(): Partial<TOptions>;
140
+ /**
141
+ * Parse all current attributes into options.
142
+ */
143
+ private _parseAttributes;
144
+ /**
145
+ * Update a single option from an attribute change.
146
+ */
147
+ private _updateOptionFromAttribute;
148
+ /**
149
+ * Schedule a render on next microtask.
150
+ * Batches multiple attribute/property changes.
151
+ */
152
+ protected _scheduleRender(): void;
153
+ /**
154
+ * Perform the actual render.
155
+ * Validates options and updates innerHTML.
156
+ */
157
+ private _render;
158
+ /**
159
+ * Generate HTML for the component.
160
+ * Subclasses must implement this to render their specific HTML.
161
+ *
162
+ * @param options - Validated options
163
+ * @param content - Original innerHTML content
164
+ * @returns HTML string to render
165
+ */
166
+ protected abstract renderHtml(options: TOptions, content: string): string;
167
+ /**
168
+ * Force an immediate re-render.
169
+ *
170
+ * @example
171
+ * ```typescript
172
+ * el.options = { loading: true };
173
+ * el.refresh(); // Force immediate render
174
+ * ```
175
+ */
176
+ refresh(): void;
177
+ /**
178
+ * Get the first child element (the actual rendered component).
179
+ *
180
+ * @typeParam T - Expected element type
181
+ * @returns The first child element or null
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const button = el.getInnerElement<HTMLButtonElement>();
186
+ * button?.focus();
187
+ * ```
188
+ */
189
+ getInnerElement<T extends Element = Element>(): T | null;
190
+ /**
191
+ * Update content and re-render.
192
+ *
193
+ * @param content - New content string
194
+ */
195
+ setContent(content: string): void;
196
+ }
197
+ export {};