function resolvePrefer()

in packages/editor-core/src/widgets/tip/utils.ts [67:104]


function resolvePrefer(prefer: any, targetRect: any, bounds: any) {
  if (!prefer) {
    if (targetRect.left - bounds.left < 10) {
      return { dir: 'right' };
    } else if (targetRect.top - bounds.top < 10) {
      return { dir: 'bottom' };
    } else if (bounds.bottom - targetRect.bottom < 10) {
      return { dir: 'top' };
    } else if (bounds.right - targetRect.right < 10) {
      return { dir: 'left' };
    }
    return {};
  }
  const force = prefer[0] === '!';
  if (force) {
    prefer = prefer.slice(1);
  }
  let [dir, offset] = prefer.split(/\s+/);
  let forceDirection = false;
  let forceOffset = false;
  if (dir === 'center') {
    dir = 'auto';
    if (!offset) {
      offset = 'center';
    }
  }

  if (force) {
    if (dir && dir !== 'auto') {
      forceDirection = true;
    }
    if (offset && offset !== 'auto') {
      forceOffset = true;
    }
  }

  return { dir, offset, forceDirection, forceOffset };
}