generated from google-gemini/aistudio-repository-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
194 lines (170 loc) · 6.58 KB
/
index.html
File metadata and controls
194 lines (170 loc) · 6.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html>
<html lang="pt-BR">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>AllFines | Premium Audio</title>
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@300;400;500;600;700&family=Inter:wght@300;400;500;600&display=swap" rel="stylesheet">
<!-- Tailwind -->
<script src="https://cdn.tailwindcss.com"></script>
<script>
tailwind.config = {
theme: {
extend: {
fontFamily: {
sans: ['Inter', 'sans-serif'],
display: ['Space Grotesk', 'sans-serif'],
},
colors: {
agency: {
yellow: '#FFD700',
black: '#0a0a0a',
dark: '#020617',
slate: '#1e293b',
}
},
animation: {
'pulse-slow': 'pulse 3s cubic-bezier(0.4, 0, 0.6, 1) infinite',
'fade-in': 'fadeIn 0.5s ease-out forwards',
},
keyframes: {
fadeIn: {
'0%': { opacity: '0', transform: 'translateY(10px)' },
'100%': { opacity: '1', transform: 'translateY(0)' },
}
}
}
}
}
</script>
<style>
html { overflow-y: auto; }
body { background-color: #020617; color: white; }
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: #020617; }
::-webkit-scrollbar-thumb { background: #334155; border-radius: 0px; }
::-webkit-scrollbar-thumb:hover { background: #FFD700; }
</style>
<!-- Babel Standalone -->
<script src="https://unpkg.com/@babel/standalone@7.24.7/babel.min.js"></script>
<!-- Import map das libs - CORRIGIDO -->
<script type="importmap">
{
"imports": {
"react": "https://esm.sh/react@18.2.0",
"react-dom/client": "https://esm.sh/react-dom@18.2.0/client",
"react/jsx-runtime": "https://esm.sh/react@18.2.0/jsx-runtime",
"lucide-react": "https://esm.sh/lucide-react@0.454.0?external=react",
"@google/genai": "https://esm.sh/@google/generative-ai@0.21.0",
"@google/generative-ai": "https://esm.sh/@google/generative-ai@0.21.0"
}
}
</script>
<!-- Pré-carrega o entry -->
<link rel="preload" href="/index.tsx" as="fetch" crossorigin="anonymous" />
</head>
<body class="bg-agency-dark text-white font-sans">
<noscript>Você precisa habilitar o JavaScript para rodar esta aplicação.</noscript>
<div id="root"></div>
<script type="module">
// Polyfill para process.env
globalThis.process = globalThis.process || { env: { NODE_ENV: 'production' } };
const blobCache = new Map();
// Carrega o arquivo TS/TSX, tentando extensões padrão (.tsx, .ts, /index.tsx, /index.ts)
async function loadSource(path, parentUrl) {
const baseUrl = new URL(path, parentUrl).href;
// Se já tem extensão, tenta direto
if (/\.(tsx?|jsx?)($|\?)/.test(baseUrl)) {
const res = await fetch(baseUrl);
if (!res.ok) throw new Error('Não foi possível carregar ' + baseUrl);
return { absoluteUrl: baseUrl, sourceCode: await res.text() };
}
const base = baseUrl.replace(/\/$/, '');
const candidates = [
base + '.tsx',
base + '.ts',
base + '/index.tsx',
base + '/index.ts',
];
for (const url of candidates) {
try {
const res = await fetch(url);
if (res.ok) {
return { absoluteUrl: url, sourceCode: await res.text() };
}
} catch (_) {
// ignora, tenta o próximo
}
}
throw new Error('Não foi possível encontrar o arquivo para ' + baseUrl);
}
async function resolveAndTranspile(entryPath, parentUrl = window.location.href) {
// 1) Descobre o arquivo real (.tsx/.ts) e lê o código-fonte
const { absoluteUrl, sourceCode } = await loadSource(entryPath, parentUrl);
// Cache por arquivo real (URL com extensão)
if (blobCache.has(absoluteUrl)) {
return blobCache.get(absoluteUrl);
}
// 2) Descobre imports relativos (somente "import ... from '...';")
const importRegex = /\bimport\s+[^'"]*['"](.*?)['"]/g;
const dependencies = new Map();
let match;
while ((match = importRegex.exec(sourceCode)) !== null) {
const depPath = match[1];
if (depPath.startsWith('.')) {
dependencies.set(depPath, null);
}
}
// 3) Resolve recursivamente as dependências em paralelo
await Promise.all(
Array.from(dependencies.keys()).map(async (depPath) => {
const childBlobUrl = await resolveAndTranspile(depPath, absoluteUrl);
dependencies.set(depPath, childBlobUrl);
})
);
// 4) Reescreve os imports locais para apontar para os blobs
let transformedCode = sourceCode;
for (const [originalPath, blobUrl] of dependencies.entries()) {
const escapedPath = originalPath.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
const re = new RegExp(`(['"])${escapedPath}\\1`, 'g');
transformedCode = transformedCode.replace(re, `$1${blobUrl}$1`);
}
// 5) PATCH: Corrige GoogleGenAI -> GoogleGenerativeAI
transformedCode = transformedCode.replace(/\bGoogleGenAI\b/g, 'GoogleGenerativeAI');
// 6) Transpila TSX -> JS com Babel (React + TypeScript)
const { code } = Babel.transform(transformedCode, {
presets: [
['react', { runtime: 'automatic' }],
['typescript', { allExtensions: true, isTSX: true }]
],
sourceType: 'module',
filename: absoluteUrl
});
// 7) Cria um Blob URL para esse módulo e guarda em cache
const blobUrl = URL.createObjectURL(
new Blob([code], { type: 'application/javascript' })
);
blobCache.set(absoluteUrl, blobUrl);
return blobUrl;
}
(async () => {
try {
// Entrada da app: ajuste aqui se seu entry não for /index.tsx
const entryModuleUrl = await resolveAndTranspile('/index.tsx');
await import(entryModuleUrl);
} catch (error) {
console.error('Falha ao inicializar a aplicação:', error);
const rootEl = document.getElementById('root');
rootEl.innerHTML =
`<div style="color:#ff8b8b; background:#2b0f0f; padding:20px; border-radius:8px; font-family:monospace; white-space:pre-wrap; margin: 20px;">
<h2>Erro na Aplicação</h2>
<p>${error.message}</p>
</div>`;
}
})();
</script>
</body>
</html>