File size: 1,027 Bytes
e67f931
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export function scaleTemplate(value, scale) {
  if (typeof value === 'number') return Math.round(value * scale);
  if (typeof value === 'string' && value.match(/^\d+(px)?$/)) return Math.round(parseInt(value,10) * scale);
  return value;
}

// compute overlay x,y from overlay width/height, extra positioning and video size
export function computeXY(overlayW, overlayH, extra = {}, vw = 0, vh = 0) {
  const padX = extra.paddingX || 5;
  const padY = extra.paddingY || 5;
  const posX = extra.positionX || 'center';
  const posY = extra.positionY || 'center';
  let x = 0, y = 0;
  if (posX === 'left' || posX === 'top') x = Math.round((padX / 100) * vw);
  else if (posX === 'right' || posX === 'bottom') x = Math.round(vw - overlayW - (padX / 100) * vw);
  else x = Math.round((vw - overlayW) / 2);

  if (posY === 'top') y = Math.round((padY / 100) * vh);
  else if (posY === 'bottom') y = Math.round(vh - overlayH - (padY / 100) * vh);
  else y = Math.round((vh - overlayH) / 2);
  return { x, y };
}