Methane@methane-ui/*
CSS LayoutsComponentsSkillsTheme BuilderGitHub
← All Components

<mth-image-cropper>

@methane-ui/ui~6.8 KB brotli (cold + Lit)~1.4 KB marginal

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

Interactive StageLive Custom Element · <mth-image-cropper> (@methane-ui/ui)
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>

Properties & Attributes

PropertyAttributeTypeDefaultDescription
srcsrcstring""Safe image URL (https, http, blob, relative path, or safe raster/svg data URI) rendered only via <img>.
altaltstring""Accessible alternative text for the source image.
aspectRatioaspect-rationumber1Target crop aspect ratio (width / height, 0 for free).
zoomzoomnumber1Zoom scale factor between 1 and 3.
offsetXoffset-xnumber0Horizontal pan offset percentage (-50 to 50).
offsetYoffset-ynumber0Vertical pan offset percentage (-50 to 50).
disableddisabledbooleanfalseDisables cropper controls.

Events

EventDetail TypeDescription
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

KeyDirectionWhenExpected Behavior
ArrowLeftbothCrop viewport is focusedNudges image offset horizontally to the left
ArrowRightbothCrop viewport is focusedNudges image offset horizontally to the right
ArrowUpbothCrop viewport is focusedNudges image offset vertically up
ArrowDownbothCrop viewport is focusedNudges image offset vertically down

Accessibility Checklist

CategoryRequirementVerified By
ariaAll aria-* IDREFs resolve within the same DOM root (ADR-003).scanSameRootAria
focusdelegatesFocus: true with zero host internals.role (ADR-014).lint-plugin & spec-compiler
contrastRenders legible borders, focus outlines, and selection indicators under forced-colors: active.Playwright forced-colors matrix
keyboardImplements all 4 APG keyboard transitions across LTR/RTL.mth-image-cropper.spec.test.ts
statesExposes ElementInternals CustomStateSet flags: :state(disabled).Conformance suite
i18nRoutes 6 UI/ARIA strings through @methane-ui/core i18n catalog.Locale context test