modern-text
Version:
Measure and render text in a way that describes the DOM.
3 lines • 195 kB
JavaScript
(function(Y,Me){typeof exports=="object"&&typeof module<"u"?Me(exports):typeof define=="function"&&define.amd?define(["exports"],Me):(Y=typeof globalThis<"u"?globalThis:Y||self,Me(Y.modernText={}))})(this,(function(Y){"use strict";var Me={grad:.9,turn:360,rad:360/(2*Math.PI)},Zt=function(r){return typeof r=="string"?r.length>0:typeof r=="number"},ot=function(r,t,e){return t===void 0&&(t=0),e===void 0&&(e=Math.pow(10,t)),Math.round(e*r)/e+0},Et=function(r,t,e){return t===void 0&&(t=0),e===void 0&&(e=1),r>e?e:r>t?r:t},yr=function(r){return(r=isFinite(r)?r%360:0)>0?r:r+360},mr=function(r){return{r:Et(r.r,0,255),g:Et(r.g,0,255),b:Et(r.b,0,255),a:Et(r.a)}},_n=function(r){return{r:ot(r.r),g:ot(r.g),b:ot(r.b),a:ot(r.a,3)}},es=/^#([0-9a-f]{3,8})$/i,He=function(r){var t=r.toString(16);return t.length<2?"0"+t:t},xr=function(r){var t=r.r,e=r.g,n=r.b,i=r.a,o=Math.max(t,e,n),s=o-Math.min(t,e,n),a=s?o===t?(e-n)/s:o===e?2+(n-t)/s:4+(t-e)/s:0;return{h:60*(a<0?a+6:a),s:o?s/o*100:0,v:o/255*100,a:i}},vr=function(r){var t=r.h,e=r.s,n=r.v,i=r.a;t=t/360*6,e/=100,n/=100;var o=Math.floor(t),s=n*(1-e),a=n*(1-(t-o)*e),l=n*(1-(1-t+o)*e),c=o%6;return{r:255*[n,a,s,s,l,n][c],g:255*[l,n,n,a,s,s][c],b:255*[s,s,l,n,n,a][c],a:i}},wr=function(r){return{h:yr(r.h),s:Et(r.s,0,100),l:Et(r.l,0,100),a:Et(r.a)}},br=function(r){return{h:ot(r.h),s:ot(r.s),l:ot(r.l),a:ot(r.a,3)}},Sr=function(r){return vr((e=(t=r).s,{h:t.h,s:(e*=((n=t.l)<50?n:100-n)/100)>0?2*e/(n+e)*100:0,v:n+e,a:t.a}));var t,e,n},Pe=function(r){return{h:(t=xr(r)).h,s:(i=(200-(e=t.s))*(n=t.v)/100)>0&&i<200?e*n/100/(i<=100?i:200-i)*100:0,l:i/2,a:t.a};var t,e,n,i},ns=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,rs=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,is=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,ss=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,Cr={string:[[function(r){var t=es.exec(r);return t?(r=t[1]).length<=4?{r:parseInt(r[0]+r[0],16),g:parseInt(r[1]+r[1],16),b:parseInt(r[2]+r[2],16),a:r.length===4?ot(parseInt(r[3]+r[3],16)/255,2):1}:r.length===6||r.length===8?{r:parseInt(r.substr(0,2),16),g:parseInt(r.substr(2,2),16),b:parseInt(r.substr(4,2),16),a:r.length===8?ot(parseInt(r.substr(6,2),16)/255,2):1}:null:null},"hex"],[function(r){var t=is.exec(r)||ss.exec(r);return t?t[2]!==t[4]||t[4]!==t[6]?null:mr({r:Number(t[1])/(t[2]?100/255:1),g:Number(t[3])/(t[4]?100/255:1),b:Number(t[5])/(t[6]?100/255:1),a:t[7]===void 0?1:Number(t[7])/(t[8]?100:1)}):null},"rgb"],[function(r){var t=ns.exec(r)||rs.exec(r);if(!t)return null;var e,n,i=wr({h:(e=t[1],n=t[2],n===void 0&&(n="deg"),Number(e)*(Me[n]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)});return Sr(i)},"hsl"]],object:[[function(r){var t=r.r,e=r.g,n=r.b,i=r.a,o=i===void 0?1:i;return Zt(t)&&Zt(e)&&Zt(n)?mr({r:Number(t),g:Number(e),b:Number(n),a:Number(o)}):null},"rgb"],[function(r){var t=r.h,e=r.s,n=r.l,i=r.a,o=i===void 0?1:i;if(!Zt(t)||!Zt(e)||!Zt(n))return null;var s=wr({h:Number(t),s:Number(e),l:Number(n),a:Number(o)});return Sr(s)},"hsl"],[function(r){var t=r.h,e=r.s,n=r.v,i=r.a,o=i===void 0?1:i;if(!Zt(t)||!Zt(e)||!Zt(n))return null;var s=(function(a){return{h:yr(a.h),s:Et(a.s,0,100),v:Et(a.v,0,100),a:Et(a.a)}})({h:Number(t),s:Number(e),v:Number(n),a:Number(o)});return vr(s)},"hsv"]]},Mr=function(r,t){for(var e=0;e<t.length;e++){var n=t[e][0](r);if(n)return[n,t[e][1]]}return[null,void 0]},os=function(r){return typeof r=="string"?Mr(r.trim(),Cr.string):typeof r=="object"&&r!==null?Mr(r,Cr.object):[null,void 0]},Tn=function(r,t){var e=Pe(r);return{h:e.h,s:Et(e.s+100*t,0,100),l:e.l,a:e.a}},kn=function(r){return(299*r.r+587*r.g+114*r.b)/1e3/255},Pr=function(r,t){var e=Pe(r);return{h:e.h,s:e.s,l:Et(e.l+100*t,0,100),a:e.a}},_r=(function(){function r(t){this.parsed=os(t)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return r.prototype.isValid=function(){return this.parsed!==null},r.prototype.brightness=function(){return ot(kn(this.rgba),2)},r.prototype.isDark=function(){return kn(this.rgba)<.5},r.prototype.isLight=function(){return kn(this.rgba)>=.5},r.prototype.toHex=function(){return t=_n(this.rgba),e=t.r,n=t.g,i=t.b,s=(o=t.a)<1?He(ot(255*o)):"","#"+He(e)+He(n)+He(i)+s;var t,e,n,i,o,s},r.prototype.toRgb=function(){return _n(this.rgba)},r.prototype.toRgbString=function(){return t=_n(this.rgba),e=t.r,n=t.g,i=t.b,(o=t.a)<1?"rgba("+e+", "+n+", "+i+", "+o+")":"rgb("+e+", "+n+", "+i+")";var t,e,n,i,o},r.prototype.toHsl=function(){return br(Pe(this.rgba))},r.prototype.toHslString=function(){return t=br(Pe(this.rgba)),e=t.h,n=t.s,i=t.l,(o=t.a)<1?"hsla("+e+", "+n+"%, "+i+"%, "+o+")":"hsl("+e+", "+n+"%, "+i+"%)";var t,e,n,i,o},r.prototype.toHsv=function(){return t=xr(this.rgba),{h:ot(t.h),s:ot(t.s),v:ot(t.v),a:ot(t.a,3)};var t},r.prototype.invert=function(){return jt({r:255-(t=this.rgba).r,g:255-t.g,b:255-t.b,a:t.a});var t},r.prototype.saturate=function(t){return t===void 0&&(t=.1),jt(Tn(this.rgba,t))},r.prototype.desaturate=function(t){return t===void 0&&(t=.1),jt(Tn(this.rgba,-t))},r.prototype.grayscale=function(){return jt(Tn(this.rgba,-1))},r.prototype.lighten=function(t){return t===void 0&&(t=.1),jt(Pr(this.rgba,t))},r.prototype.darken=function(t){return t===void 0&&(t=.1),jt(Pr(this.rgba,-t))},r.prototype.rotate=function(t){return t===void 0&&(t=15),this.hue(this.hue()+t)},r.prototype.alpha=function(t){return typeof t=="number"?jt({r:(e=this.rgba).r,g:e.g,b:e.b,a:t}):ot(this.rgba.a,3);var e},r.prototype.hue=function(t){var e=Pe(this.rgba);return typeof t=="number"?jt({h:t,s:e.s,l:e.l,a:e.a}):ot(e.h)},r.prototype.isEqual=function(t){return this.toHex()===jt(t).toHex()},r})(),jt=function(r){return r instanceof _r?r:new _r(r)};function Q(r){return r==null||r===""||r==="none"}function de(r,t=0,e=10**t){return Math.round(e*r)/e+0}function Ut(r,t=!1){if(typeof r!="object"||!r)return r;if(Array.isArray(r))return t?r.map(n=>Ut(n,t)):r;const e={};for(const n in r){const i=r[n];i!=null&&(t?e[n]=Ut(i,t):e[n]=i)}return e}function Xe(r,t){const e={};return t.forEach(n=>{n in r&&(e[n]=r[n])}),e}function An(r,t){if(r===t)return!0;if(r&&t&&typeof r=="object"&&typeof t=="object"){const e=Array.from(new Set([...Object.keys(r),...Object.keys(t)]));return!e.length||e.every(n=>r[n]===t[n])}return!1}function as(r,t,e){const n=t.length-1;if(n<0)return r===void 0?e:r;for(let i=0;i<n;i++){if(r==null)return e;r=r[t[i]]}return r==null||r[t[n]]===void 0?e:r[t[n]]}function ls(r,t,e){const n=t.length-1;for(let i=0;i<n;i++)typeof r[t[i]]!="object"&&(r[t[i]]={}),r=r[t[i]];r[t[n]]=e}function cs(r,t,e){return r==null||!t||typeof t!="string"?e:r[t]!==void 0?r[t]:(t=t.replace(/\[(\w+)\]/g,".$1"),t=t.replace(/^\./,""),as(r,t.split("."),e))}function hs(r,t,e){if(!(typeof r!="object"||!t))return t=t.replace(/\[(\w+)\]/g,".$1"),t=t.replace(/^\./,""),ls(r,t.split("."),e)}class us{_observers=new Map;on(t,e){let n=this._observers.get(t);return n===void 0&&this._observers.set(t,n=new Set),n.add(e),this}once(t,e){const n=(...i)=>{this.off(t,n),e(...i)};return this.on(t,n),this}off(t,e){const n=this._observers.get(t);return n!==void 0&&(n.delete(e),n.size===0&&this._observers.delete(t)),this}emit(t,...e){return Array.from((this._observers.get(t)||new Map).values()).forEach(n=>n(...e)),this}destroy(){this._observers=new Map}}const In=Symbol("properties"),Ye=Symbol("inited");function On(r){let t;if(Object.hasOwn(r,In))t=r[In];else{const e=Object.getPrototypeOf(r);t=new Map(e?On(e):void 0),r[In]=t}return t}function Tr(r,t,e,n){const{alias:i,internalKey:o}=n,s=r[t];i?hs(r,i,e):r[o]=e,r.onUpdateProperty?.(t,e??Ze(r,t,n),s)}function kr(r,t,e){const{alias:n,internalKey:i}=e;let o;return n?o=cs(r,n):o=r[i],o=o??Ze(r,t,e),o}function Ze(r,t,e){const{default:n,fallback:i}=e;let o;if(n!==void 0&&!r[Ye]?.[t]){r[Ye]||(r[Ye]={}),r[Ye][t]=!0;const s=typeof n=="function"?n():n;s!==void 0&&(r[t]=s,o=s)}return o===void 0&&i!==void 0&&(o=typeof i=="function"?i():i),o}function fs(r,t){function e(){return typeof this.getProperty<"u"?this.getProperty(r):kr(this,r,t)}function n(i){typeof this.setProperty<"u"?this.setProperty(r,i):Tr(this,r,i,t)}return{get:e,set:n}}function ps(r,t,e={}){const n={...e,internalKey:Symbol(t)};On(r).set(t,n);const i=fs(t,n);Object.defineProperty(r.prototype,t,{get(){return i.get.call(this)},set(o){i.set.call(this,o)},configurable:!0,enumerable:!0})}function ee(r){return function(t,e){if(typeof e!="string")throw new TypeError("Failed to @property decorator, prop name cannot be a symbol");ps(t.constructor,e,r)}}class ds extends us{_propertyAccessor;_properties=new Map;_updatedProperties=new Map;_changedProperties=new Set;_updatingPromise=Promise.resolve();_updating=!1;constructor(t){super(),this.setProperties(t)}isDirty(t){return t?this._updatedProperties.has(t):this._updatedProperties.size>0}getProperty(t){const e=this.getPropertyDeclaration(t);if(e){if(e.internal||e.alias)return kr(this,t,e);{let n;return this._propertyAccessor?.getProperty?n=this._propertyAccessor.getProperty(t):n=this._properties.get(t),n??Ze(this,t,e)}}}setProperty(t,e){const n=this.getPropertyDeclaration(t);if(n)if(n.internal||n.alias)Tr(this,t,e,n);else{const i=this.getProperty(t);this._propertyAccessor?.setProperty?.(t,e),this._properties.set(t,e),this.onUpdateProperty?.(t,e??Ze(this,t,n),i)}}getProperties(t){const e={};for(const[n,i]of this.getPropertyDeclarations())!i.internal&&!i.alias&&(!t||t.includes(n))&&(e[n]=this.getProperty(n));return e}setProperties(t){if(t&&typeof t=="object")for(const e in t)this.setProperty(e,t[e]);return this}resetProperties(){for(const[t,e]of this.getPropertyDeclarations())this.setProperty(t,typeof e.default=="function"?e.default():e.default);return this}getPropertyDeclarations(){return On(this.constructor)}getPropertyDeclaration(t){return this.getPropertyDeclarations().get(t)}setPropertyAccessor(t){const e=this.getPropertyDeclarations();this._propertyAccessor=void 0;const n={};return e.forEach((i,o)=>{n[o]=this.getProperty(o)}),this._propertyAccessor=t,e.forEach((i,o)=>{const s=this.getProperty(o),a=n[o];s!==void 0&&!Object.is(s,a)&&(this.setProperty(o,s),!i.internal&&!i.alias&&this.requestUpdate(o,s,a))}),this}async _nextTick(){return"requestAnimationFrame"in globalThis?new Promise(t=>globalThis.requestAnimationFrame(t)):Promise.resolve()}async _enqueueUpdate(){this._updating=!0;try{await this._updatingPromise}catch(t){Promise.reject(t)}await this._nextTick(),this._updating&&(this.onUpdate(),this._updating=!1)}onUpdate(){this._update(this._updatedProperties),this._updatedProperties=new Map}onUpdateProperty(t,e,n){Object.is(e,n)||this.requestUpdate(t,e,n)}requestUpdate(t,e,n){t!==void 0&&(this._updatedProperties.set(t,n),this._changedProperties.add(t),this._updateProperty(t,e,n),this.emit("updateProperty",t,e,n)),this._updating||(this._updatingPromise=this._enqueueUpdate())}_update(t){}_updateProperty(t,e,n){}toJSON(){const t={};return this._properties.forEach((e,n)=>{e!==void 0&&(e&&typeof e=="object"?"toJSON"in e&&typeof e.toJSON=="function"?t[n]=e.toJSON():Array.isArray(e)?t[n]=[...e]:t[n]={...e}:t[n]=e)}),t}clone(){return new this.constructor(this.toJSON())}destroy(){this.emit("destroy"),super.destroy()}}function Ar(r){let t;return typeof r=="number"?t={r:r>>24&255,g:r>>16&255,b:r>>8&255,a:(r&255)/255}:t=r,jt(t)}function gs(r){return{r:de(r.r),g:de(r.g),b:de(r.b),a:de(r.a,3)}}function Ke(r){const t=r.toString(16);return t.length<2?`0${t}`:t}const ys="#000000FF";function ms(r){return Ar(r).isValid()}function At(r,t=!1){const e=Ar(r);if(!e.isValid()){if(typeof r=="string")return r;const a=`Failed to normalizeColor ${r}`;if(t)throw new Error(a);return console.warn(a),ys}const{r:n,g:i,b:o,a:s}=gs(e.rgba);return`#${Ke(n)}${Ke(i)}${Ke(o)}${Ke(de(s*255))}`}var Qe=Qe||{};Qe.parse=(function(){const r={linearGradient:/^(-(webkit|o|ms|moz)-)?(linear-gradient)/i,repeatingLinearGradient:/^(-(webkit|o|ms|moz)-)?(repeating-linear-gradient)/i,radialGradient:/^(-(webkit|o|ms|moz)-)?(radial-gradient)/i,repeatingRadialGradient:/^(-(webkit|o|ms|moz)-)?(repeating-radial-gradient)/i,sideOrCorner:/^to (left (top|bottom)|right (top|bottom)|top (left|right)|bottom (left|right)|left|right|top|bottom)/i,extentKeywords:/^(closest-side|closest-corner|farthest-side|farthest-corner|contain|cover)/,positionKeywords:/^(left|center|right|top|bottom)/i,pixelValue:/^(-?((\d*\.\d+)|(\d+\.?)))px/,percentageValue:/^(-?((\d*\.\d+)|(\d+\.?)))%/,emValue:/^(-?((\d*\.\d+)|(\d+\.?)))em/,angleValue:/^(-?((\d*\.\d+)|(\d+\.?)))deg/,radianValue:/^(-?((\d*\.\d+)|(\d+\.?)))rad/,startCall:/^\(/,endCall:/^\)/,comma:/^,/,hexColor:/^#([0-9a-f]+)/i,literalColor:/^([a-z]+)/i,rgbColor:/^rgb/i,rgbaColor:/^rgba/i,varColor:/^var/i,calcValue:/^calc/i,variableName:/^(--[a-z0-9-,\s#]+)/i,number:/^((\d*\.\d+)|(\d+\.?))/,hslColor:/^hsl/i,hslaColor:/^hsla/i};let t="";function e(T){const _=new Error(`${t}: ${T}`);throw _.source=t,_}function n(){const T=i();return t.length>0&&e("Invalid input not EOF"),T}function i(){return x(o)}function o(){return s("linear-gradient",r.linearGradient,l)||s("repeating-linear-gradient",r.repeatingLinearGradient,l)||s("radial-gradient",r.radialGradient,u)||s("repeating-radial-gradient",r.repeatingRadialGradient,u)}function s(T,_,U){return a(_,$=>{const q=U();return q&&(O(r.comma)||e("Missing comma before color stops")),{type:T,orientation:q,colorStops:x(C)}})}function a(T,_){const U=O(T);if(U){O(r.startCall)||e("Missing (");const $=_(U);return O(r.endCall)||e("Missing )"),$}}function l(){const T=c();if(T)return T;const _=V("position-keyword",r.positionKeywords,1);return _?{type:"directional",value:_.value}:h()}function c(){return V("directional",r.sideOrCorner,1)}function h(){return V("angular",r.angleValue,1)||V("angular",r.radianValue,1)}function u(){let T,_=f(),U;return _&&(T=[],T.push(_),U=t,O(r.comma)&&(_=f(),_?T.push(_):t=U)),T}function f(){let T=g()||p();if(T)T.at=d();else{const _=y();if(_){T=_;const U=d();U&&(T.at=U)}else{const U=d();if(U)T={type:"default-radial",at:U};else{const $=M();$&&(T={type:"default-radial",at:$})}}}return T}function g(){const T=V("shape",/^(circle)/i,0);return T&&(T.style=L()||y()),T}function p(){const T=V("shape",/^(ellipse)/i,0);return T&&(T.style=M()||A()||y()),T}function y(){return V("extent-keyword",r.extentKeywords,1)}function d(){if(V("position",/^at/,0)){const T=M();return T||e("Missing positioning value"),T}}function M(){const T=P();if(T.x||T.y)return{type:"position",value:T}}function P(){return{x:A(),y:A()}}function x(T){let _=T();const U=[];if(_)for(U.push(_);O(r.comma);)_=T(),_?U.push(_):e("One extra comma");return U}function C(){const T=w();return T||e("Expected color definition"),T.length=A(),T}function w(){return S()||F()||E()||B()||b()||z()||v()}function v(){return V("literal",r.literalColor,0)}function S(){return V("hex",r.hexColor,1)}function b(){return a(r.rgbColor,()=>({type:"rgb",value:x(D)}))}function B(){return a(r.rgbaColor,()=>({type:"rgba",value:x(D)}))}function z(){return a(r.varColor,()=>({type:"var",value:N()}))}function E(){return a(r.hslColor,()=>{O(r.percentageValue)&&e("HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage");const _=D();O(r.comma);let U=O(r.percentageValue);const $=U?U[1]:null;O(r.comma),U=O(r.percentageValue);const q=U?U[1]:null;return(!$||!q)&&e("Expected percentage value for saturation and lightness in HSL"),{type:"hsl",value:[_,$,q]}})}function F(){return a(r.hslaColor,()=>{const T=D();O(r.comma);let _=O(r.percentageValue);const U=_?_[1]:null;O(r.comma),_=O(r.percentageValue);const $=_?_[1]:null;O(r.comma);const q=D();return(!U||!$)&&e("Expected percentage value for saturation and lightness in HSLA"),{type:"hsla",value:[T,U,$,q]}})}function N(){return O(r.variableName)[1]}function D(){return O(r.number)[1]}function A(){return V("%",r.percentageValue,1)||H()||I()||L()}function H(){return V("position-keyword",r.positionKeywords,1)}function I(){return a(r.calcValue,()=>{let T=1,_=0;for(;T>0&&_<t.length;){const $=t.charAt(_);$==="("?T++:$===")"&&T--,_++}T>0&&e("Missing closing parenthesis in calc() expression");const U=t.substring(0,_-1);return R(_-1),{type:"calc",value:U}})}function L(){return V("px",r.pixelValue,1)||V("em",r.emValue,1)}function V(T,_,U){const $=O(_);if($)return{type:T,value:$[U]}}function O(T){let _,U;return U=/^\s+/.exec(t),U&&R(U[0].length),_=T.exec(t),_&&R(_[0].length),_}function R(T){t=t.substr(T)}return function(T){return t=T.toString().trim(),t.endsWith(";")&&(t=t.slice(0,-1)),n()}})();const Ir=Qe.parse.bind(Qe);var Je=Je||{};Je.stringify=(function(){var r={"visit_linear-gradient":function(t){return r.visit_gradient(t)},"visit_repeating-linear-gradient":function(t){return r.visit_gradient(t)},"visit_radial-gradient":function(t){return r.visit_gradient(t)},"visit_repeating-radial-gradient":function(t){return r.visit_gradient(t)},visit_gradient:function(t){var e=r.visit(t.orientation);return e&&(e+=", "),t.type+"("+e+r.visit(t.colorStops)+")"},visit_shape:function(t){var e=t.value,n=r.visit(t.at),i=r.visit(t.style);return i&&(e+=" "+i),n&&(e+=" at "+n),e},"visit_default-radial":function(t){var e="",n=r.visit(t.at);return n&&(e+=n),e},"visit_extent-keyword":function(t){var e=t.value,n=r.visit(t.at);return n&&(e+=" at "+n),e},"visit_position-keyword":function(t){return t.value},visit_position:function(t){return r.visit(t.value.x)+" "+r.visit(t.value.y)},"visit_%":function(t){return t.value+"%"},visit_em:function(t){return t.value+"em"},visit_px:function(t){return t.value+"px"},visit_calc:function(t){return"calc("+t.value+")"},visit_literal:function(t){return r.visit_color(t.value,t)},visit_hex:function(t){return r.visit_color("#"+t.value,t)},visit_rgb:function(t){return r.visit_color("rgb("+t.value.join(", ")+")",t)},visit_rgba:function(t){return r.visit_color("rgba("+t.value.join(", ")+")",t)},visit_hsl:function(t){return r.visit_color("hsl("+t.value[0]+", "+t.value[1]+"%, "+t.value[2]+"%)",t)},visit_hsla:function(t){return r.visit_color("hsla("+t.value[0]+", "+t.value[1]+"%, "+t.value[2]+"%, "+t.value[3]+")",t)},visit_var:function(t){return r.visit_color("var("+t.value+")",t)},visit_color:function(t,e){var n=t,i=r.visit(e.length);return i&&(n+=" "+i),n},visit_angular:function(t){return t.value+"deg"},visit_directional:function(t){return"to "+t.value},visit_array:function(t){var e="",n=t.length;return t.forEach(function(i,o){e+=r.visit(i),o<n-1&&(e+=", ")}),e},visit_object:function(t){return t.width&&t.height?r.visit(t.width)+" "+r.visit(t.height):""},visit:function(t){if(!t)return"";if(t instanceof Array)return r.visit_array(t);if(typeof t=="object"&&!t.type)return r.visit_object(t);if(t.type){var e=r["visit_"+t.type];if(e)return e(t);throw Error("Missing visitor visit_"+t.type)}else throw Error("Invalid node.")}};return function(t){return r.visit(t)}})(),Je.stringify.bind(Je);function Or(r){const t=r.length-1;return r.map((e,n)=>{const i=e.value;let o=de(n/t,3),s="#00000000";switch(e.type){case"rgb":s=At({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0)});break;case"rgba":s=At({r:Number(i[0]??0),g:Number(i[1]??0),b:Number(i[2]??0),a:Number(i[3]??0)});break;case"literal":s=At(e.value);break;case"hex":s=At(`#${e.value}`);break}return e.length?.type==="%"&&(o=Number(e.length.value)/100),{offset:o,color:s}})}function Er(r){let t=0;return r.orientation?.type==="angular"&&(t=Number(r.orientation.value)),{type:"linear-gradient",angle:t,stops:Or(r.colorStops)}}function Dr(r){return r.orientation?.map(t=>{switch(t?.type){default:return null}}),{type:"radial-gradient",stops:Or(r.colorStops)}}function _e(r){return r.startsWith("linear-gradient(")||r.startsWith("radial-gradient(")}function xs(r){return Ir(r).map(t=>{switch(t?.type){case"linear-gradient":return Er(t);case"repeating-linear-gradient":return{...Er(t),repeat:!0};case"radial-gradient":return Dr(t);case"repeating-radial-gradient":return{...Dr(t),repeat:!0};default:return}}).filter(Boolean)}function vs(r){let t;return typeof r=="string"?t={color:r}:t={...r},{color:At(t.color)}}function ws(r){let t;if(typeof r=="string"?t={image:r}:t={...r},t.image){const{type:e,...n}=xs(t.image)[0]??{};switch(e){case"radial-gradient":return{radialGradient:n};case"linear-gradient":return{linearGradient:n}}}return Xe(t,["linearGradient","radialGradient","rotateWithShape"])}function bs(r){let t;return typeof r=="string"?t={image:r}:t={...r},Xe(t,["image","cropRect","stretchRect","tile","dpi","opacity","rotateWithShape"])}function Ss(r){let t;return typeof r=="string"?t={preset:r}:t={...r},Q(t.foregroundColor)?delete t.foregroundColor:t.foregroundColor=At(t.foregroundColor),Q(t.backgroundColor)?delete t.backgroundColor:t.backgroundColor=At(t.backgroundColor),Xe(t,["preset","foregroundColor","backgroundColor"])}function Cs(r){return!Q(r.color)}function Ms(r){return typeof r=="string"?ms(r):Cs(r)}function Ps(r){return!Q(r.image)&&_e(r.image)||!!r.linearGradient||!!r.radialGradient}function _s(r){return typeof r=="string"?_e(r):Ps(r)}function Ts(r){return!Q(r.image)&&!_e(r.image)}function ks(r){return typeof r=="string"?!_e(r):Ts(r)}function As(r){return!Q(r.preset)}function Is(r){return typeof r=="string"?!1:As(r)}function Te(r){const t=r&&typeof r=="object"?r.enabled:void 0;return Ms(r)?Ut({enabled:t,...vs(r)}):_s(r)?Ut({enabled:t,...ws(r)}):ks(r)?Ut({enabled:t,...bs(r)}):Is(r)?Ut({enabled:t,...Ss(r)}):{}}function En(r){return typeof r=="string"?{...Te(r)}:{...Te(r),...Xe(r,["width","style","lineCap","lineJoin","headEnd","tailEnd"])}}function Os(){return{boxShadow:"none"}}function Es(){return{overflow:"visible",direction:void 0,display:void 0,boxSizing:void 0,width:void 0,height:void 0,maxHeight:void 0,maxWidth:void 0,minHeight:void 0,minWidth:void 0,position:void 0,left:0,top:0,right:void 0,bottom:void 0,borderTop:void 0,borderLeft:void 0,borderRight:void 0,borderBottom:void 0,borderWidth:0,border:void 0,flex:void 0,flexBasis:void 0,flexDirection:void 0,flexGrow:void 0,flexShrink:void 0,flexWrap:void 0,justifyContent:void 0,gap:void 0,alignContent:void 0,alignItems:void 0,alignSelf:void 0,marginTop:void 0,marginLeft:void 0,marginRight:void 0,marginBottom:void 0,margin:void 0,paddingTop:void 0,paddingLeft:void 0,paddingRight:void 0,paddingBottom:void 0,padding:void 0}}function Ds(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:"none",transformOrigin:"center"}}function Bs(){return{...Es(),...Ds(),...Os(),backgroundImage:"none",backgroundSize:"auto, auto",backgroundColor:"none",backgroundColormap:"none",borderRadius:0,borderColor:"none",borderStyle:"solid",outlineWidth:0,outlineOffset:0,outlineColor:"none",outlineStyle:"none",visibility:"visible",filter:"none",opacity:1,pointerEvents:"auto",maskImage:"none"}}function Fs(){return{highlight:{},highlightImage:"none",highlightReferImage:"none",highlightColormap:"none",highlightLine:"none",highlightSize:"cover",highlightThickness:"100%"}}function Us(){return{listStyle:{},listStyleType:"none",listStyleImage:"none",listStyleColormap:"none",listStyleSize:"cover",listStylePosition:"outside"}}function Ls(){return{...Fs(),color:"#000000",verticalAlign:"baseline",letterSpacing:0,wordSpacing:0,fontSize:14,fontWeight:"normal",fontFamily:"",fontStyle:"normal",fontKerning:"normal",textTransform:"none",textOrientation:"mixed",textDecoration:"none"}}function $s(){return{...Us(),writingMode:"horizontal-tb",textWrap:"wrap",textAlign:"start",textIndent:0,lineHeight:1.2}}function Ns(){return{...$s(),...Ls(),textStrokeWidth:0,textStrokeColor:"none"}}function tn(r){return Ut({...r,color:Q(r.color)?void 0:At(r.color),backgroundColor:Q(r.backgroundColor)?void 0:At(r.backgroundColor),borderColor:Q(r.borderColor)?void 0:At(r.borderColor),outlineColor:Q(r.outlineColor)?void 0:At(r.outlineColor),shadowColor:Q(r.shadowColor)?void 0:At(r.shadowColor),textStrokeColor:Q(r.textStrokeColor)?void 0:At(r.textStrokeColor)})}function zs(){return{...Bs(),...Ns()}}const Rs=/\r\n|\n\r|\n|\r/,Vs=new RegExp(`^(${Rs.source})$`),js=`
`;function Gs(r){return Vs.test(r)}function Br(r){const t=[];function e(){return t[t.length-1]}function n(a,l,c){const h=a?tn(a):{},u=l?Te(l):void 0,f=c?En(c):void 0,g=Ut({...h,fill:u,outline:f,fragments:[]});return t[t.length-1]?.fragments.length===0?t[t.length-1]=g:t.push(g),g}function i(a="",l,c,h){const u=l?tn(l):{},f=c?Te(c):void 0,g=h?En(h):void 0;Array.from(a).forEach(p=>{if(Gs(p)){const{fragments:y,fill:d,outline:M,...P}=e()||n();y.length||y.push(Ut({...u,fill:f,outline:g,content:js})),n(P,d,M)}else{const y=e()||n(),d=y.fragments[y.fragments.length-1];if(d){const{content:M,fill:P,outline:x,...C}=d;if(An(f,P)&&An(g,x)&&An(u,C)){d.content=`${M}${p}`;return}}y.fragments.push(Ut({...u,fill:f,outline:g,content:p}))}})}(Array.isArray(r)?r:[r]).forEach(a=>{if(typeof a=="string")n(),i(a);else if(Fr(a)){const{content:l,fill:c,outline:h,...u}=a;n(u,c,h),i(l)}else if(qs(a)){const{fragments:l,fill:c,outline:h,...u}=a;n(u,c,h),l.forEach(f=>{const{content:g,fill:p,outline:y,...d}=f;i(g,d,p,y)})}else Array.isArray(a)?(n(),a.forEach(l=>{if(typeof l=="string")i(l);else if(Fr(l)){const{content:c,fill:h,outline:u,...f}=l;i(c,f,h,u)}})):console.warn("Failed to parse text content",a)});const s=e();return s&&!s.fragments.length&&s.fragments.push({content:""}),t}function qs(r){return r&&typeof r=="object"&&"fragments"in r&&Array.isArray(r.fragments)}function Fr(r){return r&&typeof r=="object"&&"content"in r&&typeof r.content=="string"}function Ws(r){return typeof r=="string"||Array.isArray(r)?{content:Br(r)}:Ut({...r,content:Br(r.content??""),style:r.style?tn(r.style):void 0,effects:r.effects?r.effects.map(t=>tn(t)):void 0,measureDom:r.measureDom,fonts:r.fonts,fill:r.fill?Te(r.fill):void 0,outline:r.outline?En(r.outline):void 0})}function Hs(r,t,e=2){const n=t&&t.length,i=n?t[0]*e:r.length;let o=Ur(r,0,i,e,!0);const s=[];if(!o||o.next===o.prev)return s;let a,l,c;if(n&&(o=Qs(r,t,o,e)),r.length>80*e){a=r[0],l=r[1];let h=a,u=l;for(let f=e;f<i;f+=e){const g=r[f],p=r[f+1];g<a&&(a=g),p<l&&(l=p),g>h&&(h=g),p>u&&(u=p)}c=Math.max(h-a,u-l),c=c!==0?32767/c:0}return ke(o,s,e,a,l,c,0),s}function Ur(r,t,e,n,i){let o;if(i===co(r,t,e,n)>0)for(let s=t;s<e;s+=n)o=zr(s/n|0,r[s],r[s+1],o);else for(let s=e-n;s>=t;s-=n)o=zr(s/n|0,r[s],r[s+1],o);return o&&ge(o,o.next)&&(Oe(o),o=o.next),o}function ce(r,t){if(!r)return r;t||(t=r);let e=r,n;do if(n=!1,!e.steiner&&(ge(e,e.next)||tt(e.prev,e,e.next)===0)){if(Oe(e),e=t=e.prev,e===e.next)break;n=!0}else e=e.next;while(n||e!==t);return t}function ke(r,t,e,n,i,o,s){if(!r)return;!s&&o&&ro(r,n,i,o);let a=r;for(;r.prev!==r.next;){const l=r.prev,c=r.next;if(o?Ys(r,n,i,o):Xs(r)){t.push(l.i,r.i,c.i),Oe(r),r=c.next,a=c.next;continue}if(r=c,r===a){s?s===1?(r=Zs(ce(r),t),ke(r,t,e,n,i,o,2)):s===2&&Ks(r,t,e,n,i,o):ke(ce(r),t,e,n,i,o,1);break}}}function Xs(r){const t=r.prev,e=r,n=r.next;if(tt(t,e,n)>=0)return!1;const i=t.x,o=e.x,s=n.x,a=t.y,l=e.y,c=n.y,h=Math.min(i,o,s),u=Math.min(a,l,c),f=Math.max(i,o,s),g=Math.max(a,l,c);let p=n.next;for(;p!==t;){if(p.x>=h&&p.x<=f&&p.y>=u&&p.y<=g&&Ae(i,a,o,l,s,c,p.x,p.y)&&tt(p.prev,p,p.next)>=0)return!1;p=p.next}return!0}function Ys(r,t,e,n){const i=r.prev,o=r,s=r.next;if(tt(i,o,s)>=0)return!1;const a=i.x,l=o.x,c=s.x,h=i.y,u=o.y,f=s.y,g=Math.min(a,l,c),p=Math.min(h,u,f),y=Math.max(a,l,c),d=Math.max(h,u,f),M=Dn(g,p,t,e,n),P=Dn(y,d,t,e,n);let x=r.prevZ,C=r.nextZ;for(;x&&x.z>=M&&C&&C.z<=P;){if(x.x>=g&&x.x<=y&&x.y>=p&&x.y<=d&&x!==i&&x!==s&&Ae(a,h,l,u,c,f,x.x,x.y)&&tt(x.prev,x,x.next)>=0||(x=x.prevZ,C.x>=g&&C.x<=y&&C.y>=p&&C.y<=d&&C!==i&&C!==s&&Ae(a,h,l,u,c,f,C.x,C.y)&&tt(C.prev,C,C.next)>=0))return!1;C=C.nextZ}for(;x&&x.z>=M;){if(x.x>=g&&x.x<=y&&x.y>=p&&x.y<=d&&x!==i&&x!==s&&Ae(a,h,l,u,c,f,x.x,x.y)&&tt(x.prev,x,x.next)>=0)return!1;x=x.prevZ}for(;C&&C.z<=P;){if(C.x>=g&&C.x<=y&&C.y>=p&&C.y<=d&&C!==i&&C!==s&&Ae(a,h,l,u,c,f,C.x,C.y)&&tt(C.prev,C,C.next)>=0)return!1;C=C.nextZ}return!0}function Zs(r,t){let e=r;do{const n=e.prev,i=e.next.next;!ge(n,i)&&$r(n,e,e.next,i)&&Ie(n,i)&&Ie(i,n)&&(t.push(n.i,e.i,i.i),Oe(e),Oe(e.next),e=r=i),e=e.next}while(e!==r);return ce(e)}function Ks(r,t,e,n,i,o){let s=r;do{let a=s.next.next;for(;a!==s.prev;){if(s.i!==a.i&&oo(s,a)){let l=Nr(s,a);s=ce(s,s.next),l=ce(l,l.next),ke(s,t,e,n,i,o,0),ke(l,t,e,n,i,o,0);return}a=a.next}s=s.next}while(s!==r)}function Qs(r,t,e,n){const i=[];for(let o=0,s=t.length;o<s;o++){const a=t[o]*n,l=o<s-1?t[o+1]*n:r.length,c=Ur(r,a,l,n,!1);c===c.next&&(c.steiner=!0),i.push(so(c))}i.sort(Js);for(let o=0;o<i.length;o++)e=to(i[o],e);return e}function Js(r,t){let e=r.x-t.x;if(e===0&&(e=r.y-t.y,e===0)){const n=(r.next.y-r.y)/(r.next.x-r.x),i=(t.next.y-t.y)/(t.next.x-t.x);e=n-i}return e}function to(r,t){const e=eo(r,t);if(!e)return t;const n=Nr(e,r);return ce(n,n.next),ce(e,e.next)}function eo(r,t){let e=t;const n=r.x,i=r.y;let o=-1/0,s;if(ge(r,e))return e;do{if(ge(r,e.next))return e.next;if(i<=e.y&&i>=e.next.y&&e.next.y!==e.y){const u=e.x+(i-e.y)*(e.next.x-e.x)/(e.next.y-e.y);if(u<=n&&u>o&&(o=u,s=e.x<e.next.x?e:e.next,u===n))return s}e=e.next}while(e!==t);if(!s)return null;const a=s,l=s.x,c=s.y;let h=1/0;e=s;do{if(n>=e.x&&e.x>=l&&n!==e.x&&Lr(i<c?n:o,i,l,c,i<c?o:n,i,e.x,e.y)){const u=Math.abs(i-e.y)/(n-e.x);Ie(e,r)&&(u<h||u===h&&(e.x>s.x||e.x===s.x&&no(s,e)))&&(s=e,h=u)}e=e.next}while(e!==a);return s}function no(r,t){return tt(r.prev,r,t.prev)<0&&tt(t.next,r,r.next)<0}function ro(r,t,e,n){let i=r;do i.z===0&&(i.z=Dn(i.x,i.y,t,e,n)),i.prevZ=i.prev,i.nextZ=i.next,i=i.next;while(i!==r);i.prevZ.nextZ=null,i.prevZ=null,io(i)}function io(r){let t,e=1;do{let n=r,i;r=null;let o=null;for(t=0;n;){t++;let s=n,a=0;for(let c=0;c<e&&(a++,s=s.nextZ,!!s);c++);let l=e;for(;a>0||l>0&&s;)a!==0&&(l===0||!s||n.z<=s.z)?(i=n,n=n.nextZ,a--):(i=s,s=s.nextZ,l--),o?o.nextZ=i:r=i,i.prevZ=o,o=i;n=s}o.nextZ=null,e*=2}while(t>1);return r}function Dn(r,t,e,n,i){return r=(r-e)*i|0,t=(t-n)*i|0,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,r|t<<1}function so(r){let t=r,e=r;do(t.x<e.x||t.x===e.x&&t.y<e.y)&&(e=t),t=t.next;while(t!==r);return e}function Lr(r,t,e,n,i,o,s,a){return(i-s)*(t-a)>=(r-s)*(o-a)&&(r-s)*(n-a)>=(e-s)*(t-a)&&(e-s)*(o-a)>=(i-s)*(n-a)}function Ae(r,t,e,n,i,o,s,a){return!(r===s&&t===a)&&Lr(r,t,e,n,i,o,s,a)}function oo(r,t){return r.next.i!==t.i&&r.prev.i!==t.i&&!ao(r,t)&&(Ie(r,t)&&Ie(t,r)&&lo(r,t)&&(tt(r.prev,r,t.prev)||tt(r,t.prev,t))||ge(r,t)&&tt(r.prev,r,r.next)>0&&tt(t.prev,t,t.next)>0)}function tt(r,t,e){return(t.y-r.y)*(e.x-t.x)-(t.x-r.x)*(e.y-t.y)}function ge(r,t){return r.x===t.x&&r.y===t.y}function $r(r,t,e,n){const i=nn(tt(r,t,e)),o=nn(tt(r,t,n)),s=nn(tt(e,n,r)),a=nn(tt(e,n,t));return!!(i!==o&&s!==a||i===0&&en(r,e,t)||o===0&&en(r,n,t)||s===0&&en(e,r,n)||a===0&&en(e,t,n))}function en(r,t,e){return t.x<=Math.max(r.x,e.x)&&t.x>=Math.min(r.x,e.x)&&t.y<=Math.max(r.y,e.y)&&t.y>=Math.min(r.y,e.y)}function nn(r){return r>0?1:r<0?-1:0}function ao(r,t){let e=r;do{if(e.i!==r.i&&e.next.i!==r.i&&e.i!==t.i&&e.next.i!==t.i&&$r(e,e.next,r,t))return!0;e=e.next}while(e!==r);return!1}function Ie(r,t){return tt(r.prev,r,r.next)<0?tt(r,t,r.next)>=0&&tt(r,r.prev,t)>=0:tt(r,t,r.prev)<0||tt(r,r.next,t)<0}function lo(r,t){let e=r,n=!1;const i=(r.x+t.x)/2,o=(r.y+t.y)/2;do e.y>o!=e.next.y>o&&e.next.y!==e.y&&i<(e.next.x-e.x)*(o-e.y)/(e.next.y-e.y)+e.x&&(n=!n),e=e.next;while(e!==r);return n}function Nr(r,t){const e=Bn(r.i,r.x,r.y),n=Bn(t.i,t.x,t.y),i=r.next,o=t.prev;return r.next=t,t.prev=r,e.next=i,i.prev=e,n.next=e,e.prev=n,o.next=n,n.prev=o,n}function zr(r,t,e,n){const i=Bn(r,t,e);return n?(i.next=n.next,i.prev=n,n.next.prev=i,n.next=i):(i.prev=i,i.next=i),i}function Oe(r){r.next.prev=r.prev,r.prev.next=r.next,r.prevZ&&(r.prevZ.nextZ=r.nextZ),r.nextZ&&(r.nextZ.prevZ=r.prevZ)}function Bn(r,t,e){return{i:r,x:t,y:e,prev:null,next:null,z:0,prevZ:null,nextZ:null,steiner:!1}}function co(r,t,e,n){let i=0;for(let o=t,s=e-n;o<e;o+=n)i+=(r[s]-r[o])*(r[o+1]+r[s+1]),s=o;return i}function ho(r,t,e,n={}){const{radius:i=1}=n;r.moveTo(t,e),r.arc(t,e,i,0,Math.PI*2)}const uo={arcs:"bevel",bevel:"bevel",miter:"miter","miter-clip":"miter",round:"round"};function Fn(r,t){const{fill:e="#000",stroke:n="none",strokeWidth:i=n==="none"?0:1,strokeLinecap:o="round",strokeLinejoin:s="miter",strokeMiterlimit:a=0,strokeDasharray:l=[],strokeDashoffset:c=0,shadowOffsetX:h=0,shadowOffsetY:u=0,shadowBlur:f=0,shadowColor:g="rgba(0, 0, 0, 0)"}=t;r.fillStyle=e,r.strokeStyle=n,r.lineWidth=i,r.lineCap=o,r.lineJoin=uo[s],r.miterLimit=a,r.setLineDash(l),r.lineDashOffset=c,r.shadowOffsetX=h,r.shadowOffsetY=u,r.shadowBlur=f,r.shadowColor=g}class k{constructor(t=0,e=0){this.x=t,this.y=e}static get MAX(){return new k(1/0,1/0)}static get MIN(){return new k(-1/0,-1/0)}get array(){return[this.x,this.y]}finite(){return this.x=Number.isFinite(this.x)?this.x:0,this.y=Number.isFinite(this.y)?this.y:0,this}set(t,e){return this.x=t,this.y=e,this}add(t){return this.x+=t.x,this.y+=t.y,this}sub(t){return this.x-=t.x,this.y-=t.y,this}multiply(t){return this.x*=t.x,this.y*=t.y,this}divide(t){return this.x/=t.x,this.y/=t.y,this}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}rotate(t,e={x:0,y:0}){const n=-t/180*Math.PI,i=this.x-e.x,o=-(this.y-e.y),s=Math.sin(n),a=Math.cos(n);return this.set(e.x+(i*a-o*s),e.y-(i*s+o*a)),this}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,n=this.y-t.y;return e*e+n*n}lengthSquared(){return this.x*this.x+this.y*this.y}length(){return Math.sqrt(this.lengthSquared())}scale(t,e=t,n={x:0,y:0}){const i=t<0?n.x-this.x+n.x:this.x,o=e<0?n.y-this.y+n.y:this.y;return this.x=i*Math.abs(t),this.y=o*Math.abs(e),this}skew(t,e=0,n={x:0,y:0}){const i=this.x-n.x,o=this.y-n.y;return this.x=n.x+(i+Math.tan(t)*o),this.y=n.y+(o+Math.tan(e)*i),this}min(...t){return this.x=Math.min(this.x,...t.map(e=>e.x)),this.y=Math.min(this.y,...t.map(e=>e.y)),this}max(...t){return this.x=Math.max(this.x,...t.map(e=>e.x)),this.y=Math.max(this.y,...t.map(e=>e.y)),this}normalize(){return this.scale(1/(this.length()||1))}addVectors(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this}subVectors(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this}multiplyVectors(t,e){return this.x=t.x*e.x,this.y=t.y*e.y,this}divideVectors(t,e){return this.x=t.x/e.x,this.y=t.y/e.y,this}lerpVectors(t,e,n){return this.x=t.x+(e.x-t.x)*n,this.y=t.y+(e.y-t.y)*n,this}equals(t){return this.x===t.x&&this.y===t.y}applyMatrix3(t){const e=this.x,n=this.y,i=t.elements;return this.x=i[0]*e+i[3]*n+i[6],this.y=i[1]*e+i[4]*n+i[7],this}copy(t){return this.x=t.x,this.y=t.y,this}clone(){return new k(this.x,this.y)}}class W{constructor(t=0,e=0,n=0,i=0){this.left=t,this.top=e,this.width=n,this.height=i}get x(){return this.left}set x(t){this.left=t}get y(){return this.top}set y(t){this.top=t}get right(){return this.left+this.width}get bottom(){return this.top+this.height}get center(){return new k((this.left+this.right)/2,(this.top+this.bottom)/2)}get array(){return[this.left,this.top,this.width,this.height]}static from(...t){if(t.length===0)return new W;if(t.length===1)return t[0].clone();const e=t[0],n=t.slice(1).reduce((i,o)=>(i.left=Math.min(i.left,o.left),i.top=Math.min(i.top,o.top),i.right=Math.max(i.right,o.right),i.bottom=Math.max(i.bottom,o.bottom),i),{left:e?.left??0,top:e?.top??0,right:e?.right??0,bottom:e?.bottom??0});return new W(n.left,n.top,n.right-n.left,n.bottom-n.top)}translate(t,e){return this.left+=t,this.top+=e,this}copy(t){return this.left=t.left,this.top=t.top,this.width=t.width,this.height=t.height,this}clone(){return new W(this.left,this.top,this.width,this.height)}}class vt{elements=[];constructor(t=1,e=0,n=0,i=0,o=1,s=0,a=0,l=0,c=1){this.set(t,e,n,i,o,s,a,l,c)}set(t,e,n,i,o,s,a,l,c){const h=this.elements;return h[0]=t,h[1]=i,h[2]=a,h[3]=e,h[4]=o,h[5]=l,h[6]=n,h[7]=s,h[8]=c,this}identity(){return this.set(1,0,0,0,1,0,0,0,1),this}copy(t){const e=this.elements,n=t.elements;return e[0]=n[0],e[1]=n[1],e[2]=n[2],e[3]=n[3],e[4]=n[4],e[5]=n[5],e[6]=n[6],e[7]=n[7],e[8]=n[8],this}multiply(t){return this.multiplyMatrices(this,t)}premultiply(t){return this.multiplyMatrices(t,this)}multiplyMatrices(t,e){const n=t.elements,i=e.elements,o=this.elements,s=n[0],a=n[3],l=n[6],c=n[1],h=n[4],u=n[7],f=n[2],g=n[5],p=n[8],y=i[0],d=i[3],M=i[6],P=i[1],x=i[4],C=i[7],w=i[2],v=i[5],S=i[8];return o[0]=s*y+a*P+l*w,o[3]=s*d+a*x+l*v,o[6]=s*M+a*C+l*S,o[1]=c*y+h*P+u*w,o[4]=c*d+h*x+u*v,o[7]=c*M+h*C+u*S,o[2]=f*y+g*P+p*w,o[5]=f*d+g*x+p*v,o[8]=f*M+g*C+p*S,this}invert(){const t=this.elements,e=t[0],n=t[1],i=t[2],o=t[3],s=t[4],a=t[5],l=t[6],c=t[7],h=t[8],u=h*s-a*c,f=a*l-h*o,g=c*o-s*l,p=e*u+n*f+i*g;if(p===0)return this.set(0,0,0,0,0,0,0,0,0);const y=1/p;return t[0]=u*y,t[1]=(i*c-h*n)*y,t[2]=(a*n-i*s)*y,t[3]=f*y,t[4]=(h*e-i*l)*y,t[5]=(i*o-a*e)*y,t[6]=g*y,t[7]=(n*l-c*e)*y,t[8]=(s*e-n*o)*y,this}transpose(){let t;const e=this.elements;return t=e[1],e[1]=e[3],e[3]=t,t=e[2],e[2]=e[6],e[6]=t,t=e[5],e[5]=e[7],e[7]=t,this}scale(t,e){return this.premultiply(Un.makeScale(t,e)),this}rotate(t){return this.premultiply(Un.makeRotation(-t)),this}translate(t,e){return this.premultiply(Un.makeTranslation(t,e)),this}makeTranslation(t,e){return this.set(1,0,t,0,1,e,0,0,1),this}makeRotation(t){const e=Math.cos(t),n=Math.sin(t);return this.set(e,-n,0,n,e,0,0,0,1),this}makeScale(t,e){return this.set(t,0,0,0,e,0,0,0,1),this}fromArray(t,e=0){for(let n=0;n<9;n++)this.elements[n]=t[n+e];return this}clone(){return new this.constructor().fromArray(this.elements)}}const Un=new vt;function Rr(r,t,e,n){const i=r*e+t*n,o=Math.sqrt(r*r+t*t)*Math.sqrt(e*e+n*n);let s=Math.acos(Math.max(-1,Math.min(1,i/o)));return r*n-t*e<0&&(s=-s),s}function fo(r,t,e,n,i,o,s,a){if(t===0||e===0){r.lineTo(a.x,a.y);return}n=n*Math.PI/180,t=Math.abs(t),e=Math.abs(e);const l=(s.x-a.x)/2,c=(s.y-a.y)/2,h=Math.cos(n)*l+Math.sin(n)*c,u=-Math.sin(n)*l+Math.cos(n)*c;let f=t*t,g=e*e;const p=h*h,y=u*u,d=p/f+y/g;if(d>1){const z=Math.sqrt(d);t=z*t,e=z*e,f=t*t,g=e*e}const M=f*y+g*p,P=(f*g-M)/M;let x=Math.sqrt(Math.max(0,P));i===o&&(x=-x);const C=x*t*u/e,w=-x*e*h/t,v=Math.cos(n)*C-Math.sin(n)*w+(s.x+a.x)/2,S=Math.sin(n)*C+Math.cos(n)*w+(s.y+a.y)/2,b=Rr(1,0,(h-C)/t,(u-w)/e),B=Rr((h-C)/t,(u-w)/e,(-h-C)/t,(-u-w)/e)%(Math.PI*2);r.ellipse(v,S,t,e,n,b,b+B,o===0)}const rt={WHITESPACE:/[ \t\r\n]/,DIGIT:/\d/,SIGN:/[-+]/,POINT:/\./,COMMA:/,/,EXP:/e/i,FLAGS:/[01]/};function Gt(r,t,e=0){let a=0,l=!0,c="",h="";const u=[];function f(d,M,P){const x=new SyntaxError(`Unexpected character "${d}" at index ${M}.`);throw x.partial=P,x}function g(){c!==""&&(h===""?u.push(Number(c)):u.push(Number(c)*10**Number(h))),c="",h=""}let p;const y=r.length;for(let d=0;d<y;d++){if(p=r[d],Array.isArray(t)&&t.includes(u.length%e)&&rt.FLAGS.test(p)){a=1,c=p,g();continue}if(a===0){if(rt.WHITESPACE.test(p))continue;if(rt.DIGIT.test(p)||rt.SIGN.test(p)){a=1,c=p;continue}if(rt.POINT.test(p)){a=2,c=p;continue}rt.COMMA.test(p)&&(l&&f(p,d,u),l=!0)}if(a===1){if(rt.DIGIT.test(p)){c+=p;continue}if(rt.POINT.test(p)){c+=p,a=2;continue}if(rt.EXP.test(p)){a=3;continue}rt.SIGN.test(p)&&c.length===1&&rt.SIGN.test(c[0])&&f(p,d,u)}if(a===2){if(rt.DIGIT.test(p)){c+=p;continue}if(rt.EXP.test(p)){a=3;continue}rt.POINT.test(p)&&c[c.length-1]==="."&&f(p,d,u)}if(a===3){if(rt.DIGIT.test(p)){h+=p;continue}if(rt.SIGN.test(p)){if(h===""){h+=p;continue}h.length===1&&rt.SIGN.test(h)&&f(p,d,u)}}rt.WHITESPACE.test(p)?(g(),a=0,l=!1):rt.COMMA.test(p)?(g(),a=0,l=!0):rt.SIGN.test(p)?(g(),a=1,c=p):rt.POINT.test(p)?(g(),a=2,c=p):f(p,d,u)}return g(),u}function ye(r,t){return r-(t-r)}function Vr(r,t){const e=new k,n=new k;for(let i=0,o=r.length;i<o;i++){const s=r[i];if(s.type==="m"||s.type==="M")s.type==="m"?e.add(s):e.copy(s),t.moveTo(e.x,e.y),n.copy(e);else if(s.type==="h"||s.type==="H")s.type==="h"?e.x+=s.x:e.x=s.x,t.lineTo(e.x,e.y),n.copy(e);else if(s.type==="v"||s.type==="V")s.type==="v"?e.y+=s.y:e.y=s.y,t.lineTo(e.x,e.y),n.copy(e);else if(s.type==="l"||s.type==="L")s.type==="l"?e.add(s):e.copy(s),t.lineTo(e.x,e.y),n.copy(e);else if(s.type==="c"||s.type==="C")s.type==="c"?(t.bezierCurveTo(e.x+s.x1,e.y+s.y1,e.x+s.x2,e.y+s.y2,e.x+s.x,e.y+s.y),n.x=e.x+s.x2,n.y=e.y+s.y2,e.add(s)):(t.bezierCurveTo(s.x1,s.y1,s.x2,s.y2,s.x,s.y),n.x=s.x2,n.y=s.y2,e.copy(s));else if(s.type==="s"||s.type==="S")s.type==="s"?(t.bezierCurveTo(ye(e.x,n.x),ye(e.y,n.y),e.x+s.x2,e.y+s.y2,e.x+s.x,e.y+s.y),n.x=e.x+s.x2,n.y=e.y+s.y2,e.add(s)):(t.bezierCurveTo(ye(e.x,n.x),ye(e.y,n.y),s.x2,s.y2,s.x,s.y),n.x=s.x2,n.y=s.y2,e.copy(s));else if(s.type==="q"||s.type==="Q")s.type==="q"?(t.quadraticCurveTo(e.x+s.x1,e.y+s.y1,e.x+s.x,e.y+s.y),n.x=e.x+s.x1,n.y=e.y+s.y1,e.add(s)):(t.quadraticCurveTo(s.x1,s.y1,s.x,s.y),n.x=s.x1,n.y=s.y1,e.copy(s));else if(s.type==="t"||s.type==="T"){const a=ye(e.x,n.x),l=ye(e.y,n.y);n.x=a,n.y=l,s.type==="t"?(t.quadraticCurveTo(a,l,e.x+s.x,e.y+s.y),e.add(s)):(t.quadraticCurveTo(a,l,s.x,s.y),e.copy(s))}else if(s.type==="a"||s.type==="A"){const a=e.clone();if(s.type==="a"){if(s.x===0&&s.y===0)continue;e.add(s)}else{if(e.equals(s))continue;e.copy(s)}n.copy(e),fo(t,s.rx,s.ry,s.angle,s.largeArcFlag,s.sweepFlag,a,e)}else s.type==="z"||s.type==="Z"?(t.startPoint&&e.copy(t.startPoint),t.closePath()):console.warn("Unsupported commands",s)}}function po(r){let t,e;const n=[];for(let i=0,o=r.length;i<o;i++){const s=r[i];switch(s.type){case"m":case"M":if(s.x.toFixed(4)===e?.x.toFixed(4)&&s.y.toFixed(4)===e?.y.toFixed(4))continue;n.push(`${s.type} ${s.x} ${s.y}`),e={x:s.x,y:s.y},t={x:s.x,y:s.y};break;case"h":case"H":n.push(`${s.type} ${s.x}`),e={x:s.x,y:e?.y??0};break;case"v":case"V":n.push(`${s.type} ${s.y}`),e={x:e?.x??0,y:s.y};break;case"l":case"L":n.push(`${s.type} ${s.x} ${s.y}`),e={x:s.x,y:s.y};break;case"c":case"C":n.push(`${s.type} ${s.x1} ${s.y1} ${s.x2} ${s.y2} ${s.x} ${s.y}`),e={x:s.x,y:s.y};break;case"s":case"S":n.push(`${s.type} ${s.x2} ${s.y2} ${s.x} ${s.y}`),e={x:s.x,y:s.y};break;case"q":case"Q":n.push(`${s.type} ${s.x1} ${s.y1} ${s.x} ${s.y}`),e={x:s.x,y:s.y};break;case"t":case"T":n.push(`${s.type} ${s.x} ${s.y}`),e={x:s.x,y:s.y};break;case"a":case"A":n.push(`${s.type} ${s.rx} ${s.ry} ${s.angle} ${s.largeArcFlag} ${s.sweepFlag} ${s.x} ${s.y}`),e={x:s.x,y:s.y};break;case"z":case"Z":n.push(s.type),t&&(e={x:t.x,y:t.y});break}}return n.join(" ")}const go=/[a-df-z][^a-df-z]*/gi;function jr(r){const t=[],e=r.match(go);if(!e)return t;for(let n=0,i=e.length;n<i;n++){const o=e[n],s=o.charAt(0),a=o.slice(1).trim();let l;switch(s){case"m":case"M":l=Gt(a);for(let c=0,h=l.length;c<h;c+=2)c===0?t.push({type:s,x:l[c],y:l[c+1]}):t.push({type:s==="m"?"l":"L",x:l[c],y:l[c+1]});break;case"h":case"H":l=Gt(a);for(let c=0,h=l.length;c<h;c++)t.push({type:s,x:l[c]});break;case"v":case"V":l=Gt(a);for(let c=0,h=l.length;c<h;c++)t.push({type:s,y:l[c]});break;case"l":case"L":l=Gt(a);for(let c=0,h=l.length;c<h;c+=2)t.push({type:s,x:l[c],y:l[c+1]});break;case"c":case"C":l=Gt(a);for(let c=0,h=l.length;c<h;c+=6)t.push({type:s,x1:l[c],y1:l[c+1],x2:l[c+2],y2:l[c+3],x:l[c+4],y:l[c+5]});break;case"s":case"S":l=Gt(a);for(let c=0,h=l.length;c<h;c+=4)t.push({type:s,x2:l[c],y2:l[c+1],x:l[c+2],y:l[c+3]});break;case"q":case"Q":l=Gt(a);for(let c=0,h=l.length;c<h;c+=4)t.push({type:s,x1:l[c],y1:l[c+1],x:l[c+2],y:l[c+3]});break;case"t":case"T":l=Gt(a);for(let c=0,h=l.length;c<h;c+=2)t.push({type:s,x:l[c],y:l[c+1]});break;case"a":case"A":l=Gt(a,[3,4],7);for(let c=0,h=l.length;c<h;c+=7)t.push({type:s,rx:l[c],ry:l[c+1],angle:l[c+2],largeArcFlag:l[c+3],sweepFlag:l[c+4],x:l[c+5],y:l[c+6]});break;case"z":case"Z":t.push({type:s});break;default:console.warn(o)}}return t}const Gr="data:image/svg+xml;",qr=`${Gr}base64,`,Wr=`${Gr}charset=utf8,`;function Hr(r){if(typeof r=="string"){let t;r.startsWith(qr)?(r=r.substring(qr.length,r.length),t=atob(r)):r.startsWith(Wr)?(r=r.substring(Wr.length,r.length),t=decodeURIComponent(r)):t=r;const e=new DOMParser().parseFromString(t,"text/xml"),n=e.querySelector("parsererror");if(n)throw new Error(`${n.textContent??"parser error"}
${t}`);return e.documentElement}else return r}const yo="px",mo=90,Xr=["mm","cm","in","pt","pc","px"],Yr={mm:{mm:1,cm:.1,in:1/25.4,pt:72/25.4,pc:6/25.4,px:-1},cm:{mm:10,cm:1,in:1/2.54,pt:72/2.54,pc:6/2.54,px:-1},in:{mm:25.4,cm:2.54,in:1,pt:72,pc:6,px:-1},pt:{mm:25.4/72,cm:2.54/72,in:1/72,pt:1,pc:6/72,px:-1},pc:{mm:25.4/6,cm:2.54/6,in:1/6,pt:72/6,pc:1,px:-1},px:{px:1}};function Z(r){let t="px";if(typeof r=="string")for(let n=0,i=Xr.length;n<i;n++){const o=Xr[n];if(r.endsWith(o)){t=o,r=r.substring(0,r.length-o.length);break}}let e;return e=Yr[t][yo],e<0&&(e=Yr[t].in*mo),e*Number.parseFloat(r)}const xo=new vt,rn=new vt,Zr=new vt,Kr=new vt;function vo(r,t,e){if(!(r.hasAttribute("transform")||r.nodeName==="use"&&(r.hasAttribute("x")||r.hasAttribute("y"))))return null;const n=wo(r);return e.length>0&&n.premultiply(e[e.length-1]),t.copy(n),e.push(n),n}function wo(r){const t=new vt,e=xo;if(r.nodeName==="use"&&(r.hasAttribute("x")||r.hasAttribute("y"))&&t.translate(Z(r.getAttribute("x")),Z(r.getAttribute("y"))),r.hasAttribute("transform")){const n=r.getAttribute("transform").split(")");for(let i=n.length-1;i>=0;i--){const o=n[i].trim();if(o==="")continue;const s=o.indexOf("("),a=o.length;if(s>0&&s<a){const l=o.slice(0,s),c=Gt(o.slice(s+1));switch(e.identity(),l){case"translate":if(c.length>=1){const h=c[0];let u=0;c.length>=2&&(u=c[1]),e.translate(h,u)}break;case"rotate":if(c.length>=1){let h=0,u=0,f=0;h=c[0]*Math.PI/180,c.length>=3&&(u=c[1],f=c[2]),rn.makeTranslation(-u,-f),Zr.makeRotation(h),Kr.multiplyMatrices(Zr,rn),rn.makeTranslation(u,f),e.multiplyMatrices(rn,Kr)}break;case"scale":c.length>=1&&e.scale(c[0],c[1]??c[0]);break;case"skewX":c.length===1&&e.set(1,Math.tan(c[0]*Math.PI/180),0,0,1,0,0,0,1);break;case"skewY":c.length===1&&e.set(1,0,0,Math.tan(c[0]*Math.PI/180),1,0,0,0,1);break;case"matrix":c.length===6&&e.set(c[0],c[2],c[4],c[1],c[3],c[5],0,0,1);break}}t.premultiply(e)}}return t}function bo(r){return new Pt().arc(Z(r.getAttribute("cx")||0),Z(r.getAttribute("cy")||0),Z(r.getAttribute("r")||0),0,Math.PI*2)}function So(r,t){if(!(!r.sheet||!r.sheet.cssRules||!r.sheet.cssRules.length))for(let e=0;e<r.sheet.cssRules.length;e++){const n=r.sheet.cssRules[e];if(n.type!==1)continue;const i=n.selectorText.split(/,/g).filter(Boolean).map(s=>s.trim()),o={};for(let s=n.style.length,a=0;a<s;a++){const l=n.style.item(a);o[l]=n.style.getPropertyValue(l)}for(let s=0;s<i.length;s++)t[i[s]]=Object.assign(t[i[s]]||{},{...o})}}function Co(r){return new Pt().ellipse(Z(r.getAttribute("cx")||0),Z(r.getAttribute("cy")||0),Z(r.getAttribute("rx")||0),Z(r.getAttribute("ry")||0),0,0,Math.PI*2)}function Mo(r){return new Pt().moveTo(Z(r.getAttribute("x1")||0),Z(r.getAttribute("y1")||0)).lineTo(Z(r.getAttribute("x2")||0),Z(r.getAttribute("y2")||0))}function Po(r){const t=new Pt,e=r.getAttribute("d");return!e||e==="none"?null:(t.addData(e),t)}const _o=/([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;function To(r){const t=new Pt;let e=0;return r.getAttribute("points")?.replace(_o,(n,i,o)=>{const s=Z(i),a=Z(o);return e===0?t.moveTo(s,a):t.lineTo(s,a),e++,n}),t.currentCurve.autoClose=!0,t}const ko=/([+-]?(?:\d+(?:\.\d+)?|\.\d+)(?:e[+-]?\d+)?)(?:,|\s)([+-]?\d*\.?\d+(?:e[+-]?\d+)?)/g;function Ao(r){const t=new Pt;let e=0;return r.getAttribute("points")?.replace(ko,(n,i,o)=>{const s=Z(i),a=Z(o);return e===0?t.moveTo(s,a):t.lineTo(s,a),e++,n}),t.currentCurve.autoClose=!1,t}function Io(r){const t=Z(r.getAttribute("x")||0),e=Z(r.getAttribute("y")||0),n=Z(r.getAttribute("rx")||r.getAttribute("ry")||0),i=Z(r.getAttribute("ry")||r.getAttribute("rx")||0),o=Z(r.getAttribute("width")),s=Z(r.getAttribute("height")),a=1-.551915024494,l=new Pt;return l.moveTo(t+n,e),l.lineTo(t+o-n,e),(n!==0||i!==0)&&l.bezierCurveTo(t+o-n*a,e,t+o,e+i*a,t+o,e+i),l.lineTo(t+o,e+s-i),(n!==0||i!==0)&&l.bezierCurveTo(t+o,e+s-i*a,t+o-n*a,e+s,t+o-n,e+s),l.lineTo(t+n,e+s),(n!==0||i!==0)&&l.bezierCurveTo(t+n*a,e+s,t,e+s-i*a,t,e+s-i),l.lineTo(t,e+i),(n!==0||i!==0)&&l.bezierCurveTo(t,e+i*a,t+n*a,e,t+n,e),l}function qt(r,t,e){t=Object.assign({},t);let n={};if(r.hasAttribute("class")){const c=r.getAttribute("class").split(/\s/).filter(Boolean).map(h=>h.trim());for(let h=0;h<c.length;h++)n=Object.assign(n,e[`.${c[h]}`])}r.hasAttribute("id")&&(n=Object.assign(n,e[`#${r.getAttribute("id")}`]));for(let c=r.style.length,h=0;h<c;h++){const u=r.style.item(h),f=r.style.getPropertyValue(u);t[u]=f,n[u]=f}function i(c,h,u=o){r.hasAttribute(c)&&(t[h]=u(r.getAttribute(c))),n[c]&&(t[h]=u(n[c]))}function o(c){return c.startsWith("url")&&console.warn("url access in attributes is not implemented."),c}function s(c){return Math.max(0,Math.min(1,Z(c)))}function a(c){return Math.max(0,Z(c))}function l(c){return c.split(" ").filter(h=>h!=="").map(h=>Z(h))}return i("fill","fill"),i("fill-opacity","fillOpacity",s),i("fill-rule","fillRule"),i("opacity","opacity",s),i("stroke","stroke"),i("stroke-opacity","strokeOpacity",s),i("stroke-width","strokeWidth",a),i("stroke-linecap","strokeLinecap"),i("stroke-linejoin","strokeLinejoin"),i("stroke-miterlimit","strokeMiterlimit",a),i("stroke-dasharray","strokeDasharray",l),i("stroke-dashoffset","strokeDashoffset",Z),i("visibility","visibility"),t}function Ln(r,t,e=[],n={}){if(r.nodeType!==1)return e;let i=!1,o=null,s={...t};switch(r.nodeName){case"svg":s=qt(r,s,n);break;case"style":So(r,n);break;case"g":s=qt(r,s,n);break;case"path":s=qt(r,s,n),r.hasAttribute("d")&&(o=Po(r));break;case"rect":s=qt(r,s,n),o=Io(r);break;case"polygon":s=qt(r,s,n),o=To(r);break;case"polyline":s=qt(r,s,n),o=Ao(r);break;case"circle":s=qt(r,s,n),o=bo(r);break;case"ellipse":s=qt(r,s,n),o=Co(r);break;case"line":s=qt(r,s,n),o=Mo(r);break;case"defs":i=!0;break;case"use":{s=qt(r,s,n);const f=(r.getAttributeNS("http://www.w3.org/1999/xlink","href")||r.getAttribute("href")||"").substring(1),g=r.viewportElement?.getElementById(f);g?Ln(g,