css-doodle/css-doodle.min.js

86 lines
55 KiB
JavaScript

/*! css-doodle@0.21.5 */
!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,s=0;return{curr:(n=0)=>e[t+n],next(n=1){let i=e[t+=n];return"\n"==i?(s++,r=0):r+=n,i},end:()=>t>=n,get:()=>({prev:e[t-1],curr:e[t+0],next:e[t+1],next2:e[t+2],next3:e[t+3],pos:[r,s]})}}function s(e){for(;e.next();){let{curr:n,prev:r}=e.get();if(t.comment(n,r))break}}function i(e){return[":",";",",","{","}","(",")","[","]"].includes(e)}function l(e){let n="";for(;!e.end();){let{curr:r,next:s}=e.get();n+=r;let i=t.symbol(s)||t.space(s)||t.digit(s);if(n.length&&i&&!t.closedTag(r,s))break;e.next()}return n.trim()}function o(e){let n="";for(;!e.end();){let{curr:r,next:s}=e.get();if(n+=r,!t.space(s))break;e.next()}return n}function a(e){let n="",r=!1;for(;!e.end();){let{curr:s,next:i,next2:l,next3:o}=e.get();if(n+=s,r&&t.dot(i))break;if(t.dot(s)&&(r=!0),t.dots(i,l))break;if(t.expWithSign(i,l,o))n+=e.next()+e.next();else if(t.exp(i,l))n+=e.next();else if(!t.digit(i)&&!t.dot(i))break;e.next()}return n}function u(e){let n="0x";for(e.next(2);!e.end();){let{curr:r,next:s}=e.get();if(n+=r,!t.hexNum(s))break;e.next()}return n}function 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))s(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 s={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(),s.status="close"):(f.push(r),s.status="open")}p.push(new n(s))}}else if(t.space(r)){let e=o(h),t=c(p),{next:r}=h.get();if(!f.length&&t){if(i(t.value)||i(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:s}=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--),s=n[r];n[r]=n[t],n[t]=s}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(),s="";for(;!t.end();){let n=t.next();if(e(n))break;s+=n}return n&&t.index(r),s}}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,s=[],i=[],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&&(i.length?i.push(b.text(o)):i.push(b.text((a=o).trim().length?_.number(+a)?+a:a.trim():a)),o.startsWith("\xb1")&&!n)){let e=o.substr(1),t=x(i);v(t).value="-"+e,s.push(L(t)),v(i).value=e}if(s.push(L(i)),[i,o]=[[],""],")"==r)break}else w[r]&&!/[0-9]/.test(e.curr(-1))&&(r=w[r]),o+=r;else i.length||(o=o.trimLeft()),o.length&&(i.push(b.text(o)),o=""),i.push(O(e));if(!(!t||")"!=e.curr()&&/[0-9a-zA-Z_\-.]/.test(e.curr())||l.length)){i.length&&s.push(L(i));break}e.next()}var a;return s}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),s=v(r.value);"string"==typeof n.value&&"string"==typeof r.value&&_.pair_of(e,s)&&(n.value=n.value.slice(1),r.value=r.value.slice(0,r.value.length-1),t.cluster=!0)}return t}function O(e){let t,n=b.func(),r="@",s=!1;for(e.next();!e.end();){t=e.curr();let i="."==t&&"@"==e.curr(1),l=e.curr(1);if("("==t||i){s=!0,e.next(),n.arguments=N(e,i,k(r));break}if(!s&&"("!==l&&!/[0-9a-zA-Z_\-.]/.test(l)){r+=t;break}r+=t,e.next()}let{fname:i,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 s=e[r],i=e[r-1],l=e[r+1];if(!(/[\d.]/.test(s)||"x"==s&&/\d/.test(i)&&/\d/.test(l))){t=e.substring(0,r+1);break}n=s+n}return{fname:t,extra:n}}(r);return n.name=i,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,s=!0;const i=[],l=[];for(i[r]=[];!e.end();)if(t=e.curr(),s&&_.white_space(t))e.next();else{if(s=!1,"\n"!=t||_.white_space(e.curr(-1)))if(","!=t||l.length){if(/[;}<]/.test(t)){n.value.length&&(i[r].push(n),n=b.text());break}"@"==t?(n.value.length&&(i[r].push(n),n=b.text()),i[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&&(i[r].push(n),n=b.text()),i[++r]=[],s=!0;else n.value+=" ";e.next()}return n.value.length&&i[r].push(n),i}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,s="",i="";s=q(t,n.name),!s&&n.fallback&&n.fallback.every((e=>{if(i=q(t,e.name),i)return s=i,!1}));try{r=V(s,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 s=e[t++];return"\n"==s?(r++,n=0):n++,s}}}(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,s=e,i=e=>e>0&&e<1?.1:1,l=arguments.length;1==l&&([e,t]=[i(e),e]),l<3&&(n=i(e));let o=[];for(;(n>=0&&e<=t||n<0&&e>t)&&(o.push(e),e+=n,!(r++>=1e3)););return o.length||o.push(s),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 se(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function ie(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(s=n[r])?"":s);var s}),"");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 s=1==t||1==n?ue:ae,i=1==t&&1==n?ue:oe,l={x:G(t||oe,1,s),y:G(n||t||oe,1,s),z:G(r||oe,1,i)};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,s=0;for(;0===r;)r=e();for(;0===s;)s=e();const i=Math.sqrt(-2*Math.log(r)),l=2*Math.PI*s;return t+n*(i*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,"=":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:i,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),(s=n)[0]==s[2]&&s[1]==s[3]?(e=0,n=[]):e=Ee(ze(e),t,n)),r.push(e)}else if("function"===o){let e=!1;/^\-/.test(i)&&(e=!0,i=i.substr(1));let n,s=l.map((e=>Ee(e,t))),o=i.split(".");for(;n=o.pop();){if(!n)continue;let e=t[n]||Math[n];s="function"==typeof e?Array.isArray(s)?e(...s):e(s):0}e&&(s*=-1),r.push(s)}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 s;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 s=t[e];if(je[s]){let i=ke(n);if("="==s&&i&&/^[!<>=]$/.test(i.value))i.value+=s;else if(/^[|&<>]$/.test(s)&&i&&i.value==s)i.value+=s;else if("-"==s&&"e"==t[e-1])r+=s;else if(n.length||r.length||!/[+-]/.test(s)){let{type:e,value:t}=i||{};"operator"==e&&!r.length&&/[^()]/.test(s)&&/[^()]/.test(t)?r+=s:(r.length&&(n.push({type:"number",value:r}),r=""),n.push({type:"operator",value:s}))}else r+=s}else/\S/.test(s)&&(","==s?(n.push({type:"number",value:r}),r="",n.push({type:"comma",value:s})):"!"==s?(n.push({type:"number",value:r}),n.push({type:"operator",value:s}),r=""):r+=s)}return r.length&&n.push({type:"number",value:r}),n}(e);const n=[],r=[];for(let e=0;e<t.length;++e){let{type:s,value:i}=t[e],l=t[e+1]||{};if("number"==s)if("("==l.value&&/[^\d.\-]/.test(i)){let n="",s=[],l=[];for(e+=1;void 0!==t[e++];){let r=t[e];if(void 0===r)break;let i=r.value;if(")"==i){if(!s.length)break;s.pop(),n+=i}else if("("==i&&s.push(i),","!=i||s.length)n+=i;else{let e=ze(n);e.length&&l.push(e),n=""}}n.length&&l.push(ze(n)),r.push({type:"function",name:i,value:l})}else/[^\d.\-]/.test(i)?r.push({type:"variable",value:i}):r.push({type:"number",value:i});else if("operator"==s)if("("==i)n.push(i);else if(")"==i){for(;n.length&&"("!=ke(n);)r.push({type:"operator",value:n.pop()});n.pop()}else{for(;n.length&&je[ke(n)]>=je[i];){let e=n.pop();/[()]/.test(e)||r.push({type:"operator",value:e})}n.push(i)}}for(;n.length;)r.push({type:"operator",value:n.pop()});return r}function 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 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 Ae(e,t){let[n,r,s]=e.match(/([\d.\-]+)(.*)/)||[],i=t[s];return void 0===i?i:"number"==typeof i?Number(r)*i:r*Ee(ze(i),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 s=t[e];if("-"!=s||"-"!=t[e-1])if("-"!=s)if("-"!=Ce(r))r.length&&n.push(Le("char",r.pop())),r.push(s);else{r.pop();let e=r.pop();n.push(e?Le("range",[e,s]):Le("char",s))}else r.push(s)}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,s=!1;n>r&&([n,r]=[r,n],s=!0);let i=we(Y)(n,r);return s&&i.reverse(),i}))}));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)),s={},i=[],l=!1;for(;n.next();){let{prev:e,curr:r,next:o}=n.get();if(r.isSymbol(":")&&!t)t=Be(i),i=[];else if(r.isSymbol(";")&&t)s[t]=De(t,Be(i),l),i=[],t=null,l=!1;else if(!r.isSymbol(";")){let n=e&&e.isSymbol("-"),s=o&&o.isSymbol("-"),a=r.isSymbol("-");t||i.length||!a||n||s||o&&o.isSymbol(":")?i.push(r):l=!0}}return i.length&&t&&(s[t]=De(t,Be(i),l)),s}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=>Ze(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,t,n){let[r,s=r]=String(n).split(/[,\s]+/).map(Number);return[e*r,t*s]}function Ze(e,{min:t,max:n}){let r=G(parseInt(e.vertices||e.points||e.split)||0,t,n),s=Object.assign({},e,{split:r}),i=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,s=e.split||180,i=e.turn||1,l=e.frame,o=e.fill||e["fill-rule"],a=2*Xe*i/s,u=[];"nonzero"!=o&&"evenodd"!=o||u.push(o);let c=void 0===e.scale?1:e.scale,h=([t,n])=>{let[r,s]=Ye(t,-n,c);e.absolute||(r=50*(r+1)+"%",s=50*(s+1)+"%"),u.push(r+" "+s)};for(let e=0;e<s;++e){let r=t(a*e,e);e||(n=r),h(r)}if(void 0!==l){h(n);let e=l/100;i>1&&(e*=2),0==e&&(e=.002);for(let n=0;n<s;++n){let s=-a*n,[i,l,o=0,u=0]=t(s,n),c=Fe(l+u,i-o),p=[i-e*He(c),l-e*qe(c)];n||(r=p),h(p)}h(r),h(n)}return u}(s,((t,n)=>{let s=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(i,s),u=Se(l,s),c=0,h=0;if(o){let e=Se(o,s);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,s=r]=String(n).split(/[,\s]+/).map(Number);return[e+(r||0),t-(s||0),r,s]}(a,u,e.move)),[a,u,c,h]}))}function Je(e,t){let n=[],s=[],i=[],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("(")&&i.push(r.value),r.isSymbol(")")&&i.pop(),"open"===r.status&&l.push(r.value),"close"===r.status&&l.pop(),a=r,!(t?a.isSymbol(","):a.isSymbol(",")||a.isSpace())||i.length||l.length?s.push(r):(n.push(Ke(s)),s=[])}var a;return s.length&&n.push(Ke(s)),n}function Ke(e){return e.map((e=>e.value)).join("")}function Qe(e,t){let n=[];for(;e.next();){let{curr:t,next:r}=e.get(),s=!r||t.isSymbol(";")||r.isSymbol("}");if(n.push(t),s)break}return n.length&&(t.value=nt(n)),t}function et(e,t){let n=[],r=[],s=t&&t.type||"";for(;e.next();){let{prev:i,curr:l,next:o}=e.get(),a=!o||l.isSymbol("}");if("block"===s&&a){o||!n.length||l.isSymbol("}")||(n[n.length-1].value+=";"+l.value),t.value=n;break}if(l.isSymbol("{")){let t=st(r,(e=>e.isSpace()));if(!t.length)continue;let s=t.pop(),i=rt(et(e,{type:"block",name:s,value:[]}));for(;s=t.pop();)i=rt({type:"block",name:s,value:[i]});n.push(i),r=[]}else if(l.isSymbol(":")&&!tt(i,o)&&r.length){let i=st(r,(e=>e.isSymbol(","))),l=Qe(e,{type:"statement",name:"unkown",value:""});i.forEach((e=>{n.push(Object.assign({},l,{name:e}))})),"block"==s&&(t.value=n),r=[]}else l.isSymbol(";")?n.length&&r.length&&(n[n.length-1].value+=";"+nt(r),r=[]):r.push(l)}return n.length&&"block"==s&&(t.value=n),s?t:n}function tt(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 nt(e){return e.filter(((t,n)=>!t.isSymbol(";","}")||n!==e.length-1)).map((e=>e.value)).join("")}function rt(e){let t=e.name||"",[n,...r]=t.split(/#/),s=r[r.length-1];return s&&(e.name=n,e.value.push({type:"statement",name:"id",value:s})),e}function st(e,t){let n=[],r=[];return e.forEach((e=>{t(e)?(n.push(nt(r)),r=[]):r.push(e)})),r.length&&n.push(nt(r)),n}function it(e,t){return et(r(h(e)),t||{type:"block",name:"svg",value:[]})}function lt(e){let t=r(h(e)),n={},s={commands:[],valid:!0};for(;t.next();){let{curr:e}=t.get();if(!e.isSpace()&&!e.isSymbol(","))if(e.isWord())n.name&&(s.commands.push(n),n={}),n.name=e.value,n.value=[],"MmLlHhVvCcSsQqTtAaZz".includes(e.value)?"mlhvcsqtaz".includes(e.value)?n.type="relative":n.type="absolute":(n.type="unknown",s.valid=!1);else if(n.value){let t=e.value;e.isNumber()&&(t=Number(e.value)),n.value.push(t)}else n.name||(s.valid=!1)}return n.name&&s.commands.push(n),s}const ot={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 at(e){const{shuffle:t}=g(e),{pick:n,rand:r,nrand:s,unique_id:i}=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 s=n.length,[i=e[r]]=t||[],l=n[(i-1)%s];return a(e,"last_pick",l)}))},"pick-d"({context:e,extra:n,position:r}){let s="pd-counter"+r,i="pd-values"+r;return Ne(((...r)=>{e[s]||(e[s]=0),e[s]+=1,e[i]||(e[i]=t(r));let l=r.length,[o=e[s]]=n||[],u=(o-1)%l,c=e[i][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)(s).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(s(...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,s=0,i=[];if(!r)return"";n.forEach((e=>{let[t,n]=Je(e);void 0!==n?i.push(n):s+=1}));let l=i.length?`(100% - ${i.join(" - ")}) / ${s}`:`100% / ${r}`;return n.map(((e,n)=>{if(i.length){let[n,r]=Je(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=i("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(--${ot.name})`,plot({count:e,context:t,extra:n,position:r,grid:s}){let i="offset-points"+r;return r=>{let[l=e,o,a,u=s.count]=n||[];if(!t[i]){let e=Ue(r);e.points=u,t[i]=Ze(e,{min:1,max:65536})}return t[i][l-1]}},Plot({count:e,context:t,extra:n,position:r,grid:s}){let i="offset-points"+r;return r=>{let[l=e,o,a,u=s.count]=n||[];if(!t[i]){let e=Ue(r);e.points=u,e.absolute=!0,t[i]=Ze(e,{min:1,max:65536})}return t[i][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,s=t.join(",");s.length&&(r=e+","+s),n=Ze(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=lt(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=lt(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=lt(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=lt(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()),s=Se(r);return 0===s&&(s=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 s=n*r,i=[],l=1;for(let e=1;e<=r;++e)for(let r=1;r<=n;++r)i.push(t(l++,r,e,s));return i}(s,((...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:"plot",Offset:"Plot",point:"plot",Point:"Plot",stripes:"stripe",strip:"stripe"},Object.keys(h).forEach((e=>{c[e]=c[h[e]]})),c;var c,h}ot.animation=`\n ${ot["animation-duration"]}ms\n ${ot["animation-timing-function"]}\n ${ot["animation-delay"]}\n ${ot["animation-iteration-count"]}\n ${ot["animation-name"]}\n`;let ut=[];function ct(e){if(!ut.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"),ut=Array.from(e)}return e&&e.test?ut.filter((t=>e.test(t))):ut}function ht(e){let t=new RegExp(`\\-?${e}\\-?`);return ct(t).map((e=>e.replace(t,""))).reduce(((e,t)=>(e[t]=t,e)),{})}const pt=ht("webkit"),ft=ht("moz");function dt(e,t){return pt[e]?`-webkit-${t} ${t}`:ft[e]?`-moz-${t} ${t}`:t}const mt={"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]},gt={portrait:"p",pt:"p",p:"p",landscape:"l",ls:"l",l:"l"};var yt={"@size"(e,{is_special_selector:t,grid:n}){let[r,s=r]=Je(e);mt[r]&&([r,s]=function(e,t){e=String(e).toLowerCase();let[n,r]=mt[e]||[];return"p"==gt[t]&&([r,n]=[n,r]),[r,n].map((e=>e+"mm"))}(r,s));let i=`\n width: ${r};\n height: ${s};\n `;return t?"auto"!==r&&"auto"!==s||(i+=`aspect-ratio: ${n.ratio};`):i+=`\n --internal-cell-width: ${r};\n --internal-cell-height: ${s};\n `,i},"@min-size"(e){let[t,n=t]=Je(e);return`min-width: ${t}; min-height: ${n};`},"@max-size"(e){let[t,n=t]=Je(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,s="50%"]=Je(n);r=e[r]||r,s=t[s]||s;const i="var(--internal-cell-width, 25%)",l="var(--internal-cell-height, 25%)";return`\n position: absolute;\n left: ${r};\n top: ${s};\n width: ${i};\n height: ${l};\n margin-left: calc(${i} / -2);\n margin-top: calc(${l} / -2);\n grid-area: unset;\n `}})(),"@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]=Je(e),r="clip-path";return"function"!=typeof Ge[t]?"":dt(r,`${r}: polygon(${Ge[t](...n).join(",")});`)+"overflow: hidden;"})),"@use"(e){if(e.length>2)return e}};function vt(e,t,n){for(let r=0;r<=n;++r)if(Se(e,{n:r})==t)return!0}const xt={even:e=>!(e%2),odd:e=>!!(e%2)};function bt(e){return/^(even|odd)$/.test(e)}var _t=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 wt={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:kt,make_array:$t,remove_empty_values:St}=g();function jt(e){return/^\:(host|doodle)/.test(e)}function Et(e){return/^\:(container|parent)/.test(e)}function zt(e){return jt(e)||Et(e)}class Tt{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=at(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=>bt(n)?xt[n](e):vt(n,e,t.count))),row:({y:e,grid:t})=>(...n)=>n.some((n=>bt(n)?xt[n](e):vt(n,e,t.y))),col:({x:e,grid:t})=>(...n)=>n.some((n=>bt(n)?xt[n](e):vt(n,e,t.x))),even:({count:e,grid:t,y:n})=>r=>{if("cross"===r&&xt.even(t.x)){let t=xt.even(n)?"odd":"even";return xt[t](e)}return xt.even(e)},odd:({count:e,grid:t,y:n})=>r=>{if("cross"===r&&xt.even(t.x)){let t=xt.even(n)?"even":"odd";return xt[t](e)}return xt.odd(e)},random:()=>(t=.5)=>(t>=1&&t<=0&&(t=.5),e()<t),match:({count:e,grid:t,x:n,y:r})=>s=>!!Se("("+s+")",{x:n,X:t.x,y:r,Y:t.y,i:e,I:t.count})}}(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,$t(t))}pick_func(e){return this.Func[e]||_t[e]}apply_func(e,t,n){let r=e(...$t(t)),s=[];return n.forEach((e=>{let t=typeof e.value,n="number"===t||"string"===t;if(!e.cluster&&n)s.push(...Je(e.value,!0));else if("function"==typeof e)s.push(e);else if(!J(e.value)){let t=ne(e.value);s.push(t)}})),s=St(s),r(...$t(s))}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),s=this.pick_func(r);if("function"==typeof s){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 i=e.arguments.map((e=>s.lazy?(...n)=>this.compose_argument(e,t,n):this.compose_argument(e,t,n))),l=this.apply_func(s,t,i);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 s=this.unique_id("shader");return this.shaders[s]={shader:e,cell:te(t,n,r)},"${"+s+"}"}compose_canvas(e,{x:t,y:n,z:r}){let s=this.unique_id("canvas");return this.canvas[s]={code:e,cell:te(t,n,r)},"${"+s+"}"}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),s=this.pick_func(r);if("function"==typeof s)if("t"===r&&(this.uniforms.time=!0),this.is_composable(r)){let s=ne((n.arguments[0]||[])[0]);if(!J(s))switch(r){case"doodle":e+=this.compose_doodle(s);break;case"shaders":e+=this.compose_shaders(s,t);break;case"canvas":e+=this.compose_canvas(s,t)}}else{t.position=n.position;let i=n.arguments.map((e=>s.lazy?(...n)=>this.compose_argument(e,t,n):this.compose_argument(e,t))),l=this.apply_func(s,t,i);J(l)||(e+="path"==r?this.compose_path(l):l)}}}return e}),""):""}compose_rule(e,t,n){let r=Object.assign({},t),s=e.property,i=e.value.reduce(((e,t)=>{let n=this.compose_value(t,r);return n&&e.push(n),e}),[]),l=i.join(", ");if(/^animation(\-name)?$/.test(s)){if(this.props.has_animation=!0,jt(n)){let e=ot[s];e&&l&&(l=e+","+l)}if(r.count>1){let{count:e}=r;switch(s){case"animation-name":l=i.map((t=>this.compose_aname(t,e))).join(", ");break;case"animation":l=i.map((t=>{let n=(t||"").split(/\s+/);return n[0]=this.compose_aname(n[0],e),n.join(" ")})).join(", ")}}}"content"===s&&(/["']|^none$|^(var|counter|counters|attr)\(/.test(l)||(l=`'${l}'`)),"transition"===s&&(this.props.has_transition=!0);let o=`${s}: ${l};`;if(o=dt(s,o),"clip-path"===s&&(o+=";overflow: hidden;"),"width"!==s&&"height"!==s||zt(n)||(o+=`--internal-cell-${s}: ${l};`),"background"===s&&(l.includes("shader")||l.includes("canvas"))&&(o+="background-size: 100% 100%;"),/^\-\-/.test(s)&&(this.custom_properties[s]=l),yt[s]){let t=yt[s](l,{is_special_selector:zt(n),grid:r.grid});switch(s){case"@grid":jt(n)?o=t.size||"":(o="",this.is_grid_defined||(t=yt[s](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":jt(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(", "),s=yt[r](t,{});this.grid=s.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":jt(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=zt(t.selector);n&&(t.skip=!0),t.selector.split(",").forEach((r=>{let s=t.styles.map((t=>this.compose_rule(t,e,r))),i=n?r:this.compose_selector(e,r);this.add_rule(i,s)}));break}case"cond":{let n=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 ${kt(t.steps.map((t=>`\n ${t.name} {\n ${kt(t.styles.map((t=>this.compose_rule(t,e))))}\n }\n `)))}\n `)}}))}output(){Object.keys(this.rules).forEach(((e,t)=>{if(Et(e))this.styles.container+=`\n .container {\n ${kt(this.rules[e])}\n }\n `;else{let t=jt(e)?"host":"cells",n=kt(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 {\n animation: ${ot.animation};\n }\n `,this.styles.keyframes+=`\n @keyframes ${ot["animation-name"]} {\n from { --${ot.name}: 0 }\n to { --${ot.name}: ${ot["animation-duration"]} }\n }\n `),this.coords.forEach(((t,n)=>{e.forEach((e=>{let r=this.compose_aname(e,t.count);var s,i;this.styles.keyframes+=`\n ${s=0===n,i=`@keyframes ${e} {\n ${this.keyframes[e](t)}\n }`,s?"function"==typeof i?i():i:""}\n @keyframes ${r} {\n ${this.keyframes[e](t)}\n }\n `}))}));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!==wt[t])return{name:e,syntax:`<${t}> | <${t}>+ | <${t}>#`,initialValue:wt[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 At(e,t,n){let r=new Tt(e,n),s={};r.pre_compose({x:1,y:1,z:1,count:1,context:{},grid:{x:1,y:1,z:1,count:1}});let{grid:i}=r.output();if(i&&(t=i),r.reset(),1==t.z)for(let e=1,n=0;e<=t.y;++e)for(let i=1;i<=t.x;++i)r.compose({x:i,y:e,z:1,count:++n,grid:t,context:s});else for(let e=1,n=0;e<=t.z;++e)r.compose({x:1,y:1,z:e,count:++n,grid:t,context:s});return r.output()}var Rt=window,Pt=Math,Ct=[],Mt=256,Nt=Pt.pow(Mt,6),Lt=Pt.pow(2,52),Ot=2*Lt,It=255;function Wt(e,t,n){var r=[],s=Ht(Bt((t=1==t?{entropy:!0}:t||{}).entropy?[e,qt(Ct)]:null==e?function(){try{var e;return e=new Uint8Array(Mt),(Rt.crypto||Rt.msCrypto).getRandomValues(e),qt(e)}catch(e){var t=Rt.navigator,n=t&&t.plugins;return[+new Date,Rt,n,Rt.screen,qt(Ct)]}}():e,3),r),i=new Ut(r),l=function(){for(var e=i.g(6),t=Nt,n=0;e<Lt;)e=(e+n)*Mt,t*=Mt,n=i.g(1);for(;e>=Ot;)e/=2,t/=2,n>>>=1;return(e+n)/t};return l.int32=function(){return 0|i.g(4)},l.quick=function(){return i.g(4)/4294967296},l.double=l,Ht(qt(i.S),Ct),(t.pass||n||function(e,t,n,r){return r&&(r.S&&Dt(r,i),e.state=function(){return Dt(i,{})}),n?(Pt.random=e,t):e})(l,s,"global"in t?t.global:this==Pt,t.state)}function Ut(e){var t,n=e.length,r=this,s=0,i=r.i=r.j=0,l=r.S=[];for(n||(e=[n++]);s<Mt;)l[s]=s++;for(s=0;s<Mt;s++)l[s]=l[i=It&i+e[s%n]+(t=l[s])],l[i]=t;(r.g=function(e){for(var t,n=0,s=r.i,i=r.j,l=r.S;e--;)t=l[s=It&s+1],n=n*Mt+l[It&(l[s]=l[i=It&i+t])+(l[i]=t)];return r.i=s,r.j=i,n})(Mt)}function Dt(e,t){return t.i=e.i,t.j=e.j,t.S=e.S.slice(),t}function Bt(e,t){var n,r=[],s=typeof e;if(t&&"object"==s)for(n in e)try{r.push(Bt(e[n],t-1))}catch(e){}return r.length?r:"string"==s?e:e+"\0"}function Ht(e,t){for(var n,r=e+"",s=0;s<r.length;)t[It&s]=It&(n^=19*t[It&s])+r.charCodeAt(s++);return qt(t)}function qt(e){return String.fromCharCode.apply(0,e)}function Ft(e,t,n){let r=e.createShader(t);return e.shaderSource(r,n),e.compileShader(r),r}function Xt(e,t){return e.includes(t)?e:t+"\n"+e}Ht(Pt.random(),Ct);function Vt(e,t,n){let r=document.createElement("canvas"),s=window.devicePixelRatio||1;t*=s,n*=s,r.width=t,r.height=n;let i=r.getContext("webgl")||r.getContext("exprimental-webgl");if(!i)return Promise.resolve("");let l=Xt(e.fragment||"","uniform vec2 u_resolution;");e.textures.forEach((e=>{let t=`uniform sampler2D ${e.name};`;l=Xt(l,t)}));let o=function(e,t,n){let r=Ft(e,e.VERTEX_SHADER,t),s=Ft(e,e.FRAGMENT_SHADER,n),i=e.createProgram();return e.attachShader(i,r),e.attachShader(i,s),e.linkProgram(i),e.getProgramParameter(i,e.LINK_STATUS)||(console.warn("Link failed: "+e.getProgramInfoLog(i)),console.warn("vs info-log: "+e.getShaderInfoLog(r)),console.warn("fs info-log: "+e.getShaderInfoLog(s))),i}(i,e.vertex||"\n attribute vec4 position;\n void main() {\n gl_Position = position;\n }\n","\n precision highp float;\n"+l),a=i.getAttribLocation(o,"position"),u=i.createBuffer();i.bindBuffer(i.ARRAY_BUFFER,u);return i.bufferData(i.ARRAY_BUFFER,new Float32Array([-1,-1,-1,1,1,-1,1,1,-1,1,1,-1]),i.STATIC_DRAW),i.enableVertexAttribArray(a),i.vertexAttribPointer(a,2,i.FLOAT,!1,0,0),i.viewport(0,0,i.drawingBufferWidth,i.drawingBufferHeight),i.clearColor(0,0,0,0),i.clear(i.COLOR_BUFFER_BIT),i.useProgram(o),i.uniform2fv(i.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)}(i,e.value,t),i.uniform1i(i.getUniformLocation(o,e.name),t)})),i.drawArrays(i.TRIANGLES,0,6),Promise.resolve(r.toDataURL())}class Gt 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:s}=this.grid_size;const i=this.generate(V(t+e,this.extra));if(!this.shadowRoot.innerHTML)return Object.assign(this.grid_size,i.grid),this.build_grid(i,i.grid);if(i.grid){let{x:e,y:t,z:l}=i.grid;if(n!==e||r!==t||s!==l)return Object.assign(this.grid_size,i.grid),this.build_grid(i,i.grid);Object.assign(this.grid_size,i.grid)}else{let i=this.get_grid(),{x:l,y:o,z:a}=i;if(n!==l||r!==o||s!==a)return Object.assign(this.grid_size,i),this.build_grid(this.generate(V(t+e,this.extra)),i)}let l=this.build_svg_paths(i.paths);if(l){let e=this.shadowRoot.querySelector(".svg-defs");e&&(e.innerHTML=l)}i.uniforms.time&&this.register_uniform_time();let o=this.replace(i);this.set_content(".style-keyframes",o(i.styles.keyframes)),i.props.has_animation&&(this.set_content(".style-cells",""),this.set_content(".style-container","")),setTimeout((()=>{this.set_content(".style-container",o(Zt(this.grid_size)+i.styles.host+i.styles.container)),this.set_content(".style-cells",o(i.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=Wt(n);return this.compiled=At(e,t,r)}doodle_to_image(e,t,n){"function"==typeof t&&(n=t,t=null);let r=V(e,this.extra),s=ce({}),i=At(r,s,this.random),l=i.grid?i.grid:s;const{keyframes:o,host:a,container:u,cells:c}=i.styles;let h=this.build_svg_paths(i.paths),p=this.replace(i),f=Kt(l);p(`\n <svg ${t&&t.width&&t.height?`width="${t.width}" height="${t.height}"`:""} xmlns="http://www.w3.org/2000/svg" preserveAspectRatio="none">\n <foreignObject width="100%" height="100%">\n <div class="host" xmlns="http://www.w3.org/1999/xhtml">\n <style>\n ${Yt()}\n ${Zt(l)}\n ${a}\n ${u}\n ${c}\n ${o}\n </style>\n <svg xmlns="http://www.w3.org/2000/svg" style="width:0; height:0">\n <defs class="svg-defs">${h}</defs>\n </svg>\n ${f}\n </div>\n </foreignObject>\n </svg>\n `).then((e=>{let t=`data:image/svg+xml;base64,${window.btoa(unescape(encodeURIComponent(e)))}`;se()&&re(t),n(t)}))}canvas_to_image({code:e,cell:t},n){let r=this.doodle.getElementById(t),{width:s,height:i}=r&&r.getBoundingClientRect()||{width:0,height:0};(function(e,t,n,r){e=ie(e);let s=document.createElement("canvas"),i=s.getContext("2d"),l=window.devicePixelRatio||1;s.style.width=s.width+"px",s.style.height=s.height+"px",s.width=t*l,s.height=n*l,i.scale(l,l);try{new Function(`return (ctx, width, height, random) => {${e}}`)()(i,t,n,r)}catch(e){}return Promise.resolve(s.toDataURL())})(e,s,i,this.random).then(n)}shader_to_image({shader:e,cell:t},n){let s=function(e){let t,n,s=r(fe(h(e))),i=[],l=[],o={textures:[]};for(;s.next();){let{curr:e,next:r}=s.get();if(e.isSymbol("{")){if(i.length)l.push(e);else{let n=de(l);he(n)?(t=n,l=[]):l.push(e)}i.push("{")}else if(e.isSymbol("}"))if(i.pop(),!i.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),i=this.doodle.getElementById(t),{width:l,height:o}=i&&i.getBoundingClientRect()||{width:0,height:0},a=window.devicePixelRatio||1;if(s.textures.length){let e=s.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=>{s.textures=e,Vt(s,l,o).then(n)}))}else Vt(s,l,o).then(n)}load(e){e||this.hasAttribute("click-to-update")&&this.addEventListener("click",(e=>this.update()));let t=V(this.get_use()+ie(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 s=Object.keys(e),i=Object.keys(t),l=Object.keys(n),o=Object.keys(r);return n=>{if(!(s.length||i.length||l.length||o.length))return Promise.resolve(n);let a=[].concat(s.map((t=>n.includes(t)?new Promise((n=>{this.doodle_to_image(e[t],(e=>n({id:t,value:e})))})):Promise.resolve(""))),i.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 s=n||r;const{keyframes:i,host:l,container:o,cells:a}=e.styles;let u=Zt(t)+l+o,c=s?"":a,h=this.build_svg_paths(e.paths);const{uniforms:p}=e;let f=this.replace(e);this.doodle.innerHTML=`\n <style>${Yt(p)}</style>\n <style class="style-keyframes">${i}</style>\n <style class="style-container">${u}</style>\n <style class="style-cells">${c}</style>\n <svg xmlns="http://www.w3.org/2000/svg" style="width:0;height:0">\n <defs class="svg-defs">${h}</defs>\n </svg>\n ${Kt(t)}\n `,this.set_content(".style-container",f(u)),s?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">\n <path d="${e[t].commands}" />\n </clipPath>\n `)).join("")}register_uniform_time(){if(!this.is_uniform_time_registered){try{CSS.registerProperty({name:"--"+ot.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(((s,i)=>{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 ${se()?"":`width="${c}px" height="${h}px"`}\n >\n <foreignObject width="100%" height="100%">\n <div\n class="host"\n xmlns="http://www.w3.org/1999/xhtml"\n style="width: ${a}px; height: ${u}px; "\n >\n <style>.host { ${f=l,f.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;")} }</style>\n ${o}\n </div>\n </foreignObject>\n </svg>\n `.replace(/\n\s+|^\s+|\n+/g," ").trim();var f;n||r?function(e,t,n,r){return new Promise(((s,i)=>{let l=`data:image/svg+xml;utf8,${encodeURIComponent(e)}`;function o(){let e=new Image;e.crossOrigin="anonymous",e.src=l,e.onload=()=>{let o=document.createElement("canvas"),a=o.getContext("2d"),u=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=>{s({blob:e,source:l,url:URL.createObjectURL(e)})}))}catch(e){i(e)}}}se()?re(l,o,200):o()}))}(p,c,h,e).then((({source:e,url:r,blob:i})=>{if(s({width:c,height:h,svg:p,blob:i,source:e}),n){let e=document.createElement("a");e.download=function(e){return(J(e)?Date.now():String(e).replace(/\/.png$/g,""))+".png"}(t),e.href=r,e.click()}})).catch((e=>{i(e)})):s({width:c,height:h,svg:p})}))}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 Yt(e={}){const t=ct(/grid/).map((e=>`${e}: inherit;`)).join("");return`\n * {\n box-sizing: border-box\n }\n *::after, *::before {\n box-sizing: inherit\n }\n :host, .host {\n display: block;\n visibility: visible;\n width: auto;\n height: auto;\n --${ot.name}: 0\n }\n :host([hidden]), .host[hidden] {\n display: none\n }\n .container {\n position: relative;\n width: 100%;\n height: 100%;\n display: grid;\n ${t}\n }\n cell:empty {\n position: relative;\n line-height: 1;\n display: grid;\n place-items: center\n }\n svg {\n position: absolute;\n width: 100%;\n height: 100%;\n }\n `}function Zt(e){let{x:t,y:n}=e||{};return`\n :host, .host {\n grid-template-rows: repeat(${n}, 1fr);\n grid-template-columns: repeat(${t}, 1fr);\n }\n `}function Jt(e,t,n){let r=document.createElement("cell");return r.id=te(e,t,n),r}function Kt(e){let{x:t,y:n,z:r}=e||{},s=document.createElement("grid"),i=document.createDocumentFragment();if(1==r)for(let e=1;e<=n;++e)for(let n=1;n<=t;++n)i.appendChild(Jt(n,e,1));else{let e=null;for(let t=1;t<=r;++t){let n=Jt(1,1,t);(e||i).appendChild(n),e=n}e=null}return s.className="container",s.appendChild(i),s.outerHTML}customElements.get("css-doodle")||customElements.define("css-doodle",Gt);return le((e=>{let t=document.createElement("css-doodle");return t.update&&t.update(e),t}))}));