raizcode-ofc 1.3.0 → 1.5.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 +34 -37
- 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 ', '')});`;
|
|
@@ -119,7 +103,6 @@ if (!fs.existsSync(caminho)) {
|
|
|
119
103
|
}
|
|
120
104
|
|
|
121
105
|
try {
|
|
122
|
-
// Busca arquivos companheiros (.rcx e .estilo)
|
|
123
106
|
const arqRcx = nomeBase + '.rcx';
|
|
124
107
|
const arqEstilo = nomeBase + '.estilo';
|
|
125
108
|
|
|
@@ -137,19 +120,23 @@ try {
|
|
|
137
120
|
|
|
138
121
|
const codigo = fs.readFileSync(caminho, 'utf-8');
|
|
139
122
|
const js = codigo.split('\n').map(traduzir).join('\n');
|
|
140
|
-
const saidaJS = nomeBase + '.js';
|
|
141
|
-
|
|
142
|
-
fs.writeFileSync(saidaJS, js);
|
|
143
123
|
|
|
124
|
+
// Nomes dos arquivos que vamos "esconder"
|
|
125
|
+
const saidaJS = nomeBase + '.js';
|
|
126
|
+
const saidaHTML = nomeBase + '.html';
|
|
127
|
+
|
|
144
128
|
if (ehSite) {
|
|
145
|
-
const saidaHTML = nomeBase + '.html';
|
|
146
129
|
const estruturaHTML = `
|
|
147
130
|
<!DOCTYPE html>
|
|
148
131
|
<html lang="pt-br">
|
|
149
132
|
<head>
|
|
150
133
|
<meta charset="UTF-8">
|
|
134
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
151
135
|
<style>
|
|
152
|
-
body { background: #
|
|
136
|
+
body { background: #0d0d0d; color: #f0f0f0; font-family: sans-serif; display: flex; justify-content: center; align-items: center; height: 100vh; margin: 0; }
|
|
137
|
+
#raiz-app { text-align: center; border: 1px solid #00ff88; padding: 40px; border-radius: 20px; background: #1a1a1a; box-shadow: 0 0 30px rgba(0,255,136,0.2); }
|
|
138
|
+
h1 { color: #00ff88; text-shadow: 0 0 10px #00ff88; }
|
|
139
|
+
button { background: #00ff88; color: #000; border: none; padding: 15px 30px; border-radius: 10px; font-weight: bold; cursor: pointer; margin: 10px; }
|
|
153
140
|
${cssExtra}
|
|
154
141
|
</style>
|
|
155
142
|
</head>
|
|
@@ -158,17 +145,27 @@ try {
|
|
|
158
145
|
<script>${js}</script>
|
|
159
146
|
</body>
|
|
160
147
|
</html>`;
|
|
148
|
+
|
|
161
149
|
fs.writeFileSync(saidaHTML, estruturaHTML);
|
|
162
|
-
console.log(`🌐 [Raizcode
|
|
150
|
+
console.log(`🌐 [Raizcode] Abrindo pré-visualização...`);
|
|
151
|
+
|
|
152
|
+
const cmd = os.platform() === 'win32' ? `start ${saidaHTML}` :
|
|
153
|
+
(os.platform() === 'darwin' ? `open ${saidaHTML}` :
|
|
154
|
+
`termux-open ${saidaHTML}`);
|
|
163
155
|
|
|
164
|
-
// Abre o navegador sozinho
|
|
165
|
-
const url = `file://${saidaHTML}`;
|
|
166
|
-
const cmd = os.platform() === 'win32' ? `start ${url}` : (os.platform() === 'darwin' ? `open ${url}` : `termux-open ${url} || xdg-open ${url}`);
|
|
167
156
|
exec(cmd);
|
|
168
157
|
|
|
158
|
+
// LIMPEZA: Apaga o HTML depois de 5 segundos (tempo de abrir)
|
|
159
|
+
setTimeout(() => {
|
|
160
|
+
if (fs.existsSync(saidaHTML)) fs.unlinkSync(saidaHTML);
|
|
161
|
+
if (fs.existsSync(saidaJS)) fs.unlinkSync(saidaJS);
|
|
162
|
+
}, 5000);
|
|
163
|
+
|
|
169
164
|
} else {
|
|
165
|
+
fs.writeFileSync(saidaJS, js);
|
|
170
166
|
execSync(`node "${saidaJS}"`, { stdio: 'inherit' });
|
|
167
|
+
if (fs.existsSync(saidaJS)) fs.unlinkSync(saidaJS);
|
|
171
168
|
}
|
|
172
169
|
} catch (err) {
|
|
173
|
-
|
|
170
|
+
console.error("❌ Erro ao processar.");
|
|
174
171
|
}
|