basant307/AI_Governance_Project
048
1let styfn = {};2 3styfn.appendFromJson = function( json ){4 let style = this;5 6 for( let i = 0; i < json.length; i++ ){7 let context = json[ i ];8 let selector = context.selector;9 let props = context.style || context.css;10 let names = Object.keys( props );11 12 style.selector( selector ); // apply selector13 14 for( let j = 0; j < names.length; j++ ){15 let name = names[j];16 let value = props[ name ];17 18 style.css( name, value ); // apply property19 }20 }21 22 return style;23};24 25// accessible cy.style() function26styfn.fromJson = function( json ){27 let style = this;28 29 style.resetToDefault();30 style.appendFromJson( json );31 32 return style;33};34 35// get json from cy.style() api36styfn.json = function(){37 let json = [];38 39 for( let i = this.defaultLength; i < this.length; i++ ){40 let cxt = this[ i ];41 let selector = cxt.selector;42 let props = cxt.properties;43 let css = {};44 45 for( let j = 0; j < props.length; j++ ){46 let prop = props[ j ];47 css[ prop.name ] = prop.strValue;48 }49 50 json.push( {51 selector: !selector ? 'core' : selector.toString(),52 style: css53 } );54 }55 56 return json;57};58 59export default styfn;60 