Skip to content

Commit

Permalink
Merge branch 'main' into gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
salif committed Sep 24, 2024
2 parents 3ba8f97 + 7fd8ff0 commit e83d15c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion build/dev/javascript/gleam_version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.4.1
1.5.0
21 changes: 12 additions & 9 deletions build/dev/javascript/prelude.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ export class List {
return desired === 0;
}

// @internal
countLength() {
let length = 0;
for (let _ of this) length++;
Expand Down Expand Up @@ -169,24 +170,24 @@ export function sizedInt(value, size, isBigEndian) {

// Convert negative number to two's complement representation
if (value < 0) {
value = (2 ** size) + value;
value = 2 ** size + value;
}

if (isBigEndian) {
for (let i = 0; i < byteArray.length; i++) {
const byte = value % 256
for (let i = byteArray.length - 1; i >= 0; i--) {
const byte = value % 256;
byteArray[i] = byte;
value = (value - byte) / 256;
}
} else {
for (let i = byteArray.length - 1; i >= 0; i--) {
const byte = value % 256
for (let i = 0; i < byteArray.length; i++) {
const byte = value % 256;
byteArray[i] = byte;
value = (value - byte) / 256;
}
}

return byteArray.reverse();
return byteArray;
}

// @internal
Expand Down Expand Up @@ -226,9 +227,9 @@ export function byteArrayToFloat(byteArray, start, end, isBigEndian) {
const byteSize = end - start;

if (byteSize === 8) {
return view.getFloat64(start, !isBigEndian)
return view.getFloat64(start, !isBigEndian);
} else if (byteSize === 4) {
return view.getFloat32(start, !isBigEndian)
return view.getFloat32(start, !isBigEndian);
} else {
const msg = `Sized floats must be 32-bit or 64-bit on JavaScript, got size of ${byteSize * 8} bits`;
throw new globalThis.Error(msg);
Expand Down Expand Up @@ -261,7 +262,7 @@ export function sizedFloat(float, size, isBigEndian) {
} else if (size === 32) {
view.setFloat32(0, float, !isBigEndian);
}

return byteArray;
}

Expand Down Expand Up @@ -414,6 +415,8 @@ export function makeError(variant, module, line, fn, message, extra) {
error.gleam_error = variant;
error.module = module;
error.line = line;
error.function = fn;
// TODO: Remove this with Gleam v2.0.0
error.fn = fn;
for (let k in extra) error[k] = extra[k];
return error;
Expand Down
23 changes: 22 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,13 @@
</select></label> &nbsp; <a class="button" href="https://codeberg.org/salif/morse-code-translator"
target="_blank"
data-lo='{"type": 1, "en": "source code", "ru": "исходный код", "bg": "програмен код"}'>source
code</a>
code</a> &nbsp; <input type="button" value="comments"
onclick="window.load_comments(this, document.getElementById('comments_container'));"
data-lo='{"type": 3, "en": "comments", "ru": "комментарии", "bg": "коментари"}' />
</td>
</tr>
</table>
<section id="comments_container" style="display: none;"></section>
<script>
// button.onclick
function add_row(dot, dash, sp, sep) {
Expand All @@ -145,6 +148,19 @@
document.getElementById("add_row_div").style.display = "none";
}

function load_comments(th, container) {
container.style.display = "block"
const el_thread = document.createElement("div")
el_thread.setAttribute("id", "disqus_thread")
el_thread.style.all = "initial"
const el_script = document.createElement('script')
el_script.setAttribute("src", "https://morse-code-translator.disqus.com/embed.js")
el_script.setAttribute("data-timestamp", +new Date());
container.appendChild(el_thread)
container.appendChild(el_script)
th.style.display = "none"
}

function set_element_language(d, dlo, lang) {
try {
const dp = JSON.parse(dlo)
Expand Down Expand Up @@ -220,6 +236,11 @@
// html table
window.el_main_table = document.getElementById("main_table")
window.add_row = add_row
window.load_comments = load_comments
window.disqus_config = function () {
this.page.url = document.querySelector("link[rel='canonical']").getAttribute("href");
this.page.identifier = "/";
};

main_table_add_row({ str_dot: "•", str_dash: "−", str_sp: "/", str_sep: " " })
main_table_add_row({ str_dot: ".", str_dash: "-", str_sp: "/", str_sep: " " })
Expand Down

0 comments on commit e83d15c

Please sign in to comment.