@fieldnotes/core 0.30.0 → 0.31.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.d.cts CHANGED
@@ -763,6 +763,7 @@ declare class SelectTool implements Tool {
763
763
  private setHovered;
764
764
  private handleResize;
765
765
  private hitTestResizeHandle;
766
+ private hitTestLineHandles;
766
767
  private getHandlePositions;
767
768
  private renderMarquee;
768
769
  private renderSelectionBoxes;
@@ -971,6 +972,6 @@ declare class TemplateTool implements Tool {
971
972
  private notifyOptionsChange;
972
973
  }
973
974
 
974
- declare const VERSION = "0.30.0";
975
+ declare const VERSION = "0.31.0";
975
976
 
976
977
  export { type ActiveFormats, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportImageOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, boundsIntersect, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
package/dist/index.d.ts CHANGED
@@ -763,6 +763,7 @@ declare class SelectTool implements Tool {
763
763
  private setHovered;
764
764
  private handleResize;
765
765
  private hitTestResizeHandle;
766
+ private hitTestLineHandles;
766
767
  private getHandlePositions;
767
768
  private renderMarquee;
768
769
  private renderSelectionBoxes;
@@ -971,6 +972,6 @@ declare class TemplateTool implements Tool {
971
972
  private notifyOptionsChange;
972
973
  }
973
974
 
974
- declare const VERSION = "0.30.0";
975
+ declare const VERSION = "0.31.0";
975
976
 
976
977
  export { type ActiveFormats, type ArrowElement, ArrowTool, type ArrowToolOptions, AutoSave, type AutoSaveOptions, type BackgroundOptions, type BackgroundPattern, type Binding, type Bounds, Camera, type CameraChangeInfo, type CameraOptions, type CanvasElement, type CanvasState, type Command, DEFAULT_NOTE_FONT_SIZE, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportImageOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, type Layer, LayerManager, MeasureTool, type MeasureToolOptions, type Measurement, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateShape, TemplateTool, type TemplateToolOptions, type TextElement, TextTool, type TextToolOptions, type Tool, type ToolContext, ToolManager, type ToolName, VERSION, Viewport, type ViewportOptions, boundsIntersect, createArrow, createGrid, createHtmlElement, createImage, createNote, createShape, createStroke, createTemplate, createText, drawHexPath, exportImage, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
package/dist/index.js CHANGED
@@ -2196,6 +2196,13 @@ function getArrowRenderGeometry(arrow) {
2196
2196
  }
2197
2197
 
2198
2198
  // src/elements/shape-geometry.ts
2199
+ function lineFromEndpoints(a, b) {
2200
+ return {
2201
+ position: { x: Math.min(a.x, b.x), y: Math.min(a.y, b.y) },
2202
+ size: { w: Math.abs(b.x - a.x), h: Math.abs(b.y - a.y) },
2203
+ flip: b.x > a.x !== b.y > a.y
2204
+ };
2205
+ }
2199
2206
  function lineEndpoints(shape) {
2200
2207
  const { x, y } = shape.position;
2201
2208
  const { w, h } = shape.size;
@@ -6601,6 +6608,12 @@ var SelectTool = class {
6601
6608
  ctx.requestRender();
6602
6609
  return;
6603
6610
  }
6611
+ const lineHit = this.hitTestLineHandles(world, ctx);
6612
+ if (lineHit) {
6613
+ this.mode = { type: "line-handle", elementId: lineHit.elementId, fixed: lineHit.fixed };
6614
+ ctx.requestRender();
6615
+ return;
6616
+ }
6604
6617
  const templateResizeHit = this.hitTestTemplateResizeHandle(world, ctx);
6605
6618
  if (templateResizeHit) {
6606
6619
  this.mode = { type: "resizing-template", elementId: templateResizeHit };
@@ -6656,6 +6669,15 @@ var SelectTool = class {
6656
6669
  applyArrowHandleDrag(this.mode.handle, this.mode.elementId, world, ctx);
6657
6670
  return;
6658
6671
  }
6672
+ if (this.mode.type === "line-handle") {
6673
+ ctx.setCursor?.("grabbing");
6674
+ const el = ctx.store.getById(this.mode.elementId);
6675
+ if (el && el.type === "shape") {
6676
+ ctx.store.update(el.id, lineFromEndpoints(this.mode.fixed, world));
6677
+ }
6678
+ ctx.requestRender();
6679
+ return;
6680
+ }
6659
6681
  if (this.mode.type === "resizing-template") {
6660
6682
  ctx.setCursor?.("nwse-resize");
6661
6683
  this.handleTemplateResize(world, ctx);
@@ -6824,6 +6846,10 @@ var SelectTool = class {
6824
6846
  ctx.setCursor?.(getArrowHandleCursor(arrowHit.handle, false));
6825
6847
  return null;
6826
6848
  }
6849
+ if (this.hitTestLineHandles(world, ctx)) {
6850
+ ctx.setCursor?.("grab");
6851
+ return null;
6852
+ }
6827
6853
  const templateResizeHit = this.hitTestTemplateResizeHandle(world, ctx);
6828
6854
  if (templateResizeHit) {
6829
6855
  ctx.setCursor?.("nwse-resize");
@@ -6911,6 +6937,7 @@ var SelectTool = class {
6911
6937
  for (const id of this._selectedIds) {
6912
6938
  const el = ctx.store.getById(id);
6913
6939
  if (!el || !("size" in el)) continue;
6940
+ if (el.type === "shape" && el.shape === "line") continue;
6914
6941
  const bounds = getElementBounds(el);
6915
6942
  if (!bounds) continue;
6916
6943
  const corners = this.getHandlePositions(bounds);
@@ -6922,6 +6949,20 @@ var SelectTool = class {
6922
6949
  }
6923
6950
  return null;
6924
6951
  }
6952
+ hitTestLineHandles(world, ctx) {
6953
+ if (this._selectedIds.length === 0) return null;
6954
+ const zoom = ctx.camera.zoom;
6955
+ const r = (HANDLE_SIZE / 2 + HANDLE_HIT_PADDING2) / zoom;
6956
+ const r2 = r * r;
6957
+ for (const id of this._selectedIds) {
6958
+ const el = ctx.store.getById(id);
6959
+ if (!el || el.type !== "shape" || el.shape !== "line") continue;
6960
+ const [a, b] = lineEndpoints(el);
6961
+ if ((world.x - a.x) ** 2 + (world.y - a.y) ** 2 <= r2) return { elementId: id, fixed: b };
6962
+ if ((world.x - b.x) ** 2 + (world.y - b.y) ** 2 <= r2) return { elementId: id, fixed: a };
6963
+ }
6964
+ return null;
6965
+ }
6925
6966
  getHandlePositions(bounds) {
6926
6967
  return [
6927
6968
  ["nw", { x: bounds.x, y: bounds.y }],
@@ -6959,6 +7000,19 @@ var SelectTool = class {
6959
7000
  this.renderBindingHighlights(canvasCtx, el, zoom);
6960
7001
  continue;
6961
7002
  }
7003
+ if (el.type === "shape" && el.shape === "line") {
7004
+ canvasCtx.setLineDash([]);
7005
+ canvasCtx.fillStyle = "#ffffff";
7006
+ const r = handleWorldSize / 2;
7007
+ for (const p of lineEndpoints(el)) {
7008
+ canvasCtx.beginPath();
7009
+ canvasCtx.arc(p.x, p.y, r, 0, Math.PI * 2);
7010
+ canvasCtx.fill();
7011
+ canvasCtx.stroke();
7012
+ }
7013
+ canvasCtx.setLineDash([4 / zoom, 4 / zoom]);
7014
+ continue;
7015
+ }
6962
7016
  const bounds = getElementBounds(el);
6963
7017
  if (!bounds) continue;
6964
7018
  const pad = SELECTION_PAD / zoom;
@@ -7969,7 +8023,7 @@ var TemplateTool = class {
7969
8023
  };
7970
8024
 
7971
8025
  // src/index.ts
7972
- var VERSION = "0.30.0";
8026
+ var VERSION = "0.31.0";
7973
8027
  export {
7974
8028
  ArrowTool,
7975
8029
  AutoSave,