@pixerate/editor-react 0.100.0 → 0.100.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -212,6 +212,8 @@ import {
212
212
  pointerPressure,
213
213
  FreeTransformTool,
214
214
  getViewportProjection,
215
+ measureCanvasViewport,
216
+ watchCanvasViewport,
215
217
  ShapeDrawGesture,
216
218
  TypeToolGesture,
217
219
  DEFAULT_SHAPE_TOOL_OPTIONS,
@@ -247,6 +249,7 @@ var ImageEditorCanvas = ({
247
249
  const canvasRef = useRef2(null);
248
250
  const containerRef = useRef2(null);
249
251
  const rootRef = useRef2(null);
252
+ const viewRef = useRef2({ width: 0, height: 0 });
250
253
  const modeRef = useRef2(mode);
251
254
  modeRef.current = mode;
252
255
  const latest = useRef2({ onError, onTypeSessionChange, locate, locateElement, open, chromeRoot, onPlaybackReveal });
@@ -258,19 +261,19 @@ var ImageEditorCanvas = ({
258
261
  const docToRoot = (p) => {
259
262
  const canvas = canvasRef.current;
260
263
  const root = rootRef.current;
261
- if (!canvas || !root || !canvas.width) return p;
264
+ if (!canvas || !root || !viewRef.current.width) return p;
262
265
  const r = canvas.getBoundingClientRect();
263
266
  const box = root.getBoundingClientRect();
264
- const c = imageToCanvasPoint(p, controller.getState(), canvas.width, canvas.height, modeRef.current === "crop");
265
- return { x: r.left - box.left + c.x * r.width / canvas.width, y: r.top - box.top + c.y * r.height / canvas.height };
267
+ const c = imageToCanvasPoint(p, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
268
+ return { x: r.left - box.left + c.x * r.width / viewRef.current.width, y: r.top - box.top + c.y * r.height / viewRef.current.height };
266
269
  };
267
270
  const clientToDoc = (p) => {
268
271
  const canvas = canvasRef.current;
269
- if (!canvas || !canvas.width) return p;
272
+ if (!canvas || !viewRef.current.width) return p;
270
273
  const r = canvas.getBoundingClientRect();
271
- const sx = r.width > 0 ? canvas.width / r.width : 1;
272
- const sy = r.height > 0 ? canvas.height / r.height : 1;
273
- return canvasToImagePoint({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), canvas.width, canvas.height, modeRef.current === "crop");
274
+ const sx = r.width > 0 ? viewRef.current.width / r.width : 1;
275
+ const sy = r.height > 0 ? viewRef.current.height / r.height : 1;
276
+ return canvasToImagePoint({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
274
277
  };
275
278
  const clientRect = (r) => {
276
279
  if (!r || r.width <= 0) return null;
@@ -369,11 +372,12 @@ var ImageEditorCanvas = ({
369
372
  const canvas = canvasRef.current;
370
373
  const container = containerRef.current;
371
374
  if (!canvas || !container) return;
372
- const vpWidth = container.clientWidth || 800;
373
- const vpHeight = container.clientHeight || 500;
375
+ const viewport = measureCanvasViewport(container);
376
+ viewRef.current = { width: viewport.width, height: viewport.height };
374
377
  await controller.render(canvas, {
375
- viewportWidth: vpWidth,
376
- viewportHeight: vpHeight,
378
+ viewportWidth: viewport.width,
379
+ viewportHeight: viewport.height,
380
+ pixelRatio: viewport.pixelRatio,
377
381
  fit,
378
382
  showCropOverlay: mode === "crop",
379
383
  showSelectionOverlay: true,
@@ -456,12 +460,12 @@ var ImageEditorCanvas = ({
456
460
  const transformPoint = (e) => {
457
461
  const canvas = canvasRef.current;
458
462
  const rect = canvas.getBoundingClientRect();
459
- const sx = rect.width > 0 ? canvas.width / rect.width : 1;
460
- const sy = rect.height > 0 ? canvas.height / rect.height : 1;
463
+ const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
464
+ const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
461
465
  const s = controller.getState();
462
466
  const cropping = mode === "crop";
463
- const projection = getViewportProjection(s, canvas.width, canvas.height, cropping);
464
- const pt = canvasToImagePoint({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s, canvas.width, canvas.height, cropping);
467
+ const projection = getViewportProjection(s, viewRef.current.width, viewRef.current.height, cropping);
468
+ const pt = canvasToImagePoint({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, cropping);
465
469
  transformTool.setView(projection.scale);
466
470
  return { pt, tolerance: 6 / (projection.scale || 1) };
467
471
  };
@@ -511,24 +515,16 @@ var ImageEditorCanvas = ({
511
515
  useEffect2(() => {
512
516
  const container = containerRef.current;
513
517
  if (!container) return;
514
- if (typeof ResizeObserver !== "undefined") {
515
- const observer = new ResizeObserver(() => {
516
- renderCanvas();
517
- });
518
- observer.observe(container);
519
- return () => observer.disconnect();
520
- } else {
521
- const handleResize = () => renderCanvas();
522
- window.addEventListener("resize", handleResize);
523
- return () => window.removeEventListener("resize", handleResize);
524
- }
518
+ const { width, height } = measureCanvasViewport(container);
519
+ viewRef.current = { width, height };
520
+ return watchCanvasViewport(container, () => renderCanvas());
525
521
  }, [renderCanvas]);
526
522
  const getCanvasEventPoint = (e) => {
527
523
  const canvas = canvasRef.current;
528
524
  if (!canvas) return { x: 0, y: 0 };
529
525
  const rect = canvas.getBoundingClientRect();
530
- const scaleX = rect.width > 0 ? canvas.width / rect.width : 1;
531
- const scaleY = rect.height > 0 ? canvas.height / rect.height : 1;
526
+ const scaleX = rect.width > 0 ? viewRef.current.width / rect.width : 1;
527
+ const scaleY = rect.height > 0 ? viewRef.current.height / rect.height : 1;
532
528
  return {
533
529
  x: (e.clientX - rect.left) * scaleX,
534
530
  y: (e.clientY - rect.top) * scaleY
@@ -540,11 +536,11 @@ var ImageEditorCanvas = ({
540
536
  const events = typeof native.getCoalescedEvents === "function" ? native.getCoalescedEvents() : [];
541
537
  const list = events.length ? events : [native];
542
538
  const rect = canvas.getBoundingClientRect();
543
- const sx = rect.width > 0 ? canvas.width / rect.width : 1;
544
- const sy = rect.height > 0 ? canvas.height / rect.height : 1;
539
+ const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
540
+ const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
545
541
  const s = controller.getState();
546
542
  return list.map((ev) => ({
547
- ...canvasToImagePoint({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s, canvas.width, canvas.height, false),
543
+ ...canvasToImagePoint({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, false),
548
544
  pressure: pointerPressure(ev)
549
545
  }));
550
546
  };
@@ -590,7 +586,7 @@ var ImageEditorCanvas = ({
590
586
  const canvasPt = getCanvasEventPoint(e);
591
587
  if (mode === "select") {
592
588
  const gesture = selectionGestureRef.current;
593
- const imgPt = canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false);
589
+ const imgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
594
590
  void gesture.begin(imgPt, e).then(() => report("select", gesture.error));
595
591
  return;
596
592
  }
@@ -601,8 +597,8 @@ var ImageEditorCanvas = ({
601
597
  width: state.imageDimensions.width,
602
598
  height: state.imageDimensions.height
603
599
  };
604
- const handle = hitTestCrop(canvasPt, state, canvas.width, canvas.height, 14, activeCrop);
605
- const startImgPt = canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, true);
600
+ const handle = hitTestCrop(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
601
+ const startImgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
606
602
  if (handle) {
607
603
  cropDragInfoRef.current = {
608
604
  handle,
@@ -621,7 +617,7 @@ var ImageEditorCanvas = ({
621
617
  return;
622
618
  }
623
619
  if (mode === "annotate" && (state.activeTool === "shape" || state.activeTool === "type")) {
624
- const imgPt = canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false);
620
+ const imgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
625
621
  report(state.activeTool, null);
626
622
  if (state.activeTool === "shape") shapeGestureRef.current.down(imgPt);
627
623
  else {
@@ -632,7 +628,7 @@ var ImageEditorCanvas = ({
632
628
  return;
633
629
  }
634
630
  if (mode === "annotate") {
635
- const imgPt = canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false);
631
+ const imgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
636
632
  dragStartPointRef.current = imgPt;
637
633
  if (state.activeTool === "select") {
638
634
  for (let i = state.annotations.length - 1; i >= 0; i--) {
@@ -673,7 +669,7 @@ var ImageEditorCanvas = ({
673
669
  const canvasPt = getCanvasEventPoint(e);
674
670
  if (mode === "select") {
675
671
  const gesture = selectionGestureRef.current;
676
- if (gesture.active && gesture.move(canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false))) {
672
+ if (gesture.active && gesture.move(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false))) {
677
673
  selectionDraftRef.current = gesture.draftPath;
678
674
  renderCanvas();
679
675
  }
@@ -682,7 +678,7 @@ var ImageEditorCanvas = ({
682
678
  if (mode === "crop") {
683
679
  const drag = cropDragInfoRef.current;
684
680
  if (drag) {
685
- const currentImgPt = canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, true);
681
+ const currentImgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
686
682
  let newCrop;
687
683
  if (drag.handle === "new") {
688
684
  const minX = Math.max(0, Math.min(drag.startImgPt.x, currentImgPt.x));
@@ -716,7 +712,7 @@ var ImageEditorCanvas = ({
716
712
  width: state.imageDimensions.width,
717
713
  height: state.imageDimensions.height
718
714
  };
719
- const handle = hitTestCrop(canvasPt, state, canvas.width, canvas.height, 14, activeCrop);
715
+ const handle = hitTestCrop(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
720
716
  canvas.style.cursor = getCropCursor(handle, state.transform);
721
717
  }
722
718
  return;
@@ -724,7 +720,7 @@ var ImageEditorCanvas = ({
724
720
  if (mode === "annotate" && state.activeTool === "shape") {
725
721
  const g = shapeGestureRef.current;
726
722
  if (g.active) {
727
- g.move(canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false), { shift: e.shiftKey, alt: e.altKey });
723
+ g.move(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false), { shift: e.shiftKey, alt: e.altKey });
728
724
  if (g.error) report("shape", g.error);
729
725
  }
730
726
  return;
@@ -732,7 +728,7 @@ var ImageEditorCanvas = ({
732
728
  if (mode === "annotate") {
733
729
  if (annotationDragInfoRef.current) {
734
730
  const drag = annotationDragInfoRef.current;
735
- const currentImgPt2 = canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false);
731
+ const currentImgPt2 = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
736
732
  const dx = currentImgPt2.x - drag.startImgPt.x;
737
733
  const dy = currentImgPt2.y - drag.startImgPt.y;
738
734
  editor.updateAnnotation(drag.annId, {
@@ -744,7 +740,7 @@ var ImageEditorCanvas = ({
744
740
  const startPt = dragStartPointRef.current;
745
741
  if (!startPt) {
746
742
  if (state.activeTool === "select") {
747
- const imgPt = canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false);
743
+ const imgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
748
744
  let hovered = false;
749
745
  for (let i = state.annotations.length - 1; i >= 0; i--) {
750
746
  if (hitTestAnnotation(imgPt, state.annotations[i])) {
@@ -758,7 +754,7 @@ var ImageEditorCanvas = ({
758
754
  }
759
755
  return;
760
756
  }
761
- const currentImgPt = canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false);
757
+ const currentImgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
762
758
  const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
763
759
  if (state.activeTool === "pen" && isDrawingRef.current) {
764
760
  currentPathRef.current.push(currentImgPt);
@@ -815,7 +811,7 @@ var ImageEditorCanvas = ({
815
811
  if (mode === "select") {
816
812
  const gesture = selectionGestureRef.current;
817
813
  if (gesture.active) {
818
- gesture.end(canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false), e);
814
+ gesture.end(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e);
819
815
  selectionDraftRef.current = null;
820
816
  renderCanvas();
821
817
  }
@@ -838,7 +834,7 @@ var ImageEditorCanvas = ({
838
834
  }
839
835
  if (mode === "annotate" && state.activeTool === "type") {
840
836
  const tool = typeToolRef.current;
841
- tool.up(canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false));
837
+ tool.up(canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false));
842
838
  setTypeSession(tool.session);
843
839
  if (tool.error) report("type", tool.error);
844
840
  void renderCanvas();
@@ -852,7 +848,7 @@ var ImageEditorCanvas = ({
852
848
  }
853
849
  const startPt = dragStartPointRef.current;
854
850
  if (startPt) {
855
- const currentImgPt = canvasToImagePoint(canvasPt, state, canvas.width, canvas.height, false);
851
+ const currentImgPt = canvasToImagePoint(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
856
852
  const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
857
853
  if (state.activeTool === "pen" && isDrawingRef.current) {
858
854
  if (currentPathRef.current.length > 1) {
@@ -919,7 +915,7 @@ var ImageEditorCanvas = ({
919
915
  onPointerUp: handlePaintPointerUp,
920
916
  onPointerCancel: () => paintGestureRef.current?.cancel(),
921
917
  "data-testid": "image-editor-canvas",
922
- style: transformTool.active ? { cursor: transformCursor } : void 0,
918
+ style: transformTool.active ? { width: "100%", height: "100%", cursor: transformCursor } : { width: "100%", height: "100%" },
923
919
  className: `absolute inset-0 w-full h-full block ${transformTool.active ? "touch-none" : mode === "paint" ? "touch-none cursor-crosshair" : mode === "annotate" && state.activeTool === "type" ? "cursor-text" : mode === "annotate" && state.activeTool === "shape" ? "cursor-crosshair" : ""}`
924
920
  }
925
921
  ),
@@ -2195,7 +2191,7 @@ import {
2195
2191
  rgbUnitToHex,
2196
2192
  setRetouchChoice
2197
2193
  } from "@pixerate/editor/image-editor";
2198
- import { DEFAULT_PAINT_GRADIENT } from "@pixerate/editor/image-editor";
2194
+ import { DEFAULT_PAINT_GRADIENT, userErrorMessage } from "@pixerate/editor/image-editor";
2199
2195
 
2200
2196
  // src/image-editor/PaintGradientEditor.tsx
2201
2197
  import { PAINT_GRADIENT_KIT } from "@pixerate/editor/image-editor";
@@ -2216,7 +2212,7 @@ var BrushOptionsBar = ({ controller, className }) => {
2216
2212
  setError(null);
2217
2213
  fn();
2218
2214
  } catch (err) {
2219
- setError(err instanceof Error ? err.message : String(err));
2215
+ setError(userErrorMessage(err));
2220
2216
  }
2221
2217
  };
2222
2218
  return /* @__PURE__ */ jsxs10("div", { className: `flex flex-col gap-2 text-xs text-foreground ${className ?? ""}`, "data-testid": "brush-options", children: [
@@ -352,6 +352,7 @@ var ImageEditorCanvas = ({
352
352
  const canvasRef = (0, import_react5.useRef)(null);
353
353
  const containerRef = (0, import_react5.useRef)(null);
354
354
  const rootRef = (0, import_react5.useRef)(null);
355
+ const viewRef = (0, import_react5.useRef)({ width: 0, height: 0 });
355
356
  const modeRef = (0, import_react5.useRef)(mode);
356
357
  modeRef.current = mode;
357
358
  const latest = (0, import_react5.useRef)({ onError, onTypeSessionChange, locate, locateElement, open, chromeRoot, onPlaybackReveal });
@@ -363,19 +364,19 @@ var ImageEditorCanvas = ({
363
364
  const docToRoot = (p) => {
364
365
  const canvas = canvasRef.current;
365
366
  const root = rootRef.current;
366
- if (!canvas || !root || !canvas.width) return p;
367
+ if (!canvas || !root || !viewRef.current.width) return p;
367
368
  const r = canvas.getBoundingClientRect();
368
369
  const box = root.getBoundingClientRect();
369
- const c = (0, import_image_editor2.imageToCanvasPoint)(p, controller.getState(), canvas.width, canvas.height, modeRef.current === "crop");
370
- return { x: r.left - box.left + c.x * r.width / canvas.width, y: r.top - box.top + c.y * r.height / canvas.height };
370
+ const c = (0, import_image_editor2.imageToCanvasPoint)(p, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
371
+ return { x: r.left - box.left + c.x * r.width / viewRef.current.width, y: r.top - box.top + c.y * r.height / viewRef.current.height };
371
372
  };
372
373
  const clientToDoc = (p) => {
373
374
  const canvas = canvasRef.current;
374
- if (!canvas || !canvas.width) return p;
375
+ if (!canvas || !viewRef.current.width) return p;
375
376
  const r = canvas.getBoundingClientRect();
376
- const sx = r.width > 0 ? canvas.width / r.width : 1;
377
- const sy = r.height > 0 ? canvas.height / r.height : 1;
378
- return (0, import_image_editor2.canvasToImagePoint)({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), canvas.width, canvas.height, modeRef.current === "crop");
377
+ const sx = r.width > 0 ? viewRef.current.width / r.width : 1;
378
+ const sy = r.height > 0 ? viewRef.current.height / r.height : 1;
379
+ return (0, import_image_editor2.canvasToImagePoint)({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
379
380
  };
380
381
  const clientRect = (r) => {
381
382
  if (!r || r.width <= 0) return null;
@@ -474,11 +475,12 @@ var ImageEditorCanvas = ({
474
475
  const canvas = canvasRef.current;
475
476
  const container = containerRef.current;
476
477
  if (!canvas || !container) return;
477
- const vpWidth = container.clientWidth || 800;
478
- const vpHeight = container.clientHeight || 500;
478
+ const viewport = (0, import_image_editor2.measureCanvasViewport)(container);
479
+ viewRef.current = { width: viewport.width, height: viewport.height };
479
480
  await controller.render(canvas, {
480
- viewportWidth: vpWidth,
481
- viewportHeight: vpHeight,
481
+ viewportWidth: viewport.width,
482
+ viewportHeight: viewport.height,
483
+ pixelRatio: viewport.pixelRatio,
482
484
  fit,
483
485
  showCropOverlay: mode === "crop",
484
486
  showSelectionOverlay: true,
@@ -561,12 +563,12 @@ var ImageEditorCanvas = ({
561
563
  const transformPoint = (e) => {
562
564
  const canvas = canvasRef.current;
563
565
  const rect = canvas.getBoundingClientRect();
564
- const sx = rect.width > 0 ? canvas.width / rect.width : 1;
565
- const sy = rect.height > 0 ? canvas.height / rect.height : 1;
566
+ const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
567
+ const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
566
568
  const s = controller.getState();
567
569
  const cropping = mode === "crop";
568
- const projection = (0, import_image_editor2.getViewportProjection)(s, canvas.width, canvas.height, cropping);
569
- const pt = (0, import_image_editor2.canvasToImagePoint)({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s, canvas.width, canvas.height, cropping);
570
+ const projection = (0, import_image_editor2.getViewportProjection)(s, viewRef.current.width, viewRef.current.height, cropping);
571
+ const pt = (0, import_image_editor2.canvasToImagePoint)({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, cropping);
570
572
  transformTool.setView(projection.scale);
571
573
  return { pt, tolerance: 6 / (projection.scale || 1) };
572
574
  };
@@ -616,24 +618,16 @@ var ImageEditorCanvas = ({
616
618
  (0, import_react5.useEffect)(() => {
617
619
  const container = containerRef.current;
618
620
  if (!container) return;
619
- if (typeof ResizeObserver !== "undefined") {
620
- const observer = new ResizeObserver(() => {
621
- renderCanvas();
622
- });
623
- observer.observe(container);
624
- return () => observer.disconnect();
625
- } else {
626
- const handleResize = () => renderCanvas();
627
- window.addEventListener("resize", handleResize);
628
- return () => window.removeEventListener("resize", handleResize);
629
- }
621
+ const { width, height } = (0, import_image_editor2.measureCanvasViewport)(container);
622
+ viewRef.current = { width, height };
623
+ return (0, import_image_editor2.watchCanvasViewport)(container, () => renderCanvas());
630
624
  }, [renderCanvas]);
631
625
  const getCanvasEventPoint = (e) => {
632
626
  const canvas = canvasRef.current;
633
627
  if (!canvas) return { x: 0, y: 0 };
634
628
  const rect = canvas.getBoundingClientRect();
635
- const scaleX = rect.width > 0 ? canvas.width / rect.width : 1;
636
- const scaleY = rect.height > 0 ? canvas.height / rect.height : 1;
629
+ const scaleX = rect.width > 0 ? viewRef.current.width / rect.width : 1;
630
+ const scaleY = rect.height > 0 ? viewRef.current.height / rect.height : 1;
637
631
  return {
638
632
  x: (e.clientX - rect.left) * scaleX,
639
633
  y: (e.clientY - rect.top) * scaleY
@@ -645,11 +639,11 @@ var ImageEditorCanvas = ({
645
639
  const events = typeof native.getCoalescedEvents === "function" ? native.getCoalescedEvents() : [];
646
640
  const list = events.length ? events : [native];
647
641
  const rect = canvas.getBoundingClientRect();
648
- const sx = rect.width > 0 ? canvas.width / rect.width : 1;
649
- const sy = rect.height > 0 ? canvas.height / rect.height : 1;
642
+ const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
643
+ const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
650
644
  const s = controller.getState();
651
645
  return list.map((ev) => ({
652
- ...(0, import_image_editor2.canvasToImagePoint)({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s, canvas.width, canvas.height, false),
646
+ ...(0, import_image_editor2.canvasToImagePoint)({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, false),
653
647
  pressure: (0, import_image_editor2.pointerPressure)(ev)
654
648
  }));
655
649
  };
@@ -695,7 +689,7 @@ var ImageEditorCanvas = ({
695
689
  const canvasPt = getCanvasEventPoint(e);
696
690
  if (mode === "select") {
697
691
  const gesture = selectionGestureRef.current;
698
- const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
692
+ const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
699
693
  void gesture.begin(imgPt, e).then(() => report("select", gesture.error));
700
694
  return;
701
695
  }
@@ -706,8 +700,8 @@ var ImageEditorCanvas = ({
706
700
  width: state.imageDimensions.width,
707
701
  height: state.imageDimensions.height
708
702
  };
709
- const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, canvas.width, canvas.height, 14, activeCrop);
710
- const startImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, true);
703
+ const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
704
+ const startImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
711
705
  if (handle) {
712
706
  cropDragInfoRef.current = {
713
707
  handle,
@@ -726,7 +720,7 @@ var ImageEditorCanvas = ({
726
720
  return;
727
721
  }
728
722
  if (mode === "annotate" && (state.activeTool === "shape" || state.activeTool === "type")) {
729
- const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
723
+ const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
730
724
  report(state.activeTool, null);
731
725
  if (state.activeTool === "shape") shapeGestureRef.current.down(imgPt);
732
726
  else {
@@ -737,7 +731,7 @@ var ImageEditorCanvas = ({
737
731
  return;
738
732
  }
739
733
  if (mode === "annotate") {
740
- const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
734
+ const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
741
735
  dragStartPointRef.current = imgPt;
742
736
  if (state.activeTool === "select") {
743
737
  for (let i = state.annotations.length - 1; i >= 0; i--) {
@@ -778,7 +772,7 @@ var ImageEditorCanvas = ({
778
772
  const canvasPt = getCanvasEventPoint(e);
779
773
  if (mode === "select") {
780
774
  const gesture = selectionGestureRef.current;
781
- if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false))) {
775
+ if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false))) {
782
776
  selectionDraftRef.current = gesture.draftPath;
783
777
  renderCanvas();
784
778
  }
@@ -787,7 +781,7 @@ var ImageEditorCanvas = ({
787
781
  if (mode === "crop") {
788
782
  const drag = cropDragInfoRef.current;
789
783
  if (drag) {
790
- const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, true);
784
+ const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
791
785
  let newCrop;
792
786
  if (drag.handle === "new") {
793
787
  const minX = Math.max(0, Math.min(drag.startImgPt.x, currentImgPt.x));
@@ -821,7 +815,7 @@ var ImageEditorCanvas = ({
821
815
  width: state.imageDimensions.width,
822
816
  height: state.imageDimensions.height
823
817
  };
824
- const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, canvas.width, canvas.height, 14, activeCrop);
818
+ const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
825
819
  canvas.style.cursor = (0, import_image_editor2.getCropCursor)(handle, state.transform);
826
820
  }
827
821
  return;
@@ -829,7 +823,7 @@ var ImageEditorCanvas = ({
829
823
  if (mode === "annotate" && state.activeTool === "shape") {
830
824
  const g = shapeGestureRef.current;
831
825
  if (g.active) {
832
- g.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false), { shift: e.shiftKey, alt: e.altKey });
826
+ g.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), { shift: e.shiftKey, alt: e.altKey });
833
827
  if (g.error) report("shape", g.error);
834
828
  }
835
829
  return;
@@ -837,7 +831,7 @@ var ImageEditorCanvas = ({
837
831
  if (mode === "annotate") {
838
832
  if (annotationDragInfoRef.current) {
839
833
  const drag = annotationDragInfoRef.current;
840
- const currentImgPt2 = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
834
+ const currentImgPt2 = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
841
835
  const dx = currentImgPt2.x - drag.startImgPt.x;
842
836
  const dy = currentImgPt2.y - drag.startImgPt.y;
843
837
  editor.updateAnnotation(drag.annId, {
@@ -849,7 +843,7 @@ var ImageEditorCanvas = ({
849
843
  const startPt = dragStartPointRef.current;
850
844
  if (!startPt) {
851
845
  if (state.activeTool === "select") {
852
- const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
846
+ const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
853
847
  let hovered = false;
854
848
  for (let i = state.annotations.length - 1; i >= 0; i--) {
855
849
  if ((0, import_image_editor2.hitTestAnnotation)(imgPt, state.annotations[i])) {
@@ -863,7 +857,7 @@ var ImageEditorCanvas = ({
863
857
  }
864
858
  return;
865
859
  }
866
- const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
860
+ const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
867
861
  const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
868
862
  if (state.activeTool === "pen" && isDrawingRef.current) {
869
863
  currentPathRef.current.push(currentImgPt);
@@ -920,7 +914,7 @@ var ImageEditorCanvas = ({
920
914
  if (mode === "select") {
921
915
  const gesture = selectionGestureRef.current;
922
916
  if (gesture.active) {
923
- gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false), e);
917
+ gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e);
924
918
  selectionDraftRef.current = null;
925
919
  renderCanvas();
926
920
  }
@@ -943,7 +937,7 @@ var ImageEditorCanvas = ({
943
937
  }
944
938
  if (mode === "annotate" && state.activeTool === "type") {
945
939
  const tool = typeToolRef.current;
946
- tool.up((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false));
940
+ tool.up((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false));
947
941
  setTypeSession(tool.session);
948
942
  if (tool.error) report("type", tool.error);
949
943
  void renderCanvas();
@@ -957,7 +951,7 @@ var ImageEditorCanvas = ({
957
951
  }
958
952
  const startPt = dragStartPointRef.current;
959
953
  if (startPt) {
960
- const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
954
+ const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
961
955
  const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
962
956
  if (state.activeTool === "pen" && isDrawingRef.current) {
963
957
  if (currentPathRef.current.length > 1) {
@@ -1024,7 +1018,7 @@ var ImageEditorCanvas = ({
1024
1018
  onPointerUp: handlePaintPointerUp,
1025
1019
  onPointerCancel: () => paintGestureRef.current?.cancel(),
1026
1020
  "data-testid": "image-editor-canvas",
1027
- style: transformTool.active ? { cursor: transformCursor } : void 0,
1021
+ style: transformTool.active ? { width: "100%", height: "100%", cursor: transformCursor } : { width: "100%", height: "100%" },
1028
1022
  className: `absolute inset-0 w-full h-full block ${transformTool.active ? "touch-none" : mode === "paint" ? "touch-none cursor-crosshair" : mode === "annotate" && state.activeTool === "type" ? "cursor-text" : mode === "annotate" && state.activeTool === "shape" ? "cursor-crosshair" : ""}`
1029
1023
  }
1030
1024
  ),
@@ -4016,7 +4010,7 @@ var BrushOptionsBar = ({ controller, className }) => {
4016
4010
  setError(null);
4017
4011
  fn();
4018
4012
  } catch (err) {
4019
- setError(err instanceof Error ? err.message : String(err));
4013
+ setError((0, import_image_editor12.userErrorMessage)(err));
4020
4014
  }
4021
4015
  };
4022
4016
  return /* @__PURE__ */ (0, import_jsx_runtime20.jsxs)("div", { className: `flex flex-col gap-2 text-xs text-foreground ${className ?? ""}`, "data-testid": "brush-options", children: [
@@ -20,7 +20,7 @@ import {
20
20
  useImageEditor,
21
21
  useImageEffectsTools,
22
22
  useImageHistogram
23
- } from "../chunk-OTDAEVHW.js";
23
+ } from "../chunk-GJ2TYERJ.js";
24
24
  import "../chunk-AJCWF6SN.js";
25
25
  import "../chunk-Q7LAFHGP.js";
26
26
  import "../chunk-5LFQ2UQZ.js";
package/dist/index.cjs CHANGED
@@ -4045,6 +4045,7 @@ var ImageEditorCanvas = ({
4045
4045
  const canvasRef = (0, import_react40.useRef)(null);
4046
4046
  const containerRef = (0, import_react40.useRef)(null);
4047
4047
  const rootRef = (0, import_react40.useRef)(null);
4048
+ const viewRef = (0, import_react40.useRef)({ width: 0, height: 0 });
4048
4049
  const modeRef = (0, import_react40.useRef)(mode);
4049
4050
  modeRef.current = mode;
4050
4051
  const latest = (0, import_react40.useRef)({ onError, onTypeSessionChange, locate, locateElement, open, chromeRoot, onPlaybackReveal });
@@ -4056,19 +4057,19 @@ var ImageEditorCanvas = ({
4056
4057
  const docToRoot = (p) => {
4057
4058
  const canvas = canvasRef.current;
4058
4059
  const root = rootRef.current;
4059
- if (!canvas || !root || !canvas.width) return p;
4060
+ if (!canvas || !root || !viewRef.current.width) return p;
4060
4061
  const r = canvas.getBoundingClientRect();
4061
4062
  const box = root.getBoundingClientRect();
4062
- const c = (0, import_image_editor2.imageToCanvasPoint)(p, controller.getState(), canvas.width, canvas.height, modeRef.current === "crop");
4063
- return { x: r.left - box.left + c.x * r.width / canvas.width, y: r.top - box.top + c.y * r.height / canvas.height };
4063
+ const c = (0, import_image_editor2.imageToCanvasPoint)(p, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
4064
+ return { x: r.left - box.left + c.x * r.width / viewRef.current.width, y: r.top - box.top + c.y * r.height / viewRef.current.height };
4064
4065
  };
4065
4066
  const clientToDoc = (p) => {
4066
4067
  const canvas = canvasRef.current;
4067
- if (!canvas || !canvas.width) return p;
4068
+ if (!canvas || !viewRef.current.width) return p;
4068
4069
  const r = canvas.getBoundingClientRect();
4069
- const sx = r.width > 0 ? canvas.width / r.width : 1;
4070
- const sy = r.height > 0 ? canvas.height / r.height : 1;
4071
- return (0, import_image_editor2.canvasToImagePoint)({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), canvas.width, canvas.height, modeRef.current === "crop");
4070
+ const sx = r.width > 0 ? viewRef.current.width / r.width : 1;
4071
+ const sy = r.height > 0 ? viewRef.current.height / r.height : 1;
4072
+ return (0, import_image_editor2.canvasToImagePoint)({ x: (p.x - r.left) * sx, y: (p.y - r.top) * sy }, controller.getState(), viewRef.current.width, viewRef.current.height, modeRef.current === "crop");
4072
4073
  };
4073
4074
  const clientRect = (r) => {
4074
4075
  if (!r || r.width <= 0) return null;
@@ -4167,11 +4168,12 @@ var ImageEditorCanvas = ({
4167
4168
  const canvas = canvasRef.current;
4168
4169
  const container = containerRef.current;
4169
4170
  if (!canvas || !container) return;
4170
- const vpWidth = container.clientWidth || 800;
4171
- const vpHeight = container.clientHeight || 500;
4171
+ const viewport = (0, import_image_editor2.measureCanvasViewport)(container);
4172
+ viewRef.current = { width: viewport.width, height: viewport.height };
4172
4173
  await controller.render(canvas, {
4173
- viewportWidth: vpWidth,
4174
- viewportHeight: vpHeight,
4174
+ viewportWidth: viewport.width,
4175
+ viewportHeight: viewport.height,
4176
+ pixelRatio: viewport.pixelRatio,
4175
4177
  fit,
4176
4178
  showCropOverlay: mode === "crop",
4177
4179
  showSelectionOverlay: true,
@@ -4254,12 +4256,12 @@ var ImageEditorCanvas = ({
4254
4256
  const transformPoint = (e) => {
4255
4257
  const canvas = canvasRef.current;
4256
4258
  const rect = canvas.getBoundingClientRect();
4257
- const sx = rect.width > 0 ? canvas.width / rect.width : 1;
4258
- const sy = rect.height > 0 ? canvas.height / rect.height : 1;
4259
+ const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
4260
+ const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
4259
4261
  const s = controller.getState();
4260
4262
  const cropping = mode === "crop";
4261
- const projection = (0, import_image_editor2.getViewportProjection)(s, canvas.width, canvas.height, cropping);
4262
- const pt = (0, import_image_editor2.canvasToImagePoint)({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s, canvas.width, canvas.height, cropping);
4263
+ const projection = (0, import_image_editor2.getViewportProjection)(s, viewRef.current.width, viewRef.current.height, cropping);
4264
+ const pt = (0, import_image_editor2.canvasToImagePoint)({ x: (e.clientX - rect.left) * sx, y: (e.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, cropping);
4263
4265
  transformTool.setView(projection.scale);
4264
4266
  return { pt, tolerance: 6 / (projection.scale || 1) };
4265
4267
  };
@@ -4309,24 +4311,16 @@ var ImageEditorCanvas = ({
4309
4311
  (0, import_react40.useEffect)(() => {
4310
4312
  const container = containerRef.current;
4311
4313
  if (!container) return;
4312
- if (typeof ResizeObserver !== "undefined") {
4313
- const observer = new ResizeObserver(() => {
4314
- renderCanvas();
4315
- });
4316
- observer.observe(container);
4317
- return () => observer.disconnect();
4318
- } else {
4319
- const handleResize = () => renderCanvas();
4320
- window.addEventListener("resize", handleResize);
4321
- return () => window.removeEventListener("resize", handleResize);
4322
- }
4314
+ const { width, height } = (0, import_image_editor2.measureCanvasViewport)(container);
4315
+ viewRef.current = { width, height };
4316
+ return (0, import_image_editor2.watchCanvasViewport)(container, () => renderCanvas());
4323
4317
  }, [renderCanvas]);
4324
4318
  const getCanvasEventPoint = (e) => {
4325
4319
  const canvas = canvasRef.current;
4326
4320
  if (!canvas) return { x: 0, y: 0 };
4327
4321
  const rect = canvas.getBoundingClientRect();
4328
- const scaleX = rect.width > 0 ? canvas.width / rect.width : 1;
4329
- const scaleY = rect.height > 0 ? canvas.height / rect.height : 1;
4322
+ const scaleX = rect.width > 0 ? viewRef.current.width / rect.width : 1;
4323
+ const scaleY = rect.height > 0 ? viewRef.current.height / rect.height : 1;
4330
4324
  return {
4331
4325
  x: (e.clientX - rect.left) * scaleX,
4332
4326
  y: (e.clientY - rect.top) * scaleY
@@ -4338,11 +4332,11 @@ var ImageEditorCanvas = ({
4338
4332
  const events = typeof native.getCoalescedEvents === "function" ? native.getCoalescedEvents() : [];
4339
4333
  const list = events.length ? events : [native];
4340
4334
  const rect = canvas.getBoundingClientRect();
4341
- const sx = rect.width > 0 ? canvas.width / rect.width : 1;
4342
- const sy = rect.height > 0 ? canvas.height / rect.height : 1;
4335
+ const sx = rect.width > 0 ? viewRef.current.width / rect.width : 1;
4336
+ const sy = rect.height > 0 ? viewRef.current.height / rect.height : 1;
4343
4337
  const s = controller.getState();
4344
4338
  return list.map((ev) => ({
4345
- ...(0, import_image_editor2.canvasToImagePoint)({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s, canvas.width, canvas.height, false),
4339
+ ...(0, import_image_editor2.canvasToImagePoint)({ x: (ev.clientX - rect.left) * sx, y: (ev.clientY - rect.top) * sy }, s, viewRef.current.width, viewRef.current.height, false),
4346
4340
  pressure: (0, import_image_editor2.pointerPressure)(ev)
4347
4341
  }));
4348
4342
  };
@@ -4388,7 +4382,7 @@ var ImageEditorCanvas = ({
4388
4382
  const canvasPt = getCanvasEventPoint(e);
4389
4383
  if (mode === "select") {
4390
4384
  const gesture = selectionGestureRef.current;
4391
- const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
4385
+ const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
4392
4386
  void gesture.begin(imgPt, e).then(() => report("select", gesture.error));
4393
4387
  return;
4394
4388
  }
@@ -4399,8 +4393,8 @@ var ImageEditorCanvas = ({
4399
4393
  width: state.imageDimensions.width,
4400
4394
  height: state.imageDimensions.height
4401
4395
  };
4402
- const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, canvas.width, canvas.height, 14, activeCrop);
4403
- const startImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, true);
4396
+ const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
4397
+ const startImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
4404
4398
  if (handle) {
4405
4399
  cropDragInfoRef.current = {
4406
4400
  handle,
@@ -4419,7 +4413,7 @@ var ImageEditorCanvas = ({
4419
4413
  return;
4420
4414
  }
4421
4415
  if (mode === "annotate" && (state.activeTool === "shape" || state.activeTool === "type")) {
4422
- const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
4416
+ const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
4423
4417
  report(state.activeTool, null);
4424
4418
  if (state.activeTool === "shape") shapeGestureRef.current.down(imgPt);
4425
4419
  else {
@@ -4430,7 +4424,7 @@ var ImageEditorCanvas = ({
4430
4424
  return;
4431
4425
  }
4432
4426
  if (mode === "annotate") {
4433
- const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
4427
+ const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
4434
4428
  dragStartPointRef.current = imgPt;
4435
4429
  if (state.activeTool === "select") {
4436
4430
  for (let i = state.annotations.length - 1; i >= 0; i--) {
@@ -4471,7 +4465,7 @@ var ImageEditorCanvas = ({
4471
4465
  const canvasPt = getCanvasEventPoint(e);
4472
4466
  if (mode === "select") {
4473
4467
  const gesture = selectionGestureRef.current;
4474
- if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false))) {
4468
+ if (gesture.active && gesture.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false))) {
4475
4469
  selectionDraftRef.current = gesture.draftPath;
4476
4470
  renderCanvas();
4477
4471
  }
@@ -4480,7 +4474,7 @@ var ImageEditorCanvas = ({
4480
4474
  if (mode === "crop") {
4481
4475
  const drag = cropDragInfoRef.current;
4482
4476
  if (drag) {
4483
- const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, true);
4477
+ const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, true);
4484
4478
  let newCrop;
4485
4479
  if (drag.handle === "new") {
4486
4480
  const minX = Math.max(0, Math.min(drag.startImgPt.x, currentImgPt.x));
@@ -4514,7 +4508,7 @@ var ImageEditorCanvas = ({
4514
4508
  width: state.imageDimensions.width,
4515
4509
  height: state.imageDimensions.height
4516
4510
  };
4517
- const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, canvas.width, canvas.height, 14, activeCrop);
4511
+ const handle = (0, import_image_editor2.hitTestCrop)(canvasPt, state, viewRef.current.width, viewRef.current.height, 14, activeCrop);
4518
4512
  canvas.style.cursor = (0, import_image_editor2.getCropCursor)(handle, state.transform);
4519
4513
  }
4520
4514
  return;
@@ -4522,7 +4516,7 @@ var ImageEditorCanvas = ({
4522
4516
  if (mode === "annotate" && state.activeTool === "shape") {
4523
4517
  const g = shapeGestureRef.current;
4524
4518
  if (g.active) {
4525
- g.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false), { shift: e.shiftKey, alt: e.altKey });
4519
+ g.move((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), { shift: e.shiftKey, alt: e.altKey });
4526
4520
  if (g.error) report("shape", g.error);
4527
4521
  }
4528
4522
  return;
@@ -4530,7 +4524,7 @@ var ImageEditorCanvas = ({
4530
4524
  if (mode === "annotate") {
4531
4525
  if (annotationDragInfoRef.current) {
4532
4526
  const drag = annotationDragInfoRef.current;
4533
- const currentImgPt2 = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
4527
+ const currentImgPt2 = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
4534
4528
  const dx = currentImgPt2.x - drag.startImgPt.x;
4535
4529
  const dy = currentImgPt2.y - drag.startImgPt.y;
4536
4530
  editor.updateAnnotation(drag.annId, {
@@ -4542,7 +4536,7 @@ var ImageEditorCanvas = ({
4542
4536
  const startPt = dragStartPointRef.current;
4543
4537
  if (!startPt) {
4544
4538
  if (state.activeTool === "select") {
4545
- const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
4539
+ const imgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
4546
4540
  let hovered = false;
4547
4541
  for (let i = state.annotations.length - 1; i >= 0; i--) {
4548
4542
  if ((0, import_image_editor2.hitTestAnnotation)(imgPt, state.annotations[i])) {
@@ -4556,7 +4550,7 @@ var ImageEditorCanvas = ({
4556
4550
  }
4557
4551
  return;
4558
4552
  }
4559
- const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
4553
+ const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
4560
4554
  const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
4561
4555
  if (state.activeTool === "pen" && isDrawingRef.current) {
4562
4556
  currentPathRef.current.push(currentImgPt);
@@ -4613,7 +4607,7 @@ var ImageEditorCanvas = ({
4613
4607
  if (mode === "select") {
4614
4608
  const gesture = selectionGestureRef.current;
4615
4609
  if (gesture.active) {
4616
- gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false), e);
4610
+ gesture.end((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false), e);
4617
4611
  selectionDraftRef.current = null;
4618
4612
  renderCanvas();
4619
4613
  }
@@ -4636,7 +4630,7 @@ var ImageEditorCanvas = ({
4636
4630
  }
4637
4631
  if (mode === "annotate" && state.activeTool === "type") {
4638
4632
  const tool = typeToolRef.current;
4639
- tool.up((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false));
4633
+ tool.up((0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false));
4640
4634
  setTypeSession(tool.session);
4641
4635
  if (tool.error) report("type", tool.error);
4642
4636
  void renderCanvas();
@@ -4650,7 +4644,7 @@ var ImageEditorCanvas = ({
4650
4644
  }
4651
4645
  const startPt = dragStartPointRef.current;
4652
4646
  if (startPt) {
4653
- const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, canvas.width, canvas.height, false);
4647
+ const currentImgPt = (0, import_image_editor2.canvasToImagePoint)(canvasPt, state, viewRef.current.width, viewRef.current.height, false);
4654
4648
  const stroke = { strokeColor: annotationColor, strokeWidth: annotationWidth };
4655
4649
  if (state.activeTool === "pen" && isDrawingRef.current) {
4656
4650
  if (currentPathRef.current.length > 1) {
@@ -4717,7 +4711,7 @@ var ImageEditorCanvas = ({
4717
4711
  onPointerUp: handlePaintPointerUp,
4718
4712
  onPointerCancel: () => paintGestureRef.current?.cancel(),
4719
4713
  "data-testid": "image-editor-canvas",
4720
- style: transformTool.active ? { cursor: transformCursor } : void 0,
4714
+ style: transformTool.active ? { width: "100%", height: "100%", cursor: transformCursor } : { width: "100%", height: "100%" },
4721
4715
  className: `absolute inset-0 w-full h-full block ${transformTool.active ? "touch-none" : mode === "paint" ? "touch-none cursor-crosshair" : mode === "annotate" && state.activeTool === "type" ? "cursor-text" : mode === "annotate" && state.activeTool === "shape" ? "cursor-crosshair" : ""}`
4722
4716
  }
4723
4717
  ),
@@ -7709,7 +7703,7 @@ var BrushOptionsBar = ({ controller, className }) => {
7709
7703
  setError(null);
7710
7704
  fn();
7711
7705
  } catch (err) {
7712
- setError(err instanceof Error ? err.message : String(err));
7706
+ setError((0, import_image_editor12.userErrorMessage)(err));
7713
7707
  }
7714
7708
  };
7715
7709
  return /* @__PURE__ */ (0, import_jsx_runtime36.jsxs)("div", { className: `flex flex-col gap-2 text-xs text-foreground ${className ?? ""}`, "data-testid": "brush-options", children: [
package/dist/index.js CHANGED
@@ -44,7 +44,7 @@ import {
44
44
  useImageEditor,
45
45
  useImageEffectsTools,
46
46
  useImageHistogram
47
- } from "./chunk-OTDAEVHW.js";
47
+ } from "./chunk-GJ2TYERJ.js";
48
48
  import "./chunk-AJCWF6SN.js";
49
49
  import "./chunk-Q7LAFHGP.js";
50
50
  import "./chunk-5LFQ2UQZ.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pixerate/editor-react",
3
- "version": "0.100.0",
3
+ "version": "0.100.1",
4
4
  "description": "React bindings and prompt/rich-text components for @pixerate/editor",
5
5
  "author": "Pixerate",
6
6
  "license": "MIT",
@@ -245,7 +245,7 @@
245
245
  },
246
246
  "peerDependencies": {
247
247
  "@dagrejs/dagre": "^1.1.8",
248
- "@pixerate/editor": ">=0.150.0 <1.0.0-0",
248
+ "@pixerate/editor": ">=0.150.1 <1.0.0-0",
249
249
  "@tiptap/core": "^2.27.3",
250
250
  "@tiptap/pm": "^2.27.3",
251
251
  "@tiptap/react": "^2.27.3",
@@ -267,12 +267,12 @@
267
267
  "@tiptap/react": "^2.27.3",
268
268
  "@types/react": "^19.3.0",
269
269
  "@types/react-dom": "^19.3.0",
270
- "react": "^19.3.0",
271
- "react-dom": "^19.3.0",
270
+ "react": "^19.3.1",
271
+ "react-dom": "^19.3.1",
272
272
  "tsup": "^9.0.0",
273
273
  "typescript": "^5.7.3",
274
274
  "vitest": "^5.0.5",
275
- "@pixerate/editor": "0.150.0"
275
+ "@pixerate/editor": "0.150.1"
276
276
  },
277
277
  "scripts": {
278
278
  "build": "tsup && tsc -p tsconfig.build.json && node ../../scripts/finalize-declarations.mjs dist",