@fieldnotes/core 0.50.2 → 0.50.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.d.cts CHANGED
@@ -1123,6 +1123,6 @@ declare class LaserTool implements Tool {
1123
1123
  private notifyOptionsChange;
1124
1124
  }
1125
1125
 
1126
- declare const VERSION = "0.50.2";
1126
+ declare const VERSION = "0.50.4";
1127
1127
 
1128
1128
  export { type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, 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, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportImageOptions, type ExportSvgOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LaserTool, type LaserToolOptions, type Layer, LayerManager, LocalStorageAdapter, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, type RotateDirection, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, 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, exportSvg, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
package/dist/index.d.ts CHANGED
@@ -1123,6 +1123,6 @@ declare class LaserTool implements Tool {
1123
1123
  private notifyOptionsChange;
1124
1124
  }
1125
1125
 
1126
- declare const VERSION = "0.50.2";
1126
+ declare const VERSION = "0.50.4";
1127
1127
 
1128
1128
  export { type ActiveFormats, type AlignEdge, type ArrowElement, type ArrowStrokeStyle, 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, type ElementChangeMeta, ElementStore, type ElementStyle, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, type ExportImageOptions, type ExportSvgOptions, type FontSizePreset, type GridElement, type GridInfo, HandTool, type HexOrientation, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, IndexedDBAdapter, type IndexedDBAdapterOptions, LaserTool, type LaserToolOptions, type Layer, LayerManager, LocalStorageAdapter, MeasureTool, type MeasureToolOptions, type Measurement, MemoryAdapter, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, type RenderStatsSnapshot, type RotateDirection, SelectTool, type ShapeElement, type ShapeKind, ShapeTool, type ShapeToolOptions, type ShortcutBindings, type ShortcutOptions, type ShortcutsApi, type Size, type StorageAdapter, type StrokeElement, type StrokePoint, type TemplateElement, type TemplateRenderStyle, 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, exportSvg, getActiveFormats, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, getElementBounds, getElementStyle, getElementsBoundingBox, getHexCellsInCone, getHexCellsInLine, getHexCellsInRadius, getHexCellsInRectangle, getHexCellsInSquare, getHexDistance, isNearBezier, setFontSize, smartSnap, snapPoint, snapToHexCenter, styleToPatch, toggleBold, toggleItalic, toggleStrikethrough, toggleUnderline };
package/dist/index.js CHANGED
@@ -2233,6 +2233,9 @@ var MAX_DEPTH = 8;
2233
2233
  function intersects(a, b) {
2234
2234
  return a.x <= b.x + b.w && a.x + a.w >= b.x && a.y <= b.y + b.h && a.y + a.h >= b.y;
2235
2235
  }
2236
+ function contains(outer, inner) {
2237
+ return inner.x >= outer.x && inner.x + inner.w <= outer.x + outer.w && inner.y >= outer.y && inner.y + inner.h <= outer.y + outer.h;
2238
+ }
2236
2239
  var QuadNode = class _QuadNode {
2237
2240
  constructor(bounds, depth) {
2238
2241
  this.bounds = bounds;
@@ -2285,6 +2288,14 @@ var QuadNode = class _QuadNode {
2285
2288
  }
2286
2289
  }
2287
2290
  }
2291
+ collect(result) {
2292
+ result.push(...this.items);
2293
+ if (this.children) {
2294
+ for (const child of this.children) {
2295
+ child.collect(result);
2296
+ }
2297
+ }
2298
+ }
2288
2299
  getChildIndex(itemBounds) {
2289
2300
  const midX = this.bounds.x + this.bounds.w / 2;
2290
2301
  const midY = this.bounds.y + this.bounds.h / 2;
@@ -2348,6 +2359,7 @@ var Quadtree = class {
2348
2359
  return this._size;
2349
2360
  }
2350
2361
  insert(id, bounds) {
2362
+ this.expandToFit(bounds);
2351
2363
  this.root.insert({ id, bounds });
2352
2364
  this._size++;
2353
2365
  }
@@ -2372,6 +2384,24 @@ var Quadtree = class {
2372
2384
  this.root = new QuadNode(this.worldBounds, 0);
2373
2385
  this._size = 0;
2374
2386
  }
2387
+ expandToFit(bounds) {
2388
+ const current = this.root.bounds;
2389
+ if (contains(current, bounds)) return;
2390
+ const currentRight = current.x + current.w;
2391
+ const currentBottom = current.y + current.h;
2392
+ const requiredWidth = Math.max(currentRight, bounds.x + bounds.w) - Math.min(current.x, bounds.x);
2393
+ const requiredHeight = Math.max(currentBottom, bounds.y + bounds.h) - Math.min(current.y, bounds.y);
2394
+ const width = Math.max(current.w * 2, requiredWidth);
2395
+ const height = Math.max(current.h * 2, requiredHeight);
2396
+ const x = bounds.x < current.x ? currentRight - width : current.x;
2397
+ const y = bounds.y < current.y ? currentBottom - height : current.y;
2398
+ const entries = [];
2399
+ this.root.collect(entries);
2400
+ this.root = new QuadNode({ x, y, w: width, h: height }, 0);
2401
+ for (const entry of entries) {
2402
+ this.root.insert(entry);
2403
+ }
2404
+ }
2375
2405
  };
2376
2406
 
2377
2407
  // src/elements/stroke-smoothing.ts
@@ -8330,7 +8360,8 @@ function hitTestArrowHandles(world, selectedIds, ctx) {
8330
8360
  const hitRadius = (HANDLE_RADIUS + HANDLE_HIT_PADDING) / zoom;
8331
8361
  for (const id of selectedIds) {
8332
8362
  const el = ctx.store.getById(id);
8333
- if (!el || el.type !== "arrow") continue;
8363
+ if (!el || el.type !== "arrow" || el.locked || (ctx.isLayerLocked?.(el.layerId) ?? false))
8364
+ continue;
8334
8365
  const handles = getArrowHandlePositions(el);
8335
8366
  for (const [handle, pos] of handles) {
8336
8367
  const dx = world.x - pos.x;
@@ -8344,7 +8375,7 @@ function hitTestArrowHandles(world, selectedIds, ctx) {
8344
8375
  }
8345
8376
  function applyArrowHandleDrag(handle, elementId, world, ctx) {
8346
8377
  const el = ctx.store.getById(elementId);
8347
- if (!el || el.type !== "arrow") return;
8378
+ if (!el || el.type !== "arrow" || el.locked || (ctx.isLayerLocked?.(el.layerId) ?? false)) return;
8348
8379
  const threshold = BIND_THRESHOLD / ctx.camera.zoom;
8349
8380
  const layerFilter = (candidate) => candidate.layerId === el.layerId;
8350
8381
  switch (handle) {
@@ -8395,7 +8426,9 @@ function applyArrowHandleDrag(handle, elementId, world, ctx) {
8395
8426
  function getArrowHandleDragTarget(handle, elementId, world, ctx) {
8396
8427
  if (handle === "mid") return null;
8397
8428
  const el = ctx.store.getById(elementId);
8398
- if (!el || el.type !== "arrow") return null;
8429
+ if (!el || el.type !== "arrow" || el.locked || (ctx.isLayerLocked?.(el.layerId) ?? false)) {
8430
+ return null;
8431
+ }
8399
8432
  const threshold = BIND_THRESHOLD / ctx.camera.zoom;
8400
8433
  const excludeId = handle === "start" ? el.toBinding?.elementId : el.fromBinding?.elementId;
8401
8434
  const layerFilter = (candidate) => candidate.layerId === el.layerId;
@@ -8587,22 +8620,25 @@ function renderSelectionBoxes(ctx, p) {
8587
8620
  for (const id of p.selectedIds) {
8588
8621
  const el = p.store.getById(id);
8589
8622
  if (!el) continue;
8623
+ const locked = el.locked || (p.isLayerLocked?.(el.layerId) ?? false);
8590
8624
  if (el.type === "arrow") {
8591
- renderArrowHandles(ctx, el, zoom);
8625
+ if (!locked) renderArrowHandles(ctx, el, zoom);
8592
8626
  renderBindingHighlights(ctx, el, zoom, p.store);
8593
8627
  continue;
8594
8628
  }
8595
8629
  if (el.type === "shape" && el.shape === "line") {
8596
- ctx.setLineDash([]);
8597
- ctx.fillStyle = "#ffffff";
8598
- const r = handleWorldSize / 2;
8599
- for (const pt of lineEndpoints(el)) {
8600
- ctx.beginPath();
8601
- ctx.arc(pt.x, pt.y, r, 0, Math.PI * 2);
8602
- ctx.fill();
8603
- ctx.stroke();
8630
+ if (!locked) {
8631
+ ctx.setLineDash([]);
8632
+ ctx.fillStyle = "#ffffff";
8633
+ const r = handleWorldSize / 2;
8634
+ for (const pt of lineEndpoints(el)) {
8635
+ ctx.beginPath();
8636
+ ctx.arc(pt.x, pt.y, r, 0, Math.PI * 2);
8637
+ ctx.fill();
8638
+ ctx.stroke();
8639
+ }
8640
+ ctx.setLineDash([4 / zoom, 4 / zoom]);
8604
8641
  }
8605
- ctx.setLineDash([4 / zoom, 4 / zoom]);
8606
8642
  continue;
8607
8643
  }
8608
8644
  const bounds = getElementBounds(el);
@@ -8837,7 +8873,8 @@ function hitTestLineHandles(world, ctx, selectedIds) {
8837
8873
  const r2 = r * r;
8838
8874
  for (const id of selectedIds) {
8839
8875
  const el = ctx.store.getById(id);
8840
- if (!el || el.type !== "shape" || el.shape !== "line") continue;
8876
+ if (!el || el.type !== "shape" || el.shape !== "line" || el.locked || (ctx.isLayerLocked?.(el.layerId) ?? false))
8877
+ continue;
8841
8878
  const [a, b] = lineEndpoints(el);
8842
8879
  if ((world.x - a.x) ** 2 + (world.y - a.y) ** 2 <= r2) return { elementId: id, fixed: b };
8843
8880
  if ((world.x - b.x) ** 2 + (world.y - b.y) ** 2 <= r2) return { elementId: id, fixed: a };
@@ -9271,10 +9308,10 @@ var SelectTool = class {
9271
9308
  if (this.mode.type === "line-handle") {
9272
9309
  ctx.setCursor?.("grabbing");
9273
9310
  const el = ctx.store.getById(this.mode.elementId);
9274
- if (el && el.type === "shape") {
9311
+ if (el && el.type === "shape" && el.shape === "line" && !el.locked && !(ctx.isLayerLocked?.(el.layerId) ?? false)) {
9275
9312
  ctx.store.update(el.id, lineFromEndpoints(this.mode.fixed, world));
9313
+ ctx.requestRender();
9276
9314
  }
9277
- ctx.requestRender();
9278
9315
  return;
9279
9316
  }
9280
9317
  if (this.mode.type === "resizing-template") {
@@ -9432,7 +9469,8 @@ var SelectTool = class {
9432
9469
  renderSelectionBoxes(canvasCtx, {
9433
9470
  selectedIds: this._selectedIds,
9434
9471
  store: this.ctx.store,
9435
- zoom: this.ctx.camera.zoom
9472
+ zoom: this.ctx.camera.zoom,
9473
+ isLayerLocked: this.ctx.isLayerLocked
9436
9474
  });
9437
9475
  if (this.mode.type === "arrow-handle" && this.ctx) {
9438
9476
  const target = getArrowHandleDragTarget(
@@ -10589,7 +10627,7 @@ var LaserTool = class {
10589
10627
  };
10590
10628
 
10591
10629
  // src/index.ts
10592
- var VERSION = "0.50.2";
10630
+ var VERSION = "0.50.4";
10593
10631
  export {
10594
10632
  ArrowTool,
10595
10633
  AutoSave,