raizcode-ofc 1.3.0 → 1.4.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/compilador.js +82 -38
- package/package.json +1 -1
package/compilador.js
CHANGED
|
@@ -32,21 +32,26 @@ let ehSite = false;
|
|
|
32
32
|
// --- NOVAS FUNÇÕES DE ACRÉSCIMO PARA INDEPENDÊNCIA ---
|
|
33
33
|
|
|
34
34
|
function traduzirEstrutura(conteudo) {
|
|
35
|
+
if(!conteudo) return "";
|
|
35
36
|
return conteudo.split('\n').map(linha => {
|
|
36
37
|
let t = linha.trim();
|
|
37
|
-
if
|
|
38
|
-
if (t.startsWith('
|
|
38
|
+
if(!t) return "";
|
|
39
|
+
if (t.startsWith('titulo ')) return `<h1>${t.replace('titulo ', '').replace(/"/g, '')}</h1>`;
|
|
40
|
+
if (t.startsWith('texto ')) return `<p>${t.replace('texto ', '').replace(/"/g, '')}</p>`;
|
|
39
41
|
if (t.startsWith('botao ')) {
|
|
40
42
|
let p = t.replace('botao ', '').split(' id ');
|
|
41
|
-
|
|
43
|
+
let texto = p[0].replace(/"/g, '');
|
|
44
|
+
let id = p[1] ? p[1].replace(/"/g, '') : 'btn-' + Math.floor(Math.random()*1000);
|
|
45
|
+
return `<button id="${id}">${texto}</button>`;
|
|
42
46
|
}
|
|
43
|
-
if (t.startsWith('caixa ')) return `<div class="
|
|
47
|
+
if (t.startsWith('caixa ')) return `<div class="${t.replace('caixa ', '').replace(/"/g, '')}">`;
|
|
44
48
|
if (t === 'fim') return `</div>`;
|
|
45
49
|
return "";
|
|
46
50
|
}).join('');
|
|
47
51
|
}
|
|
48
52
|
|
|
49
53
|
function traduzirEstilo(conteudo) {
|
|
54
|
+
if(!conteudo) return "";
|
|
50
55
|
let css = conteudo
|
|
51
56
|
.replace(/fundo:/g, 'background:')
|
|
52
57
|
.replace(/cor-texto:/g, 'color:')
|
|
@@ -66,28 +71,7 @@ function traduzir(linha) {
|
|
|
66
71
|
if (t.startsWith('pagina ')) {
|
|
67
72
|
ehSite = true;
|
|
68
73
|
let titulo = t.replace('pagina ', '');
|
|
69
|
-
return `
|
|
70
|
-
document.title = ${titulo};
|
|
71
|
-
if(!document.getElementById('raiz-app')){
|
|
72
|
-
document.body.innerHTML = '<div id="raiz-app"></div>';
|
|
73
|
-
}
|
|
74
|
-
`;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
if (t.startsWith('titulo ')) {
|
|
78
|
-
return `document.getElementById('raiz-app').innerHTML += "<h1>" + ${t.replace('titulo ', '')} + "</h1>";`;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
if (t.startsWith('botao ')) {
|
|
82
|
-
let partes = t.replace('botao ', '').split(' acao ');
|
|
83
|
-
let texto = partes[0];
|
|
84
|
-
let acao = partes[1];
|
|
85
|
-
return `
|
|
86
|
-
const btn = document.createElement('button');
|
|
87
|
-
btn.innerText = ${texto};
|
|
88
|
-
btn.onclick = () => { ${traduzir(acao)} };
|
|
89
|
-
document.getElementById('raiz-app').appendChild(btn);
|
|
90
|
-
`;
|
|
74
|
+
return `document.title = ${titulo};`;
|
|
91
75
|
}
|
|
92
76
|
|
|
93
77
|
if (t.startsWith('alerta ')) return `alert(${t.replace('alerta ', '')});`;
|
|
@@ -137,19 +121,62 @@ try {
|
|
|
137
121
|
|
|
138
122
|
const codigo = fs.readFileSync(caminho, 'utf-8');
|
|
139
123
|
const js = codigo.split('\n').map(traduzir).join('\n');
|
|
140
|
-
const saidaJS = nomeBase + '.js';
|
|
141
|
-
|
|
142
|
-
fs.writeFileSync(saidaJS, js);
|
|
143
124
|
|
|
144
125
|
if (ehSite) {
|
|
145
|
-
|
|
126
|
+
// --- SISTEMA DE ARQUIVO TEMPORÁRIO (INVISÍVEL) ---
|
|
127
|
+
const tmpDir = os.tmpdir();
|
|
128
|
+
const nomeTemporario = 'raiz-' + Date.now() + '.html';
|
|
129
|
+
const caminhoHTMLTemporario = path.join(tmpDir, nomeTemporario);
|
|
130
|
+
|
|
146
131
|
const estruturaHTML = `
|
|
147
132
|
<!DOCTYPE html>
|
|
148
133
|
<html lang="pt-br">
|
|
149
134
|
<head>
|
|
150
135
|
<meta charset="UTF-8">
|
|
136
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
151
137
|
<style>
|
|
152
|
-
|
|
138
|
+
/* DNA Raiz - Design System Padrão (Top) */
|
|
139
|
+
body {
|
|
140
|
+
background: #0d0d0d;
|
|
141
|
+
color: #f0f0f0;
|
|
142
|
+
font-family: 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
|
|
143
|
+
display: flex;
|
|
144
|
+
justify-content: center;
|
|
145
|
+
align-items: center;
|
|
146
|
+
height: 100vh;
|
|
147
|
+
margin: 0;
|
|
148
|
+
overflow: hidden;
|
|
149
|
+
}
|
|
150
|
+
#raiz-app {
|
|
151
|
+
text-align: center;
|
|
152
|
+
border: 1px solid rgba(0,255,136,0.3);
|
|
153
|
+
padding: 50px;
|
|
154
|
+
border-radius: 20px;
|
|
155
|
+
background: #1a1a1a;
|
|
156
|
+
box-shadow: 0 10px 40px rgba(0,0,0,0.5);
|
|
157
|
+
transition: 0.3s;
|
|
158
|
+
}
|
|
159
|
+
h1 { font-size: 3.5rem; color: #00ff88; text-shadow: 0 0 15px #00ff88; margin-bottom: 10px; }
|
|
160
|
+
p { font-size: 1.2rem; color: #a0a0a0; margin-bottom: 30px; }
|
|
161
|
+
button {
|
|
162
|
+
background: linear-gradient(135deg, #00ff88, #00cc6a);
|
|
163
|
+
color: #000;
|
|
164
|
+
border: none;
|
|
165
|
+
padding: 15px 30px;
|
|
166
|
+
border-radius: 10px;
|
|
167
|
+
font-weight: bold;
|
|
168
|
+
font-size: 1rem;
|
|
169
|
+
cursor: pointer;
|
|
170
|
+
transition: 0.3s;
|
|
171
|
+
margin: 10px;
|
|
172
|
+
box-shadow: 0 5px 15px rgba(0,255,136,0.2);
|
|
173
|
+
}
|
|
174
|
+
button:hover {
|
|
175
|
+
transform: translateY(-3px) scale(1.05);
|
|
176
|
+
box-shadow: 0 10px 25px rgba(0,255,136,0.4);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/* Estilos personalizados do usuário */
|
|
153
180
|
${cssExtra}
|
|
154
181
|
</style>
|
|
155
182
|
</head>
|
|
@@ -158,17 +185,34 @@ try {
|
|
|
158
185
|
<script>${js}</script>
|
|
159
186
|
</body>
|
|
160
187
|
</html>`;
|
|
161
|
-
fs.writeFileSync(saidaHTML, estruturaHTML);
|
|
162
|
-
console.log(`🌐 [Raizcode Site] Independente gerado com sucesso!`);
|
|
163
188
|
|
|
164
|
-
//
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
189
|
+
// Gravamos o arquivo temporário
|
|
190
|
+
fs.writeFileSync(caminhoHTMLTemporario, estruturaHTML);
|
|
191
|
+
console.log(`🌐 [Raizcode Site] Gerando pré-visualização profissional...`);
|
|
192
|
+
|
|
193
|
+
// Abre o navegador sozinho no arquivo temporário
|
|
194
|
+
const cmd = os.platform() === 'win32' ? `start file://${caminhoHTMLTemporario}` :
|
|
195
|
+
(os.platform() === 'darwin' ? `open file://${caminhoHTMLTemporario}` :
|
|
196
|
+
`termux-open ${caminhoHTMLTemporario} || xdg-open ${caminhoHTMLTemporario}`);
|
|
197
|
+
|
|
198
|
+
exec(cmd, (error) => {
|
|
199
|
+
// Após 2 segundos (tempo pro navegador ler o arquivo), deletamos ele
|
|
200
|
+
setTimeout(() => {
|
|
201
|
+
if (fs.existsSync(caminhoHTMLTemporario)) {
|
|
202
|
+
fs.unlinkSync(caminhoHTMLTemporario);
|
|
203
|
+
}
|
|
204
|
+
}, 2000);
|
|
205
|
+
});
|
|
168
206
|
|
|
169
207
|
} else {
|
|
208
|
+
const saidaJS = nomeBase + '.js';
|
|
209
|
+
fs.writeFileSync(saidaJS, js);
|
|
170
210
|
execSync(`node "${saidaJS}"`, { stdio: 'inherit' });
|
|
211
|
+
// Ocultamos o JS gerado deletando ele logo após a execução
|
|
212
|
+
if (fs.existsSync(saidaJS)) {
|
|
213
|
+
fs.unlinkSync(saidaJS);
|
|
214
|
+
}
|
|
171
215
|
}
|
|
172
216
|
} catch (err) {
|
|
173
|
-
|
|
217
|
+
console.error("❌ Erro na compilação invisível.");
|
|
174
218
|
}
|