Incorporo-user commited on
Commit
384b8e7
·
verified ·
1 Parent(s): 6e71154

Deploy single-threaded WASM build

Browse files
README.md CHANGED
@@ -1,10 +1,67 @@
1
  ---
2
  title: Inkvec
3
- emoji: 🐢
4
- colorFrom: green
5
  colorTo: yellow
6
  sdk: static
7
- pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  title: Inkvec
3
+ colorFrom: gray
 
4
  colorTo: yellow
5
  sdk: static
6
+ pinned: true
7
+ license: apache-2.0
8
+ short_description: Exact SVG from logos and icons, entirely in your browser
9
  ---
10
 
11
+ # Inkvec
12
+
13
+ Exact vectors from logos, icons and flat artwork, entirely in the browser. Inkvec is
14
+ LogoLabs' tracer compiled to WebAssembly and served as a static page: drop an image, get an
15
+ SVG, nothing leaves your machine.
16
+
17
+ Boundaries land where the anti-aliasing says they are, circles come back as circles, the
18
+ pieces of one colour are one path, and the number of coordinates is chosen by minimum
19
+ description length rather than a tolerance slider. Across 21 cases — 14 hash-selected real
20
+ icons across seven families, 4 hand-picked synthetic probes, and 3 real brand logos from an
21
+ external dataset (selection fixed from the seed `crosscompare-2026-09-15-v1`) — scored
22
+ against the source render, Inkvec's median colour error (dE00) is 11x lower than VTracer's
23
+ default output at roughly a quarter of the coordinates; the 3 brand logos are not part of
24
+ the repo, so a clean clone reproduces the other 18. Full numbers, sourced, are in the
25
+ [project README](https://github.com/logolabs/inkvec#results).
26
+
27
+ ## Build
28
+
29
+ ```
30
+ rustup target add wasm32-unknown-unknown
31
+ rustup toolchain install nightly --component rust-src
32
+ tools/build_wasm.sh
33
+ ```
34
+
35
+ That writes two packages, and `web/worker.js` picks between them at load:
36
+
37
+ | | `web/pkg/` | `web/pkg-threads/` |
38
+ |---|---|---|
39
+ | toolchain | stable | nightly, with `std` rebuilt for atomics |
40
+ | cores | one | one rayon worker per core |
41
+ | needs | nothing | a cross-origin isolated page |
42
+
43
+ The tracer, its arithmetic and its output are the same in both — measured, by hashing the
44
+ SVGs from each: on a sixteen-core machine the threaded build is 3.7x to 4.3x faster on real
45
+ logos and returns the identical bytes.
46
+
47
+ This Space serves the single-threaded package only: the page is not cross-origin isolated,
48
+ so `worker.js` loads `pkg/` and everything works. (The repo's `web/README.md` carries the
49
+ `custom_headers` block a threads-enabled deploy asks the Space for, plus `pkg-threads/`.)
50
+
51
+ The page is `web/index.html`; serve it over HTTP (ES modules do not load from `file://`).
52
+
53
+ ## Deploy
54
+
55
+ This folder is the Space. Create a Space under the LogoLabs org with the **static** SDK and
56
+ push these files (README, `index.html`, `worker.js`, `samples/`, the built `pkg/`). Build the
57
+ package with `tools/build_wasm.sh`, then upload this folder to the Space with
58
+ `huggingface-cli` once you are logged in.
59
+
60
+ ## Notes
61
+
62
+ - Single-threaded in the browser (rayon runs its work on the calling thread when it cannot
63
+ spawn). A 768-px logo takes about eight seconds; the native binary uses every core and is
64
+ several times faster. Browser threads need cross-origin isolation headers the static SDK
65
+ cannot set; a `coi-serviceworker` shim is the usual workaround if that ever matters.
66
+ - Inputs above the "max dimension" setting are traced at that size and written at the
67
+ original size, so a 4000-px screenshot still finishes.
index.html CHANGED
@@ -1,19 +1,516 @@
1
  <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
  </html>
 
1
  <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <meta name="viewport" content="width=device-width, initial-scale=1">
6
+ <meta http-equiv="Cache-Control" content="no-cache">
7
+ <title>Inkvec</title>
8
+ <meta name="description" content="Inkvec by LogoLabs traces logos, icons and flat artwork to exact SVG, entirely in your browser.">
9
+ <link rel="icon" href="data:image/svg+xml,%3Csvg xmlns=%27http://www.w3.org/2000/svg%27 viewBox=%270 0 32 32%27%3E%3Cpath d=%27M16 3c-4 6-9 11-9 17a9 9 0 0 0 18 0c0-6-5-11-9-17z%27 fill=%27%23c9754a%27/%3E%3Cpath d=%27M11 21c2 3 8 3 10 0%27 stroke=%27%23faf8f5%27 stroke-width=%272.2%27 fill=%27none%27 stroke-linecap=%27round%27/%3E%3C/svg%3E">
10
+ <link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Playfair+Display:ital,wght@0,500;0,600;0,700;1,500&family=Inter:wght@400;500;600;700&family=IBM+Plex+Mono:wght@400;500&display=swap">
11
+ <style>
12
+ /* LogoLabs design system: warm charcoal ramp, one copper accent, Playfair Display + Inter.
13
+ The product ships a single warm-dark theme -- no light mode. */
14
+ :root{
15
+ --paper:#1a1816;--card:#211f1c;--stage:#141210;--void:#0c0a09;--surface:#2a2724;--highlight:#35322e;
16
+ --ink:#faf8f5;--dim:rgba(250,248,245,.75);--faint:rgba(250,248,245,.55);--muted:rgba(250,248,245,.4);
17
+ --rule:rgba(250,248,245,.08);--rule2:#2a2724;
18
+ --accent:#c9754a;--accent-hover:#d4896a;--accent-ink:#1a1816;--accent-soft:rgba(201,117,74,.12);--accent-subtle:rgba(201,117,74,.08);
19
+ --gold:#b8976c;
20
+ --good:#34d399;--goodbg:rgba(52,211,153,.15);--bad:#f87171;--badbg:rgba(248,113,113,.15);--check:#2a2724;
21
+ --anchor:#f87171;--handle:#b8976c;--wire:#faf8f5;--vt:#9a938c;
22
+ --shadow:0 8px 24px -4px rgba(12,10,9,.5);--shadow-lg:0 20px 50px -12px rgba(12,10,9,.6);
23
+ --glow:0 0 30px rgba(201,117,74,.25);
24
+ --font-display:"Playfair Display",Georgia,serif;--font-body:"Inter",-apple-system,BlinkMacSystemFont,"Segoe UI",sans-serif;
25
+ --radius:12px;--radius-sm:8px;--radius-lg:16px;--radius-full:9999px}
26
+ *{box-sizing:border-box}
27
+ body{margin:0;background:var(--paper);color:var(--ink);font:15px/1.5 var(--font-body);-webkit-font-smoothing:antialiased}
28
+ a{color:var(--accent);text-decoration:none}a:hover{color:var(--accent-hover);text-decoration:underline}
29
+ button{font:600 13.5px/1 var(--font-body);color:var(--ink);background:var(--card);border:1px solid var(--rule);border-radius:var(--radius-sm);padding:10px 14px;cursor:pointer;transition:border-color .15s,background .15s,transform .1s,box-shadow .15s}
30
+ button:hover{border-color:rgba(250,248,245,.18)}button:active{transform:translateY(1px) scale(.98)}
31
+ button:disabled{opacity:.4;cursor:default;transform:none}
32
+ button.primary{background:var(--accent);border-color:var(--accent);color:var(--accent-ink);padding:12px 24px;font-size:14.5px;border-radius:var(--radius-full)}
33
+ button.primary:hover{background:var(--accent-hover);border-color:var(--accent-hover);box-shadow:var(--glow);transform:translateY(-1px)}
34
+ button[aria-pressed="true"]{background:var(--accent-soft);border-color:var(--accent);color:var(--accent)}
35
+ kbd{font:500 11px "IBM Plex Mono",monospace;border:1px solid var(--rule);border-bottom-width:2px;border-radius:5px;padding:1px 5px;color:var(--dim)}
36
+ .mono{font-family:"IBM Plex Mono",ui-monospace,monospace;font-variant-numeric:tabular-nums}
37
+ h1,h2,h3{font-family:var(--font-display)}
38
+ h2{font-size:clamp(22px,3vw,30px);letter-spacing:-.02em;font-weight:600;margin:0 0 6px;text-wrap:balance}
39
+ .sec{margin-top:64px}
40
+ /* top bar */
41
+ .top{position:sticky;top:0;z-index:20;display:flex;align-items:center;gap:14px;padding:14px 24px;border-bottom:1px solid var(--rule);background:var(--card)}
42
+ .top .mark{width:28px;height:28px}
43
+ .top .name{font-family:var(--font-display);font-weight:700;font-size:19px;letter-spacing:-.01em}
44
+ .top .by{color:var(--dim);font-size:13px}
45
+ .top nav{margin-left:auto;display:flex;gap:18px;font-size:13.5px;font-weight:600}
46
+ .top nav a{color:var(--dim)}
47
+ .top nav a:hover{color:var(--accent)}
48
+ main{max-width:1180px;margin:0 auto;padding:30px 22px 80px}
49
+ h1{font-size:clamp(30px,4.4vw,46px);line-height:1.08;letter-spacing:-.025em;font-weight:700;margin:0 0 10px;text-wrap:balance}
50
+ .lede{color:var(--dim);max-width:64ch;margin:0 0 22px;font-size:16px}
51
+ /* drop */
52
+ .drop{position:relative;display:flex;flex-direction:column;align-items:center;justify-content:center;gap:8px;min-height:140px;padding:24px;border:1.5px dashed var(--rule);border-radius:var(--radius);background:var(--card);cursor:pointer;transition:border-color .12s,background .12s;text-align:center}
53
+ .drop:hover,.drop.over{border-color:var(--accent);background:var(--accent-soft)}
54
+ .drop input{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0 0 0 0);white-space:nowrap;border:0}
55
+ .drop:focus-within{outline:2px solid var(--accent);outline-offset:3px}
56
+ .drop .big{font-weight:700;font-size:17px}
57
+ .drop .small{color:var(--dim);font-size:13.5px;max-width:72ch}
58
+ .drop svg{width:32px;height:32px;color:var(--accent)}
59
+ .samples{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin:12px 0 0;color:var(--dim);font-size:13px}
60
+ .samples button{padding:7px 11px;font-weight:600;font-size:12.5px;border-radius:999px}
61
+ /* controls */
62
+ .controls{display:flex;gap:14px;align-items:center;flex-wrap:wrap;margin:20px 0 12px}
63
+ .seg{display:inline-flex;background:var(--card);border:1px solid var(--rule);border-radius:var(--radius-full);padding:3px;gap:2px;flex-wrap:wrap}
64
+ .seg button{border:0;background:transparent;border-radius:var(--radius-full);padding:9px 13px;color:var(--dim)}
65
+ .seg button[aria-pressed="true"]{background:var(--accent-soft);color:var(--accent)}
66
+ .seg.small button{padding:7px 10px;font-size:12.5px}
67
+ .controls label.chk{display:inline-flex;align-items:center;gap:8px;font-weight:600;font-size:13.5px;color:var(--dim);cursor:pointer}
68
+ .controls .status{margin-left:auto;font-size:13px;color:var(--dim)}
69
+ .status.err{color:var(--bad)}
70
+ /* viewer */
71
+ .viewer{position:relative;display:grid;grid-template-columns:1fr 1fr;gap:10px}
72
+ .viewer.single{grid-template-columns:1fr}
73
+ .viewer.empty{display:flex;align-items:center;justify-content:center;min-height:220px;border:1px solid var(--rule);border-radius:var(--radius);background:var(--stage);color:var(--faint);text-align:center;padding:20px}
74
+ @media (max-width:720px){.viewer{grid-template-columns:1fr}}
75
+ .pane{position:relative;aspect-ratio:1;max-height:640px;background:var(--stage);border:1px solid var(--rule);border-radius:var(--radius);overflow:hidden;box-shadow:var(--shadow);cursor:grab;touch-action:none;user-select:none}
76
+ .viewer.single .pane{aspect-ratio:auto;height:min(70vh,640px)}
77
+ .pane:active{cursor:grabbing}
78
+ .pane .checker{position:absolute;inset:0;z-index:0;background-image:linear-gradient(45deg,var(--check) 25%,transparent 25%),linear-gradient(-45deg,var(--check) 25%,transparent 25%),linear-gradient(45deg,transparent 75%,var(--check) 75%),linear-gradient(-45deg,transparent 75%,var(--check) 75%);background-size:18px 18px;background-position:0 0,0 9px,9px -9px,-9px 0}
79
+ .pane .cam{position:absolute;left:0;top:0;width:100%;height:100%;transform-origin:0 0;z-index:1}
80
+ .pane .layer{position:absolute;inset:0}
81
+ .pane .layer>*{position:absolute;inset:0;width:100%;height:100%}
82
+ .pane .layer img{object-fit:contain;display:block}
83
+ .pane .layer svg{display:block}
84
+ .pane .rightwrap{position:absolute;inset:0;z-index:2}
85
+ .pane .rightwrap .cam{z-index:auto}
86
+ /* strokes stay the same size on screen at any zoom: non-scaling-stroke counters the SVG's own
87
+ viewBox scale, and dividing by --z counters the pane's CSS zoom */
88
+ .pane{--z:1}
89
+ .pane svg.wire path,.pane svg.wire circle,.pane svg.wire ellipse,.pane svg.wire rect{fill:none!important;stroke:var(--wire);stroke-width:1px;vector-effect:non-scaling-stroke;stroke-opacity:.9}
90
+ .pane svg.ov{pointer-events:none}
91
+ .pane svg.ov .h{stroke:var(--handle);stroke-width:1px;vector-effect:non-scaling-stroke;fill:none;stroke-opacity:.85}
92
+ .pane svg.ov .hd{stroke:var(--handle);stroke-width:3.5px;vector-effect:non-scaling-stroke;stroke-linecap:round;fill:none}
93
+ .pane svg.ov .a{stroke:var(--anchor);stroke-width:6px;vector-effect:non-scaling-stroke;stroke-linecap:round;fill:none}
94
+ .pane .divider{position:absolute;top:0;bottom:0;left:50%;width:2px;background:var(--accent);z-index:4;cursor:ew-resize;transform:translateX(-1px)}
95
+ .pane .divider::before{content:"";position:absolute;top:0;bottom:0;left:-14px;right:-14px}
96
+ .pane .divider::after{content:"";position:absolute;top:50%;left:50%;width:34px;height:34px;transform:translate(-50%,-50%);border-radius:50%;background:var(--accent);box-shadow:0 2px 10px rgba(12,10,9,.4);background-image:url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23faf8f5' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M8 7l-4 5 4 5M16 7l4 5-4 5'/%3E%3C/svg%3E");background-size:20px;background-repeat:no-repeat;background-position:center}
97
+ .pane .tag{position:absolute;top:10px;left:10px;z-index:3;font:600 11px/1 var(--font-body);letter-spacing:.08em;text-transform:uppercase;padding:5px 8px;border-radius:6px;background:rgba(250,248,245,.92);color:var(--accent-ink);pointer-events:none}
98
+ .pane .tag.r{left:auto;right:10px}
99
+ .pane .busy{position:absolute;inset:0;z-index:5;display:none;align-items:center;justify-content:center;background:rgba(12,10,9,.6);backdrop-filter:blur(2px)}
100
+ .pane .busy.on{display:flex}
101
+ .busy .pill{display:flex;align-items:center;gap:10px;background:var(--card);border:1px solid var(--rule);border-radius:var(--radius-full);padding:10px 16px;font-weight:600;box-shadow:var(--shadow)}
102
+ .spin{width:16px;height:16px;border:2px solid var(--rule);border-top-color:var(--accent);border-radius:50%;animation:spin .8s linear infinite}
103
+ @keyframes spin{to{transform:rotate(360deg)}}
104
+ @media (prefers-reduced-motion:reduce){.spin{animation:none}}
105
+ .zoomlbl{position:absolute;right:10px;bottom:10px;z-index:4;font:500 11px "IBM Plex Mono",monospace;padding:4px 7px;border-radius:6px;background:rgba(250,248,245,.92);color:var(--accent-ink);pointer-events:none}
106
+ /* toolbar under a viewer */
107
+ .tools{display:flex;gap:8px;align-items:center;flex-wrap:wrap;margin:10px 0}
108
+ .tools .lbl{font-size:12px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--faint);margin:0 2px 0 4px}
109
+ .tools .legend{display:flex;gap:12px;color:var(--dim);font-size:12.5px;margin-left:auto}
110
+ .tools .legend i{display:inline-block;width:10px;height:10px;border-radius:50%;vertical-align:-1px;margin-right:5px}
111
+ /* results */
112
+ .results{display:flex;gap:14px;align-items:center;flex-wrap:wrap;margin:10px 0}
113
+ .stats{display:flex;gap:6px;flex-wrap:wrap}
114
+ .stat{display:inline-flex;gap:6px;align-items:baseline;font-size:12.5px;padding:6px 10px;border-radius:999px;background:var(--rule2);color:var(--dim)}
115
+ .stat b{color:var(--ink);font-weight:700}
116
+ .results .actions{margin-left:auto;display:flex;gap:8px}
117
+ details{margin:18px 0 0}
118
+ summary{cursor:pointer;font-weight:700;font-size:13.5px;color:var(--dim);list-style:none;display:inline-flex;align-items:center;gap:6px}
119
+ summary::-webkit-details-marker{display:none}
120
+ summary::before{content:"";width:6px;height:6px;border-right:2px solid var(--faint);border-bottom:2px solid var(--faint);transform:rotate(-45deg);transition:transform .12s}
121
+ details[open] summary::before{transform:rotate(45deg)}
122
+ .adv{display:grid;grid-template-columns:repeat(auto-fit,minmax(180px,1fr));gap:12px 18px;padding:14px 0 4px}
123
+ .adv label{display:flex;flex-direction:column;gap:5px;font-size:12.5px;color:var(--dim);font-weight:600}
124
+ .adv input[type=number]{font:13px "IBM Plex Mono",monospace;padding:7px 9px;border:1px solid var(--rule);border-radius:8px;background:var(--card);color:var(--ink)}
125
+ .adv label.chk{flex-direction:row;align-items:center;gap:8px;margin-top:22px;color:var(--ink)}
126
+ .adv .hint{grid-column:1/-1;font-size:12.5px;color:var(--faint);font-weight:400}
127
+ textarea{width:100%;height:150px;margin-top:10px;font:11.5px/1.45 "IBM Plex Mono",monospace;border:1px solid var(--rule);border-radius:10px;padding:10px;background:var(--card);color:var(--ink);resize:vertical}
128
+ /* showcase */
129
+ .case{background:var(--card);border:1px solid var(--rule);border-radius:var(--radius);box-shadow:var(--shadow);padding:16px 18px;margin-bottom:22px}
130
+ .case header{display:flex;align-items:baseline;gap:10px;flex-wrap:wrap;margin-bottom:10px}
131
+ .case h3{margin:0;font-size:17px;font-weight:600;letter-spacing:-.01em}
132
+ .case .who{color:var(--faint);font-size:12.5px}
133
+ .chips{display:flex;gap:6px;flex-wrap:wrap;margin-top:8px}
134
+ .chip{display:inline-flex;gap:6px;align-items:baseline;font-size:12.5px;padding:5px 9px;border-radius:999px;background:var(--rule2);color:var(--dim)}
135
+ .chip b{color:var(--ink);font-weight:700}
136
+ .chip.win{background:var(--goodbg);color:var(--good)}.chip.win b{color:var(--good)}
137
+ .chip.vt{border:1px solid var(--rule);background:transparent}
138
+ /* versus */
139
+ .versus{display:grid;grid-template-columns:1.1fr 1fr;gap:22px;align-items:start}
140
+ @media (max-width:900px){.versus{grid-template-columns:1fr}}
141
+ .bignums{display:grid;grid-template-columns:repeat(2,1fr);gap:14px}
142
+ .bignum{background:var(--card);border:1px solid var(--rule);border-radius:var(--radius);padding:16px 18px;box-shadow:var(--shadow)}
143
+ .bignum .k{font-size:12px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--dim)}
144
+ .bignum .v{font-family:var(--font-display);font-size:32px;font-weight:600;letter-spacing:-.01em;line-height:1.1;margin:6px 0 2px;color:var(--accent)}
145
+ .bignum .s{font-size:12.5px;color:var(--dim)}
146
+ .bars{background:var(--card);border:1px solid var(--rule);border-radius:var(--radius);padding:6px 16px 14px;box-shadow:var(--shadow);overflow-x:auto}
147
+ .bars table{width:100%;border-collapse:collapse;font-size:12.5px;white-space:nowrap}
148
+ .bars caption{text-align:left;font-size:11px;font-weight:700;letter-spacing:.06em;text-transform:uppercase;color:var(--faint);padding:12px 0 8px}
149
+ .bars th,.bars td{padding:8px 10px;text-align:right;border-bottom:1px solid var(--rule2)}
150
+ .bars th:first-child,.bars td:first-child{text-align:left}
151
+ .bars thead th{color:var(--faint);font-weight:600;font-size:11px;letter-spacing:.04em;text-transform:uppercase}
152
+ .bars tbody tr:last-child td{border-bottom:0}
153
+ .bars tr.win td{color:var(--ink)}
154
+ .bars tr.win td:first-child{color:var(--accent);font-weight:600}
155
+ .note{color:var(--faint);font-size:12.5px;margin-top:10px}
156
+ footer{margin:60px auto 0;max-width:1180px;padding:0 22px;color:var(--faint);font-size:12.5px;display:flex;gap:16px;flex-wrap:wrap}
157
+ footer .v{margin-left:auto}
158
+ @media (max-width:640px){.top nav{display:none}.results .actions{margin-left:0}.bignums{grid-template-columns:1fr}.tools .legend{margin-left:0}}
159
+ </style>
160
+ </head>
161
+ <body>
162
+ <header class="top">
163
+ <svg class="mark" viewBox="0 0 32 32" aria-hidden="true"><path d="M16 3c-4 6-9 11-9 17a9 9 0 0 0 18 0c0-6-5-11-9-17z" fill="#c9754a"/><path d="M11 21c2 3 8 3 10 0" stroke="#faf8f5" stroke-width="2.2" fill="none" stroke-linecap="round"/></svg>
164
+ <span class="name">Inkvec</span><span class="by">by LogoLabs</span>
165
+ <nav><a href="#showcase">Before &amp; after</a><a href="#versus">Results</a><a href="#how">How it works</a><a href="https://github.com/logolabs/inkvec">GitHub</a></nav>
166
+ </header>
167
+ <main>
168
+ <h1>Exact vectors from your logo, in your browser.</h1>
169
+ <p class="lede">Drop a PNG, JPEG, WebP, GIF, BMP or TIFF. The tracer runs as WebAssembly on your machine, so nothing is uploaded. Edges land where the anti-aliasing says they are, circles come back as circles, and every colour is one clean path.</p>
170
+
171
+ <label class="drop" id="drop">
172
+ <input type="file" id="file" accept="image/*">
173
+ <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.8" stroke-linecap="round" stroke-linejoin="round"><path d="M12 16V4m0 0l-4 4m4-4l4 4"/><path d="M4 16v3a1 1 0 0 0 1 1h14a1 1 0 0 0 1-1v-3"/></svg>
174
+ <div class="big">Drop an image here, click to choose, or paste</div>
175
+ <div class="small">Logos, icons, flat illustrations. A 512-px logo takes a few seconds in the browser, larger ones longer; files above the max dimension are traced at that size and written at full size.</div>
176
+ </label>
177
+ <div class="samples" id="samples"><span>Try one:</span></div>
178
+
179
+ <div class="controls">
180
+ <div class="seg" id="presets" role="group" aria-label="preset">
181
+ <button data-p="logo" aria-pressed="true">Logo</button>
182
+ <button data-p="icon" aria-pressed="false">Icon</button>
183
+ <button data-p="detail" aria-pressed="false">Fine detail</button>
184
+ <button data-p="compact" aria-pressed="false">Fewer paths</button>
185
+ </div>
186
+ <label class="chk"><input type="checkbox" id="no_background"> Transparent background</label>
187
+ <button class="primary" id="go" disabled>Trace</button>
188
+ <span class="status mono" id="status">loading the tracer…</span>
189
+ </div>
190
+
191
+ <div class="viewer empty" id="viewer"><span>Your input and the vector result appear here side by side. Scroll to zoom, drag to pan; both sides move together.</span></div>
192
+ <div class="tools" id="livetools" hidden></div>
193
+
194
+ <div class="results">
195
+ <div class="stats" id="stats"></div>
196
+ <div class="actions"><button id="dl" disabled>Download SVG</button><button id="copy" disabled>Copy SVG</button><button id="showsrc" disabled aria-pressed="false">Source</button></div>
197
+ </div>
198
+ <textarea id="src" readonly hidden></textarea>
199
+
200
+ <details id="advanced"><summary>Advanced settings</summary>
201
+ <div class="adv">
202
+ <label>Precision (px)<input type="number" id="precision" value="0.1" step="0.05" min="0.02"></label>
203
+ <label>Speckle floor (px²)<input type="number" id="min_area" value="2" step="1" min="0"></label>
204
+ <label>Max colours<input type="number" id="colors" value="64" step="1" min="2"></label>
205
+ <label>Merge distance (OKLab)<input type="number" id="merge" value="0.055" step="0.005" min="0"></label>
206
+ <label>Max dimension (px)<input type="number" id="max_dim" value="1024" step="256" min="128"></label>
207
+ <label>Time budget (s)<input type="number" id="time_budget" value="20" step="5" min="0"></label>
208
+ <label>Margin (fraction)<input type="number" id="margin" value="0" step="0.02" min="0"></label>
209
+ <label class="chk"><input type="checkbox" id="minify"> Minify output</label>
210
+ <label class="chk"><input type="checkbox" id="content_units"> Content units (fewer paths)</label>
211
+ <span class="hint">Presets set these for you. Precision is the price of a coordinate; the speckle floor absorbs regions below it; content units scale the fit tolerances with the raster for a smaller file at the cost of exact corners.</span>
212
+ </div>
213
+ </details>
214
+
215
+ <section class="sec" id="showcase">
216
+ <h2>Before and after, with the geometry showing</h2>
217
+ <p class="lede">Real brand logos rendered from the brand's own file at 1024 px, then traced. Input on the left, the vector on the right, moving together as you zoom. Switch the right side to VTracer's trace of the same raster, or the view to a wipe or an A/B flick. <b>Anchors</b> shows every on-curve point the tracer emitted; <b>Handles</b> adds each cubic's control points with their tangents.</p>
218
+ <div id="gallery"></div>
219
+ </section>
220
+
221
+ <section class="sec" id="versus">
222
+ <h2>Inkvec vs the field</h2>
223
+ <p class="lede">21 cases &mdash; 14 hash-selected real icons across seven families, 4 hand-picked synthetic probes and 3 real brand logos from an external dataset (selection fixed from the seed <code class="mono">crosscompare-2026-09-15-v1</code>) &mdash; traced by every engine and scored against the source render with CIEDE2000 (colour), DISTS and DINOv3. VTracer is the widely used open-source tracer and the fastest thing here by a wide margin; that trade-off is shown too.</p>
224
+ <div class="versus">
225
+ <div class="bignums" id="bignums"></div>
226
+ <div class="bars" id="bars"></div>
227
+ </div>
228
+ <p class="note" id="vtnote"></p>
229
+ </section>
230
+
231
+ <section class="sec" id="how" style="max-width:72ch">
232
+ <h2>How it works</h2>
233
+ <p style="color:var(--dim);margin:0 0 8px">Inkvec decides the geometry from the evidence in the pixels. It finds the inks by minimum description length, builds a planar map where every boundary is shared by exactly two shapes so there are never seams, solves every boundary at once against an exact coverage render of the image, then fits lines, curves, circles and gradients priced in parameters. The result carries the artist's structure: a word is one path, a circle is a <code class="mono">&lt;circle&gt;</code>, and the coordinate count tracks the artwork rather than a tolerance slider.</p>
234
+ <p style="color:var(--dim);margin:0">The native command line uses every core and is several times faster than this browser build, which runs single-threaded.</p>
235
+ </section>
236
+ </main>
237
+ <footer><span>Runs entirely in your browser. Nothing is uploaded.</span><span>&copy; LogoLabs</span><span class="v mono" id="ver"></span></footer>
238
+
239
+ <script type="module">
240
+ const $ = id => document.getElementById(id);
241
+ const status = (t, err) => { const s = $("status"); s.textContent = t; s.className = "status mono" + (err ? " err" : ""); };
242
+ const A = window.INKVEC_ASSETS || {};
243
+ const asset = n => (A.samples && A.samples[n]) || `samples/${n}.png`;
244
+ const fmt = (v, d) => (v === undefined || v === null || Number.isNaN(v)) ? "—" : Number(v).toFixed(d);
245
+ const el = (tag, cls, html) => { const e = document.createElement(tag); if (cls) e.className = cls; if (html !== undefined) e.innerHTML = html; return e; };
246
+
247
+ // ---------------------------------------------------------------- geometry overlays
248
+ function parsePath(d, tx, ty){
249
+ const toks = d.match(/[MLHVCSQTAZmlhvcsqtaz]|-?\d*\.?\d+(?:e[-+]?\d+)?/gi) || [];
250
+ const anchors = [], handles = [];
251
+ let i = 0, cx = 0, cy = 0, sx = 0, sy = 0, cmd = null, pc = null, pcx = 0, pcy = 0;
252
+ const num = () => parseFloat(toks[i++]);
253
+ const push = (x,y) => anchors.push([x+tx, y+ty]);
254
+ const hd = (ax,ay,bx,by) => handles.push([[ax+tx,ay+ty],[bx+tx,by+ty]]);
255
+ while (i < toks.length){
256
+ const t = toks[i];
257
+ if (/[A-Za-z]/.test(t)){ cmd = t; i++; if (cmd==='Z'||cmd==='z'){ cx = sx; cy = sy; pc = null; continue; } }
258
+ const rel = cmd === cmd.toLowerCase(); const C = cmd.toUpperCase();
259
+ if (C === 'M'){ let x = num(), y = num(); if (rel){x+=cx;y+=cy;} cx=x;cy=y;sx=x;sy=y; push(x,y); cmd = rel?'l':'L'; pc=null; continue; }
260
+ if (C === 'L'){ let x = num(), y = num(); if (rel){x+=cx;y+=cy;} cx=x;cy=y; push(x,y); pc=null; continue; }
261
+ if (C === 'H'){ let x = num(); if (rel) x+=cx; cx=x; push(cx,cy); pc=null; continue; }
262
+ if (C === 'V'){ let y = num(); if (rel) y+=cy; cy=y; push(cx,cy); pc=null; continue; }
263
+ if (C === 'C'){ let x1=num(),y1=num(),x2=num(),y2=num(),x=num(),y=num(); if (rel){x1+=cx;y1+=cy;x2+=cx;y2+=cy;x+=cx;y+=cy;} hd(cx,cy,x1,y1); hd(x,y,x2,y2); cx=x;cy=y; push(x,y); pc='C'; pcx=x2; pcy=y2; continue; }
264
+ if (C === 'S'){ let x2=num(),y2=num(),x=num(),y=num(); if (rel){x2+=cx;y2+=cy;x+=cx;y+=cy;} const x1 = pc==='C' ? 2*cx-pcx : cx, y1 = pc==='C' ? 2*cy-pcy : cy; hd(cx,cy,x1,y1); hd(x,y,x2,y2); cx=x;cy=y; push(x,y); pc='C'; pcx=x2; pcy=y2; continue; }
265
+ if (C === 'Q'){ let x1=num(),y1=num(),x=num(),y=num(); if (rel){x1+=cx;y1+=cy;x+=cx;y+=cy;} hd(cx,cy,x1,y1); hd(x,y,x1,y1); cx=x;cy=y; push(x,y); pc='Q'; pcx=x1; pcy=y1; continue; }
266
+ if (C === 'T'){ let x=num(),y=num(); if (rel){x+=cx;y+=cy;} const x1 = pc==='Q' ? 2*cx-pcx : cx, y1 = pc==='Q' ? 2*cy-pcy : cy; hd(cx,cy,x1,y1); hd(x,y,x1,y1); cx=x;cy=y; push(x,y); pc='Q'; pcx=x1; pcy=y1; continue; }
267
+ if (C === 'A'){ num();num();num();num();num(); let x=num(),y=num(); if (rel){x+=cx;y+=cy;} cx=x;cy=y; push(x,y); pc=null; continue; }
268
+ i++;
269
+ }
270
+ return {anchors, handles};
271
+ }
272
+ const translateOf = e => { const m = (e.getAttribute('transform')||'').match(/translate\(\s*(-?[\d.e+-]+)[ ,]+(-?[\d.e+-]+)?\s*\)/i); return m ? [parseFloat(m[1]), parseFloat(m[2]||'0')] : [0,0]; };
273
+ function svgEl(text){ const h = document.createElement('div'); h.innerHTML = text; const s = h.querySelector('svg'); if (!s) return null; s.removeAttribute('width'); s.removeAttribute('height'); s.setAttribute('preserveAspectRatio','xMidYMid meet'); return s; }
274
+ function overlay(src){
275
+ const ns = 'http://www.w3.org/2000/svg';
276
+ const ov = document.createElementNS(ns, 'svg'); ov.setAttribute('viewBox', src.getAttribute('viewBox') || '0 0 100 100'); ov.setAttribute('class','ov'); ov.setAttribute('preserveAspectRatio','xMidYMid meet');
277
+ let Aa = '', H = '', HD = '', n = 0, nh = 0;
278
+ for (const e of src.querySelectorAll('path')){
279
+ const [tx, ty] = translateOf(e); const g = e.closest('g'); let gx = 0, gy = 0; if (g){ [gx, gy] = translateOf(g); }
280
+ const {anchors, handles} = parsePath(e.getAttribute('d')||'', tx+gx, ty+gy); n += anchors.length; nh += handles.length;
281
+ for (const [x,y] of anchors) Aa += `M${x.toFixed(2)} ${y.toFixed(2)}h0.001`;
282
+ for (const [a,b] of handles){ H += `M${a[0].toFixed(2)} ${a[1].toFixed(2)}L${b[0].toFixed(2)} ${b[1].toFixed(2)}`; HD += `M${b[0].toFixed(2)} ${b[1].toFixed(2)}h0.001`; }
283
+ }
284
+ for (const e of src.querySelectorAll('circle, ellipse')){ Aa += `M${parseFloat(e.getAttribute('cx')).toFixed(2)} ${parseFloat(e.getAttribute('cy')).toFixed(2)}h0.001`; n++; }
285
+ const mk = (d, cls) => { const p = document.createElementNS(ns,'path'); p.setAttribute('d', d||'M0 0'); p.setAttribute('class', cls); return p; };
286
+ const h = mk(H,'h'), hdp = mk(HD,'hd'), a = mk(Aa,'a'); ov.append(h, hdp, a);
287
+ return {ov, h, hd: hdp, a, n, cubics: nh/2};
288
+ }
289
+ function vectorLayer(svgText){
290
+ const fill = svgEl(svgText); const wire = svgEl(svgText); wire.setAttribute('class','wire');
291
+ const o = overlay(fill);
292
+ const root = el('div', 'layer'); root.append(fill, wire, o.ov);
293
+ const set = L => { root.dataset.layer = L; fill.style.display = (L==='fill'||L==='anchor'||L==='handle') ? '' : 'none'; fill.style.opacity = (L==='anchor'||L==='handle') ? '.35' : '1'; wire.style.display = (L==='wire'||L==='anchor'||L==='handle') ? '' : 'none'; o.a.style.display = (L==='anchor'||L==='handle') ? '' : 'none'; o.h.style.display = o.hd.style.display = (L==='handle') ? '' : 'none'; };
294
+ set('fill');
295
+ return {root, set, anchors: o.n, cubics: o.cubics};
296
+ }
297
+ const imgLayer = src => { const w = el('div', 'layer'); const im = document.createElement('img'); im.src = src; im.alt = ''; w.appendChild(im); return w; };
298
+
299
+ // ---------------------------------------------------------------- viewer: side by side, wipe, flick
300
+ function viewer(host, opts = {}){
301
+ host.classList.remove('empty'); host.innerHTML = '';
302
+ const mkPane = () => { const p = el('div', 'pane'); const chk = el('div', 'checker'); const cam = el('div', 'cam'); const tag = el('span', 'tag'); const zl = el('span', 'zoomlbl', '1.0×'); p.append(chk, cam, tag, zl); return {p, cam, tag, zl}; };
303
+ const L = mkPane(), R = mkPane();
304
+ const rightWrap = el('div', 'rightwrap'); const camW = el('div', 'cam'); rightWrap.appendChild(camW);
305
+ const tagR2 = el('span', 'tag r'); const divider = el('div', 'divider');
306
+ L.p.append(rightWrap, tagR2, divider);
307
+ if (opts.busy){ const b = el('div', 'busy', '<div class="pill"><span class="spin"></span><span class="t">Tracing…</span></div>'); L.p.appendChild(b); }
308
+ host.append(L.p, R.p);
309
+ const st = {z:1, x:0, y:0, split:0.5, mode:'side', flick:'left'};
310
+ let leftNode = null, rightNode = null;
311
+ // Zoom by resizing the camera box (the SVG re-renders at the new size, so it stays
312
+ // crisp at any magnification); only the pan is a transform.
313
+ const view = () => { const t = `translate(${st.x}px,${st.y}px)`; const sz = (st.z * 100) + '%'; for (const c of [L.cam, R.cam, camW]){ c.style.transform = t; c.style.width = sz; c.style.height = sz; } L.zl.textContent = R.zl.textContent = st.z.toFixed(1) + '×'; };
314
+ const setSplit = f => { st.split = Math.min(1, Math.max(0, f)); const px = st.split * L.p.getBoundingClientRect().width; rightWrap.style.clipPath = `inset(0 0 0 ${px}px)`; divider.style.left = px + 'px'; };
315
+ function layout(){
316
+ host.classList.toggle('single', st.mode !== 'side');
317
+ R.p.style.display = st.mode === 'side' ? '' : 'none';
318
+ divider.style.display = st.mode === 'wipe' ? '' : 'none';
319
+ rightWrap.style.display = st.mode === 'side' ? 'none' : '';
320
+ tagR2.style.display = st.mode === 'wipe' ? '' : 'none';
321
+ // where the right node lives
322
+ if (rightNode){ (st.mode === 'side' ? R.cam : camW).appendChild(rightNode); }
323
+ if (st.mode === 'wipe'){ rightWrap.style.clipPath = ''; setSplit(st.split); L.cam.style.visibility = ''; rightWrap.style.visibility = ''; }
324
+ else if (st.mode === 'flick'){ rightWrap.style.clipPath = 'none'; L.cam.style.visibility = st.flick === 'left' ? '' : 'hidden'; rightWrap.style.visibility = st.flick === 'right' ? '' : 'hidden'; }
325
+ else { L.cam.style.visibility = ''; }
326
+ if (st.mode === 'flick'){ const showing = st.flick === 'left' ? L.tag.dataset.n : R.tag.dataset.n; L.tag.textContent = 'showing ' + (showing || ''); }
327
+ }
328
+ // input: wheel zooms about the cursor in whichever pane it is over; drag pans; the divider wipes
329
+ let drag = null, onDiv = false;
330
+ for (const P of [L.p, R.p]){
331
+ P.addEventListener('wheel', ev => { ev.preventDefault(); const r = P.getBoundingClientRect(), mx = ev.clientX - r.left, my = ev.clientY - r.top; const f = Math.exp(-ev.deltaY * 0.0015), nz = Math.min(40, Math.max(0.5, st.z * f)), k = nz / st.z; st.x = mx - (mx - st.x) * k; st.y = my - (my - st.y) * k; st.z = nz; view(); }, {passive:false});
332
+ P.addEventListener('pointerdown', ev => { onDiv = !!ev.target.closest('.divider'); drag = [ev.clientX - st.x, ev.clientY - st.y]; P.setPointerCapture(ev.pointerId); });
333
+ P.addEventListener('pointermove', ev => { if (!drag) return; if (onDiv){ const r = L.p.getBoundingClientRect(); setSplit((ev.clientX - r.left) / r.width); return; } st.x = ev.clientX - drag[0]; st.y = ev.clientY - drag[1]; view(); });
334
+ const up = () => { drag = null; onDiv = false; }; P.addEventListener('pointerup', up); P.addEventListener('pointercancel', up);
335
+ P.addEventListener('dblclick', () => { st.z = 1; st.x = 0; st.y = 0; view(); });
336
+ }
337
+ window.addEventListener('resize', () => { if (st.mode === 'wipe') setSplit(st.split); });
338
+ layout(); view();
339
+ return {
340
+ setLeft(node, label){ leftNode = node; L.cam.innerHTML = ''; if (node) L.cam.appendChild(node); L.tag.dataset.n = label || ''; L.tag.textContent = label || ''; },
341
+ relabel(){ const nm = n => n ? (n.querySelector('svg') ? ' · svg · ' + ({fill:'fill', wire:'wireframe', anchor:'anchors', handle:'handles'}[n.dataset.layer] || 'fill') : ' · raster') : ''; L.tag.textContent = (L.tag.dataset.n || '') + nm(leftNode); R.tag.textContent = (R.tag.dataset.n || '') + nm(rightNode); tagR2.textContent = R.tag.textContent; },
342
+ setRight(node, label){ rightNode = node; R.cam.innerHTML = ''; camW.innerHTML = ''; if (node) (st.mode === 'side' ? R.cam : camW).appendChild(node); R.tag.dataset.n = label || ''; R.tag.textContent = label || ''; tagR2.textContent = label || ''; layout(); this.relabel(); },
343
+ setMode(m){ st.mode = m; layout(); },
344
+ flick(side){ st.flick = side; if (st.mode === 'flick') layout(); },
345
+ zoom(z){ const r = L.p.getBoundingClientRect(); st.x = (r.width - r.width*z)/2; st.y = (r.height - r.height*z)/2; st.z = z; view(); },
346
+ reset(){ st.z = 1; st.x = 0; st.y = 0; view(); },
347
+ busy(on, text){ const b = L.p.querySelector('.busy'); if (!b) return; b.classList.toggle('on', on); if (text) b.querySelector('.t').textContent = text; },
348
+ };
349
+ }
350
+ // Toolbar: view mode, layers, zoom presets. `onLayer(L)` applies a layer to the vector nodes.
351
+ function toolbar(host, v, onLayer, extra){
352
+ host.innerHTML = '';
353
+ const seg = (items, cls, on) => { const s = el('div', 'seg small'); for (const [key, label, pressed] of items){ const b = el('button', '', label); b.dataset.k = key; b.setAttribute('aria-pressed', !!pressed); b.addEventListener('click', () => { for (const o of s.children) o.setAttribute('aria-pressed','false'); b.setAttribute('aria-pressed','true'); on(key); }); s.appendChild(b); } return s; };
354
+ host.append(el('span', 'lbl', 'view'), seg([['side','Side by side',true],['wipe','Wipe'],['flick','A / B']], '', m => v.setMode(m)));
355
+ const fl = el('button', '', 'Flick'); fl.title = 'Hold to show the other side (or hold Space)';
356
+ fl.addEventListener('pointerdown', () => v.flick('right')); fl.addEventListener('pointerup', () => v.flick('left')); fl.addEventListener('pointerleave', () => v.flick('left'));
357
+ host.append(fl);
358
+ host.append(el('span', 'lbl', 'show'), seg([['fill','Fill',true],['wire','Wireframe'],['anchor','Anchors'],['handle','Handles']], '', onLayer));
359
+ const z = el('div', 'seg small'); for (const k of [1, 4, 12]){ const b = el('button', '', k + '×'); b.addEventListener('click', () => v.zoom(k)); z.appendChild(b); } host.append(el('span', 'lbl', 'zoom'), z);
360
+ if (extra) host.append(extra);
361
+ host.append(el('span', 'legend', '<span><i style="background:var(--anchor)"></i>anchor</span><span><i style="background:var(--handle)"></i>control point &amp; tangent</span>'));
362
+ }
363
+ // Space flicks whichever viewer the pointer is over
364
+ let hot = null;
365
+ document.addEventListener('keydown', e => { if (e.code === 'Space' && hot && !e.repeat && document.activeElement.tagName !== 'INPUT' && document.activeElement.tagName !== 'TEXTAREA'){ e.preventDefault(); hot.flick('right'); } });
366
+ document.addEventListener('keyup', e => { if (e.code === 'Space' && hot) hot.flick('left'); });
367
+
368
+ // ---------------------------------------------------------------- live tracer
369
+ let bytes = null, svgText = "", name = "image", jobId = 0, timer = null, live = null, liveVec = null, liveLayer = 'fill';
370
+ const PRESETS = {
371
+ logo: {precision:0.1, min_area:2, colors:64, merge:0.055, max_dim:1024, content_units:false},
372
+ icon: {precision:0.1, min_area:1, colors:16, merge:0.055, max_dim:1024, content_units:false},
373
+ detail: {precision:0.05, min_area:1, colors:64, merge:0.045, max_dim:2048, content_units:false},
374
+ compact: {precision:0.1, min_area:4, colors:32, merge:0.06, max_dim:1024, content_units:true},
375
+ };
376
+ function applyPreset(p){ const v = PRESETS[p]; for (const k in v){ const e = $(k); if (e.type === "checkbox") e.checked = v[k]; else e.value = v[k]; } }
377
+ for (const b of document.querySelectorAll("#presets button")) b.addEventListener("click", () => { for (const o of document.querySelectorAll("#presets button")) o.setAttribute("aria-pressed","false"); b.setAttribute("aria-pressed","true"); applyPreset(b.dataset.p); if (bytes) $("go").click(); });
378
+
379
+ let worker = null;
380
+ function makeWorker(){
381
+ const url = A.workerUrl || "./worker.js?v=7";
382
+ try { worker = new Worker(url, { type: "module" }); } catch (e) { worker = null; return; }
383
+ worker.onmessage = (e) => {
384
+ const m = e.data;
385
+ if (m.type === "ready") { $("ver").textContent = `inkvec ${m.version} · wasm${m.threads > 1 ? ` · ${m.threads + 1} cores` : ""}`; if (!bytes) status("ready · drop an image"); return; }
386
+ if (m.id !== jobId) return;
387
+ if (m.type === "error") {
388
+ finish(); status("failed: " + m.error, true);
389
+ // A trap inside WebAssembly can leave the module's memory in an unknown state, so the
390
+ // next image gets a fresh worker rather than the one that just failed.
391
+ if (/RuntimeError|unreachable/.test(m.error)) { worker.terminate(); makeWorker(); }
392
+ return;
393
+ }
394
+ svgText = m.svg; finish(); show(svgText, m.ms);
395
+ };
396
+ worker.onerror = (e) => { status("worker error: " + (e.message || e), true); };
397
+ }
398
+ makeWorker();
399
+
400
+ // The tracer decodes the whole image before --max-dim applies, so a huge upload costs memory
401
+ // the tab may not have. Refuse it here, with a way forward, instead of stalling the worker.
402
+ const MAX_BYTES = 40 * 1024 * 1024;
403
+ const MAX_PIXELS = 6000 * 6000;
404
+ function pick(f){
405
+ if (!f) return;
406
+ if (f.size > MAX_BYTES){ status(`${f.name} is ${(f.size/1048576).toFixed(0)} MB. The browser demo takes files up to 40 MB; use the command line for larger ones.`, true); return; }
407
+ name = f.name.replace(/\.[^.]+$/, "");
408
+ f.arrayBuffer().then(async b => {
409
+ try {
410
+ const bmp = await createImageBitmap(f);
411
+ const [bw, bh] = [bmp.width, bmp.height];
412
+ if (bmp.close) bmp.close();
413
+ if (bw * bh > MAX_PIXELS){ status(`${f.name} is ${bw} x ${bh}. The browser demo takes images up to 6000 x 6000; downscale it or use the command line.`, true); return; }
414
+ } catch (e) {
415
+ // Formats the browser cannot preview (TIFF, for one) go straight to the tracer.
416
+ }
417
+ bytes = new Uint8Array(b); $("go").disabled = false; status(`${f.name} · ${(f.size/1024).toFixed(0)} KB`);
418
+ if (!live){ live = viewer($("viewer"), {busy:true}); $("livetools").hidden = false; toolbar($("livetools"), live, L => { liveLayer = L; if (liveVec) liveVec.set(L); live.relabel(); }); $("viewer").addEventListener('pointerenter', () => hot = live); }
419
+ live.setLeft(imgLayer(URL.createObjectURL(f)), 'input'); live.setRight(null, ''); live.reset();
420
+ $("viewer").scrollIntoView({block:'nearest'});
421
+ $("go").click();
422
+ });
423
+ }
424
+ $("file").addEventListener("change", e => pick(e.target.files[0]));
425
+ const drop = $("drop");
426
+ drop.addEventListener("dragover", e => { e.preventDefault(); drop.classList.add("over"); });
427
+ drop.addEventListener("dragleave", () => drop.classList.remove("over"));
428
+ drop.addEventListener("drop", e => { e.preventDefault(); drop.classList.remove("over"); pick(e.dataTransfer.files[0]); });
429
+ document.addEventListener("paste", e => { const f = [...(e.clipboardData?.files || [])][0]; if (f) pick(f); });
430
+ for (const n of ["365retailmarkets","adamo","1075thefan"]){
431
+ const b = el("button", "", n); b.addEventListener("click", async () => { const r = await fetch(asset(n)); const bl = await r.blob(); pick(new File([bl], n + ".png", {type:"image/png"})); });
432
+ $("samples").appendChild(b);
433
+ }
434
+ function options(){ return { precision:+$("precision").value, min_area:+$("min_area").value, colors:+$("colors").value, merge:+$("merge").value, max_dim:+$("max_dim").value, time_budget:+$("time_budget").value, no_background:$("no_background").checked, minify:$("minify").checked, margin:+$("margin").value, content_units:$("content_units").checked }; }
435
+ function start(){ $("go").disabled = true; const t0 = performance.now(); live && live.busy(true, "Tracing…"); timer = setInterval(() => live && live.busy(true, `Tracing… ${((performance.now()-t0)/1000).toFixed(1)} s`), 100); }
436
+ function finish(){ $("go").disabled = false; clearInterval(timer); live && live.busy(false); }
437
+ $("go").addEventListener("click", () => {
438
+ if (!bytes) return;
439
+ start(); status("tracing…"); jobId += 1;
440
+ if (worker) worker.postMessage({ id: jobId, bytes, o: options() });
441
+ else { finish(); status("the tracer could not start in this browser", true); }
442
+ });
443
+ $("no_background").addEventListener("change", () => { if (bytes) $("go").click(); });
444
+ function show(svg, ms){
445
+ liveVec = vectorLayer(svg); liveVec.set(liveLayer);
446
+ live.setRight(liveVec.root, 'inkvec');
447
+ const paths = (svg.match(/<path/g)||[]).length, prims = (svg.match(/<(circle|ellipse|rect)\b/g)||[]).length, grads = (svg.match(/<(linear|radial)Gradient/g)||[]).length, nums = (svg.match(/-?\d+\.?\d*/g)||[]).length;
448
+ $("stats").innerHTML = [[`${(ms/1000).toFixed(2)} s`, ''], [paths, 'paths'], [prims, 'primitives'], [grads, 'gradients'], [liveVec.anchors, 'anchors'], [nums, 'numbers'], [`${(svg.length/1024).toFixed(1)} KB`, '']].map(([v, k]) => `<span class="stat"><b>${v}</b>${k ? ' ' + k : ''}</span>`).join('');
449
+ $("src").value = svg; $("dl").disabled = $("copy").disabled = $("showsrc").disabled = false;
450
+ status(`done in ${(ms/1000).toFixed(2)} s`);
451
+ }
452
+ $("dl").addEventListener("click", () => { const a = document.createElement("a"); a.href = URL.createObjectURL(new Blob([svgText], {type:"image/svg+xml"})); a.download = name + ".svg"; a.click(); });
453
+ $("copy").addEventListener("click", () => navigator.clipboard.writeText(svgText).then(() => status("copied to clipboard")));
454
+ $("showsrc").addEventListener("click", () => { const on = $("showsrc").getAttribute("aria-pressed") !== "true"; $("showsrc").setAttribute("aria-pressed", on); $("src").hidden = !on; });
455
+
456
+ // ---------------------------------------------------------------- showcase + versus
457
+ async function loadShowcase(){
458
+ let d = A.showcase;
459
+ if (!d){ try { d = await (await fetch('showcase.json?v=4')).json(); } catch (e) { return; } }
460
+ const gal = $("gallery");
461
+ for (const lg of d.logos){
462
+ const card = el('article', 'case');
463
+ card.innerHTML = `<header><h3>${lg.name}</h3><span class="who">artist: ${lg.artist_paths} paths</span></header><div class="viewer"></div><div class="tools"></div><div class="chips"></div>`;
464
+ gal.appendChild(card);
465
+ const v = viewer(card.querySelector('.viewer'));
466
+ card.querySelector('.viewer').addEventListener('pointerenter', () => hot = v);
467
+ const ours = vectorLayer(lg.ours.svg), vt = vectorLayer(lg.vtracer.svg);
468
+ let cmp = 'input';
469
+ const apply = () => { if (cmp === 'input'){ v.setLeft(imgLayer(lg.png), 'input'); v.setRight(ours.root, 'inkvec'); } else { v.setLeft(ours.root, 'inkvec'); v.setRight(vt.root, 'vtracer'); } v.relabel(); };
470
+ const cmpSeg = el('div', 'seg small');
471
+ for (const [k, label, on] of [['input', 'input · inkvec', true], ['vtracer', 'inkvec · vtracer']]){ const b = el('button', '', label); b.setAttribute('aria-pressed', !!on); b.addEventListener('click', () => { for (const o of cmpSeg.children) o.setAttribute('aria-pressed','false'); b.setAttribute('aria-pressed','true'); cmp = k; apply(); }); cmpSeg.appendChild(b); }
472
+ const wrap = el('span'); wrap.append(el('span', 'lbl', 'compare'), cmpSeg);
473
+ toolbar(card.querySelector('.tools'), v, L => { ours.set(L); vt.set(L); v.relabel(); }, wrap);
474
+ apply();
475
+ const m = lg.ours.m, w = lg.vtracer.m;
476
+ card.querySelector('.chips').innerHTML =
477
+ `<span class="chip win">inkvec dE00 <b>${fmt(m.de00,3)}</b></span><span class="chip vt">vtracer dE00 <b>${fmt(w.de00,3)}</b></span>` +
478
+ `<span class="chip win">paths <b>${m.paths}</b> · anchors <b>${ours.anchors}</b></span><span class="chip vt">paths <b>${w.paths}</b> · anchors <b>${vt.anchors}</b></span>` +
479
+ `<span class="chip win"><b>${(m.bytes/1024).toFixed(1)} KB</b></span><span class="chip vt"><b>${(w.bytes/1024).toFixed(1)} KB</b></span>`;
480
+ }
481
+ }
482
+ // Source: out/crosscompare-competitors-2026-09-15/summary.md -- 21 cases: 14 hash-selected
483
+ // real icons across seven families, 4 hand-picked synthetic probes, and 3 real brand logos
484
+ // from an external dataset (selection fixed from the seed crosscompare-2026-09-15-v1). Scored
485
+ // against the source render with CIEDE2000 (dE00), DISTS and DINOv3. Regenerate with
486
+ // bench/crosscompare_competitors.py. Timings were measured on a machine doing other CPU-bound
487
+ // work at the same time; treat them as approximate.
488
+ const COMPETITORS = [
489
+ {name:'Inkvec', mean:0.132, median:0.054, dists:0.0236, dino:0.991, coords:446, sec:1.17, win:true},
490
+ {name:'VTracer 0.6.15 (PyPI, default)', mean:1.303, median:0.598, dists:0.0508, dino:0.9633, coords:1943, sec:0.04},
491
+ {name:'VTracer 1.0.0-alpha.4 (default)', mean:1.303, median:0.598, dists:0.0508, dino:0.9633, coords:1943, sec:0.05},
492
+ {name:'VTracer 1.0.0-alpha.4 (--simplify)', mean:1.264, median:0.579, dists:0.0636, dino:0.9538, coords:1239, sec:0.06},
493
+ {name:'Trazor (PhenX/Trazor, MIT)', mean:0.518, median:0.227, dists:0.0479, dino:0.9711, coords:1172, sec:2.19},
494
+ ];
495
+ function renderVersus(){
496
+ const us = COMPETITORS[0], vt = COMPETITORS[1];
497
+ $("bignums").innerHTML = [
498
+ ['colour error, dE00 (median)', `${fmt(us.median,3)} <span style="font-size:16px;color:var(--dim)">vs ${fmt(vt.median,3)}</span>`, `${(vt.median/us.median).toFixed(1)}× lower than VTracer`],
499
+ ['DISTS', `${fmt(us.dists,4)} <span style="font-size:16px;color:var(--dim)">vs ${fmt(vt.dists,4)}</span>`, 'perceptual distance, lower is better'],
500
+ ['coordinates emitted', `${us.coords} <span style="font-size:16px;color:var(--dim)">vs ${vt.coords}</span>`, `${(vt.coords/us.coords).toFixed(1)}× fewer numbers per SVG, mean of 21 cases`],
501
+ ['seconds per case', `${fmt(us.sec,2)} <span style="font-size:16px;color:var(--dim)">vs ${fmt(vt.sec,2)}</span>`, 'VTracer is the fast, lower-fidelity option here'],
502
+ ].map(([k, val, sub]) => `<div class="bignum"><div class="k">${k}</div><div class="v">${val}</div><div class="s">${sub}</div></div>`).join('');
503
+ $("bars").innerHTML = `<table><caption>21 cases, 2026-09-15</caption><thead><tr><th>engine</th><th>mean dE00</th><th>median dE00</th><th>DISTS</th><th>DINO</th><th>coords</th><th>seconds</th></tr></thead><tbody>` +
504
+ COMPETITORS.map(r => `<tr class="${r.win ? 'win' : ''}"><td>${r.name}</td><td class="mono">${fmt(r.mean,3)}</td><td class="mono">${fmt(r.median,3)}</td><td class="mono">${fmt(r.dists,4)}</td><td class="mono">${fmt(r.dino,4)}</td><td class="mono">${r.coords}</td><td class="mono">${fmt(r.sec,2)}</td></tr>`).join('') +
505
+ `</tbody></table>`;
506
+ $("vtnote").innerHTML = `Source: <code class="mono">out/crosscompare-competitors-2026-09-15/summary.md</code>. Two more engines were measured for completeness and are left out of this table because they are not comparable at the geometry level: covecto's default mode and potrace-color both reproduce the source pixel grid almost losslessly (tens of thousands of coordinates per case) rather than artist-shaped geometry. Full detail in the <a href="https://github.com/logolabs/inkvec#results">README</a>.`;
507
+ }
508
+ renderVersus();
509
+ loadShowcase();
510
+
511
+ // ?demo=name traces a sample on load (headless check). Kept last.
512
+ const demo = new URLSearchParams(location.search).get("demo");
513
+ if (demo){ const r = await fetch(asset(demo)); const bl = await r.blob(); pick(new File([bl], demo + ".png", {type:"image/png"})); }
514
+ </script>
515
+ </body>
516
  </html>
