function getElementsFromOption(option, legacySelector, parent = document) {
  /** @type {HTMLElement[]} */
  let elements = [];

  if (option instanceof Element) {
    elements = [option];
  } else if (option instanceof NodeList || Array.isArray(option)) {
    elements = Array.from(option);
  } else {
    const selector = typeof option === 'string' ? option : legacySelector;

    if (selector) {
      elements = Array.from(parent.querySelectorAll(selector));
    }
  }

  return elements;
}
Parse `gallery` or `children` options.

@param {import('../photoswipe.js').ElementProvider} [option]
@param {string} [legacySelector]
@param {HTMLElement | Document} [parent]
@returns HTMLElement[]