feat: track images with git lfs

This commit is contained in:
max_richter 2024-04-04 21:04:51 +02:00
parent d5fa4ff79c
commit 473f696626
11 changed files with 168 additions and 139 deletions

5
Cargo.lock generated
View File

@ -443,9 +443,9 @@ checksum = "06ea2b9bc92be3c2baa9334a323ebca2d6f074ff852cd1d7b11064035cd3868f"
[[package]] [[package]]
name = "core-graphics" name = "core-graphics"
version = "0.23.1" version = "0.23.2"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "970a29baf4110c26fedbc7f82107d42c23f7e88e404c4577ed73fe99ff85a212" checksum = "c07782be35f9e1140080c6b96f0d44b739e2278479f64e02fdab4e32dfd8b081"
dependencies = [ dependencies = [
"bitflags 1.3.2", "bitflags 1.3.2",
"core-foundation", "core-foundation",
@ -2682,6 +2682,7 @@ name = "random"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"console_error_panic_hook", "console_error_panic_hook",
"plantarium",
"wasm-bindgen", "wasm-bindgen",
"wasm-bindgen-test", "wasm-bindgen-test",
] ]

View File

@ -1,5 +1,5 @@
{ {
"scripts": { "scripts": {
"build": "wasm-pack build --release" "build": "wasm-pack build --release --out-name index --no-default-features"
} }
} }

View File

@ -24,17 +24,20 @@ pub fn get_input_types() -> String {
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn execute(var_op_type: JsValue, var_a: JsValue, var_b: JsValue) -> f64 { pub fn execute(var_op_type: JsValue, var_a: JsValue, var_b: JsValue) -> String {
utils::set_panic_hook(); utils::set_panic_hook();
let op_type = unwrap_int(var_op_type); utils::set_panic_hook();
let a = unwrap_float(var_a); // Convert JsValues to strings
let b = unwrap_float(var_b); let min_str = unwrap_string(var_min);
let max_str = unwrap_string(var_max);
let seed_str = unwrap_string(var_seed);
match op_type { // Interpolate strings into JSON format
1 => return a - b, let json_string = format!(
2 => return a * b, r#"{{"parameter": "random", "min": {}, "max": {}, "seed": {}}}"#,
3 => return a / b, min_str, max_str, seed_str
_ => return a + b, );
}
json_string
} }

View File

@ -17,6 +17,7 @@ wasm-bindgen = "0.2.84"
# logging them with `console.error`. This is great for development, but requires # logging them with `console.error`. This is great for development, but requires
# all the `std::fmt` and `std::panicking` infrastructure, so isn't great for # all the `std::fmt` and `std::panicking` infrastructure, so isn't great for
# code size when deploying. # code size when deploying.
plantarium = { version = "0.1.0", path = "../../../../packages/plantarium" }
console_error_panic_hook = { version = "0.1.7", optional = true } console_error_panic_hook = { version = "0.1.7", optional = true }
[dev-dependencies] [dev-dependencies]

View File

@ -1,5 +1,5 @@
{ {
"scripts": { "scripts": {
"build": "wasm-pack build --release" "build": "wasm-pack build --release --out-name index --no-default-features"
} }
} }

View File

@ -1,13 +1,43 @@
mod utils; mod utils;
use plantarium::*;
use wasm_bindgen::prelude::*; use wasm_bindgen::prelude::*;
#[wasm_bindgen] #[wasm_bindgen]
extern "C" { pub fn get_outputs() -> Vec<String> {
fn alert(s: &str); vec!["float".to_string()]
} }
#[wasm_bindgen] #[wasm_bindgen]
pub fn greet() { pub fn get_id() -> String {
alert("Hello, random!"); "random".to_string()
} }
#[wasm_bindgen]
pub fn get_input_types() -> String {
utils::set_panic_hook();
r#"{
"min": { "type": "float", "value": 2 },
"max": { "type": "float", "value": 2 },
"seed": { "type": "seed" }
}"#
.to_string()
}
#[wasm_bindgen]
pub fn execute(var_min: JsValue, var_max: JsValue, var_seed: JsValue) -> String {
utils::set_panic_hook();
// Convert JsValues to strings
let min_str = unwrap_string(var_min);
let max_str = unwrap_string(var_max);
let seed_str = unwrap_string(var_seed);
// Interpolate strings into JSON format
let json_string = format!(
r#"{{"parameter": "random", "min": {}, "max": {}, "seed": {}}}"#,
min_str, max_str, seed_str
);
json_string
}

View File

