/*! css-doodle v0.39.0 MIT licensed */ !function(){"use strict";const e=[":",";",",","(",")","[","]","{","}","\u03c0","\xb1","+","-","*","/","%",'"',"'","`","@","=","^"],t={escape:e=>"\\"==e,space:e=>/[\r\n\t\s]/.test(e),digit:e=>/^[0-9]$/.test(e),sign:e=>/^[+-]$/.test(e),dot:e=>"."==e,quote:e=>/^["'`]$/.test(e),symbol:t=>e.includes(t),hexNum:e=>/^[0-9a-f]$/i.test(e),hex:(e,n,r)=>"0"==e&&t.letter(n,"x")&&t.hexNum(r),expWithSign:(e,n,r)=>t.letter(e,"e")&&t.sign(n)&&t.digit(r),exp:(e,n)=>t.letter(e,"e")&&t.digit(n),dots:(e,n)=>t.dot(e)&&t.dot(n),letter:(e,t)=>String(e).toLowerCase()==String(t).toLowerCase(),comment:(e,t)=>"/"==e&&"*"==t,inlineComment:(e,t)=>"/"==e&&"/"===t,selfClosedTag:(e,t)=>"/"==e&&">"==t,closedTag:(e,t)=>"<"==e&&"/"==t};class n{constructor({type:e,value:t,pos:n,status:r}){this.type=e,this.value=t,this.pos=n,r&&(this.status=r)}isSymbol(...e){let t="Symbol"==this.type;return e.length?e.some((e=>e===this.value)):t}isSpace(){return"Space"==this.type}isNumber(){return"Number"==this.type}isWord(){return"Word"==this.type}}function r(e){let t=-1,n=e.length,r=-1,s=0;return{curr:(n=0)=>e[t+n],next(n=1){let i=e[t+=n];return"\n"===i?(s++,r=0):r+=n,i},end:()=>t>=n,get:()=>({prev:e[t-1],curr:e[t+0],next:e[t+1],next2:e[t+2],next3:e[t+3],pos:[r,s]})}}function s(e){for(;e.next();){let{curr:n,prev:r}=e.get();if(t.comment(n,r))break}}function i(e){for(;e.next()&&"\n"!==e.curr(););}function l(e){return[":",";",",","{","}","(",")","[","]"].includes(e)}function o(e){let n="";for(;!e.end();){let{curr:r,next:s}=e.get();n+=r;let i=t.symbol(s)||t.space(s)||t.digit(s);if(n.length&&i&&!t.closedTag(r,s))break;e.next()}return n.trim()}function a(e){let n="";for(;!e.end();){let{curr:r,next:s}=e.get();if(n+=r,!t.space(s))break;e.next()}return n}function u(e){let n="",r=!1;for(;!e.end();){let{curr:s,next:i,next2:l,next3:o}=e.get();if(n+=s,r&&t.dot(i))break;if(t.dot(s)&&(r=!0),t.dots(i,l))break;if(t.expWithSign(i,l,o))n+=e.next()+e.next();else if(t.exp(i,l))n+=e.next();else if(!t.digit(i)&&!t.dot(i))break;e.next()}return n}function c(e){let n="0x";for(e.next(2);!e.end();){let{curr:r,next:s}=e.get();if(n+=r,!t.hexNum(s))break;e.next()}return n}function h(e){return e[e.length-1]}function p(e,p={}){let f=r(String(e).trim()),d=[],m=[];for(;f.next();){let{prev:e,curr:r,next:g,next2:v,pos:y}=f.get();if(t.comment(r,g))s(f);else if(p.ignoreInlineComment&&t.inlineComment(r,g))i(f);else if(t.hex(r,g,v)){let e=c(f);d.push(new n({type:"Number",value:e,pos:y}))}else if(t.digit(r)||t.digit(g)&&t.dot(r)&&!t.dots(e,r)){let e=u(f);d.push(new n({type:"Number",value:e,pos:y}))}else if(t.symbol(r)&&!t.selfClosedTag(r,g)){let e=h(d),s=t.digit(g)||t.dot(g)&&t.digit(v);if("-"===r&&s&&(!e||!e.isNumber())){let e=u(f);d.push(new n({type:"Number",value:e,pos:y}));continue}let i={type:"Symbol",value:r,pos:y};if(m.length&&t.escape(e.value)){d.pop();let e=o(f);e.length&&d.push(new n({type:"Word",value:e,pos:y}))}else{if(t.quote(r)){h(m)==r?(m.pop(),i.status="close"):(m.push(r),i.status="open")}d.push(new n(i))}}else if(t.space(r)){let e=a(f),t=h(d),{next:s}=f.get();if(!m.length&&t){let n=t.value,i=l(n)&&")"!==n,o=l(s)&&"("!==s;if(i||o)continue;e=p.preserveLineBreak?r:" "}d.length&&s&&s.trim()&&d.push(new n({type:"Space",value:e,pos:y}))}else{let e=o(f);e.length&&d.push(new n({type:"Word",value:e,pos:y}))}}let g=h(d);return g&&g.isSpace()&&(d.length=d.length-1),d}function f(e){let t=[];for(;e.next();){let{curr:n,next:r}=e.get();if("var"===n.value){if(r&&r.isSymbol("(")){e.next();let n=d(e);g(n.name)&&t.push(n)}}else if(t.length&&!n.isSymbol(","))break}return t}function d(e){let t={},n=[];for(;e.next();){let{curr:r,next:s}=e.get();if(r.isSymbol(")",";")&&!t.name){t.name=m(n);break}r.isSymbol(",")?(void 0===t.name&&(t.name=m(n),n=[]),t.name&&(t.fallback=f(e))):n.push(r)}return t}function m(e){return e.map((e=>e.value)).join("")}function g(e){return void 0!==e&&(!(e.length<=2)&&(!e.substr(2).startsWith("-")&&!!e.startsWith("--")))}function v(e,t,n){return e=Number(e)||0,Math.max(t,Math.min(n,e))}function y(e,t){for(let[n,r]of Object.entries(t))e[n]=e[r];return e}function b(e){return/^[a-zA-Z]$/.test(e)}function x(e){return null==e}function _(e){return x(e)||Number.isNaN(e)}function $(e){return x(e)||""===e}function w(e){let t=t=>(...n)=>e(t,...n);return t.lazy=!0,t}function k(e,t,n){return"c-"+e+"-"+t+"-"+n}function S(e){let t=e;for(;t&&!x(t.value);)t=t.value;return t??""}function j(e,t,n=0){let r=new Image;r.crossOrigin="anonymous",r.src=e,r.onload=function(){setTimeout(t,n)}}function A(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function N(e){let t=document.createElement("textarea");return t.innerHTML=e,t.value}function E(e,t=0){let n=3735928559^t,r=1103547991^t;for(let t,s=0;s>>16,2246822507)^Math.imul(r^r>>>13,3266489909),r=Math.imul(r^r>>>16,2246822507)^Math.imul(n^n>>>13,3266489909),4294967296*(2097151&r)+(n>>>0)}function R(e,t,n){return t+e*(n-t)}function T(e=""){return e+Math.random().toString(32).substr(2)}function z(e){return x(e)?[]:Array.isArray(e)?e:[e]}function P(e,t="\n"){return(e||[]).join(t)}function C(e,t=1){return x(e)?"":e[e.length-t]}function M(e){return e[0]}function O(e,t={symbol:",",noSpace:!1,verbose:!1}){let n=[],s=[],i=[],l=[],o="";if($(e))return n;let a=r(p(e));function u(e){let n=t.symbol||[","];return Array.isArray(n)||(n=[n]),t.noSpace?e.isSymbol(...n):e.isSymbol(...n)||e.isSpace()}function c(e){let r=function(e){return e.map((e=>e.value)).join("")}(e);t.verbose?(o.length||r.length)&&n.push({group:o,value:r}):n.push(r)}for(;a.next();){let{prev:e,curr:n,next:r}=a.get();n.isSymbol("(")&&i.push(n.value),n.isSymbol(")")&&i.pop(),"open"===n.status&&l.push(n.value),"close"===n.status&&l.pop();let h=!i.length&&!l.length;if(h){let s=t.noSpace&&n.isSpace()&&u(r),i=t.noSpace&&n.isSpace()&&u(e);if(s||i)continue}h&&u(n)?(c(s),o=n.value,s=[]):s.push(n)}return s.length&&c(s),n}function I(e,t){let n,r=[],s=[],i=[],l=!1;for(;e.next();){let{curr:t,next:o}=e.get();t.isSymbol("(")&&!s.length?i.push(t):t.isSymbol(")")&&!s.length&&i.pop(),t.isSymbol("'",'"')&&("open"===t.status?s.push(t):s.pop());let a=!s.length&&!i.length&&(!o||t.isSymbol(";")||o.isSymbol("}"));if(t.isSymbol("'",'"')&&o&&o.isSymbol("}")&&!s.length&&(a=!0),!i.length&&!s.length&&t.isSymbol("{")){let t=X(r);if(!t.length)continue;let s=t.pop(),i=Y(...t,s);for(n=U(L(e,H(s,{type:"block",name:s,value:[]})),i);s=t.pop();)n=U(H(s,{type:"block",name:s,value:[n]}),i);l=!0;break}if(r.push(t),a)break}return r.length&&!n?(t._valueTokens=r,t.value=B(r)):n&&(t.value=n),l&&(t.value.inline=!0),t.origin&&(t.origin.value=t.value),t}function W(e){let t=[],n=[];for(;e.next();){let{curr:r}=e.get();if(r.isSymbol("{"))t.push(r.value);else if(r.isSymbol("}")){if(!t.length)break;t.pop()}n.push(r.value)}return n.join("")}function L(e,t){let n=[],r=[],s=t&&t.type||"",i=[];for(;e.next();){let{prev:l,curr:o,next:a}=e.get();o.isSymbol("(")&&i.push(o.value),o.isSymbol(")")&&i.pop();let u=!a||o.isSymbol("}");if(G(s)&&u){if(!a&&n.length&&!o.isSymbol("}")){"string"==typeof n[n.length-1].value&&(n[n.length-1].value+=";"+o.value)}t.value=n;break}if(o.isSymbol("{")){let s=X(r);if(!s.length)continue;Y(t.name)&&(s=[B(r)]);let i=s.pop(),l=Y(...s,t.name,i);if("style"===i)n.push({type:"block",name:i,value:W(e)});else{let t=U(L(e,H(i,{type:"block",name:i,value:[]})),l);for(;i=s.pop();)t=U(H(i,{type:"block",name:i,value:[t]}),l);n.push(t)}r=[]}else if(o.isSymbol(":")&&!i.length&&!D(l,a)&&r.length){let i=F(r,(e=>e.isSymbol(","))),l={type:"statement",name:"unkown",value:""};i.length>1&&(l.origin={name:i});let o=I(e,l),a=O(o.value),u=i.length>1&&a.length===i.length;i.forEach(((e,t)=>{let r=Object.assign({},o,{name:e});/^\-\-/.test(e)&&(r.variable=!0),u&&(r.value=a[t]),/viewBox/i.test(e)&&(r.detail=q(r.value,r._valueTokens)),delete r._valueTokens,n.push(r)})),G(s)&&(t.value=n),r=[]}else o.isSymbol(";")?n.length&&r.length&&(n[n.length-1].value+=";"+B(r),r=[]):r.push(o)}return n.length&&G(s)&&(t.value=n),s?t:n}function D(e,t){let n=e&&e.value,r=t&&t.value;return["xlink:actuate","xlink:arcrole","xlink:href","xlink:role","xlink:show","xlink:title","xlink:type","xml:base","xml:lang","xml:space"].includes(n+":"+r)}function B(e){return e.filter(((t,n)=>!t.isSymbol(";","}")||n!==e.length-1)).map((e=>e.value)).join("")}function U(e,t){let n=e.name||"",[r,...s]=n.split(/#/),i=s[s.length-1];return r&&i&&!t&&(e.name=r,e.value.push({type:"statement",name:"id",value:i})),e}function F(e,t){let n=[],r=[];return e.forEach((e=>{t(e)?(n.push(B(r)),r=[]):r.push(e)})),r.length&&n.push(B(r)),n}function X(e){let t,n=[],s=r(e);for(;s.next();){let{prev:e,curr:r,next:i}=s.get(),l=e&&i&&"x"===r.value&&e.isNumber()&&i.isNumber();!r.isWord()||t||l?n[n.length-1]=(n[n.length-1]+r.value).trim():n.push(r.value.trim()),r.isSymbol()?t=!0:r.isSpace()||(t=!1)}return n}function q(e,t){const n={value:[]};let r;if(!Array.isArray(t))return n;for(let e of t)e.isSpace()||e.isSymbol(",",";")||(n.value.length<4&&e.isNumber()?n.value.push(Number(e.value)):e.isNumber()&&r?(n[r]=Number(e.value),r=null):e.isWord()&&(r=e.value));return n}function H(e,t){let n=Object.assign({},t);if(/\*\s*[0-9]/.test(e)){let[t,r]=e.split("*");r&&(n.times=r.trim(),n.pureName=t.trim())}return n}function Y(...e){return e.some((e=>"style"===e))}function G(e){return"block"===e}function V(e,t){return function(e){let t,n=[];for(let r of e.value)"svg"===r.name&&(t=r),r.variable&&n.push(r);if(t&&Array.isArray(t.value)){for(let e of n)t.value.find((t=>t.name==e.name))||t.value.unshift(e);return t}return e}(L(r(p(e)),t||{type:"block",name:"svg",value:[]}))}function Z(e,t){let n="";if("block"===e.type){let t=Array.isArray(e.value)&&e.value[0]&&e.value[0].inline;if(e.times?n+="@M"+e.times+"("+e.pureName+"{":n+=e.name+"{","style"===e.name)n+=e.value;else if(Array.isArray(e.value)&&e.value.length){let t="";for(let r of e.value)n+=Z(r,t),r.origin&&(t=r.origin.name.join(","))}e.times?n+="})":t||(n+="}")}else if("statement"===e.type){let r=e.origin&&t===e.origin.name.join(","),s=e.origin?e.origin.name.join(","):e.name,i=e.origin?e.origin.value:e.value;r||(n+=i&&i.type?s+":"+Z(i):s+":"+i+";")}return n}function K(e){return Z(e).trim()}const J={func:(e="")=>({type:"func",name:e,arguments:[]}),argument:()=>({type:"argument",value:[]}),text:(e="")=>({type:"text",value:e}),pseudo:(e="")=>({type:"pseudo",selector:e,styles:[]}),cond:(e="")=>({type:"cond",name:e,styles:[],arguments:[]}),rule:(e="")=>({type:"rule",property:e,value:[]}),keyframes:(e="")=>({type:"keyframes",name:e,steps:[]}),step:(e="")=>({type:"step",name:e,styles:[]})},Q={white_space:e=>/[\s\n\t]/.test(e),line_break:e=>/\n/.test(e),number:e=>!isNaN(e),pair:e=>['"',"(",")","'"].includes(e),pair_of:(e,t)=>({'"':'"',"'":"'","(":")"}[e]==t)},ee={\u03c0:Math.PI,"\u220f":Math.PI};function te(e){return/^@(canvas|shaders|doodle)/.test(e)}function ne(e=""){let t=0,n=1,r=1;return{curr:(n=0)=>e[t+n],end:()=>e.length<=t,info:()=>({index:t,col:n,line:r}),index:e=>void 0===e?t:t=e,range:(t,n)=>e.substring(t,n),next(){let s=e[t++];return"\n"==s?(r++,n=0):n++,s}}}function re(e,{col:t,line:n}){console.warn(`(at line ${n}, column ${t}) ${e}`)}function se(e){return function(t,n){let r=t.index(),s="";for(;!t.end();){let n=t.next();if(e(n))break;s+=n}return n&&t.index(r),s}}function ie(e,t){return se((e=>/[^\w@]/.test(e)))(e,t)}function le(e){return se((e=>/[\s\{]/.test(e)))(e)}function oe(e,t){return se((e=>Q.line_break(e)||"{"==e))(e,t)}function ae(e,t){let n,r=J.step();for(;!e.end()&&"}"!=(n=e.curr());)if(Q.white_space(n))e.next();else{if(r.name.length){if(r.styles.push(ke(e,t)),"}"==e.curr())break}else r.name=xe(e,(e=>"{"===e));e.next()}return r}function ue(e,t){const n=[];let r;for(;!e.end()&&"}"!=(r=e.curr());)Q.white_space(r)||n.push(ae(e,t)),e.next();return n}function ce(e,t){let n,r=J.keyframes();for(;!e.end()&&"}"!=(n=e.curr());)if(r.name.length){if("{"==n||"{"==e.curr(-1)){e.next(),r.steps=ue(e,t);break}e.next()}else if(ie(e),r.name=le(e),!r.name.length){re("missing keyframes name",e.info());break}return r}function he(e,t={}){for(e.next();!e.end();){let n=e.curr();if(t.inline){if("\n"==n)break}else if("*"==(n=e.curr())&&"/"==e.curr(1))break;e.next()}t.inline||(e.next(),e.next())}function pe(e){for(e.next();!e.end();){if(">"==e.curr())break;e.next()}}function fe(e){let t,n="";for(;!e.end()&&":"!=(t=e.curr());)Q.white_space(t)||(n+=t),e.next();return n}function de(e,t,n,r={}){let s,i=[],l=[],o=[],a="",u="";for(;!e.end();){s=e.curr();let h=e.curr(-1),p=e.index();if(/[\('"`]/.test(s)&&"\\"!==h)o.length&&"("!==s&&s===C(o)?o.pop():o.push(s),a+=s;else if(!n&&("@"==s||"$"===s||"."===h&&t))l.length||(a=a.trimLeft()),a.length&&(l.push(J.text(a)),a=""),l.push(be(e,r));else if(n&&/[)]/.test(s)||!n&&/[,)]/.test(s))if(o.length)")"==s&&"("===C(o)&&o.pop(),a+=s;else{if(a.length&&(l.length?/\S/.test(a)&&l.push(J.text(a)):l.push(J.text((c=a).trim().length?Q.number(+c)?+c:c.trim():c)),a.startsWith("\xb1")&&!n)){let e=a.substr(1),t=structuredClone(l);C(t).value="-"+e,i.push(ge(t)),C(l).value=e}if(i.push(ge(l)),[l,a]=[[],""],")"==s)break}else ee[s]&&!/[0-9]/.test(e.curr(-1))&&(s=ee[s]),a+=s;if(!(!t||")"!=e.curr(1)&&";"!=e.curr(1)&&/[0-9a-zA-Z_\-.]/.test(e.curr())||o.length)){l.length&&i.push(ge(l));break}u+=e.range(p,e.index()+1),e.next()}var c;return[me(i),u]}function me(e){let t=C(e[0]);return t&&"text"===t.type&&!String(t.value).trim().length&&(e[0]=e[0].slice(0,-1)),e}function ge(e){let t=e.map((e=>{if("text"==e.type&&"string"==typeof e.value){let t=String(e.value);t.includes("`")&&(e.value=t=t.replace(/`/g,'"')),e.value=t}return e})),n=M(t)||{},r=C(t)||{};if("text"==n.type&&"text"==r.type){let e=M(n.value),s=C(r.value);"string"==typeof n.value&&"string"==typeof r.value&&Q.pair_of(e,s)&&(n.value=n.value.slice(1),r.value=r.value.slice(0,r.value.length-1),t.cluster=!0)}return t}function ve(e){let t=JSON.stringify(e);return t.includes("pureName")&&t.includes("times")}function ye(e){return/^@svg$/i.test(e)}function be(e,t={}){let n,r=J.func(),s=e.curr(),i=!1,l="$"===s;for("@"===s?e.next():s="@";!e.end();){n=e.curr();let l=e.curr(1),o="."==n&&/[a-zA-Z@$]/.test(l);if("("==n||o){i=!0,e.next();let[n,l]=de(e,o,te(s),t);if(ye(s)){let e=V(l),r=0;for(let n of e.value)n.variable&&(t[n.name]=Ee(`${"\n".repeat(r++)} ${n.name}:${n.value}`)[0].value);if(/\d\s*{/.test(l)&&ve(e)){let r=K(e);r+=")",n=de(ne(r),o,te(s),t)[0]}}r.arguments=n,r.variables=t;break}if(/[0-9a-zA-Z_\-.%]/.test(n)&&(s+=n),!i&&"("!==l&&!/[0-9a-zA-Z_\-.%]/.test(l))break;e.next()}let{fname:o,extra:a}=function(e){let t="",n="";if(/\D$/.test(e)&&!/\d+[x-]\d+/.test(e)||Math[e.substr(1)])return{fname:e,extra:n};for(let r=e.length-1;r>=0;r--){let s=e[r],i=e[r-1],l=e[r+1];if(!(/[\d.]/.test(s)||("x"==s||"-"==s)&&/\d/.test(i)&&/\d/.test(l))){t=e.substring(0,r+1);break}n=s+n}return{fname:t,extra:n}}(s);if(r.name=l?"@$"+s.substr(1):o,a.length&&r.arguments.unshift([{type:"text",value:a}]),l&&r.name.length>2){if(!r.arguments.length){let e=r.name.substring(0,2),t=r.name.substring(2);r.name=e,r.arguments.push([{type:"text",value:t}])}if(/\d$/.test(r.name)){let e=r.name.substring(0,2),t=r.name.substring(2);r.name=e,r.arguments[0][0].value=t}}return r.position=e.info().index,r}function xe(e,t=(()=>{})){let n,r=J.text(),s=0,i=!0;const l=[];l[s]=[];let o=[],a=[];for(;!e.end();){if(n=e.curr(),i&&Q.white_space(n)){e.next();continue}if(i=!1,"\n"!=n||Q.white_space(e.curr(-1)))if(","!=n||o.length){if((/[;}<]/.test(n)||t(n))&&!a.length){r.value.length&&(l[s].push(r),r=J.text());break}if("@"!==n&&"$"!==n||!/[\w-\(%]/.test(e.curr(1)))if('"'===n||"'"===n){n===C(a)?a.pop():a.length||a.push(n),r.value+=n}else Q.white_space(n)&&Q.white_space(e.curr(-1))||("("==n&&o.push(n),")"==n&&o.pop(),ee[n]&&!/[0-9]/.test(e.curr(-1))&&(n=ee[n]),r.value+=n);else r.value.length&&(l[s].push(r),r=J.text()),l[s].push(be(e))}else r.value.length&&(l[s].push(r),r=J.text()),l[++s]=[],i=!0;else r.value+=" ";let u=e.curr();if((";"===u||"}"==u||t(u))&&!a.length)break;e.next()}return r.value.length&&l[s].push(r),l}function _e(e){let t,n="";for(;!e.end()&&"{"!=(t=e.curr());)n+=t,e.next();return n=n.trim(),n}function $e(e){let t,n={name:"",arguments:[]};for(;!e.end();){if("("==(t=e.curr()))e.next(),n.arguments=de(e)[0];else{if(/[){]/.test(t))break;n.name+=t}e.next()}let[r,...s]=n.name.trim().split(/\s+/);return n.name=r,n.addition=s,n}function we(e,t){let n,r=J.pseudo();for(;!e.end();){if(n=e.curr(),"/"==n&&"*"==e.curr(1))he(e);else{if("}"==n)break;if(Q.white_space(n)){e.next();continue}if(r.selector){let n=ke(e,t);if("@use"==n.property?r.styles=r.styles.concat(n.value):n.property&&r.styles.push(n),"}"==e.curr())break}else r.selector=_e(e)}e.next()}return r}function ke(e,t){let n,r=J.rule(),s=e.index();for(;!e.end();){if(n=e.curr(),"/"==n&&"*"==e.curr(1))he(e);else{if(";"==n)break;if(r.property.length){r.value=xe(e);break}if(r.property=fe(e),"@use"==r.property){r.value=Ne(e,t);break}}e.next()}let i=e.index();return r.raw=()=>e.range(s,i).trim(),r}function Se(e,t){let n,r=J.cond();for(;!e.end();){if(n=e.curr(),"/"==n&&"*"==e.curr(1))he(e);else{if("}"==n)break;if(r.name.length)if(":"==n){let t=we(e);t.selector&&r.styles.push(t)}else if("@"!=n||oe(e,!0).includes(":")){if(!Q.white_space(n)){let n=ke(e,t);if(n.property&&r.styles.push(n),"}"==e.curr())break}}else r.styles.push(Se(e));else Object.assign(r,$e(e))}e.next()}return r}function je(e,t){let n="";return e&&e.get_variable&&(n=e.get_variable(t)),n}function Ae(e,t){e.forEach&&e.forEach((e=>{if("text"==e.type&&e.value){let n=f(r(p(e.value)));e.value=n.reduce(((e,n)=>{let r,s="",i="";s=je(t,n.name),!s&&n.fallback&&n.fallback.every((e=>{if(i=je(t,e.name),i)return s=i,!1}));try{r=Ee(s,t)}catch(e){}return r&&e.push.apply(e,r),e}),[])}"func"==e.type&&e.arguments&&e.arguments.forEach((e=>{Ae(e,t)}))}))}function Ne(e,t){return e.next(),(xe(e)||[]).reduce(((e,n)=>{Ae(n,t);let[r]=n;return r.value&&r.value.length&&e.push(...r.value),e}),[])}function Ee(e,t){const n=ne(e),r=[];for(;!n.end();){let e=n.curr();if(Q.white_space(e))n.next();else{if("/"==e&&"*"==n.curr(1))he(n);else if(":"==e){let e=we(n,t);e.selector&&r.push(e)}else if("@"==e&&"@keyframes"===ie(n,!0)){let e=ce(n,t);r.push(e)}else if("@"!=e||oe(n,!0).includes(":")){if("<"==e)pe(n);else if(!Q.white_space(e)){let e=ke(n,t);e.property&&r.push(e)}}else{let e=Se(n,t);e.name.length&&r.push(e)}n.next()}}return r}function Re(e,t=64){const[n,r,s]=[1,t,t*t];let[i,l,o]=(e+"").replace(/\s+/g,"").replace(/[,\uff0cxX]+/g,"x").split("x").map((e=>parseInt(e)));const a=1==i||1==l?s:r,u=1==i&&1==l?s:n,c={x:v(i||n,1,a),y:v(l||i||n,1,a),z:v(o||n,1,u)};return Object.assign({},c,{count:c.x*c.y*c.z,ratio:c.x/c.y})}function Te(e){return/^texture\w*$|^(fragment|vertex)$/.test(e)}function ze(){return new n({type:"LineBreak",value:"\n"})}function Pe(e){let t=e[0],n=e[e.length-1];for(;t&&t.isSymbol("(")&&n&&n.isSymbol(")");)t=(e=e.slice(1,e.length-1))[0],n=e[e.length-1];return e}function Ce(e){return Pe(e).map((e=>e.value)).join("")}function Me(e){let t=r(p(e)),n={},s={commands:[],valid:!0};for(;t.next();){let{curr:e}=t.get();if(!e.isSpace()&&!e.isSymbol(","))if(e.isWord())n.name&&(s.commands.push(n),n={}),n.name=e.value,n.value=[],"MmLlHhVvCcSsQqTtAaZz".includes(e.value)?"mlhvcsqtaz".includes(e.value)?n.type="relative":n.type="absolute":(n.type="unknown",s.valid=!1);else if(n.value){let t=e.value;e.isNumber()&&(t=Number(e.value)),n.value.push(t)}else n.name||(s.valid=!1)}return n.name&&s.commands.push(n),s}function Oe(e){let t=r(p(e)),n={},s=!1;for(;t.next();){let{prev:e,curr:r,next:i}=t.get(),l=s&&(r.isWord()||r.isSymbol())&&e&&e.isNumber()&&!i;if(r.isNumber())n.value=Number(r.value),s=!0;else{if(!l)break;n.unit=r.value}}return n}const Ie='xmlns="http://www.w3.org/2000/svg"',We='xmlns="http://www.w3.org/1999/xhtml"',Le='xmlns:xlink="http://www.w3.org/1999/xlink"';function De(e,t){return`url("data:image/svg+xml;utf8,${encodeURIComponent(e)+(t?`#${t}`:"")}")`}function Be(e){return e.includes("${e}`),e.includes("xmlns")||(e=e.replace(/])/,``${t}-${++e}`}();class Fe{constructor(e,t=""){if(!e)throw new Error("Tag name is required");this.id=Symbol(),this.name=e,this.body=[],this.attrs={},this.isTextNode()&&(this.body=t)}isTextNode(){return"text-node"===this.name}find(e){let t=e.attrs.id,n=e.name;if(Array.isArray(this.body)&&void 0!==t)return this.body.find((e=>e.attrs.id===t&&e.name===n))}findSpareDefs(){return this.body.find((e=>"defs"===e.name&&!e.attrs.id))}append(e){Array.isArray(e)||(e=[e]);for(let t of e)this.isTextNode()||this.body.push(t)}merge(e){for(let[t,n]of Object.entries(e.attrs))this.attrs[t]=n;Array.isArray(e.body)&&this.body.push(...e.body)}attr(e,t){if(!this.isTextNode())return void 0===t?this.attrs[e]:this.attrs[e]=t}toString(){if(this.isTextNode())return Xe(this.body);let e=[""],t=[];for(let[t,n]of Object.entries(this.attrs))n=Xe(n),e.push(`${t}="${n}"`);for(let e of this.body)t.push(e.toString());return t.join("").length||/svg/i.test(this.name)?`<${this.name}${e.join(" ")}>${t.join("")}`:`<${this.name}${e.join(" ")}/>`}}function Xe(e){let t=(e=String(e)).startsWith('"')&&e.endsWith('"'),n=e.startsWith("'")&&e.endsWith("'");return t||n?e.substring(1,e.length-1):e}function qe(e,t,n,r){let s;if(t||(t=new Fe("root")),"block"===e.type)if("style"===e.name){let n=new Fe("style");n.append(e.value),t.append(n)}else{let i=new Fe(e.name);if(r||(r=i).attr("xmlns",Ie.split("=")[1]),"defs"===e.name){let e=r.findSpareDefs();e&&(i=e)}for(let t of e.value){e.parent=n;let l=qe(t,i,e,r);l&&(s=l)}let l=e&&e.inline&&"defs"!==e.name,o=n&&n.inline&&"defs"===n.name,a=o&&1==n.value.length;if(l||o){let t=e.value.find((e=>"statement"===e.type&&"id"===e.name));t?s=t.value:(a||l)&&(s=Ue(e.name),i.attr("id",s))}let u=t.find(i);if(u)u.merge(i);else if("defs"===e.name){let e=r.findSpareDefs();e&&!i.attrs.id?i.id!==e.id&&e.append(i.body):r.append(i)}else t.append(i)}if("statement"===e.type&&!e.variable)if("content"===e.name){let n=new Fe("text-node",e.value);t.append(n)}else if(e.name.startsWith("style ")){let n=(e.name.split("style ")[1]||"").trim();if(n.length){let r=t.attr("style")||"";t.attr("style",r+function(e,t){return`${e}:${t};`}(n,e.value))}}else{let s=e.value;if(s&&"block"===s.type){let t=qe(e.value,r,e,r);x(t)?s="":(s=`url(#${t})`,"xlink:href"!==e.name&&"href"!==e.name||(s=`#${t}`))}if(/viewBox/i.test(e.name))s=function(e){let t=e.detail.value,n=e.detail.padding||e.detail.p||e.detail.expand;if(!t.length)return"";let[r,s,i,l]=t;return n&&([r,s,i,l]=[r-n,s-n,i+2*n,l+2*n]),`${r} ${s} ${i} ${l}`}(e),s&&t.attr(e.name,s);else if("draw"!==e.name&&"animate"!==e.name||"path"!==(i=n&&n.name)&&"line"!==i&&"circle"!==i&&"ellipse"!==i&&"rect"!==i&&"polygon"!==i&&"polyline"!==i)t.attr(e.name,s);else{let[e,n]=String(s).split(/\s+/);("indefinite"===e||"infinite"===e||/\d$/.test(e))&&([e,n]=[n,e]),"infinite"===n&&(n="indefinite"),t.attr("stroke-dasharray",10),t.attr("pathLength",10);let r=new Fe("animate");r.attr("attributeName","stroke-dashoffset"),r.attr("from",10),r.attr("to",0),r.attr("dur",e),n&&r.attr("repeatCount",n),t.append(r)}e.name.includes("xlink:")&&r.attr("xmlns:xlink",Le.split("=")[1])}var i;return n?s:r.toString()}function He(e){return qe(e)}const Ye=["auto","reverse"],Ge=["deg","rad","grad","turn"];function Ve(e){let t=r(p(e)),n=!1,s="",i={direction:"",angle:""};for(;t.next();){let{prev:e,curr:r,next:l}=t.get();if(r.isWord()&&Ye.includes(r.value))i.direction=r.value,n=!0;else if(r.isNumber())i.angle=Number(r.value),n=!0;else if(r.isWord()&&e&&e.isNumber()&&Ge.includes(r.value))s=r.value;else if(r.isSpace()&&""!==i.direction&&""!==i.angle)break}return n||(i.direction="auto"),function(e,t){let{angle:n}=e;""===n&&(n=0);"rad"===t&&(n/=Math.PI/180);"grad"===t&&(n*=.9);"turn"===t&&(n*=360);return Object.assign({},e,{angle:n})}(i,s)}function Ze(e,t,n){return["fill-rule","fill"].includes(e)?t:n?`-1 * (${t})`:t}function Ke(e){return e.map((e=>e.value)).join("")}const Je=new class{#e=new Map;clear(){this.#e.clear()}set(e,t){if(x(e))return"";let n=this.getKey(e);return this.#e.set(n,t),t}has(e){return this.#e.has(e)}get(e){let t=this.getKey(e);return this.#e.get(t)}getKey(e){return E("string"==typeof e?e:JSON.stringify(e))}};function Qe(e,t){return(...n)=>{let r=e+n.join("-");return Je.get(r)||Je.set(r,t(...n))}}const et={\u03c0:Math.PI,gcd:(e,t)=>{for(;t;)[e,t]=[t,e%t];return e}},tt={"^":7,"*":6,"/":6,"\xf7":6,"%":6,"&":5,"|":5,"+":4,"-":4,"<":3,"<<":3,">":3,">>":3,"=":3,"==":3,"\u2264":3,"<=":3,"\u2265":3,">=":3,"\u2260":3,"!=":3,"\u2227":2,"&&":2,"\u2228":2,"||":2,"(":1,")":1};function nt(e,t,n=[]){let r=[];for(;e.length;){let{name:s,value:i,type:l}=e.shift();if("variable"===l){let e=t[i];_(e)&&(e=Math[i]),_(e)&&(e=it(i,t,n)),_(e)&&/^\-\D/.test(i)&&(e=it("-1"+i.substr(1),t,n)),void 0===e&&(e=0),"number"!=typeof e&&(n.push(e),lt(n)?(e=0,n=[]):e=nt(rt(e),t,n)),r.push(e)}else if("function"===l){let e=!1;/^\-/.test(s)&&(e=!0,s=s.substr(1));let l,o=i.map((e=>nt(e,t,n))),a=s.split(".");for(;l=a.pop();){if(!l)continue;let e=t[l]||Math[l];o="function"==typeof e?Array.isArray(o)?e(...o):e(o):0}e&&(o*=-1),r.push(o)}else if(/\d+/.test(i))r.push(i);else{let e=r.pop(),t=r.pop();r.push(st(i,Number(t),Number(e)))}}return Number(r[0])||0}function rt(e){let t=function(e){if(Je.has(e))return Je.get(e);let t=String(e),n=[],r="";for(let e=0;e=]$/.test(i.value))i.value+=s;else if(/^[|&<>]$/.test(s)&&i&&i.value==s)i.value+=s;else if("-"==s&&"e"==t[e-1])r+=s;else if(n.length||r.length||!/[+-]/.test(s)){let{type:e,value:t}=i||{};"operator"==e&&!r.length&&/[^()]/.test(s)&&/[^()]/.test(t)?r+=s:(r.length&&(n.push({type:"number",value:r}),r=""),n.push({type:"operator",value:s}))}else r+=s}else/\S/.test(s)&&(","==s?(n.push({type:"number",value:r}),r="",n.push({type:"comma",value:s})):"!"==s?(n.push({type:"number",value:r}),n.push({type:"operator",value:s}),r=""):r+=s)}return r.length&&n.push({type:"number",value:r}),Je.set(e,n),n}(e);const n=[],r=[];for(let e=0;e=tt[i];){let e=n.pop();/[()]/.test(e)||r.push({type:"operator",value:e})}n.push(i)}}for(;n.length;)r.push({type:"operator",value:n.pop()});return r}function st(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"%":return t%n;case"|":return t|n;case"&":return t&n;case"<":return t":return t>n;case"^":return Math.pow(t,n);case"\xf7":case"/":return t/n;case"=":case"==":return t==n;case"\u2264":case"<=":return t<=n;case"\u2265":case">=":return t>=n;case"\u2260":case"!=":return t!=n;case"\u2227":case"&&":return t&&n;case"\u2228":case"||":return t||n;case"<<":return t<>":return t>>n}}function it(e,t,n){let[r,s,i]=e.match(/([\d.\-]+)(.*)/)||[],l=t[i];return void 0===l?l:"number"==typeof l?Number(s)*l:(n.push(l),lt(n)?(n=[],0):s*nt(rt(l),t,n))}function lt(e){if(e.length>50)return!0;let t=C(e);for(let n=2;n<=4;++n){let r=e[e.length-n];if(void 0===r)return!1;if(t!==r)return!1}return!0}function ot(e,t){return nt(rt(e),Object.assign({},et,t))}const{cos:at,sin:ut,abs:ct,atan2:ht,PI:pt}=Math,ft={circle:"\n split:180;scale:.99\n ",triangle:"\n rotate:30;scale:1.1;move:0 .2\n ",pentagon:"\n split:5;rotate:54\n ",hexagon:"\n split:6;rotate:30;scale:.98\n ",octagon:"\n split:8;rotat:22.5;scale:.99\n ",star:"\n split:10;r:cos(5t);rotate:-18;scale:.99\n ",infinity:"\n split:180;scale:.99;x:cos(t)*.99 / (sin(t)^2 + 1);y:x * sin(t)\n ",heart:"\n split:180;rotate:180;a:cos(t)*13/18 - cos(2t)*5/18;b:cos(3t)/18 + cos(4t)/18;x:(.75 * sin(t)^3) * 1.2;y:(a - b + .2) * -1.1\n ",bean:"\n split:180;r:sin(t)^3 + cos(t)^3;move:-.35 .35;",bicorn:"\n split:180;x:cos(t);y:sin(t)^2 / (2 + sin(t)) - .5\n ",drop:"\n split:180;rotate:90;scale:.95;x:sin(t);y:(1 + sin(t)) * cos(t) / 1.6\n ",fish:"\n split:240;x:cos(t) - sin(t)^2 / sqrt(2) - .04;y:sin(2t)/2\n ",whale:"\n split:240;rotate:180;R:3.4 * (sin(t)^2 - .5) * cos(t);x:cos(t) * R + .75;y:sin(t) * R * 1.2\n ",windmill:"\n split:18;R:seq(.618, 1, 0);T:seq(t-.55, t, t);x:R * cos(T);y:R * sin(T)\n ",vase:"\n split:240;scale:.3;x:sin(4t) + sin(t) * 1.4;y:cos(t) + cos(t) * 4.8 + .3\n ",clover:(e=3)=>(4==(e=v(e,3,5))&&(e=2),`\n split:240;r:cos(${e}t);scale:.98\n`),hypocycloid:(e=3)=>`\n split:240;scale:${[.34,.25,.19][(e=v(e,3,5))-3]};k:${e};x:(k-1)*cos(t) + cos((k-1)*t);y:(k-1)*sin(t) - sin((k-1)*t)\n`,bud:(e=3)=>`\n split:240;scale:.8;r:1 + .2 * cos(${e=v(e,3,10)}t)\n`};class dt{constructor(e,t,n){this.x=e,this.y=t,this.extra=n}valueOf(){return this.x+" "+this.y}toString(){return this.valueOf()}}function mt(e,t){t||(t=e=>[at(e),ut(e)]);let n,r,s=e.split||180,i=e.turn||1,l=e.frame,o=e.fill||e["fill-rule"],a=Ve(e.direction||e.dir||""),u=e.unit,c=2*pt*i/s,h=[],p=void 0===e.scale?1:e.scale,f=([e,t,n=0,r=0])=>{if("evenodd"==e||"nonzero"==e)return h.push(new dt(e,"",""));let[s,i]=gt(e,-t,p),[l,o]=gt(n,-r,p),c=function(e,t,n,r,s){let i=180*ht(t+r,e-n)/pt;"reverse"===s.direction&&(i-=180);s.direction||(i=90);s.angle&&(i+=s.angle);return i}(s,i,l,o,a);void 0!==u&&"%"!==u?"none"!==u&&(s+=u,i+=u):(s=50*(s+1)+"%",i=50*(i+1)+"%"),h.push(new dt(s,i,c))};"nonzero"!=o&&"evenodd"!=o||f([o,"",""]);for(let e=0;e1&&(e*=2),0==e&&(e=.002);for(let n=0;n{let a=Object.assign({},e,{t:o||t,\u03b8:o||t,i:n+1,seq:(...e)=>e.length?e[n%e.length]:"",range:(e,t=0)=>((e=Number(e)||0)>(t=Number(t)||0)&&([e,t]=[t,e]),e+ct(t-e)/(r-1)*n)}),u=ot(s,a),c=ot(i,a),h=0,p=0;if(l){let e=ot(l,a);0==e&&(e=1e-5),o&&(t=ot(o,a)),u=e*at(t),c=e*ut(t)}return e.rotate&&([u,c]=function(e,t,n){let r=-pt/180*n;return[e*at(r)-t*ut(r),t*at(r)+e*ut(r)]}(u,c,Number(e.rotate)||0)),e.move&&([u,c,h,p]=function(e,t,n){let[r,s=r]=O(n).map(Number);return[e+(r||0),t-(s||0),r,s]}(u,c,e.move)),[u,c,h,p]}))}function yt(e,t=3,n=3600,s){let i="",[l,...o]=O(e),a=!1;switch(typeof ft[l]){case"function":i=ft[l](...o),a=!0;break;case"string":i=ft[l],a=!0;break;default:i=e}let u=function(e){let t,n=r(p(e)),s={},i=[],l=!1;for(;n.next();){let{prev:e,curr:r,next:o}=n.get();if(r.isSymbol(":")&&!t)t=Ke(i),i=[];else if(r.isSymbol(";")&&t)s[t]=Ze(t,Ke(i),l),i=[],t=null,l=!1;else if(!r.isSymbol(";")){let n=e&&e.isSymbol("-"),s=o&&o.isSymbol("-"),a=r.isSymbol("-");t||i.length||!a||n||s||o&&o.isSymbol(":")?i.push(r):l=!0}}return i.length&&t&&(s[t]=Ze(t,Ke(i),l)),s}(i);return"function"==typeof s&&(u=s(u)),{rules:u,points:vt(u,{min:t,max:n}),preset:a}}const bt=[151,160,137,91,90,15,131,13,201,95,96,53,194,233,7,225,140,36,103,30,69,142,8,99,37,240,21,10,23,190,6,148,247,120,234,75,0,26,197,62,94,252,219,203,117,35,11,32,57,177,33,88,237,149,56,87,174,20,125,136,171,168,68,175,74,165,71,134,139,48,27,166,77,146,158,231,83,111,229,122,60,211,133,230,220,105,92,41,55,46,245,40,244,102,143,54,65,25,63,161,1,216,80,73,209,76,132,187,208,89,18,169,200,196,135,130,116,188,159,86,164,100,109,198,173,186,3,64,52,217,226,250,124,123,5,202,38,147,118,126,255,82,85,212,207,206,59,227,47,16,58,17,182,189,28,42,223,183,170,213,119,248,152,2,44,154,163,70,221,153,101,155,167,43,172,9,129,22,39,253,19,98,108,110,79,113,224,232,178,185,112,104,218,246,97,228,251,34,242,193,238,210,144,12,191,179,162,241,81,51,145,235,249,14,239,107,49,192,214,31,181,199,106,157,184,84,204,176,115,121,50,45,127,4,150,254,138,236,205,93,222,114,67,29,24,72,243,141,128,195,78,66,215,61,156,180];class xt{constructor(){this.p=[].concat(bt,bt)}grad(e,t,n,r){let s=15&e,i=s<8?t:n,l=s<4?n:12==s||14==s?t:r;return(0==(1&s)?i:-i)+(0==(2&s)?l:-l)}noise(e,t,n){let{p:r,grad:s}=this,[i,l,o]=[e,t,n].map((e=>255&Math.floor(e)));[e,t,n]=[e,t,n].map((e=>e-Math.floor(e)));let[a,u,c]=[e,t,n].map((e=>e*e*e*(e*(6*e-15)+10))),h=r[i]+l,p=r[h]+o,f=r[h+1]+o,d=r[i+1]+l,m=r[d]+o,g=r[d+1]+o;return R(c,R(u,R(a,s(r[p],e,t,n),s(r[m],e-1,t,n)),R(a,s(r[f],e,t-1,n),s(r[g],e-1,t-1,n))),R(u,R(a,s(r[p+1],e,t,n-1),s(r[m+1],e-1,t,n-1)),R(a,s(r[f+1],e,t-1,n-1),s(r[g+1],e-1,t-1,n-1))))}}const _t={name:"cssd-utime","animation-name":"cssd-utime-animation","animation-duration":31536e6,animation:"31536000000ms linear 0s infinite cssd-utime-animation"},$t="cssd-umousex",wt="cssd-umousey",kt="cssd-uwidth",St="cssd-uheight";function jt(e){return(...t)=>{let n=[],r=[];for(let e of t){let{unit:t,value:s}=Oe(e);void 0!==t&&n.push(t),void 0!==s&&r.push(s)}let s=e(...r),i=n.find((e=>void 0!==e));return void 0===i?s:Array.isArray(s)?s.map((e=>e+i)):s+i}}function At(e){return(...t)=>{let n=t.map((e=>String(e).charCodeAt(0))),r=e(...n);return Array.isArray(r)?r.map((e=>String.fromCharCode(e))):String.fromCharCode(r)}}function Nt(e,t){return{type:e,value:t}}function Et(e,t,n){let r=0,s=e,i=e=>e>0&&e<1?.1:1,l=arguments.length;1==l&&([e,t]=[i(e),e]),l<3&&(n=i(e));let o=[];for(;(n>=0&&e<=t||n<0&&e>t)&&(o.push(e),e+=n,!(r++>=65535)););return o.length||o.push(s),o}const Rt=Qe("build_range",(e=>{let t=function(e){let t=String(e),n=[],r=[];if(!t.startsWith("[")||!t.endsWith("]"))return n;for(let e=1;e{if("char"==e)return t;let[n,r]=t,s=!1;n>r&&([n,r]=[r,n],s=!0);let i=At(Et)(n,r);return s&&i.reverse(),i}))}));function Tt(e){return(...t)=>e(...t.flatMap((e=>String(e).startsWith("[")?Rt(e):e)))}class zt{constructor(e){this.prev=this.next=null,this.data=e}}class Pt{constructor(e=20){this._limit=e,this._size=0}push(e){this._size>=this._limit&&(this.root=this.root.next,this.root.prev=null);let t=new zt(e);this.root?(t.prev=this.tail,this.tail.next=t,this.tail=t):this.root=this.tail=t,this._size++}last(e=1){let t=this.tail;for(;--e&&t.prev;)t=t.prev;return t.data}}function Ct(e,t){let n={},r=!0;for(let s=0;s{if(!r||!n)return"";let s=S(n()),i=s;/\D/.test(s)&&!/\d+[x-]\d+/.test(s)&&(i=ot(s),0===i&&(i=s));let l=Math.random();return function(e,t){let[n,r=1]=String(e).split(/[x-]/),[s,i]=[Math.ceil(n),Math.ceil(r)];_(s)&&(s=1),_(i)&&(i=1),n=v(s,0,65536),r=v(i,0,65536);let l=n*r,o=[],a=1;if(/x/.test(e))for(let e=1;e<=r;++e)for(let s=1;s<=n;++s)o.push(t(a,s,e,l,n,r,a)),a++;else if(/-/.test(e))if(l=Math.abs(n-r)+1,n<=r)for(let e=n;e<=r;++e)o.push(t(e,e,1,l,l,1,a++));else for(let e=n;e>=r;--e)o.push(t(e,e,1,l,l,1,a++));else for(let e=1;e<=n;++e)o.push(t(e,e,1,n,n,1,a++));return o}(i,((...e)=>r.map((t=>S(t(...e,l)))).join(","))).join(e)}))}function Ot(e,t,n){return e[t]||(e[t]=new Pt(1024)),e[t].push(n),n}function It(e){return-1*e}function Wt(e,t,n){switch(e){case"+":return t+n;case"-":return t-n;case"*":return t*n;case"/":return t/n;case"%":return t%n;default:return 0}}function Lt(e,t){if($(t)||$(e))return e;if(/^[\+\*\-\/%][\-\.\d\s]/.test(t)){let n=t[0],{unit:r="",value:s}=Oe(t.substr(1).trim()||0);return/var\(/.test(e)?"%"===n?`calc(mod(${e}, ${s}) * 1${r})`:`calc((${e} ${n} ${s}) * 1${r})`:Wt(n,e,s)+r}if(/[\+\*\-\/%]$/.test(t)){let n=t.substr(-1),{unit:r="",value:s}=Oe(t.substr(0,t.length-1).trim()||0);return/var\(/.test(e)?"%"===n?`calc(mod(${s}, ${e}) * 1${r})`:`calc((${s} ${n} ${e}) * 1${r})`:Wt(n,s,e)+r}{let{unit:n="",value:r}=Oe(t||0);return e+r+n}}function Dt(e){return(...t)=>{for(let n of t)e=Lt(e,n);return e}}const Bt=y({i:({count:e})=>Dt(e),y:({y:e})=>Dt(e),x:({x:e})=>Dt(e),z:({z:e})=>Dt(e),I:({grid:e})=>Dt(e.count),Y:({grid:e})=>Dt(e.y),X:({grid:e})=>Dt(e.x),Z:({grid:e})=>Dt(e.z),iI:({count:e,grid:t})=>Dt(e/t.count),xX:({x:e,grid:t})=>Dt(e/t.x),yY:({y:e,grid:t})=>Dt(e/t.y),id:({x:e,y:t,z:n})=>r=>k(e,t,n),dx:({x:e,grid:t})=>n=>(n=Number(n)||0,e-.5-n-t.x/2),dy:({y:e,grid:t})=>n=>(n=Number(n)||0,e-.5-n-t.y/2),n({extra:e}){let t=C(e);return t?Dt(t[0]):"@n"},nx({extra:e}){let t=C(e);return t?Dt(t[1]):"@nx"},ny({extra:e}){let t=C(e);return t?Dt(t[2]):"@ny"},N({extra:e}){let t=C(e);return t?Dt(t[3]):"@N"},nN({extra:e}){let t=C(e);return t?Dt(t[0]/t[3]):"@nN"},m:Mt(","),M:Mt(" "),\u00b5:Mt(""),p:({context:e,pick:t})=>Tt(((...n)=>{n.length||(n=e.last_pick_args||[]);let r=t(n);return e.last_pick_args=n,Ot(e,"last_pick",r)})),P({context:e,pick:t,position:n}){let r="P-counter"+n;return Tt(((...n)=>{let s=!0;n.length||(n=e.last_pick_args||[],s=!1);let i=e.last_pick,l=i?i.last(1):"";if(s&&(e[r]||(e[r]={}),l=e[r].last_pick),n.length>1){let e=n.findIndex((e=>e===l));-1!==e&&n.splice(e,1)}let o=t(n);return e.last_pick_args=n,s&&(e[r].last_pick=o),Ot(e,"last_pick",o)}))},pl({context:e,extra:t,upextra:n,position:r},s){let i=C(s&&n.length?n:t),l=(s?"PL-counter":"pl-counter")+r+(i?C(i):"");return Tt(((...t)=>{e[l]||(e[l]=0),e[l]+=1;let n=t.length,r=i&&i[6];r??=e[l];let s=t[(r-1)%n];return Ot(e,"last_pick",s)}))},PL:e=>Bt.pl(e,!0),pr({context:e,extra:t,position:n},r){let s=C(r&&upextra.length?upextra:t),i=(r?"PR-counter":"pr-counter")+n+(s?C(s):"");return Tt(((...t)=>{e[i]||(e[i]=0),e[i]+=1;let n=t.length,r=s&&s[6];r??=e[i];let l=t[n-(r-1)%n-1];return Ot(e,"last_pick",l)}))},PR:e=>Bt.pr(e,!0),pd({context:e,extra:t,position:n,shuffle:r},s){let i=C(s&&upextra.length?upextra:t),l=i?C(i):"",o=(s?"PD-counter":"pd-counter")+n+l,a=(s?"PD-valeus":"pd-values")+n+l;return Tt(((...t)=>{e[o]||(e[o]=0),e[o]+=1,e[a]||(e[a]=r(t||[]));let n=t.length,s=i&&i[6];s??=e[o];let l=(s-1)%n,u=e[a][l];return Ot(e,"last_pick",u)}))},PD:e=>Bt.pd(e,!0),lp:({context:e})=>(t=1)=>{let n=e.last_pick;return n?n.last(t):""},r:({context:e,rand:t})=>(...n)=>{let r=(n.every(b)?At:jt)(t)(...n);return Ot(e,"last_rand",r)},rn({x:e,y:t,context:n,position:r,grid:s,extra:i,random:l}){let o="noise-2d"+r,a=o+"offset-x",u=o+"offset-y",[c,h,p,f,d,m]=C(i)||[],g=c&&f;return(...r)=>{let{from:i=0,to:c=i,frequency:f=1,scale:y=1,octave:x=1}=Ct(r,["from","to","frequency","scale","octave"]);f=v(f,0,1/0),y=v(y,0,1/0),x=v(x,1,100),1==r.length&&([i,c]=[0,i]),n[o]||(n[o]=new xt),n[a]||(n[a]=l()),n[u]||(n[u]=l());let _=b(i)&&b(c)?At:jt,$=n[o],w=n[a],k=n[u],S=(g?(h-1)/d:(e-1)/s.x)+w,j=(g?(p-1)/m:(t-1)/s.y)+k;(d<=1||s.x<=1)&&(S=0),(m<=1||s.y<=1)&&(j=0),0==S&&0==j&&(S=w,j=k);let A=$.noise(S*f,j*f,0)*y;for(let e=1;efunction(e,t,n,r=1){let s=Math.sqrt(.5)*r,[i,l]=[-s,s];return R((e-i)/(l-i),t*r,n*r)}(A,e,t,y)));return Ot(n,"last_rand",N(i,c))}},lr:({context:e})=>(t=1)=>{let n=e.last_rand;return n?n.last(t):""},stripe:()=>(...e)=>{let t,n=e.map(S),r=n.length,s=0,i=[];if(!r)return"";n.forEach((e=>{let[t,n]=O(e);void 0!==n?i.push(n):s+=1}));let l=i.length?`(100% - ${i.join(" - ")}) / ${s}`:`100% / ${r}`;return n.map(((e,n)=>{if(i.length){let[n,r]=O(e);return t=(t?t+" + ":"")+(void 0!==r?r:l),`${n} 0 calc(${t})`}return`${e} 0 ${100/r*(n+1)}%`})).join(",")},calc:()=>(e,t)=>ot(S(e),t),hex:()=>e=>parseInt(S(e)).toString(16),svg:w(((e,...t)=>{let n=t.map((e=>S(e()))).join(",");if(!n.startsWith("<")){n=He(V(n))}return De(Be(n))})),"svg-filter":w(((e,...t)=>{let n=t.map((e=>S(e()))),r=n.join(","),s=T("filter-");if(n.every((e=>/^[\-\d.]/.test(e)||/^(\w+)/.test(e)&&!/[{}<>]/.test(e)))){let{frequency:t,scale:s,octave:i,seed:l=e.seed,blur:o,erode:a,dilate:u}=Ct(n,["frequency","scale","octave","seed","blur","erode","dilate"]);if(r="\n x:-20%;y:-20%;width:140%;height:140%;",x(u)||(r+=`\n feMorphology{operator:dilate;radius:${u};}`),x(a)||(r+=`\n feMorphology{operator:erode;radius:${a};}`),x(o)||(r+=`\n feGaussianBlur{stdDeviation:${o};}`),!x(t)){let[e,n=e]=O(t);i=i?`numOctaves:${i};`:"",r+=`\n feTurbulence{type:fractalNoise;baseFrequency:${e} ${n};seed:${l};${i}}`,s&&(r+=`\n feDisplacementMap{in:SourceGraphic;scale:${s};}`)}}if(!r.startsWith("<")){r=He(V(r,{type:"block",name:"filter"}))}return De(Be(r).replace(/])/,`De(He(V(`\n viewBox:0 0 1 1;preserveAspectRatio:xMidYMid slice;rect{width, height:100%;fill:defs pattern{${t.map((e=>S(e()))).join(",")}}}`))))),"svg-polygon":w(((e,...t)=>{let n=t.map((e=>S(e()))).join(","),{rules:r,points:s}=yt(n,3,65536,(e=>(delete e.frame,e.unit="none",e["stroke-width"]??=.01,e.stroke??="currentColor",e.fill??="none",e))),i=`points:${s};`,l="",o=r.padding??Number(r["stroke-width"])/2;for(let e of Object.keys(r))/^(stroke|fill|clip|marker|mask|animate|draw)/.test(e)&&(l+=`${e}:${r[e]};`);return De(He(V(`\n viewBox:-1 -1 2 2 p ${o};polygon{${l} ${i}}`)))})),var:()=>e=>`var(${S(e)})`,ut:()=>Dt(`var(--${_t.name})`),uw:()=>Dt(`var(--${kt})`),uh:()=>Dt(`var(--${St})`),ux:()=>Dt(`var(--${$t})`),uy:()=>Dt(`var(--${wt})`),plot({count:e,context:t,extra:n,position:r,grid:s}){let i="offset-points"+r,l=C(n);return(...n)=>{let r=n.join(","),[o=e,a,u,c=s.count]=l||[];if(!t[i]){let{points:e}=yt(r,1,65536,(e=>(delete e.fill,delete e["fill-rule"],delete e.frame,e.points=c,e)));t[i]=e}return t[i][o-1]}},Plot({count:e,context:t,extra:n,position:r,grid:s}){let i="Offset-points"+r,l=C(n);return(...n)=>{let r=n.join(","),[o=e,a,u,c=s.count]=l||[];if(!t[i]){let{points:e}=yt(r,1,65536,(e=>(delete e.fill,delete e["fill-rule"],delete e.frame,e.points=c,e.unit=e.unit||"none",e)));t[i]=e}return t[i][o-1]}},shape:()=>Qe("shape-function",((...e)=>{let t=e.join(","),{points:n}=yt(t);return`polygon(${n.join(",")})`})),doodle:()=>e=>e,shaders:()=>e=>e,pattern:()=>e=>e,invert:()=>e=>{let t=Me(e);return t.valid?t.commands.map((({name:e,value:t})=>{switch(e){case"v":return"h"+t.join(" ");case"V":return"H"+t.join(" ");case"h":return"v"+t.join(" ");case"H":return"V"+t.join(" ");default:return e+t.join(" ")}})).join(" "):e},flipH:()=>e=>{let t=Me(e);return t.valid?t.commands.map((({name:e,value:t})=>{switch(e){case"h":case"H":return e+t.map(It).join(" ");default:return e+t.join(" ")}})).join(" "):e},flipV:()=>e=>{let t=Me(e);return t.valid?t.commands.map((({name:e,value:t})=>{switch(e){case"v":case"V":return e+t.map(It).join(" ");default:return e+t.join(" ")}})).join(" "):e},flip(...e){let t=Bt.flipH(...e),n=Bt.flipV(...e);return e=>n(t(e))},reverse:()=>(...e)=>{let t=e.map(S),n=Me(t.join(","));if(n.valid){let e=[];for(let t=n.commands.length-1;t>=0;--t){let{name:r,value:s}=n.commands[t];e.push(r+s.join(" "))}return e.join(" ")}return t.reverse()},cycle:()=>(...e)=>{let t,n=[];1==(e=e.map((e=>"<"+e+">"))).length?(t=" ",n=O(e[0],{symbol:t})):(t=",",n=O(e.map(S).join(t),{symbol:t})),n=n.map((e=>e.replace(/^\<|>$/g,"")));let r=n.length-1,s=[n.join(t)];for(let e=0;e(...e)=>{for(let t=e.length-1;t>=0;--t)e.push(e[t]);return e},Mirror:()=>(...e)=>{for(let t=e.length-2;t>=0;--t)e.push(e[t]);return e},code:()=>(...e)=>e.map((e=>String.fromCharCode(e))),once:w((({context:e,extra:t,position:n},...r)=>{let s="once-counter"+n;return e[s]??=r.map((e=>S(e()))).join(",")})),raw:({rules:e})=>(t="")=>{try{let n=t.substring(t.indexOf(",")+1,t.lastIndexOf('")'));if(t.startsWith("${doodle")&&t.endsWith("}")){let n=t.substring(2,t.length-1),r=e.doodles;if(r&&r[n])return`${r[n].doodle}`}if(t.startsWith('url("data:image/svg+xml;utf8'))return decodeURIComponent(n);if(t.startsWith('url("data:image/svg+xml;base64'))return atob(n);if(t.startsWith('url("data:image/png;base64'))return``}catch(e){}return t}},{index:"i",col:"x",row:"y",depth:"z",rand:"r",pick:"p",pn:"pl",pnr:"pr",PN:"PL",PNR:"PR",stripes:"stripe",strip:"stripe",patern:"pattern",flipv:"flipV",fliph:"flipH",t:"ut",filter:"svg-filter","last-rand":"lr","last-pick":"lp",multiple:"m",multi:"m",rep:"\xb5",repeat:"\xb5",ms:"M",s:"I",size:"I",sx:"X","size-x":"X","size-col":"X","max-col":"X",sy:"Y","size-y":"Y","size-row":"Y","max-row":"Y",sz:"Z","size-z":"Z","size-depth":"Z",Svg:"svg","pick-by-turn":"pl","pick-n":"pl","pick-d":"pd",offset:"plot",Offset:"Plot",point:"plot",Point:"Plot",unicode:"code"}),Ut={a0:[841,1189],a1:[594,841],a2:[420,594],a3:[297,420],a4:[210,297],a5:[148,210],a6:[105,148],b0:[1e3,1414],b1:[707,1e3],b2:[500,707],b3:[353,500],b4:[250,353],b5:[176,250],b6:[125,176],c0:[917,1297],c1:[648,917],c2:[458,648],c3:[324,458],c4:[229,324],c5:[162,229],d0:[764,1064],d1:[532,760],d2:[380,528],d3:[264,376],d4:[188,260],d5:[130,184],d6:[92,126],letter:[216,279],postcard:[100,148],poster:[390,540]},Ft={portrait:"p",pt:"p",p:"p",landscape:"l",ls:"l",l:"l"};const Xt="--_cell-width",qt="--_cell-height",Ht={center:"50%",left:"0%",right:"100%",top:"50%",bottom:"50%"},Yt={center:"50%",top:"0%",bottom:"100%",left:"50%",right:"50%"};var Gt=y({size(e,{is_special_selector:t,grid:n}){let[r,s=r,i]=O(e);Ut[r]&&([r,s]=function(e,t){e=String(e).toLowerCase();let[n,r]=Ut[e]??[];return"p"==Ft[t]&&([r,n]=[n,r]),[r,n].map((e=>e+"mm"))}(r,s));let l=`width:${r};height:${s};`;return"auto"!==r&&"auto"!==s||(i&&(/^\(.+\)$/.test(i)?i=i.substring(1,i.length-1):/^calc/.test(i)||(i=`calc(${i})`),t||(l+=`aspect-ratio:${i};`)),t&&(l+=`aspect-ratio:${i||n.ratio};`)),t||(l+=`${Xt}:${r};${qt}:${s};`),l},place(e,{extra:t}){let[n,r="50%"]=O(e);n=Ht[n]||n,r=Yt[r]||r;let s=`var(${Xt}, 25%)`,i=`var(${qt}, 25%)`;return`\n position:absolute;left:${n};top:${r};width:${s};height:${i};margin-left:calc(${s} / -2);margin-top:calc(${i} / -2);grid-area:unset;--plot-angle:${t||0};rotate:${t||0}deg;`},grid(e,t){let n={clip:!0,p3d:!1},r=[];for(let t of O(e,{symbol:" "}))/border:?/i.test(t)?n.border=t.split(":")[1]||"":/^no\-*clip$/i.test(t)?n.clip=!1:/^p3d$/i.test(t)?n.p3d=!0:r.push(t);let s=O(r.join(" "),{symbol:["/","+","^","*","|","-","~","\u2206"],noSpace:!0,verbose:!0});for(let{group:e,value:r}of s)"+"===e&&(n.scale=r),"^"===e&&(n.enlarge=r),"*"===e&&(n.rotate=r),"~"===e&&(n.translate=r),"\u2206"===e&&(n.persp=O(r,{symbol:" "})),"/"===e&&(void 0===n.size?n.size=this.size(r,t):n.fill=r),"|"!==e&&"-"!=e&&""!=e||n.grid||(n.grid=Re(r,t.max_grid),"|"===e&&(n.flexCol=!0),"-"===e&&(n.flexRow=!0));return n},gap:e=>e,seed:e=>e,shape:Qe("shape-property",(e=>{let{points:t,preset:n}=yt(e);return n?`clip-path:polygon(${t.join(",")});`:""})),use(e){if(e.length>2)return e},content:e=>e},{"place-cell":"place",offset:"place",position:"place"});function Vt(e,t){return"+"===t?e:"-"===t?-1*e:e}function Zt(e){return e.reduce(((e,t)=>e+t),0)}function Kt(e){return e%2}function Jt(e){return!Kt(e)}function Qt(e){let t="";return t=0==e?"$:hover":e>0?`$:hover ${"+*".repeat(e)}`:`:has(+ ${"*+".repeat(Math.abs(e+1))} $:hover)`,t}function en(e,t){if("even"===e)return Jt(t);if("odd"===e)return Kt(t);if("n"==e)return!0;let{a:n,b:s,error:i}=function(e){let t,n,s=r(p(e)),i=[],l=[];for(;s.next();){let{prev:e,curr:r,next:o}=s.get(),a=r.value;if(r.isSymbol()){if("+"!==a&&"-"!==a){n="Unexpected "+r.value;break}t=a}else if(r.isNumber()){if((i.length||l.length)&&!t){n="Syntax error";break}if(a=Vt(Number(a),t),t=null,o&&"n"===o.value){i.push(a),s.next();continue}l.push(a)}else if("n"===a){if((i.length||l.length)&&!t){n="Syntax error";break}i.push(Vt(1,t)),t=null}else if(!r.isSpace()){n="Unexpected "+a;break}}return n?{a:0,b:0,error:n}:{a:Zt(i),b:Zt(l)}}(e);if(i)return!1;if(0===n)return t===s;{let e=(t-s)/n;return e>=0&&Number.isInteger(e)}}var tn,nn=y({at:({x:e,y:t})=>(n,r)=>e==n&&t==r,nth:({count:e,grid:t})=>(...t)=>{for(let n of t)if(en(n,e))return!0},y:({y:e,grid:t})=>(...t)=>{for(let n of t)if(en(n,e))return!0},x:({x:e,grid:t})=>(...t)=>{for(let n of t)if(en(n,e))return!0},even:({x:e,y:t})=>n=>Kt(e+t),odd:({x:e,y:t})=>n=>Jt(e+t),random:({random:e,count:t,x:n,y:r,grid:s})=>(i=.5)=>/\D/.test(i)?e()i=>!!ot("("+i+")",{x:n,X:t.x,y:r,Y:t.y,i:e,I:t.count,random:s}),hover:({count:e,x:t,y:n,grid:r,random:s})=>(...e)=>{let s=[];e.length||s.push(Qt(0));for(let i of e){let[e,l]=String(i).split(/\s+/);if(e=Number(e),l=Number(l),Number.isNaN(l)&&!Number.isNaN(e)&&s.push(Qt(e)),!Number.isNaN(e)&&!Number.isNaN(l)){let i=e+t,o=l+n;if(i>=1&&i<=r.x&&o>=1&&o<=r.y){let t=l*r.y+e;s.push(Qt(t))}}}return!!s.length&&{selector:s.join(",")}}},{col:"x",row:"y"}),rn=globalThis,sn=Math,ln=[],on=256,an=6,un="random",cn=sn.pow(on,an),hn=sn.pow(2,52),pn=2*hn,fn=on-1;function dn(e,t,n){var r=[],s=yn(vn((t=1==t?{entropy:!0}:t||{}).entropy?[e,bn(ln)]:null==e?function(){try{var e;return tn&&(e=tn.randomBytes)||(e=new Uint8Array(on),(rn.crypto||rn.msCrypto).getRandomValues(e)),bn(e)}catch(e){var t=rn.navigator,n=t&&t.plugins;return[+new Date,rn,n,rn.screen,bn(ln)]}}():e,3),r),i=new mn(r),l=function(){for(var e=i.g(an),t=cn,n=0;e=pn;)e/=2,t/=2,n>>>=1;return(e+n)/t};return l.int32=function(){return 0|i.g(4)},l.quick=function(){return i.g(4)/4294967296},l.double=l,yn(bn(i.S),ln),(t.pass||n||function(e,t,n,r){return r&&(r.S&&gn(r,i),e.state=function(){return gn(i,{})}),n?(sn[un]=e,t):e})(l,s,"global"in t?t.global:this==sn,t.state)}function mn(e){var t,n=e.length,r=this,s=0,i=r.i=r.j=0,l=r.S=[];for(n||(e=[n++]);s(...t)=>"number"==typeof Math[e]?Math[e]:(t=t.map((e=>ot(S(e)))),Math[e](...t));class kn{constructor(e){this.tokens=e,this.rules={},this.props={},this.keyframes={},this.grid=null,this.seed=null,this.is_grid_set=!1,this.is_gap_set=!1,this.coords=[],this.doodles={},this.pattern={},this.shaders={},this.vars={},this.uniforms={},this.content={},this.reset()}reset(){this.styles={host:"",container:"",cells:"",keyframes:""},this.coords=[],this.doodles={},this.pattern={},this.shaders={},this.content={};for(let e in this.rules)e.startsWith("#c")&&delete this.rules[e]}add_rule(e,t){let n=this.rules[e];n||(n=this.rules[e]=[]),n.push.apply(n,z(t))}pick_func(e){return e.startsWith("$")&&(e="calc"),Bt[e]||wn[e]}apply_func(e,t,n,r,s={}){let i=e(...z(t)),l=[];if(n.forEach((e=>{let t=typeof e.value;if(e.cluster||"number"!==t&&"string"!==t){if("function"==typeof e)l.push(e);else if(!x(e.value)){let t=S(e.value);l.push(t)}}else l.push(...O(e.value,{noSpace:!0}))})),l=z(l.filter((e=>!x(e)&&String(e).trim().length))),"function"==typeof i){if(r.startsWith("$")){let e=Object.assign({},this.vars.host,this.vars.container,this.vars[t.count],s),n={},o="";for(let[t,r]of Object.entries(e))n[t.substr(2)]=r;return r.length>1&&(o=r.split("$")[1]??""),i(l,n)+o}return i(...l)}return i}compose_aname(...e){return e.join("-")}compose_selector({x:e,y:t,z:n},r=""){return`#${k(e,t,n)}${r}`}is_composable(e){return["doodle","shaders","pattern"].includes(e)}read_var(e,t,n){let r=t.count,s=Object.assign({},this.vars.host,this.vars.container,this.vars[r],n);if(void 0!==s[e]){let t=String(s[e]).trim();if("("==t[0]){")"===t[t.length-1]&&(t=t.substring(1,t.length-1))}return t.replace(/;+$/g,"")}return e}compose_argument(e,t,n=[],r,s){t.extra||(t.extra=[]),t.extra.push(n);let i=e.map((e=>{if("text"===e.type)return/^\-\-\w/.test(e.value)?r&&"@var"===r.name?e.value:this.read_var(e.value,t,s):e.value;if("func"===e.type){let r=e.name.substr(1),i=this.pick_func(r);if("function"==typeof i){if(this.check_uniforms(r),this.is_composable(r)){let n,s=S((e.arguments[0]||[])[0]);if("doodle"===r&&/^\d/.test(s)&&(n=s,s=S((e.arguments[1]||[])[0])),!x(s))switch(r){case"doodle":return this.compose_doodle(this.inject_variables(s,t.count),n,structuredClone(t.extra));case"shaders":return this.compose_shaders(s,t);case"pattern":return this.compose_pattern(s,t)}}t.position=e.position;let l=e.arguments.map((r=>i.lazy?(...n)=>this.compose_argument(r,t,n,e,s):this.compose_argument(r,t,n,e,s)));return this.apply_func(i,t,l,r,s)}return e.name}}));return t.extra.pop(),{cluster:e.cluster,value:i.length>=2?{value:i.join("")}:i[0]}}compose_doodle(e,t,n){let r=T("doodle");return this.doodles[r]={doodle:e,arg:t,upextra:n},"${"+r+"}"}compose_shaders(e,{x:t,y:n,z:r}){let s=T("shader");return this.shaders[s]={shader:e,id:"--"+s,cell:k(t,n,r)},"${"+s+"}"}compose_pattern(e,{x:t,y:n,z:r}){let s=T("pattern");return this.pattern[s]={code:e,id:"--"+s,cell:k(t,n,r)},"${"+s+"}"}check_uniforms(e){switch(e){case"ut":case"t":this.uniforms.time=!0;break;case"ux":this.uniforms.mousex=!0;break;case"uy":this.uniforms.mousey=!0;break;case"uw":this.uniforms.width=!0;break;case"uh":this.uniforms.height=!0}}inject_variables(e,t){let n=Object.assign({},this.vars.host,this.vars.container,this.vars[t]),r=[];for(let[e,t]of Object.entries(n))r.push(`${e}:${t};`);return r=r.join(""),r.length?`:doodle{${r}}`+e:e}compose_variables(e,t,n={}){for(let[r,s]of Object.entries(e))n[r]=this.get_composed_value(s,t,n).value;return n}compose_value(e,t,n={}){if(!Array.isArray(e))return{value:"",extra:""};let r="",s=e.reduce(((e,s)=>{switch(s.type){case"text":e+=s.value;break;case"func":{let i=s.name.substr(1),l=this.pick_func(i);if("function"==typeof l)if(this.check_uniforms(i),this.is_composable(i)){let n,r=S((s.arguments[0]||[])[0]);if("doodle"===i&&/^\d/.test(r)&&(n=r,r=S((s.arguments[1]||[])[0])),!x(r))switch(i){case"doodle":e+=this.compose_doodle(this.inject_variables(r,t.count),n,structuredClone(t.extra));break;case"shaders":e+=this.compose_shaders(r,t);break;case"pattern":e+=this.compose_pattern(r,t)}}else{t.position=s.position,s.variables&&this.compose_variables(s.variables,t,n);let o=s.arguments.map((e=>l.lazy?(...r)=>this.compose_argument(e,t,r,s,n):this.compose_argument(e,t,[],s,n))),a=this.apply_func(l,t,o,i,n);x(a)||(e+=a,a.extra&&(r=a.extra))}else e+=s.name}}return e}),"");return{value:s,extra:r}}get_composed_value(e,t,n){let r,s=[];return Array.isArray(e)&&(s=e.reduce(((e,s)=>{let i=this.compose_value(s,t,n||{});return i&&(i.value&&e.push(i.value),i.extra&&(r=i.extra)),e}),[])),{extra:r,group:s,value:s.join(",")}}add_grid_style({fill:e,clip:t,rotate:n,scale:r,translate:s,enlarge:i,skew:l,persp:o,flexRow:a,flexCol:u,p3d:c,border:h}){if(e&&this.add_rule(":host",`background-color:${e};`),t||this.add_rule(":host","contain:none;"),n&&this.add_rule(":container",`rotate:${n};`),r&&this.add_rule(":container",`scale:${r};`),s&&this.add_rule(":container",`translate:${s};`),o){let[e,...t]=o;this.add_rule(":container",`perspective:${e};`),t.length&&this.add_rule(":container",`perspective-origin:${t.join(" ")};`)}if(i&&this.add_rule(":container",`\n width:calc(${i} * 100%);height:calc(${i} * 100%);left:50%;top:50%;transform-origin:0 0;transform:translate(-50%, -50%);`),a&&(this.add_rule(":container","display:flex;"),this.add_rule("cell","flex:1;")),u&&(this.add_rule(":container","display:flex;flex-direction:column;"),this.add_rule("cell","flex:1;")),c){let e="transform-style:preserve-3d;";this.add_rule(":host",e),this.add_rule(":container",e)}void 0!==h&&this.add_rule(":host",`border:1px solid ${h};`)}compose_rule(e,t,n){let r=Object.assign({},t),s=e.property;if("@seed"===s)return"";let i=this.get_composed_value(e.value,r),l=i.extra,o=i.value;if(/^animation(\-name)?$/.test(s)){if(this.props.has_animation=!0,xn(n)){let e=_t[s];e&&o&&(o=e+","+o)}if(r.count>1){let{count:e}=r;switch(s){case"animation-name":o=i.group.map((t=>this.compose_aname(t,e))).join(",");break;case"animation":o=i.group.map((t=>{let n=(t||"").split(/\s+/);return n[0]=this.compose_aname(n[0],e),n.join(" ")})).join(",")}}}if("content"===s){/["']|^none\s?$|^(var|counter|counters|attr|url)\(/.test(o)||(o=`'${o}'`);let e=new Map;return o=o.replace(/var\(\-\-cssd\-u(time|mousex|mousey|width|height)\)/g,(t=>{let n="c"+E(t);return e.set(n,`${n} calc(tan(atan2(${t},1)))`),`counter(${n})`})),`\n ${e.size?`counter-reset:${Array.from(e.values()).join(" ")};`:""} content:${o};`}"transition"===s&&(this.props.has_transition=!0);let a=`${s}:${o};`;if("width"!==s&&"height"!==s||$n(n)||(a+=`--_cell-${s}:${o};`),/^background(\-image)?$/.test(s)&&/\$\{(shader|pattern)/.test(o)&&(a+="background-size:100% 100%;"),/^\-\-/.test(s)&&this.compose_vars(t,n,s,o),/^@/.test(s)&&Gt[s.substr(1)]){let t=s.substr(1),i=Gt[t](o,{is_special_selector:$n(n),grid:r.grid,max_grid:r.max_grid,extra:l});switch(t){case"grid":xn(n)?(a=i.size||"",this.add_grid_style(i)):(a="",this.is_grid_set||(i=Gt[t](o,{is_special_selector:!0,grid:r.grid,max_grid:r.max_grid}),this.add_rule(":host",i.size||""),this.add_grid_style(i))),this.grid=r.grid,this.is_grid_set=!0;break;case"gap":a="",this.is_gap_set||(this.add_rule(":container",`gap:${i};`),this.is_gap_set=!0);break;case"content":{a="";let e=this.compose_selector(r);void 0===i||/\:before|\:after/.test(n)||_n(n)||(this.content[e]=function(e){if(e.startsWith('"')&&e.endsWith('"')||e.startsWith("'")&&e.endsWith("'"))return e.substring(1,e.length-1);return e}(String(i))),this.content[e]=Bt.raw({rules:{doodles:this.doodles}})(this.content[e]||"")}case"seed":a="";break;case"place-cell":case"place":case"position":case"offset":xn(n)||(a=i);break;case"use":e.value.length&&this.compose(r,e.value),a="";break;default:a=i}}return/^grid/.test(s)&&xn(n)&&(this.add_rule(":container",`${s}:${o};`),a=""),a}get_raw_value(e){let t=e.raw()??"",[n,...r]=t.split(e.property);return r=r.join(e.property).replace(/^\s*:\s*/,"").replace(/[;}<]$/,"").trim().replace(/[;}<]$/,""),r}compose_vars(e,t,n,r){let s=e.count;_n(t)&&(s="container"),xn(t)&&(s="host"),this.vars[s]||(this.vars[s]={}),this.vars[s][n]=r}pre_compose_rule(e,t,n){let r=Object.assign({},t),s=e.property,i=Object.assign({},this.vars.host,this.vars.container,this.vars[r.count]);if(/^\-\-/.test(s)){let l=this.get_composed_value(e.value,r,i).value;this.compose_vars(t,n,s,l)}switch(s){case"@grid":{let n=this.get_composed_value(e.value,r,i).value,l=s.substr(1),o=Gt[l](n,{max_grid:t.max_grid});this.grid=o.grid;break}case"@use":e.value.length&&this.pre_compose(r,e.value)}}pre_compose(e,t){x(this.seed)&&((t||this.tokens).forEach((e=>{if("rule"===e.type&&"@seed"===e.property&&(this.seed=this.get_raw_value(e)),"pseudo"===e.type&&xn(e.selector))for(let t of z(e.styles))"rule"===t.type&&"@seed"===t.property&&(this.seed=this.get_raw_value(t))})),x(this.seed)||e.update_random(this.seed)),(t||this.tokens).forEach((t=>{switch(t.type){case"rule":this.pre_compose_rule(t,e);break;case"pseudo":xn(t.selector)&&(t.styles||[]).forEach((t=>{this.pre_compose_rule(t,e,t.selector)}))}}))}compose(e,t,n){this.coords.push(e),(t||this.tokens).forEach(((t,r)=>{if(t.skip)return!1;if(n&&this.grid)return!1;if("@gap"===t.property&&this.is_gap_set)return!1;if("@grid"===t.property&&this.is_grid_set)return!1;switch(t.type){case"rule":this.add_rule(this.compose_selector(e),this.compose_rule(t,e));break;case"pseudo":{t.selector.startsWith(":doodle")&&(t.selector=t.selector.replace(/^\:+doodle/,":host"));let n=$n(t.selector);n&&(t.skip=!0),O(t.selector).forEach((r=>{let s=t.styles.map((t=>this.compose_rule(t,e,r))),i=n?r:this.compose_selector(e,r);this.add_rule(i,s)}));break}case"cond":{let n=t.name.substr(1),r=nn[n];if(r){let s=t.arguments.map((t=>this.compose_argument(t,e))),i=this.apply_func(r,e,s,n);if(Array.isArray(t.addition))for(let e of t.addition)"not"===e&&(i=!i);i&&(i.selector?t.styles.forEach((t=>{"rule"===t.type&&this.add_rule(i.selector.replaceAll("$",this.compose_selector(e)),this.compose_rule(t,e)),"pseudo"===t.type&&t.selector.split(",").forEach((n=>{let r=t.styles.map((t=>this.compose_rule(t,e,n)));this.add_rule((i.selector+n).replaceAll("$",this.compose_selector(e)),r)}))})):this.compose(e,t.styles))}break}case"keyframes":this.keyframes[t.name]||(this.keyframes[t.name]=e=>`\n ${P(t.steps.map((t=>`\n ${this.get_composed_value(t.name,e).value}{${P(t.styles.map((t=>this.compose_rule(t,e))))}}`)))}`)}}))}output(){for(let[e,t]of Object.entries(this.rules))if(_n(e))this.styles.container+=`grid{${P(t)}}`;else{let n=xn(e)?"host":"cells",r=P(t).trim();if(r.length){let t="host"===n?`${e},.host`:e;this.styles[n]+=`${t}{${r}}`}}this.uniforms.time&&(this.styles.container+=`\n:host,.host{animation:${_t.animation};}`,this.styles.keyframes+=`\n @keyframes ${_t["animation-name"]}{from{--${_t.name}:0} to{--${_t.name}:${_t["animation-duration"]/10}}}`),this.coords.forEach(((e,t)=>{for(let[n,r]of Object.entries(this.keyframes)){let s=this.compose_aname(n,e.count);this.styles.keyframes+=`\n ${0===t?`@keyframes ${n}{${r(e)}}`:""} @keyframes ${s}{${r(e)}}`}}));let{keyframes:e,host:t,container:n,cells:r}=this.styles,s=e+t+n;return{props:this.props,styles:{main:s,cells:r,all:s+r},grid:this.grid,seed:this.seed,random:this.random,doodles:this.doodles,shaders:this.shaders,pattern:this.pattern,uniforms:this.uniforms,content:this.content}}}function Sn(e,t,n,r,s,i=[]){let l=new kn(e),o=s||dn(String(n)),a={};function u(e=0,t){return 1==arguments.length&&([e,t]=[0,e]),R(o(),e,t)}function c(...e){let t=e.reduce(((e,t)=>e.concat(t)),[]);return t[~~(o()*t.length)]}function h(e){let t=[...e],n=e.length;for(;n;){let e=~~(o()*n--),r=t[n];t[n]=t[e],t[e]=r}return t}l.pre_compose({x:1,y:1,z:1,count:1,context:{},grid:{x:1,y:1,z:1,count:1},random:o,rand:u,pick:c,shuffle:h,max_grid:r,update_random:function(e){o=dn(String(e))},seed_value:n,rules:l,upextra:i});let{grid:p,seed:f}=l.output();if(p&&(t=p),f?(f=String(f),o=dn(f)):f=n,x(f)&&(f=Date.now(),o=dn(f)),f=String(f),l.seed=f,l.random=o,l.reset(),1==t.z)for(let e=1,n=0;e<=t.y;++e)for(let s=1;s<=t.x;++s)l.compose({x:s,y:e,z:1,count:++n,grid:t,context:a,rand:u,pick:c,shuffle:h,random:o,seed:f,max_grid:r,upextra:i,rules:l});else for(let e=1,n=0;e<=t.z;++e)l.compose({x:1,y:1,z:e,count:++n,grid:t,context:a,rand:u,pick:c,shuffle:h,random:o,seed:f,max_grid:r,rules:l,upextra:i});return l.output()}function jn(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}function An(e,t){return e.includes(t)?e:t+"\n"+e}function Nn(e,t){let n=Je.get(e);if(n)return Promise.resolve(n);let r=document.createElement("canvas"),s=devicePixelRatio||1,i=r.width=e.width*s,l=r.height=e.height*s,o=[],a=r.getContext("webgl2",{preserveDrawingBuffer:!0});if(!a)return Promise.resolve("");let u=An(e.fragment||"","uniform vec2 u_resolution;");u=An(u,"uniform float u_time;"),u=An(u,"uniform float u_timeDelta;"),u=An(u,"uniform int u_frameIndex;"),u=An(u,"uniform vec2 u_seed;"),e.textures.forEach((e=>{let t=`uniform sampler2D ${e.name};`;u=An(u,t)}));/(^|[^\w\_])void\s+mainImage\(\s*out\s+vec4\s+fragColor,\s*in\s+vec2\s+fragCoord\s*\)/gm.test(u)&&(u=`\n#define iResolution vec3(u_resolution, 0)\n#define iTime u_time\n#define iTimeDelta u_timeDelta\n#define iFrame u_frameIndex\n\n${e.textures.map(((e,t)=>`#define iChannel${t} ${e.name}`)).join("\n")}\n${u}\nvoid main(){mainImage(FragColor, gl_FragCoord.xy);}`);let c=function(e,t,n){let r=jn(e,e.VERTEX_SHADER,t),s=jn(e,e.FRAGMENT_SHADER,n),i=e.createProgram();return e.attachShader(i,r),e.attachShader(i,s),e.linkProgram(i),e.getProgramParameter(i,e.LINK_STATUS)||(console.warn("Link failed:"+e.getProgramInfoLog(i)),console.warn("vs info-log:"+e.getShaderInfoLog(r)),console.warn("fs info-log:"+e.getShaderInfoLog(s))),i}(a,e.vertex||"#version 300 es\n in vec4 position;void main(){gl_Position = position;}","#version 300 es\n precision highp float;out vec4 FragColor;"+u),h=a.getAttribLocation(c,"position"),p=a.createBuffer();a.bindBuffer(a.ARRAY_BUFFER,p);a.bufferData(a.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,-1,1,1,-1,1,1,-1]),a.STATIC_DRAW),a.enableVertexAttribArray(h),a.vertexAttribPointer(h,2,a.FLOAT,!1,0,0),a.viewport(0,0,a.drawingBufferWidth,a.drawingBufferHeight),a.clearColor(0,0,0,0),a.clear(a.COLOR_BUFFER_BIT),a.useProgram(c);const f=e=>a.getUniformLocation(c,e),d=f("u_resolution");a.uniform2fv(d,[i,l]),e.textures.forEach(((e,t)=>{o.push(function(e,t,n){const r=e.createTexture();return e.activeTexture(e["TEXTURE"+n]),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!0),e.bindTexture(e.TEXTURE_2D,r),e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,t),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.REPEAT),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),r}(a,e.value,t)),a.uniform1i(a.getUniformLocation(c,e.name),t)}));const m=f("u_seed");m&&a.uniform2f(m,E(t)/1e16,Math.random());const g=f("u_time"),v=f("u_frameIndex"),y=f("u_timeDelta");if(g||y||v){let t=0,n=0;return Promise.resolve(Je.set(e,((i,l,u,c)=>(a.clear(a.COLOR_BUFFER_BIT),e.width===l&&e.height===u||(c.forEach(((e,t)=>{a.bindTexture(a.TEXTURE_2D,o[t]),a.texImage2D(a.TEXTURE_2D,0,a.RGBA,a.RGBA,a.UNSIGNED_BYTE,e.value)})),e.width=l,e.height=u,r.width=l*s,r.height=u*s,a.viewport(0,0,r.width,r.height),a.uniform2fv(d,[r.width,r.height])),g&&a.uniform1f(g,i/1e3),v&&a.uniform1i(v,t++),y&&(a.uniform1f(y,(n-i)/1e3),n=i),a.drawArrays(a.TRIANGLES,0,6),r.toDataURL()))))}return a.drawArrays(a.TRIANGLES,0,6),Promise.resolve(Je.set(e,r.toDataURL()))}function En(e,t){let n=[];for(;e.next();){let{curr:t,next:r}=e.get(),s=!r||t.isSymbol(";")||r.isSymbol("}");if(n.push(t),s)break}return n.length&&(t.value=Tn(n)),t}function Rn(e,t){let n=[],r=[],s=t&&t.type||"",i=[];for(;e.next();){let{prev:l,curr:o,next:a}=e.get(),u=!a||o.isSymbol("}");if("block"===s&&u){a||!n.length||o.isSymbol("}")||(n[n.length-1].value+=";"+o.value),t.value=n;break}if(o.isSymbol("{")&&r.length&&!i.length){let t=zn(r);if(!t.length)continue;let s=Rn(e,{type:"block",name:"unkown",value:[]});t.forEach((e=>{let t=Object.assign({},s,{name:e.name,args:e.args});n.push(t)})),r=[]}else if(o.isSymbol(":")&&r.length&&!i.length){let i=Tn(r);n.push(En(e,{type:"statement",name:i,value:""})),"block"==s&&(t.value=n),r=[]}else o.isSymbol(";")?n.length&&r.length&&(n[n.length-1].value+=";"+Tn(r),r=[]):(o.isSymbol("(")&&i.push(o),o.isSymbol(")")&&i.pop(),r.push(o))}return n.length&&"block"==s&&(t.value=n),s?t:n}function Tn(e){return e.filter(((t,n)=>!t.isSymbol(";")||n!==e.length-1)).map((e=>e.value)).join("")}function zn(e){let t=r(e),n=[],s="",i=[],l=[],o=[];for(;t.next();){let{curr:e,next:r}=t.get();!s.length&&e.isWord()?s=e.value:e.isSymbol("(")?(o.length&&l.push(e.value),o.push(e)):e.isSymbol(")")?(o.pop(),o.length?l.push(e.value):l.length&&(i.push(l.join("")),l=[])):e.isSymbol(",")?o.length?(i.push(l.join("")),l=[]):(l.length&&(i.push(l.join("")),l=[]),s&&(n.push({name:s,args:i}),s="",i=[],l=[])):l.push(e.value)}return s&&n.push({name:s,args:i}),n.filter(((e,t,n)=>n.findIndex((t=>t.name===e.name&&e.args.join("")==t.args.join("")))===t))}function Pn(e){return Rn(r(p(e)))}function Cn(e,t){if("fill"===e.name){let{r:n,g:r,b:s,a:i}=t.get_rgba_color(e.value);return{type:"statement",value:`\ncolor = vec4(${Mn(n/255)}, ${Mn(r/255)}, ${Mn(s/255)}, ${Mn(i)});`}}return"grid"==e.name?{type:"grid",value:e.value}:{type:"statement",value:""}}function Mn(e){return String(e).includes(".")?e:e+".0"}function On(e,t){let n=Pn(e),r=[],s={x:1,y:1};return n.forEach((e=>{if("statement"===e.type){let n=Cn(e,t);"statement"==n.type&&r.push(n.value),"grid"===n.type&&(s=Re(n.value,1/0))}else"block"===e.type&&r.push(function(e,t){if("match"===e.name){let n=e.args[0],r=[];return e.value.forEach((e=>{let n=Cn(e,t);"statement"==n.type&&r.push(n.value)})),`\n if (${n}){${r.join("")}}`}return""}(e,t))})),function(e,{x:t,y:n}){return`\n vec3 mapping(vec2 uv, vec2 grid){vec2 _grid = 1.0/grid;float x = ceil(uv.x/_grid.x);float y = ceil(grid.y - uv.y/_grid.y);float i = x + (y - 1.0) * y;return vec3(x, y, i);} vec4 getColor(float x, float y, float i, float I, float X, float Y, float t){vec4 color = vec4(0, 0, 0, 0);${e} return color;} void main(){vec2 uv = gl_FragCoord.xy/u_resolution.xy;vec2 v = vec2(${t}, ${n});vec3 p = mapping(uv, v);FragColor = getColor(p.x, p.y, p.z, v.x * v.y, v.x, v.y, u_time);}`}(r.join(""),s)}const In=1e3/60;function Wn(e){if("undefined"==typeof getComputedStyle)return"";let t={};if(e.computedStyleMap)for(let[n,r]of e.computedStyleMap())n.startsWith("--")&&(t[n]=r[0][0]);else{let n=getComputedStyle(e);for(let e of n)e.startsWith("--")&&(t[e]=n.getPropertyValue(e))}return function(e){let t=[];for(let[n,r]of Object.entries(e))t.push(n+":"+r);return t.join(";")}(t)}class Ln extends HTMLElement{constructor(){super(),this.doodle=this.attachShadow({mode:"open"}),this.animations=[],this.extra={get_variable:e=>function(e,t){return"undefined"==typeof getComputedStyle?"":getComputedStyle(e).getPropertyValue(t).trim().replace(/^\(|\)$/g,"")}(this,e),get_rgba_color:e=>function(e,t){let n=e.querySelector("style");return n?(n.style.color=t,function(e){let[t,n,r,s=1]=e.replace(/rgba?\((.+)\)/,((e,t)=>t)).split(/,\s*/);return{r:t,g:n,b:r,a:s}}(getComputedStyle(n).color)):{r:0,g:0,b:0,a:1}}(this.shadowRoot,e)}}connectedCallback(e){this.innerHTML?this.load(e):setTimeout((()=>this.load(e)))}disconnectedCallback(){this.cleanup()}update(e){this.cleanup(),e||(e=N(this._code)),this._code!==e&&(this._code=e),this.grid_size||(this.grid_size=this.get_grid());const{x:t,y:n,z:r}=this.grid_size,s=this.get_use();let i="",l="";this.compiled&&(i=this.compiled.content,l=this.compiled.styles.all);const o=this.generate(Ee(s+e,this.extra));let a=o.grid||this.get_grid(),{x:u,y:c,z:h}=a,p=!this.shadowRoot.innerHTML||this.shadowRoot.querySelector("css-doodle")||t!==u||n!==c||r!==h||JSON.stringify(i)!==JSON.stringify(o.content);if(Object.assign(this.grid_size,a),p)return o.grid?this.build_grid(o,a):this.build_grid(this.generate(Ee(s+e,this.extra)),a);let f=this.replace(o);o.props.has_animation&&(this.set_style(l.replace(/animation/g,"x")),this.reflow()),this.set_style(f(Dn(this.grid_size)+o.styles.all))}pause(){this.setAttribute("cssd-paused",!0);for(let e of this.animations)e.pause()}resume(){this.removeAttribute("cssd-paused");for(let e of this.animations)e.resume()}export({scale:e,name:t,download:n,detail:r}={}){return new Promise(((s,i)=>{let l=Wn(this),o=this.doodle.innerHTML,{width:a,height:u}=this.getBoundingClientRect(),c=a*(e=parseInt(e)||1),h=u*e,p=`\n
${o}
`;var f;n||r?function(e,t,n,r){return new Promise(((s,i)=>{let l=`data:image/svg+xml;utf8,${encodeURIComponent(e)}`;function o(){let e=new Image;e.crossOrigin="anonymous",e.src=l,e.onload=()=>{let o=document.createElement("canvas"),a=o.getContext("2d"),u=devicePixelRatio||1;1!=r&&(u=1),o.width=t*u,o.height=n*u,a.drawImage(e,0,0,o.width,o.height);try{o.toBlob((e=>{s({blob:e,source:l,url:URL.createObjectURL(e)})}))}catch(e){i(e)}}}A()?j(l,o,200):o()}))}(p,c,h,e).then((({source:e,url:r,blob:i})=>{if(s({width:c,height:h,svg:p,blob:i,source:e}),n){let e=document.createElement("a");e.download=function(e){return(x(e)?Date.now():String(e).replace(/\/.png$/g,""))+".png"}(t),e.href=r,e.click()}})).catch((e=>{i(e)})):s({width:c,height:h,svg:p})}))}get grid(){return Object.assign({},this.grid_size)}set grid(e){this.attr("grid",e),this.connectedCallback(!0)}get seed(){return this._seed_value}set seed(e){this.attr("seed",e),this.connectedCallback(!0)}get use(){return this.attr("use")}set use(e){this.attr("use",e),this.connectedCallback(!0)}get_max_grid(){return this.hasAttribute("experimental")?256:64}get_grid(){return Re(this.attr("grid"),this.get_max_grid())}get_use(){let e=String(this.attr("use")||"").trim();return/^var\(/.test(e)&&(e=`@use:${e};`),e}cleanup(){if(Je.clear(),this.compiled){for(let e of this.animations)e.cancel();this.animations=[];let{pattern:e,shaders:t}=this.compiled;if(Object.keys(e).length||Object.keys(t).length)for(let e of this.shadowRoot.querySelectorAll("cell"))e.style.cssText=""}}attr(e,t){let n=arguments.length;return 1===n?this.getAttribute(e):2===n?(this.setAttribute(e,t),t):void 0}generate(e){let t=this.get_grid(),n=this.attr("seed")||this.attr("data-seed");x(n)&&(n=Date.now());let r=this.compiled=Sn(e,t,n,this.get_max_grid());return this._seed_value=r.seed,this._seed_random=r.random,r}doodle_to_image(e,t,n){"function"==typeof t&&(n=t,t=null);let r=Ee(e=":doodle{width:100%;height:100%}"+e,this.extra),s=Re(""),i=Sn(r,s,this._seed_value,this.get_max_grid(),this._seed_random,t.upextra),l=i.grid?i.grid:s,o="";if(t&&t.arg){let e=Re(t.arg,1/0);e.x&&e.y&&(t.width=e.x+"px",t.height=e.y+"px",o=`viewBox="0 0 ${e.x} ${e.y}"`)}let a=this.replace(i),u=Un(l,i.content);a(`\n
${u}
`).then((e=>{let t=`data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(e)))}`;A()&&j(t),n(t)}))}pattern_to_image({code:e,cell:t,id:n},r){let s=On(e,this.extra);this.shader_to_image({shader:s,cell:t,id:n},r)}shader_to_image({shader:e,cell:t,id:n},s){const i=this.doodle.getElementById(t);if(!i)return!1;let{width:l,height:o}=i.getBoundingClientRect(),a=devicePixelRatio||1,u=this.seed,c="string"==typeof e?function(e){let t,n,s=r(Pe(p(e,{preserveLineBreak:!0,ignoreInlineComment:!0}))),i=[],l=[],o={textures:[]};for(;s.next();){let{curr:e,next:r}=s.get();if(e.isSymbol("{")){if(i.length)l.push(e);else{let n=Ce(l);Te(n)?(t=n,l=[]):l.push(e)}i.push("{")}else if(e.isSymbol("}"))if(i.pop(),!i.length&&t){let e=Ce(l);t&&e.length&&(t.startsWith("texture")?o.textures.push({name:t,value:e}):o[t]=e,l=[]),t=null}else l.push(e);else $(n)||n==e.pos[1]||(l.push(ze()),n=null),t&&t.startsWith("texture")||e.isWord()&&e.value.startsWith("#")&&(l.push(ze()),n=r.pos[1]),l.push(e)}return $(o.fragment)&&(o.fragment=Ce(l),o.textures=o.textures||[]),o}(e):e;c.width=l,c.height=o;let h=c.textures,f=[];const d=e=>{i.style.setProperty(n,`url(${e})`)},m=e=>{"function"==typeof e?this.animations.push(function(e){let t,n=0,r=0,s=0,i=!1;function l(i){n||(n=i),e(n);let o=i-r;o1e3&&(o=s||1e3),r&&(n+=o),s=o,r=i,t=requestAnimationFrame(l)}return t=requestAnimationFrame(l),{resume(){t&&i&&(i=!1,t=requestAnimationFrame(l))},pause(){t&&(cancelAnimationFrame(t),i=!0)},cancel(){t&&(i=!1,cancelAnimationFrame(t),t=null)}}}((t=>{d(e(t,l,o,f))}))):d(e)},g=(e,t)=>{Promise.all(e.map((({name:e,value:t})=>new Promise((n=>{this.doodle_to_image(t,{width:l,height:o},(t=>{let r=new Image;r.width=l*a,r.height=l*a,r.onload=()=>n({name:e,value:r}),r.src=t}))}))))).then(t)};i.observer||(i.observer=new ResizeObserver((()=>{let e=i.getBoundingClientRect();l=e.width,o=e.height,g(h,(e=>f=e))})),i.observer.observe(i)),h.length?g(h,(e=>{c.textures=f=e,c.width=l,c.height=o,Nn(c,u).then(m).then(s)})):Nn(c,u).then(m).then(s)}load(e){this.cleanup();let t=Ee(this.get_use()+N(this.innerHTML),this.extra),n=this.generate(t);e||this.hasAttribute("click-to-update")&&this.addEventListener("click",(e=>this.update())),this.grid_size=n.grid?n.grid:this.get_grid(),this.build_grid(n,this.grid_size),this._code=this.innerHTML,this.innerHTML=""}replace({doodles:e,shaders:t,pattern:n}){let r=Object.keys(e),s=Object.keys(t),i=Object.keys(n),l=r.length+s.length+i.length;return o=>{if(!l)return Promise.resolve(o);let a=[].concat(r.map((t=>o.includes(t)?new Promise((n=>{let{arg:r,doodle:s,upextra:i}=e[t];this.doodle_to_image(s,{arg:r,upextra:i},(e=>n({id:t,value:e})))})):Promise.resolve(""))),s.map((e=>o.includes(e)?new Promise((n=>{this.shader_to_image(t[e],(t=>n({id:e,value:t})))})):Promise.resolve(""))),i.map((e=>o.includes(e)?new Promise((t=>{this.pattern_to_image(n[e],(n=>t({id:e,value:n})))})):Promise.resolve(""))));return Promise.all(a).then((e=>{for(let{id:t,value:n}of e){let e=`url(${n})`;/^shader|^pattern/.test(t)&&(e=`var(--${t})`),o=o.replaceAll("${"+t+"}",e)}return o}))}}reflow(){this.shadowRoot.querySelector("grid").offsetWidth}build_grid(e,t){const{has_transition:n,has_animation:r}=e.props;let s=n||r;const{uniforms:i,content:l,styles:o}=e;this.doodle.innerHTML=`\n${Un(t,l)}`,s&&this.reflow();let a=this.replace(e);this.set_style(a(Dn(t)+o.all)),i.time&&this.reg_utime(),i.mousex||i.mousey?this.reg_umouse(i):this.off_umouse(),i.width||i.height?this.reg_usize(i):this.off_usize()}reg_umouse(e){if(!this.umouse_fn){this.umouse_fn=t=>{let n=t.detail||t;e.mousex&&this.style.setProperty("--"+$t,n.offsetX),e.mousey&&this.style.setProperty("--"+wt,n.offsetY)},this.addEventListener("pointermove",this.umouse_fn);let t=new CustomEvent("pointermove",{detail:{offsetX:0,offsetY:0}});this.dispatchEvent(t)}}off_umouse(){this.umouse_fn&&(this.style.removeProperty("--"+$t),this.style.removeProperty("--"+wt),this.removeEventListener("pointermove",this.umouse_fn),this.umouse_fn=null)}reg_usize(e){this.usize_observer||(this.usize_observer=new ResizeObserver((()=>{let t=this.getBoundingClientRect();e.width&&this.style.setProperty("--"+kt,t.width),e.height&&this.style.setProperty("--"+St,t.height)})),this.usize_observer.observe(this))}off_usize(){this.usize_observer&&(this.style.removeProperty("--"+kt),this.style.removeProperty("--"+St),this.usize_observer.unobserve(this),this.usize_observer=null)}reg_utime(){if(!this.is_utime_set){try{CSS.registerProperty({name:"--"+_t.name,syntax:"",initialValue:0,inherits:!0})}catch(e){}this.is_utime_set=!0}}set_style(e){if(e instanceof Promise)e.then((e=>{this.set_style(e)}));else{const t=this.shadowRoot.querySelector("style");t&&(t.textContent=e.replace(/\n\s+/g," "))}}}function Dn(e){let{x:t,y:n}=e||{};return`\n *,*::after,*::before,:host,.host{box-sizing:border-box;}:host,.host{display:block;visibility:visible;width:auto;height:auto;contain:strict;--${_t.name}:0\n}:host([hidden]),[hidden]{display:none\n}:host([cssd-paused]),\n:host([cssd-paused]) *{animation-play-state:paused !important\n} grid, cell{display:grid;position:relative;} grid{gap:inherit;grid-template:repeat(${n},1fr)/repeat(${t},1fr)\n} cell{place-items:center\n} svg{position:absolute;} grid, svg{width:100%;height:100%\n}`}function Bn(e,t,n,r,s=""){let i=k(e,t,n);return`${r["#"+i]??""}${s??""}`}function Un(e,t){let{x:n,y:r,z:s}=e||{},i="";if(1==s)for(let e=1;e<=r;++e)for(let r=1;r<=n;++r)i+=Bn(r,e,1,t);else{let e="";for(let n=s;n>=1;n--){e=Bn(1,1,n,t,e)}i=e}return`${i}`}var Fn,Xn;Fn="css-doodle",Xn=Ln,"undefined"===customElements||customElements.get(Fn)||customElements.define(Fn,Xn)}();