// @bun
var{defineProperty:S,getOwnPropertyNames:v,getOwnPropertyDescriptor:g}=Object,d=Object.prototype.hasOwnProperty;function h(j){return this[j]}var m=(j)=>{var F=(y??=new WeakMap).get(j),q;if(F)return F;if(F=S({},"__esModule",{value:!0}),j&&typeof j==="object"||typeof j==="function"){for(var W of v(j))if(!d.call(F,W))S(F,W,{get:h.bind(j,W),enumerable:!(q=g(j,W))||q.enumerable})}return y.set(j,F),F},y;var u=(j)=>j;function l(j,F){this[j]=u.bind(null,F)}var r=(j,F)=>{for(var q in F)S(j,q,{get:F[q],enumerable:!0,configurable:!0,set:l.bind(F,q)})};var n=(j,F)=>()=>(j&&(F=j(j=0)),F);var s=import.meta.require;var C={if:"control-flow",else:"control-flow",elseif:"control-flow",unless:"control-flow",switch:"control-flow",case:"control-flow",default:"control-flow",for:"loop",foreach:"loop",forelse:"loop",while:"loop",empty:"loop",break:"loop",continue:"loop",extends:"layout",section:"layout",yield:"layout",parent:"layout",include:"layout",includeIf:"layout",includeWhen:"layout",includeFirst:"layout",once:"layout",push:"layout",prepend:"layout",stack:"layout",component:"component",slot:"component",props:"component",webcomponent:"component",auth:"auth",guest:"auth",can:"auth",cannot:"auth",role:"auth",hasRole:"auth",hasAnyRole:"auth",csrf:"form",method:"form",error:"form",old:"form",input:"form",textarea:"form",select:"form",checkbox:"form",radio:"form",meta:"seo",title:"seo",seo:"seo",jsonld:"seo",canonical:"seo",translate:"i18n",lang:"i18n",choice:"i18n"},p={"control-flow":"symbol-branch",loop:"symbol-loop",layout:"symbol-structure",component:"symbol-class",auth:"shield",form:"symbol-field",seo:"search",i18n:"globe",custom:"symbol-misc"};function e(j){let F={type:"document",name:"document",label:"Document",range:{start:0,end:j.length,line:1,column:1},children:[]},q=[F],W=0,V=1,G=1,X=(K)=>{if(K===`
`)V++,G=1;else G++;W++},Z=()=>({start:W,end:W,line:V,column:G});while(W<j.length){let K=j.slice(W),A=K.match(/^@(\w+)(?:\s*\(([^)]*)\))?/);if(A){let[Y,J,B]=A,H=C[J]||"custom";if(J.startsWith("end")){let Q=J.slice(3),$=q[q.length-1];if($.name===Q&&q.length>1)$.range.end=W+Y.length,q.pop()}else{let Q=x(J),$={type:"directive",name:J,label:`@${J}${B?`(${b(B,30)})`:""}`,range:Z(),children:[],directiveCategory:H,isClosable:Q,icon:p[H],description:B};if(q[q.length-1].children.push($),Q)q.push($)}for(let Q of Y)X(Q);continue}let z=K.match(/^<([A-Z][A-Za-z0-9]+)([^>]*)>/);if(z){let[Y,J,B]=z,H={type:"component",name:J,label:`<${J}>`,range:Z(),children:[],attributes:P(B),icon:"symbol-class",isClosable:!Y.endsWith("/>")};if(q[q.length-1].children.push(H),H.isClosable)q.push(H);for(let Q of Y)X(Q);continue}let U=K.match(/^<\/([A-Z][A-Za-z0-9]+)>/);if(U){let[Y,J]=U,B=q[q.length-1];if(B.name===J&&B.type==="component"&&q.length>1)B.range.end=W+Y.length,q.pop();for(let H of Y)X(H);continue}let D=K.match(/^<([a-z][a-z0-9-]*)([^>]*)>/i);if(D){let[Y,J,B]=D,H=Y.endsWith("/>")||o(J),Q={type:"element",name:J,label:`<${J}>`,range:Z(),children:[],attributes:P(B),isClosable:!H};if(q[q.length-1].children.push(Q),Q.isClosable)q.push(Q);for(let $ of Y)X($);continue}let O=K.match(/^<\/([a-z][a-z0-9-]*)>/i);if(O){let[Y,J]=O,B=q[q.length-1];if(B.name===J&&B.type==="element"&&q.length>1)B.range.end=W+Y.length,q.pop();for(let H of Y)X(H);continue}let R=K.match(/^\{\{([^}]+)\}\}/);if(R){let[Y,J]=R,B={type:"expression",name:"expression",label:`{{ ${b(J.trim(),30)} }}`,range:Z(),children:[],icon:"symbol-variable"};q[q.length-1].children.push(B);for(let H of Y)X(H);continue}let L=K.match(/^<script([^>]*)>/);if(L){let[Y]=L,J={type:"script",name:"script",label:"<script>",range:Z(),children:[],icon:"symbol-event",isClosable:!0};q[q.length-1].children.push(J),q.push(J);for(let B of Y)X(B);continue}if(K.startsWith("</script>")){let J=q[q.length-1];if(J.type==="script"&&q.length>1)J.range.end=W+9,q.pop();for(let B of"</script>")X(B);continue}let T=K.match(/^<style([^>]*)>/);if(T){let[Y]=T,J={type:"style",name:"style",label:"<style>",range:Z(),children:[],icon:"symbol-color",isClosable:!0};q[q.length-1].children.push(J),q.push(J);for(let B of Y)X(B);continue}if(K.startsWith("</style>")){let J=q[q.length-1];if(J.type==="style"&&q.length>1)J.range.end=W+8,q.pop();for(let B of"</style>")X(B);continue}let E=K.match(/^\{\{--([^}]*?)--\}\}/);if(E){let[Y,J]=E,B={type:"comment",name:"comment",label:`{{-- ${b(J.trim(),30)} --}}`,range:Z(),children:[],icon:"comment"};q[q.length-1].children.push(B);for(let H of Y)X(H);continue}X(j[W])}return F}function t(j){return N(j)}function jj(j){return N(j)}function N(j){let F=[],q=[],W=[],V=[],G=[],X=[],Z=[],K,A=/\{\{\s*([^}]+?)\s*\}\}/g,z=j.matchAll(A);for(let B of z){let Q=B[1].match(/^([a-z_$][\w$]*)/i);if(Q){let $=I(j,B.index);F.push({name:Q[1],line:$,column:c(j,B.index),context:"expression"})}}let U=/@(\w+)(?:\s*\(([^)]*)\))?/g,D=j.matchAll(U);for(let B of D){let H=B[1],Q=B[2],$=I(j,B.index);if(H==="extends"&&Q)K={extends:Q.replace(/['"]/g,""),line:$,sections:[]};else if(H==="section"&&Q){let _=Q.replace(/['"]/g,"").split(",")[0].trim();if(G.push({name:_,line:$,content:""}),K)K.sections.push(_)}else if(H==="slot")V.push({name:Q?Q.replace(/['"]/g,""):"default",line:$,isNamed:!!Q});else if(H==="component"&&Q){let _=Q.replace(/['"]/g,"").split(",")[0].trim();q.push({name:_,line:$,props:{},hasSlot:!1})}W.push({name:H,category:C[H]||"custom",line:$,params:Q,hasEndTag:x(H)})}let O=/<([A-Z][A-Za-z0-9]+)([^>]*)>/g,R=j.matchAll(O);for(let B of R){let H=B[1],Q=B[2],$=I(j,B.index),_=j.indexOf(`</${H}>`,B.index),w=_!==-1&&j.slice(B.index+B[0].length,_).trim().length>0;q.push({name:H,line:$,props:P(Q),hasSlot:w})}let L=/<script([^>]*)>([\s\S]*?)<\/script>/g,T=j.matchAll(L);for(let B of T){let H=B[1],Q=B[2],$=I(j,B.index),_=H.includes('lang="ts"')||H.includes("lang='ts'"),w=[],M=/export\s+(?:const|let|var|function|class)\s+(\w+)/g,f=Q.matchAll(M);for(let k of f)w.push(k[1]);X.push({type:_?"typescript":"javascript",line:$,content:Q,exports:w})}let E=/<style([^>]*)>([\s\S]*?)<\/style>/g,Y=j.matchAll(E);for(let B of Y){let H=B[1],Q=B[2],$=I(j,B.index),_="css";if(H.includes('lang="scss"')||H.includes("lang='scss'"))_="scss";if(H.includes('lang="less"')||H.includes("lang='less'"))_="less";Z.push({type:_,line:$,content:Q,scoped:H.includes("scoped")})}let J=i(j,W,q,F);return{variables:F,components:q,directives:W,slots:V,sections:G,scripts:X,styles:Z,layout:K,metrics:J}}function i(j,F,q,W){let V=j.split(`
`).length,G=j.length,X=0,Z=0;for(let z of F)if(z.hasEndTag&&!z.name.startsWith("end"))Z++,X=Math.max(X,Z);else if(z.name.startsWith("end"))Z--;let A=1+F.filter((z)=>z.category==="control-flow"||z.category==="loop").length;return{lines:V,characters:G,maxNestingDepth:X,directiveCount:F.length,componentCount:q.length,expressionCount:W.length,complexity:A}}async function qj(j,F={}){let{context:q={},includeStyles:W=!0,includeScripts:V=!1,wrapInDocument:G=!0,baseUrl:X="",customCss:Z=""}=F,K=j;if(K=K.replace(/\{\{\s*([^}]+?)\s*\}\}/g,(z,U)=>{let D=U.trim().split(".")[0].split("[")[0];if(D in q){let O=q[D];return typeof O==="object"?JSON.stringify(O):String(O)}return`<span class="stx-preview-placeholder">${U}</span>`}),K=K.replace(/@(\w+)(?:\s*\([^)]*\))?/g,(z,U)=>{if(U.startsWith("end"))return"";return`<span class="stx-preview-directive" data-directive="${U}">${z}</span>`}),!V)K=K.replace(/<script[\s\S]*?<\/script>/gi,"");let A="";if(W){let z=K.matchAll(/<style[^>]*>([\s\S]*?)<\/style>/gi);for(let U of z)A+=U[1];K=K.replace(/<style[\s\S]*?<\/style>/gi,"")}if(G)return`<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>STX Preview</title>
  ${X?`<base href="${X}">`:""}
  <style>
    .stx-preview-placeholder {
      background: #fff3cd;
      padding: 2px 4px;
      border-radius: 2px;
      font-family: monospace;
      font-size: 0.9em;
    }
    .stx-preview-directive {
      background: #d1ecf1;
      padding: 2px 4px;
      border-radius: 2px;
      font-family: monospace;
      font-size: 0.9em;
    }
    ${Z}
    ${A}
  </style>
</head>
<body>
  ${K}
</body>
</html>`;return K}function Bj(){return[{name:"extends",displayName:"Use Layout",category:"Layout",description:"Use a layout template",icon:"symbol-structure",snippet:`@layout('$1')

@section('content')
  $0
@endsection`},{name:"section",displayName:"Section",category:"Layout",description:"Define a section within a layout",icon:"symbol-structure",snippet:`@section('$1')
  $0
@endsection`},{name:"include",displayName:"Include Partial",category:"Layout",description:"Include another template",icon:"file-add",snippet:"@include('$1')"},{name:"if",displayName:"If Block",category:"Control Flow",description:"Conditional rendering",icon:"symbol-branch",snippet:`@if($1)
  $0
@endif`},{name:"if-else",displayName:"If-Else Block",category:"Control Flow",description:"Conditional with else branch",icon:"symbol-branch",snippet:`@if($1)
  $2
@else
  $0
@endif`},{name:"switch",displayName:"Switch Block",category:"Control Flow",description:"Switch statement for multiple conditions",icon:"symbol-branch",snippet:`@switch($1)
  @case($2)
    $3
    @break
  @default
    $0
@endswitch`},{name:"foreach",displayName:"For Each Loop",category:"Loops",description:"Iterate over a collection",icon:"symbol-loop",snippet:`@foreach($1 as $2)
  $0
@endforeach`},{name:"forelse",displayName:"For Else Loop",category:"Loops",description:"Loop with empty state",icon:"symbol-loop",snippet:`@forelse($1 as $2)
  $3
@empty
  $0
@endforelse`},{name:"for",displayName:"For Loop",category:"Loops",description:"Traditional for loop",icon:"symbol-loop",snippet:`@for($1 = 0; $1 < $2; $1++)
  $0
@endfor`},{name:"component",displayName:"Component",category:"Components",description:"Include a reusable component",icon:"symbol-class",snippet:`@component('$1')
  $0
@endcomponent`},{name:"slot",displayName:"Slot",category:"Components",description:"Define slot content placeholder",icon:"symbol-class",snippet:`@slot('$1')
  $0
@endslot`},{name:"csrf",displayName:"CSRF Token",category:"Forms",description:"Insert CSRF protection token",icon:"shield",snippet:"@csrf"},{name:"error",displayName:"Error Display",category:"Forms",description:"Display validation error",icon:"error",snippet:`@error('$1')
  <span class="error">{{ \\$message }}</span>
@enderror`},{name:"auth",displayName:"Auth Check",category:"Auth",description:"Show content for authenticated users",icon:"shield",snippet:`@auth
  $0
@endauth`},{name:"guest",displayName:"Guest Check",category:"Auth",description:"Show content for guests",icon:"shield",snippet:`@guest
  $0
@endguest`},{name:"meta",displayName:"Meta Tag",category:"SEO",description:"Insert meta tag",icon:"search",snippet:"@meta('$1', '$2')"},{name:"title",displayName:"Page Title",category:"SEO",description:"Set page title",icon:"search",snippet:"@title('$1')"},{name:"translate",displayName:"Translation",category:"i18n",description:"Translate a string",icon:"globe",snippet:"@translate('$1')"}]}function Fj(j,F,q=""){let G=j.snippet.split(`
`).map((O,R)=>R===0?O:q+O).join(`
`),X=G.match(/\$\d/),Z=G.length;if(X)Z=G.indexOf(X[0]);let K=G.replace(/\$\d/g,""),A=K.slice(0,Z),z=A.split(`
`).length-1,U=A.lastIndexOf(`
`)+1,D=Z-U;return{content:K,cursorPosition:{line:F.line+z,column:z===0?F.column+D:D,offset:F.offset+Z}}}function x(j){return["if","unless","switch","for","foreach","forelse","while","section","component","slot","push","prepend","auth","guest","can","cannot","role","hasRole","hasAnyRole","error","isset","empty","ts","js","css","markdown","verbatim","once"].includes(j)}function o(j){return["area","base","br","col","embed","hr","img","input","link","meta","param","source","track","wbr"].includes(j.toLowerCase())}function P(j){let F={},q=/([^\s=]+)(?:=["']([^"']*)["'])?/g,W=j.matchAll(q);for(let V of W){let[,G,X]=V;F[G]=X??!0}return F}function b(j,F){if(j.length<=F)return j;return`${j.slice(0,F-3)}...`}function I(j,F){return j.slice(0,F).split(`
`).length}function c(j,F){let q=j.lastIndexOf(`
`,F-1);return F-q}export{Fj as insertPaletteItem,e as getTemplateOutline,Bj as getDefaultPalette,qj as generatePreview,t as analyzeVisualEditorTemplate,jj as analyzeTemplateContent};
