Skip to content

Commit

Permalink
Clean and improve structure of salam-online
Browse files Browse the repository at this point in the history
  • Loading branch information
BaseMax committed Jan 6, 2025
1 parent 4eceea7 commit 1776417
Show file tree
Hide file tree
Showing 16 changed files with 55 additions and 54 deletions.
94 changes: 40 additions & 54 deletions salam-online.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,12 @@
width="100%"
height="100%"
></iframe>
<pre style="width: 100%" dir="ltr"></pre>
<script>
<pre id="error" style="width: 100%; color: red;" dir="ltr"></pre>
<pre id="output" style="width: 100%" dir="ltr"></pre>
<script type="text/javascript">
const iframe = document.querySelector('iframe');
const outputPre = document.querySelector('pre');
const outputPre = document.querySelector('#output');
const errorPre = document.querySelector('#error');
const codeTextArea = document.querySelector('#code');
const executeButton = document.querySelector('#execute');

Expand All @@ -90,25 +92,27 @@
}
},
print: (text) => {
console.log(text);
customLogger(text, 'log');
},
printErr: (text) => {
customLogger(text, 'error');
},
};

const restartRuntime = () => {
console.log('Restarting runtime...');
const customLogger = (text, type) => {
if (type === 'error') {
console.error(text);
} else {
console.log(text);
}

Module.onRuntimeInitialized();
Module._main();
};
const prefix = type === 'error' ? 'Error: ' : '';

const reloadModule = () => {
const script = document.createElement('script');
script.src = 'salam-wa.js';
script.onload = () => {
console.log('Salam module reloaded.');
};

document.body.appendChild(script);
if (prefix === "") {
outputPre.textContent += prefix + text + '\n';
} else {
errorPre.textContent += prefix + text + '\n';
}
};

const runSalam = () => {
Expand All @@ -130,20 +134,8 @@
};

const captureOutput = (arguments) => {
if (outputPre) {
outputPre.textContent = '';
}

let output = '';
const originalConsoleLog = console.log;
const originalConsoleError = console.error;

console.log = (text) => {
output += text + '\n';
};
console.error = (text) => {
output += 'Error: ' + text + '\n';
};
outputPre.textContent = "";
errorPre.textContent = "";

if (is_running) {
return;
Expand All @@ -155,41 +147,35 @@
if (typeof callMain === 'function') {
try {
callMain(arguments);

const iframeDocument = iframe.contentDocument || iframe.contentWindow.document;

if (iframeDocument) {
iframe.srcdoc = outputPre.textContent;
}
} catch (err) {
console.error('Runtime error:', err);
Module.printErr('Runtime error: ' + err);
}
} else {
console.error(
Module.printErr(
'callMain is not defined. Ensure NO_EXIT_RUNTIME is enabled.',
);
}
} catch (err) {
console.error('خطای غیرمنتظره رخ داد. ' + err);
Module.printErr('خطای غیرمنتظره رخ داد. ' + err);
} finally {
is_running = false;

// if (Module.noInitialRun) {
// restartRuntime();
// }
}

if (outputPre) {
outputPre.textContent = output;

const iframeDocument =
iframe.contentDocument || iframe.contentWindow.document;

if (iframeDocument) {
iframeDocument.open();
iframeDocument.write(output);
iframeDocument.close();
}
}
};

console.log = originalConsoleLog;
console.error = originalConsoleError;
const reloadModule = () => {
const script = document.createElement('script');
script.src = 'salam-wa.js';
script.onload = () => {
console.log('Salam module reloaded.');
};

return output;
document.body.appendChild(script);
};

executeButton.addEventListener('click', () => {
Expand Down
1 change: 1 addition & 0 deletions src/generated-config/ast_block_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,6 @@ ADD_BLOCK_TYPE(AST_BLOCK_TYPE_ERROR, "ERROR", "error")






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_attribute_style_global.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,6 @@ ADD_LAYOUT_ATTRIBUTE_STYLE_GLOBAL_VALUE(unset, "حذف شده")






Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ ADD_LAYOUT_ATTRIBUTE_STYLE_STATE_TYPE(AST_LAYOUT_ATTRIBUTE_STYLE_STATE_TYPE_EMPT






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_attribute_style_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -607,5 +607,6 @@ ADD_LAYOUT_ATTRIBUTE_STYLE_TYPE_HIDE(AST_LAYOUT_ATTRIBUTE_STYLE_TYPE_ERROR, "ERR






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_attribute_style_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -1511,5 +1511,6 @@ const ast_layout_attribute_pair_t ast_layout_allowed_style_list_zoom[] = {






Original file line number Diff line number Diff line change
Expand Up @@ -398,5 +398,6 @@ extern const ast_layout_attribute_pair_t ast_layout_allowed_style_list_zoom[];






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_attribute_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,5 +109,6 @@ ADD_LAYOUT_ATTRIBUTE_TYPE(AST_LAYOUT_ATTRIBUTE_TYPE_RESPONSIVE_MIN_HEIGHT, "RESP






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_attribute_value.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,6 @@ const ast_layout_attribute_pair_t ast_layout_allowed_lang[] = {






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_attribute_value_extern.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,5 +53,6 @@ extern const ast_layout_attribute_pair_t ast_layout_allowed_lang[];






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -168,5 +168,6 @@ ADD_LAYOUT_TYPE_REPEAT(AST_LAYOUT_TYPE_MEDIA, "MEDIA", "media", "@media", "وا






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_type_attributes.h
Original file line number Diff line number Diff line change
Expand Up @@ -193,5 +193,6 @@ else if (attribute->parent_node_type == AST_LAYOUT_TYPE_MEDIA) {






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_type_attributes_all.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,6 @@ const size_t map_size = sizeof(layout_map) / sizeof(layout_map[0]);






1 change: 1 addition & 0 deletions src/generated-config/ast_layout_type_attributes_values.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,5 +253,6 @@ const size_t valid_attributes_media_length = 0;






Original file line number Diff line number Diff line change
Expand Up @@ -191,5 +191,6 @@ extern const size_t valid_attributes_media_length;






1 change: 1 addition & 0 deletions src/generated-config/ast_type.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,6 @@ ADD_TYPE(AST_TYPE_ERROR, "ERROR", "error")






0 comments on commit 1776417

Please sign in to comment.