MCPcopy
hub / github.com/mifi/editly / getPositionProps

Function getPositionProps

util.js:74–132  ·  view source on GitHub ↗
({ position, width, height })

Source from the content-addressed store, hash-verified

72export const multipleOf2 = (x) => Math.round(x / 2) * 2;
73
74export function getPositionProps({ position, width, height }) {
75 let originY = 'center';
76 let originX = 'center';
77 let top = height / 2;
78 let left = width / 2;
79
80 const margin = 0.05;
81 if (position === 'top') {
82 originY = 'top';
83 top = height * margin;
84 } else if (position === 'bottom') {
85 originY = 'bottom';
86 top = height * (1 - margin);
87 } else if (position === 'center') {
88 originY = 'center';
89 top = height / 2;
90 } else if (position === 'top-left') {
91 originX = 'left';
92 originY = 'top';
93 left = width * margin;
94 top = height * margin;
95 } else if (position === 'top-right') {
96 originX = 'right';
97 originY = 'top';
98 left = width * (1 - margin);
99 top = height * margin;
100 } else if (position === 'center-left') {
101 originX = 'left';
102 originY = 'center';
103 left = width * margin;
104 top = height / 2;
105 } else if (position === 'center-right') {
106 originX = 'right';
107 originY = 'center';
108 left = width * (1 - margin);
109 top = height / 2;
110 } else if (position === 'bottom-left') {
111 originX = 'left';
112 originY = 'bottom';
113 left = width * margin;
114 top = height * (1 - margin);
115 } else if (position === 'bottom-right') {
116 originX = 'right';
117 originY = 'bottom';
118 left = width * (1 - margin);
119 top = height * (1 - margin);
120 }
121
122 if (position && position.x != null) {
123 originX = position.originX || 'left';
124 left = width * position.x;
125 }
126 if (position && position.y != null) {
127 originY = position.originY || 'top';
128 top = height * position.y;
129 }
130
131 return { originX, originY, top, left };

Callers 2

imageOverlayFrameSourceFunction · 0.90
onRenderFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected