@blazediff/ui
Framework-agnostic Web Components for building image comparison interfaces. Works with any JavaScript framework or vanilla HTML.
Installation
npm install @blazediff/ui
Features
- Framework agnostic: Works with React, Vue, Angular, Svelte, or Vanilla JS
- Web Components: Standard-based custom elements
- Multiple modes: Swipe, two-up, onion skin, and difference visualization
- Customizable: Full styling control via CSS classes
- Accessible: Keyboard navigation and proper event handling
- Lightweight: Zero dependencies (except @blazediff/core)
Quick Start
HTML
<!DOCTYPE html>
<html>
<head>
<script type="module">
import "@blazediff/ui";
</script>
</head>
<body>
<blazediff-swipe
src1="image1.jpg"
src2="image2.jpg"
alt1="Original"
alt2="Modified"
>
</blazediff-swipe>
</body>
</html>
JavaScript
import "@blazediff/ui";
// The components are now available globally
document.body.innerHTML = `
<blazediff-swipe
src1="./before.jpg"
src2="./after.jpg">
</blazediff-swipe>
`;
API Reference
<blazediff-swipe>
Interactive swipe component for comparing two images with a draggable divider.
Attributes
Attribute | Type | Default | Description |
---|---|---|---|
src1 | string | - | URL of the first image |
src2 | string | - | URL of the second image |
alt1 | string | "Before" | Alt text for the first image |
alt2 | string | "After" | Alt text for the second image |
class-container | string | - | CSS class for the container |
class-image1 | string | - | CSS class for the first image |
class-image2 | string | - | CSS class for the second image |
class-divider | string | - | CSS class for the divider |
Events
Event | Detail | Description |
---|---|---|
position-change | { position: number } | Fired when divider position changes (0-100) |
<blazediff-twoup>
Side-by-side comparison component with dimension information.
Attributes
Attribute | Type | Default | Description |
---|---|---|---|
src1 | string | - | URL of the first image |
src2 | string | - | URL of the second image |
class-container | string | - | CSS class for the main container |
class-container-inner | string | - | CSS class for the inner container |
class-panel | string | - | CSS class for each panel |
class-image | string | - | CSS class for images |
class-dimension-info | string | - | CSS class for dimension info text |
Events
Event | Detail | Description |
---|---|---|
images-loaded | { image1: {width, height}, image2: {width, height} } | Fired when both images load |
load-error | { error } | Fired when image loading fails |
<blazediff-onionskin>
Overlay comparison with opacity control slider.
Attributes
Attribute | Type | Default | Description |
---|---|---|---|
src1 | string | - | URL of the base image |
src2 | string | - | URL of the overlay image |
opacity | number | 50 | Initial opacity (0-100) |
class-container | string | - | CSS class for the main container |
class-image-container | string | - | CSS class for image container |
class-image | string | - | CSS class for images |
class-slider-container | string | - | CSS class for slider container |
class-slider | string | - | CSS class for the slider |
class-slider-label | string | - | CSS class for slider label |
text-slider-label | string | "Opacity:" | Text for the slider label |
Events
Event | Detail | Description |
---|---|---|
opacity-change | { opacity: number } | Fired when opacity changes |
images-loaded | { image1: {width, height}, image2: {width, height} } | Fired when both images load |
load-error | { error } | Fired when image loading fails |
<blazediff-difference>
Shows pixel differences using the BlazeDiff comparison algorithm.
Attributes
Attribute | Type | Default | Description |
---|---|---|---|
src1 | string | - | URL of the first image |
src2 | string | - | URL of the second image |
threshold | number | 0.1 | Difference threshold (0-1) |
include-aa | boolean | false | Include anti-aliased pixels |
alpha | number | 0.1 | Opacity of original image |
class-container | string | - | CSS class for the container |
class-canvas | string | - | CSS class for the canvas |
Events
Event | Detail | Description |
---|---|---|
diff-complete | { diffCount: number, totalPixels: number, percentage: number } | Fired when comparison completes |
diff-error | { error } | Fired when comparison fails |
Links
Last updated on