MCPcopy Create free account
hub / github.com/code100x/cms / setupZoomFeatures

Function setupZoomFeatures

src/components/VideoPlayer2.tsx:113–311  ·  view source on GitHub ↗
(player: any)

Source from the content-addressed store, hash-verified

111 };
112
113 const setupZoomFeatures = (player: any) => {
114 if (typeof window === 'undefined' || typeof document === 'undefined') return;
115
116 const videoEl = player.el().querySelector('video');
117 const container = player.el();
118
119 const transformState: TransformState = {
120 scale: 1,
121 lastScale: 1,
122 translateX: 0,
123 translateY: 0,
124 lastPanX: 0,
125 lastPanY: 0
126 };
127
128 // Zoom indicator
129 const zoomIndicator = document.createElement('div') as ZoomIndicator;
130 zoomIndicator.className = 'vjs-zoom-level';
131 container.appendChild(zoomIndicator);
132
133 // Optimized boundary calculation with memoization
134 const calculateBoundaries = (() => {
135 let lastDimensions: { width: number; height: number };
136
137 return () => {
138 const containerRect = container.getBoundingClientRect();
139 const videoAspect = videoEl.videoWidth / videoEl.videoHeight;
140
141 // returning cached values if dimensions haven't changed
142 if (lastDimensions?.width === containerRect.width &&
143 lastDimensions?.height === containerRect.height) {
144 return lastDimensions;
145 }
146
147 const containerAspect = containerRect.width / containerRect.height;
148 let actualWidth = containerRect.width;
149 let actualHeight = containerRect.height;
150
151 actualWidth = containerAspect > videoAspect
152 ? actualHeight * videoAspect
153 : actualWidth;
154 actualHeight = containerAspect > videoAspect
155 ? actualHeight
156 : actualWidth / videoAspect;
157
158 lastDimensions = {
159 width: actualWidth,
160 height: actualHeight
161 };
162
163 return lastDimensions;
164 };
165 })();
166
167 // Unified gesture handler
168 const handleGestureControl = (e: any) => {
169 const target = e.srcEvent.target as HTMLElement;
170 const isControlBar = target.closest('.vjs-control-bar');

Callers 1

VideoPlayerFunction · 0.85

Calls 4

handleGestureControlFunction · 0.85
updateTransformFunction · 0.85
showZoomLevelFunction · 0.85
resetZoomFunction · 0.85

Tested by

no test coverage detected