Skip to main content
The core factory function that creates a new engine instance. This is what every framework adapter wraps internally, and what you use directly for vanilla JS or unsupported frameworks.

Returns

LogoSoupEngine — an object with the following methods:

engine.process(options)

Triggers a processing run. Loads images, measures them, and produces normalized dimensions. Cancels any in-flight work from a previous process() call.
ProcessOptions
required
The processing options. See Options Reference for full details.
Behavior:
  • If logos is empty, transitions directly to "ready" with an empty array (synchronous).
  • If all logos are already cached, re-normalizes from cache (synchronous, no network requests).
  • Otherwise, transitions to "loading", fetches images, measures them, and transitions to "ready" or "error".
  • Calling process() again while loading cancels the previous run. Only the latest call’s results are emitted.

engine.subscribe(listener)

Subscribes to state changes. Returns an unsubscribe function.
() => void
required
A callback invoked whenever the engine’s state changes. The listener receives no arguments — call getSnapshot() inside it to read the current state.
Returns: () => void — call this to unsubscribe.
The subscribe(callback) → unsubscribe shape is designed to plug directly into framework reactivity primitives: React’s useSyncExternalStore, Vue’s shallowRef, Svelte’s createSubscriber, Solid’s from(), and Angular’s signal().

engine.getSnapshot()

Returns the current immutable state snapshot. Returns: LogoSoupState
getSnapshot() must return the same reference (===) when state hasn’t changed. This is a hard requirement for React’s useSyncExternalStore — if it returns a new object each time, React enters an infinite re-render loop. The engine handles this internally.

engine.destroy()

Cleans up the engine: revokes blob URLs created by cropToContent, cancels in-flight image loading, clears the measurement cache, and removes all subscribers.
Always call destroy() when you’re done with the engine. Framework adapters handle this automatically on component unmount / scope disposal. After calling destroy(), the engine ignores subsequent process() calls.

Types

LogoSoupEngine

LogoSoupState

If some images fail but others succeed, the engine transitions to "ready" with the successful logos. "error" only occurs when every image fails.

ProcessOptions

See Options Reference for detailed descriptions of each field.
See Options Reference for field descriptions.

Caching Behavior

The engine caches image measurements by URL. This means:
  • Changing baseSize or scaleFactor re-normalizes from cache (synchronous, no network).
  • Changing contrastThreshold, densityAware, or backgroundColor invalidates the cache because these affect the measurement itself.
  • Adding new logos only loads the new ones; previously cached logos are reused.
  • Removing logos prunes their cache entries and revokes any associated blob URLs.

Example: Full Lifecycle