function getInheritableProperty({
  dict,
  key,
  getArray = false,
  stopWhenFound = true,
}) {
  let values;
  const visited = new RefSet();

  while (dict instanceof Dict && !(dict.objId && visited.has(dict.objId))) {
    if (dict.objId) {
      visited.put(dict.objId);
    }
    const value = getArray ? dict.getArray(key) : dict.get(key);
    if (value !== undefined) {
      if (stopWhenFound) {
        return value;
      }
      (values ||= []).push(value);
    }
    dict = dict.get("Parent");
  }
  return values;
}
Get the value of an inheritable property.

If the PDF specification explicitly lists a property in a dictionary as
inheritable, then the value of the property may be present in the dictionary
itself or in one or more parents of the dictionary.

If the key is not found in the tree, `undefined` is returned. Otherwise,
the value for the key is returned or, if `stopWhenFound` is `false`, a list
of values is returned.

@param {Dict} dict - Dictionary from where to start the traversal.
@param {string} key - The key of the property to find the value for.
@param {boolean} getArray - Whether or not the value should be fetched as an
  array. The default value is `false`.
@param {boolean} stopWhenFound - Whether or not to stop the traversal when
  the key is found. If set to `false`, we always walk up the entire parent
  chain, for example to be able to find `\Resources` placed on multiple
  levels of the tree. The default value is `true`.