/*
 * Copyright (c) 2018, 2026, Oracle and/or its affiliates.
 * Licensed under The Universal Permissive License (UPL), Version 1.0
 * as shown at https://oss.oracle.com/licenses/upl/
 */
const RULENAME="oj-css-bp-dir-flow";const DESCRIPTION="For best practices, checking for [dir=\"rtl\"] may not be needed on "+"<a href=\"https://www.oracle.com/middleware/technologies/browser-policy.html\">Oracle supported browsers</a>. "+"Try using logical properties where possible - see <a href=\"https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties\">CSS_Logical_Properties</a>.";const SHORT_DESCRIPTION="[dir=\"rtl\"] may not be needed on Oracle supported browsers, try using logical properties instead";const SELECTOR="Selector";const SELECTOR_LIST="SelectorList";const TYPE_SELECTOR="TypeSelector";const PSEUDO_CLASS_SELECTOR="PseudoClassSelector";const ATTRIB_SELECTOR="AttributeSelector";const IDENTIFIER="Identifier";const STRING="String";const HTML="html";const NOT="not";const DIR="dir";const RTL="rtl";const RE=/['"]/g;const HTML_LEN=HTML.length-1;class Rule{getName(){return RULENAME}getDescription(){return DESCRIPTION}getShortDescription(){return SHORT_DESCRIPTION}register(){return{"css-rule":this._onRule}}_onRule(ruleCtx,rule){if(!(rule.prelude&&rule.prelude.children)||rule.prelude.type!==SELECTOR_LIST){return}var a,sels,sel,ch,attr,startIndex,i,j;a=rule.prelude.children;for(i=0;i<a.length;i++){sels=a[i];if(sels.type!=="Selector"){continue}ch=sels.children;for(j=0;j<ch.length;j++){sel=ch[j];if(sel.type===TYPE_SELECTOR&&sel.name==HTML){startIndex=sel.loc.start.offset;attr=this._getAttribSelector(j,ch);if(attr){if(this._checkDir(attr)){this._emit(ruleCtx,attr,startIndex)}}break}}}}_getAttribSelector(x,a){var attr,k;for(k=x+1;k<a.length;k++){attr=a[k];if(attr.type===PSEUDO_CLASS_SELECTOR){if(attr.name===NOT){attr=this._getAttrSelFromPseudo(attr)}else{attr=null}}else if(attr.type!==ATTRIB_SELECTOR){attr=null}break}return attr}_checkDir(attr){var val,name,ret=false;if(attr.name){name=attr.name;if(name.type===IDENTIFIER&&name.name===DIR){val=attr.value;ret=val.type===STRING&&_deQuote(val.value)===RTL}}return ret}_getAttrSelFromPseudo(sel){var ch,n,attr;ch=sel.children;if(ch&&ch.length){n=ch[0];if(n.type===SELECTOR_LIST){n=n.children;if(n&&n.length){n=n[0];if(n.type===SELECTOR){n=n.children;if(n&&n.length){n=n[0];if(n.type===ATTRIB_SELECTOR){attr=n}}}}}}return attr}_emit(ruleCtx,sel,startIndex){var issue=new ruleCtx.Issue(`[dir=${sel.value.value}] : try using logical properties when possible - see https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Logical_Properties`);issue.setPosition(null,null,startIndex+ruleCtx.offset.index,startIndex+ruleCtx.offset.index+HTML_LEN);ruleCtx.reporter.addIssue(issue,ruleCtx)}}function _deQuote(s){return s.replace(RE,"")}module.exports=Rule;