@omer-x/svg-viewport 2.0.0 → 2.0.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
@@ -75,21 +75,23 @@ var SvgViewport = ({
75
75
  ...otherProps
76
76
  }) => {
77
77
  const isControlled = externalTransformation !== void 0;
78
- const [internalTransformation, setInternalTransformation] = (0, import_react.useState)(() => {
79
- if (isControlled) return null;
80
- return {
81
- zoom: 1,
82
- matrix: getFocusedMatrix(initialFocusPoint, width, height)
83
- };
84
- });
78
+ const [internalTransformation, setInternalTransformation] = (0, import_react.useState)(null);
79
+ const pointer = (0, import_react.useRef)({ x: 0, y: 0 });
80
+ const [grabbing, setGrabbing] = (0, import_react.useState)(false);
81
+ const [isPanning, setIsPanning] = (0, import_react.useState)(false);
85
82
  const transformation = isControlled ? externalTransformation : internalTransformation;
86
83
  const transformationRef = (0, import_react.useRef)(transformation);
87
84
  (0, import_react.useEffect)(() => {
88
85
  transformationRef.current = transformation;
89
86
  }, [transformation]);
90
- const pointer = (0, import_react.useRef)({ x: 0, y: 0 });
91
- const [grabbing, setGrabbing] = (0, import_react.useState)(false);
92
- const [isPanning, setIsPanning] = (0, import_react.useState)(false);
87
+ (0, import_react.useEffect)(() => {
88
+ if (!isControlled && !internalTransformation) {
89
+ setInternalTransformation({
90
+ zoom: 1,
91
+ matrix: getFocusedMatrix(initialFocusPoint, width, height)
92
+ });
93
+ }
94
+ }, []);
93
95
  const setTransformation = (0, import_react.useCallback)((value) => {
94
96
  if (!isControlled) {
95
97
  setInternalTransformation(value);
package/dist/index.js CHANGED
@@ -50,21 +50,23 @@ var SvgViewport = ({
50
50
  ...otherProps
51
51
  }) => {
52
52
  const isControlled = externalTransformation !== void 0;
53
- const [internalTransformation, setInternalTransformation] = useState(() => {
54
- if (isControlled) return null;
55
- return {
56
- zoom: 1,
57
- matrix: getFocusedMatrix(initialFocusPoint, width, height)
58
- };
59
- });
53
+ const [internalTransformation, setInternalTransformation] = useState(null);
54
+ const pointer = useRef({ x: 0, y: 0 });
55
+ const [grabbing, setGrabbing] = useState(false);
56
+ const [isPanning, setIsPanning] = useState(false);
60
57
  const transformation = isControlled ? externalTransformation : internalTransformation;
61
58
  const transformationRef = useRef(transformation);
62
59
  useEffect(() => {
63
60
  transformationRef.current = transformation;
64
61
  }, [transformation]);
65
- const pointer = useRef({ x: 0, y: 0 });
66
- const [grabbing, setGrabbing] = useState(false);
67
- const [isPanning, setIsPanning] = useState(false);
62
+ useEffect(() => {
63
+ if (!isControlled && !internalTransformation) {
64
+ setInternalTransformation({
65
+ zoom: 1,
66
+ matrix: getFocusedMatrix(initialFocusPoint, width, height)
67
+ });
68
+ }
69
+ }, []);
68
70
  const setTransformation = useCallback((value) => {
69
71
  if (!isControlled) {
70
72
  setInternalTransformation(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@omer-x/svg-viewport",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "description": "Provides a simple React component for displaying SVG content with zooming and panning capabilities",
5
5
  "keywords": [
6
6
  "react",