@snackbit/opendil 0.0.0 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +200 -2
  3. package/THIRD_PARTY_NOTICES.md +9 -0
  4. package/bin/opendil.mjs +20 -0
  5. package/bin/publish-directory.mjs +32 -0
  6. package/dist/chunk-ZWAN2JCV.js +2 -0
  7. package/dist/index.js +11 -0
  8. package/dist/mermaid-diagram-GFWD4Y2X.js +2 -0
  9. package/dist/runtime/frame.html +2362 -0
  10. package/dist/runtime/frame.js +4625 -0
  11. package/dist/runtime/vm.js +6 -0
  12. package/dist/shadow-renderer-F25KL3C4.js +2363 -0
  13. package/dist/styles.css +2361 -0
  14. package/dist/types/components/ui/controls/button.d.ts +10 -0
  15. package/dist/types/components/ui/controls/checkbox.d.ts +4 -0
  16. package/dist/types/components/ui/controls/input.d.ts +3 -0
  17. package/dist/types/components/ui/controls/radio-group.d.ts +5 -0
  18. package/dist/types/components/ui/controls/slider.d.ts +4 -0
  19. package/dist/types/components/ui/controls/textarea.d.ts +3 -0
  20. package/dist/types/components/ui/controls/toggle-group.d.ts +9 -0
  21. package/dist/types/components/ui/controls/toggle.d.ts +9 -0
  22. package/dist/types/components/ui/display/badge.d.ts +9 -0
  23. package/dist/types/components/ui/display/card.d.ts +9 -0
  24. package/dist/types/components/ui/display/chart.d.ts +45 -0
  25. package/dist/types/components/ui/display/separator.d.ts +4 -0
  26. package/dist/types/components/ui/display/skeleton.d.ts +2 -0
  27. package/dist/types/components/ui/display/table.d.ts +10 -0
  28. package/dist/types/components/ui/media/carousel.d.ts +19 -0
  29. package/dist/types/components/ui/overlays/popover.d.ts +10 -0
  30. package/dist/types/components/ui/overlays/tooltip.d.ts +8 -0
  31. package/dist/types/components/ui/overlays/ui-scope.d.ts +11 -0
  32. package/dist/types/dil/custom-component.d.ts +14 -0
  33. package/dist/types/dil/customization.d.ts +21 -0
  34. package/dist/types/dil/dil-renderer.d.ts +55 -0
  35. package/dist/types/dil/isolation/frame.d.ts +1 -0
  36. package/dist/types/dil/isolation/isolated-renderer.d.ts +22 -0
  37. package/dist/types/dil/isolation/shadow-renderer.d.ts +7 -0
  38. package/dist/types/dil/isolation/shadow-styles.d.ts +2 -0
  39. package/dist/types/dil/isolation/viewport-scroll.d.ts +6 -0
  40. package/dist/types/dil/isolation/vm-worker.d.ts +1 -0
  41. package/dist/types/dil/message-renderer.d.ts +16 -0
  42. package/dist/types/dil/parser/dil-parser.d.ts +33 -0
  43. package/dist/types/dil/parser/lexical.d.ts +16 -0
  44. package/dist/types/dil/parser/stream-worker.d.ts +1 -0
  45. package/dist/types/dil/parser/types.d.ts +32 -0
  46. package/dist/types/dil/renderer-environment.d.ts +22 -0
  47. package/dist/types/dil/renderer-handle.d.ts +4 -0
  48. package/dist/types/dil/runtime/action-receipt.d.ts +5 -0
  49. package/dist/types/dil/runtime/child-list.d.ts +8 -0
  50. package/dist/types/dil/runtime/document.d.ts +42 -0
  51. package/dist/types/dil/runtime/evaluation-cache.d.ts +24 -0
  52. package/dist/types/dil/runtime/execution-queue.d.ts +55 -0
  53. package/dist/types/dil/runtime/expressions.d.ts +59 -0
  54. package/dist/types/dil/runtime/markdown-stream.d.ts +17 -0
  55. package/dist/types/dil/runtime/presentation-history.d.ts +14 -0
  56. package/dist/types/dil/runtime/presentation-scheduler.d.ts +16 -0
  57. package/dist/types/dil/runtime/render-budget.d.ts +10 -0
  58. package/dist/types/dil/runtime/view-cost.d.ts +10 -0
  59. package/dist/types/dil/view/conditional-view.d.ts +12 -0
  60. package/dist/types/dil/view/loading-block.d.ts +7 -0
  61. package/dist/types/dil/view/markdown-node.d.ts +12 -0
  62. package/dist/types/dil/view/node-children.d.ts +13 -0
  63. package/dist/types/dil/view/node-view.d.ts +11 -0
  64. package/dist/types/dil/view/progressive-reveal.d.ts +6 -0
  65. package/dist/types/dil/view/render-boundary.d.ts +22 -0
  66. package/dist/types/dil/view/render-limit.d.ts +14 -0
  67. package/dist/types/dil/view/repeated-nodes.d.ts +15 -0
  68. package/dist/types/dil/view/reveal/controller.d.ts +25 -0
  69. package/dist/types/dil/view/reveal/presentation.d.ts +13 -0
  70. package/dist/types/dil/view/reveal-options.d.ts +11 -0
  71. package/dist/types/dil/view/scroll/controller.d.ts +28 -0
  72. package/dist/types/dil/view/scroll-options.d.ts +10 -0
  73. package/dist/types/dil/view/stream-follow.d.ts +8 -0
  74. package/dist/types/dil/view/table-context.d.ts +15 -0
  75. package/dist/types/dil/view/virtual-flow.d.ts +15 -0
  76. package/dist/types/dil/widgets/action-feedback.d.ts +11 -0
  77. package/dist/types/dil/widgets/async-image.d.ts +6 -0
  78. package/dist/types/dil/widgets/charts/chart-legend.d.ts +10 -0
  79. package/dist/types/dil/widgets/charts/chart-selection.d.ts +8 -0
  80. package/dist/types/dil/widgets/charts/chart-series.d.ts +11 -0
  81. package/dist/types/dil/widgets/charts/chart-snapping.d.ts +15 -0
  82. package/dist/types/dil/widgets/charts/dil-chart.d.ts +5 -0
  83. package/dist/types/dil/widgets/charts/snap-cursor.d.ts +16 -0
  84. package/dist/types/dil/widgets/charts/snap-tooltip.d.ts +10 -0
  85. package/dist/types/dil/widgets/code/code-editor.d.ts +9 -0
  86. package/dist/types/dil/widgets/code/highlighted-code.d.ts +25 -0
  87. package/dist/types/dil/widgets/code-block.d.ts +11 -0
  88. package/dist/types/dil/widgets/control-revision.d.ts +1 -0
  89. package/dist/types/dil/widgets/control-state.d.ts +8 -0
  90. package/dist/types/dil/widgets/controls.d.ts +25 -0
  91. package/dist/types/dil/widgets/graphs/graph-model.d.ts +13 -0
  92. package/dist/types/dil/widgets/graphs/node-graph.d.ts +6 -0
  93. package/dist/types/dil/widgets/graphs/service-node.d.ts +3 -0
  94. package/dist/types/dil/widgets/mermaid-diagram.d.ts +5 -0
  95. package/dist/types/dil/widgets/primitives/attribute-values.d.ts +12 -0
  96. package/dist/types/dil/widgets/primitives/primitive.d.ts +17 -0
  97. package/dist/types/dil/widgets/primitives/vocabulary.d.ts +5 -0
  98. package/dist/types/dil/widgets/use-control-value.d.ts +2 -0
  99. package/dist/types/index.d.ts +8 -0
  100. package/dist/types/lib/cn.d.ts +2 -0
  101. package/dist/types/ui.d.ts +8 -0
  102. package/dist/ui.js +2 -0
  103. package/package.json +74 -4
  104. package/styles/tailwind.css +391 -0
  105. package/styles/tokens.css +29 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2026 OpenDIL contributors
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md CHANGED
@@ -1,3 +1,201 @@
1
- # @snackbit/opendil placeholder
1
+ <div align="center">
2
2
 
