astro-ghostcms/.pnpm-store/v3/files/ef/5e2ccff7cbd4cfcc68026afb11a...

32 lines
10 KiB
Plaintext

import{walkSync as yr,ELEMENT_NODE as er,TEXT_NODE as Pr,render as Ur}from"../index.js";import{matches as zr}from"../selector.js";var j="comm",F="rule",K="decl";var or="@import";var ar="@keyframes";var cr=Math.abs,$=String.fromCharCode;function V(r){return r.trim()}function P(r,e,t){return r.replace(e,t)}function ir(r,e){return r.indexOf(e)}function O(r,e){return r.charCodeAt(e)|0}function k(r,e,t){return r.slice(e,t)}function g(r){return r.length}function C(r){return r.length}function N(r,e){return e.push(r),r}var W=1,M=1,ur=0,x=0,f=0,R="";function Y(r,e,t,n,s,a,c){return{value:r,root:e,parent:t,type:n,props:s,children:a,line:W,column:M,length:c,return:""}}function fr(){return f}function pr(){return f=x>0?O(R,--x):0,M--,f===10&&(M=1,W--),f}function w(){return f=x<ur?O(R,x++):0,M++,f===10&&(M=1,W++),f}function I(){return O(R,x)}function U(){return x}function B(r,e){return k(R,r,e)}function X(r){switch(r){case 0:case 9:case 10:case 13:case 32:return 5;case 33:case 43:case 44:case 47:case 62:case 64:case 126:case 59:case 123:case 125:return 4;case 58:return 3;case 34:case 39:case 40:case 91:return 2;case 41:case 93:return 1}return 0}function lr(r){return W=M=1,ur=g(R=r),x=0,[]}function hr(r){return R="",r}function G(r){return V(B(x-1,J(r===91?r+2:r===40?r+1:r)))}function mr(r){for(;(f=I())&&f<33;)w();return X(r)>2||X(f)>3?"":" "}function gr(r,e){for(;--e&&w()&&!(f<48||f>102||f>57&&f<65||f>70&&f<97););return B(r,U()+(e<6&&I()==32&&w()==32))}function J(r){for(;w();)switch(f){case r:return x;case 34:case 39:r!==34&&r!==39&&J(f);break;case 40:r===41&&J(r);break;case 92:w();break}return x}function xr(r,e){for(;w()&&r+f!==47+10;)if(r+f===42+42&&I()===47)break;return"/*"+B(e,x-1)+"*"+$(r===47?r:w())}function wr(r){for(;!X(I());)w();return B(r,x)}function Q(r){return hr(Z("",null,null,null,[""],r=lr(r),0,[0],r))}function Z(r,e,t,n,s,a,c,o,i){for(var h=0,l=0,p=c,S=0,y=0,v=0,b=1,_=1,d=1,m=0,A="",D=s,T=a,E=n,u=A;_;)switch(v=m,m=w()){case 40:if(v!=108&&O(u,p-1)==58){ir(u+=P(G(m),"&","&\f"),"&\f")!=-1&&(d=-1);break}case 34:case 39:case 91:u+=G(m);break;case 9:case 10:case 13:case 32:u+=mr(v);break;case 92:u+=gr(U()-1,7);continue;case 47:switch(I()){case 42:case 47:N(Ar(xr(w(),U()),e,t),i);break;default:u+="/"}break;case 123*b:o[h++]=g(u)*d;case 125*b:case 59:case 0:switch(m){case 0:case 125:_=0;case 59+l:y>0&&g(u)-p&&N(y>32?dr(u+";",n,t,p-1):dr(P(u," ","")+";",n,t,p-2),i);break;case 59:u+=";";default:if(N(E=br(u,e,t,h,l,s,o,A,D=[],T=[],p),a),m===123)if(l===0)Z(u,e,E,E,D,a,p,o,T);else switch(S){case 100:case 109:case 115:Z(r,E,E,n&&N(br(r,E,E,0,0,s,o,A,s,D=[],p),T),s,T,p,o,n?D:T);break;default:Z(u,E,E,E,[""],T,0,o,T)}}h=l=y=0,b=d=1,A=u="",p=c;break;case 58:p=1+g(u),y=v;default:if(b<1){if(m==123)--b;else if(m==125&&b++==0&&pr()==125)continue}switch(u+=$(m),m*b){case 38:d=l>0?1:(u+="\f",-1);break;case 44:o[h++]=(g(u)-1)*d,d=1;break;case 64:I()===45&&(u+=G(w())),S=I(),l=p=g(A=u+=wr(U())),m++;break;case 45:v===45&&g(u)==2&&(b=0)}}return a}function br(r,e,t,n,s,a,c,o,i,h,l){for(var p=s-1,S=s===0?a:[""],y=C(S),v=0,b=0,_=0;v<n;++v)for(var d=0,m=k(r,p+1,p=cr(b=c[v])),A=r;d<y;++d)(A=V(b>0?S[d]+" "+m:P(m,/&\f/g,S[d])))&&(i[_++]=A);return Y(r,e,t,s===0?F:o,i,h,l)}function Ar(r,e,t){return Y(r,e,t,j,$(fr()),k(r,2,-2),0)}function dr(r,e,t,n){return Y(r,e,t,K,k(r,0,n),k(r,n+1,-1),n)}function z(r,e){for(var t="",n=C(r),s=0;s<n;s++)t+=e(r[s],s,r,e)||"";return t}function Er(r,e,t,n){switch(r.type){case or:case K:return r.return=r.return||r.value;case j:return"";case ar:return r.return=r.value+"{"+z(r.children,n)+"}";case F:r.value=r.props.join(",")}return g(t=z(r.children,n))?r.return=r.value+"{"+t+"}":""}function rr(r){var e=C(r);return function(t,n,s,a){for(var c="",o=0;o<e;o++)c+=r[o](t,n,s,a)||"";return c}}var H={attribute:/\[\s*(?:(?<namespace>\*|[-\w\P{ASCII}]*)\|)?(?<name>[-\w\P{ASCII}]+)\s*(?:(?<operator>\W?=)\s*(?<value>.+?)\s*(\s(?<caseSensitive>[iIsS]))?\s*)?\]/gu,id:/#(?<name>[-\w\P{ASCII}]+)/gu,class:/\.(?<name>[-\w\P{ASCII}]+)/gu,comma:/\s*,\s*/g,combinator:/\s*[\s>+~]\s*/g,"pseudo-element":/::(?<name>[-\w\P{ASCII}]+)(?:\((?<argument>¶*)\))?/gu,"pseudo-class":/:(?<name>[-\w\P{ASCII}]+)(?:\((?<argument>¶*)\))?/gu,universal:/(?:(?<namespace>\*|[-\w\P{ASCII}]*)\|)?\*/gu,type:/(?:(?<namespace>\*|[-\w\P{ASCII}]*)\|)?(?<name>[-\w\P{ASCII}]+)/gu},kr=new Set(["combinator","comma"]),Ir=new Set(["not","is","where","has","matches","-moz-any","-webkit-any","nth-child","nth-last-child"]),Sr=/(?<index>[\dn+-]+)\s+of\s+(?<subtree>.+)/,Tr={"nth-child":Sr,"nth-last-child":Sr},Or=r=>{switch(r){case"pseudo-element":case"pseudo-class":return new RegExp(H[r].source.replace("(?<argument>\xB6*)","(?<argument>.*)"),"gu");default:return H[r]}};function Cr(r,e){let t=0,n="";for(;e<r.length;e++){let s=r[e];switch(s){case"(":++t;break;case")":--t}if(n+=s,t===0)return n}return n}function Nr(r,e=H){if(!r)return[];let t=[r];for(let[s,a]of Object.entries(e))for(let c=0;c<t.length;c++){let o=t[c];if(typeof o!="string")continue;a.lastIndex=0;let i=a.exec(o);if(!i)continue;let h=i.index-1,l=[],p=i[0],S=o.slice(0,h+1);S&&l.push(S),l.push({...i.groups,type:s,content:p});let y=o.slice(h+p.length+1);y&&l.push(y),t.splice(c,1,...l)}let n=0;for(let s of t)switch(typeof s){case"string":throw new Error(`Unexpected sequence ${s} found at index ${n}`);case"object":n+=s.content.length,s.pos=[n-s.content.length,n],kr.has(s.type)&&(s.content=s.content.trim()||" ")}return t}var Mr=/(['"])([^\\\n]+?)\1/g,Rr=/\\./g;function $r(r,e=H){if((r=r.trim())==="")return[];let t=[];r=(r=r.replace(Rr,(a,c)=>(t.push({value:a,offset:c}),"\uE000".repeat(a.length)))).replace(Mr,(a,c,o,i)=>(t.push({value:a,offset:i}),`${c}${"\uE001".repeat(o.length)}${c}`));{let a,c=0;for(;(a=r.indexOf("(",c))>-1;){let o=Cr(r,a);t.push({value:o,offset:a}),r=`${r.substring(0,a)}(${"\xB6".repeat(o.length-2)})${r.substring(a+o.length)}`,c=a+o.length}}let n=Nr(r,e),s=new Set;for(let a of t.reverse())for(let c of n){let{offset:o,value:i}=a;if(!(c.pos[0]<=o&&o+i.length<=c.pos[1]))continue;let{content:h}=c,l=o-c.pos[0];c.content=h.slice(0,l)+i+h.slice(l+i.length),c.content!==h&&s.add(c)}for(let a of s){let c=Or(a.type);if(!c)throw new Error(`Unknown token type: ${a.type}`);c.lastIndex=0;let o=c.exec(a.content);if(!o)throw new Error(`Unable to parse content for ${a.type}: ${a.content}`);Object.assign(a,o.groups)}return n}function L(r,{list:e=!0}={}){if(e&&r.find(t=>t.type==="comma")){let t=[],n=[];for(let s=0;s<r.length;s++)if(r[s].type==="comma"){if(n.length===0)throw new Error("Incorrect comma at "+s);t.push(L(n,{list:!1})),n.length=0}else n.push(r[s]);if(n.length===0)throw new Error("Trailing comma");return t.push(L(n,{list:!1})),{type:"list",list:t}}for(let t=r.length-1;t>=0;t--){let n=r[t];if(n.type==="combinator"){let s=r.slice(0,t),a=r.slice(t+1);return{type:"complex",combinator:n.content,left:L(s),right:L(a)}}}switch(r.length){case 0:throw new Error("Could not build AST.");case 1:return r[0];default:return{type:"compound",list:[...r]}}}function*q(r,e){switch(r.type){case"list":for(let t of r.list)yield*q(t,r);break;case"complex":yield*q(r.left,r),yield*q(r.right,r);break;case"compound":yield*r.list.map(t=>[t,r]);break;default:yield[r,e]}}function tr(r,{recursive:e=!0,list:t=!0}={}){let n=$r(r);if(!n)return;let s=L(n,{list:t});if(!e)return s;for(let[a]of q(s)){if(a.type!=="pseudo-class"||!a.argument||!Ir.has(a.name))continue;let c=a.argument,o=Tr[a.name];if(o){let i=o.exec(c);if(!i)continue;Object.assign(a,i.groups),c=i.groups.subtree}c&&Object.assign(a,{subtree:tr(c,{recursive:!0,list:!0})})}return s}function Lr(r={}){return async e=>{let t=r.hash??Wr(await Ur(e)),n=[],s=!1,a=new Set,c=new Set;yr(e,o=>{if(o.type===er&&o.name==="style"&&(!r.attribute||Dr(o,r.attribute))){s=!0,r.attribute&&delete o.attributes[r.attribute];for(let i of Kr(o.children[0].value))a.add(i)}o.type===er&&c.add(o)}),s&&yr(e,o=>{o.type===er&&(n.push(()=>jr(o,t,a)),o.name==="style"&&n.push(()=>{o.children=o.children.map(i=>(i.type!==Pr||(i.value=Fr(i.value,t),i.value===""&&(o.parent.children=o.parent.children.filter(h=>h!==o))),i))}))});for(let o of n)o();return e}}var _r=new Set(["base","font","frame","frameset","head","link","meta","noframes","noscript","script","style","title"]);function Dr(r,e){return e in r.attributes?r.attributes[e]!=="false":!1}function jr(r,e,t){let{name:n}=r;if(!!n&&!(n.length<1)&&!_r.has(n)&&!r.attributes["data-scope"]){for(let s of t)if(zr(r,s)){r.attributes["data-scope"]=e;return}}}function vr(r,e){let t=tr(r),n=s=>{switch(s.type){case"pseudo-class":return s.name==="root"?s.content:s.name==="global"?s.argument:`${s.content}:where([data-scope="${e}"])`;case"compound":return`${r}:where([data-scope="${e}"])`;case"complex":{let{left:a,right:c,combinator:o}=s;return`${n(a)}${o}${n(c)}`}case"list":return s.list.map(a=>n(a)).join(" ");default:return`${s.content}:where([data-scope="${e}"])`}};return n(t)}function Fr(r,e){return z(Q(r),rr([t=>{t.type==="rule"&&(Array.isArray(t.props)?t.props=t.props.map(n=>vr(n,e)):t.props=vr(t.props,e))},Er]))}function Kr(r){let e=new Set;return z(Q(r),rr([t=>{if(t.type==="rule")if(Array.isArray(t.props))for(let n of t.props)e.add(n);else e.add(t.props)}])),Array.from(e)}var sr="0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXY",nr=sr.length;function Vr(r){let e=0;if(r.length===0)return e;for(let t=0;t<r.length;t++){let n=r.charCodeAt(t);e=(e<<5)-e+n,e=e&e}return e}function Wr(r){let e,t="",n=Vr(r),s=n<0?"Z":"";for(n=Math.abs(n);n>=nr;)e=n%nr,n=Math.floor(n/nr),t=sr[e]+t;return n>0&&(t=sr[n]+t),s+t}export{Lr as default};
/**
* shorthash - https://github.com/bibig/node-shorthash
*
* @license
*
* (The MIT License)
*
* Copyright (c) 2013 Bibig <bibig@me.com>
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
*/