|
| 1 | +/** |
| 2 | + * Screen Recording API for Script Kit |
| 3 | + * Enables screen capture with optional area selection |
| 4 | + * |
| 5 | + * These functions are available globally in scripts. |
| 6 | + * This module re-exports them for explicit imports if needed. |
| 7 | + */ |
| 8 | + |
| 9 | +/** |
| 10 | + * Screen source available for recording |
| 11 | + */ |
| 12 | +export interface ScreenSource { |
| 13 | + id: string |
| 14 | + name: string |
| 15 | + thumbnail: string |
| 16 | + displayId: string |
| 17 | +} |
| 18 | + |
| 19 | +/** |
| 20 | + * Area definition for recording a portion of the screen |
| 21 | + */ |
| 22 | +export interface RecordingArea { |
| 23 | + x: number |
| 24 | + y: number |
| 25 | + width: number |
| 26 | + height: number |
| 27 | + displayId?: number |
| 28 | +} |
| 29 | + |
| 30 | +/** |
| 31 | + * Result returned from a screen recording operation |
| 32 | + */ |
| 33 | +export interface ScreenRecordingResult { |
| 34 | + filePath: string |
| 35 | + duration: number |
| 36 | + width: number |
| 37 | + height: number |
| 38 | + cancelled: boolean |
| 39 | +} |
| 40 | + |
| 41 | +/** |
| 42 | + * Result returned from a measurement operation |
| 43 | + */ |
| 44 | +export interface MeasureResult { |
| 45 | + x: number |
| 46 | + y: number |
| 47 | + width: number |
| 48 | + height: number |
| 49 | + right: number |
| 50 | + bottom: number |
| 51 | + centerX: number |
| 52 | + centerY: number |
| 53 | + area: number |
| 54 | + displayId?: string |
| 55 | + scaleFactor?: number |
| 56 | + cancelled: boolean |
| 57 | +} |
| 58 | + |
| 59 | +/** |
| 60 | + * Configuration options for screen recording |
| 61 | + */ |
| 62 | +export interface ScreenRecordOptions { |
| 63 | + /** Video format: 'webm' or 'mp4' (default: 'webm') */ |
| 64 | + format?: 'webm' | 'mp4' |
| 65 | + /** Video quality 0.0-1.0 (default: 0.9) */ |
| 66 | + quality?: number |
| 67 | + /** Frame rate in FPS (default: 30) */ |
| 68 | + frameRate?: number |
| 69 | + /** Include system audio (default: false) */ |
| 70 | + includeAudio?: boolean |
| 71 | + /** Whether to prompt for area selection (default: false for full screen) */ |
| 72 | + selectArea?: boolean |
| 73 | + /** Pre-defined area to record (skips area selection) */ |
| 74 | + area?: RecordingArea |
| 75 | + /** Specific source ID to record (skips source selection) */ |
| 76 | + sourceId?: string |
| 77 | + /** Custom file path for the recording (default: temp directory) */ |
| 78 | + filePath?: string |
| 79 | + /** Maximum recording duration in seconds (0 = unlimited) */ |
| 80 | + maxDuration?: number |
| 81 | + /** Instructions shown to the user during area selection */ |
| 82 | + hint?: string |
| 83 | + /** Whether to show recording controls overlay (default: true) */ |
| 84 | + showControls?: boolean |
| 85 | + /** Whether to show countdown before recording starts (default: true) */ |
| 86 | + countdown?: boolean |
| 87 | + /** Countdown duration in seconds (default: 3) */ |
| 88 | + countdownSeconds?: number |
| 89 | +} |
| 90 | + |
| 91 | +/** |
| 92 | + * Configuration options for the measurement tool |
| 93 | + */ |
| 94 | +export interface MeasureOptions { |
| 95 | + /** Stroke color for the selection rectangle (default: #00ff00) */ |
| 96 | + color?: string |
| 97 | + /** Width of the selection border in pixels (default: 2) */ |
| 98 | + strokeWidth?: number |
| 99 | + /** Opacity of the selection fill (0-1, default: 0.1) */ |
| 100 | + fillOpacity?: number |
| 101 | + /** Whether to show dimension labels (default: true) */ |
| 102 | + showDimensions?: boolean |
| 103 | + /** Whether to show crosshair guides (default: true) */ |
| 104 | + showCrosshair?: boolean |
| 105 | + /** Font size for dimension labels (default: 14) */ |
| 106 | + fontSize?: number |
| 107 | + /** Grid size for snapping, 1 = no snap (default: 1) */ |
| 108 | + gridSnap?: number |
| 109 | + /** Whether to constrain selection to current display (default: false) */ |
| 110 | + constrainToDisplay?: boolean |
| 111 | + /** Whether to allow keyboard adjustments after initial drag (default: true) */ |
| 112 | + allowKeyboardAdjust?: boolean |
| 113 | + /** Instructions shown to the user */ |
| 114 | + hint?: string |
| 115 | + /** Starting position for the overlay (follows cursor if not specified) */ |
| 116 | + startPosition?: { x: number; y: number } |
| 117 | + /** Initial rectangle to display (for editing existing measurement) */ |
| 118 | + initialRect?: { x: number; y: number; width: number; height: number } |
| 119 | + /** Clipboard format when user presses Cmd+C during measurement */ |
| 120 | + clipboardFormat?: 'dimensions' | 'css' | 'json' |
| 121 | +} |
| 122 | + |
| 123 | +/** |
| 124 | + * Get available screen sources for recording |
| 125 | + * @see global.getScreenSources |
| 126 | + */ |
| 127 | +export const getScreenSources = (): Promise<ScreenSource[]> => global.getScreenSources() |
| 128 | + |
| 129 | +/** |
| 130 | + * Start a screen recording session |
| 131 | + * @see global.screenRecord |
| 132 | + */ |
| 133 | +export const screenRecord = (options?: ScreenRecordOptions): Promise<ScreenRecordingResult | null> => |
| 134 | + global.screenRecord(options) |
| 135 | + |
| 136 | +/** |
| 137 | + * Stop an active screen recording |
| 138 | + * @see global.stopScreenRecording |
| 139 | + */ |
| 140 | +export const stopScreenRecording = (): Promise<ScreenRecordingResult | null> => |
| 141 | + global.stopScreenRecording() |
| 142 | + |
| 143 | +/** |
| 144 | + * Pause an active screen recording |
| 145 | + * @see global.pauseScreenRecording |
| 146 | + */ |
| 147 | +export const pauseScreenRecording = (): Promise<boolean> => global.pauseScreenRecording() |
| 148 | + |
| 149 | +/** |
| 150 | + * Resume a paused screen recording |
| 151 | + * @see global.resumeScreenRecording |
| 152 | + */ |
| 153 | +export const resumeScreenRecording = (): Promise<boolean> => global.resumeScreenRecording() |
| 154 | + |
| 155 | +/** |
| 156 | + * Get the current screen recording status |
| 157 | + * @see global.getScreenRecordingStatus |
| 158 | + */ |
| 159 | +export const getScreenRecordingStatus = () => global.getScreenRecordingStatus() |
| 160 | + |
| 161 | +/** |
| 162 | + * Opens a transparent overlay for measuring screen areas |
| 163 | + * @see global.measure |
| 164 | + */ |
| 165 | +export const measure = (options?: MeasureOptions): Promise<MeasureResult | null> => |
| 166 | + global.measure(options) |
0 commit comments