mirror of
https://github.com/visioncortex/vtracer.git
synced 2026-09-14 16:15:49 -07:00
upgrade webapp
This commit is contained in:
+6
-4
@@ -17,12 +17,14 @@ crate-type = ["cdylib"]
|
||||
default = ["console_error_panic_hook"]
|
||||
|
||||
[dependencies]
|
||||
cfg-if = "0.1"
|
||||
console_log = { version = "0.2", features = ["color"] }
|
||||
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
|
||||
cfg-if = "1.0"
|
||||
console_log = { version = "1.0", features = ["color"] }
|
||||
# `serde-serialize` was removed upstream in 0.2.84; params arrive as a JSON
|
||||
# string and are parsed with serde_json, so the feature was never needed.
|
||||
wasm-bindgen = "0.2"
|
||||
serde = { version = "1.0", features = ["derive"] }
|
||||
serde_json = "1.0"
|
||||
visioncortex = "0.8.1"
|
||||
visioncortex = "0.9"
|
||||
|
||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||
# logging them with `console.error`. This is great for development, but requires
|
||||
|
||||
Generated
+3933
-4877
File diff suppressed because it is too large
Load Diff
@@ -7,7 +7,7 @@
|
||||
"private": true,
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"start": "webpack-dev-server",
|
||||
"start": "webpack serve",
|
||||
"build": "webpack"
|
||||
},
|
||||
"keywords": [
|
||||
@@ -16,10 +16,10 @@
|
||||
],
|
||||
"dependencies": {
|
||||
"vtracer": "file:../pkg",
|
||||
"webpack": "^4.41.5"
|
||||
"webpack": "^5.101.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"webpack-cli": "^3.3.11",
|
||||
"webpack-dev-server": "^3.10.1"
|
||||
"webpack-cli": "^6.0.1",
|
||||
"webpack-dev-server": "^5.2.2"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,10 +5,16 @@ module.exports = {
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist"),
|
||||
filename: "bootstrap.js",
|
||||
clean: true,
|
||||
},
|
||||
mode: "development",
|
||||
// wasm-pack's `bundler` target emits ESM imports of the .wasm module; webpack
|
||||
// 5 handles those natively once this experiment is on.
|
||||
experiments: {
|
||||
asyncWebAssembly: true,
|
||||
},
|
||||
devServer: {
|
||||
//host: "0.0.0.0",
|
||||
//host: "0.0.0.0",
|
||||
port: 8080,
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
use wasm_bindgen::prelude::*;
|
||||
use visioncortex::{Color, ColorImage, PathSimplifyMode};
|
||||
use visioncortex::color_clusters::{Clusters, Runner, RunnerConfig, HIERARCHICAL_MAX, IncrementalBuilder, KeyingAction};
|
||||
use visioncortex::color_clusters::{
|
||||
Cluster, Clusters, ClustersView, IncrementalBuilder, KeyingAction, NeighbourInfo, Runner,
|
||||
RunnerConfig, HIERARCHICAL_MAX,
|
||||
};
|
||||
|
||||
use crate::canvas::*;
|
||||
use crate::svg::*;
|
||||
@@ -38,11 +41,41 @@ pub struct ColorImageConverter {
|
||||
|
||||
pub enum Stage {
|
||||
New,
|
||||
Clustering(IncrementalBuilder),
|
||||
Reclustering(IncrementalBuilder),
|
||||
Clustering(Box<dyn ClusterBuilder>),
|
||||
Reclustering(Box<dyn ClusterBuilder>),
|
||||
Vectorize(Clusters),
|
||||
}
|
||||
|
||||
/// visioncortex 0.9 parameterises `IncrementalBuilder` over its four closures,
|
||||
/// and `Runner::start()` returns them as anonymous `impl Fn` types, so the
|
||||
/// builder can no longer be named in a field. The stage machine only ever steps
|
||||
/// it, so erase the closures behind a trait object.
|
||||
pub trait ClusterBuilder {
|
||||
fn tick(&mut self) -> bool;
|
||||
fn progress(&self) -> u32;
|
||||
fn result(&mut self) -> Clusters;
|
||||
}
|
||||
|
||||
impl<C, D, P, H> ClusterBuilder for IncrementalBuilder<C, D, P, H>
|
||||
where
|
||||
C: Fn(Color, Color) -> bool,
|
||||
D: Fn(Color, Color) -> i32,
|
||||
P: Fn(&ClustersView, &Cluster, &[NeighbourInfo]) -> bool,
|
||||
H: Fn(&ClustersView, &Cluster, &[NeighbourInfo]) -> bool,
|
||||
{
|
||||
fn tick(&mut self) -> bool {
|
||||
IncrementalBuilder::tick(self)
|
||||
}
|
||||
|
||||
fn progress(&self) -> u32 {
|
||||
IncrementalBuilder::progress(self)
|
||||
}
|
||||
|
||||
fn result(&mut self) -> Clusters {
|
||||
IncrementalBuilder::result(self)
|
||||
}
|
||||
}
|
||||
|
||||
impl ColorImageConverter {
|
||||
pub fn new(params: ColorImageConverterParams) -> Self {
|
||||
let canvas = Canvas::new_from_id(¶ms.canvas_id);
|
||||
@@ -106,7 +139,7 @@ impl ColorImageConverter {
|
||||
KeyingAction::Discard
|
||||
},
|
||||
}, image);
|
||||
self.stage = Stage::Clustering(runner.start());
|
||||
self.stage = Stage::Clustering(Box::new(runner.start()));
|
||||
}
|
||||
|
||||
pub fn tick(&mut self) -> bool {
|
||||
@@ -138,7 +171,7 @@ impl ColorImageConverter {
|
||||
key_color: Default::default(),
|
||||
keying_action: KeyingAction::Discard,
|
||||
}, image);
|
||||
self.stage = Stage::Reclustering(runner.start());
|
||||
self.stage = Stage::Reclustering(Box::new(runner.start()));
|
||||
},
|
||||
_ => panic!("unknown hierarchical `{}`", self.params.hierarchical)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user