@markup-canvas/react 1.0.0 → 1.0.3
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/README.md +124 -67
- package/dist/index.cjs.js +1 -1
- package/dist/index.esm.js +1 -1
- package/package.json +5 -3
package/README.md
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
# @markup-canvas/react
|
|
2
2
|
|
|
3
|
-
React
|
|
3
|
+
React wrapper for `@markup-canvas/core`.
|
|
4
|
+
|
|
5
|
+
A lightweight, canvas-like container with smooth pan and zoom capabilities for HTML and React content.
|
|
4
6
|
|
|
5
7
|
## ✨ Live Demo
|
|
6
8
|
|
|
@@ -18,7 +20,7 @@ yarn add @markup-canvas/react @markup-canvas/core
|
|
|
18
20
|
|
|
19
21
|
## Usage
|
|
20
22
|
|
|
21
|
-
### Component
|
|
23
|
+
### MarkupCanvas Component
|
|
22
24
|
|
|
23
25
|
```tsx
|
|
24
26
|
import { useRef } from 'react';
|
|
@@ -52,7 +54,126 @@ function App() {
|
|
|
52
54
|
}
|
|
53
55
|
```
|
|
54
56
|
|
|
55
|
-
|
|
57
|
+
#### Props
|
|
58
|
+
|
|
59
|
+
The `MarkupCanvas` component accepts the following props:
|
|
60
|
+
|
|
61
|
+
**Canvas Dimensions**
|
|
62
|
+
|
|
63
|
+
| Prop | Type | Default | Description |
|
|
64
|
+
|------|------|---------|-------------|
|
|
65
|
+
| `width` | `number` | - | Canvas width in pixels |
|
|
66
|
+
| `height` | `number` | - | Canvas height in pixels |
|
|
67
|
+
| `enableAcceleration` | `boolean` | `true` | Enable hardware acceleration |
|
|
68
|
+
|
|
69
|
+
**Interaction Controls**
|
|
70
|
+
|
|
71
|
+
| Prop | Type | Default | Description |
|
|
72
|
+
|------|------|---------|-------------|
|
|
73
|
+
| `enableZoom` | `boolean` | `true` | Enable zoom functionality |
|
|
74
|
+
| `enablePan` | `boolean` | `true` | Enable pan functionality |
|
|
75
|
+
| `enableTouch` | `boolean` | `true` | Enable touch gestures |
|
|
76
|
+
| `enableKeyboard` | `boolean` | `true` | Enable keyboard controls |
|
|
77
|
+
| `limitKeyboardEventsToCanvas` | `boolean` | `true` | Limit keyboard events to when canvas is focused |
|
|
78
|
+
|
|
79
|
+
**Zoom Behavior**
|
|
80
|
+
|
|
81
|
+
| Prop | Type | Default | Description |
|
|
82
|
+
|------|------|---------|-------------|
|
|
83
|
+
| `zoomSpeed` | `number` | `1.2` | Zoom speed factor |
|
|
84
|
+
| `minZoom` | `number` | `0.1` | Minimum zoom level |
|
|
85
|
+
| `maxZoom` | `number` | `10` | Maximum zoom level |
|
|
86
|
+
| `enableTransition` | `boolean` | `false` | Enable smooth transitions |
|
|
87
|
+
| `transitionDuration` | `number` | `300` | Transition duration in ms |
|
|
88
|
+
| `enableAdaptiveSpeed` | `boolean` | `true` | Enable adaptive zoom speed |
|
|
89
|
+
|
|
90
|
+
**Pan Behavior**
|
|
91
|
+
|
|
92
|
+
| Prop | Type | Default | Description |
|
|
93
|
+
|------|------|---------|-------------|
|
|
94
|
+
| `enableLeftDrag` | `boolean` | `true` | Enable left mouse button drag |
|
|
95
|
+
| `enableMiddleDrag` | `boolean` | `true` | Enable middle mouse button drag |
|
|
96
|
+
| `requireSpaceForMouseDrag` | `boolean` | `false` | Require space key for mouse drag |
|
|
97
|
+
| `keyboardPanStep` | `number` | `50` | Keyboard pan step size in pixels |
|
|
98
|
+
| `keyboardFastMultiplier` | `number` | `3` | Fast pan multiplier (with shift key) |
|
|
99
|
+
| `keyboardZoomStep` | `number` | `0.2` | Keyboard zoom step size |
|
|
100
|
+
|
|
101
|
+
**Click-to-Zoom**
|
|
102
|
+
|
|
103
|
+
| Prop | Type | Default | Description |
|
|
104
|
+
|------|------|---------|-------------|
|
|
105
|
+
| `enableClickToZoom` | `boolean` | `false` | Enable click to zoom |
|
|
106
|
+
| `clickZoomLevel` | `number` | `2` | Target zoom level for click-to-zoom |
|
|
107
|
+
| `requireOptionForClickZoom` | `boolean` | `false` | Require Option/Alt key for click-to-zoom |
|
|
108
|
+
|
|
109
|
+
**Visual Elements**
|
|
110
|
+
|
|
111
|
+
| Prop | Type | Default | Description |
|
|
112
|
+
|------|------|---------|-------------|
|
|
113
|
+
| `enableRulers` | `boolean` | `true` | Show rulers on top and left |
|
|
114
|
+
| `enableGrid` | `boolean` | `false` | Show background grid |
|
|
115
|
+
| `gridColor` | `string` | `"#e0e0e0"` | Grid line color |
|
|
116
|
+
|
|
117
|
+
**Ruler Styling**
|
|
118
|
+
|
|
119
|
+
| Prop | Type | Default | Description |
|
|
120
|
+
|------|------|---------|-------------|
|
|
121
|
+
| `rulerBackgroundColor` | `string` | `"#f5f5f5"` | Ruler background color |
|
|
122
|
+
| `rulerBorderColor` | `string` | `"#d0d0d0"` | Ruler border color |
|
|
123
|
+
| `rulerTextColor` | `string` | `"#666666"` | Ruler text color |
|
|
124
|
+
| `rulerMajorTickColor` | `string` | `"#666666"` | Major tick mark color |
|
|
125
|
+
| `rulerMinorTickColor` | `string` | `"#999999"` | Minor tick mark color |
|
|
126
|
+
| `rulerFontSize` | `number` | `12` | Ruler font size in pixels |
|
|
127
|
+
| `rulerFontFamily` | `string` | `"monospace"` | Ruler font family |
|
|
128
|
+
| `rulerUnits` | `string` | `"px"` | Ruler units label |
|
|
129
|
+
|
|
130
|
+
**React-Specific Props**
|
|
131
|
+
|
|
132
|
+
| Prop | Type | Default | Description |
|
|
133
|
+
|------|------|---------|-------------|
|
|
134
|
+
| `children` | `ReactNode` | - | Content to render inside the canvas |
|
|
135
|
+
| `className` | `string` | - | CSS class name |
|
|
136
|
+
| `style` | `CSSProperties` | - | Inline styles |
|
|
137
|
+
|
|
138
|
+
**Callbacks**
|
|
139
|
+
|
|
140
|
+
| Prop | Type | Description |
|
|
141
|
+
|------|------|-------------|
|
|
142
|
+
| `onTransformUpdate` | `(transform: Transform) => void` | Called continuously during transform updates |
|
|
143
|
+
| `onTransformChange` | `(transform: Transform) => void` | Called when transform change completes |
|
|
144
|
+
| `onZoomChange` | `(zoom: number) => void` | Called when zoom level changes |
|
|
145
|
+
| `onPanChange` | `(pan: { x: number; y: number }) => void` | Called when pan position changes |
|
|
146
|
+
| `onReady` | `(canvas: MarkupCanvas) => void` | Called when canvas is ready |
|
|
147
|
+
|
|
148
|
+
**Example with Multiple Props**
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
<MarkupCanvas
|
|
152
|
+
ref={canvasRef}
|
|
153
|
+
width={20000}
|
|
154
|
+
height={15000}
|
|
155
|
+
enableZoom={true}
|
|
156
|
+
enablePan={true}
|
|
157
|
+
enableKeyboard={true}
|
|
158
|
+
enableRulers={true}
|
|
159
|
+
enableGrid={true}
|
|
160
|
+
zoomSpeed={1.2}
|
|
161
|
+
minZoom={0.1}
|
|
162
|
+
maxZoom={10}
|
|
163
|
+
gridColor="#e8e8e8"
|
|
164
|
+
rulerBackgroundColor="#fafafa"
|
|
165
|
+
enableClickToZoom={true}
|
|
166
|
+
clickZoomLevel={2}
|
|
167
|
+
onZoomChange={(zoom) => console.log('Zoom:', zoom)}
|
|
168
|
+
onPanChange={(pan) => console.log('Pan:', pan)}
|
|
169
|
+
onReady={(canvas) => console.log('Canvas ready:', canvas)}
|
|
170
|
+
className="custom-canvas"
|
|
171
|
+
>
|
|
172
|
+
{/* Canvas content */}
|
|
173
|
+
</MarkupCanvas>
|
|
174
|
+
```
|
|
175
|
+
|
|
176
|
+
### useMarkupCanvas Hook
|
|
56
177
|
|
|
57
178
|
The `useMarkupCanvas` hook provides convenient access to canvas methods.
|
|
58
179
|
**Important:** You must pass `initCanvasUtils` to the `onReady` prop for the hook to work properly.
|
|
@@ -90,70 +211,6 @@ function App() {
|
|
|
90
211
|
}
|
|
91
212
|
```
|
|
92
213
|
|
|
93
|
-
## API
|
|
94
|
-
|
|
95
|
-
### Component Props
|
|
96
|
-
|
|
97
|
-
#### Canvas Dimensions
|
|
98
|
-
- `width?: number` - Canvas width in pixels
|
|
99
|
-
- `height?: number` - Canvas height in pixels
|
|
100
|
-
- `enableAcceleration?: boolean` - Enable hardware acceleration
|
|
101
|
-
|
|
102
|
-
#### Interaction Controls
|
|
103
|
-
- `enableZoom?: boolean` - Enable zoom functionality
|
|
104
|
-
- `enablePan?: boolean` - Enable pan functionality
|
|
105
|
-
- `enableTouch?: boolean` - Enable touch gestures
|
|
106
|
-
- `enableKeyboard?: boolean` - Enable keyboard controls
|
|
107
|
-
- `limitKeyboardEventsToCanvas?: boolean` - Limit keyboard events to when canvas is focused
|
|
108
|
-
|
|
109
|
-
#### Zoom Behavior
|
|
110
|
-
- `zoomSpeed?: number` - Zoom speed factor
|
|
111
|
-
- `minZoom?: number` - Minimum zoom level
|
|
112
|
-
- `maxZoom?: number` - Maximum zoom level
|
|
113
|
-
- `enableTransition?: boolean` - Enable smooth transitions
|
|
114
|
-
- `transitionDuration?: number` - Transition duration in ms
|
|
115
|
-
- `enableAdaptiveSpeed?: boolean` - Enable adaptive zoom speed
|
|
116
|
-
|
|
117
|
-
#### Pan Behavior
|
|
118
|
-
- `enableLeftDrag?: boolean` - Enable left mouse button drag
|
|
119
|
-
- `enableMiddleDrag?: boolean` - Enable middle mouse button drag
|
|
120
|
-
- `requireSpaceForMouseDrag?: boolean` - Require space key for mouse drag
|
|
121
|
-
- `keyboardPanStep?: number` - Keyboard pan step size
|
|
122
|
-
- `keyboardFastMultiplier?: number` - Fast pan multiplier (with shift)
|
|
123
|
-
- `keyboardZoomStep?: number` - Keyboard zoom step size
|
|
124
|
-
|
|
125
|
-
#### Click-to-Zoom
|
|
126
|
-
- `enableClickToZoom?: boolean` - Enable click to zoom
|
|
127
|
-
- `clickZoomLevel?: number` - Target zoom level for click-to-zoom
|
|
128
|
-
- `requireOptionForClickZoom?: boolean` - Require Option/Alt key for click-to-zoom
|
|
129
|
-
|
|
130
|
-
#### Visual Elements
|
|
131
|
-
- `enableRulers?: boolean` - Show rulers
|
|
132
|
-
- `enableGrid?: boolean` - Show background grid
|
|
133
|
-
- `gridColor?: string` - Grid line color
|
|
134
|
-
|
|
135
|
-
#### Ruler Styling
|
|
136
|
-
- `rulerBackgroundColor?: string` - Ruler background color
|
|
137
|
-
- `rulerBorderColor?: string` - Ruler border color
|
|
138
|
-
- `rulerTextColor?: string` - Ruler text color
|
|
139
|
-
- `rulerMajorTickColor?: string` - Major tick mark color
|
|
140
|
-
- `rulerMinorTickColor?: string` - Minor tick mark color
|
|
141
|
-
- `rulerFontSize?: number` - Ruler font size
|
|
142
|
-
- `rulerFontFamily?: string` - Ruler font family
|
|
143
|
-
- `rulerUnits?: string` - Ruler units label
|
|
144
|
-
|
|
145
|
-
#### React-Specific Props
|
|
146
|
-
- `children?: ReactNode` - Content to render inside the canvas
|
|
147
|
-
- `className?: string` - CSS class name
|
|
148
|
-
- `style?: CSSProperties` - Inline styles
|
|
149
|
-
|
|
150
|
-
#### Callbacks
|
|
151
|
-
- `onTransformUpdate?: (transform: Transform) => void` - Called on transform update
|
|
152
|
-
- `onTransformChange?: (transform: Transform) => void` - Called on transform change
|
|
153
|
-
- `onZoomChange?: (zoom: number) => void` - Called on zoom change
|
|
154
|
-
- `onPanChange?: (pan: { x: number; y: number }) => void` - Called on pan change
|
|
155
|
-
- `onReady?: (canvas: MarkupCanvas) => void` - Called when canvas is ready
|
|
156
|
-
|
|
157
214
|
## License
|
|
158
215
|
|
|
159
216
|
**CC BY-NC 4.0** - Creative Commons Attribution-NonCommercial 4.0 International
|
package/dist/index.cjs.js
CHANGED
package/dist/index.esm.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@markup-canvas/react",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.3",
|
|
4
4
|
"description": "React components and hooks for markup-canvas",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.cjs.js",
|
|
@@ -8,7 +8,8 @@
|
|
|
8
8
|
"types": "dist/index.d.ts",
|
|
9
9
|
"files": [
|
|
10
10
|
"dist/",
|
|
11
|
-
"src/"
|
|
11
|
+
"src/",
|
|
12
|
+
"README.md"
|
|
12
13
|
],
|
|
13
14
|
"scripts": {
|
|
14
15
|
"build": "rollup -c",
|
|
@@ -25,6 +26,7 @@
|
|
|
25
26
|
},
|
|
26
27
|
"devDependencies": {
|
|
27
28
|
"@biomejs/biome": "2.2.6",
|
|
29
|
+
"@markup-canvas/core": "workspace:*",
|
|
28
30
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
29
31
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
30
32
|
"@types/react": "^19.2.2",
|
|
@@ -53,5 +55,5 @@
|
|
|
53
55
|
"bugs": {
|
|
54
56
|
"url": "https://github.com/fritzbenning/markup-canvas/issues"
|
|
55
57
|
},
|
|
56
|
-
"homepage": "https://
|
|
58
|
+
"homepage": "https://markup-canvas.vercel.app/"
|
|
57
59
|
}
|