json-ui-lite-rn 0.12.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +230 -0
- package/lib/commonjs/GenUINode.js +113 -0
- package/lib/commonjs/GenUINode.js.map +1 -0
- package/lib/commonjs/GenerativeUIView.js +116 -0
- package/lib/commonjs/GenerativeUIView.js.map +1 -0
- package/lib/commonjs/index.js +78 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/parseGenUIProps.js +53 -0
- package/lib/commonjs/parseGenUIProps.js.map +1 -0
- package/lib/commonjs/prompt.js +27 -0
- package/lib/commonjs/prompt.js.map +1 -0
- package/lib/commonjs/registry.js +70 -0
- package/lib/commonjs/registry.js.map +1 -0
- package/lib/commonjs/tools.js +386 -0
- package/lib/commonjs/tools.js.map +1 -0
- package/lib/module/GenUINode.js +108 -0
- package/lib/module/GenUINode.js.map +1 -0
- package/lib/module/GenerativeUIView.js +111 -0
- package/lib/module/GenerativeUIView.js.map +1 -0
- package/lib/module/index.js +9 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/parseGenUIProps.js +49 -0
- package/lib/module/parseGenUIProps.js.map +1 -0
- package/lib/module/prompt.js +23 -0
- package/lib/module/prompt.js.map +1 -0
- package/lib/module/registry.js +66 -0
- package/lib/module/registry.js.map +1 -0
- package/lib/module/tools.js +383 -0
- package/lib/module/tools.js.map +1 -0
- package/lib/typescript/GenUINode.d.ts +12 -0
- package/lib/typescript/GenUINode.d.ts.map +1 -0
- package/lib/typescript/GenerativeUIView.d.ts +23 -0
- package/lib/typescript/GenerativeUIView.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +8 -0
- package/lib/typescript/index.d.ts.map +1 -0
- package/lib/typescript/parseGenUIProps.d.ts +20 -0
- package/lib/typescript/parseGenUIProps.d.ts.map +1 -0
- package/lib/typescript/prompt.d.ts +12 -0
- package/lib/typescript/prompt.d.ts.map +1 -0
- package/lib/typescript/registry.d.ts +36 -0
- package/lib/typescript/registry.d.ts.map +1 -0
- package/lib/typescript/tools.d.ts +119 -0
- package/lib/typescript/tools.d.ts.map +1 -0
- package/package.json +56 -0
- package/src/GenUINode.tsx +115 -0
- package/src/GenerativeUIView.tsx +137 -0
- package/src/index.ts +25 -0
- package/src/parseGenUIProps.ts +59 -0
- package/src/prompt.ts +49 -0
- package/src/registry.ts +73 -0
- package/src/tools.ts +392 -0
package/README.md
ADDED
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
# `json-ui-lite-rn`
|
|
2
|
+
|
|
3
|
+
Lightweight JSON UI tooling for React Native + Vercel AI SDK tool calling.
|
|
4
|
+
|
|
5
|
+
**This package provides:**
|
|
6
|
+
|
|
7
|
+
- a component/style registry (`GEN_UI_NODE_HINTS`, `GEN_UI_STYLES`, `GEN_UI_NODE_NAMES`)
|
|
8
|
+
- a ready-to-use tool set for JSON UI mutation (`createGenUITools`)
|
|
9
|
+
- a reusable system prompt builder (`buildGenUISystemPrompt`)
|
|
10
|
+
- a React Native renderer for specs (`GenerativeUIView`), which passes `GEN_UI_STYLES` (overridable) to the default `GenUINode` and lets you supply a custom node renderer
|
|
11
|
+
|
|
12
|
+
**Why this package?** a.k.a. prior art
|
|
13
|
+
|
|
14
|
+
There exists a great library for streaming interfaces: [`json-render`](https://github.com/vercel-labs/json-render). The full specification is provided in this section, but **TLDR**: this library - `json-ui-lite-rn` - is the choice for small language models (e.g. parameters in the order of magnitude of 3B), which is usually the case if you are running inference locally, on-device. If you are using a cloud provider (OpenAI or Antrophic API), then you will want to go with `json-render` instead.
|
|
15
|
+
|
|
16
|
+
## Requirements
|
|
17
|
+
|
|
18
|
+
- React Native app
|
|
19
|
+
- Vercel AI SDK tool-calling flow (`streamText`, `generateText`, etc.)
|
|
20
|
+
- model that supports tool calling
|
|
21
|
+
|
|
22
|
+
## Installation
|
|
23
|
+
|
|
24
|
+
```sh
|
|
25
|
+
bun add json-ui-lite-rn
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Quick Start
|
|
29
|
+
|
|
30
|
+
```ts
|
|
31
|
+
import { streamText } from 'ai'
|
|
32
|
+
import { buildGenUISystemPrompt, createGenUITools } from 'json-ui-lite-rn'
|
|
33
|
+
|
|
34
|
+
type UISpec = {
|
|
35
|
+
root: string
|
|
36
|
+
elements: Record<
|
|
37
|
+
string,
|
|
38
|
+
{ type: string; props: Record<string, unknown>; children?: string[] }
|
|
39
|
+
>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const tools = createGenUITools<UISpec>({
|
|
43
|
+
contextId: chatId,
|
|
44
|
+
getSpec: (id) => getSpecForChat(id),
|
|
45
|
+
updateSpec: (id, nextSpec) => setSpecForChat(id, nextSpec),
|
|
46
|
+
toolWrapper: (toolName, execute) => async (args) => {
|
|
47
|
+
console.log('[json-ui-lite-rn] Executing tool', toolName, args)
|
|
48
|
+
return execute(args)
|
|
49
|
+
},
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const result = streamText({
|
|
53
|
+
model,
|
|
54
|
+
messages,
|
|
55
|
+
tools,
|
|
56
|
+
system: buildGenUISystemPrompt({
|
|
57
|
+
additionalInstructions:
|
|
58
|
+
'Keep responses short. Ask follow-up questions when UI intent is unclear.',
|
|
59
|
+
}),
|
|
60
|
+
})
|
|
61
|
+
```
|
|
62
|
+
|
|
63
|
+
## API
|
|
64
|
+
|
|
65
|
+
### `createGenUITools(options)`
|
|
66
|
+
|
|
67
|
+
Creates a set of tool definitions:
|
|
68
|
+
|
|
69
|
+
- `getUIRootNode`
|
|
70
|
+
- `getUINode`
|
|
71
|
+
- `getUILayout`
|
|
72
|
+
- `getAvailableUINodes`
|
|
73
|
+
- `setUINodeProps`
|
|
74
|
+
- `deleteUINode`
|
|
75
|
+
- `addUINode`
|
|
76
|
+
- `reorderUINodes`
|
|
77
|
+
|
|
78
|
+
`reorderUINodes` moves one sibling by index offset (with clamping):
|
|
79
|
+
|
|
80
|
+
- `nodeId`: node to move
|
|
81
|
+
- `offset`: integer shift among siblings (`< 0` moves earlier, `> 0` moves later)
|
|
82
|
+
|
|
83
|
+
Options:
|
|
84
|
+
|
|
85
|
+
- `contextId`: string key for your current conversation/context
|
|
86
|
+
- `getSpec(contextId)`: return current spec (or `null`)
|
|
87
|
+
- `updateSpec(contextId, spec)`: persist changes
|
|
88
|
+
- `createId`: optional id factory
|
|
89
|
+
- `rootId`: optional root id override (default: `"root"`)
|
|
90
|
+
- `nodeHints`: optional component registry override
|
|
91
|
+
- `nodeNamesThatSupportChildren`: optional parent whitelist override
|
|
92
|
+
- `toolWrapper(toolName, execute)`: required wrapper used to decorate all tool executions (for logging, error handling, telemetry, etc.)
|
|
93
|
+
|
|
94
|
+
Tool behavior details:
|
|
95
|
+
|
|
96
|
+
- `setUINodeProps`: `{ id, props, replace? }`; defaults to merge mode, set `replace: true` to replace all props
|
|
97
|
+
- `addUINode`: `{ parentId?, type, props? }`; if `parentId` is omitted it defaults to root
|
|
98
|
+
- `reorderUINodes`: clamps index movement to valid sibling bounds
|
|
99
|
+
|
|
100
|
+
### `buildGenUISystemPrompt(options?)`
|
|
101
|
+
|
|
102
|
+
Builds the reusable, non-app-specific system instructions for JSON UI tooling.
|
|
103
|
+
|
|
104
|
+
Options:
|
|
105
|
+
|
|
106
|
+
- `additionalInstructions`: append app-specific guidance
|
|
107
|
+
- `requireLayoutReadBeforeAddingNodes`: defaults to `true`
|
|
108
|
+
- `styleHints`: override style metadata used in prompt text
|
|
109
|
+
|
|
110
|
+
### Registries
|
|
111
|
+
|
|
112
|
+
- `GEN_UI_NODE_NAMES`
|
|
113
|
+
- `GEN_UI_NODE_HINTS`
|
|
114
|
+
- `GEN_UI_NODE_NAMES_THAT_SUPPORT_CHILDREN`
|
|
115
|
+
- `GEN_UI_STYLES`
|
|
116
|
+
- `GEN_UI_STYLE_HINTS`
|
|
117
|
+
|
|
118
|
+
### `GenerativeUIView`
|
|
119
|
+
|
|
120
|
+
Renders a JSON UI spec directly in React Native. The default node renderer (`GenUINode`) receives style validators from the view; you can override styles or supply a custom renderer.
|
|
121
|
+
|
|
122
|
+
```tsx
|
|
123
|
+
import { GenerativeUIView } from 'json-ui-lite-rn'
|
|
124
|
+
;<GenerativeUIView spec={spec} loading={isGenerating} />
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
Props:
|
|
128
|
+
|
|
129
|
+
- `spec`: `{ root, elements }` object (or `null`/`undefined`)
|
|
130
|
+
- `loading`: optional boolean for empty-state loading text
|
|
131
|
+
- `showCollapsibleJSON`: optional boolean to render an expandable JSON debug panel
|
|
132
|
+
- `styles`: optional override for style validators (merged with default `GEN_UI_STYLES`); the resulting map is passed to `GenUINode`
|
|
133
|
+
- `GenUINodeComponent`: optional custom component to render the tree; receives `{ nodeId, elements, styles }`; delegate to default `GenUINode` for nodes you don’t handle
|
|
134
|
+
|
|
135
|
+
#### Styles from GenerativeUIView
|
|
136
|
+
|
|
137
|
+
The default `GenUINode` does not import `GEN_UI_STYLES` itself. `GenerativeUIView` merges the registry default with any `styles` prop and passes the result down as the `styles` prop to `GenUINode`. So all style validation is driven by what the view provides, and you can pass custom validators:
|
|
138
|
+
|
|
139
|
+
```tsx
|
|
140
|
+
import { z } from 'zod'
|
|
141
|
+
import { GenerativeUIView, GEN_UI_STYLES } from 'json-ui-lite-rn'
|
|
142
|
+
|
|
143
|
+
;<GenerativeUIView
|
|
144
|
+
spec={spec}
|
|
145
|
+
styles={{
|
|
146
|
+
borderRadius: z.number(),
|
|
147
|
+
}}
|
|
148
|
+
/>
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
#### Custom GenUINode example
|
|
152
|
+
|
|
153
|
+
You can supply your own node renderer and reuse the library’s style/prop parsing for custom component types. For one type render a custom component using `parseGenUIElementProps`; for everything else use the default `GenUINode`:
|
|
154
|
+
|
|
155
|
+
```tsx
|
|
156
|
+
import { View, Text, StyleSheet } from 'react-native'
|
|
157
|
+
import {
|
|
158
|
+
GenerativeUIView,
|
|
159
|
+
GenUINode,
|
|
160
|
+
parseGenUIElementProps,
|
|
161
|
+
type GenUINodeProps,
|
|
162
|
+
} from 'json-ui-lite-rn'
|
|
163
|
+
|
|
164
|
+
const BADGE_TYPE = 'Badge'
|
|
165
|
+
|
|
166
|
+
function CustomGenUINode({
|
|
167
|
+
nodeId,
|
|
168
|
+
elements,
|
|
169
|
+
styles,
|
|
170
|
+
GenUINodeComponent,
|
|
171
|
+
}: GenUINodeProps) {
|
|
172
|
+
const element = elements[nodeId]
|
|
173
|
+
if (!element) return null
|
|
174
|
+
if (element.type === BADGE_TYPE) {
|
|
175
|
+
const { baseStyle, text } = parseGenUIElementProps(element, styles, {
|
|
176
|
+
nodeId,
|
|
177
|
+
type: BADGE_TYPE,
|
|
178
|
+
})
|
|
179
|
+
return (
|
|
180
|
+
<View style={[customStyles.badge, baseStyle]}>
|
|
181
|
+
<Text style={customStyles.badgeText}>{text ?? ''}</Text>
|
|
182
|
+
</View>
|
|
183
|
+
)
|
|
184
|
+
}
|
|
185
|
+
return (
|
|
186
|
+
<GenUINode
|
|
187
|
+
nodeId={nodeId}
|
|
188
|
+
elements={elements}
|
|
189
|
+
styles={styles}
|
|
190
|
+
GenUINodeComponent={GenUINodeComponent}
|
|
191
|
+
/>
|
|
192
|
+
)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
const customStyles = StyleSheet.create({
|
|
196
|
+
badge: { alignSelf: 'flex-start', paddingHorizontal: 8, paddingVertical: 4, borderRadius: 12 },
|
|
197
|
+
badgeText: { fontSize: 12, color: '#fff' },
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
// Use the custom renderer; styles still come from the view (default or overridden).
|
|
201
|
+
<GenerativeUIView spec={spec} GenUINodeComponent={CustomGenUINode} />
|
|
202
|
+
```
|
|
203
|
+
|
|
204
|
+
## Notes
|
|
205
|
+
|
|
206
|
+
- style validation is schema-based (`zod`) through `GEN_UI_STYLES`
|
|
207
|
+
- tools are framework-agnostic as long as your spec matches `{ root, elements }`
|
|
208
|
+
- this package is intentionally minimal and optimized for small-model tool loops
|
|
209
|
+
|
|
210
|
+
## Prior art
|
|
211
|
+
|
|
212
|
+
[`json-render`](https://github.com/vercel-labs/json-render) is an alternative that has existed before this library was introduced.
|
|
213
|
+
It provides a package both for React and React Native integration and is also compatible with the [AI SDK](https://github.com/vercel/ai). Its design involves two primary concepts:
|
|
214
|
+
|
|
215
|
+
- the LLM streams the UI directly in a predefined format and all outputs are intercepted by the stream parser
|
|
216
|
+
- the library provides a (long) system prompt which well describes that format for the LLM to follow, along with examples
|
|
217
|
+
|
|
218
|
+
This is good if you are running a large language model, such as the powerful models provided by cloud providers like OpenAPI or Antrophic. However, if you are running locally, for instance using Apple Foundation models, you will encounter the following problems:
|
|
219
|
+
|
|
220
|
+
- context window size limit - Apple Foundation models have 4096 tokens, meaning roughly 2-3 times as much latin characters (even less multi-byte chars); if you consider the long system prompt (which is needed since the format is complex), you will soon run out of tokens in this window and need e.g. to summarize
|
|
221
|
+
- model comprehension - json-render introduces complex actions and state capabilities, while just generating static UIs is a complex task for small language models; thus, json-render is an overkill that the local model may not manage to power
|
|
222
|
+
|
|
223
|
+
This library solves this:
|
|
224
|
+
|
|
225
|
+
- instead of a feature-rich, complex format for streaming, we use tool calling - thus, the model outputs small JSONs in parts by calling tools on smaller pieces, reducing the probability of errors
|
|
226
|
+
- the feature set is more narrow, currently supporting only static UIs (which will change in the future), for models with less parameters to be able to complete the given tasks successfully
|
|
227
|
+
|
|
228
|
+
## License
|
|
229
|
+
|
|
230
|
+
MIT
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GenUINode = GenUINode;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _parseGenUIProps = require("./parseGenUIProps");
|
|
10
|
+
var _registry = require("./registry");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function GenUINode({
|
|
14
|
+
nodeId,
|
|
15
|
+
elements,
|
|
16
|
+
styles: styleValidators,
|
|
17
|
+
GenUINodeComponent
|
|
18
|
+
}) {
|
|
19
|
+
const element = elements[nodeId];
|
|
20
|
+
if (!element) return null;
|
|
21
|
+
const {
|
|
22
|
+
type,
|
|
23
|
+
props,
|
|
24
|
+
children = []
|
|
25
|
+
} = element;
|
|
26
|
+
const {
|
|
27
|
+
baseStyle,
|
|
28
|
+
text,
|
|
29
|
+
label
|
|
30
|
+
} = (0, _parseGenUIProps.parseGenUIElementProps)(element, styleValidators, {
|
|
31
|
+
nodeId,
|
|
32
|
+
type
|
|
33
|
+
});
|
|
34
|
+
const ChildRenderer = GenUINodeComponent ?? GenUINode;
|
|
35
|
+
const childProps = {
|
|
36
|
+
elements,
|
|
37
|
+
styles: styleValidators,
|
|
38
|
+
GenUINodeComponent
|
|
39
|
+
};
|
|
40
|
+
switch (type) {
|
|
41
|
+
case 'Container':
|
|
42
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
43
|
+
style: [styles.container, baseStyle],
|
|
44
|
+
children: children.map(id => /*#__PURE__*/(0, _jsxRuntime.jsx)(ChildRenderer, {
|
|
45
|
+
...childProps,
|
|
46
|
+
nodeId: id
|
|
47
|
+
}, id))
|
|
48
|
+
});
|
|
49
|
+
case _registry.GEN_UI_NODE_NAMES.Text:
|
|
50
|
+
case _registry.GEN_UI_NODE_NAMES.Paragraph:
|
|
51
|
+
case _registry.GEN_UI_NODE_NAMES.Label:
|
|
52
|
+
case _registry.GEN_UI_NODE_NAMES.Heading:
|
|
53
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
54
|
+
style: [styles.text, baseStyle],
|
|
55
|
+
children: text ?? label ?? ''
|
|
56
|
+
});
|
|
57
|
+
case _registry.GEN_UI_NODE_NAMES.Button:
|
|
58
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Pressable, {
|
|
59
|
+
style: [styles.button, baseStyle],
|
|
60
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
61
|
+
style: [styles.buttonText, baseStyle],
|
|
62
|
+
children: label ?? text ?? ''
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
case _registry.GEN_UI_NODE_NAMES.TextInput:
|
|
66
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.TextInput, {
|
|
67
|
+
placeholder: props?.placeholder,
|
|
68
|
+
style: [styles.textInput, baseStyle],
|
|
69
|
+
onChangeText: () => {}
|
|
70
|
+
});
|
|
71
|
+
default:
|
|
72
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
73
|
+
style: [styles.container, baseStyle],
|
|
74
|
+
children: children.map(id => /*#__PURE__*/(0, _jsxRuntime.jsx)(ChildRenderer, {
|
|
75
|
+
...childProps,
|
|
76
|
+
nodeId: id
|
|
77
|
+
}, id))
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
const styles = _reactNative.StyleSheet.create({
|
|
82
|
+
container: {
|
|
83
|
+
gap: 8,
|
|
84
|
+
flex: 1
|
|
85
|
+
},
|
|
86
|
+
text: {
|
|
87
|
+
fontSize: 16,
|
|
88
|
+
color: '#111827',
|
|
89
|
+
flex: 1
|
|
90
|
+
},
|
|
91
|
+
button: {
|
|
92
|
+
paddingHorizontal: 16,
|
|
93
|
+
paddingVertical: 10,
|
|
94
|
+
backgroundColor: '#3b82f6',
|
|
95
|
+
borderRadius: 8,
|
|
96
|
+
alignSelf: 'flex-start',
|
|
97
|
+
flex: 1
|
|
98
|
+
},
|
|
99
|
+
buttonText: {
|
|
100
|
+
flex: 1,
|
|
101
|
+
color: 'white'
|
|
102
|
+
},
|
|
103
|
+
textInput: {
|
|
104
|
+
borderWidth: 1,
|
|
105
|
+
borderColor: '#e0e0e0',
|
|
106
|
+
borderRadius: 8,
|
|
107
|
+
padding: 8,
|
|
108
|
+
fontSize: 16,
|
|
109
|
+
color: '#111827',
|
|
110
|
+
flex: 1
|
|
111
|
+
}
|
|
112
|
+
});
|
|
113
|
+
//# sourceMappingURL=GenUINode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_parseGenUIProps","_registry","_jsxRuntime","e","__esModule","default","GenUINode","nodeId","elements","styles","styleValidators","GenUINodeComponent","element","type","props","children","baseStyle","text","label","parseGenUIElementProps","ChildRenderer","childProps","jsx","View","style","container","map","id","GEN_UI_NODE_NAMES","Text","Paragraph","Label","Heading","Button","Pressable","button","buttonText","TextInput","placeholder","textInput","onChangeText","StyleSheet","create","gap","flex","fontSize","color","paddingHorizontal","paddingVertical","backgroundColor","borderRadius","alignSelf","borderWidth","borderColor","padding"],"sourceRoot":"../../src","sources":["GenUINode.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAGA,IAAAE,gBAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AAA+D,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAD,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAUxD,SAASG,SAASA,CAAC;EACxBC,MAAM;EACNC,QAAQ;EACRC,MAAM,EAAEC,eAAe;EACvBC;AACc,CAAC,EAAE;EACjB,MAAMC,OAAO,GAAGJ,QAAQ,CAACD,MAAM,CAAC;EAChC,IAAI,CAACK,OAAO,EAAE,OAAO,IAAI;EAEzB,MAAM;IAAEC,IAAI;IAAEC,KAAK;IAAEC,QAAQ,GAA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S,EAAE;IACTa,WAAW,EAAE,CAAC;IACdC,WAAW,EAAE,SAAS;IACtBH,YAAY,EAAE,CAAC;IACfI,OAAO,EAAE,CAAC;IACVT,QAAQ,EAAE,EAAE;IACZC,KAAK,EAAE,SAAS;IAChBF,IAAI,EAAE;EACR;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.GenerativeUIView = GenerativeUIView;
|
|
7
|
+
var _react = _interopRequireDefault(require("react"));
|
|
8
|
+
var _reactNative = require("react-native");
|
|
9
|
+
var _GenUINode = require("./GenUINode");
|
|
10
|
+
var _registry = require("./registry");
|
|
11
|
+
var _jsxRuntime = require("react/jsx-runtime");
|
|
12
|
+
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
13
|
+
function GenerativeUIView({
|
|
14
|
+
spec,
|
|
15
|
+
loading,
|
|
16
|
+
showCollapsibleJSON,
|
|
17
|
+
styles: stylesOverride,
|
|
18
|
+
GenUINodeComponent
|
|
19
|
+
}) {
|
|
20
|
+
const [expanded, setExpanded] = _react.default.useState(false);
|
|
21
|
+
const normalized = _react.default.useMemo(() => {
|
|
22
|
+
if (!spec?.root || !spec.elements) return null;
|
|
23
|
+
const rootElement = spec.elements[spec.root];
|
|
24
|
+
if (!rootElement) return null;
|
|
25
|
+
return spec;
|
|
26
|
+
}, [spec]);
|
|
27
|
+
const styleValidators = _react.default.useMemo(() => ({
|
|
28
|
+
..._registry.GEN_UI_STYLES,
|
|
29
|
+
...stylesOverride
|
|
30
|
+
}), [stylesOverride]);
|
|
31
|
+
if (!normalized) {
|
|
32
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
|
|
33
|
+
style: styles.placeholder,
|
|
34
|
+
children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
35
|
+
style: styles.placeholderText,
|
|
36
|
+
children: loading ? 'Loading…' : 'Use tools getGenUIRootNode, addNode, etc. to build the UI.'
|
|
37
|
+
})
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
const NodeRenderer = GenUINodeComponent ?? _GenUINode.GenUINode;
|
|
41
|
+
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
42
|
+
style: styles.wrapper,
|
|
43
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(NodeRenderer, {
|
|
44
|
+
nodeId: normalized.root,
|
|
45
|
+
elements: normalized.elements,
|
|
46
|
+
styles: styleValidators,
|
|
47
|
+
GenUINodeComponent: GenUINodeComponent
|
|
48
|
+
}), showCollapsibleJSON ? /*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.View, {
|
|
49
|
+
style: styles.jsonPanel,
|
|
50
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)(_reactNative.Pressable, {
|
|
51
|
+
onPress: () => setExpanded(prev => !prev),
|
|
52
|
+
style: styles.jsonHeader,
|
|
53
|
+
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
54
|
+
style: styles.jsonHeaderText,
|
|
55
|
+
children: "UI JSON"
|
|
56
|
+
}), /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
57
|
+
style: styles.jsonHeaderIcon,
|
|
58
|
+
children: expanded ? '[-]' : '[+]'
|
|
59
|
+
})]
|
|
60
|
+
}), expanded ? /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.Text, {
|
|
61
|
+
selectable: true,
|
|
62
|
+
style: styles.jsonText,
|
|
63
|
+
children: JSON.stringify(normalized, null, 2)
|
|
64
|
+
}) : null]
|
|
65
|
+
}) : null]
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
const styles = _reactNative.StyleSheet.create({
|
|
69
|
+
wrapper: {
|
|
70
|
+
flex: 1,
|
|
71
|
+
justifyContent: 'center',
|
|
72
|
+
gap: 8
|
|
73
|
+
},
|
|
74
|
+
jsonPanel: {
|
|
75
|
+
borderWidth: 1,
|
|
76
|
+
borderColor: '#e5e7eb',
|
|
77
|
+
borderRadius: 12,
|
|
78
|
+
paddingHorizontal: 12,
|
|
79
|
+
paddingVertical: 10,
|
|
80
|
+
backgroundColor: '#f9fafb'
|
|
81
|
+
},
|
|
82
|
+
jsonHeader: {
|
|
83
|
+
flexDirection: 'row',
|
|
84
|
+
justifyContent: 'space-between',
|
|
85
|
+
alignItems: 'center',
|
|
86
|
+
gap: 8
|
|
87
|
+
},
|
|
88
|
+
jsonHeaderText: {
|
|
89
|
+
fontSize: 13,
|
|
90
|
+
color: '#4b5563',
|
|
91
|
+
fontWeight: '600'
|
|
92
|
+
},
|
|
93
|
+
jsonHeaderIcon: {
|
|
94
|
+
fontSize: 12,
|
|
95
|
+
color: '#9ca3af',
|
|
96
|
+
fontWeight: '600'
|
|
97
|
+
},
|
|
98
|
+
jsonText: {
|
|
99
|
+
marginTop: 8,
|
|
100
|
+
fontSize: 12,
|
|
101
|
+
lineHeight: 18,
|
|
102
|
+
color: '#374151',
|
|
103
|
+
fontFamily: 'Menlo'
|
|
104
|
+
},
|
|
105
|
+
placeholder: {
|
|
106
|
+
flex: 1,
|
|
107
|
+
justifyContent: 'center',
|
|
108
|
+
padding: 24
|
|
109
|
+
},
|
|
110
|
+
placeholderText: {
|
|
111
|
+
fontSize: 15,
|
|
112
|
+
color: '#6b7280',
|
|
113
|
+
textAlign: 'center'
|
|
114
|
+
}
|
|
115
|
+
});
|
|
116
|
+
//# sourceMappingURL=GenerativeUIView.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_GenUINode","_registry","_jsxRuntime","e","__esModule","default","GenerativeUIView","spec","loading","showCollapsibleJSON","styles","stylesOverride","GenUINodeComponent","expanded","setExpanded","React","useState","normalized","useMemo","root","elements","rootElement","styleValidators","GEN_UI_STYLES","jsx","View","style","placeholder","children","Text","placeholderText","NodeRenderer","GenUINode","jsxs","wrapper","nodeId","jsonPanel","Pressable","onPress","prev","jsonHeader","jsonHeaderText","jsonHeaderIcon","selectable","jsonText","JSON","stringify","StyleSheet","create","flex","justifyContent","gap","borderWidth","borderColor","borderRadius","paddingHorizontal","paddingVertical","backgroundColor","flexDirection","alignItems","fontSize","color","fontWeight","marginTop","lineHeight","fontFamily","padding","textAlign"],"sourceRoot":"../../src","sources":["GenerativeUIView.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAGA,IAAAE,UAAA,GAAAF,OAAA;AAEA,IAAAG,SAAA,GAAAH,OAAA;AAA2D,IAAAI,WAAA,GAAAJ,OAAA;AAAA,SAAAD,uBAAAM,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAoBpD,SAASG,gBAAgBA,CAAC;EAC/BC,IAAI;EACJC,OAAO;EACPC,mBAAmB;EACnBC,MAAM,EAAEC,cAAc;EACtBC;AACqB,CAAC,EAAE;EACxB,MAAM,CAACC,QAAQ,EAAEC,WAAW,CAAC,GAAGC,cAAK,CAACC,QAAQ,CAAC,KAAK,CAAC;EACrD,MAAMC,UAAU,GAAGF,cAAK,CAACG,OAAO,CAAC,MAAM;IACrC,IAAI,CAACX,IAAI,EAAEY,IAAI,IAAI,CAACZ,IAAI,CAACa,QAAQ,EAAE,OAAO,IAAI;IAC9C,MAAMC,WAAW,GAAGd,IAAI,CAACa,QAAQ,CAACb,IAAI,CAACY,IAAI,CAAC;IAC5C,IAAI,CAACE,WAAW,EAAE,OAAO,IAAI;IAC7B,OAAOd,IAAI;EACb,CAAC,EAAE,CAACA,IAAI,CAAC,CAAC;EAEV,MAAMe,eAAkC,GAAGP,cAAK,CAACG,OAAO,CACtD,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AE,EAAE;IACZI,UAAU,EAAE,EAAE;IACdH,KAAK,EAAE,SAAS;IAChBI,UAAU,EAAE;EACd,CAAC;EACDtC,WAAW,EAAE;IACXsB,IAAI,EAAE,CAAC;IACPC,cAAc,EAAE,QAAQ;IACxBgB,OAAO,EAAE;EACX,CAAC;EACDpC,eAAe,EAAE;IACf8B,QAAQ,EAAE,EAAE;IACZC,KAAK,EAAE,SAAS;IAChBM,SAAS,EAAE;EACb;AACF,CAAC,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "DEFAULT_GEN_UI_ROOT_ID", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _registry.DEFAULT_GEN_UI_ROOT_ID;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "GEN_UI_NODE_HINTS", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _registry.GEN_UI_NODE_HINTS;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "GEN_UI_NODE_NAMES", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _registry.GEN_UI_NODE_NAMES;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "GEN_UI_NODE_NAMES_THAT_SUPPORT_CHILDREN", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _registry.GEN_UI_NODE_NAMES_THAT_SUPPORT_CHILDREN;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "GEN_UI_STYLES", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _registry.GEN_UI_STYLES;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "GEN_UI_STYLE_HINTS", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _registry.GEN_UI_STYLE_HINTS;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "GenUINode", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _GenUINode.GenUINode;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
Object.defineProperty(exports, "GenerativeUIView", {
|
|
49
|
+
enumerable: true,
|
|
50
|
+
get: function () {
|
|
51
|
+
return _GenerativeUIView.GenerativeUIView;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
Object.defineProperty(exports, "buildGenUISystemPrompt", {
|
|
55
|
+
enumerable: true,
|
|
56
|
+
get: function () {
|
|
57
|
+
return _prompt.buildGenUISystemPrompt;
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
Object.defineProperty(exports, "createGenUITools", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function () {
|
|
63
|
+
return _tools.createGenUITools;
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
Object.defineProperty(exports, "parseGenUIElementProps", {
|
|
67
|
+
enumerable: true,
|
|
68
|
+
get: function () {
|
|
69
|
+
return _parseGenUIProps.parseGenUIElementProps;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
var _GenerativeUIView = require("./GenerativeUIView");
|
|
73
|
+
var _GenUINode = require("./GenUINode");
|
|
74
|
+
var _parseGenUIProps = require("./parseGenUIProps");
|
|
75
|
+
var _prompt = require("./prompt");
|
|
76
|
+
var _registry = require("./registry");
|
|
77
|
+
var _tools = require("./tools");
|
|
78
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_GenerativeUIView","require","_GenUINode","_parseGenUIProps","_prompt","_registry","_tools"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,IAAAA,iBAAA,GAAAC,OAAA;AAIA,IAAAC,UAAA,GAAAD,OAAA;AACA,IAAAE,gBAAA,GAAAF,OAAA;AAMA,IAAAG,OAAA,GAAAH,OAAA;AAKA,IAAAI,SAAA,GAAAJ,OAAA;AAQA,IAAAK,MAAA,GAAAL,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.parseGenUIElementProps = parseGenUIElementProps;
|
|
7
|
+
/**
|
|
8
|
+
* Parses a JSON UI element's props into a baseStyle object (validated by style validators)
|
|
9
|
+
* and common fields (text, label). Use this in custom GenUINode implementations to reuse
|
|
10
|
+
* the same style and prop parsing as the default renderer.
|
|
11
|
+
*/
|
|
12
|
+
function parseGenUIElementProps(element, styleValidators, options) {
|
|
13
|
+
const {
|
|
14
|
+
nodeId = '',
|
|
15
|
+
type = ''
|
|
16
|
+
} = options ?? {};
|
|
17
|
+
const props = element.props ?? {};
|
|
18
|
+
const style = props.style;
|
|
19
|
+
const flex = props.flex;
|
|
20
|
+
const padding = props.padding;
|
|
21
|
+
const gap = props.gap;
|
|
22
|
+
const text = props.text ?? props.value ?? props.label;
|
|
23
|
+
const label = props.label ?? props.text;
|
|
24
|
+
const baseStyle = {
|
|
25
|
+
...(flex != null ? {
|
|
26
|
+
flex
|
|
27
|
+
} : {}),
|
|
28
|
+
...(padding != null ? {
|
|
29
|
+
padding
|
|
30
|
+
} : {}),
|
|
31
|
+
...(gap != null ? {
|
|
32
|
+
gap
|
|
33
|
+
} : {}),
|
|
34
|
+
...style
|
|
35
|
+
};
|
|
36
|
+
for (const key of Object.keys(props)) {
|
|
37
|
+
const validator = styleValidators[key];
|
|
38
|
+
if (validator) {
|
|
39
|
+
if (validator.safeParse(props[key]).success) {
|
|
40
|
+
baseStyle[key] = props[key];
|
|
41
|
+
} else {
|
|
42
|
+
console.warn(`[json-ui-lite-rn] Invalid style prop: ${key} for node ${nodeId} of type ${type}: ${props[key]}`);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
baseStyle,
|
|
48
|
+
text,
|
|
49
|
+
label,
|
|
50
|
+
props
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=parseGenUIProps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["parseGenUIElementProps","element","styleValidators","options","nodeId","type","props","style","flex","padding","gap","text","value","label","baseStyle","key","Object","keys","validator","safeParse","success","console","warn"],"sourceRoot":"../../src","sources":["parseGenUIProps.ts"],"mappings":";;;;;;AAkBA;AACA;AACA;AACA;AACA;AACO,SAASA,sBAAsBA,CACpCC,OAAsB,EACtBC,eAAkC,EAClCC,OAAuC,EACrB;EAClB,MAAM;IAAEC,MAAM,GAAG,EAAE;IAAEC,IAAI,GAAG;EAAG,CAAC,GAAGF,OAAO,IAAI,CAAC,CAAC;EAChD,MAAMG,KAAK,GAAGL,OAAO,CAACK,KAAK,IAAI,CAAC,CAAC;EACjC,MAAMC,KAAK,GAAGD,KAAK,CAACC,KAA4C;EAChE,MAAMC,IAAI,GAAGF,KAAK,CAACE,IAA0B;EAC7C,MAAMC,OAAO,GAAGH,KAAK,CAACG,OAA6B;EACnD,MAAMC,GAAG,GAAGJ,KAAK,CAACI,GAAyB;EAC3C,MAAMC,IAAI,GAAIL,KAAK,CAACK,IAAI,IAAIL,KAAK,CAACM,KAAK,IAAIN,KAAK,CAACO,KAA4B;EAC7E,MAAMA,KAAK,GAAIP,KAAK,CAACO,KAAK,IAAIP,KAAK,CAACK,IAA2B;EAE/D,MAAMG,SAAS,GAAG;IAChB,IAAIN,IAAI,IAAI,IAAI,GAAG;MAAEA;IAAK,CAAC,GAAG,CAAC,CAAC,CAAC;IACjC,IAAIC,OAAO,IAAI,IAAI,GAAG;MAAEA;IAAQ,CAAC,GAAG,CAAC,CAAC,CAAC;IACvC,IAAIC,GAAG,IAAI,IAAI,GAAG;MAAEA;IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAC/B,GAAGH;EACL,CAA4B;EAE5B,KAAK,MAAMQ,GAAG,IAAIC,MAAM,CAACC,IAAI,CAACX,KAAK,CAAC,EAAE;IACpC,MAAMY,SAAS,GAAGhB,eAAe,CAACa,GAAG,CAAC;IACtC,IAAIG,SAAS,EAAE;MACb,IAAIA,SAAS,CAACC,SAAS,CAACb,KAAK,CAACS,GAAG,CAAC,CAAC,CAACK,OAAO,EAAE;QAC3CN,SAAS,CAACC,GAAG,CAAC,GAAGT,KAAK,CAACS,GAAG,CAAC;MAC7B,CAAC,MAAM;QACLM,OAAO,CAACC,IAAI,CACV,yCAAyCP,GAAG,aAAaX,MAAM,YAAYC,IAAI,KAAKC,KAAK,CAACS,GAAG,CAAC,EAChG,CAAC;MACH;IACF;EACF;EAEA,OAAO;IAAED,SAAS;IAAEH,IAAI;IAAEE,KAAK;IAAEP;EAAM,CAAC;AAC1C","ignoreList":[]}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.buildGenUISystemPrompt = buildGenUISystemPrompt;
|
|
7
|
+
var _registry = require("./registry");
|
|
8
|
+
function buildGenUISystemPrompt({
|
|
9
|
+
additionalInstructions,
|
|
10
|
+
requireLayoutReadBeforeAddingNodes = true,
|
|
11
|
+
styleHints = _registry.GEN_UI_STYLE_HINTS
|
|
12
|
+
} = {}) {
|
|
13
|
+
const styleKeysText = Object.entries(styleHints).map(([key, entry]) => {
|
|
14
|
+
let text = `${key} [${entry.type}]`;
|
|
15
|
+
if (entry.description) text += ` (${entry.description})`;
|
|
16
|
+
return text;
|
|
17
|
+
}).join(', ');
|
|
18
|
+
const parts = ['You are a helpful assistant.', 'You have tools to create and update UI nodes. Before any tool calls for UI, ALWAYS CALL getUILayout before and after.', 'Remember this is React Native, not web, and use simple props.', `If you set the "style" prop on a UI node, the possible keys are: ${styleKeysText}.`, 'Remember NEVER use web values.'];
|
|
19
|
+
if (requireLayoutReadBeforeAddingNodes) {
|
|
20
|
+
parts.push('BEFORE ADDING ANY UI ELEMENTS, GET THE WHOLE UI TREE with getGenUILayout.');
|
|
21
|
+
}
|
|
22
|
+
if (additionalInstructions?.trim()) {
|
|
23
|
+
parts.push(additionalInstructions.trim());
|
|
24
|
+
}
|
|
25
|
+
return parts.join(' ');
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=prompt.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_registry","require","buildGenUISystemPrompt","additionalInstructions","requireLayoutReadBeforeAddingNodes","styleHints","GEN_UI_STYLE_HINTS","styleKeysText","Object","entries","map","key","entry","text","type","description","join","parts","push","trim"],"sourceRoot":"../../src","sources":["prompt.ts"],"mappings":";;;;;;AAAA,IAAAA,SAAA,GAAAC,OAAA;AAgBO,SAASC,sBAAsBA,CAAC;EACrCC,sBAAsB;EACtBC,kCAAkC,GAAG,IAAI;EACzCC,UAAU,GAAGC;AACgB,CAAC,GAAG,CAAC,CAAC,EAAE;EACrC,MAAMC,aAAa,GAAGC,MAAM,CAACC,OAAO,CAACJ,UAAU,CAAC,CAC7CK,GAAG,CAAC,CAAC,CAACC,GAAG,EAAEC,KAAK,CAAC,KAAK;IACrB,IAAIC,IAAI,GAAG,GAAGF,GAAG,KAAKC,KAAK,CAACE,IAAI,GAAG;IACnC,IAAIF,KAAK,CAACG,WAAW,EAAEF,IAAI,IAAI,KAAKD,KAAK,CAACG,WAAW,GAAG;IACxD,OAAOF,IAAI;EACb,CAAC,CAAC,CACDG,IAAI,CAAC,IAAI,CAAC;EAEb,MAAMC,KAAK,GAAG,CACZ,8BAA8B,EAC9B,uHAAuH,EACvH,+DAA+D,EAC/D,oEAAoEV,aAAa,GAAG,EACpF,gCAAgC,CACjC;EAED,IAAIH,kCAAkC,EAAE;IACtCa,KAAK,CAACC,IAAI,CACR,2EACF,CAAC;EACH;EAEA,IAAIf,sBAAsB,EAAEgB,IAAI,CAAC,CAAC,EAAE;IAClCF,KAAK,CAACC,IAAI,CAACf,sBAAsB,CAACgB,IAAI,CAAC,CAAC,CAAC;EAC3C;EAEA,OAAOF,KAAK,CAACD,IAAI,CAAC,GAAG,CAAC;AACxB","ignoreList":[]}
|