UNPKG

@g20/core

Version:

Geometric Algebra 2D Graphics Library

1 lines 86.2 kB
import{signal as t,effect as e,computed as i}from"@g20/reactive";var s=function(t,e){return s=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},s(t,e)};function r(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}s(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}function o(t){var e="function"==typeof Symbol&&Symbol.iterator,i=e&&t[e],s=0;if(i)return i.call(t);if(t&&"number"==typeof t.length)return{next:function(){return t&&s>=t.length&&(t=void 0),{value:t&&t[s++],done:!t}}};throw new TypeError(e?"Object is not iterable.":"Symbol.iterator is not defined.")}function n(t,e){var i="function"==typeof Symbol&&t[Symbol.iterator];if(!i)return t;var s,r,o=i.call(t),n=[];try{for(;(void 0===e||e-- >0)&&!(s=o.next()).done;)n.push(s.value)}catch(t){r={error:t}}finally{try{s&&!s.done&&(i=o.return)&&i.call(o)}finally{if(r)throw r.error}}return n}function h(t,e,i){if(i||2===arguments.length)for(var s,r=0,o=e.length;r<o;r++)!s&&r in e||(s||(s=Array.prototype.slice.call(e,0,r)),s[r]=e[r]);return t.concat(s||Array.prototype.slice.call(e))}function a(t){return"function"==typeof t}function c(t){var e=t((function(t){Error.call(t),t.stack=(new Error).stack}));return e.prototype=Object.create(Error.prototype),e.prototype.constructor=e,e}"function"==typeof SuppressedError&&SuppressedError;var l=c((function(t){return function(e){t(this),this.message=e?e.length+" errors occurred during unsubscription:\n"+e.map((function(t,e){return e+1+") "+t.toString()})).join("\n "):"",this.name="UnsubscriptionError",this.errors=e}}));function u(t,e){if(t){var i=t.indexOf(e);0<=i&&t.splice(i,1)}}var d=function(){function t(t){this.initialTeardown=t,this.closed=!1,this._parentage=null,this._finalizers=null}var e;return t.prototype.unsubscribe=function(){var t,e,i,s,r;if(!this.closed){this.closed=!0;var c=this._parentage;if(c)if(this._parentage=null,Array.isArray(c))try{for(var u=o(c),d=u.next();!d.done;d=u.next()){d.value.remove(this)}}catch(e){t={error:e}}finally{try{d&&!d.done&&(e=u.return)&&e.call(u)}finally{if(t)throw t.error}}else c.remove(this);var p=this.initialTeardown;if(a(p))try{p()}catch(t){r=t instanceof l?t.errors:[t]}var f=this._finalizers;if(f){this._finalizers=null;try{for(var g=o(f),b=g.next();!b.done;b=g.next()){var m=b.value;try{y(m)}catch(t){r=null!=r?r:[],t instanceof l?r=h(h([],n(r)),n(t.errors)):r.push(t)}}}catch(t){i={error:t}}finally{try{b&&!b.done&&(s=g.return)&&s.call(g)}finally{if(i)throw i.error}}}if(r)throw new l(r)}},t.prototype.add=function(e){var i;if(e&&e!==this)if(this.closed)y(e);else{if(e instanceof t){if(e.closed||e._hasParent(this))return;e._addParent(this)}(this._finalizers=null!==(i=this._finalizers)&&void 0!==i?i:[]).push(e)}},t.prototype._hasParent=function(t){var e=this._parentage;return e===t||Array.isArray(e)&&e.includes(t)},t.prototype._addParent=function(t){var e=this._parentage;this._parentage=Array.isArray(e)?(e.push(t),e):e?[e,t]:t},t.prototype._removeParent=function(t){var e=this._parentage;e===t?this._parentage=null:Array.isArray(e)&&u(e,t)},t.prototype.remove=function(e){var i=this._finalizers;i&&u(i,e),e instanceof t&&e._removeParent(this)},t.EMPTY=((e=new t).closed=!0,e),t}(),p=d.EMPTY;function f(t){return t instanceof d||t&&"closed"in t&&a(t.remove)&&a(t.add)&&a(t.unsubscribe)}function y(t){a(t)?t():t.unsubscribe()}var g={onUnhandledError:null,onStoppedNotification:null,Promise:void 0,useDeprecatedSynchronousErrorHandling:!1,useDeprecatedNextContext:!1},b=function(t,e){for(var i=[],s=2;s<arguments.length;s++)i[s-2]=arguments[s];return setTimeout.apply(void 0,h([t,e],n(i)))};function m(){}function v(t){t()}var x=function(t){function e(e){var i=t.call(this)||this;return i.isStopped=!1,e?(i.destination=e,f(e)&&e.add(i)):i.destination=O,i}return r(e,t),e.create=function(t,e,i){return new A(t,e,i)},e.prototype.next=function(t){this.isStopped||this._next(t)},e.prototype.error=function(t){this.isStopped||(this.isStopped=!0,this._error(t))},e.prototype.complete=function(){this.isStopped||(this.isStopped=!0,this._complete())},e.prototype.unsubscribe=function(){this.closed||(this.isStopped=!0,t.prototype.unsubscribe.call(this),this.destination=null)},e.prototype._next=function(t){this.destination.next(t)},e.prototype._error=function(t){try{this.destination.error(t)}finally{this.unsubscribe()}},e.prototype._complete=function(){try{this.destination.complete()}finally{this.unsubscribe()}},e}(d),w=Function.prototype.bind;function z(t,e){return w.call(t,e)}var k=function(){function t(t){this.partialObserver=t}return t.prototype.next=function(t){var e=this.partialObserver;if(e.next)try{e.next(t)}catch(t){_(t)}},t.prototype.error=function(t){var e=this.partialObserver;if(e.error)try{e.error(t)}catch(t){_(t)}else _(t)},t.prototype.complete=function(){var t=this.partialObserver;if(t.complete)try{t.complete()}catch(t){_(t)}},t}(),A=function(t){function e(e,i,s){var r,o,n=t.call(this)||this;a(e)||!e?r={next:null!=e?e:void 0,error:null!=i?i:void 0,complete:null!=s?s:void 0}:n&&g.useDeprecatedNextContext?((o=Object.create(e)).unsubscribe=function(){return n.unsubscribe()},r={next:e.next&&z(e.next,o),error:e.error&&z(e.error,o),complete:e.complete&&z(e.complete,o)}):r=e;return n.destination=new k(r),n}return r(e,t),e}(x);function _(t){var e;e=t,b((function(){throw e}))}var O={closed:!0,next:m,error:function(t){throw t},complete:m},M="function"==typeof Symbol&&Symbol.observable||"@@observable";function C(t){return t}var E=function(){function t(t){t&&(this._subscribe=t)}return t.prototype.lift=function(e){var i=new t;return i.source=this,i.operator=e,i},t.prototype.subscribe=function(t,e,i){var s,r=this,o=(s=t)&&s instanceof x||function(t){return t&&a(t.next)&&a(t.error)&&a(t.complete)}(s)&&f(s)?t:new A(t,e,i);return v((function(){var t=r,e=t.operator,i=t.source;o.add(e?e.call(o,i):i?r._subscribe(o):r._trySubscribe(o))})),o},t.prototype._trySubscribe=function(t){try{return this._subscribe(t)}catch(e){t.error(e)}},t.prototype.forEach=function(t,e){var i=this;return new(e=S(e))((function(e,s){var r=new A({next:function(e){try{t(e)}catch(t){s(t),r.unsubscribe()}},error:s,complete:e});i.subscribe(r)}))},t.prototype._subscribe=function(t){var e;return null===(e=this.source)||void 0===e?void 0:e.subscribe(t)},t.prototype[M]=function(){return this},t.prototype.pipe=function(){for(var t,e=[],i=0;i<arguments.length;i++)e[i]=arguments[i];return(0===(t=e).length?C:1===t.length?t[0]:function(e){return t.reduce((function(t,e){return e(t)}),e)})(this)},t.prototype.toPromise=function(t){var e=this;return new(t=S(t))((function(t,i){var s;e.subscribe((function(t){return s=t}),(function(t){return i(t)}),(function(){return t(s)}))}))},t.create=function(e){return new t(e)},t}();function S(t){var e;return null!==(e=null!=t?t:g.Promise)&&void 0!==e?e:Promise}var V=c((function(t){return function(){t(this),this.name="ObjectUnsubscribedError",this.message="object unsubscribed"}})),B=function(t){function e(){var e=t.call(this)||this;return e.closed=!1,e.currentObservers=null,e.observers=[],e.isStopped=!1,e.hasError=!1,e.thrownError=null,e}return r(e,t),e.prototype.lift=function(t){var e=new F(this,this);return e.operator=t,e},e.prototype._throwIfClosed=function(){if(this.closed)throw new V},e.prototype.next=function(t){var e=this;v((function(){var i,s;if(e._throwIfClosed(),!e.isStopped){e.currentObservers||(e.currentObservers=Array.from(e.observers));try{for(var r=o(e.currentObservers),n=r.next();!n.done;n=r.next()){n.value.next(t)}}catch(t){i={error:t}}finally{try{n&&!n.done&&(s=r.return)&&s.call(r)}finally{if(i)throw i.error}}}}))},e.prototype.error=function(t){var e=this;v((function(){if(e._throwIfClosed(),!e.isStopped){e.hasError=e.isStopped=!0,e.thrownError=t;for(var i=e.observers;i.length;)i.shift().error(t)}}))},e.prototype.complete=function(){var t=this;v((function(){if(t._throwIfClosed(),!t.isStopped){t.isStopped=!0;for(var e=t.observers;e.length;)e.shift().complete()}}))},e.prototype.unsubscribe=function(){this.isStopped=this.closed=!0,this.observers=this.currentObservers=null},Object.defineProperty(e.prototype,"observed",{get:function(){var t;return(null===(t=this.observers)||void 0===t?void 0:t.length)>0},enumerable:!1,configurable:!0}),e.prototype._trySubscribe=function(e){return this._throwIfClosed(),t.prototype._trySubscribe.call(this,e)},e.prototype._subscribe=function(t){return this._throwIfClosed(),this._checkFinalizedStatuses(t),this._innerSubscribe(t)},e.prototype._innerSubscribe=function(t){var e=this,i=this,s=i.hasError,r=i.isStopped,o=i.observers;return s||r?p:(this.currentObservers=null,o.push(t),new d((function(){e.currentObservers=null,u(o,t)})))},e.prototype._checkFinalizedStatuses=function(t){var e=this,i=e.hasError,s=e.thrownError,r=e.isStopped;i?t.error(s):r&&t.complete()},e.prototype.asObservable=function(){var t=new E;return t.source=this,t},e.create=function(t,e){return new F(t,e)},e}(E),F=function(t){function e(e,i){var s=t.call(this)||this;return s.destination=e,s.source=i,s}return r(e,t),e.prototype.next=function(t){var e,i;null===(i=null===(e=this.destination)||void 0===e?void 0:e.next)||void 0===i||i.call(e,t)},e.prototype.error=function(t){var e,i;null===(i=null===(e=this.destination)||void 0===e?void 0:e.error)||void 0===i||i.call(e,t)},e.prototype.complete=function(){var t,e;null===(e=null===(t=this.destination)||void 0===t?void 0:t.complete)||void 0===e||e.call(t)},e.prototype._subscribe=function(t){var e,i;return null!==(i=null===(e=this.source)||void 0===e?void 0:e.subscribe(t))&&void 0!==i?i:p},e}(B),R=function(t){function e(e){var i=t.call(this)||this;return i._value=e,i}return r(e,t),Object.defineProperty(e.prototype,"value",{get:function(){return this.getValue()},enumerable:!1,configurable:!0}),e.prototype._subscribe=function(e){var i=t.prototype._subscribe.call(this,e);return!i.closed&&e.next(this._value),i},e.prototype.getValue=function(){var t=this,e=t.hasError,i=t.thrownError,s=t._value;if(e)throw i;return this._throwIfClosed(),s},e.prototype.next=function(e){t.prototype.next.call(this,this._value=e)},e}(B);class W{#t;constructor(t){this.#t=t}subscribe(t){const e=this.#t.subscribe(t);return{dispose(){e.unsubscribe()}}}}class L{#e;constructor(t,e={}){this.#e=t}get(){return this.#e.getValue()}set(t){this.#e.next(t)}asObservable(){return new W(this.#e.asObservable())}}function $(t,e={}){const i=new R(t);return new L(i,e)}const D=Math.abs;function P(t,e,i){let s=D(t[e][e]),r=e;for(let o=e+1;o<i;o++)D(t[o][e])>s&&(s=D(t[o][e]),r=o);return r}function N(t,e,i,s){const r=s+1;for(let s=e;s<r;s++){const r=t[i][s];t[i][s]=t[e][s],t[e][s]=r}}function j(t,e,i){for(let s=e+1;s<i;s++){const r=-t[s][e]/t[e][e];for(let o=e;o<i+1;o++)e===o?t[s][o]=0:t[s][o]+=r*t[e][o]}}const q=Math.sqrt;function T(t){return 0===(e=t).x&&0===e.y&&function(t){return 0===t.b}(t)&&0===t.a&&0===t.b;var e}const I=-1*Math.random();function X(t){return t.lock(),t}function U(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]}function Y(t){return t.isMutable()?t:t.clone()}function G(t){return t instanceof K?Y(t):Array.isArray(t)?K.vector(t[0],t[1]):null}function Z(t){return t instanceof K?Y(t):Array.isArray(t)?K.spinor(t[0],t[1]):null}class K{#i=[[0,0,0,0],[0,0,0,0]];#s=t(this.#i[0],{equals:U});#r=I;#o=$(this);change$=this.#o.asObservable();constructor(t=0,e=0,i=0,s=0){this.set(t,e,i,s)}static scalar(t){return new K(0,0,t,0)}static bivector(t){return new K(0,0,0,t)}static spinor(t,e){return new K(0,0,t,e)}static vector(t,e){return new K(t,e,0,0)}isLocked(){return this.#r!==I}isMutable(){return this.#r===I}lock(){if(this.#r!==I)throw new Error("already locked");return this.#r=Math.random(),this.#r}unlock(t){if(this.#r===I)throw new Error("not locked");if(this.#r===t)return this.#r=I,this;throw new Error("unlock denied")}get a(){return this.#s.get()[0]}set a(t){if("number"==typeof t){const e=this.#i[0];if(t!==e[0]){const i=e[1],s=e[2],r=e[3];this.set(i,s,t,r)}}}get x(){return this.#s.get()[1]}set x(t){if("number"==typeof t){const e=this.#i[0];if(t!==e[1]){const i=e[0],s=e[3],r=e[2];this.set(t,r,i,s)}}}get y(){return this.#s.get()[2]}set y(t){if("number"==typeof t){const e=this.#i[0];if(t!==e[2]){const i=e[1],s=e[0],r=e[3];this.set(i,t,s,r)}}}get b(){return this.#s.get()[3]}set b(t){if("number"==typeof t){const e=this.#i[0];if(t!==e[3]){const i=e[1],s=e[2],r=e[0];this.set(i,s,r,t)}}}static one=X(new K(0,0,1,0));static zero=X(new K(0,0,0,0));static ex=X(new K(1,0,0,0));static ey=X(new K(0,1,0,0));static I=X(new K(0,0,0,1));static add(t,e){const i=t.x+e.x,s=t.y+e.y,r=t.a+e.a,o=t.b+e.b;return new K(i,s,r,o)}static copy(t){return new K(t.x,t.y,t.a,t.b)}static fromBivector(t){return K.bivector(t.b)}static fromScalar(t){return K.scalar(t.a)}static fromSpinor(t){return K.spinor(t.a,t.b)}static fromVector(t){return K.vector(t.x,t.y)}static rotorFromDirections(t,e){return new K(0,0,0,0).rotorFromDirections(t,e)}static rotorFromVectorToVector(t,e){return new K(0,0,0,0).rotorFromVectorToVector(t,e)}static sub(t,e){const i=t.x-e.x,s=t.y-e.y,r=t.a-e.a,o=t.b-e.b;return new K(i,s,r,o)}static subtract(t,e){return K.sub(t,e)}static ratioBetween(t,e){return(t.x*e.x+t.y*e.y)/(t.magnitude()*e.magnitude())}static angleBetween(t,e){const i=t.x-e.x,s=t.y-e.y;return Math.atan2(s,i)}static distanceBetween(t,e){return Math.sqrt(K.distanceBetweenSquared(t,e))}static distanceBetweenSquared(t,e){const i=t.x-e.x,s=t.y-e.y;return i*i+s*s}add2(t,e){return T(t)?this.set(e.x,e.y,e.a,e.b):T(e)?this.set(t.x,t.y,t.a,t.b):this.set(t.x+e.x,t.y+e.y,t.a+e.a,t.b+e.b)}addPseudo(t){return this.isLocked()?X(this.clone().addPseudo(t)):0===t?this:this.set(this.x,this.y,this.a,this.b+t)}addScalar(t,e=1){return this.isLocked()?X(this.clone().addScalar(t,e)):this.isZero()?(this.a=t*e,this):(0===t||0===e||(this.a+=t*e),this)}conj(){return this.isLocked()?X(this.clone().conj()):this.set(-this.x,-this.y,this.a,-this.b)}copy(t){return this.set(t.x,t.y,t.a,t.b)}copySpinor(t){return this.set(0,0,t.a,t.b)}copyVector(t){return this.set(t.x,t.y,0,0)}clear(){return this.set(0,0,0,0)}clone(){return new K(this.x,this.y,this.a,this.b)}div(t){return this.isLocked()?X(this.clone().div(t)):0===(e=t).x&&0===e.y&&0===e.b?this.scale(1/t.a):this.mul(K.copy(t).inv());var e}ext(t){if(this.isLocked())return X(this.clone().ext(t));{const e=this.a,i=this.x,s=this.y,r=this.b,o=t.a,n=t.x,h=t.y,a=e*o,c=e*n+i*o,l=e*h+s*o,u=e*t.b+i*h-s*n+r*o;return this.set(c,l,a,u)}}inv(){if(this.isLocked())return X(this.clone().inv());{const t=this.a,e=this.x,i=this.y,s=this.b,r=function(t,e){const i=t.length;for(let s=0;s<i;s++){const i=t[s],r=e[s];i.push(r)}for(let e=0;e<i;e++)N(t,e,P(t,e,i),i),j(t,e,i);return function(t,e){const i=function(t,e){const i=[];for(let s=0;s<t;s++)i.push(e);return i}(e,0);for(let s=e-1;s>-1;s--){i[s]=t[s][e]/t[s][s];for(let r=s-1;r>-1;r--)t[r][e]-=t[r][s]*i[s]}return i}(t,i)}([[+t,+e,+i,-s],[+e,+t,-s,+i],[+i,+s,+t,-e],[+s,+i,-e,+t]],[1,0,0,0]),o=r[0],n=r[1],h=r[2],a=r[3];return this.set(n,h,o,a)}}lco(t){return this.isLocked()?X(this.clone().lco(t)):this.#n(this,t)}#n(t,e){const i=t.a,s=t.x,r=t.y,o=t.b,n=e.a,h=e.x,a=e.y,c=e.b,l=i*n+s*h+r*a-o*c,u=i*h-r*c,d=i*a+s*c,p=i*c;return this.set(u,d,l,p)}add(t){if(this.isLocked())return X(this.clone().add(t));{const e=this.x+t.x,i=this.y+t.y,s=this.a+t.a,r=this.b+t.b;return this.set(e,i,s,r)}}sub(t){if(this.isLocked())return X(this.clone().sub(t));{const e=this.x-t.x,i=this.y-t.y,s=this.a-t.a,r=this.b-t.b;return this.set(e,i,s,r)}}mul(t){return this.isLocked()?X(this.clone().mul(t)):this.#h(this,t)}#h(t,e){const i=t.a,s=t.x,r=t.y,o=t.b,n=e.a,h=e.x,a=e.y,c=e.b,l=i*n+s*h+r*a-o*c,u=i*h+s*n-r*c+o*a,d=i*a+s*c+r*n-o*h,p=i*c+s*a-r*h+o*n;return this.set(u,d,l,p)}neg(){return this.scale(-1)}dot(t){return this.x*t.x+this.y*t.y}exp(){if(this.isLocked())return X(this.clone().exp());{const t=this.a,e=this.b,i=Math.exp(t),s=Math.sqrt(e*e),r=i*(0!==s?Math.sin(s)/s:1),o=i*Math.cos(s),n=e*r;return this.set(0,0,o,n)}}magnitude(){return Math.sqrt(this.quaditude())}quaditude(){const t=this.a,e=this.x,i=this.y,s=this.b;return t*t+e*e+i*i-s*s}normalize(){return this.isLocked()?X(this.clone().normalize()):this.scale(1/this.magnitude())}distanceTo(t){return Math.sqrt(this.distanceToSquared(t))}distanceToSquared(t){const e=this.x-t.x,i=this.y-t.y;return e*e+i*i}rco(t){return this.isLocked()?X(this.clone().rco(t)):this.#a(this,t)}#a(t,e){const i=t.a,s=t.x,r=t.y,o=t.b,n=e.a,h=e.x,a=e.y,c=i*n+s*h+r*a-o*e.b,l=s*n+o*a,u=r*n-o*h,d=o*n;return this.set(l,u,c,d)}reflect(t){if(this.isLocked())return X(this.clone().reflect(t));{const e=t.x,i=t.y,s=this.a,r=this.x,o=this.y,n=e*e,h=i*i,a=n-h,c=-2*e*i,l=n+h,u=-l*s,d=c*o-a*r,p=c*r+a*o,f=l*this.b;return this.set(d,p,u,f)}}rotorFromDirections(t,e){return this.isLocked()?X(this.clone().rotorFromDirections(t,e)):(function(t,e,i){const s=t.x,r=t.y,o=e.x,n=e.y,h=s*s+r*r,a=q(h),c=o*o+n*n,l=q(c)*a,u=s*o+r*n,d=q(2*(c*h+l*u));if(0!==d){const t=r*o-s*n;i.set(0,0,(l+u)/d,t/d)}}(t,e,this),this)}rotorFromAngle(t){if(this.isLocked())return X(this.clone().rotorFromAngle(t));{const e=t/2;return this.set(0,0,Math.cos(e),-Math.sin(e))}}rotorFromVectorToVector(t,e){if(this.isLocked())return X(this.clone().rotorFromVectorToVector(t,e));{const i=t.x,s=t.y,r=e.x,o=e.y,n=Math.sqrt(r*r+o*o),h=Math.sqrt(i*i+s*s),a=n*h,c=r*i+o*s,l=r*s-o*i,u=Math.sqrt(2*a*(a+c)),d=Math.sqrt(n)/(Math.sqrt(h)*u),p=d*(a+c),f=d*l;return this.set(0,0,p,f)}}scale(t){if(this.isLocked())return X(this.clone().scale(t));{const e=this.x*t,i=this.y*t,s=this.a*t,r=this.b*t;return this.set(e,i,s,r)}}scp(t){return this.isLocked()?X(this.clone().scp(t)):this.#c(this,t)}#c(t,e){const i=t.a,s=t.x,r=t.y,o=t.b,n=i*e.a+s*e.x+r*e.y-o*e.b;return this.set(0,0,n,0)}set(t,e,i=0,s=0){if(this.isMutable()){const r=this.#i[0],o=this.#i[1];return o[0]=i,o[3]=s,o[1]=t,o[2]=e,U(o,r)||(this.#i[0]=o,this.#i[1]=r,this.#s.set(o),this.#o.set(this)),this}throw new Error}equals(t,e){return e=void 0===e?1e-4:e,this.distanceTo(t)<e}lerp(t,e){if(this.isLocked())return X(this.clone().lerp(t,e));{const i=(t.x-this.x)*e+this.x,s=(t.y-this.y)*e+this.y,r=(t.a-this.a)*e+this.a,o=(t.b-this.b)*e+this.b;return this.set(i,s,r,o)}}isZero(t){return"number"==typeof t?Math.abs(this.a)<t&&Math.abs(this.x)<t&&Math.abs(this.y)<t&&Math.abs(this.b)<t:0===this.a&&0===this.x&&0===this.y&&0===this.b}toString(){return JSON.stringify({x:this.x,y:this.y,a:this.a,b:this.b})}rev(){if(this.isMutable()){const t=+this.a,e=+this.x,i=+this.y,s=-this.b;return this.set(e,i,t,s)}return X(this.clone().rev())}rotate(t){if(this.isMutable()){const e=this.x,i=this.y,s=Math.cos(t),r=Math.sin(t),o=e*s-i*r,n=e*r+i*s;return this.set(o,n,this.a,this.b)}return X(this.clone().rotate(t))}subScalar(t,e=1){return this.isLocked()?X(this.clone().subScalar(t,e)):this.isZero()?(this.a=-t*e,this):(0===t||0===e||(this.a-=t*e),this)}versor(t,e){if(this.isMutable()){const i=t.x*e.x+t.y*e.y,s=0,r=0,o=t.x*e.y-t.y*e.x;return this.set(s,r,i,o)}throw new Error}__div__(t){return t instanceof K?X(this.clone().div(t)):"number"==typeof t?X(this.clone().scale(1/t)):void 0}__rdiv__(t){return t instanceof K?X(K.copy(t).div(this)):"number"==typeof t?X(K.scalar(t).div(this)):void 0}__vbar__(t){return t instanceof K?X(K.copy(this).scp(t)):"number"==typeof t?X(K.copy(this).scp(K.scalar(t))):void 0}__rvbar__(t){return t instanceof K?X(K.copy(t).scp(this)):"number"==typeof t?X(K.scalar(t).scp(this)):void 0}__wedge__(t){return t instanceof K?X(K.copy(this).ext(t)):"number"==typeof t?X(K.copy(this).scale(t)):void 0}__rwedge__(t){return t instanceof K?X(K.copy(t).ext(this)):"number"==typeof t?X(K.copy(this).scale(t)):void 0}__lshift__(t){return t instanceof K?X(K.copy(this).lco(t)):"number"==typeof t?X(K.copy(this).lco(K.scalar(t))):void 0}__rlshift__(t){return t instanceof K?X(K.copy(t).lco(this)):"number"==typeof t?X(K.scalar(t).lco(this)):void 0}__rshift__(t){return t instanceof K?X(K.copy(this).rco(t)):"number"==typeof t?X(K.copy(this).rco(K.scalar(t))):void 0}__rrshift__(t){return t instanceof K?X(K.copy(t).rco(this)):"number"==typeof t?X(K.scalar(t).rco(this)):void 0}__bang__(){return X(K.copy(this).inv())}__eq__(t){return t instanceof K?this.equals(t):"number"==typeof t&&this.equals(K.scalar(t))}__ne__(t){return t instanceof K?!this.equals(t):"number"!=typeof t||!this.equals(K.scalar(t))}__tilde__(){return X(K.copy(this).rev())}__add__(t){return t instanceof K?X(this.clone().add(t)):"number"==typeof t?X(this.clone().addScalar(t,1)):void 0}__radd__(t){return t instanceof K?X(K.copy(t).add(this)):"number"==typeof t?X(K.scalar(t).add(this)):void 0}__sub__(t){return t instanceof K?X(this.clone().sub(t)):"number"==typeof t?X(this.clone().subScalar(t,1)):void 0}__rsub__(t){return t instanceof K?X(K.copy(t).sub(this)):"number"==typeof t?X(K.scalar(t).sub(this)):void 0}__pos__(){return X(K.copy(this))}__neg__(){return X(K.copy(this).neg())}__mul__(t){return t instanceof K?X(this.clone().mul(t)):"number"==typeof t?X(this.clone().scale(t)):void 0}__rmul__(t){return t instanceof K?X(K.copy(t).mul(this)):"number"==typeof t?X(K.copy(this).scale(t)):void 0}}const Q={move:"M",line:"L",curve:"C",arc:"A",close:"Z"};class J{origin;#l;controls={a:new K,b:new K};#u;#d;#p;#f;#y;#g;#b;#m;#v;#o=$(this);change$=this.#o.asObservable();#x;constructor(t,e=Q.move,i=0,s=0,r=0,o=0){var n;this.origin=(n=t)instanceof K?n.isLocked()?n.clone():n:Array.isArray(n)?new K(n[0],n[1]):K.zero.clone(),this.controls.a.set(i,s),this.controls.b.set(r,o),this.#p=e,this.#f=!0,this.#y=0,this.#g=0,this.#b=0,this.#m=0,this.#v=1,this.#x=0,this.#l=this.origin.change$.subscribe((()=>{this.#o.set(this)})),this.#u=this.controls.a.change$.subscribe((()=>{this.#o.set(this)})),this.#d=this.controls.b.change$.subscribe((()=>{this.#o.set(this)}))}dispose(){this.#l&&this.#l.dispose(),this.#u&&this.#u.dispose(),this.#d&&this.#d.dispose()}get x(){return this.origin.x}set x(t){this.origin.x=t}get y(){return this.origin.y}set y(t){this.origin.y=t}get t(){return this.#x}set t(t){this.t!==t&&(this.#x=t)}copy(t){return this.origin.copyVector(t.origin),this.command=t.command,this.controls.a.copyVector(t.controls.a),this.controls.b.copyVector(t.controls.b),this.relative=t.relative,this.rx=t.rx,this.ry=t.ry,this.xAxisRotation=t.xAxisRotation,this.largeArcFlag=t.largeArcFlag,this.sweepFlag=t.sweepFlag,this}ignore(){throw new Error("TODO: Anchor.ignore()")}listen(){}get command(){return this.#p}set command(t){this.command!==t&&(this.#p=t)}get relative(){return this.#f}set relative(t){this.relative!==!!t&&(this.#f=t)}get rx(){return this.#y}set rx(t){this.rx!==t&&(this.#y=t)}get ry(){return this.#g}set ry(t){this.ry!==t&&(this.#g=t)}get xAxisRotation(){return this.#b}set xAxisRotation(t){this.xAxisRotation!==t&&(this.#b=t)}get largeArcFlag(){return this.#m}set largeArcFlag(t){this.largeArcFlag!==t&&(this.#m=t)}get sweepFlag(){return this.#v}set sweepFlag(t){this.sweepFlag!==t&&(this.#v=t)}}class H{#w;insert$;#z;remove$;#k;order$;#A;constructor(t){this.#A=t,this.#w=new B,this.insert$=new W(this.#w.asObservable()),this.#z=new B,this.remove$=new W(this.#z.asObservable()),this.#k=new B,this.order$=new W(this.#k.asObservable())}forEach(t,e){this.#A.forEach(t,e)}get length(){return this.#A.length}getAt(t){return this.#A[t]}get(){return this.#A}ping(){this.#w.next(this.#A)}pop(){const t=this.#A.pop();return this.#z.next([t]),t}shift(){const t=this.#A.shift();return this.#z.next([t]),t}push(...t){const e=this.#A.push(...t);return this.#w.next(t),e}unshift(...t){const e=this.#A.unshift();return this.#w.next(t),e}splice(t,e,...i){if("number"==typeof e){const s=this.#A.splice(t,e,...i);return this.#z.next(s),s}{const e=this.#A.splice(t);return this.#z.next(e),e}}sort(t){return this.#A.sort(t),this.#k.next(),this}reverse(){return this.#A.reverse(),this.#k.next(),this}indexOf(t,e){return this.#A.indexOf(t,e)}map(t,e){return this.#A.map(t,e)}}const tt=(1+Math.sqrt(5))/2,et=Math.atan2(.5,tt);class it{board;arc={};arrow={};circle={};ellipse={};line={};point={};polygon={};rectangle={};text={};constructor(t){this.board=t}reset(){this.arc.fillColor="none",this.arc.fillOpacity=null,this.arc.strokeColor="gray",this.arc.strokeOpacity=null,this.arc.strokeWidth=3/this.board.sx,this.arrow.fillColor="none",this.arrow.fillOpacity=null,this.arrow.headAngle=et,this.arrow.headLength=.05,this.arrow.strokeColor="gray",this.arrow.strokeOpacity=null,this.arrow.strokeWidth=3/this.board.sx,this.circle.fillColor="none",this.circle.fillOpacity=null,this.circle.strokeColor="gray",this.circle.strokeOpacity=null,this.circle.strokeWidth=3/this.board.sx,this.ellipse.fillColor="none",this.ellipse.fillOpacity=null,this.ellipse.strokeColor="gray",this.ellipse.strokeOpacity=null,this.ellipse.strokeWidth=3/this.board.sx,this.line.fillColor="none",this.line.fillOpacity=null,this.line.strokeColor="gray",this.line.strokeOpacity=.6,this.line.strokeWidth=2/this.board.sx,this.point.iconColor="gray",this.point.iconOpacity=null,this.point.iconKind="ellipse",this.point.textColor="gray",this.point.textOpacity=null,this.point.strokeWidth=2/this.board.sx,this.polygon.fillColor="none",this.polygon.fillOpacity=null,this.polygon.strokeColor="gray",this.polygon.strokeOpacity=null,this.polygon.strokeWidth=3/this.board.sx,this.rectangle.fillColor="none",this.rectangle.fillOpacity=null,this.rectangle.strokeColor="gray",this.rectangle.strokeOpacity=null,this.rectangle.strokeWidth=3/this.board.sx,this.text.fillColor="gray",this.text.fillOpacity=null,this.text.fontFamily="sans-serif",this.text.fontSize=20}}function st(t){if("string"==typeof t)return!1;if(null===t)return!1;if(Array.isArray(t))return!1;if("object"==typeof t){const e=t;return"function"==typeof e.serialize&&"function"==typeof e.incrementUse&&"function"==typeof e.decrementUse}return!1}function rt(t){return!!st(t)||"string"==typeof t}var ot;function nt(t){for(let e=t.length-1;e>=0;e--)t[e].dispose();t.length=0}!function(t){t[t.Beginning=0]="Beginning",t[t.Cap=1]="Cap",t[t.ClipFlag=2]="ClipFlag",t[t.ClipPath=3]="ClipPath",t[t.Columns=4]="Columns",t[t.EndAngle=5]="EndAngle",t[t.Ending=6]="Ending",t[t.Fill=7]="Fill",t[t.FrameRate=8]="FrameRate",t[t.Index=9]="Index",t[t.Rows=10]="Rows",t[t.Sides=11]="Sides",t[t.Spread=12]="Spread",t[t.StartAngle=13]="StartAngle",t[t.Stops=14]="Stops",t[t.Stroke=15]="Stroke",t[t.Units=16]="Units"}(ot||(ot={}));class ht{disposables=[];flags={};appended;#_=$(!1);ismask$=this.#_.asObservable();svgClipPathElement;context;effect;viewee;hasFillEffect;hasStrokeEffect;image;offset;vertices=[];vertices_subject=$(0);vertices$=this.vertices_subject.asObservable();dispose(){nt(this.disposables)}get ismask(){return this.#_.get()}set ismask(t){this.#_.set(t),this.flags[ot.ClipFlag]=!0}}class at{parent;zzz=new ht;#O=t(null);constructor(e){"string"==typeof e&&(this.#O=t(e))}dispose(){this.zzz.dispose()}get id(){return this.#O.get()}set id(t){this.#O.set(t)}}const ct=2*Math.PI,lt=.5*Math.PI;function ut(t,e,i){return i*(e-t)+t}function dt(t,e){for(;t<0;)t+=e;return t%e}const pt=Math.floor;function ft(t){return pt(1e6*t)/1e6}const yt={ns:"http://www.w3.org/2000/svg",xlink:"http://www.w3.org/1999/xlink",createElement:function(t,e={}){const i=document.createElementNS(yt.ns,t);return e&&Object.keys(e).length>0&&yt.setAttributes(i,e),i},setAttributes:function(t,e){const i=e,s=Object.keys(e);for(let e=0;e<s.length;e++){const r=s[e],o=i[r];/href/.test(s[e])?t.setAttributeNS(yt.xlink,r,o):t.setAttribute(r,o)}return this},removeAttributes:function(t,e){if(t){for(const i in e)t.removeAttribute(i);return this}throw new Error("elem MUST be defined.")},path_from_anchors:function(t,e,i,s,r){const[o,n]=function(t){return t.goofy?t.crazy?[(t,e)=>e,(t,e)=>t]:[(t,e)=>t,(t,e)=>e]:t.crazy?[(t,e)=>t,(t,e)=>e]:[(t,e)=>e,(t,e)=>t]}(t),h=s.length,a=h-1;let c;const l=[];for(let t=0;t<h;t++){const e=s[t],i=s[r?dt(t-1,h):Math.max(t-1,0)];let u,d,p=ft(o(e.x,e.y)),f=ft(n(e.x,e.y));switch(e.command){case Q.close:u=Q.close;break;case Q.arc:{const t=e.rx,i=e.ry,s=e.xAxisRotation,r=e.largeArcFlag,o=e.sweepFlag;u=Q.arc+" "+t+" "+i+" "+s+" "+r+" "+o+" "+p+" "+f;break}case Q.curve:{const s=i.controls&&i.controls.b||K.zero,r=e.controls&&e.controls.a||K.zero;let h,a,c,l;i.relative?(h=ft(o(s.x+i.x,s.y+i.y)),a=ft(n(s.x+i.x,s.y+i.y))):(h=ft(o(s.x,s.y)),a=ft(n(s.x,s.y))),e.relative?(c=ft(o(r.x+e.x,r.y+e.y)),l=ft(n(r.x+e.x,r.y+e.y))):(c=ft(o(r.x,r.y)),l=ft(n(r.x,r.y))),u=(0===t?Q.move:Q.curve)+" "+h+" "+a+" "+c+" "+l+" "+p+" "+f;break}case Q.move:c=e,u=Q.move+" "+p+" "+f;break;default:u=e.command+" "+p+" "+f}if(t>=a&&r){if(e.command===Q.curve){d=c;const t=e.controls&&e.controls.b||e,i=d.controls&&d.controls.a||d;let s,r,h,a;e.relative?(s=ft(o(t.x+e.x,t.y+e.y)),r=ft(n(t.x+e.x,t.y+e.y))):(s=ft(o(t.x,t.y)),r=ft(n(t.x,t.y))),d.relative?(h=ft(o(i.x+d.x,i.y+d.y)),a=ft(n(i.x+d.x,i.y+d.y))):(h=ft(o(i.x,i.y)),a=ft(n(i.x,i.y))),p=ft(o(d.x,d.y)),f=ft(n(d.x,d.y)),u+=" C "+s+" "+r+" "+h+" "+a+" "+p+" "+f}e.command!==Q.close&&(u+=" Z")}l.push(u)}return l.join(" ")},getClip:function(t,e,i){let s=e.zzz.svgClipPathElement;return s||(s=e.zzz.svgClipPathElement=t.createSVGElement("clipPath",{"clip-rule":"nonzero"})),null===t.getParentNode(s)&&t.appendChild(t.getElementDefs(i),s),s},defs:{update:function(t,e){if(function(t){return t._flagUpdate}(e)){const i=Array.prototype.slice.call(e.children,0);for(let s=0;s<i.length;s++){const r=i[s],o=r.id,n=`[fill="url(#${o})"],[stroke="url(#${o})"],[clip-path="url(#${o})"]`;t.querySelector(n)||e.removeChild(r)}!function(t,e){t._flagUpdate=e}(e,!1)}}}};function gt(t){return`matrix(${[t.a,t.b,t.c,t.d,t.e,t.f].map(ft).join(" ")})`}const bt=12;function mt(t,e,i,s,r,o,n,h,a){const c=r*r-o*o,l=2*r*o,u=i,d=s,p=Math.tan(n),f=Math.tan(h),y=u*l,g=d*c,b=g*p,m=d*l,v=u*c-y*f+b*(p*f)*m,x=-y+b,w=t+p*e,z=g*f+m,k=g,A=e;a.set(v,x,w,z,k,A,0,0,1)}const vt=Math.cos,xt=Math.sin,wt=Math.tan;function zt(t,e){return t[0]===e[0]&&t[1]===e[1]&&t[2]===e[2]&&t[3]===e[3]&&t[4]===e[4]&&t[5]===e[5]&&t[6]===e[6]&&t[7]===e[7]&&t[8]===e[8]}class kt{#i=[[1,0,0,0,1,0,0,0,1],[1,0,0,0,1,0,0,0,1]];#s=t(this.#i[0],{equals:zt});constructor(t=1,e=0,i=0,s=0,r=1,o=0,n=0,h=0,a=1){this.set(t,e,i,s,r,o,n,h,a)}get a(){return this.#s.get()[0]}get b(){return this.#s.get()[3]}get c(){return this.#s.get()[1]}get d(){return this.#s.get()[4]}get e(){return this.#s.get()[2]}get f(){return this.#s.get()[5]}get a11(){return this.#s.get()[0]}get a12(){return this.#s.get()[1]}get a13(){return this.#s.get()[2]}get a21(){return this.#s.get()[3]}get a22(){return this.#s.get()[4]}get a23(){return this.#s.get()[5]}get a31(){return this.#s.get()[6]}get a32(){return this.#s.get()[7]}get a33(){return this.#s.get()[8]}toString(){return JSON.stringify([[this.a11,this.a12,this.a13],[this.a21,this.a22,this.a23],[this.a31,this.a32,this.a33]])}set(t,e,i,s,r,o,n,h,a){const c=this.#i[0],l=this.#i[1];return l[0]=t,l[1]=e,l[2]=i,l[3]=s,l[4]=r,l[5]=o,l[6]=n,l[7]=h,l[8]=a,zt(l,c)||(this.#i[0]=l,this.#i[1]=c,this.#s.set(l)),this}copy(t){return this.set(t.a11,t.a12,t.a13,t.a21,t.a22,t.a23,t.a31,t.a32,t.a33)}identity(){return this.set(1,0,0,0,1,0,0,0,1)}isNaN(){return isNaN(this.a11)||isNaN(this.a12)||isNaN(this.a13)||isNaN(this.a21)||isNaN(this.a22)||isNaN(this.a23)||isNaN(this.a31)||isNaN(this.a32)||isNaN(this.a33)}isOne(){return 1===this.a11&&0===this.a12&&0==this.a13&&0===this.a21&&1===this.a22&&0===this.a23&&0===this.a31&&0===this.a32&&1===this.a33}multiply(t,e,i,s,r,o,n,h,a){const c=this.#i[0],l=c[0],u=c[1],d=c[2],p=c[3],f=c[4],y=c[5],g=c[6],b=c[7],m=c[8],v=l*t+u*s+d*n,x=l*e+u*r+d*h,w=l*i+u*o+d*a,z=p*t+f*s+y*n,k=p*e+f*r+y*h,A=p*i+f*o+y*a,_=g*t+b*s+m*n,O=g*e+b*r+m*h,M=g*i+b*o+m*a;return this.set(v,x,w,z,k,A,_,O,M)}multiply_vector(t=0,e=0,i=1){return[this.a11*t+this.a12*e+this.a13*i,this.a21*t+this.a22*e+this.a23*i,this.a31*t+this.a32*e+this.a33*i]}multiply_by_scalar(t){const e=this.#i[0],i=e[0]*t,s=e[1]*t,r=e[2]*t,o=e[3]*t,n=e[4]*t,h=e[5]*t,a=e[6]*t,c=e[7]*t,l=e[8]*t;return this.set(i,s,r,o,n,h,a,c,l)}scale(t,e){return 1===t&&1===e?this:this.multiply(t,0,0,0,e,0,0,0,1)}rotate(t){const e=vt(t),i=xt(t);return 1===e&&0===i?this:this.multiply(e,-i,0,i,e,0,0,0,1)}translate(t){return 0===t.x&&0===t.y?this:this.multiply(1,0,t.x,0,1,t.y,0,0,1)}skewX(t){if(0===t)return this;{const e=wt(t);return this.multiply(1,e,0,0,1,0,0,0,1)}}skewY(t){if(0===t)return this;{const e=wt(t);return this.multiply(1,0,0,e,1,0,0,0,1)}}}class At extends at{board;#M=[];#C=new kt;#E=null;#S;#V;#B=new K(1,1);#F=new K(0,0);#R=t(1);#W=t("visible");#L=t(!1);#$=t(null);constructor(t,e={}){super(e.id),this.board=t,this.worldMatrix=new kt,e.position?this.#S=G(e.position):this.#S=new K(0,0),e.attitude?this.#V=Z(e.attitude):this.#V=new K(0,0,1,0),"boolean"==typeof e.plumb&&this.#L.set(e.plumb),"number"==typeof e.opacity&&this.#R.set(e.opacity),e.visibility&&this.#W.set(e.visibility);const i={sx:1,sy:1};"number"==typeof e.sx&&(i.sx=e.sx),"number"==typeof e.sy&&(i.sy=e.sy),this.#B.set(i.sx,i.sy),this.skewX=0,this.skewY=0,this.#M.push(this.#S.change$.subscribe((()=>{_t(this.#S,this.#V,this.#B,this.skewX,this.skewY,this.plumb,this.board.goofy,this.board.crazy,this.#C)}))),this.#M.push(this.#V.change$.subscribe((()=>{_t(this.#S,this.#V,this.#B,this.skewX,this.skewY,this.plumb,this.board.goofy,this.board.crazy,this.#C)}))),this.#M.push(this.#B.change$.subscribe((()=>{_t(this.#S,this.#V,this.#B,this.skewX,this.skewY,this.plumb,this.board.goofy,this.board.crazy,this.#C)}))),this.#M.push(this.#F.change$.subscribe((()=>{_t(this.#S,this.#V,this.#B,this.skewX,this.skewY,this.plumb,this.board.goofy,this.board.crazy,this.#C)})))}dispose(){nt(this.#M),super.dispose()}render(t,i,s){this.zzz.disposables.push(e((()=>{this.mask?(this.mask.render(t,i,s),t.setAttribute(this.zzz.viewee,"clip-path","url(#"+this.mask.id+")")):t.removeAttribute(this.zzz.viewee,"clip-path")}))),this.zzz.disposables.push(e((()=>{"string"==typeof this.id?t.setAttribute(this.zzz.viewee,"id",this.id):t.removeAttribute(this.zzz.viewee,"id")}))),this.zzz.disposables.push(e((()=>{const e=this.opacity,i={opacity:`${e}`};return 1===e?t.removeAttribute(this.zzz.viewee,"opacity"):t.setAttributes(this.zzz.viewee,i),function(){}}))),this.zzz.disposables.push(e((()=>{const e=this.zzz.viewee;this.matrix.isOne()?t.removeAttribute(e,"transform"):this.matrix.isNaN()?(t.setAttribute(e,"visibility","collapse"),t.removeAttribute(e,"transform")):t.setAttribute(e,"transform",gt(this.matrix))}))),this.zzz.disposables.push(e((()=>{const e=this.visibility;switch(e){case"visible":{const i={visibility:e};t.removeAttributes(this.zzz.viewee,i);break}default:{const i={visibility:e};t.setAttributes(this.zzz.viewee,i);break}}return function(){}})))}update(){return this}viewee(){return this.zzz.viewee}get X(){return this.#S}set X(t){if(t instanceof K)this.#S.copyVector(t);else if(Array.isArray(t))this.#S.set(t[0],t[1]);else{if(null===t)throw new Error;if("object"==typeof t){const e=t,i=e.x,s=e.y;"number"==typeof i&&"number"==typeof s&&this.#S.set(i,s)}}}get plumb(){return this.#L.get()}set plumb(t){this.#L.set(t)}get R(){return this.#V}set R(t){t instanceof K&&this.#V.copySpinor(t)}get scale(){if(this.#B.x===this.#B.y)return this.#B.x;throw new Error}set scale(t){"number"==typeof t?this.#B.set(t,t):Array.isArray(t)&&this.#B.set(t[0],t[1])}get sx(){return this.#B.x}set sx(t){this.#B.x=t}get sy(){return this.#B.y}set sy(t){this.#B.y=t}get skewX(){return this.#F.x}set skewX(t){this.#F.x=t}get skewY(){return this.#F.y}set skewY(t){this.#F.y=t}get mask(){return this.#$.get()}set mask(t){this.#$.set(t),this.zzz.flags[ot.ClipPath]=!0,t instanceof At&&!t.zzz.ismask&&(t.zzz.ismask=!0)}get matrix(){return this.#C}get opacity(){return this.#R.get()}set opacity(t){"number"==typeof t&&t>=0&&t<=1&&this.opacity!==t&&this.#R.set(t)}get visibility(){return this.#W.get()}set visibility(t){"string"==typeof t&&this.visibility!==t&&this.#W.set(t)}show(){return this.visibility="visible",this}hide(){return this.visibility="hidden",this}collapse(){return this.visibility="collapse",this}get worldMatrix(){return function(t,e){e=e&&e.identity()||new kt;let i=t;const s=[];for(;i&&i.matrix;)s.push(i.matrix),i=i.parent;s.reverse();for(let t=0;t<s.length;t++){const i=s[t];e.multiply(i.a11,i.a12,i.a13,i.a21,i.a22,i.a23,i.a31,i.a32,i.a33)}}(this,this.#E),this.#E}set worldMatrix(t){this.#E=t}}function _t(t,e,i,s,r,o,n,h,a){const c=t.x,l=t.y,u=i.x,d=i.y;if(n)if(o)if(h){const t=e.a,i=-e.b;mt(l,c,d,u,(i-t)/Math.SQRT2,(t+i)/Math.SQRT2,r,s,a)}else{mt(c,l,u,d,e.a,-e.b,s,r,a)}else if(h){mt(l,c,d,u,e.a,e.b,r,s,a)}else{mt(c,l,u,d,e.a,-e.b,s,r,a)}else if(o)if(h){mt(c,l,u,d,e.b,e.a,s,r,a)}else{const t=e.a,i=e.b;mt(l,c,d,u,(t-i)/Math.SQRT2,(t+i)/Math.SQRT2,r,s,a)}else if(h){mt(c,l,u,d,e.a,-e.b,s,r,a)}else{mt(l,c,d,u,e.a,e.b,r,s,a)}}class Ot extends At{#D;constructor(e,i=[],s={}){super(e,function(t){const e={id:t.id,attitude:t.attitude,opacity:t.opacity,plumb:t.plumb,position:t.position,sx:t.sx,sy:t.sy,visibility:t.visibility};return e}(s)),this.flagReset(!0),this.zzz.flags[ot.Beginning]=!1,this.zzz.flags[ot.Ending]=!1,this.zzz.flags[ot.ClipPath]=!1,this.#D=t(i)}dispose(){for(const t of this.children)t.dispose();super.dispose()}hasBoundingBox(){return!1}render(t,e,i){if(this.update(),this.zzz.viewee)t.setAttribute(this.zzz.viewee,"transform",gt(this.matrix));else{if(!t)throw new Error("viewDOM must be defined");{const s=t.createSVGElement("g",{id:this.id});if(this.zzz.viewee=s,!e)throw new Error("parentElement must be defined");t.appendChild(e,s),super.render(t,e,i)}}const s=this.children,r=s.length,o=this.zzz.viewee;for(let e=0;e<r;e++){s[e].render(t,o,i)}this.flagReset()}center(){const t=this.getBoundingBox(!0),e=(t.left+t.right)/2-this.X.x,i=(t.top+t.bottom)/2-this.X.y,s=this.children,r=s.length;for(let t=0;t<r;t++){const r=s[t];r.X.x-=e,r.X.y-=i}return this.mask&&(this.mask.X.x-=e,this.mask.X.y-=i),this}getById(t){let e=null;return function i(s){if(s.id===t)return s;if(s instanceof Ot&&s.children)for(let t=0;t<s.children.length;t++)if(e=i(s.children[t]),e)return e;return null}(this)}getByType(t){const e=[];return function i(s){if(s instanceof t&&e.push(s),s instanceof Ot&&s.children)for(let t=0;t<s.children.length;t++){i(s.children[t])}return e}(this)}add(...t){const e=this.children;for(let i=0;i<t.length;i++){const s=t[i],r=e.indexOf(s);r>=0&&e.splice(r,1),e.push(s)}return this}remove(...t){const e=this.children;for(let i=0;i<t.length;i++){const s=t[i];s.dispose();const r=e.indexOf(s);r>=0&&e.splice(r,1)}return this}getBoundingBox(t=!1){this.update();let e=1/0,i=-1/0,s=1/0,r=-1/0;const o=t?this.matrix:this.worldMatrix;for(let n=0;n<this.children.length;n++){const h=this.children[n];if("visible"!==h.visibility||h.hasBoundingBox())continue;const a=h.getBoundingBox(t),c="number"!=typeof a.top||isNaN(a.top)||!isFinite(a.top),l="number"!=typeof a.left||isNaN(a.left)||!isFinite(a.left),u="number"!=typeof a.right||isNaN(a.right)||!isFinite(a.right),d="number"!=typeof a.bottom||isNaN(a.bottom)||!isFinite(a.bottom);if(!(c||l||u||d))if(t){const[t,n]=o.multiply_vector(a.left,a.top),[h,c]=o.multiply_vector(a.right,a.top),[l,u]=o.multiply_vector(a.left,a.bottom),[d,p]=o.multiply_vector(a.right,a.bottom);s=Math.min(n,c,u,p),e=Math.min(t,h,l,d),i=Math.max(t,h,l,d),r=Math.max(n,c,u,p)}else s=Math.min(a.top,s),e=Math.min(a.left,e),i=Math.max(a.right,i),r=Math.max(a.bottom,r)}return{top:s,left:e,right:i,bottom:r}}update(){return super.update()}flagReset(t=!1){return this.zzz.flags[ot.ClipPath]=t,this.zzz.flags[ot.Beginning]=t,this.zzz.flags[ot.Ending]=t,this}get children(){return this.#D.get()}set children(t){this.#D.set(t);for(let e=0;e<t.length;e++){Mt(t[e],this)}}}function Mt(t,e){const i=t.parent;if(i!==e){if(i&&i instanceof Ot){const e=i.children.indexOf(t);i.children.splice(e,1)}e?t.parent=e:delete t.parent}}class Ct{name;#P=[];#N=[];#j;#q=null;#T=null;#I;constructor(e,i){this.name=i,this.#j=t(e)}get(){return this.#j.get()}set(t){const e=this.#j.get();t!==e&&(st(e)&&(this.#q?e.decrementUse(this.#T,this.#T.getElementDefs(this.#q)):this.#N.push(e)),st(t)&&(this.#q?t.incrementUse(this.#T,this.#T.getElementDefs(this.#q)):this.#P.push(t)),this.#j.set(t))}use(t,e,i){this.#T=t,this.#q=e,this.#I=i;const s=this.#T.getElementDefs(e);for(const t of this.#P)t.incrementUse(this.#T,s);this.#P.length=0;for(const t of this.#N)t.decrementUse(this.#T,s);this.#N.length=0}update(){const t=this.#j.get();"string"==typeof t?this.#T.setAttribute(this.#I,this.name,t):st(t)?this.#T.setAttribute(this.#I,this.name,t.serialize()):this.#T.removeAttribute(this.#I,this.name)}}class Et extends At{#X=new Ct(null,"fill");#U=t(1);#Y=new Ct(null,"stroke");#G=t(1);#Z=t(1);#K=t([]);#Q=t(null);constructor(t,e={}){super(t,function(t){const e={id:t.id,plumb:t.plumb,attitude:t.attitude,position:t.position,sx:t.sx,sy:t.sy,visibility:t.visibility};return e}(e)),Array.isArray(e.dashes)&&(this.dashes=e.dashes),e.fillColor&&(this.fillColor=e.fillColor),"number"==typeof e.fillOpacity?this.fillOpacity=e.fillOpacity:this.fillOpacity=1,e.strokeColor&&(this.strokeColor=e.strokeColor),"number"==typeof e.strokeWidth?this.strokeWidth=e.strokeWidth:this.strokeWidth=1,"number"==typeof e.strokeOpacity?this.strokeOpacity=e.strokeOpacity:this.strokeOpacity=1,"string"==typeof e.vectorEffect&&(this.vectorEffect=e.vectorEffect)}get dashes(){return this.#K.get()}set dashes(t){Array.isArray(t)&&this.#K.set(t)}get fillColor(){return this.#X.get()}set fillColor(t){this.#X.set(t),this.zzz.flags[ot.Fill]=!0}get fillOpacity(){return this.#U.get()}set fillOpacity(t){this.#U.set(t)}get strokeColor(){return this.#Y.get()}set strokeColor(t){this.#Y.set(t),this.zzz.flags[ot.Stroke]=!0}get strokeOpacity(){return this.#Z.get()}set strokeOpacity(t){this.#Z.set(t)}get strokeWidth(){return this.#G.get()}set strokeWidth(t){"number"==typeof t&&(isNaN(t)||this.#G.set(t))}get vectorEffect(){return this.#Q.get()}set vectorEffect(t){this.#Q.set(t)}noFill(){return this.fillColor="none",this}noStroke(){return this.strokeColor="none",this}render(t,i,s){if(!this.zzz.viewee)throw new Error;this.#X.use(t,s,this.zzz.viewee),this.#Y.use(t,s,this.zzz.viewee),this.zzz.disposables.push(e((()=>{const e=this.dashes;return Array.isArray(e)&&e.length>0?t.setAttribute(this.zzz.viewee,"stroke-dasharray",this.dashes.join(" ")):t.removeAttribute(this.zzz.viewee,"stroke-dasharray"),function(){}}))),this.zzz.disposables.push(e((()=>(this.#X.update(),function(){})))),this.zzz.disposables.push(e((()=>{const e=this.fillOpacity;return 1!==e?t.setAttribute(this.zzz.viewee,"fill-opacity",`${e}`):t.removeAttribute(this.zzz.viewee,"fill-opacity"),function(){}}))),this.zzz.disposables.push(e((()=>(this.#Y.update(),function(){})))),this.zzz.disposables.push(e((()=>{const e=this.strokeOpacity;return 1!==e?t.setAttribute(this.zzz.viewee,"stroke-opacity",`${e}`):t.removeAttribute(this.zzz.viewee,"stroke-opacity"),function(){}}))),this.zzz.disposables.push(e((()=>{const e=this.strokeWidth;return 1!==e?t.setAttribute(this.zzz.viewee,"stroke-width",`${e}`):t.removeAttribute(this.zzz.viewee,"stroke-width"),function(){}}))),this.zzz.disposables.push(e((()=>{const e=this.vectorEffect;return"string"==typeof e?t.setAttribute(this.zzz.viewee,"vector-effect",`${e}`):t.removeAttribute(this.zzz.viewee,"vector-effect"),function(){}}))),super.render(t,i,s)}}const St={CollinearityEpsilon:Math.pow(10,-30),RecursionLimit:16,CuspLimit:0,Tolerance:{distance:.25,angle:0,epsilon:Number.EPSILON},abscissas:[[.5773502691896257],[0,.7745966692414834],[.33998104358485626,.8611363115940526],[0,.5384693101056831,.906179845938664],[.2386191860831969,.6612093864662645,.932469514203152],[0,.4058451513773972,.7415311855993945,.9491079123427585],[.1834346424956498,.525532409916329,.7966664774136267,.9602898564975363],[0,.3242534234038089,.6133714327005904,.8360311073266358,.9681602395076261],[.14887433898163122,.4333953941292472,.6794095682990244,.8650633666889845,.9739065285171717],[0,.26954315595234496,.5190961292068118,.7301520055740494,.8870625997680953,.978228658146057],[.1252334085114689,.3678314989981802,.5873179542866175,.7699026741943047,.9041172563704749,.9815606342467192],[0,.2304583159551348,.44849275103644687,.6423493394403402,.8015780907333099,.9175983992229779,.9841830547185881],[.10805494870734367,.31911236892788974,.5152486363581541,.6872929048116855,.827201315069765,.9284348836635735,.9862838086968123],[0,.20119409399743451,.3941513470775634,.5709721726085388,.7244177313601701,.8482065834104272,.937273392400706,.9879925180204854],[.09501250983763744,.2816035507792589,.45801677765722737,.6178762444026438,.755404408355003,.8656312023878318,.9445750230732326,.9894009349916499]],weights:[[1],[.8888888888888888,.5555555555555556],[.6521451548625461,.34785484513745385],[.5688888888888889,.47862867049936647,.23692688505618908],[.46791393457269104,.3607615730481386,.17132449237917036],[.4179591836734694,.3818300505051189,.27970539148927664,.1294849661688697],[.362683783378362,.31370664587788727,.22238103445337448,.10122853629037626],[.3302393550012598,.31234707704000286,.26061069640293544,.1806481606948574,.08127438836157441],[.29552422471475287,.26926671930999635,.21908636251598204,.1494513491505806,.06667134430868814],[.2729250867779006,.26280454451024665,.23319376459199048,.18629021092773426,.1255803694649046,.05566856711617366],[.24914704581340277,.2334925365383548,.20316742672306592,.16007832854334622,.10693932599531843,.04717533638651183],[.2325515532308739,.22628318026289723,.2078160475368885,.17814598076194574,.13887351021978725,.09212149983772845,.04048400476531588],[.2152638534631578,.2051984637212956,.18553839747793782,.15720316715819355,.12151857068790319,.08015808715976021,.03511946033175186],[.2025782419255613,.19843148532711158,.1861610000155622,.16626920581699392,.13957067792615432,.10715922046717194,.07036604748810812,.03075324199611727],[.1894506104550685,.18260341504492358,.16915651939500254,.14959598881657674,.12462897125553388,.09515851168249279,.062253523938647894,.027152459411754096]]};function Vt(t,e,i,s,r){const o=1-t;return o*o*o*e+3*o*o*t*i+3*o*t*t*s+t*t*t*r}function Bt(t,e,i,s,r,o,n,h,a){if(t===i&&e===s&&r===n&&o===h){const i=n-t,s=h-e;return Math.sqrt(i*i+s*s)}const c=9*(i-r)+3*(n-t),l=6*(t+r)-12*i,u=3*(i-t),d=9*(s-o)+3*(h-e),p=6*(e+o)-12*s,f=3*(s-e);return function(t,e,i,s){const r=St.abscissas[s-2],o=St.weights[s-2],n=.5*(i-e),h=n+e;let a=0;const c=s+1>>1;let l=1&s?o[a++]*t(h):0;for(;a<c;){const e=n*r[a];l+=o[a++]*(t(h+e)+t(h-e))}return n*l}((function(t){const e=(c*t+l)*t+u,i=(d*t+p)*t+f;return Math.sqrt(e*e+i*i)}),0,1,a||St.RecursionLimit)}function Ft(t,e,i,s,r,o,n,h){const a=[],c=[[],[]];let l,u,d,p,f,y,g,b;for(let c=0;c<2;++c)if(0==c?(u=6*t-12*i+6*r,l=-3*t+9*i-9*r+3*n,d=3*i-3*t):(u=6*e-12*s+6*o,l=-3*e+9*s-9*o+3*h,d=3*s-3*e),Math.abs(l)<1e-12){if(Math.abs(u)<1e-12)continue;p=-d/u,0<p&&p<1&&a.push(p)}else g=u*u-4*d*l,b=Math.sqrt(g),g<0||(f=(-u+b)/(2*l),0<f&&f<1&&a.push(f),y=(-u-b)/(2*l),0<y&&y<1&&a.push(y));const m=a.length;let v,x=m;for(;x--;)p=a[x],v=1-p,c[0][x]=v*v*v*t+3*v*v*p*i+3*v*p*p*r+p*p*p*n,c[1][x]=v*v*v*e+3*v*v*p*s+3*v*p*p*o+p*p*p*h;return c[0][m]=t,c[1][m]=e,c[0][m+1]=n,c[1][m+1]=h,c[0].length=c[1].length=m+2,{min:{x:Math.min.apply(0,c[0]),y:Math.min.apply(0,c[1])},max:{x:Math.max.apply(0,c[0]),y:Math.max.apply(0,c[1])}}}function Rt(t,e,i){const s=K.angleBetween(t.origin,e.origin),r=K.angleBetween(i.origin,e.origin);let o=K.distanceBetween(t.origin,e.origin),n=K.distanceBetween(i.origin,e.origin),h=(s+r)/2;return o<1e-4||n<1e-4?("boolean"!=typeof e.relative||e.relative||(e.controls.a.copyVector(e.origin),e.controls.b.copyVector(e.origin)),e):(o*=.33,n*=.33,r<s?h+=lt:h-=lt,e.controls.a.x=Math.cos(h)*o,e.controls.a.y=Math.sin(h)*o,h-=Math.PI,e.controls.b.x=Math.cos(h)*n,e.controls.b.y=Math.sin(h)*n,"boolean"!=typeof e.relative||e.relative||(e.controls.a.x+=e.x,e.controls.a.y+=e.y,e.controls.b.x+=e.x,e.controls.b.y+=e.y),e)}function Wt(t,e){if(0===e||1===e)return!0;const i=t.length*e;let s=0;const r=t.lengths;for(let t=0;t<r.length;t++){const e=r[t];if(s>=i)return i-s>=0;s+=e}return!1}function Lt(t,e){const i=t.length;if(e<=0)return 0;if(e>=i)return t.lengths.length-1;for(let i=0,s=0;i<t.lengths.length;i++){if(s+t.lengths[i]>=e)return e-=s,Math.max(i-1,0)+e/t.lengths[i];s+=t.lengths[i]}return-1}function $t(t,e,i){let s,r,o,n;const h=e.controls&&e.controls.b,a=t.controls&&t.controls.a,c=e.x,l=e.y;s=(h||e).x,o=(h||e).y,r=(a||t).x,n=(a||t).y;const u=t.x,d=t.y;return h&&e.relative&&(s+=e.x,o+=e.y),a&&t.relative&&(r+=t.x,n+=t.y),Bt(c,l,s,o,r,n,u,d,i)}function Dt(t,e,i){const s=e.controls.b,r=t.controls.a,o=e.x,n=e.y;let h=s.x,a=s.y,c=r.x,l=r.y;const u=t.x,d=t.y;e.relative&&(h+=e.x,a+=e.y),t.relative&&(c+=t.x,l+=t.y);return function(t,e,i,s,r,o,n,h,a,c=St.RecursionLimit){const l=c+1;if(Math.abs(e-h)<.001&&Math.abs(i-a)<.001)return[t(h,a)];const u=[];for(let c=0;c<l;c++){const d=c/l,p=Vt(d,e,s,o,h),f=Vt(d,i,r,n,a);u.push(t(p,f))}return u}(((t,e)=>new J(K.vector(t,e))),o,n,h,a,c,l,u,d,i)}const Pt=Math.min,Nt=Math.max,jt=new K;class qt extends Et{#J=0;#H=[];#tt=t("round");#et=t("round");#it=t(4);#st=t(!0);#rt=t(!1);#ot=t(!0);#nt=t(0);#ht=t(1);#at;#ct=null;#lt=null;#ut=[];#dt=new Map;constructor(t,e=[],i,s,r,o={}){super(t,function(t){const e={id:t.id,dashes:t.dashes,position:t.position,attitude:t.attitude,fillColor:t.fillColor,fillOpacity:t.fillOpacity,strokeColor:t.strokeColor,strokeOpacity:t.strokeOpacity,strokeWidth:t.strokeWidth,opacity:t.opacity,plumb:t.plumb,vectorEffect:t.vectorEffect,visibility:t.visibility};return e}(o)),this.flagReset(!0),this.zzz.flags[ot.ClipPath]=!1,this.zzz.flags[ot.ClipFlag]=!1,this.closed=!!i,this.curved=!!s,this.beginning=0,this.ending=1,this.cap="butt",this.join="miter",this.miterLimit=4,this.vertices=new H(e),this.automatic=!r}render(t,i,s){if(!this.zzz.viewee){const r={};r.id=this.id;const o=t.createSVGElement("path",r);this.zzz.viewee=o,t.appendChild(i,o),super.render(t,i,s),this.zzz.disposables.push(e((()=>{this.cap&&"butt"!==this.cap?t.setAttribute(o,"stroke-linecap",this.cap):