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 +21 -0
- package/README.md +188 -0
- package/dist/index.cjs +2283 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +186 -0
- package/dist/index.d.ts +186 -0
- package/dist/index.js +2269 -0
- package/dist/index.js.map +1 -0
- package/dist/react.cjs +2330 -0
- package/dist/react.cjs.map +1 -0
- package/dist/react.d.cts +145 -0
- package/dist/react.d.ts +145 -0
- package/dist/react.js +2327 -0
- package/dist/react.js.map +1 -0
- package/dist/svelte.cjs +2297 -0
- package/dist/svelte.cjs.map +1 -0
- package/dist/svelte.d.cts +152 -0
- package/dist/svelte.d.ts +152 -0
- package/dist/svelte.js +2294 -0
- package/dist/svelte.js.map +1 -0
- package/dist/vue.cjs +2327 -0
- package/dist/vue.cjs.map +1 -0
- package/dist/vue.d.cts +146 -0
- package/dist/vue.d.ts +146 -0
- package/dist/vue.js +2324 -0
- package/dist/vue.js.map +1 -0
- package/package.json +120 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Base error class for all Diorama errors.
|
|
3
|
+
* Every error has a `code` property for programmatic handling.
|
|
4
|
+
*/
|
|
5
|
+
declare class DioramaError extends Error {
|
|
6
|
+
readonly code: string;
|
|
7
|
+
constructor(code: string, message: string);
|
|
8
|
+
}
|
|
9
|
+
/** GitHub returns 404 for the repository. */
|
|
10
|
+
declare class RepoNotFoundError extends DioramaError {
|
|
11
|
+
constructor(owner: string, repo: string);
|
|
12
|
+
}
|
|
13
|
+
/** The specified branch doesn't exist. */
|
|
14
|
+
declare class BranchNotFoundError extends DioramaError {
|
|
15
|
+
constructor(owner: string, repo: string, branch: string);
|
|
16
|
+
}
|
|
17
|
+
/** GitHub API rate limit exceeded. */
|
|
18
|
+
declare class RateLimitError extends DioramaError {
|
|
19
|
+
readonly resetAt: Date | null;
|
|
20
|
+
constructor(resetTimestamp?: number);
|
|
21
|
+
}
|
|
22
|
+
/** Fetch failures, CORS issues, timeouts. */
|
|
23
|
+
declare class NetworkError extends DioramaError {
|
|
24
|
+
constructor(message?: string);
|
|
25
|
+
}
|
|
26
|
+
/** Can't detect a supported project type. */
|
|
27
|
+
declare class ProjectTypeError extends DioramaError {
|
|
28
|
+
constructor(message?: string);
|
|
29
|
+
}
|
|
30
|
+
/** Project imports a Node.js built-in module. */
|
|
31
|
+
declare class NodeBuiltinError extends DioramaError {
|
|
32
|
+
readonly moduleName: string;
|
|
33
|
+
constructor(moduleName: string);
|
|
34
|
+
}
|
|
35
|
+
/** esbuild reports a syntax error during transpilation. */
|
|
36
|
+
declare class TranspileError extends DioramaError {
|
|
37
|
+
readonly file: string;
|
|
38
|
+
readonly line?: number;
|
|
39
|
+
readonly column?: number;
|
|
40
|
+
constructor(message: string, file: string, line?: number, column?: number);
|
|
41
|
+
}
|
|
42
|
+
/** esbuild-wasm binary fails to download or initialize. */
|
|
43
|
+
declare class TranspilerLoadError extends DioramaError {
|
|
44
|
+
constructor(message?: string);
|
|
45
|
+
}
|
|
46
|
+
/** HTML assembly hits an unresolvable state. */
|
|
47
|
+
declare class AssemblyError extends DioramaError {
|
|
48
|
+
constructor(message: string);
|
|
49
|
+
}
|
|
50
|
+
/** A dependency can't be resolved on the CDN. */
|
|
51
|
+
declare class PackageNotFoundError extends DioramaError {
|
|
52
|
+
readonly packageName: string;
|
|
53
|
+
constructor(packageName: string);
|
|
54
|
+
}
|
|
55
|
+
/** No index.html or JS entry point found. */
|
|
56
|
+
declare class EntryPointError extends DioramaError {
|
|
57
|
+
constructor(message?: string);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** A fully resolved project fetched from GitHub. */
|
|
61
|
+
interface ResolvedProject {
|
|
62
|
+
owner: string;
|
|
63
|
+
repo: string;
|
|
64
|
+
branch: string;
|
|
65
|
+
/** Git tree SHA — used as cache key. */
|
|
66
|
+
sha: string;
|
|
67
|
+
/** Relative path → text file content. */
|
|
68
|
+
files: Map<string, string>;
|
|
69
|
+
/** Relative path → binary blob (images, fonts, etc.). */
|
|
70
|
+
binaryFiles: Map<string, Blob>;
|
|
71
|
+
}
|
|
72
|
+
type ProjectType = 'static' | 'static-esm' | 'jsx' | 'typescript' | 'jsx-typescript' | 'vite';
|
|
73
|
+
type Framework = 'react' | 'preact' | 'solid' | 'none';
|
|
74
|
+
/** Result of project type detection / analysis. */
|
|
75
|
+
interface ProjectConfig {
|
|
76
|
+
type: ProjectType;
|
|
77
|
+
/** Path to the main HTML file (may be generated). */
|
|
78
|
+
entryPoint: string;
|
|
79
|
+
/** npm dependencies from package.json (name → semver). */
|
|
80
|
+
dependencies: Record<string, string>;
|
|
81
|
+
framework: Framework;
|
|
82
|
+
hasJSX: boolean;
|
|
83
|
+
hasTypeScript: boolean;
|
|
84
|
+
/** JS entry point for generated HTML shells (e.g. `src/index.tsx`). */
|
|
85
|
+
jsEntryPoint?: string;
|
|
86
|
+
/** Whether the project uses Vite as its build tool. */
|
|
87
|
+
isVite: boolean;
|
|
88
|
+
}
|
|
89
|
+
type CDNProviderName = 'esm.sh' | 'skypack' | 'unpkg';
|
|
90
|
+
type CacheStrategy = 'normal' | 'aggressive';
|
|
91
|
+
type LoadingStrategy = 'eager' | 'click' | 'viewport';
|
|
92
|
+
/**
|
|
93
|
+
* Built-in decorative frame styles that wrap the rendered iframe.
|
|
94
|
+
*
|
|
95
|
+
* - `'none'` — No frame (default).
|
|
96
|
+
* - `'standard'` — Clean, minimal border with subtle shadow.
|
|
97
|
+
* - `'polaroid'` — Polaroid-photo style with thick white bottom.
|
|
98
|
+
* - `'museum'` — Ornate golden frame like a fine-art gallery.
|
|
99
|
+
* - `'terminal'` — Dark terminal / code-editor chrome.
|
|
100
|
+
* - `'postcard'` — Vintage postcard with stamp and postmark.
|
|
101
|
+
* - `'blueprint'` — Technical blueprint with grid overlay border.
|
|
102
|
+
* - `'browser'` — Browser window chrome with address bar.
|
|
103
|
+
*/
|
|
104
|
+
type FrameStyle = 'none' | 'standard' | 'polaroid' | 'museum' | 'terminal' | 'postcard' | 'blueprint' | 'browser';
|
|
105
|
+
interface DioramaOptions {
|
|
106
|
+
/** Enable localStorage caching. Default: `true`. */
|
|
107
|
+
cache?: boolean;
|
|
108
|
+
/** Cache time-to-live in seconds. Default: `3600` (1 hour). */
|
|
109
|
+
cacheTTL?: number;
|
|
110
|
+
/** Cache strategy. `'aggressive'` also caches the tree SHA. Default: `'normal'`. */
|
|
111
|
+
cacheStrategy?: CacheStrategy;
|
|
112
|
+
/** CDN used to resolve bare npm imports. Default: `'esm.sh'`. */
|
|
113
|
+
cdnProvider?: CDNProviderName;
|
|
114
|
+
/** Optional GitHub personal-access token (increases rate limit to 5 000/h). */
|
|
115
|
+
githubToken?: string;
|
|
116
|
+
/** URL to the esbuild-wasm binary. `'auto'` loads from esm.sh. */
|
|
117
|
+
esbuildWasmURL?: string | 'auto';
|
|
118
|
+
/** Maximum parallel file fetches. Default: `6`. */
|
|
119
|
+
maxConcurrentFetches?: number;
|
|
120
|
+
/** Total render timeout in milliseconds. Default: `30000`. */
|
|
121
|
+
timeout?: number;
|
|
122
|
+
}
|
|
123
|
+
interface RenderOptions {
|
|
124
|
+
/** Override the branch to render. */
|
|
125
|
+
branch?: string;
|
|
126
|
+
/** Render a subdirectory within the repo. */
|
|
127
|
+
subdirectory?: string;
|
|
128
|
+
/** When to create and populate the iframe. Default: `'eager'`. */
|
|
129
|
+
loading?: LoadingStrategy;
|
|
130
|
+
/** Image URL shown as a placeholder for `click` / `viewport` loading. */
|
|
131
|
+
placeholder?: string;
|
|
132
|
+
/** CSS height of the iframe. Default: `'500px'`. */
|
|
133
|
+
height?: string;
|
|
134
|
+
/** Decorative frame style wrapping the iframe. Default: `'none'`. */
|
|
135
|
+
frame?: FrameStyle;
|
|
136
|
+
/** Allow click-to-expand the preview to fill the viewport. Default: `false`. */
|
|
137
|
+
expand?: boolean;
|
|
138
|
+
/** Iframe sandbox flags. Default: `['allow-scripts']`. */
|
|
139
|
+
sandbox?: string[];
|
|
140
|
+
/** Override automatic project type detection. */
|
|
141
|
+
projectType?: ProjectType;
|
|
142
|
+
/** Override entry point detection. */
|
|
143
|
+
entryPoint?: string;
|
|
144
|
+
/** Glob patterns of files to include. */
|
|
145
|
+
include?: string[];
|
|
146
|
+
/** Glob patterns of files to exclude. */
|
|
147
|
+
exclude?: string[];
|
|
148
|
+
/** Called when rendering completes successfully. */
|
|
149
|
+
onLoad?: () => void;
|
|
150
|
+
/** Called when an error occurs at any pipeline stage. */
|
|
151
|
+
onError?: (error: DioramaError) => void;
|
|
152
|
+
}
|
|
153
|
+
interface DioramaInstance {
|
|
154
|
+
/** Re-fetch the project and re-render. */
|
|
155
|
+
reload(): Promise<void>;
|
|
156
|
+
/** Remove the iframe, revoke Blob URLs, clean up observers. */
|
|
157
|
+
destroy(): void;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
declare class Diorama {
|
|
161
|
+
private options;
|
|
162
|
+
private cache;
|
|
163
|
+
constructor(options?: DioramaOptions);
|
|
164
|
+
/**
|
|
165
|
+
* Fetch, transform, and render a GitHub project inside a
|
|
166
|
+
* sandboxed iframe.
|
|
167
|
+
*
|
|
168
|
+
* @param container CSS selector or DOM element.
|
|
169
|
+
* @param repoURL GitHub URL or `owner/repo` shorthand.
|
|
170
|
+
* @param options Per-render options.
|
|
171
|
+
* @returns A handle for reloading or destroying the instance.
|
|
172
|
+
*/
|
|
173
|
+
render(container: string | HTMLElement, repoURL: string, options?: RenderOptions): Promise<DioramaInstance>;
|
|
174
|
+
/**
|
|
175
|
+
* Pre-fetch a project (resolve + cache) without rendering.
|
|
176
|
+
*/
|
|
177
|
+
prefetch(repoURL: string, options?: Pick<RenderOptions, 'branch' | 'subdirectory'>): Promise<void>;
|
|
178
|
+
/**
|
|
179
|
+
* Clear cached data.
|
|
180
|
+
* @param repoSlug Optional `owner/repo` to clear a specific entry.
|
|
181
|
+
*/
|
|
182
|
+
clearCache(repoSlug?: string): void;
|
|
183
|
+
private fetchProject;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
export { AssemblyError, BranchNotFoundError, type CDNProviderName, type CacheStrategy, Diorama, DioramaError, type DioramaInstance, type DioramaOptions, EntryPointError, type FrameStyle, type Framework, type LoadingStrategy, NetworkError, NodeBuiltinError, PackageNotFoundError, type ProjectConfig, type ProjectType, ProjectTypeError, RateLimitError, type RenderOptions, RepoNotFoundError, type ResolvedProject, TranspileError, TranspilerLoadError };
|