CoolFace
Datasetpublic

basant307/AI_Governance_Project

sourceHugging Faceapache-2.0updated 2mo agoView on Hugging Face
0likes48downloads
state.mjs148 linesDownload Raw Back to selector
1import * as util from '../util/index.mjs';2 3export const stateSelectors = [4  {5    selector: ':selected',6    matches: function( ele ){ return ele.selected(); }7  },8  {9    selector: ':unselected',10    matches: function( ele ){ return !ele.selected(); }11  },12  {13    selector: ':selectable',14    matches: function( ele ){ return ele.selectable(); }15  },16  {17    selector: ':unselectable',18    matches: function( ele ){ return !ele.selectable(); }19  },20  {21    selector: ':locked',22    matches: function( ele ){ return ele.locked(); }23  },24  {25    selector: ':unlocked',26    matches: function( ele ){ return !ele.locked(); }27  },28  {29    selector: ':visible',30    matches: function( ele ){ return ele.visible(); }31  },32  {33    selector: ':hidden',34    matches: function( ele ){ return !ele.visible(); }35  },36  {37    selector: ':transparent',38    matches: function( ele ){ return ele.transparent(); }39  },40  {41    selector: ':grabbed',42    matches: function( ele ){ return ele.grabbed(); }43  },44  {45    selector: ':free',46    matches: function( ele ){ return !ele.grabbed(); }47  },48  {49    selector: ':removed',50    matches: function( ele ){ return ele.removed(); }51  },52  {53    selector: ':inside',54    matches: function( ele ){ return !ele.removed(); }55  },56  {57    selector: ':grabbable',58    matches: function( ele ){ return ele.grabbable(); }59  },60  {61    selector: ':ungrabbable',62    matches: function( ele ){ return !ele.grabbable(); }63  },64  {65    selector: ':animated',66    matches: function( ele ){ return ele.animated(); }67  },68  {69    selector: ':unanimated',70    matches: function( ele ){ return !ele.animated(); }71  },72  {73    selector: ':parent',74    matches: function( ele ){ return ele.isParent(); }75  },76  {77    selector: ':childless',78    matches: function( ele ){ return ele.isChildless(); }79  },80  {81    selector: ':child',82    matches: function( ele ){ return ele.isChild(); }83  },84  {85    selector: ':orphan',86    matches: function( ele ){ return ele.isOrphan(); }87  },88  {89    selector: ':nonorphan',90    matches: function( ele ){ return ele.isChild(); }91  },92  {93    selector: ':compound',94    matches: function( ele ){95      if( ele.isNode() ){96        return ele.isParent();97      } else {98        return ele.source().isParent() || ele.target().isParent();99      }100    }101  },102  {103    selector: ':loop',104    matches: function( ele ){ return ele.isLoop(); }105  },106  {107    selector: ':simple',108    matches: function( ele ){ return ele.isSimple(); }109  },110  {111    selector: ':active',112    matches: function( ele ){ return ele.active(); }113  },114  {115    selector: ':inactive',116    matches: function( ele ){ return !ele.active(); }117  },118  {119    selector: ':backgrounding',120    matches: function( ele ){ return ele.backgrounding(); }121  },122  {123    selector: ':nonbackgrounding',124    matches: function( ele ){ return !ele.backgrounding(); }125  }126].sort(function( a, b ){ // n.b. selectors that are starting substrings of others must have the longer ones first127  return util.sort.descending( a.selector, b.selector );128});129 130let lookup = (function(){131  let selToFn = {};132  let s;133 134  for( let i = 0; i < stateSelectors.length; i++ ){135    s = stateSelectors[i];136 137    selToFn[ s.selector ] = s.matches;138  }139 140  return selToFn;141})();142 143export const stateSelectorMatches = function( sel, ele ){144  return lookup[ sel ]( ele );145};146 147export const stateSelectorRegex = '(' + stateSelectors.map(s => s.selector).join('|') + ')';148 
basant307/AI_Governance_Project · CoolFace