@tsdraw/react 0.8.5 → 0.9.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.
package/dist/index.cjs CHANGED
@@ -760,6 +760,7 @@ function useTsdrawCanvasController(options = {}) {
760
760
  const touchOptionsRef = react.useRef(options.touchOptions);
761
761
  const keyboardShortcutsRef = react.useRef(options.keyboardShortcuts);
762
762
  const penOptionsRef = react.useRef(options.penOptions);
763
+ const backgroundRef = react.useRef(options.background);
763
764
  const readOnlyRef = react.useRef(options.readOnly ?? false);
764
765
  const containerRef = react.useRef(null);
765
766
  const canvasRef = react.useRef(null);
@@ -841,6 +842,9 @@ function useTsdrawCanvasController(options = {}) {
841
842
  react.useEffect(() => {
842
843
  penOptionsRef.current = options.penOptions;
843
844
  }, [options.penOptions]);
845
+ react.useEffect(() => {
846
+ backgroundRef.current = options.background;
847
+ }, [options.background]);
844
848
  react.useEffect(() => {
845
849
  readOnlyRef.current = options.readOnly ?? false;
846
850
  }, [options.readOnly]);
@@ -860,8 +864,11 @@ function useTsdrawCanvasController(options = {}) {
860
864
  const ctx = canvas.getContext("2d");
861
865
  if (!ctx) return;
862
866
  const dpr = dprRef.current || 1;
867
+ const logicalWidth = canvas.width / dpr;
868
+ const logicalHeight = canvas.height / dpr;
863
869
  ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
864
- ctx.clearRect(0, 0, canvas.width / dpr, canvas.height / dpr);
870
+ ctx.clearRect(0, 0, logicalWidth, logicalHeight);
871
+ core.renderCanvasBackground(ctx, editor.viewport, logicalWidth, logicalHeight, backgroundRef.current, editor.renderer.theme);
865
872
  editor.render(ctx);
866
873
  }, []);
867
874
  const refreshSelectionBounds = react.useCallback((editor, ids = selectedShapeIdsRef.current) => {
@@ -1712,6 +1719,10 @@ function useTsdrawCanvasController(options = {}) {
1712
1719
  editor.renderer.setTheme(options.theme ?? "light");
1713
1720
  render();
1714
1721
  }, [options.theme, render]);
1722
+ react.useEffect(() => {
1723
+ if (!editorRef.current) return;
1724
+ render();
1725
+ }, [options.background, render]);
1715
1726
  const setTool = react.useCallback(
1716
1727
  (tool) => {
1717
1728
  const editor = editorRef.current;
@@ -1963,6 +1974,7 @@ function Tsdraw(props) {
1963
1974
  touchOptions: props.touchOptions,
1964
1975
  keyboardShortcuts: props.keyboardShortcuts,
1965
1976
  penOptions: props.penOptions,
1977
+ background: props.background,
1966
1978
  readOnly: props.readOnly,
1967
1979
  autoFocus: props.autoFocus,
1968
1980
  snapshot: props.snapshot,