function findVisibleTextLayerInfos(parent) {
  let visibleTextLayers = util.getAllLayersMatchingPredicate(
      parent,
      TEXT_LAYER_PREDICATE);

  visibleTextLayers = visibleTextLayers.filter(layer => {
    while (layer && layer !== parent) {
      if (!layer.isVisible()) {
        return false;
      }
      layer = layer.parentGroup();
    }

    return true;
  });

  let visibleTextLayerInfos = visibleTextLayers.map(layer => {
    let frame = layer.frame();
    let rectangle = { x: frame.x(), y: frame.y(), w: frame.width(), h: frame.height() };
    let parent = layer.parentGroup();
    let opacity = 1;
    while (parent && !(parent instanceof MSArtboardGroup || parent instanceof MSSymbolMaster)) {
      rectangle.x += parent.frame().x();
      rectangle.y += parent.frame().y();
      opacity *= parent.style().contextSettings().opacity();
      parent = parent.parentGroup();
    }

    return {
      layer,
      opacity,
      rectangle
    };
  });

  let symbolInstances = util.getAllLayersMatchingPredicate(
      parent,
      NSPredicate.predicateWithFormat('className == %@', 'MSSymbolInstance'))
      .filter(symbolInstance => doesSymbolInstanceHaveTextLayers(symbolInstance));
  for (let symbolInstance of symbolInstances) {
    // symbol instance has text layers; detach it to a group to allow hiding them
    // before doing that, see if the symbol includes its background in instances
    let master = symbolInstance.symbolMaster();
    let frame = symbolInstance.frame();
    let bgColor = (master && master.includeBackgroundColorInInstance())
        ? master.backgroundColor() : null;
    let detachedSymbol;
    if (symbolInstance.detachStylesAndReplaceWithGroupRecursively) {
      let map = symbolInstance.detachStylesAndReplaceWithGroupRecursively();
      detachedSymbol = map.objectForKey(symbolInstance.immutableModelObject());
    } else {
      detachedSymbol = symbolInstance.detachByReplacingWithGroup();
    }

    if (detachedSymbol) {
      visibleTextLayerInfos = [
        ...visibleTextLayerInfos,
        ...findVisibleTextLayerInfos(detachedSymbol)
      ];
    }
    if (bgColor) {
      let bgLayer = MSShapeGroup.shapeWithRect(
          NSMakeRect(frame.x(), frame.y(), frame.width(), frame.height()));
      let fill = bgLayer.style().addStylePartOfType(util.StylePartType.FILL);
      fill.color = bgColor;
      detachedSymbol.parentGroup().insertLayer_beforeLayer_(bgLayer, detachedSymbol);
    }
  }

  return visibleTextLayerInfos;
}
/**
 * Deep-search for visible MSTextLayers in the given parent layer, returning an array
 * containing the layer, its frame rectangle, and effective opacity.
 *
 * Has side effects! Will detach symbols.
 */
Deep-search for visible MSTextLayers in the given parent layer, returning an array
containing the layer, its frame rectangle, and effective opacity.