3
- This version only reserves the package name. Install `@snackbit/opendil@0.1.0` or later. Source: https://github.com/snackbit/opendil
3
+ # OpenDIL
4
+
5
+ **Interactive interfaces that stream in with your model's answer.**
6
+
7
+ [![npm](https://img.shields.io/npm/v/@snackbit/opendil?color=5e4cff&label=npm)](https://www.npmjs.com/package/@snackbit/opendil)
8
+ [![CI](https://github.com/snackbit/opendil/actions/workflows/ci.yml/badge.svg)](https://github.com/snackbit/opendil/actions/workflows/ci.yml)
9
+ [![License](https://img.shields.io/badge/license-Apache--2.0-5e4cff)](https://github.com/snackbit/opendil/blob/main/LICENSE)
10
+
11
+ [Website](https://opendil.com/) · [Playground](https://opendil.com/demo/) · [Docs](https://opendil.com/docs/getting-started/) · [Agent Spec](https://opendil.com/agent-spec/)
12
+
13
+ <img src="https://raw.githubusercontent.com/snackbit/opendil/main/docs/dil-assets/streaming-demo.gif" width="880" alt="DIL source streams in on the left while a budget planner builds up on the right. After the stream ends, the team slider moves from 8 to 18, annual billing is switched on, and the total and chart update." />
14
+
15
+ </div>
16
+
17
+ OpenDIL is a React renderer for DIL (Dynamic Interface Language): Markdown with components, charts, form controls, and a little reactive state. A language model writes DIL as plain text. Your app passes along whatever has arrived so far, and OpenDIL turns it into an interface people can use before the answer is finished.
18
+
19
+ We started OpenDIL after experimenting with ChatGPT's generative UI and wanting the same thing in our own products. It is an independent project with its own documented dialect.
20
+
21
+ ## Quick start
22
+
23
+ ### 1. Install
24
+
25
+ ```sh
26
+ npm install @snackbit/opendil react react-dom
27
+ npx opendil copy-assets --out public/opendil
28
+ ```
29
+
30
+ The second command copies the sandboxed runtime that the default iframe mode loads from `/opendil/`. Skip it if you only use host or Shadow DOM mode.
31
+
32
+ ### 2. Teach your model DIL
33
+
34
+ Put the [Agent Spec](https://opendil.com/agent-spec/) in your system prompt. It covers the syntax, the stock components, and the output rules that keep documents safe to render. The source lives in [`spec/genui.agent.md`](https://github.com/snackbit/opendil/blob/main/spec/genui.agent.md).
35
+
36
+ ### 3. Render the stream
37
+
38
+ ```tsx
39
+ import { DilRenderer } from "@snackbit/opendil";
40
+ import "@snackbit/opendil/styles.css";
41
+
42
+ type AnswerProps = { id: string; text: string; streaming: boolean };
43
+
44
+ export function Answer({ id, text, streaming }: AnswerProps) {
45
+ return (
46
+ <DilRenderer key={id} text={text} isStreaming={streaming} autoScroll />
47
+ );
48
+ }
49
+ ```
50
+
51
+ Pass the full text received so far on every update and set `isStreaming={false}` after the last chunk. A new `key` starts a new document. OpenDIL never talks to your model provider, so it works with any client that streams text.
52
+
53
+ ## What DIL looks like
54
+
55
+ ```jsx
56
+ {@body const [seats, setSeats] = DIL.useState(8)}
57
+ {@body const [annual, setAnnual] = DIL.useState(true)}
58
+ <box border padding={5} radius="xl" gap={4}>
59
+ <title size="xl">A plan that grows with you</title>
60
+ <row justify="between">
61
+ <label>Team members</label>
62
+ <text>{seats}</text>
63
+ </row>
64
+ <slider
65
+ aria-label="Team members"
66
+ min={1}
67
+ max={50}
68
+ value={seats}
69
+ onChange={setSeats}
70
+ />
71
+ <checkbox checked={annual} onChange={setAnnual} lineThrough={false}>
72
+ Annual billing · save 20%
73
+ </checkbox>
74
+ <divider />
75
+ <title size="2xl">€{(seats * 29 * (annual ? 0.8 : 1)).toFixed(2)} / month</title>
76
+ <caption>{seats} seats · €29 per seat{annual ? " · annual discount applied" : ""}</caption>
77
+ <button onClick={() => GenUI.copy(JSON.stringify({ seats, annual }))}>Copy configuration</button>
78
+ </box>
79
+ ```
80
+
81
+ <img src="https://raw.githubusercontent.com/snackbit/opendil/main/apps/demo/src/site/assets/pricing.png" width="520" alt="The rendered pricing card: a team member slider set to 8, annual billing checked, and a total of €185.60 per month." />
82
+
83
+ The slider and checkbox change document state, and the price recomputes from it. Expressions such as `seats * 29` run in a QuickJS WebAssembly worker with memory and execution limits. They never run as JavaScript in your page.
84
+
85
+ ## Why OpenDIL
86
+
87
+ ### Usable while it streams
88
+
89
+ OpenDIL parses the partial document on every update. Text, charts, and controls appear as soon as their source is complete enough, so a reader can drag a slider while the model is still writing the paragraph below it. Unfinished tags don't produce guessed-size skeletons, and a control keeps its place on screen while it becomes ready.
90
+
91
+ ### Plain text a model can write
92
+
93
+ DIL reads like Markdown mixed with JSX, two formats models already produce well. A document needs no schema or tool call, and it can hold its own state, derived values, conditional views, and repeated content.
94
+
95
+ ### Sandboxed by default
96
+
97
+ The default renderer draws stock components inside an opaque-origin iframe with a strict Content Security Policy and no network access. When you need your own React components, switch to host or Shadow DOM mode and decide what you trust.
98
+
99
+ ### Built for long answers
100
+
101
+ Repeated content and large flows are virtualized, and active inputs keep their values while they scroll out of view. Our benchmark fixture renders 5,000 cards from about 2.4 MB of DIL.
102
+
103
+ ## Components
104
+
105
+ | Group | Includes |
106
+ | --------------------------------------------------------- | ------------------------------------------------------------------------- |
107
+ | [Text](https://opendil.com/docs/components/text/) | Typography, captions, icons, and status badges |
108
+ | [Layout](https://opendil.com/docs/components/layout/) | Boxes, rows, and responsive grids |
109
+ | [Inputs](https://opendil.com/docs/components/inputs/) | Text inputs, sliders, checkboxes, and radio groups |
110
+ | [Actions](https://opendil.com/docs/components/actions/) | Buttons, pressable cards, segmented controls, and conditional navigation |
111
+ | [Charts](https://opendil.com/docs/components/charts/) | Line, bar, pie, and scatter charts with hover detail and series selection |
112
+ | [Tables](https://opendil.com/docs/components/tables/) | Native tables and virtualized repeated rows |
113
+ | [Code](https://opendil.com/docs/components/code/) | Highlighted source with editing, wrapping, and copy |
114
+ | [Diagrams](https://opendil.com/docs/components/diagrams/) | React Flow graphs, Mermaid diagrams, and SVG |
115
+ | [Media](https://opendil.com/docs/components/media/) | Offline illustrations and an image carousel |
116
+ | [Overlays](https://opendil.com/docs/components/overlays/) | Popovers with keyboard support, collision handling, and focus restoration |
117
+
118
+ ## Rendering modes
119
+
120
+ | Mode | Rendering boundary | Your own React components |
121
+ | ---------------------- | ----------------------------------------- | ------------------------------- |
122
+ | `"isolated"` (default) | Sandboxed iframe without network access | Requires a custom runtime build |
123
+ | `"shadow"` | Shadow DOM scopes markup and styles | Supported |
124
+ | `"host"` | Renderer-scoped styles in your page's DOM | Supported |
125
+
126
+ All three modes keep DIL expressions in bounded QuickJS workers. Shadow DOM shares your page's JavaScript privileges, so use host and Shadow DOM mode only with documents and components you trust. The [isolation guide](https://opendil.com/docs/isolation/) covers the details.
127
+
128
+ ## Bring your own components
129
+
130
+ In host or Shadow DOM mode you can register components for new tags or replace stock ones:
131
+
132
+ ```tsx
133
+ import { DilRenderer, type DilComponentProps } from "@snackbit/opendil";
134
+ import "@snackbit/opendil/styles.css";
135
+
136
+ function Callout({
137
+ children,
138
+ className,
139
+ config,
140
+ presentationRef,
141
+ }: DilComponentProps) {
142
+ return (
143
+ <aside ref={presentationRef} className={className}>
144
+ <strong>{String(config.label ?? "Note")}</strong>
145
+ {children}
146
+ </aside>
147
+ );
148
+ }
149
+
150
+ // Keep the registry at module scope so React doesn't remount your components.
151
+ const components = { Callout };
152
+
153
+ export function Preview() {
154
+ return (
155
+ <DilRenderer
156
+ mode="host"
157
+ text="<Callout>Your application owns this component.</Callout>"
158
+ components={components}
159
+ componentConfig={{ Callout: { label: "From our design system" } }}
160
+ tokens={{ "--primary": "#156f55", "--radius": "1rem" }}
161
+ />
162
+ );
163
+ }
164
+ ```
165
+
166
+ Components receive evaluated attributes, so validate the values you accept and don't spread them onto DOM elements. Theming works through `appearance`, CSS variables in `tokens`, and per-tag `classNames`. Tailwind v4 projects can import `@snackbit/opendil/tailwind.css` instead of the compiled stylesheet. See [Customization](https://opendil.com/docs/customization/overview/).
167
+
168
+ ## Streaming options
169
+
170
+ | Prop | Default | Effect |
171
+ | ------------------- | ----------- | ------------------------------------------------------------------------------ |
172
+ | `progressiveReveal` | `false` | Fades new blocks in sequence. `true` uses a 50 ms stagger and 180 ms fade. |
173
+ | `updateInterval` | `"instant"` | Pass milliseconds to batch presentation updates. User input stays immediate. |
174
+ | `autoScroll` | `false` | Follows the stream until the reader scrolls. Accepts `behavior` and `padding`. |
175
+ | `onFollowChange` | | Reports whether the renderer is following, for a "Jump to latest" button. |
176
+
177
+ Call `resumeAutoScroll()` on the renderer ref to start following again. The [renderer reference](https://opendil.com/docs/renderer/) lists every prop.
178
+
179
+ ## Limits
180
+
181
+ DIL is a bounded document language. It doesn't compile arbitrary JSX or TypeScript, and the stock renderer has no maps, live weather, product search, or file export. Image components show offline illustrations; register a host component if you want to connect an image service.
182
+
183
+ OpenDIL needs React 19 and a browser with Web Workers, WebAssembly, and sandboxed iframes. Shadow DOM mode also needs constructable stylesheets (`adoptedStyleSheets`). The `opendil` asset CLI needs Node 22 or newer.
184
+
185
+ ## Development
186
+
187
+ ```sh
188
+ npm ci
189
+ npm run build
190
+ npm run check # format, lint, typecheck, unit tests with coverage
191
+ npx playwright install chromium
192
+ npm run test:e2e
193
+ ```
194
+
195
+ `npm run dev` rebuilds the package and starts the site on port 5173. The publishable renderer lives in `packages/opendil` and the website, playground, and docs in `apps/demo`. [CONTRIBUTING.md](https://github.com/snackbit/opendil/blob/main/CONTRIBUTING.md) covers the remaining checks and the release process. Report vulnerabilities as described in [SECURITY.md](https://github.com/snackbit/opendil/blob/main/SECURITY.md).
196
+
197
+ ## License
198
+
199
+ Apache 2.0. See [LICENSE](https://github.com/snackbit/opendil/blob/main/LICENSE) and the [third-party notices](https://github.com/snackbit/opendil/blob/main/THIRD_PARTY_NOTICES.md).
200
+
201
+ Made by [Felix Faust](https://turtledev.net).
@@ -0,0 +1,9 @@
1
+ # Third-party notices
2
+
3
+ OpenDIL uses React, Radix UI, shadcn/ui-derived primitives, Tailwind CSS, QuickJS/WASM, Acorn, Recharts, React Flow, Mermaid, DOMPurify, Lowlight/highlight.js, and other packages listed in its package manifest. The demo uses gpt-tokenizer. Their licenses remain in their distributed packages; Apache 2.0 does not replace those terms.
4
+
5
+ The maintained UI primitives were adapted from shadcn/ui, copyright shadcn, under the MIT license. Permission is granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: the above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8
+
9
+ The website uses Astro, Starlight, CodeMirror, and self-hosted Space Grotesk, Inter, and IBM Plex Mono fonts. Their licenses remain in the corresponding distributed packages. The demo showcase document is adapted from a generative UI response that a maintainer created with ChatGPT. The raw captures of that session are not part of the repository or the npm package. The image carousel uses original geometric SVG illustrations. OpenDIL is an independent project and is not affiliated with or endorsed by OpenAI.
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ import { resolve } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import { publishDirectory } from "./publish-directory.mjs";
5
+ const [command, flag, destination, ...extra] = process.argv.slice(2);
6
+ if (
7
+ command !== "copy-assets" ||
8
+ flag !== "--out" ||
9
+ !destination ||
10
+ extra.length
11
+ ) {
12
+ console.error("Usage: opendil copy-assets --out <public-directory>");
13
+ process.exitCode = 1;
14
+ } else {
15
+ const output = resolve(destination);
16
+ await publishDirectory(
17
+ fileURLToPath(new URL("../dist/runtime/", import.meta.url)),
18
+ output,
19
+ );
20
+ }
@@ -0,0 +1,32 @@
1
+ import { mkdir, readdir, copyFile, rename, rm } from "node:fs/promises";
2
+ import { join, dirname } from "node:path";
3
+ import { randomUUID } from "node:crypto";
4
+
5
+ /** Publish complete files without removing paths used by an active dev server. */
6
+ export async function publishDirectory(source, destination) {
7
+ const files = [];
8
+ async function collect(relative = "") {
9
+ for (const entry of await readdir(join(source, relative), {
10
+ withFileTypes: true,
11
+ })) {
12
+ const file = join(relative, entry.name);
13
+ if (entry.isDirectory()) await collect(file);
14
+ else files.push(file);
15
+ }
16
+ }
17
+ await collect();
18
+ const priority = (file) =>
19
+ /(?:^|\/)(?:index\.js|ui\.js|frame\.html)$/.test(file) ? 1 : 0;
20
+ files.sort((a, b) => priority(a) - priority(b));
21
+ for (const file of files) {
22
+ const target = join(destination, file);
23
+ await mkdir(dirname(target), { recursive: true });
24
+ const temporary = target + "." + randomUUID() + ".tmp";
25
+ try {
26
+ await copyFile(join(source, file), temporary);
27
+ await rename(temporary, target);
28
+ } finally {
29
+ await rm(temporary, { force: true });
30
+ }
31
+ }
32
+ }
@@ -0,0 +1,2 @@
1
+ "use client";
2
+ import{createContext as V,useContext as G,useState as _,useMemo as A}from"react";import{clsx as N}from"clsx";import{twMerge as S}from"tailwind-merge";function a(...e){return S(N(e))}import{jsx as x,jsxs as I}from"react/jsx-runtime";var y=V({container:null});function c(){return G(y)}function W({children:e,className:t,style:o,appearance:i="light",tokens:n,boundary:r,...g}){let[v,f]=_(null),T=A(()=>({container:v,...r?{boundary:r}:{}}),[v,r]);return x("section",{...g,className:a("dil-scope",t),"data-theme":i,style:{...o,...n},children:I(y.Provider,{value:T,children:[e,x("div",{"data-dil-portals":!0,ref:f})]})})}import"react";import{Popover as s}from"radix-ui";import{jsx as d}from"react/jsx-runtime";function oe({...e}){return d(s.Root,{"data-slot":"popover",...e})}function re({...e}){return d(s.Trigger,{"data-slot":"popover-trigger",...e})}function ie({className:e,align:t="center",sideOffset:o=4,...i}){let{container:n,boundary:r}=c();return d(s.Portal,{container:n,children:d(s.Content,{"data-slot":"popover-content",align:t,sideOffset:o,collisionBoundary:r,className:a("z-50 w-72 origin-(--radix-popover-content-transform-origin) rounded-md border bg-popover p-4 text-popover-foreground shadow-md outline-hidden data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2 data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=closed]:zoom-out-95 data-[state=open]:animate-in data-[state=open]:fade-in-0 data-[state=open]:zoom-in-95",e),...i})})}function ae({...e}){return d(s.Anchor,{"data-slot":"popover-anchor",...e})}import"react";import{cva as M}from"class-variance-authority";import{Slot as E}from"radix-ui";import{jsx as D}from"react/jsx-runtime";var B=M("inline-flex shrink-0 items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-all outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-primary text-primary-foreground hover:bg-primary/90",destructive:"bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:bg-destructive/60 dark:focus-visible:ring-destructive/40",outline:"border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:border-input dark:bg-input/30 dark:hover:bg-input/50",secondary:"bg-secondary text-secondary-foreground hover:bg-secondary/80",ghost:"hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",link:"text-primary underline-offset-4 hover:underline"},size:{default:"h-9 px-4 py-2 has-[>svg]:px-3",xs:"h-6 gap-1 rounded-md px-2 text-xs has-[>svg]:px-1.5 [&_svg:not([class*='size-'])]:size-3",sm:"h-8 gap-1.5 rounded-md px-3 has-[>svg]:px-2.5",lg:"h-10 rounded-md px-6 has-[>svg]:px-4",icon:"size-9","icon-xs":"size-6 rounded-md [&_svg:not([class*='size-'])]:size-3","icon-sm":"size-8","icon-lg":"size-10"}},defaultVariants:{variant:"default",size:"default"}});function ue({className:e,variant:t="default",size:o="default",asChild:i=!1,...n}){let r=i?E.Root:"button";return D(r,{"data-slot":"button","data-variant":t,"data-size":o,className:a(B({variant:t,size:o,className:e})),...n})}import{Tooltip as l}from"radix-ui";import{jsx as p,jsxs as H}from"react/jsx-runtime";function be({label:e,children:t,open:o}){let{container:i,boundary:n}=c();return p(l.Provider,{delayDuration:250,children:H(l.Root,{...o===void 0?{}:{open:o},children:[p(l.Trigger,{asChild:!0,children:t}),p(l.Portal,{container:i,children:p(l.Content,{sideOffset:6,collisionPadding:8,collisionBoundary:n,className:"dil-tooltip",children:e})})]})})}import"react";import{CheckIcon as U}from"lucide-react";import{Checkbox as R}from"radix-ui";import{jsx as b}from"react/jsx-runtime";function Ce({className:e,...t}){return b(R.Root,{"data-slot":"checkbox",className:a("peer size-4 shrink-0 rounded-[4px] border border-input shadow-xs transition-shadow outline-none focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:cursor-not-allowed disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=checked]:border-primary data-[state=checked]:bg-primary data-[state=checked]:text-primary-foreground dark:bg-input/30 dark:aria-invalid:ring-destructive/40 dark:data-[state=checked]:bg-primary",e),...t,children:b(R.Indicator,{"data-slot":"checkbox-indicator",className:"grid place-content-center text-current transition-none",children:b(U,{className:"size-3.5"})})})}import"react";import{jsx as L}from"react/jsx-runtime";function Se({className:e,type:t,...o}){return L("input",{type:t,"data-slot":"input",className:a("h-9 w-full min-w-0 rounded-md border border-input bg-transparent px-3 py-1 text-base shadow-xs transition-[color,box-shadow] outline-none selection:bg-primary selection:text-primary-foreground file:inline-flex file:h-7 file:border-0 file:bg-transparent file:text-sm file:font-medium file:text-foreground placeholder:text-muted-foreground disabled:pointer-events-none disabled:cursor-not-allowed disabled:opacity-50 md:text-sm dark:bg-input/30","focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50","aria-invalid:border-destructive aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40",e),...o})}import*as k from"react";import{Slider as u}from"radix-ui";import{jsx as h,jsxs as O}from"react/jsx-runtime";function Ie({className:e,defaultValue:t,value:o,min:i=0,max:n=100,...r}){let g=k.useMemo(()=>Array.isArray(o)?o:Array.isArray(t)?t:[i,n],[o,t,i,n]);return O(u.Root,{"data-slot":"slider",defaultValue:t,value:o,min:i,max:n,className:a("relative flex w-full touch-none items-center select-none data-[disabled]:opacity-50 data-[orientation=vertical]:h-full data-[orientation=vertical]:min-h-44 data-[orientation=vertical]:w-auto data-[orientation=vertical]:flex-col",e),...r,children:[h(u.Track,{"data-slot":"slider-track",className:a("relative grow overflow-hidden rounded-full bg-muted data-[orientation=horizontal]:h-1.5 data-[orientation=horizontal]:w-full data-[orientation=vertical]:h-full data-[orientation=vertical]:w-1.5"),children:h(u.Range,{"data-slot":"slider-range",className:a("absolute bg-primary data-[orientation=horizontal]:h-full data-[orientation=vertical]:w-full")})}),Array.from({length:g.length},(v,f)=>h(u.Thumb,{"aria-label":r["aria-label"],"aria-valuetext":r["aria-valuetext"],"data-slot":"slider-thumb",className:"block size-4 shrink-0 rounded-full border border-primary bg-white shadow-sm ring-ring/50 transition-[color,box-shadow] hover:ring-4 focus-visible:ring-4 focus-visible:outline-hidden disabled:pointer-events-none disabled:opacity-50"},f))]})}import*as m from"react";import"class-variance-authority";import{ToggleGroup as w}from"radix-ui";import"react";import{cva as $}from"class-variance-authority";import{Toggle as Ue}from"radix-ui";import{jsx as Oe}from"react/jsx-runtime";var C=$("inline-flex items-center justify-center gap-2 rounded-md text-sm font-medium whitespace-nowrap transition-[color,box-shadow] outline-none hover:bg-muted hover:text-muted-foreground focus-visible:border-ring focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-destructive/20 data-[state=on]:bg-accent data-[state=on]:text-accent-foreground dark:aria-invalid:ring-destructive/40 [&_svg]:pointer-events-none [&_svg]:shrink-0 [&_svg:not([class*='size-'])]:size-4",{variants:{variant:{default:"bg-transparent",outline:"border border-input bg-transparent shadow-xs hover:bg-accent hover:text-accent-foreground"},size:{default:"h-9 min-w-9 px-2",sm:"h-8 min-w-8 px-1.5",lg:"h-10 min-w-10 px-2.5"}},defaultVariants:{variant:"default",size:"default"}});import{jsx as P}from"react/jsx-runtime";var z=m.createContext({size:"default",variant:"default",spacing:0});function Qe({className:e,variant:t,size:o,spacing:i=0,children:n,...r}){return P(w.Root,{"data-slot":"toggle-group","data-variant":t,"data-size":o,"data-spacing":i,style:{"--gap":i},className:a("group/toggle-group flex w-fit items-center gap-[--spacing(var(--gap))] rounded-md data-[spacing=default]:data-[variant=outline]:shadow-xs",e),...r,children:P(z.Provider,{value:{variant:t,size:o,spacing:i},children:n})})}function We({className:e,children:t,variant:o,size:i,...n}){let r=m.useContext(z);return P(w.Item,{"data-slot":"toggle-group-item","data-variant":r.variant||o,"data-size":r.size||i,"data-spacing":r.spacing,className:a(C({variant:r.variant||o,size:r.size||i}),"w-auto min-w-0 shrink-0 px-3 focus:z-10 focus-visible:z-10","rounded-md data-[state=on]:bg-background data-[state=on]:shadow-sm",e),...n,children:t})}export{a,W as b,oe as c,re as d,ie as e,ae as f,B as g,ue as h,be as i,Ce as j,Se as k,Ie as l,Qe as m,We as n};