forked from css-doodle/css-doodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcss-doodle.min.js
1 lines (1 loc) · 77.8 KB
/
css-doodle.min.js
1
/*! [email protected] */!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,i=0;return{curr:(n=0)=>e[t+n],next(n=1){let s=e[t+=n];return"\n"===s?(i++,r=0):r+=n,s},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,i]})}}function i(e){for(;e.next();){let{curr:n,prev:r}=e.get();if(t.comment(n,r))break}}function s(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:i}=e.get();n+=r;let s=t.symbol(i)||t.space(i)||t.digit(i);if(n.length&&s&&!t.closedTag(r,i))break;e.next()}return n.trim()}function a(e){let n="";for(;!e.end();){let{curr:r,next:i}=e.get();if(n+=r,!t.space(i))break;e.next()}return n}function u(e){let n="",r=!1;for(;!e.end();){let{curr:i,next:s,next2:l,next3:o}=e.get();if(n+=i,r&&t.dot(s))break;if(t.dot(i)&&(r=!0),t.dots(s,l))break;if(t.expWithSign(s,l,o))n+=e.next()+e.next();else if(t.exp(s,l))n+=e.next();else if(!t.digit(s)&&!t.dot(s))break;e.next()}return n}function c(e){let n="0x";for(e.next(2);!e.end();){let{curr:r,next:i}=e.get();if(n+=r,!t.hexNum(i))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))i(f);else if(p.ignoreInlineComment&&t.inlineComment(r,g))s(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),i=t.digit(g)||t.dot(g)&&t.digit(v);if("-"===r&&i&&(!e||!e.isNumber())){let e=u(f);d.push(new n({type:"Number",value:e,pos:y}));continue}let s={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(),s.status="close"):(m.push(r),s.status="open")}d.push(new n(s))}}else if(t.space(r)){let e=a(f),t=h(d),{next:i}=f.get();if(!m.length&&t){let n=t.value,s=l(n)&&")"!==n,o=l(i)&&"("!==i;if(s||o)continue;e=p.preserveLineBreak?r:" "}d.length&&i&&i.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:i}=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 x(t)?"":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,i=0;i<e.length;i++)t=e.charCodeAt(i),n=Math.imul(n^t,2654435761),r=Math.imul(r^t,1597334677);return n=Math.imul(n^n>>>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 T(e,t,n){return t+e*(n-t)}function R(e=""){return e+Math.random().toString(32).substr(2)}function z(e){return x(e)?[]:Array.isArray(e)?e:[e]}function C(e,t="\n"){return(e||[]).join(t)}function M(e,t=1){return x(e)?"":e[e.length-t]}function P(e){return e[0]}function O(e,t={symbol:",",noSpace:!1,verbose:!1}){let n=[],i=[],s=[],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("(")&&s.push(n.value),n.isSymbol(")")&&s.pop(),"open"===n.status&&l.push(n.value),"close"===n.status&&l.pop();let h=!s.length&&!l.length;if(h){let i=t.noSpace&&n.isSpace()&&u(r),s=t.noSpace&&n.isSpace()&&u(e);if(i||s)continue}h&&u(n)?(c(i),o=n.value,i=[]):i.push(n)}return i.length&&c(i),n}function I(e,t){let n,r=[],i=[],s=[],l=!1;for(;e.next();){let{curr:t,next:o}=e.get();t.isSymbol("(")&&!i.length?s.push(t):t.isSymbol(")")&&!i.length&&s.pop(),t.isSymbol("'",'"')&&("open"===t.status?i.push(t):i.pop());let a=!i.length&&!s.length&&(!o||t.isSymbol(";")||o.isSymbol("}"));if(t.isSymbol("'",'"')&&o&&o.isSymbol("}")&&!i.length&&(a=!0),!s.length&&!i.length&&t.isSymbol("{")){let t=X(r);if(!t.length)continue;let i=t.pop(),s=Y(...t,i);for(n=U(L(e,H(i,{type:"block",name:i,value:[]})),s);i=t.pop();)n=U(H(i,{type:"block",name:i,value:[n]}),s);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=[],i=t&&t.type||"",s=[];for(;e.next();){let{prev:l,curr:o,next:a}=e.get();o.isSymbol("(")&&s.push(o.value),o.isSymbol(")")&&s.pop();let u=!a||o.isSymbol("}");if(G(i)&&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 i=X(r);if(!i.length)continue;Y(t.name)&&(i=[B(r)]);let s=i.pop(),l=Y(...i,t.name,s);if("style"===s)n.push({type:"block",name:s,value:W(e)});else{let t=U(L(e,H(s,{type:"block",name:s,value:[]})),l);for(;s=i.pop();)t=U(H(s,{type:"block",name:s,value:[t]}),l);n.push(t)}r=[]}else if(o.isSymbol(":")&&!s.length&&!D(l,a)&&r.length){let s=F(r,(e=>e.isSymbol(","))),l={type:"statement",name:"unkown",value:""};s.length>1&&(l.origin={name:s});let o=I(e,l),a=O(o.value),u=s.length>1&&a.length===s.length;s.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(i)&&(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(i)&&(t.value=n),i?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,...i]=n.split(/#/),s=i[i.length-1];return r&&s&&!t&&(e.name=r,e.value.push({type:"statement",name:"id",value:s})),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=[],i=r(e);for(;i.next();){let{prev:e,curr:r,next:s}=i.get(),l=e&&s&&"x"===r.value&&e.isNumber()&&s.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(","),i=e.origin?e.origin.name.join(","):e.name,s=e.origin?e.origin.value:e.value;r||(n+=s&&s.type?i+":"+Z(s):i+":"+s+";")}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 i=e[t++];return"\n"==i?(r++,n=0):n++,i}}}function re(e,{col:t,line:n}){console.warn(`(at line ${n}, column ${t}) ${e}`)}function ie(e){return function(t,n){let r=t.index(),i="";for(;!t.end();){let n=t.next();if(e(n))break;i+=n}return n&&t.index(r),i}}function se(e,t){return ie((e=>/[^\w@]/.test(e)))(e,t)}function le(e){return ie((e=>/[\s\{]/.test(e)))(e)}function oe(e,t){return ie((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(se(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 i,s=[],l=[],o=[],a="",u="";for(;!e.end();){i=e.curr();let h=e.curr(-1),p=e.index();if(/[\('"`]/.test(i)&&"\\"!==h)o.length&&"("!==i&&i===M(o)?o.pop():o.push(i),a+=i;else if(!n&&("@"==i||"$"===i||"."===h&&t))l.length||(a=a.trimLeft()),a.length&&(l.push(J.text(a)),a=""),l.push(be(e,r));else if(n&&/[)]/.test(i)||!n&&/[,)]/.test(i))if(o.length)")"==i&&"("===M(o)&&o.pop(),a+=i;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);M(t).value="-"+e,s.push(ge(t)),M(l).value=e}if(s.push(ge(l)),[l,a]=[[],""],")"==i)break}else ee[i]&&!/[0-9]/.test(e.curr(-1))&&(i=ee[i]),a+=i;if(!(!t||")"!=e.curr(1)&&";"!=e.curr(1)&&/[0-9a-zA-Z_\-.]/.test(e.curr())||o.length)){l.length&&s.push(ge(l));break}u+=e.range(p,e.index()+1),e.next()}var c;return[me(s),u]}function me(e){let t=M(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=P(t)||{},r=M(t)||{};if("text"==n.type&&"text"==r.type){let e=P(n.value),i=M(r.value);"string"==typeof n.value&&"string"==typeof r.value&&Q.pair_of(e,i)&&(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(),i=e.curr(),s=!1,l="$"===i;for("@"===i?e.next():i="@";!e.end();){n=e.curr();let l=e.curr(1),o="."==n&&/[a-zA-Z@$]/.test(l);if("("==n||o){s=!0,e.next();let[n,l]=de(e,o,te(i),t);if(ye(i)){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(i),t)[0]}}r.arguments=n,r.variables=t;break}if(/[0-9a-zA-Z_\-.%]/.test(n)&&(i+=n),!s&&"("!==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 i=e[r],s=e[r-1],l=e[r+1];if(!(/[\d.]/.test(i)||("x"==i||"-"==i)&&/\d/.test(s)&&/\d/.test(l))){t=e.substring(0,r+1);break}n=i+n}return{fname:t,extra:n}}(i);if(r.name=l?"@$"+i.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(),i=0,s=!0;const l=[];l[i]=[];let o=[],a=[];for(;!e.end();){if(n=e.curr(),s&&Q.white_space(n)){e.next();continue}if(s=!1,"\n"!=n||Q.white_space(e.curr(-1)))if(","!=n||o.length){if((/[;}<]/.test(n)||t(n))&&!a.length){r.value.length&&(l[i].push(r),r=J.text());break}if("@"!==n&&"$"!==n||!/[\w-\(%]/.test(e.curr(1)))if('"'===n||"'"===n){n===M(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[i].push(r),r=J.text()),l[i].push(be(e))}else r.value.length&&(l[i].push(r),r=J.text()),l[++i]=[],s=!0;else r.value+=" ";let u=e.curr();if((";"===u||"}"==u||t(u))&&!a.length)break;e.next()}return r.value.length&&l[i].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,...i]=n.name.trim().split(/\s+/);return n.name=r,n.addition=i,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(),i=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 s=e.index();return r.raw=()=>e.range(i,s).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,i="",s="";i=je(t,n.name),!i&&n.fallback&&n.fallback.every((e=>{if(s=je(t,e.name),s)return i=s,!1}));try{r=Ee(i,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"===se(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 Te(e,t=64){const[n,r,i]=[1,t,t*t];let[s,l,o]=(e+"").replace(/\s+/g,"").replace(/[,\uff0cxX]+/g,"x").split("x").map((e=>parseInt(e)));const a=1==s||1==l?i:r,u=1==s&&1==l?i:n,c={x:v(s||n,1,a),y:v(l||s||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 Re(e){return/^texture\w*$|^(fragment|vertex)$/.test(e)}function ze(){return new n({type:"LineBreak",value:"\n"})}function Ce(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 Me(e){return Ce(e).map((e=>e.value)).join("")}const Pe='xmlns="http://www.w3.org/2000/svg"',Oe='xmlns="http://www.w3.org/1999/xhtml"',Ie='xmlns:xlink="http://www.w3.org/1999/xlink"';function We(e,t){return`url("data:image/svg+xml;utf8,${encodeURIComponent(e)+(t?`#${t}`:"")}")`}function Le(e){return e.includes("<svg")||(e=`<svg ${Pe} ${Ie}>${e}</svg>`),e.includes("xmlns")||(e=e.replace(/<svg([\s>])/,`<svg ${Pe} ${Ie}$1`)),e}function De(e){let t=r(p(e)),n={},i=!1;for(;t.next();){let{prev:e,curr:r,next:s}=t.get(),l=i&&(r.isWord()||r.isSymbol())&&e&&e.isNumber()&&!s;if(r.isNumber())n.value=Number(r.value),i=!0;else{if(!l)break;n.unit=r.value}}return n}function Be(e){return(...t)=>{let n=[],r=[];for(let e of t){let{unit:t,value:i}=De(e);void 0!==t&&n.push(t),void 0!==i&&r.push(i)}let i=e(...r),s=n.find((e=>void 0!==e));return void 0===s?i:Array.isArray(i)?i.map((e=>e+s)):i+s}}function Ue(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)}}var Fe=new class{constructor(){this.cache={}}clear(){this.cache={}}set(e,t){if(x(e))return"";let n=this.getKey(e);return this.cache[n]=t}get(e){let t=this.getKey(e);return this.cache[t]}getKey(e){return E("string"==typeof e?e:JSON.stringify(e))}};function Xe(e,t){return(...n)=>{let r=e+n.join("-");return Fe.get(r)||Fe.set(r,t(...n))}}function qe(e,t){return{type:e,value:t}}function He(e,t,n){let r=0,i=e,s=e=>e>0&&e<1?.1:1,l=arguments.length;1==l&&([e,t]=[s(e),e]),l<3&&(n=s(e));let o=[];for(;(n>=0&&e<=t||n<0&&e>t)&&(o.push(e),e+=n,!(r++>=65535)););return o.length||o.push(i),o}const Ye=Xe("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<t.length-1;++e){let i=t[e];if("-"!=i||"-"!=t[e-1])if("-"!=i)if("-"!=M(r))r.length&&n.push(qe("char",r.pop())),r.push(i);else{r.pop();let e=r.pop();n.push(e?qe("range",[e,i]):qe("char",i))}else r.push(i)}return r.length&&n.push(qe("char",r.pop())),n}(e);return t.flatMap((({type:e,value:t})=>{if("char"==e)return t;let[n,r]=t,i=!1;n>r&&([n,r]=[r,n],i=!0);let s=Ue(He)(n,r);return i&&s.reverse(),s}))}));function Ge(e){return(...t)=>e(...t.flatMap((e=>String(e).startsWith("[")?Ye(e):e)))}class Ve{constructor(e){this.prev=this.next=null,this.data=e}}class Ze{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 Ve(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}}const Ke=[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 Je{constructor(){this.p=[].concat(Ke,Ke)}grad(e,t,n,r){let i=15&e,s=i<8?t:n,l=i<4?n:12==i||14==i?t:r;return(0==(1&i)?s:-s)+(0==(2&i)?l:-l)}noise(e,t,n){let{p:r,grad:i}=this,[s,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[s]+l,p=r[h]+o,f=r[h+1]+o,d=r[s+1]+l,m=r[d]+o,g=r[d+1]+o;return T(c,T(u,T(a,i(r[p],e,t,n),i(r[m],e-1,t,n)),T(a,i(r[f],e,t-1,n),i(r[g],e-1,t-1,n))),T(u,T(a,i(r[p+1],e,t,n-1),i(r[m+1],e-1,t,n-1)),T(a,i(r[f+1],e,t-1,n-1),i(r[g+1],e-1,t-1,n-1))))}}function Qe(e,t){let n={},r=!0;for(let i=0;i<e.length;++i){let s=e[i],l=t[i];if(/=/.test(s)){let[e,i]=O(s,{symbol:"=",noSpace:!0});void 0!==i?(t.includes(e)&&(n[e]=i),r=!1):n[l]=s}else r&&(n[l]=s)}return n}const et=new Map,tt={\u03c0:Math.PI,gcd:(e,t)=>{for(;t;)[e,t]=[t,e%t];return e}},nt={"^":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 rt(e,t,n=[]){let r=[];for(;e.length;){let{name:i,value:s,type:l}=e.shift();if("variable"===l){let e=t[s];_(e)&&(e=Math[s]),_(e)&&(e=lt(s,t,n)),_(e)&&/^\-\D/.test(s)&&(e=lt("-1"+s.substr(1),t,n)),void 0===e&&(e=0),"number"!=typeof e&&(n.push(e),ot(n)?(e=0,n=[]):e=rt(it(e),t,n)),r.push(e)}else if("function"===l){let e=!1;/^\-/.test(i)&&(e=!0,i=i.substr(1));let l,o=s.map((e=>rt(e,t,n))),a=i.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(s))r.push(s);else{let e=r.pop(),t=r.pop();r.push(st(s,Number(t),Number(e)))}}return Number(r[0])||0}function it(e){let t=function(e){if(et.has(e))return et.get(e);let t=String(e),n=[],r="";for(let e=0;e<t.length;++e){let i=t[e];if(nt[i]){let s=M(n);if("="==i&&s&&/^[!<>=]$/.test(s.value))s.value+=i;else if(/^[|&<>]$/.test(i)&&s&&s.value==i)s.value+=i;else if("-"==i&&"e"==t[e-1])r+=i;else if(n.length||r.length||!/[+-]/.test(i)){let{type:e,value:t}=s||{};"operator"==e&&!r.length&&/[^()]/.test(i)&&/[^()]/.test(t)?r+=i:(r.length&&(n.push({type:"number",value:r}),r=""),n.push({type:"operator",value:i}))}else r+=i}else/\S/.test(i)&&(","==i?(n.push({type:"number",value:r}),r="",n.push({type:"comma",value:i})):"!"==i?(n.push({type:"number",value:r}),n.push({type:"operator",value:i}),r=""):r+=i)}return r.length&&n.push({type:"number",value:r}),et.set(e,n),n}(e);const n=[],r=[];for(let e=0;e<t.length;++e){let{type:i,value:s}=t[e],l=t[e+1]||{};if("number"==i)if("("==l.value&&/[^\d.\-]/.test(s)){let n="",i=[],l=[];for(e+=1;void 0!==t[e++];){let r=t[e];if(void 0===r)break;let s=r.value;if(")"==s){if(!i.length)break;i.pop(),n+=s}else if("("==s&&i.push(s),","!=s||i.length)n+=s;else{let e=it(n);e.length&&l.push(e),n=""}}n.length&&l.push(it(n)),r.push({type:"function",name:s,value:l})}else/[^\d.\-]/.test(s)?r.push({type:"variable",value:s}):r.push({type:"number",value:s});else if("operator"==i)if("("==s)n.push(s);else if(")"==s){for(;n.length&&"("!=M(n);)r.push({type:"operator",value:n.pop()});n.pop()}else{for(;n.length&&nt[M(n)]>=nt[s];){let e=n.pop();/[()]/.test(e)||r.push({type:"operator",value:e})}n.push(s)}}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<n;case">":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<<n;case">>":return t>>n}}function lt(e,t,n){let[r,i,s]=e.match(/([\d.\-]+)(.*)/)||[],l=t[s];return void 0===l?l:"number"==typeof l?Number(i)*l:(n.push(l),ot(n)?(n=[],0):i*rt(it(l),t,n))}function ot(e){if(e.length>50)return!0;let t=M(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 at(e,t){return rt(it(e),Object.assign({},tt,t))}const ut={name:"cssd-utime","animation-name":"cssd-utime-animation","animation-duration":31536e6,"animation-iteration-count":"infinite","animation-delay":"0s","animation-direction":"normal","animation-fill-mode":"none","animation-play-state":"running","animation-timing-function":"linear"};ut.animation=`\n ${ut["animation-duration"]}ms\n ${ut["animation-timing-function"]} ${ut["animation-delay"]} ${ut["animation-iteration-count"]} ${ut["animation-name"]}`;const ct="cssd-umousex",ht="cssd-umousey",pt="cssd-uwidth",ft="cssd-uheight";function dt(e){let t=r(p(e)),n={},i={commands:[],valid:!0};for(;t.next();){let{curr:e}=t.get();if(!e.isSpace()&&!e.isSymbol(","))if(e.isWord())n.name&&(i.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",i.valid=!1);else if(n.value){let t=e.value;e.isNumber()&&(t=Number(e.value)),n.value.push(t)}else n.name||(i.valid=!1)}return n.name&&i.commands.push(n),i}const mt=function(){let e=0;return(t="")=>`${t}-${++e}`}();class gt{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 vt(this.body);let e=[""],t=[];for(let[t,n]of Object.entries(this.attrs))n=vt(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}>`:`<${this.name}${e.join(" ")}/>`}}function vt(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 yt(e,t,n,r){let i;if(t||(t=new gt("root")),"block"===e.type)if("style"===e.name){let n=new gt("style");n.append(e.value),t.append(n)}else{let s=new gt(e.name);if(r||(r=s).attr("xmlns",Pe.split("=")[1]),"defs"===e.name){let e=r.findSpareDefs();e&&(s=e)}for(let t of e.value){e.parent=n;let l=yt(t,s,e,r);l&&(i=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?i=t.value:(a||l)&&(i=mt(e.name),s.attr("id",i))}let u=t.find(s);if(u)u.merge(s);else if("defs"===e.name){let e=r.findSpareDefs();e&&!s.attrs.id?s.id!==e.id&&e.append(s.body):r.append(s)}else t.append(s)}if("statement"===e.type&&!e.variable)if("content"===e.name){let n=new gt("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 i=e.value;if(i&&"block"===i.type){let t=yt(e.value,r,e,r);x(t)?i="":(i=`url(#${t})`,"xlink:href"!==e.name&&"href"!==e.name||(i=`#${t}`))}if(/viewBox/i.test(e.name))i=function(e){let t=e.detail.value,n=e.detail.padding||e.detail.p||e.detail.expand;if(!t.length)return"";let[r,i,s,l]=t;return n&&([r,i,s,l]=[r-n,i-n,s+2*n,l+2*n]),`${r} ${i} ${s} ${l}`}(e),i&&t.attr(e.name,i);else if("draw"!==e.name&&"animate"!==e.name||"path"!==(s=n&&n.name)&&"line"!==s&&"circle"!==s&&"ellipse"!==s&&"rect"!==s&&"polygon"!==s&&"polyline"!==s)t.attr(e.name,i);else{let[e,n]=String(i).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 gt("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",Ie.split("=")[1])}var s;return n?i:r.toString()}function bt(e){return yt(e)}const xt=["auto","reverse"],_t=["deg","rad","grad","turn"];function $t(e){let t=r(p(e)),n=!1,i="",s={direction:"",angle:""};for(;t.next();){let{prev:e,curr:r,next:l}=t.get();if(r.isWord()&&xt.includes(r.value))s.direction=r.value,n=!0;else if(r.isNumber())s.angle=Number(r.value),n=!0;else if(r.isWord()&&e&&e.isNumber()&&_t.includes(r.value))i=r.value;else if(r.isSpace()&&""!==s.direction&&""!==s.angle)break}return n||(s.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})}(s,i)}function wt(e,t,n){return["fill-rule","fill"].includes(e)?t:n?`-1 * (${t})`:t}function kt(e){return e.map((e=>e.value)).join("")}const{cos:St,sin:jt,abs:At,atan2:Nt,PI:Et}=Math,Tt={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 Rt{constructor(e,t,n){this.x=e,this.y=t,this.extra=n}valueOf(){return this.x+" "+this.y}toString(){return this.valueOf()}}function zt(e,t){t||(t=e=>[St(e),jt(e)]);let n,r,i=e.split||180,s=e.turn||1,l=e.frame,o=e.fill||e["fill-rule"],a=$t(e.direction||e.dir||""),u=e.unit,c=2*Et*s/i,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 Rt(e,"",""));let[i,s]=Ct(e,-t,p),[l,o]=Ct(n,-r,p),c=function(e,t,n,r,i){let s=180*Nt(t+r,e-n)/Et;"reverse"===i.direction&&(s-=180);i.direction||(s=90);i.angle&&(s+=i.angle);return s}(i,s,l,o,a);void 0!==u&&"%"!==u?"none"!==u&&(i+=u,s+=u):(i=50*(i+1)+"%",s=50*(s+1)+"%"),h.push(new Rt(i,s,c))};"nonzero"!=o&&"evenodd"!=o||f([o,"",""]);for(let e=0;e<i;++e){let r=t(c*e,e);e||(n=r),f(r)}if(void 0!==l){f(n);let e=l/100;s>1&&(e*=2),0==e&&(e=.002);for(let n=0;n<i;++n){let i=-c*n,[s,l,o=0,a=0]=t(i,n),u=Nt(l+a,s-o),h=[s-e*St(u),l-e*jt(u)];n||(r=h),f(h)}f(r),f(n)}return h}function Ct(e,t,n){let[r,i=r]=O(n).map(Number);return[e*r,t*i]}function Mt(e,{min:t,max:n}){let r=v(parseInt(e.vertices||e.points||e.split)||0,t,n),i=$(e.x)?"cos(t)":e.x,s=$(e.y)?"sin(t)":e.y,l=$(e.r)?"":e.r,o=$(e.t)?"":e.t,{unit:a,value:u}=De(l);return a&&!e[a]&&"t"!==a&&($(e.unit)&&(e.unit=a),l=e.r=u),e.degree&&(e.rotate=e.degree),e.origin&&(e.move=e.origin),e.split=r,zt(e,((t,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+At(t-e)/(r-1)*n)}),u=at(i,a),c=at(s,a),h=0,p=0;if(l){let e=at(l,a);0==e&&(e=1e-5),o&&(t=at(o,a)),u=e*St(t),c=e*jt(t)}return e.rotate&&([u,c]=function(e,t,n){let r=-Et/180*n;return[e*St(r)-t*jt(r),t*St(r)+e*jt(r)]}(u,c,Number(e.rotate)||0)),e.move&&([u,c,h,p]=function(e,t,n){let[r,i=r]=O(n).map(Number);return[e+(r||0),t-(i||0),r,i]}(u,c,e.move)),[u,c,h,p]}))}function Pt(e,t=3,n=3600,i){let s="",[l,...o]=O(e),a=!1;switch(typeof Tt[l]){case"function":s=Tt[l](...o),a=!0;break;case"string":s=Tt[l],a=!0;break;default:s=e}let u=function(e){let t,n=r(p(e)),i={},s=[],l=!1;for(;n.next();){let{prev:e,curr:r,next:o}=n.get();if(r.isSymbol(":")&&!t)t=kt(s),s=[];else if(r.isSymbol(";")&&t)i[t]=wt(t,kt(s),l),s=[],t=null,l=!1;else if(!r.isSymbol(";")){let n=e&&e.isSymbol("-"),i=o&&o.isSymbol("-"),a=r.isSymbol("-");t||s.length||!a||n||i||o&&o.isSymbol(":")?s.push(r):l=!0}}return s.length&&t&&(i[t]=wt(t,kt(s),l)),i}(s);return"function"==typeof i&&(u=i(u)),{rules:u,points:Mt(u,{min:t,max:n}),preset:a}}function Ot(e){return w(((t,n,...r)=>{if(!r||!n)return"";let i=S(n()),s=i;/\D/.test(i)&&!/\d+[x-]\d+/.test(i)&&(s=at(i),0===s&&(s=i));let l=Math.random();return function(e,t){let[n,r=1]=String(e).split(/[x-]/),[i,s]=[Math.ceil(n),Math.ceil(r)];_(i)&&(i=1),_(s)&&(s=1),n=v(i,0,65536),r=v(s,0,65536);let l=n*r,o=[],a=1;if(/x/.test(e))for(let e=1;e<=r;++e)for(let i=1;i<=n;++i)o.push(t(a,i,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}(s,((...e)=>r.map((t=>S(t(...e,l)))).join(","))).join(e)}))}function It(e,t,n){return e[t]||(e[t]=new Ze(1024)),e[t].push(n),n}function Wt(e){return-1*e}function Lt(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 Dt(e){return t=>{if($(t)||$(e))return e;if(/^[\+\*\-\/%][\-\.\d\s]/.test(t)){let n=t[0],{unit:r="",value:i}=De(t.substr(1).trim()||0);return/^var/.test(e)?`calc((${e} ${n} ${i}) * 1${r})`:Lt(n,e,i)+r}if(/[\+\*\-\/%]$/.test(t)){let n=t.substr(-1),{unit:r="",value:i}=De(t.substr(0,t.length-1).trim()||0);return/^var/.test(e)?`calc((${i} ${n} ${e}) * 1${r})`:Lt(n,i,e)+r}{let{unit:n="",value:r}=De(t||0);return e+r+n}}}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),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=M(e);return t?Dt(t[0]):"@n"},nx({extra:e}){let t=M(e);return t?Dt(t[1]):"@nx"},ny({extra:e}){let t=M(e);return t?Dt(t[2]):"@ny"},N({extra:e}){let t=M(e);return t?Dt(t[3]):"@N"},nN({extra:e}){let t=M(e);return t?Dt(t[0]/t[3]):"@nN"},m:Ot(","),M:Ot(" "),\u00b5:Ot(""),p:({context:e,pick:t})=>Ge(((...n)=>{n.length||(n=e.last_pick_args||[]);let r=t(n);return e.last_pick_args=n,It(e,"last_pick",r)})),P({context:e,pick:t,position:n}){let r="P-counter"+n;return Ge(((...n)=>{let i=!0;n.length||(n=e.last_pick_args||[],i=!1);let s=e.last_pick,l=s?s.last(1):"";if(i&&(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,i&&(e[r].last_pick=o),It(e,"last_pick",o)}))},pl({context:e,extra:t,position:n}){let r=M(t),i="pl-counter"+n+(r?M(r):"");return Ge(((...t)=>{e[i]||(e[i]=0),e[i]+=1;let n=t.length,s=r&&r[6];x(s)&&(s=e[i]);let l=t[(s-1)%n];return It(e,"last_pick",l)}))},pr({context:e,extra:t,position:n}){let r=M(t),i="pr-counter"+n+(r?M(r):"");return Ge(((...t)=>{e[i]||(e[i]=0),e[i]+=1;let n=t.length,s=r&&r[6];x(s)&&(s=e[i]);let l=t[n-(s-1)%n-1];return It(e,"last_pick",l)}))},pd({context:e,extra:t,position:n,shuffle:r}){let i=M(t),s=i?M(i):"",l="pd-counter"+n+s,o="pd-values"+n+s;return Ge(((...t)=>{e[l]||(e[l]=0),e[l]+=1,e[o]||(e[o]=r(t||[]));let n=t.length,s=i&&i[6];x(s)&&(s=e[l]);let a=(s-1)%n,u=e[o][a];return It(e,"last_pick",u)}))},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)?Ue:Be)(t)(...n);return It(e,"last_rand",r)},rn({x:e,y:t,context:n,position:r,grid:i,extra:s,random:l}){let o="noise-2d"+r,a=o+"offset-x",u=o+"offset-y",[c,h,p,f,d,m]=M(s)||[],g=c&&f;return(...r)=>{let{from:s=0,to:c=s,frequency:f=1,scale:y=1,octave:x=1}=Qe(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&&([s,c]=[0,s]),n[o]||(n[o]=new Je),n[a]||(n[a]=l()),n[u]||(n[u]=l());let _=b(s)&&b(c)?Ue:Be,$=n[o],w=n[a],k=n[u],S=(g?(h-1)/d:(e-1)/i.x)+w,j=(g?(p-1)/m:(t-1)/i.y)+k;(d<=1||i.x<=1)&&(S=0),(m<=1||i.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;e<x;++e){let t=2*e;A+=$.noise(S*f*t,j*f*t,0)*(y/t)}let N=_(((e,t)=>function(e,t,n,r=1){let i=Math.sqrt(.5)*r,[s,l]=[-i,i];return T((e-s)/(l-s),t*r,n*r)}(A,e,t,y)));return It(n,"last_rand",N(s,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,i=0,s=[];if(!r)return"";n.forEach((e=>{let[t,n]=O(e);void 0!==n?s.push(n):i+=1}));let l=s.length?`(100% - ${s.join(" - ")}) / ${i}`:`100% / ${r}`;return n.map(((e,n)=>{if(s.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)=>at(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=bt(V(n))}return We(Le(n))})),"svg-filter":w(((e,...t)=>{let n=t.map((e=>S(e()))),r=n.join(","),i=R("filter-");if(n.every((e=>/^[\-\d.]/.test(e)||/^(\w+)/.test(e)&&!/[{}<>]/.test(e)))){let{frequency:t,scale:i,octave:s,seed:l=e.seed,blur:o,erode:a,dilate:u}=Qe(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);s=s?`numOctaves:${s};`:"",r+=`\n feTurbulence{type:fractalNoise;baseFrequency:${e} ${n};seed:${l};${s}}`,i&&(r+=`\n feDisplacementMap{in:SourceGraphic;scale:${i};}`)}}if(!r.startsWith("<")){r=bt(V(r,{type:"block",name:"filter"}))}return We(Le(r).replace(/<filter([\s>])/,`<filter id="${i}"$1`),i)})),"svg-pattern":w(((e,...t)=>We(bt(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:i}=Pt(n,3,65536,(e=>(delete e.frame,e.unit="none",e["stroke-width"]??=.01,e.stroke??="currentColor",e.fill??="none",e))),s=`points:${i};`,l="";for(let e of Object.keys(r))/^(stroke|fill|clip|marker|mask|animate|draw)/.test(e)&&(l+=`${e}:${r[e]};`);return We(bt(V(`\n viewBox:-1 -1 2 2 p ${Number(r["stroke-width"])/2};polygon{${l} ${s}}`)))})),var:()=>e=>`var(${S(e)})`,ut:()=>Dt(`var(--${ut.name})`),uw:()=>Dt(`var(--${pt})`),uh:()=>Dt(`var(--${ft})`),ux:()=>Dt(`var(--${ct})`),uy:()=>Dt(`var(--${ht})`),plot({count:e,context:t,extra:n,position:r,grid:i}){let s="offset-points"+r,l=M(n);return(...n)=>{let r=n.join(","),[o=e,a,u,c=i.count]=l||[];if(!t[s]){let{points:e}=Pt(r,1,65536,(e=>(delete e.fill,delete e["fill-rule"],delete e.frame,e.points=c,e)));t[s]=e}return t[s][o-1]}},Plot({count:e,context:t,extra:n,position:r,grid:i}){let s="Offset-points"+r,l=M(n);return(...n)=>{let r=n.join(","),[o=e,a,u,c=i.count]=l||[];if(!t[s]){let{points:e}=Pt(r,1,65536,(e=>(delete e.fill,delete e["fill-rule"],delete e.frame,e.points=c,e.unit=e.unit||"none",e)));t[s]=e}return t[s][o-1]}},shape:()=>Xe("shape-function",((...e)=>{let t=e.join(","),{points:n}=Pt(t);return`polygon(${n.join(",")})`})),doodle:()=>e=>e,shaders:()=>e=>e,pattern:()=>e=>e,invert:()=>e=>{let t=dt(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=dt(e);return t.valid?t.commands.map((({name:e,value:t})=>{switch(e){case"h":case"H":return e+t.map(Wt).join(" ");default:return e+t.join(" ")}})).join(" "):e},flipV:()=>e=>{let t=dt(e);return t.valid?t.commands.map((({name:e,value:t})=>{switch(e){case"v":case"V":return e+t.map(Wt).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=dt(t.join(","));if(n.valid){let e=[];for(let t=n.commands.length-1;t>=0;--t){let{name:r,value:i}=n.commands[t];e.push(r+i.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,i=[n.join(t)];for(let e=0;e<r;++e){let e=n.shift();n.push(e),i.push(n.join(t))}return i},mirror:()=>(...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 i="once-counter"+n;return x(e[i])?e[i]=r.map((e=>S(e()))).join(","):e[i]})),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`<css-doodle>${r[n].doodle}</css-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`<img src="${t}" alt="" />`}catch(e){}return t}},{index:"i",col:"x",row:"y",depth:"z",rand:"r",pick:"p",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"};let Xt=[];function qt(e){let t=new RegExp(`\\-?${e}\\-?`);return function(e){if(!Xt.length){let e=new Set;if("undefined"!=typeof document)for(let t in document.head.style)t.startsWith("-")||e.add(t.replace(/[A-Z]/g,"-$&").toLowerCase());e.has("grid-gap")||e.add("grid-gap"),Xt=Array.from(e)}return e instanceof RegExp?Xt.filter((t=>e.test(t))):Xt}(t).map((e=>e.replace(t,""))).reduce(((e,t)=>(e[t]=t,e)),{})}const Ht=qt("webkit"),Yt=qt("moz");function Gt(e,t){return Ht[e]?`-webkit-${t} ${t}`:Yt[e]?`-moz-${t} ${t}`:t}const Vt="--_cell-width",Zt="--_cell-height",Kt={center:"50%",left:"0%",right:"100%",top:"50%",bottom:"50%"},Jt={center:"50%",top:"0%",bottom:"100%",left:"50%",right:"50%"};var Qt=y({size(e,{is_special_selector:t,grid:n}){let[r,i=r,s]=O(e);Ut[r]&&([r,i]=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,i));let l=`width:${r};height:${i};`;return"auto"!==r&&"auto"!==i||(s&&(/^\(.+\)$/.test(s)?s=s.substring(1,s.length-1):/^calc/.test(s)||(s=`calc(${s})`),t||(l+=`aspect-ratio:${s};`)),t&&(l+=`aspect-ratio:${s||n.ratio};`)),t||(l+=`${Vt}:${r};${Zt}:${i};`),l},place(e,{extra:t}){let[n,r="50%"]=O(e);n=Kt[n]||n,r=Jt[r]||r;let i=`var(${Vt}, 25%)`,s=`var(${Zt}, 25%)`;return`\n position:absolute;left:${n};top:${r};width:${i};height:${s};margin-left:calc(${i} / -2);margin-top:calc(${s} / -2);grid-area:unset;--plot-angle:${t||0};rotate:${t||0}deg;`},grid(e,t){let n={clip:!0};/no\-*clip/i.test(e)&&(n.clip=!1,e=e.replace(/no\-*clip/i,""));let r=O(e,{symbol:["/","+","^","*","|","-","~","\u2206"],noSpace:!0,verbose:!0});for(let{group:e,value:i}of r)"+"===e&&(n.scale=i),"^"===e&&(n.enlarge=i),"*"===e&&(n.rotate=i),"~"===e&&(n.translate=i),"\u2206"===e&&(n.persp=O(i,{symbol:" "})),"/"===e&&(void 0===n.size?n.size=this.size(i,t):n.fill=i),"|"!==e&&"-"!=e&&""!=e||n.grid||(n.grid=Te(i,t.max_grid),"|"===e&&(n.flexCol=!0),"-"===e&&(n.flexRow=!0));return n},gap:e=>e,seed:e=>e,shape:Xe("shape-property",(e=>{let{points:t,preset:n}=Pt(e);if(!n)return"";let r="clip-path";return Gt(r,`${r}:polygon(${t.join(",")});`)})),use(e){if(e.length>2)return e},content:e=>e},{"place-cell":"place",offset:"place",position:"place"});function en(e,t){return"+"===t?e:"-"===t?-1*e:e}function tn(e){return e.reduce(((e,t)=>e+t),0)}function nn(e){return e%2}function rn(e){return!nn(e)}function sn(e){let t="";return t=0==e?"$:hover":e>0?`$:hover ${"+*".repeat(e)}`:`:has(+ ${"*+".repeat(Math.abs(e+1))} $:hover)`,t}function ln(e,t){if("even"===e)return rn(t);if("odd"===e)return nn(t);if("n"==e)return!0;let{a:n,b:i,error:s}=function(e){let t,n,i=r(p(e)),s=[],l=[];for(;i.next();){let{prev:e,curr:r,next:o}=i.get(),a=r.value;if(r.isSymbol()){if("+"!==a&&"-"!==a){n="Unexpected "+r.value;break}t=a}else if(r.isNumber()){if((s.length||l.length)&&!t){n="Syntax error";break}if(a=en(Number(a),t),t=null,o&&"n"===o.value){s.push(a),i.next();continue}l.push(a)}else if("n"===a){if((s.length||l.length)&&!t){n="Syntax error";break}s.push(en(1,t)),t=null}else if(!r.isSpace()){n="Unexpected "+a;break}}return n?{a:0,b:0,error:n}:{a:tn(s),b:tn(l)}}(e);if(s)return!1;if(0===n)return t===i;{let e=(t-i)/n;return e>=0&&Number.isInteger(e)}}var on,an=y({at:({x:e,y:t})=>(n,r)=>e==n&&t==r,nth:({count:e,grid:t})=>(...t)=>{for(let n of t)if(ln(n,e))return!0},y:({y:e,grid:t})=>(...t)=>{for(let n of t)if(ln(n,e))return!0},x:({x:e,grid:t})=>(...t)=>{for(let n of t)if(ln(n,e))return!0},even:({x:e,y:t})=>n=>nn(e+t),odd:({x:e,y:t})=>n=>rn(e+t),random:({random:e,count:t,x:n,y:r,grid:i})=>(s=.5)=>/\D/.test(s)?e()<at("("+s+")",{x:n,X:i.x,y:r,Y:i.y,i:t,I:i.count,random:e}):e()<s,match:({count:e,grid:t,x:n,y:r,random:i})=>s=>!!at("("+s+")",{x:n,X:t.x,y:r,Y:t.y,i:e,I:t.count,random:i}),hover:({count:e,x:t,y:n,grid:r,random:i})=>(...e)=>{let i=[];e.length||i.push(sn(0));for(let s of e){let[e,l]=String(s).split(/\s+/);if(e=Number(e),l=Number(l),Number.isNaN(l)&&!Number.isNaN(e)&&i.push(sn(e)),!Number.isNaN(e)&&!Number.isNaN(l)){let s=e+t,o=l+n;if(s>=1&&s<=r.x&&o>=1&&o<=r.y){let t=l*r.y+e;i.push(sn(t))}}}return!!i.length&&{selector:i.join(",")}}},{col:"x",row:"y"}),un=globalThis,cn=Math,hn=[],pn=256,fn=6,dn="random",mn=cn.pow(pn,fn),gn=cn.pow(2,52),vn=2*gn,yn=pn-1;function bn(e,t,n){var r=[],i=wn($n((t=1==t?{entropy:!0}:t||{}).entropy?[e,kn(hn)]:null==e?function(){try{var e;return on&&(e=on.randomBytes)||(e=new Uint8Array(pn),(un.crypto||un.msCrypto).getRandomValues(e)),kn(e)}catch(e){var t=un.navigator,n=t&&t.plugins;return[+new Date,un,n,un.screen,kn(hn)]}}():e,3),r),s=new xn(r),l=function(){for(var e=s.g(fn),t=mn,n=0;e<gn;)e=(e+n)*pn,t*=pn,n=s.g(1);for(;e>=vn;)e/=2,t/=2,n>>>=1;return(e+n)/t};return l.int32=function(){return 0|s.g(4)},l.quick=function(){return s.g(4)/4294967296},l.double=l,wn(kn(s.S),hn),(t.pass||n||function(e,t,n,r){return r&&(r.S&&_n(r,s),e.state=function(){return _n(s,{})}),n?(cn[dn]=e,t):e})(l,i,"global"in t?t.global:this==cn,t.state)}function xn(e){var t,n=e.length,r=this,i=0,s=r.i=r.j=0,l=r.S=[];for(n||(e=[n++]);i<pn;)l[i]=i++;for(i=0;i<pn;i++)l[i]=l[s=yn&s+e[i%n]+(t=l[i])],l[s]=t;(r.g=function(e){for(var t,n=0,i=r.i,s=r.j,l=r.S;e--;)t=l[i=yn&i+1],n=n*pn+l[yn&(l[i]=l[s=yn&s+t])+(l[s]=t)];return r.i=i,r.j=s,n})(pn)}function _n(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function $n(e,t){var n,r=[],i=typeof e;if(t&&"object"==i)for(n in e)try{r.push($n(e[n],t-1))}catch(e){}return r.length?r:"string"==i?e:e+"\0"}function wn(e,t){for(var n,r=e+"",i=0;i<r.length;)t[yn&i]=yn&(n^=19*t[yn&i])+r.charCodeAt(i++);return kn(t)}function kn(e){return String.fromCharCode.apply(0,e)}function Sn(e){return/^\:(host|doodle)/.test(e)}function jn(e){return/^\:(container|parent)/.test(e)}function An(e){return Sn(e)||jn(e)}wn(cn.random(),hn);const Nn={};for(let e of Object.getOwnPropertyNames(Math))Nn[e]=()=>(...t)=>"number"==typeof Math[e]?Math[e]:(t=t.map((e=>at(S(e)))),Math[e](...t));class En{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]||Nn[e]}apply_func(e,t,n,r,i={}){let s=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 s){if(r.startsWith("$")){let e=Object.assign({},this.vars.host,this.vars.container,this.vars[t.count],i),n={},o="";for(let[t,r]of Object.entries(e))n[t.substr(2)]=r;return r.length>1&&(o=r.split("$")[1]??""),s(l,n)+o}return s(...l)}return s}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,i=Object.assign({},this.vars.host,this.vars.container,this.vars[r],n);if(void 0!==i[e]){let t=String(i[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,i){t.extra||(t.extra=[]),t.extra.push(n);let s=e.map((e=>{if("text"===e.type)return/^\-\-\w/.test(e.value)?r&&"@var"===r.name?e.value:this.read_var(e.value,t,i):e.value;if("func"===e.type){let r=e.name.substr(1),s=this.pick_func(r);if("function"==typeof s){if(this.check_uniforms(r),this.is_composable(r)){let n,i=S((e.arguments[0]||[])[0]);if("doodle"===r&&/^\d/.test(i)&&(n=i,i=S((e.arguments[1]||[])[0])),!x(i))switch(r){case"doodle":return this.compose_doodle(this.inject_variables(i,t.count),n);case"shaders":return this.compose_shaders(i,t);case"pattern":return this.compose_pattern(i,t)}}t.position=e.position;let l=e.arguments.map((r=>s.lazy?(...n)=>this.compose_argument(r,t,n,e,i):this.compose_argument(r,t,n,e,i)));return this.apply_func(s,t,l,r,i)}return e.name}}));return t.extra.pop(),{cluster:e.cluster,value:s.length>=2?{value:s.join("")}:s[0]}}compose_doodle(e,t){let n=R("doodle");return this.doodles[n]={doodle:e,arg:t},"${"+n+"}"}compose_shaders(e,{x:t,y:n,z:r}){let i=R("shader");return this.shaders[i]={shader:e,id:"--"+i,cell:k(t,n,r)},"${"+i+"}"}compose_pattern(e,{x:t,y:n,z:r}){let i=R("pattern");return this.pattern[i]={code:e,id:"--"+i,cell:k(t,n,r)},"${"+i+"}"}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,i]of Object.entries(e))n[r]=this.get_composed_value(i,t,n).value;return n}compose_value(e,t,n={}){if(!Array.isArray(e))return{value:"",extra:""};let r="",i=e.reduce(((e,i)=>{switch(i.type){case"text":e+=i.value;break;case"func":{let s=i.name.substr(1),l=this.pick_func(s);if("function"==typeof l)if(this.check_uniforms(s),this.is_composable(s)){let n,r=S((i.arguments[0]||[])[0]);if("doodle"===s&&/^\d/.test(r)&&(n=r,r=S((i.arguments[1]||[])[0])),!x(r))switch(s){case"doodle":e+=this.compose_doodle(this.inject_variables(r,t.count),n);break;case"shaders":e+=this.compose_shaders(r,t);break;case"pattern":e+=this.compose_pattern(r,t)}}else{t.position=i.position,i.variables&&this.compose_variables(i.variables,t,n);let o=i.arguments.map((e=>l.lazy?(...r)=>this.compose_argument(e,t,r,i,n):this.compose_argument(e,t,[],i,n))),a=this.apply_func(l,t,o,s,n);x(a)||(e+=a,a.extra&&(r=a.extra))}else e+=i.name}}return e}),"");return{value:i,extra:r}}get_composed_value(e,t,n){let r,i=[];return Array.isArray(e)&&(i=e.reduce(((e,i)=>{let s=this.compose_value(i,t,n||{});return s&&(s.value&&e.push(s.value),s.extra&&(r=s.extra)),e}),[])),{extra:r,group:i,value:i.join(",")}}add_grid_style({fill:e,clip:t,rotate:n,scale:r,translate:i,enlarge:s,skew:l,persp:o,flexRow:a,flexCol:u}){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};`),i&&this.add_rule(":container",`translate:${i};`),o){let[e,...t]=o;this.add_rule(":container",`perspective:${e};`),t.length&&this.add_rule(":container",`perspective-origin:${t.join(" ")};`)}s&&this.add_rule(":container",`\n width:calc(${s} * 100%);height:calc(${s} * 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;"))}compose_rule(e,t,n){let r=Object.assign({},t),i=e.property;if("@seed"===i)return"";let s=this.get_composed_value(e.value,r),l=s.extra,o=s.value;if(/^animation(\-name)?$/.test(i)){if(this.props.has_animation=!0,Sn(n)){let e=ut[i];e&&o&&(o=e+","+o)}if(r.count>1){let{count:e}=r;switch(i){case"animation-name":o=s.group.map((t=>this.compose_aname(t,e))).join(",");break;case"animation":o=s.group.map((t=>{let n=(t||"").split(/\s+/);return n[0]=this.compose_aname(n[0],e),n.join(" ")})).join(",")}}}"content"===i&&(/["']|^none\s?$|^(var|counter|counters|attr|url)\(/.test(o)||(o=`'${o}'`)),"transition"===i&&(this.props.has_transition=!0);let a=`${i}:${o};`;if(a=Gt(i,a),"width"!==i&&"height"!==i||An(n)||(a+=`--_cell-${i}:${o};`),/^(background|background\-image)$/.test(i)&&/\$\{(shader|pattern)/.test(o)&&(a+="background-size:100% 100%;"),/^\-\-/.test(i)&&this.compose_vars(t,n,i,o),/^@/.test(i)&&Qt[i.substr(1)]){let t=i.substr(1),s=Qt[t](o,{is_special_selector:An(n),grid:r.grid,max_grid:r.max_grid,extra:l});switch(t){case"grid":Sn(n)?(a=s.size||"",this.add_grid_style(s)):(a="",this.is_grid_set||(s=Qt[t](o,{is_special_selector:!0,grid:r.grid,max_grid:r.max_grid}),this.add_rule(":host",s.size||""),this.add_grid_style(s))),this.grid=r.grid,this.is_grid_set=!0;break;case"gap":a="",this.is_gap_set||(this.add_rule(":container",`gap:${s};`),this.is_gap_set=!0);break;case"content":{a="";let e=this.compose_selector(r);void 0===s||/\:before|\:after/.test(n)||jn(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(s))),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":Sn(n)||(a=s);break;case"use":e.value.length&&this.compose(r,e.value),a="";break;default:a=s}}return/^grid/.test(i)&&Sn(n)&&(this.add_rule(":container",`${i}:${o};`),a=""),a}get_raw_value(e){let t=e.raw();x(t)&&(t="");let[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 i=e.count;jn(t)&&(i="container"),Sn(t)&&(i="host"),this.vars[i]||(this.vars[i]={}),this.vars[i][n]=r}pre_compose_rule(e,t,n){let r=Object.assign({},t),i=e.property,s=Object.assign({},this.vars.host,this.vars.container,this.vars[r.count]);if(/^\-\-/.test(i)){let l=this.get_composed_value(e.value,r,s).value;this.compose_vars(t,n,i,l)}switch(i){case"@grid":{let n=this.get_composed_value(e.value,r,s).value,l=i.substr(1),o=Qt[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&&Sn(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":Sn(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;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=An(t.selector);n&&(t.skip=!0),O(t.selector).forEach((r=>{let i=t.styles.map((t=>this.compose_rule(t,e,r))),s=n?r:this.compose_selector(e,r);this.add_rule(s,i)}));break}case"cond":{let n=t.name.substr(1),r=an[n];if(r){let i=t.arguments.map((t=>this.compose_argument(t,e))),s=this.apply_func(r,e,i,n);if(Array.isArray(t.addition))for(let e of t.addition)"not"===e&&(s=!s);s&&(s.selector?t.styles.forEach((t=>{"rule"===t.type&&this.add_rule(s.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((s.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 ${C(t.steps.map((t=>`\n ${this.get_composed_value(t.name,e).value}{${C(t.styles.map((t=>this.compose_rule(t,e))))}}`)))}`)}}))}output(){for(let[e,t]of Object.entries(this.rules))if(jn(e))this.styles.container+=`grid{${C(t)}}`;else{let n=Sn(e)?"host":"cells",r=C(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:${ut.animation};}`,this.styles.keyframes+=`\n @keyframes ${ut["animation-name"]}{from{--${ut.name}:0} to{--${ut.name}:${ut["animation-duration"]/10}}}`),this.coords.forEach(((e,t)=>{for(let[n,r]of Object.entries(this.keyframes)){let i=this.compose_aname(n,e.count);this.styles.keyframes+=`\n ${0===t?`@keyframes ${n}{${r(e)}}`:""} @keyframes ${i}{${r(e)}}`}}));let{keyframes:e,host:t,container:n,cells:r}=this.styles,i=e+t+n;return{props:this.props,styles:{main:i,cells:r,all:i+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 Tn(e,t,n,r,i){let s=new En(e),l=i||bn(String(n)),o={};function a(e=0,t){return 1==arguments.length&&([e,t]=[0,e]),T(l(),e,t)}function u(...e){let t=e.reduce(((e,t)=>e.concat(t)),[]);return t[~~(l()*t.length)]}function c(e){let t=[...e],n=e.length;for(;n;){let e=~~(l()*n--),r=t[n];t[n]=t[e],t[e]=r}return t}s.pre_compose({x:1,y:1,z:1,count:1,context:{},grid:{x:1,y:1,z:1,count:1},random:l,rand:a,pick:u,shuffle:c,max_grid:r,update_random:function(e){l=bn(String(e))},seed_value:n,rules:s});let{grid:h,seed:p}=s.output();if(h&&(t=h),p?(p=String(p),l=bn(p)):p=n,x(p)&&(p=Date.now(),l=bn(p)),p=String(p),s.seed=p,s.random=l,s.reset(),1==t.z)for(let e=1,n=0;e<=t.y;++e)for(let i=1;i<=t.x;++i)s.compose({x:i,y:e,z:1,count:++n,grid:t,context:o,rand:a,pick:u,shuffle:c,random:l,seed:p,max_grid:r,rules:s});else for(let e=1,n=0;e<=t.z;++e)s.compose({x:1,y:1,z:e,count:++n,grid:t,context:o,rand:a,pick:u,shuffle:c,random:l,seed:p,max_grid:r,rules:s});return s.output()}function Rn(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}function zn(e,t){return e.includes(t)?e:t+"\n"+e}function Cn(e,t){let n=Fe.get(e);if(n)return Promise.resolve(n);let r=document.createElement("canvas"),i=devicePixelRatio||1,s=r.width=e.width*i,l=r.height=e.height*i,o=[],a=r.getContext("webgl2",{preserveDrawingBuffer:!0});if(!a)return Promise.resolve("");let u=zn(e.fragment||"","uniform vec2 u_resolution;");u=zn(u,"uniform float u_time;"),u=zn(u,"uniform float u_timeDelta;"),u=zn(u,"uniform int u_frameIndex;"),u=zn(u,"uniform vec2 u_seed;"),e.textures.forEach((e=>{let t=`uniform sampler2D ${e.name};`;u=zn(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=Rn(e,e.VERTEX_SHADER,t),i=Rn(e,e.FRAGMENT_SHADER,n),s=e.createProgram();return e.attachShader(s,r),e.attachShader(s,i),e.linkProgram(s),e.getProgramParameter(s,e.LINK_STATUS)||(console.warn("Link failed:"+e.getProgramInfoLog(s)),console.warn("vs info-log:"+e.getShaderInfoLog(r)),console.warn("fs info-log:"+e.getShaderInfoLog(i))),s}(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,[s,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(Fe.set(e,((s,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*i,r.height=u*i,a.viewport(0,0,r.width,r.height),a.uniform2fv(d,[r.width,r.height])),g&&a.uniform1f(g,s/1e3),v&&a.uniform1i(v,t++),y&&(a.uniform1f(y,(n-s)/1e3),n=s),a.drawArrays(a.TRIANGLES,0,6),r.toDataURL()))))}return a.drawArrays(a.TRIANGLES,0,6),Promise.resolve(Fe.set(e,r.toDataURL()))}function Mn(e,t){let n=[];for(;e.next();){let{curr:t,next:r}=e.get(),i=!r||t.isSymbol(";")||r.isSymbol("}");if(n.push(t),i)break}return n.length&&(t.value=On(n)),t}function Pn(e,t){let n=[],r=[],i=t&&t.type||"",s=[];for(;e.next();){let{prev:l,curr:o,next:a}=e.get(),u=!a||o.isSymbol("}");if("block"===i&&u){a||!n.length||o.isSymbol("}")||(n[n.length-1].value+=";"+o.value),t.value=n;break}if(o.isSymbol("{")&&r.length&&!s.length){let t=In(r);if(!t.length)continue;let i=Pn(e,{type:"block",name:"unkown",value:[]});t.forEach((e=>{let t=Object.assign({},i,{name:e.name,args:e.args});n.push(t)})),r=[]}else if(o.isSymbol(":")&&r.length&&!s.length){let s=On(r);n.push(Mn(e,{type:"statement",name:s,value:""})),"block"==i&&(t.value=n),r=[]}else o.isSymbol(";")?n.length&&r.length&&(n[n.length-1].value+=";"+On(r),r=[]):(o.isSymbol("(")&&s.push(o),o.isSymbol(")")&&s.pop(),r.push(o))}return n.length&&"block"==i&&(t.value=n),i?t:n}function On(e){return e.filter(((t,n)=>!t.isSymbol(";")||n!==e.length-1)).map((e=>e.value)).join("")}function In(e){let t=r(e),n=[],i="",s=[],l=[],o=[];for(;t.next();){let{curr:e,next:r}=t.get();!i.length&&e.isWord()?i=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&&(s.push(l.join("")),l=[])):e.isSymbol(",")?o.length?(s.push(l.join("")),l=[]):(l.length&&(s.push(l.join("")),l=[]),i&&(n.push({name:i,args:s}),i="",s=[],l=[])):l.push(e.value)}return i&&n.push({name:i,args:s}),n.filter(((e,t,n)=>n.findIndex((t=>t.name===e.name&&e.args.join("")==t.args.join("")))===t))}function Wn(e){return Pn(r(p(e)))}function Ln(e,t){if("fill"===e.name){let{r:n,g:r,b:i,a:s}=t.get_rgba_color(e.value);return{type:"statement",value:`\ncolor = vec4(${Dn(n/255)}, ${Dn(r/255)}, ${Dn(i/255)}, ${Dn(s)});`}}return"grid"==e.name?{type:"grid",value:e.value}:{type:"statement",value:""}}function Dn(e){return String(e).includes(".")?e:e+".0"}function Bn(e,t){let n=Wn(e),r=[],i={x:1,y:1};return n.forEach((e=>{if("statement"===e.type){let n=Ln(e,t);"statement"==n.type&&r.push(n.value),"grid"===n.type&&(i=Te(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=Ln(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(""),i)}function Un(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)}const Fn=1e3/60;if("undefined"!=typeof customElements){class e 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,i=1]=e.replace(/rgba?\((.+)\)/,((e,t)=>t)).split(/,\s*/);return{r:t,g:n,b:r,a:i}}(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()}cleanup(){Fe.clear();for(let e of this.animations)e.cancel();this.animations=[]}update(e){this.cleanup(),e||(e=N(this._innerHTML)),this._innerHTML!==e&&(this._innerHTML=e),this.grid_size||(this.grid_size=this.get_grid());const{x:t,y:n,z:r}=this.grid_size,i=this.get_use();let s="",l="";this.compiled&&(s=this.compiled.content,l=this.compiled.styles.all);const o=this.generate(Ee(i+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(s)!==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(i+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(Xn(this.grid_size)+o.styles.all))}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 Te(this.attr("grid"),this.get_max_grid())}get_use(){let e=String(this.attr("use")||"").trim();return/^var\(/.test(e)&&(e=`@use:${e};`),e}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=Tn(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),i=Te(""),s=Tn(r,i,this._seed_value,this.get_max_grid(),this._seed_random),l=s.grid?s.grid:i,o="";if(t&&t.arg){let e=Te(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(s),u=Yn(l,s.content);a(`\n<svg ${t&&t.width&&t.height?`width="${t.width}" height="${t.height}"`:""} ${Pe} preserveAspectRatio="none" ${o}><foreignObject width="100%" height="100%"><div class="host" width="100%" height="100%" ${Oe}><style>${Xn(l)} ${s.styles.all}</style>${u}</div></foreignObject></svg>`).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 i=Bn(e,this.extra);this.shader_to_image({shader:i,cell:t,id:n},r)}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()}shader_to_image({shader:e,cell:t,id:n},i){const s=this.doodle.getElementById(t);if(!s)return!1;let{width:l,height:o}=s.getBoundingClientRect(),a=devicePixelRatio||1,u=this.seed,c="string"==typeof e?function(e){let t,n,i=r(Ce(p(e,{preserveLineBreak:!0,ignoreInlineComment:!0}))),s=[],l=[],o={textures:[]};for(;i.next();){let{curr:e,next:r}=i.get();if(e.isSymbol("{")){if(s.length)l.push(e);else{let n=Me(l);Re(n)?(t=n,l=[]):l.push(e)}s.push("{")}else if(e.isSymbol("}"))if(s.pop(),!s.length&&t){let e=Me(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=Me(l),o.textures=o.textures||[]),o}(e):e;c.width=l,c.height=o;let h=c.textures,f=[];const d=e=>{s.style.setProperty(n,`url(${e})`)},m=e=>{"function"==typeof e?this.animations.push(function(e){let t,n=0,r=0,i=0,s=!1;function l(s){n||(n=s),e(n);let o=s-r;o<Fn&&(o=Fn),o>1e3&&(o=i||1e3),r&&(n+=o),i=o,r=s,t=requestAnimationFrame(l)}return t=requestAnimationFrame(l),{resume(){t&&s&&(s=!1,t=requestAnimationFrame(l))},pause(){t&&(cancelAnimationFrame(t),s=!0)},cancel(){t&&(s=!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)};s.observer||(s.observer=new ResizeObserver((()=>{let e=s.getBoundingClientRect();l=e.width,o=e.height,g(h,(e=>f=e))})),s.observer.observe(s)),h.length?g(h,(e=>{c.textures=f=e,c.width=l,c.height=o,Cn(c,u).then(m).then(i)})):Cn(c,u).then(m).then(i)}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._innerHTML=this.innerHTML,this.innerHTML=""}replace({doodles:e,shaders:t,pattern:n}){let r=Object.keys(e),i=Object.keys(t),s=Object.keys(n),l=r.length+i.length+s.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:i}=e[t];this.doodle_to_image(i,{arg:r},(e=>n({id:t,value:e})))})):Promise.resolve(""))),i.map((e=>o.includes(e)?new Promise((n=>{this.shader_to_image(t[e],(t=>n({id:e,value:t})))})):Promise.resolve(""))),s.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 i=n||r;const{uniforms:s,content:l,styles:o}=e;this.doodle.innerHTML=`\n<style>${Xn(t)+o.main}</style>${Yn(t,l)}`,i&&this.reflow();let a=this.replace(e);this.set_style(a(Xn(t)+o.all)),s.time&&this.register_utime(),s.mousex||s.mousey?this.register_umouse(s):this.remove_umouse(),s.width||s.height?this.register_usize(s):this.remove_usize()}register_umouse(e){if(!this.umouse_fn){this.umouse_fn=t=>{let n=t.detail||t;e.mousex&&this.style.setProperty("--"+ct,n.offsetX),e.mousey&&this.style.setProperty("--"+ht,n.offsetY)},this.addEventListener("pointermove",this.umouse_fn);let t=new CustomEvent("pointermove",{detail:{offsetX:0,offsetY:0}});this.dispatchEvent(t)}}remove_umouse(){this.umouse_fn&&(this.style.removeProperty("--"+ct),this.style.removeProperty("--"+ht),this.removeEventListener("pointermove",this.umouse_fn),this.umouse_fn=null)}register_usize(e){this.usize_observer||(this.usize_observer=new ResizeObserver((()=>{let t=this.getBoundingClientRect();e.width&&this.style.setProperty("--"+pt,t.width),e.height&&this.style.setProperty("--"+ft,t.height)})),this.usize_observer.observe(this))}remove_usize(){this.usize_observer&&(this.style.removeProperty("--"+pt),this.style.removeProperty("--"+ft),this.usize_observer.unobserve(this),this.usize_observer=null)}register_utime(){if(!this.is_utime_set){try{CSS.registerProperty({name:"--"+ut.name,syntax:"<number>",initialValue:0,inherits:!0})}catch(e){}this.is_utime_set=!0}}export({scale:e,name:t,download:n,detail:r}={}){return new Promise(((i,s)=>{let l=Un(this),o=this.doodle.innerHTML,{width:a,height:u}=this.getBoundingClientRect(),c=a*(e=parseInt(e)||1),h=u*e,p=`\n<svg ${Pe} preserveAspectRatio="none"\n viewBox="0 0 ${a} ${u}"\n ${A()?"":`width="${c}px" height="${h}px"`}><foreignObject width="100%" height="100%"><div class="host" ${Oe} style="width:${a}px;height:${u}px"><style>.host{${f=l,f.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}}</style>${o}</div></foreignObject></svg>`;var f;n||r?function(e,t,n,r){return new Promise(((i,s)=>{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=>{i({blob:e,source:l,url:URL.createObjectURL(e)})}))}catch(e){s(e)}}}A()?j(l,o,200):o()}))}(p,c,h,e).then((({source:e,url:r,blob:s})=>{if(i({width:c,height:h,svg:p,blob:s,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=>{s(e)})):i({width:c,height:h,svg:p})}))}set_style(e){if(e instanceof Promise)e.then((e=>{this.set_style(e)}));else{const t=this.shadowRoot.querySelector("style");let n=e.replace(/\n\s+/g," ");t&&(t.styleSheet?t.styleSheet.cssText=n:t.innerHTML=n)}}}customElements.get("css-doodle")||customElements.define("css-doodle",e)}function Xn(e){let{x:t,y:n}=e||{};return`\n *,*::after,*::before{box-sizing:border-box;}:host,.host{display:block;visibility:visible;width:auto;height:auto;contain:content;box-sizing:border-box;--${ut.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 qn(e){return x(e)?"":e}function Hn(e,t,n,r,i=""){let s=k(e,t,n);return`<cell id="${s}">${qn(r["#"+s])}${qn(i)}</cell>`}function Yn(e,t){let{x:n,y:r,z:i}=e||{},s="";if(1==i)for(let e=1;e<=r;++e)for(let r=1;r<=n;++r)s+=Hn(r,e,1,t);else{let e="";for(let n=i;n>=1;n--){e=Hn(1,1,n,t,e)}s=e}return`<grid>${s}</grid>`}}();