/*!
Copyright (c) 2026 Lenovo SSG BASD. All rights reserved.
@license Proprietary

This software is the confidential and proprietary property of Lenovo SSG BASD.
You shall not disclose such Confidential Information and shall use it only in
accordance with the terms of the license agreement.

--- Build Info ---
Version: 1.1.1
Build Time: 2026/2/26 17:21:00
Build Commit: 81e556ed827e2f043668506dae6fae8dbb9ef395
*/
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../../@lezer/xml/dist/index.js"),t=require("../../language/dist/index.js"),n=require("../../state/dist/index.js"),l=require("../../view/dist/index.js");function o(e,t){let n=t&&t.getChild("TagName");return n?e.sliceString(n.from,n.to):""}function a(e,t){let n=t&&t.firstChild;return n&&"OpenTag"==n.name?o(e,n):""}function r(e){for(let t=e&&e.parent;t;t=t.parent)if("Element"==t.name)return t;return null}class i{constructor(e,t,n){this.attrs=t,this.attrValues=n,this.children=[],this.name=e.name,this.completion=Object.assign(Object.assign({type:"type"},e.completion||{}),{label:this.name}),this.openCompletion=Object.assign(Object.assign({},this.completion),{label:"<"+this.name}),this.closeCompletion=Object.assign(Object.assign({},this.completion),{label:"</"+this.name+">",boost:2}),this.closeNameCompletion=Object.assign(Object.assign({},this.completion),{label:this.name+">"}),this.text=e.textContent?e.textContent.map(e=>({label:e,type:"text"})):[]}}const s=/^[:\-\.\w\u00b7-\uffff]*$/;function m(e){return Object.assign(Object.assign({type:"property"},e.completion||{}),{label:e.name})}function u(e){return"string"==typeof e?{label:`"${e}"`,type:"constant"}:/^"/.test(e.label)?e:Object.assign(Object.assign({},e),{label:`"${e.label}"`})}function c(e,n){let l=[],c=[],p=Object.create(null);for(let t of n){let e=m(t);l.push(e),t.global&&c.push(e),t.values&&(p[t.name]=t.values.map(u))}let f=[],g=[],d=Object.create(null);for(let t of e){let e=c,n=p;t.attributes&&(e=e.concat(t.attributes.map(e=>"string"==typeof e?l.find(t=>t.label==e)||{label:e,type:"property"}:(e.values&&(n==p&&(n=Object.create(n)),n[e.name]=e.values.map(u)),m(e)))));let o=new i(t,e,n);d[o.name]=o,f.push(o),t.top&&g.push(o)}g.length||(g=f);for(let t=0;t<f.length;t++){let n=e[t],l=f[t];if(n.children)for(let e of n.children)d[e]&&l.children.push(d[e]);else l.children=f}return e=>{var n;let{doc:l}=e.state,i=function(e,n){var l;let o=t.syntaxTree(e).resolveInner(n,-1),a=null;for(let t=o;!a&&t.parent;t=t.parent)"OpenTag"!=t.name&&"CloseTag"!=t.name&&"SelfClosingTag"!=t.name&&"MismatchedCloseTag"!=t.name||(a=t);if(a&&(a.to>n||a.lastChild.type.isError)){let e=a.parent;if("TagName"==o.name)return"CloseTag"==a.name||"MismatchedCloseTag"==a.name?{type:"closeTag",from:o.from,context:e}:{type:"openTag",from:o.from,context:r(e)};if("AttributeName"==o.name)return{type:"attrName",from:o.from,context:a};if("AttributeValue"==o.name)return{type:"attrValue",from:o.from,context:a};let t=o==a||"Attribute"==o.name?o.childBefore(n):o;return"StartTag"==(null==t?void 0:t.name)?{type:"openTag",from:n,context:r(e)}:"StartCloseTag"==(null==t?void 0:t.name)&&t.to<=n?{type:"closeTag",from:n,context:e}:"Is"==(null==t?void 0:t.name)?{type:"attrValue",from:n,context:a}:t?{type:"attrName",from:n,context:a}:null}if("StartCloseTag"==o.name)return{type:"closeTag",from:n,context:o.parent};for(;o.parent&&o.to==n&&!(null===(l=o.lastChild)||void 0===l?void 0:l.type.isError);)o=o.parent;return"Element"==o.name||"Text"==o.name||"Document"==o.name?{type:"tag",from:n,context:"Element"==o.name?o:r(o)}:null}(e.state,e.pos);if(!i||"tag"==i.type&&!e.explicit)return null;let{type:m,from:u,context:h}=i;if("openTag"==m){let e=g,t=a(l,h);if(t){let n=d[t];e=(null==n?void 0:n.children)||f}return{from:u,options:e.map(e=>e.completion),validFor:s}}if("closeTag"==m){let t=a(l,h);return t?{from:u,to:e.pos+(">"==l.sliceString(e.pos,e.pos+1)?1:0),options:[(null===(n=d[t])||void 0===n?void 0:n.closeNameCompletion)||{label:t+">",type:"type"}],validFor:s}:null}if("attrName"==m){let e=d[o(l,h)];return{from:u,options:(null==e?void 0:e.attrs)||c,validFor:s}}if("attrValue"==m){let t=function(e,t,n){let l=t&&t.getChildren("Attribute").find(e=>e.from<=n&&e.to>=n),o=l&&l.getChild("AttributeName");return o?e.sliceString(o.from,o.to):""}(l,h,u);if(!t)return null;let n=d[o(l,h)],a=((null==n?void 0:n.attrValues)||p)[t];return a&&a.length?{from:u,to:e.pos+('"'==l.sliceString(e.pos,e.pos+1)?1:0),options:a,validFor:/^"[^"]*"?$/}:null}if("tag"==m){let t=a(l,h),n=d[t],r=[],i=h&&h.lastChild;!t||i&&"CloseTag"==i.name&&o(l,i)==t||r.push(n?n.closeCompletion:{label:"</"+t+">",type:"type",boost:2});let s=r.concat(((null==n?void 0:n.children)||(h?f:g)).map(e=>e.openCompletion));if(h&&(null==n?void 0:n.text.length)){let t=h.firstChild;t.to>e.pos-20&&!/\S/.test(e.state.sliceDoc(t.to,e.pos))&&(s=s.concat(n.text))}return{from:u,options:s,validFor:/^<\/?[:\-\.\w\u00b7-\uffff]*$/}}return null}}const p=t.LRLanguage.define({name:"xml",parser:e.parser.configure({props:[t.indentNodeProp.add({Element(e){let t=/^\s*<\//.test(e.textAfter);return e.lineIndent(e.node.from)+(t?0:e.unit)},"OpenTag CloseTag SelfClosingTag":e=>e.column(e.node.from)+e.unit}),t.foldNodeProp.add({Element(e){let t=e.firstChild,n=e.lastChild;return t&&"OpenTag"==t.name?{from:t.to,to:"CloseTag"==n.name?n.from:e.to}:null}}),t.bracketMatchingHandle.add({"OpenTag CloseTag":e=>e.getChild("TagName")})]}),languageData:{commentTokens:{block:{open:"\x3c!--",close:"--\x3e"}},indentOnInput:/^\s*<\/$/}});function f(e,t,n=e.length){if(!t)return"";let l=t.firstChild,o=l&&l.getChild("TagName");return o?e.sliceString(o.from,Math.min(o.to,n)):""}const g=l.EditorView.inputHandler.of((e,l,o,a,r)=>{if(e.composing||e.state.readOnly||l!=o||">"!=a&&"/"!=a||!p.isActiveAt(e.state,l,-1))return!1;let i=r(),{state:s}=i,m=s.changeByRange(e=>{var l,o,r;let i,{head:m}=e,u=s.doc.sliceString(m-1,m)==a,c=t.syntaxTree(s).resolveInner(m,-1);if(u&&">"==a&&"EndTag"==c.name){let t=c.parent;if("CloseTag"!=(null===(o=null===(l=t.parent)||void 0===l?void 0:l.lastChild)||void 0===o?void 0:o.name)&&(i=f(s.doc,t.parent,m))){return{range:e,changes:{from:m,to:m+(">"===s.doc.sliceString(m,m+1)?1:0),insert:`</${i}>`}}}}else if(u&&"/"==a&&"StartCloseTag"==c.name){let e=c.parent;if(c.from==m-2&&"CloseTag"!=(null===(r=e.lastChild)||void 0===r?void 0:r.name)&&(i=f(s.doc,e,m))){let e=m+(">"===s.doc.sliceString(m,m+1)?1:0),t=`${i}>`;return{range:n.EditorSelection.cursor(m+t.length,-1),changes:{from:m,to:e,insert:t}}}}return{range:e}});return!m.changes.empty&&(e.dispatch([i,s.update(m,{userEvent:"input.complete",scrollIntoView:!0})]),!0)});exports.autoCloseTags=g,exports.completeFromSchema=c,exports.xml=function(e={}){let n=[p.data.of({autocomplete:c(e.elements||[],e.attributes||[])})];return!1!==e.autoCloseTags&&n.push(g),new t.LanguageSupport(p,n)},exports.xmlLanguage=p;