All files / plugins removeHiddenElems.ts

85.71% Statements 6/7
90% Branches 9/10
100% Functions 1/1
85.71% Lines 6/7
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33      1x           5x         5x         2x     3x     1x              
import { JsApi } from '../lib/jsapi';
import { Plugin } from './_types';
 
const regValidPath = /M\s*(?:[-+]?(?:\d*\.\d+|\d+(?:\.|(?!\.)))([eE][-+]?\d+)?(?!\d)\s*,?\s*){2}\D*\d/i;
 
/**
 * Remove hidden elements.
 */
function fn(item: JsApi) {
  Iif (!item.isElem() || item.hasAttr('android:name')) {
    return item;
  }
 
  // Remove paths/clip-paths with empty/invalid path data strings.
  if (
    (item.isElem('path') || item.isElem('clip-path')) &&
    (!item.hasAttr('android:pathData') ||
      !regValidPath.test(item.attr('android:pathData').value))
  ) {
    return undefined;
  }
 
  return item;
}
 
export const removeHiddenElems: Plugin<undefined> = {
  type: 'perItem',
  active: true,
  description: 'removes hidden elements',
  params: undefined,
  fn,
};