hyperprop-charting-library 0.1.109 → 0.1.111

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.
@@ -3944,13 +3944,14 @@ function createChart(element, options = {}) {
3944
3944
  }
3945
3945
  return { index: barIndex, price: nearest };
3946
3946
  };
3947
- const drawingPointFromCanvas = (x, y) => {
3947
+ const drawingPointFromCanvas = (x, y, snap = true) => {
3948
3948
  if (!drawState) {
3949
3949
  return null;
3950
3950
  }
3951
3951
  const ratio = clamp((x - drawState.chartLeft) / drawState.chartWidth, 0, 1);
3952
3952
  const rawIndex = drawState.xStart + ratio * drawState.xSpan - 0.5;
3953
- const snapped = applyMagnet(y, rawIndex, priceFromCanvasY(y));
3953
+ const rawPrice = priceFromCanvasY(y);
3954
+ const snapped = snap ? applyMagnet(y, rawIndex, rawPrice) : { index: rawIndex, price: rawPrice };
3954
3955
  const nearestIndex = Math.round(snapped.index);
3955
3956
  const time = getTimeForIndex(nearestIndex);
3956
3957
  return {
@@ -4480,7 +4481,7 @@ function createChart(element, options = {}) {
4480
4481
  if (!drawingDragState) {
4481
4482
  return false;
4482
4483
  }
4483
- const currentPoint = drawingPointFromCanvas(x, y);
4484
+ const currentPoint = drawingPointFromCanvas(x, y, drawingDragState.target === "handle");
4484
4485
  if (!currentPoint) {
4485
4486
  return true;
4486
4487
  }
@@ -4616,52 +4617,55 @@ function createChart(element, options = {}) {
4616
4617
  return;
4617
4618
  }
4618
4619
  }
4619
- const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4620
- if (crosshairButtonRegion) {
4621
- crosshairPriceActionHandler?.({
4622
- x: point.x,
4623
- y: point.y,
4624
- price: crosshairButtonRegion.price
4625
- });
4626
- return;
4627
- }
4628
- const orderRegion = getOrderActionRegion(point.x, point.y);
4629
- if (orderRegion) {
4630
- if (orderRegion.draggable) {
4631
- activePointerId = event.pointerId;
4632
- const startPrice = roundToPricePrecision(orderRegion.line.price);
4633
- actionDragState = {
4620
+ const drawingToolCapturesPointer = activeDrawingTool !== null || draftDrawing !== null;
4621
+ if (!drawingToolCapturesPointer) {
4622
+ const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4623
+ if (crosshairButtonRegion) {
4624
+ crosshairPriceActionHandler?.({
4625
+ x: point.x,
4626
+ y: point.y,
4627
+ price: crosshairButtonRegion.price
4628
+ });
4629
+ return;
4630
+ }
4631
+ const orderRegion = getOrderActionRegion(point.x, point.y);
4632
+ if (orderRegion) {
4633
+ if (orderRegion.draggable) {
4634
+ activePointerId = event.pointerId;
4635
+ const startPrice = roundToPricePrecision(orderRegion.line.price);
4636
+ actionDragState = {
4637
+ orderId: orderRegion.orderId,
4638
+ action: orderRegion.action,
4639
+ startPrice,
4640
+ lastPrice: startPrice,
4641
+ moved: false
4642
+ };
4643
+ canvas.setPointerCapture(event.pointerId);
4644
+ canvas.style.cursor = "ns-resize";
4645
+ setCrosshairPoint(null);
4646
+ return;
4647
+ }
4648
+ setCrosshairPoint(null);
4649
+ orderActionHandler?.({
4634
4650
  orderId: orderRegion.orderId,
4635
4651
  action: orderRegion.action,
4636
- startPrice,
4637
- lastPrice: startPrice,
4638
- moved: false
4652
+ line: orderRegion.line
4653
+ });
4654
+ return;
4655
+ }
4656
+ const orderDragRegion = getOrderDragRegion(point.x, point.y);
4657
+ if (orderDragRegion) {
4658
+ activePointerId = event.pointerId;
4659
+ orderDragState = {
4660
+ orderId: orderDragRegion.orderId,
4661
+ startPrice: orderDragRegion.price,
4662
+ lastPrice: orderDragRegion.price
4639
4663
  };
4640
4664
  canvas.setPointerCapture(event.pointerId);
4641
4665
  canvas.style.cursor = "ns-resize";
4642
4666
  setCrosshairPoint(null);
4643
4667
  return;
4644
4668
  }
4645
- setCrosshairPoint(null);
4646
- orderActionHandler?.({
4647
- orderId: orderRegion.orderId,
4648
- action: orderRegion.action,
4649
- line: orderRegion.line
4650
- });
4651
- return;
4652
- }
4653
- const orderDragRegion = getOrderDragRegion(point.x, point.y);
4654
- if (orderDragRegion) {
4655
- activePointerId = event.pointerId;
4656
- orderDragState = {
4657
- orderId: orderDragRegion.orderId,
4658
- startPrice: orderDragRegion.price,
4659
- lastPrice: orderDragRegion.price
4660
- };
4661
- canvas.setPointerCapture(event.pointerId);
4662
- canvas.style.cursor = "ns-resize";
4663
- setCrosshairPoint(null);
4664
- return;
4665
4669
  }
4666
4670
  const region = getHitRegion(point.x, point.y);
4667
4671
  if (region === "outside") {
@@ -4679,7 +4683,7 @@ function createChart(element, options = {}) {
4679
4683
  y: point.y
4680
4684
  });
4681
4685
  if (!drawingHit.drawing.locked) {
4682
- const startCanvasPoint = drawingPointFromCanvas(point.x, point.y);
4686
+ const startCanvasPoint = drawingPointFromCanvas(point.x, point.y, false);
4683
4687
  if (startCanvasPoint) {
4684
4688
  drawingDragState = {
4685
4689
  drawingId: drawingHit.drawing.id,
@@ -4838,23 +4842,26 @@ function createChart(element, options = {}) {
4838
4842
  return;
4839
4843
  }
4840
4844
  if (!isDragging || !dragMode) {
4841
- const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4842
- if (crosshairButtonRegion) {
4843
- canvas.style.cursor = "pointer";
4844
- setCrosshairPoint(point);
4845
- return;
4846
- }
4847
- const orderRegion = getOrderActionRegion(point.x, point.y);
4848
- if (orderRegion) {
4849
- canvas.style.cursor = orderRegion.draggable ? "ns-resize" : "pointer";
4850
- setCrosshairPoint(null);
4851
- return;
4852
- }
4853
- const orderDragRegion = getOrderDragRegion(point.x, point.y);
4854
- if (orderDragRegion) {
4855
- canvas.style.cursor = "ns-resize";
4856
- setCrosshairPoint(null);
4857
- return;
4845
+ const drawingToolOwnsHover = activeDrawingTool !== null || draftDrawing !== null;
4846
+ if (!drawingToolOwnsHover) {
4847
+ const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4848
+ if (crosshairButtonRegion) {
4849
+ canvas.style.cursor = "pointer";
4850
+ setCrosshairPoint(point);
4851
+ return;
4852
+ }
4853
+ const orderRegion = getOrderActionRegion(point.x, point.y);
4854
+ if (orderRegion) {
4855
+ canvas.style.cursor = orderRegion.draggable ? "ns-resize" : "pointer";
4856
+ setCrosshairPoint(null);
4857
+ return;
4858
+ }
4859
+ const orderDragRegion = getOrderDragRegion(point.x, point.y);
4860
+ if (orderDragRegion) {
4861
+ canvas.style.cursor = "ns-resize";
4862
+ setCrosshairPoint(null);
4863
+ return;
4864
+ }
4858
4865
  }
4859
4866
  if (!activeDrawingTool && getDrawingHit(point.x, point.y)) {
4860
4867
  const drawingHit = getDrawingHit(point.x, point.y);
@@ -3918,13 +3918,14 @@ function createChart(element, options = {}) {
3918
3918
  }
3919
3919
  return { index: barIndex, price: nearest };
3920
3920
  };
3921
- const drawingPointFromCanvas = (x, y) => {
3921
+ const drawingPointFromCanvas = (x, y, snap = true) => {
3922
3922
  if (!drawState) {
3923
3923
  return null;
3924
3924
  }
3925
3925
  const ratio = clamp((x - drawState.chartLeft) / drawState.chartWidth, 0, 1);
3926
3926
  const rawIndex = drawState.xStart + ratio * drawState.xSpan - 0.5;
3927
- const snapped = applyMagnet(y, rawIndex, priceFromCanvasY(y));
3927
+ const rawPrice = priceFromCanvasY(y);
3928
+ const snapped = snap ? applyMagnet(y, rawIndex, rawPrice) : { index: rawIndex, price: rawPrice };
3928
3929
  const nearestIndex = Math.round(snapped.index);
3929
3930
  const time = getTimeForIndex(nearestIndex);
3930
3931
  return {
@@ -4454,7 +4455,7 @@ function createChart(element, options = {}) {
4454
4455
  if (!drawingDragState) {
4455
4456
  return false;
4456
4457
  }
4457
- const currentPoint = drawingPointFromCanvas(x, y);
4458
+ const currentPoint = drawingPointFromCanvas(x, y, drawingDragState.target === "handle");
4458
4459
  if (!currentPoint) {
4459
4460
  return true;
4460
4461
  }
@@ -4590,52 +4591,55 @@ function createChart(element, options = {}) {
4590
4591
  return;
4591
4592
  }
4592
4593
  }
4593
- const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4594
- if (crosshairButtonRegion) {
4595
- crosshairPriceActionHandler?.({
4596
- x: point.x,
4597
- y: point.y,
4598
- price: crosshairButtonRegion.price
4599
- });
4600
- return;
4601
- }
4602
- const orderRegion = getOrderActionRegion(point.x, point.y);
4603
- if (orderRegion) {
4604
- if (orderRegion.draggable) {
4605
- activePointerId = event.pointerId;
4606
- const startPrice = roundToPricePrecision(orderRegion.line.price);
4607
- actionDragState = {
4594
+ const drawingToolCapturesPointer = activeDrawingTool !== null || draftDrawing !== null;
4595
+ if (!drawingToolCapturesPointer) {
4596
+ const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4597
+ if (crosshairButtonRegion) {
4598
+ crosshairPriceActionHandler?.({
4599
+ x: point.x,
4600
+ y: point.y,
4601
+ price: crosshairButtonRegion.price
4602
+ });
4603
+ return;
4604
+ }
4605
+ const orderRegion = getOrderActionRegion(point.x, point.y);
4606
+ if (orderRegion) {
4607
+ if (orderRegion.draggable) {
4608
+ activePointerId = event.pointerId;
4609
+ const startPrice = roundToPricePrecision(orderRegion.line.price);
4610
+ actionDragState = {
4611
+ orderId: orderRegion.orderId,
4612
+ action: orderRegion.action,
4613
+ startPrice,
4614
+ lastPrice: startPrice,
4615
+ moved: false
4616
+ };
4617
+ canvas.setPointerCapture(event.pointerId);
4618
+ canvas.style.cursor = "ns-resize";
4619
+ setCrosshairPoint(null);
4620
+ return;
4621
+ }
4622
+ setCrosshairPoint(null);
4623
+ orderActionHandler?.({
4608
4624
  orderId: orderRegion.orderId,
4609
4625
  action: orderRegion.action,
4610
- startPrice,
4611
- lastPrice: startPrice,
4612
- moved: false
4626
+ line: orderRegion.line
4627
+ });
4628
+ return;
4629
+ }
4630
+ const orderDragRegion = getOrderDragRegion(point.x, point.y);
4631
+ if (orderDragRegion) {
4632
+ activePointerId = event.pointerId;
4633
+ orderDragState = {
4634
+ orderId: orderDragRegion.orderId,
4635
+ startPrice: orderDragRegion.price,
4636
+ lastPrice: orderDragRegion.price
4613
4637
  };
4614
4638
  canvas.setPointerCapture(event.pointerId);
4615
4639
  canvas.style.cursor = "ns-resize";
4616
4640
  setCrosshairPoint(null);
4617
4641
  return;
4618
4642
  }
4619
- setCrosshairPoint(null);
4620
- orderActionHandler?.({
4621
- orderId: orderRegion.orderId,
4622
- action: orderRegion.action,
4623
- line: orderRegion.line
4624
- });
4625
- return;
4626
- }
4627
- const orderDragRegion = getOrderDragRegion(point.x, point.y);
4628
- if (orderDragRegion) {
4629
- activePointerId = event.pointerId;
4630
- orderDragState = {
4631
- orderId: orderDragRegion.orderId,
4632
- startPrice: orderDragRegion.price,
4633
- lastPrice: orderDragRegion.price
4634
- };
4635
- canvas.setPointerCapture(event.pointerId);
4636
- canvas.style.cursor = "ns-resize";
4637
- setCrosshairPoint(null);
4638
- return;
4639
4643
  }
4640
4644
  const region = getHitRegion(point.x, point.y);
4641
4645
  if (region === "outside") {
@@ -4653,7 +4657,7 @@ function createChart(element, options = {}) {
4653
4657
  y: point.y
4654
4658
  });
4655
4659
  if (!drawingHit.drawing.locked) {
4656
- const startCanvasPoint = drawingPointFromCanvas(point.x, point.y);
4660
+ const startCanvasPoint = drawingPointFromCanvas(point.x, point.y, false);
4657
4661
  if (startCanvasPoint) {
4658
4662
  drawingDragState = {
4659
4663
  drawingId: drawingHit.drawing.id,
@@ -4812,23 +4816,26 @@ function createChart(element, options = {}) {
4812
4816
  return;
4813
4817
  }
4814
4818
  if (!isDragging || !dragMode) {
4815
- const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4816
- if (crosshairButtonRegion) {
4817
- canvas.style.cursor = "pointer";
4818
- setCrosshairPoint(point);
4819
- return;
4820
- }
4821
- const orderRegion = getOrderActionRegion(point.x, point.y);
4822
- if (orderRegion) {
4823
- canvas.style.cursor = orderRegion.draggable ? "ns-resize" : "pointer";
4824
- setCrosshairPoint(null);
4825
- return;
4826
- }
4827
- const orderDragRegion = getOrderDragRegion(point.x, point.y);
4828
- if (orderDragRegion) {
4829
- canvas.style.cursor = "ns-resize";
4830
- setCrosshairPoint(null);
4831
- return;
4819
+ const drawingToolOwnsHover = activeDrawingTool !== null || draftDrawing !== null;
4820
+ if (!drawingToolOwnsHover) {
4821
+ const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4822
+ if (crosshairButtonRegion) {
4823
+ canvas.style.cursor = "pointer";
4824
+ setCrosshairPoint(point);
4825
+ return;
4826
+ }
4827
+ const orderRegion = getOrderActionRegion(point.x, point.y);
4828
+ if (orderRegion) {
4829
+ canvas.style.cursor = orderRegion.draggable ? "ns-resize" : "pointer";
4830
+ setCrosshairPoint(null);
4831
+ return;
4832
+ }
4833
+ const orderDragRegion = getOrderDragRegion(point.x, point.y);
4834
+ if (orderDragRegion) {
4835
+ canvas.style.cursor = "ns-resize";
4836
+ setCrosshairPoint(null);
4837
+ return;
4838
+ }
4832
4839
  }
4833
4840
  if (!activeDrawingTool && getDrawingHit(point.x, point.y)) {
4834
4841
  const drawingHit = getDrawingHit(point.x, point.y);
package/dist/index.cjs CHANGED
@@ -3944,13 +3944,14 @@ function createChart(element, options = {}) {
3944
3944
  }
3945
3945
  return { index: barIndex, price: nearest };
3946
3946
  };
3947
- const drawingPointFromCanvas = (x, y) => {
3947
+ const drawingPointFromCanvas = (x, y, snap = true) => {
3948
3948
  if (!drawState) {
3949
3949
  return null;
3950
3950
  }
3951
3951
  const ratio = clamp((x - drawState.chartLeft) / drawState.chartWidth, 0, 1);
3952
3952
  const rawIndex = drawState.xStart + ratio * drawState.xSpan - 0.5;
3953
- const snapped = applyMagnet(y, rawIndex, priceFromCanvasY(y));
3953
+ const rawPrice = priceFromCanvasY(y);
3954
+ const snapped = snap ? applyMagnet(y, rawIndex, rawPrice) : { index: rawIndex, price: rawPrice };
3954
3955
  const nearestIndex = Math.round(snapped.index);
3955
3956
  const time = getTimeForIndex(nearestIndex);
3956
3957
  return {
@@ -4480,7 +4481,7 @@ function createChart(element, options = {}) {
4480
4481
  if (!drawingDragState) {
4481
4482
  return false;
4482
4483
  }
4483
- const currentPoint = drawingPointFromCanvas(x, y);
4484
+ const currentPoint = drawingPointFromCanvas(x, y, drawingDragState.target === "handle");
4484
4485
  if (!currentPoint) {
4485
4486
  return true;
4486
4487
  }
@@ -4616,52 +4617,55 @@ function createChart(element, options = {}) {
4616
4617
  return;
4617
4618
  }
4618
4619
  }
4619
- const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4620
- if (crosshairButtonRegion) {
4621
- crosshairPriceActionHandler?.({
4622
- x: point.x,
4623
- y: point.y,
4624
- price: crosshairButtonRegion.price
4625
- });
4626
- return;
4627
- }
4628
- const orderRegion = getOrderActionRegion(point.x, point.y);
4629
- if (orderRegion) {
4630
- if (orderRegion.draggable) {
4631
- activePointerId = event.pointerId;
4632
- const startPrice = roundToPricePrecision(orderRegion.line.price);
4633
- actionDragState = {
4620
+ const drawingToolCapturesPointer = activeDrawingTool !== null || draftDrawing !== null;
4621
+ if (!drawingToolCapturesPointer) {
4622
+ const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4623
+ if (crosshairButtonRegion) {
4624
+ crosshairPriceActionHandler?.({
4625
+ x: point.x,
4626
+ y: point.y,
4627
+ price: crosshairButtonRegion.price
4628
+ });
4629
+ return;
4630
+ }
4631
+ const orderRegion = getOrderActionRegion(point.x, point.y);
4632
+ if (orderRegion) {
4633
+ if (orderRegion.draggable) {
4634
+ activePointerId = event.pointerId;
4635
+ const startPrice = roundToPricePrecision(orderRegion.line.price);
4636
+ actionDragState = {
4637
+ orderId: orderRegion.orderId,
4638
+ action: orderRegion.action,
4639
+ startPrice,
4640
+ lastPrice: startPrice,
4641
+ moved: false
4642
+ };
4643
+ canvas.setPointerCapture(event.pointerId);
4644
+ canvas.style.cursor = "ns-resize";
4645
+ setCrosshairPoint(null);
4646
+ return;
4647
+ }
4648
+ setCrosshairPoint(null);
4649
+ orderActionHandler?.({
4634
4650
  orderId: orderRegion.orderId,
4635
4651
  action: orderRegion.action,
4636
- startPrice,
4637
- lastPrice: startPrice,
4638
- moved: false
4652
+ line: orderRegion.line
4653
+ });
4654
+ return;
4655
+ }
4656
+ const orderDragRegion = getOrderDragRegion(point.x, point.y);
4657
+ if (orderDragRegion) {
4658
+ activePointerId = event.pointerId;
4659
+ orderDragState = {
4660
+ orderId: orderDragRegion.orderId,
4661
+ startPrice: orderDragRegion.price,
4662
+ lastPrice: orderDragRegion.price
4639
4663
  };
4640
4664
  canvas.setPointerCapture(event.pointerId);
4641
4665
  canvas.style.cursor = "ns-resize";
4642
4666
  setCrosshairPoint(null);
4643
4667
  return;
4644
4668
  }
4645
- setCrosshairPoint(null);
4646
- orderActionHandler?.({
4647
- orderId: orderRegion.orderId,
4648
- action: orderRegion.action,
4649
- line: orderRegion.line
4650
- });
4651
- return;
4652
- }
4653
- const orderDragRegion = getOrderDragRegion(point.x, point.y);
4654
- if (orderDragRegion) {
4655
- activePointerId = event.pointerId;
4656
- orderDragState = {
4657
- orderId: orderDragRegion.orderId,
4658
- startPrice: orderDragRegion.price,
4659
- lastPrice: orderDragRegion.price
4660
- };
4661
- canvas.setPointerCapture(event.pointerId);
4662
- canvas.style.cursor = "ns-resize";
4663
- setCrosshairPoint(null);
4664
- return;
4665
4669
  }
4666
4670
  const region = getHitRegion(point.x, point.y);
4667
4671
  if (region === "outside") {
@@ -4679,7 +4683,7 @@ function createChart(element, options = {}) {
4679
4683
  y: point.y
4680
4684
  });
4681
4685
  if (!drawingHit.drawing.locked) {
4682
- const startCanvasPoint = drawingPointFromCanvas(point.x, point.y);
4686
+ const startCanvasPoint = drawingPointFromCanvas(point.x, point.y, false);
4683
4687
  if (startCanvasPoint) {
4684
4688
  drawingDragState = {
4685
4689
  drawingId: drawingHit.drawing.id,
@@ -4838,23 +4842,26 @@ function createChart(element, options = {}) {
4838
4842
  return;
4839
4843
  }
4840
4844
  if (!isDragging || !dragMode) {
4841
- const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4842
- if (crosshairButtonRegion) {
4843
- canvas.style.cursor = "pointer";
4844
- setCrosshairPoint(point);
4845
- return;
4846
- }
4847
- const orderRegion = getOrderActionRegion(point.x, point.y);
4848
- if (orderRegion) {
4849
- canvas.style.cursor = orderRegion.draggable ? "ns-resize" : "pointer";
4850
- setCrosshairPoint(null);
4851
- return;
4852
- }
4853
- const orderDragRegion = getOrderDragRegion(point.x, point.y);
4854
- if (orderDragRegion) {
4855
- canvas.style.cursor = "ns-resize";
4856
- setCrosshairPoint(null);
4857
- return;
4845
+ const drawingToolOwnsHover = activeDrawingTool !== null || draftDrawing !== null;
4846
+ if (!drawingToolOwnsHover) {
4847
+ const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4848
+ if (crosshairButtonRegion) {
4849
+ canvas.style.cursor = "pointer";
4850
+ setCrosshairPoint(point);
4851
+ return;
4852
+ }
4853
+ const orderRegion = getOrderActionRegion(point.x, point.y);
4854
+ if (orderRegion) {
4855
+ canvas.style.cursor = orderRegion.draggable ? "ns-resize" : "pointer";
4856
+ setCrosshairPoint(null);
4857
+ return;
4858
+ }
4859
+ const orderDragRegion = getOrderDragRegion(point.x, point.y);
4860
+ if (orderDragRegion) {
4861
+ canvas.style.cursor = "ns-resize";
4862
+ setCrosshairPoint(null);
4863
+ return;
4864
+ }
4858
4865
  }
4859
4866
  if (!activeDrawingTool && getDrawingHit(point.x, point.y)) {
4860
4867
  const drawingHit = getDrawingHit(point.x, point.y);
package/dist/index.js CHANGED
@@ -3918,13 +3918,14 @@ function createChart(element, options = {}) {
3918
3918
  }
3919
3919
  return { index: barIndex, price: nearest };
3920
3920
  };
3921
- const drawingPointFromCanvas = (x, y) => {
3921
+ const drawingPointFromCanvas = (x, y, snap = true) => {
3922
3922
  if (!drawState) {
3923
3923
  return null;
3924
3924
  }
3925
3925
  const ratio = clamp((x - drawState.chartLeft) / drawState.chartWidth, 0, 1);
3926
3926
  const rawIndex = drawState.xStart + ratio * drawState.xSpan - 0.5;
3927
- const snapped = applyMagnet(y, rawIndex, priceFromCanvasY(y));
3927
+ const rawPrice = priceFromCanvasY(y);
3928
+ const snapped = snap ? applyMagnet(y, rawIndex, rawPrice) : { index: rawIndex, price: rawPrice };
3928
3929
  const nearestIndex = Math.round(snapped.index);
3929
3930
  const time = getTimeForIndex(nearestIndex);
3930
3931
  return {
@@ -4454,7 +4455,7 @@ function createChart(element, options = {}) {
4454
4455
  if (!drawingDragState) {
4455
4456
  return false;
4456
4457
  }
4457
- const currentPoint = drawingPointFromCanvas(x, y);
4458
+ const currentPoint = drawingPointFromCanvas(x, y, drawingDragState.target === "handle");
4458
4459
  if (!currentPoint) {
4459
4460
  return true;
4460
4461
  }
@@ -4590,52 +4591,55 @@ function createChart(element, options = {}) {
4590
4591
  return;
4591
4592
  }
4592
4593
  }
4593
- const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4594
- if (crosshairButtonRegion) {
4595
- crosshairPriceActionHandler?.({
4596
- x: point.x,
4597
- y: point.y,
4598
- price: crosshairButtonRegion.price
4599
- });
4600
- return;
4601
- }
4602
- const orderRegion = getOrderActionRegion(point.x, point.y);
4603
- if (orderRegion) {
4604
- if (orderRegion.draggable) {
4605
- activePointerId = event.pointerId;
4606
- const startPrice = roundToPricePrecision(orderRegion.line.price);
4607
- actionDragState = {
4594
+ const drawingToolCapturesPointer = activeDrawingTool !== null || draftDrawing !== null;
4595
+ if (!drawingToolCapturesPointer) {
4596
+ const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4597
+ if (crosshairButtonRegion) {
4598
+ crosshairPriceActionHandler?.({
4599
+ x: point.x,
4600
+ y: point.y,
4601
+ price: crosshairButtonRegion.price
4602
+ });
4603
+ return;
4604
+ }
4605
+ const orderRegion = getOrderActionRegion(point.x, point.y);
4606
+ if (orderRegion) {
4607
+ if (orderRegion.draggable) {
4608
+ activePointerId = event.pointerId;
4609
+ const startPrice = roundToPricePrecision(orderRegion.line.price);
4610
+ actionDragState = {
4611
+ orderId: orderRegion.orderId,
4612
+ action: orderRegion.action,
4613
+ startPrice,
4614
+ lastPrice: startPrice,
4615
+ moved: false
4616
+ };
4617
+ canvas.setPointerCapture(event.pointerId);
4618
+ canvas.style.cursor = "ns-resize";
4619
+ setCrosshairPoint(null);
4620
+ return;
4621
+ }
4622
+ setCrosshairPoint(null);
4623
+ orderActionHandler?.({
4608
4624
  orderId: orderRegion.orderId,
4609
4625
  action: orderRegion.action,
4610
- startPrice,
4611
- lastPrice: startPrice,
4612
- moved: false
4626
+ line: orderRegion.line
4627
+ });
4628
+ return;
4629
+ }
4630
+ const orderDragRegion = getOrderDragRegion(point.x, point.y);
4631
+ if (orderDragRegion) {
4632
+ activePointerId = event.pointerId;
4633
+ orderDragState = {
4634
+ orderId: orderDragRegion.orderId,
4635
+ startPrice: orderDragRegion.price,
4636
+ lastPrice: orderDragRegion.price
4613
4637
  };
4614
4638
  canvas.setPointerCapture(event.pointerId);
4615
4639
  canvas.style.cursor = "ns-resize";
4616
4640
  setCrosshairPoint(null);
4617
4641
  return;
4618
4642
  }
4619
- setCrosshairPoint(null);
4620
- orderActionHandler?.({
4621
- orderId: orderRegion.orderId,
4622
- action: orderRegion.action,
4623
- line: orderRegion.line
4624
- });
4625
- return;
4626
- }
4627
- const orderDragRegion = getOrderDragRegion(point.x, point.y);
4628
- if (orderDragRegion) {
4629
- activePointerId = event.pointerId;
4630
- orderDragState = {
4631
- orderId: orderDragRegion.orderId,
4632
- startPrice: orderDragRegion.price,
4633
- lastPrice: orderDragRegion.price
4634
- };
4635
- canvas.setPointerCapture(event.pointerId);
4636
- canvas.style.cursor = "ns-resize";
4637
- setCrosshairPoint(null);
4638
- return;
4639
4643
  }
4640
4644
  const region = getHitRegion(point.x, point.y);
4641
4645
  if (region === "outside") {
@@ -4653,7 +4657,7 @@ function createChart(element, options = {}) {
4653
4657
  y: point.y
4654
4658
  });
4655
4659
  if (!drawingHit.drawing.locked) {
4656
- const startCanvasPoint = drawingPointFromCanvas(point.x, point.y);
4660
+ const startCanvasPoint = drawingPointFromCanvas(point.x, point.y, false);
4657
4661
  if (startCanvasPoint) {
4658
4662
  drawingDragState = {
4659
4663
  drawingId: drawingHit.drawing.id,
@@ -4812,23 +4816,26 @@ function createChart(element, options = {}) {
4812
4816
  return;
4813
4817
  }
4814
4818
  if (!isDragging || !dragMode) {
4815
- const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4816
- if (crosshairButtonRegion) {
4817
- canvas.style.cursor = "pointer";
4818
- setCrosshairPoint(point);
4819
- return;
4820
- }
4821
- const orderRegion = getOrderActionRegion(point.x, point.y);
4822
- if (orderRegion) {
4823
- canvas.style.cursor = orderRegion.draggable ? "ns-resize" : "pointer";
4824
- setCrosshairPoint(null);
4825
- return;
4826
- }
4827
- const orderDragRegion = getOrderDragRegion(point.x, point.y);
4828
- if (orderDragRegion) {
4829
- canvas.style.cursor = "ns-resize";
4830
- setCrosshairPoint(null);
4831
- return;
4819
+ const drawingToolOwnsHover = activeDrawingTool !== null || draftDrawing !== null;
4820
+ if (!drawingToolOwnsHover) {
4821
+ const crosshairButtonRegion = getCrosshairPriceActionRegion(point.x, point.y);
4822
+ if (crosshairButtonRegion) {
4823
+ canvas.style.cursor = "pointer";
4824
+ setCrosshairPoint(point);
4825
+ return;
4826
+ }
4827
+ const orderRegion = getOrderActionRegion(point.x, point.y);
4828
+ if (orderRegion) {
4829
+ canvas.style.cursor = orderRegion.draggable ? "ns-resize" : "pointer";
4830
+ setCrosshairPoint(null);
4831
+ return;
4832
+ }
4833
+ const orderDragRegion = getOrderDragRegion(point.x, point.y);
4834
+ if (orderDragRegion) {
4835
+ canvas.style.cursor = "ns-resize";
4836
+ setCrosshairPoint(null);
4837
+ return;
4838
+ }
4832
4839
  }
4833
4840
  if (!activeDrawingTool && getDrawingHit(point.x, point.y)) {
4834
4841
  const drawingHit = getDrawingHit(point.x, point.y);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "hyperprop-charting-library",
3
- "version": "0.1.109",
3
+ "version": "0.1.111",
4
4
  "description": "Lightweight TypeScript charting core",
5
5
  "type": "module",
6
6
  "main": "./dist/hyperprop-charting-library.cjs",