2 lines
6.4 KiB
JavaScript
2 lines
6.4 KiB
JavaScript
|
|
import{p as I}from"./vendor-lezer-xml-Cc5__j09.js";import{L as F,s as $,c as L,d as _,f as w,l as x}from"./cm-language-CDsY7zq0.js";import{E as M}from"./cm-state-X9WpHEQO.js";import{E as k}from"./cm-view-CiSFjroV.js";import"./vendor-lezer-lr-eZ5kYecM.js";import"./vendor-lezer-common-tVQBIsvN.js";import"./vendor-lezer-highlight-DuEf3ZFH.js";import"./vendor-style-mod-Bs6eFhZE.js";import"./vendor-marijn-find-cluster-break-DXwl3gUT.js";import"./vendor-w3c-keyname-Vcq4gwWv.js";import"./vendor-crelt-C8TCjufn.js";function v(e,t){let i=t&&t.getChild("TagName");return i?e.sliceString(i.from,i.to):""}function O(e,t){let i=t&&t.firstChild;return!i||i.name!="OpenTag"?"":v(e,i)}function D(e,t,i){let n=t&&t.getChildren("Attribute").find(o=>o.from<=i&&o.to>=i),a=n&&n.getChild("AttributeName");return a?e.sliceString(a.from,a.to):""}function N(e){for(let t=e&&e.parent;t;t=t.parent)if(t.name=="Element")return t;return null}function P(e,t){var i;let n=$(e).resolveInner(t,-1),a=null;for(let o=n;!a&&o.parent;o=o.parent)(o.name=="OpenTag"||o.name=="CloseTag"||o.name=="SelfClosingTag"||o.name=="MismatchedCloseTag")&&(a=o);if(a&&(a.to>t||a.lastChild.type.isError)){let o=a.parent;if(n.name=="TagName")return a.name=="CloseTag"||a.name=="MismatchedCloseTag"?{type:"closeTag",from:n.from,context:o}:{type:"openTag",from:n.from,context:N(o)};if(n.name=="AttributeName")return{type:"attrName",from:n.from,context:a};if(n.name=="AttributeValue")return{type:"attrValue",from:n.from,context:a};let s=n==a||n.name=="Attribute"?n.childBefore(t):n;return s?.name=="StartTag"?{type:"openTag",from:t,context:N(o)}:s?.name=="StartCloseTag"&&s.to<=t?{type:"closeTag",from:t,context:o}:s?.name=="Is"?{type:"attrValue",from:t,context:a}:s?{type:"attrName",from:t,context:a}:null}else if(n.name=="StartCloseTag")return{type:"closeTag",from:t,context:n.parent};for(;n.parent&&n.to==t&&!(!((i=n.lastChild)===null||i===void 0)&&i.type.isError);)n=n.parent;return n.name=="Element"||n.name=="Text"||n.name=="Document"?{type:"tag",from:t,context:n.name=="Element"?n:N(n)}:null}class B{constructor(t,i,n){this.attrs=i,this.attrValues=n,this.children=[],this.name=t.name,this.completion=Object.assign(Object.assign({type:"type"},t.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=t.textContent?t.textContent.map(a=>({label:a,type:"text"})):[]}}const E=/^[:\-\.\w\u00b7-\uffff]*$/;function j(e){return Object.assign(Object.assign({type:"property"},e.completion||{}),{label:e.name})}function A(e){return typeof e=="string"?{label:`"${e}"`,type:"constant"}:/^"/.test(e.label)?e:Object.assign(Object.assign({},e),{label:`"${e.label}"`})}function H(e,t){let i=[],n=[],a=Object.create(null);for(let l of t){let p=j(l);i.push(p),l.global&&n.push(p),l.values&&(a[l.name]=l.values.map(A))}let o=[],s=[],h=Object.create(null);for(let l of e){let p=n,u=a;l.attributes&&(p=p.concat(l.attributes.map(r=>typeof r=="string"?i.find(b=>b.label==r)||{label:r,type:"property"}:(r.values&&(u==a&&(u=Object.create(u)),u[r.name]=r.values.map(A)),j(r)))));let g=new B(l,p,u);h[g.name]=g,o.push(g),l.top&&s.push(g)}s.length||(s=o);for(let l=0;l<o.length;l++){let p=e[l],u=o[l];if(p.children)for(let g of p.children)h[g]&&u.children.push(h[g]);else u.children=o}return l=>{var p;let{doc:u}=l.state,g=P(l.state,l.pos);if(!g||g.type=="tag"&&!l.explicit)return null;let{type:r,from:b,context:c}=g;if(r=="openTag"){let m=s,f=O(u,c);if(f){let d=h[f];m=d?.children||o}return{from:b,options:m.map(d=>d.completion),validFor:E}}else if(r=="closeTag"){let m=O(u,c);return m?{from:b,to:l.pos+(u.sliceString(l.pos,l.pos+1)==">"?1:0),options:[((p=h[m])===null||p===void 0?void 0:p.closeNameCompletion)||{label:m+">",type:"type"}],validFor:E}:null}else if(r=="attrName"){let m=h[v(u,c)];return{from:b,options:m?.attrs||n,validFor:E}}else if(r=="attrValue"){let m=D(u,c,b);if(!
|