How hungyuantu/goldilocks works
Goldilocks is a browser-side custom element that typesets English paragraph text with justified line breaks and hyphenation. A user places text in <goldi-break lang="en">; the element validates its input and dimensions, parses text into breakable nodes, measures candidate fragments, chooses line breaks, and replaces its content with marked-up text that permits browser wrapping. The graph also shows the optional debug dump. Relationships follow the sampled calls and README; unsampled measurement details are not inferred.
Main entry points: main.ts Custom element · defs.ts Breakable nodes · from.ts Text parser · wrap.ts Line breaker
Components 14
Browser runtime
- Package entry
src/init.ts - Custom element
src/main.ts - Rendered paragraph
Paragraph layout
- Text parser
src/nodes/from.ts - Breakable nodes
src/nodes/defs.ts - Text measurement
src/nodes/size.ts - Line breaker
src/nodes/wrap.ts - Knuth parameters
src/knuth/defs.ts - Break marking
src/nodes/mark.ts
English hyphenation
- Word hyphenation
src/utils/hyph.ts - English patterns
src/utils/trie.ts
Debugging
- Debug hook
src/debug/init.ts - Break dump
src/debug/dump.ts
Other components
- Page author
Connections 16
- Page author → Custom element: adds text
README.md - Package entry → Custom element: loads
src/init.ts - Package entry → Debug hook: loads
src/init.ts - Custom element → Text parser: parses text
src/main.ts - Custom element → Text measurement: measures nodes
src/main.ts - Custom element → Line breaker: chooses breaks
src/main.ts - Custom element → Break marking: marks breaks
src/main.ts - Custom element → Rendered paragraph: updates content
src/main.ts - Text parser → Breakable nodes: builds nodes
src/nodes/from.ts - Text parser → Word hyphenation: gets breakpoints
src/nodes/from.ts - Line breaker → Breakable nodes: uses nodes
src/nodes/wrap.ts - Line breaker → Knuth parameters: scores candidates
src/nodes/wrap.ts - Break marking → Breakable nodes: clips text
src/nodes/mark.ts - Word hyphenation → English patterns: looks up patterns
src/utils/hyph.ts - Debug hook → Break dump: dumps breaks
src/debug/init.ts - Break dump → Breakable nodes: formats break data
src/debug/dump.ts