@fieldnotes/core 0.1.0 → 0.1.2

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.cjs CHANGED
@@ -220,6 +220,7 @@ var Camera = class {
220
220
  };
221
221
 
222
222
  // src/canvas/background.ts
223
+ var MIN_PATTERN_SPACING = 16;
223
224
  var DEFAULTS = {
224
225
  pattern: "dots",
225
226
  spacing: 24,
@@ -255,8 +256,15 @@ var Background = class {
255
256
  }
256
257
  ctx.restore();
257
258
  }
259
+ adaptSpacing(baseSpacing, zoom) {
260
+ let spacing = baseSpacing * zoom;
261
+ while (spacing < MIN_PATTERN_SPACING) {
262
+ spacing *= 2;
263
+ }
264
+ return spacing;
265
+ }
258
266
  renderDots(ctx, camera, width, height) {
259
- const spacing = this.spacing * camera.zoom;
267
+ const spacing = this.adaptSpacing(this.spacing, camera.zoom);
260
268
  const offsetX = camera.position.x % spacing;
261
269
  const offsetY = camera.position.y % spacing;
262
270
  const radius = this.dotRadius * Math.min(camera.zoom, 2);
@@ -271,7 +279,7 @@ var Background = class {
271
279
  ctx.fill();
272
280
  }
273
281
  renderGrid(ctx, camera, width, height) {
274
- const spacing = this.spacing * camera.zoom;
282
+ const spacing = this.adaptSpacing(this.spacing, camera.zoom);
275
283
  const offsetX = camera.position.x % spacing;
276
284
  const offsetY = camera.position.y % spacing;
277
285
  const lineW = this.lineWidth * Math.min(camera.zoom, 2);
@@ -331,9 +339,13 @@ var InputHandler = class {
331
339
  }
332
340
  onWheel = (e) => {
333
341
  e.preventDefault();
342
+ const rect = this.element.getBoundingClientRect();
334
343
  const zoomFactor = 1 - e.deltaY * ZOOM_SENSITIVITY;
335
344
  const newZoom = this.camera.zoom * zoomFactor;
336
- this.camera.zoomAt(newZoom, { x: e.clientX, y: e.clientY });
345
+ this.camera.zoomAt(newZoom, {
346
+ x: e.clientX - rect.left,
347
+ y: e.clientY - rect.top
348
+ });
337
349
  };
338
350
  isInteractiveHtmlContent(e) {
339
351
  const target = e.target;
@@ -460,7 +472,12 @@ var InputHandler = class {
460
472
  return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
461
473
  }
462
474
  toPointerState(e) {
463
- return { x: e.clientX, y: e.clientY, pressure: e.pressure };
475
+ const rect = this.element.getBoundingClientRect();
476
+ return {
477
+ x: e.clientX - rect.left,
478
+ y: e.clientY - rect.top,
479
+ pressure: e.pressure
480
+ };
464
481
  }
465
482
  dispatchToolDown(e) {
466
483
  if (!this.toolManager || !this.toolContext) return;
@@ -2203,7 +2220,7 @@ var ImageTool = class {
2203
2220
  };
2204
2221
 
2205
2222
  // src/index.ts
2206
- var VERSION = "0.1.0";
2223
+ var VERSION = "0.1.2";
2207
2224
  // Annotate the CommonJS export names for ESM import in node:
2208
2225
  0 && (module.exports = {
2209
2226
  AddElementCommand,