生态产品多个设计器现已发布候选版本

查看生态总览
Skip to content

ImageCropper ​

Data entry component. This page is the API reference, generated from the source code. Usage guidance and live examples are on the Chinese page.

Anatomy ​

Parts in bold are required.

data-scope="image-cropper": root · viewport · image · crop-area · crop-handle · grid · zoom-slider · rotate-slider · flip-trigger · hidden-input

API reference ​

Descriptions of individual props, events and slots are written in Chinese and appear on the Chinese page.

Artifacts ​

LayerValue
Custom element<xh-image-cropper>
Vue componentsXhImageCropperCropArea XhImageCropperCropHandle XhImageCropperFlipTrigger XhImageCropperGrid XhImageCropperHiddenInput XhImageCropperImage XhImageCropperRoot XhImageCropperRotateSlider XhImageCropperViewport XhImageCropperZoomSlider
ComposableuseImageCropper
State machineimageCropperMachine
Skin@xihan-ui/styles/image-cropper.css

Props ​

PropTypeRequired
srcstring
altstring
aspectRationumber | null
valueImageCropperRect
defaultValueImageCropperRect
minWidthnumber
minHeightnumber
zoomnumber
defaultZoomnumber
minZoomnumber
maxZoomnumber
zoomStepnumber
rotationnumber
defaultRotationnumber
minRotationnumber
maxRotationnumber
rotationStepnumber
flipImageCropperFlip
defaultFlipImageCropperFlip
shapeImageCropperShape
ariaLabelstring
disabledboolean
readOnlyboolean
namestring
translationsPartial<ImageCropperTranslations>
onValueChange(details: ImageCropperValueChangeDetails) => void
onValueChangeEnd(details: ImageCropperValueChangeEndDetails) => void
onZoomChange(details: ImageCropperZoomChangeDetails) => void
onRotationChange(details: ImageCropperRotationChangeDetails) => void
onFlipChange(details: ImageCropperFlipChangeDetails) => void

Events ​

Custom elements put the payload in detail; Vue emits an event of the same name.

EventPayload
value-changeImageCropperValueChangeDetails
value-change-endImageCropperValueChangeEndDetails
zoom-changeImageCropperZoomChangeDetails
rotation-changeImageCropperRotationChangeDetails
flip-changeImageCropperFlipChangeDetails

Slots ​

Only slots with a payload are listed.

Vue componentSlotPayload
XhImageCropperRootdefaultImageCropperRootSlotProps

React adapter props ​

Only the props each component declares itself: DOM attributes inherited from ComponentPropsWithRef are left out, and root props already listed in the Props table are not repeated. The Vue counterpart is the slot table above.

React componentPropTypeRequired
XhImageCropperCropHandlepositionImageCropperHandlePositionYes
XhImageCropperFlipTriggeraxisImageCropperFlipAxisYes
XhImageCropperRootchildrenSlotChildren<ImageCropperRootSlotProps>

State ​

Public state is written to data-state.

PartValues
flip-trigger'on' | 'off'

The following names are internal to the state machine.

States: dragging · idle · resizing

Events: VALUE.SET · ZOOM.SET · ROTATE.SET · FLIP.SET · FLIP.TOGGLE · IMAGE.LOAD · CROP.NUDGE · HANDLE.NUDGE · DRAG.START · RESIZE.START · DRAG.MOVE · DRAG.END · FORM.RESET · PRESS.START · PRESS.END

Guards: canEdit · canPress

connect API ​

getXxxProps() returns the host attributes of the matching part.

MemberType
valueImageCropperRect
zoomnumber
rotationnumber
flipImageCropperFlip
naturalImageCropperSize
draggingboolean
resizingboolean
disabledboolean
readOnlyboolean
getCropRect() => ImageCropperRect
toCanvas(options?: CropToCanvasOptions) => HTMLCanvasElement | null
setValue(next: ImageCropperRect) => void
setZoom(next: number) => void
setRotation(next: number) => void
setFlip(next: ImageCropperFlip) => void
toggleFlip(axis: ImageCropperFlipAxis) => void
getRootProps() => T['element']
getViewportProps() => T['element']
getImageProps() => T['img']
getCropAreaProps() => T['element']
getCropHandleProps(props: ImageCropperHandleProps) => T['button']
getGridProps() => T['element']
getZoomSliderProps() => T['input']
getRotateSliderProps() => T['input']
getFlipTriggerProps(props: ImageCropperFlipTriggerProps) => T['button']
getHiddenInputProps() => T['input']

Accessibility ​

Keyboard ​

Specification: W3C APG. Each row is a stable behavior id that the conformance tests cover; the conditions and effects are described on the Chinese page.

KeysBehavior
ArrowLeft / ArrowRight / ArrowUp / ArrowDownimage-cropper.kbd.move
Shift+ArrowLeft / Shift+ArrowRight / Shift+ArrowUp / Shift+ArrowDownimage-cropper.kbd.move-large
ArrowLeft / ArrowRight / ArrowUp / ArrowDownimage-cropper.kbd.resize
Shift+ArrowLeft / Shift+ArrowRight / Shift+ArrowUp / Shift+ArrowDownimage-cropper.kbd.resize-large
Enter / Spaceimage-cropper.kbd.flip
Enter / Spaceimage-cropper.kbd.flip-press
Tab / Shift+Tabimage-cropper.kbd.tab

ARIA ​

These attributes are produced by connect.

