modern-text
Version:
Measure and render text in a way that describes the DOM.
3 lines • 278 kB
JavaScript
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports):typeof define==`function`&&define.amd?define([`exports`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e.modernText={}))})(this,function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});var t=Object.create,n=Object.defineProperty,r=Object.getOwnPropertyDescriptor,i=Object.getOwnPropertyNames,a=Object.getPrototypeOf,o=Object.prototype.hasOwnProperty,s=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),c=(e,t,a,s)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var c=i(t),l=0,u=c.length,d;l<u;l++)d=c[l],!o.call(e,d)&&d!==a&&n(e,d,{get:(e=>t[e]).bind(null,d),enumerable:!(s=r(t,d))||s.enumerable});return e},l=(e,r,i)=>(i=e==null?{}:t(a(e)),c(r||!e||!e.__esModule?n(i,`default`,{value:e,enumerable:!0}):i,e)),u={grad:.9,turn:360,rad:360/(2*Math.PI)},d=function(e){return typeof e==`string`?e.length>0:typeof e==`number`},f=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=10**t),Math.round(n*e)/n+0},p=function(e,t,n){return t===void 0&&(t=0),n===void 0&&(n=1),e>n?n:e>t?e:t},m=function(e){return(e=isFinite(e)?e%360:0)>0?e:e+360},h=function(e){return{r:p(e.r,0,255),g:p(e.g,0,255),b:p(e.b,0,255),a:p(e.a)}},g=function(e){return{r:f(e.r),g:f(e.g),b:f(e.b),a:f(e.a,3)}},_=/^#([0-9a-f]{3,8})$/i,v=function(e){var t=e.toString(16);return t.length<2?`0`+t:t},y=function(e){var t=e.r,n=e.g,r=e.b,i=e.a,a=Math.max(t,n,r),o=a-Math.min(t,n,r),s=o?a===t?(n-r)/o:a===n?2+(r-t)/o:4+(t-n)/o:0;return{h:60*(s<0?s+6:s),s:a?o/a*100:0,v:a/255*100,a:i}},b=function(e){var t=e.h,n=e.s,r=e.v,i=e.a;t=t/360*6,n/=100,r/=100;var a=Math.floor(t),o=r*(1-n),s=r*(1-(t-a)*n),c=r*(1-(1-t+a)*n),l=a%6;return{r:255*[r,s,o,o,c,r][l],g:255*[c,r,r,s,o,o][l],b:255*[o,o,c,r,r,s][l],a:i}},x=function(e){return{h:m(e.h),s:p(e.s,0,100),l:p(e.l,0,100),a:p(e.a)}},S=function(e){return{h:f(e.h),s:f(e.s),l:f(e.l),a:f(e.a,3)}},C=function(e){return b((n=(t=e).s,{h:t.h,s:(n*=((r=t.l)<50?r:100-r)/100)>0?2*n/(r+n)*100:0,v:r+n,a:t.a}));var t,n,r},w=function(e){return{h:(t=y(e)).h,s:(i=(200-(n=t.s))*(r=t.v)/100)>0&&i<200?n*r/100/(i<=100?i:200-i)*100:0,l:i/2,a:t.a};var t,n,r,i},T=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s*,\s*([+-]?\d*\.?\d+)%\s*,\s*([+-]?\d*\.?\d+)%\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,E=/^hsla?\(\s*([+-]?\d*\.?\d+)(deg|rad|grad|turn)?\s+([+-]?\d*\.?\d+)%\s+([+-]?\d*\.?\d+)%\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,D=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*,\s*([+-]?\d*\.?\d+)(%)?\s*(?:,\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,O=/^rgba?\(\s*([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s+([+-]?\d*\.?\d+)(%)?\s*(?:\/\s*([+-]?\d*\.?\d+)(%)?\s*)?\)$/i,k={string:[[function(e){var t=_.exec(e);return t?(e=t[1]).length<=4?{r:parseInt(e[0]+e[0],16),g:parseInt(e[1]+e[1],16),b:parseInt(e[2]+e[2],16),a:e.length===4?f(parseInt(e[3]+e[3],16)/255,2):1}:e.length===6||e.length===8?{r:parseInt(e.substr(0,2),16),g:parseInt(e.substr(2,2),16),b:parseInt(e.substr(4,2),16),a:e.length===8?f(parseInt(e.substr(6,2),16)/255,2):1}:null:null},`hex`],[function(e){var t=D.exec(e)||O.exec(e);return t?t[2]!==t[4]||t[4]!==t[6]?null:h({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(e){var t=T.exec(e)||E.exec(e);if(!t)return null;var n,r;return C(x({h:(n=t[1],r=t[2],r===void 0&&(r=`deg`),Number(n)*(u[r]||1)),s:Number(t[3]),l:Number(t[4]),a:t[5]===void 0?1:Number(t[5])/(t[6]?100:1)}))},`hsl`]],object:[[function(e){var t=e.r,n=e.g,r=e.b,i=e.a,a=i===void 0?1:i;return d(t)&&d(n)&&d(r)?h({r:Number(t),g:Number(n),b:Number(r),a:Number(a)}):null},`rgb`],[function(e){var t=e.h,n=e.s,r=e.l,i=e.a,a=i===void 0?1:i;return!d(t)||!d(n)||!d(r)?null:C(x({h:Number(t),s:Number(n),l:Number(r),a:Number(a)}))},`hsl`],[function(e){var t=e.h,n=e.s,r=e.v,i=e.a,a=i===void 0?1:i;return!d(t)||!d(n)||!d(r)?null:b(function(e){return{h:m(e.h),s:p(e.s,0,100),v:p(e.v,0,100),a:p(e.a)}}({h:Number(t),s:Number(n),v:Number(r),a:Number(a)}))},`hsv`]]},A=function(e,t){for(var n=0;n<t.length;n++){var r=t[n][0](e);if(r)return[r,t[n][1]]}return[null,void 0]},j=function(e){return typeof e==`string`?A(e.trim(),k.string):typeof e==`object`&&e?A(e,k.object):[null,void 0]},M=function(e,t){var n=w(e);return{h:n.h,s:p(n.s+100*t,0,100),l:n.l,a:n.a}},N=function(e){return(299*e.r+587*e.g+114*e.b)/1e3/255},P=function(e,t){var n=w(e);return{h:n.h,s:n.s,l:p(n.l+100*t,0,100),a:n.a}},F=function(){function e(e){this.parsed=j(e)[0],this.rgba=this.parsed||{r:0,g:0,b:0,a:1}}return e.prototype.isValid=function(){return this.parsed!==null},e.prototype.brightness=function(){return f(N(this.rgba),2)},e.prototype.isDark=function(){return N(this.rgba)<.5},e.prototype.isLight=function(){return N(this.rgba)>=.5},e.prototype.toHex=function(){return e=g(this.rgba),t=e.r,n=e.g,r=e.b,a=(i=e.a)<1?v(f(255*i)):``,`#`+v(t)+v(n)+v(r)+a;var e,t,n,r,i,a},e.prototype.toRgb=function(){return g(this.rgba)},e.prototype.toRgbString=function(){return e=g(this.rgba),t=e.r,n=e.g,r=e.b,(i=e.a)<1?`rgba(`+t+`, `+n+`, `+r+`, `+i+`)`:`rgb(`+t+`, `+n+`, `+r+`)`;var e,t,n,r,i},e.prototype.toHsl=function(){return S(w(this.rgba))},e.prototype.toHslString=function(){return e=S(w(this.rgba)),t=e.h,n=e.s,r=e.l,(i=e.a)<1?`hsla(`+t+`, `+n+`%, `+r+`%, `+i+`)`:`hsl(`+t+`, `+n+`%, `+r+`%)`;var e,t,n,r,i},e.prototype.toHsv=function(){return e=y(this.rgba),{h:f(e.h),s:f(e.s),v:f(e.v),a:f(e.a,3)};var e},e.prototype.invert=function(){return I({r:255-(e=this.rgba).r,g:255-e.g,b:255-e.b,a:e.a});var e},e.prototype.saturate=function(e){return e===void 0&&(e=.1),I(M(this.rgba,e))},e.prototype.desaturate=function(e){return e===void 0&&(e=.1),I(M(this.rgba,-e))},e.prototype.grayscale=function(){return I(M(this.rgba,-1))},e.prototype.lighten=function(e){return e===void 0&&(e=.1),I(P(this.rgba,e))},e.prototype.darken=function(e){return e===void 0&&(e=.1),I(P(this.rgba,-e))},e.prototype.rotate=function(e){return e===void 0&&(e=15),this.hue(this.hue()+e)},e.prototype.alpha=function(e){return typeof e==`number`?I({r:(t=this.rgba).r,g:t.g,b:t.b,a:e}):f(this.rgba.a,3);var t},e.prototype.hue=function(e){var t=w(this.rgba);return typeof e==`number`?I({h:e,s:t.s,l:t.l,a:t.a}):f(t.h)},e.prototype.isEqual=function(e){return this.toHex()===I(e).toHex()},e}(),I=function(e){return e instanceof F?e:new F(e)};function L(e){return e==null||e===``||e===`none`}function R(e,t=0,n=10**t){return Math.round(n*e)/n+0}function z(e,t){if(typeof e==`number`)return Number.isFinite(e)?e:t;if(typeof e==`string`){let n=Number.parseFloat(e);return Number.isFinite(n)?n:t}return t}function B(e,t=!1){if(typeof e!=`object`||!e)return e;if(Array.isArray(e))return t?e.map(e=>B(e,t)):e;let n={};for(let r in e){let i=e[r];i!=null&&(t?n[r]=B(i,t):n[r]=i)}return n}function V(e,t){let n={};return t.forEach(t=>{t in e&&(n[t]=e[t])}),n}function ee(e,t){if(e===t)return!0;if(e&&t&&typeof e==`object`&&typeof t==`object`){let n=Array.from(new Set([...Object.keys(e),...Object.keys(t)]));return!n.length||n.every(n=>e[n]===t[n])}return!1}function te(e,t,n){let r=t.length-1;if(r<0)return e===void 0?n:e;for(let i=0;i<r;i++){if(e==null)return n;e=e[t[i]]}return e==null||e[t[r]]===void 0?n:e[t[r]]}function ne(e,t,n){let r=t.length-1;for(let n=0;n<r;n++)typeof e[t[n]]!=`object`&&(e[t[n]]={}),e=e[t[n]];e[t[r]]=n}function re(e,t,n){return e==null||!t||typeof t!=`string`?n:e[t]===void 0?(t=t.replace(/\[(\w+)\]/g,`.$1`),t=t.replace(/^\./,``),te(e,t.split(`.`),n)):e[t]}function ie(e,t,n){if(!(typeof e!=`object`||!t))return t=t.replace(/\[(\w+)\]/g,`.$1`),t=t.replace(/^\./,``),ne(e,t.split(`.`),n)}var ae=class{_eventListeners={};on(e,t){let n=this._eventListeners[e];n===void 0&&(n=[],this._eventListeners[e]=n);let r=n.indexOf(t);return r>-1&&n.splice(r,1),n.push(t),this}once(e,t){let n=(...r)=>{this.off(e,n),t.apply(this,r)};return this.on(e,n),this}off(e,t){let n=this._eventListeners[e];if(n!==void 0){let e=n.indexOf(t);e>-1&&n.splice(e,1)}return this}emit(e,...t){let n=this._eventListeners[e];if(n!==void 0){let e=n.length;if(e>0)for(let r=0;r<e;r++)n[r].apply(this,t)}return this}removeAllListeners(){return this._eventListeners={},this}hasEventListener(e){return!!this._eventListeners[e]}destroy(){this.removeAllListeners()}},oe=Symbol.for(`declarations`),se=Symbol.for(`inited`);function ce(e){let t;if(Object.hasOwn(e,oe))t=e[oe];else{let n=Object.getPrototypeOf(e);t={...n?ce(n):{}},e[oe]=t}return t}function le(e,t,n,r){let{alias:i,internalKey:a}=r,o=e[t];i?ie(e,i,n):e[a]=n,e.onUpdateProperty?.(t,n??de(e,t,r),o)}function ue(e,t,n){let{alias:r,internalKey:i}=n,a;return a=r?re(e,r):e[i],a??=de(e,t,n),a}function de(e,t,n){let{default:r,fallback:i}=n,a;if(r!==void 0&&!e[se]?.[t]){e[se]||(e[se]={}),e[se][t]=!0;let n=typeof r==`function`?r():r;n!==void 0&&(e[t]=n,a=n)}return a===void 0&&i!==void 0&&(a=typeof i==`function`?i():i),a}function fe(e,t){function n(){return this.getProperty?this.getProperty(e):ue(this,e,t)}function r(n){this.setProperty?this.setProperty(e,n):le(this,e,n,t)}return{get:n,set:r}}function pe(e,t,n={}){let r={...n,internalKey:Symbol.for(t)},i=ce(e);i[t]=r;let{get:a,set:o}=fe(t,r);Object.defineProperty(e.prototype,t,{get(){return a.call(this)},set(e){o.call(this,e)},configurable:!0,enumerable:!0})}function me(e){return function(t,n){if(typeof n!=`string`)throw TypeError(`Failed to @property decorator, prop name cannot be a symbol`);pe(t.constructor,n,e)}}var he=class extends ae{_propertyAccessor;_properties={};_updatedProperties={};_changedProperties=new Set;_updatingPromise=Promise.resolve();_updating=!1;constructor(e){super(),this.setProperties(e)}isDirty(e){return e?!!this._updatedProperties[e]:Object.keys(this._updatedProperties).length>0}offsetGetProperty(e){return this._properties[e]}offsetSetProperty(e,t){t===void 0?delete this._properties[e]:this._properties[e]=t}offsetGetProperties(e){let t=this._properties,n=Object.keys(t),r={};for(let i,a,o=0;o<n.length;o++)i=n[o],a=t[i],a!==void 0&&(!e||e.includes(i))&&(a&&typeof a==`object`?`toJSON`in a?r[i]=a.toJSON():Array.isArray(a)?r[i]=[...a]:r[i]={...a}:r[i]=a);return r}offsetSetProperties(e){if(e&&typeof e==`object`){let t=Object.keys(e);for(let n,r=0;r<t.length;r++)n=t[r],this.offsetSetProperty(n,e[n])}return this}getProperty(e){let t=this.getPropertyDeclaration(e);if(t){if(t.internal||t.alias)return ue(this,e,t);{let n=this._propertyAccessor,r;return r=n&&n.getProperty?n.getProperty(e):this.offsetGetProperty(e),r??de(this,e,t)}}}setProperty(e,t){let n=this.getPropertyDeclaration(e);if(n)if(n.internal||n.alias)le(this,e,t,n);else{let r=this.offsetGetProperty(e);if(Object.is(r,t))return;let i=this.getProperty(e);this._propertyAccessor?.setProperty?.(e,t),this.offsetSetProperty(e,t),this.onUpdateProperty?.(e,t??de(this,e,n),i)}}getProperties(e){let t={},n=this.getPropertyDeclarations(),r=Object.keys(n);for(let i=0,a=r.length;i<a;i++){let a=r[i],o=n[a];o.internal||o.alias||(!e||e.includes(a))&&(t[a]=this.getProperty(a))}return t}setProperties(e){if(e&&typeof e==`object`)for(let t in e)this.setProperty(t,e[t]);return this}resetProperties(){let e=this.getPropertyDeclarations(),t=Object.keys(e);for(let n=0,r=t.length;n<r;n++){let r=t[n],i=e[r];this.setProperty(r,typeof i.default==`function`?i.default():i.default)}return this}getPropertyDeclarations(){return ce(this.constructor)}getPropertyDeclaration(e){return this.getPropertyDeclarations()[e]}setPropertyAccessor(e){let t=this.getPropertyDeclarations(),n=[];if(e&&e.getProperty&&e.setProperty){let r=Object.keys(t);for(let i=0,a=r.length;i<a;i++){let a=r[i],o=t[a];if(o.internal||o.alias)continue;let s=this.offsetGetProperty(a),c=e.getProperty(a);c!==void 0&&!Object.is(s,c)&&(this.offsetSetProperty(a,c),n.push({key:a,newValue:c,oldValue:s}))}}this._propertyAccessor=e;for(let e=0,t=n.length;e<t;e++){let{key:t,newValue:r,oldValue:i}=n[e];this.requestUpdate(t,r,i)}return this}async _nextTick(){return`requestAnimationFrame`in globalThis?new Promise(e=>globalThis.requestAnimationFrame(e)):Promise.resolve()}async _enqueueUpdate(){this._updating=!0;try{await this._updatingPromise}catch(e){Promise.reject(e)}await this._nextTick(),this._updating&&=(this.onUpdate(),!1)}onUpdate(){this._update(this._updatedProperties),this._updatedProperties={}}onUpdateProperty(e,t,n){Object.is(t,n)||this.requestUpdate(e,t,n)}requestUpdate(e,t,n){e!==void 0&&(this._updatedProperties[e]=n,this._changedProperties.add(e),this._updateProperty(e,t,n),this.emit(`updateProperty`,e,t,n)),this._updating||(this._updatingPromise=this._enqueueUpdate())}_update(e){}_updateProperty(e,t,n){}toJSON(){return this.offsetGetProperties()}clone(){return new this.constructor(this.toJSON())}destroy(){this.emit(`destroy`),super.destroy()}};function ge(e){let t;return t=typeof e==`number`?{r:e>>24&255,g:e>>16&255,b:e>>8&255,a:(e&255)/255}:e,I(t)}function _e(e){return{r:R(e.r),g:R(e.g),b:R(e.b),a:R(e.a,3)}}function ve(e){let t=e.toString(16);return t.length<2?`0${t}`:t}var ye=`#000000FF`;function be(e){return ge(e).isValid()}function xe(e,t=!1){let n=ge(e);if(!n.isValid()){if(typeof e==`string`)return e;let n=`Failed to normalizeColor ${e}`;if(t)throw Error(n);return console.warn(n),ye}let{r,g:i,b:a,a:o}=_e(n.rgba);return`#${ve(r)}${ve(i)}${ve(a)}${ve(R(o*255))}`}var Se=Se||{};Se.parse=(function(){let e={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},t=``;function n(e){let n=Error(`${t}: ${e}`);throw n.source=t,n}function r(){let e=i();return t.length>0&&n(`Invalid input not EOF`),e}function i(){return y(a)}function a(){return o(`linear-gradient`,e.linearGradient,c)||o(`repeating-linear-gradient`,e.repeatingLinearGradient,c)||o(`radial-gradient`,e.radialGradient,d)||o(`repeating-radial-gradient`,e.repeatingRadialGradient,d)}function o(t,r,i){return s(r,r=>{let a=i();return a&&(I(e.comma)||n(`Missing comma before color stops`)),{type:t,orientation:a,colorStops:y(b)}})}function s(t,r){let i=I(t);if(i){I(e.startCall)||n(`Missing (`);let t=r(i);return I(e.endCall)||n(`Missing )`),t}}function c(){let t=l();if(t)return t;let n=F(`position-keyword`,e.positionKeywords,1);return n?{type:`directional`,value:n.value}:u()}function l(){return F(`directional`,e.sideOrCorner,1)}function u(){return F(`angular`,e.angleValue,1)||F(`angular`,e.radianValue,1)}function d(){let n,r=f(),i;return r&&(n=[],n.push(r),i=t,I(e.comma)&&(r=f(),r?n.push(r):t=i)),n}function f(){let e=p()||m();if(e)e.at=g();else{let t=h();if(t){e=t;let n=g();n&&(e.at=n)}else{let t=g();if(t)e={type:`default-radial`,at:t};else{let t=_();t&&(e={type:`default-radial`,at:t})}}}return e}function p(){let e=F(`shape`,/^(circle)/i,0);return e&&(e.style=P()||h()),e}function m(){let e=F(`shape`,/^(ellipse)/i,0);return e&&(e.style=_()||j()||h()),e}function h(){return F(`extent-keyword`,e.extentKeywords,1)}function g(){if(F(`position`,/^at/,0)){let e=_();return e||n(`Missing positioning value`),e}}function _(){let e=v();if(e.x||e.y)return{type:`position`,value:e}}function v(){return{x:j(),y:j()}}function y(t){let r=t(),i=[];if(r)for(i.push(r);I(e.comma);)r=t(),r?i.push(r):n(`One extra comma`);return i}function b(){let e=x();return e||n(`Expected color definition`),e.length=j(),e}function x(){return C()||O()||D()||T()||w()||E()||S()}function S(){return F(`literal`,e.literalColor,0)}function C(){return F(`hex`,e.hexColor,1)}function w(){return s(e.rgbColor,()=>({type:`rgb`,value:y(A)}))}function T(){return s(e.rgbaColor,()=>({type:`rgba`,value:y(A)}))}function E(){return s(e.varColor,()=>({type:`var`,value:k()}))}function D(){return s(e.hslColor,()=>{I(e.percentageValue)&&n(`HSL hue value must be a number in degrees (0-360) or normalized (-360 to 360), not a percentage`);let t=A();I(e.comma);let r=I(e.percentageValue),i=r?r[1]:null;I(e.comma),r=I(e.percentageValue);let a=r?r[1]:null;return(!i||!a)&&n(`Expected percentage value for saturation and lightness in HSL`),{type:`hsl`,value:[t,i,a]}})}function O(){return s(e.hslaColor,()=>{let t=A();I(e.comma);let r=I(e.percentageValue),i=r?r[1]:null;I(e.comma),r=I(e.percentageValue);let a=r?r[1]:null;I(e.comma);let o=A();return(!i||!a)&&n(`Expected percentage value for saturation and lightness in HSLA`),{type:`hsla`,value:[t,i,a,o]}})}function k(){return I(e.variableName)[1]}function A(){return I(e.number)[1]}function j(){return F(`%`,e.percentageValue,1)||M()||N()||P()}function M(){return F(`position-keyword`,e.positionKeywords,1)}function N(){return s(e.calcValue,()=>{let e=1,r=0;for(;e>0&&r<t.length;){let n=t.charAt(r);n===`(`?e++:n===`)`&&e--,r++}e>0&&n(`Missing closing parenthesis in calc() expression`);let i=t.substring(0,r-1);return L(r-1),{type:`calc`,value:i}})}function P(){return F(`px`,e.pixelValue,1)||F(`em`,e.emValue,1)}function F(e,t,n){let r=I(t);if(r)return{type:e,value:r[n]}}function I(e){let n,r;return r=/^\s+/.exec(t),r&&L(r[0].length),n=e.exec(t),n&&L(n[0].length),n}function L(e){t=t.substr(e)}return function(e){return t=e.toString().trim(),t.endsWith(`;`)&&(t=t.slice(0,-1)),r()}})();var Ce=Se.parse.bind(Se),we=we||{};we.stringify=(function(){var e={"visit_linear-gradient":function(t){return e.visit_gradient(t)},"visit_repeating-linear-gradient":function(t){return e.visit_gradient(t)},"visit_radial-gradient":function(t){return e.visit_gradient(t)},"visit_repeating-radial-gradient":function(t){return e.visit_gradient(t)},visit_gradient:function(t){var n=e.visit(t.orientation);return n&&(n+=`, `),t.type+`(`+n+e.visit(t.colorStops)+`)`},visit_shape:function(t){var n=t.value,r=e.visit(t.at),i=e.visit(t.style);return i&&(n+=` `+i),r&&(n+=` at `+r),n},"visit_default-radial":function(t){var n=``,r=e.visit(t.at);return r&&(n+=r),n},"visit_extent-keyword":function(t){var n=t.value,r=e.visit(t.at);return r&&(n+=` at `+r),n},"visit_position-keyword":function(e){return e.value},visit_position:function(t){return e.visit(t.value.x)+` `+e.visit(t.value.y)},"visit_%":function(e){return e.value+`%`},visit_em:function(e){return e.value+`em`},visit_px:function(e){return e.value+`px`},visit_calc:function(e){return`calc(`+e.value+`)`},visit_literal:function(t){return e.visit_color(t.value,t)},visit_hex:function(t){return e.visit_color(`#`+t.value,t)},visit_rgb:function(t){return e.visit_color(`rgb(`+t.value.join(`, `)+`)`,t)},visit_rgba:function(t){return e.visit_color(`rgba(`+t.value.join(`, `)+`)`,t)},visit_hsl:function(t){return e.visit_color(`hsl(`+t.value[0]+`, `+t.value[1]+`%, `+t.value[2]+`%)`,t)},visit_hsla:function(t){return e.visit_color(`hsla(`+t.value[0]+`, `+t.value[1]+`%, `+t.value[2]+`%, `+t.value[3]+`)`,t)},visit_var:function(t){return e.visit_color(`var(`+t.value+`)`,t)},visit_color:function(t,n){var r=t,i=e.visit(n.length);return i&&(r+=` `+i),r},visit_angular:function(e){return e.value+`deg`},visit_directional:function(e){return`to `+e.value},visit_array:function(t){var n=``,r=t.length;return t.forEach(function(t,i){n+=e.visit(t),i<r-1&&(n+=`, `)}),n},visit_object:function(t){return t.width&&t.height?e.visit(t.width)+` `+e.visit(t.height):``},visit:function(t){if(!t)return``;if(t instanceof Array)return e.visit_array(t);if(typeof t==`object`&&!t.type)return e.visit_object(t);if(t.type){var n=e[`visit_`+t.type];if(n)return n(t);throw Error(`Missing visitor visit_`+t.type)}else throw Error(`Invalid node.`)}};return function(t){return e.visit(t)}})(),we.stringify.bind(we);function Te(e){let t=e.length-1;return e.map((e,n)=>{let r=e.value,i=R(n/t,3),a=`#00000000`;switch(e.type){case`rgb`:a=xe({r:Number(r[0]??0),g:Number(r[1]??0),b:Number(r[2]??0)});break;case`rgba`:a=xe({r:Number(r[0]??0),g:Number(r[1]??0),b:Number(r[2]??0),a:Number(r[3]??0)});break;case`literal`:a=xe(e.value);break;case`hex`:a=xe(`#${e.value}`);break}switch(e.length?.type){case`%`:i=Number(e.length.value)/100;break}return{offset:i,color:a}})}function Ee(e){let t=0;switch(e.orientation?.type){case`angular`:t=Number(e.orientation.value);break}return{type:`linear-gradient`,angle:t,stops:Te(e.colorStops)}}function De(e){return e.orientation?.map(e=>{switch(e?.type){default:return null}}),{type:`radial-gradient`,stops:Te(e.colorStops)}}function Oe(e){return e.startsWith(`linear-gradient(`)||e.startsWith(`radial-gradient(`)}function ke(e){return Ce(e).map(e=>{switch(e?.type){case`linear-gradient`:return Ee(e);case`repeating-linear-gradient`:return{...Ee(e),repeat:!0};case`radial-gradient`:return De(e);case`repeating-radial-gradient`:return{...De(e),repeat:!0};default:return}}).filter(Boolean)}var Ae=[`color`];function je(e){let t;return t=typeof e==`string`?{color:e}:{...e},t.color&&=xe(t.color),V(t,Ae)}var Me=[`linearGradient`,`radialGradient`,`rotateWithShape`];function Ne(e){let t;if(t=typeof e==`string`?{image:e}:{...e},t.image){let{type:e,...n}=ke(t.image)[0]??{};switch(e){case`radial-gradient`:return{radialGradient:n};case`linear-gradient`:return{linearGradient:n}}}return V(t,Me)}function Pe(e){return B({name:e.name,params:e.params})}var Fe=[`image`,`cropRect`,`stretchRect`,`tile`,`dpi`,`opacity`,`rotateWithShape`,`imagePipelines`];function Ie(e){let t;t=typeof e==`string`?{image:e}:{...e};let n=V(t,Fe);return n.imagePipelines=t.imagePipelines?.length?t.imagePipelines.map(Pe):void 0,B(n)}var Le=[`preset`,`foregroundColor`,`backgroundColor`];function Re(e){let t;return t=typeof e==`string`?{preset:e}:{...e},L(t.foregroundColor)?delete t.foregroundColor:t.foregroundColor=xe(t.foregroundColor),L(t.backgroundColor)?delete t.backgroundColor:t.backgroundColor=xe(t.backgroundColor),V(t,Le)}function ze(e){return!L(e.color)}function Be(e){return typeof e==`string`?be(e):ze(e)}function Ve(e){return!L(e.image)&&Oe(e.image)||!!e.linearGradient||!!e.radialGradient}function He(e){return typeof e==`string`?Oe(e):Ve(e)}function Ue(e){return!L(e.image)&&!Oe(e.image)}function We(e){return typeof e==`string`?!be(e)&&!Oe(e):Ue(e)}function Ge(e){return!L(e.preset)}function Ke(e){return typeof e==`string`?!1:Ge(e)}function qe(e){let t={enabled:e&&typeof e==`object`?e.enabled??!0:!0};return Be(e)&&Object.assign(t,je(e)),He(e)&&Object.assign(t,Ne(e)),We(e)&&Object.assign(t,Ie(e)),Ke(e)&&Object.assign(t,Re(e)),V(B(t),Array.from(new Set([`enabled`,...Ae,...Fe,...Me,...Le])))}function Je(){return{backgroundImage:`none`,backgroundSize:`auto, auto`,backgroundColor:`none`,backgroundColormap:`none`}}function Ye(e){return typeof e==`string`?{...qe(e)}:{...qe(e),...V(e,[`width`,`style`,`lineCap`,`lineJoin`,`headEnd`,`tailEnd`])}}function Xe(){return{outlineWidth:0,outlineOffset:0,outlineColor:`none`,outlineStyle:`none`}}function Ze(e){return typeof e==`string`?{enabled:!0,color:xe(e)}:{...e,enabled:e.enabled??!0,color:L(e.color)?ye:xe(e.color)}}function Qe(){return{boxShadow:`none`}}function $e(e){return B({blur:e.blur,brightness:e.brightness,contrast:e.contrast,grayscale:e.grayscale,hueRotate:e.hueRotate,invert:e.invert,opacity:e.opacity,saturate:e.saturate,sepia:e.sepia,duotone:e.duotone?[xe(e.duotone[0]),xe(e.duotone[1])]:void 0,biLevel:e.biLevel,colorChange:e.colorChange?{from:xe(e.colorChange.from),to:xe(e.colorChange.to)}:void 0})}var et=[`fill`,`outline`,`shadow`,`transform`,`transformOrigin`,`filter`];function tt(e){let t=V(e,et),{rotate:n,scaleX:r,scaleY:i,skewX:a,skewY:o,translateX:s,translateY:c}=e,l=[];return(s||c)&&l.push(`translate(${s||0}, ${c||0})`),n&&l.push(`rotate(${n}deg)`),(r||i)&&l.push(`scale(${r??1}, ${i??1})`),a&&l.push(`skewX(${a}deg)`),o&&l.push(`skewY(${o}deg)`),l.length>0&&(t.transform=l.join(` `)),(e.textStrokeWidth||e.textStrokeColor)&&(t.outline={color:e.textStrokeColor,width:e.textStrokeWidth}),e.color&&(t.fill={color:e.color}),(e.shadowOffsetX||e.shadowOffsetY||e.shadowBlur||e.shadowColor)&&(t.shadow={offsetX:e.shadowOffsetX,offsetY:e.shadowOffsetY,blur:e.shadowBlur,color:e.shadowColor}),t}function nt(e){let t=tt(e);return B({fill:L(t.fill)?void 0:qe(t.fill),outline:L(t.outline)?void 0:Ye(t.outline),shadow:L(t.shadow)?void 0:Ze(t.shadow),transform:L(t.transform)?void 0:t.transform,transformOrigin:t.transformOrigin,filter:t.filter?$e(t.filter):void 0})}function rt(){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 it(){return{rotate:0,scaleX:1,scaleY:1,skewX:0,skewY:0,translateX:0,translateY:0,transform:`none`,transformOrigin:`center`}}function at(){return{...rt(),...it(),...Qe(),...Je(),...Xe(),borderRadius:0,borderColor:`none`,borderStyle:`solid`,visibility:`visible`,filter:`none`,opacity:1,pointerEvents:`auto`,maskImage:`none`}}function ot(){return{highlight:{},highlightImage:`none`,highlightReferImage:`none`,highlightColormap:`none`,highlightLine:`none`,highlightSize:`cover`,highlightThickness:`100%`}}function st(){return{listStyle:{},listStyleType:`none`,listStyleImage:`none`,listStyleColormap:`none`,listStyleSize:`cover`,listStylePosition:`outside`}}function ct(){return{...ot(),color:`#000000`,verticalAlign:`baseline`,letterSpacing:0,wordSpacing:0,fontSize:14,fontWeight:`normal`,fontFamily:``,fontStyle:`normal`,fontKerning:`normal`,textTransform:`none`,textOrientation:`mixed`,textDecoration:`none`}}function lt(){return{...st(),writingMode:`horizontal-tb`,textWrap:`wrap`,textAlign:`start`,textIndent:0,lineHeight:1.2}}function ut(){return{...lt(),...ct(),textStrokeWidth:0,textStrokeColor:`none`}}var dt=[`textIndent`,`lineHeight`,`letterSpacing`,`wordSpacing`,`fontSize`,`textStrokeWidth`,`borderRadius`,`opacity`,`rotate`,`scaleX`,`scaleY`,`skewX`,`skewY`,`translateX`,`translateY`,`borderWidth`,`flex`,`flexGrow`,`flexShrink`];function ft(e){let t=B({...e,color:L(e.color)?void 0:xe(e.color),backgroundColor:L(e.backgroundColor)?void 0:xe(e.backgroundColor),borderColor:L(e.borderColor)?void 0:xe(e.borderColor),outlineColor:L(e.outlineColor)?void 0:xe(e.outlineColor),shadowColor:L(e.shadowColor)?void 0:xe(e.shadowColor),textStrokeColor:L(e.textStrokeColor)?void 0:xe(e.textStrokeColor)});for(let e of dt)if(e in t){let n=z(t[e]);n===void 0?delete t[e]:t[e]=n}return t}function pt(){return{...at(),...ut()}}var mt=/\r\n|\n\r|\n|\r/;RegExp(`${mt.source}|<br\\/>`,`g`);var ht=RegExp(`^(${mt.source})$`),gt=`
`;function _t(e){return ht.test(e)}function vt(e){let t=[];function n(){return t[t.length-1]}function r(e,n,r){let i=e?ft(e):{},a=n?qe(n):void 0,o=r?Ye(r):void 0,s=B({...i,fill:a,outline:o,fragments:[]});return t[t.length-1]?.fragments.length===0?t[t.length-1]=s:t.push(s),s}function i(e=``,t,i,a){let o=t?ft(t):{},s=i?qe(i):void 0,c=a?Ye(a):void 0;Array.from(e).forEach(e=>{if(_t(e)){let{fragments:e,fill:t,outline:i,...a}=n()||r();e.length||e.push(B({...o,fill:s,outline:c,content:gt})),r(a,t,i)}else{let t=n()||r(),i=t.fragments[t.fragments.length-1];if(i){let{content:t,fill:n,outline:r,...a}=i;if(ee(s,n)&&ee(c,r)&&ee(o,a)){i.content=`${t}${e}`;return}}t.fragments.push(B({...o,fill:s,outline:c,content:e}))}})}(Array.isArray(e)?e:[e]).forEach(e=>{if(typeof e==`string`)r(),i(e);else if(bt(e)){let{content:t,fill:n,outline:a,...o}=e;r(o,n,a),i(t)}else if(yt(e)){let{fragments:t,fill:n,outline:a,...o}=e;r(o,n,a),t.forEach(e=>{let{content:t,fill:n,outline:r,...a}=e;i(t,a,n,r)})}else Array.isArray(e)?(r(),e.forEach(e=>{if(typeof e==`string`)i(e);else if(bt(e)){let{content:t,fill:n,outline:r,...a}=e;i(t,a,n,r)}})):console.warn(`Failed to parse text content`,e)});let a=n();return a&&!a.fragments.length&&a.fragments.push({content:``}),t}function yt(e){return e&&typeof e==`object`&&`fragments`in e&&Array.isArray(e.fragments)}function bt(e){return e&&typeof e==`object`&&`content`in e&&typeof e.content==`string`}function xt(e){return B({type:e.type,intensities:e.intensities,maxFontSize:e.maxFontSize??100})}function St(e){return typeof e==`string`||Array.isArray(e)?{enabled:!0,content:vt(e)}:B({enabled:e.enabled??!0,content:vt(e.content??``),style:e.style?ft(e.style):void 0,deformation:e.deformation?xt(e.deformation):void 0,measureDom:e.measureDom,fonts:e.fonts,...nt(e),effects:e.effects?e.effects.map(e=>nt(e)):void 0})}var Ct=new Set,wt=!1;function Tt(e,t,n=2){let r=t&&t.length,i=r?t[0]*n:e.length;Ct.size&&Ct.clear();let a=Et(e,0,i,n,!0),o=[];if(!a||a.next===a.prev)return o;let s=0,c=0,l=0;if(r&&(a=Pt(e,t,a,n)),e.length>80*n){s=e[0],c=e[1];let t=s,r=c;for(let a=n;a<i;a+=n){let n=e[a],i=e[a+1];n<s&&(s=n),i<c&&(c=i),n>t&&(t=n),i>r&&(r=i)}l=Math.max(t-s,r-c),l=l===0?0:32767/l}return Ot(a,o,s,c,l),o}function Et(e,t,n,r,i){let a=null;if(i===vn(e,t,n,r)>0)for(let i=t;i<n;i+=r)a=hn(i/r|0,e[i],e[i+1],a);else for(let i=n-r;i>=t;i-=r)a=hn(i/r|0,e[i],e[i+1],a);return a&&cn(a,a.next)&&(gn(a),a=a.next),a}function Dt(e,t=e){let n=t===e,r=e,i;do i=!1,r!==r.next&&(Ct.size===0||!Ct.has(r))&&(cn(r,r.next)||sn(r.prev,r,r.next)===0)?((n||r===t)&&(t=r.prev),wt=!0,gn(r),r=r.prev,i=!0):(n||r!==t)&&(r=r.next,i=!n);while(i||r!==t);return t}function Ot(e,t,n,r,i){i&&$t(e,n,r,i);let a=e,o=!1;for(;e.prev!==e.next;){let s=e.prev,c=e.next;if(sn(s,e,c)<0&&(i?At(e,n,r,i):kt(e))){t.push(s.i,e.i,c.i),gn(e),e=c,a=c;continue}if(e=c,e===a){if(wt=!1,e=Dt(e),wt){a=e;continue}if(!o){e=jt(e,t),a=e,o=!0;continue}Mt(e,t,n,r,i);break}}}function kt(e){let t=e.prev,n=e,r=e.next,i=t.x,a=n.x,o=r.x,s=t.y,c=n.y,l=r.y,u=Math.min(i,a,o),d=Math.min(s,c,l),f=Math.max(i,a,o),p=Math.max(s,c,l),m=r.next;for(;m!==t;){if(m.x>=u&&m.x<=f&&m.y>=d&&m.y<=p&&!(i===m.x&&s===m.y)&&an(i,s,a,c,o,l,m.x,m.y)&&sn(m.prev,m,m.next)>=0)return!1;m=m.next}return!0}function At(e,t,n,r){let i=e.prev,a=e,o=e.next,s=i.x,c=a.x,l=o.x,u=i.y,d=a.y,f=o.y,p=Math.min(s,c,l),m=Math.min(u,d,f),h=Math.max(s,c,l),g=Math.max(u,d,f),_=nn(p,m,t,n,r),v=nn(h,g,t,n,r),y=e.prevZ;for(;y&&y.z>=_;){if(y.x>=p&&y.x<=h&&y.y>=m&&y.y<=g&&y!==o&&!(s===y.x&&u===y.y)&&an(s,u,c,d,l,f,y.x,y.y)&&sn(y.prev,y,y.next)>=0)return!1;y=y.prevZ}let b=e.nextZ;for(;b&&b.z<=v;){if(b.x>=p&&b.x<=h&&b.y>=m&&b.y<=g&&b!==o&&!(s===b.x&&u===b.y)&&an(s,u,c,d,l,f,b.x,b.y)&&sn(b.prev,b,b.next)>=0)return!1;b=b.nextZ}return!0}function jt(e,t){let n=e,r=!1;do{let i=n.prev,a=n.next.next;ln(i,n,n.next,a,!1)&&fn(i,a)&&fn(a,i)&&(t.push(i.i,n.i,a.i),gn(n),gn(n.next),n=e=a,r=!0),n=n.next}while(n!==e);return r?Dt(n):n}function Mt(e,t,n,r,i){let a=e;do{let e=a.next.next;for(;e!==a.prev;){if(a.i!==e.i&&on(a,e)){let o=mn(a,e);a=Dt(a,a.next),o=Dt(o,o.next),Ot(a,t,n,r,i),Ot(o,t,n,r,i);return}e=e.next}a=a.next}while(a!==e)}var Nt=!1;function Pt(e,t,n,r){let i=[];for(let n=0,a=t.length;n<a;n++){let o=Et(e,t[n]*r,n<a-1?t[n+1]*r:e.length,r,!1);o===o.next&&Ct.add(o),i.push(rn(o))}i.sort(Ft),Vt(e.length/r,t.length),Ht(n,n),Nt=!0;for(let e=0;e<i.length;e++)n=It(i[e],n);return Nt=!1,Dt(n)}function Ft(e,t){return e.x-t.x||e.y-t.y||(e.next.y-e.y)/(e.next.x-e.x)-(t.next.y-t.y)/(t.next.x-t.x)}function It(e,t){let n=Kt(e,t);if(!n)return t;let r=mn(n,e),i=r.next;return Ht(n,i.next),Dt(r,r.next),Dt(n,n.next)}var Lt=16,H=new Float64Array,Rt=0,zt=[],Bt=[];function Vt(e,t){let n=Math.ceil((e+2*t)/Lt)+t+2;H.length<n*4&&(H=new Float64Array(n*4)),Rt=0}function Ht(e,t){let n=e;do{let e=Rt++;zt[e]=n;let r=1/0,i=1/0,a=-1/0,o=-1/0,s=0;do{let t=n.next;n.z=e,n.x<r&&(r=n.x),n.x>a&&(a=n.x),n.y<i&&(i=n.y),n.y>o&&(o=n.y),t.x<r&&(r=t.x),t.x>a&&(a=t.x),t.y<i&&(i=t.y),t.y>o&&(o=t.y),n=t}while(++s<Lt&&n!==t);Bt[e]=n;let c=e*4;H[c]=r,H[c+1]=i,H[c+2]=a,H[c+3]=o}while(n!==t)}function Ut(e,t){let n=e.z*4;t.x<H[n]&&(H[n]=t.x),t.y<H[n+1]&&(H[n+1]=t.y),t.x>H[n+2]&&(H[n+2]=t.x),t.y>H[n+3]&&(H[n+3]=t.y)}function Wt(e){let t=Bt[e];for(;t.prev.next!==t;)t=t.next;return Bt[e]=t,t}function Gt(e){let t=zt[e];for(;t.prev.next!==t;)t=t.next;return zt[e]=t,t}function Kt(e,t){let n=t,r=e.x,i=e.y,a=-1/0,o;if(cn(e,n))return n;for(let t=0,s=0;t<Rt;t++,s+=4){if(i<H[s+1]||i>H[s+3]||H[s]>r||H[s+2]<=a)continue;let c=Wt(t);n=Gt(t);do{if(n.prev.next===n){if(cn(e,n.next))return n.next;if(i<=n.y&&i>=n.next.y&&n.next.y!==n.y){let e=n.x+(i-n.y)*(n.next.x-n.x)/(n.next.y-n.y);if(e<=r&&e>a&&(a=e,o=n.x<n.next.x?n:n.next,e===r))return o}}n=n.next}while(n!==c)}if(!o)return null;let s=o.x,c=o.y,l=Math.min(i,c),u=Math.max(i,c),d=1/0;for(let t=0,f=0;t<Rt;t++,f+=4){if(H[f+2]<s||H[f]>r||H[f+3]<l||H[f+1]>u)continue;let p=Wt(t);n=Gt(t);do{if(n.prev.next===n&&r>=n.x&&n.x>=s&&r!==n.x&&an(i<c?r:a,i,s,c,i<c?a:r,i,n.x,n.y)){let t=Math.abs(i-n.y)/(r-n.x);(fn(n,e)||n.y===i&&n.next.y===i&&n.next.x>r)&&(t<d||t===d&&(n.x>o.x||n.x===o.x&&qt(o,n)))&&(o=n,d=t)}n=n.next}while(n!==p)}return o}function qt(e,t){return sn(e.prev,e,t.prev)<0&&sn(t.next,e,e.next)<0}var Jt=[],Yt=[],Xt=new Uint32Array,Zt=new Uint32Array,Qt=new Uint32Array(256);function $t(e,t,n,r){let i=e,a=0;do i.z=nn(i.x,i.y,t,n,r),Jt[a++]=i,i=i.next;while(i!==e);en(a);let o=null;for(let e=0;e<a;e++){let t=Jt[e];t.prevZ=o,o&&(o.nextZ=t),o=t}o.nextZ=null}function en(e){if(e<=32){for(let t=1;t<e;t++){let e=Jt[t],n=e.z,r=t-1;for(;r>=0&&Jt[r].z>n;)Jt[r+1]=Jt[r],r--;Jt[r+1]=e}return}Xt.length<e&&(Xt=new Uint32Array(e),Zt=new Uint32Array(e),Yt=Array(e));for(let t=0;t<e;t++)Xt[t]=Jt[t].z;tn(e,Jt,Xt,Yt,Zt,0),tn(e,Yt,Zt,Jt,Xt,8),tn(e,Jt,Xt,Yt,Zt,16),tn(e,Yt,Zt,Jt,Xt,24)}function tn(e,t,n,r,i,a){Qt.fill(0);for(let t=0;t<e;t++)Qt[n[t]>>>a&255]++;let o=0;for(let e=0;e<256;e++){let t=Qt[e];Qt[e]=o,o+=t}for(let o=0;o<e;o++){let e=n[o],s=Qt[e>>>a&255]++;r[s]=t[o],i[s]=e}}function nn(e,t,n,r,i){return e=(e-n)*i|0,t=(t-r)*i|0,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e|t<<1}function rn(e){let t=e,n=e;do(t.x<n.x||t.x===n.x&&t.y<n.y)&&(n=t),t=t.next;while(t!==e);return n}function an(e,t,n,r,i,a,o,s){return(i-o)*(t-s)>=(e-o)*(a-s)&&(e-o)*(r-s)>=(n-o)*(t-s)&&(n-o)*(a-s)>=(i-o)*(r-s)}function on(e,t){let n=cn(e,t)&&sn(e.prev,e,e.next)>0&&sn(t.prev,t,t.next)>0;return e.next.i!==t.i&&(n||fn(e,t)&&fn(t,e)&&(sn(e.prev,e,t.prev)!==0||sn(e,t.prev,t)!==0))&&!dn(e,t)&&(n||pn(e,t))}function sn(e,t,n){return(t.y-e.y)*(n.x-t.x)-(t.x-e.x)*(n.y-t.y)}function cn(e,t){return e.x===t.x&&e.y===t.y}function ln(e,t,n,r,i=!0){let a=sn(e,t,n),o=sn(e,t,r),s=sn(n,r,e),c=sn(n,r,t);return(a>0&&o<0||a<0&&o>0)&&(s>0&&c<0||s<0&&c>0)?!0:i?!!(a===0&&un(e,n,t)||o===0&&un(e,r,t)||s===0&&un(n,e,r)||c===0&&un(n,t,r)):!1}function un(e,t,n){return t.x<=Math.max(e.x,n.x)&&t.x>=Math.min(e.x,n.x)&&t.y<=Math.max(e.y,n.y)&&t.y>=Math.min(e.y,n.y)}function dn(e,t){let n=Math.min(e.x,t.x),r=Math.max(e.x,t.x),i=Math.min(e.y,t.y),a=Math.max(e.y,t.y),o=e;do{let s=o.next;if(o.x>r&&s.x>r||o.x<n&&s.x<n||o.y>a&&s.y>a||o.y<i&&s.y<i){o=s;continue}if(o.i!==e.i&&s.i!==e.i&&o.i!==t.i&&s.i!==t.i&&ln(o,s,e,t))return!0;o=s}while(o!==e);return!1}function fn(e,t){return sn(e.prev,e,e.next)<0?sn(e,t,e.next)>=0&&sn(e,e.prev,t)>=0:sn(e,t,e.prev)<0||sn(e,e.next,t)<0}function pn(e,t){let n=e,r=!1,i=(e.x+t.x)/2,a=(e.y+t.y)/2;do{let e=n.next;n.y>a!=e.y>a&&i<(e.x-n.x)*(a-n.y)/(e.y-n.y)+n.x&&(r=!r),n=e}while(n!==e);return r}function mn(e,t){let n=_n(e.i,e.x,e.y),r=_n(t.i,t.x,t.y),i=e.next,a=t.prev;return e.next=t,t.prev=e,n.next=i,i.prev=n,r.next=n,n.prev=r,a.next=r,r.prev=a,r}function hn(e,t,n,r){let i=_n(e,t,n);return r?(i.next=r.next,i.prev=r,r.next.prev=i,r.next=i):(i.prev=i,i.next=i),i}function gn(e){e.next.prev=e.prev,e.prev.next=e.next,e.prevZ&&(e.prevZ.nextZ=e.nextZ),e.nextZ&&(e.nextZ.prevZ=e.prevZ),Nt&&Ut(e.prev,e.next)}function _n(e,t,n){return{i:e,x:t,y:n,prev:null,next:null,z:0,prevZ:null,nextZ:null}}function vn(e,t,n,r){let i=0;for(let a=t,o=n-r;a<n;a+=r)i+=(e[o]-e[a])*(e[a+1]+e[o+1]),o=a;return i}var yn=l(s(((e,t)=>{(function(n,r){typeof e==`object`&&t!==void 0?t.exports=r():typeof define==`function`&&define.amd?define(r):(n=typeof globalThis<`u`?globalThis:n||self,n.polygonClipping=r())})(e,(function(){"use strict";function e(e,t){var n={label:0,sent:function(){if(a[0]&1)throw a[1];return a[1]},trys:[],ops:[]},r,i,a,o;return o={next:s(0),throw:s(1),return:s(2)},typeof Symbol==`function`&&(o[Symbol.iterator]=function(){return this}),o;function s(e){return function(t){return c([e,t])}}function c(o){if(r)throw TypeError(`Generator is already executing.`);for(;n;)try{if(r=1,i&&(a=o[0]&2?i.return:o[0]?i.throw||((a=i.return)&&a.call(i),0):i.next)&&!(a=a.call(i,o[1])).done)return a;switch(i=0,a&&(o=[o[0]&2,a.value]),o[0]){case 0:case 1:a=o;break;case 4:return n.label++,{value:o[1],done:!1};case 5:n.label++,i=o[1],o=[0];continue;case 7:o=n.ops.pop(),n.trys.pop();continue;default:if((a=n.trys,!(a=a.length>0&&a[a.length-1]))&&(o[0]===6||o[0]===2)){n=0;continue}if(o[0]===3&&(!a||o[1]>a[0]&&o[1]<a[3])){n.label=o[1];break}if(o[0]===6&&n.label<a[1]){n.label=a[1],a=o;break}if(a&&n.label<a[2]){n.label=a[2],n.ops.push(o);break}a[2]&&n.ops.pop(),n.trys.pop();continue}o=t.call(e,n)}catch(e){o=[6,e],i=0}finally{r=a=0}if(o[0]&5)throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}}var t=function(){function e(e,t){this.next=null,this.key=e,this.data=t,this.left=null,this.right=null}return e}();function n(e,t){return e>t?1:e<t?-1:0}function r(e,n,r){for(var i=new t(null,null),a=i,o=i;;){var s=r(e,n.key);if(s<0){if(n.left===null)break;if(r(e,n.left.key)<0){var c=n.left;if(n.left=c.right,c.right=n,n=c,n.left===null)break}o.left=n,o=n,n=n.left}else if(s>0){if(n.right===null)break;if(r(e,n.right.key)>0){var c=n.right;if(n.right=c.left,c.left=n,n=c,n.right===null)break}a.right=n,a=n,n=n.right}else break}return a.right=n.left,o.left=n.right,n.left=i.right,n.right=i.left,n}function i(e,n,i,a){var o=new t(e,n);if(i===null)return o.left=o.right=null,o;i=r(e,i,a);var s=a(e,i.key);return s<0?(o.left=i.left,o.right=i,i.left=null):s>=0&&(o.right=i.right,o.left=i,i.right=null),o}function a(e,t,n){var i=null,a=null;if(t){t=r(e,t,n);var o=n(t.key,e);o===0?(i=t.left,a=t.right):o<0?(a=t.right,t.right=null,i=t):(i=t.left,t.left=null,a=t)}return{left:i,right:a}}function o(e,t,n){return t===null?e:e===null?t:(t=r(e.key,t,n),t.left=e,t)}function s(e,t,n,r,i){if(e){r(``+t+(n?`└── `:`├── `)+i(e)+`
`);var a=t+(n?` `:`│ `);e.left&&s(e.left,a,!1,r,i),e.right&&s(e.right,a,!0,r,i)}}var c=function(){function c(e){e===void 0&&(e=n),this._root=null,this._size=0,this._comparator=e}return c.prototype.insert=function(e,t){return this._size++,this._root=i(e,t,this._root,this._comparator)},c.prototype.add=function(e,n){var i=new t(e,n);this._root===null&&(i.left=i.right=null,this._size++,this._root=i);var a=this._comparator,o=r(e,this._root,a),s=a(e,o.key);return s===0?this._root=o:(s<0?(i.left=o.left,i.right=o,o.left=null):s>0&&(i.right=o.right,i.left=o,o.right=null),this._size++,this._root=i),this._root},c.prototype.remove=function(e){this._root=this._remove(e,this._root,this._comparator)},c.prototype._remove=function(e,t,n){var i;return t===null?null:(t=r(e,t,n),n(e,t.key)===0?(t.left===null?i=t.right:(i=r(e,t.left,n),i.right=t.right),this._size--,i):t)},c.prototype.pop=function(){var e=this._root;if(e){for(;e.left;)e=e.left;return this._root=r(e.key,this._root,this._comparator),this._root=this._remove(e.key,this._root,this._comparator),{key:e.key,data:e.data}}return null},c.prototype.findStatic=function(e){for(var t=this._root,n=this._comparator;t;){var r=n(e,t.key);if(r===0)return t;t=r<0?t.left:t.right}return null},c.prototype.find=function(e){return this._root&&(this._root=r(e,this._root,this._comparator),this._comparator(e,this._root.key)!==0)?null:this._root},c.prototype.contains=function(e){for(var t=this._root,n=this._comparator;t;){var r=n(e,t.key);if(r===0)return!0;t=r<0?t.left:t.right}return!1},c.prototype.forEach=function(e,t){for(var n=this._root,r=[],i=!1;!i;)n===null?r.length===0?i=!0:(n=r.pop(),e.call(t,n),n=n.right):(r.push(n),n=n.left);return this},c.prototype.range=function(e,t,n,r){for(var i=[],a=this._comparator,o=this._root,s;i.length!==0||o;)if(o)i.push(o),o=o.left;else{if(o=i.pop(),s=a(o.key,t),s>0)break;if(a(o.key,e)>=0&&n.call(r,o))return this;o=o.right}return this},c.prototype.keys=function(){var e=[];return this.forEach(function(t){var n=t.key;return e.push(n)}),e},c.prototype.values=function(){var e=[];return this.forEach(function(t){var n=t.data;return e.push(n)}),e},c.prototype.min=function(){return this._root?this.minNode(this._root).key:null},c.prototype.max=function(){return this._root?this.maxNode(this._root).key:null},c.prototype.minNode=function(e){if(e===void 0&&(e=this._root),e)for(;e.left;)e=e.left;return e},c.prototype.maxNode=function(e){if(e===void 0&&(e=this._root),e)for(;e.right;)e=e.right;return e},c.prototype.at=function(e){for(var t=this._root,n=!1,r=0,i=[];!n;)if(t)i.push(t),t=t.left;else if(i.length>0){if(t=i.pop(),r===e)return t;r++,t=t.right}else n=!0;return null},c.prototype.next=function(e){var t=this._root,n=null;if(e.right){for(n=e.right;n.left;)n=n.left;return n}for(var r=this._comparator;t;){var i=r(e.key,t.key);if(i===0)break;i<0?(n=t,t=t.left):t=t.right}return n},c.prototype.prev=function(e){var t=this._root,n=null;if(e.left!==null){for(n=e.left;n.right;)n=n.right;return n}for(var r=this._comparator;t;){var i=r(e.key,t.key);if(i===0)break;i<0?t=t.left:(n=t,t=t.right)}return n},c.prototype.clear=function(){return this._root=null,this._size=0,this},c.prototype.toList=function(){return d(this._root)},c.prototype.load=function(e,t,n){t===void 0&&(t=[]),n===void 0&&(n=!1);var r=e.length,i=this._comparator;if(n&&m(e,t,0,r-1,i),this._root===null)this._root=l(e,t,0,r),this._size=r;else{var a=p(this.toList(),u(e,t),i);r=this._size+r,this._root=f({head:a},0,r)}return this},c.prototype.isEmpty=function(){return this._root===null},Object.defineProperty(c.prototype,"size",{get:function(){return this._size},enumerable:!0,configurable:!0}),Object.defineProperty(c.prototype,"root",{get:function(){return this._root},enumerable:!0,configurable:!0}),c.prototype.toString=function(e){e===void 0&&(e=function(e){return String(e.key)});var t=[];return s(this._root,``,!0,function(e){return t.push(e)},e),t.join(``)},c.prototype.update=function(e,t,n){var r=this._comparator,s=a(e,this._root,r),c=s.left,l=s.right;r(e,t)<0?l=i(t,n,l,r):c=i(t,n,c,r),this._root=o(c,l,r)},c.prototype.split=function(e){return a(e,this._root,this._comparator)},c.prototype[Symbol.iterator]=function(){var t,n,r;return e(this,function(e){switch(e.label){case 0:t=this._root,n=[],r=!1,e.label=1;case 1:return r?[3,6]:t===null?[3,2]:(n.push(t),t=t.left,[3,5]);case 2:return n.length===0?[3,4]:(t=n.pop(),[4,t]);case 3:return e.sent(),t=t.right,[3,5];case 4:r=!0,e.label=5;case 5:return[3,1];case 6:return[2]}})},c}();function l(e,n,r,i){var a=i-r;if(a>0){var o=r+Math.floor(a/2),s=e[o],c=n[o],u=new t(s,c);return u.left=l(e,n,r,o),u.right=l(e,n,o+1,i),u}return null}function u(e,n){for(var r=new t(null,null),i=r,a=0;a<e.length;a++)i=i.next=new t(e[a],n[a]);return i.next=null,r.next}function d(e){for(var n=e,r=[],i=!1,a=new t(null,null),o=a;!i;)n?(r.push(n),n=n.left):r.length>0?(n=o=o.next=r.pop(),n=n.right):i=!0;return o.next=null,a.next}function f(e,t,n){var r=n-t;if(r>0){var i=t+Math.floor(r/2),a=f(e,t,i),o=e.head;return o.left=a,e.head=e.head.next,o.right=f(e,i+1,n),o}return null}function p(e,n,r){for(var i=new t(null,null),a=i,o=e,s=n;o!==null&&s!==null;)r(o.key,s.key)<0?(a.next=o,o=o.next):(a.next=s,s=s.next),a=a.next;return o===null?s!==null&&(a.next=s):a.next=o,i.next}function m(e,t,n,r,i){if(!(n>=r)){for(var a=e[n+r>>1],o=n-1,s=r+1;;){do o++;while(i(e[o],a)<0);do s--;while(i(e[s],a)>0);if(o>=s)break;var c=e[o];e[o]=e[s],e[s]=c,c=t[o],t[o]=t[s],t[s]=c}m(e,t,n,s,i),m(e,t,s+1,r,i)}}let h=(e,t)=>e.ll.x<=t.x&&t.x<=e.ur.x&&e.ll.y<=t.y&&t.y<=e.ur.y,g=(e,t)=>{if(t.ur.x<e.ll.x||e.ur.x<t.ll.x||t.ur.y<e.ll.y||e.ur.y<t.ll.y)return null;let n=e.ll.x<t.ll.x?t.ll.x:e.ll.x,r=e.ur.x<t.ur.x?e.ur.x:t.ur.x,i=e.ll.y<t.ll.y?t.ll.y:e.ll.y,a=e.ur.y<t.ur.y?e.ur.y:t.ur.y;return{ll:{x:n,y:i},ur:{x:r,y:a}}},_=2**-52;_===void 0&&(_=2**-52);let v=_*_,y=(e,t)=>{if(-_<e&&e<_&&-_<t&&t<_)return 0;let n=e-t;return n*n<v*e*t?0:e<t?-1:1};class b{constructor(){this.reset()}reset(){this.xRounder=new x,this.yRounder=new x}round(e,t){return{x:this.xRounder.round(e),y:this.yRounder.round(t)}}}class x{constructor(){this.tree=new c,this.round(0)}round(e){let t=this.tree.add(e),n=this.tree.prev(t);if(n!==null&&y(t.key,n.key)===0)return this.tree.remove(e),n.key;let r=this.tree.next(t);return r!==null&&y(t.key,r.key)===0?(this.tree.remove(e),r.key):e}}let S=new b,C=134217729;function w(e,t,n,r,i){let a,o,s,c,l=t[0],u=r[0],d=0,f=0;u>l==u>-l?(a=l,l=t[++d]):(a=u,u=r[++f]);let p=0;if(d<e&&f<n)for(u>l==u>-l?(o=l+a,s=a-(o-l),l=t[++d]):(o=u+a,s=a-(o-u),u=r[++f]),a=o,s!==0&&(i[p++]=s);d<e&&f<n;)u>l==u>-l?(o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d]):(o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f]),a=o,s!==0&&(i[p++]=s);for(;d<e;)o=a+l,c=o-a,s=a-(o-c)+(l-c),l=t[++d],a=o,s!==0&&(i[p++]=s);for(;f<n;)o=a+u,c=o-a,s=a-(o-c)+(u-c),u=r[++f],a=o,s!==0&&(i[p++]=s);return(a!==0||p===0)&&(i[p++]=a),p}function T(e,t){let n=t[0];for(let r=1;r<e;r++)n+=t[r];return n}function E(e){return new Float64Array(e)}let D=E(4),O=E(8),k=E(12),A=E(16),j=E(4);function M(e,t,n,r,i,a,o){let s,c,l,u,d,f,p,m,h,g,_,v,y,b,x,S,E,M,N=e-i,P=n-i,F=t-a,I=r-a;b=N*I,f=C*N,p=f-(f-N),m=N-p,f=C*I,h=f-(f-I),g=I-h,x=m*g-(b-p*h-m*h-p*g),S=F*P,f=C*F,p=f-(f-F),m=F-p,f=C*P,h=f-(f-P),g=P-h,E=m*g-(S-p*h-m*h-p*g),_=x-E,d=x-_,D[0]=x-(_+d)+(d-E),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,D[1]=y-(_+d)+(d-S),M=v+_,d=M-v,D[2]=v-(M-d)+(_-d),D[3]=M;let L=T(4,D),R=22204460492503146e-32*o;if(L>=R||-L>=R||(d=e-N,s=e-(N+d)+(d-i),d=n-P,l=n-(P+d)+(d-i),d=t-F,c=t-(F+d)+(d-a),d=r-I,u=r-(I+d)+(d-a),s===0&&c===0&&l===0&&u===0)||(R=11093356479670487e-47*o+33306690738754706e-32*Math.abs(L),L+=N*u+I*s-(F*l+P*c),L>=R||-L>=R))return L;b=s*I,f=C*s,p=f-(f-s),m=s-p,f=C*I,h=f-(f-I),g=I-h,x=m*g-(b-p*h-m*h-p*g),S=c*P,f=C*c,p=f-(f-c),m=c-p,f=C*P,h=f-(f-P),g=P-h,E=m*g-(S-p*h-m*h-p*g),_=x-E,d=x-_,j[0]=x-(_+d)+(d-E),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,j[1]=y-(_+d)+(d-S),M=v+_,d=M-v,j[2]=v-(M-d)+(_-d),j[3]=M;let z=w(4,D,4,j,O);b=N*u,f=C*N,p=f-(f-N),m=N-p,f=C*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=F*l,f=C*F,p=f-(f-F),m=F-p,f=C*l,h=f-(f-l),g=l-h,E=m*g-(S-p*h-m*h-p*g),_=x-E,d=x-_,j[0]=x-(_+d)+(d-E),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,j[1]=y-(_+d)+(d-S),M=v+_,d=M-v,j[2]=v-(M-d)+(_-d),j[3]=M;let B=w(z,O,4,j,k);return b=s*u,f=C*s,p=f-(f-s),m=s-p,f=C*u,h=f-(f-u),g=u-h,x=m*g-(b-p*h-m*h-p*g),S=c*l,f=C*c,p=f-(f-c),m=c-p,f=C*l,h=f-(f-l),g=l-h,E=m*g-(S-p*h-m*h-p*g),_=x-E,d=x-_,j[0]=x-(_+d)+(d-E),v=b+_,d=v-b,y=b-(v-d)+(_-d),_=y-S,d=y-_,j[1]=y-(_+d)+(d-S),M=v+_,d=M-v,j[2]=v-(M-d)+(_-d),j[3]=M,A[w(B,k,4,j,A)-1]}function N(e,t,n,r,i,a){let o=(t-a)*(n-i),s=(e-i)*(r-a),c=o-s,l=Math.abs(o+s);return Math.abs(c)>=33306690738754716e-32*l?c:-M(e,t,n,r,i,a,l)}let P=(e,t)=>e.x*t.y-e.y*t.x,F=(e,t)=>e.x*t.x+e.y*t.y,I=(e,t,n)=>{let r=N(e.x,e.y,t.x,t.y,n.x,n.y);return r>0?-1:+(r<0)},L=e=>Math.sqrt(F(e,e)),R=(e,t,n)=>{let r={x:t.x-e.x,y:t.y-e.y},i={x:n.x-e.x,y:n.y-e.y};return P(i,r)/L(i)/L(r)},z=(e,t,n)=>{let r={x:t.x-e.x,y:t.y-e.y},i={x:n.x-e.x,y:n.y-e.y};return F(i,r)/L(i)/L(r)},B=(e,t,n)=>t.y===0?null:{x:e.x+t.x/t.y*(n-e.y),y:n},V=(e,t,n)=>t.x===0?null:{x:n,y:e.y+t.y/t.x*(n-e.x)},ee=(e,t,n,r)=>{if(t.x===0)return V(n,r,e.x);if(r.x===0)return V(e,t,n.x);if(t.y===0)return B(n,r,e.y);if(r.y===0)return B(e,t,n.y);let i=P(t,r);if(i==0)return null;let a={x:n.x-e.x,y:n.y-e.y},o=P(a,t)/i,s=P(a,r)/i,c=e.x+s*t.x,l=n.x+o*r.x,u=e.y+s*t.y,d=n.y+o*r.y;return{x:(c+l)/2,y:(u+d)/2}};class te{static compare(e,t){let n=te.comparePoints(e.point,t.point);return n===0?(e.point!==t.point&&e.link(t),e.isLeft===t.isLeft?re.compare(e.segment,t.segment):e.isLeft?1:-1):n}static comparePoints(e,t){return e.x<t.x?-1:e.x>t.x?1:e.y<t.y?-1:+(e.y>t.y)}constructor(e,t){e.events===void 0?e.events=[this]:e.events.push(this),this.point=e,this.isLeft=t}link(e){if(e.point===this.point)throw Error(`Tried to link already linked events`);let t=e.point.events;for(let e=0,n=t.length;e<n;e++){let n=t[e];this.point.events.push(n),n.point=this.point}this.checkForConsuming()}checkForConsuming(){let e=this.point.events.length;for(let t=0;t<e;t++){let n=this.point.events[t];if(n.segment.consumedBy===void 0)for(let r=t+1;r<e;r++){let e=this.point.events[r];e.consumedBy===void 0&&n.otherSE.point.events===e.otherSE.point.events&&n.segment.consume(e.segment)}}}getAvailableLinkedEvents(){let e=[];for(let t=0,n=this.point.events.length;t<n;t++){let n=this.point.events[t];n!==this&&!n.segment.ringOut&&n.segment.isInResult()&&e.push(n)}return e}getLeftmostComparator(e){let t=new Map,n=n=>{let r=n.otherSE;t.set(n,{sine:R(this.point,e.point,r.point),cosine:z(this.point,e.point,r.point)})};return(e,r)=>{t.has(e)||n(e),t.has(r)||n(r);let{sine:i,cosine:a}=t.get(e),{sine:o,cosine:s}=t.get(r);return i>=0&&o>=0?a<s?1:a>s?-1:0:i<0&&o<0?a<s?-1:+(a>s):o<i?-1:+(o>i)}}}let ne=0;class re{static compare(e,t){let n=e.leftSE.point.x,r=t.leftSE.point.x,i=e.rightSE.point.x,a=t.right