"use strict";var Ue=Object.create;var J=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var Ke=Object.getOwnPropertyNames;var Qe=Object.getPrototypeOf,Ge=Object.prototype.hasOwnProperty;var Ze=(h,e)=>{for(var t in e)J(h,t,{get:e[t],enumerable:!0})},ce=(h,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Ke(e))!Ge.call(h,i)&&i!==t&&J(h,i,{get:()=>e[i],enumerable:!(n=Ve(e,i))||n.enumerable});return h};var g=(h,e,t)=>(t=h!=null?Ue(Qe(h)):{},ce(e||!h||!h.__esModule?J(t,"default",{value:h,enumerable:!0}):t,h)),qe=h=>ce(J({},"__esModule",{value:!0}),h);var ht={};Ze(ht,{BladeFormatter:()=>le,Formatter:()=>F});module.exports=qe(ht);var Xe=g(require("ignore"),1),S=g(require("chalk"),1),ae=g(require("find-config"),1),W=g(require("fs"),1),Je=g(require("glob"),1),P=g(require("lodash"),1),R=g(require("path"),1),f=g(require("process"),1),oe=g(require("util"),1);var H=class extends Error{};var Y=require("@shufo/tailwindcss-class-sorter"),ke=g(require("aigle"),1),v=g(require("detect-indent"),1),se=require("html-attribute-sorter"),E=g(require("js-beautify"),1),r=g(require("lodash"),1),lt=g(require("vscode-textmate"),1),Fe=g(require("xregexp"),1),x=g(require("string-replace-async"),1);function Ye(h){return h.split(`
`)}function et(h){return h.trim().startsWith("*")}function tt(h){return h.length>1}function nt(h){return` ${h}`}function he(h){let e=Ye(h);if(!tt(e))return h;let t=!1;return e.map((i,s)=>{if(s===0||t)return i;if(!et(i))return t=!0,i;let a=i.trim();return nt(a)}).join(`
`)}var it={defaultPrintWidth:120},ee=it;var z=g(require("lodash"),1),T="@",b=["@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"],pe=z.default.map(b,h=>h.substring(1)),D=["@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"],L=["@elseenv","@elseif","@elsecanany","@elsecannot","@elsecan","@else","@elsecustomdirective"],te={"@section":2,"@push":2,"@prepend":2,"@slot":2},de=["@forelse","@if"],ne=["@empty"],ue=["@default"],j=["@forelse","@if","@for","@foreach","@while","@sectionmissing","@case"],M=["@endforelse","@endif","@endforeach","@endfor","@endwhile","@break"],ie=["@button","@class","@include","@disabled","@checked","@json"],O=["@set","@json","@selected","@checked","@disabled","@php","@include","@includeif","@includewhen","@includeunless","@includefirst","@button","@class","@props","@aware"],me=["@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 ge(h,e){return z.default.filter(h.tokens,t=>{let n=e.substring(t.startIndex,t.endIndex).trim();return z.default.includes(b,n)||z.default.includes(D,n)}).length>=2}var _="\\(((?:[^)(]+|\\((?:[^)(]+|\\((?:[^)(]+|\\((?:[^)(]+|\\([^)(]*\\))*\\))*\\))*\\))*)\\)?";var fe=g(require("lodash"),1);function ye(h){let e=["@unless"];return fe.default.replace(h,new RegExp(`(?`${n} (${i})`)}var C=g(require("lodash"),1),_e=g(require("fs"),1),we=g(require("os"),1),K=g(require("chalk"),1),N=g(require("prettier/standalone"),1),Q=g(require("@prettier/plugin-php/standalone"),1),rt=g(require("detect-indent"),1),ve=g(require("string-replace-async"),1);var y=h=>{let e={get(){return null}};return C.default.isUndefined(h)||C.default.isNull(h)?e:h};async function G(h){return new Promise((e,t)=>{_e.default.readFile(h,(n,i)=>n?t(n):e(i))})}function X(h){return h?h.split(/\r\n|\n|\r/):""}var k=1e3,Pe={noPhpSyntaxCheck:!1,printWidth:k,trailingCommaPHP:!0,phpVersion:"8.1",noSingleQuote:!1};async function A(h,e={}){var s;let t={...Pe,...e},n=(s=e.adjustPrintWidthBy)!=null?s:0,i=e.useProjectPrintWidth?t.printWidth-n:k;try{return await N.format(h.replace(/\n$/,""),{parser:"php",printWidth:i,singleQuote:!t.noSingleQuote,phpVersion:t.phpVersion,trailingCommaPHP:t.trailingCommaPHP,plugins:[Q.default]})}catch(a){if(t.noPhpSyntaxCheck===!1)throw a;return h}}async function B(h,e={}){let t={...Pe,...e};try{return(await N.format(``,{parser:"php",printWidth:t.printWidth,singleQuote:!t.noSingleQuote,phpVersion:t.phpVersion,trailingCommaPHP:t.trailingCommaPHP,plugins:[Q.default]})).replace(/<\?php echo (.*)?\?>/gs,(n,i)=>i.trim().replace(/;\s*$/,""))}catch(n){if(t.noPhpSyntaxCheck===!1)throw n;return h}}async function $e(h){let e=``;try{let{ast:t}=await N.__debug.parse(e,{parser:"php",phpVersion:"8.1",plugins:[Q.default]});return t.children[0].expression.arguments.length||0}catch{return 0}}function be(h){return Promise.all(C.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 Se(h,e,t){let n=C.default.map(e,(i,s)=>C.default.isEmpty(i)||i===t[s]?null:{path:h,line:s+1,original:i,formatted:t[s]});return C.default.without(n,null)}async function st(h,e){let t=C.default.without(b,"@switch","@forelse","@php").join("|"),n=new RegExp(`(?!\\/\\*.*?\\*\\/)(${t})(\\s*?)${_}`,"gmi");return new Promise(i=>i(h)).then(i=>(0,ve.default)(i,n,async(s,a,l,o)=>(await A(``,e)).replace(/<\?php\s(.*?)(\s*?)\((.*?)\);*\s\?>\n/gs,(c,d,p,u)=>`@${d.trim()}${p}(${u.trim()})`).replace(/([\n\s]*)->([\n\s]*)/gs,"->").replace(/,\)$/,")").replace(/(?:\n\s*)* as(?= (?:&{0,1}\$[\w]+|list|\[\$[\w]+))/g," as"))).then(i=>A(i,e))}async function xe(h,e){return st(h,e)}function Ce(h){let e=C.default.without(j,"@case"),t=C.default.without(M,"@break");return new Promise(n=>n(h)).then(n=>{let i=new RegExp(`(${e.join("|")})([\\s]*?)${_}`,"gis");return C.default.replace(n,i,(s,a,l,o)=>``)}).then(n=>{let i=new RegExp(`(?!end=".*)(${t.join("|")})(?!.*")`,"gi");return C.default.replace(n,i,(s,a)=>``)})}function Be(h){return new Promise(e=>e(h)).then(e=>C.default.replace(e,//gs,(t,n,i)=>`${n}(${C.default.unescape(i)})`)).then(e=>C.default.replace(e,/<\/beautifyTag.*?end="(.*?)"\s*>/gs,(t,n)=>`${n}`))}var at=["/\\*\\* phptag_start \\*\\*/","/\\*\\* end_phptag \\*\\*/","/\\*escaped\\*/","__BLADE__;","/\\* blade_comment_start \\*/","/\\* blade_comment_end \\*/","/\\*\\*\\*script_placeholder\\*\\*\\*/","blade___non_native_scripts_","blade___scripts_","blade___html_tags_","beautifyTag","@customdirective","@elsecustomdirective","@endcustomdirective","x-slot --___\\d+___--","___attrs_+\\d+___"];function Ie(h){if(new RegExp(at.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 Re(h){switch(h){case"LF":return`
`;case"CRLF":return`\r
`;default:return we.default.EOL}}var De=require("fs"),Le=g(require("lodash"),1),Z=g(require("vscode-oniguruma"),1),Ae=g(require("path"),1);var q=class{constructor(e,t){return(async()=>{var n;return this.vsctm=(n=e.default)!=null?n:e,this.oniguruma=t||(Z==null?void 0:Z.default)||Z,await this.loadWasm(),this})()}async loadWasm(){var t;let e=await De.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"?G(Ae.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 Le.default.map(e,n=>{var i;return t.tokenizeLine(n,(i=this.vsctm)==null?void 0:i.INITIAL)})}};var F=class{constructor(e){this.options={noPhpSyntaxCheck:!1,trailingCommaPHP:!e.noTrailingCommaPhp,printWidth:e.wrapLineLength||ee.defaultPrintWidth,...e},this.vsctm=y(this.options).vsctm||lt,this.oniguruma=y(this.options).oniguruma,this.indentCharacter=y(this.options).useTabs?" ":" ",this.indentSize=y(this.options).indentSize||4,this.wrapLineLength=y(this.options).wrapLineLength||ee.defaultPrintWidth,this.wrapAttributes=y(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.xSlot=[],this.result=[],this.diffs=[],this.defaultPhpFormatOption={noPhpSyntaxCheck:this.options.noPhpSyntaxCheck,printWidth:this.wrapLineLength},this.endOfLine=Re(y(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=>xe(t,this.options)).then(t=>this.preserveBladeComment(t)).then(t=>this.preserveBladeBrace(t)).then(t=>this.preserveRawBladeBrace(t)).then(t=>this.preserveConditions(t)).then(t=>this.preservePropsBlock(t)).then(t=>this.preserveInlinePhpDirective(t)).then(t=>this.preserveInlineDirective(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.preservePhpBlock(t)).then(t=>this.sortHtmlAttributes(t)).then(t=>this.preserveHtmlAttributes(t)).then(t=>this.preserveComponentAttribute(t)).then(t=>this.preserveShorthandBinding(t)).then(t=>this.preserveXslot(t)).then(t=>this.preserveHtmlTags(t)).then(t=>this.formatAsHtml(t)).then(t=>this.formatAsBlade(t)).then(t=>this.restoreHtmlTags(t)).then(t=>this.restoreXslot(t)).then(t=>this.restoreShorthandBinding(t)).then(t=>this.restoreComponentAttribute(t)).then(t=>this.restoreHtmlAttributes(t)).then(t=>this.restorePhpBlock(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.restoreInlineDirective(t)).then(t=>this.restoreInlinePhpDirective(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=>ye(t)).then(t=>Ie(t))}formatAsHtml(e){let t={indent_size:y(this.options).indentSize||4,wrap_line_length:y(this.options).wrapLineLength||120,wrap_attributes:y(this.options).wrapAttributes||"auto",wrap_attributes_min_attrs:y(this.options).wrapAttributesMinAttrs,indent_inner_html:y(this.options).indentInnerHtml||!1,end_with_newline:y(this.options).endWithNewline||!0,max_preserve_newlines:y(this.options).noMultipleEmptyLines?1:void 0,extra_liners:y(this.options).extraLiners,css:{end_with_newline:!1},eol:this.endOfLine},n=new Promise(i=>i(e)).then(i=>Ce(i)).then(i=>E.default.html_beautify(i,t)).then(i=>Be(i));return Promise.resolve(n)}async sortTailwindcssClasses(e){return this.options.sortTailwindcssClasses?r.default.replace(e,/(?<=\s+(?!:)class\s*=\s*([\"\']))(.*?)(?=\1)/gis,(t,n,i)=>{if(r.default.isEmpty(i))return i;if(this.options.tailwindcssConfigPath){let s={tailwindConfigPath:this.options.tailwindcssConfigPath};return(0,Y.sortClasses)(i,s)}if(this.options.tailwindcssConfig){let s={tailwindConfig:this.options.tailwindcssConfig};return(0,Y.sortClasses)(i,s)}return(0,Y.sortClasses)(i)}):e}async preserveIgnoredLines(e){return r.default.chain(e).replace(/(^(?this.storeIgnoredLines(`${n}${i.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 r.default.replace(e,/@{{(.*?)}}/gs,(t,n)=>this.storeCurlyBraceForJS(n))}async preservePhpBlock(e){return this.preserveRawPhpBlock(e)}async preservePropsBlock(e){return r.default.replace(e,/@props\(((?:[^\\(\\)]|\([^\\(\\)]*\))*)\)/gs,(t,n)=>this.storeRawPropsBlock(n))}async preserveRawPhpBlock(e){return r.default.replace(e,/(?this.storeRawBlock(n))}async preserveHtmlTags(e){let t=["textarea","pre"];return r.default.replace(e,new RegExp(`<(${t.join("|")})\\s{0,1}.*?>.*?<\\/(${t.join("|")})>`,"gis"),n=>this.storeHtmlTag(n))}preserveCustomDirective(e){let t=[...r.default.without(b,"@unless"),...D,...L,"@unless\\(.*?\\)"].join("|"),n=r.default.chain([...r.default.without(b,"@unless","@for"),...D,...L,...O,...r.default.without(j,"@for"),"@unless[a-z]*\\(.*?\\)","@for\\(.*?\\)",...U,...V]).uniq().join("|").value(),i=new RegExp(`(?!(${n}))(@([a-zA-Z1-9_\\-]+))(?!.*?@end\\3)${_}.*?(?this.storeInlineCustomDirective(l)),a=r.default.replace(a,s,(l,o,c,d,p,u,m,$)=>{if(b.includes(c))return l;let w=l;return w=r.default.replace(w,new RegExp(`${c}(${_})*`,"gim"),I=>this.storeBeginCustomDirective(I)),w=r.default.replace(w,$,this.storeEndCustomDirective($)),w=r.default.replace(w,new RegExp(`@else${p}(${_})*`,"gim"),I=>this.storeElseCustomDirective(I)),w}),s.test(a)&&(a=this.preserveCustomDirective(a)),a}preserveInlineDirective(e){let t=new RegExp(`(<[\\w\\-\\_]+?[^>]*?)${T}(${pe.join("|")})(\\s*?)?(\\([^)]*?\\))?((?:(?!@end\\2).)+)(@end\\2|@endif)(.*?/*>)`,"gims"),n=r.default.replace(e,t,(i,s,a,l,o,c,d,p)=>l===void 0&&o===void 0?`${s}${this.storeInlineDirective(`${T}${a.trim()}${c.trim()} ${d.trim()}`)}${p}`:l===void 0?`${s}${this.storeInlineDirective(`${T}${a.trim()}${o.trim()}${c}${d.trim()}`)}${p}`:o===void 0?`${s}${this.storeInlineDirective(`${T}${a.trim()}${l}${c.trim()} ${d.trim()}`)}${p}`:`${s}${this.storeInlineDirective(`${T}${a.trim()}${l}${o.trim()} ${c.trim()} ${d.trim()}`)}${p}`);return t.test(n)?this.preserveInlineDirective(n):n}async preserveInlinePhpDirective(e){return r.default.replace(e,new RegExp(`(?!\\/\\*.*?\\*\\/)(${O.join("|")})(\\s*?)${_}`,"gmsi"),t=>this.storeInlinePhpDirective(t))}preserveBladeDirectivesInScripts(e){return r.default.replace(e,/(?<=