@tsdraw/react 0.8.5 → 0.9.0
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 +13 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +14 -2
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
-
import { ZoomRange, ToolId, ColorStyle, DashStyle, FillStyle, SizeStyle, Editor, ToolDefinition, TsdrawEditorSnapshot, TsdrawDocumentSnapshot, Viewport } from '@tsdraw/core';
|
|
3
|
+
import { ZoomRange, ToolId, ColorStyle, DashStyle, FillStyle, SizeStyle, Editor, ToolDefinition, TsdrawBackgroundOptions, TsdrawEditorSnapshot, TsdrawDocumentSnapshot, Viewport } from '@tsdraw/core';
|
|
4
|
+
export { TsdrawBackgroundCustom, TsdrawBackgroundOptions, TsdrawBackgroundPreset, TsdrawBackgroundType } from '@tsdraw/core';
|
|
4
5
|
|
|
5
6
|
interface TsdrawCameraOptions {
|
|
6
7
|
panSpeed?: number;
|
|
@@ -152,6 +153,7 @@ interface TsdrawProps {
|
|
|
152
153
|
touchOptions?: TsdrawTouchOptions;
|
|
153
154
|
keyboardShortcuts?: TsdrawKeyboardShortcutOptions;
|
|
154
155
|
penOptions?: TsdrawPenOptions;
|
|
156
|
+
background?: TsdrawBackgroundOptions;
|
|
155
157
|
readOnly?: boolean;
|
|
156
158
|
autoFocus?: boolean;
|
|
157
159
|
snapshot?: TsdrawEditorSnapshot;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import * as react_jsx_runtime from 'react/jsx-runtime';
|
|
2
2
|
import { ReactNode, CSSProperties } from 'react';
|
|
3
|
-
import { ZoomRange, ToolId, ColorStyle, DashStyle, FillStyle, SizeStyle, Editor, ToolDefinition, TsdrawEditorSnapshot, TsdrawDocumentSnapshot, Viewport } from '@tsdraw/core';
|
|
3
|
+
import { ZoomRange, ToolId, ColorStyle, DashStyle, FillStyle, SizeStyle, Editor, ToolDefinition, TsdrawBackgroundOptions, TsdrawEditorSnapshot, TsdrawDocumentSnapshot, Viewport } from '@tsdraw/core';
|
|
4
|
+
export { TsdrawBackgroundCustom, TsdrawBackgroundOptions, TsdrawBackgroundPreset, TsdrawBackgroundType } from '@tsdraw/core';
|
|
4
5
|
|
|
5
6
|
interface TsdrawCameraOptions {
|
|
6
7
|
panSpeed?: number;
|
|
@@ -152,6 +153,7 @@ interface TsdrawProps {
|
|
|
152
153
|
touchOptions?: TsdrawTouchOptions;
|
|
153
154
|
keyboardShortcuts?: TsdrawKeyboardShortcutOptions;
|
|
154
155
|
penOptions?: TsdrawPenOptions;
|
|
156
|
+
background?: TsdrawBackgroundOptions;
|
|
155
157
|
readOnly?: boolean;
|
|
156
158
|
autoFocus?: boolean;
|
|
157
159
|
snapshot?: TsdrawEditorSnapshot;
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useState, useMemo, useEffect, useCallback, useRef } from 'react';
|
|
2
2
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
3
|
-
import { DEFAULT_COLORS, getSelectionBoundsPage, buildTransformSnapshots, Editor, STROKE_WIDTHS, ERASER_MARGIN, resolveThemeColor, pageToScreen, getTopShapeAtPoint, buildStartPositions, applyRotation, applyResize, applyMove, normalizeSelectionBounds, getShapesInBounds, HandDraggingState, startCameraSlide, isSelectTool, beginCameraPan, moveCameraPan } from '@tsdraw/core';
|
|
3
|
+
import { DEFAULT_COLORS, renderCanvasBackground, getSelectionBoundsPage, buildTransformSnapshots, Editor, STROKE_WIDTHS, ERASER_MARGIN, resolveThemeColor, pageToScreen, getTopShapeAtPoint, buildStartPositions, applyRotation, applyResize, applyMove, normalizeSelectionBounds, getShapesInBounds, HandDraggingState, startCameraSlide, isSelectTool, beginCameraPan, moveCameraPan } from '@tsdraw/core';
|
|
4
4
|
import { IconPointer, IconPencil, IconSquare, IconCircle, IconEraser, IconHandStop, IconArrowBackUp, IconArrowForwardUp } from '@tabler/icons-react';
|
|
5
5
|
|
|
6
6
|
// src/components/TsdrawCanvas.tsx
|
|
@@ -758,6 +758,7 @@ function useTsdrawCanvasController(options = {}) {
|
|
|
758
758
|
const touchOptionsRef = useRef(options.touchOptions);
|
|
759
759
|
const keyboardShortcutsRef = useRef(options.keyboardShortcuts);
|
|
760
760
|
const penOptionsRef = useRef(options.penOptions);
|
|
761
|
+
const backgroundRef = useRef(options.background);
|
|
761
762
|
const readOnlyRef = useRef(options.readOnly ?? false);
|
|
762
763
|
const containerRef = useRef(null);
|
|
763
764
|
const canvasRef = useRef(null);
|
|
@@ -839,6 +840,9 @@ function useTsdrawCanvasController(options = {}) {
|
|
|
839
840
|
useEffect(() => {
|
|
840
841
|
penOptionsRef.current = options.penOptions;
|
|
841
842
|
}, [options.penOptions]);
|
|
843
|
+
useEffect(() => {
|
|
844
|
+
backgroundRef.current = options.background;
|
|
845
|
+
}, [options.background]);
|
|
842
846
|
useEffect(() => {
|
|
843
847
|
readOnlyRef.current = options.readOnly ?? false;
|
|
844
848
|
}, [options.readOnly]);
|
|
@@ -858,8 +862,11 @@ function useTsdrawCanvasController(options = {}) {
|
|
|
858
862
|
const ctx = canvas.getContext("2d");
|
|
859
863
|
if (!ctx) return;
|
|
860
864
|
const dpr = dprRef.current || 1;
|
|
865
|
+
const logicalWidth = canvas.width / dpr;
|
|
866
|
+
const logicalHeight = canvas.height / dpr;
|
|
861
867
|
ctx.setTransform(dpr, 0, 0, dpr, 0, 0);
|
|
862
|
-
ctx.clearRect(0, 0,
|
|
868
|
+
ctx.clearRect(0, 0, logicalWidth, logicalHeight);
|
|
869
|
+
renderCanvasBackground(ctx, editor.viewport, logicalWidth, logicalHeight, backgroundRef.current, editor.renderer.theme);
|
|
863
870
|
editor.render(ctx);
|
|
864
871
|
}, []);
|
|
865
872
|
const refreshSelectionBounds = useCallback((editor, ids = selectedShapeIdsRef.current) => {
|
|
@@ -1710,6 +1717,10 @@ function useTsdrawCanvasController(options = {}) {
|
|
|
1710
1717
|
editor.renderer.setTheme(options.theme ?? "light");
|
|
1711
1718
|
render();
|
|
1712
1719
|
}, [options.theme, render]);
|
|
1720
|
+
useEffect(() => {
|
|
1721
|
+
if (!editorRef.current) return;
|
|
1722
|
+
render();
|
|
1723
|
+
}, [options.background, render]);
|
|
1713
1724
|
const setTool = useCallback(
|
|
1714
1725
|
(tool) => {
|
|
1715
1726
|
const editor = editorRef.current;
|
|
@@ -1961,6 +1972,7 @@ function Tsdraw(props) {
|
|
|
1961
1972
|
touchOptions: props.touchOptions,
|
|
1962
1973
|
keyboardShortcuts: props.keyboardShortcuts,
|
|
1963
1974
|
penOptions: props.penOptions,
|
|
1975
|
+
background: props.background,
|
|
1964
1976
|
readOnly: props.readOnly,
|
|
1965
1977
|
autoFocus: props.autoFocus,
|
|
1966
1978
|
snapshot: props.snapshot,
|