@deepnoid/canvas 0.1.26 → 0.1.27

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.
@@ -132,63 +132,20 @@ export const usePanZoom = ({ canvasRef, imageRef, panZoomable = false, resetOnIm
132
132
  redraw();
133
133
  }, [moveX, moveY, zoomX, zoomY, zoom, dx, dy, dw, dh, imageOnloadCount, canvasRef, imageRef]);
134
134
  useEffect(() => {
135
- if (!imageRef?.current || !canvasRef?.current)
135
+ if (!imageRef?.current || !canvasRef?.current || !width || !height)
136
136
  return;
137
137
  const canvasEl = resolutionCanvas(canvasRef.current);
138
138
  if (!canvasEl)
139
139
  return;
140
- if (resetOnImageChange) {
141
- if (width && height) {
142
- console.log('> init (resetOnImageChange true)');
143
- init(canvasEl, imageRef.current);
144
- setImageOnloadCount((prev) => prev + 1);
145
- }
140
+ const isFirstLoad = imageOnloadCount === 0;
141
+ if (isFirstLoad || resetOnImageChange) {
142
+ init(canvasEl, imageRef.current);
146
143
  }
147
144
  else {
148
145
  drawCanvas(moveX, moveY, zoomX, zoomY, zoom, dx, dy, canvasEl, imageRef.current, true);
149
146
  }
147
+ setImageOnloadCount((prev) => prev + 1);
150
148
  }, [imageRef?.current, width, height, resetOnImageChange]);
151
- useEffect(() => {
152
- if (!imageRef?.current || !canvasRef?.current)
153
- return;
154
- const canvasEl = resolutionCanvas(canvasRef.current);
155
- if (!canvasEl)
156
- return;
157
- if (!resetOnImageChange) {
158
- if (width && height) {
159
- console.log('> init (resetOnImageChange false, width/height ready)');
160
- init(canvasEl, imageRef.current);
161
- setImageOnloadCount((prev) => prev + 1);
162
- }
163
- else {
164
- drawCanvas(moveX, moveY, zoomX, zoomY, zoom, dx, dy, canvasEl, imageRef.current, true);
165
- }
166
- }
167
- }, [width, height, resetOnImageChange]);
168
- // useEffect(() => {
169
- // if (!imageRef?.current || !canvasRef?.current || !width || !height) {
170
- // console.log(888888888888888888888);
171
- // return;
172
- // }
173
- // console.log(11111111111111111111111111111);
174
- // if (resetOnImageChange) {
175
- // const canvasEl = resolutionCanvas(canvasRef.current);
176
- // if (canvasEl) init(canvasEl, imageRef.current);
177
- // }
178
- // setImageOnloadCount((prev) => prev + 1);
179
- // }, [imageRef?.current]);
180
- // useEffect(() => {
181
- // if (!imageRef?.current || !canvasRef?.current || !width || !height) {
182
- // console.log(99999999999999999999999);
183
- // return;
184
- // }
185
- // const canvasEl = resolutionCanvas(canvasRef.current);
186
- // if (canvasEl && !resetOnImageChange) {
187
- // console.log(333333333333333333333333333333);
188
- // init(canvasEl, imageRef.current);
189
- // }
190
- // setImageOnloadCount((prev) => prev + 1);
191
- // }, [width, height]);
192
149
  return {
193
150
  moveX,
194
151
  moveY,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@deepnoid/canvas",
3
- "version": "0.1.26",
3
+ "version": "0.1.27",
4
4
  "type": "module",
5
5
  "license": "MIT",
6
6
  "main": "./dist/index.cjs",