docs/api/cropper-element.md
The CropperElement interface represents any Cropper element, extends the HTMLElement interface.
$.$.$on.import { CropperElement } from 'cropperjs';
// Or
// import CropperElement from '@cropper/element';
class MyCropperElement extends CropperElement {
myStringProperty = '';
myNumberProperty = NaN;
myBooleanProperty = false;
static get observedAttributes() {
return super.observedAttributes.concat([
'my-boolean-property',
'my-number-property',
'my-string-property',
]);
}
// ...
}
MyCropperElement.$define();
<my-cropper-element my-string-property="foo" my-number-property="1" my-boolean-property></my-cropper-element>
Inherits properties from its parent, HTMLElement, and implements the following properties:
| Name | Type | Default | Options | Description |
|---|---|---|---|---|
| shadowRootMode | string | "open" | "closed" | "open" | Indicates the encapsulation mode for the shadow DOM tree. |
| slottable | boolean | true | - | Indicates whether this element contains a <slot> element. |
| themeColor | string | - | - | Indicates the theme color of this element and its children. |
$getShadowRoot()ShadowRootOutputs the shadow root of the element, even if its mode is "closed".
Syntax: $addStyles(styles)
Arguments:
styles:
stringReturns:
CSSStyleSheet | HTMLStyleElementExample:
const canvas = new CropperCanvas();
canvas.$addStyles(`
:host {
border: 1px solid #39f;
}
`);
Adds styles to the shadow root.
Syntax:
$emit(type)$emit(type, detail)$emit(type, detail, options)Arguments:
type:
stringdetail:
*undefinedoptions:
CustomEventInit{ bubbles: true, cancelable: true, composed: true }Returns:
booleanExample:
const selection = new CropperSelection();
selection.$emit('change', {
x: 10,
y: 5,
width: 160,
height: 90,
});
Dispatches an event at the current element.
$nextTick()$nextTick(callback)callback:
FunctionPromiseDefers the callback to be executed after the next DOM update cycle.
| Name | Type | Description |
|---|---|---|
| $name | string | The name of the custom element. |
| $version | string | The version of the package. |
Defines the constructor as a new custom element. It is just a shortcut to call CustomElementRegistry.define().
Syntax:
$define()$define(name)$define(options)$define(name, options)Alternatives:
customElements.define(name, constructor)customElements.define(name, constructor, options)Arguments:
name:
string$name static property of the constructor.options:
ObjectExample:
// Define as a autonomous custom element: `<my-cropper-element></my-cropper-element>`.
CropperElement.$define('my-cropper-element');