Skip to content

Drag, resize, and rotate

Read as Markdown

Use the convenience component with a writable geometry box.

Plain source. Run as a browser module after the document body exists. TSX uses jsx: "react-jsx" and jsxImportSource: "@pibbl/core".

import {
pibbl,
Manipulable,
Rectangle,
useSignal,
degrees,
type PibblManipulableProps,
type PibblManipulationBox,
} from "@pibbl/core";
function Scene() {
const box = useSignal<PibblManipulationBox>({
left: 80,
top: 70,
width: 180,
height: 100,
});
const rotation = useSignal(degrees(10));
const { width, height } = box.get();
const props: PibblManipulableProps = {
style: box,
rotation,
draggable: true,
resizable: true,
rotatable: true,
};
return (
<Manipulable {...props}>
<Rectangle style={{ width, height, fill: "#087e8b" }} />
</Manipulable>
);
}
const canvas = document.createElement("canvas");
canvas.width = 420;
canvas.height = 280;
document.body.append(canvas);
const controller = pibbl(canvas, <Scene />);
window.addEventListener("pagehide", () => controller.dispose(), { once: true });
  • Angles are radians; degrees() converts author-friendly degrees. The mounted component owns input listeners and gesture cleanup.

Documentation built with @pibbl/core 0.0.2, revision 2dccb19. ALPHA — NOT FOR PRODUCTION USE.