@frontmcp/uipack 0.6.1

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 (417) hide show
  1. package/CLAUDE.md +246 -0
  2. package/LICENSE +201 -0
  3. package/README.md +150 -0
  4. package/adapters/index.d.ts +13 -0
  5. package/adapters/index.d.ts.map +1 -0
  6. package/adapters/index.js +462 -0
  7. package/adapters/platform-meta.d.ts +166 -0
  8. package/adapters/platform-meta.d.ts.map +1 -0
  9. package/adapters/response-builder.d.ts +108 -0
  10. package/adapters/response-builder.d.ts.map +1 -0
  11. package/adapters/serving-mode.d.ts +107 -0
  12. package/adapters/serving-mode.d.ts.map +1 -0
  13. package/base-template/bridge.d.ts +90 -0
  14. package/base-template/bridge.d.ts.map +1 -0
  15. package/base-template/default-base-template.d.ts +92 -0
  16. package/base-template/default-base-template.d.ts.map +1 -0
  17. package/base-template/index.d.ts +15 -0
  18. package/base-template/index.d.ts.map +1 -0
  19. package/base-template/index.js +1398 -0
  20. package/base-template/polyfills.d.ts +31 -0
  21. package/base-template/polyfills.d.ts.map +1 -0
  22. package/base-template/theme-styles.d.ts +74 -0
  23. package/base-template/theme-styles.d.ts.map +1 -0
  24. package/bridge-runtime/iife-generator.d.ts +62 -0
  25. package/bridge-runtime/iife-generator.d.ts.map +1 -0
  26. package/bridge-runtime/index.d.ts +10 -0
  27. package/bridge-runtime/index.d.ts.map +1 -0
  28. package/bridge-runtime/index.js +883 -0
  29. package/build/cdn-resources.d.ts +243 -0
  30. package/build/cdn-resources.d.ts.map +1 -0
  31. package/build/index.d.ts +295 -0
  32. package/build/index.d.ts.map +1 -0
  33. package/build/index.js +6861 -0
  34. package/build/widget-manifest.d.ts +362 -0
  35. package/build/widget-manifest.d.ts.map +1 -0
  36. package/bundler/cache.d.ts +173 -0
  37. package/bundler/cache.d.ts.map +1 -0
  38. package/bundler/file-cache/component-builder.d.ts +167 -0
  39. package/bundler/file-cache/component-builder.d.ts.map +1 -0
  40. package/bundler/file-cache/hash-calculator.d.ts +155 -0
  41. package/bundler/file-cache/hash-calculator.d.ts.map +1 -0
  42. package/bundler/file-cache/index.d.ts +12 -0
  43. package/bundler/file-cache/index.d.ts.map +1 -0
  44. package/bundler/file-cache/storage/filesystem.d.ts +149 -0
  45. package/bundler/file-cache/storage/filesystem.d.ts.map +1 -0
  46. package/bundler/file-cache/storage/index.d.ts +11 -0
  47. package/bundler/file-cache/storage/index.d.ts.map +1 -0
  48. package/bundler/file-cache/storage/interface.d.ts +152 -0
  49. package/bundler/file-cache/storage/interface.d.ts.map +1 -0
  50. package/bundler/file-cache/storage/redis.d.ts +139 -0
  51. package/bundler/file-cache/storage/redis.d.ts.map +1 -0
  52. package/bundler/index.d.ts +35 -0
  53. package/bundler/index.d.ts.map +1 -0
  54. package/bundler/index.js +2947 -0
  55. package/bundler/sandbox/enclave-adapter.d.ts +121 -0
  56. package/bundler/sandbox/enclave-adapter.d.ts.map +1 -0
  57. package/bundler/sandbox/executor.d.ts +14 -0
  58. package/bundler/sandbox/executor.d.ts.map +1 -0
  59. package/bundler/sandbox/policy.d.ts +62 -0
  60. package/bundler/sandbox/policy.d.ts.map +1 -0
  61. package/bundler/types.d.ts +702 -0
  62. package/bundler/types.d.ts.map +1 -0
  63. package/dependency/cdn-registry.d.ts +98 -0
  64. package/dependency/cdn-registry.d.ts.map +1 -0
  65. package/dependency/import-map.d.ts +186 -0
  66. package/dependency/import-map.d.ts.map +1 -0
  67. package/dependency/import-parser.d.ts +82 -0
  68. package/dependency/import-parser.d.ts.map +1 -0
  69. package/dependency/index.d.ts +17 -0
  70. package/dependency/index.d.ts.map +1 -0
  71. package/dependency/index.js +3215 -0
  72. package/dependency/resolver.d.ts +164 -0
  73. package/dependency/resolver.d.ts.map +1 -0
  74. package/dependency/schemas.d.ts +486 -0
  75. package/dependency/schemas.d.ts.map +1 -0
  76. package/dependency/template-loader.d.ts +204 -0
  77. package/dependency/template-loader.d.ts.map +1 -0
  78. package/dependency/template-processor.d.ts +118 -0
  79. package/dependency/template-processor.d.ts.map +1 -0
  80. package/dependency/types.d.ts +739 -0
  81. package/dependency/types.d.ts.map +1 -0
  82. package/esm/adapters/index.d.ts +13 -0
  83. package/esm/adapters/index.d.ts.map +1 -0
  84. package/esm/adapters/index.js +427 -0
  85. package/esm/adapters/platform-meta.d.ts +166 -0
  86. package/esm/adapters/platform-meta.d.ts.map +1 -0
  87. package/esm/adapters/response-builder.d.ts +108 -0
  88. package/esm/adapters/response-builder.d.ts.map +1 -0
  89. package/esm/adapters/serving-mode.d.ts +107 -0
  90. package/esm/adapters/serving-mode.d.ts.map +1 -0
  91. package/esm/base-template/bridge.d.ts +90 -0
  92. package/esm/base-template/bridge.d.ts.map +1 -0
  93. package/esm/base-template/default-base-template.d.ts +92 -0
  94. package/esm/base-template/default-base-template.d.ts.map +1 -0
  95. package/esm/base-template/index.d.ts +15 -0
  96. package/esm/base-template/index.d.ts.map +1 -0
  97. package/esm/base-template/index.js +1364 -0
  98. package/esm/base-template/polyfills.d.ts +31 -0
  99. package/esm/base-template/polyfills.d.ts.map +1 -0
  100. package/esm/base-template/theme-styles.d.ts +74 -0
  101. package/esm/base-template/theme-styles.d.ts.map +1 -0
  102. package/esm/bridge-runtime/iife-generator.d.ts +62 -0
  103. package/esm/bridge-runtime/iife-generator.d.ts.map +1 -0
  104. package/esm/bridge-runtime/index.d.ts +10 -0
  105. package/esm/bridge-runtime/index.d.ts.map +1 -0
  106. package/esm/bridge-runtime/index.js +853 -0
  107. package/esm/build/cdn-resources.d.ts +243 -0
  108. package/esm/build/cdn-resources.d.ts.map +1 -0
  109. package/esm/build/index.d.ts +295 -0
  110. package/esm/build/index.d.ts.map +1 -0
  111. package/esm/build/index.js +6786 -0
  112. package/esm/build/widget-manifest.d.ts +362 -0
  113. package/esm/build/widget-manifest.d.ts.map +1 -0
  114. package/esm/bundler/cache.d.ts +173 -0
  115. package/esm/bundler/cache.d.ts.map +1 -0
  116. package/esm/bundler/file-cache/component-builder.d.ts +167 -0
  117. package/esm/bundler/file-cache/component-builder.d.ts.map +1 -0
  118. package/esm/bundler/file-cache/hash-calculator.d.ts +155 -0
  119. package/esm/bundler/file-cache/hash-calculator.d.ts.map +1 -0
  120. package/esm/bundler/file-cache/index.d.ts +12 -0
  121. package/esm/bundler/file-cache/index.d.ts.map +1 -0
  122. package/esm/bundler/file-cache/storage/filesystem.d.ts +149 -0
  123. package/esm/bundler/file-cache/storage/filesystem.d.ts.map +1 -0
  124. package/esm/bundler/file-cache/storage/index.d.ts +11 -0
  125. package/esm/bundler/file-cache/storage/index.d.ts.map +1 -0
  126. package/esm/bundler/file-cache/storage/interface.d.ts +152 -0
  127. package/esm/bundler/file-cache/storage/interface.d.ts.map +1 -0
  128. package/esm/bundler/file-cache/storage/redis.d.ts +139 -0
  129. package/esm/bundler/file-cache/storage/redis.d.ts.map +1 -0
  130. package/esm/bundler/index.d.ts +35 -0
  131. package/esm/bundler/index.d.ts.map +1 -0
  132. package/esm/bundler/index.js +2882 -0
  133. package/esm/bundler/sandbox/enclave-adapter.d.ts +121 -0
  134. package/esm/bundler/sandbox/enclave-adapter.d.ts.map +1 -0
  135. package/esm/bundler/sandbox/executor.d.ts +14 -0
  136. package/esm/bundler/sandbox/executor.d.ts.map +1 -0
  137. package/esm/bundler/sandbox/policy.d.ts +62 -0
  138. package/esm/bundler/sandbox/policy.d.ts.map +1 -0
  139. package/esm/bundler/types.d.ts +702 -0
  140. package/esm/bundler/types.d.ts.map +1 -0
  141. package/esm/dependency/cdn-registry.d.ts +98 -0
  142. package/esm/dependency/cdn-registry.d.ts.map +1 -0
  143. package/esm/dependency/import-map.d.ts +186 -0
  144. package/esm/dependency/import-map.d.ts.map +1 -0
  145. package/esm/dependency/import-parser.d.ts +82 -0
  146. package/esm/dependency/import-parser.d.ts.map +1 -0
  147. package/esm/dependency/index.d.ts +17 -0
  148. package/esm/dependency/index.d.ts.map +1 -0
  149. package/esm/dependency/index.js +3096 -0
  150. package/esm/dependency/resolver.d.ts +164 -0
  151. package/esm/dependency/resolver.d.ts.map +1 -0
  152. package/esm/dependency/schemas.d.ts +486 -0
  153. package/esm/dependency/schemas.d.ts.map +1 -0
  154. package/esm/dependency/template-loader.d.ts +204 -0
  155. package/esm/dependency/template-loader.d.ts.map +1 -0
  156. package/esm/dependency/template-processor.d.ts +118 -0
  157. package/esm/dependency/template-processor.d.ts.map +1 -0
  158. package/esm/dependency/types.d.ts +739 -0
  159. package/esm/dependency/types.d.ts.map +1 -0
  160. package/esm/handlebars/expression-extractor.d.ts +147 -0
  161. package/esm/handlebars/expression-extractor.d.ts.map +1 -0
  162. package/esm/handlebars/helpers.d.ts +339 -0
  163. package/esm/handlebars/helpers.d.ts.map +1 -0
  164. package/esm/handlebars/index.d.ts +195 -0
  165. package/esm/handlebars/index.d.ts.map +1 -0
  166. package/esm/handlebars/index.js +587 -0
  167. package/esm/index.d.ts +50 -0
  168. package/esm/index.d.ts.map +1 -0
  169. package/esm/index.js +12434 -0
  170. package/esm/package.json +68 -0
  171. package/esm/registry/index.d.ts +46 -0
  172. package/esm/registry/index.d.ts.map +1 -0
  173. package/esm/registry/index.js +6237 -0
  174. package/esm/registry/render-template.d.ts +91 -0
  175. package/esm/registry/render-template.d.ts.map +1 -0
  176. package/esm/registry/tool-ui.registry.d.ts +294 -0
  177. package/esm/registry/tool-ui.registry.d.ts.map +1 -0
  178. package/esm/registry/uri-utils.d.ts +56 -0
  179. package/esm/registry/uri-utils.d.ts.map +1 -0
  180. package/esm/renderers/cache.d.ts +145 -0
  181. package/esm/renderers/cache.d.ts.map +1 -0
  182. package/esm/renderers/html.renderer.d.ts +123 -0
  183. package/esm/renderers/html.renderer.d.ts.map +1 -0
  184. package/esm/renderers/index.d.ts +36 -0
  185. package/esm/renderers/index.d.ts.map +1 -0
  186. package/esm/renderers/index.js +1654 -0
  187. package/esm/renderers/mdx.renderer.d.ts +120 -0
  188. package/esm/renderers/mdx.renderer.d.ts.map +1 -0
  189. package/esm/renderers/registry.d.ts +133 -0
  190. package/esm/renderers/registry.d.ts.map +1 -0
  191. package/esm/renderers/types.d.ts +342 -0
  192. package/esm/renderers/types.d.ts.map +1 -0
  193. package/esm/renderers/utils/detect.d.ts +107 -0
  194. package/esm/renderers/utils/detect.d.ts.map +1 -0
  195. package/esm/renderers/utils/hash.d.ts +40 -0
  196. package/esm/renderers/utils/hash.d.ts.map +1 -0
  197. package/esm/renderers/utils/index.d.ts +9 -0
  198. package/esm/renderers/utils/index.d.ts.map +1 -0
  199. package/esm/renderers/utils/transpiler.d.ts +89 -0
  200. package/esm/renderers/utils/transpiler.d.ts.map +1 -0
  201. package/esm/runtime/adapters/html.adapter.d.ts +59 -0
  202. package/esm/runtime/adapters/html.adapter.d.ts.map +1 -0
  203. package/esm/runtime/adapters/index.d.ts +26 -0
  204. package/esm/runtime/adapters/index.d.ts.map +1 -0
  205. package/esm/runtime/adapters/mdx.adapter.d.ts +73 -0
  206. package/esm/runtime/adapters/mdx.adapter.d.ts.map +1 -0
  207. package/esm/runtime/adapters/types.d.ts +95 -0
  208. package/esm/runtime/adapters/types.d.ts.map +1 -0
  209. package/esm/runtime/csp.d.ts +48 -0
  210. package/esm/runtime/csp.d.ts.map +1 -0
  211. package/esm/runtime/index.d.ts +17 -0
  212. package/esm/runtime/index.d.ts.map +1 -0
  213. package/esm/runtime/index.js +4976 -0
  214. package/esm/runtime/mcp-bridge.d.ts +101 -0
  215. package/esm/runtime/mcp-bridge.d.ts.map +1 -0
  216. package/esm/runtime/renderer-runtime.d.ts +133 -0
  217. package/esm/runtime/renderer-runtime.d.ts.map +1 -0
  218. package/esm/runtime/sanitizer.d.ts +172 -0
  219. package/esm/runtime/sanitizer.d.ts.map +1 -0
  220. package/esm/runtime/types.d.ts +415 -0
  221. package/esm/runtime/types.d.ts.map +1 -0
  222. package/esm/runtime/wrapper.d.ts +421 -0
  223. package/esm/runtime/wrapper.d.ts.map +1 -0
  224. package/esm/styles/index.d.ts +8 -0
  225. package/esm/styles/index.d.ts.map +1 -0
  226. package/esm/styles/index.js +171 -0
  227. package/esm/styles/variants.d.ts +51 -0
  228. package/esm/styles/variants.d.ts.map +1 -0
  229. package/esm/theme/cdn.d.ts +195 -0
  230. package/esm/theme/cdn.d.ts.map +1 -0
  231. package/esm/theme/index.d.ts +18 -0
  232. package/esm/theme/index.d.ts.map +1 -0
  233. package/esm/theme/index.js +700 -0
  234. package/esm/theme/platforms.d.ts +107 -0
  235. package/esm/theme/platforms.d.ts.map +1 -0
  236. package/esm/theme/presets/github-openai.d.ts +50 -0
  237. package/esm/theme/presets/github-openai.d.ts.map +1 -0
  238. package/esm/theme/presets/index.d.ts +11 -0
  239. package/esm/theme/presets/index.d.ts.map +1 -0
  240. package/esm/theme/theme.d.ts +396 -0
  241. package/esm/theme/theme.d.ts.map +1 -0
  242. package/esm/tool-template/builder.d.ts +213 -0
  243. package/esm/tool-template/builder.d.ts.map +1 -0
  244. package/esm/tool-template/index.d.ts +16 -0
  245. package/esm/tool-template/index.d.ts.map +1 -0
  246. package/esm/tool-template/index.js +3518 -0
  247. package/esm/types/index.d.ts +14 -0
  248. package/esm/types/index.d.ts.map +1 -0
  249. package/esm/types/index.js +75 -0
  250. package/esm/types/ui-config.d.ts +641 -0
  251. package/esm/types/ui-config.d.ts.map +1 -0
  252. package/esm/types/ui-runtime.d.ts +1008 -0
  253. package/esm/types/ui-runtime.d.ts.map +1 -0
  254. package/esm/typings/cache/cache-adapter.d.ts +125 -0
  255. package/esm/typings/cache/cache-adapter.d.ts.map +1 -0
  256. package/esm/typings/cache/index.d.ts +10 -0
  257. package/esm/typings/cache/index.d.ts.map +1 -0
  258. package/esm/typings/cache/memory-cache.d.ts +92 -0
  259. package/esm/typings/cache/memory-cache.d.ts.map +1 -0
  260. package/esm/typings/dts-parser.d.ts +90 -0
  261. package/esm/typings/dts-parser.d.ts.map +1 -0
  262. package/esm/typings/index.d.ts +48 -0
  263. package/esm/typings/index.d.ts.map +1 -0
  264. package/esm/typings/index.js +812 -0
  265. package/esm/typings/schemas.d.ts +232 -0
  266. package/esm/typings/schemas.d.ts.map +1 -0
  267. package/esm/typings/type-fetcher.d.ts +89 -0
  268. package/esm/typings/type-fetcher.d.ts.map +1 -0
  269. package/esm/typings/types.d.ts +320 -0
  270. package/esm/typings/types.d.ts.map +1 -0
  271. package/esm/utils/escape-html.d.ts +58 -0
  272. package/esm/utils/escape-html.d.ts.map +1 -0
  273. package/esm/utils/index.d.ts +10 -0
  274. package/esm/utils/index.d.ts.map +1 -0
  275. package/esm/utils/index.js +40 -0
  276. package/esm/utils/safe-stringify.d.ts +30 -0
  277. package/esm/utils/safe-stringify.d.ts.map +1 -0
  278. package/esm/validation/error-box.d.ts +56 -0
  279. package/esm/validation/error-box.d.ts.map +1 -0
  280. package/esm/validation/index.d.ts +13 -0
  281. package/esm/validation/index.d.ts.map +1 -0
  282. package/esm/validation/index.js +542 -0
  283. package/esm/validation/schema-paths.d.ts +118 -0
  284. package/esm/validation/schema-paths.d.ts.map +1 -0
  285. package/esm/validation/template-validator.d.ts +143 -0
  286. package/esm/validation/template-validator.d.ts.map +1 -0
  287. package/esm/validation/wrapper.d.ts +97 -0
  288. package/esm/validation/wrapper.d.ts.map +1 -0
  289. package/handlebars/expression-extractor.d.ts +147 -0
  290. package/handlebars/expression-extractor.d.ts.map +1 -0
  291. package/handlebars/helpers.d.ts +339 -0
  292. package/handlebars/helpers.d.ts.map +1 -0
  293. package/handlebars/index.d.ts +195 -0
  294. package/handlebars/index.d.ts.map +1 -0
  295. package/handlebars/index.js +666 -0
  296. package/index.d.ts +50 -0
  297. package/index.d.ts.map +1 -0
  298. package/index.js +12683 -0
  299. package/package.json +66 -0
  300. package/registry/index.d.ts +46 -0
  301. package/registry/index.d.ts.map +1 -0
  302. package/registry/index.js +6280 -0
  303. package/registry/render-template.d.ts +91 -0
  304. package/registry/render-template.d.ts.map +1 -0
  305. package/registry/tool-ui.registry.d.ts +294 -0
  306. package/registry/tool-ui.registry.d.ts.map +1 -0
  307. package/registry/uri-utils.d.ts +56 -0
  308. package/registry/uri-utils.d.ts.map +1 -0
  309. package/renderers/cache.d.ts +145 -0
  310. package/renderers/cache.d.ts.map +1 -0
  311. package/renderers/html.renderer.d.ts +123 -0
  312. package/renderers/html.renderer.d.ts.map +1 -0
  313. package/renderers/index.d.ts +36 -0
  314. package/renderers/index.d.ts.map +1 -0
  315. package/renderers/index.js +1706 -0
  316. package/renderers/mdx.renderer.d.ts +120 -0
  317. package/renderers/mdx.renderer.d.ts.map +1 -0
  318. package/renderers/registry.d.ts +133 -0
  319. package/renderers/registry.d.ts.map +1 -0
  320. package/renderers/types.d.ts +342 -0
  321. package/renderers/types.d.ts.map +1 -0
  322. package/renderers/utils/detect.d.ts +107 -0
  323. package/renderers/utils/detect.d.ts.map +1 -0
  324. package/renderers/utils/hash.d.ts +40 -0
  325. package/renderers/utils/hash.d.ts.map +1 -0
  326. package/renderers/utils/index.d.ts +9 -0
  327. package/renderers/utils/index.d.ts.map +1 -0
  328. package/renderers/utils/transpiler.d.ts +89 -0
  329. package/renderers/utils/transpiler.d.ts.map +1 -0
  330. package/runtime/adapters/html.adapter.d.ts +59 -0
  331. package/runtime/adapters/html.adapter.d.ts.map +1 -0
  332. package/runtime/adapters/index.d.ts +26 -0
  333. package/runtime/adapters/index.d.ts.map +1 -0
  334. package/runtime/adapters/mdx.adapter.d.ts +73 -0
  335. package/runtime/adapters/mdx.adapter.d.ts.map +1 -0
  336. package/runtime/adapters/types.d.ts +95 -0
  337. package/runtime/adapters/types.d.ts.map +1 -0
  338. package/runtime/csp.d.ts +48 -0
  339. package/runtime/csp.d.ts.map +1 -0
  340. package/runtime/index.d.ts +17 -0
  341. package/runtime/index.d.ts.map +1 -0
  342. package/runtime/index.js +5052 -0
  343. package/runtime/mcp-bridge.d.ts +101 -0
  344. package/runtime/mcp-bridge.d.ts.map +1 -0
  345. package/runtime/renderer-runtime.d.ts +133 -0
  346. package/runtime/renderer-runtime.d.ts.map +1 -0
  347. package/runtime/sanitizer.d.ts +172 -0
  348. package/runtime/sanitizer.d.ts.map +1 -0
  349. package/runtime/types.d.ts +415 -0
  350. package/runtime/types.d.ts.map +1 -0
  351. package/runtime/wrapper.d.ts +421 -0
  352. package/runtime/wrapper.d.ts.map +1 -0
  353. package/styles/index.d.ts +8 -0
  354. package/styles/index.d.ts.map +1 -0
  355. package/styles/index.js +222 -0
  356. package/styles/variants.d.ts +51 -0
  357. package/styles/variants.d.ts.map +1 -0
  358. package/theme/cdn.d.ts +195 -0
  359. package/theme/cdn.d.ts.map +1 -0
  360. package/theme/index.d.ts +18 -0
  361. package/theme/index.d.ts.map +1 -0
  362. package/theme/index.js +757 -0
  363. package/theme/platforms.d.ts +107 -0
  364. package/theme/platforms.d.ts.map +1 -0
  365. package/theme/presets/github-openai.d.ts +50 -0
  366. package/theme/presets/github-openai.d.ts.map +1 -0
  367. package/theme/presets/index.d.ts +11 -0
  368. package/theme/presets/index.d.ts.map +1 -0
  369. package/theme/theme.d.ts +396 -0
  370. package/theme/theme.d.ts.map +1 -0
  371. package/tool-template/builder.d.ts +213 -0
  372. package/tool-template/builder.d.ts.map +1 -0
  373. package/tool-template/index.d.ts +16 -0
  374. package/tool-template/index.d.ts.map +1 -0
  375. package/tool-template/index.js +3562 -0
  376. package/types/index.d.ts +14 -0
  377. package/types/index.d.ts.map +1 -0
  378. package/types/index.js +108 -0
  379. package/types/ui-config.d.ts +641 -0
  380. package/types/ui-config.d.ts.map +1 -0
  381. package/types/ui-runtime.d.ts +1008 -0
  382. package/types/ui-runtime.d.ts.map +1 -0
  383. package/typings/cache/cache-adapter.d.ts +125 -0
  384. package/typings/cache/cache-adapter.d.ts.map +1 -0
  385. package/typings/cache/index.d.ts +10 -0
  386. package/typings/cache/index.d.ts.map +1 -0
  387. package/typings/cache/memory-cache.d.ts +92 -0
  388. package/typings/cache/memory-cache.d.ts.map +1 -0
  389. package/typings/dts-parser.d.ts +90 -0
  390. package/typings/dts-parser.d.ts.map +1 -0
  391. package/typings/index.d.ts +48 -0
  392. package/typings/index.d.ts.map +1 -0
  393. package/typings/index.js +868 -0
  394. package/typings/schemas.d.ts +232 -0
  395. package/typings/schemas.d.ts.map +1 -0
  396. package/typings/type-fetcher.d.ts +89 -0
  397. package/typings/type-fetcher.d.ts.map +1 -0
  398. package/typings/types.d.ts +320 -0
  399. package/typings/types.d.ts.map +1 -0
  400. package/utils/escape-html.d.ts +58 -0
  401. package/utils/escape-html.d.ts.map +1 -0
  402. package/utils/index.d.ts +10 -0
  403. package/utils/index.d.ts.map +1 -0
  404. package/utils/index.js +70 -0
  405. package/utils/safe-stringify.d.ts +30 -0
  406. package/utils/safe-stringify.d.ts.map +1 -0
  407. package/validation/error-box.d.ts +56 -0
  408. package/validation/error-box.d.ts.map +1 -0
  409. package/validation/index.d.ts +13 -0
  410. package/validation/index.d.ts.map +1 -0
  411. package/validation/index.js +583 -0
  412. package/validation/schema-paths.d.ts +118 -0
  413. package/validation/schema-paths.d.ts.map +1 -0
  414. package/validation/template-validator.d.ts +143 -0
  415. package/validation/template-validator.d.ts.map +1 -0
  416. package/validation/wrapper.d.ts +97 -0
  417. package/validation/wrapper.d.ts.map +1 -0