pkg/inkvec_wasm.d.ts ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+
4
+ /**
5
+ * How many workers the pool should start, from the browser's own estimate.
6
+ *
7
+ * Returned rather than decided here: the pool is started from JavaScript, and only the
8
+ * page knows whether it is allowed to (`crossOriginIsolated`) and how many cores the
9
+ * visitor has agreed to give it.
10
+ */
11
+ export function threads_available(): boolean;
12
+
13
+ /**
14
+ * Trace image bytes to an SVG string.
15
+ *
16
+ * `precision`, `min_area`, `colors`, `merge` are the tracer's quality knobs (pass the
17
+ * defaults 0.1, 2, 64, 0.055 when unsure); `max_dim` and `time_budget` bound the work;
18
+ * `no_background`, `minify`, `margin`, `content_units` shape the output.
19
+ */
20
+ export function trace(bytes: Uint8Array, precision: number, min_area: number, colors: number, merge: number, max_dim: number, time_budget: number, no_background: boolean, minify: boolean, margin: number, content_units: boolean): string;
21
+
22
+ /**
23
+ * The tracer's version, for the page footer.
24
+ */
25
+ export function version(): string;
26
+
27
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
28
+
29
+ export interface InitOutput {
30
+ readonly memory: WebAssembly.Memory;
31
+ readonly threads_available: () => number;
32
+ readonly trace: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => [number, number, number, number];
33
+ readonly version: () => [number, number];
34
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
35
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
36
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
37
+ readonly __externref_table_alloc: () => number;
38
+ readonly __wbindgen_externrefs: WebAssembly.Table;
39
+ readonly __externref_table_dealloc: (a: number) => void;
40
+ readonly __wbindgen_start: () => void;
41
+ }
42
+
43
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
44
+
45
+ /**
46
+ * Instantiates the given `module`, which can either be bytes or
47
+ * a precompiled `WebAssembly.Module`.
48
+ *
49
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
50
+ *
51
+ * @returns {InitOutput}
52
+ */
53
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
54
+
55
+ /**
56
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
57
+ * for everything else, calls `WebAssembly.instantiate` directly.
58
+ *
59
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
60
+ *
61
+ * @returns {Promise<InitOutput>}
62
+ */
63
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
pkg/inkvec_wasm.js ADDED
@@ -0,0 +1,354 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* @ts-self-types="./inkvec_wasm.d.ts" */
2
+
3
+ /**
4
+ * How many workers the pool should start, from the browser's own estimate.
5
+ *
6
+ * Returned rather than decided here: the pool is started from JavaScript, and only the
7
+ * page knows whether it is allowed to (`crossOriginIsolated`) and how many cores the
8
+ * visitor has agreed to give it.
9
+ * @returns {boolean}
10
+ */
11
+ export function threads_available() {
12
+ const ret = wasm.threads_available();
13
+ return ret !== 0;
14
+ }
15
+
16
+ /**
17
+ * Trace image bytes to an SVG string.
18
+ *
19
+ * `precision`, `min_area`, `colors`, `merge` are the tracer's quality knobs (pass the
20
+ * defaults 0.1, 2, 64, 0.055 when unsure); `max_dim` and `time_budget` bound the work;
21
+ * `no_background`, `minify`, `margin`, `content_units` shape the output.
22
+ * @param {Uint8Array} bytes
23
+ * @param {number} precision
24
+ * @param {number} min_area
25
+ * @param {number} colors
26
+ * @param {number} merge
27
+ * @param {number} max_dim
28
+ * @param {number} time_budget
29
+ * @param {boolean} no_background
30
+ * @param {boolean} minify
31
+ * @param {number} margin
32
+ * @param {boolean} content_units
33
+ * @returns {string}
34
+ */
35
+ export function trace(bytes, precision, min_area, colors, merge, max_dim, time_budget, no_background, minify, margin, content_units) {
36
+ let deferred3_0;
37
+ let deferred3_1;
38
+ try {
39
+ const ptr0 = passArray8ToWasm0(bytes, wasm.__wbindgen_malloc);
40
+ const len0 = WASM_VECTOR_LEN;
41
+ const ret = wasm.trace(ptr0, len0, precision, min_area, colors, merge, max_dim, time_budget, no_background, minify, margin, content_units);
42
+ var ptr2 = ret[0];
43
+ var len2 = ret[1];
44
+ if (ret[3]) {
45
+ ptr2 = 0; len2 = 0;
46
+ throw takeFromExternrefTable0(ret[2]);
47
+ }
48
+ deferred3_0 = ptr2;
49
+ deferred3_1 = len2;
50
+ return getStringFromWasm0(ptr2, len2);
51
+ } finally {
52
+ wasm.__wbindgen_free(deferred3_0, deferred3_1, 1);
53
+ }
54
+ }
55
+
56
+ /**
57
+ * The tracer's version, for the page footer.
58
+ * @returns {string}
59
+ */
60
+ export function version() {
61
+ let deferred1_0;
62
+ let deferred1_1;
63
+ try {
64
+ const ret = wasm.version();
65
+ deferred1_0 = ret[0];
66
+ deferred1_1 = ret[1];
67
+ return getStringFromWasm0(ret[0], ret[1]);
68
+ } finally {
69
+ wasm.__wbindgen_free(deferred1_0, deferred1_1, 1);
70
+ }
71
+ }
72
+ function __wbg_get_imports() {
73
+ const import0 = {
74
+ __proto__: null,
75
+ __wbg___wbindgen_is_undefined_8c687d0b90d5b524: function(arg0) {
76
+ const ret = arg0 === undefined;
77
+ return ret;
78
+ },
79
+ __wbg___wbindgen_throw_5d9e815e6fdf150f: function(arg0, arg1) {
80
+ throw new Error(getStringFromWasm0(arg0, arg1));
81
+ },
82
+ __wbg_error_757e9472f8410341: function(arg0, arg1) {
83
+ let deferred0_0;
84
+ let deferred0_1;
85
+ try {
86
+ deferred0_0 = arg0;
87
+ deferred0_1 = arg1;
88
+ console.error(getStringFromWasm0(arg0, arg1));
89
+ } finally {
90
+ wasm.__wbindgen_free(deferred0_0, deferred0_1, 1);
91
+ }
92
+ },
93
+ __wbg_new_227d7c05414eb861: function() {
94
+ const ret = new Error();
95
+ return ret;
96
+ },
97
+ __wbg_now_e7c6795a7f81e10f: function(arg0) {
98
+ const ret = arg0.now();
99
+ return ret;
100
+ },
101
+ __wbg_performance_3fcf6e32a7e1ed0a: function(arg0) {
102
+ const ret = arg0.performance;
103
+ return ret;
104
+ },
105
+ __wbg_stack_3b0d974bbf31e44f: function(arg0, arg1) {
106
+ const ret = arg1.stack;
107
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
108
+ const len1 = WASM_VECTOR_LEN;
109
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
110
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
111
+ },
112
+ __wbg_static_accessor_GLOBAL_8eb4cd83130a11a0: function() {
113
+ const ret = typeof global === 'undefined' ? null : global;
114
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
115
+ },
116
+ __wbg_static_accessor_GLOBAL_THIS_1e7044f654e934db: function() {
117
+ const ret = typeof globalThis === 'undefined' ? null : globalThis;
118
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
119
+ },
120
+ __wbg_static_accessor_SELF_d8b50611246a6d92: function() {
121
+ const ret = typeof self === 'undefined' ? null : self;
122
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
123
+ },
124
+ __wbg_static_accessor_WINDOW_fd0bc376bf0f8b42: function() {
125
+ const ret = typeof window === 'undefined' ? null : window;
126
+ return isLikeNone(ret) ? 0 : addToExternrefTable0(ret);
127
+ },
128
+ __wbindgen_generic_0000000000000001: function(arg0, arg1) {
129
+ // Cast intrinsic for `Ref(String) -> Externref`.
130
+ const ret = getStringFromWasm0(arg0, arg1);
131
+ return ret;
132
+ },
133
+ __wbindgen_init_externref_table: function() {
134
+ const table = wasm.__wbindgen_externrefs;
135
+ const offset = table.grow(4);
136
+ table.set(0, undefined);
137
+ table.set(offset + 0, undefined);
138
+ table.set(offset + 1, null);
139
+ table.set(offset + 2, true);
140
+ table.set(offset + 3, false);
141
+ },
142
+ };
143
+ return {
144
+ __proto__: null,
145
+ "./inkvec_wasm_bg.js": import0,
146
+ };
147
+ }
148
+
149
+ function addToExternrefTable0(obj) {
150
+ const idx = wasm.__externref_table_alloc();
151
+ wasm.__wbindgen_externrefs.set(idx, obj);
152
+ return idx;
153
+ }
154
+
155
+ let cachedDataViewMemory0 = null;
156
+ function getDataViewMemory0() {
157
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
158
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
159
+ }
160
+ return cachedDataViewMemory0;
161
+ }
162
+
163
+ function getStringFromWasm0(ptr, len) {
164
+ return decodeText(ptr >>> 0, len);
165
+ }
166
+
167
+ let cachedUint8ArrayMemory0 = null;
168
+ function getUint8ArrayMemory0() {
169
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
170
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
171
+ }
172
+ return cachedUint8ArrayMemory0;
173
+ }
174
+
175
+ function isLikeNone(x) {
176
+ return x === undefined || x === null;
177
+ }
178
+
179
+ function passArray8ToWasm0(arg, malloc) {
180
+ const ptr = malloc(arg.length * 1, 1) >>> 0;
181
+ getUint8ArrayMemory0().set(arg, ptr / 1);
182
+ WASM_VECTOR_LEN = arg.length;
183
+ return ptr;
184
+ }
185
+
186
+ function passStringToWasm0(arg, malloc, realloc) {
187
+ if (realloc === undefined) {
188
+ const buf = cachedTextEncoder.encode(arg);
189
+ const ptr = malloc(buf.length, 1) >>> 0;
190
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
191
+ WASM_VECTOR_LEN = buf.length;
192
+ return ptr;
193
+ }
194
+
195
+ let len = arg.length;
196
+ let ptr = malloc(len, 1) >>> 0;
197
+
198
+ const mem = getUint8ArrayMemory0();
199
+
200
+ let offset = 0;
201
+
202
+ for (; offset < len; offset++) {
203
+ const code = arg.charCodeAt(offset);
204
+ if (code > 0x7F) break;
205
+ mem[ptr + offset] = code;
206
+ }
207
+ if (offset !== len) {
208
+ if (offset !== 0) {
209
+ arg = arg.slice(offset);
210
+ }
211
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
212
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
213
+ const ret = cachedTextEncoder.encodeInto(arg, view);
214
+
215
+ offset += ret.written;
216
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
217
+ }
218
+
219
+ WASM_VECTOR_LEN = offset;
220
+ return ptr;
221
+ }
222
+
223
+ function takeFromExternrefTable0(idx) {
224
+ const value = wasm.__wbindgen_externrefs.get(idx);
225
+ wasm.__externref_table_dealloc(idx);
226
+ return value;
227
+ }
228
+
229
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
230
+ cachedTextDecoder.decode();
231
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
232
+ let numBytesDecoded = 0;
233
+ function decodeText(ptr, len) {
234
+ numBytesDecoded += len;
235
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
236
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
237
+ cachedTextDecoder.decode();
238
+ numBytesDecoded = len;
239
+ }
240
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
241
+ }
242
+
243
+ const cachedTextEncoder = new TextEncoder();
244
+
245
+ if (!('encodeInto' in cachedTextEncoder)) {
246
+ cachedTextEncoder.encodeInto = function (arg, view) {
247
+ const buf = cachedTextEncoder.encode(arg);
248
+ view.set(buf);
249
+ return {
250
+ read: arg.length,
251
+ written: buf.length
252
+ };
253
+ };
254
+ }
255
+
256
+ let WASM_VECTOR_LEN = 0;
257
+
258
+ let wasmModule, wasmInstance, wasm;
259
+ function __wbg_finalize_init(instance, module) {
260
+ wasmInstance = instance;
261
+ wasm = instance.exports;
262
+ wasmModule = module;
263
+ cachedDataViewMemory0 = null;
264
+ cachedUint8ArrayMemory0 = null;
265
+ wasm.__wbindgen_start();
266
+ return wasm;
267
+ }
268
+
269
+ async function __wbg_load(module, imports) {
270
+ if (typeof Response === 'function' && module instanceof Response) {
271
+ if (!module.ok) {
272
+ throw new Error(`failed to fetch Wasm: ${module.status} ${module.statusText} fetching '${module.url}'`);
273
+ }
274
+
275
+ if (typeof WebAssembly.instantiateStreaming === 'function') {
276
+ try {
277
+ return await WebAssembly.instantiateStreaming(module, imports);
278
+ } catch (e) {
279
+ const validResponse = expectedResponseType(module.type);
280
+
281
+ if (validResponse && module.headers.get('Content-Type') !== 'application/wasm') {
282
+ 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);
283
+
284
+ } else { throw e; }
285
+ }
286
+ }
287
+
288
+ const bytes = await module.arrayBuffer();
289
+ return await WebAssembly.instantiate(bytes, imports);
290
+ } else {
291
+ const instance = await WebAssembly.instantiate(module, imports);
292
+
293
+ if (instance instanceof WebAssembly.Instance) {
294
+ return { instance, module };
295
+ } else {
296
+ return instance;
297
+ }
298
+ }
299
+
300
+ function expectedResponseType(type) {
301
+ switch (type) {
302
+ case 'basic': case 'cors': case 'default': return true;
303
+ }
304
+ return false;
305
+ }
306
+ }
307
+
308
+ function initSync(module) {
309
+ if (wasm !== undefined) return wasm;
310
+
311
+
312
+ if (module !== undefined) {
313
+ if (Object.getPrototypeOf(module) === Object.prototype) {
314
+ ({module} = module)
315
+ } else {
316
+ console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
317
+ }
318
+ }
319
+
320
+ const imports = __wbg_get_imports();
321
+ if (!(module instanceof WebAssembly.Module)) {
322
+ module = new WebAssembly.Module(module);
323
+ }
324
+ const instance = new WebAssembly.Instance(module, imports);
325
+ return __wbg_finalize_init(instance, module);
326
+ }
327
+
328
+ async function __wbg_init(module_or_path) {
329
+ if (wasm !== undefined) return wasm;
330
+
331
+
332
+ if (module_or_path !== undefined) {
333
+ if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
334
+ ({module_or_path} = module_or_path)
335
+ } else {
336
+ console.warn('using deprecated parameters for the initialization function; pass a single object instead')
337
+ }
338
+ }
339
+
340
+ if (module_or_path === undefined) {
341
+ module_or_path = new URL('inkvec_wasm_bg.wasm', import.meta.url);
342
+ }
343
+ const imports = __wbg_get_imports();
344
+
345
+ if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
346
+ module_or_path = fetch(module_or_path);
347
+ }
348
+
349
+ const { instance, module } = await __wbg_load(await module_or_path, imports);
350
+
351
+ return __wbg_finalize_init(instance, module);
352
+ }
353
+
354
+ export { initSync, __wbg_init as default };
pkg/inkvec_wasm_bg.wasm ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:425ae1e38b51989f15955507d7060dd8e6ed9b4f9939d59fb0fe0864281897ed
3
+ size 2648007
pkg/inkvec_wasm_bg.wasm.d.ts ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /* tslint:disable */
2
+ /* eslint-disable */
3
+ export const memory: WebAssembly.Memory;
4
+ export const threads_available: () => number;
5
+ export const trace: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number, i: number, j: number, k: number, l: number) => [number, number, number, number];
6
+ export const version: () => [number, number];
7
+ export const __wbindgen_free: (a: number, b: number, c: number) => void;
8
+ export const __wbindgen_malloc: (a: number, b: number) => number;
9
+ export const __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
10
+ export const __externref_table_alloc: () => number;
11
+ export const __wbindgen_externrefs: WebAssembly.Table;
12
+ export const __externref_table_dealloc: (a: number) => void;
13
+ export const __wbindgen_start: () => void;
pkg/package.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "name": "inkvec-wasm",
3
+ "type": "module",
4
+ "collaborators": [
5
+ "LogoLabs"
6
+ ],
7
+ "description": "Inkvec in the browser: the tracer compiled to WebAssembly",
8
+ "version": "0.1.0",
9
+ "license": "Apache-2.0",
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "https://github.com/logolabs/inkvec"
13
+ },
14
+ "files": [
15
+ "inkvec_wasm_bg.wasm",
16
+ "inkvec_wasm.js",
17
+ "inkvec_wasm.d.ts"
18
+ ],
19
+ "main": "inkvec_wasm.js",
20
+ "homepage": "https://github.com/logolabs/inkvec",
21
+ "types": "inkvec_wasm.d.ts",
22
+ "sideEffects": [
23
+ "./snippets/*"
24
+ ]
25
+ }
samples/1075thefan.png ADDED
samples/365retailmarkets.png ADDED
samples/adamo.png ADDED
samples/tiny.png ADDED
worker.js ADDED
@@ -0,0 +1,71 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ // The trace runs here so the page stays responsive: a 768-px logo is seconds of work and
2
+ // on the main thread that would freeze the controls.
3
+ //
4
+ // Two builds of the same tracer sit beside each other, and which one loads is decided by
5
+ // whether the browser will give us threads. `pkg-threads/` is compiled with the wasm
6
+ // atomics feature and starts a rayon pool; the pipeline is already parallel — one
7
+ // independent dynamic program per boundary, which is 81% of the single-threaded time — so
8
+ // it needs no other change to use it. That build only runs on a cross-origin isolated page,
9
+ // because the pool is a `SharedArrayBuffer`. The Space asks for isolation with
10
+ // `custom_headers` in its README; anywhere that does not grant it, `pkg/` loads instead and
11
+ // behaves exactly as it always has. Same source, same f64, same output, one core.
12
+ //
13
+ // The `?v=` token is on every URL deliberately. The generated loader resolves the wasm
14
+ // against `import.meta.url` and URL resolution drops the base's query, so a token on the
15
+ // import alone busts the JavaScript and never the WebAssembly — the wrong way round, since
16
+ // the bindings rarely change and the wasm changes on every build. Bump it when `pkg/` or
17
+ // `pkg-threads/` is rebuilt.
18
+ const V = "v=7";
19
+
20
+ const isolated = typeof crossOriginIsolated !== "undefined" && crossOriginIsolated;
21
+
22
+ // One worker per core, less the one this thread is already using. `hardwareConcurrency`
23
+ // is what the browser is willing to admit to; on machines that report nothing, four is a
24
+ // safe guess that still pays.
25
+ const POOL = Math.max(1, Math.min(navigator.hardwareConcurrency || 4, 16) - 1);
26
+
27
+ async function load() {
28
+ const dir = isolated ? "./pkg-threads" : "./pkg";
29
+ stage = "import"; postMessage({ type: "stage", stage });
30
+ const mod = await import(`${dir}/inkvec_wasm.js?${V}`);
31
+ stage = "instantiate"; postMessage({ type: "stage", stage });
32
+ await mod.default({ module_or_path: new URL(`${dir}/inkvec_wasm_bg.wasm?${V}`, import.meta.url) });
33
+ stage = "pool"; postMessage({ type: "stage", stage });
34
+ let threads = 0;
35
+ if (isolated && mod.initThreadPool) {
36
+ // If the pool cannot start — nested workers refused, memory limits — say so and carry
37
+ // on. Rayon runs its work on the calling thread when it has no pool, so the trace is
38
+ // still correct, just no faster than the fallback would have been.
39
+ try {
40
+ await mod.initThreadPool(POOL);
41
+ threads = POOL;
42
+ stage = "ready";
43
+ } catch (e) {
44
+ poolError = String((e && e.stack) || e);
45
+ console.warn("inkvec: thread pool did not start, running on one core:", e);
46
+ }
47
+ }
48
+ return { mod, threads };
49
+ }
50
+
51
+ let poolError = null;
52
+ let stage = "start";
53
+
54
+ const ready = load().then(({ mod, threads }) => {
55
+ postMessage({ type: "ready", version: mod.version(), threads, poolError });
56
+ return mod;
57
+ });
58
+ ready.catch((e) => postMessage({ type: "loadfail", stage, error: String((e && e.stack) || e) }));
59
+
60
+ onmessage = async (e) => {
61
+ const mod = await ready;
62
+ const { id, bytes, o } = e.data;
63
+ const t0 = performance.now();
64
+ try {
65
+ const svg = mod.trace(bytes, o.precision, o.min_area, o.colors, o.merge, o.max_dim,
66
+ o.time_budget, o.no_background, o.minify, o.margin, o.content_units);
67
+ postMessage({ type: "done", id, svg, ms: performance.now() - t0 });
68
+ } catch (err) {
69
+ postMessage({ type: "error", id, error: String(err) });
70
+ }
71
+ };