@turnix-co/konva-editor 2.0.24 → 2.0.27

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.ts CHANGED
@@ -1,18 +1,110 @@
1
- import Konva from 'konva';
2
- export { default as Konva } from 'konva';
3
- export { Stage as KonvaStage } from 'konva/lib/Stage';
4
1
  import React$1 from 'react';
2
+ import Konva from 'konva';
5
3
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
4
  import * as _reduxjs_toolkit from '@reduxjs/toolkit';
7
5
  import * as redux_thunk from 'redux-thunk';
8
6
  import * as redux from 'redux';
9
7
  export { Provider as ReduxProvider } from 'react-redux';
10
8
 
9
+ /**
10
+ * Tool identifiers for the main toolbar
11
+ */
12
+ type ToolType = 'select' | 'pen' | 'eraser' | 'text' | 'shapes' | 'activities' | 'media';
13
+ /**
14
+ * Shape identifiers available in shapes submenu
15
+ */
16
+ type ShapeType = 'rectangle' | 'circle' | 'ellipse' | 'triangle' | 'polygon' | 'star' | 'ring' | 'wedge' | 'arrow' | 'line' | 'arc';
17
+ /**
18
+ * Activity identifiers available in activities submenu
19
+ */
20
+ type ActivityType = 'flashcard' | 'multiple-choice' | 'true-false' | 'short-answer' | 'fill-in-the-blank';
21
+ /**
22
+ * Media identifiers available in media submenu
23
+ */
24
+ type MediaType = 'photo-frame' | 'image' | 'video';
25
+ /**
26
+ * Action identifiers for the toolbar action buttons
27
+ */
28
+ type ActionType = 'undo' | 'redo' | 'screen-record' | 'camera-record' | 'clear';
29
+ /**
30
+ * Configuration for which tools to show in the toolbar
31
+ */
32
+ interface ToolbarToolsConfig {
33
+ /** Show select/cursor tool */
34
+ select?: boolean;
35
+ /** Show pen drawing tool */
36
+ pen?: boolean;
37
+ /** Show eraser tool */
38
+ eraser?: boolean;
39
+ /** Show text tool */
40
+ text?: boolean;
41
+ /** Show shapes menu (or provide specific shapes) */
42
+ shapes?: boolean | ShapeType[];
43
+ /** Show activities menu (or provide specific activities) */
44
+ activities?: boolean | ActivityType[];
45
+ /** Show media menu (or provide specific media types) */
46
+ media?: boolean | MediaType[];
47
+ }
48
+ /**
49
+ * Configuration for which action buttons to show
50
+ */
51
+ interface ToolbarActionsConfig {
52
+ /** Show undo button */
53
+ undo?: boolean;
54
+ /** Show redo button */
55
+ redo?: boolean;
56
+ /** Show screen recording button */
57
+ screenRecord?: boolean;
58
+ /** Show camera recording button */
59
+ cameraRecord?: boolean;
60
+ /** Show clear canvas button */
61
+ clear?: boolean;
62
+ }
63
+ /**
64
+ * Complete toolbar configuration
65
+ */
66
+ interface ToolbarConfig {
67
+ /** Configure which tools to show */
68
+ tools?: ToolbarToolsConfig;
69
+ /** Configure which action buttons to show */
70
+ actions?: ToolbarActionsConfig;
71
+ }
72
+ /**
73
+ * Default toolbar configuration - all tools and actions enabled
74
+ */
75
+ declare const DEFAULT_TOOLBAR_CONFIG: Required<ToolbarConfig>;
76
+ /**
77
+ * Context menu configuration
78
+ * Simple boolean to enable/disable context menu on right-click of canvas elements
79
+ */
80
+ interface ContextMenuConfig {
81
+ /** Enable/disable context menu entirely (default: true) */
82
+ enabled: boolean;
83
+ }
84
+ /**
85
+ * Default context menu configuration - enabled by default
86
+ */
87
+ declare const DEFAULT_CONTEXT_MENU_CONFIG: ContextMenuConfig;
88
+ /**
89
+ * Merge user's toolbar config with defaults
90
+ */
91
+ declare function mergeToolbarConfig(userConfig?: ToolbarConfig): Required<ToolbarConfig>;
92
+ /**
93
+ * Preset: Viewer-only mode (no editing capabilities)
94
+ */
95
+ declare const VIEWER_TOOLBAR_CONFIG: ToolbarConfig;
96
+ /**
97
+ * Preset: Basic editor (no activities)
98
+ */
99
+ declare const BASIC_EDITOR_TOOLBAR_CONFIG: ToolbarConfig;
100
+
11
101
  type CanvasProps = {
12
102
  onStageReady?: (stageRef: React$1.RefObject<Konva.Stage | null>) => void;
13
103
  onSelectionChange?: (selectedId: string | null) => void;
14
104
  onTextEditingReady?: (startEditingFn: (textId: string) => void) => void;
15
105
  onDirectDrawingCanvasReady?: (canvasRef: React$1.RefObject<HTMLCanvasElement | null>) => void;
106
+ /** Configuration for context menu permissions and visibility */
107
+ contextMenuConfig?: ContextMenuConfig;
16
108
  };
