Cropper

A movable, resizable crop region with image gestures and canvas export.

Props

All optional props without a default remain undefined. class accepts Svelte ClassValue; style is a CSS string.

PropTypeDefault
settingsE & { [K in keyof CropperSettingProps]?: never }undefined
srcstring | nullundefined
canvasbooleantrue
checkOrientationbooleantrue
crossOriginboolean | 'anonymous' | 'use-credentials'true (anonymous)
unloadTimenumber500 ms
autoReconcileStatebooleantrue
disabledbooleanfalse
classClassValueundefined
stylestringundefined
childrenSnippetDefault RectangleStencil
moveImageboolean | MoveImageOptionstrue
scaleImageboolean | ScaleImageOptionstrue
rotateImageboolean | RotateImageOptionsfalse
stencilConstraintsStencilConstraints<E>defaultStencilConstraints
wrapperSnippet<[CropperWrapperSnippetProps<E>]>CropperWrapper
boundarySnippet<[CropperBoundarySnippetProps<E>]>StretchableBoundary
backgroundWrapperSnippet<[CropperBackgroundWrapperSnippetProps<E>]>CropperBackgroundWrapper
backgroundSnippet<[CropperBackgroundSnippetProps<E>]>CropperBackgroundImage

Built-in settings are flat props. settings accepts only extension fields and excludes every built-in setting key.

Built-in settings

The indexed types below are the exact public setting types, including value-or-function alternatives. Settings and defaults expands their behavior.

PropTypeDefault
transformImageCropperSettingsInput<E>['transformImage']{ adjustStencil: true }
moveCoordinatesCropperSettingsInput<E>['moveCoordinates']undefined; no modifier override
resizeCoordinatesCropperSettingsInput<E>['resizeCoordinates']undefined; no modifier override
defaultCoordinatesCropperSettingsInput<E>['defaultCoordinates']Computed from defaultSize, then defaultPosition
defaultVisibleAreaCropperSettingsInput<E>['defaultVisibleArea']Core defaultVisibleArea function
areaPositionRestrictionsCropperSettingsInput<E>['areaPositionRestrictions']Core defaultAreaPositionRestrictions function
areaSizeRestrictionsCropperSettingsInput<E>['areaSizeRestrictions']Core defaultAreaSizeRestrictions function
sizeRestrictionsCropperSettingsInput<E>['sizeRestrictions']Core pixelsRestrictions function
positionRestrictionsCropperSettingsInput<E>['positionRestrictions']Core defaultPositionRestrictions function
aspectRatioCropperSettingsInput<E>['aspectRatio']Stencil ratio, otherwise unrestricted (0 to Infinity)
minWidthCropperSettingsInput<E>['minWidth']undefined; effective minimum 0
minHeightCropperSettingsInput<E>['minHeight']undefined; effective minimum 0
maxWidthCropperSettingsInput<E>['maxWidth']undefined; effective maximum Infinity
maxHeightCropperSettingsInput<E>['maxHeight']undefined; effective maximum Infinity
defaultSizeCropperSettingsInput<E>['defaultSize']Core defaultSize function
defaultPositionCropperSettingsInput<E>['defaultPosition']Core defaultPosition function
defaultTransformsCropperSettingsInput<E>['defaultTransforms']undefined; image transforms on initialization
imageRestrictionCropperSettingsInput<E>['imageRestriction']ImageRestriction.fitArea
priorityCropperSettingsInput<E>['priority']undefined; core Priority.coordinates

Algorithms and transitions

PropTypeDefault
transitionsCropperTransitionsSettings | booleantrue; duration 350, timing ease-in-out
postProcessPostprocessFunction<CropperSettings<E>> | PostprocessFunction<CropperSettings<E>>[]None
setCoordinatesAlgorithmSetCoordinatesAlgorithm<CropperSettings<E>>undefined
setVisibleAreaAlgorithmSetVisibleAreaAlgorithm<CropperSettings<E>>undefined
setBoundaryAlgorithmSetBoundaryAlgorithm<CropperSettings<E>>undefined
transformImageAlgorithmTransformImageAlgorithm<CropperSettings<E>>undefined
moveCoordinatesAlgorithmMoveAlgorithm<CropperSettings<E>>undefined
resizeCoordinatesAlgorithmResizeAlgorithm<CropperSettings<E>>undefined
createStateAlgorithmCreateStateAlgorithm<CropperSettings<E>>undefined
reconcileStateAlgorithmReconcileStateAlgorithm<CropperSettings<E>>undefined

The eight algorithm props default to the corresponding core state modifier (setCoordinates, setVisibleArea, setBoundary, transformImage, moveCoordinates, resizeCoordinates, createState, reconcileState). postProcess runs configured functions after state operations.

Callbacks

Every callback is optional, defaults to undefined, and has type CropperCallback<E> = (cropper: CropperInstance<E>) => void.

CallbackNotification
onReadyCurrent image, rendered initialized state and enabled export source are ready.
onErrorImage loading failed.
onChangeCrop geometry changes.
onUpdateState, interactions, transitions or loading observations change.
onMove, onMoveEndStencil movement and completion.
onResize, onResizeEndStencil resize and completion.
onTransformImage, onTransformImageEndImage transformation and completion.
onInteractionStart, onInteractionEndOverall interaction lifetime.
onTransitionsStart, onTransitionsEndTransition lifetime.

Callbacks run untracked while mounted. onReady is coalesced per displayed image; it is not emitted again for every reset. Clearing src clears pending loading, and stale asynchronous loads cannot commit after replacement or destruction.

Snippets and context

The four layer signatures appear in the props table and snippet contracts. children?: Snippet selects stencil children; omitting it creates one rectangle stencil. Supplying empty children creates no stencil. This component provides isolated CropperContext and requires no ancestor context.

Instance and styling

bind:this exposes all 33 CropperInstance methods. Getters remain reactive; disabled prevents user gestures, not programmatic actions. getCanvas() returns null with export disabled.

The root is .advanced-cropper, with --disabled, __boundary, __background-wrapper and __background selectors. See the complete styling contract.

Loading and gesture options

src may be an image URL, data URL or application-owned object URL; null or an empty string clears it. checkOrientation reads EXIF orientation. crossOrigin={true} requests anonymous CORS, false omits the attribute, and the string values select their corresponding modes. unloadTime gives the previous image time to fade out before replacement. canvas enables the internal export canvas.

moveImage accepts { mouse?: boolean; touch?: boolean }; scaleImage accepts { touch?: boolean; wheel?: boolean | { ratio?: number } }; rotateImage accepts { touch?: boolean }. A boolean enables or disables all gestures in that group. Omitted object fields are enabled; wheel ratio defaults to 0.1. Rotation is disabled by the cropper default. transformImage.adjustStencil controls geometry during scaling, separately from input options.