diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index d7ee8fb..364e182 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -38,22 +38,23 @@ jobs: - uses: jetli/wasm-pack-action@v0.4.0 - name: Build wasm (target web) - working-directory: wasm_project + working-directory: wasm run: wasm-pack build --release --target web - name: Prepare dist run: | set -euo pipefail mkdir -p "$DIST_DIR" - cp index.html "$DIST_DIR/" - cp -r js "$DIST_DIR/js" - cp gif.js "$DIST_DIR/gif.js" - cp gif.worker.js "$DIST_DIR/gif.worker.js" - mkdir -p "$DIST_DIR/wasm_project" - cp -r wasm_project/pkg "$DIST_DIR/wasm_project/pkg" - if [ -d test/images ]; then + cp web/index.html "$DIST_DIR/" + mkdir -p "$DIST_DIR/js" + cp -r web/js/* "$DIST_DIR/js/" + mkdir -p "$DIST_DIR/vendor" + cp -r web/vendor/* "$DIST_DIR/vendor/" + mkdir -p "$DIST_DIR/wasm/pkg" + cp -r wasm/pkg/* "$DIST_DIR/wasm/pkg/" + if [ -d web/test/images ]; then mkdir -p "$DIST_DIR/test/images" - cp -r test/images/* "$DIST_DIR/test/images/" + cp -r web/test/images/* "$DIST_DIR/test/images/" fi touch "$DIST_DIR/.nojekyll" diff --git a/.gitignore b/.gitignore index 496ee2c..c9a84e2 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,4 @@ +/wasm/target/ +/wasm/pkg/ + .DS_Store \ No newline at end of file diff --git a/wasm_project/.rustfmt.toml b/wasm/.rustfmt.toml similarity index 100% rename from wasm_project/.rustfmt.toml rename to wasm/.rustfmt.toml diff --git a/wasm_project/Cargo.lock b/wasm/Cargo.lock similarity index 99% rename from wasm_project/Cargo.lock rename to wasm/Cargo.lock index c32908b..bb858eb 100644 --- a/wasm_project/Cargo.lock +++ b/wasm/Cargo.lock @@ -1,6 +1,6 @@ # This file is automatically @generated by Cargo. # It is not intended for manual editing. -version = 3 +version = 4 [[package]] name = "bumpalo" @@ -67,6 +67,14 @@ version = "1.0.12" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b" +[[package]] +name = "wasm" +version = "0.1.0" +dependencies = [ + "svg", + "wasm-bindgen", +] + [[package]] name = "wasm-bindgen" version = "0.2.92" @@ -120,11 +128,3 @@ name = "wasm-bindgen-shared" version = "0.2.92" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "af190c94f2773fdb3729c55b007a722abb5384da03bc0986df4c289bf5567e96" - -[[package]] -name = "wasm_project" -version = "0.1.0" -dependencies = [ - "svg", - "wasm-bindgen", -] diff --git a/wasm_project/Cargo.toml b/wasm/Cargo.toml similarity index 73% rename from wasm_project/Cargo.toml rename to wasm/Cargo.toml index 70f556e..d2a3c57 100644 --- a/wasm_project/Cargo.toml +++ b/wasm/Cargo.toml @@ -1,7 +1,7 @@ [package] -name = "wasm_project" +name = "wasm" version = "0.1.0" -edition = "2021" +edition = "2024" [lib] crate-type = ["cdylib"] diff --git a/wasm_project/src/algorithms/greedy.rs b/wasm/src/algorithms/greedy.rs similarity index 100% rename from wasm_project/src/algorithms/greedy.rs rename to wasm/src/algorithms/greedy.rs diff --git a/wasm_project/src/algorithms/mod.rs b/wasm/src/algorithms/mod.rs similarity index 100% rename from wasm_project/src/algorithms/mod.rs rename to wasm/src/algorithms/mod.rs diff --git a/wasm_project/src/algorithms/simulated_annealing.rs b/wasm/src/algorithms/simulated_annealing.rs similarity index 100% rename from wasm_project/src/algorithms/simulated_annealing.rs rename to wasm/src/algorithms/simulated_annealing.rs diff --git a/wasm_project/src/lib.rs b/wasm/src/lib.rs similarity index 100% rename from wasm_project/src/lib.rs rename to wasm/src/lib.rs diff --git a/wasm_project/.gitignore b/wasm_project/.gitignore deleted file mode 100644 index 1de5659..0000000 --- a/wasm_project/.gitignore +++ /dev/null @@ -1 +0,0 @@ -target \ No newline at end of file diff --git a/wasm_project/pkg/.gitignore b/wasm_project/pkg/.gitignore deleted file mode 100644 index e69de29..0000000 diff --git a/wasm_project/pkg/package.json b/wasm_project/pkg/package.json deleted file mode 100644 index d055f82..0000000 --- a/wasm_project/pkg/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "wasm_project", - "version": "0.1.0", - "files": [ - "wasm_project_bg.wasm", - "wasm_project.js", - "wasm_project.d.ts" - ], - "module": "wasm_project.js", - "types": "wasm_project.d.ts", - "sideEffects": false -} \ No newline at end of file diff --git a/wasm_project/pkg/wasm_project.d.ts b/wasm_project/pkg/wasm_project.d.ts deleted file mode 100644 index 22aed92..0000000 --- a/wasm_project/pkg/wasm_project.d.ts +++ /dev/null @@ -1,77 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -/** -* @param {number} num_rectangles -* @param {number} width -* @param {number} height -* @param {Uint8Array} rgb_data -* @returns {(string)[]} -*/ -export function run_greedy(num_rectangles: number, width: number, height: number, rgb_data: Uint8Array): (string)[]; -/** -* @param {number} num_rectangles -* @param {number} width -* @param {number} height -* @param {Uint8Array} rgb_data -* @returns {(string)[]} -*/ -export function run_simulated_annealing(num_rectangles: number, width: number, height: number, rgb_data: Uint8Array): (string)[]; -/** -* @param {number} algorithm_id -* @param {number} num_rectangles -* @param {number} width -* @param {number} height -* @param {Uint8Array} image_data -* @returns {Ret} -*/ -export function run_algorithm(algorithm_id: number, num_rectangles: number, width: number, height: number, image_data: Uint8Array): Ret; -/** -*/ -export class Ret { - free(): void; -/** -*/ - animation_data: (string)[]; -/** -*/ - max_turn: number; -} - -export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module; - -export interface InitOutput { - readonly memory: WebAssembly.Memory; - readonly run_greedy: (a: number, b: number, c: number, d: number, e: number, f: number) => void; - readonly run_simulated_annealing: (a: number, b: number, c: number, d: number, e: number, f: number) => void; - readonly __wbg_ret_free: (a: number) => void; - readonly __wbg_get_ret_animation_data: (a: number, b: number) => void; - readonly __wbg_set_ret_animation_data: (a: number, b: number, c: number) => void; - readonly __wbg_get_ret_max_turn: (a: number) => number; - readonly __wbg_set_ret_max_turn: (a: number, b: number) => void; - readonly run_algorithm: (a: number, b: number, c: number, d: number, e: number, f: number) => number; - readonly __wbindgen_malloc: (a: number, b: number) => number; - readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number; - readonly __wbindgen_add_to_stack_pointer: (a: number) => number; - readonly __wbindgen_free: (a: number, b: number, c: number) => void; -} - -export type SyncInitInput = BufferSource | WebAssembly.Module; -/** -* Instantiates the given `module`, which can either be bytes or -* a precompiled `WebAssembly.Module`. -* -* @param {SyncInitInput} module -* -* @returns {InitOutput} -*/ -export function initSync(module: SyncInitInput): InitOutput; - -/** -* If `module_or_path` is {RequestInfo} or {URL}, makes a request and -* for everything else, calls `WebAssembly.instantiate` directly. -* -* @param {InitInput | Promise} module_or_path -* -* @returns {Promise} -*/ -export default function __wbg_init (module_or_path?: InitInput | Promise): Promise; diff --git a/wasm_project/pkg/wasm_project.js b/wasm_project/pkg/wasm_project.js deleted file mode 100644 index a606c89..0000000 --- a/wasm_project/pkg/wasm_project.js +++ /dev/null @@ -1,249 +0,0 @@ -let wasm; - -const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } ); - -if (typeof TextDecoder !== 'undefined') { 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) { - ptr = ptr >>> 0; - return cachedTextDecoder.decode(getUint8Memory0().subarray(ptr, ptr + len)); -} - -const heap = new Array(128).fill(undefined); - -heap.push(undefined, null, true, false); - -let heap_next = heap.length; - -function addHeapObject(obj) { - if (heap_next === heap.length) heap.push(heap.length + 1); - const idx = heap_next; - heap_next = heap[idx]; - - heap[idx] = obj; - return idx; -} - -let WASM_VECTOR_LEN = 0; - -function passArray8ToWasm0(arg, malloc) { - const ptr = malloc(arg.length * 1, 1) >>> 0; - getUint8Memory0().set(arg, ptr / 1); - WASM_VECTOR_LEN = arg.length; - return ptr; -} - -let cachedInt32Memory0 = null; - -function getInt32Memory0() { - if (cachedInt32Memory0 === null || cachedInt32Memory0.byteLength === 0) { - cachedInt32Memory0 = new Int32Array(wasm.memory.buffer); - } - return cachedInt32Memory0; -} - -function getObject(idx) { return heap[idx]; } - -function dropObject(idx) { - if (idx < 132) return; - heap[idx] = heap_next; - heap_next = idx; -} - -function takeObject(idx) { - const ret = getObject(idx); - dropObject(idx); - return ret; -} - -const StoreFinalization = (typeof FinalizationRegistry === 'undefined') - ? { register: () => {}, unregister: () => {} } - : new FinalizationRegistry(ptr => wasm.__wbg_store_free(ptr >>> 0)); -/** -*/ -export class Store { - - __destroy_into_raw() { - const ptr = this.__wbg_ptr; - this.__wbg_ptr = 0; - StoreFinalization.unregister(this); - return ptr; - } - - free() { - const ptr = this.__destroy_into_raw(); - wasm.__wbg_store_free(ptr); - } - /** - */ - constructor() { - const ret = wasm.store_new(); - this.__wbg_ptr = ret >>> 0; - return this; - } - /** - */ - clear() { - wasm.store_clear(this.__wbg_ptr); - } - /** - * @param {number} width - * @param {number} height - */ - init(width, height) { - wasm.store_init(this.__wbg_ptr, width, height); - } - /** - * @param {number} algorithm_id - * @param {number} num_rectangles - * @param {Uint8Array} rgba - */ - runAlgorithmWithImage(algorithm_id, num_rectangles, rgba) { - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - const ptr0 = passArray8ToWasm0(rgba, wasm.__wbindgen_malloc); - const len0 = WASM_VECTOR_LEN; - wasm.store_runAlgorithmWithImage(retptr, this.__wbg_ptr, algorithm_id, num_rectangles, ptr0, len0); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - if (r1) { - throw takeObject(r0); - } - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - } - } - /** - * @param {number} step - * @returns {string} - */ - visSvg(step) { - let deferred1_0; - let deferred1_1; - try { - const retptr = wasm.__wbindgen_add_to_stack_pointer(-16); - wasm.store_visSvg(retptr, this.__wbg_ptr, step); - var r0 = getInt32Memory0()[retptr / 4 + 0]; - var r1 = getInt32Memory0()[retptr / 4 + 1]; - deferred1_0 = r0; - deferred1_1 = r1; - return getStringFromWasm0(r0, r1); - } finally { - wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred1_0, deferred1_1, 1); - } - } - /** - * @returns {number} - */ - stepCount() { - const ret = wasm.store_stepCount(this.__wbg_ptr); - return ret >>> 0; - } -} - -async function __wbg_load(module, imports) { - if (typeof Response === 'function' && module instanceof Response) { - if (typeof WebAssembly.instantiateStreaming === 'function') { - try { - return await WebAssembly.instantiateStreaming(module, imports); - - } catch (e) { - if (module.headers.get('Content-Type') != 'application/wasm') { - console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e); - - } else { - throw e; - } - } - } - - const bytes = await module.arrayBuffer(); - return await WebAssembly.instantiate(bytes, imports); - - } else { - const instance = await WebAssembly.instantiate(module, imports); - - if (instance instanceof WebAssembly.Instance) { - return { instance, module }; - - } else { - return instance; - } - } -} - -function __wbg_get_imports() { - const imports = {}; - imports.wbg = {}; - imports.wbg.__wbindgen_error_new = function(arg0, arg1) { - const ret = new Error(getStringFromWasm0(arg0, arg1)); - return addHeapObject(ret); - }; - imports.wbg.__wbindgen_throw = function(arg0, arg1) { - throw new Error(getStringFromWasm0(arg0, arg1)); - }; - - return imports; -} - -function __wbg_init_memory(imports, maybe_memory) { - -} - -function __wbg_finalize_init(instance, module) { - wasm = instance.exports; - __wbg_init.__wbindgen_wasm_module = module; - cachedInt32Memory0 = null; - cachedUint8Memory0 = null; - - - return wasm; -} - -function initSync(module) { - if (wasm !== undefined) return wasm; - - const imports = __wbg_get_imports(); - - __wbg_init_memory(imports); - - if (!(module instanceof WebAssembly.Module)) { - module = new WebAssembly.Module(module); - } - - const instance = new WebAssembly.Instance(module, imports); - - return __wbg_finalize_init(instance, module); -} - -async function __wbg_init(input) { - if (wasm !== undefined) return wasm; - - if (typeof input === 'undefined') { - input = new URL('wasm_project_bg.wasm', import.meta.url); - } - const imports = __wbg_get_imports(); - - if (typeof input === 'string' || (typeof Request === 'function' && input instanceof Request) || (typeof URL === 'function' && input instanceof URL)) { - input = fetch(input); - } - - __wbg_init_memory(imports); - - const { instance, module } = await __wbg_load(await input, imports); - - return __wbg_finalize_init(instance, module); -} - -export { initSync } -export default __wbg_init; diff --git a/wasm_project/pkg/wasm_project_bg.wasm b/wasm_project/pkg/wasm_project_bg.wasm deleted file mode 100644 index 828b213..0000000 Binary files a/wasm_project/pkg/wasm_project_bg.wasm and /dev/null differ diff --git a/wasm_project/pkg/wasm_project_bg.wasm.d.ts b/wasm_project/pkg/wasm_project_bg.wasm.d.ts deleted file mode 100644 index 4acb318..0000000 --- a/wasm_project/pkg/wasm_project_bg.wasm.d.ts +++ /dev/null @@ -1,15 +0,0 @@ -/* tslint:disable */ -/* eslint-disable */ -export const memory: WebAssembly.Memory; -export function run_greedy(a: number, b: number, c: number, d: number, e: number, f: number): void; -export function run_simulated_annealing(a: number, b: number, c: number, d: number, e: number, f: number): void; -export function __wbg_ret_free(a: number): void; -export function __wbg_get_ret_animation_data(a: number, b: number): void; -export function __wbg_set_ret_animation_data(a: number, b: number, c: number): void; -export function __wbg_get_ret_max_turn(a: number): number; -export function __wbg_set_ret_max_turn(a: number, b: number): void; -export function run_algorithm(a: number, b: number, c: number, d: number, e: number, f: number): number; -export function __wbindgen_malloc(a: number, b: number): number; -export function __wbindgen_realloc(a: number, b: number, c: number, d: number): number; -export function __wbindgen_add_to_stack_pointer(a: number): number; -export function __wbindgen_free(a: number, b: number, c: number): void; diff --git a/index.html b/web/index.html similarity index 99% rename from index.html rename to web/index.html index 4b91514..8860c67 100644 --- a/index.html +++ b/web/index.html @@ -153,7 +153,7 @@

再生・保存

© 2025 Rectangle Fitting by Shimo-1999 - +