function _resolveTarget(sources, index, propagate) {
  const source = sources[index];
  let fill = source.fill;
  const visited = [index];
  let target;

  if (!propagate) {
    return fill;
  }

  while (fill !== false && visited.indexOf(fill) === -1) {
    if (!isFinite(fill)) {
      return fill;
    }

    target = sources[fill];
    if (!target) {
      return false;
    }

    if (target.visible) {
      return fill;
    }

    visited.push(fill);
    fill = target.fill;
  }

  return false;
}
@typedef { import('../../core/core.scale.js').default } Scale
@typedef { import('../../elements/element.line.js').default } LineElement
@typedef { import('../../types/index.js').FillTarget } FillTarget
@typedef { import('../../types/index.js').ComplexFillTarget } ComplexFillTarget