"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,/(?<=]*?(?)(.*?)(?=<\/script>)/gis,t=>{let n=[...b,...O];if(new RegExp(n.join("|"),"gmi").test(t)===!1)return/^[\s\n]+$/.test(t)?t.trim():t;let i=O.join("|"),s=new RegExp(`(?!\\/\\*.*?\\*\\/)(${i})(\\s*?)${_}`,"gmi"),a=r.default.chain(D).without("@endphp"),l=t;return l=r.default.replace(l,s,o=>this.storeBladeDirective(B(o,{...this.options,printWidth:k}))),l=r.default.replace(l,new RegExp(`(${b.join("|")})\\s*?${_}`,"gis"),o=>`if ( /*${this.storeBladeDirectiveInScript(o)}*/ ) {`),l=r.default.replace(l,new RegExp(`(${[...L,...ne].join("|")})(?!\\w+?\\s*?\\(.*?\\))`,"gis"),o=>`/***script_placeholder***/} /* ${this.storeBladeDirectiveInScript(o)} */ {`),l=r.default.replace(l,new RegExp(`(${a.join("|")})`,"gis"),o=>`/***script_placeholder***/} /*${this.storeBladeDirectiveInScript(o)}*/`),l=r.default.replace(l,/(?this.storeRawBlock(c)),l=this.preserveCustomDirectiveInScript(l),l})}preserveBladeDirectivesInStyles(e){return r.default.replace(e,/(?<=]*?(?)(.*?)(?=<\/style>)/gis,t=>{let n=t,i=new RegExp(`(?!${["@end","@else",...V].join("|")})@(\\w+)\\s*?(?![^\\1]*@end\\1)${_}`,"gmi");n=r.default.replace(n,i,c=>`${this.storeBladeDirectiveInStyle(c)} {/* inline_directive */}`);let s=new RegExp(`(?!${["@end","@else",...V].join("|")})@(\\w+)\\s*?(${_})`,"gmi");n=r.default.replace(n,s,c=>`${this.storeBladeDirectiveInStyle(c)} { /*start*/`);let a=new RegExp(`(${b.join("|")})\\s*?(${_})`,"gmi");n=r.default.replace(n,a,c=>`${this.storeBladeDirectiveInStyle(c)} { /*start*/`);let l=new RegExp(`(${["@else\\w+",...L].join("|")})\\s*?(${_})?`,"gmi");n=r.default.replace(n,l,c=>`} ${this.storeBladeDirectiveInStyle(c)} { /*else*/`);let o=new RegExp(`${["@end\\w+",...D].join("|")}`,"gmi");return n=r.default.replace(n,o,c=>`} /* ${this.storeBladeDirectiveInStyle(c)} */`),n})}preserveCustomDirectiveInScript(e){let t=[...r.default.without(b,"@unless"),...D,...L,"@unless\\(.*?\\)"].join("|"),n=[...r.default.without(b,"@unless"),...D,...L,...O,...j,"@unless[a-z]*\\(.*?\\)",...U].join("|"),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=>`if ( /*${this.storeBladeDirectiveInScript(I)}*/ ) {`),w=r.default.replace(w,new RegExp(`@else${p}(${_})*`,"gim"),I=>`/***script_placeholder***/} /* ${this.storeBladeDirectiveInScript(I)} */ {`),w=r.default.replace(w,$,I=>`/***script_placeholder***/} /*${this.storeBladeDirectiveInScript(I)}*/`),w}),s.test(a)&&(a=this.preserveCustomDirectiveInScript(a)),a}breakLineBeforeAndAfterDirective(e){e=r.default.replace(e,new RegExp(`(?<=<.*?(?)(${r.default.without(b,"@php").join("|")})(\\s*)${_}.*?(?=<.*?>)`,"gmis"),s=>` ${s.trim()} `),e=r.default.replace(e,new RegExp(`(?<=<.*?(?).*?(${r.default.without(D,"@endphp").join("|")})(?=<.*?>)`,"gmis"),s=>` ${s.trim()} `);let t=["@case",...L];e=r.default.replace(e,new RegExp(`(\\s*?)(${t.join("|")})(\\s*?)${_}(\\s*)`,"gmi"),s=>` ${s.trim()} `),e=r.default.replace(e,new RegExp(`\\s*?(?!(${r.default.without(L,"@else").join("|")}))@else\\s+`,"gim"),s=>` ${s.trim()} `),e=r.default.replace(e,/@case\S*?\s*?@case/gim,s=>`${s.replace(` `,"")}`);let n=["@break"];r.default.forEach(n,s=>{e=r.default.replace(e,new RegExp(`(\\s*?)${s}\\s+`,"gmi"),a=>` ${a.trim()} `)}),r.default.forEach(["@default"],s=>{e=r.default.replace(e,new RegExp(`(\\s*?)${s}\\s*`,"gmi"),a=>` ${a.trim()} `)});let i=r.default.chain(b).map(s=>r.default.replace(s,/@/,"")).value();return r.default.forEach(i,s=>{try{let a=Fe.default.matchRecursive(e,`\\@${s}`,`\\@end${s}`,"gmi",{valueNames:[null,"left","match","right"]});if(r.default.isEmpty(a))return;for(let l of a)if(l.name==="match"){new RegExp(b.join("|")).test(l.value)&&(e=r.default.replace(e,l.value,this.breakLineBeforeAndAfterDirective(re(l.value))));let o=new RegExp(`^(\\s*?)${_}(.*)`,"gmis"),c=r.default.replace(`${l.value}`,o,(d,p,u,m)=>m.trim()===""?`${p}(${u.trim()}) ${m.trim()}`:`${p}(${u.trim()}) ${m.trim()} `);e=r.default.replace(e,l.value,re(c))}}catch{}}),e}async preserveEscapedBladeDirective(e){return r.default.replace(e,/@@\w*/gim,t=>this.storeEscapedBladeDirective(t))}async preserveXslot(e){return r.default.replace(e,/(?<=<\/?)(x-slot:[\w_\\-]+)(?=(?:[^>]*?[^?])?>)/gm,t=>this.storeXslot(t))}async preserveBladeComment(e){return r.default.replace(e,/\{\{--(.*?)--\}\}/gs,t=>this.storeBladeComment(t))}preservePhpComment(e){return r.default.replace(e,/\/\*(?:[^*]|[\r\n]|(?:\*+(?:[^*\/]|[\r\n])))*\*+\//gi,t=>this.storePhpComment(t))}async preserveBladeBrace(e){return r.default.replace(e,/\{\{(.*?)\}\}/gs,(t,n)=>n===""?this.storeBladeBrace(n,n.length):/\S/.test(n)?this.storeBladeBrace(n.trim(),n.trim().length):this.storeBladeBrace(" ",1))}async preserveRawBladeBrace(e){return r.default.replace(e,/\{!!(.*?)!!\}/gs,(t,n)=>n===""?this.storeRawBladeBrace(n):/\S/.test(n)?this.storeRawBladeBrace(n.trim()):this.storeRawBladeBrace(" "))}async preserveConditions(e){let t=new RegExp(`(${me.join("|")})(\\s*?)${_}`,"gi");return r.default.replace(e,t,(n,i,s,a)=>`${i}${s}(${this.storeConditions(a)})`)}preserveUnbalancedDirective(e){let t=new RegExp(`((${U.join("|")})(?!.*?\\2)(?:\\s|\\(.*?\\)))+(?=.*?@endif)`,"gis"),n=r.default.replace(e,t,(i,s)=>`${this.storeUnbalancedDirective(s)}`);return t.test(n)&&(n=this.preserveUnbalancedDirective(n)),n}async preserveRawPhpTags(e){return r.default.replace(e,/<\?php(.*?)\?>/gms,t=>this.storeRawPhpTags(t))}async preserveNonnativeScripts(e){return r.default.replace(e,/]*?type=(["'])(?!(text\/javascript|module))[^\1]*?\1[^>]*?>.*?<\/script>/gis,t=>this.storeNonnativeScripts(t))}async preserveScripts(e){return r.default.replace(e,/.*?<\/script>/gis,t=>this.storeScripts(t))}async preserveHtmlAttributes(e){return r.default.replace(e,/(?<=<[\w\-\.\:\_]+[^]*\s)(?!x-bind)([^\s\:][^\s\'\"]+\s*=\s*(["'])(?)/gms,t=>`${this.storeHtmlAttribute(t)}`)}async sortHtmlAttributes(e){var n;let t=(n=this.options.sortHtmlAttributes)!=null?n:"none";if(!r.default.isEmpty(t)&&t!=="none"){let i=this.options.customHtmlAttributesOrder;if(r.default.isArray(i))return(0,se.sortAttributes)(e,{order:t,customRegexes:i});let s=r.default.chain(i).split(",").map(r.default.trim).value();return(0,se.sortAttributes)(e,{order:t,customRegexes:s})}return e}async preserveShorthandBinding(e){return r.default.replace(e,/(?<=<(?!livewire:)[^<]*?(\s|x-bind)):{1}(?)[\w\-_.]*?=(["'])(?!=>)[^\2]*?\2(?=[^>]*?\/*?>)/gim,t=>`${this.storeShorthandBinding(t)}`)}async preserveComponentAttribute(e){return r.default.replace(e,/(?<=<(x-|livewire:)[^<]*?\s):{1,2}(?)[\w\-_.]*?=(["'])(?!=>)[^\2]*?\2(?=[^>]*?\/*?>)/gim,t=>`${this.storeComponentAttribute(t)}`)}async formatXData(e){return r.default.replace(e,/(\s*)x-data="(.*?)"(\s*)/gs,(t,n,i,s)=>`${n}x-data="${this.storeXData(i)}"${s}`)}async formatXInit(e){return r.default.replace(e,/(\s*)x-init="(.*?)"(\s*)/gs,(t,n,i,s)=>`${n}x-init="${this.storeXInit(i)}"${s}`)}preserveStringLiteralInPhp(e){return r.default.replace(e,/(\"([^\\]|\\.)*?\"|\'([^\\]|\\.)*?\')/gm,t=>`${this.storeStringLiteralInPhp(t)}`)}storeIgnoredLines(e){return this.getIgnoredLinePlaceholder(this.ignoredLines.push(e)-1)}storeCurlyBraceForJS(e){return this.getCurlyBraceForJSPlaceholder(this.curlyBracesWithJSs.push(e)-1)}storeRawBlock(e){return this.getRawPlaceholder(this.rawBlocks.push(e)-1)}storeInlineDirective(e){return this.getInlinePlaceholder(this.inlineDirectives.push(e)-1,e.length)}storeConditions(e){return this.getConditionPlaceholder(this.conditions.push(e)-1)}storeInlinePhpDirective(e){return this.getInlinePhpPlaceholder(this.inlinePhpDirectives.push(e)-1)}storeRawPropsBlock(e){return this.getRawPropsPlaceholder(this.rawPropsBlocks.push(e)-1)}storeBladeDirective(e){return this.getBladeDirectivePlaceholder(this.bladeDirectives.push(e)-1)}storeBladeDirectiveInStyle(e){return this.getBladeDirectiveInStylePlaceholder((this.bladeDirectivesInStyle.push(e)-1).toString())}storeEscapedBladeDirective(e){return this.getEscapedBladeDirectivePlaceholder((this.escapedBladeDirectives.push(e)-1).toString())}storeXslot(e){return this.getXslotPlaceholder((this.xSlot.push(e)-1).toString())}storeBladeComment(e){return this.getBladeCommentPlaceholder(this.bladeComments.push(e)-1)}storePhpComment(e){return this.getPhpCommentPlaceholder((this.phpComments.push(e)-1).toString())}storeHtmlTag(e){return this.getHtmlTagPlaceholder((this.htmlTags.push(e)-1).toString())}storeInlineCustomDirective(e){return this.getInlineCustomDirectivePlaceholder((this.customDirectives.push(e)-1).toString())}storeBeginCustomDirective(e){return this.getBeginCustomDirectivePlaceholder((this.customDirectives.push(e)-1).toString())}storeElseCustomDirective(e){return this.getElseCustomDirectivePlaceholder((this.customDirectives.push(e)-1).toString())}storeEndCustomDirective(e){return this.getEndCustomDirectivePlaceholder((this.customDirectives.push(e)-1).toString())}storeUnbalancedDirective(e){return this.getUnbalancedDirectivePlaceholder((this.unbalancedDirectives.push(e)-1).toString())}storeBladeBrace(e,t){let n=this.bladeBraces.push(e)-1,i="{{ }}";return this.getBladeBracePlaceholder(n,t+i.length)}storeRawBladeBrace(e){let t=this.rawBladeBraces.push(e)-1;return this.getRawBladeBracePlaceholder(t)}storeRawPhpTags(e){let t=this.rawPhpTags.push(e)-1;return this.getRawPhpTagPlaceholder(t)}storeNonnativeScripts(e){let t=this.nonnativeScripts.push(e)-1;return this.getNonnativeScriptPlaceholder(t.toString())}storeScripts(e){let t=this.scripts.push(e)-1;return this.getScriptPlaceholder(t)}storeHtmlAttribute(e){let t=this.htmlAttributes.push(e)-1;return e.length>0?this.getHtmlAttributePlaceholder(t.toString(),e.length):this.getHtmlAttributePlaceholder(t.toString(),0)}storeShorthandBinding(e){let t=this.shorthandBindings.push(e)-1;return this.getShorthandBindingPlaceholder(t.toString(),e.length)}storeComponentAttribute(e){let t=this.componentAttributes.push(e)-1;return this.getComponentAttributePlaceholder(t.toString())}storeXData(e){let t=this.xData.push(e)-1;return this.getXDataPlaceholder(t)}storeXInit(e){let t=this.xInit.push(e)-1;return this.getXInitPlaceholder(t)}storeTemplatingString(e){let t=this.templatingStrings.push(e)-1;return this.getTemplatingStringPlaceholder(t)}storeStringLiteralInPhp(e){let t=this.stringLiteralInPhp.push(e)-1;return this.getStringLiteralInPhpPlaceholder(t)}storeBladeDirectiveInScript(e){return this.getBladeDirectiveInScriptPlaceholder((this.directivesInScript.push(e)-1).toString())}getIgnoredLinePlaceholder(e){return r.default.replace("___ignored_line_#___","#",e)}getCurlyBraceForJSPlaceholder(e){return r.default.replace("___js_curly_brace_#___","#",e)}getRawPlaceholder(e){return r.default.replace("___raw_block_#___","#",e)}getInlinePlaceholder(e,t=0){if(t>0){let i=t-"___inline_directive_#___".length;return r.default.replace(`___inline_directive_${r.default.repeat("_",i>0?i:0)}#___`,"#",e)}return r.default.replace("___inline_directive_+?#___","#",e)}getConditionPlaceholder(e){return r.default.replace("___directive_condition_#___","#",e)}getInlinePhpPlaceholder(e){return r.default.replace("___inline_php_directive_#___","#",e)}getRawPropsPlaceholder(e){return r.default.replace("@__raw_props_block_#__@","#",e)}getBladeDirectivePlaceholder(e){return r.default.replace("___blade_directive_#___","#",e)}getBladeDirectiveInStylePlaceholder(e){return r.default.replace(".___blade_directive_in_style_#__","#",e)}getEscapedBladeDirectivePlaceholder(e){return r.default.replace("___escaped_directive_#___","#",e)}getXslotPlaceholder(e){return r.default.replace("x-slot --___#___--","#",e)}getBladeCommentPlaceholder(e){return r.default.replace("___blade_comment_#___","#",e)}getPhpCommentPlaceholder(e){return r.default.replace("___php_comment_#___","#",e)}getBladeBracePlaceholder(e,t=0){if(t>0){let i=t-"___blade_brace_#___".length;return r.default.replace(`___blade_brace_${r.default.repeat("_",i>0?i:0)}#___`,"#",e)}return r.default.replace("___blade_brace_+?#___","#",e)}getRawBladeBracePlaceholder(e){return r.default.replace("___raw_blade_brace_#___","#",e)}getRawPhpTagPlaceholder(e){return r.default.replace("___raw_php_tag_#___","#",e)}getNonnativeScriptPlaceholder(e){return r.default.replace("","#",e)}getScriptPlaceholder(e){return r.default.replace("","#",e)}getHtmlTagPlaceholder(e){return r.default.replace("","#",e)}getInlineCustomDirectivePlaceholder(e){return r.default.replace("___inline_cd_#___","#",e)}getBeginCustomDirectivePlaceholder(e){return r.default.replace("@customdirective(___#___)","#",e)}getElseCustomDirectivePlaceholder(e){return r.default.replace("@else(___#___)","#",e)}getEndCustomDirectivePlaceholder(e){return r.default.replace("@endcustomdirective(___#___)","#",e)}getUnbalancedDirectivePlaceholder(e){return r.default.replace("@if (unbalanced___#___)","#",e)}getHtmlAttributePlaceholder(e,t){if(t&&t>0){let i=t-"___attrs_#___".length;return r.default.replace(`___attrs${r.default.repeat("_",i>0?i:1)}#___`,"#",e)}return r.default.isNull(t)?r.default.replace("___attrs_#___","#",e):r.default.replace("___attrs_+?#___","#",e)}getShorthandBindingPlaceholder(e,t=0){if(t&&t>0){let i=t-"___short_binding_#___".length;return r.default.replace(`___short_binding_${r.default.repeat("_",i>0?i:1)}#___`,"#",e)}return r.default.replace("___short_binding_+?#___","#",e)}getComponentAttributePlaceholder(e){return r.default.replace("___attribute_#___","#",e)}getXInitPlaceholder(e){return r.default.replace("___x_init_#___","#",e)}getPlaceholder(e,t,n=null){if(n&&n>0){let i=`___${e}_#___`,s=n-i.length;return r.default.replace(`___${e}${r.default.repeat("_",s>0?s:1)}#___`,"#",t)}return r.default.isNull(n)?r.default.replace(`___${e}_#___`,"#",t):r.default.replace(`s___${e}_+?#___`,"#",t)}getXDataPlaceholder(e){return r.default.replace("___x_data_#___","#",e)}getTemplatingStringPlaceholder(e){return r.default.replace("___templating_str_#___","#",e)}getStringLiteralInPhpPlaceholder(e){return r.default.replace("'___php_content_#___'","#",e)}getBladeDirectiveInScriptPlaceholder(e){return r.default.replace("___directives_script_#___","#",e)}restoreIgnoredLines(e){return r.default.replace(e,new RegExp(`${this.getIgnoredLinePlaceholder("(\\d+)")}`,"gm"),(t,n)=>this.ignoredLines[n])}restoreCurlyBraceForJS(e){return r.default.replace(e,new RegExp(`${this.getCurlyBraceForJSPlaceholder("(\\d+)")}`,"gm"),(t,n)=>`@{{ ${E.default.js_beautify(this.curlyBracesWithJSs[n].trim())} }}`)}restorePhpBlock(e){return this.restoreRawPhpBlock(e).then(t=>this.restoreRawPropsBlock(t))}async restoreRawPhpBlock(e){return(0,x.default)(e,new RegExp(`${this.getRawPlaceholder("(\\d+)")}`,"gm"),async(t,n)=>{var d;let i=this.rawBlocks[n],s=this.getRawPlaceholder(n.toString()),a=(d=e.match(new RegExp(`^(.*?)${s}`,"gmi")))!=null?d:[""],l=(0,v.default)(a[0]),o=this.isInline(i),c=await this.isMultilineStatement(i);if(o&&c)i=(await A(``,this.options)).trim();else if(c){let p=l.amount+this.indentSize;i=(await A(``,{...this.options,useProjectPrintWidth:!0,adjustPrintWidthBy:p})).trimEnd()}else o?i=``:i=(await A(``,this.options)).trimEnd();return r.default.replace(i,/^(\s*)?<\?php(.*?)\?>/gms,(p,u,m)=>{if(this.isInline(i))return`@php${m}@endphp`;let $=this.preserveStringLiteralInPhp(m);$=this.preservePhpComment($);let w=this.indentRawBlock(l,$);return w=this.restorePhpComment(w),`@php${this.restoreStringLiteralInPhp(w)}@endphp`})})}async restoreRawPropsBlock(e){let t=this.getRawPropsPlaceholder("(\\d+)");return(0,x.default)(e,new RegExp(t,"gms"),async(n,i)=>{var c;let s=this.getRawPropsPlaceholder(i.toString()),a=(c=e.match(new RegExp(`^(.*?)${s}`,"gmi")))!=null?c:[""],l=(0,v.default)(a[0]),o=`@props(${(await B(this.rawPropsBlocks[i],{...this.options})).trim()})`;return this.indentRawPhpBlock(l,o)})}isInline(e){return r.default.split(e,` `).length===1}async isMultilineStatement(e){return(await A(``,this.options)).trimRight().split(` `).length>1}indentRawBlock(e,t){if(this.isInline(t))return`${e.indent}${t}`;let i=e.amount/this.indentSize,s=this.indentCharacter.repeat(i<0?0:(i+1)*this.indentSize),a=this.indentCharacter.repeat(i<0?0:i*this.indentSize),l=t.split(` `);return r.default.chain(l).map((o,c)=>c===0?o.trim():c===l.length-1?a+o:o.length===0?o:s+o).join(` `).value()}indentBladeDirectiveBlock(e,t){if(r.default.isEmpty(e.indent))return t;if(this.isInline(t))return`${e.indent}${t}`;let i=e.amount/this.indentSize,s=this.indentCharacter.repeat(i<0?0:i*this.indentSize),a=this.indentCharacter.repeat(i<0?0:i*this.indentSize),l=t.split(` `);return r.default.chain(l).map((o,c)=>c===l.length-1?a+o:s+o).value().join(` `)}indentScriptBlock(e,t){if(r.default.isEmpty(e.indent))return t;if(this.isInline(t))return`${t}`;let i=e.amount/this.indentSize,s=this.indentCharacter.repeat(i<0?0:i*this.indentSize),a=this.indentCharacter.repeat(i<0?0:i*this.indentSize),o=r.default.replace(t,/`.*?`/gs,d=>this.storeTemplatingString(d)).split(` `),c=r.default.chain(o).map((d,p)=>p===0?d:p===o.length-1?a+d:r.default.isEmpty(d)?d:s+d).value().join(` `);return this.restoreTemplatingString(`${c}`)}indentRawPhpBlock(e,t){if(r.default.isEmpty(e.indent))return t;if(this.isInline(t))return`${t}`;let i=e.amount/this.indentSize,s=this.indentCharacter.repeat(i<0?0:i*this.indentSize),a=t.split(` `);return r.default.chain(a).map((l,o)=>o===0?l.trim():s+l).value().join(` `)}indentComponentAttribute(e,t){if(r.default.isEmpty(e))return t;if(this.isInline(t))return`${t}`;if(this.isInline(t)&&/\S/.test(e))return`${t}`;let i=(0,v.default)(e).amount/this.indentSize,s=this.indentCharacter.repeat(i<0?0:i*this.indentSize),a=t.split(` `);return r.default.chain(a).map((l,o)=>o===0?l.trim():s+l).value().join(` `)}indentPhpComment(e,t){if(r.default.isEmpty(e.indent))return t;if(this.isInline(t))return`${t}`;let i=e.amount/this.indentSize,s=this.indentCharacter.repeat(i<0?0:i*this.indentSize),a=t.split(` `),l=!1;return r.default.chain(a).map((o,c)=>c===0?o.trim():o.trim().startsWith("*")?o.trim().endsWith("*/")&&l?o:s+o:(l=!0,o)).join(` `).value()}restoreBladeDirectivesInStyles(e){return r.default.replace(e,/(?<=]*?(?)(.*?)(?=<\/style>)/gis,t=>{let n=t,i=new RegExp(`${this.getBladeDirectiveInStylePlaceholder("(\\d+)")} {\\s*?/\\* inline_directive \\*/\\s*?}`,"gmi");n=r.default.replace(n,i,(o,c)=>this.bladeDirectivesInStyle[c]);let s=new RegExp(`}\\s*?${this.getBladeDirectiveInStylePlaceholder("(\\d+)")} {\\s*?/\\*else\\*/`,"gmi");n=r.default.replace(n,s,(o,c)=>`${this.bladeDirectivesInStyle[c]}`);let a=new RegExp(`${this.getBladeDirectiveInStylePlaceholder("(\\d+)")} {\\s*?/\\*start\\*/`,"gmi");n=r.default.replace(n,a,(o,c)=>`${this.bladeDirectivesInStyle[c]}`);let l=new RegExp(`}\\s*?/\\* ${this.getBladeDirectiveInStylePlaceholder("(\\d+)")} \\*/`,"gmi");return n=r.default.replace(n,l,(o,c)=>`${this.bladeDirectivesInStyle[c]}`),n})}async restoreBladeDirectivesInScripts(e){let t=new RegExp(`${this.getBladeDirectivePlaceholder("(\\d+)")}`,"gm"),n=r.default.replace(e,t,(i,s)=>{var c;let a=this.getBladeDirectivePlaceholder(s.toString()),l=(c=e.match(new RegExp(`^(.*?)${a}`,"gmi")))!=null?c:[""],o=(0,v.default)(l[0]);return this.indentBladeDirectiveBlock(o,this.bladeDirectives[s])});return n=await(0,x.default)(n,/(?<=]*?(?)(.*?)(?=<\/script>)/gis,async i=>{let s=i;return s=r.default.replace(s,new RegExp(`if \\( \\/\\*(?:(?:${this.getBladeDirectiveInScriptPlaceholder("(\\d+)")}).*?)\\*\\/ \\) \\{`,"gis"),(a,l)=>`${this.directivesInScript[l]}`),s=r.default.replace(s,new RegExp(`} \\/\\* (?:${this.getBladeDirectiveInScriptPlaceholder("(\\d+)")}) \\*\\/ {(\\s*?\\(___directive_condition_\\d+___\\))?`,"gim"),(a,l,o)=>r.default.isUndefined(o)?`${this.directivesInScript[l].trim()}`:`${this.directivesInScript[l].trim()} ${(o!=null?o:"").trim()}`),s=r.default.replace(s,new RegExp(`} \\/\\*(?:${this.getBladeDirectiveInScriptPlaceholder("(\\d+)")})\\*\\/`,"gis"),(a,l)=>`${this.directivesInScript[l]}`),s=await(0,x.default)(s,new RegExp(`${this.getRawPlaceholder("(\\d+)")}`,"gm"),async(a,l)=>{var u;let o=this.rawBlocks[l],c=this.getRawPlaceholder(l.toString()),d=(u=e.match(new RegExp(`^(.*?)${c}`,"gmi")))!=null?u:[""],p=(0,v.default)(d[0]);return this.isInline(o)&&await this.isMultilineStatement(o)?o=(await A(``,this.options)).trim():o.split(` `).length>1?o=(await A(``,this.options)).trim():o=``,r.default.replace(o,/^(\s*)?<\?php(.*?)\?>/gms,(m,$,w)=>{if(this.isInline(o))return`@php${w}@endphp`;let I=this.preserveStringLiteralInPhp(w),Me=this.indentRawBlock(p,I);return`@php${this.restoreStringLiteralInPhp(Me)}@endphp`})}),s=r.default.replace(s,/(?<=[\S]+)(\s*?)\/\*\*\*script_placeholder\*\*\*\/(\s)?/gim,(a,l,o)=>{if(o!==void 0)return o;let c=l!=null?l:"",d=o!=null?o:"";return c+d}),s}),t.test(n)&&(n=await this.restoreBladeDirectivesInScripts(n)),n}async formatPreservedBladeDirectives(e){return ke.default.map(e,async t=>{let n=await this.formatAsHtml(t);return(await this.formatAsBlade(n)).trimRight(` `)})}restoreBladeComment(e){return new Promise(t=>t(e)).then(t=>r.default.replace(t,new RegExp(`${this.getBladeCommentPlaceholder("(\\d+)")}`,"gms"),(n,i)=>this.bladeComments[i].replace(/{{--(?=\S)/g,"{{-- ").replace(/(?<=\S)--}}/g," --}}")))}restoreXslot(e){return r.default.replace(e,/x-slot\s*--___(\d+)___--/gms,(t,n)=>this.xSlot[n]).replace(/(?<=)/gm,()=>"")}restorePhpComment(e){return r.default.replace(e,new RegExp(`${this.getPhpCommentPlaceholder("(\\d+)")};{0,1}`,"gms"),(t,n)=>{var o;let i=this.getPhpCommentPlaceholder(n.toString()),s=(o=e.match(new RegExp(`^(.*?)${i}`,"gmi")))!=null?o:[""],a=(0,v.default)(s[0]),l=he(this.phpComments[n]);return this.indentPhpComment(a,l)})}async restoreEscapedBladeDirective(e){return new Promise(t=>t(e)).then(t=>r.default.replace(t,new RegExp(`${this.getEscapedBladeDirectivePlaceholder("(\\d+)")}`,"gms"),(n,i)=>this.escapedBladeDirectives[i]))}async restoreBladeBrace(e){return new Promise(t=>t(e)).then(t=>(0,x.default)(t,new RegExp(`${this.getBladeBracePlaceholder("(\\d+)")}`,"gm"),async(n,i)=>{var c;let s=this.getBladeBracePlaceholder(i.toString()),a=(c=e.match(new RegExp(`^(.*?)${s}`,"gmi")))!=null?c:[""],l=(0,v.default)(a[0]),o=this.bladeBraces[i];return o.trim()===""?`{{${o}}}`:this.isInline(o)?`{{ ${(await B(o,{...this.options,trailingCommaPHP:!1,printWidth:k})).replace(/([\n\s]*)->([\n\s]*)/gs,"->").split(` `).map(d=>d.trim()).join("").trimRight(` `)} }}`:`{{ ${this.indentRawPhpBlock(l,(await B(o,this.options)).replace(/([\n\s]*)->([\n\s]*)/gs,"->").trim().trimEnd())} }}`}))}async restoreRawBladeBrace(e){return new Promise(t=>t(e)).then(t=>(0,x.default)(t,new RegExp(`${this.getRawBladeBracePlaceholder("(\\d+)")}`,"gms"),async(n,i)=>{var c;let s=this.getRawBladeBracePlaceholder(i),a=(c=e.match(new RegExp(`^(.*?)${s}`,"gmi")))!=null?c:[""],l=(0,v.default)(a[0]),o=this.rawBladeBraces[i];return o.trim()===""?`{!!${o}!!}`:this.indentRawPhpBlock(l,`{!! ${(await B(o,this.options)).replace(/([\n\s]*)->([\n\s]*)/gs,"->").trim()} !!}`)}))}restoreInlineDirective(e){return new Promise(t=>t(e)).then(t=>r.default.replace(t,new RegExp(`${this.getInlinePlaceholder("(\\d+)")}`,"gms"),(n,i)=>this.inlineDirectives[i]))}async restoreConditions(e){return new Promise(t=>t(e)).then(t=>(0,x.default)(t,new RegExp(`${this.getConditionPlaceholder("(\\d+)")}`,"gms"),async(n,i)=>{var c;let s=this.getConditionPlaceholder(i),a=(c=e.match(new RegExp(`^(.*?)${s}`,"gmi")))!=null?c:[""],l=(0,v.default)(a[0]),o=this.conditions[i];return this.formatExpressionInsideBladeDirective(o,l)}))}restoreUnbalancedDirective(e){return new Promise(t=>t(e)).then(t=>r.default.replace(t,/@if \(unbalanced___(\d+)___\)/gms,(n,i)=>this.unbalancedDirectives[i]))}async restoreInlinePhpDirective(e){return new Promise(t=>t(e)).then(t=>(0,x.default)(t,new RegExp(`${this.getInlinePhpPlaceholder("(\\d+)")}`,"gm"),async(n,i)=>{var c;let s=this.inlinePhpDirectives[i],a=this.getInlinePhpPlaceholder(i),l=(c=e.match(new RegExp(`^(.*?)${a}`,"gmi")))!=null?c:[""],o=(0,v.default)(l[0]);return s.includes("@php")?`${(await B(s,{...this.options,printWidth:k})).replace(/([\n\s]*)->([\n\s]*)/gs,"->").trim().trimRight(` `)}`:new RegExp(ie.join("|"),"gi").test(s)?(0,x.default)(s,new RegExp(`(?<=@(${r.default.map(ie,p=>p.substring(1)).join("|")}).*?\\()(.*)(?=\\))`,"gis"),async(p,u,m)=>{let $=this.wrapLineLength;return["button","class"].includes(u)&&($=80),u==="include"&&($=this.wrapLineLength-4-i.length-o.amount),this.formatExpressionInsideBladeDirective(m,o,$)}):`${(await B(s,{...this.options,printWidth:k})).trimEnd()}`}))}async restoreRawPhpTags(e){return new Promise(t=>t(e)).then(t=>(0,x.default)(t,new RegExp(`${this.getRawPhpTagPlaceholder("(\\d+)")}`,"gms"),async(n,i)=>{var s;try{let a=this.rawPhpTags[i],o=/(?<=<\?php\s*?)\/\*.*?\*\/(?=\s*?\?>)/gim.test(a)&&this.isInline(a),c=this.getRawPhpTagPlaceholder(i),d=(s=e.match(new RegExp(`^(.*?)${c}`,"gmi")))!=null?s:[""],p=(0,v.default)(d[0]);if(o)return a;let u=(await A(this.rawPhpTags[i],this.options)).trim().trimEnd();if(this.isInline(u))return u;let m=this.preservePhpComment(u);return p.indent&&(m=this.indentRawPhpBlock(p,m)),this.restorePhpComment(m)}catch{return`${this.rawPhpTags[i]}`}}))}restoreNonnativeScripts(e){return r.default.replace(e,new RegExp(`${this.getNonnativeScriptPlaceholder("(\\d+)")}`,"gmi"),(t,n)=>`${this.nonnativeScripts[n]}`)}restoreScripts(e){return new Promise(t=>t(e)).then(t=>r.default.replace(t,new RegExp(`${this.getScriptPlaceholder("(\\d+)")}`,"gim"),(n,i)=>{var p;let s=this.scripts[i],a=this.getScriptPlaceholder(i),l=(p=e.match(new RegExp(`^(.*?)${a}`,"gmi")))!=null?p:[""],o=(0,v.default)(l[0]),c=y(this.options).useTabs||!1,d={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,extra_liners:y(this.options).extraLiners,indent_with_tabs:c,end_with_newline:!1,templating:["php"]};return c?this.indentScriptBlock(o,r.default.replace(E.default.html_beautify(s,d),/\t/g," ".repeat(this.indentSize))):this.indentScriptBlock(o,E.default.html_beautify(s,d))}))}async restoreCustomDirective(e){return this.restoreInlineCustomDirective(e).then(t=>this.restoreBeginCustomDirective(t)).then(t=>this.restoreElseCustomDirective(t)).then(t=>this.restoreEndCustomDirective(t))}async restoreInlineCustomDirective(e){return(0,x.default)(e,new RegExp(`${this.getInlineCustomDirectivePlaceholder("(\\d+)")}`,"gim"),async(t,n)=>{var o;let i=this.getInlineCustomDirectivePlaceholder(n.toString()),s=(o=e.match(new RegExp(`^(.*?)${r.default.escapeRegExp(i)}`,"gmi")))!=null?o:[""],a=(0,v.default)(s[0]),l=`${this.customDirectives[n]}`;return(0,x.default)(l,/(@[a-zA-z0-9\-_]+)(.*)/gis,async(c,d,p)=>{try{let u=(await B(`func${p}`,{...this.options,printWidth:k})).replace(/([\n\s]*)->([\n\s]*)/gs,"->").replace(/,(\s*?\))$/gm,(m,$)=>$).trim().substring(4);return`${d}${this.indentComponentAttribute(a.indent,u)}`}catch{return`${c}`}})})}async restoreBeginCustomDirective(e){return(0,x.default)(e,new RegExp(`@customdirective\\(___(\\d+)___\\)\\s*?(${_})*`,"gim"),async(t,n)=>{var o;let i=this.getBeginCustomDirectivePlaceholder(n.toString()),s=(o=e.match(new RegExp(`^(.*?)${r.default.escapeRegExp(i)}`,"gmi")))!=null?o:[""],a=(0,v.default)(s[0]),l=`${this.customDirectives[n]}`;return(0,x.default)(l,/(@[a-zA-z0-9\-_]+)(.*)/gis,async(c,d,p)=>{try{let u=(await B(`func${p}`,{...this.options,trailingCommaPHP:!1})).replace(/([\n\s]*)->([\n\s]*)/gs,"->").trim().substring(4);return`${d}${this.indentComponentAttribute(a.indent,u)}`}catch{return`${c}`}})})}async restoreElseCustomDirective(e){return r.default.replace(e,/@else\(___(\d+)___\)/gim,(t,n)=>`${this.customDirectives[n]}`)}async restoreEndCustomDirective(e){return r.default.replace(e,/@endcustomdirective\(___(\d+)___\)/gim,(t,n)=>`${this.customDirectives[n]}`)}async restoreHtmlTags(e){return r.default.replace(e,new RegExp(`${this.getHtmlTagPlaceholder("(\\d+)")}`,"gim"),(t,n)=>{var p;let i=this.getHtmlTagPlaceholder(n.toString()),s=(p=e.match(new RegExp(`^(.*?)${i}`,"gmi")))!=null?p:[""],a=(0,v.default)(s[0]),l={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,extra_liners:y(this.options).extraLiners,end_with_newline:!1,templating:["php"]},o=this.htmlTags[n],c=r.default.first(o.match(/(<(textarea|pre).*?(?)(?=.*?<\/\2>)/gis));if(c===void 0)return`${this.indentScriptBlock(a,E.default.html_beautify(o,l))}`;let d=o.substring(c.length,o.length);return`${this.indentScriptBlock(a,E.default.html_beautify(c,l))}${d}`})}restoreHtmlAttributes(e){return r.default.replace(e,new RegExp(`${this.getHtmlAttributePlaceholder("(\\d+)")}`,"gms"),(t,n)=>this.htmlAttributes[n])}restoreXData(e){return r.default.replace(e,new RegExp(`${this.getXDataPlaceholder("(\\d+)")}`,"gm"),(t,n)=>{var u;let i=this.getXDataPlaceholder(n.toString()),s=(u=e.match(new RegExp(`^(.*?)${i}`,"gmi")))!=null?u:[""],a=(0,v.default)(s[0]),l=this.formatJS(this.xData[n]).split(` `),o=a.amount/(this.indentCharacter===" "?4:1),c=l[0],d=this.indentCharacter.repeat(o<0?0:o),p=l.map(m=>d+m);return p[0]=c,`${p.join(` `)}`})}restoreXInit(e){return r.default.replace(e,new RegExp(`${this.getXInitPlaceholder("(\\d+)")}`,"gm"),(t,n)=>{var u;let i=this.getXInitPlaceholder(n.toString()),s=(u=e.match(new RegExp(`^(.*?)${i}`,"gmi")))!=null?u:[""],a=(0,v.default)(s[0]),l=this.formatJS(this.xInit[n]).split(` `),o=a.amount/(this.indentCharacter===" "?4:1),c=l[0],d=this.indentCharacter.repeat(o<0?0:o),p=l.map(m=>d+m);return p[0]=c,`${p.join(` `)}`})}restoreTemplatingString(e){return r.default.replace(e,new RegExp(`${this.getTemplatingStringPlaceholder("(\\d+)")}`,"gms"),(t,n)=>this.templatingStrings[n])}restoreStringLiteralInPhp(e){return r.default.replace(e,new RegExp(`${this.getStringLiteralInPhpPlaceholder("(\\d+)")}`,"gms"),(t,n)=>this.stringLiteralInPhp[n])}async restoreComponentAttribute(e){return(0,x.default)(e,new RegExp(`${this.getComponentAttributePlaceholder("(\\d+)")}`,"gim"),async(t,n)=>{var c;let i=this.getComponentAttributePlaceholder(n),s=(c=e.match(new RegExp(`^(.*?)${i}`,"gmi")))!=null?c:[""],a=(0,v.default)(s[0]),l=this.componentAttributes[n],o=await(0,x.default)(l,/(:{1,2}.*?=)(["'])(.*?)(?=\2)/gis,async(d,p,u,m)=>{if(m==="")return d;if(s[0].startsWith("{var c;let i=this.getShorthandBindingPlaceholder(n),s=(c=e.match(new RegExp(`^(.*?)${i}`,"gmi")))!=null?c:[""],a=(0,v.default)(s[0]),l=this.shorthandBindings[n],o=r.default.replace(l,/(:{1,2}.*?=)(["'])(.*?)(?=\2)/gis,(d,p,u,m)=>{let $={wrap_line_length:this.wrapLineLength-a.amount,brace_style:"preserve-inline"};if(m==="")return d;if(this.isInline(m))try{return`${p}${u}${E.default.js_beautify(m.trim(),$).trim()}`}catch{return`${p}${u}${m.trim()}`}return`${p}${u}${E.default.js_beautify(m.trim(),$).trim()}`});return`${this.indentComponentAttribute(a.indent,o)}`})}async formatAsBlade(e){this.currentIndentLevel=0,this.shouldBeIndent=!1;let t=X(e),n=await new q(this.vsctm,this.oniguruma);return n.createRegistry().loadGrammar("text.html.php.blade").then(a=>n.tokenizeLines(t,a)).then(a=>this.formatTokenizedLines(t,a)).catch(a=>{throw a})}async formatTokenizedLines(e,t){this.result=[],this.stack=[];for(let n=0;n0&&this.decrementIndentLevel(),this.shouldBeIndent=!0,this.stack.push(e)):(this.shouldBeIndent=!0,this.stack.push(e))),r.default.includes(D,e)){if(e==="@endswitch"&&r.default.last(this.stack)==="@default"){this.decrementIndentLevel(2),this.shouldBeIndent=!1;return}this.decrementIndentLevel(),this.shouldBeIndent=!1,this.stack.pop()}r.default.includes(L,e)&&(this.decrementIndentLevel(),this.shouldBeIndent=!0)}async processToken(e,t){if(r.default.includes(e.scopes,"punctuation.definition.comment.begin.blade")&&(this.isInsideCommentBlock=!0),this.argumentCheck){let{count:n,inString:i,stack:s,unindentOn:a}=this.argumentCheck;if(!i&&t===")"){if(s.push(t),n[t]+=1,n["("]===n[t]){let l=s.join("");await $e(l)>=a&&(this.shouldBeIndent=!1),this.argumentCheck=!1}return}s.push(t),i===t?this.argumentCheck.inString=!1:!i&&(t==='"'||t==="'")&&(this.argumentCheck.inString=t),t==="("&&!i&&(n[t]+=1)}r.default.includes(e.scopes,"punctuation.definition.comment.end.blade")&&(this.isInsideCommentBlock=!1),(t==="{{--"||t.includes("{{--"))&&(this.isInsideCommentBlock=!0),(t==="--}}"||t.includes("--}}"))&&(this.isInsideCommentBlock=!1),r.default.includes(e.scopes,"keyword.blade")&&(this.isInsideCommentBlock||(await this.processKeyword(t.toLowerCase()),r.default.includes(Object.keys(te),t.toLowerCase())&&(this.argumentCheck={unindentOn:te[t.toLowerCase()],stack:[],inString:!1,count:{"(":0,")":0}})))}async processTokenizeResult(e,t){if(this.shouldBeIndent&&(this.incrementIndentLevel(),this.shouldBeIndent=!1),ge(e,t)){this.insertFormattedLineToResult(t);return}for(let n=0;n0&&this.result.push(i),i!==e&&this.diffs.push({original:e,formatted:i})}incrementIndentLevel(e=1){this.currentIndentLevel+=e}decrementIndentLevel(e=1){this.currentIndentLevel-=e}async formatExpressionInsideBladeDirective(e,t,n=void 0){let i=`func(${e})`,s=await B(i,{...this.options,printWidth:n!=null?n:this.defaultPhpFormatOption.printWidth});if(s===i)return e;let a=s.replace(/([\n\s]*)->([\n\s]*)/gs,"->").replace(/(?`${o}] )`).replace(/,[\n\s]*?\)/gs,")").replace(/,(\s*?\))$/gm,(l,o)=>o).trim();return this.options.useTabs&&(a=r.default.replace(a,/(?<=^ *) {4}/gm," ".repeat(this.indentSize))),a=a.replace(/func\((.*)\)/gis,(l,o)=>o),this.isInline(a.trim())&&(a=a.trim()),this.indentRawPhpBlock(t,a)}formatJS(e){let t=e,n={js:[],entangle:[]};return Object.keys(n).forEach(i=>{t=t.replace(new RegExp(`@${i}\\((?:[^)(]+|\\((?:[^)(]+|\\([^)(]*\\))*\\))*\\)`,"gs"),s=>{let a=n[i].push(s)-1;return this.getPlaceholder(i,a,s.length)})}),t=E.default.js_beautify(t,{brace_style:"preserve-inline"}),Object.keys(n).forEach(i=>{t=t.replace(new RegExp(this.getPlaceholder(i,"_*(\\d+)"),"gms"),(s,a)=>n[i][a])}),t}};var je=g(require("ajv"),1),Oe=g(require("find-config"),1),We=g(require("fs"),1),He=g(require("path"),1),ct=new je.default,Te=[".bladeformatterrc.json",".bladeformatterrc"];function ze(h){for(let e=0;e{throw new H(i)})}async formatFromCLI(){try{this.printPreamble(),await this.readIgnoreFile(f.default.cwd()),await this.processPaths(),this.printResults()}catch{}}fileExists(e){return W.default.promises.access(e,W.default.constants.F_OK).then(()=>!0).catch(()=>!1)}async readIgnoreFile(e){let t=".bladeignore",n,i=R.default.dirname(e);if(this.options.ignoreFilePath?n=this.options.ignoreFilePath:n=(0,ae.default)(t,{cwd:i}),!!n)try{this.ignoreFile=(await W.default.promises.readFile(n)).toString()}catch{}}async findTailwindConfig(e){if(!this.options.sortTailwindcssClasses)return;let t="tailwind.config.js",n;if(this.options.tailwindcssConfigPath)if(this.runtimeConfigPath){let i=R.default.dirname(this.runtimeConfigPath);n=R.default.resolve(i,this.options.tailwindcssConfigPath)}else R.default.isAbsolute(this.options.tailwindcssConfigPath)?n=R.default.resolve(this.options.tailwindcssConfigPath):n=R.default.resolve(this.options.tailwindcssConfigPath);else{let i=R.default.dirname(e);n=(0,ae.default)(t,{cwd:i})}n&&(this.options.tailwindcssConfigPath=n)}async readRuntimeConfig(e){var n,i;P.default.isEmpty(this.runtimeConfigCache)&&(this.options=P.default.merge(this.options,this.runtimeConfigCache));let t;if(this.options.runtimeConfigPath?t=this.options.runtimeConfigPath:t=ze(e),!P.default.isNull(t)){this.runtimeConfigPath=t;try{let s=await Ne(t);this.options=P.default.mergeWith(this.options,s,(a,l)=>P.default.isNil(l)?a:l),this.runtimeConfigCache=this.options,this.options.sortTailwindcssClasses&&await this.findTailwindConfig(e)}catch(s){s instanceof SyntaxError&&(f.default.stdout.write(S.default.red.bold(` Blade Formatter JSON Syntax Error: `)),f.default.stdout.write(oe.default.format(s)),f.default.exit(1)),f.default.stdout.write(S.default.red.bold(` Blade Formatter Config Error: ${R.default.basename(t)} `)),f.default.stdout.write(`\`${s.errors[0].instancePath.replace("/","")}\` ${s.errors[0].message} `),(n=s.errors[0].params)!=null&&n.allowedValues&&console.log((i=s.errors[0].params)==null?void 0:i.allowedValues),f.default.exit(1)}}}async processPaths(){await Promise.all(P.default.map(this.paths,async e=>this.processPath(e)))}async processPath(e){await h.globFiles(e).then(t=>P.default.map(t,n=>R.default.relative(".",n))).then(t=>this.filterFiles(t)).then(this.fulFillFiles).then(t=>this.formatFiles(t))}static globFiles(e){return new Promise((t,n)=>{(0,Je.default)(e,(i,s)=>i?n(i):t(s))})}async filterFiles(e){if(this.ignoreFile==="")return e;let t=/^\.\.*/,n=P.default.filter(e,a=>t.test(R.default.relative(".",a))),i=P.default.xor(e,n),s=(0,Xe.default)().add(this.ignoreFile).filter(i);return P.default.concat(n,s)}static fulFillFiles(e){return this.targetFiles.push(e),Promise.resolve(e)}async formatFiles(e){await Promise.all(P.default.map(e,async t=>this.formatFile(t)))}async formatFile(e){await this.findTailwindConfig(e),await this.readRuntimeConfig(e),await G(e).then(t=>Promise.resolve(t.toString("utf-8"))).then(t=>new F(this.options).formatContent(t)).then(t=>this.checkFormatted(e,t)).then(t=>this.writeToFile(e,t)).catch(t=>{this.handleError(e,t)})}async checkFormatted(e,t){this.printFormattedOutput(e,t);let n=W.default.readFileSync(e,"utf-8"),i=X(n),s=X(t),a=Se(e,i,s);return this.diffs.push(a),this.outputs.push(t),a.length>0&&((this.options.progress||this.options.write)&&f.default.stdout.write(S.default.green("F")),this.options.checkFormatted&&(f.default.stdout.write(`${e} `),f.default.exitCode=1),this.formattedFiles.push(e)),a.length===0&&(this.options.progress||this.options.write)&&f.default.stdout.write(S.default.green(".")),Promise.resolve(t)}printFormattedOutput(e,t){this.options.write||this.options.checkFormatted||(f.default.stdout.write(`${t}`),P.default.last(this.paths)===e||P.default.last(this.targetFiles)===e)||(this.paths.length>1||this.targetFiles.length>1)&&f.default.stdout.write(` `)}writeToFile(e,t){this.options.write&&(this.options.checkFormatted||t.length===0||P.default.isNull(t)||P.default.isEmpty(t)||W.default.writeFile(e,t,n=>{n&&(f.default.stdout.write(`${S.default.red(n.message)} `),f.default.exit(1))}))}handleError(e,t){(this.options.progress||this.options.write)&&f.default.stdout.write(S.default.red("E")),f.default.exitCode=1,this.errors.push({path:e,message:t.message,error:t})}printPreamble(){this.options.checkFormatted&&f.default.stdout.write(`Check formatting... `)}async printResults(){this.printDescription(),this.printDifferences(),this.printFormattedFiles(),this.printErrors()}printDescription(){if(!this.options.write)return;let e=` `;f.default.stdout.write(e),f.default.stdout.write(S.default.bold.green(`Fixed: F `)),f.default.stdout.write(S.default.bold.red(`Errors: E `)),f.default.stdout.write(S.default.bold("Not Changed: ")+S.default.bold.green(`. `))}printFormattedFiles(){if(this.formattedFiles.length===0){this.options.checkFormatted&&f.default.stdout.write(S.default.bold(` All matched files are formatted! `));return}if(!this.options.write){this.options.checkFormatted&&f.default.stdout.write(` Above file(s) are formattable. Forgot to run formatter? Use ${S.default.bold("--write")} option to overwrite. `);return}f.default.stdout.write(S.default.bold(` Formatted Files: `)),P.default.each(this.formattedFiles,e=>f.default.stdout.write(`${S.default.bold(e)} `))}printDifferences(){if(this.options.diff){if(f.default.stdout.write(S.default.bold(` Differences: `)),P.default.filter(this.diffs,e=>e.length>0).length===0){f.default.stdout.write((0,S.default)(`No changes found. `));return}P.default.each(this.diffs,e=>be(e))}}printErrors(){P.default.isEmpty(this.errors)||(f.default.stdout.write(S.default.red.bold(` Errors: `)),P.default.each(this.errors,e=>f.default.stdout.write(`${oe.default.format(e)} `)))}};0&&(module.exports={BladeFormatter,Formatter}); //# sourceMappingURL=bundle.cjs.map