@fieldnotes/core 0.36.0 → 0.38.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
@@ -514,6 +514,21 @@ declare class Viewport {
514
514
  w: number;
515
515
  h: number;
516
516
  }): string;
517
+ addShape(opts?: {
518
+ shape?: ShapeKind;
519
+ size?: {
520
+ w: number;
521
+ h: number;
522
+ };
523
+ position?: {
524
+ x: number;
525
+ y: number;
526
+ };
527
+ strokeColor?: string;
528
+ fillColor?: string;
529
+ strokeWidth?: number;
530
+ }): string;
531
+ private centeredPosition;
517
532
  removeLayer(id: string): void;
518
533
  updateHtmlElement(id: string, newContent: HTMLElement): void;
519
534
  addGrid(input: {
@@ -1011,6 +1026,6 @@ declare class TemplateTool implements Tool {
1011
1026
  private notifyOptionsChange;
1012
1027
  }
1013
1028
 
1014
- declare const VERSION = "0.36.0";
1029
+ declare const VERSION = "0.38.0";
1015
1030
 
1016
1031
  export { type ActiveFormats, type AlignEdge, 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, type DistributeAxis, 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
@@ -514,6 +514,21 @@ declare class Viewport {
514
514
  w: number;
515
515
  h: number;
516
516
  }): string;
517
+ addShape(opts?: {
518
+ shape?: ShapeKind;
519
+ size?: {
520
+ w: number;
521
+ h: number;
522
+ };
523
+ position?: {
524
+ x: number;
525
+ y: number;
526
+ };
527
+ strokeColor?: string;
528
+ fillColor?: string;
529
+ strokeWidth?: number;
530
+ }): string;
531
+ private centeredPosition;
517
532
  removeLayer(id: string): void;
518
533
  updateHtmlElement(id: string, newContent: HTMLElement): void;
519
534
  addGrid(input: {
@@ -1011,6 +1026,6 @@ declare class TemplateTool implements Tool {
1011
1026
  private notifyOptionsChange;
1012
1027
  }
1013
1028
 
1014
- declare const VERSION = "0.36.0";
1029
+ declare const VERSION = "0.38.0";
1015
1030
 
1016
1031
  export { type ActiveFormats, type AlignEdge, 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, type DistributeAxis, 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
@@ -2002,9 +2002,10 @@ var Quadtree = class {
2002
2002
  };
2003
2003
 
2004
2004
  // src/elements/stroke-smoothing.ts
2005
- var MIN_PRESSURE_SCALE = 0.2;
2005
+ var MIN_PRESSURE_SCALE = 0.4;
2006
+ var MAX_PRESSURE_SCALE = 1.8;
2006
2007
  function pressureToWidth(pressure, baseWidth) {
2007
- return baseWidth * (MIN_PRESSURE_SCALE + (1 - MIN_PRESSURE_SCALE) * pressure);
2008
+ return baseWidth * (MIN_PRESSURE_SCALE + (MAX_PRESSURE_SCALE - MIN_PRESSURE_SCALE) * pressure);
2008
2009
  }
2009
2010
  function simplifyPoints(points, tolerance) {
2010
2011
  if (points.length <= 2) return points.slice();
@@ -3667,12 +3668,33 @@ var NoteToolbar = class {
3667
3668
  e.stopPropagation();
3668
3669
  });
3669
3670
  select.addEventListener("change", () => {
3670
- setFontSize(Number(select.value));
3671
+ this.applyFontSize(Number(select.value));
3671
3672
  this.updateActiveStates();
3672
3673
  this.anchor?.focus();
3673
3674
  });
3674
3675
  return select;
3675
3676
  }
3677
+ applyFontSize(size) {
3678
+ const sel = window.getSelection();
3679
+ const collapsed = !sel || sel.rangeCount === 0 || sel.getRangeAt(0).collapsed;
3680
+ if (collapsed && this.anchor) {
3681
+ const range = document.createRange();
3682
+ range.selectNodeContents(this.anchor);
3683
+ sel?.removeAllRanges();
3684
+ sel?.addRange(range);
3685
+ setFontSize(size);
3686
+ const after = window.getSelection();
3687
+ if (after) {
3688
+ const caret = document.createRange();
3689
+ caret.selectNodeContents(this.anchor);
3690
+ caret.collapse(false);
3691
+ after.removeAllRanges();
3692
+ after.addRange(caret);
3693
+ }
3694
+ return;
3695
+ }
3696
+ setFontSize(size);
3697
+ }
3676
3698
  positionToolbar(anchor) {
3677
3699
  if (!this.el) return;
3678
3700
  const rect = anchor.getBoundingClientRect();
@@ -6017,6 +6039,32 @@ var Viewport = class {
6017
6039
  this.requestRender();
6018
6040
  return el.id;
6019
6041
  }
6042
+ addShape(opts = {}) {
6043
+ const size = opts.size ?? { w: 100, h: 100 };
6044
+ const position = opts.position ?? this.centeredPosition(size);
6045
+ const shape = createShape({
6046
+ position,
6047
+ size,
6048
+ shape: opts.shape,
6049
+ strokeColor: opts.strokeColor,
6050
+ strokeWidth: opts.strokeWidth,
6051
+ fillColor: opts.fillColor,
6052
+ layerId: this.layerManager.activeLayerId
6053
+ });
6054
+ this.historyRecorder.begin();
6055
+ this.store.add(shape);
6056
+ this.historyRecorder.commit();
6057
+ this.getSelectTool()?.setSelection([shape.id]);
6058
+ this.requestRender();
6059
+ return shape.id;
6060
+ }
6061
+ centeredPosition(size) {
6062
+ const c = this.camera.screenToWorld({
6063
+ x: this.wrapper.clientWidth / 2,
6064
+ y: this.wrapper.clientHeight / 2
6065
+ });
6066
+ return { x: c.x - size.w / 2, y: c.y - size.h / 2 };
6067
+ }
6020
6068
  removeLayer(id) {
6021
6069
  this.historyRecorder.begin();
6022
6070
  this.layerManager.removeLayer(id);
@@ -8818,7 +8866,7 @@ var TemplateTool = class {
8818
8866
  };
8819
8867
 
8820
8868
  // src/index.ts
8821
- var VERSION = "0.36.0";
8869
+ var VERSION = "0.38.0";
8822
8870
  export {
8823
8871
  ArrowTool,
8824
8872
  AutoSave,