# Library: @cp949/web-image-util

## Overview
- Browser image processing library built on Canvas 2D API.
- Main workflow is async image processing through a chain returned by `processImage(...)`.
- Provides preset helpers and SVG/conversion utilities for browser-safe image workflows.

## Key APIs
- `processImage(source: ImageSource, options?: ProcessorOptions): InitialProcessor`
- `type ResizeConfig = CoverConfig | ContainConfig | FillConfig | MaxFitConfig | MinFitConfig`
- `createThumbnail(source: ImageSource, options: ThumbnailOptions): Promise<ResultBlob>`
- `createAvatar(source: ImageSource, options?: AvatarOptions): Promise<ResultBlob>`
- `createSocialImage(source: ImageSource, options: SocialImageOptions): Promise<ResultBlob>`
- `convertToBlob(source: ImageSource | HTMLCanvasElement, options?: ConvertToBlobOptions): Promise<Blob>`
- `detectBrowserCapabilities(options?: DetectionOptions): Promise<BrowserCapabilities>`
- `enhanceSvgForBrowser(svgString: string): string`
- `sanitizeSvg(svgString: string): string`

## Usage Patterns
- Use `processImage(...)` for resize and output generation.
- The processing chain is lazy until an output method such as `toBlob()`, `toCanvas()`, `toDataURL()`, or `toFile()` is called.
- The main processing flow is async.
- Preset helpers return `Promise<ResultBlob>` directly.
- Utility functions are better when only conversion or SVG sanitizing is needed.

## Examples
- `const blob = await processImage(file).resize({ fit: 'cover', width: 300, height: 200 }).toBlob({ format: 'webp', quality: 0.85 });`
- `const avatar = await createAvatar(file, { size: 128, format: 'png' });`
- `const safeSvg = sanitizeSvg(svgString);`
- `const blob = await convertToBlob(canvas);`

## Constraints
- Only use exported public APIs from the package root or exported subpaths.
- `resize()` should be used as a single resize step in one processing chain.
- `maxFit` and `minFit` require at least one of `width` or `height`.
- SVG safety-sensitive input should be sanitized before use when the source is untrusted.
- This library targets browser environments with Canvas 2D API support.

## Anti-Patterns
- Do not invent unsupported chain methods such as `crop()`, `rotate()`, or `sharpen()`.
- Do not call `resize()` multiple times in the same chain.
- Do not rely on internal `dist/chunk-*` files or non-exported symbols.
- Do not describe this package as a Node.js image pipeline.

## Notes
- `createAvatar()` defaults to PNG-oriented avatar output.
- `createSocialImage()` applies platform-oriented sizing rules through `SocialImageOptions`.
- `sanitizeSvg()` removes dangerous SVG content, it does not rasterize the image by itself.