PartAttributeValue
crop-areaaria-disabled'true' | 'false'
crop-areaaria-labelprops.ariaLabel
crop-arearole'application'
crop-handlearia-disabled'true' | 'false'
crop-handlearia-labellabel.handle(position)
crop-handlearia-valuemaxString(HANDLE_AXIS[position] === 'width' ? natural.wi…
crop-handlearia-valueminString(HANDLE_AXIS[position] === 'width' ? minWidth :…
crop-handlearia-valuenowString(HANDLE_AXIS[position] === 'width' ? value.widt…
crop-handlearia-valuetextlabel.valueText({ ...value })
crop-handlerole'slider'
gridaria-hidden'true'
zoom-slideraria-labellabel.zoomSlider
rotate-slideraria-labellabel.rotateSlider
flip-triggeraria-labellabel.flip(axis)
flip-triggeraria-pressed'true' | 'false'

Style reference ​

Skin ​

@xihan-ui/styles/image-cropper.css is written against [data-scope="image-cropper"][data-part="root"] part selectors; the published build uses the mount class .xh-scope-image-cropper in place of data-scope (same specificity) and sits in the xihan.components layer. Put overrides in xihan.overrides; the part selectors work as usual.

Data attributes ​

Produced by connect; valueless attributes are omitted while their condition does not hold.

PartAttributeValue
rootdata-disabled'' (present only while the condition holds)
rootdata-dragging'' (present only while the condition holds)
rootdata-readonly'' (present only while the condition holds)
rootdata-resizing'' (present only while the condition holds)
rootdata-shapeprops.shape
viewportdata-disabled'' (present only while the condition holds)
viewportdata-dragging'' (present only while the condition holds)
viewportdata-readonly'' (present only while the condition holds)
viewportdata-resizing'' (present only while the condition holds)
crop-areadata-disabled'' (present only while the condition holds)
crop-areadata-dragging'' (present only while the condition holds)
crop-areadata-readonly'' (present only while the condition holds)
crop-areadata-resizing'' (present only while the condition holds)
crop-areadata-shapeprops.shape
crop-handledata-disabled'' (present only while the condition holds)
crop-handledata-positionposition
crop-handledata-readonly'' (present only while the condition holds)
crop-handledata-resizing'' (present only while the condition holds)
griddata-shapeprops.shape
zoom-sliderdata-disabled'' (present only while the condition holds)
rotate-sliderdata-disabled'' (present only while the condition holds)
flip-triggerdata-axisaxis
flip-triggerdata-disabled'' (present only while the condition holds)
flip-triggerdata-pressed'' (present only while the condition holds)
flip-triggerdata-state'on' | 'off'
flip-triggerdata-xh-action-control''
flip-triggerdata-xh-action-display'always'
flip-triggerdata-xh-action-profile'text'
flip-triggerdata-xh-action-size'sm'
flip-triggerdata-xh-action-variant'outline'

CSS variables ​

The public override slots, generated from what the standalone skin actually consumes.

VariablePartCSS propertyStateDefault from
--xh-image-cropper-bgviewportbackgrounddefault--xh-bg-muted
--xh-image-cropper-crop-area-radiuscrop-areaborder-radiusshape=round--xh-shape-circle
--xh-image-cropper-crop-bordercrop-areaborder-colordefault--xh-bg-surface
--xh-image-cropper-grid-linegridbackground-imagedefault--xh-bg-subtle-opaque
--xh-image-cropper-handle-bgcrop-handlebackground
border
default
is([data-position='nw'], [data-position='ne'], [data-position='sw'], [data-position='se'])
position=ne
position=nw
position=se
position=sw
--xh-bg-surface
--xh-image-cropper-handle-bg-hovercrop-handlebackground
border
disabled
hover
is([data-position='nw'], [data-position='ne'], [data-position='sw'], [data-position='se'])
not([data-disabled], [data-readonly])
position=ne
position=nw
position=se
position=sw
readonly
--xh-bg-subtle-opaque
--xh-image-cropper-handle-bg-resizingcrop-handlebackground
border
is([data-position='nw'], [data-position='ne'], [data-position='sw'], [data-position='se'])
position=ne
position=nw
position=se
position=sw
resizing
--xh-bg-brand
--xh-image-cropper-handle-bordercrop-handleborderis([data-position='nw'], [data-position='ne'], [data-position='sw'], [data-position='se'])
position=ne
position=nw
position=se
position=sw
--xh-_image-cropper-handle-color
--xh-image-cropper-handle-lengthcrop-handleblock-size
inline-size
is([data-position='e'], [data-position='w'])
is([data-position='n'], [data-position='s'])
position=e
position=n
position=s
position=w
--xh-space-8
--xh-image-cropper-handle-radiuscrop-handleborder-radiusdefault--xh-shape-pill
--xh-image-cropper-handle-sizecrop-handle
root
block-size
inline-size
inset
default
is([data-position='nw'], [data-position='ne'], [data-position='sw'], [data-position='se'])
position=ne
position=nw
position=se
position=sw
--xh-control-indicator-size
--xh-image-cropper-handle-thicknesscrop-handleblock-size
border-block-end-width
border-block-start-width
border-inline-end-width
border-inline-start-width
inline-size
is([data-position='e'], [data-position='w'])
is([data-position='n'], [data-position='s'])
position=e
position=n
position=ne
position=nw
position=s
position=se
position=sw
position=w
--xh-stroke-strong
--xh-image-cropper-maskcrop-areabox-shadowdefault--xh-bg-overlay
--xh-image-cropper-slider-accentrotate-slider
zoom-slider
accent-colordefault--xh-bg-brand
--xh-image-cropper-slider-wrotate-slider
zoom-slider
inline-sizedefault100%
--xh-image-cropper-viewport-radiusviewportborder-radiusdefault--xh-shape-surface
--xh-image-cropper-wrootinline-sizedefault100%

Released under The MIT License