TesseractJs.Component (tesseract_js v0.1.0)

Copy Markdown View Source

HEEx components that wire tesseract_js into a Phoenix layout.

Drop these into root.html.heex:

<TesseractJs.Component.preload />
<TesseractJs.Component.script />

preload/1 hints the browser to start fetching tesseract.min.js and the WASM core early. script/1 emits the <script> tags that load the upstream tesseract.js, the wrapper bundle, and a small inline config block at window.__tesseractJs.

Both components read :tesseract_js Application config and accept inline overrides via attributes for per-page customization.

Summary

Functions

Renders <link rel="preload"> hints for the OCR assets.

Emits the <script> tags that load tesseract.js + the wrapper, and an inline config block at window.__tesseractJs that the wrapper reads at boot.

Functions

preload(assigns)

Renders <link rel="preload"> hints for the OCR assets.

When preload_core: true (the default), also preloads the WASM core. Disable this on pages where OCR is optional/lazy to avoid wasted bandwidth.

Attributes

  • base_path (:string) - Defaults to nil.
  • preload_core (:boolean) - Defaults to true.

script(assigns)

Emits the <script> tags that load tesseract.js + the wrapper, and an inline config block at window.__tesseractJs that the wrapper reads at boot.

All attrs are optional — defaults come from config :tesseract_js, ....

Attributes

  • base_path (:string) - Defaults to nil.
  • lang (:string) - Defaults to nil.
  • source (:atom) - Defaults to nil.Must be one of nil, :cdn, or :local.
  • tessdata_repo (:atom) - Defaults to nil.Must be one of nil, :standard, or :best.
  • core_variant (:atom) - Defaults to nil.Must be one of nil, :simd_lstm, :simd, or :basic.
  • defer (:boolean) - Defaults to true.