@dcg-overseas/number-line 1.0.0-beta.3 → 1.0.0-beta.4

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
@@ -289,7 +289,6 @@ function NumberLineProvider({
289
289
  onChange: onViewChange
290
290
  });
291
291
  const [liveStroke, setLiveStroke] = React.useState(null);
292
- const svgPoint = React.useRef(null);
293
292
  const [eraseHoverIds, setEraseHoverIds] = React.useState(/* @__PURE__ */ new Set());
294
293
  const eraseGesture = React.useRef(null);
295
294
  const createHistorySnapshot = React.useCallback(
@@ -319,20 +318,17 @@ function NumberLineProvider({
319
318
  drawing.resetStrokes,
320
319
  history.clear
321
320
  ]);
322
- const getLocalCoords = React.useCallback(
323
- (e) => {
324
- const svg = svgRef.current;
325
- if (!svg) return null;
326
- const ctm = svg.getScreenCTM();
327
- if (!ctm) return null;
328
- if (!svgPoint.current) svgPoint.current = svg.createSVGPoint();
329
- svgPoint.current.x = e.clientX;
330
- svgPoint.current.y = e.clientY;
331
- const pt = svgPoint.current.matrixTransform(ctm.inverse());
332
- return [pt.x, pt.y];
333
- },
334
- [svgRef]
335
- );
321
+ const getLocalCoords = React.useCallback((event) => {
322
+ const svg = svgRef.current;
323
+ if (!svg) return null;
324
+ const rect = svg.getBoundingClientRect();
325
+ const viewBox = svg.viewBox.baseVal;
326
+ if (rect.width <= 0 || rect.height <= 0 || viewBox.width <= 0 || viewBox.height <= 0) return null;
327
+ return [
328
+ viewBox.x + (event.clientX - rect.left) / rect.width * viewBox.width,
329
+ viewBox.y + (event.clientY - rect.top) / rect.height * viewBox.height
330
+ ];
331
+ }, [svgRef]);
336
332
  const strokeIdsNear = React.useCallback(
337
333
  (x, y, radius) => {
338
334
  const ids = [];
package/dist/index.js CHANGED
@@ -287,7 +287,6 @@ function NumberLineProvider({
287
287
  onChange: onViewChange
288
288
  });
289
289
  const [liveStroke, setLiveStroke] = useState(null);
290
- const svgPoint = useRef(null);
291
290
  const [eraseHoverIds, setEraseHoverIds] = useState(/* @__PURE__ */ new Set());
292
291
  const eraseGesture = useRef(null);
293
292
  const createHistorySnapshot = useCallback(
@@ -317,20 +316,17 @@ function NumberLineProvider({
317
316
  drawing.resetStrokes,
318
317
  history.clear
319
318
  ]);
320
- const getLocalCoords = useCallback(
321
- (e) => {
322
- const svg = svgRef.current;
323
- if (!svg) return null;
324
- const ctm = svg.getScreenCTM();
325
- if (!ctm) return null;
326
- if (!svgPoint.current) svgPoint.current = svg.createSVGPoint();
327
- svgPoint.current.x = e.clientX;
328
- svgPoint.current.y = e.clientY;
329
- const pt = svgPoint.current.matrixTransform(ctm.inverse());
330
- return [pt.x, pt.y];
331
- },
332
- [svgRef]
333
- );
319
+ const getLocalCoords = useCallback((event) => {
320
+ const svg = svgRef.current;
321
+ if (!svg) return null;
322
+ const rect = svg.getBoundingClientRect();
323
+ const viewBox = svg.viewBox.baseVal;
324
+ if (rect.width <= 0 || rect.height <= 0 || viewBox.width <= 0 || viewBox.height <= 0) return null;
325
+ return [
326
+ viewBox.x + (event.clientX - rect.left) / rect.width * viewBox.width,
327
+ viewBox.y + (event.clientY - rect.top) / rect.height * viewBox.height
328
+ ];
329
+ }, [svgRef]);
334
330
  const strokeIdsNear = useCallback(
335
331
  (x, y, radius) => {
336
332
  const ids = [];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dcg-overseas/number-line",
3
- "version": "1.0.0-beta.3",
3
+ "version": "1.0.0-beta.4",
4
4
  "description": "Interactive number line component with group arcs and freehand drawing",
5
5
  "type": "module",
6
6
  "license": "MIT",