@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 +22 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +22 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -114,6 +114,7 @@ declare class Background {
|
|
|
114
114
|
private readonly lineWidth;
|
|
115
115
|
constructor(options?: BackgroundOptions);
|
|
116
116
|
render(ctx: CanvasRenderingContext2D, camera: Camera): void;
|
|
117
|
+
private adaptSpacing;
|
|
117
118
|
private renderDots;
|
|
118
119
|
private renderGrid;
|
|
119
120
|
}
|
|
@@ -577,6 +578,6 @@ declare class ImageTool implements Tool {
|
|
|
577
578
|
onPointerUp(state: PointerState, ctx: ToolContext): void;
|
|
578
579
|
}
|
|
579
580
|
|
|
580
|
-
declare const VERSION = "0.1.
|
|
581
|
+
declare const VERSION = "0.1.2";
|
|
581
582
|
|
|
582
583
|
export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Bounds, Camera, type CameraOptions, type CanvasElement, type CanvasState, type Command, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, HandTool, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, SelectTool, type Size, type StrokeElement, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, VERSION, Viewport, type ViewportOptions, createArrow, createHtmlElement, createId, createImage, createNote, createStroke, exportState, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, isNearBezier, parseState };
|
package/dist/index.d.ts
CHANGED
|
@@ -114,6 +114,7 @@ declare class Background {
|
|
|
114
114
|
private readonly lineWidth;
|
|
115
115
|
constructor(options?: BackgroundOptions);
|
|
116
116
|
render(ctx: CanvasRenderingContext2D, camera: Camera): void;
|
|
117
|
+
private adaptSpacing;
|
|
117
118
|
private renderDots;
|
|
118
119
|
private renderGrid;
|
|
119
120
|
}
|
|
@@ -577,6 +578,6 @@ declare class ImageTool implements Tool {
|
|
|
577
578
|
onPointerUp(state: PointerState, ctx: ToolContext): void;
|
|
578
579
|
}
|
|
579
580
|
|
|
580
|
-
declare const VERSION = "0.1.
|
|
581
|
+
declare const VERSION = "0.1.2";
|
|
581
582
|
|
|
582
583
|
export { AddElementCommand, type ArrowElement, ArrowTool, type ArrowToolOptions, Background, type BackgroundOptions, type BackgroundPattern, BatchCommand, type Bounds, Camera, type CameraOptions, type CanvasElement, type CanvasState, type Command, ElementRenderer, ElementStore, type ElementType, type ElementUpdateEvent, EraserTool, type EraserToolOptions, EventBus, HandTool, HistoryRecorder, HistoryStack, type HistoryStackOptions, type HtmlElement, type ImageElement, ImageTool, type ImageToolOptions, InputHandler, NoteEditor, type NoteElement, NoteTool, type NoteToolOptions, PencilTool, type PencilToolOptions, type Point, type PointerState, RemoveElementCommand, SelectTool, type Size, type StrokeElement, type Tool, type ToolContext, ToolManager, type ToolName, UpdateElementCommand, VERSION, Viewport, type ViewportOptions, createArrow, createHtmlElement, createId, createImage, createNote, createStroke, exportState, getArrowBounds, getArrowControlPoint, getArrowMidpoint, getArrowTangentAngle, getBendFromPoint, isNearBezier, parseState };
|
package/dist/index.js
CHANGED
|
@@ -158,6 +158,7 @@ var Camera = class {
|
|
|
158
158
|
};
|
|
159
159
|
|
|
160
160
|
// src/canvas/background.ts
|
|
161
|
+
var MIN_PATTERN_SPACING = 16;
|
|
161
162
|
var DEFAULTS = {
|
|
162
163
|
pattern: "dots",
|
|
163
164
|
spacing: 24,
|
|
@@ -193,8 +194,15 @@ var Background = class {
|
|
|
193
194
|
}
|
|
194
195
|
ctx.restore();
|
|
195
196
|
}
|
|
197
|
+
adaptSpacing(baseSpacing, zoom) {
|
|
198
|
+
let spacing = baseSpacing * zoom;
|
|
199
|
+
while (spacing < MIN_PATTERN_SPACING) {
|
|
200
|
+
spacing *= 2;
|
|
201
|
+
}
|
|
202
|
+
return spacing;
|
|
203
|
+
}
|
|
196
204
|
renderDots(ctx, camera, width, height) {
|
|
197
|
-
const spacing = this.spacing
|
|
205
|
+
const spacing = this.adaptSpacing(this.spacing, camera.zoom);
|
|
198
206
|
const offsetX = camera.position.x % spacing;
|
|
199
207
|
const offsetY = camera.position.y % spacing;
|
|
200
208
|
const radius = this.dotRadius * Math.min(camera.zoom, 2);
|
|
@@ -209,7 +217,7 @@ var Background = class {
|
|
|
209
217
|
ctx.fill();
|
|
210
218
|
}
|
|
211
219
|
renderGrid(ctx, camera, width, height) {
|
|
212
|
-
const spacing = this.spacing
|
|
220
|
+
const spacing = this.adaptSpacing(this.spacing, camera.zoom);
|
|
213
221
|
const offsetX = camera.position.x % spacing;
|
|
214
222
|
const offsetY = camera.position.y % spacing;
|
|
215
223
|
const lineW = this.lineWidth * Math.min(camera.zoom, 2);
|
|
@@ -269,9 +277,13 @@ var InputHandler = class {
|
|
|
269
277
|
}
|
|
270
278
|
onWheel = (e) => {
|
|
271
279
|
e.preventDefault();
|
|
280
|
+
const rect = this.element.getBoundingClientRect();
|
|
272
281
|
const zoomFactor = 1 - e.deltaY * ZOOM_SENSITIVITY;
|
|
273
282
|
const newZoom = this.camera.zoom * zoomFactor;
|
|
274
|
-
this.camera.zoomAt(newZoom, {
|
|
283
|
+
this.camera.zoomAt(newZoom, {
|
|
284
|
+
x: e.clientX - rect.left,
|
|
285
|
+
y: e.clientY - rect.top
|
|
286
|
+
});
|
|
275
287
|
};
|
|
276
288
|
isInteractiveHtmlContent(e) {
|
|
277
289
|
const target = e.target;
|
|
@@ -398,7 +410,12 @@ var InputHandler = class {
|
|
|
398
410
|
return { x: (a.x + b.x) / 2, y: (a.y + b.y) / 2 };
|
|
399
411
|
}
|
|
400
412
|
toPointerState(e) {
|
|
401
|
-
|
|
413
|
+
const rect = this.element.getBoundingClientRect();
|
|
414
|
+
return {
|
|
415
|
+
x: e.clientX - rect.left,
|
|
416
|
+
y: e.clientY - rect.top,
|
|
417
|
+
pressure: e.pressure
|
|
418
|
+
};
|
|
402
419
|
}
|
|
403
420
|
dispatchToolDown(e) {
|
|
404
421
|
if (!this.toolManager || !this.toolContext) return;
|
|
@@ -2141,7 +2158,7 @@ var ImageTool = class {
|
|
|
2141
2158
|
};
|
|
2142
2159
|
|
|
2143
2160
|
// src/index.ts
|
|
2144
|
-
var VERSION = "0.1.
|
|
2161
|
+
var VERSION = "0.1.2";
|
|
2145
2162
|
export {
|
|
2146
2163
|
AddElementCommand,
|
|
2147
2164
|
ArrowTool,
|