@fieldnotes/core 0.28.0 → 0.29.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
@@ -701,14 +701,17 @@ declare class PencilTool implements Tool {
701
701
 
702
702
  interface EraserToolOptions {
703
703
  radius?: number;
704
+ mode?: 'partial' | 'stroke';
704
705
  }
705
706
  declare class EraserTool implements Tool {
706
707
  readonly name = "eraser";
707
708
  private erasing;
708
- private readonly radius;
709
- private readonly cursor;
709
+ private radius;
710
+ private cursor;
711
+ private mode;
710
712
  constructor(options?: EraserToolOptions);
711
713
  getOptions(): EraserToolOptions;
714
+ setOptions(options: EraserToolOptions): void;
712
715
  onActivate(ctx: ToolContext): void;
713
716
  onDeactivate(ctx: ToolContext): void;
714
717
  onPointerDown(state: PointerState, ctx: ToolContext): void;
@@ -957,6 +960,6 @@ declare class TemplateTool implements Tool {
957
960
  private notifyOptionsChange;
958
961
  }
959
962
 
960
- declare const VERSION = "0.28.0";
963
+ declare const VERSION = "0.29.0";
961
964
 
962
965
  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
@@ -701,14 +701,17 @@ declare class PencilTool implements Tool {
701
701
 
702
702
  interface EraserToolOptions {
703
703
  radius?: number;
704
+ mode?: 'partial' | 'stroke';
704
705
  }
705
706
  declare class EraserTool implements Tool {
706
707
  readonly name = "eraser";
707
708
  private erasing;
708
- private readonly radius;
709
- private readonly cursor;
709
+ private radius;
710
+ private cursor;
711
+ private mode;
710
712
  constructor(options?: EraserToolOptions);
711
713
  getOptions(): EraserToolOptions;
714
+ setOptions(options: EraserToolOptions): void;
712
715
  onActivate(ctx: ToolContext): void;
713
716
  onDeactivate(ctx: ToolContext): void;
714
717
  onPointerDown(state: PointerState, ctx: ToolContext): void;
@@ -957,6 +960,6 @@ declare class TemplateTool implements Tool {
957
960
  private notifyOptionsChange;
958
961
  }
959
962
 
960
- declare const VERSION = "0.28.0";
963
+ declare const VERSION = "0.29.0";
961
964
 
962
965
  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
@@ -6210,6 +6210,79 @@ function hitTestStroke(stroke, point, radius) {
6210
6210
  return false;
6211
6211
  }
6212
6212
 
6213
+ // src/elements/stroke-erase.ts
6214
+ function lerp(a, b, t) {
6215
+ return {
6216
+ x: a.x + (b.x - a.x) * t,
6217
+ y: a.y + (b.y - a.y) * t,
6218
+ pressure: a.pressure + (b.pressure - a.pressure) * t
6219
+ };
6220
+ }
6221
+ function erasePoints(points, eraser, radius) {
6222
+ const r2 = radius * radius;
6223
+ if (points.length < 2) {
6224
+ const p = points[0];
6225
+ if (p && (p.x - eraser.x) ** 2 + (p.y - eraser.y) ** 2 <= r2) return [];
6226
+ return null;
6227
+ }
6228
+ const runs = [];
6229
+ let current = [];
6230
+ let erased = false;
6231
+ const flush = () => {
6232
+ if (current.length >= 2) runs.push(current);
6233
+ current = [];
6234
+ };
6235
+ for (let i = 0; i < points.length - 1; i++) {
6236
+ const a = points[i];
6237
+ const b = points[i + 1];
6238
+ if (!a || !b) continue;
6239
+ const dx = b.x - a.x;
6240
+ const dy = b.y - a.y;
6241
+ const fx = a.x - eraser.x;
6242
+ const fy = a.y - eraser.y;
6243
+ const A = dx * dx + dy * dy;
6244
+ const B = 2 * (fx * dx + fy * dy);
6245
+ const C = fx * fx + fy * fy - r2;
6246
+ let tLo = 1;
6247
+ let tHi = 0;
6248
+ if (A === 0) {
6249
+ if (C <= 0) {
6250
+ tLo = 0;
6251
+ tHi = 1;
6252
+ }
6253
+ } else {
6254
+ const disc = B * B - 4 * A * C;
6255
+ if (disc >= 0) {
6256
+ const sq = Math.sqrt(disc);
6257
+ const lo = Math.max(0, (-B - sq) / (2 * A));
6258
+ const hi = Math.min(1, (-B + sq) / (2 * A));
6259
+ if (lo < hi) {
6260
+ tLo = lo;
6261
+ tHi = hi;
6262
+ }
6263
+ }
6264
+ }
6265
+ if (tLo > tHi) {
6266
+ if (current.length === 0) current.push(a);
6267
+ current.push(b);
6268
+ continue;
6269
+ }
6270
+ erased = true;
6271
+ if (tLo > 0) {
6272
+ if (current.length === 0) current.push(a);
6273
+ current.push(lerp(a, b, tLo));
6274
+ flush();
6275
+ } else {
6276
+ flush();
6277
+ }
6278
+ if (tHi < 1) {
6279
+ current = [lerp(a, b, tHi), b];
6280
+ }
6281
+ }
6282
+ flush();
6283
+ return erased ? runs : null;
6284
+ }
6285
+
6213
6286
  // src/tools/eraser-tool.ts
6214
6287
  var DEFAULT_RADIUS = 20;
6215
6288
  function makeEraserCursor(radius) {
@@ -6222,12 +6295,21 @@ var EraserTool = class {
6222
6295
  erasing = false;
6223
6296
  radius;
6224
6297
  cursor;
6298
+ mode;
6225
6299
  constructor(options = {}) {
6226
6300
  this.radius = options.radius ?? DEFAULT_RADIUS;
6227
6301
  this.cursor = makeEraserCursor(this.radius);
6302
+ this.mode = options.mode ?? "partial";
6228
6303
  }
6229
6304
  getOptions() {
6230
- return { radius: this.radius };
6305
+ return { radius: this.radius, mode: this.mode };
6306
+ }
6307
+ setOptions(options) {
6308
+ if (options.mode !== void 0) this.mode = options.mode;
6309
+ if (options.radius !== void 0) {
6310
+ this.radius = options.radius;
6311
+ this.cursor = makeEraserCursor(this.radius);
6312
+ }
6231
6313
  }
6232
6314
  onActivate(ctx) {
6233
6315
  ctx.setCursor?.(this.cursor);
@@ -6260,10 +6342,30 @@ var EraserTool = class {
6260
6342
  if (el.type !== "stroke") continue;
6261
6343
  if (ctx.isLayerVisible && !ctx.isLayerVisible(el.layerId)) continue;
6262
6344
  if (ctx.isLayerLocked && ctx.isLayerLocked(el.layerId)) continue;
6263
- if (this.strokeIntersects(el, world)) {
6345
+ if (!this.strokeIntersects(el, world)) continue;
6346
+ if (this.mode === "stroke") {
6264
6347
  ctx.store.remove(el.id);
6265
6348
  erased = true;
6349
+ continue;
6350
+ }
6351
+ const localEraser = { x: world.x - el.position.x, y: world.y - el.position.y };
6352
+ const runs = erasePoints(el.points, localEraser, this.radius);
6353
+ if (runs === null) continue;
6354
+ ctx.store.remove(el.id);
6355
+ for (const run of runs) {
6356
+ ctx.store.add(
6357
+ createStroke({
6358
+ points: run,
6359
+ color: el.color,
6360
+ width: el.width,
6361
+ opacity: el.opacity,
6362
+ layerId: el.layerId,
6363
+ zIndex: el.zIndex,
6364
+ position: el.position
6365
+ })
6366
+ );
6266
6367
  }
6368
+ erased = true;
6267
6369
  }
6268
6370
  if (erased) ctx.requestRender();
6269
6371
  }
@@ -7802,7 +7904,7 @@ var TemplateTool = class {
7802
7904
  };
7803
7905
 
7804
7906
  // src/index.ts
7805
- var VERSION = "0.28.0";
7907
+ var VERSION = "0.29.0";
7806
7908
  export {
7807
7909
  ArrowTool,
7808
7910
  AutoSave,