Download web/src/apps/code/frameDocument.ts from fsanyoto/loopable: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/apps/code/frameDocument.ts
- Command line
-
hf download hf://spaces/fsanyoto/loopable/web/src/apps/code/frameDocument.ts
-
curl -L -o frameDocument.ts https://huggingface.co/spaces/fsanyoto/loopable/resolve/main/web/src/apps/code/frameDocument.ts
1.03 kB
| import { bridgeScript } from "./bridge"; | |
| export const CODE_APP_SANDBOX = "allow-scripts"; | |
| export const CODE_APP_MAX_BYTES = 512 * 1024; | |
| const POLICY = "default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline'; connect-src 'none'; img-src 'none'; font-src data:; media-src 'none'; object-src 'none'; frame-src 'none'; worker-src 'none'; base-uri 'none'; form-action 'none'"; | |
| const POLICY_META = `<meta http-equiv="Content-Security-Policy" content="${POLICY}">`; | |
| export function checkCodeAppSize(html: string): void { | |
| if (new TextEncoder().encode(html).byteLength > CODE_APP_MAX_BYTES) { | |
| throw new RangeError("This App is too large to open."); | |
| } | |
| } | |
| export function appDocument(html: string, css: string): string { | |
| checkCodeAppSize(html); | |
| // Escape stylesheet markup so the kit cannot close its host-owned style element. | |
| const stylesheet = css.replace(/</g, "\\3c "); | |
| return `<!doctype html>${POLICY_META}<meta charset="utf-8"><style>${stylesheet}</style><script>${bridgeScript()}</script>${html}`; | |
| } | |