@@ -0,0 +1,3215 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // libs/uipack/src/dependency/index.ts
31
+ var dependency_exports = {};
32
+ __export(dependency_exports, {
33
+ CDN_PROVIDER_PRIORITY: () => CDN_PROVIDER_PRIORITY,
34
+ DEFAULT_CDN_REGISTRY: () => DEFAULT_CDN_REGISTRY,
35
+ DependencyResolutionError: () => DependencyResolutionError,
36
+ DependencyResolver: () => DependencyResolver,
37
+ NoProviderError: () => NoProviderError,
38
+ addScope: () => addScope,
39
+ buildManifestMetadataSchema: () => buildManifestMetadataSchema,
40
+ buildManifestOutputsSchema: () => buildManifestOutputsSchema,
41
+ bundleTargetSchema: () => bundleTargetSchema,
42
+ cacheStatsSchema: () => cacheStatsSchema,
43
+ cdnDependencySchema: () => cdnDependencySchema,
44
+ cdnPlatformTypeSchema: () => cdnPlatformTypeSchema,
45
+ cdnProviderConfigSchema: () => cdnProviderConfigSchema,
46
+ cdnProviderSchema: () => cdnProviderSchema,
47
+ cdnRegistryEntrySchema: () => cdnRegistryEntrySchema,
48
+ clearHandlebarsCache: () => clearHandlebarsCache,
49
+ clearUrlCache: () => clearUrlCache,
50
+ componentBuildManifestSchema: () => componentBuildManifestSchema,
51
+ createClaudeResolver: () => createClaudeResolver,
52
+ createImportMap: () => createImportMap,
53
+ createImportMapFromOverrides: () => createImportMapFromOverrides,
54
+ createOpenAIResolver: () => createOpenAIResolver,
55
+ createResolver: () => createResolver,
56
+ dependencyResolverOptionsSchema: () => dependencyResolverOptionsSchema,
57
+ detectFormatFromPath: () => detectFormatFromPath,
58
+ detectFormatFromUrl: () => detectFormatFromUrl,
59
+ detectTemplateMode: () => detectTemplateMode,
60
+ detectTemplateSource: () => detectTemplateSource,
61
+ extractExternalPackages: () => extractExternalPackages,
62
+ fetchTemplateFromUrl: () => fetchTemplateFromUrl,
63
+ fileBundleOptionsSchema: () => fileBundleOptionsSchema,
64
+ fileTemplateConfigSchema: () => fileTemplateConfigSchema,
65
+ filterImportsByPackages: () => filterImportsByPackages,
66
+ generateCDNScriptTags: () => generateCDNScriptTags,
67
+ generateDependencyHTML: () => generateDependencyHTML,
68
+ generateESMScriptTags: () => generateESMScriptTags,
69
+ generateImportMapForPackages: () => generateImportMapForPackages,
70
+ generateImportMapScriptTag: () => generateImportMapScriptTag,
71
+ generateImportMapScriptTagMinified: () => generateImportMapScriptTagMinified,
72
+ generateUMDShim: () => generateUMDShim,
73
+ getImportStats: () => getImportStats,
74
+ getPackageCDNDependency: () => getPackageCDNDependency,
75
+ getPackageCDNUrl: () => getPackageCDNUrl,
76
+ getPackageName: () => getPackageName,
77
+ getPackagePeerDependencies: () => getPackagePeerDependencies,
78
+ getRegisteredPackages: () => getRegisteredPackages,
79
+ getUrlCache: () => getUrlCache,
80
+ importMapSchema: () => importMapSchema,
81
+ importTypeSchema: () => importTypeSchema,
82
+ invalidateUrlCache: () => invalidateUrlCache,
83
+ isFileBasedTemplate: () => isFileBasedTemplate,
84
+ isMarkedAvailable: () => isMarkedAvailable,
85
+ isPackageRegistered: () => isPackageRegistered,
86
+ lookupPackage: () => lookupPackage,
87
+ mergeImportMaps: () => mergeImportMaps,
88
+ mergeRegistries: () => mergeRegistries,
89
+ needsRefetch: () => needsRefetch,
90
+ packageMetadataSchema: () => packageMetadataSchema,
91
+ parseImports: () => parseImports,
92
+ parsedImportResultSchema: () => parsedImportResultSchema,
93
+ parsedImportSchema: () => parsedImportSchema,
94
+ processHtmlTemplate: () => processHtmlTemplate,
95
+ processMarkdownTemplate: () => processMarkdownTemplate,
96
+ processMdxTemplate: () => processMdxTemplate,
97
+ processTemplate: () => processTemplate,
98
+ processTemplates: () => processTemplates,
99
+ producesHtml: () => producesHtml,
100
+ readTemplateFromFile: () => readTemplateFromFile,
101
+ requiresBundling: () => requiresBundling,
102
+ resolveAllDependencies: () => resolveAllDependencies,
103
+ resolveDependencies: () => resolveDependencies,
104
+ resolveFilePath: () => resolveFilePath,
105
+ resolveTemplate: () => resolveTemplate,
106
+ resolvedDependencySchema: () => resolvedDependencySchema,
107
+ safeParseBuildManifest: () => safeParseBuildManifest,
108
+ safeParseCDNDependency: () => safeParseCDNDependency,
109
+ safeParseFileTemplateConfig: () => safeParseFileTemplateConfig,
110
+ supportsHandlebars: () => supportsHandlebars,
111
+ validateBuildManifest: () => validateBuildManifest,
112
+ validateCDNDependency: () => validateCDNDependency,
113
+ validateFileTemplateConfig: () => validateFileTemplateConfig,
114
+ validateImportMap: () => validateImportMap,
115
+ validateTemplateUrl: () => validateTemplateUrl
116
+ });
117
+ module.exports = __toCommonJS(dependency_exports);
118
+
119
+ // libs/uipack/src/dependency/types.ts
120
+ function detectTemplateMode(template) {
121
+ if (typeof template === "function") {
122
+ return "inline-function";
123
+ }
124
+ if (typeof template === "string") {
125
+ if (template.startsWith("http://") || template.startsWith("https://")) {
126
+ return "url";
127
+ }
128
+ const looksLikeFilePath = (
129
+ // Relative paths
130
+ template.startsWith("./") || template.startsWith("../") || // Absolute paths (Unix)
131
+ template.startsWith("/") || // Windows-style paths (C:\, D:\, etc.)
132
+ /^[A-Za-z]:\\/.test(template) || // File extensions (must not contain spaces to avoid false positives)
133
+ /\.(tsx?|jsx?|mdx?)$/i.test(template) && !template.includes(" ")
134
+ );
135
+ if (looksLikeFilePath && template.length < 500 && !template.includes("\n") && !template.includes("<")) {
136
+ return "file-path";
137
+ }
138
+ }
139
+ return "inline-string";
140
+ }
141
+ function detectFormatFromPath(pathOrUrl) {
142
+ const lower = pathOrUrl.toLowerCase();
143
+ if (lower.endsWith(".tsx") || lower.endsWith(".jsx")) {
144
+ return "react";
145
+ }
146
+ if (lower.endsWith(".mdx")) {
147
+ return "mdx";
148
+ }
149
+ if (lower.endsWith(".md")) {
150
+ return "markdown";
151
+ }
152
+ return "html";
153
+ }
154
+
155
+ // libs/uipack/src/dependency/schemas.ts
156
+ var import_zod = require("zod");
157
+ var cdnProviderSchema = import_zod.z.enum(["cloudflare", "jsdelivr", "unpkg", "esm.sh", "skypack"]);
158
+ var cdnPlatformTypeSchema = import_zod.z.enum(["claude", "openai", "cursor", "gemini", "continue", "cody", "unknown"]);
159
+ var cdnDependencySchema = import_zod.z.object({
160
+ /**
161
+ * CDN URL (must be HTTPS).
162
+ */
163
+ url: import_zod.z.string().url().refine((url) => url.startsWith("https://"), {
164
+ message: "CDN URLs must use HTTPS"
165
+ }),
166
+ /**
167
+ * SRI integrity hash.
168
+ */
169
+ integrity: import_zod.z.string().regex(/^sha(256|384|512)-[A-Za-z0-9+/=]+$/, {
170
+ message: "Invalid SRI hash format. Must be sha256-, sha384-, or sha512- followed by base64"
171
+ }).optional(),
172
+ /**
173
+ * Global variable name for UMD builds.
174
+ */
175
+ global: import_zod.z.string().min(1).optional(),
176
+ /**
177
+ * Named exports from the library.
178
+ */
179
+ exports: import_zod.z.array(import_zod.z.string().min(1)).optional(),
180
+ /**
181
+ * Whether this is an ES module.
182
+ */
183
+ esm: import_zod.z.boolean().optional(),
184
+ /**
185
+ * Cross-origin attribute.
186
+ */
187
+ crossorigin: import_zod.z.enum(["anonymous", "use-credentials"]).optional(),
188
+ /**
189
+ * Peer dependencies (npm package names).
190
+ */
191
+ peerDependencies: import_zod.z.array(import_zod.z.string().min(1)).optional()
192
+ }).strict();
193
+ var bundleTargetSchema = import_zod.z.enum(["es2018", "es2019", "es2020", "es2021", "es2022", "esnext"]);
194
+ var fileBundleOptionsSchema = import_zod.z.object({
195
+ /**
196
+ * Minify output.
197
+ */
198
+ minify: import_zod.z.boolean().optional(),
199
+ /**
200
+ * Generate source maps.
201
+ */
202
+ sourceMaps: import_zod.z.boolean().optional(),
203
+ /**
204
+ * Target JavaScript version.
205
+ */
206
+ target: bundleTargetSchema.optional(),
207
+ /**
208
+ * Enable tree shaking.
209
+ */
210
+ treeShake: import_zod.z.boolean().optional(),
211
+ /**
212
+ * JSX factory function.
213
+ */
214
+ jsxFactory: import_zod.z.string().min(1).optional(),
215
+ /**
216
+ * JSX fragment factory.
217
+ */
218
+ jsxFragment: import_zod.z.string().min(1).optional(),
219
+ /**
220
+ * JSX import source.
221
+ */
222
+ jsxImportSource: import_zod.z.string().min(1).optional()
223
+ }).strict();
224
+ var fileTemplateConfigSchema = import_zod.z.object({
225
+ /**
226
+ * Packages to load from CDN.
227
+ */
228
+ externals: import_zod.z.array(import_zod.z.string().min(1)).optional(),
229
+ /**
230
+ * Explicit CDN dependency overrides.
231
+ */
232
+ dependencies: import_zod.z.record(import_zod.z.string().min(1), cdnDependencySchema).optional(),
233
+ /**
234
+ * Bundle options.
235
+ */
236
+ bundleOptions: fileBundleOptionsSchema.optional()
237
+ }).strict();
238
+ var importMapSchema = import_zod.z.object({
239
+ /**
240
+ * Module specifier to URL mappings.
241
+ */
242
+ imports: import_zod.z.record(
243
+ import_zod.z.string().min(1),
244
+ import_zod.z.string().url().refine((url) => url.startsWith("https://"), {
245
+ message: "Import map URLs must use HTTPS"
246
+ })
247
+ ),
248
+ /**
249
+ * Scoped mappings.
250
+ */
251
+ scopes: import_zod.z.record(
252
+ import_zod.z.string().min(1),
253
+ import_zod.z.record(
254
+ import_zod.z.string().min(1),
255
+ import_zod.z.string().url().refine((url) => url.startsWith("https://"), {
256
+ message: "Scoped import URLs must use HTTPS"
257
+ })
258
+ )
259
+ ).optional(),
260
+ /**
261
+ * Integrity hashes.
262
+ */
263
+ integrity: import_zod.z.record(import_zod.z.string().url(), import_zod.z.string().regex(/^sha(256|384|512)-[A-Za-z0-9+/=]+$/)).optional()
264
+ }).strict();
265
+ var resolvedDependencySchema = import_zod.z.object({
266
+ packageName: import_zod.z.string().min(1),
267
+ version: import_zod.z.string().min(1),
268
+ cdnUrl: import_zod.z.string().url(),
269
+ integrity: import_zod.z.string().optional(),
270
+ global: import_zod.z.string().optional(),
271
+ esm: import_zod.z.boolean(),
272
+ provider: cdnProviderSchema
273
+ }).strict();
274
+ var buildManifestMetadataSchema = import_zod.z.object({
275
+ createdAt: import_zod.z.string().datetime(),
276
+ buildTimeMs: import_zod.z.number().nonnegative(),
277
+ totalSize: import_zod.z.number().nonnegative(),
278
+ bundlerVersion: import_zod.z.string().optional()
279
+ }).strict();
280
+ var buildManifestOutputsSchema = import_zod.z.object({
281
+ code: import_zod.z.string(),
282
+ sourceMap: import_zod.z.string().optional(),
283
+ ssrHtml: import_zod.z.string().optional()
284
+ }).strict();
285
+ var componentBuildManifestSchema = import_zod.z.object({
286
+ version: import_zod.z.literal("1.0"),
287
+ buildId: import_zod.z.string().uuid(),
288
+ toolName: import_zod.z.string().min(1),
289
+ entryPath: import_zod.z.string().min(1),
290
+ contentHash: import_zod.z.string().regex(/^[a-f0-9]{64}$/, {
291
+ message: "Content hash must be a 64-character SHA-256 hex string"
292
+ }),
293
+ dependencies: import_zod.z.array(resolvedDependencySchema),
294
+ outputs: buildManifestOutputsSchema,
295
+ importMap: importMapSchema,
296
+ metadata: buildManifestMetadataSchema
297
+ }).strict();
298
+ var cdnProviderConfigSchema = import_zod.z.record(cdnProviderSchema, cdnDependencySchema);
299
+ var packageMetadataSchema = import_zod.z.object({
300
+ description: import_zod.z.string().optional(),
301
+ homepage: import_zod.z.string().url().optional(),
302
+ license: import_zod.z.string().optional()
303
+ }).strict();
304
+ var cdnRegistryEntrySchema = import_zod.z.object({
305
+ packageName: import_zod.z.string().min(1),
306
+ defaultVersion: import_zod.z.string().min(1),
307
+ providers: cdnProviderConfigSchema,
308
+ preferredProviders: import_zod.z.array(cdnProviderSchema).optional(),
309
+ metadata: packageMetadataSchema.optional()
310
+ }).strict();
311
+ var dependencyResolverOptionsSchema = import_zod.z.object({
312
+ platform: cdnPlatformTypeSchema.optional(),
313
+ preferredProviders: import_zod.z.array(cdnProviderSchema).optional(),
314
+ customRegistry: import_zod.z.record(import_zod.z.string().min(1), cdnRegistryEntrySchema).optional(),
315
+ strictMode: import_zod.z.boolean().optional(),
316
+ requireIntegrity: import_zod.z.boolean().optional()
317
+ }).strict();
318
+ var importTypeSchema = import_zod.z.enum(["named", "default", "namespace", "side-effect", "dynamic"]);
319
+ var parsedImportSchema = import_zod.z.object({
320
+ statement: import_zod.z.string(),
321
+ specifier: import_zod.z.string().min(1),
322
+ type: importTypeSchema,
323
+ namedImports: import_zod.z.array(import_zod.z.string().min(1)).optional(),
324
+ defaultImport: import_zod.z.string().min(1).optional(),
325
+ namespaceImport: import_zod.z.string().min(1).optional(),
326
+ line: import_zod.z.number().int().positive(),
327
+ column: import_zod.z.number().int().nonnegative()
328
+ }).strict();
329
+ var parsedImportResultSchema = import_zod.z.object({
330
+ imports: import_zod.z.array(parsedImportSchema),
331
+ externalImports: import_zod.z.array(parsedImportSchema),
332
+ relativeImports: import_zod.z.array(parsedImportSchema),
333
+ externalPackages: import_zod.z.array(import_zod.z.string().min(1))
334
+ }).strict();
335
+ var cacheStatsSchema = import_zod.z.object({
336
+ entries: import_zod.z.number().int().nonnegative(),
337
+ totalSize: import_zod.z.number().nonnegative(),
338
+ hits: import_zod.z.number().int().nonnegative(),
339
+ misses: import_zod.z.number().int().nonnegative(),
340
+ hitRate: import_zod.z.number().min(0).max(1)
341
+ }).strict();
342
+ function validateCDNDependency(data) {
343
+ return cdnDependencySchema.parse(data);
344
+ }
345
+ function safeParseCDNDependency(data) {
346
+ return cdnDependencySchema.safeParse(data);
347
+ }
348
+ function validateFileTemplateConfig(data) {
349
+ return fileTemplateConfigSchema.parse(data);
350
+ }
351
+ function safeParseFileTemplateConfig(data) {
352
+ return fileTemplateConfigSchema.safeParse(data);
353
+ }
354
+ function validateBuildManifest(data) {
355
+ return componentBuildManifestSchema.parse(data);
356
+ }
357
+ function safeParseBuildManifest(data) {
358
+ return componentBuildManifestSchema.safeParse(data);
359
+ }
360
+
361
+ // libs/uipack/src/dependency/cdn-registry.ts
362
+ var DEFAULT_CDN_REGISTRY = {
363
+ // ============================================
364
+ // React Ecosystem
365
+ // ============================================
366
+ react: {
367
+ packageName: "react",
368
+ defaultVersion: "18.3.1",
369
+ providers: {
370
+ cloudflare: {
371
+ url: "https://cdnjs.cloudflare.com/ajax/libs/react/18.3.1/umd/react.production.min.js",
372
+ integrity: "sha512-Qp8J4Xr8LBZ5CXNJQc/HmLqFrpXz6lNkbzMYkYHKzQx5p1q1yOqPQHntXKoYgPPE/n9m0QF1OkJdXa2ePpO4fw==",
373
+ global: "React",
374
+ crossorigin: "anonymous"
375
+ },
376
+ jsdelivr: {
377
+ url: "https://cdn.jsdelivr.net/npm/react@18.3.1/umd/react.production.min.js",
378
+ global: "React",
379
+ crossorigin: "anonymous"
380
+ },
381
+ unpkg: {
382
+ url: "https://unpkg.com/react@18.3.1/umd/react.production.min.js",
383
+ global: "React",
384
+ crossorigin: "anonymous"
385
+ },
386
+ "esm.sh": {
387
+ url: "https://esm.sh/react@18.3.1",
388
+ esm: true,
389
+ crossorigin: "anonymous"
390
+ }
391
+ },
392
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
393
+ metadata: {
394
+ description: "A JavaScript library for building user interfaces",
395
+ homepage: "https://react.dev",
396
+ license: "MIT"
397
+ }
398
+ },
399
+ "react-dom": {
400
+ packageName: "react-dom",
401
+ defaultVersion: "18.3.1",
402
+ providers: {
403
+ cloudflare: {
404
+ url: "https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.3.1/umd/react-dom.production.min.js",
405
+ integrity: "sha512-6s2gVRdS3aT+FDdZTRJSzKlzIPqDXWyYl/5hPQb6hSgzKPGFcQyZhbqjbWVxGrs2dYNrINFXb0k0UD3d+CKPJA==",
406
+ global: "ReactDOM",
407
+ crossorigin: "anonymous",
408
+ peerDependencies: ["react"]
409
+ },
410
+ jsdelivr: {
411
+ url: "https://cdn.jsdelivr.net/npm/react-dom@18.3.1/umd/react-dom.production.min.js",
412
+ global: "ReactDOM",
413
+ crossorigin: "anonymous",
414
+ peerDependencies: ["react"]
415
+ },
416
+ unpkg: {
417
+ url: "https://unpkg.com/react-dom@18.3.1/umd/react-dom.production.min.js",
418
+ global: "ReactDOM",
419
+ crossorigin: "anonymous",
420
+ peerDependencies: ["react"]
421
+ },
422
+ "esm.sh": {
423
+ url: "https://esm.sh/react-dom@18.3.1",
424
+ esm: true,
425
+ crossorigin: "anonymous",
426
+ peerDependencies: ["react"]
427
+ }
428
+ },
429
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
430
+ metadata: {
431
+ description: "React package for working with the DOM",
432
+ homepage: "https://react.dev",
433
+ license: "MIT"
434
+ }
435
+ },
436
+ // ============================================
437
+ // Charting Libraries
438
+ // ============================================
439
+ "chart.js": {
440
+ packageName: "chart.js",
441
+ defaultVersion: "4.4.7",
442
+ providers: {
443
+ cloudflare: {
444
+ url: "https://cdnjs.cloudflare.com/ajax/libs/Chart.js/4.4.7/chart.umd.min.js",
445
+ integrity: "sha512-dMDjIoZjJD6gs0KPBhFYjLQrH3kIohSEn6HzWs6Y6GiO0+L9kk/bM3cR5KNEDK1KvMNpTIZG6pHK9SZfCJHRpQ==",
446
+ global: "Chart",
447
+ crossorigin: "anonymous"
448
+ },
449
+ jsdelivr: {
450
+ url: "https://cdn.jsdelivr.net/npm/chart.js@4.4.7/dist/chart.umd.min.js",
451
+ global: "Chart",
452
+ crossorigin: "anonymous"
453
+ },
454
+ unpkg: {
455
+ url: "https://unpkg.com/chart.js@4.4.7/dist/chart.umd.min.js",
456
+ global: "Chart",
457
+ crossorigin: "anonymous"
458
+ }
459
+ },
460
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
461
+ metadata: {
462
+ description: "Simple yet flexible JavaScript charting library",
463
+ homepage: "https://www.chartjs.org",
464
+ license: "MIT"
465
+ }
466
+ },
467
+ "react-chartjs-2": {
468
+ packageName: "react-chartjs-2",
469
+ defaultVersion: "5.3.0",
470
+ providers: {
471
+ cloudflare: {
472
+ url: "https://cdnjs.cloudflare.com/ajax/libs/react-chartjs-2/5.3.0/react-chartjs-2.min.js",
473
+ global: "ReactChartjs2",
474
+ crossorigin: "anonymous",
475
+ peerDependencies: ["react", "chart.js"]
476
+ },
477
+ jsdelivr: {
478
+ url: "https://cdn.jsdelivr.net/npm/react-chartjs-2@5.3.0/dist/index.umd.js",
479
+ global: "ReactChartjs2",
480
+ crossorigin: "anonymous",
481
+ peerDependencies: ["react", "chart.js"]
482
+ },
483
+ "esm.sh": {
484
+ url: "https://esm.sh/react-chartjs-2@5.3.0",
485
+ esm: true,
486
+ crossorigin: "anonymous",
487
+ peerDependencies: ["react", "chart.js"]
488
+ }
489
+ },
490
+ preferredProviders: ["cloudflare", "jsdelivr", "esm.sh"],
491
+ metadata: {
492
+ description: "React components for Chart.js",
493
+ homepage: "https://react-chartjs-2.js.org",
494
+ license: "MIT"
495
+ }
496
+ },
497
+ // ============================================
498
+ // D3.js
499
+ // ============================================
500
+ d3: {
501
+ packageName: "d3",
502
+ defaultVersion: "7.9.0",
503
+ providers: {
504
+ cloudflare: {
505
+ url: "https://cdnjs.cloudflare.com/ajax/libs/d3/7.9.0/d3.min.js",
506
+ integrity: "sha512-vc58qvvBdrDR4etbxMdlTt4GBQk1qjvyORR2nrsPsFPyrs+/u5c3+1Ct6upOgdZoIl7eq6k3a1UPDSNAQi/32A==",
507
+ global: "d3",
508
+ crossorigin: "anonymous"
509
+ },
510
+ jsdelivr: {
511
+ url: "https://cdn.jsdelivr.net/npm/d3@7.9.0/dist/d3.min.js",
512
+ global: "d3",
513
+ crossorigin: "anonymous"
514
+ },
515
+ unpkg: {
516
+ url: "https://unpkg.com/d3@7.9.0/dist/d3.min.js",
517
+ global: "d3",
518
+ crossorigin: "anonymous"
519
+ }
520
+ },
521
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
522
+ metadata: {
523
+ description: "Data-Driven Documents",
524
+ homepage: "https://d3js.org",
525
+ license: "ISC"
526
+ }
527
+ },
528
+ // ============================================
529
+ // Utility Libraries
530
+ // ============================================
531
+ lodash: {
532
+ packageName: "lodash",
533
+ defaultVersion: "4.17.21",
534
+ providers: {
535
+ cloudflare: {
536
+ url: "https://cdnjs.cloudflare.com/ajax/libs/lodash.js/4.17.21/lodash.min.js",
537
+ integrity: "sha512-WFN04846sdKMIP5LKNphMaWzU7YpMyCU245etK3g/2ARYbPK9Ub18eG+ljU96qKRCWh+quCY7yefSmlkQw1ANQ==",
538
+ global: "_",
539
+ crossorigin: "anonymous"
540
+ },
541
+ jsdelivr: {
542
+ url: "https://cdn.jsdelivr.net/npm/lodash@4.17.21/lodash.min.js",
543
+ global: "_",
544
+ crossorigin: "anonymous"
545
+ },
546
+ unpkg: {
547
+ url: "https://unpkg.com/lodash@4.17.21/lodash.min.js",
548
+ global: "_",
549
+ crossorigin: "anonymous"
550
+ }
551
+ },
552
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
553
+ metadata: {
554
+ description: "A modern JavaScript utility library",
555
+ homepage: "https://lodash.com",
556
+ license: "MIT"
557
+ }
558
+ },
559
+ "lodash-es": {
560
+ packageName: "lodash-es",
561
+ defaultVersion: "4.17.21",
562
+ providers: {
563
+ "esm.sh": {
564
+ url: "https://esm.sh/lodash-es@4.17.21",
565
+ esm: true,
566
+ crossorigin: "anonymous"
567
+ },
568
+ jsdelivr: {
569
+ url: "https://cdn.jsdelivr.net/npm/lodash-es@4.17.21/+esm",
570
+ esm: true,
571
+ crossorigin: "anonymous"
572
+ }
573
+ },
574
+ preferredProviders: ["esm.sh", "jsdelivr"],
575
+ metadata: {
576
+ description: "Lodash exported as ES modules",
577
+ homepage: "https://lodash.com",
578
+ license: "MIT"
579
+ }
580
+ },
581
+ dayjs: {
582
+ packageName: "dayjs",
583
+ defaultVersion: "1.11.13",
584
+ providers: {
585
+ cloudflare: {
586
+ url: "https://cdnjs.cloudflare.com/ajax/libs/dayjs/1.11.13/dayjs.min.js",
587
+ integrity: "sha512-Ot7ArUEhJDU0cwoBNNnWe487kjL5wAOsIYig8llY/l0P2TUFwgsAHVmrZMHsT8NGo+HwkjTJsNErS6QqIkBxDw==",
588
+ global: "dayjs",
589
+ crossorigin: "anonymous"
590
+ },
591
+ jsdelivr: {
592
+ url: "https://cdn.jsdelivr.net/npm/dayjs@1.11.13/dayjs.min.js",
593
+ global: "dayjs",
594
+ crossorigin: "anonymous"
595
+ },
596
+ unpkg: {
597
+ url: "https://unpkg.com/dayjs@1.11.13/dayjs.min.js",
598
+ global: "dayjs",
599
+ crossorigin: "anonymous"
600
+ }
601
+ },
602
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
603
+ metadata: {
604
+ description: "Fast 2kB alternative to Moment.js with the same modern API",
605
+ homepage: "https://day.js.org",
606
+ license: "MIT"
607
+ }
608
+ },
609
+ "date-fns": {
610
+ packageName: "date-fns",
611
+ defaultVersion: "4.1.0",
612
+ providers: {
613
+ "esm.sh": {
614
+ url: "https://esm.sh/date-fns@4.1.0",
615
+ esm: true,
616
+ crossorigin: "anonymous"
617
+ },
618
+ jsdelivr: {
619
+ url: "https://cdn.jsdelivr.net/npm/date-fns@4.1.0/+esm",
620
+ esm: true,
621
+ crossorigin: "anonymous"
622
+ }
623
+ },
624
+ preferredProviders: ["esm.sh", "jsdelivr"],
625
+ metadata: {
626
+ description: "Modern JavaScript date utility library",
627
+ homepage: "https://date-fns.org",
628
+ license: "MIT"
629
+ }
630
+ },
631
+ // ============================================
632
+ // Animation Libraries
633
+ // ============================================
634
+ "framer-motion": {
635
+ packageName: "framer-motion",
636
+ defaultVersion: "11.15.0",
637
+ providers: {
638
+ "esm.sh": {
639
+ url: "https://esm.sh/framer-motion@11.15.0",
640
+ esm: true,
641
+ crossorigin: "anonymous",
642
+ peerDependencies: ["react", "react-dom"]
643
+ },
644
+ jsdelivr: {
645
+ url: "https://cdn.jsdelivr.net/npm/framer-motion@11.15.0/dist/framer-motion.js",
646
+ global: "Motion",
647
+ crossorigin: "anonymous",
648
+ peerDependencies: ["react", "react-dom"]
649
+ }
650
+ },
651
+ preferredProviders: ["esm.sh", "jsdelivr"],
652
+ metadata: {
653
+ description: "Production-ready motion library for React",
654
+ homepage: "https://www.framer.com/motion/",
655
+ license: "MIT"
656
+ }
657
+ },
658
+ // ============================================
659
+ // UI Component Libraries
660
+ // ============================================
661
+ "lucide-react": {
662
+ packageName: "lucide-react",
663
+ defaultVersion: "0.468.0",
664
+ providers: {
665
+ "esm.sh": {
666
+ url: "https://esm.sh/lucide-react@0.468.0",
667
+ esm: true,
668
+ crossorigin: "anonymous",
669
+ peerDependencies: ["react"]
670
+ },
671
+ jsdelivr: {
672
+ url: "https://cdn.jsdelivr.net/npm/lucide-react@0.468.0/dist/esm/lucide-react.js",
673
+ esm: true,
674
+ crossorigin: "anonymous",
675
+ peerDependencies: ["react"]
676
+ }
677
+ },
678
+ preferredProviders: ["esm.sh", "jsdelivr"],
679
+ metadata: {
680
+ description: "Beautiful & consistent icon toolkit for React",
681
+ homepage: "https://lucide.dev",
682
+ license: "ISC"
683
+ }
684
+ },
685
+ // ============================================
686
+ // Markdown/Syntax Highlighting
687
+ // ============================================
688
+ marked: {
689
+ packageName: "marked",
690
+ defaultVersion: "15.0.4",
691
+ providers: {
692
+ cloudflare: {
693
+ url: "https://cdnjs.cloudflare.com/ajax/libs/marked/15.0.4/marked.min.js",
694
+ integrity: "sha512-Rn/d0sGeizGbk3VJEiYNDt/mMcfuzYoFkia3iBffv+HX8VUrHMo/0cKjZuxWGoZLPh/VxUcC9ais+RBFZW9EBg==",
695
+ global: "marked",
696
+ crossorigin: "anonymous"
697
+ },
698
+ jsdelivr: {
699
+ url: "https://cdn.jsdelivr.net/npm/marked@15.0.4/marked.min.js",
700
+ global: "marked",
701
+ crossorigin: "anonymous"
702
+ },
703
+ unpkg: {
704
+ url: "https://unpkg.com/marked@15.0.4/marked.min.js",
705
+ global: "marked",
706
+ crossorigin: "anonymous"
707
+ }
708
+ },
709
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
710
+ metadata: {
711
+ description: "A markdown parser and compiler",
712
+ homepage: "https://marked.js.org",
713
+ license: "MIT"
714
+ }
715
+ },
716
+ "highlight.js": {
717
+ packageName: "highlight.js",
718
+ defaultVersion: "11.10.0",
719
+ providers: {
720
+ cloudflare: {
721
+ url: "https://cdnjs.cloudflare.com/ajax/libs/highlight.js/11.10.0/highlight.min.js",
722
+ integrity: "sha512-6yoqbrcLAHDWAdQmiRlHG4+m0g/CT/V9AGyxabG8j7Jk8j3v3k6mIP1iN/PvSofcWet2tf8SRn/j3L/+pb7LRQ==",
723
+ global: "hljs",
724
+ crossorigin: "anonymous"
725
+ },
726
+ jsdelivr: {
727
+ url: "https://cdn.jsdelivr.net/npm/highlight.js@11.10.0/lib/core.min.js",
728
+ global: "hljs",
729
+ crossorigin: "anonymous"
730
+ },
731
+ unpkg: {
732
+ url: "https://unpkg.com/highlight.js@11.10.0/lib/core.min.js",
733
+ global: "hljs",
734
+ crossorigin: "anonymous"
735
+ }
736
+ },
737
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
738
+ metadata: {
739
+ description: "Syntax highlighting for the web",
740
+ homepage: "https://highlightjs.org",
741
+ license: "BSD-3-Clause"
742
+ }
743
+ },
744
+ // ============================================
745
+ // Interactive Libraries
746
+ // ============================================
747
+ "htmx.org": {
748
+ packageName: "htmx.org",
749
+ defaultVersion: "2.0.4",
750
+ providers: {
751
+ cloudflare: {
752
+ url: "https://cdnjs.cloudflare.com/ajax/libs/htmx/2.0.4/htmx.min.js",
753
+ integrity: "sha512-2kIcAizYXhIn5IyXrMC72f2nh0JAtESHRpOieVw5dYPYeHwLCC2eKCqvdZDYRSEgasKrPpEPpRFjL8gqwBZWAA==",
754
+ global: "htmx",
755
+ crossorigin: "anonymous"
756
+ },
757
+ jsdelivr: {
758
+ url: "https://cdn.jsdelivr.net/npm/htmx.org@2.0.4/dist/htmx.min.js",
759
+ global: "htmx",
760
+ crossorigin: "anonymous"
761
+ },
762
+ unpkg: {
763
+ url: "https://unpkg.com/htmx.org@2.0.4/dist/htmx.min.js",
764
+ global: "htmx",
765
+ crossorigin: "anonymous"
766
+ }
767
+ },
768
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
769
+ metadata: {
770
+ description: "High power tools for HTML",
771
+ homepage: "https://htmx.org",
772
+ license: "BSD-2-Clause"
773
+ }
774
+ },
775
+ alpinejs: {
776
+ packageName: "alpinejs",
777
+ defaultVersion: "3.14.3",
778
+ providers: {
779
+ cloudflare: {
780
+ url: "https://cdnjs.cloudflare.com/ajax/libs/alpinejs/3.14.3/cdn.min.js",
781
+ integrity: "sha512-lrQ8FHgsWKFSuQFq8NKPJicjlvJFEIrCqEj8zeX7ZOUlHWltN/Iow4jND+x84jqTdDf9n+hvQpJjGDvOl/eDRA==",
782
+ global: "Alpine",
783
+ crossorigin: "anonymous"
784
+ },
785
+ jsdelivr: {
786
+ url: "https://cdn.jsdelivr.net/npm/alpinejs@3.14.3/dist/cdn.min.js",
787
+ global: "Alpine",
788
+ crossorigin: "anonymous"
789
+ },
790
+ unpkg: {
791
+ url: "https://unpkg.com/alpinejs@3.14.3/dist/cdn.min.js",
792
+ global: "Alpine",
793
+ crossorigin: "anonymous"
794
+ }
795
+ },
796
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
797
+ metadata: {
798
+ description: "A rugged, minimal framework for composing behavior directly in your markup",
799
+ homepage: "https://alpinejs.dev",
800
+ license: "MIT"
801
+ }
802
+ },
803
+ // ============================================
804
+ // Templating Libraries
805
+ // ============================================
806
+ handlebars: {
807
+ packageName: "handlebars",
808
+ defaultVersion: "4.7.8",
809
+ providers: {
810
+ cloudflare: {
811
+ url: "https://cdnjs.cloudflare.com/ajax/libs/handlebars.js/4.7.8/handlebars.min.js",
812
+ integrity: "sha512-E1dSFxg+wsfJ4HKjutk/WaCzK7S2wv1POn1RRPGh8ZK+ag9l244Vqxji3r6wgz9YBf6+vhQEYJZpSjqWFPg9gg==",
813
+ global: "Handlebars",
814
+ crossorigin: "anonymous"
815
+ },
816
+ jsdelivr: {
817
+ url: "https://cdn.jsdelivr.net/npm/handlebars@4.7.8/dist/handlebars.min.js",
818
+ global: "Handlebars",
819
+ crossorigin: "anonymous"
820
+ },
821
+ unpkg: {
822
+ url: "https://unpkg.com/handlebars@4.7.8/dist/handlebars.min.js",
823
+ global: "Handlebars",
824
+ crossorigin: "anonymous"
825
+ }
826
+ },
827
+ preferredProviders: ["cloudflare", "jsdelivr", "unpkg"],
828
+ metadata: {
829
+ description: "Minimal templating on steroids",
830
+ homepage: "https://handlebarsjs.com",
831
+ license: "MIT"
832
+ }
833
+ }
834
+ };
835
+ var CDN_PROVIDER_PRIORITY = {
836
+ claude: ["cloudflare"],
837
+ // ONLY cloudflare for Claude
838
+ openai: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
839
+ cursor: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
840
+ gemini: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
841
+ continue: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
842
+ cody: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"],
843
+ unknown: ["cloudflare", "jsdelivr", "unpkg", "esm.sh"]
844
+ // Default to cloudflare first
845
+ };
846
+ function lookupPackage(packageName, registry = DEFAULT_CDN_REGISTRY) {
847
+ return registry[packageName];
848
+ }
849
+ function getPackageCDNUrl(packageName, platform = "unknown", registry = DEFAULT_CDN_REGISTRY) {
850
+ const entry = lookupPackage(packageName, registry);
851
+ if (!entry) return void 0;
852
+ const providerPriority = CDN_PROVIDER_PRIORITY[platform];
853
+ for (const provider of providerPriority) {
854
+ const config = entry.providers[provider];
855
+ if (config?.url) {
856
+ return config.url;
857
+ }
858
+ }
859
+ for (const provider of Object.keys(entry.providers)) {
860
+ const config = entry.providers[provider];
861
+ if (config?.url) {
862
+ return config.url;
863
+ }
864
+ }
865
+ return void 0;
866
+ }
867
+ function getPackageCDNDependency(packageName, platform = "unknown", registry = DEFAULT_CDN_REGISTRY) {
868
+ const entry = lookupPackage(packageName, registry);
869
+ if (!entry) return void 0;
870
+ const providerPriority = CDN_PROVIDER_PRIORITY[platform];
871
+ for (const provider of providerPriority) {
872
+ const config = entry.providers[provider];
873
+ if (config?.url) {
874
+ return { provider, dependency: config };
875
+ }
876
+ }
877
+ for (const provider of Object.keys(entry.providers)) {
878
+ const config = entry.providers[provider];
879
+ if (config?.url) {
880
+ return { provider, dependency: config };
881
+ }
882
+ }
883
+ return void 0;
884
+ }
885
+ function getRegisteredPackages(registry = DEFAULT_CDN_REGISTRY) {
886
+ return Object.keys(registry);
887
+ }
888
+ function isPackageRegistered(packageName, registry = DEFAULT_CDN_REGISTRY) {
889
+ return packageName in registry;
890
+ }
891
+ function mergeRegistries(customRegistry) {
892
+ return {
893
+ ...DEFAULT_CDN_REGISTRY,
894
+ ...customRegistry
895
+ };
896
+ }
897
+ function getPackagePeerDependencies(packageName, registry = DEFAULT_CDN_REGISTRY) {
898
+ const entry = lookupPackage(packageName, registry);
899
+ if (!entry) return [];
900
+ for (const provider of Object.keys(entry.providers)) {
901
+ const config = entry.providers[provider];
902
+ if (config?.peerDependencies) {
903
+ return config.peerDependencies;
904
+ }
905
+ }
906
+ return [];
907
+ }
908
+ function resolveAllDependencies(packageNames, platform = "unknown", registry = DEFAULT_CDN_REGISTRY) {
909
+ const resolved = /* @__PURE__ */ new Set();
910
+ const queue = [...packageNames];
911
+ while (queue.length > 0) {
912
+ const packageName = queue.shift();
913
+ if (!packageName) continue;
914
+ if (resolved.has(packageName)) continue;
915
+ resolved.add(packageName);
916
+ const peers = getPackagePeerDependencies(packageName, registry);
917
+ for (const peer of peers) {
918
+ if (!resolved.has(peer)) {
919
+ queue.push(peer);
920
+ }
921
+ }
922
+ }
923
+ const result = [];
924
+ const remaining = new Set(resolved);
925
+ while (remaining.size > 0) {
926
+ let added = false;
927
+ for (const pkg of remaining) {
928
+ const peers = getPackagePeerDependencies(pkg, registry);
929
+ const allPeersResolved = peers.every((peer) => !remaining.has(peer) || result.includes(peer));
930
+ if (allPeersResolved) {
931
+ if (!result.includes(pkg)) {
932
+ result.push(pkg);
933
+ }
934
+ remaining.delete(pkg);
935
+ added = true;
936
+ }
937
+ }
938
+ if (!added && remaining.size > 0) {
939
+ const next = remaining.values().next().value;
940
+ if (next !== void 0) {
941
+ if (!result.includes(next)) {
942
+ result.push(next);
943
+ }
944
+ remaining.delete(next);
945
+ }
946
+ }
947
+ }
948
+ return result;
949
+ }
950
+
951
+ // libs/uipack/src/dependency/import-parser.ts
952
+ var IMPORT_PATTERNS = {
953
+ /**
954
+ * Named imports: import { foo, bar } from 'module'
955
+ * Also handles renamed imports: import { foo as f } from 'module'
956
+ */
957
+ named: /import\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/g,
958
+ /**
959
+ * Default imports: import foo from 'module'
960
+ */
961
+ default: /import\s+(\w+)\s+from\s*['"]([^'"]+)['"]/g,
962
+ /**
963
+ * Namespace imports: import * as foo from 'module'
964
+ */
965
+ namespace: /import\s*\*\s*as\s+(\w+)\s+from\s*['"]([^'"]+)['"]/g,
966
+ /**
967
+ * Side-effect imports: import 'module'
968
+ */
969
+ sideEffect: /import\s*['"]([^'"]+)['"]/g,
970
+ /**
971
+ * Dynamic imports: import('module') or await import('module')
972
+ */
973
+ dynamic: /(?:await\s+)?import\s*\(\s*['"]([^'"]+)['"]\s*\)/g,
974
+ /**
975
+ * Combined default and named: import foo, { bar } from 'module'
976
+ */
977
+ defaultAndNamed: /import\s+(\w+)\s*,\s*\{([^}]+)\}\s*from\s*['"]([^'"]+)['"]/g,
978
+ /**
979
+ * Combined default and namespace: import foo, * as bar from 'module'
980
+ */
981
+ defaultAndNamespace: /import\s+(\w+)\s*,\s*\*\s*as\s+(\w+)\s+from\s*['"]([^'"]+)['"]/g,
982
+ /**
983
+ * Re-exports: export { foo } from 'module'
984
+ */
985
+ reExport: /export\s*\{[^}]+\}\s*from\s*['"]([^'"]+)['"]/g,
986
+ /**
987
+ * Re-export all: export * from 'module'
988
+ */
989
+ reExportAll: /export\s*\*\s*from\s*['"]([^'"]+)['"]/g
990
+ };
991
+ function parseNamedImports(namedString) {
992
+ return namedString.split(",").map((s) => s.trim()).filter((s) => s.length > 0).map((s) => {
993
+ const asMatch = s.match(/^(\w+)\s+as\s+\w+$/);
994
+ return asMatch ? asMatch[1] : s;
995
+ });
996
+ }
997
+ function isRelativeImport(specifier) {
998
+ return specifier.startsWith("./") || specifier.startsWith("../") || specifier.startsWith("/");
999
+ }
1000
+ function isExternalImport(specifier) {
1001
+ return !isRelativeImport(specifier) && !specifier.startsWith("#");
1002
+ }
1003
+ function getPackageName(specifier) {
1004
+ if (specifier.startsWith("@")) {
1005
+ const parts = specifier.split("/");
1006
+ if (parts.length >= 2) {
1007
+ return `${parts[0]}/${parts[1]}`;
1008
+ }
1009
+ return specifier;
1010
+ }
1011
+ const firstSlash = specifier.indexOf("/");
1012
+ return firstSlash === -1 ? specifier : specifier.slice(0, firstSlash);
1013
+ }
1014
+ function getLineNumber(source, index) {
1015
+ let line = 1;
1016
+ for (let i = 0; i < index && i < source.length; i++) {
1017
+ if (source[i] === "\n") {
1018
+ line++;
1019
+ }
1020
+ }
1021
+ return line;
1022
+ }
1023
+ function getColumnNumber(source, index) {
1024
+ let column = 0;
1025
+ for (let i = index - 1; i >= 0 && source[i] !== "\n"; i--) {
1026
+ column++;
1027
+ }
1028
+ return column;
1029
+ }
1030
+ function parseImports(source) {
1031
+ const imports = [];
1032
+ const seenStatements = /* @__PURE__ */ new Set();
1033
+ const addImport = (imp) => {
1034
+ const key = `${imp.type}:${imp.specifier}:${imp.statement}`;
1035
+ if (!seenStatements.has(key)) {
1036
+ seenStatements.add(key);
1037
+ imports.push(imp);
1038
+ }
1039
+ };
1040
+ let match;
1041
+ const defaultAndNamedRegex = new RegExp(IMPORT_PATTERNS.defaultAndNamed.source, "g");
1042
+ while ((match = defaultAndNamedRegex.exec(source)) !== null) {
1043
+ const [statement, defaultName, namedString, specifier] = match;
1044
+ const namedImports = parseNamedImports(namedString);
1045
+ addImport({
1046
+ statement,
1047
+ specifier,
1048
+ type: "default",
1049
+ defaultImport: defaultName,
1050
+ namedImports,
1051
+ line: getLineNumber(source, match.index),
1052
+ column: getColumnNumber(source, match.index)
1053
+ });
1054
+ }
1055
+ const defaultAndNamespaceRegex = new RegExp(IMPORT_PATTERNS.defaultAndNamespace.source, "g");
1056
+ while ((match = defaultAndNamespaceRegex.exec(source)) !== null) {
1057
+ const [statement, defaultName, namespaceName, specifier] = match;
1058
+ addImport({
1059
+ statement,
1060
+ specifier,
1061
+ type: "default",
1062
+ defaultImport: defaultName,
1063
+ namespaceImport: namespaceName,
1064
+ line: getLineNumber(source, match.index),
1065
+ column: getColumnNumber(source, match.index)
1066
+ });
1067
+ }
1068
+ const namedRegex = new RegExp(IMPORT_PATTERNS.named.source, "g");
1069
+ while ((match = namedRegex.exec(source)) !== null) {
1070
+ const [statement, namedString, specifier] = match;
1071
+ const namedImports = parseNamedImports(namedString);
1072
+ addImport({
1073
+ statement,
1074
+ specifier,
1075
+ type: "named",
1076
+ namedImports,
1077
+ line: getLineNumber(source, match.index),
1078
+ column: getColumnNumber(source, match.index)
1079
+ });
1080
+ }
1081
+ const defaultRegex = new RegExp(IMPORT_PATTERNS.default.source, "g");
1082
+ while ((match = defaultRegex.exec(source)) !== null) {
1083
+ const [statement, defaultName, specifier] = match;
1084
+ const afterMatch = source.slice(match.index + match[0].length - specifier.length - 2);
1085
+ if (afterMatch.startsWith(",")) continue;
1086
+ addImport({
1087
+ statement,
1088
+ specifier,
1089
+ type: "default",
1090
+ defaultImport: defaultName,
1091
+ line: getLineNumber(source, match.index),
1092
+ column: getColumnNumber(source, match.index)
1093
+ });
1094
+ }
1095
+ const namespaceRegex = new RegExp(IMPORT_PATTERNS.namespace.source, "g");
1096
+ while ((match = namespaceRegex.exec(source)) !== null) {
1097
+ const [statement, namespaceName, specifier] = match;
1098
+ addImport({
1099
+ statement,
1100
+ specifier,
1101
+ type: "namespace",
1102
+ namespaceImport: namespaceName,
1103
+ line: getLineNumber(source, match.index),
1104
+ column: getColumnNumber(source, match.index)
1105
+ });
1106
+ }
1107
+ const sideEffectRegex = new RegExp(IMPORT_PATTERNS.sideEffect.source, "g");
1108
+ while ((match = sideEffectRegex.exec(source)) !== null) {
1109
+ const [statement, specifier] = match;
1110
+ const beforeMatch = source.slice(Math.max(0, match.index - 50), match.index);
1111
+ if (beforeMatch.includes("from")) continue;
1112
+ addImport({
1113
+ statement,
1114
+ specifier,
1115
+ type: "side-effect",
1116
+ line: getLineNumber(source, match.index),
1117
+ column: getColumnNumber(source, match.index)
1118
+ });
1119
+ }
1120
+ const dynamicRegex = new RegExp(IMPORT_PATTERNS.dynamic.source, "g");
1121
+ while ((match = dynamicRegex.exec(source)) !== null) {
1122
+ const [statement, specifier] = match;
1123
+ addImport({
1124
+ statement,
1125
+ specifier,
1126
+ type: "dynamic",
1127
+ line: getLineNumber(source, match.index),
1128
+ column: getColumnNumber(source, match.index)
1129
+ });
1130
+ }
1131
+ const reExportRegex = new RegExp(IMPORT_PATTERNS.reExport.source, "g");
1132
+ while ((match = reExportRegex.exec(source)) !== null) {
1133
+ const [statement, specifier] = match;
1134
+ addImport({
1135
+ statement,
1136
+ specifier,
1137
+ type: "named",
1138
+ line: getLineNumber(source, match.index),
1139
+ column: getColumnNumber(source, match.index)
1140
+ });
1141
+ }
1142
+ const reExportAllRegex = new RegExp(IMPORT_PATTERNS.reExportAll.source, "g");
1143
+ while ((match = reExportAllRegex.exec(source)) !== null) {
1144
+ const [statement, specifier] = match;
1145
+ addImport({
1146
+ statement,
1147
+ specifier,
1148
+ type: "namespace",
1149
+ line: getLineNumber(source, match.index),
1150
+ column: getColumnNumber(source, match.index)
1151
+ });
1152
+ }
1153
+ const externalImports = imports.filter((imp) => isExternalImport(imp.specifier));
1154
+ const relativeImports = imports.filter((imp) => isRelativeImport(imp.specifier));
1155
+ const externalPackages = [...new Set(externalImports.map((imp) => getPackageName(imp.specifier)))];
1156
+ return {
1157
+ imports,
1158
+ externalImports,
1159
+ relativeImports,
1160
+ externalPackages
1161
+ };
1162
+ }
1163
+ function extractExternalPackages(source) {
1164
+ const result = parseImports(source);
1165
+ return result.externalPackages;
1166
+ }
1167
+ function filterImportsByPackages(result, packages) {
1168
+ const packageSet = new Set(packages);
1169
+ return result.externalImports.filter((imp) => {
1170
+ const pkgName = getPackageName(imp.specifier);
1171
+ return packageSet.has(pkgName);
1172
+ });
1173
+ }
1174
+ function getImportStats(source) {
1175
+ const result = parseImports(source);
1176
+ const byType = {
1177
+ named: 0,
1178
+ default: 0,
1179
+ namespace: 0,
1180
+ "side-effect": 0,
1181
+ dynamic: 0
1182
+ };
1183
+ for (const imp of result.imports) {
1184
+ byType[imp.type] = (byType[imp.type] || 0) + 1;
1185
+ }
1186
+ return {
1187
+ total: result.imports.length,
1188
+ external: result.externalImports.length,
1189
+ relative: result.relativeImports.length,
1190
+ byType,
1191
+ packages: result.externalPackages
1192
+ };
1193
+ }
1194
+
1195
+ // libs/uipack/src/utils/escape-html.ts
1196
+ function escapeHtml(str) {
1197
+ if (str === null || str === void 0) {
1198
+ return "";
1199
+ }
1200
+ const s = String(str);
1201
+ return s.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/"/g, "&quot;").replace(/'/g, "&#39;").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
1202
+ }
1203
+ function escapeHtmlAttr(str) {
1204
+ return str.replace(/&/g, "&amp;").replace(/"/g, "&quot;");
1205
+ }
1206
+
1207
+ // libs/uipack/src/dependency/import-map.ts
1208
+ function createImportMap(dependencies) {
1209
+ const imports = {};
1210
+ const integrity = {};
1211
+ for (const dep of dependencies) {
1212
+ imports[dep.packageName] = dep.cdnUrl;
1213
+ if (dep.integrity) {
1214
+ integrity[dep.cdnUrl] = dep.integrity;
1215
+ }
1216
+ }
1217
+ return {
1218
+ imports,
1219
+ integrity: Object.keys(integrity).length > 0 ? integrity : void 0
1220
+ };
1221
+ }
1222
+ function createImportMapFromOverrides(dependencies) {
1223
+ const imports = {};
1224
+ const integrity = {};
1225
+ for (const [pkgName, config] of Object.entries(dependencies)) {
1226
+ imports[pkgName] = config.url;
1227
+ if (config.integrity) {
1228
+ integrity[config.url] = config.integrity;
1229
+ }
1230
+ }
1231
+ return {
1232
+ imports,
1233
+ integrity: Object.keys(integrity).length > 0 ? integrity : void 0
1234
+ };
1235
+ }
1236
+ function mergeImportMaps(...maps) {
1237
+ const imports = {};
1238
+ const integrity = {};
1239
+ const scopes = {};
1240
+ for (const map of maps) {
1241
+ Object.assign(imports, map.imports);
1242
+ if (map.integrity) {
1243
+ Object.assign(integrity, map.integrity);
1244
+ }
1245
+ if (map.scopes) {
1246
+ for (const [scope, mappings] of Object.entries(map.scopes)) {
1247
+ scopes[scope] = { ...scopes[scope], ...mappings };
1248
+ }
1249
+ }
1250
+ }
1251
+ return {
1252
+ imports,
1253
+ integrity: Object.keys(integrity).length > 0 ? integrity : void 0,
1254
+ scopes: Object.keys(scopes).length > 0 ? scopes : void 0
1255
+ };
1256
+ }
1257
+ function addScope(map, scopeUrl, mappings) {
1258
+ return {
1259
+ ...map,
1260
+ scopes: {
1261
+ ...map.scopes,
1262
+ [scopeUrl]: { ...map.scopes?.[scopeUrl] ?? {}, ...mappings }
1263
+ }
1264
+ };
1265
+ }
1266
+ function generateImportMapScriptTag(map) {
1267
+ const json2 = JSON.stringify(map, null, 2).replace(/<\//g, "<\\/");
1268
+ return `<script type="importmap">
1269
+ ${json2}
1270
+ </script>`;
1271
+ }
1272
+ function generateImportMapScriptTagMinified(map) {
1273
+ const json2 = JSON.stringify(map).replace(/<\//g, "<\\/");
1274
+ return `<script type="importmap">${json2}</script>`;
1275
+ }
1276
+ function generateUMDShim(dependencies, options = {}) {
1277
+ const { safe = true, minify = false } = options;
1278
+ const depsWithGlobals = dependencies.filter((d) => d.global && !d.esm);
1279
+ if (depsWithGlobals.length === 0) {
1280
+ return "";
1281
+ }
1282
+ const entries = depsWithGlobals.map((dep) => {
1283
+ const global = dep.global;
1284
+ return `'${dep.packageName}': { default: window.${global}, ...window.${global} }`;
1285
+ });
1286
+ const shimObject = `{
1287
+ ${entries.join(",\n ")}
1288
+ }`;
1289
+ const code = safe ? `(function() {
1290
+ try {
1291
+ window.__esm_shim = ${shimObject};
1292
+ } catch (e) {
1293
+ console.warn('UMD shim failed:', e);
1294
+ }
1295
+ })();` : `window.__esm_shim = ${shimObject};`;
1296
+ return minify ? code.replace(/\s+/g, " ").replace(/\s*([{},:])\s*/g, "$1") : code;
1297
+ }
1298
+ function generateCDNScriptTags(dependencies) {
1299
+ return dependencies.filter((dep) => !dep.esm).map((dep) => {
1300
+ const attrs = [`src="${escapeHtmlAttr(dep.cdnUrl)}"`];
1301
+ if (dep.integrity) {
1302
+ attrs.push(`integrity="${escapeHtmlAttr(dep.integrity)}"`);
1303
+ }
1304
+ attrs.push('crossorigin="anonymous"');
1305
+ return `<script ${attrs.join(" ")}></script>`;
1306
+ });
1307
+ }
1308
+ function generateESMScriptTags(dependencies) {
1309
+ return dependencies.filter((dep) => dep.esm).map((dep) => {
1310
+ const attrs = ['type="module"', `src="${escapeHtmlAttr(dep.cdnUrl)}"`];
1311
+ if (dep.integrity) {
1312
+ attrs.push(`integrity="${escapeHtmlAttr(dep.integrity)}"`);
1313
+ }
1314
+ attrs.push('crossorigin="anonymous"');
1315
+ return `<script ${attrs.join(" ")}></script>`;
1316
+ });
1317
+ }
1318
+ function generateDependencyHTML(dependencies, options = {}) {
1319
+ const { minify = false, includeShim = true } = options;
1320
+ const parts = [];
1321
+ const importMap = createImportMap(dependencies);
1322
+ const importMapTag = minify ? generateImportMapScriptTagMinified(importMap) : generateImportMapScriptTag(importMap);
1323
+ parts.push(importMapTag);
1324
+ const umdTags = generateCDNScriptTags(dependencies);
1325
+ parts.push(...umdTags);
1326
+ if (includeShim) {
1327
+ const shim = generateUMDShim(dependencies, { minify });
1328
+ if (shim) {
1329
+ parts.push(`<script>${shim}</script>`);
1330
+ }
1331
+ }
1332
+ const esmTags = generateESMScriptTags(dependencies);
1333
+ parts.push(...esmTags);
1334
+ return parts.join(minify ? "" : "\n");
1335
+ }
1336
+ function validateImportMap(map) {
1337
+ const errors = [];
1338
+ if (typeof map !== "object" || map === null) {
1339
+ return { valid: false, errors: ["Import map must be an object"] };
1340
+ }
1341
+ const obj = map;
1342
+ if (!obj["imports"]) {
1343
+ errors.push('Import map must have an "imports" field');
1344
+ } else if (typeof obj["imports"] !== "object" || obj["imports"] === null) {
1345
+ errors.push('"imports" must be an object');
1346
+ } else {
1347
+ const imports = obj["imports"];
1348
+ for (const [key, value] of Object.entries(imports)) {
1349
+ if (typeof value !== "string") {
1350
+ errors.push(`Import "${key}" must map to a string URL`);
1351
+ } else if (!value.startsWith("https://")) {
1352
+ errors.push(`Import "${key}" URL must use HTTPS: ${value}`);
1353
+ }
1354
+ }
1355
+ }
1356
+ if (obj["integrity"] !== void 0) {
1357
+ if (typeof obj["integrity"] !== "object" || obj["integrity"] === null) {
1358
+ errors.push('"integrity" must be an object');
1359
+ } else {
1360
+ const integrity = obj["integrity"];
1361
+ for (const [url, hash] of Object.entries(integrity)) {
1362
+ if (typeof hash !== "string") {
1363
+ errors.push(`Integrity for "${url}" must be a string`);
1364
+ } else if (!hash.match(/^sha(256|384|512)-/)) {
1365
+ errors.push(`Invalid integrity hash format for "${url}": ${hash}`);
1366
+ }
1367
+ }
1368
+ }
1369
+ }
1370
+ if (obj["scopes"] !== void 0) {
1371
+ if (typeof obj["scopes"] !== "object" || obj["scopes"] === null) {
1372
+ errors.push('"scopes" must be an object');
1373
+ }
1374
+ }
1375
+ return { valid: errors.length === 0, errors };
1376
+ }
1377
+
1378
+ // libs/uipack/src/dependency/resolver.ts
1379
+ var DependencyResolutionError = class extends Error {
1380
+ constructor(packageName, reason) {
1381
+ super(`Failed to resolve dependency "${packageName}": ${reason}`);
1382
+ this.packageName = packageName;
1383
+ this.reason = reason;
1384
+ this.name = "DependencyResolutionError";
1385
+ }
1386
+ };
1387
+ var NoProviderError = class extends DependencyResolutionError {
1388
+ constructor(packageName, platform) {
1389
+ super(packageName, `No CDN provider available for platform "${platform}"`);
1390
+ this.platform = platform;
1391
+ this.name = "NoProviderError";
1392
+ }
1393
+ };
1394
+ var DependencyResolver = class {
1395
+ options;
1396
+ registry;
1397
+ constructor(options = {}) {
1398
+ this.options = {
1399
+ platform: options.platform ?? "unknown",
1400
+ preferredProviders: options.preferredProviders ?? CDN_PROVIDER_PRIORITY[options.platform ?? "unknown"],
1401
+ customRegistry: options.customRegistry ?? {},
1402
+ strictMode: options.strictMode ?? true,
1403
+ requireIntegrity: options.requireIntegrity ?? false
1404
+ };
1405
+ this.registry = mergeRegistries(this.options.customRegistry);
1406
+ }
1407
+ /**
1408
+ * Resolve a single package to its CDN dependency.
1409
+ *
1410
+ * @param packageName - NPM package name
1411
+ * @param override - Optional explicit CDN dependency override
1412
+ * @returns Resolved dependency, or null in non-strict mode if package is not found (should be bundled)
1413
+ * @throws DependencyResolutionError if package cannot be resolved in strict mode
1414
+ */
1415
+ resolve(packageName, override) {
1416
+ if (override) {
1417
+ return this.createResolvedDependency(packageName, override, "custom");
1418
+ }
1419
+ const entry = lookupPackage(packageName, this.registry);
1420
+ if (!entry) {
1421
+ if (this.options.strictMode) {
1422
+ throw new DependencyResolutionError(
1423
+ packageName,
1424
+ 'Package not found in CDN registry. Add it to "dependencies" for explicit CDN configuration.'
1425
+ );
1426
+ }
1427
+ return null;
1428
+ }
1429
+ const providerPriority = this.options.preferredProviders;
1430
+ for (const provider of providerPriority) {
1431
+ const config = entry.providers[provider];
1432
+ if (config?.url) {
1433
+ if (this.options.requireIntegrity && !config.integrity) {
1434
+ continue;
1435
+ }
1436
+ return this.createResolvedDependency(packageName, config, provider, entry.defaultVersion);
1437
+ }
1438
+ }
1439
+ throw new NoProviderError(packageName, this.options.platform);
1440
+ }
1441
+ /**
1442
+ * Resolve multiple packages.
1443
+ *
1444
+ * @param packageNames - Array of package names
1445
+ * @param overrides - Optional explicit overrides for specific packages
1446
+ * @returns Array of resolved dependencies (in dependency order)
1447
+ */
1448
+ resolveMany(packageNames, overrides) {
1449
+ const allPackages = resolveAllDependencies(packageNames, this.options.platform, this.registry);
1450
+ const resolved = [];
1451
+ for (const pkgName of allPackages) {
1452
+ try {
1453
+ const override = overrides?.[pkgName];
1454
+ const dep = this.resolve(pkgName, override);
1455
+ if (dep) {
1456
+ resolved.push(dep);
1457
+ }
1458
+ } catch (error) {
1459
+ if (this.options.strictMode) {
1460
+ throw error;
1461
+ }
1462
+ }
1463
+ }
1464
+ return resolved;
1465
+ }
1466
+ /**
1467
+ * Resolve dependencies from source code.
1468
+ *
1469
+ * Parses the source to extract imports, then resolves external packages
1470
+ * that are in the externals list.
1471
+ *
1472
+ * @param source - Source code to parse
1473
+ * @param externals - Package names to resolve from CDN (others are bundled)
1474
+ * @param overrides - Optional explicit CDN overrides
1475
+ * @returns Resolved dependencies
1476
+ */
1477
+ resolveFromSource(source, externals, overrides) {
1478
+ const parseResult = parseImports(source);
1479
+ const packagesToResolve = parseResult.externalPackages.filter((pkg) => externals.includes(pkg));
1480
+ return this.resolveMany(packagesToResolve, overrides);
1481
+ }
1482
+ /**
1483
+ * Generate an import map for resolved dependencies.
1484
+ *
1485
+ * @param dependencies - Resolved dependencies
1486
+ * @returns Browser import map
1487
+ */
1488
+ generateImportMap(dependencies) {
1489
+ return createImportMap(dependencies);
1490
+ }
1491
+ /**
1492
+ * Check if a package can be resolved for the current platform.
1493
+ *
1494
+ * @param packageName - Package name to check
1495
+ * @returns true if the package can be resolved
1496
+ */
1497
+ canResolve(packageName) {
1498
+ try {
1499
+ const result = this.resolve(packageName);
1500
+ return result !== null;
1501
+ } catch {
1502
+ return false;
1503
+ }
1504
+ }
1505
+ /**
1506
+ * Get the resolved CDN URL for a package.
1507
+ *
1508
+ * @param packageName - Package name
1509
+ * @param override - Optional explicit override
1510
+ * @returns CDN URL or undefined if cannot resolve
1511
+ */
1512
+ getUrl(packageName, override) {
1513
+ try {
1514
+ const resolved = this.resolve(packageName, override);
1515
+ return resolved?.cdnUrl;
1516
+ } catch {
1517
+ return void 0;
1518
+ }
1519
+ }
1520
+ /**
1521
+ * Get peer dependencies for a package.
1522
+ */
1523
+ getPeerDependencies(packageName) {
1524
+ return getPackagePeerDependencies(packageName, this.registry);
1525
+ }
1526
+ /**
1527
+ * Create the current registry (default + custom).
1528
+ */
1529
+ getRegistry() {
1530
+ return this.registry;
1531
+ }
1532
+ /**
1533
+ * Get the current platform.
1534
+ */
1535
+ getPlatform() {
1536
+ return this.options.platform;
1537
+ }
1538
+ /**
1539
+ * Create a resolved dependency object.
1540
+ */
1541
+ createResolvedDependency(packageName, config, provider, version) {
1542
+ return {
1543
+ packageName,
1544
+ version: version ?? this.extractVersionFromUrl(config.url) ?? "latest",
1545
+ cdnUrl: config.url,
1546
+ integrity: config.integrity,
1547
+ global: config.global,
1548
+ esm: config.esm ?? false,
1549
+ provider
1550
+ };
1551
+ }
1552
+ /**
1553
+ * Try to extract version from CDN URL.
1554
+ */
1555
+ extractVersionFromUrl(url) {
1556
+ const versionMatch = url.match(/@(\d+\.\d+\.\d+(?:-[\w.]+)?)/);
1557
+ if (versionMatch) {
1558
+ return versionMatch[1];
1559
+ }
1560
+ const versionMatch2 = url.match(/\/v?(\d+\.\d+\.\d+)\//);
1561
+ if (versionMatch2) {
1562
+ return versionMatch2[1];
1563
+ }
1564
+ return void 0;
1565
+ }
1566
+ };
1567
+ function createResolver(platform, options) {
1568
+ return new DependencyResolver({
1569
+ platform,
1570
+ ...options
1571
+ });
1572
+ }
1573
+ function createClaudeResolver(options) {
1574
+ return createResolver("claude", options);
1575
+ }
1576
+ function createOpenAIResolver(options) {
1577
+ return createResolver("openai", options);
1578
+ }
1579
+ function resolveDependencies(source, externals, options) {
1580
+ const resolver = new DependencyResolver(options);
1581
+ return resolver.resolveFromSource(source, externals);
1582
+ }
1583
+ function generateImportMapForPackages(externals, options) {
1584
+ const resolver = new DependencyResolver(options);
1585
+ const resolved = resolver.resolveMany(externals);
1586
+ return resolver.generateImportMap(resolved);
1587
+ }
1588
+
1589
+ // libs/uipack/src/dependency/template-loader.ts
1590
+ var import_fs = require("fs");
1591
+ var import_path = require("path");
1592
+
1593
+ // libs/uipack/src/bundler/file-cache/hash-calculator.ts
1594
+ var import_crypto = require("crypto");
1595
+ function sha256(content) {
1596
+ return (0, import_crypto.createHash)("sha256").update(content, "utf8").digest("hex");
1597
+ }
1598
+
1599
+ // libs/uipack/src/dependency/template-loader.ts
1600
+ var urlCache = /* @__PURE__ */ new Map();
1601
+ function getUrlCache() {
1602
+ return urlCache;
1603
+ }
1604
+ function clearUrlCache() {
1605
+ urlCache.clear();
1606
+ }
1607
+ function detectTemplateSource(template) {
1608
+ const mode = detectTemplateMode(template);
1609
+ switch (mode) {
1610
+ case "url":
1611
+ return { type: "url", url: template };
1612
+ case "file-path":
1613
+ return { type: "file", path: template };
1614
+ case "inline-string":
1615
+ case "inline-function":
1616
+ default:
1617
+ return { type: "inline", content: template };
1618
+ }
1619
+ }
1620
+ function isFileBasedTemplate(mode) {
1621
+ return mode === "file-path" || mode === "url";
1622
+ }
1623
+ function validateTemplateUrl(url) {
1624
+ const parsed = new URL(url);
1625
+ if (parsed.protocol !== "https:") {
1626
+ throw new Error(`Template URLs must use HTTPS. Got: ${parsed.protocol}`);
1627
+ }
1628
+ }
1629
+ function detectFormatFromUrl(url) {
1630
+ const parsed = new URL(url);
1631
+ return detectFormatFromPath(parsed.pathname);
1632
+ }
1633
+ async function fetchTemplateFromUrl(url, options = {}) {
1634
+ validateTemplateUrl(url);
1635
+ const { timeout = 3e4, skipCache = false, headers: customHeaders = {} } = options;
1636
+ if (!skipCache) {
1637
+ const cached = urlCache.get(url);
1638
+ if (cached?.etag) {
1639
+ const headers = {
1640
+ ...customHeaders,
1641
+ "If-None-Match": cached.etag
1642
+ };
1643
+ const controller2 = new AbortController();
1644
+ const timeoutId2 = setTimeout(() => controller2.abort(), timeout);
1645
+ try {
1646
+ const response = await fetch(url, {
1647
+ headers,
1648
+ signal: controller2.signal
1649
+ });
1650
+ clearTimeout(timeoutId2);
1651
+ if (response.status === 304) {
1652
+ return cached;
1653
+ }
1654
+ return await processFetchResponse(url, response);
1655
+ } catch (error) {
1656
+ clearTimeout(timeoutId2);
1657
+ if (error instanceof Error && error.name === "AbortError") {
1658
+ throw new Error(`Template fetch timed out after ${timeout}ms: ${url}`);
1659
+ }
1660
+ throw error;
1661
+ }
1662
+ }
1663
+ }
1664
+ const controller = new AbortController();
1665
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
1666
+ try {
1667
+ const response = await fetch(url, {
1668
+ headers: customHeaders,
1669
+ signal: controller.signal
1670
+ });
1671
+ clearTimeout(timeoutId);
1672
+ return await processFetchResponse(url, response);
1673
+ } catch (error) {
1674
+ clearTimeout(timeoutId);
1675
+ if (error instanceof Error && error.name === "AbortError") {
1676
+ throw new Error(`Template fetch timed out after ${timeout}ms: ${url}`);
1677
+ }
1678
+ throw error;
1679
+ }
1680
+ }
1681
+ async function processFetchResponse(url, response) {
1682
+ if (!response.ok) {
1683
+ throw new Error(`Failed to fetch template: ${response.status} ${response.statusText} - ${url}`);
1684
+ }
1685
+ const content = await response.text();
1686
+ const etag = response.headers.get("etag") ?? void 0;
1687
+ const contentType = response.headers.get("content-type") ?? void 0;
1688
+ const result = {
1689
+ content,
1690
+ etag,
1691
+ contentType,
1692
+ fetchedAt: (/* @__PURE__ */ new Date()).toISOString()
1693
+ };
1694
+ urlCache.set(url, result);
1695
+ return result;
1696
+ }
1697
+ async function readTemplateFromFile(filePath, options = {}) {
1698
+ const { basePath = process.cwd(), encoding = "utf-8" } = options;
1699
+ const absolutePath = (0, import_path.isAbsolute)(filePath) ? filePath : (0, import_path.resolve)(basePath, filePath);
1700
+ const normalizedBase = (0, import_path.resolve)(basePath);
1701
+ if (!absolutePath.startsWith(normalizedBase + import_path.sep) && absolutePath !== normalizedBase) {
1702
+ throw new Error(`Template path escapes base directory: ${filePath}`);
1703
+ }
1704
+ try {
1705
+ return await import_fs.promises.readFile(absolutePath, encoding);
1706
+ } catch (error) {
1707
+ const err = error;
1708
+ if (err.code === "ENOENT") {
1709
+ throw new Error(`Template file not found: ${absolutePath}`);
1710
+ }
1711
+ if (err.code === "EACCES") {
1712
+ throw new Error(`Permission denied reading template file: ${absolutePath}`);
1713
+ }
1714
+ throw new Error(`Failed to read template file: ${absolutePath} - ${err.message}`);
1715
+ }
1716
+ }
1717
+ function resolveFilePath(filePath, basePath = process.cwd()) {
1718
+ return (0, import_path.isAbsolute)(filePath) ? filePath : (0, import_path.resolve)(basePath, filePath);
1719
+ }
1720
+ async function resolveTemplate(template, options = {}) {
1721
+ const { basePath = process.cwd(), skipCache = false, timeout = 3e4, format: overrideFormat } = options;
1722
+ const source = detectTemplateSource(template);
1723
+ let content;
1724
+ let format;
1725
+ let metadata = {};
1726
+ switch (source.type) {
1727
+ case "inline":
1728
+ content = source.content;
1729
+ format = overrideFormat ?? "html";
1730
+ break;
1731
+ case "file": {
1732
+ const absolutePath = resolveFilePath(source.path, basePath);
1733
+ content = await readTemplateFromFile(absolutePath);
1734
+ format = overrideFormat ?? detectFormatFromPath(source.path);
1735
+ metadata.resolvedPath = absolutePath;
1736
+ break;
1737
+ }
1738
+ case "url": {
1739
+ const fetchResult = await fetchTemplateFromUrl(source.url, {
1740
+ skipCache,
1741
+ timeout
1742
+ });
1743
+ content = fetchResult.content;
1744
+ format = overrideFormat ?? detectFormatFromUrl(source.url);
1745
+ metadata = {
1746
+ fetchedAt: fetchResult.fetchedAt,
1747
+ etag: fetchResult.etag,
1748
+ contentType: fetchResult.contentType
1749
+ };
1750
+ break;
1751
+ }
1752
+ }
1753
+ const hash = sha256(content);
1754
+ return {
1755
+ source,
1756
+ format,
1757
+ content,
1758
+ hash,
1759
+ metadata: Object.keys(metadata).length > 0 ? metadata : void 0
1760
+ };
1761
+ }
1762
+ var URL_CACHE_TTL_MS = 5 * 60 * 1e3;
1763
+ function needsRefetch(resolved) {
1764
+ if (resolved.source.type !== "url") {
1765
+ return false;
1766
+ }
1767
+ const cached = urlCache.get(resolved.source.url);
1768
+ if (!cached) {
1769
+ return true;
1770
+ }
1771
+ if (cached.etag) {
1772
+ return false;
1773
+ }
1774
+ if (cached.fetchedAt) {
1775
+ const fetchedTime = new Date(cached.fetchedAt).getTime();
1776
+ const age = Date.now() - fetchedTime;
1777
+ return age > URL_CACHE_TTL_MS;
1778
+ }
1779
+ return true;
1780
+ }
1781
+ function invalidateUrlCache(url) {
1782
+ return urlCache.delete(url);
1783
+ }
1784
+
1785
+ // libs/uipack/src/handlebars/helpers.ts
1786
+ function formatDate(date, format) {
1787
+ if (date === null || date === void 0) {
1788
+ return "";
1789
+ }
1790
+ let dateObj;
1791
+ if (date instanceof Date) {
1792
+ dateObj = date;
1793
+ } else if (typeof date === "string" || typeof date === "number") {
1794
+ dateObj = new Date(date);
1795
+ } else {
1796
+ return String(date);
1797
+ }
1798
+ if (isNaN(dateObj.getTime())) {
1799
+ return String(date);
1800
+ }
1801
+ const options = {};
1802
+ switch (format) {
1803
+ case "short":
1804
+ options.dateStyle = "short";
1805
+ break;
1806
+ case "medium":
1807
+ options.dateStyle = "medium";
1808
+ break;
1809
+ case "long":
1810
+ options.dateStyle = "long";
1811
+ break;
1812
+ case "full":
1813
+ options.dateStyle = "full";
1814
+ break;
1815
+ case "time":
1816
+ options.timeStyle = "short";
1817
+ break;
1818
+ case "datetime":
1819
+ options.dateStyle = "medium";
1820
+ options.timeStyle = "short";
1821
+ break;
1822
+ case "iso":
1823
+ return dateObj.toISOString();
1824
+ case "relative":
1825
+ return formatRelativeDate(dateObj);
1826
+ default:
1827
+ options.dateStyle = "medium";
1828
+ }
1829
+ return new Intl.DateTimeFormat("en-US", options).format(dateObj);
1830
+ }
1831
+ function formatRelativeDate(date) {
1832
+ const now = /* @__PURE__ */ new Date();
1833
+ const diffMs = now.getTime() - date.getTime();
1834
+ const diffSecs = Math.floor(diffMs / 1e3);
1835
+ const diffMins = Math.floor(diffSecs / 60);
1836
+ const diffHours = Math.floor(diffMins / 60);
1837
+ const diffDays = Math.floor(diffHours / 24);
1838
+ if (diffSecs < 60) {
1839
+ return "just now";
1840
+ } else if (diffMins < 60) {
1841
+ return `${diffMins} minute${diffMins === 1 ? "" : "s"} ago`;
1842
+ } else if (diffHours < 24) {
1843
+ return `${diffHours} hour${diffHours === 1 ? "" : "s"} ago`;
1844
+ } else if (diffDays < 7) {
1845
+ return `${diffDays} day${diffDays === 1 ? "" : "s"} ago`;
1846
+ } else {
1847
+ return formatDate(date, "medium");
1848
+ }
1849
+ }
1850
+ function formatCurrency(amount, currency) {
1851
+ if (amount === null || amount === void 0) {
1852
+ return "";
1853
+ }
1854
+ const num = typeof amount === "number" ? amount : parseFloat(String(amount));
1855
+ if (isNaN(num)) {
1856
+ return String(amount);
1857
+ }
1858
+ return new Intl.NumberFormat("en-US", {
1859
+ style: "currency",
1860
+ currency: typeof currency === "string" ? currency : "USD"
1861
+ }).format(num);
1862
+ }
1863
+ function formatNumber(value, decimals) {
1864
+ if (value === null || value === void 0) {
1865
+ return "";
1866
+ }
1867
+ const num = typeof value === "number" ? value : parseFloat(String(value));
1868
+ if (isNaN(num)) {
1869
+ return String(value);
1870
+ }
1871
+ const options = {};
1872
+ if (typeof decimals === "number") {
1873
+ options.minimumFractionDigits = decimals;
1874
+ options.maximumFractionDigits = decimals;
1875
+ }
1876
+ return new Intl.NumberFormat("en-US", options).format(num);
1877
+ }
1878
+ function jsonEmbed(data) {
1879
+ const json2 = JSON.stringify(data ?? null);
1880
+ return json2.replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026").replace(/\u2028/g, "\\u2028").replace(/\u2029/g, "\\u2029");
1881
+ }
1882
+ function json(data, pretty) {
1883
+ return JSON.stringify(data ?? null, null, pretty ? 2 : void 0);
1884
+ }
1885
+ function eq(a, b) {
1886
+ return a === b;
1887
+ }
1888
+ function ne(a, b) {
1889
+ return a !== b;
1890
+ }
1891
+ function gt(a, b) {
1892
+ return Number(a) > Number(b);
1893
+ }
1894
+ function gte(a, b) {
1895
+ return Number(a) >= Number(b);
1896
+ }
1897
+ function lt(a, b) {
1898
+ return Number(a) < Number(b);
1899
+ }
1900
+ function lte(a, b) {
1901
+ return Number(a) <= Number(b);
1902
+ }
1903
+ function and(a, b) {
1904
+ return Boolean(a) && Boolean(b);
1905
+ }
1906
+ function or(a, b) {
1907
+ return Boolean(a) || Boolean(b);
1908
+ }
1909
+ function not(value) {
1910
+ return !value;
1911
+ }
1912
+ function first(arr) {
1913
+ if (!Array.isArray(arr)) return void 0;
1914
+ return arr[0];
1915
+ }
1916
+ function last(arr) {
1917
+ if (!Array.isArray(arr)) return void 0;
1918
+ return arr[arr.length - 1];
1919
+ }
1920
+ function length(value) {
1921
+ if (Array.isArray(value)) return value.length;
1922
+ if (typeof value === "string") return value.length;
1923
+ return 0;
1924
+ }
1925
+ function includes(arr, value) {
1926
+ if (!Array.isArray(arr)) return false;
1927
+ return arr.includes(value);
1928
+ }
1929
+ function join(arr, separator) {
1930
+ if (!Array.isArray(arr)) return "";
1931
+ return arr.join(typeof separator === "string" ? separator : ", ");
1932
+ }
1933
+ function uppercase(str) {
1934
+ return String(str ?? "").toUpperCase();
1935
+ }
1936
+ function lowercase(str) {
1937
+ return String(str ?? "").toLowerCase();
1938
+ }
1939
+ function capitalize(str) {
1940
+ const s = String(str ?? "");
1941
+ return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
1942
+ }
1943
+ function truncate(str, maxLength, suffix) {
1944
+ const s = String(str ?? "");
1945
+ const len = typeof maxLength === "number" ? maxLength : 50;
1946
+ const suf = typeof suffix === "string" ? suffix : "...";
1947
+ if (s.length <= len) return s;
1948
+ return s.slice(0, len - suf.length) + suf;
1949
+ }
1950
+ function defaultValue(value, defaultValue2) {
1951
+ return value || defaultValue2;
1952
+ }
1953
+ var idCounter = 0;
1954
+ function uniqueId(prefix) {
1955
+ const id = ++idCounter;
1956
+ return prefix ? `${prefix}-${id}` : `id-${id}`;
1957
+ }
1958
+ function classNames(...classes) {
1959
+ return classes.filter(Boolean).map(String).join(" ");
1960
+ }
1961
+ var builtinHelpers = {
1962
+ // Escaping
1963
+ escapeHtml,
1964
+ // Formatting
1965
+ formatDate,
1966
+ formatCurrency,
1967
+ formatNumber,
1968
+ json,
1969
+ jsonEmbed,
1970
+ // Comparison
1971
+ eq,
1972
+ ne,
1973
+ gt,
1974
+ gte,
1975
+ lt,
1976
+ lte,
1977
+ // Logical
1978
+ and,
1979
+ or,
1980
+ not,
1981
+ // Array
1982
+ first,
1983
+ last,
1984
+ length,
1985
+ includes,
1986
+ join,
1987
+ // String
1988
+ uppercase,
1989
+ lowercase,
1990
+ capitalize,
1991
+ truncate,
1992
+ // Utility
1993
+ default: defaultValue,
1994
+ uniqueId,
1995
+ classNames
1996
+ };
1997
+
1998
+ // libs/uipack/src/handlebars/expression-extractor.ts
1999
+ var EXPRESSION_REGEX = /\{\{\{?(?!!)(#|\/)?([^}]+?)\}?\}\}/g;
2000
+ var PATH_REGEX = /\b(output|input|structuredContent)(\.[a-zA-Z_$][a-zA-Z0-9_$]*|\.\[[^\]]+\])+/g;
2001
+ var KEYWORDS = /* @__PURE__ */ new Set(["this", "else", "@index", "@key", "@first", "@last", "@root"]);
2002
+ function extractExpressions(template) {
2003
+ const expressions = [];
2004
+ const lines = template.split("\n");
2005
+ const positionMap = buildPositionMap(template);
2006
+ let match;
2007
+ EXPRESSION_REGEX.lastIndex = 0;
2008
+ while ((match = EXPRESSION_REGEX.exec(template)) !== null) {
2009
+ const fullExpression = match[0];
2010
+ const prefix = match[1];
2011
+ const content = match[2].trim();
2012
+ const position = positionMap.get(match.index) ?? { line: 1, column: 1 };
2013
+ let type = "variable";
2014
+ let helperName;
2015
+ if (prefix === "/") {
2016
+ type = "block-close";
2017
+ helperName = content;
2018
+ } else if (prefix === "#") {
2019
+ type = "block";
2020
+ const parts = content.split(/\s+/);
2021
+ helperName = parts[0];
2022
+ } else {
2023
+ const parts = content.split(/\s+/);
2024
+ if (parts.length > 1 && !content.startsWith("(")) {
2025
+ const firstToken = parts[0];
2026
+ if (!firstToken.includes(".") && !KEYWORDS.has(firstToken)) {
2027
+ type = "helper";
2028
+ helperName = firstToken;
2029
+ }
2030
+ }
2031
+ }
2032
+ const paths = extractPathsFromContent(content);
2033
+ for (const path of paths) {
2034
+ expressions.push({
2035
+ path,
2036
+ fullExpression,
2037
+ line: position.line,
2038
+ column: position.column,
2039
+ type,
2040
+ helperName
2041
+ });
2042
+ }
2043
+ if (paths.length === 0 && type === "variable") {
2044
+ const cleanContent = content.trim();
2045
+ if (!KEYWORDS.has(cleanContent) && !cleanContent.includes(" ") && !cleanContent.startsWith("(")) {
2046
+ }
2047
+ }
2048
+ }
2049
+ return expressions;
2050
+ }
2051
+ function extractPathsFromContent(content) {
2052
+ const paths = [];
2053
+ let match;
2054
+ const regex = new RegExp(PATH_REGEX.source, "g");
2055
+ while ((match = regex.exec(content)) !== null) {
2056
+ paths.push(match[0]);
2057
+ }
2058
+ return paths;
2059
+ }
2060
+ function buildPositionMap(template) {
2061
+ const map = /* @__PURE__ */ new Map();
2062
+ let line = 1;
2063
+ let column = 1;
2064
+ for (let i = 0; i < template.length; i++) {
2065
+ map.set(i, { line, column });
2066
+ if (template[i] === "\n") {
2067
+ line++;
2068
+ column = 1;
2069
+ } else {
2070
+ column++;
2071
+ }
2072
+ }
2073
+ return map;
2074
+ }
2075
+ function extractAll(template) {
2076
+ const expressions = extractExpressions(template);
2077
+ const paths = [...new Set(expressions.map((e) => e.path))];
2078
+ return {
2079
+ expressions,
2080
+ paths,
2081
+ outputPaths: paths.filter((p) => p.startsWith("output.")),
2082
+ inputPaths: paths.filter((p) => p.startsWith("input.")),
2083
+ structuredContentPaths: paths.filter((p) => p.startsWith("structuredContent."))
2084
+ };
2085
+ }
2086
+ function normalizePath(path) {
2087
+ return path.replace(/\.\d+\./g, ".[].").replace(/\.\d+$/g, ".[]").replace(/\[\d+\]/g, ".[]");
2088
+ }
2089
+
2090
+ // libs/uipack/src/handlebars/index.ts
2091
+ var Handlebars = null;
2092
+ async function loadHandlebars() {
2093
+ if (Handlebars !== null) {
2094
+ return Handlebars;
2095
+ }
2096
+ try {
2097
+ Handlebars = await import("handlebars");
2098
+ return Handlebars;
2099
+ } catch {
2100
+ throw new Error("Handlebars is required for template rendering. Install it: npm install handlebars");
2101
+ }
2102
+ }
2103
+ var HandlebarsRenderer = class {
2104
+ options;
2105
+ compiledTemplates = /* @__PURE__ */ new Map();
2106
+ initialized = false;
2107
+ hbs = null;
2108
+ constructor(options = {}) {
2109
+ this.options = {
2110
+ strict: false,
2111
+ autoEscape: true,
2112
+ ...options
2113
+ };
2114
+ }
2115
+ /**
2116
+ * Initialize the renderer with Handlebars.
2117
+ */
2118
+ async init() {
2119
+ if (this.initialized) return;
2120
+ this.hbs = await loadHandlebars();
2121
+ for (const [name, helper] of Object.entries(builtinHelpers)) {
2122
+ this.hbs.registerHelper(name, helper);
2123
+ }
2124
+ if (this.options.helpers) {
2125
+ for (const [name, helper] of Object.entries(this.options.helpers)) {
2126
+ this.hbs.registerHelper(name, helper);
2127
+ }
2128
+ }
2129
+ if (this.options.partials) {
2130
+ for (const [name, template] of Object.entries(this.options.partials)) {
2131
+ this.hbs.registerPartial(name, template);
2132
+ }
2133
+ }
2134
+ this.initialized = true;
2135
+ }
2136
+ /**
2137
+ * Render a Handlebars template.
2138
+ *
2139
+ * @param template - Template string
2140
+ * @param context - Render context with input/output
2141
+ * @returns Rendered HTML string
2142
+ */
2143
+ async render(template, context) {
2144
+ await this.init();
2145
+ if (!this.hbs) {
2146
+ throw new Error("Handlebars not initialized");
2147
+ }
2148
+ let compiled = this.compiledTemplates.get(template);
2149
+ if (!compiled) {
2150
+ compiled = this.hbs.compile(template, {
2151
+ strict: this.options.strict,
2152
+ noEscape: !this.options.autoEscape
2153
+ });
2154
+ this.compiledTemplates.set(template, compiled);
2155
+ }
2156
+ const data = {
2157
+ input: context.input ?? {},
2158
+ output: context.output ?? {},
2159
+ structuredContent: context.structuredContent,
2160
+ // Also expose at root level for convenience
2161
+ ...context.input,
2162
+ ...typeof context.output === "object" && context.output !== null ? context.output : {}
2163
+ };
2164
+ try {
2165
+ return compiled(data);
2166
+ } catch (error) {
2167
+ throw new Error(`Template rendering failed: ${error instanceof Error ? error.message : String(error)}`);
2168
+ }
2169
+ }
2170
+ /**
2171
+ * Render a template synchronously.
2172
+ *
2173
+ * Note: Requires Handlebars to be pre-loaded. Use `render()` for async loading.
2174
+ *
2175
+ * @param template - Template string
2176
+ * @param context - Render context
2177
+ * @returns Rendered HTML string
2178
+ */
2179
+ renderSync(template, context) {
2180
+ if (!this.initialized || !this.hbs) {
2181
+ throw new Error("HandlebarsRenderer not initialized. Call render() first or use initSync().");
2182
+ }
2183
+ let compiled = this.compiledTemplates.get(template);
2184
+ if (!compiled) {
2185
+ compiled = this.hbs.compile(template, {
2186
+ strict: this.options.strict,
2187
+ noEscape: !this.options.autoEscape
2188
+ });
2189
+ this.compiledTemplates.set(template, compiled);
2190
+ }
2191
+ const data = {
2192
+ input: context.input ?? {},
2193
+ output: context.output ?? {},
2194
+ structuredContent: context.structuredContent,
2195
+ ...context.input,
2196
+ ...typeof context.output === "object" && context.output !== null ? context.output : {}
2197
+ };
2198
+ return compiled(data);
2199
+ }
2200
+ /**
2201
+ * Initialize synchronously (for environments where Handlebars is already loaded).
2202
+ */
2203
+ initSync(handlebars) {
2204
+ this.hbs = handlebars;
2205
+ for (const [name, helper] of Object.entries(builtinHelpers)) {
2206
+ this.hbs.registerHelper(name, helper);
2207
+ }
2208
+ if (this.options.helpers) {
2209
+ for (const [name, helper] of Object.entries(this.options.helpers)) {
2210
+ this.hbs.registerHelper(name, helper);
2211
+ }
2212
+ }
2213
+ if (this.options.partials) {
2214
+ for (const [name, template] of Object.entries(this.options.partials)) {
2215
+ this.hbs.registerPartial(name, template);
2216
+ }
2217
+ }
2218
+ this.initialized = true;
2219
+ }
2220
+ /**
2221
+ * Register a custom helper.
2222
+ *
2223
+ * @param name - Helper name
2224
+ * @param fn - Helper function
2225
+ */
2226
+ registerHelper(name, fn) {
2227
+ if (this.hbs) {
2228
+ this.hbs.registerHelper(name, fn);
2229
+ }
2230
+ if (!this.options.helpers) {
2231
+ this.options.helpers = {};
2232
+ }
2233
+ this.options.helpers[name] = fn;
2234
+ }
2235
+ /**
2236
+ * Register a partial template.
2237
+ *
2238
+ * @param name - Partial name
2239
+ * @param template - Partial template string
2240
+ */
2241
+ registerPartial(name, template) {
2242
+ if (this.hbs) {
2243
+ this.hbs.registerPartial(name, template);
2244
+ }
2245
+ if (!this.options.partials) {
2246
+ this.options.partials = {};
2247
+ }
2248
+ this.options.partials[name] = template;
2249
+ }
2250
+ /**
2251
+ * Clear compiled template cache.
2252
+ */
2253
+ clearCache() {
2254
+ this.compiledTemplates.clear();
2255
+ }
2256
+ /**
2257
+ * Check if a template string contains Handlebars syntax.
2258
+ *
2259
+ * @param template - Template string to check
2260
+ * @returns true if contains {{...}} syntax
2261
+ */
2262
+ static containsHandlebars(template) {
2263
+ return /\{\{(?!!)[\s\S]*?\}\}/.test(template);
2264
+ }
2265
+ /**
2266
+ * Check if the renderer is initialized.
2267
+ */
2268
+ get isInitialized() {
2269
+ return this.initialized;
2270
+ }
2271
+ };
2272
+ function containsHandlebars(template) {
2273
+ return HandlebarsRenderer.containsHandlebars(template);
2274
+ }
2275
+
2276
+ // libs/uipack/src/renderers/utils/detect.ts
2277
+ function containsMdxSyntax(source) {
2278
+ if (/<[A-Z][a-zA-Z0-9]*/.test(source)) {
2279
+ return true;
2280
+ }
2281
+ if (/^(import|export)\s/m.test(source)) {
2282
+ return true;
2283
+ }
2284
+ if (/\s(className|onClick|onChange|onSubmit|htmlFor|dangerouslySetInnerHTML)=/.test(source)) {
2285
+ return true;
2286
+ }
2287
+ if (/\{[^}"'\n]*\}/.test(source) && !/=\s*["'][^"']*\{/.test(source)) {
2288
+ return true;
2289
+ }
2290
+ if (/^---[\s\S]*?---/m.test(source)) {
2291
+ return true;
2292
+ }
2293
+ if (/<>|<\/>/.test(source)) {
2294
+ return true;
2295
+ }
2296
+ return false;
2297
+ }
2298
+
2299
+ // libs/uipack/src/renderers/utils/hash.ts
2300
+ function hashString(source) {
2301
+ let hash = 2166136261;
2302
+ for (let i = 0; i < source.length; i++) {
2303
+ hash ^= source.charCodeAt(i);
2304
+ hash = hash * 16777619 >>> 0;
2305
+ }
2306
+ return hash.toString(36);
2307
+ }
2308
+
2309
+ // libs/uipack/src/renderers/cache.ts
2310
+ var TranspileCache = class {
2311
+ cache = /* @__PURE__ */ new Map();
2312
+ maxSize;
2313
+ ttl;
2314
+ /** Cache statistics */
2315
+ stats = {
2316
+ hits: 0,
2317
+ misses: 0,
2318
+ evictions: 0
2319
+ };
2320
+ constructor(options = {}) {
2321
+ this.maxSize = options.maxSize ?? 500;
2322
+ this.ttl = options.ttl ?? 0;
2323
+ }
2324
+ /**
2325
+ * Get a cached transpile result by source content.
2326
+ *
2327
+ * @param source - Source code to look up
2328
+ * @returns Cached result or undefined if not found/expired
2329
+ */
2330
+ get(source) {
2331
+ const key = hashString(source);
2332
+ return this.getByKey(key);
2333
+ }
2334
+ /**
2335
+ * Get a cached transpile result by hash key.
2336
+ *
2337
+ * @param key - Hash key
2338
+ * @returns Cached result or undefined if not found/expired
2339
+ */
2340
+ getByKey(key) {
2341
+ const entry = this.cache.get(key);
2342
+ if (!entry) {
2343
+ this.stats.misses++;
2344
+ return void 0;
2345
+ }
2346
+ if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {
2347
+ this.cache.delete(key);
2348
+ this.stats.misses++;
2349
+ return void 0;
2350
+ }
2351
+ this.cache.delete(key);
2352
+ entry.accessCount++;
2353
+ this.cache.set(key, entry);
2354
+ this.stats.hits++;
2355
+ return entry.value;
2356
+ }
2357
+ /**
2358
+ * Store a transpile result.
2359
+ *
2360
+ * @param source - Source code (used to generate key)
2361
+ * @param value - Transpile result to cache
2362
+ * @returns The hash key used for storage
2363
+ */
2364
+ set(source, value) {
2365
+ const key = hashString(source);
2366
+ this.setByKey(key, value);
2367
+ return key;
2368
+ }
2369
+ /**
2370
+ * Store a transpile result by hash key.
2371
+ *
2372
+ * @param key - Hash key
2373
+ * @param value - Transpile result to cache
2374
+ */
2375
+ setByKey(key, value) {
2376
+ if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
2377
+ const oldestKey = this.cache.keys().next().value;
2378
+ if (oldestKey) {
2379
+ this.cache.delete(oldestKey);
2380
+ this.stats.evictions++;
2381
+ }
2382
+ }
2383
+ this.cache.set(key, {
2384
+ value,
2385
+ timestamp: Date.now(),
2386
+ accessCount: 1
2387
+ });
2388
+ }
2389
+ /**
2390
+ * Check if a source is cached.
2391
+ *
2392
+ * @param source - Source code to check
2393
+ * @returns True if cached and not expired
2394
+ */
2395
+ has(source) {
2396
+ const key = hashString(source);
2397
+ return this.hasByKey(key);
2398
+ }
2399
+ /**
2400
+ * Check if a key is cached.
2401
+ *
2402
+ * @param key - Hash key to check
2403
+ * @returns True if cached and not expired
2404
+ */
2405
+ hasByKey(key) {
2406
+ const entry = this.cache.get(key);
2407
+ if (!entry) return false;
2408
+ if (this.ttl > 0 && Date.now() - entry.timestamp > this.ttl) {
2409
+ this.cache.delete(key);
2410
+ return false;
2411
+ }
2412
+ return true;
2413
+ }
2414
+ /**
2415
+ * Delete a cached entry by source.
2416
+ *
2417
+ * @param source - Source code to delete
2418
+ * @returns True if entry was deleted
2419
+ */
2420
+ delete(source) {
2421
+ const key = hashString(source);
2422
+ return this.cache.delete(key);
2423
+ }
2424
+ /**
2425
+ * Clear all cached entries.
2426
+ */
2427
+ clear() {
2428
+ this.cache.clear();
2429
+ this.stats = { hits: 0, misses: 0, evictions: 0 };
2430
+ }
2431
+ /**
2432
+ * Get current cache size.
2433
+ */
2434
+ get size() {
2435
+ return this.cache.size;
2436
+ }
2437
+ /**
2438
+ * Get cache statistics.
2439
+ */
2440
+ getStats() {
2441
+ const total = this.stats.hits + this.stats.misses;
2442
+ return {
2443
+ ...this.stats,
2444
+ size: this.cache.size,
2445
+ hitRate: total > 0 ? this.stats.hits / total : 0
2446
+ };
2447
+ }
2448
+ };
2449
+ var transpileCache = new TranspileCache({ maxSize: 500 });
2450
+ var renderCache = new TranspileCache({
2451
+ maxSize: 1e3,
2452
+ ttl: 5 * 60 * 1e3
2453
+ // 5 minutes
2454
+ });
2455
+ var ComponentCache = class {
2456
+ cache = /* @__PURE__ */ new Map();
2457
+ maxSize;
2458
+ constructor(maxSize = 200) {
2459
+ this.maxSize = maxSize;
2460
+ }
2461
+ get(key) {
2462
+ const entry = this.cache.get(key);
2463
+ if (!entry) return void 0;
2464
+ this.cache.delete(key);
2465
+ this.cache.set(key, entry);
2466
+ return entry.value;
2467
+ }
2468
+ set(key, value) {
2469
+ if (this.cache.size >= this.maxSize && !this.cache.has(key)) {
2470
+ const oldestKey = this.cache.keys().next().value;
2471
+ if (oldestKey) {
2472
+ this.cache.delete(oldestKey);
2473
+ }
2474
+ }
2475
+ this.cache.set(key, { value, timestamp: Date.now() });
2476
+ }
2477
+ has(key) {
2478
+ return this.cache.has(key);
2479
+ }
2480
+ delete(key) {
2481
+ return this.cache.delete(key);
2482
+ }
2483
+ clear() {
2484
+ this.cache.clear();
2485
+ }
2486
+ get size() {
2487
+ return this.cache.size;
2488
+ }
2489
+ };
2490
+ var componentCache = new ComponentCache();
2491
+
2492
+ // libs/uipack/src/renderers/mdx.renderer.ts
2493
+ var REACT_CDN = {
2494
+ react: "https://unpkg.com/react@18/umd/react.production.min.js",
2495
+ reactDom: "https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"
2496
+ };
2497
+ var INLINE_MDX_PLACEHOLDER = `
2498
+ // MDX runtime not available inline yet.
2499
+ // For blocked-network platforms, use pre-rendered HTML templates.
2500
+ console.warn('[FrontMCP] MDX hydration not available on this platform.');
2501
+ `;
2502
+ var MdxRenderer = class {
2503
+ type = "mdx";
2504
+ priority = 10;
2505
+ // Between HTML (0) and React (20)
2506
+ /**
2507
+ * Lazy-loaded modules.
2508
+ */
2509
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2510
+ React = null;
2511
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2512
+ ReactDOMServer = null;
2513
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2514
+ jsxRuntime = null;
2515
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2516
+ mdxEvaluate = null;
2517
+ /**
2518
+ * Check if this renderer can handle the given template.
2519
+ *
2520
+ * Accepts strings containing MDX syntax (Markdown + JSX).
2521
+ */
2522
+ canHandle(template) {
2523
+ if (typeof template !== "string") {
2524
+ return false;
2525
+ }
2526
+ return containsMdxSyntax(template);
2527
+ }
2528
+ /**
2529
+ * Transpile MDX to executable JavaScript.
2530
+ *
2531
+ * Uses @mdx-js/mdx to compile MDX source to a module.
2532
+ * Note: For MDX, we use evaluate() which combines compile + run,
2533
+ * so this method just returns the source hash for caching purposes.
2534
+ */
2535
+ async transpile(template, _options) {
2536
+ const hash = hashString(template);
2537
+ const cached = transpileCache.getByKey(hash);
2538
+ if (cached) {
2539
+ return { ...cached, cached: true };
2540
+ }
2541
+ const transpileResult = {
2542
+ code: template,
2543
+ // Store original MDX for evaluate()
2544
+ hash,
2545
+ cached: false
2546
+ };
2547
+ transpileCache.setByKey(hash, transpileResult);
2548
+ return transpileResult;
2549
+ }
2550
+ /**
2551
+ * Render MDX template to HTML string.
2552
+ *
2553
+ * Uses @mdx-js/mdx's evaluate() for clean compilation + execution,
2554
+ * then renders the resulting React component to HTML via SSR.
2555
+ */
2556
+ async render(template, context, options) {
2557
+ await this.loadReact();
2558
+ await this.loadMdx();
2559
+ if (!this.mdxEvaluate) {
2560
+ throw new Error("MDX compilation requires @mdx-js/mdx. Install it: npm install @mdx-js/mdx");
2561
+ }
2562
+ const templateHash = hashString(template);
2563
+ const cacheKey = `mdx-component:${templateHash}`;
2564
+ let Content = componentCache.get(cacheKey);
2565
+ if (!Content) {
2566
+ const result = await this.mdxEvaluate(template, {
2567
+ ...this.jsxRuntime,
2568
+ Fragment: this.React.Fragment,
2569
+ development: false
2570
+ });
2571
+ Content = result.default;
2572
+ componentCache.set(cacheKey, Content);
2573
+ }
2574
+ const mdxComponents = {
2575
+ // User-provided components from tool config
2576
+ ...options?.mdxComponents,
2577
+ // Wrapper that provides context to the content
2578
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
2579
+ wrapper: ({ children }) => {
2580
+ return this.React.createElement("div", { className: "mdx-content" }, children);
2581
+ }
2582
+ };
2583
+ const props = {
2584
+ input: context.input,
2585
+ output: context.output,
2586
+ structuredContent: context.structuredContent,
2587
+ helpers: context.helpers
2588
+ };
2589
+ const spreadProps = {
2590
+ ...props,
2591
+ ...typeof context.output === "object" && context.output !== null ? context.output : {}
2592
+ };
2593
+ const element = this.React.createElement(Content, {
2594
+ components: mdxComponents,
2595
+ ...spreadProps
2596
+ });
2597
+ const html = this.ReactDOMServer.renderToString(element);
2598
+ if (options?.hydrate) {
2599
+ const escapedProps = JSON.stringify(props).replace(/&/g, "&amp;").replace(/'/g, "&#39;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
2600
+ return `<div data-mdx-hydrate="true" data-props='${escapedProps}'>${html}</div>`;
2601
+ }
2602
+ return html;
2603
+ }
2604
+ /**
2605
+ * Get runtime scripts for client-side functionality.
2606
+ */
2607
+ getRuntimeScripts(platform) {
2608
+ if (platform.networkMode === "blocked") {
2609
+ return {
2610
+ headScripts: "",
2611
+ inlineScripts: INLINE_MDX_PLACEHOLDER,
2612
+ isInline: true
2613
+ };
2614
+ }
2615
+ return {
2616
+ headScripts: `
2617
+ <script crossorigin src="${REACT_CDN.react}"></script>
2618
+ <script crossorigin src="${REACT_CDN.reactDom}"></script>
2619
+ `,
2620
+ isInline: false
2621
+ };
2622
+ }
2623
+ /**
2624
+ * Load React and ReactDOMServer modules.
2625
+ */
2626
+ async loadReact() {
2627
+ if (this.React && this.ReactDOMServer && this.jsxRuntime) {
2628
+ return;
2629
+ }
2630
+ try {
2631
+ const [react, reactDomServer, jsxRuntime] = await Promise.all([
2632
+ import("react"),
2633
+ import("react-dom/server"),
2634
+ import("react/jsx-runtime")
2635
+ ]);
2636
+ this.React = react;
2637
+ this.ReactDOMServer = reactDomServer;
2638
+ this.jsxRuntime = jsxRuntime;
2639
+ } catch {
2640
+ throw new Error("React is required for MdxRenderer. Install react and react-dom: npm install react react-dom");
2641
+ }
2642
+ }
2643
+ /**
2644
+ * Load @mdx-js/mdx evaluate function.
2645
+ *
2646
+ * evaluate() is the cleanest way to run MDX - it combines
2647
+ * compile and run in a single step, handling all the runtime
2648
+ * injection automatically.
2649
+ */
2650
+ async loadMdx() {
2651
+ if (this.mdxEvaluate) {
2652
+ return;
2653
+ }
2654
+ try {
2655
+ const mdx = await import("@mdx-js/mdx");
2656
+ this.mdxEvaluate = mdx.evaluate;
2657
+ } catch {
2658
+ console.warn(
2659
+ "[@frontmcp/ui] @mdx-js/mdx not available. MDX rendering disabled. Install @mdx-js/mdx to enable: npm install @mdx-js/mdx"
2660
+ );
2661
+ }
2662
+ }
2663
+ };
2664
+ var mdxRenderer = new MdxRenderer();
2665
+
2666
+ // libs/uipack/src/validation/schema-paths.ts
2667
+ var import_zod2 = require("zod");
2668
+ function extractSchemaPaths(schema, prefix = "output", options = {}) {
2669
+ const { maxDepth = 10, includeArrayItems = true } = options;
2670
+ const paths = [];
2671
+ const visited = /* @__PURE__ */ new Set();
2672
+ function recurse(currentSchema, currentPath, depth, isOptional, isNullable, isArrayItem) {
2673
+ if (depth > maxDepth) return;
2674
+ const pathKey = `${currentPath}:${depth}`;
2675
+ if (visited.has(pathKey)) return;
2676
+ visited.add(pathKey);
2677
+ const description = currentSchema.description;
2678
+ const innerType = unwrapType(currentSchema);
2679
+ paths.push({
2680
+ path: currentPath,
2681
+ zodType: currentSchema,
2682
+ optional: isOptional,
2683
+ nullable: isNullable,
2684
+ isArrayItem,
2685
+ description
2686
+ });
2687
+ if (innerType instanceof import_zod2.z.ZodObject) {
2688
+ const shape = innerType.shape;
2689
+ for (const [key, value] of Object.entries(shape)) {
2690
+ const childSchema = value;
2691
+ const childOptional = isOptional || isOptionalType(childSchema);
2692
+ const childNullable = isNullable || isNullableType(childSchema);
2693
+ recurse(childSchema, `${currentPath}.${key}`, depth + 1, childOptional, childNullable, false);
2694
+ }
2695
+ } else if (innerType instanceof import_zod2.z.ZodArray && includeArrayItems) {
2696
+ const itemSchema = innerType.element;
2697
+ recurse(itemSchema, `${currentPath}.[]`, depth + 1, isOptional, isNullable, true);
2698
+ } else if (innerType instanceof import_zod2.z.ZodUnion || innerType instanceof import_zod2.z.ZodDiscriminatedUnion) {
2699
+ const options2 = "options" in innerType ? innerType.options : [];
2700
+ for (const option of options2) {
2701
+ recurse(option, currentPath, depth, isOptional, isNullable, isArrayItem);
2702
+ }
2703
+ } else if (innerType instanceof import_zod2.z.ZodIntersection) {
2704
+ recurse(innerType._def.left, currentPath, depth, isOptional, isNullable, isArrayItem);
2705
+ recurse(innerType._def.right, currentPath, depth, isOptional, isNullable, isArrayItem);
2706
+ } else if (innerType instanceof import_zod2.z.ZodRecord) {
2707
+ const valueSchema = innerType._def.valueType;
2708
+ recurse(valueSchema, `${currentPath}.[]`, depth + 1, isOptional, isNullable, true);
2709
+ } else if (innerType instanceof import_zod2.z.ZodTuple) {
2710
+ const items = innerType._def.items;
2711
+ items.forEach((item, index) => {
2712
+ recurse(item, `${currentPath}.${index}`, depth + 1, isOptional, isNullable, true);
2713
+ });
2714
+ }
2715
+ }
2716
+ recurse(schema, prefix, 0, false, false, false);
2717
+ const seen = /* @__PURE__ */ new Set();
2718
+ return paths.filter((p) => {
2719
+ if (seen.has(p.path)) return false;
2720
+ seen.add(p.path);
2721
+ return true;
2722
+ });
2723
+ }
2724
+ function unwrapType(schema) {
2725
+ if (schema instanceof import_zod2.z.ZodOptional) {
2726
+ return unwrapType(schema.unwrap());
2727
+ }
2728
+ if (schema instanceof import_zod2.z.ZodNullable) {
2729
+ return unwrapType(schema.unwrap());
2730
+ }
2731
+ if (schema instanceof import_zod2.z.ZodDefault) {
2732
+ return unwrapType(schema._def.innerType);
2733
+ }
2734
+ if (schema instanceof import_zod2.z.ZodCatch && "innerType" in schema._def) {
2735
+ return unwrapType(schema._def.innerType);
2736
+ }
2737
+ return schema;
2738
+ }
2739
+ function isOptionalType(schema) {
2740
+ if (schema instanceof import_zod2.z.ZodOptional) return true;
2741
+ if (schema instanceof import_zod2.z.ZodDefault) return true;
2742
+ if (schema instanceof import_zod2.z.ZodNullable) return isOptionalType(schema.unwrap());
2743
+ return false;
2744
+ }
2745
+ function isNullableType(schema) {
2746
+ if (schema instanceof import_zod2.z.ZodNullable) return true;
2747
+ if (schema instanceof import_zod2.z.ZodOptional) return isNullableType(schema.unwrap());
2748
+ return false;
2749
+ }
2750
+ function getSchemaPathStrings(schema, prefix = "output") {
2751
+ const paths = extractSchemaPaths(schema, prefix);
2752
+ return new Set(paths.map((p) => p.path));
2753
+ }
2754
+
2755
+ // libs/uipack/src/validation/template-validator.ts
2756
+ function validateTemplate(template, outputSchema, options = {}) {
2757
+ const { inputSchema, warnOnOptional = true, suggestSimilar = true, maxSuggestionDistance = 3 } = options;
2758
+ const errors = [];
2759
+ const warnings = [];
2760
+ const extraction = extractAll(template);
2761
+ const expressions = extractExpressions(template);
2762
+ const outputPaths = getSchemaPathStrings(outputSchema, "output");
2763
+ const inputPaths = inputSchema ? getSchemaPathStrings(inputSchema, "input") : /* @__PURE__ */ new Set();
2764
+ const outputPathInfos = extractSchemaPaths(outputSchema, "output");
2765
+ const inputPathInfos = inputSchema ? extractSchemaPaths(inputSchema, "input") : [];
2766
+ const pathInfoMap = /* @__PURE__ */ new Map();
2767
+ for (const info of [...outputPathInfos, ...inputPathInfos]) {
2768
+ pathInfoMap.set(info.path, info);
2769
+ }
2770
+ for (const expr of expressions) {
2771
+ const { path, fullExpression, line, column } = expr;
2772
+ let validPaths;
2773
+ let allPaths;
2774
+ if (path.startsWith("output.")) {
2775
+ validPaths = outputPaths;
2776
+ allPaths = Array.from(outputPaths);
2777
+ } else if (path.startsWith("input.")) {
2778
+ if (!inputSchema) {
2779
+ continue;
2780
+ }
2781
+ validPaths = inputPaths;
2782
+ allPaths = Array.from(inputPaths);
2783
+ } else if (path.startsWith("structuredContent.")) {
2784
+ continue;
2785
+ } else {
2786
+ continue;
2787
+ }
2788
+ const normalizedPath = normalizePath(path);
2789
+ const isValid = validPaths.has(path) || validPaths.has(normalizedPath);
2790
+ if (!isValid) {
2791
+ const isArrayAccess = checkArrayAccess(path, validPaths);
2792
+ if (!isArrayAccess) {
2793
+ const suggestions = suggestSimilar ? findSimilarPaths(path, allPaths, maxSuggestionDistance) : [];
2794
+ errors.push({
2795
+ type: "missing_field",
2796
+ path,
2797
+ expression: fullExpression,
2798
+ line,
2799
+ column,
2800
+ message: `Field '${getFieldName(path)}' does not exist in ${getSchemaName(path)} schema`,
2801
+ suggestions
2802
+ });
2803
+ }
2804
+ } else {
2805
+ const pathInfo = pathInfoMap.get(path) ?? pathInfoMap.get(normalizedPath);
2806
+ if (pathInfo && warnOnOptional) {
2807
+ if (pathInfo.optional && expr.type === "variable") {
2808
+ const hasGuard = hasConditionalGuard(template, path);
2809
+ if (!hasGuard) {
2810
+ warnings.push({
2811
+ type: "optional_field",
2812
+ path,
2813
+ expression: fullExpression,
2814
+ line,
2815
+ message: `Accessing optional field '${getFieldName(path)}' without {{#if}} guard`
2816
+ });
2817
+ }
2818
+ }
2819
+ }
2820
+ }
2821
+ }
2822
+ return {
2823
+ valid: errors.length === 0,
2824
+ errors,
2825
+ warnings,
2826
+ templatePaths: extraction.paths,
2827
+ schemaPaths: [...outputPaths, ...inputPaths]
2828
+ };
2829
+ }
2830
+ function checkArrayAccess(path, validPaths) {
2831
+ const parts = path.split(".");
2832
+ for (let i = 0; i < parts.length; i++) {
2833
+ if (/^\d+$/.test(parts[i])) {
2834
+ const wildcardParts = [...parts];
2835
+ wildcardParts[i] = "[]";
2836
+ const wildcardPath = wildcardParts.join(".");
2837
+ if (validPaths.has(wildcardPath)) {
2838
+ return true;
2839
+ }
2840
+ }
2841
+ }
2842
+ return false;
2843
+ }
2844
+ function getFieldName(path) {
2845
+ const parts = path.split(".");
2846
+ return parts[parts.length - 1];
2847
+ }
2848
+ function getSchemaName(path) {
2849
+ if (path.startsWith("output.")) return "output";
2850
+ if (path.startsWith("input.")) return "input";
2851
+ if (path.startsWith("structuredContent.")) return "structuredContent";
2852
+ return "unknown";
2853
+ }
2854
+ function hasConditionalGuard(template, path) {
2855
+ const guardPattern = new RegExp(`\\{\\{#if\\s+${escapeRegex(path)}`, "i");
2856
+ return guardPattern.test(template);
2857
+ }
2858
+ function escapeRegex(str) {
2859
+ return str.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
2860
+ }
2861
+ function findSimilarPaths(path, validPaths, maxDistance) {
2862
+ const fieldName = getFieldName(path);
2863
+ const prefix = path.substring(0, path.lastIndexOf(".") + 1);
2864
+ const suggestions = [];
2865
+ for (const validPath of validPaths) {
2866
+ if (!validPath.startsWith(prefix)) continue;
2867
+ const validFieldName = getFieldName(validPath);
2868
+ const distance = levenshteinDistance(fieldName, validFieldName);
2869
+ if (distance <= maxDistance && distance > 0) {
2870
+ suggestions.push({ path: validPath, distance });
2871
+ }
2872
+ }
2873
+ return suggestions.sort((a, b) => a.distance - b.distance).slice(0, 3).map((s) => s.path);
2874
+ }
2875
+ function levenshteinDistance(a, b) {
2876
+ const matrix = [];
2877
+ for (let i = 0; i <= a.length; i++) {
2878
+ matrix[i] = [i];
2879
+ }
2880
+ for (let j = 0; j <= b.length; j++) {
2881
+ matrix[0][j] = j;
2882
+ }
2883
+ for (let i = 1; i <= a.length; i++) {
2884
+ for (let j = 1; j <= b.length; j++) {
2885
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
2886
+ matrix[i][j] = Math.min(
2887
+ matrix[i - 1][j] + 1,
2888
+ // deletion
2889
+ matrix[i][j - 1] + 1,
2890
+ // insertion
2891
+ matrix[i - 1][j - 1] + cost
2892
+ // substitution
2893
+ );
2894
+ }
2895
+ }
2896
+ return matrix[a.length][b.length];
2897
+ }
2898
+ function formatValidationWarnings(result, toolName) {
2899
+ if (result.valid && result.warnings.length === 0) {
2900
+ return "";
2901
+ }
2902
+ const lines = [];
2903
+ if (result.errors.length > 0) {
2904
+ lines.push(`[FrontMCP] Template validation warnings for tool "${toolName}":`);
2905
+ lines.push("");
2906
+ for (const error of result.errors) {
2907
+ lines.push(` Line ${error.line}: ${error.expression}`);
2908
+ lines.push(` ${error.message}`);
2909
+ if (error.suggestions.length > 0) {
2910
+ lines.push(` Did you mean: ${error.suggestions.join(", ")}?`);
2911
+ }
2912
+ lines.push("");
2913
+ }
2914
+ const outputFields = result.schemaPaths.filter((p) => p.startsWith("output.") && p.split(".").length === 2).map((p) => p.replace("output.", ""));
2915
+ if (outputFields.length > 0) {
2916
+ lines.push(` Available output fields: ${outputFields.join(", ")}`);
2917
+ }
2918
+ }
2919
+ if (result.warnings.length > 0) {
2920
+ if (lines.length > 0) lines.push("");
2921
+ lines.push(` Warnings:`);
2922
+ for (const warning of result.warnings) {
2923
+ lines.push(` Line ${warning.line}: ${warning.message}`);
2924
+ }
2925
+ }
2926
+ return lines.join("\n");
2927
+ }
2928
+ function logValidationWarnings(result, toolName) {
2929
+ const formatted = formatValidationWarnings(result, toolName);
2930
+ if (formatted) {
2931
+ console.warn(formatted);
2932
+ }
2933
+ }
2934
+
2935
+ // libs/uipack/src/dependency/template-processor.ts
2936
+ function safeInputToRecord(input) {
2937
+ if (input && typeof input === "object" && !Array.isArray(input)) {
2938
+ return input;
2939
+ }
2940
+ return {};
2941
+ }
2942
+ var defaultHelpers = {
2943
+ escapeHtml,
2944
+ formatDate: (date, format) => {
2945
+ const d = date instanceof Date ? date : new Date(date);
2946
+ if (format === "iso") return d.toISOString();
2947
+ if (format === "time") return d.toLocaleTimeString();
2948
+ return d.toLocaleDateString();
2949
+ },
2950
+ formatCurrency: (amount, currency = "USD") => new Intl.NumberFormat("en-US", { style: "currency", currency }).format(amount),
2951
+ uniqueId: (prefix = "id") => `${prefix}-${Math.random().toString(36).substring(2, 9)}`,
2952
+ jsonEmbed: (data) => JSON.stringify(data).replace(/</g, "\\u003c").replace(/>/g, "\\u003e").replace(/&/g, "\\u0026")
2953
+ };
2954
+ function getSourceName(source) {
2955
+ switch (source.type) {
2956
+ case "file":
2957
+ return source.path;
2958
+ case "url":
2959
+ return source.url;
2960
+ case "inline":
2961
+ return "inline-template";
2962
+ }
2963
+ }
2964
+ var handlebarsRenderer = null;
2965
+ async function getHandlebarsRenderer(customHelpers) {
2966
+ if (customHelpers) {
2967
+ const freshRenderer = new HandlebarsRenderer();
2968
+ for (const [name, fn] of Object.entries(customHelpers)) {
2969
+ freshRenderer.registerHelper(name, fn);
2970
+ }
2971
+ return freshRenderer;
2972
+ }
2973
+ if (!handlebarsRenderer) {
2974
+ handlebarsRenderer = new HandlebarsRenderer();
2975
+ }
2976
+ return handlebarsRenderer;
2977
+ }
2978
+ function clearHandlebarsCache() {
2979
+ if (handlebarsRenderer) {
2980
+ handlebarsRenderer.clearCache();
2981
+ }
2982
+ }
2983
+ var markedModule = null;
2984
+ async function loadMarked() {
2985
+ if (markedModule) {
2986
+ return markedModule;
2987
+ }
2988
+ try {
2989
+ const moduleName = "marked";
2990
+ markedModule = await import(
2991
+ /* webpackIgnore: true */
2992
+ moduleName
2993
+ );
2994
+ return markedModule;
2995
+ } catch {
2996
+ throw new Error("marked is required for Markdown rendering. Install it: npm install marked");
2997
+ }
2998
+ }
2999
+ async function isMarkedAvailable() {
3000
+ try {
3001
+ await loadMarked();
3002
+ return true;
3003
+ } catch {
3004
+ return false;
3005
+ }
3006
+ }
3007
+ async function processTemplate(resolved, options) {
3008
+ const { format, content } = resolved;
3009
+ const { context, handlebarsHelpers, outputSchema, inputSchema, toolName } = options;
3010
+ if (format === "react") {
3011
+ return {
3012
+ code: content,
3013
+ format: "react",
3014
+ needsBundling: true
3015
+ };
3016
+ }
3017
+ if (outputSchema && process.env["NODE_ENV"] !== "production" && containsHandlebars(content)) {
3018
+ const sourceName = getSourceName(resolved.source);
3019
+ const validation = validateTemplate(content, outputSchema, {
3020
+ inputSchema,
3021
+ warnOnOptional: true,
3022
+ suggestSimilar: true,
3023
+ toolName: toolName ?? sourceName
3024
+ });
3025
+ if (!validation.valid || validation.warnings.length > 0) {
3026
+ logValidationWarnings(validation, toolName ?? sourceName ?? "unknown");
3027
+ }
3028
+ }
3029
+ let processedContent = content;
3030
+ if (containsHandlebars(content)) {
3031
+ const hbs = await getHandlebarsRenderer(handlebarsHelpers);
3032
+ const renderContext = {
3033
+ input: safeInputToRecord(context.input),
3034
+ output: context.output,
3035
+ structuredContent: context.structuredContent
3036
+ };
3037
+ processedContent = await hbs.render(content, renderContext);
3038
+ }
3039
+ switch (format) {
3040
+ case "html":
3041
+ return {
3042
+ html: processedContent,
3043
+ format: "html"
3044
+ };
3045
+ case "markdown": {
3046
+ const { marked } = await loadMarked();
3047
+ const html = await marked.parse(processedContent);
3048
+ return {
3049
+ html,
3050
+ format: "markdown"
3051
+ };
3052
+ }
3053
+ case "mdx": {
3054
+ const templateContext = {
3055
+ input: context.input,
3056
+ output: context.output,
3057
+ structuredContent: context.structuredContent,
3058
+ helpers: defaultHelpers
3059
+ };
3060
+ const html = await mdxRenderer.render(processedContent, templateContext);
3061
+ return {
3062
+ html,
3063
+ format: "mdx"
3064
+ };
3065
+ }
3066
+ default:
3067
+ return {
3068
+ html: processedContent,
3069
+ format: "html"
3070
+ };
3071
+ }
3072
+ }
3073
+ async function processTemplates(items) {
3074
+ return Promise.all(items.map(({ resolved, options }) => processTemplate(resolved, options)));
3075
+ }
3076
+ function supportsHandlebars(format) {
3077
+ return format === "html" || format === "markdown" || format === "mdx";
3078
+ }
3079
+ function producesHtml(format) {
3080
+ return format !== "react";
3081
+ }
3082
+ function requiresBundling(format) {
3083
+ return format === "react";
3084
+ }
3085
+ async function processHtmlTemplate(content, context, helpers) {
3086
+ if (!containsHandlebars(content)) {
3087
+ return content;
3088
+ }
3089
+ const hbs = await getHandlebarsRenderer(helpers);
3090
+ const renderContext = {
3091
+ input: safeInputToRecord(context.input),
3092
+ output: context.output,
3093
+ structuredContent: context.structuredContent
3094
+ };
3095
+ return hbs.render(content, renderContext);
3096
+ }
3097
+ async function processMarkdownTemplate(content, context, helpers) {
3098
+ let processed = content;
3099
+ if (containsHandlebars(content)) {
3100
+ const hbs = await getHandlebarsRenderer(helpers);
3101
+ const renderContext = {
3102
+ input: safeInputToRecord(context.input),
3103
+ output: context.output,
3104
+ structuredContent: context.structuredContent
3105
+ };
3106
+ processed = await hbs.render(content, renderContext);
3107
+ }
3108
+ const { marked } = await loadMarked();
3109
+ return marked.parse(processed);
3110
+ }
3111
+ async function processMdxTemplate(content, context, helpers) {
3112
+ let processed = content;
3113
+ if (containsHandlebars(content)) {
3114
+ const hbs = await getHandlebarsRenderer(helpers);
3115
+ const renderContext = {
3116
+ input: safeInputToRecord(context.input),
3117
+ output: context.output,
3118
+ structuredContent: context.structuredContent
3119
+ };
3120
+ processed = await hbs.render(content, renderContext);
3121
+ }
3122
+ const templateContext = {
3123
+ input: context.input,
3124
+ output: context.output,
3125
+ structuredContent: context.structuredContent,
3126
+ helpers: defaultHelpers
3127
+ };
3128
+ return mdxRenderer.render(processed, templateContext);
3129
+ }
3130
+ // Annotate the CommonJS export names for ESM import in node:
3131
+ 0 && (module.exports = {
3132
+ CDN_PROVIDER_PRIORITY,
3133
+ DEFAULT_CDN_REGISTRY,
3134
+ DependencyResolutionError,
3135
+ DependencyResolver,
3136
+ NoProviderError,
3137
+ addScope,
3138
+ buildManifestMetadataSchema,
3139
+ buildManifestOutputsSchema,
3140
+ bundleTargetSchema,
3141
+ cacheStatsSchema,
3142
+ cdnDependencySchema,
3143
+ cdnPlatformTypeSchema,
3144
+ cdnProviderConfigSchema,
3145
+ cdnProviderSchema,
3146
+ cdnRegistryEntrySchema,
3147
+ clearHandlebarsCache,
3148
+ clearUrlCache,
3149
+ componentBuildManifestSchema,
3150
+ createClaudeResolver,
3151
+ createImportMap,
3152
+ createImportMapFromOverrides,
3153
+ createOpenAIResolver,
3154
+ createResolver,
3155
+ dependencyResolverOptionsSchema,
3156
+ detectFormatFromPath,
3157
+ detectFormatFromUrl,
3158
+ detectTemplateMode,
3159
+ detectTemplateSource,
3160
+ extractExternalPackages,
3161
+ fetchTemplateFromUrl,
3162
+ fileBundleOptionsSchema,
3163
+ fileTemplateConfigSchema,
3164
+ filterImportsByPackages,
3165
+ generateCDNScriptTags,
3166
+ generateDependencyHTML,
3167
+ generateESMScriptTags,
3168
+ generateImportMapForPackages,
3169
+ generateImportMapScriptTag,
3170
+ generateImportMapScriptTagMinified,
3171
+ generateUMDShim,
3172
+ getImportStats,
3173
+ getPackageCDNDependency,
3174
+ getPackageCDNUrl,
3175
+ getPackageName,
3176
+ getPackagePeerDependencies,
3177
+ getRegisteredPackages,
3178
+ getUrlCache,
3179
+ importMapSchema,
3180
+ importTypeSchema,
3181
+ invalidateUrlCache,
3182
+ isFileBasedTemplate,
3183
+ isMarkedAvailable,
3184
+ isPackageRegistered,
3185
+ lookupPackage,
3186
+ mergeImportMaps,
3187
+ mergeRegistries,
3188
+ needsRefetch,
3189
+ packageMetadataSchema,
3190
+ parseImports,
3191
+ parsedImportResultSchema,
3192
+ parsedImportSchema,
3193
+ processHtmlTemplate,
3194
+ processMarkdownTemplate,
3195
+ processMdxTemplate,
3196
+ processTemplate,
3197
+ processTemplates,
3198
+ producesHtml,
3199
+ readTemplateFromFile,
3200
+ requiresBundling,
3201
+ resolveAllDependencies,
3202
+ resolveDependencies,
3203
+ resolveFilePath,
3204
+ resolveTemplate,
3205
+ resolvedDependencySchema,
3206
+ safeParseBuildManifest,
3207
+ safeParseCDNDependency,
3208
+ safeParseFileTemplateConfig,
3209
+ supportsHandlebars,
3210
+ validateBuildManifest,
3211
+ validateCDNDependency,
3212
+ validateFileTemplateConfig,
3213
+ validateImportMap,
3214
+ validateTemplateUrl
3215
+ });