"use strict";var tt=Object.create;var X=Object.defineProperty;var nt=Object.getOwnPropertyDescriptor;var rt=Object.getOwnPropertyNames;var it=Object.getPrototypeOf,st=Object.prototype.hasOwnProperty;var at=(h,e)=>{for(var t in e)X(h,t,{get:e[t],enumerable:!0})},ce=(h,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of rt(e))!st.call(h,r)&&r!==t&&X(h,r,{get:()=>e[r],enumerable:!(n=nt(e,r))||n.enumerable});return h};var m=(h,e,t)=>(t=h!=null?tt(it(h)):{},ce(e||!h||!h.__esModule?X(t,"default",{value:h,enumerable:!0}):t,h)),ot=h=>ce(X({},"__esModule",{value:!0}),h);var _t={};at(_t,{default:()=>Ye});module.exports=ot(_t);var Ue=m(require("yargs")),Ve=m(require("concat-stream")),Ke=require("vscode-oniguruma"),W=m(require("chalk")),Ge=m(require("lodash")),Qe=m(require("os")),qe=require("fs"),Ze=require("yargs/helpers");var Ne=m(require("ignore")),B=m(require("path")),H=m(require("fs")),f=m(require("process")),$=m(require("chalk")),Je=m(require("glob")),ae=m(require("util")),v=m(require("lodash")),oe=m(require("find-config"));var R=m(require("js-beautify")),i=m(require("lodash")),ft=m(require("vscode-textmate")),w=m(require("detect-indent")),Fe=m(require("aigle")),ke=m(require("xregexp")),Y=require("@shufo/tailwindcss-class-sorter"),se=require("html-attribute-sorter");var Be=require("fs"),Ie=m(require("lodash")),ie=m(require("vscode-oniguruma")),Re=m(require("path"));var S=m(require("lodash")),ge=m(require("fs")),fe=m(require("os")),K=m(require("chalk")),G=m(require("prettier/standalone")),Q=m(require("@prettier/plugin-php/standalone")),lt=m(require("detect-indent"));var z=m(require("lodash")),A="@",P=["@alert","@pushonce","@push","@slot","@switch","@unless","@verbatim","@prependonce","@prepend","@once","@error","@empty","@guest","@isset","@permission","@permissions","@canany","@cannot","@can","@role","@hasrole","@hasanyrole","@hasallroles","@unlessrole","@hasexactroles","@if","@production","@env","@while","@auth","@forelse","@for","@foreach","@php","@component","@section","@customdirective"],he=z.default.map(P,h=>h.substring(1)),E=["@endalert","@endpushonce","@endpush","@endslot","@endswitch","@endunless","@endverbatim","@show","@stop","@endprependonce","@endprepend","@endonce","@enderror","@append","@overwrite","@endempty","@endguest","@endisset","@endpermission","@endpermissions","@endcanany","@endcannot","@endcan","@endrole","@endhasrole","@endhasanyrole","@endhasallroles","@endunlessrole","@endhasexactroles","@endif","@endproduction","@endenv","@endwhile","@endauth","@endforelse","@endforeach","@endfor","@endphp","@endcomponent","@endsection","@endcustomdirective"],D=["@elseenv","@elseif","@elsecanany","@elsecannot","@elsecan","@else","@elsecustomdirective"],ee={"@section":2,"@push":2,"@prepend":2,"@slot":2},pe=["@forelse","@if"],te=["@empty"],de=["@default"],T=["@forelse","@if","@for","@foreach","@while","@sectionmissing","@case"],M=["@endforelse","@endif","@endforeach","@endfor","@endwhile","@break"],ne=["@button","@class","@include","@disabled","@checked","@json"],O=["@set","@json","@selected","@checked","@disabled","@php","@include","@includeif","@includewhen","@includeunless","@includefirst","@button","@class","@props","@aware"],ue=["@if","@while","@case","@isset","@empty","@elseif","@component","@hassection","@unless"],U=["@hassection"],V=["@charset","@color-profile","@counter-style","@font-face","@font-feature-values","@import","@keyframes","@media","@namespace","@page","@property","@supports"];function me(h,e){return z.default.filter(h.tokens,t=>{let n=e.substring(t.startIndex,t.endIndex).trim();return z.default.includes(P,n)||z.default.includes(E,n)}).length>=2}var y="\\(((?:[^)(]+|\\((?:[^)(]+|\\((?:[^)(]+|\\((?:[^)(]+|\\([^)(]*\\))*\\))*\\))*\\))*)\\)?";var _=h=>{let e={get(){return null}};return S.default.isUndefined(h)||S.default.isNull(h)?e:h};async function q(h){return new Promise((e,t)=>{ge.default.readFile(h,(n,r)=>n?t(n):e(r))})}function N(h){return h?h.split(/\r\n|\n|\r/):""}var F=1e3,ye={noPhpSyntaxCheck:!1,printWidth:F,trailingCommaPHP:!0,phpVersion:"8.1",singleQuote:!0};function L(h,e={}){let t={...ye,...e};try{return G.default.format(h.replace(/\n$/,""),{parser:"php",printWidth:1e3,singleQuote:t.singleQuote,phpVersion:t.phpVersion,trailingCommaPHP:t.trailingCommaPHP,plugins:[Q.default]})}catch(n){if(t.noPhpSyntaxCheck===!1)throw n;return h}}function C(h,e={}){let t={...ye,...e};try{return G.default.format(``,{parser:"php",printWidth:t.printWidth,singleQuote:t.singleQuote,phpVersion:t.phpVersion,trailingCommaPHP:t.trailingCommaPHP,plugins:[Q.default]}).replace(/<\?php echo (.*)?\?>/gs,(n,r)=>r.trim().replace(/;\s*$/,""))}catch(n){if(t.noPhpSyntaxCheck===!1)throw n;return h}}function _e(h){let e=``,{ast:t}=G.default.__debug.parse(e,{parser:"php",phpVersion:"8.0",plugins:[Q.default]});try{return t.children[0].expression.arguments.length||0}catch{return 0}}function we(h){return Promise.all(S.default.map(h,async e=>{process.stdout.write(`path: ${K.default.bold(e.path)}:${e.line}
`),process.stdout.write(K.default.red(`--${e.original}
`)),process.stdout.write(K.default.green(`++${e.formatted}
`))}))}function ve(h,e,t){let n=S.default.map(e,(r,s)=>S.default.isEmpty(r)||r===t[s]?null:{path:h,line:s+1,original:r,formatted:t[s]});return S.default.without(n,null)}async function ct(h){let e=S.default.without(P,"@switch","@forelse","@php").join("|"),t=new RegExp(`(?!\\/\\*.*?\\*\\/)(${e})(\\s*?)${y}`,"gmi");return new Promise(n=>n(h)).then(n=>S.default.replace(n,t,(r,s,a,l)=>L(``).replace(/<\?php\s(.*?)(\s*?)\((.*?)\);*\s\?>\n/gs,(o,c,d,p)=>`@${c.trim()}${d}(${p.trim()})`).replace(/([\n\s]*)->([\n\s]*)/gs,"->").replace(/,\)$/,")").replace(/(?:\n\s*)* as(?= (?:&{0,1}\$[\w]+|list|\[\$[\w]+))/g," as"))).then(n=>L(n))}async function be(h){return ct(h)}function Pe(h){let e=S.default.without(T,"@case"),t=S.default.without(M,"@break");return new Promise(n=>n(h)).then(n=>{let r=new RegExp(`(${e.join("|")})([\\s]*?)${y}`,"gis");return S.default.replace(n,r,(s,a,l,o)=>``)}).then(n=>{let r=new RegExp(`(?!end=".*)(${t.join("|")})(?!.*")`,"gi");return S.default.replace(n,r,(s,a)=>``)})}function $e(h){return new Promise(e=>e(h)).then(e=>S.default.replace(e,//gs,(t,n,r)=>`${n}(${S.default.unescape(r)})`)).then(e=>S.default.replace(e,/<\/beautifyTag.*?end="(.*?)"\s*>/gs,(t,n)=>`${n}`))}var ht=["/\\*\\* phptag_start \\*\\*/","/\\*\\* end_phptag \\*\\*/","/\\*escaped\\*/","__BLADE__;","/\\* blade_comment_start \\*/","/\\* blade_comment_end \\*/","/\\*\\*\\*script_placeholder\\*\\*\\*/","beautifyTag","@customdirective","@elsecustomdirective","@endcustomdirective"];function xe(h){if(new RegExp(ht.join("|")).test(h))throw new Error(["Can't format blade: something goes wrong.","Please check if template is too complicated or not. Or simplify template might solves issue."].join(`
`));return h}function re(h){return h.replace(/\$/g,"$$$$")}function Se(h){switch(h){case"LF":return`
`;case"CRLF":return`\r
`;default:return fe.default.EOL}}var Z=class{constructor(e,t){return(async()=>{var n;return this.vsctm=(n=e.default)!=null?n:e,this.oniguruma=t||ie.default||ie,await this.loadWasm(),this})()}async loadWasm(){var t;let e=await Be.promises.readFile(require.resolve("vscode-oniguruma/release/onig.wasm"));if(await((t=this.oniguruma)==null?void 0:t.loadWASM(e.buffer)),!this.initCalled){try{this.oniguruma.loadWASM(e.buffer)}catch{this.initCalled=!0}this.initCalled=!0}}createRegistry(){return this.registry=new this.vsctm.Registry({loadGrammar:e=>e==="text.html.php.blade"?q(Re.default.resolve(__dirname,"../syntaxes/blade.tmLanguage.json")).then(t=>this.vsctm.parseRawGrammar(t.toString(),"./blade.tmLanguage.json")):null,onigLib:Promise.resolve({createOnigScanner:e=>new this.oniguruma.OnigScanner(e),createOnigString:e=>new this.oniguruma.OnigString(e)})}),this.registry}tokenizeLines(e,t){return Ie.default.map(e,n=>{var r;return t.tokenizeLine(n,(r=this.vsctm)==null?void 0:r.INITIAL)})}};function dt(h){return h.split(`
`)}function ut(h){return h.trim().startsWith("*")}function mt(h){return h.length>1}function gt(h){return` ${h}`}function Ee(h){let e=dt(h);if(!mt(e))return h;let t=!1;return e.map((r,s)=>{if(s===0||t)return r;if(!ut(r))return t=!0,r;let a=r.trim();return gt(a)}).join(`
`)}var De=m(require("lodash"));function Le(h){let e=["@unless"];return De.default.replace(h,new RegExp(`(?`${n} (${r})`)}var j=class{constructor(e){this.options={noPhpSyntaxCheck:!1,...e},this.vsctm=_(this.options).vsctm||ft,this.oniguruma=_(this.options).oniguruma,this.indentCharacter=_(this.options).useTabs?" ":" ",this.indentSize=_(this.options).indentSize||4,this.wrapLineLength=_(this.options).wrapLineLength||120,this.wrapAttributes=_(this.options).wrapAttributes||"auto",this.currentIndentLevel=0,this.shouldBeIndent=!1,this.isInsideCommentBlock=!1,this.stack=[],this.ignoredLines=[],this.curlyBracesWithJSs=[],this.rawBlocks=[],this.rawPhpTags=[],this.inlineDirectives=[],this.conditions=[],this.inlinePhpDirectives=[],this.rawPropsBlocks=[],this.bladeDirectives=[],this.bladeDirectivesInStyle=[],this.bladeComments=[],this.phpComments=[],this.bladeBraces=[],this.rawBladeBraces=[],this.nonnativeScripts=[],this.scripts=[],this.htmlAttributes=[],this.xData=[],this.xInit=[],this.htmlTags=[],this.templatingStrings=[],this.stringLiteralInPhp=[],this.shorthandBindings=[],this.componentAttributes=[],this.customDirectives=[],this.directivesInScript=[],this.unbalancedDirectives=[],this.escapedBladeDirectives=[],this.result=[],this.diffs=[],this.defaultPhpFormatOption={noPhpSyntaxCheck:this.options.noPhpSyntaxCheck,printWidth:this.wrapLineLength},this.endOfLine=Se(_(this.options).endOfLine)}formatContent(e){return new Promise(t=>t(e)).then(t=>this.preserveIgnoredLines(t)).then(t=>this.preserveNonnativeScripts(t)).then(t=>this.preserveCurlyBraceForJS(t)).then(t=>this.preserveRawPhpTags(t)).then(t=>this.preserveEscapedBladeDirective(t)).then(t=>be(t)).then(t=>this.preserveBladeComment(t)).then(t=>this.preserveBladeBrace(t)).then(t=>this.preserveRawBladeBrace(t)).then(t=>this.preserveConditions(t)).then(t=>this.preserveInlineDirective(t)).then(t=>this.preserveInlinePhpDirective(t)).then(t=>this.preserveBladeDirectivesInScripts(t)).then(t=>this.preserveBladeDirectivesInStyles(t)).then(t=>this.preserveCustomDirective(t)).then(t=>this.preserveUnbalancedDirective(t)).then(t=>this.breakLineBeforeAndAfterDirective(t)).then(async t=>(this.bladeDirectives=await this.formatPreservedBladeDirectives(this.bladeDirectives),t)).then(t=>this.preserveScripts(t)).then(t=>this.sortTailwindcssClasses(t)).then(t=>this.formatXInit(t)).then(t=>this.formatXData(t)).then(t=>this.preserveComponentAttribute(t)).then(t=>this.preserveShorthandBinding(t)).then(t=>this.sortHtmlAttributes(t)).then(t=>this.preservePhpBlock(t)).then(t=>this.preserveHtmlAttributes(t)).then(t=>this.preserveHtmlTags(t)).then(t=>this.formatAsHtml(t)).then(t=>this.formatAsBlade(t)).then(t=>this.restoreHtmlTags(t)).then(t=>this.restoreHtmlAttributes(t)).then(t=>this.restorePhpBlock(t)).then(t=>this.restoreShorthandBinding(t)).then(t=>this.restoreComponentAttribute(t)).then(t=>this.restoreXData(t)).then(t=>this.restoreXInit(t)).then(t=>this.restoreScripts(t)).then(t=>this.restoreUnbalancedDirective(t)).then(t=>this.restoreCustomDirective(t)).then(t=>this.restoreBladeDirectivesInStyles(t)).then(t=>this.restoreBladeDirectivesInScripts(t)).then(t=>this.restoreInlinePhpDirective(t)).then(t=>this.restoreInlineDirective(t)).then(t=>this.restoreConditions(t)).then(t=>this.restoreRawBladeBrace(t)).then(t=>this.restoreBladeBrace(t)).then(t=>this.restoreBladeComment(t)).then(t=>this.restoreEscapedBladeDirective(t)).then(t=>this.restoreRawPhpTags(t)).then(t=>this.restoreCurlyBraceForJS(t)).then(t=>this.restoreNonnativeScripts(t)).then(t=>this.restoreIgnoredLines(t)).then(t=>Le(t)).then(t=>xe(t))}formatAsHtml(e){let t={indent_size:_(this.options).indentSize||4,wrap_line_length:_(this.options).wrapLineLength||120,wrap_attributes:_(this.options).wrapAttributes||"auto",end_with_newline:_(this.options).endWithNewline||!0,max_preserve_newlines:_(this.options).noMultipleEmptyLines?1:void 0,css:{end_with_newline:!1},eol:this.endOfLine},n=new Promise(r=>r(e)).then(r=>Pe(r)).then(r=>R.default.html_beautify(r,t)).then(r=>$e(r));return Promise.resolve(n)}async sortTailwindcssClasses(e){return this.options.sortTailwindcssClasses?i.default.replace(e,/(?<=\s+(?!:)class\s*=\s*([\"\']))(.*?)(?=\1)/gis,(t,n,r)=>{if(i.default.isEmpty(r))return r;if(this.options.tailwindcssConfigPath){let s={tailwindConfigPath:this.options.tailwindcssConfigPath};return(0,Y.sortClasses)(r,s)}if(this.options.tailwindcssConfig){let s={tailwindConfig:this.options.tailwindcssConfig};return(0,Y.sortClasses)(r,s)}return(0,Y.sortClasses)(r)}):e}async preserveIgnoredLines(e){return i.default.chain(e).replace(/(^(?this.storeIgnoredLines(`${n}${r.replace(/^\n/,"")}`)).replace(/(?:({{--\s*?blade-formatter-disable\s*?--}}||{{--\s*?prettier-ignore-start\s*?--}})).*?(?:({{--\s*?blade-formatter-enable\s*?--}}||{{--\s*?prettier-ignore-end\s*?--}}))/gis,t=>this.storeIgnoredLines(t)).replace(/(?:{{--\s*?blade-formatter-disable-next-line\s*?--}}|{{--\s*?prettier-ignore\s*?--}}|)[\r\n]+[^\r\n]+/gis,t=>this.storeIgnoredLines(t)).value()}async preserveCurlyBraceForJS(e){return i.default.replace(e,/@{{(.*?)}}/gs,(t,n)=>this.storeCurlyBraceForJS(n))}async preservePhpBlock(e){return this.preserveRawPhpBlock(e)}async preservePropsBlock(e){return i.default.replace(e,/@props\(((?:[^\\(\\)]|\([^\\(\\)]*\))*)\)/gs,(t,n)=>this.storeRawPropsBlock(n))}async preserveRawPhpBlock(e){return i.default.replace(e,/(?this.storeRawBlock(n))}async preserveHtmlTags(e){let t=["textarea","pre"];return i.default.replace(e,new RegExp(`<(${t.join("|")})\\s{0,1}.*?>.*?<\\/(${t.join("|")})>`,"gis"),n=>this.storeHtmlTag(n))}preserveCustomDirective(e){let t=[...i.default.without(P,"@unless"),...E,...D,"@unless\\(.*?\\)"].join("|"),n=i.default.chain([...i.default.without(P,"@unless","@for"),...E,...D,...O,...i.default.without(T,"@for"),"@unless[a-z]*\\(.*?\\)","@for\\(.*?\\)",...U,...V]).uniq().join("|").value(),r=new RegExp(`(?!(${n}))(@([a-zA-Z1-9_\\-]+))(?!.*?@end\\3)${y}.*?(?this.storeInlineCustomDirective(l)),a=i.default.replace(a,s,(l,o,c,d,p,u,g,x)=>{if(P.includes(c))return l;let b=l;return b=i.default.replace(b,new RegExp(`${c}(${y})*`,"gim"),I=>this.storeBeginCustomDirective(I)),b=i.default.replace(b,x,this.storeEndCustomDirective(x)),b=i.default.replace(b,new RegExp(`@else${p}(${y})*`,"gim"),I=>this.storeElseCustomDirective(I)),b}),s.test(a)&&(a=this.preserveCustomDirective(a)),a}preserveInlineDirective(e){let t=new RegExp(`(<[\\w\\-\\_]+?[^>]*?)${A}(${he.join("|")})(\\s*?)?(\\([^)]*?\\))?((?:(?!@end\\2).)+)(@end\\2|@endif)(.*?/*>)`,"gims"),n=i.default.replace(e,t,(r,s,a,l,o,c,d,p)=>l===void 0&&o===void 0?`${s}${this.storeInlineDirective(`${A}${a.trim()}${c.trim()} ${d.trim()}`)}${p}`:l===void 0?`${s}${this.storeInlineDirective(`${A}${a.trim()}${o.trim()}${c}${d.trim()}`)}${p}`:o===void 0?`${s}${this.storeInlineDirective(`${A}${a.trim()}${l}${c.trim()} ${d.trim()}`)}${p}`:`${s}${this.storeInlineDirective(`${A}${a.trim()}${l}${o.trim()} ${c.trim()} ${d.trim()}`)}${p}`);return t.test(n)?this.preserveInlineDirective(n):n}async preserveInlinePhpDirective(e){return i.default.replace(e,new RegExp(`(?!\\/\\*.*?\\*\\/)(${O.join("|")})(\\s*?)${y}`,"gmsi"),t=>this.storeInlinePhpDirective(t))}preserveBladeDirectivesInScripts(e){return i.default.replace(e,/(?<=