UNPKG

@copilotkit/a2ui-renderer

Version:

A2UI Renderer for CopilotKit - render A2UI surfaces in React applications

1,447 lines (1,418 loc) 71.8 kB
(function(global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('@a2ui/web_core/v0_9'), require('react/jsx-runtime'), require('@a2ui/web_core/v0_9/basic_catalog'), require('zod'), require('clsx'), require('zod-to-json-schema')) : typeof define === 'function' && define.amd ? define(['exports', 'react', '@a2ui/web_core/v0_9', 'react/jsx-runtime', '@a2ui/web_core/v0_9/basic_catalog', 'zod', 'clsx', 'zod-to-json-schema'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.CopilotKitA2UIRenderer = {}), global.React,global._a2ui_web_core_v0_9,global.React,global._a2ui_web_core_v0_9_basic_catalog,global.Zod,global.clsx,global.zod_to_json_schema)); })(this, function(exports, react, _a2ui_web_core_v0_9, react_jsx_runtime, _a2ui_web_core_v0_9_basic_catalog, zod, clsx, zod_to_json_schema) { Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); //#region \0rolldown/runtime.js var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) { key = keys[i]; if (!__hasOwnProp.call(to, key) && key !== except) { __defProp(to, key, { get: ((k) => from[k]).bind(null, key), enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } } } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod)); //#endregion react = __toESM(react); //#region src/react-renderer/a2ui-react/A2uiSurface.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ResolvedChild = (0, react.memo)(({ surface, id, basePath, compImpl, componentModel }) => { const ComponentToRender = compImpl.render; const context = (0, react.useMemo)(() => new _a2ui_web_core_v0_9.ComponentContext(surface, id, basePath), [ surface, id, basePath, componentModel ]); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ComponentToRender, { context, buildChild: (0, react.useCallback)((childId, specificPath) => { const path = specificPath || context.dataContext.path; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DeferredChild, { surface, id: childId, basePath: path }, `${childId}-${path}`); }, [surface, context.dataContext.path]) }); }); ResolvedChild.displayName = "ResolvedChild"; const DeferredChild = (0, react.memo)(({ surface, id, basePath }) => { const store = (0, react.useMemo)(() => { let version = 0; return { subscribe: (cb) => { const unsub1 = surface.componentsModel.onCreated.subscribe((comp) => { if (comp.id === id) { version++; cb(); } }); const unsub2 = surface.componentsModel.onDeleted.subscribe((delId) => { if (delId === id) { version++; cb(); } }); return () => { unsub1.unsubscribe(); unsub2.unsubscribe(); }; }, getSnapshot: () => { const comp = surface.componentsModel.get(id); return comp ? `${comp.type}-${version}` : `missing-${version}`; } }; }, [surface, id]); (0, react.useSyncExternalStore)(store.subscribe, store.getSnapshot); const componentModel = surface.componentsModel.get(id); if (!componentModel) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { padding: "12px 16px", borderRadius: "8px", background: "linear-gradient(90deg, #f3f4f6 25%, #e5e7eb 50%, #f3f4f6 75%)", backgroundSize: "200% 100%", animation: "a2ui-shimmer 1.5s ease-in-out infinite", minHeight: "2rem" }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", { children: `@keyframes a2ui-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }` }) }); const compImpl = surface.catalog.components.get(componentModel.type); if (!compImpl) return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { color: "red" }, children: ["Unknown component: ", componentModel.type] }); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ResolvedChild, { surface, id, basePath, componentModel, compImpl }); }); DeferredChild.displayName = "DeferredChild"; const A2uiSurface = ({ surface }) => { return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(DeferredChild, { surface, id: "root", basePath: "/" }); }; //#endregion //#region src/react-renderer/a2ui-react/adapter.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * Creates a React component implementation using the deep generic binder. */ function createReactComponent(api, RenderComponent) { const MemoizedRender = (0, react.memo)(RenderComponent, (prev, next) => { if (prev.props !== next.props) return false; if (prev.context.componentModel.id !== next.context.componentModel.id) return false; if (prev.context.dataContext.path !== next.context.dataContext.path) return false; return true; }); const ReactWrapper = ({ context, buildChild }) => { const bindingRef = (0, react.useRef)(null); if (!bindingRef.current) bindingRef.current = new _a2ui_web_core_v0_9.GenericBinder(context, api.schema); else if (bindingRef.current.context !== context) { bindingRef.current.dispose(); bindingRef.current = new _a2ui_web_core_v0_9.GenericBinder(context, api.schema); } const binding = bindingRef.current; const props = (0, react.useSyncExternalStore)((0, react.useCallback)((callback) => { const sub = binding.subscribe(callback); return () => sub.unsubscribe(); }, [binding]), (0, react.useCallback)(() => binding.snapshot, [binding])); (0, react.useEffect)(() => { return () => binding.dispose(); }, [binding]); return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(MemoizedRender, { props: props || {}, buildChild, context }); }; return { name: api.name, schema: api.schema, render: ReactWrapper }; } //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/utils.ts /** Standard leaf margin from the implementation guide. */ const LEAF_MARGIN = "8px"; /** Standard internal padding for visually bounded containers. */ const CONTAINER_PADDING = "16px"; /** Standard border for cards and inputs. */ const STANDARD_BORDER = "1px solid #ccc"; /** Standard border radius. */ const STANDARD_RADIUS = "8px"; const mapJustify$2 = (j) => { switch (j) { case "center": return "center"; case "end": return "flex-end"; case "spaceAround": return "space-around"; case "spaceBetween": return "space-between"; case "spaceEvenly": return "space-evenly"; case "start": return "flex-start"; case "stretch": return "stretch"; default: return "flex-start"; } }; const mapAlign$2 = (a) => { switch (a) { case "start": return "flex-start"; case "center": return "center"; case "end": return "flex-end"; case "stretch": return "stretch"; default: return "stretch"; } }; const getBaseLeafStyle = () => ({ margin: LEAF_MARGIN, boxSizing: "border-box" }); const getBaseContainerStyle = () => ({ margin: LEAF_MARGIN, padding: CONTAINER_PADDING, border: STANDARD_BORDER, borderRadius: STANDARD_RADIUS, boxSizing: "border-box" }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Text.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Text$1 = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.TextApi, ({ props }) => { var _props$text; const text = (_props$text = props.text) !== null && _props$text !== void 0 ? _props$text : ""; const style = { ...getBaseLeafStyle(), display: "inline-block" }; switch (props.variant) { case "h1": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", { style, children: text }); case "h2": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", { style, children: text }); case "h3": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { style, children: text }); case "h4": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { style, children: text }); case "h5": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h5", { style, children: text }); case "caption": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { style: { ...style, color: "#666", textAlign: "left" }, children: text }); default: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style, children: text }); } }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Image.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Image = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.ImageApi, ({ props }) => { const mapFit = (fit) => { if (fit === "scaleDown") return "scale-down"; return fit || "fill"; }; const style = { ...getBaseLeafStyle(), objectFit: mapFit(props.fit), width: "100%", height: "auto", display: "block" }; if (props.variant === "icon") { style.width = "24px"; style.height = "24px"; } else if (props.variant === "avatar") { style.width = "40px"; style.height = "40px"; style.borderRadius = "50%"; } else if (props.variant === "smallFeature") style.maxWidth = "100px"; else if (props.variant === "largeFeature") style.maxHeight = "400px"; else if (props.variant === "header") { style.height = "200px"; style.objectFit = "cover"; } return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("img", { src: props.url, alt: props.description || "", style }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Icon.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Icon = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.IconApi, ({ props }) => { var _props$name; const iconName = typeof props.name === "string" ? props.name : (_props$name = props.name) === null || _props$name === void 0 ? void 0 : _props$name.path; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { className: "material-symbols-outlined", style: { ...getBaseLeafStyle(), fontSize: "24px", width: "24px", height: "24px", display: "inline-flex", alignItems: "center", justifyContent: "center" }, children: iconName }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Video.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Video = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.VideoApi, ({ props }) => { const style = { ...getBaseLeafStyle(), width: "100%", aspectRatio: "16/9" }; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("video", { src: props.url, controls: true, style }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/AudioPlayer.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const AudioPlayer = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.AudioPlayerApi, ({ props }) => { const style = { ...getBaseLeafStyle(), width: "100%" }; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px", width: "100%" }, children: [props.description && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: { fontSize: "12px", color: "#666" }, children: props.description }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("audio", { src: props.url, controls: true, style })] }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/ChildList.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ChildList$1 = ({ childList, buildChild }) => { if (Array.isArray(childList)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: childList.map((item, i) => { if (item && typeof item === "object" && "id" in item) { const node = item; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: buildChild(node.id, node.basePath) }, `${node.id}-${i}`); } if (typeof item === "string") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: buildChild(item) }, `${item}-${i}`); return null; }) }); return null; }; //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Row.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Row$1 = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.RowApi, ({ props, buildChild, context }) => { return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { display: "flex", flexDirection: "row", justifyContent: mapJustify$2(props.justify), alignItems: mapAlign$2(props.align), width: "100%", margin: 0, padding: 0 }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChildList$1, { childList: props.children, buildChild, context }) }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Column.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Column$1 = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.ColumnApi, ({ props, buildChild, context }) => { return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { display: "flex", flexDirection: "column", justifyContent: mapJustify$2(props.justify), alignItems: mapAlign$2(props.align), width: "100%", margin: 0, padding: 0 }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChildList$1, { childList: props.children, buildChild, context }) }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/List.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const List = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.ListApi, ({ props, buildChild, context }) => { const isHorizontal = props.direction === "horizontal"; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { display: "flex", flexDirection: isHorizontal ? "row" : "column", alignItems: mapAlign$2(props.align), overflowX: isHorizontal ? "auto" : "hidden", overflowY: isHorizontal ? "hidden" : "auto", width: "100%", margin: 0, padding: 0 }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChildList$1, { childList: props.children, buildChild, context }) }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Card.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Card = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.CardApi, ({ props, buildChild }) => { return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { ...getBaseContainerStyle(), backgroundColor: "#fff", boxShadow: "0 2px 4px rgba(0,0,0,0.1)", width: "100%" }, children: props.child ? buildChild(props.child) : null }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Tabs.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Tabs = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.TabsApi, ({ props, buildChild }) => { const [selectedIndex, setSelectedIndex] = (0, react.useState)(0); const tabs = props.tabs || []; const activeTab = tabs[selectedIndex]; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", width: "100%", margin: LEAF_MARGIN }, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { display: "flex", borderBottom: "1px solid #ccc", marginBottom: "8px" }, children: tabs.map((tab, i) => /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", { onClick: () => setSelectedIndex(i), style: { padding: "8px 16px", border: "none", background: "none", borderBottom: selectedIndex === i ? "2px solid var(--a2ui-primary-color, #007bff)" : "none", fontWeight: selectedIndex === i ? "bold" : "normal", cursor: "pointer", color: selectedIndex === i ? "var(--a2ui-primary-color, #007bff)" : "inherit" }, children: tab.title }, i)) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { flex: 1 }, children: activeTab ? buildChild(activeTab.child) : null })] }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Divider.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Divider = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.DividerApi, ({ props }) => { const isVertical = props.axis === "vertical"; const style = { margin: LEAF_MARGIN, border: "none", backgroundColor: "#ccc" }; if (isVertical) { style.width = "1px"; style.height = "100%"; } else { style.width = "100%"; style.height = "1px"; } return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Modal.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Modal = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.ModalApi, ({ props, buildChild }) => { const [isOpen, setIsOpen] = (0, react.useState)(false); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { onClick: () => setIsOpen(true), style: { display: "inline-block" }, children: props.trigger ? buildChild(props.trigger) : null }), isOpen && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { position: "fixed", top: 0, left: 0, right: 0, bottom: 0, backgroundColor: "rgba(0,0,0,0.5)", display: "flex", alignItems: "center", justifyContent: "center", zIndex: 1e3 }, onClick: () => setIsOpen(false), children: /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { backgroundColor: "#fff", padding: "24px", borderRadius: "8px", maxWidth: "90%", maxHeight: "90%", overflow: "auto", display: "flex", flexDirection: "column" }, onClick: (e) => e.stopPropagation(), children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { display: "flex", justifyContent: "flex-end" }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", { onClick: () => setIsOpen(false), style: { border: "none", background: "none", fontSize: "20px", cursor: "pointer", padding: "4px" }, children: "×" }) }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { flex: 1 }, children: props.content ? buildChild(props.content) : null })] }) })] }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Button.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Button$1 = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.ButtonApi, ({ props, buildChild }) => { return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", { style: { margin: LEAF_MARGIN, padding: "8px 16px", cursor: "pointer", border: props.variant === "borderless" ? "none" : "1px solid #ccc", backgroundColor: props.variant === "primary" ? "var(--a2ui-primary-color, #007bff)" : props.variant === "borderless" ? "transparent" : "#fff", color: props.variant === "primary" ? "#fff" : "inherit", borderRadius: "4px", display: "inline-flex", alignItems: "center", justifyContent: "center", boxSizing: "border-box" }, onClick: props.action, disabled: props.isValid === false, children: props.child ? buildChild(props.child) : null }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/TextField.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const TextField$1 = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.TextFieldApi, ({ props }) => { const onChange = (e) => { props.setValue(e.target.value); }; const isLong = props.variant === "longText"; const type = props.variant === "number" ? "number" : props.variant === "obscured" ? "password" : "text"; const style = { padding: "8px", width: "100%", border: STANDARD_BORDER, borderRadius: STANDARD_RADIUS, boxSizing: "border-box" }; const uniqueId = react.default.useId(); const hasError = props.validationErrors && props.validationErrors.length > 0; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px", width: "100%", margin: LEAF_MARGIN }, children: [ props.label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", { htmlFor: uniqueId, style: { fontSize: "14px", fontWeight: "bold" }, children: props.label }), isLong ? /* @__PURE__ */ (0, react_jsx_runtime.jsx)("textarea", { id: uniqueId, style: { ...style, border: hasError ? "1px solid red" : STANDARD_BORDER }, value: props.value || "", onChange }) : /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { id: uniqueId, type, style: { ...style, border: hasError ? "1px solid red" : STANDARD_BORDER }, value: props.value || "", onChange }), hasError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: { fontSize: "12px", color: "red" }, children: props.validationErrors[0] }) ] }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/CheckBox.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const CheckBox = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.CheckBoxApi, ({ props }) => { var _props$validationErro; const onChange = (e) => { props.setValue(e.target.checked); }; const uniqueId = react.default.useId(); const hasError = props.validationErrors && props.validationErrors.length > 0; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", margin: LEAF_MARGIN }, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", alignItems: "center", gap: "8px" }, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { id: uniqueId, type: "checkbox", checked: !!props.value, onChange, style: { cursor: "pointer", outline: hasError ? "1px solid red" : "none" } }), props.label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", { htmlFor: uniqueId, style: { cursor: "pointer", color: hasError ? "red" : "inherit" }, children: props.label })] }), hasError && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: { fontSize: "12px", color: "red", marginTop: "4px" }, children: (_props$validationErro = props.validationErrors) === null || _props$validationErro === void 0 ? void 0 : _props$validationErro[0] })] }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/ChoicePicker.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ChoicePicker = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.ChoicePickerApi, ({ props, context }) => { const [filter, setFilter] = (0, react.useState)(""); const values = Array.isArray(props.value) ? props.value : []; const isMutuallyExclusive = props.variant === "mutuallyExclusive"; const onToggle = (val) => { if (isMutuallyExclusive) props.setValue([val]); else { const newValues = values.includes(val) ? values.filter((v) => v !== val) : [...values, val]; props.setValue(newValues); } }; const options = (props.options || []).filter((opt) => !props.filterable || filter === "" || String(opt.label).toLowerCase().includes(filter.toLowerCase())); const containerStyle = { display: "flex", flexDirection: "column", gap: "8px", margin: LEAF_MARGIN, width: "100%" }; const listStyle = { display: "flex", flexDirection: props.displayStyle === "chips" ? "row" : "column", flexWrap: props.displayStyle === "chips" ? "wrap" : "nowrap", gap: "8px" }; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: containerStyle, children: [ props.label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("strong", { style: { fontSize: "14px" }, children: props.label }), props.filterable && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { type: "text", placeholder: "Filter options...", value: filter, onChange: (e) => setFilter(e.target.value), style: { padding: "4px 8px", border: STANDARD_BORDER, borderRadius: STANDARD_RADIUS } }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: listStyle, children: options.map((opt, i) => { const isSelected = values.includes(opt.value); if (props.displayStyle === "chips") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", { onClick: () => onToggle(opt.value), style: { padding: "4px 12px", borderRadius: "16px", border: isSelected ? "1px solid var(--a2ui-primary-color, #007bff)" : STANDARD_BORDER, backgroundColor: isSelected ? "var(--a2ui-primary-color, #007bff)" : "#fff", color: isSelected ? "#fff" : "inherit", cursor: "pointer", fontSize: "12px" }, children: opt.label }, i); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("label", { style: { display: "flex", alignItems: "center", gap: "8px", cursor: "pointer" }, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { type: isMutuallyExclusive ? "radio" : "checkbox", checked: isSelected, onChange: () => onToggle(opt.value), name: isMutuallyExclusive ? `choice-${context.componentModel.id}` : void 0 }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: { fontSize: "14px" }, children: opt.label })] }, i); }) }) ] }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/Slider.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const Slider = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.SliderApi, ({ props }) => { var _props$min, _props$value; const onChange = (e) => { props.setValue(Number(e.target.value)); }; const uniqueId = react.default.useId(); return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px", margin: LEAF_MARGIN, width: "100%" }, children: [/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", justifyContent: "space-between" }, children: [props.label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", { htmlFor: uniqueId, style: { fontSize: "14px", fontWeight: "bold" }, children: props.label }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { style: { fontSize: "12px", color: "#666" }, children: props.value })] }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { id: uniqueId, type: "range", min: (_props$min = props.min) !== null && _props$min !== void 0 ? _props$min : 0, max: props.max, value: (_props$value = props.value) !== null && _props$value !== void 0 ? _props$value : 0, onChange, style: { width: "100%", cursor: "pointer" } })] }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/components/DateTimeInput.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const DateTimeInput = createReactComponent(_a2ui_web_core_v0_9_basic_catalog.DateTimeInputApi, ({ props }) => { const onChange = (e) => { props.setValue(e.target.value); }; const uniqueId = react.default.useId(); let type = "datetime-local"; if (props.enableDate && !props.enableTime) type = "date"; if (!props.enableDate && props.enableTime) type = "time"; const style = { padding: "8px", width: "100%", border: STANDARD_BORDER, borderRadius: STANDARD_RADIUS, boxSizing: "border-box" }; return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("div", { style: { display: "flex", flexDirection: "column", gap: "4px", width: "100%", margin: LEAF_MARGIN }, children: [props.label && /* @__PURE__ */ (0, react_jsx_runtime.jsx)("label", { htmlFor: uniqueId, style: { fontSize: "14px", fontWeight: "bold" }, children: props.label }), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("input", { id: uniqueId, type, style, value: props.value || "", onChange, min: typeof props.min === "string" ? props.min : void 0, max: typeof props.max === "string" ? props.max : void 0 })] }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/basic/index.ts /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const basicComponents = [ Text$1, Image, Icon, Video, AudioPlayer, Row$1, Column$1, List, Card, Tabs, Divider, Modal, Button$1, TextField$1, CheckBox, ChoicePicker, Slider, DateTimeInput ]; const basicCatalog = new _a2ui_web_core_v0_9.Catalog("https://a2ui.org/specification/v0_9/basic_catalog.json", basicComponents, _a2ui_web_core_v0_9_basic_catalog.BASIC_FUNCTIONS); //#endregion //#region src/react-renderer/a2ui-react/catalog/minimal/components/Text.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const TextSchema = zod.z.object({ text: _a2ui_web_core_v0_9.CommonSchemas.DynamicString, variant: zod.z.enum([ "h1", "h2", "h3", "h4", "h5", "caption", "body" ]).optional() }); const TextApiDef = { name: "Text", schema: TextSchema }; const Text = createReactComponent(TextApiDef, ({ props }) => { var _props$text; const text = (_props$text = props.text) !== null && _props$text !== void 0 ? _props$text : ""; switch (props.variant) { case "h1": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h1", { children: text }); case "h2": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h2", { children: text }); case "h3": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h3", { children: text }); case "h4": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h4", { children: text }); case "h5": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("h5", { children: text }); case "caption": return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("small", { children: text }); default: return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("span", { children: text }); } }); //#endregion //#region src/react-renderer/a2ui-react/catalog/minimal/components/Button.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ButtonSchema = zod.z.object({ child: _a2ui_web_core_v0_9.CommonSchemas.ComponentId, action: _a2ui_web_core_v0_9.CommonSchemas.Action, variant: zod.z.enum(["primary", "borderless"]).optional() }); const ButtonApiDef = { name: "Button", schema: ButtonSchema }; const Button = createReactComponent(ButtonApiDef, ({ props, buildChild }) => { return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", { style: { padding: "8px 16px", cursor: "pointer", border: props.variant === "borderless" ? "none" : "1px solid #ccc", backgroundColor: props.variant === "primary" ? "#007bff" : "transparent", color: props.variant === "primary" ? "#fff" : "inherit", borderRadius: "4px" }, onClick: props.action, children: props.child ? buildChild(props.child) : null }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/minimal/components/ChildList.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ChildList = ({ childList, buildChild }) => { if (Array.isArray(childList)) return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react_jsx_runtime.Fragment, { children: childList.map((item, i) => { if (item && typeof item === "object" && "id" in item) { const node = item; return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: buildChild(node.id, node.basePath) }, `${node.id}-${i}`); } if (typeof item === "string") return /* @__PURE__ */ (0, react_jsx_runtime.jsx)(react.default.Fragment, { children: buildChild(item) }, `${item}-${i}`); return null; }) }); return null; }; //#endregion //#region src/react-renderer/a2ui-react/catalog/minimal/components/Row.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const RowSchema = zod.z.object({ children: _a2ui_web_core_v0_9.CommonSchemas.ChildList, justify: zod.z.enum([ "center", "end", "spaceAround", "spaceBetween", "spaceEvenly", "start", "stretch" ]).optional(), align: zod.z.enum([ "start", "center", "end", "stretch" ]).optional() }); const mapJustify$1 = (j) => { switch (j) { case "center": return "center"; case "end": return "flex-end"; case "spaceAround": return "space-around"; case "spaceBetween": return "space-between"; case "spaceEvenly": return "space-evenly"; case "start": return "flex-start"; case "stretch": return "stretch"; default: return "flex-start"; } }; const mapAlign$1 = (a) => { switch (a) { case "start": return "flex-start"; case "center": return "center"; case "end": return "flex-end"; case "stretch": return "stretch"; default: return "stretch"; } }; const RowApiDef = { name: "Row", schema: RowSchema }; const Row = createReactComponent(RowApiDef, ({ props, buildChild }) => { return /* @__PURE__ */ (0, react_jsx_runtime.jsx)("div", { style: { display: "flex", flexDirection: "row", justifyContent: mapJustify$1(props.justify), alignItems: mapAlign$1(props.align) }, children: /* @__PURE__ */ (0, react_jsx_runtime.jsx)(ChildList, { childList: props.children, buildChild }) }); }); //#endregion //#region src/react-renderer/a2ui-react/catalog/minimal/components/Column.tsx /** * Copyright 2026 Google LLC * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ const ColumnSchema = zod.z.object({ children: _a2ui_web_core_v0_9.CommonSchemas.ChildList, justify: zod.z.enum([ "start", "center", "end", "spaceBetween", "spaceAround", "spaceEvenly", "stretch" ]).optional(), align: zod.z.enum([ "center", "end", "start", "stretch"