1import{Controller}from"@hotwired/stimulus";export default class extends Controller{static targets=["linked"];static values={prefix:String,postfix:String,sourceSelector:String,separator:{type:String,default:"-"},withIcon:{type:Boolean,default:!1}};connect(){this.sourceSelectorValue.length>0&&(this.charReplacements={"\xc0":"A","\xc1":"A","\xc2":"A","\xc3":"A","\xc4":"A","\xc5":"A","\xc6":"AE","\xc7":"C","\xc8":"E","\xc9":"E","\xca":"E","\xcb":"E","\xcc":"I","\xcd":"I","\xce":"I","\xcf":"I","\xd0":"D","\xd1":"N","\xd2":"O","\xd3":"O","\xd4":"O","\xd5":"O","\xd6":"O","\u0150":"O","\xd8":"O","\xd9":"U","\xda":"U","\xdb":"U","\xdc":"U","\u0170":"U","\xdd":"Y","\xde":"TH","\xdf":"ss","\xe0":"a","\xe1":"a","\xe2":"a","\xe3":"a","\xe4":"a","\xe5":"a","\xe6":"ae","\xe7":"c","\xe8":"e","\xe9":"e","\xea":"e","\xeb":"e","\xec":"i","\xed":"i","\xee":"i","\xef":"i","\xf0":"d","\xf1":"n","\xf2":"o","\xf3":"o","\xf4":"o","\xf5":"o","\xf6":"o","\u0151":"o","\xf8":"o","\xf9":"u","\xfa":"u","\xfb":"u","\xfc":"u","\u0171":"u","\xfd":"y","\xfe":"th","\xff":"y"},this.linkerTarget=document.querySelector(this.sourceSelectorValue),this.hasLinkedTarget&&(this.withIconValue&&this.placeLinkIcon(),this.setupEventListeners(),this.valuesCompared()&&(this.linkedTarget.dataset.linkedWithLinker="1",this.linkIcon&&this.toggleLinkIcon(!0))))}parameterize(e){let t=e.split("").map((e=>this.charReplacements[e]||e)).join("");return""!==t&&(this.hasPreixValue&&(t=`${this.prefixValue}${t}`),this.hasPostfixValue&&(t=`${t}${this.postfixValue}`)),t=t.toLowerCase().replace(/[^a-z0-9]+/g,this.separatorValue),t=t.replace(/(^-|-$|^_|_$)/g,""),t}placeLinkIcon(){this.linkIcon=document.createElement("md-icon-button"),this.linkIcon.className="rotate-90",this.linkIcon.setAttribute("slot","trailing-icon"),this.linkIcon.innerHTML="<md-icon>link</md-icon>",this.linkedTarget.appendChild(this.linkIcon)}toggleLinkIcon(e){this.linkIcon.querySelector("md-icon").textContent=e?"link":"link_off"}valuesCompared(){let e=this.linkedTarget.value;return this.hasPrefixValue&&""!==e&&(e=e.replace(new RegExp(`^${this.prefixValue}`,"g"),""),e=`${this.prefixValue}${e}`,e=e.replace(/(-$|_$)/g,"")),this.hasPostfixValue&&""!==e&&(e=e.replace(new RegExp(`${this.postfixValue}$`,"g"),""),e=`${e}${this.postfixValue}`,e=e.replace(/(^-|^_)/g,"")),this.parameterize(this.linkerTarget.value)===e}compareValues(){this.valuesCompared()&&"1"!==this.linkedTarget.dataset.forceCancelLink?(this.linkedTarget.dataset.linkedWithLinker="1",this.linkIcon&&this.toggleLinkIcon(!0)):(this.linkedTarget.dataset.linkedWithLinker="0",this.linkIcon&&this.toggleLinkIcon(!1))}setupEventListeners(){this.linkerTarget.addEventListener("change",(()=>this.compareValues())),this.linkedTarget.addEventListener("change",(()=>this.compareValues())),this.linkerTarget.addEventListener("keyup",(()=>{"1"!==this.linkedTarget.dataset.forceCancelLink&&"1"===this.linkedTarget.dataset.linkedWithLinker&&(this.linkedTarget.value=this.parameterize(this.linkerTarget.value),this.linkedTarget.parentElement.classList.contains("is-dirty")||this.linkedTarget.parentElement.classList.add("is-dirty"))})),this.linkIcon&&this.linkIcon.addEventListener("click",(e=>{e.preventDefault(),"1"===this.linkedTarget.dataset.forceCancelLink?(this.linkedTarget.dataset.forceCancelLink="0",this.toggleLinkIcon(!0),this.linkedTarget.value=this.parameterize(this.linkerTarget.value),this.linkedTarget.parentElement.classList.add("is-dirty"),this.linkedTarget.dataset.linkedWithLinker="1"):(this.linkedTarget.dataset.forceCancelLink="1",this.toggleLinkIcon(!1),this.linkedTarget.dataset.linkedWithLinker="0")}))}}
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.