diff --git a/package.json b/package.json index c2f42e22..6fc9edce 100644 --- a/package.json +++ b/package.json @@ -75,8 +75,8 @@ "probe-check:safari": "PROBE_CHECK_BROWSER=safari bun run scripts/probe-check.ts", "status-dashboard": "bun run scripts/status-dashboard.ts", "site:build": "rm -rf site && bun run scripts/build-demo-site.ts", - "start": "HOST=${HOST:-0.0.0.0}; PORT=3000; pids=$(lsof -tiTCP:$PORT -sTCP:LISTEN 2>/dev/null); if [ -n \"$pids\" ]; then echo \"Freeing port $PORT: terminating $pids\"; kill $pids 2>/dev/null || true; sleep 1; pids=$(lsof -tiTCP:$PORT -sTCP:LISTEN 2>/dev/null); if [ -n \"$pids\" ]; then echo \"Port $PORT still busy: killing $pids\"; kill -9 $pids 2>/dev/null || true; fi; fi; bun pages/*.html pages/demos/*.html pages/demos/*/index.html --host=$HOST:$PORT", - "start:windows": "bun pages/*.html pages/demos/*.html pages/demos/*/index.html --host=0.0.0.0:3000" + "start": "HOST=${HOST:-0.0.0.0}; PORT=3002; pids=$(lsof -tiTCP:$PORT -sTCP:LISTEN 2>/dev/null); if [ -n \"$pids\" ]; then echo \"Freeing port $PORT: terminating $pids\"; kill $pids 2>/dev/null || true; sleep 1; pids=$(lsof -tiTCP:$PORT -sTCP:LISTEN 2>/dev/null); if [ -n \"$pids\" ]; then echo \"Port $PORT still busy: killing $pids\"; kill -9 $pids 2>/dev/null || true; fi; fi; bun pages/*.html pages/demos/*.html pages/demos/*/index.html --host=$HOST:$PORT", + "start:windows": "bun pages/*.html pages/demos/*.html pages/demos/*/index.html --host=0.0.0.0 --port=3002" }, "devDependencies": { "@types/bun": "latest", diff --git a/pages/demos/index.html b/pages/demos/index.html index c03d4a80..9fdeee6e 100644 --- a/pages/demos/index.html +++ b/pages/demos/index.html @@ -141,6 +141,11 @@
A text-card occlusion demo where height prediction comes from Pretext instead of DOM reads.
+ + +Full Knuth-Plass with badness, penalties, fitness classification, and river detection.
+ + + ++ A full Knuth-Plass implementation showing dynamic programming for optimal line breaks, + badness calculation, fitness classification, and typography river detection. +
+ ++ The Knuth-Plass algorithm finds the optimal line breaks by treating text layout as a + dynamic programming problem. It evaluates all possible break points and chooses the + sequence that minimizes total "badness" — a measure of how far each line deviates + from the ideal inter-word spacing. +
+
+ Badness formula: (slack / lineWidth)³ × 1000 — cubic
+ penalty that heavily disfavors very tight or very loose lines.
+
+ Penalties: River gaps (+5000 when spaces align vertically), + tight lines (+3000), and hyphenation (+50) all increase badness. +
++ Fitness classification: Lines are categorized as tight (≤65% stretch), + decent, loose (100-150%), or very loose (>150%, indicating potential rivers). +
+diff --git a/pages/demos/optimal-line-breaking.html b/pages/demos/optimal-line-breaking.html new file mode 100644 index 00000000..96756084 --- /dev/null +++ b/pages/demos/optimal-line-breaking.html @@ -0,0 +1,217 @@ + + +
+ + + +
+ + +
+