UNPKG

@unocss/inspector

Version:

The inspector UI for UnoCSS

1 lines 6.09 kB
import{A as e,C as t,D as n,E as r,F as i,I as a,L as o,M as s,N as c,O as l,P as u,R as d,S as f,T as p,_ as m,a as h,c as g,d as _,f as v,g as y,h as b,i as x,j as S,k as C,m as w,n as T,o as E,r as D,s as O,t as k,u as A,v as j,w as M,x as N}from"./index-DuJyx2-I.js";var P=/^(?!.*\[[^:]+:.+\]$)((?:.+:)?!?)(.*)$/;function F(e={}){let t=e.prefix??`un-`,n=e.prefixedOnly??!1,r=e.trueToNonValued??!1,i;return{name:`attributify`,match(e,{generator:a}){let o=y(e);if(!o)return;let s=o[1];if(s.startsWith(t))s=s.slice(t.length);else if(n)return;let c=o[2],[,l=``,u=c]=c.match(P)||[];if(u===`~`||r&&u===`true`||!u)return`${l}${s}`;if(i==null){let e=a?.config?.separators?.join(`|`);i=e?RegExp(`^(.*\\](?:${e}))(\\[[^\\]]+?\\])$`):!1}if(i){let[,e,t]=c.match(i)||[];if(t)return`${e}${l}${s}-${t}`}if(l&&/^[\d.]+$/.test(u)){let e=l.split(/([^:]*:)/g).filter(Boolean),t=e.pop()+u,n=e.join(``);return[{matcher:`${l}${s}-${u}`},{matcher:`${n}${s}-${t}`}]}return`${l}${s}-${u}`}}}var I=/(<\w[\w:.$-]*\s)((?:'[^>']*'|"[^>"]*"|`[^>`]*`|\{[^>}]*\}|[^>]*?)*)/g,L=/(\?|(?!\d|-{2}|-\d)[\w\u00A0-\uFFFF-:%]+)(?:=("[^"]*|'[^']*))?/g,R=/[\s'"`;>]+/;function z(e){return{name:`attributify`,extract:({content:t,cursor:n})=>{let r=t.matchAll(I),i,a=0;for(let e of r){let[,t,r]=e,o=e.index+t.length;if(n>o&&n<=o+r.length){a=o,i=r;break}}if(!i)return null;let o=i.matchAll(L),s=0,c,l;for(let e of o){let[t,r,i]=e,o=a+e.index;if(n>o&&n<=o+t.length){s=o,c=r,l=i?.slice(1);break}}if(!c||c===`class`||c===`className`||c===`:class`)return null;let u=!!e?.prefix&&c.startsWith(e.prefix);if(e?.prefixedOnly&&!u)return null;let d=u?c.slice(e.prefix.length):c;if(l===void 0)return{extracted:d,resolveReplacement(t){let n=u?e.prefix.length:0;return{start:s+n,end:s+c.length,replacement:t}}};let f=s+c.length+2,p=R.exec(l),m=0,h;for(;p;){let[e]=p;if(n>f+m&&n<=f+m+p.index){h=l.slice(m,m+p.index);break}m+=p.index+e.length,p=R.exec(l.slice(m))}h===void 0&&(h=l.slice(m));let[,g=``,_]=h.match(P)||[];return{extracted:`${g}${d}-${_}`,transformSuggestions(e){return e.filter(e=>e.startsWith(`${g}${d}-`)).map(e=>g+e.slice(g.length+d.length+1))},resolveReplacement(e){return{start:m+f,end:m+f+h.length,replacement:g+e.slice(g.length+d.length+1)}}}}}}var B=[`v-bind:`,`:`],V=/[\s'"`;]+/g,H=/<[^>\s]*\s((?:'[^']*'|"[^"]*"|`[^`]*`|\{[^}]*\}|=>|[^>]*?)*)/g,U=/(\?|(?!\d|-{2}|-\d)[\w\u00A0-\uFFFF:!%.~<-]+)=?(?:"([^"]*)"|'([^']*)'|\{([^}]*)\})?/g,W=[`placeholder`,`fill`,`opacity`,`stroke-opacity`];function G(e){let t=e?.ignoreAttributes??W,n=e?.nonValuedAttribute??!0,r=e?.trueToNonValued??!1;return{name:`@unocss/preset-attributify/extractor`,extract({code:i}){return Array.from(i.matchAll(H)).flatMap(e=>Array.from((e[1]||``).matchAll(U))).flatMap(([,i,...a])=>{let o=a.filter(Boolean).join(``);if(t.includes(i))return[];for(let e of B)if(i.startsWith(e)){i=i.slice(e.length);break}if(!o){if(m(i)&&n!==!1){let e=[`[${i}=""]`];return r&&e.push(`[${i}="true"]`),e}return[]}return[`class`,`className`].includes(i)?o.split(V).filter(m):H.test(o)?(H.lastIndex=0,this.extract({code:o})):e?.prefixedOnly&&e.prefix&&!i.startsWith(e.prefix)?[]:o.split(V).filter(e=>!!e&&e!==`:`).map(e=>`[${i}~="${e}"]`)})}}}var K=b((e={})=>(e.strict=e.strict??!1,e.prefix=e.prefix??`un-`,e.prefixedOnly=e.prefixedOnly??!1,e.nonValuedAttribute=e.nonValuedAttribute??!0,e.ignoreAttributes=e.ignoreAttributes??W,{name:`@unocss/preset-attributify`,enforce:`post`,variants:[F(e)],extractors:[G(e)],options:e,autocomplete:{extractors:[z(e)]},extractorDefault:e.strict?!1:void 0})),q={key:0,"h-full":``,"of-hidden":``,flex:``,"flex-col":``},J={p:`4`,grid:`~ cols-4 gap-4`},Y={key:0,"row-span-3":``},X={key:0,"h-full":``,"of-hidden":``},Z=C({__name:`ModuleInfo`,props:{id:{}},setup(m){let y=m,{data:b}=g(i(y,`id`)),C=y.id.split(/\./g).pop(),D=u(null),P=h(D,`module-scrolls`);function F(){fetch(`/__open-in-editor?file=${encodeURIComponent(y.id)}`)}let{extractors:I}=K({strict:!0}),L=j(async()=>{let e=new Set;if(I){let t={code:b.value?.code||``};for(let n of I)(await n.extract(t))?.forEach(t=>e.add(t))}return Array.from(e).filter(e=>!e.startsWith(`[`)).filter(e=>!b.value?.matched?.some(({rawSelector:t})=>t===e))},[]),R=u(!1),z=u(`source`),B=E(f(()=>b.value?.css),R);return(i,u)=>{let f=O,m=A,h=v,g=w,y=_,E=x;return a(b)?(e(),r(`div`,q,[l(h,{ref_key:`status`,ref:D,p0:``},{default:S(()=>[t(`div`,J,[t(`div`,null,[u[3]||=t(`div`,{op50:``},` Module `,-1),t(`a`,{"cursor-pointer":``,op80:``,"hover:op100":``,onClick:F},[l(f,{id:a(b).id,"mr-1":``},null,8,[`id`]),u[2]||=t(`div`,{"i-carbon-launch":``},null,-1)])]),t(`div`,null,[u[4]||=t(`div`,{op50:``},` Matched Rules `,-1),n(` `+d(a(b).matched.length),1)]),t(`div`,null,[u[5]||=t(`div`,{op50:``},` CSS Size `,-1),n(` `+d(((a(b)?.gzipSize||0)/1024).toFixed(2))+` KiB `,1),u[6]||=t(`span`,{op50:``},`gzipped`,-1)]),a(L).length?(e(),r(`div`,Y,[u[7]||=t(`div`,{op50:``},` Potentially Unmatched `,-1),t(`code`,null,d(a(L).join(`, `)),1)])):p(``,!0)]),l(m,{modelValue:a(z),"onUpdate:modelValue":u[0]||=e=>c(z)?z.value=e:null},null,8,[`modelValue`])]),_:1},512),a(z)===`source`?(e(),r(`div`,X,[l(a(k),null,{default:S(()=>[l(a(T),{size:`50`},{default:S(()=>[l(g,{"h-full":``,"model-value":a(b).code,"read-only":!0,mode:a(C),matched:a(b).matched?.map(({rawSelector:e})=>e),class:`scrolls module-scrolls`,style:o(a(P))},null,8,[`model-value`,`mode`,`matched`,`style`])]),_:1}),l(a(T),{size:`50`},{default:S(()=>[t(`div`,null,[l(y,{border:`l b gray-400/20`,title:`Output CSS`},{default:S(()=>[t(`label`,null,[s(t(`input`,{"onUpdate:modelValue":u[1]||=e=>c(R)?R.value=e:null,type:`checkbox`},null,512),[[N,a(R)]]),u[8]||=n(` Prettify `,-1)])]),_:1}),l(g,{"h-full":``,border:`l main`,"model-value":a(B),"read-only":!0,mode:`css`,class:`scrolls module-scrolls`,style:o(a(P))},null,8,[`model-value`,`style`])])]),_:1})]),_:1})])):(e(),M(E,{key:1,"flex-grow":``,"overflow-y-auto":``,selectors:a(b).matched,icons:a(b).icons,colors:a(b).colors},null,8,[`selectors`,`icons`,`colors`]))])):p(``,!0)}}}),Q=C({__name:`[id]`,setup(t){let n=D();return(t,r)=>{let i=Z;return e(),M(i,{id:a(n).params.id},null,8,[`id`])}}});export{Q as default};