← All Components
<mth-image-cropper>
Accessible image cropper with zoom/pan controls, keyboard arrow nudging, safe <img> SVG rendering, and canvas crop export.
When NOT to use: Use a lightweight @methane-ui/css layout class instead of a custom element when static CSS suffices.
Live Interactive Preview
Ready · interact with <mth-image-cropper>, or toggle Theme, Direction (LTR/RTL), or props above.
Multi-Framework Playground & Snippets
<script type="module" src="@methane-ui/ui/image-cropper"></script>
<mth-image-cropper aspect-ratio="1" zoom="1"></mth-image-cropper>import '@methane-ui/ui/image-cropper';
import '@methane-ui/react';
export function Example() {
return <mth-image-cropper aspect-ratio="1" zoom="1"></mth-image-cropper>;
}<script setup lang="ts">
import '@methane-ui/ui/image-cropper';
</script>
<template>
<mth-image-cropper aspect-ratio="1" zoom="1"></mth-image-cropper>
</template>import { Component, CUSTOM_ELEMENTS_SCHEMA } from '@angular/core';
import '@methane-ui/ui/image-cropper';
import { MthImageCropperDirective } from '@methane-ui/angular';
@Component({
standalone: true,
schemas: [CUSTOM_ELEMENTS_SCHEMA],
imports: [MthImageCropperDirective],
template: `<mth-image-cropper aspect-ratio="1" zoom="1"></mth-image-cropper>`,
})
export class ExampleComponent {}<script lang="ts">
import '@methane-ui/ui/image-cropper';
import MthImageCropper from '@methane-ui/svelte/MthImageCropper.svelte';
</script>
<MthImageCropper aspect-ratio="1" zoom="1"></MthImageCropper>Properties & Attributes
| Property | Attribute | Type | Default | Description |
|---|---|---|---|---|
src | src | string | "" | Safe image URL (https, http, blob, relative path, or safe raster/svg data URI) rendered only via <img>. |
alt | alt | string | "" | Accessible alternative text for the source image. |
aspectRatio | aspect-ratio | number | 1 | Target crop aspect ratio (width / height, 0 for free). |
zoom | zoom | number | 1 | Zoom scale factor between 1 and 3. |
offsetX | offset-x | number | 0 | Horizontal pan offset percentage (-50 to 50). |
offsetY | offset-y | number | 0 | Vertical pan offset percentage (-50 to 50). |
disabled | disabled | boolean | false | Disables cropper controls. |
Events
| Event | Detail Type | Description |
|---|---|---|
mth-change | { zoom: number; offsetX: number; offsetY: number } | Fired when zoom or pan offset changes. |
mth-crop | { zoom: number; offsetX: number; offsetY: number; aspectRatio: number; dataUrl: string } | Fired when crop() completes. |
APG Keyboard Matrix
| Key | Direction | When | Expected Behavior |
|---|---|---|---|
| ArrowLeft | both | Crop viewport is focused | Nudges image offset horizontally to the left |
| ArrowRight | both | Crop viewport is focused | Nudges image offset horizontally to the right |
| ArrowUp | both | Crop viewport is focused | Nudges image offset vertically up |
| ArrowDown | both | Crop viewport is focused | Nudges image offset vertically down |
Accessibility Checklist
| Category | Requirement | Verified By |
|---|---|---|
| aria | All aria-* IDREFs resolve within the same DOM root (ADR-003). | scanSameRootAria |
| focus | delegatesFocus: true with zero host internals.role (ADR-014). | lint-plugin & spec-compiler |
| contrast | Renders legible borders, focus outlines, and selection indicators under forced-colors: active. | Playwright forced-colors matrix |
| keyboard | Implements all 4 APG keyboard transitions across LTR/RTL. | mth-image-cropper.spec.test.ts |
| states | Exposes ElementInternals CustomStateSet flags: :state(disabled). | Conformance suite |
| i18n | Routes 6 UI/ARIA strings through @methane-ui/core i18n catalog. | Locale context test |