Image
A picture: an <img> that fills the box of the component as fit says. It can also take a file the user drops on it.
import { Image } from "x4js"
Fit
fit says how the picture fills its box: contain, cover, fill or scale-down.
export function fit( ) {
return new HBox( { cls: "fits", content: [
new VBox( { content: [
new Image( { src: landscape, fit: "contain", width: 150, height: 150 } ),
new Label( { text: "contain" } ),
] } ),
new VBox( { content: [
new Image( { src: landscape, fit: "cover", width: 150, height: 150 } ),
new Label( { text: "cover" } ),
] } ),
new VBox( { content: [
new Image( { src: landscape, fit: "fill", width: 150, height: 150 } ),
new Label( { text: "fill" } ),
] } ),
new VBox( { content: [
new Image( { src: landscape, fit: "scale-down", width: 150, height: 150 } ),
new Label( { text: "scale-down" } ),
] } ),
] } );
}
.fits {
gap: 16px;
align-items: flex-start;
.x4image {
border: 1px solid var( --border );
}
}
setImage
setImage shows another picture; clear( ) shows none.
export function setImage( ) {
const image = new Image( { src: landscape, fit: "contain", width: 200, height: 140, alt: "A picture" } );
return new HBox( { cls: "fits", content: [
image,
new VBox( { content: [
new Button( { label: "Landscape", cls: "outline", click: ( ) => image.setImage( landscape ) } ),
new Button( { label: "Portrait", cls: "outline", click: ( ) => image.setImage( portrait ) } ),
new Button( { label: "Clear", cls: "outline", click: ( ) => image.clear( ) } ),
] } ),
] } );
}
Drop a file
With candrop, a click opens the file dialog and a file can be dropped on it; change gives the files, shown here with setImage.
export function dropFile( ) {
const image = new Image( {
cls: "drop",
src: portrait,
fit: "contain",
width: 200,
height: 160,
candrop: true,
accept: "image/*",
change: ( ev ) => {
image.setImage( URL.createObjectURL( ev.files[0] ) );
},
} );
return new HBox( { cls: "fits", content: [
image,
new Label( { text: "Click the picture, or drop one on it" } ),
] } );
}
.x4image.drop {
border: 2px dashed var( --border );
cursor: pointer;
}
For an assistant: llms.txt, llms-full.txt.