@ -1,11 +1,11 @@
import { json } from "@sveltejs/kit"; import { json } from "@sveltejs/kit";
import type { RequestHandler } from "./$types"; import type { RequestHandler } from "./$types";
export const GET: RequestHandler = async function GET({ fetch }) { export const GET: RequestHandler = async function GET({ fetch, params }) {
const d = await fetch("/max/plantarium/math/wasm"); const d = await fetch(`/${params.user}/${params.collection}/${params.node}/wasm`);
const wrapWasm = await import("./wrap-wasm"); const wrapWasm = await import("./wrap-wasm");
const module = new WebAssembly.Module(await d.arrayBuffer()); const module = new WebAssembly.Module(await d.arrayBuffer());
const instance = new WebAssembly.Instance(module, { "./math_bg.js": wrapWasm }); const instance = new WebAssembly.Instance(module, { ["./index_bg.js"]: wrapWasm });
wrapWasm.__wbg_set_wasm(instance.exports); wrapWasm.__wbg_set_wasm(instance.exports);
const id = wrapWasm.get_id(); const id = wrapWasm.get_id();
const outputs = wrapWasm.get_outputs(); const outputs = wrapWasm.get_outputs();

View File

@ -1,15 +1,14 @@
import type { RequestHandler } from "./$types"; import type { RequestHandler } from "./$types";
import fs from "fs/promises"; import fs from "fs/promises";
import path from "path";
export const GET: RequestHandler = async function GET({ fetch, params }) { export const GET: RequestHandler = async function GET({ fetch, params }) {
const path = `../../../../../../../../nodes/${params.user}/${params.collection}/${params.node}/pkg/${params.node}_bg.wasm`; const filePath = path.resolve(`../../nodes/${params.user}/${params.collection}/${params.node}/pkg/index_bg.wasm`);
const file = await fs.readFile(path); const file = await fs.readFile(filePath);
console.log({ file }); const bytes = new Uint8Array(file);
const bytes = new Uint8Array([]);
return new Response(bytes, { status: 200, headers: { "Content-Type": "application/wasm" } }); return new Response(bytes, { status: 200, headers: { "Content-Type": "application/wasm" } });
} }

View File

@ -1,9 +1,9 @@
let wasm; let wasm;
export function __wbg_set_wasm(val) { export function __wbg_set_wasm(val) {
if (wasm) return;
wasm = val; wasm = val;
} }
const heap = new Array(128).fill(undefined); const heap = new Array(128).fill(undefined);
heap.push(undefined, null, true, false); heap.push(undefined, null, true, false);
@ -24,19 +24,77 @@ function takeObject(idx) {
return ret; return ret;
} }
let WASM_VECTOR_LEN = 0;
let cachedUint8Memory0 = null;
function getUint8Memory0() {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
let cachedTextEncoder = new lTextEncoder('utf-8');
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
? function (arg, view) {
return cachedTextEncoder.encodeInto(arg, view);
}
: function (arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
});
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8Memory0();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
function isLikeNone(x) { function isLikeNone(x) {
return x === undefined || x === null; return x === undefined || x === null;
} }
let cachedFloat64Memory0 = null;
function getFloat64Memory0() {
if (cachedFloat64Memory0 === null || cachedFloat64Memory0.byteLength === 0) {
cachedFloat64Memory0 = new Float64Array(wasm.memory.buffer);
}
return cachedFloat64Memory0;
}
let cachedInt32Memory0 = null; let cachedInt32Memory0 = null;
function getInt32Memory0() { function getInt32Memory0() {
@ -52,15 +110,6 @@ let cachedTextDecoder = new lTextDecoder('utf-8', { ignoreBOM: true, fatal: true
cachedTextDecoder.decode(); cachedTextDecoder.decode();
let cachedUint8Memory0 = null;
function getUint8Memory0() {
if (cachedUint8Memory0 === null || cachedUint8Memory0.byteLength === 0) {
cachedUint8Memory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8Memory0;
}
function getStringFromWasm0(ptr, len) { function getStringFromWasm0(ptr, len) {
ptr = ptr >>> 0; ptr = ptr >>> 0;
return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len));
@ -152,102 +201,27 @@ export function get_input_types() {
} }
/** /**
* @param {any} var_op_type * @param {any} var_min
* @param {any} var_a * @param {any} var_max
* @param {any} var_b * @param {any} var_seed
* @returns {number} * @returns {string}
*/ */
export function execute(var_op_type, var_a, var_b) { export function execute(var_min, var_max, var_seed) {
const ret = wasm.execute(addHeapObject(var_op_type), addHeapObject(var_a), addHeapObject(var_b)); let deferred1_0;
return ret; let deferred1_1;
}
let WASM_VECTOR_LEN = 0;
const lTextEncoder = typeof TextEncoder === 'undefined' ? (0, module.require)('util').TextEncoder : TextEncoder;
let cachedTextEncoder = new lTextEncoder('utf-8');
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
? function (arg, view) {
return cachedTextEncoder.encodeInto(arg, view);
}
: function (arg, view) {
const buf = cachedTextEncoder.encode(arg);
view.set(buf);
return {
read: arg.length,
written: buf.length
};
});
function passStringToWasm0(arg, malloc, realloc) {
if (realloc === undefined) {
const buf = cachedTextEncoder.encode(arg);
const ptr = malloc(buf.length, 1) >>> 0;
getUint8Memory0().subarray(ptr, ptr + buf.length).set(buf);
WASM_VECTOR_LEN = buf.length;
return ptr;
}
let len = arg.length;
let ptr = malloc(len, 1) >>> 0;
const mem = getUint8Memory0();
let offset = 0;
for (; offset < len; offset++) {
const code = arg.charCodeAt(offset);
if (code > 0x7F) break;
mem[ptr + offset] = code;
}
if (offset !== len) {
if (offset !== 0) {
arg = arg.slice(offset);
}
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
const view = getUint8Memory0().subarray(ptr + offset, ptr + len);
const ret = encodeString(arg, view);
offset += ret.written;
ptr = realloc(ptr, len, offset, 1) >>> 0;
}
WASM_VECTOR_LEN = offset;
return ptr;
}
export function __wbg_new_abda76e883ba8a5f() {
const ret = new Error();
return addHeapObject(ret);
};
export function __wbg_stack_658279fe44541cf6(arg0, arg1) {
const ret = getObject(arg1).stack;
const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
const len1 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len1;
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
};
export function __wbg_error_f851667af71bcfc6(arg0, arg1) {
let deferred0_0;
let deferred0_1;
try { try {
deferred0_0 = arg0; const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
deferred0_1 = arg1; wasm.execute(retptr, addHeapObject(var_min), addHeapObject(var_max), addHeapObject(var_seed));
console.error(getStringFromWasm0(arg0, arg1)); var r0 = getInt32Memory0()[retptr / 4 + 0];
var r1 = getInt32Memory0()[retptr / 4 + 1];
deferred1_0 = r0;
deferred1_1 = r1;
return getStringFromWasm0(r0, r1);
} finally { } finally {
wasm.__wbindgen_free(deferred0_0, deferred0_1, 1); wasm.__wbindgen_add_to_stack_pointer(16);
wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
}
} }
};
export function __wbindgen_object_drop_ref(arg0) {
takeObject(arg0);
};
export function __wbindgen_is_undefined(arg0) { export function __wbindgen_is_undefined(arg0) {
const ret = getObject(arg0) === undefined; const ret = getObject(arg0) === undefined;
@ -259,11 +233,17 @@ export function __wbindgen_is_null(arg0) {
return ret; return ret;
}; };
export function __wbindgen_number_get(arg0, arg1) { export function __wbindgen_object_drop_ref(arg0) {
takeObject(arg0);
};
export function __wbindgen_string_get(arg0, arg1) {
const obj = getObject(arg1); const obj = getObject(arg1);
const ret = typeof (obj) === 'number' ? obj : undefined; const ret = typeof (obj) === 'string' ? obj : undefined;
getFloat64Memory0()[arg0 / 8 + 1] = isLikeNone(ret) ? 0 : ret; var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
getInt32Memory0()[arg0 / 4 + 0] = !isLikeNone(ret); var len1 = WASM_VECTOR_LEN;
getInt32Memory0()[arg0 / 4 + 1] = len1;
getInt32Memory0()[arg0 / 4 + 0] = ptr1;
}; };
export function __wbindgen_string_new(arg0, arg1) { export function __wbindgen_string_new(arg0, arg1) {
@ -271,3 +251,4 @@ export function __wbindgen_string_new(arg0, arg1) {
return addHeapObject(ret); return addHeapObject(ret);
}; };

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.3 KiB

View File

@ -13,3 +13,17 @@ pub fn unwrap_float(val: JsValue) -> f64 {
} }
return val.as_f64().unwrap(); return val.as_f64().unwrap();
} }
pub fn unwrap_string(val: JsValue) -> String {
if val.is_undefined() || val.is_null() {
panic!("Value is undefined");
}
return val.as_string().unwrap();
}
pub fn evaluate_parameter(val: JsValue) -> String {
if val.is_undefined() || val.is_null() {
panic!("Value is undefined");
}
return val.as_string().unwrap();
}