diorama-js 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Rebecca Rozansky
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,188 @@
1
+ # Diorama
2
+
3
+ **JavaScript library that renders GitHub-hosted web projects in a sandboxed iframe.**
4
+
5
+ Diorama is an iframe wrapper that allows developers to easily showcase existing projects via just a Github link on a portfolio or any other website. Give Diorama a GitHub URL and it fetches the source files, transforms them as needed (import rewriting, JSX/TypeScript transpilation), and renders the running project inline, all entirely in the browser.
6
+
7
+ ## Quick Start
8
+
9
+ ### Install
10
+
11
+ ```bash
12
+ npm install diorama-js
13
+ ```
14
+
15
+ ### Vanilla JS
16
+
17
+ ```javascript
18
+ import { Diorama } from 'diorama-js';
19
+
20
+ const diorama = new Diorama();
21
+
22
+ await diorama.render('#container', 'https://github.com/user/repo', {
23
+ height: '500px',
24
+ loading: 'eager',
25
+ });
26
+ ```
27
+
28
+ ### React
29
+
30
+ ```tsx
31
+ import { DioramaPreview } from 'diorama-js/react';
32
+
33
+ function Portfolio() {
34
+ return (
35
+ <DioramaPreview
36
+ repo="https://github.com/user/repo"
37
+ loading="click"
38
+ height="500px"
39
+ onLoad={() => console.log('loaded!')}
40
+ />
41
+ );
42
+ }
43
+ ```
44
+
45
+ ### Vue
46
+
47
+ ```javascript
48
+ <template>
49
+ <DioramaPreview
50
+ repo="https://github.com/user/repo"
51
+ loading="viewport"
52
+ height="500px"
53
+ />
54
+ </template>
55
+
56
+ <script setup>
57
+ import { DioramaPreview } from 'diorama-js/vue';
58
+ </script>
59
+ ```
60
+
61
+ ### Svelte
62
+
63
+ ```javascript
64
+ <script>
65
+ import { dioramaAction } from 'diorama-js/svelte';
66
+ </script>
67
+
68
+ <div use:dioramaAction={{ repo: 'user/repo', height: '500px' }} />
69
+ ```
70
+
71
+ ## Supported Project Types
72
+
73
+ ### Tier 1 — Static (no build step)
74
+ - `index.html` + CSS + JS with no npm imports
75
+ - Projects using CDN-loaded libraries via `<script>` tags
76
+ - Canvas games, D3 visualizations, vanilla single-page apps
77
+
78
+ ### Tier 2 — Static with ESM imports
79
+ - ES module `import` statements from npm packages
80
+ - Bare imports are automatically rewritten to CDN URLs ([esm.sh](https://esm.sh))
81
+ - Relative imports resolve via import maps
82
+
83
+ ### Tier 3 — JSX and TypeScript
84
+ - React and Preact projects with `.jsx` / `.tsx` files
85
+ - TypeScript projects with `.ts` files
86
+ - Transpilation via esbuild-wasm (lazy-loaded, ~8MB)
87
+
88
+ ## API Reference
89
+
90
+ ### `new Diorama(options?)`
91
+
92
+ Create a Diorama instance with global configuration.
93
+
94
+ | Option | Type | Default | Description |
95
+ |---|---|---|---|
96
+ | `cache` | `boolean` | `true` | Enable localStorage caching |
97
+ | `cacheTTL` | `number` | `3600` | Cache TTL in seconds |
98
+ | `cacheStrategy` | `'normal' \| 'aggressive'` | `'normal'` | Aggressive skips even the tree API call within 5 min |
99
+ | `cdnProvider` | `'esm.sh' \| 'skypack' \| 'unpkg'` | `'esm.sh'` | CDN for resolving bare npm imports |
100
+ | `githubToken` | `string` | `undefined` | GitHub PAT for higher API rate limits (60/h → 5000/h) |
101
+ | `esbuildWasmURL` | `string` | `'auto'` | Custom URL for the esbuild-wasm binary |
102
+ | `maxConcurrentFetches` | `number` | `6` | Parallel file fetch limit |
103
+ | `timeout` | `number` | `30000` | Total render timeout in ms |
104
+
105
+ ### `diorama.render(container, repoURL, options?)`
106
+
107
+ Render a GitHub project. Returns a `Promise<DioramaInstance>`.
108
+
109
+ | Option | Type | Default | Description |
110
+ |---|---|---|---|
111
+ | `branch` | `string` | auto | Branch to render |
112
+ | `subdirectory` | `string` | — | Subdirectory within the repo |
113
+ | `loading` | `'eager' \| 'click' \| 'viewport'` | `'eager'` | When to create the iframe |
114
+ | `placeholder` | `string` | — | Image URL for click/viewport placeholder |
115
+ | `height` | `string` | `'500px'` | CSS height of the iframe |
116
+ | `sandbox` | `string[]` | `['allow-scripts']` | Iframe sandbox flags |
117
+ | `projectType` | `string` | auto | Override project type detection |
118
+ | `entryPoint` | `string` | auto | Override entry point detection |
119
+ | `onLoad` | `() => void` | — | Called when rendering completes |
120
+ | `onError` | `(err) => void` | — | Called on failure |
121
+ | `frame` | `FrameStyle` | `'none'` | Decorative frame wrapping the iframe |
122
+ | `expand` | `boolean` | `false` | Allow click-to-expand fullscreen lightbox |
123
+
124
+ #### Frame styles
125
+
126
+ | Value | Description |
127
+ |---|---|
128
+ | `'none'` | No frame (default) |
129
+ | `'standard'` | Clean border with subtle shadow |
130
+ | `'polaroid'` | Polaroid photo with white border and handwritten caption |
131
+ | `'museum'` | Ornate golden frame with inner mat |
132
+ | `'terminal'` | Dark terminal chrome with traffic-light dots |
133
+ | `'postcard'` | Vintage postcard with stamp and postmark |
134
+ | `'blueprint'` | Technical blueprint with grid overlay |
135
+ | `'browser'` | Browser window chrome with address bar |
136
+
137
+ ### Instance methods
138
+
139
+ ```javascript
140
+ const instance = await diorama.render('#el', 'user/repo');
141
+
142
+ instance.reload(); // Re-fetch and re-render
143
+ instance.destroy(); // Clean up iframe, Blob URLs, observers
144
+ ```
145
+
146
+ ### Utility methods
147
+
148
+ ```javascript
149
+ diorama.clearCache(); // Clear all cached projects
150
+ diorama.clearCache('user/repo'); // Clear a specific repo
151
+ diorama.prefetch('user/repo'); // Pre-fetch without rendering
152
+ ```
153
+
154
+ ## Error Handling
155
+
156
+ All errors extend `DioramaError` with a `code` property:
157
+
158
+ | Error | Code | Trigger |
159
+ |---|---|---|
160
+ | `RepoNotFoundError` | `REPO_NOT_FOUND` | Repository doesn't exist or is private |
161
+ | `BranchNotFoundError` | `BRANCH_NOT_FOUND` | Branch doesn't exist |
162
+ | `RateLimitError` | `RATE_LIMIT` | GitHub API rate limit exceeded |
163
+ | `NetworkError` | `NETWORK_ERROR` | Fetch failures or timeouts |
164
+ | `NodeBuiltinError` | `NODE_BUILTIN` | Project imports a Node.js module |
165
+ | `TranspileError` | `TRANSPILE_FAILED` | Syntax error in JSX/TS |
166
+ | `EntryPointError` | `NO_ENTRY_POINT` | No entry point found |
167
+
168
+ Errors are displayed as a styled message inside the iframe, so users always see actionable feedback.
169
+
170
+ ## Not Supported
171
+
172
+ These require server-side runtimes and is currently not supported:
173
+
174
+ - Next.js, Remix, SvelteKit, Astro
175
+ - Node.js APIs (`fs`, `path`, `crypto`, `http`, etc.)
176
+ - Backend servers or database connections
177
+
178
+ ## Browser Support
179
+
180
+ Chrome 89+, Firefox 108+, Safari 16.4+, Edge 89+ (import maps required for ESM projects).
181
+
182
+ ## Contributing
183
+
184
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for development setup and guidelines.
185
+
186
+ ## License
187
+
188
+ [MIT](LICENSE)