mirror of
https://github.com/visioncortex/vtracer.git
synced 2026-09-26 14:01:18 -07:00
upgrade webapp
This commit is contained in:
+6
-4
@@ -17,12 +17,14 @@ crate-type = ["cdylib"]
|
|||||||
default = ["console_error_panic_hook"]
|
default = ["console_error_panic_hook"]
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
cfg-if = "0.1"
|
cfg-if = "1.0"
|
||||||
console_log = { version = "0.2", features = ["color"] }
|
console_log = { version = "1.0", features = ["color"] }
|
||||||
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
|
# `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 = { version = "1.0", features = ["derive"] }
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
visioncortex = "0.8.1"
|
visioncortex = "0.9"
|
||||||
|
|
||||||
# The `console_error_panic_hook` crate provides better debugging of panics by
|
# The `console_error_panic_hook` crate provides better debugging of panics by
|
||||||
# logging them with `console.error`. This is great for development, but requires
|
# 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,
|
"private": true,
|
||||||
"main": "index.js",
|
"main": "index.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"start": "webpack-dev-server",
|
"start": "webpack serve",
|
||||||
"build": "webpack"
|
"build": "webpack"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
@@ -16,10 +16,10 @@
|
|||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"vtracer": "file:../pkg",
|
"vtracer": "file:../pkg",
|
||||||
"webpack": "^4.41.5"
|
"webpack": "^5.101.0"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"webpack-cli": "^3.3.11",
|
"webpack-cli": "^6.0.1",
|
||||||
"webpack-dev-server": "^3.10.1"
|
"webpack-dev-server": "^5.2.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,16 @@ module.exports = {
|
|||||||
output: {
|
output: {
|
||||||
path: path.resolve(__dirname, "dist"),
|
path: path.resolve(__dirname, "dist"),
|
||||||
filename: "bootstrap.js",
|
filename: "bootstrap.js",
|
||||||
|
clean: true,
|
||||||
},
|
},
|
||||||
mode: "development",
|
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: {
|
devServer: {
|
||||||
//host: "0.0.0.0",
|
//host: "0.0.0.0",
|
||||||
port: 8080,
|
port: 8080,
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
use wasm_bindgen::prelude::*;
|
use wasm_bindgen::prelude::*;
|
||||||
use visioncortex::{Color, ColorImage, PathSimplifyMode};
|
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::canvas::*;
|
||||||
use crate::svg::*;
|
use crate::svg::*;
|
||||||
@@ -38,11 +41,41 @@ pub struct ColorImageConverter {
|
|||||||
|
|
||||||
pub enum Stage {
|
pub enum Stage {
|
||||||
New,
|
New,
|
||||||
Clustering(IncrementalBuilder),
|
Clustering(Box<dyn ClusterBuilder>),
|
||||||
Reclustering(IncrementalBuilder),
|
Reclustering(Box<dyn ClusterBuilder>),
|
||||||
Vectorize(Clusters),
|
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 {
|
impl ColorImageConverter {
|
||||||
pub fn new(params: ColorImageConverterParams) -> Self {
|
pub fn new(params: ColorImageConverterParams) -> Self {
|
||||||
let canvas = Canvas::new_from_id(¶ms.canvas_id);
|
let canvas = Canvas::new_from_id(¶ms.canvas_id);
|
||||||
@@ -106,7 +139,7 @@ impl ColorImageConverter {
|
|||||||
KeyingAction::Discard
|
KeyingAction::Discard
|
||||||
},
|
},
|
||||||
}, image);
|
}, image);
|
||||||
self.stage = Stage::Clustering(runner.start());
|
self.stage = Stage::Clustering(Box::new(runner.start()));
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn tick(&mut self) -> bool {
|
pub fn tick(&mut self) -> bool {
|
||||||
@@ -138,7 +171,7 @@ impl ColorImageConverter {
|
|||||||
key_color: Default::default(),
|
key_color: Default::default(),
|
||||||
keying_action: KeyingAction::Discard,
|
keying_action: KeyingAction::Discard,
|
||||||
}, image);
|
}, image);
|
||||||
self.stage = Stage::Reclustering(runner.start());
|
self.stage = Stage::Reclustering(Box::new(runner.start()));
|
||||||
},
|
},
|
||||||
_ => panic!("unknown hierarchical `{}`", self.params.hierarchical)
|
_ => panic!("unknown hierarchical `{}`", self.params.hierarchical)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user