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) · 53 KB
/
css-doodle.min.js
1
/*! [email protected] */!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e="undefined"!=typeof globalThis?globalThis:e||self).CSSDoodle=t()}(this,(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,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){return[":",";",",","{","}","(",")","[","]"].includes(e)}function l(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 o(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 a(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 u(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 c(e){return e[e.length-1]}function h(e){let h=r(String(e).trim()),p=[],f=[];for(;h.next();){let{prev:e,curr:r,next:d,next2:m,pos:g}=h.get();if(t.comment(r,d))i(h);else if(t.hex(r,d,m)){let e=u(h);p.push(new n({type:"Number",value:e,pos:g}))}else if(t.digit(r)||t.digit(d)&&t.dot(r)&&!t.dots(e,r)){let e=a(h);p.push(new n({type:"Number",value:e,pos:g}))}else if(t.symbol(r)&&!t.selfClosedTag(r,d)){let e=c(p);if("-"===r&&t.digit(d)&&(!e||!e.isNumber())){let e=a(h);p.push(new n({type:"Number",value:e,pos:g}));continue}let i={type:"Symbol",value:r,pos:g};if(f.length&&t.escape(e.value)){p.pop();let e=l(h);e.length&&p.push(new n({type:"Word",value:e,pos:g}))}else{if(t.quote(r)){c(f)==r?(f.pop(),i.status="close"):(f.push(r),i.status="open")}p.push(new n(i))}}else if(t.space(r)){let e=o(h),t=c(p),{next:r}=h.get();if(!f.length&&t){if(s(t.value)||s(r))continue;e=" "}p.length&&r&&r.trim()&&p.push(new n({type:"Space",value:e,pos:g}))}else{let e=l(h);e.length&&p.push(new n({type:"Word",value:e,pos:g}))}}let d=c(p);return d&&d.isSpace()&&(p.length=p.length-1),p}function p(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=f(e);m(n.name)&&t.push(n)}}else if(t.length&&!n.isSymbol(","))break}return t}function f(e){let t={},n=[];for(;e.next();){let{curr:r,next:i}=e.get();if(r.isSymbol(")",";")&&!t.name){t.name=d(n);break}r.isSymbol(",")?(void 0===t.name&&(t.name=d(n),n=[]),t.name&&(t.fallback=p(e))):n.push(r)}return t}function d(e){return e.map((e=>e.value)).join("")}function m(e){return void 0!==e&&(!(e.length<=2)&&(!e.substr(2).startsWith("-")&&!!e.startsWith("--")))}function g(e){return{make_array:function(e){return Array.isArray(e)?e:[e]},join:function(e,t="\n"){return(e||[]).join(t)},last:function(e,t=1){return e[e.length-t]},first:function(e){return e[0]},clone:function(e){return JSON.parse(JSON.stringify(e))},shuffle:function(t){let n=Array.from?Array.from(t):t.slice(),r=t.length;for(;r;){let t=~~(e()*r--),i=n[r];n[r]=n[t],n[t]=i}return n},flat_map:function(e,t){return Array.prototype.flatMap?e.flatMap(t):e.reduce(((e,n)=>e.concat(t(n))),[])},remove_empty_values:function(e){return e.filter((e=>null!=e&&String(e).trim().length))}}}let{first:y,last:v,clone:x}=g();const b={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:[]})},_={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)},w={\u03c0:Math.PI,"\u220f":Math.PI};function k(e){return["@canvas","@shaders","@doodle"].includes(e)}function $(e,{col:t,line:n}){console.warn(`(at line ${n}, column ${t}) ${e}`)}function S(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 j(e,t){return S((e=>/[^\w@]/.test(e)))(e,t)}function E(e){return S((e=>/[\s\{]/.test(e)))(e)}function z(e,t){return S((e=>_.line_break(e)||"{"==e))(e,t)}function T(e,t){let n,r=b.step();for(;!e.end()&&"}"!=(n=e.curr());)if(_.white_space(n))e.next();else{if(r.name.length){if(r.styles.push(B(e,t)),"}"==e.curr())break}else r.name=W(e);e.next()}return r}function A(e,t){const n=[];let r;for(;!e.end()&&"}"!=(r=e.curr());)_.white_space(r)||n.push(T(e,t)),e.next();return n}function R(e,t){let n,r=b.keyframes();for(;!e.end()&&"}"!=(n=e.curr());)if(r.name.length){if("{"==n){e.next(),r.steps=A(e,t);break}e.next()}else if(j(e),r.name=E(e),!r.name.length){$("missing keyframes name",e.info());break}return r}function P(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 C(e){for(e.next();!e.end();){if(">"==e.curr())break;e.next()}}function M(e){let t,n="";for(;!e.end()&&":"!=(t=e.curr());)_.white_space(t)||(n+=t),e.next();return n}function N(e,t,n){let r,i=[],s=[],l=[],o="";for(;!e.end();){if(r=e.curr(),/[\('"`]/.test(r)&&"\\"!==e.curr(-1))l.length&&"("!=r&&r===v(l)?l.pop():l.push(r),o+=r;else if("@"!=r||n)if(n&&/[)]/.test(r)||!n&&/[,)]/.test(r))if(l.length)")"==r&&l.pop(),o+=r;else{if(o.length&&(s.length?s.push(b.text(o)):s.push(b.text((a=o).trim().length?_.number(+a)?+a:a.trim():a)),o.startsWith("\xb1")&&!n)){let e=o.substr(1),t=x(s);v(t).value="-"+e,i.push(L(t)),v(s).value=e}if(i.push(L(s)),[s,o]=[[],""],")"==r)break}else w[r]&&!/[0-9]/.test(e.curr(-1))&&(r=w[r]),o+=r;else s.length||(o=o.trimLeft()),o.length&&(s.push(b.text(o)),o=""),s.push(O(e));if(!(!t||")"!=e.curr()&&/[0-9a-zA-Z_\-.]/.test(e.curr())||l.length)){s.length&&i.push(L(s));break}e.next()}var a;return i}function L(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.replace(/\n+|\s+/g," ")}return e})),n=y(t)||{},r=v(t)||{};if("text"==n.type&&"text"==r.type){let e=y(n.value),i=v(r.value);"string"==typeof n.value&&"string"==typeof r.value&&_.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 O(e){let t,n=b.func(),r="@",i=!1;for(e.next();!e.end();){t=e.curr();let s="."==t&&"@"==e.curr(1),l=e.curr(1);if("("==t||s){i=!0,e.next(),n.arguments=N(e,s,k(r));break}if(!i&&"("!==l&&!/[0-9a-zA-Z_\-.]/.test(l)){r+=t;break}r+=t,e.next()}let{fname:s,extra:l}=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&&/\d/.test(s)&&/\d/.test(l))){t=e.substring(0,r+1);break}n=i+n}return{fname:t,extra:n}}(r);return n.name=s,l.length&&n.arguments.unshift([{type:"text",value:l}]),n.position=e.info().index,n}function I(e){let t,n=b.text(),r=0,i=!0;const s=[],l=[];for(s[r]=[];!e.end();)if(t=e.curr(),i&&_.white_space(t))e.next();else{if(i=!1,"\n"!=t||_.white_space(e.curr(-1)))if(","!=t||l.length){if(/[;}<]/.test(t)){n.value.length&&(s[r].push(n),n=b.text());break}"@"==t?(n.value.length&&(s[r].push(n),n=b.text()),s[r].push(O(e))):_.white_space(t)&&_.white_space(e.curr(-1))||("("==t&&l.push(t),")"==t&&l.pop(),w[t]&&!/[0-9]/.test(e.curr(-1))&&(t=w[t]),n.value+=t)}else n.value.length&&(s[r].push(n),n=b.text()),s[++r]=[],i=!0;else n.value+=" ";e.next()}return n.value.length&&s[r].push(n),s}function W(e){let t,n="";for(;!e.end()&&"{"!=(t=e.curr());)_.white_space(t)||(n+=t),e.next();return n}function U(e){let t,n={name:"",arguments:[]};for(;!e.end();){if("("==(t=e.curr()))e.next(),n.arguments=N(e);else{if(/[){]/.test(t))break;_.white_space(t)||(n.name+=t)}e.next()}return n}function D(e,t){let n,r=b.pseudo();for(;!e.end()&&"}"!=(n=e.curr());)if(_.white_space(n))e.next();else{if(r.selector){let n=B(e,t);if("@use"==n.property?r.styles=r.styles.concat(n.value):r.styles.push(n),"}"==e.curr())break}else r.selector=W(e);e.next()}return r}function B(e,t){let n=b.rule();for(;!e.end()&&";"!=e.curr();){if(n.property.length){n.value=I(e);break}if(n.property=M(e),"@use"==n.property){n.value=X(e,t);break}e.next()}return n}function H(e,t){let n,r=b.cond();for(;!e.end()&&"}"!=(n=e.curr());){if(r.name.length)if(":"==n){let t=D(e);t.selector&&r.styles.push(t)}else if("@"!=n||z(e,!0).includes(":")){if(!_.white_space(n)){let n=B(e,t);if(n.property&&r.styles.push(n),"}"==e.curr())break}}else r.styles.push(H(e));else Object.assign(r,U(e));e.next()}return r}function q(e,t){let n="";return e&&e.get_variable&&(n=e.get_variable(t)),n}function F(e,t){e.forEach&&e.forEach((e=>{if("text"==e.type&&e.value){let n=p(r(h(e.value)));e.value=n.reduce(((e,n)=>{let r,i="",s="";i=q(t,n.name),!i&&n.fallback&&n.fallback.every((e=>{if(s=q(t,e.name),s)return i=s,!1}));try{r=V(i,t)}catch(e){}return r&&e.push.apply(e,r),e}),[])}"func"==e.type&&e.arguments&&e.arguments.forEach((e=>{F(e,t)}))}))}function X(e,t){return e.next(),(I(e)||[]).reduce(((e,n)=>{F(n,t);let[r]=n;return r.value&&r.value.length&&e.push(...r.value),e}),[])}function V(e,t){const n=function(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,next(){let i=e[t++];return"\n"==i?(r++,n=0):n++,i}}}(e),r=[];for(;!n.end();){let e=n.curr();if(_.white_space(e))n.next();else{if("/"==e&&"*"==n.curr(1))P(n);else if("/"==e&&"/"==n.curr(1))P(n,{inline:!0});else if(":"==e){let e=D(n,t);e.selector&&r.push(e)}else if("@"==e&&"@keyframes"===j(n,!0)){let e=R(n,t);r.push(e)}else if("@"!=e||z(n,!0).includes(":")){if("<"==e)C(n);else if(!_.white_space(e)){let e=B(n,t);e.property&&r.push(e)}}else{let e=H(n,t);e.name.length&&r.push(e)}n.next()}}return r}function G(e,t,n){return Math.max(t,Math.min(n,e))}function Y(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++>=1e3)););return o.length||o.push(i),o}function Z(e){return/^[a-zA-Z]$/.test(e)}function J(e){return null==e}function K(e){return J(e)||Number.isNaN(e)}function Q(e){return J(e)||""===e}function ee(e){let t=()=>e;return t.lazy=!0,t}function te(e,t,n){return"c-"+e+"-"+t+"-"+n}function ne(e){for(;e&&e.value;)return ne(e.value);return J(e)?"":e}function re(e,t,n=0){let r=new Image;r.crossOrigin="anonymous",r.src=e,r.onload=function(){setTimeout(t,n)}}function ie(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function se(e){let t=document.createElement("textarea");return t.innerHTML=e,t.value}function le(e){return(t,...n)=>{let r=t.reduce(((e,t,r)=>{return e+t+(J(i=n[r])?"":i);var i}),"");return e(r)}}const[oe,ae,ue]=[1,32,1024];function ce(e){let[t,n,r]=(e+"").replace(/\s+/g,"").replace(/[,\uff0cxX]+/g,"x").split("x").map((e=>parseInt(e)));const i=1==t||1==n?ue:ae,s=1==t&&1==n?ue:oe,l={x:G(t||oe,1,i),y:G(n||t||oe,1,i),z:G(r||oe,1,s)};return Object.assign({},l,{count:l.x*l.y*l.z,ratio:l.x/l.y})}function he(e){return/^texture\w*$|^(fragment|vertex)$/.test(e)}function pe(){return new n({type:"LineBreak",value:"\n"})}function fe(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 de(e){return fe(e).map((e=>e.value)).join("")}const me="http://www.w3.org/2000/svg",ge="http://www.w3.org/1999/xlink";function ye(e,t){return`url("data:image/svg+xml;utf8,${encodeURIComponent(e)+(t?`#${t}`:"")}")`}function ve(e){const t=`xmlns="${me}"`,n=`xmlns:xlink="${ge}"`;return e.includes("<svg")||(e=`<svg ${t} ${n}>${e}</svg>`),e.includes("xmlns")||(e=e.replace(/<svg([\s>])/,`<svg ${t} ${n}$1`)),e}function xe(e,t,n){if(t||(t=document.createDocumentFragment()),"block"===e.type)try{let n=document.createElementNS(me,e.name);n&&(e.value.forEach((t=>{xe(t,n,e)})),t.appendChild(n))}catch(e){}if("statement"===e.type)if(n&&"text"==n.name&&"content"===e.name)t.textContent=e.value;else try{let n=e.name.startsWith("xlink:")?ge:me;t.setAttributeNS(n,e.name,e.value)}catch(e){}if(!n){let e=t.childNodes[0];return e&&e.outerHTML||""}return t}function be(e){function t(e,t,n){return e*(1-n)+t*n}return{lerp:t,rand:function(n=0,r){return 1==arguments.length&&([n,r]=[0,n]),t(n,r,e())},nrand:function(t=0,n=1){let r=0,i=0;for(;0===r;)r=e();for(;0===i;)i=e();const s=Math.sqrt(-2*Math.log(r)),l=2*Math.PI*i;return t+n*(s*Math.cos(l))},pick:function(...t){let n=t.reduce(((e,t)=>e.concat(t)),[]);return n[~~(e()*n.length)]},unique_id:function(e=""){return e+Math.random().toString(32).substr(2)}}}function _e(e){return(...t)=>{let n=function(e){let t="";return e.some((e=>{let n=String(e).trim();if(!n)return"";let r=n.match(/\d(\D+)$/);return t=r?r[1]:""})),t}(t);return function(e,t){return(...n)=>{n=n.map((e=>Number(String(e).replace(/\D+$/g,""))));let r=e.apply(null,n);return t.length?Array.isArray(r)?r.map((e=>e+t)):r+t:r}}(e,n).apply(null,t)}}function we(e){return(...t)=>{let n=t.map((e=>String(e).charCodeAt(0))),r=e.apply(null,n);return Array.isArray(r)?r.map((e=>String.fromCharCode(e))):String.fromCharCode(r)}}let{last:ke}=g();const $e={\u03c0:Math.PI,gcd:(e,t)=>{for(;t;)[e,t]=[t,e%t];return e}};function Se(e,t){return Ee(ze(e),Object.assign({},$e,t))}const je={"^":7,"*":6,"/":6,"\xf7":6,"%":6,"&":5,"|":5,"+":4,"-":4,"<":3,">":3,"=":3,"==":3,"\u2264":3,"<=":3,"\u2265":3,">=":3,"\u2260":3,"!=":3,"\u2227":2,"&&":2,"\u2228":2,"||":2,"(":1,")":1};function Ee(e,t,n=[]){let r=[];for(;e.length;){let{name:s,value:l,type:o}=e.shift();if("variable"===o){let e=t[l];K(e)&&(e=Math[l]),K(e)&&(e=Ae(l,t)),K(e)&&/^\-\D/.test(l)&&(e=Ae("-1"+l.substr(1),t)),void 0===e&&(e=0),"number"!=typeof e&&(n.push(e),(i=n)[0]==i[2]&&i[1]==i[3]?(e=0,n=[]):e=Ee(ze(e),t,n)),r.push(e)}else if("function"===o){let e=!1;/^\-/.test(s)&&(e=!0,s=s.substr(1));let n,i=l.map((e=>Ee(e,t))),o=s.split(".");for(;n=o.pop();){if(!n)continue;let e=t[n]||Math[n];i="function"==typeof e?Array.isArray(i)?e(...i):e(i):0}e&&(i*=-1),r.push(i)}else if(/\d+/.test(l))r.push(l);else{let e=r.pop(),t=r.pop();r.push(Te(l,Number(t),Number(e)))}}var i;return Number(r[0])||0}function ze(e){let t=function(e){let t=String(e),n=[],r="";for(let e=0;e<t.length;++e){let i=t[e];if(je[i]){let s=ke(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}),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=ze(n);e.length&&l.push(e),n=""}}n.length&&l.push(ze(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&&"("!=ke(n);)r.push({type:"operator",value:n.pop()});n.pop()}else{for(;n.length&&je[ke(n)]>=je[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 Te(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 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}}function Ae(e,t){let[n,r,i]=e.match(/([\d.\-]+)(.*)/)||[],s=t[i];return void 0===s?s:"number"==typeof s?Number(r)*s:r*Ee(ze(s),t)}const Re={};function Pe(e,t){return(...n)=>{let r=e+n.join("-");return Re[r]?Re[r]:Re[r]=t.apply(null,n)}}const{last:Ce,flat_map:Me}=g();function Ne(e){return(...t)=>e.apply(null,Me(t,(e=>String(e).startsWith("[")?Oe(e):e)))}function Le(e,t){return{type:e,value:t}}const Oe=Pe("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("-"!=Ce(r))r.length&&n.push(Le("char",r.pop())),r.push(i);else{r.pop();let e=r.pop();n.push(e?Le("range",[e,i]):Le("char",i))}else r.push(i)}return r.length&&n.push(Le("char",r.pop())),n}(e);return Me(t,(({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=we(Y)(n,r);return i&&s.reverse(),s}))}));class Ie{constructor(e){this.prev=this.next=null,this.data=e}}class We{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 Ie(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 Ue(e){let t,n=r(h(e)),i={},s=[],l=!1;for(;n.next();){let{prev:e,curr:r,next:o}=n.get();if(r.isSymbol(":")&&!t)t=Be(s),s=[];else if(r.isSymbol(";")&&t)i[t]=De(t,Be(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]=De(t,Be(s),l)),i}function De(e,t,n){return"fill-rule"===e?t:n?`-1 * (${t})`:t}function Be(e){return e.map((e=>e.value)).join("")}const{cos:He,sin:qe,atan2:Fe,PI:Xe}=Math,Ve=le((e=>Ye(Ue(e),{min:3,max:3600}))),Ge={circle:()=>Ve`split:180;scale:.99`,triangle:()=>Ve`rotate:30;scale:1.1;move:0 .2`,pentagon:()=>Ve`split:5;rotate:54`,hexagon:()=>Ve`split:6;rotate:30;scale:.98`,octagon:()=>Ve`split:8;rotat:22.5;scale:.99`,star:()=>Ve`split:10;r:cos(5t);rotate:-18;scale:.99`,infinity:()=>Ve`split:180;scale:.99;x:cos(t)*.99 / (sin(t)^2 + 1);y:x * sin(t)`,heart:()=>Ve`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`,bean:()=>Ve`split:180;r:sin(t)^3 + cos(t)^3;move:-.35 .35;`,bicorn:()=>Ve`split:180;x:cos(t);y:sin(t)^2 / (2 + sin(t)) - .5`,drop:()=>Ve`split:180;rotate:90;scale:.95;x:sin(t);y:(1 + sin(t)) * cos(t) / 1.6`,fish:()=>Ve`split:240;x:cos(t) - sin(t)^2 / sqrt(2) - .04;y:sin(2t)/2`,whale:()=>Ve`split:240;rotate:180;R:3.4 * (sin(t)^2 - .5) * cos(t);x:cos(t) * R + .75;y:sin(t) * R * 1.2`,windmill:()=>Ve`split:18;R:seq(.618, 1, 0);T:seq(t-.55, t, t);x:R * cos(T);y:R * sin(T)`,vase:()=>Ve`split:240;scale:.3;x:sin(4t) + sin(t) * 1.4;y:cos(t) + cos(t) * 4.8 + .3`,clover:(e=3)=>(4==(e=G(e,3,5))&&(e=2),Ve`split:240;r:cos(${e}t);scale:.98`),hypocycloid:(e=3)=>(e=G(e,3,5),Ve`split:240;scale:${[0,0,0,.34,.25,.19][e]};k:${e};x:(k-1)*cos(t) + cos((k-1)*t);y:(k-1)*sin(t) - sin((k-1)*t)`),bud:(e=3)=>(e=G(e,3,10),Ve`split:240;scale:.8;r:1 + .2 * cos(${e}t)`)};function Ye(e,{min:t,max:n}){let r=G(parseInt(e.points||e.split)||0,t,n),i=Object.assign({},e,{split:r}),s=Q(e.x)?"cos(t)":e.x,l=Q(e.y)?"sin(t)":e.y,o=Q(e.r)?"":e.r;return e.degree&&(e.rotate=e.degree),e.origin&&(e.move=e.origin),function(e,t){"function"==typeof arguments[0]&&(t=e,e={}),t||(t=e=>[He(e),qe(e)]);let n,r,i=e.split||180,s=e.scale||1,l=e.turn||1,o=e.frame,a=e.fill||e["fill-rule"],u=2*-Xe*l/i,c=[];"nonzero"!=a&&"evenodd"!=a||c.push(a);let h=([t,n])=>{let r=50*t*s+50+"%",i=50*-n*s+50+"%";e.absolute&&(r=t*s,i=-n*s),c.push(r+" "+i)};for(let e=0;e<i;++e){let r=t(-u*e,e);e||(n=r),h(r)}if(void 0!==o){h(n);let e=(o||1)/100;e<=0&&(e=.002);for(let n=0;n<i;++n){let i=u*n,[s,l,o=0,a=0]=t(i,n),c=Fe(l+a,s-o),p=[s-e*He(c),l-e*qe(c)];n||(r=p),h(p)}h(r),h(n)}return c}(i,((t,n)=>{let i=Object.assign({},e,{t,\u03b8:t,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+Math.abs(t-e)/(r-1)*n)}),a=Se(s,i),u=Se(l,i),c=0,h=0;if(o){let e=Se(o,i);a=e*Math.cos(t),u=e*Math.sin(t)}return e.rotate&&([a,u]=function(e,t,n){let r=-Xe/180*n;return[e*He(r)-t*qe(r),t*He(r)+e*qe(r)]}(a,u,Number(e.rotate)||0)),e.move&&([a,u,c,h]=function(e,t,n){let[r,i=r]=String(n).split(/[,\s]/).map(Number);return[e+(r||0),t-(i||0),r,i]}(a,u,e.move)),[a,u,c,h]}))}function Ze(e,t){let n=[],i=[],s=[],l=[];if(Q(e))return n;let o=r(h(e));for(;o.next();){let{prev:e,curr:r,next:u}=o.get();r.isSymbol("(")&&s.push(r.value),r.isSymbol(")")&&s.pop(),"open"===r.status&&l.push(r.value),"close"===r.status&&l.pop(),a=r,!(t?a.isSymbol(","):a.isSymbol(",")||a.isSpace())||s.length||l.length?i.push(r):(n.push(Je(i)),i=[])}var a;return i.length&&n.push(Je(i)),n}function Je(e){return e.map((e=>e.value)).join("")}function Ke(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=tt(n)),t}function Qe(e,t){let n=[],r=[],i=t&&t.type||"";for(;e.next();){let{prev:s,curr:l,next:o}=e.get(),a=!o||l.isSymbol("}");if("block"===i&&a){o||!n.length||l.isSymbol("}")||(n[n.length-1].value+=";"+l.value),t.value=n;break}if(l.isSymbol("{")){let t=rt(r,(e=>e.isSpace()));if(!t.length)continue;let i=t.pop(),s=nt(Qe(e,{type:"block",name:i,value:[]}));for(;i=t.pop();)s=nt({type:"block",name:i,value:[s]});n.push(s),r=[]}else if(l.isSymbol(":")&&!et(s,o)&&r.length){let s=rt(r,(e=>e.isSymbol(","))),l=Ke(e,{type:"statement",name:"unkown",value:""});s.forEach((e=>{n.push(Object.assign({},l,{name:e}))})),"block"==i&&(t.value=n),r=[]}else l.isSymbol(";")?n.length&&r.length&&(n[n.length-1].value+=";"+tt(r),r=[]):r.push(l)}return n.length&&"block"==i&&(t.value=n),i?t:n}function et(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 tt(e){return e.filter(((t,n)=>!t.isSymbol(";","}")||n!==e.length-1)).map((e=>e.value)).join("")}function nt(e){let t=e.name||"",[n,...r]=t.split(/#/),i=r[r.length-1];return i&&(e.name=n,e.value.push({type:"statement",name:"id",value:i})),e}function rt(e,t){let n=[],r=[];return e.forEach((e=>{t(e)?(n.push(tt(r)),r=[]):r.push(e)})),r.length&&n.push(tt(r)),n}function it(e,t){return Qe(r(h(e)),t||{type:"block",name:"svg",value:[]})}function st(e){let t=r(h(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 lt={name:"cssd-uniform-time","animation-name":"cssd-uniform-time-animation","animation-duration":"31536000000","animation-iteration-count":"infinite","animation-delay":"0s","animation-direction":"normal","animation-fill-mode":"none","animation-play-state":"running","animation-timing-function":"linear"};function ot(e){const{shuffle:t}=g(e),{pick:n,rand:r,nrand:i,unique_id:s}=be(e),l={index:({count:e})=>t=>e,row:({y:e})=>t=>e,col:({x:e})=>t=>e,depth:({z:e})=>t=>e,size:({grid:e})=>t=>e.count,"size-row":({grid:e})=>t=>e.y,"size-col":({grid:e})=>t=>e.x,"size-depth":({grid:e})=>t=>e.z,id:({x:e,y:t,z:n})=>r=>te(e,t,n),n:({extra:e})=>t=>e?e[0]+(Number(t)||0):"@n",nx:({extra:e})=>t=>e?e[1]+(Number(t)||0):"@nx",ny:({extra:e})=>t=>e?e[2]+(Number(t)||0):"@ny",N:({extra:e})=>t=>e?e[3]+(Number(t)||0):"@N",repeat:o(""),multiple:o(","),"multiple-with-space":o(" "),pick:({context:e})=>Ne(((...t)=>a(e,"last_pick",n(t)))),"pick-n"({context:e,extra:t,position:n}){let r="pn-counter"+n;return Ne(((...n)=>{e[r]||(e[r]=0),e[r]+=1;let i=n.length,[s=e[r]]=t||[],l=n[(s-1)%i];return a(e,"last_pick",l)}))},"pick-d"({context:e,extra:n,position:r}){let i="pd-counter"+r,s="pd-values"+r;return Ne(((...r)=>{e[i]||(e[i]=0),e[i]+=1,e[s]||(e[s]=t(r));let l=r.length,[o=e[i]]=n||[],u=(o-1)%l,c=e[s][u];return a(e,"last_pick",c)}))},"last-pick":({context:e})=>(t=1)=>{let n=e.last_pick;return n?n.last(t):""},rand:({context:e})=>(...t)=>{let n=(t.every(Z)?we:_e)(r).apply(null,t);return a(e,"last_rand",n)},nrand:({context:e})=>(...t)=>{let n=(t.every(Z)?we:_e)(i).apply(null,t);return a(e,"last_rand",n)},"rand-int":({context:e})=>(...t)=>{let n=(t.every(Z)?we:_e)(((...e)=>Math.round(r(...e)))).apply(null,t);return a(e,"last_rand",n)},"nrand-int":({context:e})=>(...t)=>{let n=(t.every(Z)?we:_e)(((...e)=>Math.round(i(...e)))).apply(null,t);return a(e,"last_rand",n)},"last-rand":({context:e})=>(t=1)=>{let n=e.last_rand;return n?n.last(t):""},stripe:()=>(...e)=>{let t,n=e.map(ne),r=n.length,i=0,s=[];if(!r)return"";n.forEach((e=>{let[t,n]=Ze(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]=Ze(e);return t=(t?t+" + ":"")+(void 0!==r?r:l),`${n} 0 calc(${t})`}return`${e} 0 ${100/r*(n+1)}%`})).join(",")},reflect:()=>(...e)=>[...e,...e.slice(0,-1).reverse()].join(","),calc:()=>e=>Se(ne(e)),hex:()=>e=>parseInt(ne(e)).toString(16),svg:ee(((...e)=>{let t=e.map((e=>ne(e()).trim())).join(",");if(!t.startsWith("<")){t=xe(it(t))}return ye(ve(t))})),"svg-filter":ee(((...e)=>{let t=e.map((e=>ne(e()).trim())).join(","),n=s("filter-");if(!t.startsWith("<")){t=xe(it(t,{type:"block",name:"filter"}))}return ye(ve(t).replace(/<filter([\s>])/,`<filter id="${n}"$1`),n)})),var:()=>e=>`var(${ne(e)})`,t:()=>e=>`var(--${lt.name})`,point({count:e,context:t,extra:n,position:r,grid:i}){let s="offset-points"+r;return r=>{let[l=e,o,a,u=i.count]=n||[];if(!t[s]){let e=Ue(r);e.points=u,t[s]=Ye(e,{min:1,max:65536})}return t[s][l-1]}},Point({count:e,context:t,extra:n,position:r,grid:i}){let s="offset-points"+r;return r=>{let[l=e,o,a,u=i.count]=n||[];if(!t[s]){let e=Ue(r);e.points=u,e.absolute=!0,t[s]=Ye(e,{min:1,max:65536})}return t[s][l-1]}},shape:()=>Pe("shape-function",((e="",...t)=>{let n=[];if((e=String(e).trim()).length)if("function"==typeof Ge[e])n=Ge[e](t);else{let r=e,i=t.join(",");i.length&&(r=e+","+i),n=Ye(Ue(r),{min:3,max:3600})}return`polygon(${n.join(",")})`})),doodle:()=>e=>e,shaders:()=>e=>e,canvas:()=>e=>e,path:()=>e=>e,invert:()=>e=>{let t=st(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=st(e);return t.valid?t.commands.map((({name:e,value:t})=>{switch(e){case"h":case"H":return e+t.map(u).join(" ");default:return e+t.join(" ")}})).join(" "):e},flipV:()=>e=>{let t=st(e);return t.valid?t.commands.map((({name:e,value:t})=>{switch(e){case"v":case"V":return e+t.map(u).join(" ");default:return e+t.join(" ")}})).join(" "):e},flip(...e){let t=l.flipH(...e),n=l.flipV(...e);return e=>n(t(e))},reverse:(...e)=>e=>{let t=st(e);return t.valid?t.commands.reverse().map((({name:e,value:t})=>e+t.join(" "))).join(" "):e}};function o(e){return ee(((t,...n)=>{if(!n||!t)return"";let r=ne(t()),i=Se(r);return 0===i&&(i=r),function(e,t){let[n,r=1]=String(e).split("x");n=G(parseInt(n)||1,1,65536),r=G(parseInt(r)||1,1,65536);let i=n*r,s=[],l=1;for(let e=1;e<=r;++e)for(let r=1;r<=n;++r)s.push(t(l++,r,e,i));return s}(i,((...e)=>n.map((t=>ne(t(...e)))).join(","))).join(e)}))}function a(e,t,n){return e[t]||(e[t]=new We),e[t].push(n),n}function u(e){return-1*e}return c=l,h={m:"multiple",M:"multiple-with-space",r:"rand",rn:"nrand",ri:"rand-int",rni:"nrand-int",lr:"last-rand",p:"pick",pn:"pick-n",pd:"pick-d",lp:"last-pick",rep:"repeat",i:"index",x:"col",y:"row",z:"depth",I:"size",X:"size-col",Y:"size-row",Z:"size-depth",flipv:"flipV",fliph:"flipH",nr:"rn",nri:"nri",ms:"multiple-with-space",s:"size",sx:"size-col",sy:"size-row",sz:"size-depth","size-x":"size-col","size-y":"size-row","size-z":"size-depth",multi:"multiple","pick-by-turn":"pick-n","max-row":"size-row","max-col":"size-col",offset:"point",Offset:"Point",stripes:"stripe",strip:"stripe"},Object.keys(h).forEach((e=>{c[e]=c[h[e]]})),c;var c,h}lt.animation=`\n ${lt["animation-duration"]}ms\n ${lt["animation-timing-function"]} ${lt["animation-delay"]} ${lt["animation-iteration-count"]} ${lt["animation-name"]}`;let at=[];function ut(e){if(!at.length){let e=new Set;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"),at=Array.from(e)}return e&&e.test?at.filter((t=>e.test(t))):at}function ct(e){let t=new RegExp(`\\-?${e}\\-?`);return ut(t).map((e=>e.replace(t,""))).reduce(((e,t)=>(e[t]=t,e)),{})}const ht=ct("webkit"),pt=ct("moz");function ft(e,t){return ht[e]?`-webkit-${t} ${t}`:pt[e]?`-moz-${t} ${t}`:t}const dt={"4a0":[1682,2378],"2a0":[1189,1682],a0:[841,1189],a1:[594,841],a2:[420,594],a3:[297,420],a4:[210,297],a5:[148,210],a6:[105,148],a7:[74,105],a8:[52,74],a9:[37,52],a10:[26,37],b0:[1e3,1414],b1:[707,1e3],b2:[500,707],b3:[353,500],b4:[250,353],b5:[176,250],b6:[125,176],b7:[88,125],b8:[62,88],b9:[44,62],b10:[31,44],b11:[22,32],b12:[16,22],c0:[917,1297],c1:[648,917],c2:[458,648],c3:[324,458],c4:[229,324],c5:[162,229],c6:[114,162],c7:[81,114],c8:[57,81],c9:[40,57],c10:[28,40],c11:[22,32],c12:[16,22],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]},mt={portrait:"p",pt:"p",p:"p",landscape:"l",ls:"l",l:"l"};var gt={"@size"(e,{is_special_selector:t,grid:n}){let[r,i=r]=Ze(e);dt[r]&&([r,i]=function(e,t){e=String(e).toLowerCase();let[n,r]=dt[e]||[];return"p"==mt[t]&&([r,n]=[n,r]),[r,n].map((e=>e+"mm"))}(r,i));let s=`\n width:${r};height:${i};`;return t?"auto"!==r&&"auto"!==i||(s+=`aspect-ratio:${n.ratio};`):s+=`\n --internal-cell-width:${r};--internal-cell-height:${i};`,s},"@min-size"(e){let[t,n=t]=Ze(e);return`min-width:${t};min-height:${n};`},"@max-size"(e){let[t,n=t]=Ze(e);return`max-width:${t};max-height:${n};`},"@place-cell":(()=>{let e={center:"50%",left:"0%",right:"100%",top:"50%",bottom:"50%"},t={center:"50%",top:"0%",bottom:"100%",left:"50%",right:"50%"};return n=>{let[r,i="50%"]=Ze(n);r=e[r]||r,i=t[i]||i;const s="var(--internal-cell-width, 25%)",l="var(--internal-cell-height, 25%)";return`\n position:absolute;left:${r};top:${i};width:${s};height:${l};margin-left:calc(${s} / -2);margin-top:calc(${l} / -2);grid-area:unset;`}})(),"@grid"(e,t){let[n,...r]=e.split("/").map((e=>e.trim()));return r=r.join(" / "),{grid:ce(n),size:r?this["@size"](r,t):""}},"@shape":Pe("shape-property",(e=>{let[t,...n]=Ze(e),r="clip-path";return"function"!=typeof Ge[t]?"":ft(r,`${r}:polygon(${Ge[t](...n).join(",")});`)+"overflow:hidden;"})),"@use"(e){if(e.length>2)return e}};function yt(e,t,n){for(let r=0;r<=n;++r)if(Se(e,{n:r})==t)return!0}const vt={even:e=>!(e%2),odd:e=>!!(e%2)};function xt(e){return/^(even|odd)$/.test(e)}var bt=Object.getOwnPropertyNames(Math).reduce(((e,t)=>(e[t]=()=>(...e)=>(e=e.map(ne),"number"==typeof Math[t]?Math[t]:Math[t].apply(null,e.map(Se))),e)),{});const _t={length:"0px",number:0,color:"black",url:"url()",image:"url()",integer:0,angle:"0deg",time:"0ms",resolution:"0dpi",percentage:"0%","length-percentage":"0%","transform-function":"translate(0)","transform-list":"translate(0)","custom-ident":"_"};let{join:wt,make_array:kt,remove_empty_values:$t}=g();function St(e){return/^\:(host|doodle)/.test(e)}function jt(e){return/^\:(container|parent)/.test(e)}function Et(e){return St(e)||jt(e)}class zt{constructor(e,t){this.tokens=e,this.rules={},this.props={},this.keyframes={},this.grid=null,this.is_grid_defined=!1,this.coords=[],this.doodles={},this.canvas={},this.shaders={},this.paths={},this.reset(),this.Func=ot(t),this.Selector=function(e){return{at:({x:e,y:t})=>(n,r)=>e==n&&t==r,nth:({count:e,grid:t})=>(...n)=>n.some((n=>xt(n)?vt[n](e):yt(n,e,t.count))),row:({y:e,grid:t})=>(...n)=>n.some((n=>xt(n)?vt[n](e):yt(n,e,t.y))),col:({x:e,grid:t})=>(...n)=>n.some((n=>xt(n)?vt[n](e):yt(n,e,t.x))),even:({count:e,grid:t,y:n})=>r=>{if("cross"===r&&vt.even(t.x)){let t=vt.even(n)?"odd":"even";return vt[t](e)}return vt.even(e)},odd:({count:e,grid:t,y:n})=>r=>{if("cross"===r&&vt.even(t.x)){let t=vt.even(n)?"even":"odd";return vt[t](e)}return vt.odd(e)},random:()=>(t=.5)=>(t>=1&&t<=0&&(t=.5),e()<t),match:({count:e,grid:t,x:n,y:r})=>i=>!!Se("("+i+")",{x:n,y:r,X:t.x,Y:t.y,i:e})}}(t),this.custom_properties={},this.uniforms={},this.unique_id=be(t).unique_id}reset(){this.styles={host:"",container:"",cells:"",keyframes:""},this.coords=[],this.doodles={},this.canvas={},this.shaders={};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,kt(t))}pick_func(e){return this.Func[e]||bt[e]}apply_func(e,t,n){let r=e(...kt(t)),i=[];return n.forEach((e=>{let t=typeof e.value,n="number"===t||"string"===t;if(!e.cluster&&n)i.push(...Ze(e.value,!0));else if("function"==typeof e)i.push(e);else if(!J(e.value)){let t=ne(e.value);i.push(t)}})),i=$t(i),r(...kt(i))}compose_aname(...e){return e.join("-")}compose_selector({x:e,y:t,z:n},r=""){return`#${te(e,t,n)}${r}`}is_composable(e){return["doodle","shaders","canvas"].includes(e)}compose_argument(e,t,n=[]){let r=e.map((e=>{if("text"===e.type)return e.value;if("func"===e.type){let r=e.name.substr(1),i=this.pick_func(r);if("function"==typeof i){if("t"===r&&(this.uniforms.time=!0),this.is_composable(r)){let n=ne((e.arguments[0]||[])[0]);if(!J(n))switch(r){case"doodle":return this.compose_doodle(n);case"shaders":return this.compose_shaders(n,t);case"canvas":return this.compose_canvas(n,t)}}t.extra=n,t.position=e.position;let s=e.arguments.map((e=>i.lazy?(...n)=>this.compose_argument(e,t,n):this.compose_argument(e,t,n))),l=this.apply_func(i,t,s);return"path"==r?this.compose_path(l):l}}}));return{cluster:e.cluster,value:r.length>=2?{value:r.join("")}:r[0]}}compose_doodle(e){let t=this.unique_id("doodle");return this.doodles[t]=e,"${"+t+"}"}compose_shaders(e,{x:t,y:n,z:r}){let i=this.unique_id("shader");return this.shaders[i]={shader:e,cell:te(t,n,r)},"${"+i+"}"}compose_canvas(e,{x:t,y:n,z:r}){let i=this.unique_id("canvas");return this.canvas[i]={code:e,cell:te(t,n,r)},"${"+i+"}"}compose_path(e){let t=this.unique_id("path");return this.paths[t]={id:t,commands:e},"${"+t+"}"}compose_value(e,t){return Array.isArray(e)?e.reduce(((e,n)=>{switch(n.type){case"text":e+=n.value;break;case"func":{let r=n.name.substr(1),i=this.pick_func(r);if("function"==typeof i)if("t"===r&&(this.uniforms.time=!0),this.is_composable(r)){let i=ne((n.arguments[0]||[])[0]);if(!J(i))switch(r){case"doodle":e+=this.compose_doodle(i);break;case"shaders":e+=this.compose_shaders(i,t);break;case"canvas":e+=this.compose_canvas(i,t)}}else{t.position=n.position;let s=n.arguments.map((e=>i.lazy?(...n)=>this.compose_argument(e,t,n):this.compose_argument(e,t))),l=this.apply_func(i,t,s);J(l)||(e+="path"==r?this.compose_path(l):l)}}}return e}),""):""}compose_rule(e,t,n){let r=Object.assign({},t),i=e.property,s=e.value.reduce(((e,t)=>{let n=this.compose_value(t,r);return n&&e.push(n),e}),[]),l=s.join(", ");if(/^animation(\-name)?$/.test(i)){if(this.props.has_animation=!0,St(n)){let e=lt[i];e&&l&&(l=e+","+l)}if(r.count>1){let{count:e}=r;switch(i){case"animation-name":l=s.map((t=>this.compose_aname(t,e))).join(", ");break;case"animation":l=s.map((t=>{let n=(t||"").split(/\s+/);return n[0]=this.compose_aname(n[0],e),n.join(" ")})).join(", ")}}}"content"===i&&(/["']|^none$|^(var|counter|counters|attr)\(/.test(l)||(l=`'${l}'`)),"transition"===i&&(this.props.has_transition=!0);let o=`${i}:${l};`;if(o=ft(i,o),"clip-path"===i&&(o+=";overflow:hidden;"),"width"!==i&&"height"!==i||Et(n)||(o+=`--internal-cell-${i}:${l};`),"background"===i&&(l.includes("shader")||l.includes("canvas"))&&(o+="background-size:100% 100%;"),/^\-\-/.test(i)&&(this.custom_properties[i]=l),gt[i]){let t=gt[i](l,{is_special_selector:Et(n),grid:r.grid});switch(i){case"@grid":St(n)?o=t.size||"":(o="",this.is_grid_defined||(t=gt[i](l,{is_special_selector:!0,grid:r.grid}),this.add_rule(":host",t.size||""))),this.grid=r.grid,this.is_grid_defined=!0;break;case"@place-cell":St(n)||(o=t);break;case"@use":e.value.length&&this.compose(r,e.value),o="";break;default:o=t}}return o}pre_compose_rule(e,t){let n=Object.assign({},t),r=e.property;switch(r){case"@grid":{let t=e.value.reduce(((e,t)=>{let r=this.compose_value(t,n);return r&&e.push(r),e}),[]).join(", "),i=gt[r](t,{});this.grid=i.grid;break}case"@use":e.value.length&&this.pre_compose(n,e.value)}}pre_compose(e,t){(t||this.tokens).forEach((t=>{switch(t.type){case"rule":this.pre_compose_rule(t,e);break;case"pseudo":St(t.selector)&&(t.styles||[]).forEach((t=>{this.pre_compose_rule(t,e)}))}}))}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=Et(t.selector);n&&(t.skip=!0),t.selector.split(",").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=this.Selector[t.name.substr(1)];if(n){let r=t.arguments.map((t=>this.compose_argument(t,e)));this.apply_func(n,e,r)&&this.compose(e,t.styles)}break}case"keyframes":this.keyframes[t.name]||(this.keyframes[t.name]=e=>`\n ${wt(t.steps.map((t=>`\n ${t.name}{${wt(t.styles.map((t=>this.compose_rule(t,e))))}}`)))}`)}}))}output(){Object.keys(this.rules).forEach(((e,t)=>{if(jt(e))this.styles.container+=`\n .container{${wt(this.rules[e])}}`;else{let t=St(e)?"host":"cells",n=wt(this.rules[e]).trim(),r="host"===t?`${e}, .host`:e;this.styles[t]+=`${r}{${n}}`}}));let e=Object.keys(this.keyframes);this.uniforms.time&&(this.styles.container+=`\n:host, .host{animation:${lt.animation};}`,this.styles.keyframes+=`\n @keyframes ${lt["animation-name"]}{from{--${lt.name}:0} to{--${lt.name}:${lt["animation-duration"]}}}`),this.coords.forEach(((t,n)=>{e.forEach((e=>{let r=this.compose_aname(e,t.count);var i,s;this.styles.keyframes+=`\n ${i=0===n,s=`@keyframes ${e}{${this.keyframes[e](t)}}`,i?"function"==typeof s?s():s:""} @keyframes ${r}{${this.keyframes[e](t)}}`}))}));let t=[];return Object.keys(this.custom_properties).forEach((e=>{let n=function(e){let t=String(e).substr(2).split("-")[0];if(void 0!==_t[t])return{name:e,syntax:`<${t}>|<${t}>+ |<${t}>#`,initialValue:_t[t],inherits:!1}}(e);n&&t.push(n)})),{props:this.props,styles:this.styles,grid:this.grid,doodles:this.doodles,shaders:this.shaders,paths:this.paths,canvas:this.canvas,definitions:t,uniforms:this.uniforms}}}function Tt(e,t,n){let r=new zt(e,n),i={};r.pre_compose({x:1,y:1,z:1,count:1,context:{},grid:{x:1,y:1,z:1,count:1}});let{grid:s}=r.output();if(s&&(t=s),r.reset(),1==t.z)for(let e=1,n=0;e<=t.y;++e)for(let s=1;s<=t.x;++s)r.compose({x:s,y:e,z:1,count:++n,grid:t,context:i});else for(let e=1,n=0;e<=t.z;++e)r.compose({x:1,y:1,z:e,count:++n,grid:t,context:i});return r.output()}var At=window,Rt=Math,Pt=[],Ct=256,Mt=Rt.pow(Ct,6),Nt=Rt.pow(2,52),Lt=2*Nt,Ot=255;function It(e,t,n){var r=[],i=Bt(Dt((t=1==t?{entropy:!0}:t||{}).entropy?[e,Ht(Pt)]:null==e?function(){try{var e;return e=new Uint8Array(Ct),(At.crypto||At.msCrypto).getRandomValues(e),Ht(e)}catch(e){var t=At.navigator,n=t&&t.plugins;return[+new Date,At,n,At.screen,Ht(Pt)]}}():e,3),r),s=new Wt(r),l=function(){for(var e=s.g(6),t=Mt,n=0;e<Nt;)e=(e+n)*Ct,t*=Ct,n=s.g(1);for(;e>=Lt;)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,Bt(Ht(s.S),Pt),(t.pass||n||function(e,t,n,r){return r&&(r.S&&Ut(r,s),e.state=function(){return Ut(s,{})}),n?(Rt.random=e,t):e})(l,i,"global"in t?t.global:this==Rt,t.state)}function Wt(e){var t,n=e.length,r=this,i=0,s=r.i=r.j=0,l=r.S=[];for(n||(e=[n++]);i<Ct;)l[i]=i++;for(i=0;i<Ct;i++)l[i]=l[s=Ot&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=Ot&i+1],n=n*Ct+l[Ot&(l[i]=l[s=Ot&s+t])+(l[s]=t)];return r.i=i,r.j=s,n})(Ct)}function Ut(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function Dt(e,t){var n,r=[],i=typeof e;if(t&&"object"==i)for(n in e)try{r.push(Dt(e[n],t-1))}catch(e){}return r.length?r:"string"==i?e:e+"\0"}function Bt(e,t){for(var n,r=e+"",i=0;i<r.length;)t[Ot&i]=Ot&(n^=19*t[Ot&i])+r.charCodeAt(i++);return Ht(t)}function Ht(e){return String.fromCharCode.apply(0,e)}function qt(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}function Ft(e,t){return e.includes(t)?e:t+"\n"+e}Bt(Rt.random(),Pt);function Xt(e,t,n){let r=document.createElement("canvas"),i=window.devicePixelRatio||1;t*=i,n*=i,r.width=t,r.height=n;let s=r.getContext("webgl")||r.getContext("exprimental-webgl");if(!s)return Promise.resolve("");let l=Ft(e.fragment||"","uniform vec2 u_resolution;");e.textures.forEach((e=>{let t=`uniform sampler2D ${e.name};`;l=Ft(l,t)}));let o=function(e,t,n){let r=qt(e,e.VERTEX_SHADER,t),i=qt(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}(s,e.vertex||"\n attribute vec4 position;void main(){gl_Position = position;}","\n precision highp float;"+l),a=s.getAttribLocation(o,"position"),u=s.createBuffer();s.bindBuffer(s.ARRAY_BUFFER,u);return s.bufferData(s.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,-1,1,1,-1,1,1,-1]),s.STATIC_DRAW),s.enableVertexAttribArray(a),s.vertexAttribPointer(a,2,s.FLOAT,!1,0,0),s.viewport(0,0,s.drawingBufferWidth,s.drawingBufferHeight),s.clearColor(0,0,0,0),s.clear(s.COLOR_BUFFER_BIT),s.useProgram(o),s.uniform2fv(s.getUniformLocation(o,"u_resolution"),[t,n]),e.textures.forEach(((e,t)=>{!function(e,t,n){const r=e.createTexture();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.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,e.CLAMP_TO_EDGE),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR)}(s,e.value,t),s.uniform1i(s.getUniformLocation(o,e.name),t)})),s.drawArrays(s.TRIANGLES,0,6),Promise.resolve(r.toDataURL())}class Vt extends HTMLElement{constructor(){super(),this.doodle=this.attachShadow({mode:"open"}),this.extra={get_variable:e=>function(e,t){return getComputedStyle(e).getPropertyValue(t).trim().replace(/^\(|\)$/g,"")}(this,e)}}connectedCallback(e){/^(complete|interactive|loaded)$/.test(document.readyState)?this.load(e):setTimeout((()=>this.load(e)))}update(e){let t=this.get_use();e||(e=this.innerHTML),this.innerHTML=e,this.grid_size||(this.grid_size=this.get_grid());let{x:n,y:r,z:i}=this.grid_size;const s=this.generate(V(t+e,this.extra));if(!this.shadowRoot.innerHTML)return Object.assign(this.grid_size,s.grid),this.build_grid(s,s.grid);if(s.grid){let{x:e,y:t,z:l}=s.grid;if(n!==e||r!==t||i!==l)return Object.assign(this.grid_size,s.grid),this.build_grid(s,s.grid);Object.assign(this.grid_size,s.grid)}else{let s=this.get_grid(),{x:l,y:o,z:a}=s;if(n!==l||r!==o||i!==a)return Object.assign(this.grid_size,s),this.build_grid(this.generate(V(t+e,this.extra)),s)}let l=this.build_svg_paths(s.paths);if(l){let e=this.shadowRoot.querySelector(".svg-defs");e&&(e.innerHTML=l)}s.uniforms.time&&this.register_uniform_time();let o=this.replace(s);this.set_content(".style-keyframes",o(s.styles.keyframes)),s.props.has_animation&&(this.set_content(".style-cells",""),this.set_content(".style-container","")),setTimeout((()=>{this.set_content(".style-container",o(Yt(this.grid_size)+s.styles.host+s.styles.container)),this.set_content(".style-cells",o(s.styles.cells))}))}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)}static get observedAttributes(){return["grid","use","seed"]}attributeChangedCallback(e,t,n){if(t==n)return!1;["grid","use","seed"].includes(e)&&!J(t)&&(this[e]=n)}get_grid(){return ce(this.attr("grid"))}get_use(){let e=this.attr("use")||"";return e&&(e=`@use:${e};`),e}attr(e,t){return 1===arguments.length?this.getAttribute(e):2===arguments.length?(this.setAttribute(e,t),t):void 0}generate(e){let t=this.get_grid(),n=this.attr("seed")||this.attr("data-seed");J(n)&&(n=Date.now()),n=String(n),this._seed_value=n;let r=this.random=It(n);return this.compiled=Tt(e,t,r)}doodle_to_image(e,t,n){"function"==typeof t&&(n=t,t=null);let r=V(e,this.extra),i=ce({}),s=Tt(r,i,this.random),l=s.grid?s.grid:i;const{keyframes:o,host:a,container:u,cells:c}=s.styles;let h=this.build_svg_paths(s.paths),p=this.replace(s),f=Jt(l);p(`\n<svg ${t&&t.width&&t.height?`width="${t.width}" height="${t.height}"`:""} xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none"><foreignObject width="100%" height="100%"><div class="host" xmlns="http://www.w3.org/1999/xhtml"><style>${Gt()} ${Yt(l)} ${a} ${u} ${c} ${o}</style><svg xmlns="http://www.w3.org/2000/svg" style="width:0;height:0"><defs class="svg-defs">${h}</defs></svg>${f}</div></foreignObject></svg>`).then((e=>{let t=`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(e)))}`;ie()&&re(t),n(t)}))}canvas_to_image({code:e,cell:t},n){let r=this.doodle.getElementById(t),{width:i,height:s}=r&&r.getBoundingClientRect()||{width:0,height:0};(function(e,t,n,r){e=se(e);let i=document.createElement("canvas"),s=i.getContext("2d"),l=window.devicePixelRatio||1;i.style.width=i.width+"px",i.style.height=i.height+"px",i.width=t*l,i.height=n*l,s.scale(l,l);try{new Function(`return (ctx, width, height, random) =>{${e}}`)()(s,t,n,r)}catch(e){}return Promise.resolve(i.toDataURL())})(e,i,s,this.random).then(n)}shader_to_image({shader:e,cell:t},n){let i=function(e){let t,n,i=r(fe(h(e))),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=de(l);he(n)?(t=n,l=[]):l.push(e)}s.push("{")}else if(e.isSymbol("}"))if(s.pop(),!s.length&&t){let e=de(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 Q(n)||n==e.pos[1]||(l.push(pe()),n=null),e.isWord()&&e.value.startsWith("#")&&(l.push(pe()),n=r.pos[1]),l.push(e)}return Q(o.fragment)?{fragment:de(l),textures:[]}:o}(e),s=this.doodle.getElementById(t),{width:l,height:o}=s&&s.getBoundingClientRect()||{width:0,height:0},a=window.devicePixelRatio||1;if(i.textures.length){let e=i.textures.map((e=>new Promise((t=>{this.doodle_to_image(e.value,{width:l,height:o},(n=>{let r=new Image;r.width=l*a,r.height=o*a,r.onload=()=>t({name:e.name,value:r}),r.src=n}))}))));Promise.all(e).then((e=>{i.textures=e,Xt(i,l,o).then(n)}))}else Xt(i,l,o).then(n)}load(e){e||this.hasAttribute("click-to-update")&&this.addEventListener("click",(e=>this.update()));let t=V(this.get_use()+se(this.innerHTML),this.extra),n=this.generate(t);this.grid_size=n.grid?n.grid:this.get_grid(),this.build_grid(n,this.grid_size)}replace({doodles:e,shaders:t,paths:n,canvas:r}){let i=Object.keys(e),s=Object.keys(t),l=Object.keys(n),o=Object.keys(r);return n=>{if(!(i.length||s.length||l.length||o.length))return Promise.resolve(n);let a=[].concat(i.map((t=>n.includes(t)?new Promise((n=>{this.doodle_to_image(e[t],(e=>n({id:t,value:e})))})):Promise.resolve(""))),s.map((e=>n.includes(e)?new Promise((n=>{this.shader_to_image(t[e],(t=>n({id:e,value:t})))})):Promise.resolve(""))),o.map((e=>n.includes(e)?new Promise((t=>{this.canvas_to_image(r[e],(n=>t({id:e,value:n})))})):Promise.resolve(""))),l.map((e=>n.includes(e)?Promise.resolve({id:e,value:"#"+e}):Promise.resolve(""))));return Promise.all(a).then((e=>(n.replaceAll?e.forEach((({id:e,value:t})=>{n=n.replaceAll("${"+e+"}",`url(${t})`)})):e.forEach((({id:e,value:t})=>{n=n.replace("${"+e+"}",`url(${t})`)})),n)))}}build_grid(e,t){const{has_transition:n,has_animation:r}=e.props;let i=n||r;const{keyframes:s,host:l,container:o,cells:a}=e.styles;let u=Yt(t)+l+o,c=i?"":a,h=this.build_svg_paths(e.paths);const{uniforms:p}=e;let f=this.replace(e);this.doodle.innerHTML=`\n<style>${Gt(p)}</style><style class="style-keyframes">${s}</style><style class="style-container">${u}</style><style class="style-cells">${c}</style><svg xmlns="http://www.w3.org/2000/svg" style="width:0;height:0"><defs class="svg-defs">${h}</defs></svg>${Jt(t)}`,this.set_content(".style-container",f(u)),i?setTimeout((()=>{this.set_content(".style-cells",f(a))}),50):this.set_content(".style-cells",f(a));const d=e.definitions;if(window.CSS&&window.CSS.registerProperty)try{p.time&&this.register_uniform_time(),d.forEach(CSS.registerProperty)}catch(e){}}build_svg_paths(e){return Object.keys(e||{}).map((t=>`\n<clipPath id="${e[t].id}" clipPathUnits="objectBoundingBox"><path d="${e[t].commands}" /></clipPath>`)).join("")}register_uniform_time(){if(!this.is_uniform_time_registered){try{CSS.registerProperty({name:"--"+lt.name,syntax:"<number>",initialValue:0,inherits:!0})}catch(e){}this.is_uniform_time_registered=!0}}export({scale:e,name:t,download:n,detail:r}={}){return new Promise(((i,s)=>{let l=function(e){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 in e)t.push(n+":"+e[n]);return t.join(";")}(t)}(this),o=this.doodle.innerHTML,{width:a,height:u}=this.getBoundingClientRect(),c=a*(e=parseInt(e)||1),h=u*e,p=`\n<svg xmlns="http://www.w3.org/2000/svg"\n preserveAspectRatio="none"\n viewBox="0 0 ${a} ${u}"\n ${ie()?"":`width="${c}px" height="${h}px"`}><foreignObject width="100%" height="100%"><div\n class="host"\n xmlns="http://www.w3.org/1999/xhtml"\n style="width:${a}px;height:${u}px;"\n><style>.host{${f=l,f.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""")}}</style>${o}</div></foreignObject></svg>`.replace(/\n\s+|^\s+|\n+/g," ").trim();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=window.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)}}}ie()?re(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(J(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_content(e,t){if(t instanceof Promise)t.then((t=>{this.set_content(e,t)}));else{const n=this.shadowRoot.querySelector(e);n&&(n.styleSheet?n.styleSheet.cssText=t:n.innerHTML=t)}}}function Gt(e={}){const t=ut(/grid/).map((e=>`${e}:inherit;`)).join("");return`\n *{box-sizing:border-box\n} *::after, *::before{box-sizing:inherit\n}:host, .host{display:block;visibility:visible;width:auto;height:auto;--${lt.name}:0\n}:host([hidden]), .host[hidden]{display:none\n} .container{position:relative;width:100%;height:100%;display:grid;${t}} cell:empty{position:relative;line-height:1;display:grid;place-items:center\n} svg{position:absolute;width:100%;height:100%;}`}function Yt(e){let{x:t,y:n}=e||{};return`\n:host, .host{grid-template-rows:repeat(${n}, 1fr);grid-template-columns:repeat(${t}, 1fr);}`}function Zt(e,t,n){let r=document.createElement("cell");return r.id=te(e,t,n),r}function Jt(e){let{x:t,y:n,z:r}=e||{},i=document.createElement("grid"),s=document.createDocumentFragment();if(1==r)for(let e=1;e<=n;++e)for(let n=1;n<=t;++n)s.appendChild(Zt(n,e,1));else{let e=null;for(let t=1;t<=r;++t){let n=Zt(1,1,t);(e||s).appendChild(n),e=n}e=null}return i.className="container",i.appendChild(s),i.outerHTML}customElements.get("css-doodle")||customElements.define("css-doodle",Vt);return le((e=>{let t=document.createElement("css-doodle");return t.update&&t.update(e),t}))}));