@tsdraw/core 0.8.5 → 0.9.1
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 +169 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +19 -2
- package/dist/index.d.ts +19 -2
- package/dist/index.js +169 -5
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -282,7 +282,8 @@ interface ICanvasRenderer {
|
|
|
282
282
|
render(ctx: CanvasRenderingContext2D, viewport: Viewport, shapes: Shape[]): void;
|
|
283
283
|
}
|
|
284
284
|
declare class CanvasRenderer implements ICanvasRenderer {
|
|
285
|
-
private
|
|
285
|
+
private _theme;
|
|
286
|
+
get theme(): TsdrawRenderTheme;
|
|
286
287
|
setTheme(theme: TsdrawRenderTheme): void;
|
|
287
288
|
render(ctx: CanvasRenderingContext2D, viewport: Viewport, shapes: Shape[]): void;
|
|
288
289
|
private paintStroke;
|
|
@@ -290,6 +291,22 @@ declare class CanvasRenderer implements ICanvasRenderer {
|
|
|
290
291
|
private paintClosedShapeFill;
|
|
291
292
|
}
|
|
292
293
|
|
|
294
|
+
type TsdrawBackgroundType = 'blank' | 'lines' | 'grid' | 'dots';
|
|
295
|
+
interface TsdrawBackgroundPreset {
|
|
296
|
+
type: TsdrawBackgroundType;
|
|
297
|
+
color?: string;
|
|
298
|
+
colorDark?: string;
|
|
299
|
+
spacing?: number;
|
|
300
|
+
size?: number;
|
|
301
|
+
opacity?: number;
|
|
302
|
+
}
|
|
303
|
+
interface TsdrawBackgroundCustom {
|
|
304
|
+
type: 'custom';
|
|
305
|
+
render: (ctx: CanvasRenderingContext2D, viewport: Viewport, canvasWidth: number, canvasHeight: number) => void;
|
|
306
|
+
}
|
|
307
|
+
type TsdrawBackgroundOptions = TsdrawBackgroundPreset | TsdrawBackgroundCustom;
|
|
308
|
+
declare function renderCanvasBackground(ctx: CanvasRenderingContext2D, viewport: Viewport, canvasWidth: number, canvasHeight: number, options: TsdrawBackgroundOptions | undefined, theme: TsdrawRenderTheme): void;
|
|
309
|
+
|
|
293
310
|
type DefaultToolId = 'pen' | 'eraser' | 'select' | 'hand' | 'square' | 'circle';
|
|
294
311
|
type ToolId = DefaultToolId | (string & {});
|
|
295
312
|
interface ToolDefinition {
|
|
@@ -667,4 +684,4 @@ declare function decodePathToPoints(segments: {
|
|
|
667
684
|
y: number;
|
|
668
685
|
}[];
|
|
669
686
|
|
|
670
|
-
export { type Bounds, type CameraPanSession, type CameraSlideAnimation, type CameraSlideOptions, CanvasRenderer, CircleDrawingState, CircleIdleState, type ColorStyle, DEFAULT_COLORS, DEFAULT_ZOOM_RANGE, DRAG_DISTANCE_SQUARED, type DashStyle, type DefaultToolId, DocumentStore, type DocumentStoreSnapshot, type DrawSegment, type DrawShape, ERASER_MARGIN, Editor, type EditorOptions, EraserErasingState, EraserIdleState, EraserPointingState, type FillStyle, HandDraggingState, HandIdleState, type ICanvasRenderer, type IEditor, InputManager, MAX_POINTS_PER_SHAPE, type PageState, PenDrawingState, PenIdleState, type PointerInput, type ResizeHandle, STROKE_WIDTHS, type SegmentType, SelectIdleState, type SelectionBounds, type Shape, type ShapeId, type SizeStyle, SquareDrawingState, SquareIdleState, StateNode, type StateNodeConstructor, type ToolDefinition, type ToolId, type ToolKeyInfo, ToolManager, type ToolPointerDownInfo, type ToolPointerMoveInfo, type ToolStateContext, type ToolStateTransitionInfo, type TransformSnapshot, type TsdrawDocumentSnapshot, type TsdrawEditorSnapshot, type TsdrawHistorySnapshot, type TsdrawPageRecord, type TsdrawPersistedRecord, type TsdrawRenderTheme, type TsdrawSessionStateSnapshot, type TsdrawShapeRecord, type Vec3, type Viewport, type ZoomRange, applyMove, applyResize, applyRotation, beginCameraPan, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, clampZoom, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, moveCameraPan, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, resolveThemeColor, rotatePoint, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, startCameraSlide, zoomViewport };
|
|
687
|
+
export { type Bounds, type CameraPanSession, type CameraSlideAnimation, type CameraSlideOptions, CanvasRenderer, CircleDrawingState, CircleIdleState, type ColorStyle, DEFAULT_COLORS, DEFAULT_ZOOM_RANGE, DRAG_DISTANCE_SQUARED, type DashStyle, type DefaultToolId, DocumentStore, type DocumentStoreSnapshot, type DrawSegment, type DrawShape, ERASER_MARGIN, Editor, type EditorOptions, EraserErasingState, EraserIdleState, EraserPointingState, type FillStyle, HandDraggingState, HandIdleState, type ICanvasRenderer, type IEditor, InputManager, MAX_POINTS_PER_SHAPE, type PageState, PenDrawingState, PenIdleState, type PointerInput, type ResizeHandle, STROKE_WIDTHS, type SegmentType, SelectIdleState, type SelectionBounds, type Shape, type ShapeId, type SizeStyle, SquareDrawingState, SquareIdleState, StateNode, type StateNodeConstructor, type ToolDefinition, type ToolId, type ToolKeyInfo, ToolManager, type ToolPointerDownInfo, type ToolPointerMoveInfo, type ToolStateContext, type ToolStateTransitionInfo, type TransformSnapshot, type TsdrawBackgroundCustom, type TsdrawBackgroundOptions, type TsdrawBackgroundPreset, type TsdrawBackgroundType, type TsdrawDocumentSnapshot, type TsdrawEditorSnapshot, type TsdrawHistorySnapshot, type TsdrawPageRecord, type TsdrawPersistedRecord, type TsdrawRenderTheme, type TsdrawSessionStateSnapshot, type TsdrawShapeRecord, type Vec3, type Viewport, type ZoomRange, applyMove, applyResize, applyRotation, beginCameraPan, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, clampZoom, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, moveCameraPan, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, renderCanvasBackground, resolveThemeColor, rotatePoint, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, startCameraSlide, zoomViewport };
|
package/dist/index.d.ts
CHANGED
|
@@ -282,7 +282,8 @@ interface ICanvasRenderer {
|
|
|
282
282
|
render(ctx: CanvasRenderingContext2D, viewport: Viewport, shapes: Shape[]): void;
|
|
283
283
|
}
|
|
284
284
|
declare class CanvasRenderer implements ICanvasRenderer {
|
|
285
|
-
private
|
|
285
|
+
private _theme;
|
|
286
|
+
get theme(): TsdrawRenderTheme;
|
|
286
287
|
setTheme(theme: TsdrawRenderTheme): void;
|
|
287
288
|
render(ctx: CanvasRenderingContext2D, viewport: Viewport, shapes: Shape[]): void;
|
|
288
289
|
private paintStroke;
|
|
@@ -290,6 +291,22 @@ declare class CanvasRenderer implements ICanvasRenderer {
|
|
|
290
291
|
private paintClosedShapeFill;
|
|
291
292
|
}
|
|
292
293
|
|
|
294
|
+
type TsdrawBackgroundType = 'blank' | 'lines' | 'grid' | 'dots';
|
|
295
|
+
interface TsdrawBackgroundPreset {
|
|
296
|
+
type: TsdrawBackgroundType;
|
|
297
|
+
color?: string;
|
|
298
|
+
colorDark?: string;
|
|
299
|
+
spacing?: number;
|
|
300
|
+
size?: number;
|
|
301
|
+
opacity?: number;
|
|
302
|
+
}
|
|
303
|
+
interface TsdrawBackgroundCustom {
|
|
304
|
+
type: 'custom';
|
|
305
|
+
render: (ctx: CanvasRenderingContext2D, viewport: Viewport, canvasWidth: number, canvasHeight: number) => void;
|
|
306
|
+
}
|
|
307
|
+
type TsdrawBackgroundOptions = TsdrawBackgroundPreset | TsdrawBackgroundCustom;
|
|
308
|
+
declare function renderCanvasBackground(ctx: CanvasRenderingContext2D, viewport: Viewport, canvasWidth: number, canvasHeight: number, options: TsdrawBackgroundOptions | undefined, theme: TsdrawRenderTheme): void;
|
|
309
|
+
|
|
293
310
|
type DefaultToolId = 'pen' | 'eraser' | 'select' | 'hand' | 'square' | 'circle';
|
|
294
311
|
type ToolId = DefaultToolId | (string & {});
|
|
295
312
|
interface ToolDefinition {
|
|
@@ -667,4 +684,4 @@ declare function decodePathToPoints(segments: {
|
|
|
667
684
|
y: number;
|
|
668
685
|
}[];
|
|
669
686
|
|
|
670
|
-
export { type Bounds, type CameraPanSession, type CameraSlideAnimation, type CameraSlideOptions, CanvasRenderer, CircleDrawingState, CircleIdleState, type ColorStyle, DEFAULT_COLORS, DEFAULT_ZOOM_RANGE, DRAG_DISTANCE_SQUARED, type DashStyle, type DefaultToolId, DocumentStore, type DocumentStoreSnapshot, type DrawSegment, type DrawShape, ERASER_MARGIN, Editor, type EditorOptions, EraserErasingState, EraserIdleState, EraserPointingState, type FillStyle, HandDraggingState, HandIdleState, type ICanvasRenderer, type IEditor, InputManager, MAX_POINTS_PER_SHAPE, type PageState, PenDrawingState, PenIdleState, type PointerInput, type ResizeHandle, STROKE_WIDTHS, type SegmentType, SelectIdleState, type SelectionBounds, type Shape, type ShapeId, type SizeStyle, SquareDrawingState, SquareIdleState, StateNode, type StateNodeConstructor, type ToolDefinition, type ToolId, type ToolKeyInfo, ToolManager, type ToolPointerDownInfo, type ToolPointerMoveInfo, type ToolStateContext, type ToolStateTransitionInfo, type TransformSnapshot, type TsdrawDocumentSnapshot, type TsdrawEditorSnapshot, type TsdrawHistorySnapshot, type TsdrawPageRecord, type TsdrawPersistedRecord, type TsdrawRenderTheme, type TsdrawSessionStateSnapshot, type TsdrawShapeRecord, type Vec3, type Viewport, type ZoomRange, applyMove, applyResize, applyRotation, beginCameraPan, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, clampZoom, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, moveCameraPan, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, resolveThemeColor, rotatePoint, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, startCameraSlide, zoomViewport };
|
|
687
|
+
export { type Bounds, type CameraPanSession, type CameraSlideAnimation, type CameraSlideOptions, CanvasRenderer, CircleDrawingState, CircleIdleState, type ColorStyle, DEFAULT_COLORS, DEFAULT_ZOOM_RANGE, DRAG_DISTANCE_SQUARED, type DashStyle, type DefaultToolId, DocumentStore, type DocumentStoreSnapshot, type DrawSegment, type DrawShape, ERASER_MARGIN, Editor, type EditorOptions, EraserErasingState, EraserIdleState, EraserPointingState, type FillStyle, HandDraggingState, HandIdleState, type ICanvasRenderer, type IEditor, InputManager, MAX_POINTS_PER_SHAPE, type PageState, PenDrawingState, PenIdleState, type PointerInput, type ResizeHandle, STROKE_WIDTHS, type SegmentType, SelectIdleState, type SelectionBounds, type Shape, type ShapeId, type SizeStyle, SquareDrawingState, SquareIdleState, StateNode, type StateNodeConstructor, type ToolDefinition, type ToolId, type ToolKeyInfo, ToolManager, type ToolPointerDownInfo, type ToolPointerMoveInfo, type ToolStateContext, type ToolStateTransitionInfo, type TransformSnapshot, type TsdrawBackgroundCustom, type TsdrawBackgroundOptions, type TsdrawBackgroundPreset, type TsdrawBackgroundType, type TsdrawDocumentSnapshot, type TsdrawEditorSnapshot, type TsdrawHistorySnapshot, type TsdrawPageRecord, type TsdrawPersistedRecord, type TsdrawRenderTheme, type TsdrawSessionStateSnapshot, type TsdrawShapeRecord, type Vec3, type Viewport, type ZoomRange, applyMove, applyResize, applyRotation, beginCameraPan, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, clampZoom, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, moveCameraPan, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, renderCanvasBackground, resolveThemeColor, rotatePoint, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, startCameraSlide, zoomViewport };
|
package/dist/index.js
CHANGED
|
@@ -370,9 +370,12 @@ function resolveThemeColor(colorStyle, theme) {
|
|
|
370
370
|
return DARK_COLORS[colorStyle] ?? lightThemeColor;
|
|
371
371
|
}
|
|
372
372
|
var CanvasRenderer = class {
|
|
373
|
-
|
|
373
|
+
_theme = "light";
|
|
374
|
+
get theme() {
|
|
375
|
+
return this._theme;
|
|
376
|
+
}
|
|
374
377
|
setTheme(theme) {
|
|
375
|
-
this.
|
|
378
|
+
this._theme = theme;
|
|
376
379
|
}
|
|
377
380
|
render(ctx, viewport, shapes) {
|
|
378
381
|
ctx.save();
|
|
@@ -390,7 +393,7 @@ var CanvasRenderer = class {
|
|
|
390
393
|
const width = (STROKE_WIDTHS[shape.props.size] ?? 3.5) * shape.props.scale;
|
|
391
394
|
const samples = flattenSegments(shape);
|
|
392
395
|
if (samples.length === 0) return;
|
|
393
|
-
const color = resolveThemeColor(shape.props.color, this.
|
|
396
|
+
const color = resolveThemeColor(shape.props.color, this._theme);
|
|
394
397
|
const fillStyle = shape.props.fill ?? "none";
|
|
395
398
|
if (shape.props.isClosed && fillStyle !== "none") {
|
|
396
399
|
this.paintClosedShapeFill(ctx, samples, color, fillStyle);
|
|
@@ -456,7 +459,7 @@ var CanvasRenderer = class {
|
|
|
456
459
|
ctx.fillStyle = color;
|
|
457
460
|
ctx.globalAlpha = 0.55;
|
|
458
461
|
} else if (fillStyle === "none") {
|
|
459
|
-
ctx.fillStyle = this.
|
|
462
|
+
ctx.fillStyle = this._theme === "dark" ? "#0f0f0f" : "#fafafa";
|
|
460
463
|
ctx.globalAlpha = 1;
|
|
461
464
|
} else {
|
|
462
465
|
ctx.fillStyle = color;
|
|
@@ -552,6 +555,167 @@ function getLineDash(dash, width) {
|
|
|
552
555
|
}
|
|
553
556
|
}
|
|
554
557
|
|
|
558
|
+
// src/canvas/backgroundRenderer.ts
|
|
559
|
+
var DEFAULT_SPACING = 20;
|
|
560
|
+
var DEFAULT_LINE_WIDTH = 0.5;
|
|
561
|
+
var DEFAULT_DOT_RADIUS = 1;
|
|
562
|
+
var DEFAULT_OPACITY = 1;
|
|
563
|
+
var LINE_GAP_FADE_IN = 3;
|
|
564
|
+
var LINE_GAP_FADE_FULL = 8;
|
|
565
|
+
var DOT_GAP_FADE_IN = 2;
|
|
566
|
+
var DOT_GAP_FADE_FULL = 16;
|
|
567
|
+
function resolvePresetPatternColor(colorLight, colorDark, theme) {
|
|
568
|
+
if (theme === "dark") return colorDark ?? colorLight ?? "#888888";
|
|
569
|
+
return colorLight ?? "#c0c0c0";
|
|
570
|
+
}
|
|
571
|
+
function visiblePageRect(viewport, canvasWidth, canvasHeight) {
|
|
572
|
+
return {
|
|
573
|
+
minX: (0 - viewport.x) / viewport.zoom,
|
|
574
|
+
minY: (0 - viewport.y) / viewport.zoom,
|
|
575
|
+
maxX: (canvasWidth - viewport.x) / viewport.zoom,
|
|
576
|
+
maxY: (canvasHeight - viewport.y) / viewport.zoom
|
|
577
|
+
};
|
|
578
|
+
}
|
|
579
|
+
function isOnGrid(value, gridSpacing) {
|
|
580
|
+
const remainder = (value % gridSpacing + gridSpacing) % gridSpacing;
|
|
581
|
+
return remainder < 0.5 || remainder > gridSpacing - 0.5;
|
|
582
|
+
}
|
|
583
|
+
function fadeForScreenGap(screenGap, fadeIn, fadeFull) {
|
|
584
|
+
return Math.min(1, Math.max(0, (screenGap - fadeIn) / (fadeFull - fadeIn)));
|
|
585
|
+
}
|
|
586
|
+
function buildLevels(baseSpacing, zoom, fadeIn, fadeFull) {
|
|
587
|
+
let topSpacing = baseSpacing;
|
|
588
|
+
while (topSpacing * zoom < fadeFull) {
|
|
589
|
+
topSpacing *= 2;
|
|
590
|
+
}
|
|
591
|
+
const levels = [];
|
|
592
|
+
for (let s = topSpacing; s >= baseSpacing; s /= 2) {
|
|
593
|
+
const fade = fadeForScreenGap(s * zoom, fadeIn, fadeFull);
|
|
594
|
+
if (fade < 0.01) break;
|
|
595
|
+
levels.push({ spacing: s, fade });
|
|
596
|
+
}
|
|
597
|
+
return levels;
|
|
598
|
+
}
|
|
599
|
+
function drawDotTile(ctx, physicalWidth, physicalHeight, panXPx, panYPx, exactTileSize, radiusPx, color, alpha) {
|
|
600
|
+
if (alpha < 5e-3 || exactTileSize < 2) return;
|
|
601
|
+
const tilePixels = Math.ceil(exactTileSize);
|
|
602
|
+
const tileScale = exactTileSize / tilePixels;
|
|
603
|
+
const center = tilePixels / 2;
|
|
604
|
+
const tile = new OffscreenCanvas(tilePixels, tilePixels);
|
|
605
|
+
const tctx = tile.getContext("2d");
|
|
606
|
+
tctx.fillStyle = color;
|
|
607
|
+
tctx.beginPath();
|
|
608
|
+
tctx.arc(center, center, radiusPx / tileScale, 0, Math.PI * 2);
|
|
609
|
+
tctx.fill();
|
|
610
|
+
const pattern = ctx.createPattern(tile, "repeat");
|
|
611
|
+
if (!pattern) return;
|
|
612
|
+
pattern.setTransform(
|
|
613
|
+
new DOMMatrix().translateSelf(panXPx - exactTileSize / 2, panYPx - exactTileSize / 2).scaleSelf(tileScale, tileScale)
|
|
614
|
+
);
|
|
615
|
+
ctx.save();
|
|
616
|
+
ctx.setTransform(1, 0, 0, 1, 0, 0);
|
|
617
|
+
ctx.globalAlpha = alpha;
|
|
618
|
+
ctx.fillStyle = pattern;
|
|
619
|
+
ctx.fillRect(0, 0, physicalWidth, physicalHeight);
|
|
620
|
+
ctx.restore();
|
|
621
|
+
}
|
|
622
|
+
function drawMergingDots(ctx, viewport, canvasWidth, canvasHeight, baseSpacing, dotRadius, color, opacity) {
|
|
623
|
+
const dpr = ctx.getTransform().a;
|
|
624
|
+
const levels = buildLevels(baseSpacing, viewport.zoom, DOT_GAP_FADE_IN, DOT_GAP_FADE_FULL);
|
|
625
|
+
if (levels.length === 0) return;
|
|
626
|
+
const physicalWidth = canvasWidth * dpr;
|
|
627
|
+
const physicalHeight = canvasHeight * dpr;
|
|
628
|
+
const panXPx = viewport.x * dpr;
|
|
629
|
+
const panYPx = viewport.y * dpr;
|
|
630
|
+
const radiusPx = dotRadius * dpr;
|
|
631
|
+
for (const level of levels) {
|
|
632
|
+
const tileSize = level.spacing * viewport.zoom * dpr;
|
|
633
|
+
drawDotTile(ctx, physicalWidth, physicalHeight, panXPx, panYPx, tileSize, radiusPx, color, opacity * level.fade);
|
|
634
|
+
}
|
|
635
|
+
}
|
|
636
|
+
function drawHorizontalLinesForLevel(ctx, visible, spacing, skipSpacing, lineWidth, color, alpha) {
|
|
637
|
+
const startY = Math.floor(visible.minY / spacing) * spacing;
|
|
638
|
+
ctx.save();
|
|
639
|
+
ctx.strokeStyle = color;
|
|
640
|
+
ctx.lineWidth = lineWidth;
|
|
641
|
+
ctx.globalAlpha = alpha;
|
|
642
|
+
ctx.beginPath();
|
|
643
|
+
for (let y = startY; y <= visible.maxY; y += spacing) {
|
|
644
|
+
if (skipSpacing > 0 && isOnGrid(y, skipSpacing)) continue;
|
|
645
|
+
ctx.moveTo(visible.minX, y);
|
|
646
|
+
ctx.lineTo(visible.maxX, y);
|
|
647
|
+
}
|
|
648
|
+
ctx.stroke();
|
|
649
|
+
ctx.restore();
|
|
650
|
+
}
|
|
651
|
+
function drawMergingLines(ctx, visible, baseSpacing, lineWidth, color, opacity, zoom) {
|
|
652
|
+
const compensatedWidth = lineWidth / ctx.getTransform().a;
|
|
653
|
+
const levels = buildLevels(baseSpacing, zoom, LINE_GAP_FADE_IN, LINE_GAP_FADE_FULL);
|
|
654
|
+
for (let i = 0; i < levels.length; i++) {
|
|
655
|
+
const level = levels[i];
|
|
656
|
+
const coarserSpacing = i > 0 ? levels[i - 1].spacing : 0;
|
|
657
|
+
drawHorizontalLinesForLevel(ctx, visible, level.spacing, coarserSpacing, compensatedWidth, color, opacity * level.fade);
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
function drawGridForLevel(ctx, visible, spacing, skipSpacing, lineWidth, color, alpha) {
|
|
661
|
+
const startX = Math.floor(visible.minX / spacing) * spacing;
|
|
662
|
+
const startY = Math.floor(visible.minY / spacing) * spacing;
|
|
663
|
+
ctx.save();
|
|
664
|
+
ctx.strokeStyle = color;
|
|
665
|
+
ctx.lineWidth = lineWidth;
|
|
666
|
+
ctx.globalAlpha = alpha;
|
|
667
|
+
ctx.beginPath();
|
|
668
|
+
for (let x = startX; x <= visible.maxX; x += spacing) {
|
|
669
|
+
if (skipSpacing > 0 && isOnGrid(x, skipSpacing)) continue;
|
|
670
|
+
ctx.moveTo(x, visible.minY);
|
|
671
|
+
ctx.lineTo(x, visible.maxY);
|
|
672
|
+
}
|
|
673
|
+
for (let y = startY; y <= visible.maxY; y += spacing) {
|
|
674
|
+
if (skipSpacing > 0 && isOnGrid(y, skipSpacing)) continue;
|
|
675
|
+
ctx.moveTo(visible.minX, y);
|
|
676
|
+
ctx.lineTo(visible.maxX, y);
|
|
677
|
+
}
|
|
678
|
+
ctx.stroke();
|
|
679
|
+
ctx.restore();
|
|
680
|
+
}
|
|
681
|
+
function drawMergingGrid(ctx, visible, baseSpacing, lineWidth, color, opacity, zoom) {
|
|
682
|
+
const compensatedWidth = lineWidth / ctx.getTransform().a;
|
|
683
|
+
const levels = buildLevels(baseSpacing, zoom, LINE_GAP_FADE_IN, LINE_GAP_FADE_FULL);
|
|
684
|
+
for (let i = 0; i < levels.length; i++) {
|
|
685
|
+
const level = levels[i];
|
|
686
|
+
const coarserSpacing = i > 0 ? levels[i - 1].spacing : 0;
|
|
687
|
+
drawGridForLevel(ctx, visible, level.spacing, coarserSpacing, compensatedWidth, color, opacity * level.fade);
|
|
688
|
+
}
|
|
689
|
+
}
|
|
690
|
+
function renderCanvasBackground(ctx, viewport, canvasWidth, canvasHeight, options, theme) {
|
|
691
|
+
if (!options || options.type === "blank") return;
|
|
692
|
+
if (options.type === "custom") {
|
|
693
|
+
options.render(ctx, viewport, canvasWidth, canvasHeight);
|
|
694
|
+
return;
|
|
695
|
+
}
|
|
696
|
+
const baseSpacing = options.spacing ?? DEFAULT_SPACING;
|
|
697
|
+
if (baseSpacing <= 0) return;
|
|
698
|
+
const color = resolvePresetPatternColor(options.color, options.colorDark, theme);
|
|
699
|
+
const opacity = options.opacity ?? DEFAULT_OPACITY;
|
|
700
|
+
if (options.type === "dots") {
|
|
701
|
+
drawMergingDots(ctx, viewport, canvasWidth, canvasHeight, baseSpacing, options.size ?? DEFAULT_DOT_RADIUS, color, opacity);
|
|
702
|
+
return;
|
|
703
|
+
}
|
|
704
|
+
const visible = visiblePageRect(viewport, canvasWidth, canvasHeight);
|
|
705
|
+
ctx.save();
|
|
706
|
+
ctx.translate(viewport.x, viewport.y);
|
|
707
|
+
ctx.scale(viewport.zoom, viewport.zoom);
|
|
708
|
+
switch (options.type) {
|
|
709
|
+
case "lines":
|
|
710
|
+
drawMergingLines(ctx, visible, baseSpacing, options.size ?? DEFAULT_LINE_WIDTH, color, opacity, viewport.zoom);
|
|
711
|
+
break;
|
|
712
|
+
case "grid":
|
|
713
|
+
drawMergingGrid(ctx, visible, baseSpacing, options.size ?? DEFAULT_LINE_WIDTH, color, opacity, viewport.zoom);
|
|
714
|
+
break;
|
|
715
|
+
}
|
|
716
|
+
ctx.restore();
|
|
717
|
+
}
|
|
718
|
+
|
|
555
719
|
// src/input/inputManager.ts
|
|
556
720
|
var InputManager = class {
|
|
557
721
|
_current = { x: 0, y: 0 };
|
|
@@ -2260,6 +2424,6 @@ function applyResize(editor, handle, startBounds, startShapes, pointer, lockAspe
|
|
|
2260
2424
|
}
|
|
2261
2425
|
}
|
|
2262
2426
|
|
|
2263
|
-
export { CanvasRenderer, CircleDrawingState, CircleIdleState, DEFAULT_COLORS, DEFAULT_ZOOM_RANGE, DRAG_DISTANCE_SQUARED, DocumentStore, ERASER_MARGIN, Editor, EraserErasingState, EraserIdleState, EraserPointingState, HandDraggingState, HandIdleState, InputManager, MAX_POINTS_PER_SHAPE, PenDrawingState, PenIdleState, STROKE_WIDTHS, SelectIdleState, SquareDrawingState, SquareIdleState, StateNode, ToolManager, applyMove, applyResize, applyRotation, beginCameraPan, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, clampZoom, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds2 as getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, moveCameraPan, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, resolveThemeColor, rotatePoint, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, startCameraSlide, zoomViewport };
|
|
2427
|
+
export { CanvasRenderer, CircleDrawingState, CircleIdleState, DEFAULT_COLORS, DEFAULT_ZOOM_RANGE, DRAG_DISTANCE_SQUARED, DocumentStore, ERASER_MARGIN, Editor, EraserErasingState, EraserIdleState, EraserPointingState, HandDraggingState, HandIdleState, InputManager, MAX_POINTS_PER_SHAPE, PenDrawingState, PenIdleState, STROKE_WIDTHS, SelectIdleState, SquareDrawingState, SquareIdleState, StateNode, ToolManager, applyMove, applyResize, applyRotation, beginCameraPan, boundsContainPoint, boundsIntersect, boundsOf, buildStartPositions, buildTransformSnapshots, clampZoom, closestOnSegment, createViewport, decodeFirstPoint, decodeLastPoint, decodePathToPoints, decodePoints, distance, documentSnapshotToRecords, encodePoints, getSelectionBoundsPage, getShapeBounds2 as getShapeBounds, getShapesInBounds, getTopShapeAtPoint, isSelectTool, minDistanceToPolyline, moveCameraPan, normalizeSelectionBounds, padBounds, pageToScreen, panViewport, pointHitsShape, recordsToDocumentSnapshot, renderCanvasBackground, resolveThemeColor, rotatePoint, screenToPage, segmentHitsShape, segmentTouchesPolyline, setViewport, shapePagePoints, sqDistance, startCameraSlide, zoomViewport };
|
|
2264
2428
|
//# sourceMappingURL=index.js.map
|
|
2265
2429
|
//# sourceMappingURL=index.js.map
|