Has side effects. Will detach symbols.
Deep - search for visible MSTextLayers in the given parent layer returning an array containing the layer its frame rectangle and effective opacity . Has side effects . Will detach symbols .
function findVisibleTextLayerInfos(parent) {
  let visibleTextLayers = util.getAllLayersMatchingPredicate(
      parent,
      TEXT_LAYER_PREDICATE);
  visibleTextLayers = visibleTextLayers.filter(layer => {
    while (layer && layer !== parent) {
      if (!layer.isVisible()) {
        return false;
      }
      layer = layer.parentGroup();
    }
    return true;
  });
  let visibleTextLayerInfos = visibleTextLayers.map(layer => {
    let frame = layer.frame();
    let rectangle = { x: frame.x(), y: frame.y(), w: frame.width(), h: frame.height() };
    let parent = layer.parentGroup();
    let opacity = 1;
    while (parent && !(parent instanceof MSArtboardGroup || parent instanceof MSSymbolMaster)) {
      rectangle.x += parent.frame().x();
      rectangle.y += parent.frame().y();
      opacity *= parent.style().contextSettings().opacity();
      parent = parent.parentGroup();
    }
    return {
      layer,
      opacity,
      rectangle
    };
  });
  let symbolInstances = util.getAllLayersMatchingPredicate(
      parent,
      NSPredicate.predicateWithFormat('className == %@', 'MSSymbolInstance'))
      .filter(symbolInstance => doesSymbolInstanceHaveTextLayers(symbolInstance));
  for (let symbolInstance of symbolInstances) {
    let master = symbolInstance.symbolMaster();
    let frame = symbolInstance.frame();
    let bgColor = (master && master.includeBackgroundColorInInstance())
        ? master.backgroundColor() : null;
    let detachedSymbol;
    if (symbolInstance.detachStylesAndReplaceWithGroupRecursively) {
      let map = symbolInstance.detachStylesAndReplaceWithGroupRecursively();
      detachedSymbol = map.objectForKey(symbolInstance.immutableModelObject());
    } else {
      detachedSymbol = symbolInstance.detachByReplacingWithGroup();
    }
    if (detachedSymbol) {
      visibleTextLayerInfos = [
        ...visibleTextLayerInfos,
        ...findVisibleTextLayerInfos(detachedSymbol)
      ];
    }
    if (bgColor) {
      let bgLayer = MSShapeGroup.shapeWithRect(
          NSMakeRect(frame.x(), frame.y(), frame.width(), frame.height()));
      let fill = bgLayer.style().addStylePartOfType(util.StylePartType.FILL);
      fill.color = bgColor;
      detachedSymbol.parentGroup().insertLayer_beforeLayer_(bgLayer, detachedSymbol);
    }
  }
  return visibleTextLayerInfos;
}
function findVisibleTextLayerInfos ( parent ) { let visibleTextLayers = util . getAllLayersMatchingPredicate ( parent , TEXT_LAYER_PREDICATE ) ; visibleTextLayers = visibleTextLayers . filter ( layer => { while ( layer && layer !== parent ) { if ( ! layer . isVisible ( ) ) { return false ; } layer = layer . parentGroup ( ) ; } return true ; } ) ; let visibleTextLayerInfos = visibleTextLayers . map ( layer => { let frame = layer . frame ( ) ; let rectangle = { x : frame . x ( ) , y : frame . y ( ) , w : frame . width ( ) , h : frame . height ( ) } ; let parent = layer . parentGroup ( ) ; let opacity = 1 ; while ( parent && ! ( parent instanceof MSArtboardGroup || parent instanceof MSSymbolMaster ) ) { rectangle . x += parent . frame ( ) . x ( ) ; rectangle . y += parent . frame ( ) . y ( ) ; opacity *= parent . style ( ) . contextSettings ( ) . opacity ( ) ; parent = parent . parentGroup ( ) ; } return { layer , opacity , rectangle } ; } ) ; let symbolInstances = util . getAllLayersMatchingPredicate ( parent , NSPredicate . predicateWithFormat ( 'className == %@' , 'MSSymbolInstance' ) ) . filter ( symbolInstance => doesSymbolInstanceHaveTextLayers ( symbolInstance ) ) ; for ( let symbolInstance of symbolInstances ) { let master = symbolInstance . symbolMaster ( ) ; let frame = symbolInstance . frame ( ) ; let bgColor = ( master && master . includeBackgroundColorInInstance ( ) ) ? master . backgroundColor ( ) : null ; let detachedSymbol ; if ( symbolInstance . detachStylesAndReplaceWithGroupRecursively ) { let map = symbolInstance . detachStylesAndReplaceWithGroupRecursively ( ) ; detachedSymbol = map . objectForKey ( symbolInstance . immutableModelObject ( ) ) ; } else { detachedSymbol = symbolInstance . detachByReplacingWithGroup ( ) ; } if ( detachedSymbol ) { visibleTextLayerInfos = [ ... visibleTextLayerInfos , ... findVisibleTextLayerInfos ( detachedSymbol ) ] ; } if ( bgColor ) { let bgLayer = MSShapeGroup . shapeWithRect ( NSMakeRect ( frame . x ( ) , frame . y ( ) , frame . width ( ) , frame . height ( ) ) ) ; let fill = bgLayer . style ( ) . addStylePartOfType ( util . StylePartType . FILL ) ; fill . color = bgColor ; detachedSymbol . parentGroup ( ) . insertLayer_beforeLayer_ ( bgLayer , detachedSymbol ) ; } } return visibleTextLayerInfos ; }
Deep-search for visible MSTextLayers in the given parent layer, returning an array
 containing the layer, its frame rectangle, and effective opacity.
Deep - search for visible MSTextLayers in the given parent layer returning an array containing the layer its frame rectangle and effective opacity .
// symbol instance has text layers; detach it to a group to allow hiding them // before doing that, see if the symbol includes its background in instances