17
109
  declare const Canvas: React$1.FC<CanvasProps>;
18
110
 
@@ -23,8 +115,10 @@ type ToolbarProps = {
23
115
  stageRef?: React.RefObject<Konva.Stage | null>;
24
116
  onTextAdded?: (textId: string) => void;
25
117
  showToggleButton?: boolean;
118
+ /** Configuration for which tools and actions to show */
119
+ config?: ToolbarConfig;
26
120
  };
27
- declare const Toolbar: ({ isOpen: isOpenProp, onClose, onScreenRecord, stageRef, onTextAdded, showToggleButton, }?: ToolbarProps) => react_jsx_runtime.JSX.Element;
121
+ declare const Toolbar: ({ isOpen: isOpenProp, onClose, onScreenRecord, stageRef, onTextAdded, showToggleButton, config, }?: ToolbarProps) => react_jsx_runtime.JSX.Element;
28
122
 
29
123
  declare const SlideNavigation: React$1.FC;
30
124
 
@@ -36,7 +130,7 @@ type ScreenRecorderProps = {
36
130
  };
37
131
  declare const ScreenRecorder: React$1.FC<ScreenRecorderProps>;
38
132
 
39
- type Line$1 = {
133
+ type Line = {
40
134
  id?: string;
41
135
  tool: string;
42
136
  points: number[];
@@ -98,7 +192,7 @@ type ImageElement = {
98
192
  zIndex?: number;
99
193
  timestamp?: number;
100
194
  audioData?: string;
101
- annotations?: Line$1[];
195
+ annotations?: Line[];
102
196
  isDrawingMode?: boolean;
103
197
  };
104
198
  type VideoElement = {
@@ -157,7 +251,7 @@ type PhotoFrameElement = {
157
251
  timestamp?: number;
158
252
  audioData?: string;
159
253
  isCapturing: boolean;
160
- annotations?: Line$1[];
254
+ annotations?: Line[];
161
255
  isDrawingMode?: boolean;
162
256
  };
163
257
  type TextElement = {
@@ -308,7 +402,7 @@ type Slide = {
308
402
  name: string;
309
403
  thumbnail?: string;
310
404
  backgroundColor?: string;
311
- lines: Line$1[];
405
+ lines: Line[];
312
406
  shapes: Shape[];
313
407
  images: ImageElement[];
314
408
  videos: VideoElement[];
@@ -356,7 +450,7 @@ declare const loadSlides: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<{
356
450
  slides: Slide[];
357
451
  currentSlideId: string;
358
452
  }, "canvas/loadSlides">;
359
- declare const addLine: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<Line$1, "canvas/addLine">;
453
+ declare const addLine: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<Line, "canvas/addLine">;
360
454
  declare const removeLine: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<number, "canvas/removeLine">;
361
455
  declare const addImage: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<ImageElement, "canvas/addImage">;
362
456
  declare const updateImage: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<Partial<ImageElement> & {
@@ -401,7 +495,7 @@ declare const duplicatePhotoFrame: _reduxjs_toolkit.ActionCreatorWithOptionalPay
401
495
  declare const toggleImageDrawingMode: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<string, "canvas/toggleImageDrawingMode">;
402
496
  declare const addImageAnnotation: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<{
403
497
  imageId: string;
404
- line: Line$1;
498
+ line: Line;
405
499
  }, "canvas/addImageAnnotation">;
406
500
  declare const updateImageAnnotation: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<{
407
501
  imageId: string;
@@ -411,7 +505,7 @@ declare const clearImageAnnotations: _reduxjs_toolkit.ActionCreatorWithOptionalP
411
505
  declare const togglePhotoFrameDrawingMode: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<string, "canvas/togglePhotoFrameDrawingMode">;
412
506
  declare const addPhotoFrameAnnotation: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<{
413
507
  frameId: string;
414
- line: Line$1;
508
+ line: Line;
415
509
  }, "canvas/addPhotoFrameAnnotation">;
416
510
  declare const updatePhotoFrameAnnotation: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<{
417
511
  frameId: string;
@@ -484,7 +578,7 @@ declare const setAudioData: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<{
484
578
  }, "canvas/setAudioData">;
485
579
  declare const updateLastLine: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<number[], "canvas/updateLastLine">;
486
580
  declare const finalizeDrawing: _reduxjs_toolkit.ActionCreatorWithoutPayload<"canvas/finalizeDrawing">;
487
- declare const setLines: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<Line$1[], "canvas/setLines">;
581
+ declare const setLines: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<Line[], "canvas/setLines">;
488
582
  declare const updateLinePosition: _reduxjs_toolkit.ActionCreatorWithOptionalPayload<{
489
583
  id: string;
490
584
  x: number;
@@ -546,82 +640,6 @@ interface PublishButtonProps {
546
640
  }
547
641
  declare const PublishButton: React$1.FC<PublishButtonProps>;
548
642
 
549
- interface EditorRootProps {
550
- children: React$1.ReactNode;
551
- className?: string;
552
- style?: React$1.CSSProperties;
553
- }
554
- /**
555
- * EditorRoot wraps the konva editor components and scopes all Tailwind styles
556
- * to prevent conflicts with host application styles.
557
- *
558
- * All konva-editor Tailwind utilities are scoped to the .konva-editor-root class
559
- * via the `important` setting in tailwind.config.js
560
- *
561
- * Default styles are applied for full-screen layout. Override with the style prop if needed.
562
- */
563
- declare function EditorRoot({ children, className, style }: EditorRootProps): react_jsx_runtime.JSX.Element;
564
-
565
- type TopNavBarProps = {
566
- /** Title displayed in the header */
567
- title?: string;
568
- /** Auto-save status message */
569
- autoSaveMessage?: string;
570
- /** Callback when back button is clicked */
571
- onBack?: () => void;
572
- /** Callback when settings button is clicked */
573
- onSettings?: () => void;
574
- /** Callback when user/profile button is clicked */
575
- onProfile?: () => void;
576
- /** Function to publish slides (passed to PublishButton) */
577
- onPublish?: PublishButtonProps['onPublish'];
578
- /** Whether to show the publish button */
579
- showPublishButton?: boolean;
580
- /** Whether to show the settings button */
581
- showSettingsButton?: boolean;
582
- /** Whether to show the profile button */
583
- showProfileButton?: boolean;
584
- /** Whether to show the back button */
585
- showBackButton?: boolean;
586
- /** Custom class name for the container */
587
- className?: string;
588
- /** Custom content to render on the right side (replaces default buttons) */
589
- rightContent?: React$1.ReactNode;
590
- /** Custom content to render on the left side (replaces default content) */
591
- leftContent?: React$1.ReactNode;
592
- };
593
- declare const TopNavBar: React$1.FC<TopNavBarProps>;
594
-
595
- type BottomToolbarProps = {
596
- /** Custom colors array to override defaults */
597
- colors?: Array<{
598
- name: string;
599
- value: string;
600
- }>;
601
- /** Whether to show the size slider */
602
- showSizeSlider?: boolean;
603
- /** Whether to show the color picker */
604
- showColorPicker?: boolean;
605
- /** Whether to show the background color picker */
606
- showBackgroundPicker?: boolean;
607
- /** Custom class name for the container */
608
- className?: string;
609
- };
610
- declare const BottomToolbar: React$1.FC<BottomToolbarProps>;
611
-
612
- type LayerItem = {
613
- id: string;
614
- type: 'image' | 'video' | 'shape' | 'text' | 'flashcard' | 'photoFrame' | 'mcq' | 'trueFalse' | 'shortAnswer' | 'longAnswer' | 'fillInTheBlanks' | 'line';
615
- name: string;
616
- timestamp: number;
617
- };
618
- type LayersPanelProps = {
619
- selectedElementId?: string;
620
- onClose: () => void;
621
- onSelectElement: (id: string, type: LayerItem['type']) => void;
622
- };
623
- declare const LayersPanel: React$1.FC<LayersPanelProps>;
624
-
625
643
  type ToolbarState = {
626
644
  selectedTool: string;
627
645
  penColor: string;
@@ -677,60 +695,6 @@ declare const exportSlideAsImage: (stage: Konva.Stage, options?: ExportOptions)
677
695
  declare const exportSlideAsBlob: (stage: Konva.Stage, options?: Omit<ExportOptions, "fileName">) => Promise<Blob>;
678
696
  declare const getSlideDataURL: (stage: Konva.Stage, options?: Omit<ExportOptions, "fileName">) => string;
679
697
 
680
- /**
681
- * Line simplification utilities using Douglas-Peucker algorithm
682
- * Reduces the number of points in a line while preserving its shape
683
- */
684
- /**
685
- * Simplify a flat points array using Douglas-Peucker algorithm
686
- *
687
- * @param flatPoints Array of points [x1, y1, x2, y2, ...]
688
- * @param epsilon Tolerance for simplification (default: 1.5 pixels)
689
- * @returns Simplified flat points array
690
- */
691
- declare const simplifyFlatPoints: (flatPoints: number[], epsilon?: number) => number[];
692
- /**
693
- * Line type matching the canvasSlice Line type
694
- */
695
- type Line = {
696
- id?: string;
697
- tool: string;
698
- points: number[];
699
- color: string;
700
- strokeWidth: number;
701
- isSketch?: boolean;
702
- timestamp?: number;
703
- x?: number;
704
- y?: number;
705
- scaleX?: number;
706
- scaleY?: number;
707
- rotation?: number;
708
- };
709
- /**
710
- * Simplify a single line's points using Douglas-Peucker algorithm
711
- *
712
- * @param line The line object to simplify
713
- * @param epsilon Tolerance for simplification
714
- * @returns New line object with simplified points
715
- */
716
- declare const simplifyLine: (line: Line, epsilon?: number) => Line;
717
- /**
718
- * Simplify an array of lines
719
- *
720
- * @param lines Array of line objects
721
- * @param epsilon Tolerance for simplification
722
- * @returns Array of lines with simplified points
723
- */
724
- declare const simplifyLines: (lines: Line[], epsilon?: number) => Line[];
725
- /**
726
- * Calculate compression ratio for debugging/logging
727
- */
728
- declare const getCompressionStats: (original: number[], simplified: number[]) => {
729
- originalPoints: number;
730
- simplifiedPoints: number;
731
- reduction: string;
732
- };
733
-
734
698
  declare const useDispatch: () => redux_thunk.ThunkDispatch<{
735
699
  toolbar: ToolbarState;
736
700
  canvas: {
@@ -748,4 +712,4 @@ declare const useSelector: <T>(selector: (state: RootState) => T) => T;
748
712
 
749
713
  declare const useSlidesPersistence: () => void;
750
714
 
751
- export { type AppDispatch, BottomToolbar, type BottomToolbarProps, Canvas, type CanvasProps, EditorRoot, type EditorRootProps, type ExportOptions, type FillInTheBlanks, type FlashcardElement, type ImageElement, LayersPanel, type Line$1 as Line, type LongAnswer, type MultipleChoice, type PhotoFrameElement, PublishButton, type PublishButtonProps, type PublishProgress, type PublishResponse, type RootState, ScreenRecorder, type Shape, type ShortAnswer, type Slide, SlideNavigation, type TextElement, Toolbar, type ToolbarProps, TopNavBar, type TopNavBarProps, type TrueFalse, type VideoElement, addFillInTheBlanks, addFlashcard, addImage, addImageAnnotation, addLine, addLongAnswer, addMultipleChoice, addPhotoFrame, addPhotoFrameAnnotation, addShape, addShortAnswer, addSlide, addText, addTrueFalse, addVideo, bringToFront, clearCanvas, clearImageAnnotations, clearPhotoFrameAnnotations, deleteFillInTheBlanks, deleteFlashcard, deleteImage, deleteLineById, deleteLongAnswer, deleteMultipleChoice, deletePhotoFrame, deleteShape, deleteShortAnswer, deleteSlide, deleteText, deleteTrueFalse, deleteVideo, duplicateFillInTheBlanks, duplicateFlashcard, duplicateImage, duplicateLine, duplicateLongAnswer, duplicateMultipleChoice, duplicatePhotoFrame, duplicateShape, duplicateShortAnswer, duplicateSlide, duplicateText, duplicateTrueFalse, duplicateVideo, editFlashcard, editMultipleChoice, exportSlideAsBlob, exportSlideAsImage, finalizeDrawing, getCompressionStats, getSlideDataURL, loadSlides, nextFlashcard, previousFlashcard, redo, removeLine, reorderSlides, saveToHistory, selectAllSlides, selectCanAddSlide, selectCurrentSlide, selectCurrentSlideId, selectSlideById, sendToBack, setActivityType, setAltText, setAudioData, setBackgroundColor, setCurrentSlide, setEditingActivity, setEditingTextId, setLines, setLink, setPenColor, setShowFlashcardForm, setShowMcqForm, setSketchMode, setStrokeWidth, setTool, simplifyFlatPoints, simplifyLine, simplifyLines, store, toggleImageDrawingMode, toggleLock, togglePhotoFrameDrawingMode, toggleSketchMode, toggleVideoPlaying, undo, updateElementOrder, updateFillInTheBlanks, updateFlashcard, updateImage, updateImageAnnotation, updateLastLine, updateLinePosition, updateLineTransform, updateLongAnswer, updateMultipleChoice, updatePhotoFrame, updatePhotoFrameAnnotation, updateShape, updateShortAnswer, updateSlideThumbnail, updateText, updateTrueFalse, updateVideo, useDispatch, useSelector, useSlidesPersistence };
715
+ export { type ActionType, type ActivityType, type AppDispatch, BASIC_EDITOR_TOOLBAR_CONFIG, Canvas, type CanvasProps, type ContextMenuConfig, DEFAULT_CONTEXT_MENU_CONFIG, DEFAULT_TOOLBAR_CONFIG, type ExportOptions, type FillInTheBlanks, type FlashcardElement, type ImageElement, type Line, type LongAnswer, type MediaType, type MultipleChoice, type PhotoFrameElement, PublishButton, type PublishButtonProps, type PublishProgress, type PublishResponse, type RootState, ScreenRecorder, type Shape, type ShapeType, type ShortAnswer, type Slide, SlideNavigation, type TextElement, type ToolType, Toolbar, type ToolbarActionsConfig, type ToolbarConfig, type ToolbarProps, type ToolbarToolsConfig, type TrueFalse, VIEWER_TOOLBAR_CONFIG, type VideoElement, addFillInTheBlanks, addFlashcard, addImage, addImageAnnotation, addLine, addLongAnswer, addMultipleChoice, addPhotoFrame, addPhotoFrameAnnotation, addShape, addShortAnswer, addSlide, addText, addTrueFalse, addVideo, bringToFront, clearCanvas, clearImageAnnotations, clearPhotoFrameAnnotations, deleteFillInTheBlanks, deleteFlashcard, deleteImage, deleteLineById, deleteLongAnswer, deleteMultipleChoice, deletePhotoFrame, deleteShape, deleteShortAnswer, deleteSlide, deleteText, deleteTrueFalse, deleteVideo, duplicateFillInTheBlanks, duplicateFlashcard, duplicateImage, duplicateLine, duplicateLongAnswer, duplicateMultipleChoice, duplicatePhotoFrame, duplicateShape, duplicateShortAnswer, duplicateSlide, duplicateText, duplicateTrueFalse, duplicateVideo, editFlashcard, editMultipleChoice, exportSlideAsBlob, exportSlideAsImage, finalizeDrawing, getSlideDataURL, loadSlides, mergeToolbarConfig, nextFlashcard, previousFlashcard, redo, removeLine, reorderSlides, saveToHistory, selectAllSlides, selectCanAddSlide, selectCurrentSlide, selectCurrentSlideId, selectSlideById, sendToBack, setActivityType, setAltText, setAudioData, setBackgroundColor, setCurrentSlide, setEditingActivity, setEditingTextId, setLines, setLink, setPenColor, setShowFlashcardForm, setShowMcqForm, setSketchMode, setStrokeWidth, setTool, store, toggleImageDrawingMode, toggleLock, togglePhotoFrameDrawingMode, toggleSketchMode, toggleVideoPlaying, undo, updateElementOrder, updateFillInTheBlanks, updateFlashcard, updateImage, updateImageAnnotation, updateLastLine, updateLinePosition, updateLineTransform, updateLongAnswer, updateMultipleChoice, updatePhotoFrame, updatePhotoFrameAnnotation, updateShape, updateShortAnswer, updateSlideThumbnail, updateText, updateTrueFalse, updateVideo, useDispatch, useSelector, useSlidesPersistence };