See `8.11.2.2 Optional Content Membership Dictionaries` -> `VE` entry. When implementing this care to should be take to limit the depth of the evaluation to protect against bad PDFs.
if (group.type === "OCG") {
      if (!this._groups.has(group.id)) {
        warn(`Optional content group not found: ${group.id}`);
        return true;
      }
      return this._groups.get(group.id).visible;
    } else if (group.type === "OCMD") {
      
      
      if (group.expression) {
        warn("Visibility expression not supported yet.");
      }
      if (!group.policy || group.policy === "AnyOn") {
        
        for (const id of group.ids) {
          if (!this._groups.has(id)) {
            warn(`Optional content group not found: ${id}`);
            return true;
          }
          if (this._groups.get(id).visible) {
            return true;
          }
        }
        return false;
      } else if (group.policy === "AllOn") {
        for (const id of group.ids) {
          if (!this._groups.has(id)) {
            warn(`Optional content group not found: ${id}`);
            return true;